summaryrefslogtreecommitdiff
path: root/apps/gui/gwps-common.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/gui/gwps-common.c')
-rw-r--r--apps/gui/gwps-common.c124
1 files changed, 4 insertions, 120 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;