forked from len0rd/rockbox
Magnus Holmgren's patch #708098 that makes bmp2rb insensitive to endianess
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@3691 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
09d1a73d35
commit
2d81cf9956
1 changed files with 20 additions and 19 deletions
|
@ -70,17 +70,18 @@ struct RGBQUAD
|
||||||
unsigned char rgbReserved;
|
unsigned char rgbReserved;
|
||||||
} STRUCT_PACKED;
|
} STRUCT_PACKED;
|
||||||
|
|
||||||
#ifdef LITTLE_ENDIAN
|
|
||||||
#define readshort(x) x
|
|
||||||
#define readlong(x) x
|
|
||||||
#else
|
|
||||||
|
|
||||||
#define readshort(x) (((x&0xff00)>>8)|((x&0x00ff)<<8))
|
short readshort(void* value)
|
||||||
#define readlong(x) (((x&0xff000000)>>24)| \
|
{
|
||||||
((x&0x00ff0000)>>8) | \
|
unsigned char* bytes = (unsigned char*) value;
|
||||||
((x&0x0000ff00)<<8) | \
|
return bytes[0] | (bytes[1] << 8);
|
||||||
((x&0x000000ff)<<24))
|
}
|
||||||
#endif
|
|
||||||
|
int readlong(void* value)
|
||||||
|
{
|
||||||
|
unsigned char* bytes = (unsigned char*) value;
|
||||||
|
return bytes[0] | (bytes[1] << 8) | (bytes[2] << 16) | (bytes[3] << 24);
|
||||||
|
}
|
||||||
|
|
||||||
/*********************************************************************
|
/*********************************************************************
|
||||||
* read_bmp_file()
|
* read_bmp_file()
|
||||||
|
@ -125,7 +126,7 @@ int read_bmp_file(char* filename,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Exit if more than 8 bits */
|
/* Exit if more than 8 bits */
|
||||||
depth = readshort(fh.BitCount);
|
depth = readshort(&fh.BitCount);
|
||||||
if(depth > 8)
|
if(depth > 8)
|
||||||
{
|
{
|
||||||
debugf("error - Bitmap uses more than 8 bit depth, got %d\n",
|
debugf("error - Bitmap uses more than 8 bit depth, got %d\n",
|
||||||
|
@ -135,19 +136,19 @@ int read_bmp_file(char* filename,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Exit if too wide */
|
/* Exit if too wide */
|
||||||
if(readlong(fh.Width) > 112)
|
if(readlong(&fh.Width) > 112)
|
||||||
{
|
{
|
||||||
debugf("error - Bitmap is too wide (%d pixels, max is 112)\n",
|
debugf("error - Bitmap is too wide (%d pixels, max is 112)\n",
|
||||||
readlong(fh.Width));
|
readlong(&fh.Width));
|
||||||
close(fd);
|
close(fd);
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Exit if too high */
|
/* Exit if too high */
|
||||||
if(readlong(fh.Height) > 64)
|
if(readlong(&fh.Height) > 64)
|
||||||
{
|
{
|
||||||
debugf("error - Bitmap is too high (%d pixels, max is 64)\n",
|
debugf("error - Bitmap is too high (%d pixels, max is 64)\n",
|
||||||
readlong(fh.Height));
|
readlong(&fh.Height));
|
||||||
close(fd);
|
close(fd);
|
||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
|
@ -183,14 +184,14 @@ int read_bmp_file(char* filename,
|
||||||
background = 1;
|
background = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
width = readlong(fh.Width);
|
width = readlong(&fh.Width);
|
||||||
|
|
||||||
if(depth == 8)
|
if(depth == 8)
|
||||||
PaddedWidth = ((width+3)&(~0x3)); /* aligned 4-bytes boundaries */
|
PaddedWidth = ((width+3)&(~0x3)); /* aligned 4-bytes boundaries */
|
||||||
else
|
else
|
||||||
PaddedWidth = ((width+31)&(~0x1f))/8;
|
PaddedWidth = ((width+31)&(~0x1f))/8;
|
||||||
|
|
||||||
size = PaddedWidth*readlong(fh.Height);
|
size = PaddedWidth*readlong(&fh.Height);
|
||||||
|
|
||||||
bmp = (unsigned char *)malloc(size);
|
bmp = (unsigned char *)malloc(size);
|
||||||
*bitmap = (unsigned char *)malloc(size);
|
*bitmap = (unsigned char *)malloc(size);
|
||||||
|
@ -210,8 +211,8 @@ int read_bmp_file(char* filename,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bitmap_height = readlong(fh.Height);
|
bitmap_height = readlong(&fh.Height);
|
||||||
bitmap_width = readlong(fh.Width);
|
bitmap_width = readlong(&fh.Width);
|
||||||
|
|
||||||
*get_width = bitmap_width;
|
*get_width = bitmap_width;
|
||||||
*get_height = bitmap_height;
|
*get_height = bitmap_height;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue