1
0
Fork 0
forked from len0rd/rockbox

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
This commit is contained in:
Teruaki Kawashima 2010-11-01 12:13:49 +00:00
parent 308936cd35
commit d055ff4a94
4 changed files with 560 additions and 594 deletions

View file

@ -31,19 +31,18 @@
#include "lcd.h" #include "lcd.h"
#include <lib/pluginlib_bmp.h> #include <lib/pluginlib_bmp.h>
#include "tinf.h" #include "tinf.h"
#include "png.h" #include "../imageviewer.h"
#include "png_decoder.h" #include "png_decoder.h"
#include "bmp.h" #include "bmp.h"
/* decoder context struct */ /* decoder context struct */
static LodePNG_Decoder decoder; static LodePNG_Decoder decoder;
/* my memory pool (from the mp3 buffer) */ static char print[32]; /* use a common snprintf() buffer */
static char print[128]; /* use a common snprintf() buffer */
/* decompressed image in the possible sizes (1,2,4,8), wasting the other */ /* decompressed image in the possible sizes (1,2,4,8), wasting the other */
static fb_data *disp[9]; static unsigned char *disp[9];
static fb_data *disp_buf; static unsigned char *disp_buf;
#if defined(HAVE_LCD_COLOR) #if defined(HAVE_LCD_COLOR)
#define resize_bitmap smooth_resize_bitmap #define resize_bitmap smooth_resize_bitmap
@ -64,16 +63,16 @@ bool img_ext(const char *ext)
void draw_image_rect(struct image_info *info, void draw_image_rect(struct image_info *info,
int x, int y, int width, int height) int x, int y, int width, int height)
{ {
fb_data **pdisp = (fb_data**)info->data; unsigned char **pdisp = (unsigned char **)info->data;
#ifdef HAVE_LCD_COLOR #ifdef HAVE_LCD_COLOR
rb->lcd_bitmap_part(*pdisp, info->x + x, info->y + y, rb->lcd_bitmap_part((fb_data *)*pdisp, info->x + x, info->y + y,
STRIDE(SCREEN_MAIN, info->width, info->height), STRIDE(SCREEN_MAIN, info->width, info->height),
x + MAX(0, (LCD_WIDTH-info->width)/2), x + MAX(0, (LCD_WIDTH-info->width)/2),
y + MAX(0, (LCD_HEIGHT-info->height)/2), y + MAX(0, (LCD_HEIGHT-info->height)/2),
width, height); width, height);
#else #else
mylcd_ub_gray_bitmap_part((const unsigned char*)*pdisp, mylcd_ub_gray_bitmap_part(*pdisp,
info->x + x, info->y + y, info->width, info->x + x, info->y + y, info->width,
x + MAX(0, (LCD_WIDTH-info->width)/2), x + MAX(0, (LCD_WIDTH-info->width)/2),
y + MAX(0, (LCD_HEIGHT-info->height)/2), y + MAX(0, (LCD_HEIGHT-info->height)/2),
@ -102,9 +101,8 @@ int load_image(char *filename, struct image_info *info,
int w, h; /* used to center output */ int w, h; /* used to center output */
LodePNG_Decoder *p_decoder = &decoder; LodePNG_Decoder *p_decoder = &decoder;
unsigned char *memory, *memory_max; unsigned char *memory, *memory_max, *image;
static size_t memory_size, file_size; size_t memory_size, file_size;
static unsigned char *image;
/* cleanup */ /* cleanup */
memset(&disp, 0, sizeof(disp)); memset(&disp, 0, sizeof(disp));
@ -239,16 +237,16 @@ int load_image(char *filename, struct image_info *info,
info->x_size = p_decoder->infoPng.width; info->x_size = p_decoder->infoPng.width;
info->y_size = p_decoder->infoPng.height; info->y_size = p_decoder->infoPng.height;
disp_buf = (fb_data *)(p_decoder->buf + p_decoder->native_img_size); p_decoder->native_img_size = (p_decoder->native_img_size + 3) & ~3;
disp_buf = (fb_data *)ALIGN_UP((uintptr_t)disp_buf,4); disp_buf = p_decoder->buf + p_decoder->native_img_size;
*buf_size = memory_max - (unsigned char*)disp_buf; *buf_size = memory_max - disp_buf;
return PLUGIN_OK; return PLUGIN_OK;
} }
int get_image(struct image_info *info, int ds) int get_image(struct image_info *info, int ds)
{ {
fb_data **p_disp = &disp[ds]; /* short cut */ unsigned char **p_disp = &disp[ds]; /* short cut */
LodePNG_Decoder *p_decoder = &decoder; LodePNG_Decoder *p_decoder = &decoder;
info->width = p_decoder->infoPng.width / ds; info->width = p_decoder->infoPng.width / ds;
@ -270,33 +268,28 @@ int get_image(struct image_info *info, int ds)
} }
struct bitmap bmp_src, bmp_dst; struct bitmap bmp_src, bmp_dst;
int size = info->width * info->height; int size = img_mem(ds);
if ((unsigned char *)(disp_buf + size) >= p_decoder->buf + p_decoder->buf_size) { if (disp_buf + size >= p_decoder->buf + p_decoder->buf_size) {
/* have to discard the current */ /* have to discard the current */
int i; int i;
for (i=1; i<=8; i++) for (i=1; i<=8; i++)
disp[i] = NULL; /* invalidate all bitmaps */ disp[i] = NULL; /* invalidate all bitmaps */
/* start again from the beginning of the buffer */ /* start again from the beginning of the buffer */
disp_buf = (fb_data *)(p_decoder->buf + p_decoder->native_img_size); disp_buf = p_decoder->buf + p_decoder->native_img_size;
disp_buf = (fb_data *)ALIGN_UP((uintptr_t)disp_buf,4);
} }
*p_disp = disp_buf; *p_disp = disp_buf;
#ifdef USEGSLIB
disp_buf = (fb_data *)((unsigned char *)disp_buf + size);
#else
disp_buf += size; disp_buf += size;
#endif
bmp_src.width = p_decoder->infoPng.width; bmp_src.width = p_decoder->infoPng.width;
bmp_src.height = p_decoder->infoPng.height; bmp_src.height = p_decoder->infoPng.height;
bmp_src.data = (unsigned char *)p_decoder->buf; bmp_src.data = p_decoder->buf;
bmp_dst.width = info->width; bmp_dst.width = info->width;
bmp_dst.height = info->height; bmp_dst.height = info->height;
bmp_dst.data = (unsigned char *)*p_disp; bmp_dst.data = *p_disp;
#ifdef HAVE_ADJUSTABLE_CPU_FREQ #ifdef HAVE_ADJUSTABLE_CPU_FREQ
rb->cpu_boost(true); rb->cpu_boost(true);
resize_bitmap(&bmp_src, &bmp_dst); resize_bitmap(&bmp_src, &bmp_dst);
@ -305,7 +298,7 @@ int get_image(struct image_info *info, int ds)
resize_bitmap(&bmp_src, &bmp_dst); resize_bitmap(&bmp_src, &bmp_dst);
#endif /*HAVE_ADJUSTABLE_CPU_FREQ*/ #endif /*HAVE_ADJUSTABLE_CPU_FREQ*/
} else { } else {
*p_disp = (fb_data *)p_decoder->buf; *p_disp = p_decoder->buf;
} }
return PLUGIN_OK; return PLUGIN_OK;

View file

@ -1,25 +0,0 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$id $
*
* Copyright (C) 2009 by Christophe Gouiran <bechris13250 -at- gmail -dot- com>
*
* Based on lodepng, a lightweight png decoder/encoder
* (c) 2005-2008 Lode Vandevenne
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#include "../imageviewer.h"

View file

@ -408,7 +408,7 @@ static void LodePNG_convert(LodePNG_Decoder *decoder)
#ifdef HAVE_LCD_COLOR #ifdef HAVE_LCD_COLOR
struct uint8_rgb *line_buf = (struct uint8_rgb *)(out + w * h * FB_DATA_SZ); struct uint8_rgb *line_buf = (struct uint8_rgb *)(out + w * h * FB_DATA_SZ);
#else #else
uint8_t *line_buf = (unsigned char *)(out + w * h * FB_DATA_SZ); uint8_t *line_buf = (unsigned char *)(out + w * h);
#endif #endif
struct bitmap bm = { struct bitmap bm = {
@ -428,12 +428,12 @@ static void LodePNG_convert(LodePNG_Decoder *decoder)
const struct custom_format *cformat = &format_native; const struct custom_format *cformat = &format_native;
#endif #endif
void (*output_row_8)(uint32_t, void*, struct scaler_context*) = cformat->output_row_8; void (*output_row_8)(uint32_t, void*, struct scaler_context*) = cformat->output_row_8;
#ifdef HAVE_LCD_COLOR #ifdef HAVE_LCD_COLOR
struct uint8_rgb *pixel; struct uint8_rgb *pixel;
#else #else
unsigned char *pixel; unsigned char *pixel;
#endif #endif
#ifdef HAVE_LCD_COLOR #ifdef HAVE_LCD_COLOR
@ -711,8 +711,8 @@ unsigned char *pixel;
} }
} }
#else /* greyscale targets */ #else /* greyscale targets */
struct uint8_rgb px_rgb; /* for rgb(a) -> greyscale conversion */ struct uint8_rgb px_rgb; /* for rgb(a) -> greyscale conversion */
uint8_t background_grey; /* for rgb background -> greyscale background */ uint8_t background_grey; /* for rgb background -> greyscale background */
if (infoIn->color.bitDepth == 8) if (infoIn->color.bitDepth == 8)
{ {
@ -1097,13 +1097,13 @@ static uint8_t unfilterScanline(uint8_t* recon,
* disjoint. * disjoint.
*/ */
/* storage space for cached portion of scanline */ /* storage space for cached portion of scanline */
unsigned char cache[512+16]; unsigned char cache[512+16];
/* ptr to second element of the cache */ /* ptr to second element of the cache */
unsigned char *cache_1 = cache + bytewidth; unsigned char *cache_1 = cache + bytewidth;
unsigned char *p_cache = cache + 256 + 8; /* half way */ unsigned char *p_cache = cache + 256 + 8; /* half way */
unsigned char *p_cache_1 = p_cache + bytewidth; unsigned char *p_cache_1 = p_cache + bytewidth;
size_t i; size_t i;
switch (filterType) switch (filterType)
@ -2080,7 +2080,7 @@ void LodePNG_decode(LodePNG_Decoder* decoder,
/* one line more as temp buffer for conversion */ /* one line more as temp buffer for conversion */
#ifdef HAVE_LCD_COLOR #ifdef HAVE_LCD_COLOR
decoder->native_img_size = decoder->infoPng.width * decoder->native_img_size = decoder->infoPng.width *
(decoder->infoPng.height)*FB_DATA_SZ; decoder->infoPng.height * FB_DATA_SZ;
line_buf_size = decoder->infoPng.width * sizeof(struct uint8_rgb); line_buf_size = decoder->infoPng.width * sizeof(struct uint8_rgb);
#else #else
decoder->native_img_size = decoder->infoPng.width * decoder->native_img_size = decoder->infoPng.width *
@ -2134,11 +2134,9 @@ void LodePNG_decode(LodePNG_Decoder* decoder,
{ {
/* calculate 'corrected' image size */ /* calculate 'corrected' image size */
#ifdef HAVE_LCD_COLOR #ifdef HAVE_LCD_COLOR
c_native_img_size = dim_dst.width * c_native_img_size = dim_dst.width * dim_dst.height * FB_DATA_SZ;
(dim_dst.height)*FB_DATA_SZ;
#else #else
c_native_img_size = dim_dst.width * c_native_img_size = dim_dst.width * dim_dst.height;
dim_dst.height;
#endif #endif
/* check memory constraints /* check memory constraints
* do the correction only if there is enough * do the correction only if there is enough
@ -2170,10 +2168,10 @@ void LodePNG_decode(LodePNG_Decoder* decoder,
memcpy(img_src.data, img_dst.data, decoder->native_img_size); memcpy(img_src.data, img_dst.data, decoder->native_img_size);
} }
} }
#endif /* (LCD_PIXEL_ASPECT_HEIGHT != 1 || LCD_PIXEL_ASPECT_WIDTH != 1) */ #endif /* (LCD_PIXEL_ASPECT_HEIGHT != 1 || LCD_PIXEL_ASPECT_WIDTH != 1) */
time = *rb->current_tick - time;
if (pf_progress) pf_progress(100, 100); time = *rb->current_tick - time;
if (pf_progress) pf_progress(100, 100);
} }
void LodePNG_Decoder_init(LodePNG_Decoder* decoder, void LodePNG_Decoder_init(LodePNG_Decoder* decoder,