summaryrefslogtreecommitdiff
path: root/apps/plugins/imageviewer/png/png.c
diff options
context:
space:
mode:
authorTeruaki Kawashima <teru@rockbox.org>2010-11-01 12:13:49 +0000
committerTeruaki Kawashima <teru@rockbox.org>2010-11-01 12:13:49 +0000
commitd055ff4a94e5fe2f06a1454c4baa60c641ea8012 (patch)
treec3128ead15bfd5c3df09c4d9e10676405fce8a95 /apps/plugins/imageviewer/png/png.c
parent308936cd356fa2c559fbc2b2e3273403437e5fe7 (diff)
downloadrockbox-d055ff4a94e5fe2f06a1454c4baa60c641ea8012.tar.gz
rockbox-d055ff4a94e5fe2f06a1454c4baa60c641ea8012.zip
reduce casts between "unsinged char *" and "fb_data *". make calculation precise. maintain spaces.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28428 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/imageviewer/png/png.c')
-rw-r--r--apps/plugins/imageviewer/png/png.c45
1 files changed, 19 insertions, 26 deletions
diff --git a/apps/plugins/imageviewer/png/png.c b/apps/plugins/imageviewer/png/png.c
index 4bd988d939..956cad37d8 100644
--- a/apps/plugins/imageviewer/png/png.c
+++ b/apps/plugins/imageviewer/png/png.c
@@ -31,19 +31,18 @@
31#include "lcd.h" 31#include "lcd.h"
32#include <lib/pluginlib_bmp.h> 32#include <lib/pluginlib_bmp.h>
33#include "tinf.h" 33#include "tinf.h"
34#include "png.h" 34#include "../imageviewer.h"
35#include "png_decoder.h" 35#include "png_decoder.h"
36#include "bmp.h" 36#include "bmp.h"
37 37
38/* decoder context struct */ 38/* decoder context struct */
39static LodePNG_Decoder decoder; 39static LodePNG_Decoder decoder;
40 40
41/* my memory pool (from the mp3 buffer) */ 41static char print[32]; /* use a common snprintf() buffer */
42static char print[128]; /* use a common snprintf() buffer */
43 42
44/* decompressed image in the possible sizes (1,2,4,8), wasting the other */ 43/* decompressed image in the possible sizes (1,2,4,8), wasting the other */
45static fb_data *disp[9]; 44static unsigned char *disp[9];
46static fb_data *disp_buf; 45static unsigned char *disp_buf;
47 46
48#if defined(HAVE_LCD_COLOR) 47#if defined(HAVE_LCD_COLOR)
49#define resize_bitmap smooth_resize_bitmap 48#define resize_bitmap smooth_resize_bitmap
@@ -64,16 +63,16 @@ bool img_ext(const char *ext)
64void draw_image_rect(struct image_info *info, 63void draw_image_rect(struct image_info *info,
65 int x, int y, int width, int height) 64 int x, int y, int width, int height)
66{ 65{
67 fb_data **pdisp = (fb_data**)info->data; 66 unsigned char **pdisp = (unsigned char **)info->data;
68 67
69#ifdef HAVE_LCD_COLOR 68#ifdef HAVE_LCD_COLOR
70 rb->lcd_bitmap_part(*pdisp, info->x + x, info->y + y, 69 rb->lcd_bitmap_part((fb_data *)*pdisp, info->x + x, info->y + y,
71 STRIDE(SCREEN_MAIN, info->width, info->height), 70 STRIDE(SCREEN_MAIN, info->width, info->height),
72 x + MAX(0, (LCD_WIDTH-info->width)/2), 71 x + MAX(0, (LCD_WIDTH-info->width)/2),
73 y + MAX(0, (LCD_HEIGHT-info->height)/2), 72 y + MAX(0, (LCD_HEIGHT-info->height)/2),
74 width, height); 73 width, height);
75#else 74#else
76 mylcd_ub_gray_bitmap_part((const unsigned char*)*pdisp, 75 mylcd_ub_gray_bitmap_part(*pdisp,
77 info->x + x, info->y + y, info->width, 76 info->x + x, info->y + y, info->width,
78 x + MAX(0, (LCD_WIDTH-info->width)/2), 77 x + MAX(0, (LCD_WIDTH-info->width)/2),
79 y + MAX(0, (LCD_HEIGHT-info->height)/2), 78 y + MAX(0, (LCD_HEIGHT-info->height)/2),
@@ -102,9 +101,8 @@ int load_image(char *filename, struct image_info *info,
102 int w, h; /* used to center output */ 101 int w, h; /* used to center output */
103 LodePNG_Decoder *p_decoder = &decoder; 102 LodePNG_Decoder *p_decoder = &decoder;
104 103
105 unsigned char *memory, *memory_max; 104 unsigned char *memory, *memory_max, *image;
106 static size_t memory_size, file_size; 105 size_t memory_size, file_size;
107 static unsigned char *image;
108 106
109 /* cleanup */ 107 /* cleanup */
110 memset(&disp, 0, sizeof(disp)); 108 memset(&disp, 0, sizeof(disp));
@@ -239,16 +237,16 @@ int load_image(char *filename, struct image_info *info,
239 info->x_size = p_decoder->infoPng.width; 237 info->x_size = p_decoder->infoPng.width;
240 info->y_size = p_decoder->infoPng.height; 238 info->y_size = p_decoder->infoPng.height;
241 239
242 disp_buf = (fb_data *)(p_decoder->buf + p_decoder->native_img_size); 240 p_decoder->native_img_size = (p_decoder->native_img_size + 3) & ~3;
243 disp_buf = (fb_data *)ALIGN_UP((uintptr_t)disp_buf,4); 241 disp_buf = p_decoder->buf + p_decoder->native_img_size;
244 *buf_size = memory_max - (unsigned char*)disp_buf; 242 *buf_size = memory_max - disp_buf;
245 243
246 return PLUGIN_OK; 244 return PLUGIN_OK;
247} 245}
248 246
249int get_image(struct image_info *info, int ds) 247int get_image(struct image_info *info, int ds)
250{ 248{
251 fb_data **p_disp = &disp[ds]; /* short cut */ 249 unsigned char **p_disp = &disp[ds]; /* short cut */
252 LodePNG_Decoder *p_decoder = &decoder; 250 LodePNG_Decoder *p_decoder = &decoder;
253 251
254 info->width = p_decoder->infoPng.width / ds; 252 info->width = p_decoder->infoPng.width / ds;
@@ -270,33 +268,28 @@ int get_image(struct image_info *info, int ds)
270 } 268 }
271 struct bitmap bmp_src, bmp_dst; 269 struct bitmap bmp_src, bmp_dst;
272 270
273 int size = info->width * info->height; 271 int size = img_mem(ds);
274 272
275 if ((unsigned char *)(disp_buf + size) >= p_decoder->buf + p_decoder->buf_size) { 273 if (disp_buf + size >= p_decoder->buf + p_decoder->buf_size) {
276 /* have to discard the current */ 274 /* have to discard the current */
277 int i; 275 int i;
278 for (i=1; i<=8; i++) 276 for (i=1; i<=8; i++)
279 disp[i] = NULL; /* invalidate all bitmaps */ 277 disp[i] = NULL; /* invalidate all bitmaps */
280 278
281 /* start again from the beginning of the buffer */ 279 /* start again from the beginning of the buffer */
282 disp_buf = (fb_data *)(p_decoder->buf + p_decoder->native_img_size); 280 disp_buf = p_decoder->buf + p_decoder->native_img_size;
283 disp_buf = (fb_data *)ALIGN_UP((uintptr_t)disp_buf,4);
284 } 281 }
285 282
286 *p_disp = disp_buf; 283 *p_disp = disp_buf;
287#ifdef USEGSLIB
288 disp_buf = (fb_data *)((unsigned char *)disp_buf + size);
289#else
290 disp_buf += size; 284 disp_buf += size;
291#endif
292 285
293 bmp_src.width = p_decoder->infoPng.width; 286 bmp_src.width = p_decoder->infoPng.width;
294 bmp_src.height = p_decoder->infoPng.height; 287 bmp_src.height = p_decoder->infoPng.height;
295 bmp_src.data = (unsigned char *)p_decoder->buf; 288 bmp_src.data = p_decoder->buf;
296 289
297 bmp_dst.width = info->width; 290 bmp_dst.width = info->width;
298 bmp_dst.height = info->height; 291 bmp_dst.height = info->height;
299 bmp_dst.data = (unsigned char *)*p_disp; 292 bmp_dst.data = *p_disp;
300#ifdef HAVE_ADJUSTABLE_CPU_FREQ 293#ifdef HAVE_ADJUSTABLE_CPU_FREQ
301 rb->cpu_boost(true); 294 rb->cpu_boost(true);
302 resize_bitmap(&bmp_src, &bmp_dst); 295 resize_bitmap(&bmp_src, &bmp_dst);
@@ -305,7 +298,7 @@ int get_image(struct image_info *info, int ds)
305 resize_bitmap(&bmp_src, &bmp_dst); 298 resize_bitmap(&bmp_src, &bmp_dst);
306#endif /*HAVE_ADJUSTABLE_CPU_FREQ*/ 299#endif /*HAVE_ADJUSTABLE_CPU_FREQ*/
307 } else { 300 } else {
308 *p_disp = (fb_data *)p_decoder->buf; 301 *p_disp = p_decoder->buf;
309 } 302 }
310 303
311 return PLUGIN_OK; 304 return PLUGIN_OK;