struct definitions now go inside rpng_common.h - move them

away from public headers
This commit is contained in:
twinaphex 2015-09-01 13:08:10 +02:00
parent 2194ab6631
commit c259b983de
5 changed files with 87 additions and 75 deletions

View File

@ -78,6 +78,73 @@ struct adam7_pass
unsigned stride_y;
};
struct idat_buffer
{
uint8_t *data;
size_t size;
};
struct png_chunk
{
uint32_t size;
char type[4];
uint8_t *data;
};
struct png_ihdr
{
uint32_t width;
uint32_t height;
uint8_t depth;
uint8_t color_type;
uint8_t compression;
uint8_t filter;
uint8_t interlace;
};
struct rpng_process_t
{
bool initialized;
bool inflate_initialized;
bool adam7_pass_initialized;
bool pass_initialized;
uint32_t *data;
uint32_t *palette;
struct png_ihdr ihdr;
uint8_t *prev_scanline;
uint8_t *decoded_scanline;
uint8_t *inflate_buf;
size_t restore_buf_size;
size_t adam7_restore_buf_size;
size_t data_restore_buf_size;
size_t inflate_buf_size;
unsigned bpp;
unsigned pitch;
unsigned h;
struct
{
unsigned width;
unsigned height;
size_t size;
unsigned pos;
} pass;
void *stream;
zlib_file_handle_t handle;
};
struct rpng_t
{
struct rpng_process_t process;
bool has_ihdr;
bool has_idat;
bool has_iend;
bool has_plte;
struct idat_buffer idat_buf;
struct png_ihdr ihdr;
uint8_t *buff_data;
uint32_t palette[256];
};
/* Paeth prediction filter. */
static INLINE int paeth(int a, int b, int c)
{

View File

@ -266,10 +266,20 @@ bool rpng_is_valid(struct rpng_t *rpng)
return false;
}
void rpng_set_buf_ptr(struct rpng_t *rpng, uint8_t *data)
bool rpng_set_buf_ptr(struct rpng_t *rpng, uint8_t *data)
{
if (!rpng)
return false;
rpng->buff_data = data;
return true;
}
struct rpng_t *rpng_alloc(void)
{
struct rpng_t *rpng = (struct rpng_t*)calloc(1, sizeof(struct rpng_t));
if (!rpng)
return NULL;
return rpng;
}

View File

@ -65,7 +65,7 @@ static bool rpng_nbio_load_image_argb(const char *path, uint32_t **data,
goto end;
}
rpng = (struct rpng_t*)calloc(1, sizeof(struct rpng_t));
rpng = rpng_alloc();
if (!rpng)
{
@ -73,9 +73,7 @@ static bool rpng_nbio_load_image_argb(const char *path, uint32_t **data,
goto end;
}
rpng->buff_data = (uint8_t*)ptr;
if (!rpng->buff_data)
if (!rpng_set_buf_ptr(rpng, (uint8_t*)ptr))
{
ret = false;
goto end;
@ -95,7 +93,7 @@ static bool rpng_nbio_load_image_argb(const char *path, uint32_t **data,
fprintf(stderr, "has_iend: %d\n", rpng->has_iend);
#endif
if (!rpng->has_ihdr || !rpng->has_idat || !rpng->has_iend)
if (!rpng_is_valid(rpng))
{
ret = false;
goto end;

View File

@ -33,72 +33,7 @@
extern "C" {
#endif
struct idat_buffer
{
uint8_t *data;
size_t size;
};
struct png_chunk
{
uint32_t size;
char type[4];
uint8_t *data;
};
struct png_ihdr
{
uint32_t width;
uint32_t height;
uint8_t depth;
uint8_t color_type;
uint8_t compression;
uint8_t filter;
uint8_t interlace;
};
struct rpng_process_t
{
bool initialized;
bool inflate_initialized;
bool adam7_pass_initialized;
bool pass_initialized;
uint32_t *data;
uint32_t *palette;
struct png_ihdr ihdr;
uint8_t *prev_scanline;
uint8_t *decoded_scanline;
uint8_t *inflate_buf;
size_t restore_buf_size;
size_t adam7_restore_buf_size;
size_t data_restore_buf_size;
size_t inflate_buf_size;
unsigned bpp;
unsigned pitch;
unsigned h;
struct
{
unsigned width;
unsigned height;
size_t size;
unsigned pos;
} pass;
void *stream;
zlib_file_handle_t handle;
};
struct rpng_t
{
struct rpng_process_t process;
bool has_ihdr;
bool has_idat;
bool has_iend;
bool has_plte;
struct idat_buffer idat_buf;
struct png_ihdr ihdr;
uint8_t *buff_data;
uint32_t palette[256];
};
struct rpng_t;
bool rpng_load_image_argb(const char *path, uint32_t **data,
unsigned *width, unsigned *height);
@ -107,7 +42,9 @@ struct rpng_t *rpng_nbio_load_image_argb_init(const char *path);
bool rpng_is_valid(struct rpng_t *rpng);
void rpng_set_buf_ptr(struct rpng_t *rpng, uint8_t *data);
bool rpng_set_buf_ptr(struct rpng_t *rpng, uint8_t *data);
struct rpng_t *rpng_alloc(void);
void rpng_nbio_load_image_free(struct rpng_t *rpng);

View File

@ -458,7 +458,7 @@ static int cb_nbio_image_menu_wallpaper(void *data, size_t len)
if (!nbio || !data)
return -1;
nbio->image.handle = (struct rpng_t*)calloc(1, sizeof(struct rpng_t));
nbio->image.handle = rpng_alloc();
nbio->image.cb = &cb_image_menu_wallpaper;
return cb_nbio_generic(nbio, &len);
@ -471,7 +471,7 @@ static int cb_nbio_image_menu_boxart(void *data, size_t len)
if (!nbio || !data)
return -1;
nbio->image.handle = (struct rpng_t*)calloc(1, sizeof(struct rpng_t));
nbio->image.handle = rpng_alloc();
nbio->image.cb = &cb_image_menu_boxart;
return cb_nbio_generic(nbio, &len);