(RPNG) Move more common code outside

This commit is contained in:
twinaphex 2015-09-01 13:27:36 +02:00
parent c80e59b888
commit 3ccb4380f1
3 changed files with 18 additions and 31 deletions

View File

@ -181,5 +181,15 @@ static INLINE bool png_read_plte(uint8_t *buf,
return true;
}
static INLINE bool png_realloc_idat(const struct png_chunk *chunk, struct idat_buffer *buf)
{
uint8_t *new_buffer = (uint8_t*)realloc(buf->data, buf->size + chunk->size);
if (!new_buffer)
return false;
buf->data = new_buffer;
return true;
}
#endif

View File

@ -96,24 +96,6 @@ static bool png_parse_ihdr_fio(FILE **fd,
return true;
}
static bool png_append_idat_fio(FILE **fd,
const struct png_chunk *chunk, struct idat_buffer *buf)
{
FILE *file = *fd;
uint8_t *new_buffer = (uint8_t*)realloc(buf->data, buf->size + chunk->size);
if (!new_buffer)
return false;
buf->data = new_buffer;
if (fread(buf->data + buf->size, 1, chunk->size, file) != chunk->size)
return false;
if (fseek(file, sizeof(uint32_t), SEEK_CUR) < 0)
return false;
buf->size += chunk->size;
return true;
}
bool rpng_load_image_argb_iterate(FILE **fd, struct rpng_t *rpng)
{
struct png_chunk chunk = {0};
@ -184,9 +166,16 @@ bool rpng_load_image_argb_iterate(FILE **fd, struct rpng_t *rpng)
if (!rpng->has_ihdr || rpng->has_iend || (rpng->ihdr.color_type == PNG_IHDR_COLOR_PLT && !rpng->has_plte))
return false;
if (!png_append_idat_fio(fd, &chunk, &rpng->idat_buf))
if (!png_realloc_idat(&chunk, &rpng->idat_buf))
return false;
if (fread(rpng->idat_buf.data + rpng->idat_buf.size, 1, chunk.size, file) != chunk.size)
return false;
if (fseek(file, sizeof(uint32_t), SEEK_CUR) < 0)
return false;
rpng->idat_buf.size += chunk.size;
rpng->has_idat = true;
break;

View File

@ -66,18 +66,6 @@ static bool png_parse_ihdr(uint8_t *buf,
return true;
}
static bool png_realloc_idat(const struct png_chunk *chunk, struct idat_buffer *buf)
{
uint8_t *new_buffer = (uint8_t*)realloc(buf->data, buf->size + chunk->size);
if (!new_buffer)
return false;
buf->data = new_buffer;
return true;
}
bool rpng_nbio_load_image_argb_iterate(struct rpng_t *rpng)
{
unsigned i;