summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tools/bmp2rb.c36
1 files changed, 27 insertions, 9 deletions
diff --git a/tools/bmp2rb.c b/tools/bmp2rb.c
index 18b37f9cf6..f874fed677 100644
--- a/tools/bmp2rb.c
+++ b/tools/bmp2rb.c
@@ -104,10 +104,12 @@ int read_bmp_file(char* filename,
104 int background; 104 int background;
105 int fd = open(filename, O_RDONLY); 105 int fd = open(filename, O_RDONLY);
106 long size; 106 long size;
107 long allocsize;
107 unsigned int row, col; 108 unsigned int row, col;
108 int l; 109 int l;
109 unsigned char *bmp; 110 unsigned char *bmp;
110 int width; 111 int width;
112 int height;
111 int depth; 113 int depth;
112 114
113 if(fd == -1) 115 if(fd == -1)
@@ -136,22 +138,30 @@ int read_bmp_file(char* filename,
136 } 138 }
137 139
138 /* Exit if too wide */ 140 /* Exit if too wide */
139 if(readlong(&fh.Width) > 112) 141 if(readlong(&fh.Width) > 160)
140 { 142 {
141 debugf("error - Bitmap is too wide (%d pixels, max is 112)\n", 143 debugf("error - Bitmap is too wide for iRiver models (%d pixels, max is 160)\n",
142 readlong(&fh.Width)); 144 readlong(&fh.Width));
143 close(fd);
144 return 3; 145 return 3;
145 } 146 }
147 if(readlong(&fh.Width) > 112)
148 {
149 debugf("info - Bitmap is too wide for Archos models (%d pixels, max is 112)\n",
150 readlong(&fh.Width));
151 }
146 152
147 /* Exit if too high */ 153 /* Exit if too high */
148 if(readlong(&fh.Height) > 64) 154 if(readlong(&fh.Height) > 128)
149 { 155 {
150 debugf("error - Bitmap is too high (%d pixels, max is 64)\n", 156 debugf("error - Bitmap is too high for iRiver models (%d pixels, max is 128)\n",
151 readlong(&fh.Height)); 157 readlong(&fh.Height));
152 close(fd);
153 return 4; 158 return 4;
154 } 159 }
160 if(readlong(&fh.Height) > 64)
161 {
162 debugf("info - Bitmap is too high for Archos models (%d pixels, max is 64)\n",
163 readlong(&fh.Height));
164 }
155 165
156 for(l=0;l < 2;l++) 166 for(l=0;l < 2;l++)
157 { 167 {
@@ -191,10 +201,18 @@ int read_bmp_file(char* filename,
191 else 201 else
192 PaddedWidth = ((width+31)&(~0x1f))/8; 202 PaddedWidth = ((width+31)&(~0x1f))/8;
193 203
194 size = PaddedWidth*readlong(&fh.Height); 204 height = readlong(&fh.Height);
195 205
206 allocsize = size = PaddedWidth*height; /* read this many bytes */
196 bmp = (unsigned char *)malloc(size); 207 bmp = (unsigned char *)malloc(size);
197 *bitmap = (unsigned char *)malloc(size); 208
209 if(height%8) {
210 /* not even 8 bytes, add up to a full 8 pixels boundary */
211 height += 8-(height%8);
212 allocsize = PaddedWidth*height; /* bytes to alloc */
213 }
214
215 *bitmap = (unsigned char *)malloc(allocsize);
198 216
199 if(bmp == NULL) 217 if(bmp == NULL)
200 { 218 {