mirror of
https://git.code.sf.net/p/libpng/code.git
synced 2025-07-10 18:04:09 +02:00
Imported from libpng-1.2.37beta03.tar
This commit is contained in:
99
pngread.c
99
pngread.c
@@ -1,7 +1,7 @@
|
||||
|
||||
/* pngread.c - read a PNG file
|
||||
*
|
||||
* Last changed in libpng 1.2.35 [February 14, 2009]
|
||||
* Last changed in libpng 1.2.37 [May 20, 2009]
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1998-2009 Glenn Randers-Pehrson
|
||||
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
|
||||
@@ -57,7 +57,7 @@ png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
|
||||
if (png_ptr == NULL)
|
||||
return (NULL);
|
||||
|
||||
/* added at libpng-1.2.6 */
|
||||
/* Added at libpng-1.2.6 */
|
||||
#ifdef PNG_SET_USER_LIMITS_SUPPORTED
|
||||
png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
|
||||
png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
|
||||
@@ -137,7 +137,7 @@ png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
|
||||
}
|
||||
}
|
||||
|
||||
/* initialize zbuf - compression buffer */
|
||||
/* Initialize zbuf - compression buffer */
|
||||
png_ptr->zbuf_size = PNG_ZBUF_SIZE;
|
||||
png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
|
||||
(png_uint_32)png_ptr->zbuf_size);
|
||||
@@ -266,7 +266,7 @@ png_read_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
|
||||
png_debug(1, "in png_read_init_3");
|
||||
|
||||
#ifdef PNG_SETJMP_SUPPORTED
|
||||
/* save jump buffer and error functions */
|
||||
/* Save jump buffer and error functions */
|
||||
png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof(jmp_buf));
|
||||
#endif
|
||||
|
||||
@@ -277,21 +277,21 @@ png_read_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
|
||||
png_ptr = *ptr_ptr;
|
||||
}
|
||||
|
||||
/* reset all variables to 0 */
|
||||
/* Reset all variables to 0 */
|
||||
png_memset(png_ptr, 0, png_sizeof(png_struct));
|
||||
|
||||
#ifdef PNG_SETJMP_SUPPORTED
|
||||
/* restore jump buffer */
|
||||
/* Restore jump buffer */
|
||||
png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof(jmp_buf));
|
||||
#endif
|
||||
|
||||
/* added at libpng-1.2.6 */
|
||||
/* Added at libpng-1.2.6 */
|
||||
#ifdef PNG_SET_USER_LIMITS_SUPPORTED
|
||||
png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
|
||||
png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
|
||||
#endif
|
||||
|
||||
/* initialize zbuf - compression buffer */
|
||||
/* Initialize zbuf - compression buffer */
|
||||
png_ptr->zbuf_size = PNG_ZBUF_SIZE;
|
||||
png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
|
||||
(png_uint_32)png_ptr->zbuf_size);
|
||||
@@ -326,7 +326,8 @@ png_read_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
|
||||
void PNGAPI
|
||||
png_read_info(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
if (png_ptr == NULL || info_ptr == NULL) return;
|
||||
if (png_ptr == NULL || info_ptr == NULL)
|
||||
return;
|
||||
png_debug(1, "in png_read_info");
|
||||
/* If we haven't checked all of the PNG signature bytes, do so now. */
|
||||
if (png_ptr->sig_bytes < 8)
|
||||
@@ -529,12 +530,13 @@ png_read_info(png_structp png_ptr, png_infop info_ptr)
|
||||
}
|
||||
#endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
|
||||
|
||||
/* optional call to update the users info_ptr structure */
|
||||
/* Optional call to update the users info_ptr structure */
|
||||
void PNGAPI
|
||||
png_read_update_info(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
png_debug(1, "in png_read_update_info");
|
||||
if (png_ptr == NULL) return;
|
||||
if (png_ptr == NULL)
|
||||
return;
|
||||
if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
|
||||
png_read_start_row(png_ptr);
|
||||
else
|
||||
@@ -553,7 +555,8 @@ void PNGAPI
|
||||
png_start_read_image(png_structp png_ptr)
|
||||
{
|
||||
png_debug(1, "in png_start_read_image");
|
||||
if (png_ptr == NULL) return;
|
||||
if (png_ptr == NULL)
|
||||
return;
|
||||
if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
|
||||
png_read_start_row(png_ptr);
|
||||
}
|
||||
@@ -570,14 +573,15 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
|
||||
PNG_CONST int png_pass_mask[7] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
|
||||
#endif
|
||||
int ret;
|
||||
if (png_ptr == NULL) return;
|
||||
if (png_ptr == NULL)
|
||||
return;
|
||||
png_debug2(1, "in png_read_row (row %lu, pass %d)",
|
||||
png_ptr->row_number, png_ptr->pass);
|
||||
if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
|
||||
png_read_start_row(png_ptr);
|
||||
if (png_ptr->row_number == 0 && png_ptr->pass == 0)
|
||||
{
|
||||
/* check for transforms that have been set but were defined out */
|
||||
/* Check for transforms that have been set but were defined out */
|
||||
#if defined(PNG_WRITE_INVERT_SUPPORTED) && !defined(PNG_READ_INVERT_SUPPORTED)
|
||||
if (png_ptr->transformations & PNG_INVERT_MONO)
|
||||
png_warning(png_ptr, "PNG_READ_INVERT_SUPPORTED is not defined.");
|
||||
@@ -609,7 +613,7 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
|
||||
}
|
||||
|
||||
#if defined(PNG_READ_INTERLACING_SUPPORTED)
|
||||
/* if interlaced and we do not need a new row, combine row and return */
|
||||
/* If interlaced and we do not need a new row, combine row and return */
|
||||
if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
|
||||
{
|
||||
switch (png_ptr->pass)
|
||||
@@ -756,15 +760,15 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
|
||||
png_do_read_transformations(png_ptr);
|
||||
|
||||
#if defined(PNG_READ_INTERLACING_SUPPORTED)
|
||||
/* blow up interlaced rows to full size */
|
||||
/* Blow up interlaced rows to full size */
|
||||
if (png_ptr->interlaced &&
|
||||
(png_ptr->transformations & PNG_INTERLACE))
|
||||
{
|
||||
if (png_ptr->pass < 6)
|
||||
/* old interface (pre-1.0.9):
|
||||
png_do_read_interlace(&(png_ptr->row_info),
|
||||
png_ptr->row_buf + 1, png_ptr->pass, png_ptr->transformations);
|
||||
*/
|
||||
/* Old interface (pre-1.0.9):
|
||||
* png_do_read_interlace(&(png_ptr->row_info),
|
||||
* png_ptr->row_buf + 1, png_ptr->pass, png_ptr->transformations);
|
||||
*/
|
||||
png_do_read_interlace(png_ptr);
|
||||
|
||||
if (dsp_row != NULL)
|
||||
@@ -823,7 +827,8 @@ png_read_rows(png_structp png_ptr, png_bytepp row,
|
||||
png_bytepp dp;
|
||||
|
||||
png_debug(1, "in png_read_rows");
|
||||
if (png_ptr == NULL) return;
|
||||
if (png_ptr == NULL)
|
||||
return;
|
||||
rp = row;
|
||||
dp = display_row;
|
||||
if (rp != NULL && dp != NULL)
|
||||
@@ -872,7 +877,8 @@ png_read_image(png_structp png_ptr, png_bytepp image)
|
||||
png_bytepp rp;
|
||||
|
||||
png_debug(1, "in png_read_image");
|
||||
if (png_ptr == NULL) return;
|
||||
if (png_ptr == NULL)
|
||||
return;
|
||||
|
||||
#ifdef PNG_READ_INTERLACING_SUPPORTED
|
||||
pass = png_set_interlace_handling(png_ptr);
|
||||
@@ -908,7 +914,8 @@ void PNGAPI
|
||||
png_read_end(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
png_debug(1, "in png_read_end");
|
||||
if (png_ptr == NULL) return;
|
||||
if (png_ptr == NULL)
|
||||
return;
|
||||
png_crc_finish(png_ptr, 0); /* Finish off CRC from last IDAT chunk */
|
||||
|
||||
do
|
||||
@@ -1075,7 +1082,7 @@ png_read_end(png_structp png_ptr, png_infop info_ptr)
|
||||
}
|
||||
#endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
|
||||
|
||||
/* free all memory used by the read */
|
||||
/* Free all memory used by the read */
|
||||
void PNGAPI
|
||||
png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
|
||||
png_infopp end_info_ptr_ptr)
|
||||
@@ -1147,7 +1154,7 @@ png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
|
||||
}
|
||||
}
|
||||
|
||||
/* free all memory used by the read (old method) */
|
||||
/* Free all memory used by the read (old method) */
|
||||
void /* PRIVATE */
|
||||
png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr)
|
||||
{
|
||||
@@ -1296,7 +1303,8 @@ png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr
|
||||
void PNGAPI
|
||||
png_set_read_status_fn(png_structp png_ptr, png_read_status_ptr read_row_fn)
|
||||
{
|
||||
if (png_ptr == NULL) return;
|
||||
if (png_ptr == NULL)
|
||||
return;
|
||||
png_ptr->read_row_fn = read_row_fn;
|
||||
}
|
||||
|
||||
@@ -1310,9 +1318,10 @@ png_read_png(png_structp png_ptr, png_infop info_ptr,
|
||||
{
|
||||
int row;
|
||||
|
||||
if (png_ptr == NULL) return;
|
||||
if (png_ptr == NULL)
|
||||
return;
|
||||
#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
|
||||
/* invert the alpha channel from opacity to transparency
|
||||
/* Invert the alpha channel from opacity to transparency
|
||||
*/
|
||||
if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
|
||||
png_set_invert_alpha(png_ptr);
|
||||
@@ -1328,10 +1337,10 @@ png_read_png(png_structp png_ptr, png_infop info_ptr,
|
||||
/* -------------- image transformations start here ------------------- */
|
||||
|
||||
#if defined(PNG_READ_16_TO_8_SUPPORTED)
|
||||
/* tell libpng to strip 16 bit/color files down to 8 bits per color
|
||||
/* Tell libpng to strip 16 bit/color files down to 8 bits per color.
|
||||
*/
|
||||
if (transforms & PNG_TRANSFORM_STRIP_16)
|
||||
png_set_strip_16(png_ptr);
|
||||
png_set_strip_16(png_ptr);
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
|
||||
@@ -1339,7 +1348,7 @@ png_read_png(png_structp png_ptr, png_infop info_ptr,
|
||||
* the background (not recommended).
|
||||
*/
|
||||
if (transforms & PNG_TRANSFORM_STRIP_ALPHA)
|
||||
png_set_strip_alpha(png_ptr);
|
||||
png_set_strip_alpha(png_ptr);
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_PACK_SUPPORTED) && !defined(PNG_READ_EXPAND_SUPPORTED)
|
||||
@@ -1347,7 +1356,7 @@ png_read_png(png_structp png_ptr, png_infop info_ptr,
|
||||
* byte into separate bytes (useful for paletted and grayscale images).
|
||||
*/
|
||||
if (transforms & PNG_TRANSFORM_PACKING)
|
||||
png_set_packing(png_ptr);
|
||||
png_set_packing(png_ptr);
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_PACKSWAP_SUPPORTED)
|
||||
@@ -1355,7 +1364,7 @@ png_read_png(png_structp png_ptr, png_infop info_ptr,
|
||||
* (not useful if you are using png_set_packing).
|
||||
*/
|
||||
if (transforms & PNG_TRANSFORM_PACKSWAP)
|
||||
png_set_packswap(png_ptr);
|
||||
png_set_packswap(png_ptr);
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_EXPAND_SUPPORTED)
|
||||
@@ -1365,9 +1374,9 @@ png_read_png(png_structp png_ptr, png_infop info_ptr,
|
||||
* channels so the data will be available as RGBA quartets.
|
||||
*/
|
||||
if (transforms & PNG_TRANSFORM_EXPAND)
|
||||
if ((png_ptr->bit_depth < 8) ||
|
||||
(png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ||
|
||||
(png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)))
|
||||
if ((png_ptr->bit_depth < 8) ||
|
||||
(png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ||
|
||||
(png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)))
|
||||
png_set_expand(png_ptr);
|
||||
#endif
|
||||
|
||||
@@ -1375,10 +1384,10 @@ png_read_png(png_structp png_ptr, png_infop info_ptr,
|
||||
*/
|
||||
|
||||
#if defined(PNG_READ_INVERT_SUPPORTED)
|
||||
/* invert monochrome files to have 0 as white and 1 as black
|
||||
/* Invert monochrome files to have 0 as white and 1 as black
|
||||
*/
|
||||
if (transforms & PNG_TRANSFORM_INVERT_MONO)
|
||||
png_set_invert_mono(png_ptr);
|
||||
png_set_invert_mono(png_ptr);
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_SHIFT_SUPPORTED)
|
||||
@@ -1397,24 +1406,24 @@ png_read_png(png_structp png_ptr, png_infop info_ptr,
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_BGR_SUPPORTED)
|
||||
/* flip the RGB pixels to BGR (or RGBA to BGRA)
|
||||
/* Flip the RGB pixels to BGR (or RGBA to BGRA)
|
||||
*/
|
||||
if (transforms & PNG_TRANSFORM_BGR)
|
||||
png_set_bgr(png_ptr);
|
||||
png_set_bgr(png_ptr);
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
|
||||
/* swap the RGBA or GA data to ARGB or AG (or BGRA to ABGR)
|
||||
/* Swap the RGBA or GA data to ARGB or AG (or BGRA to ABGR)
|
||||
*/
|
||||
if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
|
||||
png_set_swap_alpha(png_ptr);
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_SWAP_SUPPORTED)
|
||||
/* swap bytes of 16 bit files to least significant byte first
|
||||
/* Swap bytes of 16 bit files to least significant byte first
|
||||
*/
|
||||
if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
|
||||
png_set_swap(png_ptr);
|
||||
png_set_swap(png_ptr);
|
||||
#endif
|
||||
|
||||
/* We don't handle adding filler bytes */
|
||||
@@ -1447,10 +1456,10 @@ png_read_png(png_structp png_ptr, png_infop info_ptr,
|
||||
png_read_image(png_ptr, info_ptr->row_pointers);
|
||||
info_ptr->valid |= PNG_INFO_IDAT;
|
||||
|
||||
/* read rest of file, and get additional chunks in info_ptr - REQUIRED */
|
||||
/* Read rest of file, and get additional chunks in info_ptr - REQUIRED */
|
||||
png_read_end(png_ptr, info_ptr);
|
||||
|
||||
transforms = transforms; /* quiet compiler warnings */
|
||||
transforms = transforms; /* Quiet compiler warnings */
|
||||
params = params;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user