diff options
author | Daniel Stenberg <daniel@haxx.se> | 2003-05-21 06:31:44 +0000 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2003-05-21 06:31:44 +0000 |
commit | 2d81cf995665f2dbf97fd88ebef97b8b9149b76c (patch) | |
tree | e6db3d97b532895e18a7060fa399677f147a2d03 | |
parent | 09d1a73d35ffab5eea3773fb90e9d08f0e3a6a66 (diff) | |
download | rockbox-2d81cf995665f2dbf97fd88ebef97b8b9149b76c.tar.gz rockbox-2d81cf995665f2dbf97fd88ebef97b8b9149b76c.zip |
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
-rw-r--r-- | tools/bmp2rb.c | 39 |
1 files changed, 20 insertions, 19 deletions
diff --git a/tools/bmp2rb.c b/tools/bmp2rb.c index 2fbfcc1a16..18b37f9cf6 100644 --- a/tools/bmp2rb.c +++ b/tools/bmp2rb.c @@ -70,17 +70,18 @@ struct RGBQUAD unsigned char rgbReserved; } STRUCT_PACKED; -#ifdef LITTLE_ENDIAN -#define readshort(x) x -#define readlong(x) x -#else -#define readshort(x) (((x&0xff00)>>8)|((x&0x00ff)<<8)) -#define readlong(x) (((x&0xff000000)>>24)| \ - ((x&0x00ff0000)>>8) | \ - ((x&0x0000ff00)<<8) | \ - ((x&0x000000ff)<<24)) -#endif +short readshort(void* value) +{ + unsigned char* bytes = (unsigned char*) value; + return bytes[0] | (bytes[1] << 8); +} + +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() @@ -125,7 +126,7 @@ int read_bmp_file(char* filename, } /* Exit if more than 8 bits */ - depth = readshort(fh.BitCount); + depth = readshort(&fh.BitCount); if(depth > 8) { 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 */ - if(readlong(fh.Width) > 112) + if(readlong(&fh.Width) > 112) { debugf("error - Bitmap is too wide (%d pixels, max is 112)\n", - readlong(fh.Width)); + readlong(&fh.Width)); close(fd); return 3; } /* 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", - readlong(fh.Height)); + readlong(&fh.Height)); close(fd); return 4; } @@ -183,14 +184,14 @@ int read_bmp_file(char* filename, background = 1; } - width = readlong(fh.Width); + width = readlong(&fh.Width); if(depth == 8) PaddedWidth = ((width+3)&(~0x3)); /* aligned 4-bytes boundaries */ else PaddedWidth = ((width+31)&(~0x1f))/8; - size = PaddedWidth*readlong(fh.Height); + size = PaddedWidth*readlong(&fh.Height); bmp = (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_width = readlong(fh.Width); + bitmap_height = readlong(&fh.Height); + bitmap_width = readlong(&fh.Width); *get_width = bitmap_width; *get_height = bitmap_height; |