summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiika Pekkarinen <miipekk@ihme.org>2006-02-01 08:43:29 +0000
committerMiika Pekkarinen <miipekk@ihme.org>2006-02-01 08:43:29 +0000
commitb106e010d5974e6e8812028f967a29692e52632d (patch)
treecca8717f7ab13b40d7676af88e1a4df56f19f582
parent98c37c7f89e811ad65a811cb408231b42f0c638a (diff)
downloadrockbox-b106e010d5974e6e8812028f967a29692e52632d.tar.gz
rockbox-b106e010d5974e6e8812028f967a29692e52632d.zip
Reverted the wps image cache as it was causing trouble to users when
updating the image files on disk. Better solution is to be implemented soon. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8519 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/gui/gwps-common.c124
-rw-r--r--apps/gui/gwps-common.h3
-rw-r--r--apps/gui/gwps.c5
3 files changed, 4 insertions, 128 deletions
diff --git a/apps/gui/gwps-common.c b/apps/gui/gwps-common.c
index 1cda8c0f24..d6d765f418 100644
--- a/apps/gui/gwps-common.c
+++ b/apps/gui/gwps-common.c
@@ -75,22 +75,6 @@ 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
84struct bmp_cache_entry {
85 char filename[MAX_PATH];
86 int width;
87 int height;
88 int format;
89 int size;
90};
91static int bmp_cache_fd = -1;
92static bool bmp_cache_write;
93
94static int get_image_id(int c) 78static int get_image_id(int c)
95{ 79{
96 if(c >= 'a' && c <= 'z') 80 if(c >= 'a' && c <= 'z')
@@ -99,80 +83,6 @@ static int get_image_id(int c)
99 c = c - 'A' + 26; 83 c = c - 'A' + 26;
100 return c; 84 return c;
101} 85}
102
103void wps_initialize_bmp_cache(const char *file)
104{
105 struct bmp_cache_header h;
106
107 bmp_cache_fd = open(file, O_RDONLY);
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
122 if (bmp_cache_fd < 0)
123 {
124 bmp_cache_fd = open(file, O_WRONLY | O_CREAT);
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));
130 }
131}
132
133void wps_close_bmp_cache(const char *file)
134{
135 if (bmp_cache_fd >= 0)
136 {
137 close(bmp_cache_fd);
138 bmp_cache_fd = -1;
139 return ;
140 }
141
142 /* Remove the file if cache read failed. */
143 remove(file);
144}
145
146static int read_bmp_from_cache(const char *filename, struct bitmap *bm,
147 int buflen)
148{
149 struct bmp_cache_entry c;
150 int rc;
151
152 if (!bmp_cache_fd || bmp_cache_write)
153 return -1;
154
155 rc = read(bmp_cache_fd, &c, sizeof(struct bmp_cache_entry));
156 if (rc != sizeof(struct bmp_cache_entry))
157 return -2;
158
159 if (buflen < c.size)
160 return -3;
161
162 if (strcasecmp(filename, c.filename))
163 return -4;
164
165 bm->width = c.width;
166 bm->height = c.height;
167#if LCD_DEPTH > 1
168 bm->format = c.format;
169#endif
170 rc = read(bmp_cache_fd, bm->data, c.size);
171 if (rc != c.size)
172 return -4;
173
174 return c.size;
175}
176#endif 86#endif
177 87
178/* 88/*
@@ -308,21 +218,9 @@ bool wps_data_preload_tags(struct wps_data *data, char *buf,
308 218
309 /* load the image */ 219 /* load the image */
310 data->img[n].bm.data = data->img_buf_ptr; 220 data->img[n].bm.data = data->img_buf_ptr;
311 ret = read_bmp_from_cache(imgname, &data->img[n].bm, 221 ret = read_bmp_file(imgname, &data->img[n].bm,
312 data->img_buf_free); 222 data->img_buf_free,
313 223 FORMAT_ANY|FORMAT_TRANSPARENT);
314 if (ret < 0)
315 {
316 if (!bmp_cache_write)
317 {
318 close(bmp_cache_fd);
319 bmp_cache_fd = -1;
320 }
321
322 ret = read_bmp_file(imgname, &data->img[n].bm,
323 data->img_buf_free,
324 FORMAT_ANY|FORMAT_TRANSPARENT);
325 }
326 224
327 if (ret > 0) 225 if (ret > 0)
328 { 226 {
@@ -330,21 +228,7 @@ bool wps_data_preload_tags(struct wps_data *data, char *buf,
330 if (ret % 2) ret++; 228 if (ret % 2) ret++;
331 /* Always consume an even number of bytes */ 229 /* Always consume an even number of bytes */
332#endif 230#endif
333 /* Update the image cache. */ 231
334 if (bmp_cache_write && bmp_cache_fd >= 0)
335 {
336 struct bmp_cache_entry c;
337 strncpy(c.filename, imgname, sizeof(c.filename)-1);
338 c.width = data->img[n].bm.width;
339 c.height = data->img[n].bm.height;
340#if LCD_DEPTH > 1
341 c.format = data->img[n].bm.format;
342#endif
343 c.size = ret;
344 write(bmp_cache_fd, &c, sizeof(struct bmp_cache_entry));
345 write(bmp_cache_fd, data->img_buf_ptr, ret);
346 }
347
348 data->img_buf_ptr += ret; 232 data->img_buf_ptr += ret;
349 data->img_buf_free -= ret; 233 data->img_buf_free -= ret;
350 data->img[n].loaded = true; 234 data->img[n].loaded = true;
diff --git a/apps/gui/gwps-common.h b/apps/gui/gwps-common.h
index b106203f98..ecda1d47ea 100644
--- a/apps/gui/gwps-common.h
+++ b/apps/gui/gwps-common.h
@@ -23,9 +23,6 @@
23 23
24#include "gwps.h" 24#include "gwps.h"
25 25
26void wps_initialize_bmp_cache(const char *file);
27void wps_close_bmp_cache(const char *file);
28
29void gui_wps_format_time(char* buf, int buf_size, long time); 26void gui_wps_format_time(char* buf, int buf_size, long time);
30void fade(bool fade_in); 27void fade(bool fade_in);
31void gui_wps_format(struct wps_data *data); 28void gui_wps_format(struct wps_data *data);
diff --git a/apps/gui/gwps.c b/apps/gui/gwps.c
index e7ae67266f..d7d436c089 100644
--- a/apps/gui/gwps.c
+++ b/apps/gui/gwps.c
@@ -862,7 +862,6 @@ bool wps_data_load(struct wps_data *wps_data,
862 wps_data->img_buf_ptr = wps_data->img_buf; /* where in image buffer */ 862 wps_data->img_buf_ptr = wps_data->img_buf; /* where in image buffer */
863 863
864 wps_data->img_buf_free = IMG_BUFSIZE; /* free space in image buffer */ 864 wps_data->img_buf_free = IMG_BUFSIZE; /* free space in image buffer */
865 wps_initialize_bmp_cache(ROCKBOX_DIR "/.wpscache");
866#endif 865#endif
867 while( ( read_line(fd, &wps_data->format_buffer[start], 866 while( ( read_line(fd, &wps_data->format_buffer[start],
868 sizeof(wps_data->format_buffer)-start) ) > 0 ) 867 sizeof(wps_data->format_buffer)-start) ) > 0 )
@@ -881,10 +880,6 @@ bool wps_data_load(struct wps_data *wps_data,
881 } 880 }
882 } 881 }
883 882
884#ifdef HAVE_LCD_BITMAP
885 wps_close_bmp_cache(ROCKBOX_DIR "/.wpscache");
886#endif
887
888 if (start > 0) 883 if (start > 0)
889 { 884 {
890 gui_wps_format(wps_data); 885 gui_wps_format(wps_data);