fixed few things in pnglite

This commit is contained in:
oy 2012-08-11 11:51:01 +02:00
parent 6510dddbf4
commit 25da0f4c52
2 changed files with 39 additions and 6 deletions

View file

@ -150,6 +150,7 @@ static int png_get_bpp(png_t* png)
static int png_read_ihdr(png_t* png)
{
int result;
unsigned length;
#if DO_CRC_CHECKS
unsigned orig_crc;
@ -168,7 +169,9 @@ static int png_read_ihdr(png_t* png)
if(file_read(png, ihdr, 1, 13+4) != 13+4)
return PNG_EOF_ERROR;
#if DO_CRC_CHECKS
file_read_ul(png, &orig_crc);
result = file_read_ul(png, &orig_crc);
if(result != PNG_NO_ERROR)
return result;
calc_crc = crc32(0L, 0, 0);
calc_crc = crc32(calc_crc, ihdr, 13+4);
@ -176,7 +179,9 @@ static int png_read_ihdr(png_t* png)
if(orig_crc != calc_crc)
return PNG_CRC_ERROR;
#else
file_read_ul(png);
result = file_read_ul(png);
if(result != PNG_NO_ERROR)
return result;
#endif
png->width = get_ul(ihdr+4);
@ -275,6 +280,8 @@ int png_open_read(png_t* png, png_read_callback_t read_fun, void* user_pointer)
result = png_read_ihdr(png);
png->bpp = (unsigned char)png_get_bpp(png);
if(png->bpp < 0)
result = png->bpp;
return result;
}
@ -392,6 +399,7 @@ static int png_end_deflate(png_t* png)
deflateEnd(stream);
png_free(png->zs);
png->zs = 0;
return PNG_NO_ERROR;
}
@ -418,6 +426,7 @@ static int png_end_inflate(png_t* png)
}
png_free(png->zs);
png->zs = 0;
return PNG_NO_ERROR;
}
@ -527,6 +536,8 @@ static int png_read_idat(png_t* png, unsigned firstlen)
#endif
chunk = png_alloc(firstlen);
if(!chunk)
return PNG_MEMORY_ERROR;
result = png_init_inflate(png);
@ -571,7 +582,12 @@ static int png_read_idat(png_t* png, unsigned firstlen)
if(length > old_len)
{
png_free(chunk);
chunk = png_alloc(length);
chunk = png_alloc(length);
if(!chunk)
{
png_end_inflate(png);
return PNG_MEMORY_ERROR;
}
old_len = length;
}
@ -605,8 +621,13 @@ static int png_process_chunk(png_t* png)
if(type == *(unsigned int*)"IDAT") /* if we found an idat, all other idats should be followed with no other chunks in between */
{
png->png_datalen = png->width * png->height * png->bpp + png->height;
png->png_data = png_alloc(png->png_datalen);
if(!png->png_data)
{
png->png_datalen = png->width * png->height * png->bpp + png->height;
png->png_data = png_alloc(png->png_datalen);
}
else
return PNG_FILE_ERROR;
if(!png->png_data)
return PNG_MEMORY_ERROR;
@ -797,6 +818,8 @@ static int png_unfilter(png_t* png, unsigned char* data)
int png_get_data(png_t* png, unsigned char* data)
{
int result = PNG_NO_ERROR;
png->png_data = 0;
png->zs = 0;
while(result == PNG_NO_ERROR)
{
@ -805,13 +828,18 @@ int png_get_data(png_t* png, unsigned char* data)
if(result != PNG_DONE)
{
png_free(png->png_data);
if(!png->png_data)
{
png_free(png->png_data);
png->png_data = 0;
}
return result;
}
result = png_unfilter(png, data);
png_free(png->png_data);
png->png_data = 0;
return result;
}

View file

@ -24,6 +24,11 @@
daniel.karling@gmail.com
*/
/*
NOTICE:
This is a modified version which contains changes that address
compiler warnings and increase stability.
*/
#ifndef _PNGLITE_H_
#define _PNGLITE_H_