[master] Imported from libpng-1.4.0.tar

This commit is contained in:
Glenn Randers-Pehrson
2010-01-02 23:05:45 -06:00
parent 115817d118
commit 7e3a82cd9c
130 changed files with 4698 additions and 8343 deletions

View File

@@ -1,8 +1,8 @@
/* pngpread.c - read a png file in push mode
*
* Last changed in libpng 1.2.42 [January 3, 2010]
* Copyright (c) 1998-2009 Glenn Randers-Pehrson
* Last changed in libpng 1.4.0 [January 3, 2010]
* Copyright (c) 1998-2010 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*
@@ -11,10 +11,10 @@
* and license in png.h
*/
#define PNG_INTERNAL
#define PNG_NO_PEDANTIC_WARNINGS
#include "png.h"
#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
#include "pngpriv.h"
/* Push model modes */
#define PNG_READ_SIG_MODE 0
@@ -150,63 +150,61 @@ png_push_read_sig(png_structp png_ptr, png_infop info_ptr)
void /* PRIVATE */
png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
{
#ifdef PNG_USE_LOCAL_ARRAYS
PNG_CONST PNG_IHDR;
PNG_CONST PNG_IDAT;
PNG_CONST PNG_IEND;
PNG_CONST PNG_PLTE;
PNG_IHDR;
PNG_IDAT;
PNG_IEND;
PNG_PLTE;
#ifdef PNG_READ_bKGD_SUPPORTED
PNG_CONST PNG_bKGD;
PNG_bKGD;
#endif
#ifdef PNG_READ_cHRM_SUPPORTED
PNG_CONST PNG_cHRM;
PNG_cHRM;
#endif
#ifdef PNG_READ_gAMA_SUPPORTED
PNG_CONST PNG_gAMA;
PNG_gAMA;
#endif
#ifdef PNG_READ_hIST_SUPPORTED
PNG_CONST PNG_hIST;
PNG_hIST;
#endif
#ifdef PNG_READ_iCCP_SUPPORTED
PNG_CONST PNG_iCCP;
PNG_iCCP;
#endif
#ifdef PNG_READ_iTXt_SUPPORTED
PNG_CONST PNG_iTXt;
PNG_iTXt;
#endif
#ifdef PNG_READ_oFFs_SUPPORTED
PNG_CONST PNG_oFFs;
PNG_oFFs;
#endif
#ifdef PNG_READ_pCAL_SUPPORTED
PNG_CONST PNG_pCAL;
PNG_pCAL;
#endif
#ifdef PNG_READ_pHYs_SUPPORTED
PNG_CONST PNG_pHYs;
PNG_pHYs;
#endif
#ifdef PNG_READ_sBIT_SUPPORTED
PNG_CONST PNG_sBIT;
PNG_sBIT;
#endif
#ifdef PNG_READ_sCAL_SUPPORTED
PNG_CONST PNG_sCAL;
PNG_sCAL;
#endif
#ifdef PNG_READ_sRGB_SUPPORTED
PNG_CONST PNG_sRGB;
PNG_sRGB;
#endif
#ifdef PNG_READ_sPLT_SUPPORTED
PNG_CONST PNG_sPLT;
PNG_sPLT;
#endif
#ifdef PNG_READ_tEXt_SUPPORTED
PNG_CONST PNG_tEXt;
PNG_tEXt;
#endif
#ifdef PNG_READ_tIME_SUPPORTED
PNG_CONST PNG_tIME;
PNG_tIME;
#endif
#ifdef PNG_READ_tRNS_SUPPORTED
PNG_CONST PNG_tRNS;
PNG_tRNS;
#endif
#ifdef PNG_READ_zTXt_SUPPORTED
PNG_CONST PNG_zTXt;
PNG_zTXt;
#endif
#endif /* PNG_USE_LOCAL_ARRAYS */
/* First we make sure we have enough data for the 4 byte chunk name
* and the 4 byte chunk length before proceeding with decoding the
@@ -324,7 +322,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
return;
if (png_ptr->mode & PNG_AFTER_IDAT)
png_error(png_ptr, "Too many IDAT's found");
png_benign_error(png_ptr, "Too many IDATs found");
}
png_ptr->idat_size = png_ptr->push_length;
@@ -701,7 +699,7 @@ png_push_save_buffer(png_structp png_ptr)
new_max = png_ptr->save_buffer_size + png_ptr->current_buffer_size + 256;
old_buffer = png_ptr->save_buffer;
png_ptr->save_buffer = (png_bytep)png_malloc(png_ptr,
(png_uint_32)new_max);
(png_size_t)new_max);
png_memcpy(png_ptr->save_buffer, old_buffer, png_ptr->save_buffer_size);
png_free(png_ptr, old_buffer);
png_ptr->save_buffer_max = new_max;
@@ -730,9 +728,7 @@ png_push_restore_buffer(png_structp png_ptr, png_bytep buffer,
void /* PRIVATE */
png_push_read_IDAT(png_structp png_ptr)
{
#ifdef PNG_USE_LOCAL_ARRAYS
PNG_CONST PNG_IDAT;
#endif
PNG_IDAT;
if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
{
png_byte chunk_length[4];
@@ -829,7 +825,7 @@ png_process_IDAT_data(png_structp png_ptr, png_bytep buffer,
int ret;
if ((png_ptr->flags & PNG_FLAG_ZLIB_FINISHED) && buffer_length)
png_error(png_ptr, "Extra compression data");
png_benign_error(png_ptr, "Extra compression data");
png_ptr->zstream.next_in = buffer;
png_ptr->zstream.avail_in = (uInt)buffer_length;
@@ -841,7 +837,7 @@ png_process_IDAT_data(png_structp png_ptr, png_bytep buffer,
if (ret == Z_STREAM_END)
{
if (png_ptr->zstream.avail_in)
png_error(png_ptr, "Extra compressed data");
png_benign_error(png_ptr, "Extra compressed data");
if (!(png_ptr->zstream.avail_out))
{
@@ -898,8 +894,7 @@ png_push_process_row(png_structp png_ptr)
png_ptr->row_buf + 1, png_ptr->prev_row + 1,
(int)(png_ptr->row_buf[0]));
png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf,
png_ptr->rowbytes + 1);
png_memcpy(png_ptr->prev_row, png_ptr->row_buf, png_ptr->rowbytes + 1);
if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))
png_do_read_transformations(png_ptr);
@@ -930,7 +925,7 @@ png_push_process_row(png_structp png_ptr)
{
for (i = 0; i < 4 && png_ptr->pass == 2; i++)
{
png_push_have_row(png_ptr, png_bytep_NULL);
png_push_have_row(png_ptr, NULL);
png_read_push_finish_row(png_ptr);
}
}
@@ -939,14 +934,14 @@ png_push_process_row(png_structp png_ptr)
{
for (i = 0; i < 2 && png_ptr->pass == 4; i++)
{
png_push_have_row(png_ptr, png_bytep_NULL);
png_push_have_row(png_ptr, NULL);
png_read_push_finish_row(png_ptr);
}
}
if (png_ptr->pass == 6 && png_ptr->height <= 4)
{
png_push_have_row(png_ptr, png_bytep_NULL);
png_push_have_row(png_ptr, NULL);
png_read_push_finish_row(png_ptr);
}
@@ -966,7 +961,7 @@ png_push_process_row(png_structp png_ptr)
{
for (i = 0; i < 4 && png_ptr->pass == 2; i++)
{
png_push_have_row(png_ptr, png_bytep_NULL);
png_push_have_row(png_ptr, NULL);
png_read_push_finish_row(png_ptr);
}
}
@@ -986,7 +981,7 @@ png_push_process_row(png_structp png_ptr)
for (i = 0; i < 4 && png_ptr->pass == 2; i++)
{
png_push_have_row(png_ptr, png_bytep_NULL);
png_push_have_row(png_ptr, NULL);
png_read_push_finish_row(png_ptr);
}
@@ -994,7 +989,7 @@ png_push_process_row(png_structp png_ptr)
{
for (i = 0; i < 2 && png_ptr->pass == 4; i++)
{
png_push_have_row(png_ptr, png_bytep_NULL);
png_push_have_row(png_ptr, NULL);
png_read_push_finish_row(png_ptr);
}
}
@@ -1016,7 +1011,7 @@ png_push_process_row(png_structp png_ptr)
{
for (i = 0; i < 2 && png_ptr->pass == 4; i++)
{
png_push_have_row(png_ptr, png_bytep_NULL);
png_push_have_row(png_ptr, NULL);
png_read_push_finish_row(png_ptr);
}
}
@@ -1036,13 +1031,13 @@ png_push_process_row(png_structp png_ptr)
for (i = 0; i < 2 && png_ptr->pass == 4; i++)
{
png_push_have_row(png_ptr, png_bytep_NULL);
png_push_have_row(png_ptr, NULL);
png_read_push_finish_row(png_ptr);
}
if (png_ptr->pass == 6) /* Pass 5 might be empty */
{
png_push_have_row(png_ptr, png_bytep_NULL);
png_push_have_row(png_ptr, NULL);
png_read_push_finish_row(png_ptr);
}
@@ -1061,7 +1056,7 @@ png_push_process_row(png_structp png_ptr)
if (png_ptr->pass == 6) /* Skip top generated row */
{
png_push_have_row(png_ptr, png_bytep_NULL);
png_push_have_row(png_ptr, NULL);
png_read_push_finish_row(png_ptr);
}
@@ -1075,7 +1070,7 @@ png_push_process_row(png_structp png_ptr)
if (png_ptr->pass != 6)
break;
png_push_have_row(png_ptr, png_bytep_NULL);
png_push_have_row(png_ptr, NULL);
png_read_push_finish_row(png_ptr);
}
}
@@ -1091,7 +1086,6 @@ png_push_process_row(png_structp png_ptr)
void /* PRIVATE */
png_read_push_finish_row(png_structp png_ptr)
{
#ifdef PNG_USE_LOCAL_ARRAYS
/* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
/* Start of interlace block */
@@ -1110,7 +1104,6 @@ png_read_push_finish_row(png_structp png_ptr)
* it, uncomment it here and in png.h
PNG_CONST int FARDATA png_pass_height[] = {8, 8, 4, 4, 2, 2, 1};
*/
#endif
png_ptr->row_number++;
if (png_ptr->row_number < png_ptr->num_rows)
@@ -1120,7 +1113,7 @@ png_read_push_finish_row(png_structp png_ptr)
if (png_ptr->interlaced)
{
png_ptr->row_number = 0;
png_memset_check(png_ptr, png_ptr->prev_row, 0,
png_memset(png_ptr->prev_row, 0,
png_ptr->rowbytes + 1);
do
{
@@ -1180,7 +1173,7 @@ png_push_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
#endif
png_ptr->current_text = (png_charp)png_malloc(png_ptr,
(png_uint_32)(length + 1));
(png_size_t)(length + 1));
png_ptr->current_text[length] = '\0';
png_ptr->current_text_ptr = png_ptr->current_text;
png_ptr->current_text_size = (png_size_t)length;
@@ -1234,7 +1227,7 @@ png_push_read_tEXt(png_structp png_ptr, png_infop info_ptr)
text++;
text_ptr = (png_textp)png_malloc(png_ptr,
(png_uint_32)png_sizeof(png_text));
png_sizeof(png_text));
text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
text_ptr->key = key;
#ifdef PNG_iTXt_SUPPORTED
@@ -1250,7 +1243,7 @@ png_push_read_tEXt(png_structp png_ptr, png_infop info_ptr)
png_ptr->current_text = NULL;
if (ret)
png_warning(png_ptr, "Insufficient memory to store text chunk.");
png_warning(png_ptr, "Insufficient memory to store text chunk");
}
}
#endif
@@ -1280,7 +1273,7 @@ png_push_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
#endif
png_ptr->current_text = (png_charp)png_malloc(png_ptr,
(png_uint_32)(length + 1));
(png_size_t)(length + 1));
png_ptr->current_text[length] = '\0';
png_ptr->current_text_ptr = png_ptr->current_text;
png_ptr->current_text_size = (png_size_t)length;
@@ -1373,7 +1366,7 @@ png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
if (text == NULL)
{
text = (png_charp)png_malloc(png_ptr,
(png_uint_32)(png_ptr->zbuf_size
(png_ptr->zbuf_size
- png_ptr->zstream.avail_out + key_size + 1));
png_memcpy(text + key_size, png_ptr->zbuf,
@@ -1392,7 +1385,7 @@ png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
tmp = text;
text = (png_charp)png_malloc(png_ptr, text_size +
(png_uint_32)(png_ptr->zbuf_size
(png_ptr->zbuf_size
- png_ptr->zstream.avail_out + 1));
png_memcpy(text, tmp, text_size);
@@ -1436,7 +1429,7 @@ png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
text += key_size;
text_ptr = (png_textp)png_malloc(png_ptr,
(png_uint_32)png_sizeof(png_text));
png_sizeof(png_text));
text_ptr->compression = PNG_TEXT_COMPRESSION_zTXt;
text_ptr->key = key;
#ifdef PNG_iTXt_SUPPORTED
@@ -1451,7 +1444,7 @@ png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
png_free(png_ptr, text_ptr);
if (ret)
png_warning(png_ptr, "Insufficient memory to store text chunk.");
png_warning(png_ptr, "Insufficient memory to store text chunk");
}
}
#endif
@@ -1479,7 +1472,7 @@ png_push_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
#endif
png_ptr->current_text = (png_charp)png_malloc(png_ptr,
(png_uint_32)(length + 1));
(png_size_t)(length + 1));
png_ptr->current_text[length] = '\0';
png_ptr->current_text_ptr = png_ptr->current_text;
png_ptr->current_text_size = (png_size_t)length;
@@ -1556,7 +1549,7 @@ png_push_read_iTXt(png_structp png_ptr, png_infop info_ptr)
text++;
text_ptr = (png_textp)png_malloc(png_ptr,
(png_uint_32)png_sizeof(png_text));
png_sizeof(png_text));
text_ptr->compression = comp_flag + 2;
text_ptr->key = key;
@@ -1572,7 +1565,7 @@ png_push_read_iTXt(png_structp png_ptr, png_infop info_ptr)
png_free(png_ptr, text_ptr);
if (ret)
png_warning(png_ptr, "Insufficient memory to store iTXt chunk.");
png_warning(png_ptr, "Insufficient memory to store iTXt chunk");
}
}
#endif
@@ -1627,7 +1620,7 @@ png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32
else
{
png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr,
(png_uint_32)length);
(png_size_t)length);
png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
}
@@ -1692,10 +1685,8 @@ void PNGAPI
png_progressive_combine_row (png_structp png_ptr,
png_bytep old_row, png_bytep new_row)
{
#ifdef PNG_USE_LOCAL_ARRAYS
PNG_CONST int FARDATA png_pass_dsp_mask[7] =
{0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
#endif
if (png_ptr == NULL)
return;