/* pngread.c - read a PNG file
*
* libpng 1.2.8 - December 3, 2004
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2004 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.)
*
* This file contains routines that an application calls directly to
* read a PNG file or stream.
*/
#define PNG_INTERNAL
#include "png.h"
/* Create a PNG structure for reading, and allocate any memory needed. */
{
#ifdef PNG_USER_MEM_SUPPORTED
}
/* Alternate create PNG structure for reading, and allocate any memory needed. */
{
#endif /* PNG_USER_MEM_SUPPORTED */
#ifdef PNG_SETJMP_SUPPORTED
#ifdef USE_FAR_KEYWORD
#endif
#endif
int i;
#ifdef PNG_USER_MEM_SUPPORTED
#else
#endif
return (NULL);
#if !defined(PNG_1_0_X)
#ifdef PNG_ASSEMBLER_CODE_SUPPORTED
#endif
#endif /* PNG_1_0_X */
/* added at libpng-1.2.6 */
#endif
#ifdef PNG_SETJMP_SUPPORTED
#ifdef USE_FAR_KEYWORD
#else
#endif
{
#ifdef PNG_USER_MEM_SUPPORTED
#else
#endif
return (NULL);
}
#ifdef USE_FAR_KEYWORD
#endif
#endif
#ifdef PNG_USER_MEM_SUPPORTED
#endif
i=0;
do
{
if(user_png_ver[i] != png_libpng_ver[i])
} while (png_libpng_ver[i++]);
{
/* Libpng 0.90 and later are binary incompatible with libpng 0.89, so
* we must recompile any applications that use any older library version.
* For versions after libpng 1.0, we will be compatible, so we need
* only check the first digit.
*/
{
#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
if (user_png_ver)
{
}
#endif
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
#endif
"Incompatible libpng version in application and library");
}
}
/* initialize zbuf - compression buffer */
{
case Z_OK: /* Do nothing */ break;
case Z_MEM_ERROR:
}
#ifdef PNG_SETJMP_SUPPORTED
/* Applications that neglect to set up their own setjmp() and then encounter
a png_error() will longjmp here. Since the jmpbuf is then meaningless we
abort instead of returning. */
#ifdef USE_FAR_KEYWORD
PNG_ABORT();
#else
PNG_ABORT();
#endif
#endif
return (png_ptr);
}
/* Initialize PNG structure for reading, and allocate any memory needed.
This interface is deprecated in favour of the png_create_read_struct(),
and it will eventually disappear. */
void PNGAPI
{
/* We only come here via pre-1.0.7-compiled applications */
}
#endif
void PNGAPI
{
/* We only come here via pre-1.0.12-compiled applications */
#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
{
if (user_png_ver)
{
}
}
#endif
{
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
#endif
"The png struct allocated by the application for reading is too small.");
}
{
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
#endif
"The info struct allocated by application for reading is too small.");
}
}
void PNGAPI
{
#ifdef PNG_SETJMP_SUPPORTED
#endif
int i=0;
do
{
if(user_png_ver[i] != png_libpng_ver[i])
{
#ifdef PNG_LEGACY_SUPPORTED
#else
"Application uses deprecated png_read_init() and should be recompiled.");
break;
#endif
}
} while (png_libpng_ver[i++]);
#ifdef PNG_SETJMP_SUPPORTED
/* save jump buffer and error functions */
#endif
{
}
/* reset all variables to 0 */
#ifdef PNG_SETJMP_SUPPORTED
/* restore jump buffer */
#endif
/* added at libpng-1.2.6 */
#endif
/* initialize zbuf - compression buffer */
{
case Z_OK: /* Do nothing */ break;
case Z_MEM_ERROR:
}
}
#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
/* Read the information before the actual image data. This has been
* changed in v0.90 to allow reading a file that already has the magic
* bytes read from the stream. You can tell libpng how many bytes have
* been read from the beginning of the stream (up to the maximum of 8)
* via png_set_sig_bytes(), and we will only check the remaining bytes
* here. The application can then have access to the signature bytes we
* read if it is determined that this isn't a valid PNG file.
*/
void PNGAPI
{
/* If we haven't checked all of the PNG signature bytes, do so now. */
{
{
if (num_checked < 4 &&
else
}
if (num_checked < 3)
}
for(;;)
{
#ifdef PNG_USE_LOCAL_ARRAYS
#if defined(PNG_READ_bKGD_SUPPORTED)
#endif
#if defined(PNG_READ_cHRM_SUPPORTED)
#endif
#if defined(PNG_READ_gAMA_SUPPORTED)
#endif
#if defined(PNG_READ_hIST_SUPPORTED)
#endif
#if defined(PNG_READ_iCCP_SUPPORTED)
#endif
#if defined(PNG_READ_iTXt_SUPPORTED)
#endif
#if defined(PNG_READ_oFFs_SUPPORTED)
#endif
#if defined(PNG_READ_pCAL_SUPPORTED)
#endif
#if defined(PNG_READ_pHYs_SUPPORTED)
#endif
#if defined(PNG_READ_sBIT_SUPPORTED)
#endif
#if defined(PNG_READ_sCAL_SUPPORTED)
#endif
#if defined(PNG_READ_sPLT_SUPPORTED)
#endif
#if defined(PNG_READ_sRGB_SUPPORTED)
#endif
#if defined(PNG_READ_tEXt_SUPPORTED)
#endif
#if defined(PNG_READ_tIME_SUPPORTED)
#endif
#if defined(PNG_READ_tRNS_SUPPORTED)
#endif
#if defined(PNG_READ_zTXt_SUPPORTED)
#endif
#endif /* PNG_USE_LOCAL_ARRAYS */
length);
/* This should be a binary subdivision search or a hash for
* matching the chunk name rather than a linear search.
*/
{
{
break;
}
}
#endif
{
break;
}
#if defined(PNG_READ_bKGD_SUPPORTED)
#endif
#if defined(PNG_READ_cHRM_SUPPORTED)
#endif
#if defined(PNG_READ_gAMA_SUPPORTED)
#endif
#if defined(PNG_READ_hIST_SUPPORTED)
#endif
#if defined(PNG_READ_oFFs_SUPPORTED)
#endif
#if defined(PNG_READ_pCAL_SUPPORTED)
#endif
#if defined(PNG_READ_sCAL_SUPPORTED)
#endif
#if defined(PNG_READ_pHYs_SUPPORTED)
#endif
#if defined(PNG_READ_sBIT_SUPPORTED)
#endif
#if defined(PNG_READ_sRGB_SUPPORTED)
#endif
#if defined(PNG_READ_iCCP_SUPPORTED)
#endif
#if defined(PNG_READ_sPLT_SUPPORTED)
#endif
#if defined(PNG_READ_tEXt_SUPPORTED)
#endif
#if defined(PNG_READ_tIME_SUPPORTED)
#endif
#if defined(PNG_READ_tRNS_SUPPORTED)
#endif
#if defined(PNG_READ_zTXt_SUPPORTED)
#endif
#if defined(PNG_READ_iTXt_SUPPORTED)
#endif
else
}
}
#endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
/* optional call to update the users info_ptr structure */
void PNGAPI
{
else
"Ignoring extra png_read_update_info() call; row buffer not reallocated");
}
#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
/* Initialize palette, background, etc, after transformations
* are set, but before any reading takes place. This allows
* the user to obtain a gamma-corrected palette, for example.
* If the user doesn't call this, we will do it ourselves.
*/
void PNGAPI
{
}
#endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
void PNGAPI
{
#ifdef PNG_USE_LOCAL_ARRAYS
#endif
int ret;
{
/* check for transforms that have been set but were defined out */
#if defined(PNG_WRITE_INVERT_SUPPORTED) && !defined(PNG_READ_INVERT_SUPPORTED)
#endif
#if defined(PNG_WRITE_FILLER_SUPPORTED) && !defined(PNG_READ_FILLER_SUPPORTED)
#endif
#if defined(PNG_WRITE_PACKSWAP_SUPPORTED) && !defined(PNG_READ_PACKSWAP_SUPPORTED)
#endif
#if defined(PNG_WRITE_PACK_SUPPORTED) && !defined(PNG_READ_PACK_SUPPORTED)
#endif
#if defined(PNG_WRITE_SHIFT_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED)
#endif
#if defined(PNG_WRITE_BGR_SUPPORTED) && !defined(PNG_READ_BGR_SUPPORTED)
#endif
#if defined(PNG_WRITE_SWAP_SUPPORTED) && !defined(PNG_READ_SWAP_SUPPORTED)
#endif
}
#if defined(PNG_READ_INTERLACING_SUPPORTED)
/* if interlaced and we do not need a new row, combine row and return */
{
{
case 0:
{
return;
}
break;
case 1:
{
return;
}
break;
case 2:
{
return;
}
break;
case 3:
{
return;
}
break;
case 4:
{
return;
}
break;
case 5:
{
return;
}
break;
case 6:
{
return;
}
break;
}
}
#endif
do
{
{
{
png_crc_finish(png_ptr, 0);
}
}
if (ret == Z_STREAM_END)
{
break;
}
"Decompression error");
#if defined(PNG_MNG_FEATURES_SUPPORTED)
{
/* Intrapixel differencing */
}
#endif
#if defined(PNG_READ_INTERLACING_SUPPORTED)
/* blow up interlaced rows to full size */
if (png_ptr->interlaced &&
{
/* 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);
*/
}
else
#endif
{
}
}
#endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
/* Read one or more rows of image data. If the image is interlaced,
* and png_set_interlace_handling() has been called, the rows need to
* contain the contents of the rows from the previous pass. If the
* image has alpha or transparency, and png_handle_alpha()[*] has been
* called, the rows contents must be initialized to the contents of the
* screen.
*
* "row" holds the actual image, and pixels are placed in it
* as they arrive. If the image is displayed after each pass, it will
* appear to "sparkle" in. "display_row" can be used to display a
* "chunky" progressive image, with finer detail added as it becomes
* available. If you do not want this "chunky" display, you may pass
* NULL for display_row. If you do not want the sparkle display, and
* you have not called png_handle_alpha(), you may pass NULL for rows.
* If you have called png_handle_alpha(), and the image has either an
* alpha channel or a transparency chunk, you must provide a buffer for
* rows. In this case, you do not have to provide a display_row buffer
* also, but you may. If the image is not interlaced, or if you have
* not called png_set_interlace_handling(), the display_row buffer will
* be ignored, so pass NULL to it.
*
* [*] png_handle_alpha() does not exist yet, as of libpng version 1.2.8
*/
void PNGAPI
{
png_uint_32 i;
dp = display_row;
for (i = 0; i < num_rows; i++)
{
}
for (i = 0; i < num_rows; i++)
{
rp++;
}
for (i = 0; i < num_rows; i++)
{
dp++;
}
}
#endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
/* Read the entire image. If the image has an alpha channel or a tRNS
* chunk, and you have called png_handle_alpha()[*], you will need to
* initialize the image to the current image that PNG will be overlaying.
* We set the num_rows again here, in case it was incorrectly set in
* png_read_start_row() by a call to png_read_update_info() or
* png_start_read_image() if png_set_interlace_handling() wasn't called
* prior to either of these functions like it should have been. You can
* only call this function once. If you desire to have an image for
* each pass of a interlaced image, use png_read_rows() instead.
*
* [*] png_handle_alpha() does not exist yet, as of libpng version 1.2.8
*/
void PNGAPI
{
int pass, j;
#else
if (png_ptr->interlaced)
"Cannot read interlaced image -- interlace handler disabled.");
pass = 1;
#endif
for (j = 0; j < pass; j++)
{
for (i = 0; i < image_height; i++)
{
rp++;
}
}
}
#endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
/* Read the end of the PNG file. Will not read past the end of the
* file, will verify the end is accurate, and will read any comments
* or time information at the end of the file, if info is not NULL.
*/
void PNGAPI
{
do
{
#ifdef PNG_USE_LOCAL_ARRAYS
#if defined(PNG_READ_bKGD_SUPPORTED)
#endif
#if defined(PNG_READ_cHRM_SUPPORTED)
#endif
#if defined(PNG_READ_gAMA_SUPPORTED)
#endif
#if defined(PNG_READ_hIST_SUPPORTED)
#endif
#if defined(PNG_READ_iCCP_SUPPORTED)
#endif
#if defined(PNG_READ_iTXt_SUPPORTED)
#endif
#if defined(PNG_READ_oFFs_SUPPORTED)
#endif
#if defined(PNG_READ_pCAL_SUPPORTED)
#endif
#if defined(PNG_READ_pHYs_SUPPORTED)
#endif
#if defined(PNG_READ_sBIT_SUPPORTED)
#endif
#if defined(PNG_READ_sCAL_SUPPORTED)
#endif
#if defined(PNG_READ_sPLT_SUPPORTED)
#endif
#if defined(PNG_READ_sRGB_SUPPORTED)
#endif
#if defined(PNG_READ_tEXt_SUPPORTED)
#endif
#if defined(PNG_READ_tIME_SUPPORTED)
#endif
#if defined(PNG_READ_tRNS_SUPPORTED)
#endif
#if defined(PNG_READ_zTXt_SUPPORTED)
#endif
#endif /* PNG_USE_LOCAL_ARRAYS */
{
{
}
else
}
#endif
{
/* Zero length IDATs are legal after the last IDAT has been
* read, but not after other chunks have been read.
*/
}
#if defined(PNG_READ_bKGD_SUPPORTED)
#endif
#if defined(PNG_READ_cHRM_SUPPORTED)
#endif
#if defined(PNG_READ_gAMA_SUPPORTED)
#endif
#if defined(PNG_READ_hIST_SUPPORTED)
#endif
#if defined(PNG_READ_oFFs_SUPPORTED)
#endif
#if defined(PNG_READ_pCAL_SUPPORTED)
#endif
#if defined(PNG_READ_sCAL_SUPPORTED)
#endif
#if defined(PNG_READ_pHYs_SUPPORTED)
#endif
#if defined(PNG_READ_sBIT_SUPPORTED)
#endif
#if defined(PNG_READ_sRGB_SUPPORTED)
#endif
#if defined(PNG_READ_iCCP_SUPPORTED)
#endif
#if defined(PNG_READ_sPLT_SUPPORTED)
#endif
#if defined(PNG_READ_tEXt_SUPPORTED)
#endif
#if defined(PNG_READ_tIME_SUPPORTED)
#endif
#if defined(PNG_READ_tRNS_SUPPORTED)
#endif
#if defined(PNG_READ_zTXt_SUPPORTED)
#endif
#if defined(PNG_READ_iTXt_SUPPORTED)
#endif
else
}
#endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
/* free all memory used by the read */
void PNGAPI
{
#ifdef PNG_USER_MEM_SUPPORTED
#endif
if (png_ptr_ptr != NULL)
png_ptr = *png_ptr_ptr;
if (info_ptr_ptr != NULL)
info_ptr = *info_ptr_ptr;
if (end_info_ptr_ptr != NULL)
#ifdef PNG_USER_MEM_SUPPORTED
#endif
{
#if defined(PNG_TEXT_SUPPORTED)
#endif
#ifdef PNG_USER_MEM_SUPPORTED
#else
#endif
*info_ptr_ptr = NULL;
}
if (end_info_ptr != NULL)
{
#if defined(PNG_READ_TEXT_SUPPORTED)
#endif
#ifdef PNG_USER_MEM_SUPPORTED
#else
#endif
*end_info_ptr_ptr = NULL;
}
{
#ifdef PNG_USER_MEM_SUPPORTED
#else
#endif
*png_ptr_ptr = NULL;
}
}
/* free all memory used by the read (old method) */
void /* PRIVATE */
{
#ifdef PNG_SETJMP_SUPPORTED
#endif
#ifdef PNG_USER_MEM_SUPPORTED
#endif
if (end_info_ptr != NULL)
#if defined(PNG_READ_DITHER_SUPPORTED)
#endif
#if defined(PNG_READ_GAMMA_SUPPORTED)
#endif
#if defined(PNG_READ_BACKGROUND_SUPPORTED)
#endif
#ifdef PNG_FREE_ME_SUPPORTED
#else
#endif
#if defined(PNG_tRNS_SUPPORTED) || \
defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
#ifdef PNG_FREE_ME_SUPPORTED
#else
#endif
#endif
#if defined(PNG_READ_hIST_SUPPORTED)
#ifdef PNG_FREE_ME_SUPPORTED
#else
#endif
#endif
#if defined(PNG_READ_GAMMA_SUPPORTED)
{
int i;
for (i = 0; i < istop; i++)
{
}
}
#if defined(PNG_READ_BACKGROUND_SUPPORTED)
{
int i;
for (i = 0; i < istop; i++)
{
}
}
{
int i;
for (i = 0; i < istop; i++)
{
}
}
#endif
#endif
#if defined(PNG_TIME_RFC1123_SUPPORTED)
#endif
#endif
#ifdef PNG_TEXT_SUPPORTED
#endif /* PNG_TEXT_SUPPORTED */
#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
/* Save the important info out of the png_struct, in case it is
* being used again.
*/
#ifdef PNG_SETJMP_SUPPORTED
#endif
#ifdef PNG_USER_MEM_SUPPORTED
#endif
#ifdef PNG_USER_MEM_SUPPORTED
#endif
#ifdef PNG_SETJMP_SUPPORTED
#endif
}
void PNGAPI
{
}
#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
#if defined(PNG_INFO_IMAGE_SUPPORTED)
void PNGAPI
int transforms,
{
int row;
#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
/* invert the alpha channel from opacity to transparency
*/
#endif
/* png_read_info() gives us all of the information from the
* PNG file before the first IDAT (image data chunk).
*/
/* -------------- image transformations start here ------------------- */
#if defined(PNG_READ_16_TO_8_SUPPORTED)
*/
if (transforms & PNG_TRANSFORM_STRIP_16)
#endif
#if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
/* Strip alpha bytes from the input data without combining with
* the background (not recommended).
*/
#endif
#if defined(PNG_READ_PACK_SUPPORTED) && !defined(PNG_READ_EXPAND_SUPPORTED)
/* Extract multiple pixels with bit depths of 1, 2, or 4 from a single
* byte into separate bytes (useful for paletted and grayscale images).
*/
if (transforms & PNG_TRANSFORM_PACKING)
#endif
#if defined(PNG_READ_PACKSWAP_SUPPORTED)
/* Change the order of packed pixels to least significant bit first
* (not useful if you are using png_set_packing).
*/
if (transforms & PNG_TRANSFORM_PACKSWAP)
#endif
#if defined(PNG_READ_EXPAND_SUPPORTED)
/* Expand paletted colors into true RGB triplets
* Expand paletted or RGB images with transparency to full alpha
* channels so the data will be available as RGBA quartets.
*/
if (transforms & PNG_TRANSFORM_EXPAND)
#endif
/* We don't handle background color or gamma transformation or dithering.
*/
#if defined(PNG_READ_INVERT_SUPPORTED)
/* invert monochrome files to have 0 as white and 1 as black
*/
#endif
#if defined(PNG_READ_SHIFT_SUPPORTED)
/* If you want to shift the pixel values from the range [0,255] or
* [0,65535] to the original [0,7] or [0,31], or whatever range the
* colors were originally in:
*/
if ((transforms & PNG_TRANSFORM_SHIFT)
{
}
#endif
#if defined(PNG_READ_BGR_SUPPORTED)
/* flip the RGB pixels to BGR (or RGBA to BGRA)
*/
if (transforms & PNG_TRANSFORM_BGR)
#endif
#if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
/* swap the RGBA or GA data to ARGB or AG (or BGRA to ABGR)
*/
#endif
#if defined(PNG_READ_SWAP_SUPPORTED)
/* swap bytes of 16 bit files to least significant byte first
*/
#endif
/* We don't handle adding filler bytes */
/* Optional call to gamma correct and add the background to the palette
* and update info structure. REQUIRED if you are expecting libpng to
* update the palette for you (i.e., you selected such a transform above).
*/
/* -------------- image transformations end here ------------------- */
#ifdef PNG_FREE_ME_SUPPORTED
#endif
{
#ifdef PNG_FREE_ME_SUPPORTED
#endif
{
}
}
/* read rest of file, and get additional chunks in info_ptr - REQUIRED */
/* quiet compiler warnings */ return;
}
#endif
#endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */