mirror of
https://git.code.sf.net/p/libpng/code.git
synced 2025-07-10 18:04:09 +02:00
Imported from pngcrush-1.4.3.tar
This commit is contained in:
19
png.c
19
png.c
@@ -1,7 +1,7 @@
|
||||
|
||||
/* png.c - location for general purpose libpng functions
|
||||
*
|
||||
* libpng version 1.0.6f - April 14, 2000
|
||||
* libpng version 1.0.6h - April 24, 2000
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
|
||||
@@ -14,14 +14,14 @@
|
||||
#include "png.h"
|
||||
|
||||
/* Generate a compiler error if there is an old png.h in the search path. */
|
||||
typedef version_1_0_6f Your_png_h_is_not_version_1_0_6f;
|
||||
typedef version_1_0_6h Your_png_h_is_not_version_1_0_6h;
|
||||
|
||||
/* Version information for C files. This had better match the version
|
||||
* string defined in png.h. */
|
||||
|
||||
#ifdef PNG_USE_GLOBAL_ARRAYS
|
||||
/* png_libpng_ver was changed to a function in version 1.0.5c */
|
||||
char png_libpng_ver[12] = "1.0.6f";
|
||||
char png_libpng_ver[12] = "1.0.6h";
|
||||
|
||||
/* png_sig was changed to a function in version 1.0.5c */
|
||||
/* Place to hold the signature string for a PNG file. */
|
||||
@@ -561,7 +561,7 @@ png_charp
|
||||
png_get_copyright(png_structp png_ptr)
|
||||
{
|
||||
if (png_ptr != NULL || png_ptr == NULL) /* silence compiler warning */
|
||||
return ("\n libpng version 1.0.6f - April 14, 2000\n\
|
||||
return ("\n libpng version 1.0.6h - April 24, 2000\n\
|
||||
Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.\n\
|
||||
Copyright (c) 1996, 1997 Andreas Dilger\n\
|
||||
Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson\n");
|
||||
@@ -579,8 +579,8 @@ png_get_libpng_ver(png_structp png_ptr)
|
||||
{
|
||||
/* Version of *.c files used when building libpng */
|
||||
if(png_ptr != NULL) /* silence compiler warning about unused png_ptr */
|
||||
return("1.0.6f");
|
||||
return("1.0.6f");
|
||||
return("1.0.6h");
|
||||
return("1.0.6h");
|
||||
}
|
||||
|
||||
png_charp
|
||||
@@ -617,3 +617,10 @@ png_handle_as_unknown(png_structp png_ptr, png_bytep chunk_name)
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* This function, added to libpng-1.0.6g, is untested. */
|
||||
int
|
||||
png_reset_zstream(png_structp png_ptr)
|
||||
{
|
||||
return (inflateReset(&png_ptr->zstream));
|
||||
}
|
||||
|
||||
98
png.h
98
png.h
@@ -1,7 +1,7 @@
|
||||
|
||||
/* png.h - header file for PNG reference library
|
||||
*
|
||||
* libpng version 1.0.6f - April 14, 2000
|
||||
* libpng version 1.0.6h - April 24, 2000
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
|
||||
@@ -9,7 +9,7 @@
|
||||
* Authors and maintainers:
|
||||
* libpng versions 0.71, May 1995, through 0.88, January 1996: Guy Schalnat
|
||||
* libpng versions 0.89c, June 1996, through 0.96, May 1997: Andreas Dilger
|
||||
* libpng versions 0.97, January 1998, through 1.0.6f - April 14, 2000: Glenn
|
||||
* libpng versions 0.97, January 1998, through 1.0.6h - April 24, 2000: Glenn
|
||||
* See also "Contributing Authors", below.
|
||||
*
|
||||
* Note about libpng version numbers:
|
||||
@@ -44,20 +44,26 @@
|
||||
* 1.0.4a-f 1.0.4a-f 10005 2.1.0.4a-f
|
||||
* 1.0.5 (+ 2 patches) 1.0.5 10005 2.1.0.5
|
||||
* 1.0.5a-d 1.0.5a-d 10006 2.1.0.5a-d
|
||||
* 1.0.5e-r 1.0.5e-r 10100 2.1.0.5e-r (not compatible)
|
||||
* 1.0.5s-v 1.0.5s-v 10006 2.1.0.5s-v (compatible)
|
||||
* 1.0.6 (+ 3 patches) 1.0.6 10006 2.1.0.6
|
||||
* 1.0.6d-f 1.0.6d-f 10007 2.1.0.6d-f
|
||||
* 1.0.7 1.0.7 10007 2.1.0.7 (still compatible)
|
||||
* 1.0.5e-r 1.0.5e-r 10100 2.1.0.5e-r (not source compatible)
|
||||
* 1.0.5s-v 1.0.5s-v 10006 2.1.0.5s-v (not binary compatible)
|
||||
* 1.0.6 (+ 3 patches) 1.0.6 10006 2.1.0.6 (still binary incompat)
|
||||
* 1.0.6d-f 1.0.6d-f 10007 2.1.0.6d-f (still binary incompat)
|
||||
* 1.0.6g 1.0.6g 10007 2.1.0.6g (compatible with 1.0.5)
|
||||
* 1.0.6h 1.0.6h 10007 10.6h (compatible with 1.0.5)
|
||||
* 1.0.7 1.0.7 10007 10.7 (still compatible)
|
||||
*
|
||||
* Henceforth the source version will match the shared-library minor
|
||||
* and patch numbers; the shared-library major version number will be
|
||||
* Henceforth the source version will match the shared-library major
|
||||
* and minor numbers; the shared-library major version number will be
|
||||
* used for changes in backward compatibility, as it is intended. The
|
||||
* PNG_PNGLIB_VER macro, which is not used within libpng but is available
|
||||
* for applications, is an unsigned integer of the form xyyzz corresponding
|
||||
* to the source version x.y.z (leading zeros in y and z). Beta versions
|
||||
* are given the previous public release number plus a letter or two.
|
||||
*
|
||||
* Binary incompatibility exists only when applications make direct access
|
||||
* to the info_ptr or png_ptr members through png.h, and the compiled
|
||||
* application is loaded with a different version of the library.
|
||||
*
|
||||
* See libpng.txt or libpng.3 for more information. The PNG specification
|
||||
* is available as RFC 2083 <ftp://ftp.uu.net/graphics/png/documents/>
|
||||
* and as a W3C Recommendation <http://www.w3.org/TR/REC.png.html>
|
||||
@@ -73,7 +79,7 @@
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* (libpng versions 0.89c, June 1996, through 0.96, May 1997)
|
||||
* Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
|
||||
* (libpng versions 0.97, January 1998, through 1.0.6f, April 14, 2000)
|
||||
* (libpng versions 0.97, January 1998, through 1.0.6h, April 24, 2000)
|
||||
*
|
||||
* For the purposes of this copyright and license, "Contributing Authors"
|
||||
* is defined as the following set of individuals:
|
||||
@@ -148,13 +154,13 @@
|
||||
* Y2K compliance in libpng:
|
||||
* =========================
|
||||
*
|
||||
* April 14, 2000
|
||||
* April 24, 2000
|
||||
*
|
||||
* Since the PNG Development group is an ad-hoc body, we can't make
|
||||
* an official declaration.
|
||||
*
|
||||
* This is your unofficial assurance that libpng from version 0.71 and
|
||||
* upward through 1.0.6f are Y2K compliant. It is my belief that earlier
|
||||
* upward through 1.0.6h are Y2K compliant. It is my belief that earlier
|
||||
* versions were also Y2K compliant.
|
||||
*
|
||||
* Libpng only has three year fields. One is a 2-byte unsigned integer
|
||||
@@ -232,7 +238,7 @@ extern "C" {
|
||||
*/
|
||||
|
||||
/* Version information for png.h - this should match the version in png.c */
|
||||
#define PNG_LIBPNG_VER_STRING "1.0.6f"
|
||||
#define PNG_LIBPNG_VER_STRING "1.0.6h"
|
||||
|
||||
/* Careful here. At one time, Guy wanted to use 082, but that would be octal.
|
||||
* We must not include leading zeros.
|
||||
@@ -483,8 +489,6 @@ typedef struct png_info_struct
|
||||
* and initialize the appropriate fields below.
|
||||
*/
|
||||
|
||||
png_uint_32 free_me; /* flags items libpng is responsible for freeing */
|
||||
|
||||
#if defined(PNG_gAMA_SUPPORTED) || defined(PNG_READ_GAMMA_SUPPORTED)
|
||||
/* The gAMA chunk describes the gamma characteristics of the system
|
||||
* on which the image was created, normally in the range [1.0, 2.5].
|
||||
@@ -493,7 +497,6 @@ typedef struct png_info_struct
|
||||
#ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
float gamma; /* gamma value of image, if (valid & PNG_INFO_gAMA) */
|
||||
#endif
|
||||
png_fixed_point int_gamma; /* gamma value of image, if (valid & PNG_INFO_gAMA) */
|
||||
#endif
|
||||
|
||||
#if defined(PNG_sRGB_SUPPORTED)
|
||||
@@ -609,16 +612,6 @@ defined(PNG_READ_BACKGROUND_SUPPORTED)
|
||||
float x_blue;
|
||||
float y_blue;
|
||||
#endif
|
||||
#ifdef PNG_FIXED_POINT_SUPPORTED
|
||||
png_fixed_point int_x_white;
|
||||
png_fixed_point int_y_white;
|
||||
png_fixed_point int_x_red;
|
||||
png_fixed_point int_y_red;
|
||||
png_fixed_point int_x_green;
|
||||
png_fixed_point int_y_green;
|
||||
png_fixed_point int_x_blue;
|
||||
png_fixed_point int_y_blue;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(PNG_pCAL_SUPPORTED)
|
||||
@@ -687,6 +680,24 @@ defined(PNG_READ_BACKGROUND_SUPPORTED)
|
||||
/* Data valid if (valid & PNG_INFO_IDAT) non-zero */
|
||||
png_bytepp row_pointers; /* the image bits */
|
||||
#endif
|
||||
|
||||
#if defined(PNG_gAMA_SUPPORTED) || defined(PNG_READ_GAMMA_SUPPORTED)
|
||||
png_fixed_point int_gamma; /* gamma of image, if (valid & PNG_INFO_gAMA) */
|
||||
#endif
|
||||
|
||||
#if defined(PNG_cHRM_SUPPORTED) && defined(PNG_FIXED_POINT_SUPPORTED)
|
||||
png_fixed_point int_x_white;
|
||||
png_fixed_point int_y_white;
|
||||
png_fixed_point int_x_red;
|
||||
png_fixed_point int_y_red;
|
||||
png_fixed_point int_x_green;
|
||||
png_fixed_point int_y_green;
|
||||
png_fixed_point int_x_blue;
|
||||
png_fixed_point int_y_blue;
|
||||
#endif
|
||||
|
||||
png_uint_32 free_me; /* flags items libpng is responsible for freeing */
|
||||
|
||||
} png_info;
|
||||
|
||||
typedef png_info FAR * png_infop;
|
||||
@@ -881,14 +892,8 @@ struct png_struct_def
|
||||
png_byte user_transform_channels; /* channels in user transformed pixels */
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
|
||||
png_voidp user_chunk_ptr;
|
||||
png_user_chunk_ptr read_user_chunk_fn; /* user read chunk handler */
|
||||
#endif
|
||||
|
||||
png_uint_32 mode; /* tells us where we are in the PNG file */
|
||||
png_uint_32 flags; /* flags indicating various things to libpng */
|
||||
png_uint_32 free_me; /* flags items libpng is responsible for freeing */
|
||||
png_uint_32 transformations; /* which transformations to perform */
|
||||
|
||||
z_stream zstream; /* pointer to decompression structure (below) */
|
||||
@@ -962,7 +967,6 @@ struct png_struct_def
|
||||
float gamma; /* file gamma value */
|
||||
float screen_gamma; /* screen gamma value (display_exponent) */
|
||||
#endif
|
||||
png_fixed_point int_gamma;
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
|
||||
@@ -1070,12 +1074,23 @@ struct png_struct_def
|
||||
int num_chunk_list;
|
||||
png_bytep chunk_list;
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
|
||||
png_fixed_point int_gamma;
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
|
||||
png_voidp user_chunk_ptr;
|
||||
png_user_chunk_ptr read_user_chunk_fn; /* user read chunk handler */
|
||||
#endif
|
||||
|
||||
png_uint_32 free_me; /* flags items libpng is responsible for freeing */
|
||||
};
|
||||
|
||||
/* This prevents a compiler error in png_get_copyright() in png.c if png.c
|
||||
and png.h are both at * version 1.0.6f
|
||||
and png.h are both at * version 1.0.6h
|
||||
*/
|
||||
typedef png_structp version_1_0_6f;
|
||||
typedef png_structp version_1_0_6h;
|
||||
|
||||
typedef png_struct FAR * FAR * png_structpp;
|
||||
|
||||
@@ -1114,6 +1129,15 @@ extern PNG_EXPORT(png_structp,png_create_write_struct)
|
||||
PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
|
||||
png_error_ptr error_fn, png_error_ptr warn_fn));
|
||||
|
||||
extern PNG_EXPORT(png_uint_32,png_get_compression_buffer_size)
|
||||
PNGARG((png_structp png_ptr));
|
||||
|
||||
extern PNG_EXPORT(void,png_set_compression_buffer_size)
|
||||
PNGARG((png_structp png_ptr, png_uint_32 size));
|
||||
|
||||
/* Reset the compression stream */
|
||||
extern PNG_EXPORT(int,png_reset_zstream) PNGARG((png_structp png_ptr));
|
||||
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
extern PNG_EXPORT(png_structp,png_create_read_struct_2)
|
||||
PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
|
||||
@@ -2003,6 +2027,8 @@ extern PNG_EXPORT(void, png_set_keep_unknown_chunks) PNGARG((png_structp
|
||||
png_ptr, int keep, png_bytep chunk_list, int num_chunks));
|
||||
extern PNG_EXPORT(void, png_set_unknown_chunks) PNGARG((png_structp png_ptr,
|
||||
png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns));
|
||||
extern PNG_EXPORT(void, png_set_unknown_chunk_location)
|
||||
PNGARG((png_structp png_ptr, png_infop info_ptr, int chunk, int location));
|
||||
extern PNG_EXPORT(png_uint_32,png_get_unknown_chunks) PNGARG((png_structp
|
||||
png_ptr, png_infop info_ptr, png_unknown_chunkpp entries));
|
||||
#endif
|
||||
@@ -2058,7 +2084,7 @@ extern PNG_EXPORT(png_charp,png_get_header_version) PNGARG((png_structp png_ptr)
|
||||
extern PNG_EXPORT(png_charp,png_get_libpng_ver) PNGARG((png_structp png_ptr));
|
||||
|
||||
#define PNG_HEADER_VERSION_STRING \
|
||||
" libpng version 1.0.6f - April 14, 2000 (header)\n"
|
||||
" libpng version 1.0.6h - April 24, 2000 (header)\n"
|
||||
|
||||
#ifdef PNG_READ_COMPOSITE_NODIV_SUPPORTED
|
||||
/* With these routines we avoid an integer divide, which will be slower on
|
||||
|
||||
221
png_ptr.h
Normal file
221
png_ptr.h
Normal file
@@ -0,0 +1,221 @@
|
||||
struct png_struct_def
|
||||
{
|
||||
#ifdef PNG_SETJMP_SUPPORTED
|
||||
jmp_buf jmpbuf; /* used in png_error */
|
||||
#endif
|
||||
png_error_ptr error_fn; /* function for printing errors and aborting */
|
||||
png_error_ptr warning_fn; /* function for printing warnings */
|
||||
png_voidp error_ptr; /* user supplied struct for error functions */
|
||||
png_rw_ptr write_data_fn; /* function for writing output data */
|
||||
png_rw_ptr read_data_fn; /* function for reading input data */
|
||||
png_voidp io_ptr; /* ptr to application struct for I/O functions*/
|
||||
|
||||
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
|
||||
png_user_transform_ptr read_user_transform_fn; /* user read transform */
|
||||
#endif
|
||||
|
||||
#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
|
||||
png_user_transform_ptr write_user_transform_fn; /* user write transform */
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
|
||||
defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
|
||||
png_voidp user_transform_ptr; /* user supplied struct for user transform */
|
||||
png_byte user_transform_depth; /* bit depth of user transformed pixels */
|
||||
png_byte user_transform_channels; /* channels in user transformed pixels */
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
|
||||
png_voidp user_chunk_ptr;
|
||||
png_user_chunk_ptr read_user_chunk_fn; /* user read chunk handler */
|
||||
#endif
|
||||
|
||||
png_uint_32 mode; /* tells us where we are in the PNG file */
|
||||
png_uint_32 flags; /* flags indicating various things to libpng */
|
||||
png_uint_32 transformations; /* which transformations to perform */
|
||||
|
||||
z_stream zstream; /* pointer to decompression structure (below) */
|
||||
png_bytep zbuf; /* buffer for zlib */
|
||||
png_size_t zbuf_size; /* size of zbuf */
|
||||
int zlib_level; /* holds zlib compression level */
|
||||
int zlib_method; /* holds zlib compression method */
|
||||
int zlib_window_bits; /* holds zlib compression window bits */
|
||||
int zlib_mem_level; /* holds zlib compression memory level */
|
||||
int zlib_strategy; /* holds zlib compression strategy */
|
||||
|
||||
png_uint_32 width; /* width of image in pixels */
|
||||
png_uint_32 height; /* height of image in pixels */
|
||||
png_uint_32 num_rows; /* number of rows in current pass */
|
||||
png_uint_32 usr_width; /* width of row at start of write */
|
||||
png_uint_32 rowbytes; /* size of row in bytes */
|
||||
png_uint_32 irowbytes; /* size of current interlaced row in bytes */
|
||||
png_uint_32 iwidth; /* width of current interlaced row in pixels */
|
||||
png_uint_32 row_number; /* current row in interlace pass */
|
||||
png_bytep prev_row; /* buffer to save previous (unfiltered) row */
|
||||
png_bytep row_buf; /* buffer to save current (unfiltered) row */
|
||||
png_bytep sub_row; /* buffer to save "sub" row when filtering */
|
||||
png_bytep up_row; /* buffer to save "up" row when filtering */
|
||||
png_bytep avg_row; /* buffer to save "avg" row when filtering */
|
||||
png_bytep paeth_row; /* buffer to save "Paeth" row when filtering */
|
||||
png_row_info row_info; /* used for transformation routines */
|
||||
|
||||
png_uint_32 idat_size; /* current IDAT size for read */
|
||||
png_uint_32 crc; /* current chunk CRC value */
|
||||
png_colorp palette; /* palette from the input file */
|
||||
png_uint_16 num_palette; /* number of color entries in palette */
|
||||
png_uint_16 num_trans; /* number of transparency values */
|
||||
png_byte chunk_name[5]; /* null-terminated name of current chunk */
|
||||
png_byte compression; /* file compression type (always 0) */
|
||||
png_byte filter; /* file filter type (always 0) */
|
||||
png_byte interlaced; /* PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
|
||||
png_byte pass; /* current interlace pass (0 - 6) */
|
||||
png_byte do_filter; /* row filter flags (see PNG_FILTER_ below ) */
|
||||
png_byte color_type; /* color type of file */
|
||||
png_byte bit_depth; /* bit depth of file */
|
||||
png_byte usr_bit_depth; /* bit depth of users row */
|
||||
png_byte pixel_depth; /* number of bits per pixel */
|
||||
png_byte channels; /* number of channels in file */
|
||||
png_byte usr_channels; /* channels at start of write */
|
||||
png_byte sig_bytes; /* magic bytes read/written from start of file */
|
||||
|
||||
#if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
|
||||
png_uint_16 filler; /* filler bytes for pixel expansion */
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_bKGD_SUPPORTED)
|
||||
png_byte background_gamma_type;
|
||||
#ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
float background_gamma;
|
||||
#endif
|
||||
png_color_16 background; /* background color in screen gamma space */
|
||||
# if defined(PNG_READ_GAMMA_SUPPORTED)
|
||||
png_color_16 background_1; /* background normalized to gamma 1.0 */
|
||||
# endif /* PNG_READ_GAMMA && PNG_READ_bKGD_SUPPORTED */
|
||||
#endif /* PNG_READ_bKGD_SUPPORTED */
|
||||
|
||||
#if defined(PNG_WRITE_FLUSH_SUPPORTED)
|
||||
png_flush_ptr output_flush_fn;/* Function for flushing output */
|
||||
png_uint_32 flush_dist; /* how many rows apart to flush, 0 - no flush */
|
||||
png_uint_32 flush_rows; /* number of rows written since last flush */
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
|
||||
int gamma_shift; /* number of "insignificant" bits 16-bit gamma */
|
||||
#ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
float gamma; /* file gamma value */
|
||||
float screen_gamma; /* screen gamma value (display_exponent) */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
|
||||
png_bytep gamma_table; /* gamma table for 8-bit depth files */
|
||||
png_bytep gamma_from_1; /* converts from 1.0 to screen */
|
||||
png_bytep gamma_to_1; /* converts from file to 1.0 */
|
||||
png_uint_16pp gamma_16_table; /* gamma table for 16-bit depth files */
|
||||
png_uint_16pp gamma_16_from_1; /* converts from 1.0 to screen */
|
||||
png_uint_16pp gamma_16_to_1; /* converts from file to 1.0 */
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_GAMMA_SUPPORTED) || defined (PNG_READ_sBIT_SUPPORTED)
|
||||
png_color_8 sig_bit; /* significant bits in each available channel */
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
|
||||
png_color_8 shift; /* shift for significant bit tranformation */
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_tRNS_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) \
|
||||
|| defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
|
||||
png_bytep trans; /* transparency values for paletted files */
|
||||
png_color_16 trans_values; /* transparency values for non-paletted files */
|
||||
#endif
|
||||
|
||||
png_read_status_ptr read_row_fn; /* called after each row is decoded */
|
||||
png_write_status_ptr write_row_fn; /* called after each row is encoded */
|
||||
#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
|
||||
png_progressive_info_ptr info_fn; /* called after header data fully read */
|
||||
png_progressive_row_ptr row_fn; /* called after each prog. row is decoded */
|
||||
png_progressive_end_ptr end_fn; /* called after image is complete */
|
||||
png_bytep save_buffer_ptr; /* current location in save_buffer */
|
||||
png_bytep save_buffer; /* buffer for previously read data */
|
||||
png_bytep current_buffer_ptr; /* current location in current_buffer */
|
||||
png_bytep current_buffer; /* buffer for recently used data */
|
||||
png_uint_32 push_length; /* size of current input chunk */
|
||||
png_uint_32 skip_length; /* bytes to skip in input data */
|
||||
png_size_t save_buffer_size; /* amount of data now in save_buffer */
|
||||
png_size_t save_buffer_max; /* total size of save_buffer */
|
||||
png_size_t buffer_size; /* total amount of available input data */
|
||||
png_size_t current_buffer_size; /* amount of data now in current_buffer */
|
||||
int process_mode; /* what push library is currently doing */
|
||||
int cur_palette; /* current push library palette index */
|
||||
|
||||
# if defined(PNG_READ_TEXT_SUPPORTED)
|
||||
png_size_t current_text_size; /* current size of text input data */
|
||||
png_size_t current_text_left; /* how much text left to read in input */
|
||||
png_charp current_text; /* current text chunk buffer */
|
||||
png_charp current_text_ptr; /* current location in current_text */
|
||||
# endif /* PNG_PROGRESSIVE_READ_SUPPORTED && PNG_READ_TEXT_SUPPORTED */
|
||||
|
||||
#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
|
||||
|
||||
#if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
|
||||
/* for the Borland special 64K segment handler */
|
||||
png_bytepp offset_table_ptr;
|
||||
png_bytep offset_table;
|
||||
png_uint_16 offset_table_number;
|
||||
png_uint_16 offset_table_count;
|
||||
png_uint_16 offset_table_count_free;
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_DITHER_SUPPORTED)
|
||||
png_bytep palette_lookup; /* lookup table for dithering */
|
||||
png_bytep dither_index; /* index translation for palette files */
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_DITHER_SUPPORTED) || defined(PNG_READ_hIST_SUPPORTED)
|
||||
png_uint_16p hist; /* histogram */
|
||||
#endif
|
||||
|
||||
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
|
||||
png_byte heuristic_method; /* heuristic for row filter selection */
|
||||
png_byte num_prev_filters; /* number of weights for previous rows */
|
||||
png_bytep prev_filters; /* filter type(s) of previous row(s) */
|
||||
png_uint_16p filter_weights; /* weight(s) for previous line(s) */
|
||||
png_uint_16p inv_filter_weights; /* 1/weight(s) for previous line(s) */
|
||||
png_uint_16p filter_costs; /* relative filter calculation cost */
|
||||
png_uint_16p inv_filter_costs; /* 1/relative filter calculation cost */
|
||||
#endif
|
||||
|
||||
#if defined(PNG_TIME_RFC1123_SUPPORTED)
|
||||
png_charp time_buffer; /* String to hold RFC 1123 time text */
|
||||
#endif
|
||||
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
png_voidp mem_ptr; /* user supplied struct for mem functions */
|
||||
png_malloc_ptr malloc_fn; /* function for allocating memory */
|
||||
png_free_ptr free_fn; /* function for freeing memory */
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
|
||||
png_byte rgb_to_gray_status;
|
||||
png_uint_16 rgb_to_gray_red_coeff;
|
||||
png_uint_16 rgb_to_gray_green_coeff;
|
||||
png_uint_16 rgb_to_gray_blue_coeff;
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
|
||||
defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
|
||||
png_byte empty_plte_permitted;
|
||||
#endif
|
||||
|
||||
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
|
||||
int num_chunk_list;
|
||||
png_bytep chunk_list;
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
|
||||
png_fixed_point int_gamma;
|
||||
#endif
|
||||
|
||||
png_uint_32 free_me; /* flags items libpng is responsible for freeing */
|
||||
};
|
||||
@@ -1,6 +1,6 @@
|
||||
/* pngasmrd.h - assembler version of utilities to read a PNG file
|
||||
*
|
||||
* libpng 1.0.6f - April 14, 2000
|
||||
* libpng 1.0.6h - April 24, 2000
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1999, 2000 Glenn Randers-Pehrson
|
||||
*
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
/* pngconf.h - machine configurable file for libpng
|
||||
*
|
||||
* libpng 1.0.6f - April 14, 2000
|
||||
* libpng 1.0.6h - April 24, 2000
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
@@ -17,8 +17,6 @@
|
||||
#ifndef PNGCONF_H
|
||||
#define PNGCONF_H
|
||||
|
||||
#include "pngcrush.h" /* except for this line, this is libpng's pngconf.h */
|
||||
|
||||
/* This is the size of the compression buffer, and thus the size of
|
||||
* an IDAT chunk. Make this whatever size you feel is best for your
|
||||
* machine. One of these will be allocated per png_struct. When this
|
||||
|
||||
244
pngcrush.c
244
pngcrush.c
@@ -15,7 +15,7 @@
|
||||
* occasionally creating Linux executables.
|
||||
*/
|
||||
|
||||
#define PNGCRUSH_VERSION "1.4.2"
|
||||
#define PNGCRUSH_VERSION "1.4.3"
|
||||
|
||||
/*
|
||||
* COPYRIGHT NOTICE, DISCLAIMER, AND LICENSE:
|
||||
@@ -46,6 +46,18 @@
|
||||
*/
|
||||
|
||||
/* Change log:
|
||||
*
|
||||
* Version 1.4.3 (built with libpng-1.0.6h and cexcept-0.6.3)
|
||||
*
|
||||
* Reduced scope of Try/Catch blocks to avoid nesting them, and
|
||||
* removed returns from within the Try blocks, where they are not
|
||||
* allowed.
|
||||
*
|
||||
* Removed direct access to the png structure when possible, and isolated
|
||||
* the remaining direct accesses to the png structure into new
|
||||
* png_get_compression_buffer_size(), png_set_compression_buffer_size(),
|
||||
* and png_set_unknown_chunk_location() functions that were installed
|
||||
* in libpng version 1.0.6g.
|
||||
*
|
||||
* Version 1.4.2 (built with libpng-1.0.6f and cexcept-0.6.0)
|
||||
*
|
||||
@@ -278,6 +290,7 @@ static PNG_CONST char *outname = "pngout.png";
|
||||
static PNG_CONST char *directory_name = "pngcrush.bak";
|
||||
static PNG_CONST char *extension = "_C.png";
|
||||
|
||||
static png_uint_32 measured_idat_length;
|
||||
static int all_chunks_are_safe=0;
|
||||
static int number_of_open_files;
|
||||
static int do_pplt = 0;
|
||||
@@ -309,8 +322,8 @@ char *str_return;
|
||||
#include "cexcept.h"
|
||||
define_exception_type(const char *);
|
||||
extern struct exception_context the_exception_context[1];
|
||||
|
||||
struct exception_context the_exception_context[1];
|
||||
png_const_charp msg;
|
||||
|
||||
static png_uint_32 total_input_length = 0;
|
||||
static png_uint_32 total_output_length = 0;
|
||||
@@ -385,7 +398,7 @@ static png_infop end_info_ptr;
|
||||
static png_infop write_end_info_ptr;
|
||||
static FILE *fpin, *fpout;
|
||||
png_uint_32 measure_idats(FILE *fpin);
|
||||
png_uint_32 png_measure_idat(png_structp png_ptr, png_infop info_ptr);
|
||||
png_uint_32 png_measure_idat(png_structp png_ptr);
|
||||
# define MAX_METHODS 200
|
||||
# define MAX_METHODSP1 201
|
||||
# define DEFAULT_METHODS 10
|
||||
@@ -394,9 +407,54 @@ static int filter_method, zlib_level;
|
||||
static png_bytep png_row_filters=NULL;
|
||||
static float t_start, t_stop, t_decode, t_encode, t_misc;
|
||||
|
||||
static int max_idat_size = PNG_ZBUF_SIZE;
|
||||
static png_uint_32 max_idat_size = PNG_ZBUF_SIZE;
|
||||
int ia;
|
||||
|
||||
/********* Functions to make direct access to the png_ptr. ***************
|
||||
*
|
||||
* Making direct access to the png_ptr or info_ptr is frowned upon because
|
||||
* it incurs a risk of binary incompatibility with otherwise compatible
|
||||
* versions of libpng, so all such accesses are collected here. These
|
||||
* functions could be candidates for inclusion in some future version of
|
||||
* libpng.
|
||||
*/
|
||||
|
||||
#if (PNG_LIBPNG_VER < 10007)
|
||||
/* This is binary incompatible with versions earlier than 0.99h because of the
|
||||
* introduction of png_user_transform stuff ahead of the zbuf_size member
|
||||
* of png_ptr in libpng version 0.99h. Not needed after libpng-1.0.6g
|
||||
* because the functions became available in libpng.
|
||||
*/
|
||||
static png_uint_32
|
||||
png_get_compression_buffer_size(png_structp png_ptr)
|
||||
{
|
||||
return(png_ptr->zbuf_size);
|
||||
}
|
||||
static void
|
||||
png_set_compression_buffer_size(png_structp png_ptr, png_uint_32 size)
|
||||
{
|
||||
if(png_ptr->zbuf)
|
||||
png_free(png_ptr, png_ptr->zbuf);
|
||||
{
|
||||
png_ptr->zbuf_size = (png_size_t)size;
|
||||
png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, size);
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
|
||||
static void
|
||||
png_set_unknown_chunk_location(png_structp png_ptr, png_infop info_ptr,
|
||||
int chunk, int location)
|
||||
{
|
||||
if(png_ptr != NULL && info_ptr != NULL && chunk >= 0 && chunk <
|
||||
info_ptr->unknown_chunks_num)
|
||||
info_ptr->unknown_chunks[chunk].location = (png_byte)location;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/************* end of direct access functions *****************************/
|
||||
|
||||
/* cexcept interface */
|
||||
|
||||
static void
|
||||
@@ -404,19 +462,20 @@ png_cexcept_error(png_structp png_ptr, png_const_charp msg)
|
||||
{
|
||||
if(png_ptr)
|
||||
;
|
||||
#if (PNG_LIBPNG_VER > 10006)
|
||||
#if (PNG_LIBPNG_VER > 10006 && defined(PNGCRUSH_H))
|
||||
if (!strcmp(msg, "Too many IDAT's found"))
|
||||
{
|
||||
#ifndef PNG_NO_CONSOLE_IO
|
||||
fprintf(stderr, "Correcting ");
|
||||
fprintf(stderr, "\nIn %s, correcting ",inname);
|
||||
#else
|
||||
png_warning(png_ptr, msg);
|
||||
#endif
|
||||
/* png_ptr->mode |= PNG_AFTER_IDAT; */
|
||||
}
|
||||
else
|
||||
#endif
|
||||
Throw msg;
|
||||
{
|
||||
Throw msg;
|
||||
}
|
||||
}
|
||||
|
||||
/* START of code to validate memory allocation and deallocation */
|
||||
@@ -531,21 +590,6 @@ void png_crush_pause(void)
|
||||
/* stifle compiler warning */ return;
|
||||
}
|
||||
}
|
||||
#define PNG_CRUSH_CLEANUP \
|
||||
fprintf(STDERR, "%s -> %s: libpng read error\n", inname, outname); \
|
||||
if(row_buf != NULL)png_free(read_ptr, row_buf); \
|
||||
row_buf = (png_bytep)NULL; \
|
||||
png_destroy_info_struct(write_ptr, &write_end_info_ptr); \
|
||||
png_destroy_write_struct(&write_ptr, &write_info_ptr); \
|
||||
if(nosave == 0) \
|
||||
{ \
|
||||
FCLOSE(fpout); \
|
||||
} \
|
||||
png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr); \
|
||||
FCLOSE(fpin); \
|
||||
if(verbose > 1) \
|
||||
fprintf(STDERR, "returning after longjump\n");
|
||||
|
||||
int keep_chunk(png_const_charp name, char *argv[]);
|
||||
|
||||
int keep_chunk(png_const_charp name, char *argv[])
|
||||
@@ -926,7 +970,7 @@ main(int argc, char *argv[])
|
||||
{
|
||||
names++;
|
||||
BUMP_I;
|
||||
max_idat_size = atoi(argv[i]);
|
||||
max_idat_size = (png_uint_32)atoi(argv[i]);
|
||||
if (max_idat_size > PNG_ZBUF_SIZE) max_idat_size=PNG_ZBUF_SIZE;
|
||||
}
|
||||
else if(!strncmp(argv[i],"-m",2))
|
||||
@@ -1604,12 +1648,9 @@ main(int argc, char *argv[])
|
||||
for (ia=0; ia<255; ia++)
|
||||
trns_array[ia]=255;
|
||||
|
||||
for(;;) /* loop on input files */
|
||||
for(;;) /* loop on input files */
|
||||
|
||||
{
|
||||
png_const_charp msg;
|
||||
Try
|
||||
{
|
||||
{
|
||||
first_trial = 1;
|
||||
|
||||
if(png_row_filters != NULL)
|
||||
@@ -1714,6 +1755,11 @@ main(int argc, char *argv[])
|
||||
else
|
||||
idat_length[0]=1;
|
||||
|
||||
if (input_color_type == 4 || input_color_type == 6)
|
||||
/* check for unused alpha channel */
|
||||
{
|
||||
}
|
||||
|
||||
if(!methods_specified || try_method[0] == 0)
|
||||
{
|
||||
for (i=1; i<=DEFAULT_METHODS; i++) try_method[i]=0;
|
||||
@@ -1865,6 +1911,8 @@ main(int argc, char *argv[])
|
||||
P2("files are opened.\n");
|
||||
png_crush_pause();
|
||||
|
||||
Try
|
||||
{
|
||||
png_debug(0, "Allocating read and write structures\n");
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
read_ptr = png_create_read_struct_2(PNG_LIBPNG_VER_STRING, (png_voidp)NULL,
|
||||
@@ -1921,31 +1969,26 @@ main(int argc, char *argv[])
|
||||
/* We don't need to check CRC's because they were already checked
|
||||
in the png_measure_idat function */
|
||||
|
||||
read_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_NOWARN |
|
||||
PNG_FLAG_CRC_ANCILLARY_USE |
|
||||
PNG_FLAG_CRC_CRITICAL_IGNORE;
|
||||
png_set_crc_action(read_ptr, PNG_CRC_QUIET_USE, PNG_CRC_QUIET_USE);
|
||||
|
||||
#if (PNG_LIBPNG_VER >= 10000)
|
||||
/* reinitialize zbuf - compression buffer */
|
||||
|
||||
if(read_ptr->zbuf_size < (png_size_t)max_idat_size)
|
||||
if(png_get_compression_buffer_size(read_ptr) < max_idat_size)
|
||||
{
|
||||
P2("reinitializing read zbuf.\n");
|
||||
png_free(read_ptr, read_ptr->zbuf);
|
||||
read_ptr->zbuf_size = (png_size_t)max_idat_size;
|
||||
read_ptr->zbuf =
|
||||
(png_bytep)png_malloc(read_ptr, (png_uint_32)read_ptr->zbuf_size);
|
||||
P2("reinitializing read zbuf.\n");
|
||||
png_set_compression_buffer_size(read_ptr, max_idat_size);
|
||||
}
|
||||
if(nosave == 0)
|
||||
{
|
||||
if(write_ptr->zbuf_size > (png_size_t)max_idat_size)
|
||||
if(png_get_compression_buffer_size(write_ptr) < max_idat_size)
|
||||
{
|
||||
P2("reinitializing write zbuf.\n");
|
||||
png_free(write_ptr, write_ptr->zbuf);
|
||||
write_ptr->zbuf_size = (png_size_t)max_idat_size;
|
||||
write_ptr->zbuf = (png_bytep)png_malloc(write_ptr,
|
||||
(png_uint_32)write_ptr->zbuf_size);
|
||||
png_set_compression_buffer_size(write_ptr, max_idat_size);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
|
||||
png_set_keep_unknown_chunks(read_ptr, HANDLE_CHUNK_ALWAYS,
|
||||
(png_bytep)NULL, 0);
|
||||
@@ -2172,8 +2215,7 @@ main(int argc, char *argv[])
|
||||
int required_window;
|
||||
int channels=0;
|
||||
|
||||
write_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_STRATEGY;
|
||||
write_ptr->zlib_strategy = z_strategy;
|
||||
png_set_compression_strategy(write_ptr, z_strategy);
|
||||
|
||||
if (output_color_type == 0)channels=1;
|
||||
if (output_color_type == 2)channels=3;
|
||||
@@ -2813,12 +2855,12 @@ main(int argc, char *argv[])
|
||||
&unknowns);
|
||||
if (num_unknowns)
|
||||
{
|
||||
png_size_t i;
|
||||
int i;
|
||||
png_set_unknown_chunks(write_ptr, write_info_ptr, unknowns,
|
||||
num_unknowns);
|
||||
for (i = 0; i < read_info_ptr->unknown_chunks_num; i++)
|
||||
write_info_ptr->unknown_chunks[i].location =
|
||||
unknowns[i].location;
|
||||
for (i = 0; i < num_unknowns; i++)
|
||||
png_set_unknown_chunk_location(write_ptr, write_info_ptr,
|
||||
i, (int)unknowns[i].location);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -2836,7 +2878,10 @@ main(int argc, char *argv[])
|
||||
if(output_bit_depth < input_bit_depth)
|
||||
{
|
||||
png_color_8 true_bits;
|
||||
#if 0
|
||||
/* why did we need this? */
|
||||
write_ptr->bit_depth=(png_byte)output_bit_depth;
|
||||
#endif
|
||||
true_bits.gray = (png_byte)(8 - (input_bit_depth - output_bit_depth));
|
||||
png_set_shift(read_ptr, &true_bits);
|
||||
png_set_packing(write_ptr);
|
||||
@@ -2876,18 +2921,7 @@ main(int argc, char *argv[])
|
||||
#endif
|
||||
|
||||
if (row_buf == NULL)
|
||||
{
|
||||
fprintf(STDERR, "Insufficient memory to allocate row buffer\n");
|
||||
png_destroy_read_struct(&read_ptr, &read_info_ptr, (png_infopp)NULL);
|
||||
png_destroy_write_struct(&write_ptr, &write_info_ptr);
|
||||
if(png_row_filters != NULL)
|
||||
{
|
||||
free(png_row_filters); png_row_filters=NULL;
|
||||
}
|
||||
FCLOSE(fpin);
|
||||
FCLOSE(fpout);
|
||||
return 1;
|
||||
}
|
||||
png_error(read_ptr, "Insufficient memory to allocate row buffer");
|
||||
|
||||
{
|
||||
/* check for sufficient memory: we need 2*zlib_window
|
||||
@@ -3092,13 +3126,13 @@ main(int argc, char *argv[])
|
||||
&unknowns);
|
||||
if (num_unknowns && nosave == 0)
|
||||
{
|
||||
png_size_t i;
|
||||
int i;
|
||||
printf("setting %d unknown chunks after IDAT\n",num_unknowns);
|
||||
png_set_unknown_chunks(write_ptr, write_end_info_ptr, unknowns,
|
||||
num_unknowns);
|
||||
for (i = 0; i < read_info_ptr->unknown_chunks_num; i++)
|
||||
write_end_info_ptr->unknown_chunks[i].location =
|
||||
unknowns[i].location;
|
||||
for (i = 0; i < num_unknowns; i++)
|
||||
png_set_unknown_chunk_location(write_ptr, write_end_info_ptr,
|
||||
i, (int)unknowns[i].location);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -3116,9 +3150,29 @@ main(int argc, char *argv[])
|
||||
png_destroy_info_struct(write_ptr, &write_end_info_ptr);
|
||||
png_destroy_write_struct(&write_ptr, &write_info_ptr);
|
||||
}
|
||||
}
|
||||
Catch (msg)
|
||||
{
|
||||
if(nosave == 0)
|
||||
fprintf(stderr, "While converting %s to %s:\n", inname, outname);
|
||||
else
|
||||
fprintf(stderr, "While reading %s:\n", inname);
|
||||
fprintf(stderr, " pngcrush caught libpng error:\n %s\n\n",msg);
|
||||
if(row_buf != NULL)png_free(read_ptr, row_buf);
|
||||
row_buf = (png_bytep)NULL;
|
||||
png_destroy_info_struct(write_ptr, &write_end_info_ptr);
|
||||
png_destroy_write_struct(&write_ptr, &write_info_ptr);
|
||||
if(nosave == 0)
|
||||
FCLOSE(fpout);
|
||||
png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr);
|
||||
FCLOSE(fpin);
|
||||
if(verbose > 1)
|
||||
fprintf(stderr, "returning after cleanup\n");
|
||||
trial = MAX_METHODS+1;
|
||||
}
|
||||
|
||||
read_ptr=NULL;
|
||||
write_ptr=NULL;
|
||||
|
||||
FCLOSE(fpin);
|
||||
if(nosave == 0)
|
||||
FCLOSE(fpout);
|
||||
@@ -3204,72 +3258,61 @@ main(int argc, char *argv[])
|
||||
if(verbose > 0) show_result();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Catch (msg)
|
||||
{
|
||||
fprintf(stderr, "Caught libpng error:\n %s\n\n",msg);
|
||||
PNG_CRUSH_CLEANUP
|
||||
}
|
||||
} /* end of loop on input files */
|
||||
} /* end of loop on input files */
|
||||
}
|
||||
|
||||
png_uint_32
|
||||
measure_idats(FILE *fpin)
|
||||
{
|
||||
png_uint_32 measured_idat_length;
|
||||
png_const_charp msg;
|
||||
P2("measure_idats:\n");
|
||||
png_debug(0, "Allocating read structure\n");
|
||||
Try
|
||||
{
|
||||
read_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, (png_voidp)NULL,
|
||||
(png_error_ptr)png_cexcept_error, (png_error_ptr)NULL);
|
||||
png_debug(0, "Allocating read_info, end_info structures\n");
|
||||
read_info_ptr = png_create_info_struct(read_ptr);
|
||||
end_info_ptr = png_create_info_struct(read_ptr);
|
||||
|
||||
Try
|
||||
{
|
||||
|
||||
#if !defined(PNG_NO_STDIO)
|
||||
png_init_io(read_ptr, fpin);
|
||||
#else
|
||||
png_set_read_fn(read_ptr, (png_voidp)fpin, png_default_read_data);
|
||||
#endif
|
||||
|
||||
read_ptr->sig_bytes=0;
|
||||
measured_idat_length=png_measure_idat(read_ptr, read_info_ptr);
|
||||
png_set_sig_bytes(read_ptr, 0);
|
||||
measured_idat_length=png_measure_idat(read_ptr);
|
||||
P2("measure_idats: IDAT length=%lu\n",measured_idat_length);
|
||||
png_debug(0, "Destroying data structs\n");
|
||||
png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr);
|
||||
return measured_idat_length;
|
||||
}
|
||||
Catch (msg)
|
||||
{
|
||||
PNG_CRUSH_CLEANUP
|
||||
P2("Measure_idats caught libpng error:\n %s\n\n",msg);
|
||||
fprintf(STDERR, "\nWhile reading %s ", inname);
|
||||
fprintf(STDERR,"pngcrush caught libpng error:\n %s\n\n",msg);
|
||||
png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr);
|
||||
png_debug(0, "Destroyed data structs\n");
|
||||
measured_idat_length=0;
|
||||
}
|
||||
return 0;
|
||||
return measured_idat_length;
|
||||
}
|
||||
|
||||
|
||||
png_uint_32
|
||||
png_measure_idat(png_structp png_ptr, png_infop info_ptr)
|
||||
png_measure_idat(png_structp png_ptr)
|
||||
{
|
||||
png_uint_32 sum_idat_length=0;
|
||||
png_debug(1, "in png_read_info\n");
|
||||
|
||||
/* If we haven't checked all of the PNG signature bytes, do so now. */
|
||||
if (png_ptr->sig_bytes < 8)
|
||||
{
|
||||
png_size_t num_checked = png_ptr->sig_bytes,
|
||||
num_to_check = 8 - num_checked;
|
||||
png_byte png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10};
|
||||
|
||||
png_read_data(png_ptr, &(info_ptr->signature[num_checked]), num_to_check);
|
||||
png_ptr->sig_bytes = 8;
|
||||
png_read_data(png_ptr, png_sig, 8);
|
||||
png_set_sig_bytes(png_ptr, 8);
|
||||
|
||||
if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
|
||||
if (png_sig_cmp(png_sig, 0, 8))
|
||||
{
|
||||
if (num_checked < 4 &&
|
||||
png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))
|
||||
if (png_sig_cmp(png_sig, 0, 4))
|
||||
png_error(png_ptr, "Not a PNG file");
|
||||
else
|
||||
png_error(png_ptr, "PNG file corrupted by ASCII conversion");
|
||||
@@ -3282,10 +3325,12 @@ png_measure_idat(png_structp png_ptr, png_infop info_ptr)
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
PNG_IDAT;
|
||||
PNG_IEND;
|
||||
PNG_IHDR;
|
||||
#endif
|
||||
#endif
|
||||
png_byte chunk_name[5];
|
||||
png_byte chunk_length[4];
|
||||
png_byte buffer[16];
|
||||
png_uint_32 length;
|
||||
|
||||
png_read_data(png_ptr, chunk_length, 4);
|
||||
@@ -3294,6 +3339,17 @@ png_measure_idat(png_structp png_ptr, png_infop info_ptr)
|
||||
png_reset_crc(png_ptr);
|
||||
png_crc_read(png_ptr, chunk_name, 4);
|
||||
|
||||
#ifdef PNG_UINT_IDAT
|
||||
if (png_get_uint_32(chunk_name) == PNG_UINT_IHDR)
|
||||
#else
|
||||
if (!png_memcmp(chunk_name, png_IHDR, 4))
|
||||
#endif
|
||||
{
|
||||
/* get the color type */
|
||||
png_crc_read(png_ptr, buffer, 13);
|
||||
length-=13;
|
||||
input_color_type=buffer[9];
|
||||
}
|
||||
|
||||
#ifdef PNG_UINT_IDAT
|
||||
if (png_get_uint_32(chunk_name) == PNG_UINT_IDAT)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
/* pngerror.c - stub functions for i/o and memory allocation
|
||||
*
|
||||
* libpng 1.0.6f - April 14, 2000
|
||||
* libpng 1.0.6h - April 24, 2000
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
|
||||
10
pnggccrd.c
10
pnggccrd.c
@@ -6,7 +6,7 @@
|
||||
* and http://www.intel.com/drg/pentiumII/appnotes/923/923.htm
|
||||
* for Intel's performance analysis of the MMX vs. non-MMX code.
|
||||
*
|
||||
* libpng 1.0.6f - April 14, 2000
|
||||
* libpng 1.0.6h - April 24, 2000
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1998, Intel Corporation
|
||||
* Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
|
||||
@@ -137,6 +137,12 @@ int mmxsupport(void);
|
||||
|
||||
static int mmx_supported = 2;
|
||||
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
static const int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
|
||||
static const int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
|
||||
static const int png_pass_width[7] = {8, 4, 4, 2, 2, 1, 1};
|
||||
#endif
|
||||
|
||||
// djgpp adds its own underscores to global variables, so define them without:
|
||||
#ifdef __DJGPP__
|
||||
# define _unmask unmask
|
||||
@@ -4494,7 +4500,7 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep
|
||||
break;
|
||||
|
||||
default:
|
||||
png_error(png_ptr, "Bad adaptive filter type");
|
||||
png_error(png_ptr, "#103 Bad adaptive filter type");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
8
pngget.c
8
pngget.c
@@ -1,7 +1,7 @@
|
||||
|
||||
/* pngget.c - retrieval of values from info struct
|
||||
*
|
||||
* libpng 1.0.6f - April 14, 2000
|
||||
* libpng 1.0.6h - April 24, 2000
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
@@ -801,3 +801,9 @@ png_get_user_chunk_ptr(png_structp png_ptr)
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
png_uint_32
|
||||
png_get_compression_buffer_size(png_structp png_ptr)
|
||||
{
|
||||
return(png_ptr->zbuf_size);
|
||||
}
|
||||
|
||||
2
pngmem.c
2
pngmem.c
@@ -1,7 +1,7 @@
|
||||
|
||||
/* pngmem.c - stub functions for memory allocation
|
||||
*
|
||||
* libpng 1.0.6f - April 14, 2000
|
||||
* libpng 1.0.6h - April 24, 2000
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
/* pngpread.c - read a png file in push mode
|
||||
*
|
||||
* libpng 1.0.6f - April 14, 2000
|
||||
* libpng 1.0.6h - April 24, 2000
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
/* pngread.c - read a PNG file
|
||||
*
|
||||
* libpng 1.0.6f - April 14, 2000
|
||||
* libpng 1.0.6h - April 24, 2000
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
@@ -641,7 +641,7 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
|
||||
* 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.0.6f.
|
||||
* [*] png_handle_alpha() does not exist yet, as of libpng version 1.0.6h.
|
||||
*/
|
||||
|
||||
void
|
||||
@@ -690,7 +690,7 @@ png_read_rows(png_structp png_ptr, png_bytepp row,
|
||||
* 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.0.6f.
|
||||
* [*] png_handle_alpha() does not exist yet, as of libpng version 1.0.6h.
|
||||
*/
|
||||
void
|
||||
png_read_image(png_structp png_ptr, png_bytepp image)
|
||||
|
||||
2
pngrio.c
2
pngrio.c
@@ -1,7 +1,7 @@
|
||||
|
||||
/* pngrio.c - functions for data input
|
||||
*
|
||||
* libpng 1.0.6f - April 14, 2000
|
||||
* libpng 1.0.6h - April 24, 2000
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
/* pngrtran.c - transforms the data in a row for PNG readers
|
||||
*
|
||||
* libpng 1.0.6f - April 14, 2000
|
||||
* libpng 1.0.6h - April 24, 2000
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
/* pngrutil.c - utilities to read a PNG file
|
||||
*
|
||||
* libpng 1.0.6f - April 14, 2000
|
||||
* libpng 1.0.6h - April 24, 2000
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
|
||||
21
pngset.c
21
pngset.c
@@ -1,7 +1,7 @@
|
||||
|
||||
/* pngset.c - storage of image information into info struct
|
||||
*
|
||||
* libpng 1.0.6f - April 14, 2000
|
||||
* libpng 1.0.6h - April 24, 2000
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
@@ -693,6 +693,14 @@ png_set_unknown_chunks(png_structp png_ptr,
|
||||
info_ptr->unknown_chunks_num += num_unknowns;
|
||||
info_ptr->free_me |= PNG_FREE_UNKN;
|
||||
}
|
||||
void
|
||||
png_set_unknown_chunk_location(png_structp png_ptr, png_infop info_ptr,
|
||||
int chunk, int location)
|
||||
{
|
||||
if(png_ptr != NULL && info_ptr != NULL && chunk >= 0 && chunk <
|
||||
(int)info_ptr->unknown_chunks_num)
|
||||
info_ptr->unknown_chunks[chunk].location = (png_byte)location;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
|
||||
@@ -772,3 +780,14 @@ png_set_rows(png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers)
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void
|
||||
png_set_compression_buffer_size(png_structp png_ptr, png_uint_32 size)
|
||||
{
|
||||
if(png_ptr->zbuf)
|
||||
png_free(png_ptr, png_ptr->zbuf);
|
||||
png_ptr->zbuf_size = (png_size_t)size;
|
||||
png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, size);
|
||||
png_ptr->zstream.next_out = png_ptr->zbuf;
|
||||
png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
/* pngtrans.c - transforms the data in a row (used by both readers and writers)
|
||||
*
|
||||
* libpng 1.0.6f - April 14, 2000
|
||||
* libpng 1.0.6h - April 24, 2000
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
*
|
||||
* For Intel x86 CPU and Microsoft Visual C++ compiler
|
||||
*
|
||||
* libpng 1.0.6f - April 14, 2000
|
||||
* libpng 1.0.6h - April 24, 2000
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1998, Intel Corporation
|
||||
* Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
|
||||
|
||||
2
pngwio.c
2
pngwio.c
@@ -1,7 +1,7 @@
|
||||
|
||||
/* pngwio.c - functions for data output
|
||||
*
|
||||
* libpng 1.0.6f - April 14, 2000
|
||||
* libpng 1.0.6h - April 24, 2000
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
/* pngwrite.c - general routines to write a PNG file
|
||||
*
|
||||
* libpng 1.0.6f - April 14, 2000
|
||||
* libpng 1.0.6h - April 24, 2000
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
/* pngwtran.c - transforms the data in a row for PNG writers
|
||||
*
|
||||
* libpng 1.0.6f - April 14, 2000
|
||||
* libpng 1.0.6h - April 24, 2000
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
/* pngwutil.c - utilities to write a PNG file
|
||||
*
|
||||
* libpng 1.0.6f - April 14, 2000
|
||||
* libpng 1.0.6h - April 24, 2000
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
|
||||
Reference in New Issue
Block a user