diff options
Diffstat (limited to 'apps/recorder')
-rw-r--r-- | apps/recorder/bmp.c | 59 | ||||
-rw-r--r-- | apps/recorder/bmp.h | 9 |
2 files changed, 41 insertions, 27 deletions
diff --git a/apps/recorder/bmp.c b/apps/recorder/bmp.c index 352b2f47b1..6416eb7bac 100644 --- a/apps/recorder/bmp.c +++ b/apps/recorder/bmp.c | |||
@@ -143,15 +143,41 @@ static inline unsigned brightness(union rgb_union color) | |||
143 | * Reads a BMP file and puts the data in rockbox format in *bitmap. | 143 | * Reads a BMP file and puts the data in rockbox format in *bitmap. |
144 | * | 144 | * |
145 | *****************************************************************************/ | 145 | *****************************************************************************/ |
146 | int read_bmp_file(char* filename, | 146 | int read_bmp_file(const char* filename, |
147 | struct bitmap *bm, | 147 | struct bitmap *bm, |
148 | int maxsize, | 148 | int maxsize, |
149 | int format) | 149 | int format) |
150 | { | 150 | { |
151 | int fd, ret; | ||
152 | fd = open(filename, O_RDONLY); | ||
153 | |||
154 | /* Exit if file opening failed */ | ||
155 | if (fd < 0) { | ||
156 | DEBUGF("read_bmp_file: can't open '%s', rc: %d\n", filename, fd); | ||
157 | return fd * 10 - 1; | ||
158 | } | ||
159 | |||
160 | ret = read_bmp_fd(fd, bm, maxsize, format); | ||
161 | close(fd); | ||
162 | return ret; | ||
163 | } | ||
164 | |||
165 | /****************************************************************************** | ||
166 | * read_bmp_fd() | ||
167 | * | ||
168 | * Reads a BMP file in an open file descriptor and puts the data in rockbox | ||
169 | * format in *bitmap. | ||
170 | * | ||
171 | *****************************************************************************/ | ||
172 | int read_bmp_fd(int fd, | ||
173 | struct bitmap *bm, | ||
174 | int maxsize, | ||
175 | int format) | ||
176 | { | ||
151 | struct bmp_header bmph; | 177 | struct bmp_header bmph; |
152 | int width, height, padded_width; | 178 | int width, height, padded_width; |
153 | int dst_height, dst_width; | 179 | int dst_height, dst_width; |
154 | int fd, row, col, ret; | 180 | int row, col, ret; |
155 | int depth, numcolors, compression, totalsize; | 181 | int depth, numcolors, compression, totalsize; |
156 | 182 | ||
157 | unsigned char *bitmap = bm->data; | 183 | unsigned char *bitmap = bm->data; |
@@ -185,32 +211,21 @@ int read_bmp_file(char* filename, | |||
185 | (void)format; | 211 | (void)format; |
186 | #endif /* (LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1) */ | 212 | #endif /* (LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1) */ |
187 | 213 | ||
188 | fd = open(filename, O_RDONLY); | ||
189 | |||
190 | /* Exit if file opening failed */ | ||
191 | if (fd < 0) { | ||
192 | DEBUGF("read_bmp_file: can't open '%s', rc: %d\n", filename, fd); | ||
193 | return fd * 10 - 1; | ||
194 | } | ||
195 | |||
196 | /* read fileheader */ | 214 | /* read fileheader */ |
197 | ret = read(fd, &bmph, sizeof(struct bmp_header)); | 215 | ret = read(fd, &bmph, sizeof(struct bmp_header)); |
198 | if (ret < 0) { | 216 | if (ret < 0) { |
199 | close(fd); | ||
200 | return ret * 10 - 2; | 217 | return ret * 10 - 2; |
201 | } | 218 | } |
202 | 219 | ||
203 | if (ret != sizeof(struct bmp_header)) { | 220 | if (ret != sizeof(struct bmp_header)) { |
204 | DEBUGF("read_bmp_file: can't read BMP header."); | 221 | DEBUGF("read_bmp_fd: can't read BMP header."); |
205 | close(fd); | ||
206 | return -3; | 222 | return -3; |
207 | } | 223 | } |
208 | 224 | ||
209 | width = readlong(&bmph.width); | 225 | width = readlong(&bmph.width); |
210 | if (width > LCD_WIDTH) { | 226 | if (width > LCD_WIDTH) { |
211 | DEBUGF("read_bmp_file: Bitmap too wide (%d pixels, max is %d)\n", | 227 | DEBUGF("read_bmp_fd: Bitmap too wide (%d pixels, max is %d)\n", |
212 | width, LCD_WIDTH); | 228 | width, LCD_WIDTH); |
213 | close(fd); | ||
214 | return -4; | 229 | return -4; |
215 | } | 230 | } |
216 | 231 | ||
@@ -267,9 +282,8 @@ int read_bmp_file(char* filename, | |||
267 | 282 | ||
268 | /* Check if this fits the buffer */ | 283 | /* Check if this fits the buffer */ |
269 | if (totalsize > maxsize) { | 284 | if (totalsize > maxsize) { |
270 | DEBUGF("read_bmp_file: Bitmap too large for buffer: " | 285 | DEBUGF("read_bmp_fd: Bitmap too large for buffer: " |
271 | "%d bytes.\n", totalsize); | 286 | "%d bytes.\n", totalsize); |
272 | close(fd); | ||
273 | return -6; | 287 | return -6; |
274 | } | 288 | } |
275 | 289 | ||
@@ -285,8 +299,7 @@ int read_bmp_file(char* filename, | |||
285 | if (read(fd, palette, numcolors * sizeof(uint32_t)) | 299 | if (read(fd, palette, numcolors * sizeof(uint32_t)) |
286 | != numcolors * (int)sizeof(uint32_t)) | 300 | != numcolors * (int)sizeof(uint32_t)) |
287 | { | 301 | { |
288 | DEBUGF("read_bmp_file: Can't read color palette\n"); | 302 | DEBUGF("read_bmp_fd: Can't read color palette\n"); |
289 | close(fd); | ||
290 | return -7; | 303 | return -7; |
291 | } | 304 | } |
292 | } | 305 | } |
@@ -320,9 +333,8 @@ int read_bmp_file(char* filename, | |||
320 | 333 | ||
321 | default: | 334 | default: |
322 | if (compression != 0) { /* not BI_RGB */ | 335 | if (compression != 0) { /* not BI_RGB */ |
323 | DEBUGF("read_bmp_file: Unsupported compression (type %d)\n", | 336 | DEBUGF("read_bmp_fd: Unsupported compression (type %d)\n", |
324 | compression); | 337 | compression); |
325 | close(fd); | ||
326 | return -8; | 338 | return -8; |
327 | } | 339 | } |
328 | break; | 340 | break; |
@@ -345,9 +357,8 @@ int read_bmp_file(char* filename, | |||
345 | /* read one row */ | 357 | /* read one row */ |
346 | ret = read(fd, bmpbuf, padded_width); | 358 | ret = read(fd, bmpbuf, padded_width); |
347 | if (ret != padded_width) { | 359 | if (ret != padded_width) { |
348 | DEBUGF("read_bmp_file: error reading image, read returned: %d " | 360 | DEBUGF("read_bmp_fd: error reading image, read returned: %d " |
349 | "expected: %d\n", ret, padded_width); | 361 | "expected: %d\n", ret, padded_width); |
350 | close(fd); | ||
351 | return -9; | 362 | return -9; |
352 | } | 363 | } |
353 | 364 | ||
@@ -537,8 +548,6 @@ int read_bmp_file(char* filename, | |||
537 | } | 548 | } |
538 | } | 549 | } |
539 | 550 | ||
540 | close(fd); | ||
541 | |||
542 | DEBUGF("totalsize: %d\n", totalsize); | 551 | DEBUGF("totalsize: %d\n", totalsize); |
543 | return totalsize; /* return the used buffer size. */ | 552 | return totalsize; /* return the used buffer size. */ |
544 | } | 553 | } |
diff --git a/apps/recorder/bmp.h b/apps/recorder/bmp.h index f8650b2203..3d33a8c34b 100644 --- a/apps/recorder/bmp.h +++ b/apps/recorder/bmp.h | |||
@@ -26,12 +26,17 @@ | |||
26 | * read_bmp_file() | 26 | * read_bmp_file() |
27 | * | 27 | * |
28 | * Reads a 8bit BMP file and puts the data in a 1-pixel-per-byte | 28 | * Reads a 8bit BMP file and puts the data in a 1-pixel-per-byte |
29 | * array. | 29 | * array. |
30 | * Returns < 0 for error, or number of bytes used from the bitmap buffer | 30 | * Returns < 0 for error, or number of bytes used from the bitmap buffer |
31 | * | 31 | * |
32 | **********************************************/ | 32 | **********************************************/ |
33 | int read_bmp_file(char* filename, | 33 | int read_bmp_file(const char* filename, |
34 | struct bitmap *bm, | 34 | struct bitmap *bm, |
35 | int maxsize, | 35 | int maxsize, |
36 | int format); | 36 | int format); |
37 | |||
38 | int read_bmp_fd(int fd, | ||
39 | struct bitmap *bm, | ||
40 | int maxsize, | ||
41 | int format); | ||
37 | #endif | 42 | #endif |