summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tools/bmp2rb.c39
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
70 unsigned char rgbReserved; 70 unsigned char rgbReserved;
71} STRUCT_PACKED; 71} STRUCT_PACKED;
72 72
73#ifdef LITTLE_ENDIAN
74#define readshort(x) x
75#define readlong(x) x
76#else
77 73
78#define readshort(x) (((x&0xff00)>>8)|((x&0x00ff)<<8)) 74short readshort(void* value)
79#define readlong(x) (((x&0xff000000)>>24)| \ 75{
80 ((x&0x00ff0000)>>8) | \ 76 unsigned char* bytes = (unsigned char*) value;
81 ((x&0x0000ff00)<<8) | \ 77 return bytes[0] | (bytes[1] << 8);
82 ((x&0x000000ff)<<24)) 78}
83#endif 79
80int readlong(void* value)
81{
82 unsigned char* bytes = (unsigned char*) value;
83 return bytes[0] | (bytes[1] << 8) | (bytes[2] << 16) | (bytes[3] << 24);
84}
84 85
85/********************************************************************* 86/*********************************************************************
86 * read_bmp_file() 87 * read_bmp_file()
@@ -125,7 +126,7 @@ int read_bmp_file(char* filename,
125 } 126 }
126 127
127 /* Exit if more than 8 bits */ 128 /* Exit if more than 8 bits */
128 depth = readshort(fh.BitCount); 129 depth = readshort(&fh.BitCount);
129 if(depth > 8) 130 if(depth > 8)
130 { 131 {
131 debugf("error - Bitmap uses more than 8 bit depth, got %d\n", 132 debugf("error - Bitmap uses more than 8 bit depth, got %d\n",
@@ -135,19 +136,19 @@ int read_bmp_file(char* filename,
135 } 136 }
136 137
137 /* Exit if too wide */ 138 /* Exit if too wide */
138 if(readlong(fh.Width) > 112) 139 if(readlong(&fh.Width) > 112)
139 { 140 {
140 debugf("error - Bitmap is too wide (%d pixels, max is 112)\n", 141 debugf("error - Bitmap is too wide (%d pixels, max is 112)\n",
141 readlong(fh.Width)); 142 readlong(&fh.Width));
142 close(fd); 143 close(fd);
143 return 3; 144 return 3;
144 } 145 }
145 146
146 /* Exit if too high */ 147 /* Exit if too high */
147 if(readlong(fh.Height) > 64) 148 if(readlong(&fh.Height) > 64)
148 { 149 {
149 debugf("error - Bitmap is too high (%d pixels, max is 64)\n", 150 debugf("error - Bitmap is too high (%d pixels, max is 64)\n",
150 readlong(fh.Height)); 151 readlong(&fh.Height));
151 close(fd); 152 close(fd);
152 return 4; 153 return 4;
153 } 154 }
@@ -183,14 +184,14 @@ int read_bmp_file(char* filename,
183 background = 1; 184 background = 1;
184 } 185 }
185 186
186 width = readlong(fh.Width); 187 width = readlong(&fh.Width);
187 188
188 if(depth == 8) 189 if(depth == 8)
189 PaddedWidth = ((width+3)&(~0x3)); /* aligned 4-bytes boundaries */ 190 PaddedWidth = ((width+3)&(~0x3)); /* aligned 4-bytes boundaries */
190 else 191 else
191 PaddedWidth = ((width+31)&(~0x1f))/8; 192 PaddedWidth = ((width+31)&(~0x1f))/8;
192 193
193 size = PaddedWidth*readlong(fh.Height); 194 size = PaddedWidth*readlong(&fh.Height);
194 195
195 bmp = (unsigned char *)malloc(size); 196 bmp = (unsigned char *)malloc(size);
196 *bitmap = (unsigned char *)malloc(size); 197 *bitmap = (unsigned char *)malloc(size);
@@ -210,8 +211,8 @@ int read_bmp_file(char* filename,
210 } 211 }
211 } 212 }
212 213
213 bitmap_height = readlong(fh.Height); 214 bitmap_height = readlong(&fh.Height);
214 bitmap_width = readlong(fh.Width); 215 bitmap_width = readlong(&fh.Width);
215 216
216 *get_width = bitmap_width; 217 *get_width = bitmap_width;
217 *get_height = bitmap_height; 218 *get_height = bitmap_height;