summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorMiika Pekkarinen <miipekk@ihme.org>2006-01-29 19:16:35 +0000
committerMiika Pekkarinen <miipekk@ihme.org>2006-01-29 19:16:35 +0000
commit58231d50f2cb940a309814e31ae583b4b0dfed24 (patch)
tree3dce0d57cd1d9740b6dd0f26da58887b2cbf41ea /apps
parent65721f0b3573460d306528ff34aa395c45e94ea3 (diff)
downloadrockbox-58231d50f2cb940a309814e31ae583b4b0dfed24.tar.gz
rockbox-58231d50f2cb940a309814e31ae583b4b0dfed24.zip
Save image format tag in bmp cache also to hopefully fix the color
issue. Added also a simple header version check. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8487 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
-rw-r--r--apps/gui/gwps-common.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/apps/gui/gwps-common.c b/apps/gui/gwps-common.c
index 9b32b862ff..11e92a640d 100644
--- a/apps/gui/gwps-common.c
+++ b/apps/gui/gwps-common.c
@@ -75,10 +75,17 @@ static char* skip_utf8_bom(char* buf)
75 * a..z and A..Z 75 * a..z and A..Z
76 */ 76 */
77#ifdef HAVE_LCD_BITMAP 77#ifdef HAVE_LCD_BITMAP
78#define BMP_CACHE_VERSION 1
79
80struct bmp_cache_header {
81 int version;
82};
83
78struct bmp_cache_entry { 84struct bmp_cache_entry {
79 char filename[MAX_PATH]; 85 char filename[MAX_PATH];
80 int width; 86 int width;
81 int height; 87 int height;
88 int format;
82 int size; 89 int size;
83}; 90};
84static int bmp_cache_fd = -1; 91static int bmp_cache_fd = -1;
@@ -95,12 +102,31 @@ static int get_image_id(int c)
95 102
96void wps_initialize_bmp_cache(const char *file) 103void wps_initialize_bmp_cache(const char *file)
97{ 104{
105 struct bmp_cache_header h;
106
98 bmp_cache_fd = open(file, O_RDONLY); 107 bmp_cache_fd = open(file, O_RDONLY);
99 bmp_cache_write = 0; 108 bmp_cache_write = 0;
109
110 /* Check header validity. */
111 if (bmp_cache_fd >= 0)
112 {
113 if ((read(bmp_cache_fd, &h, sizeof(struct bmp_cache_header))
114 != sizeof(struct bmp_cache_header)
115 ) || h.version != BMP_CACHE_VERSION)
116 {
117 close(bmp_cache_fd);
118 bmp_cache_fd = -1;
119 }
120 }
121
100 if (bmp_cache_fd < 0) 122 if (bmp_cache_fd < 0)
101 { 123 {
102 bmp_cache_fd = open(file, O_WRONLY | O_CREAT); 124 bmp_cache_fd = open(file, O_WRONLY | O_CREAT);
103 bmp_cache_write = 1; 125 bmp_cache_write = 1;
126
127 /* Write the header. */
128 h.version = BMP_CACHE_VERSION;
129 write(bmp_cache_fd, &h, sizeof(struct bmp_cache_header));
104 } 130 }
105} 131}
106 132
@@ -138,6 +164,9 @@ static int read_bmp_from_cache(const char *filename, struct bitmap *bm,
138 164
139 bm->width = c.width; 165 bm->width = c.width;
140 bm->height = c.height; 166 bm->height = c.height;
167#if LCD_DEPTH > 1
168 bm->format = c.format;
169#endif
141 rc = read(bmp_cache_fd, bm->data, c.size); 170 rc = read(bmp_cache_fd, bm->data, c.size);
142 if (rc != c.size) 171 if (rc != c.size)
143 return -4; 172 return -4;
@@ -297,12 +326,16 @@ bool wps_data_preload_tags(struct wps_data *data, char *buf,
297 326
298 if (ret > 0) 327 if (ret > 0)
299 { 328 {
329 /* Update the image cache. */
300 if (bmp_cache_write && bmp_cache_fd >= 0) 330 if (bmp_cache_write && bmp_cache_fd >= 0)
301 { 331 {
302 struct bmp_cache_entry c; 332 struct bmp_cache_entry c;
303 strncpy(c.filename, imgname, sizeof(c.filename)-1); 333 strncpy(c.filename, imgname, sizeof(c.filename)-1);
304 c.width = data->img[n].bm.width; 334 c.width = data->img[n].bm.width;
305 c.height = data->img[n].bm.height; 335 c.height = data->img[n].bm.height;
336#if LCD_DEPTH > 1
337 c.format = data->img[n].bm.format;
338#endif
306 c.size = ret; 339 c.size = ret;
307 write(bmp_cache_fd, &c, sizeof(struct bmp_cache_entry)); 340 write(bmp_cache_fd, &c, sizeof(struct bmp_cache_entry));
308 write(bmp_cache_fd, data->img_buf_ptr, ret); 341 write(bmp_cache_fd, data->img_buf_ptr, ret);