Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate
Sign In | Create Account

Paste Description for Unnamed

Add read_bmp_fd and make the first parameter of read_bmp_file ("filename") const.

Unnamed
Saturday, November 10th, 2007 at 12:18:00pm UTC 

  1. commit 950f1173a0406d6ed731a5212df2f1e846acf862
  2. Author: Nicolas Pennequin <nicolas@nicolas-laptop.(none)>
  3. Date:   Sat Nov 10 13:14:29 2007 +0100
  4.  
  5.     Add read_bmp_fd and make the first parameter of read_bmp_file ("filename") const.
  6.  
  7. diff --git a/apps/plugin.h b/apps/plugin.h
  8. index f56590c..75d8654 100644
  9. --- a/apps/plugin.h
  10. +++ b/apps/plugin.h
  11. @@ -603,7 +603,7 @@ struct plugin_api {
  12.      bool (*peak_meter_get_use_dbfs)(void);
  13.  #endif
  14.  #ifdef HAVE_LCD_BITMAP
  15. -    int (*read_bmp_file)(char* filename, struct bitmap *bm, int maxsize,
  16. +    int (*read_bmp_file)(const char* filename, struct bitmap *bm, int maxsize,
  17.                           int format);
  18.      void (*screen_dump_set_hook)(void (*hook)(int fh));
  19.  #endif
  20. diff --git a/apps/recorder/bmp.c b/apps/recorder/bmp.c
  21. index 352b2f4..fe63ce4 100644
  22. --- a/apps/recorder/bmp.c
  23. +++ b/apps/recorder/bmp.c
  24. @@ -138,20 +138,20 @@ static inline unsigned brightness(union rgb_union color)
  25.  }
  26.  
  27.  /******************************************************************************
  28. - * read_bmp_file()
  29. + * read_bmp_fd()
  30.   *
  31.   * Reads a BMP file and puts the data in rockbox format in *bitmap.
  32.   *
  33.   *****************************************************************************/
  34. -int read_bmp_file(char* filename,
  35. -                  struct bitmap *bm,
  36. -                  int maxsize,
  37. -                  int format)
  38. +int read_bmp_fd(int fd,
  39. +                struct bitmap *bm,
  40. +                int maxsize,
  41. +                int format)
  42.  {
  43.      struct bmp_header bmph;
  44.      int width, height, padded_width;
  45.      int dst_height, dst_width;
  46. -    int fd, row, col, ret;
  47. +    int row, col, ret;
  48.      int depth, numcolors, compression, totalsize;
  49.  
  50.      unsigned char *bitmap = bm->data;
  51. @@ -185,14 +185,6 @@ int read_bmp_file(char* filename,
  52.      (void)format;
  53.  #endif /* (LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1) */
  54.  
  55. -    fd = open(filename, O_RDONLY);
  56. -
  57. -    /* Exit if file opening failed */
  58. -    if (fd < 0) {
  59. -        DEBUGF("read_bmp_file: can't open '%s', rc: %d\n", filename, fd);
  60. -        return fd * 10 - 1;
  61. -    }
  62. -
  63.      /* read fileheader */
  64.      ret = read(fd, &bmph, sizeof(struct bmp_header));
  65.      if (ret < 0) {
  66. @@ -201,14 +193,14 @@ int read_bmp_file(char* filename,
  67.      }
  68.  
  69.      if (ret != sizeof(struct bmp_header)) {
  70. -        DEBUGF("read_bmp_file: can't read BMP header.");
  71. +        DEBUGF("read_bmp_fd: can't read BMP header.");
  72.          close(fd);
  73.          return -3;
  74.      }
  75.  
  76.      width = readlong(&bmph.width);
  77.      if (width > LCD_WIDTH) {
  78. -        DEBUGF("read_bmp_file: Bitmap too wide (%d pixels, max is %d)\n",
  79. +        DEBUGF("read_bmp_fd: Bitmap too wide (%d pixels, max is %d)\n",
  80.                          width, LCD_WIDTH);
  81.          close(fd);
  82.          return -4;
  83. @@ -267,7 +259,7 @@ int read_bmp_file(char* filename,
  84.  
  85.      /* Check if this fits the buffer */
  86.      if (totalsize > maxsize) {
  87. -        DEBUGF("read_bmp_file: Bitmap too large for buffer: "
  88. +        DEBUGF("read_bmp_fd: Bitmap too large for buffer: "
  89.                 "%d bytes.\n", totalsize);
  90.          close(fd);
  91.          return -6;
  92. @@ -285,7 +277,7 @@ int read_bmp_file(char* filename,
  93.          if (read(fd, palette, numcolors * sizeof(uint32_t))
  94.              != numcolors * (int)sizeof(uint32_t))
  95.          {
  96. -            DEBUGF("read_bmp_file: Can't read color palette\n");
  97. +            DEBUGF("read_bmp_fd: Can't read color palette\n");
  98.              close(fd);
  99.              return -7;
  100.          }
  101. @@ -320,7 +312,7 @@ int read_bmp_file(char* filename,
  102.  
  103.        default:
  104.          if (compression != 0) { /* not BI_RGB */
  105. -            DEBUGF("read_bmp_file: Unsupported compression (type %d)\n",
  106. +            DEBUGF("read_bmp_fd: Unsupported compression (type %d)\n",
  107.                     compression);
  108.              close(fd);
  109.              return -8;
  110. @@ -345,7 +337,7 @@ int read_bmp_file(char* filename,
  111.          /* read one row */
  112.          ret = read(fd, bmpbuf, padded_width);
  113.          if (ret != padded_width) {
  114. -            DEBUGF("read_bmp_file: error reading image, read returned: %d "
  115. +            DEBUGF("read_bmp_fd: error reading image, read returned: %d "
  116.                     "expected: %d\n", ret, padded_width);
  117.              close(fd);
  118.              return -9;
  119. @@ -537,8 +529,26 @@ int read_bmp_file(char* filename,
  120.          }
  121.      }
  122.  
  123. -    close(fd);
  124. -
  125.      DEBUGF("totalsize: %d\n", totalsize);
  126.      return totalsize; /* return the used buffer size. */
  127.  }
  128. +
  129. +
  130. +int read_bmp_file(const char* filename,
  131. +                  struct bitmap *bm,
  132. +                  int maxsize,
  133. +                  int format)
  134. +{
  135. +    int ret;
  136. +    int fd = open(filename, O_RDONLY);
  137. +
  138. +    /* Exit if file opening failed */
  139. +    if (fd < 0) {
  140. +        DEBUGF("read_bmp_file: can't open '%s', rc: %d\n", filename, fd);
  141. +        return fd * 10 - 1;
  142. +    }
  143. +
  144. +    ret = read_bmp_fd(fd, bm, maxsize, format);
  145. +    close(fd);
  146. +    return ret;
  147. +}
  148. diff --git a/apps/recorder/bmp.h b/apps/recorder/bmp.h
  149. index f8650b2..3d33a8c 100644
  150. --- a/apps/recorder/bmp.h
  151. +++ b/apps/recorder/bmp.h
  152. @@ -26,12 +26,17 @@
  153.   * read_bmp_file()
  154.   *
  155.   * Reads a 8bit BMP file and puts the data in a 1-pixel-per-byte
  156. - * array.
  157. + * array.
  158.   * Returns < 0 for error, or number of bytes used from the bitmap buffer
  159.   *
  160.   **********************************************/
  161. -int read_bmp_file(char* filename,
  162. +int read_bmp_file(const char* filename,
  163.                    struct bitmap *bm,
  164.                    int maxsize,
  165.                    int format);
  166. +
  167. +int read_bmp_fd(int fd,
  168. +                struct bitmap *bm,
  169. +                int maxsize,
  170. +                int format);
  171.  #endif

Update the Post

Either update this post and resubmit it with changes, or make a new post.

You may also comment on this post.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.

comments powered by Disqus
worth-right
worth-right