rendered paste bodycommit 950f1173a0406d6ed731a5212df2f1e846acf862Author: Nicolas Pennequin <nicolas@nicolas-laptop.(none)>Date: Sat Nov 10 13:14:29 2007 +0100 Add read_bmp_fd and make the first parameter of read_bmp_file ("filename") const.diff --git a/apps/plugin.h b/apps/plugin.hindex 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)); #endifdiff --git a/apps/recorder/bmp.c b/apps/recorder/bmp.cindex 352b2f4..fe63ce4 100644--- a/apps/recorder/bmp.c+++ b/apps/recorder/bmp.c@@ -138,20 +138,20 @@ static inline unsigned brightness(union rgb_union color) } /******************************************************************************- * read_bmp_file()+ * read_bmp_fd() * * Reads a BMP file and puts the data in rockbox format in *bitmap. * *****************************************************************************/-int read_bmp_file(char* filename,- struct bitmap *bm,- int maxsize,- int format)+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,14 +185,6 @@ 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) {@@ -201,14 +193,14 @@ int read_bmp_file(char* filename, } if (ret != sizeof(struct bmp_header)) {- DEBUGF("read_bmp_file: can't read BMP header.");+ DEBUGF("read_bmp_fd: can't read BMP header."); close(fd); 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,7 +259,7 @@ 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,7 +277,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");+ DEBUGF("read_bmp_fd: Can't read color palette\n"); close(fd); return -7; }@@ -320,7 +312,7 @@ 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;@@ -345,7 +337,7 @@ 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 +529,26 @@ int read_bmp_file(char* filename, } } - close(fd);- DEBUGF("totalsize: %d\n", totalsize); return totalsize; /* return the used buffer size. */ }+++int read_bmp_file(const char* filename,+ struct bitmap *bm,+ int maxsize,+ int format)+{+ int ret;+ int 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;+}diff --git a/apps/recorder/bmp.h b/apps/recorder/bmp.hindex 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