diff options
| author | Nicolas Pennequin <nicolas.pennequin@free.fr> | 2007-11-10 13:26:11 +0000 |
|---|---|---|
| committer | Nicolas Pennequin <nicolas.pennequin@free.fr> | 2007-11-10 13:26:11 +0000 |
| commit | ec6569ed22d27eb6eb5a3902502eecc59d83de7a (patch) | |
| tree | cd67240c2c3d338dae8ca0fa2adacc09b278af06 | |
| parent | d3ba403f607b744becbd437a4f193c6bda49b6da (diff) | |
| download | rockbox-ec6569ed22d27eb6eb5a3902502eecc59d83de7a.zip rockbox-ec6569ed22d27eb6eb5a3902502eecc59d83de7a.tar.gz rockbox-ec6569ed22d27eb6eb5a3902502eecc59d83de7a.tar.bz2 rockbox-ec6569ed22d27eb6eb5a3902502eecc59d83de7a.tar.xz | |
Add read_bmp_fd and make the first parameter of read_bmp_file ("filename") const.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15553 a1c6a512-1295-4272-9138-f99709370657
| -rw-r--r-- | apps/plugin.h | 2 | ||||
| -rw-r--r-- | apps/recorder/bmp.c | 59 | ||||
| -rw-r--r-- | apps/recorder/bmp.h | 9 |
3 files changed, 42 insertions, 28 deletions
diff --git a/apps/plugin.h b/apps/plugin.h index f56590c..75d8654 100644 --- a/apps/plugin.h +++ b/apps/plugin.h @@ -603,7 +603,7 @@ struct plugin_api { bool (*peak_meter_get_use_dbfs)(void); #endif #ifdef HAVE_LCD_BITMAP - int (*read_bmp_file)(char* filename, struct bitmap *bm, int maxsize, + int (*read_bmp_file)(const char* filename, struct bitmap *bm, int maxsize, int format); void (*screen_dump_set_hook)(void (*hook)(int fh)); #endif diff --git a/apps/recorder/bmp.c b/apps/recorder/bmp.c index 352b2f4..6416eb7 100644 --- a/apps/recorder/bmp.c +++ b/apps/recorder/bmp.c @@ -143,15 +143,41 @@ static inline unsigned brightness(union rgb_union color) * Reads a BMP file and puts the data in rockbox format in *bitmap. * *****************************************************************************/ -int read_bmp_file(char* filename, +int read_bmp_file(const char* filename, struct bitmap *bm, int maxsize, int format) { + int fd, ret; + fd = open(filename, O_RDONLY); + + /* Exit if file opening failed */ + if (fd < 0) { + DEBUGF("read_bmp_file: can't open '%s', rc: %d\n", filename, fd); + return fd * 10 - 1; + } + + ret = read_bmp_fd(fd, bm, maxsize, format); + close(fd); + return ret; +} + +/****************************************************************************** + * read_bmp_fd() + * + * Reads a BMP file in an open file descriptor and puts the data in rockbox + * format in *bitmap. + * + *****************************************************************************/ +int read_bmp_fd(int fd, + struct bitmap *bm, + int maxsize, + int format) +{ struct bmp_header bmph; int width, height, padded_width; int dst_height, dst_width; - int fd, row, col, ret; + int row, col, ret; int depth, numcolors, compression, totalsize; unsigned char *bitmap = bm->data; @@ -185,32 +211,21 @@ int read_bmp_file(char* filename, (void)format; #endif /* (LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1) */ - fd = open(filename, O_RDONLY); - - /* Exit if file opening failed */ - if (fd < 0) { - DEBUGF("read_bmp_file: can't open '%s', rc: %d\n", filename, fd); - return fd * 10 - 1; - } - /* read fileheader */ ret = read(fd, &bmph, sizeof(struct bmp_header)); if (ret < 0) { - close(fd); return ret * 10 - 2; } if (ret != sizeof(struct bmp_header)) { - DEBUGF("read_bmp_file: can't read BMP header."); - close(fd); + DEBUGF("read_bmp_fd: can't read BMP header."); return -3; } width = readlong(&bmph.width); if (width > LCD_WIDTH) { - DEBUGF("read_bmp_file: Bitmap too wide (%d pixels, max is %d)\n", + DEBUGF("read_bmp_fd: Bitmap too wide (%d pixels, max is %d)\n", width, LCD_WIDTH); - close(fd); return -4; } @@ -267,9 +282,8 @@ int read_bmp_file(char* filename, /* Check if this fits the buffer */ if (totalsize > maxsize) { - DEBUGF("read_bmp_file: Bitmap too large for buffer: " + DEBUGF("read_bmp_fd: Bitmap too large for buffer: " "%d bytes.\n", totalsize); - close(fd); return -6; } @@ -285,8 +299,7 @@ int read_bmp_file(char* filename, if (read(fd, palette, numcolors * sizeof(uint32_t)) != numcolors * (int)sizeof(uint32_t)) { - DEBUGF("read_bmp_file: Can't read color palette\n"); - close(fd); + DEBUGF("read_bmp_fd: Can't read color palette\n"); return -7; } } @@ -320,9 +333,8 @@ int read_bmp_file(char* filename, default: if (compression != 0) { /* not BI_RGB */ - DEBUGF("read_bmp_file: Unsupported compression (type %d)\n", + DEBUGF("read_bmp_fd: Unsupported compression (type %d)\n", compression); - close(fd); return -8; } break; @@ -345,9 +357,8 @@ int read_bmp_file(char* filename, /* read one row */ ret = read(fd, bmpbuf, padded_width); if (ret != padded_width) { - DEBUGF("read_bmp_file: error reading image, read returned: %d " + DEBUGF("read_bmp_fd: error reading image, read returned: %d " "expected: %d\n", ret, padded_width); - close(fd); return -9; } @@ -537,8 +548,6 @@ int read_bmp_file(char* filename, } } - close(fd); - DEBUGF("totalsize: %d\n", totalsize); return totalsize; /* return the used buffer size. */ } diff --git a/apps/recorder/bmp.h b/apps/recorder/bmp.h index f8650b2..3d33a8c 100644 --- a/apps/recorder/bmp.h +++ b/apps/recorder/bmp.h @@ -26,12 +26,17 @@ * read_bmp_file() * * Reads a 8bit BMP file and puts the data in a 1-pixel-per-byte - * array. + * array. * Returns < 0 for error, or number of bytes used from the bitmap buffer * **********************************************/ -int read_bmp_file(char* filename, +int read_bmp_file(const char* filename, struct bitmap *bm, int maxsize, int format); + +int read_bmp_fd(int fd, + struct bitmap *bm, + int maxsize, + int format); #endif |