diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/gui/gwps-common.c | 92 | ||||
-rw-r--r-- | apps/gui/gwps-common.h | 3 | ||||
-rw-r--r-- | apps/gui/gwps.c | 5 |
3 files changed, 97 insertions, 3 deletions
diff --git a/apps/gui/gwps-common.c b/apps/gui/gwps-common.c index b32deba479..9b32b862ff 100644 --- a/apps/gui/gwps-common.c +++ b/apps/gui/gwps-common.c | |||
@@ -75,6 +75,15 @@ 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 | struct bmp_cache_entry { | ||
79 | char filename[MAX_PATH]; | ||
80 | int width; | ||
81 | int height; | ||
82 | int size; | ||
83 | }; | ||
84 | static int bmp_cache_fd = -1; | ||
85 | static bool bmp_cache_write; | ||
86 | |||
78 | static int get_image_id(int c) | 87 | static int get_image_id(int c) |
79 | { | 88 | { |
80 | if(c >= 'a' && c <= 'z') | 89 | if(c >= 'a' && c <= 'z') |
@@ -83,7 +92,60 @@ static int get_image_id(int c) | |||
83 | c = c - 'A' + 26; | 92 | c = c - 'A' + 26; |
84 | return c; | 93 | return c; |
85 | } | 94 | } |
95 | |||
96 | void wps_initialize_bmp_cache(const char *file) | ||
97 | { | ||
98 | bmp_cache_fd = open(file, O_RDONLY); | ||
99 | bmp_cache_write = 0; | ||
100 | if (bmp_cache_fd < 0) | ||
101 | { | ||
102 | bmp_cache_fd = open(file, O_WRONLY | O_CREAT); | ||
103 | bmp_cache_write = 1; | ||
104 | } | ||
105 | } | ||
106 | |||
107 | void wps_close_bmp_cache(const char *file) | ||
108 | { | ||
109 | if (bmp_cache_fd >= 0) | ||
110 | { | ||
111 | close(bmp_cache_fd); | ||
112 | bmp_cache_fd = -1; | ||
113 | return ; | ||
114 | } | ||
115 | |||
116 | /* Remove the file if cache read failed. */ | ||
117 | remove(file); | ||
118 | } | ||
119 | |||
120 | static int read_bmp_from_cache(const char *filename, struct bitmap *bm, | ||
121 | int buflen) | ||
122 | { | ||
123 | struct bmp_cache_entry c; | ||
124 | int rc; | ||
125 | |||
126 | if (!bmp_cache_fd || bmp_cache_write) | ||
127 | return -1; | ||
128 | |||
129 | rc = read(bmp_cache_fd, &c, sizeof(struct bmp_cache_entry)); | ||
130 | if (rc != sizeof(struct bmp_cache_entry)) | ||
131 | return -2; | ||
132 | |||
133 | if (buflen < c.size) | ||
134 | return -3; | ||
135 | |||
136 | if (strcasecmp(filename, c.filename)) | ||
137 | return -4; | ||
138 | |||
139 | bm->width = c.width; | ||
140 | bm->height = c.height; | ||
141 | rc = read(bmp_cache_fd, bm->data, c.size); | ||
142 | if (rc != c.size) | ||
143 | return -4; | ||
144 | |||
145 | return c.size; | ||
146 | } | ||
86 | #endif | 147 | #endif |
148 | |||
87 | /* | 149 | /* |
88 | * parse the given buffer for following static tags: | 150 | * parse the given buffer for following static tags: |
89 | * %x - load image for always display | 151 | * %x - load image for always display |
@@ -217,11 +279,35 @@ bool wps_data_preload_tags(struct wps_data *data, char *buf, | |||
217 | 279 | ||
218 | /* load the image */ | 280 | /* load the image */ |
219 | data->img[n].bm.data = data->img_buf_ptr; | 281 | data->img[n].bm.data = data->img_buf_ptr; |
220 | ret = read_bmp_file(imgname, &data->img[n].bm, | 282 | ret = read_bmp_from_cache(imgname, &data->img[n].bm, |
221 | data->img_buf_free, | 283 | data->img_buf_free); |
222 | FORMAT_ANY|FORMAT_TRANSPARENT); | 284 | |
285 | if (ret < 0) | ||
286 | { | ||
287 | if (!bmp_cache_write) | ||
288 | { | ||
289 | close(bmp_cache_fd); | ||
290 | bmp_cache_fd = -1; | ||
291 | } | ||
292 | |||
293 | ret = read_bmp_file(imgname, &data->img[n].bm, | ||
294 | data->img_buf_free, | ||
295 | FORMAT_ANY|FORMAT_TRANSPARENT); | ||
296 | } | ||
297 | |||
223 | if (ret > 0) | 298 | if (ret > 0) |
224 | { | 299 | { |
300 | if (bmp_cache_write && bmp_cache_fd >= 0) | ||
301 | { | ||
302 | struct bmp_cache_entry c; | ||
303 | strncpy(c.filename, imgname, sizeof(c.filename)-1); | ||
304 | c.width = data->img[n].bm.width; | ||
305 | c.height = data->img[n].bm.height; | ||
306 | c.size = ret; | ||
307 | write(bmp_cache_fd, &c, sizeof(struct bmp_cache_entry)); | ||
308 | write(bmp_cache_fd, data->img_buf_ptr, ret); | ||
309 | } | ||
310 | |||
225 | data->img_buf_ptr += ret; | 311 | data->img_buf_ptr += ret; |
226 | data->img_buf_free -= ret; | 312 | data->img_buf_free -= ret; |
227 | data->img[n].loaded = true; | 313 | data->img[n].loaded = true; |
diff --git a/apps/gui/gwps-common.h b/apps/gui/gwps-common.h index ecda1d47ea..b106203f98 100644 --- a/apps/gui/gwps-common.h +++ b/apps/gui/gwps-common.h | |||
@@ -23,6 +23,9 @@ | |||
23 | 23 | ||
24 | #include "gwps.h" | 24 | #include "gwps.h" |
25 | 25 | ||
26 | void wps_initialize_bmp_cache(const char *file); | ||
27 | void wps_close_bmp_cache(const char *file); | ||
28 | |||
26 | void gui_wps_format_time(char* buf, int buf_size, long time); | 29 | void gui_wps_format_time(char* buf, int buf_size, long time); |
27 | void fade(bool fade_in); | 30 | void fade(bool fade_in); |
28 | void gui_wps_format(struct wps_data *data); | 31 | void gui_wps_format(struct wps_data *data); |
diff --git a/apps/gui/gwps.c b/apps/gui/gwps.c index d7d436c089..e7ae67266f 100644 --- a/apps/gui/gwps.c +++ b/apps/gui/gwps.c | |||
@@ -862,6 +862,7 @@ 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"); | ||
865 | #endif | 866 | #endif |
866 | while( ( read_line(fd, &wps_data->format_buffer[start], | 867 | while( ( read_line(fd, &wps_data->format_buffer[start], |
867 | sizeof(wps_data->format_buffer)-start) ) > 0 ) | 868 | sizeof(wps_data->format_buffer)-start) ) > 0 ) |
@@ -880,6 +881,10 @@ bool wps_data_load(struct wps_data *wps_data, | |||
880 | } | 881 | } |
881 | } | 882 | } |
882 | 883 | ||
884 | #ifdef HAVE_LCD_BITMAP | ||
885 | wps_close_bmp_cache(ROCKBOX_DIR "/.wpscache"); | ||
886 | #endif | ||
887 | |||
883 | if (start > 0) | 888 | if (start > 0) |
884 | { | 889 | { |
885 | gui_wps_format(wps_data); | 890 | gui_wps_format(wps_data); |