diff options
Diffstat (limited to 'apps/plugins/imageviewer/png/png.c')
-rw-r--r-- | apps/plugins/imageviewer/png/png.c | 55 |
1 files changed, 30 insertions, 25 deletions
diff --git a/apps/plugins/imageviewer/png/png.c b/apps/plugins/imageviewer/png/png.c index 956cad37d8..10404b7c30 100644 --- a/apps/plugins/imageviewer/png/png.c +++ b/apps/plugins/imageviewer/png/png.c | |||
@@ -50,18 +50,13 @@ static unsigned char *disp_buf; | |||
50 | #define resize_bitmap grey_resize_bitmap | 50 | #define resize_bitmap grey_resize_bitmap |
51 | #endif | 51 | #endif |
52 | 52 | ||
53 | bool img_ext(const char *ext) | 53 | #if defined(USEGSLIB) && (CONFIG_PLATFORM & PLATFORM_HOSTED) |
54 | { | 54 | /* hack: fix error "undefined reference to `_grey_info'". */ |
55 | if (!ext) | 55 | GREY_INFO_STRUCT |
56 | return false; | 56 | #endif /* USEGSLIB */ |
57 | if (!rb->strcasecmp(ext,".png")) | ||
58 | return true; | ||
59 | else | ||
60 | return false; | ||
61 | } | ||
62 | 57 | ||
63 | void draw_image_rect(struct image_info *info, | 58 | static void draw_image_rect(struct image_info *info, |
64 | int x, int y, int width, int height) | 59 | int x, int y, int width, int height) |
65 | { | 60 | { |
66 | unsigned char **pdisp = (unsigned char **)info->data; | 61 | unsigned char **pdisp = (unsigned char **)info->data; |
67 | 62 | ||
@@ -80,7 +75,7 @@ void draw_image_rect(struct image_info *info, | |||
80 | #endif | 75 | #endif |
81 | } | 76 | } |
82 | 77 | ||
83 | int img_mem(int ds) | 78 | static int img_mem(int ds) |
84 | { | 79 | { |
85 | LodePNG_Decoder *p_decoder = &decoder; | 80 | LodePNG_Decoder *p_decoder = &decoder; |
86 | 81 | ||
@@ -93,8 +88,8 @@ int img_mem(int ds) | |||
93 | #endif | 88 | #endif |
94 | } | 89 | } |
95 | 90 | ||
96 | int load_image(char *filename, struct image_info *info, | 91 | static int load_image(char *filename, struct image_info *info, |
97 | unsigned char *buf, ssize_t *buf_size) | 92 | unsigned char *buf, ssize_t *buf_size) |
98 | { | 93 | { |
99 | int fd; | 94 | int fd; |
100 | long time = 0; /* measured ticks */ | 95 | long time = 0; /* measured ticks */ |
@@ -122,7 +117,7 @@ int load_image(char *filename, struct image_info *info, | |||
122 | 117 | ||
123 | DEBUGF("reading file '%s'\n", filename); | 118 | DEBUGF("reading file '%s'\n", filename); |
124 | 119 | ||
125 | if (!running_slideshow) { | 120 | if (!iv->running_slideshow) { |
126 | rb->lcd_puts(0, 0, rb->strrchr(filename,'/')+1); | 121 | rb->lcd_puts(0, 0, rb->strrchr(filename,'/')+1); |
127 | rb->lcd_update(); | 122 | rb->lcd_update(); |
128 | } | 123 | } |
@@ -132,7 +127,7 @@ int load_image(char *filename, struct image_info *info, | |||
132 | rb->close(fd); | 127 | rb->close(fd); |
133 | 128 | ||
134 | } else { | 129 | } else { |
135 | if (!running_slideshow) { | 130 | if (!iv->running_slideshow) { |
136 | rb->lcd_putsf(0, 1, "loading %zu bytes", file_size); | 131 | rb->lcd_putsf(0, 1, "loading %zu bytes", file_size); |
137 | rb->lcd_update(); | 132 | rb->lcd_update(); |
138 | } | 133 | } |
@@ -142,12 +137,12 @@ int load_image(char *filename, struct image_info *info, | |||
142 | rb->read(fd, image, file_size); | 137 | rb->read(fd, image, file_size); |
143 | rb->close(fd); | 138 | rb->close(fd); |
144 | 139 | ||
145 | if (!running_slideshow) { | 140 | if (!iv->running_slideshow) { |
146 | rb->lcd_puts(0, 2, "decoding image"); | 141 | rb->lcd_puts(0, 2, "decoding image"); |
147 | rb->lcd_update(); | 142 | rb->lcd_update(); |
148 | } | 143 | } |
149 | #ifdef DISK_SPINDOWN | 144 | #ifdef DISK_SPINDOWN |
150 | else if (immediate_ata_off) { | 145 | else if (iv->immediate_ata_off) { |
151 | /* running slideshow and time is long enough: power down disk */ | 146 | /* running slideshow and time is long enough: power down disk */ |
152 | rb->storage_sleep(); | 147 | rb->storage_sleep(); |
153 | } | 148 | } |
@@ -167,7 +162,7 @@ int load_image(char *filename, struct image_info *info, | |||
167 | 162 | ||
168 | if (!p_decoder->error) { | 163 | if (!p_decoder->error) { |
169 | 164 | ||
170 | if (!running_slideshow) { | 165 | if (!iv->running_slideshow) { |
171 | rb->lcd_putsf(0, 2, "image %dx%d", | 166 | rb->lcd_putsf(0, 2, "image %dx%d", |
172 | p_decoder->infoPng.width, | 167 | p_decoder->infoPng.width, |
173 | p_decoder->infoPng.height); | 168 | p_decoder->infoPng.height); |
@@ -181,16 +176,16 @@ int load_image(char *filename, struct image_info *info, | |||
181 | time = *rb->current_tick; | 176 | time = *rb->current_tick; |
182 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ | 177 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ |
183 | rb->cpu_boost(true); | 178 | rb->cpu_boost(true); |
184 | LodePNG_decode(p_decoder, image, file_size, cb_progress); | 179 | LodePNG_decode(p_decoder, image, file_size, iv->cb_progress); |
185 | rb->cpu_boost(false); | 180 | rb->cpu_boost(false); |
186 | #else | 181 | #else |
187 | LodePNG_decode(p_decoder, image, file_size, cb_progress); | 182 | LodePNG_decode(p_decoder, image, file_size, iv->cb_progress); |
188 | #endif /*HAVE_ADJUSTABLE_CPU_FREQ*/ | 183 | #endif /*HAVE_ADJUSTABLE_CPU_FREQ*/ |
189 | time = *rb->current_tick - time; | 184 | time = *rb->current_tick - time; |
190 | } | 185 | } |
191 | } | 186 | } |
192 | 187 | ||
193 | if (!running_slideshow && !p_decoder->error) | 188 | if (!iv->running_slideshow && !p_decoder->error) |
194 | { | 189 | { |
195 | rb->snprintf(print, sizeof(print), " %ld.%02ld sec ", time/HZ, time%HZ); | 190 | rb->snprintf(print, sizeof(print), " %ld.%02ld sec ", time/HZ, time%HZ); |
196 | rb->lcd_getstringsize(print, &w, &h); /* centered in progress bar */ | 191 | rb->lcd_getstringsize(print, &w, &h); /* centered in progress bar */ |
@@ -200,7 +195,7 @@ int load_image(char *filename, struct image_info *info, | |||
200 | 195 | ||
201 | if (p_decoder->error) { | 196 | if (p_decoder->error) { |
202 | #ifdef USE_PLUG_BUF | 197 | #ifdef USE_PLUG_BUF |
203 | if (plug_buf && (p_decoder->error == FILE_TOO_LARGE || | 198 | if (iv->plug_buf && (p_decoder->error == FILE_TOO_LARGE || |
204 | p_decoder->error == OUT_OF_MEMORY || | 199 | p_decoder->error == OUT_OF_MEMORY || |
205 | p_decoder->error == TINF_DATA_ERROR)) | 200 | p_decoder->error == TINF_DATA_ERROR)) |
206 | return PLUGIN_OUTOFMEM; | 201 | return PLUGIN_OUTOFMEM; |
@@ -244,7 +239,7 @@ int load_image(char *filename, struct image_info *info, | |||
244 | return PLUGIN_OK; | 239 | return PLUGIN_OK; |
245 | } | 240 | } |
246 | 241 | ||
247 | int get_image(struct image_info *info, int ds) | 242 | static int get_image(struct image_info *info, int ds) |
248 | { | 243 | { |
249 | unsigned char **p_disp = &disp[ds]; /* short cut */ | 244 | unsigned char **p_disp = &disp[ds]; /* short cut */ |
250 | LodePNG_Decoder *p_decoder = &decoder; | 245 | LodePNG_Decoder *p_decoder = &decoder; |
@@ -261,7 +256,7 @@ int get_image(struct image_info *info, int ds) | |||
261 | 256 | ||
262 | /* assign image buffer */ | 257 | /* assign image buffer */ |
263 | if (ds > 1) { | 258 | if (ds > 1) { |
264 | if (!running_slideshow) | 259 | if (!iv->running_slideshow) |
265 | { | 260 | { |
266 | rb->lcd_putsf(0, 3, "resizing %d*%d", info->width, info->height); | 261 | rb->lcd_putsf(0, 3, "resizing %d*%d", info->width, info->height); |
267 | rb->lcd_update(); | 262 | rb->lcd_update(); |
@@ -303,3 +298,13 @@ int get_image(struct image_info *info, int ds) | |||
303 | 298 | ||
304 | return PLUGIN_OK; | 299 | return PLUGIN_OK; |
305 | } | 300 | } |
301 | |||
302 | const struct image_decoder image_decoder = { | ||
303 | true, | ||
304 | img_mem, | ||
305 | load_image, | ||
306 | get_image, | ||
307 | draw_image_rect, | ||
308 | }; | ||
309 | |||
310 | IMGDEC_HEADER | ||