Imported from pngcrush-1.5.2.tar

This commit is contained in:
Glenn Randers-Pehrson
2000-11-19 07:33:38 -06:00
parent 28affe866f
commit 0d46dafc86
24 changed files with 2032 additions and 1289 deletions

View File

@@ -1,6 +1,8 @@
Pngcrush documentation
This is the copyright notice, disclaimer, and license:
This is is a copy of the copyright notice, disclaimer, and license, for
your convenience (the actual notice appears in the file pngcrush.c; in
case of any discrepancy, the copy in pngcrush.c shall prevail):
/*
* COPYRIGHT NOTICE, DISCLAIMER, AND LICENSE:
@@ -38,12 +40,13 @@ This is the copyright notice, disclaimer, and license:
This is the output of "pngcrush" and "pngcrush -help":
| pngcrush 1.5.1, Copyright (C) 1998, 1999, 2000 Glenn Randers-Pehrson
| pngcrush 1.5.2, Copyright (C) 1998, 1999, 2000 Glenn Randers-Pehrson
| This is a free, open-source program. Permission is
| irrevocably granted to everyone to use this version
| of pngcrush without payment of any fee.
| This program was built with libpng version 1.0.8,
| and is running with libpng version 1.0.8 - July 24, 2000 (header)
| This program was built with libpng version 1.0.9beta2,
| and is running with libpng version 1.0.9beta2 - November 19, 2000 (header)
| Copyright (C) 1998, 1999, 2000 Glenn Randers-Pehrson,
| Copyright (C) 1996, 1997 Andreas Dilger,
| Copyright (C) 1995, Guy Eric Schalnat, Group 42 Inc.,
@@ -66,14 +69,16 @@ options:
-fix (fix otherwise fatal conditions such as bad CRCs)
-force (Write a new output file even if larger than input)
-g gamma (float or fixed*100000, e.g., 0.45455 or 45455)
-iccp length "Profile Name" iccp_file
-itxt b[efore_IDAT]|a[fter_IDAT] "keyword" "text"
-l zlib_compression_level [0-9]
-m method [0 through 200]
-max maximum_IDAT_size [1 through 524288]
-max maximum_IDAT_size [default 524288]
-no_cc (no color counting)
-n (no save; does not do compression or write output PNG)
-plte_len n (truncate PLTE)
-q (quiet)
-reduce (do lossless color type or bit depth reduction)
-rem chunkname (or "alla" or "allb")
-replace_gamma gamma (float or fixed*100000) even if gAMA is present.
-res dpi
@@ -86,29 +91,16 @@ options:
-h (help and legal notices)
-p (pause)
options (Note: any option can be spelled out for clarity, e.g.,
"pngcrush -dir New -method 7 -remove bkgd *.png"
is the same as "pngcrush -d New -m 7 -rem bkgd *.png"):
| pngcrush 1.5.1, Copyright (C) 1998, 1999, 2000 Glenn Randers-Pehrson
| This is a free, open-source program. Permission is
| irrevocably granted to everyone to use this version
| of pngcrush without payment of any fee.
| This program was built with libpng version 1.0.8,
| and is running with libpng version 1.0.8 - July 24, 2000 (header)
| Copyright (C) 1998, 1999, 2000 Glenn Randers-Pehrson,
| Copyright (C) 1996, 1997 Andreas Dilger,
| Copyright (C) 1995, Guy Eric Schalnat, Group 42 Inc.,
| and zlib version 1.1.3pc, Copyright (C) 1998,
| Jean-loup Gailly and Mark Adler.
usage: pngcrush [options] infile.png outfile.png
pngcrush -e ext [other options] files.png ...
pngcrush -d dir [other options] files.png ...
options:
-already already_crushed_size [e.g., 8192]
If file has an IDAT greater than this size, it
will be considered to be already crushed.
will be considered to be already crushed and will
not be processed, unless you are making other changes
or the "-force" option is present.
-brute (Use brute-force, try 114 different methods [11-124])
@@ -168,6 +160,10 @@ options:
file has no gAMA chunk. To replace an existing
gAMA chunk, use the '-replace_gamma' option.
-iccp length "Profile Name" iccp_file
file with ICC profile to insert in an iCCP chunk.
-itxt b[efore_IDAT]|a[fter_IDAT] "keyword" "text"
Uncompressed iTXt chunk to insert (see -text).
@@ -188,7 +184,7 @@ options:
1, 4, and 7 use no filtering; methods 11 and up use
specified filter, compression level, and strategy.
-max maximum_IDAT_size [1 through 524288]
-max maximum_IDAT_size [default 524288]
-no_cc (no color counting)
@@ -199,11 +195,14 @@ options:
-plte_len n (truncate PLTE)
Truncates the PLTE. Be sure not to truncate it to
less than the greatest index present in IDAT.
-q (quiet)
-reduce (do lossless color type or bit depth reduction)
(if possible)
-rem chunkname (or "alla" or "allb")
Name of an ancillary chunk or optional PLTE to be
@@ -249,6 +248,9 @@ options:
-version (display the pngcrush version)
Look for the most recent version of pngcrush at
http://pmt.sourceforge.net
-w compression_window_size [32, 16, 8, 4, 2, 1, 512]
Size of the sliding compression window, in kbytes
@@ -262,6 +264,8 @@ options:
zlib compression strategy to use with the preceding
'-m method' argument.
-zmem zlib_compression_mem_level [1-9, default 9]
-zitxt b[efore_IDAT]|a[fter_IDAT] "keyword" "text"
Compressed iTXt chunk to insert (see -text).
@@ -280,3 +284,4 @@ options:
e.g., type 'pngcrush -pause -help', if the help
screen scrolls out of sight.

68
compress.c Normal file
View File

@@ -0,0 +1,68 @@
/* compress.c -- compress a memory buffer
* Copyright (C) 1995-1998 Jean-loup Gailly.
* For conditions of distribution and use, see copyright notice in zlib.h
*/
/* @(#) $Id$ */
#include "zlib.h"
/* ===========================================================================
Compresses the source buffer into the destination buffer. The level
parameter has the same meaning as in deflateInit. sourceLen is the byte
length of the source buffer. Upon entry, destLen is the total size of the
destination buffer, which must be at least 0.1% larger than sourceLen plus
12 bytes. Upon exit, destLen is the actual size of the compressed buffer.
compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
memory, Z_BUF_ERROR if there was not enough room in the output buffer,
Z_STREAM_ERROR if the level parameter is invalid.
*/
int ZEXPORT compress2 (dest, destLen, source, sourceLen, level)
Bytef *dest;
uLongf *destLen;
const Bytef *source;
uLong sourceLen;
int level;
{
z_stream stream;
int err;
stream.next_in = (Bytef*)source;
stream.avail_in = (uInt)sourceLen;
#ifdef MAXSEG_64K
/* Check for source > 64K on 16-bit machine: */
if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
#endif
stream.next_out = dest;
stream.avail_out = (uInt)*destLen;
if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
stream.zalloc = (alloc_func)0;
stream.zfree = (free_func)0;
stream.opaque = (voidpf)0;
err = deflateInit(&stream, level);
if (err != Z_OK) return err;
err = deflate(&stream, Z_FINISH);
if (err != Z_STREAM_END) {
deflateEnd(&stream);
return err == Z_OK ? Z_BUF_ERROR : err;
}
*destLen = stream.total_out;
err = deflateEnd(&stream);
return err;
}
/* ===========================================================================
*/
int ZEXPORT compress (dest, destLen, source, sourceLen)
Bytef *dest;
uLongf *destLen;
const Bytef *source;
uLong sourceLen;
{
return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
}

34
png.c
View File

@@ -1,7 +1,7 @@
/* png.c - location for general purpose libpng functions
*
* libpng version 1.0.8 - July 24, 2000
* libpng version 1.0.9beta2 - November 19, 2000
* Copyright (c) 1998, 1999, 2000 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.)
@@ -13,18 +13,18 @@
#include "png.h"
/* Generate a compiler error if there is an old png.h in the search path. */
typedef version_1_0_8 Your_png_h_is_not_version_1_0_8;
typedef version_1_0_9beta2 Your_png_h_is_not_version_1_0_9beta2;
/* 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.8";
const char png_libpng_ver[18] = "1.0.9beta2";
/* png_sig was changed to a function in version 1.0.5c */
/* Place to hold the signature string for a PNG file. */
png_byte FARDATA png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10};
const png_byte FARDATA png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10};
/* Invoke global declarations for constant strings for known chunk types */
PNG_IHDR;
@@ -52,32 +52,33 @@ PNG_zTXt;
/* arrays to facilitate easy interlacing - use pass (0 - 6) as index */
/* start of interlace block */
int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
const int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
/* offset to next interlace block */
int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
const int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
/* start of interlace block in the y direction */
int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
const int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
/* offset to next interlace block in the y direction */
int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
const int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
/* width of interlace block (used in assembler routines only) */
#ifdef PNG_HAVE_ASSEMBLER_COMBINE_ROW
int FARDATA png_pass_width[] = {8, 4, 4, 2, 2, 1, 1};
const int FARDATA png_pass_width[] = {8, 4, 4, 2, 2, 1, 1};
#endif
/* Height of interlace block. This is not currently used - if you need
* it, uncomment it here and in png.h
int FARDATA png_pass_height[] = {8, 8, 4, 4, 2, 2, 1};
const int FARDATA png_pass_height[] = {8, 8, 4, 4, 2, 2, 1};
*/
/* Mask to determine which pixels are valid in a pass */
int FARDATA png_pass_mask[] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
const int FARDATA png_pass_mask[] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
/* Mask to determine which pixels to overwrite while displaying */
int FARDATA png_pass_dsp_mask[] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
const int FARDATA png_pass_dsp_mask[]
= {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
#endif
@@ -625,7 +626,7 @@ png_charp PNGAPI
png_get_copyright(png_structp png_ptr)
{
if (png_ptr != NULL || png_ptr == NULL) /* silence compiler warning */
return ((png_charp) "\n libpng version 1.0.8 - July 24, 2000\n\
return ((png_charp) "\n libpng version 1.0.9beta2 - November 19, 2000\n\
Copyright (c) 1998-2000 Glenn Randers-Pehrson\n\
Copyright (c) 1996, 1997 Andreas Dilger\n\
Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.\n");
@@ -643,8 +644,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((png_charp) "1.0.8");
return((png_charp) "1.0.8");
return((png_charp) "1.0.9beta2");
return((png_charp) "1.0.9beta2");
}
png_charp PNGAPI
@@ -689,9 +690,10 @@ png_reset_zstream(png_structp png_ptr)
return (inflateReset(&png_ptr->zstream));
}
/* This function was added to libpng-1.0.7 */
png_uint_32 PNGAPI
png_access_version_number(void)
{
/* Version of *.c files used when building libpng */
return((png_uint_32) 10008L);
return((png_uint_32) 10009L);
}

85
png.h
View File

@@ -1,7 +1,7 @@
/* png.h - header file for PNG reference library
*
* libpng version 1.0.8 - July 24, 2000
* libpng version 1.0.9beta2 - November 19, 2000
* Copyright (c) 1998, 1999, 2000 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.)
@@ -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.8 - July 24, 2000: Glenn
* libpng versions 0.97, January 1998, through 1.0.9beta2 - November 19, 2000: Glenn
* See also "Contributing Authors", below.
*
* Note about libpng version numbers:
@@ -58,6 +58,7 @@
* 1.0.8beta1-4 10008 2.1.0.8beta1-4
* 1.0.8rc1 10008 2.1.0.8rc1
* 1.0.8 10008 2.1.0.8
* 1.0.9beta1-2 10009 2.1.0.9
*
* Henceforth the source version will match the shared-library major
* and minor numbers; the shared-library major version number will be
@@ -84,7 +85,7 @@
* If you modify libpng you may insert additional notices immediately following
* this sentence.
*
* libpng versions 1.0.7, July 1, 2000, through 1.0.8, July 24, 2000, are
* libpng versions 1.0.7, July 1, 2000, through 1.0.9beta2, November 19, 2000, are
* Copyright (c) 2000 Glenn Randers-Pehrson, and are
* distributed according to the same disclaimer and license as libpng-1.0.6
* with the following individuals added to the list of Contributing Authors
@@ -189,13 +190,13 @@
* Y2K compliance in libpng:
* =========================
*
* July 24, 2000
* November 19, 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.8 are Y2K compliant. It is my belief that earlier
* upward through 1.0.9beta2 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
@@ -251,26 +252,25 @@
*/
/* Version information for png.h - this should match the version in png.c */
#define PNG_LIBPNG_VER_STRING "1.0.8"
#define PNG_LIBPNG_VER_STRING "1.0.9beta2"
#define PNG_LIBPNG_VER_SONUM 2
/* These should match the first 3 components of PNG_LIBPNG_VER_STRING: */
#define PNG_LIBPNG_VER_MAJOR 1
#define PNG_LIBPNG_VER_MINOR 0
#define PNG_LIBPNG_VER_RELEASE 8
#define PNG_LIBPNG_VER_RELEASE 9
/* This should match the numeric part of the final component of
* PNG_LIBPNG_VER_STRING, omitting any leading zero: */
#define PNG_LIBPNG_VER_BUILD 0
#define PNG_LIBPNG_VER_BUILD 2
#define PNG_LIBPNG_BUILD_TYPE beta /* alpha, beta, rc, stable, patched */
/* Careful here. At one time, Guy wanted to use 082, but that would be octal.
* We must not include leading zeros.
* Versions 0.7 through 1.0.0 were in the range 0 to 100 here (only
* version 1.0.0 was mis-numbered 100 instead of 10000). From
* version 1.0.1 it's xxyyzz, where x=major, y=minor, z=release */
#define PNG_LIBPNG_VER 10008 /* 1.0.8 */
/* Note to maintainer: update this number in scripts/pngdef.pas as well */
#define PNG_LIBPNG_VER 10009 /* 1.0.9 */
#ifndef PNG_VERSION_INFO_ONLY
@@ -302,8 +302,8 @@ extern "C" {
* the version above.
*/
#ifdef PNG_USE_GLOBAL_ARRAYS
PNG_EXPORT_VAR (char) png_libpng_ver[12]; /* need room for 99.99.99-patch-aa0*/
/* Note to maintainer: increase to 18 at the next opportunity */
PNG_EXPORT_VAR (const char) png_libpng_ver[18];
/* need room for 99.99.99beta99z*/
#else
#define png_libpng_ver png_get_header_ver(NULL)
#endif
@@ -311,17 +311,17 @@ PNG_EXPORT_VAR (char) png_libpng_ver[12]; /* need room for 99.99.99-patch-aa0*/
#ifdef PNG_USE_GLOBAL_ARRAYS
/* This was removed in version 1.0.5c */
/* Structures to facilitate easy interlacing. See png.c for more details */
PNG_EXPORT_VAR (int FARDATA) png_pass_start[7];
PNG_EXPORT_VAR (int FARDATA) png_pass_inc[7];
PNG_EXPORT_VAR (int FARDATA) png_pass_ystart[7];
PNG_EXPORT_VAR (int FARDATA) png_pass_yinc[7];
PNG_EXPORT_VAR (int FARDATA) png_pass_mask[7];
PNG_EXPORT_VAR (int FARDATA) png_pass_dsp_mask[7];
PNG_EXPORT_VAR (const int FARDATA) png_pass_start[7];
PNG_EXPORT_VAR (const int FARDATA) png_pass_inc[7];
PNG_EXPORT_VAR (const int FARDATA) png_pass_ystart[7];
PNG_EXPORT_VAR (const int FARDATA) png_pass_yinc[7];
PNG_EXPORT_VAR (const int FARDATA) png_pass_mask[7];
PNG_EXPORT_VAR (const int FARDATA) png_pass_dsp_mask[7];
#ifdef PNG_HAVE_ASSEMBLER_COMBINE_ROW
extern int FARDATA png_pass_width[7]; /* now used in pngvcrd.c, pnggccrd.c */
PNG_EXPORT_VAR (const int FARDATA) png_pass_width[7];
#endif
/* This isn't currently used. If you need it, see png.c for more details.
extern int FARDATA png_pass_height[7];
PNG_EXPORT_VAR (const int FARDATA) png_pass_height[7];
*/
#endif
@@ -523,6 +523,7 @@ typedef struct png_info_struct
png_uint_16 num_trans; /* number of transparent palette color (tRNS) */
png_byte bit_depth; /* 1, 2, 4, 8, or 16 bits/channel (from IHDR) */
png_byte color_type; /* see PNG_COLOR_TYPE_ below (from IHDR) */
/* The following three should have been named *_method not *_type */
png_byte compression_type; /* must be PNG_COMPRESSION_TYPE_BASE (IHDR) */
png_byte filter_type; /* must be PNG_FILTER_TYPE_BASE (from IHDR) */
png_byte interlace_type; /* One of PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
@@ -764,6 +765,9 @@ typedef png_info FAR * FAR * png_infopp;
#define PNG_COLOR_TYPE_RGB (PNG_COLOR_MASK_COLOR)
#define PNG_COLOR_TYPE_RGB_ALPHA (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_ALPHA)
#define PNG_COLOR_TYPE_GRAY_ALPHA (PNG_COLOR_MASK_ALPHA)
/* aliases */
#define PNG_COLOR_TYPE_RGBA PNG_COLOR_TYPE_RGB_ALPHA
#define PNG_COLOR_TYPE_GA PNG_COLOR_TYPE_GRAY_ALPHA
/* This is for compression type. PNG 1.0-1.2 only define the single type. */
#define PNG_COMPRESSION_TYPE_BASE 0 /* Deflate method 8, 32K window */
@@ -904,6 +908,10 @@ typedef void (PNGAPI *png_unknown_chunk_ptr) PNGARG((png_structp));
#define PNG_TRANSFORM_INVERT_ALPHA 0x0400 /* read and write */
#define PNG_TRANSFORM_STRIP_FILLER 0x0800 /* WRITE only */
/* Flags for MNG supported features */
#define PNG_FLAG_MNG_EMPTY_PLTE 0x01
#define PNG_ALL_MNG_FEATURES 0x01
typedef png_voidp (*png_malloc_ptr) PNGARG((png_structp, png_size_t));
typedef void (*png_free_ptr) PNGARG((png_structp, png_voidp));
@@ -1137,9 +1145,11 @@ struct png_struct_def
png_uint_16 rgb_to_gray_blue_coeff;
#endif
#if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
#if defined(PNG_MNG_FEATURES_SUPPORTED) || \
defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
png_byte empty_plte_permitted;
/* Note to maintainer: change this to png_uint_32 at next opportunity */
png_byte mng_features_permitted;
#endif
#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
@@ -1149,9 +1159,9 @@ struct png_struct_def
};
/* This prevents a compiler error in png_get_copyright() in png.c if png.c
and png.h are both at * version 1.0.8
and png.h are both at * version 1.0.9beta2
*/
typedef png_structp version_1_0_8;
typedef png_structp version_1_0_9beta2;
typedef png_struct FAR * FAR * png_structpp;
@@ -1387,6 +1397,7 @@ extern PNG_EXPORT(void,png_set_gamma) PNGARG((png_structp png_ptr,
#if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
/* Permit or disallow empty PLTE (0: not permitted, 1: permitted) */
/* Deprecated and will be removed. Use png_permit_mng_features() instead. */
extern PNG_EXPORT(void,png_permit_empty_plte) PNGARG((png_structp png_ptr,
int empty_plte_permitted));
#endif
@@ -1928,12 +1939,13 @@ extern PNG_EXPORT(void,png_set_hIST) PNGARG((png_structp png_ptr,
extern PNG_EXPORT(png_uint_32,png_get_IHDR) PNGARG((png_structp png_ptr,
png_infop info_ptr, png_uint_32 *width, png_uint_32 *height,
int *bit_depth, int *color_type, int *interlace_type,
int *compression_type, int *filter_type));
int *bit_depth, int *color_type, int *interlace_method,
int *compression_method, int *filter_method));
extern PNG_EXPORT(void,png_set_IHDR) PNGARG((png_structp png_ptr,
png_infop info_ptr, png_uint_32 width, png_uint_32 height, int bit_depth,
int color_type, int interlace_type, int compression_type, int filter_type));
int color_type, int interlace_method, int compression_method,
int filter_method));
#if defined(PNG_READ_oFFs_SUPPORTED)
extern PNG_EXPORT(png_uint_32,png_get_oFFs) PNGARG((png_structp png_ptr,
@@ -2117,11 +2129,11 @@ extern PNG_EXPORT(void, png_set_invalid) PNGARG((png_structp png_ptr,
extern PNG_EXPORT(void, png_read_png) PNGARG((png_structp png_ptr,
png_infop info_ptr,
int transforms,
voidp params));
png_voidp params));
extern PNG_EXPORT(void, png_write_png) PNGARG((png_structp png_ptr,
png_infop info_ptr,
int transforms,
voidp params));
png_voidp params));
#endif
/* Define PNG_DEBUG at compile time for debugging information. Higher
@@ -2182,8 +2194,13 @@ extern PNG_EXPORT(png_charp,png_get_header_ver) PNGARG((png_structp png_ptr));
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));
#ifdef PNG_MNG_FEATURES_SUPPORTED
extern PNG_EXPORT(png_uint_32,png_permit_mng_features) PNGARG((png_structp
png_ptr, png_uint_32 mng_features_permitted));
#endif
#define PNG_HEADER_VERSION_STRING \
" libpng version 1.0.8 - July 24, 2000 (header)\n"
" libpng version 1.0.9beta2 - November 19, 2000 (header)\n"
#ifdef PNG_READ_COMPOSITE_NODIV_SUPPORTED
/* With these routines we avoid an integer divide, which will be slower on
@@ -2330,7 +2347,7 @@ extern PNG_EXPORT(png_charp,png_get_libpng_ver) PNGARG((png_structp png_ptr));
#if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN)
/* place to hold the signature string for a PNG file. */
#ifdef PNG_USE_GLOBAL_ARRAYS
PNG_EXPORT_VAR (png_byte FARDATA) png_sig[8];
PNG_EXPORT_VAR (const png_byte FARDATA) png_sig[8];
#else
#define png_sig png_sig_bytes(NULL)
#endif
@@ -2516,8 +2533,8 @@ PNG_EXTERN void png_write_sig PNGARG((png_structp png_ptr));
*/
PNG_EXTERN void png_write_IHDR PNGARG((png_structp png_ptr, png_uint_32 width,
png_uint_32 height,
int bit_depth, int color_type, int compression_type, int filter_type,
int interlace_type));
int bit_depth, int color_type, int compression_method, int filter_method,
int interlace_method));
PNG_EXTERN void png_write_PLTE PNGARG((png_structp png_ptr, png_colorp palette,
png_uint_32 num_pal));

View File

@@ -1,6 +1,6 @@
/* pngasmrd.h - assembler version of utilities to read a PNG file
*
* libpng 1.0.8 - July 24, 2000
* libpng 1.0.9beta2 - November 19, 2000
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1999, 2000 Glenn Randers-Pehrson
*

View File

@@ -1,6 +1,6 @@
/* pngconf.h - machine configurable file for libpng
*
* libpng 1.0.8 - July 24, 2000
* libpng 1.0.9beta2 - November 19, 2000
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
@@ -400,6 +400,7 @@
#define PNG_NO_WRITE_USER_TRANSFORM
#define PNG_NO_USER_MEM
#define PNG_NO_READ_EMPTY_PLTE
#define PNG_NO_MNG_FEATURES
#define PNG_NO_FIXED_POINT_SUPPORTED
#endif
@@ -492,8 +493,12 @@
#endif
#endif
#ifndef PNG_NO_MNG_FEATURES
#define PNG_MNG_FEATURES_SUPPORTED /* Useful for MNG applications */
#endif
/* Deprecated, will be removed */
#ifndef PNG_NO_READ_EMPTY_PLTE
#define PNG_READ_EMPTY_PLTE_SUPPORTED /* useful for MNG applications */
#define PNG_READ_EMPTY_PLTE_SUPPORTED
#endif
#ifdef PNG_WRITE_TRANSFORMS_SUPPORTED
@@ -549,8 +554,9 @@ defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
#define PNG_WRITE_FLUSH_SUPPORTED
#endif
/* Deprecated, see PNG_MNG_FEATURES_SUPPORTED, above */
#ifndef PNG_NO_WRITE_EMPTY_PLTE
#define PNG_WRITE_EMPTY_PLTE_SUPPORTED /* useful for MNG applications */
#define PNG_WRITE_EMPTY_PLTE_SUPPORTED
#endif
#ifndef PNG_NO_STDIO
@@ -1134,6 +1140,13 @@ typedef z_stream FAR * png_zstreamp;
#endif
#endif
#ifndef PNGAPI
# define PNGAPI
#endif
#ifndef PNG_IMPEXP
# define PNG_IMPEXP
#endif
#ifndef PNG_EXPORT
# define PNG_EXPORT(type,symbol) PNG_IMPEXP type PNGAPI symbol
#endif

View File

@@ -1,9 +1,12 @@
/* pngcrush.c - recompresses png files
* Copyright (C) 1998, 1999, 2000 Glenn Randers-Pehrson (randeg@alum.rpi.edu)
*
* The most recent version of pngcrush can be found at
* http://pmt.sourceforge.net/pngcrush/
*
* This program reads in a PNG image, and writes it out again, with the
* optimum filter_type and zlib_level. It uses brute force (trying
* filter_type none, and libpng adaptive filtering, with compression
* optimum filter_method and zlib_level. It uses brute force (trying
* filter_method none, and libpng adaptive filtering, with compression
* levels 3 and 9). It does the most time-consuming method last in case
* it turns out to be the best.
*
@@ -14,9 +17,13 @@
*
* Thanks to Greg Roelofs for various bug fixes, suggestions, and
* occasionally creating Linux executables.
*
* Thanks to Stephan Levavej for some helpful suggestions about gcc compiler
* options and for a suggestion to increase the Z_MEM_LEVEL from default.
*
*/
#define PNGCRUSH_VERSION "1.5.1"
#define PNGCRUSH_VERSION "1.5.2"
/*
*/
@@ -57,6 +64,26 @@
*/
/* Change log:
*
* Version 1.5.2 (built with libpng-1.0.9beta1)
*
* Added "-iccp" option.
*
* Increased the zlib memory level, which improves compression (typically
* about 1.3 percent for photos) at the expense of increased memory usage.
*
* Enabled the "-max max_idat_size" option, even when max_idat_size
* exceeds the default 1/2 megabyte size.
*
* Added missing "png_ptr" argument to png_error() call
*
* Revised the "-help" output slightly and improved the "-version" output.
*
* The "-already[_crushed]" option is now ignored if the "-force" option
* is present or if chunks are being added, deleted, or modified.
*
* Improved "things_have_changed" behavior (now, when set in a particular
* file, it is not set for all remaining files)
*
* Version 1.5.1 (built with libpng-1.0.8)
*
@@ -272,26 +299,31 @@
/* To do:
*
* Version 1.4.*: check for unused alpha channel and ok-to-reduce-depth.
* Rearrange palette to put most-used color first and transparent color
* second (see ImageMagick 5.1.1 and later).
* Finish pplt (partial palette) feature.
* Check for unused alpha channel and ok-to-reduce-depth.
* Take care that sBIT and bKGD data aren't lost when reducing images
* from truecolor to grayscale.
*
* Version 1.4.*: Use an alternate write function for the trial passes, that
* Rearrange palette to put most-used color first and transparent color
* second (see ImageMagick 5.1.1 and later).
*
* Finish pplt (partial palette) feature.
*
* Use an alternate write function for the trial passes, that
* simply counts bytes rather than actually writing to a file, to save wear
* and tear on disk drives.
*
* Version 1.4.*: Allow in-place file replacement or as a filter, as in
* Allow in-place file replacement or as a filter, as in
* "pngcrush -overwrite file.png"
* "pngcreator | pngcrush > output.png"
*
* Version 1.4.*: Remove text-handling and color-handling features and put
* Remove text-handling and color-handling features and put
* those in a separate program or programs, to avoid unnecessary
* recompressing.
*
* Move the Photoshop-fixing stuff into a separate program.
*
* add "-time" directive
*
*/
#define PNG_INTERNAL
@@ -301,6 +333,11 @@
* so they are ifdef'ed out in a special version of pngconf.h, which
* includes pngcrush.h and is included by png.h */
/* defined so I can write to a file on gui/windowing platforms */
/* #define STDERR stderr */
#define STDERR stdout /* for DOS */
#ifndef PNGCRUSH_LIBPNG_VER
# define PNGCRUSH_LIBPNG_VER PNG_LIBPNG_VER
#endif
@@ -427,10 +464,6 @@ main()
# define TIME_T float
#endif
/* defined so I can write to a file on gui/windowing platforms */
/* #define STDERR stderr */
#define STDERR stdout /* for DOS */
/* input and output filenames */
static PNG_CONST char *progname = "pngtest" DOT "png";
static PNG_CONST char *inname = "pngtest" DOT "png";
@@ -438,6 +471,7 @@ static PNG_CONST char *outname = "pngout" DOT "png";
static PNG_CONST char *directory_name = "pngcrush" DOT "bak";
static PNG_CONST char *extension = "_C" DOT "png";
static png_uint_32 width, height;
static png_uint_32 measured_idat_length;
static int pngcrush_must_exit=0;
@@ -465,6 +499,15 @@ char text_keyword[800];
char text_lang[800];
char text_lang_key[800];
#endif
#if (PNG_LIBPNG_VER < 10009)
#undef PNG_iCCP_SUPPORTED
#endif
#ifdef PNG_iCCP_SUPPORTED
int iccp_length = 0;
char *iccp_text;
char *iccp_file;
char iccp_name[80];
#endif
int best;
char buffer[256];
@@ -498,8 +541,10 @@ static int verbose=1;
static int help=0;
static int fix=0;
static int things_have_changed=0;
static int global_things_have_changed=0;
static int default_compression_window=15;
static int force_compression_window=0;
static int compression_mem_level=9;
static int final_method=0;
static int brute_force=0;
static int brute_force_level=0;
@@ -562,6 +607,7 @@ static png_infop write_end_info_ptr;
static FILE *fpin, *fpout;
png_uint_32 measure_idats(FILE *fpin);
static int do_color_count;
static int reduction_ok=0;
#ifdef PNGCRUSH_COUNT_COLORS
int count_colors(FILE *fpin);
static int num_rgba, reduce_to_gray, it_is_opaque;
@@ -571,11 +617,15 @@ png_uint_32 png_measure_idat(png_structp png_ptr);
# define MAX_METHODSP1 201
# define DEFAULT_METHODS 10
static png_uint_32 idat_length[MAX_METHODSP1];
static int filter_method, zlib_level;
static int filter_type, zlib_level;
static png_bytep png_row_filters=NULL;
static TIME_T t_start, t_stop, t_decode, t_encode, t_misc;
#if (PNG_LIBPNG_VER >= 10000)
static png_uint_32 max_idat_size = 524288;
#else
static png_uint_32 max_idat_size = PNG_ZBUF_SIZE;
#endif
static png_uint_32 crushed_idat_size = 0x3ffffffL;
static int already_crushed = 0;
int ia;
@@ -622,8 +672,8 @@ png_set_compression_buffer_size(png_structp png_ptr, png_uint_32 size)
png_free(png_ptr, png_ptr->zbuf); png_ptr->zbuf=NULL;
png_ptr->zbuf_size = (png_size_t)size;
png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, size);
if(png_ptr->zbuf)
png_error("Unable to malloc zbuf");
if(!png_ptr->zbuf)
png_error(png_ptr,"Unable to malloc zbuf");
}
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
@@ -1096,7 +1146,7 @@ main(int argc, char *argv[])
else if(!strncmp(argv[i],"-dou",4))
{
double_gamma++;
things_have_changed=1;
global_things_have_changed=1;
}
#endif
else if(!strncmp(argv[i],"-d",2))
@@ -1114,7 +1164,7 @@ main(int argc, char *argv[])
extension= argv[names++];
}
else if(!strncmp(argv[i],"-force",6))
things_have_changed=1;
global_things_have_changed=1;
else if(!strncmp(argv[i],"-fix",4))
fix++;
else if(!strncmp(argv[i],"-f",2))
@@ -1231,12 +1281,46 @@ main(int argc, char *argv[])
help++;
verbose++;
}
else if(!strncmp(argv[i],"-iccp",5))
{
#ifdef PNG_iCCP_SUPPORTED
FILE *iccp_fn;
if(iccp_length)
free(iccp_text);
iccp_length=atoi(argv[++i]);
names+=3;
strcpy(iccp_name,argv[++i]);
iccp_file=argv[++i];
if ((iccp_fn = FOPEN(iccp_file, "rb")) == NULL)
{
fprintf(STDERR, "Could not find file: %s\n", iccp_file);
iccp_length=0;
}
else
{
int ic;
iccp_text=malloc(iccp_length+1);
iccp_text[iccp_length]=(char)0x00;
for (ic=0; ic<iccp_length; ic++)
{
png_size_t num_in;
num_in = fread(buffer, 1, 1, iccp_fn);
if (!num_in)
break;
iccp_text[ic]=buffer[0];
}
}
#else
names+=3;
i+=3;
fprintf(STDERR, "libpng-1.0.9 or later is required to support iCCP.\n");
#endif
}
else if(!strncmp(argv[i],"-max",4))
{
names++;
BUMP_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))
{
@@ -1269,7 +1353,7 @@ main(int argc, char *argv[])
do_pplt++;
BUMP_I;
strcpy(pplt_string,argv[i]);
things_have_changed=1;
global_things_have_changed=1;
}
else if(!strncmp(argv[i],"-p",2))
{
@@ -1277,6 +1361,10 @@ main(int argc, char *argv[])
}
else if(!strncmp(argv[i],"-q",2))
verbose=0;
else if(!strncmp(argv[i],"-reduce",7))
{
reduction_ok++;
}
#ifdef PNG_gAMA_SUPPORTED
else if(!strncmp(argv[i],"-rep",4))
{
@@ -1309,7 +1397,7 @@ main(int argc, char *argv[])
force_specified_gamma=atof(argv[i]);
#endif
}
things_have_changed=1;
global_things_have_changed=1;
}
#endif
#ifdef PNG_pHYs_SUPPORTED
@@ -1318,6 +1406,7 @@ main(int argc, char *argv[])
names++;
BUMP_I;
resolution=atoi(argv[i]);
global_things_have_changed=1;
}
#endif
#ifdef PNGCRUSH_MULTIPLE_ROWS
@@ -1448,11 +1537,14 @@ main(int argc, char *argv[])
#endif
else if(!strncmp(argv[i],"-version",8))
{
fprintf(STDERR,"libpng ");
fprintf(STDERR, " pngcrush ");
fprintf(STDERR, PNGCRUSH_VERSION );
fprintf(STDERR,", uses libpng ");
fprintf(STDERR, PNG_LIBPNG_VER_STRING );
fprintf(STDERR,", uses zlib ");
fprintf(STDERR,"and zlib ");
fprintf(STDERR, ZLIB_VERSION );
fprintf(STDERR,"\n");
fprintf(STDERR, "\n Check http://pmt.sourceforge.net\n");
fprintf(STDERR, " for the most recent version.\n");
}
else if(!strncmp(argv[i],"-v",2))
{
@@ -1464,6 +1556,11 @@ main(int argc, char *argv[])
force_compression_window++;
names++;
}
else if(!strncmp(argv[i],"-zm",3))
{
compression_mem_level=atoi(argv[++i]);
names++;
}
else if(!strncmp(argv[i],"-z",2))
{
int lev, strat, filt;
@@ -1593,7 +1690,12 @@ main(int argc, char *argv[])
if(verbose > 1)
{
png_crush_pause();
fprintf(STDERR, "\noptions:\n");
fprintf(STDERR,
"\noptions (Note: any option can be spelled out for clarity, e.g.,\n");
fprintf(STDERR,
" \"pngcrush -dir New -method 7 -remove bkgd *.png\"\n");
fprintf(STDERR,
" is the same as \"pngcrush -d New -m 7 -rem bkgd *.png\"):\n\n");
}
else
fprintf(STDERR, "options:\n");
@@ -1604,7 +1706,11 @@ main(int argc, char *argv[])
fprintf(STDERR,
"\n If file has an IDAT greater than this size, it\n");
fprintf(STDERR,
" will be considered to be already crushed.\n\n");
" will be considered to be already crushed and will\n");
fprintf(STDERR,
" not be processed, unless you are making other changes\n");
fprintf(STDERR,
" or the \"-force\" option is present.\n\n");
}
fprintf(STDERR,
" -brute (Use brute-force, try 114 different methods [11-124])\n");
@@ -1722,6 +1828,16 @@ main(int argc, char *argv[])
fprintf(STDERR,
" gAMA chunk, use the '-replace_gamma' option.\n\n");
png_crush_pause();
#ifdef PNG_iCCP_SUPPORTED
fprintf(STDERR,
" -iccp length \"Profile Name\" iccp_file\n");
if(verbose > 1)
{
fprintf(STDERR,
"\n file with ICC profile to insert in an iCCP chunk.");
fprintf(STDERR, "\n\n");
}
#endif
#ifdef PNG_iTXt_SUPPORTED
fprintf(STDERR,
" -itxt b[efore_IDAT]|a[fter_IDAT] \"keyword\" \"text\"\n");
@@ -1763,7 +1879,7 @@ main(int argc, char *argv[])
}
fprintf(STDERR,
" -max maximum_IDAT_size [1 through %d]\n",PNG_ZBUF_SIZE);
" -max maximum_IDAT_size [default %d]\n",PNG_ZBUF_SIZE);
if(verbose > 1)
fprintf(STDERR,"\n");
#if 0
@@ -1791,13 +1907,18 @@ main(int argc, char *argv[])
fprintf(STDERR,
"\n Truncates the PLTE. Be sure not to truncate it to\n");
fprintf(STDERR,
"\n less than the greatest index present in IDAT.\n\n");
" less than the greatest index present in IDAT.\n\n");
}
fprintf(STDERR,
" -q (quiet)\n");
if(verbose > 1)
fprintf(STDERR,"\n");
fprintf(STDERR,
" -reduce (do lossless color type or bit depth reduction)\n");
if(verbose > 1)
fprintf(STDERR,
"\n (if possible)\n\n");
fprintf(STDERR,
" -rem chunkname (or \"alla\" or \"allb\")\n");
if(verbose > 1)
@@ -1890,7 +2011,6 @@ main(int argc, char *argv[])
" color type, scaled to the output bit depth.\n\n");
}
#endif
fprintf(STDERR,
" -v (display more detailed information)\n");
if(verbose > 1)
@@ -1899,7 +2019,12 @@ main(int argc, char *argv[])
fprintf(STDERR,
" -version (display the pngcrush version)\n");
if(verbose > 1)
fprintf(STDERR,"\n");
{
fprintf(STDERR,
"\n Look for the most recent version of pngcrush at\n");
fprintf(STDERR,
" http://pmt.sourceforge.net\n\n");
}
fprintf(STDERR,
" -w compression_window_size [32, 16, 8, 4, 2, 1, 512]\n");
if(verbose > 1)
@@ -1923,6 +2048,10 @@ main(int argc, char *argv[])
fprintf(STDERR,
" '-m method' argument.\n\n");
}
fprintf(STDERR,
" -zmem zlib_compression_mem_level [1-9, default 9]\n");
if(verbose > 1)
fprintf(STDERR,"\n");
#ifdef PNG_iTXt_SUPPORTED
fprintf(STDERR,
" -zitxt b[efore_IDAT]|a[fter_IDAT] \"keyword\" \"text\"\n");
@@ -2013,6 +2142,8 @@ main(int argc, char *argv[])
{
first_trial = 1;
things_have_changed=global_things_have_changed;
if(png_row_filters != NULL)
{
free(png_row_filters); png_row_filters=NULL;
@@ -2121,7 +2252,7 @@ main(int argc, char *argv[])
if(already_crushed)
{
fprintf(STDERR, "File has already been crushed: %s\n", inname);
continue;
if(!things_have_changed) continue;
}
if(verbose > 0)
@@ -2142,6 +2273,7 @@ main(int argc, char *argv[])
if (do_color_count)
{
if (force_output_color_type == 8 && (input_color_type == 2 ||
(input_color_type == 3) ||
input_color_type == 4 || input_color_type == 6))
/* check for unused alpha channel or single transparent color */
{
@@ -2298,7 +2430,7 @@ main(int argc, char *argv[])
}
else
{
filter_method=fm[best];
filter_type=fm[best];
zlib_level=lv[best];
if(zs[best] == 0)z_strategy=Z_DEFAULT_STRATEGY;
if(zs[best] == 1)z_strategy=Z_FILTERED;
@@ -2317,7 +2449,7 @@ main(int argc, char *argv[])
if((trial == 6 || trial == 9 || trial == 10) && best_of_three != 3)
continue;
}
filter_method=fm[trial];
filter_type=fm[trial];
zlib_level=lv[trial];
if(zs[trial] == 0)z_strategy=Z_DEFAULT_STRATEGY;
if(zs[trial] == 1)z_strategy=Z_FILTERED;
@@ -2325,7 +2457,7 @@ main(int argc, char *argv[])
final_method=trial;
if(nosave == 0)
P2(" Begin trial %d, filter %d, strategy %d, level %d\n",
trial, filter_method, z_strategy, zlib_level);
trial, filter_type, z_strategy, zlib_level);
}
P2("prepare to open files.\n");
@@ -2463,7 +2595,7 @@ main(int argc, char *argv[])
}
if(nosave == 0)
{
if(png_get_compression_buffer_size(write_ptr) < max_idat_size)
if(png_get_compression_buffer_size(write_ptr) != max_idat_size)
{
P2("reinitializing write zbuf.\n");
png_set_compression_buffer_size(write_ptr, max_idat_size);
@@ -2511,6 +2643,9 @@ main(int argc, char *argv[])
png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_IF_SAFE,
(png_bytep)NULL, 0);
/* Process the following chunks as if safe-to-copy since it is known that
recompressing the IDAT chunks has no effect on them */
#if !defined(PNG_cHRM_SUPPORTED)
png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS,
(png_bytep)png_cHRM, 1);
@@ -2593,30 +2728,44 @@ main(int argc, char *argv[])
#endif /* PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED */
png_debug(0, "Reading info struct\n");
{
png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
png_read_data(read_ptr, png_signature, 8);
png_set_sig_bytes(read_ptr, 8);
if (png_sig_cmp(png_signature, 0, 8))
{
if (png_sig_cmp(png_signature, 0, 4))
png_error(read_ptr, "Not a PNG file!");
else
png_error(read_ptr, "PNG file corrupted by ASCII conversion");
}
}
png_read_info(read_ptr, read_info_ptr);
#if (PNG_LIBPNG_VER > 90)
png_debug(0, "Transferring info struct\n");
{
int interlace_type, compression_type, filter_type;
int interlace_method, compression_method, filter_method;
if (png_get_IHDR(read_ptr, read_info_ptr, &width, &height, &bit_depth,
&color_type, &interlace_type, &compression_type, &filter_type))
&color_type, &interlace_method, &compression_method, &filter_method))
{
int compression_window;
int need_expand = 0;
int output_interlace_type=interlace_type;
int output_interlace_method=interlace_method;
input_color_type=color_type;
input_bit_depth=bit_depth;
if(nointerlace)
output_interlace_type=0;
output_interlace_method=0;
if(verbose > 1 && first_trial)
{
fprintf(STDERR, " IHDR chunk data:\n");
fprintf(STDERR, " Width=%ld, height=%ld\n", width, height);
fprintf(STDERR, " Bit depth =%d\n", bit_depth);
fprintf(STDERR, " Color type=%d\n", color_type);
fprintf(STDERR, " Interlace =%d\n", interlace_type);
fprintf(STDERR, " Interlace =%d\n", interlace_method);
}
if(output_color_type > 7)
@@ -2720,6 +2869,7 @@ main(int argc, char *argv[])
int channels=0;
png_set_compression_strategy(write_ptr, z_strategy);
png_set_compression_mem_level(write_ptr, compression_mem_level);
if (output_color_type == 0)channels=1;
if (output_color_type == 2)channels=3;
@@ -2757,10 +2907,10 @@ main(int argc, char *argv[])
fprintf(STDERR, " Setting IHDR\n");
png_set_IHDR(write_ptr, write_info_ptr, width, height,
output_bit_depth, output_color_type, output_interlace_type,
compression_type, filter_type);
output_bit_depth, output_color_type, output_interlace_method,
compression_method, filter_method);
if(output_color_type != input_color_type) things_have_changed++;
if(output_color_type != input_color_type) things_have_changed=1;
}
}
#if defined(PNG_READ_bKGD_SUPPORTED) && defined(PNG_WRITE_bKGD_SUPPORTED)
@@ -2953,15 +3103,26 @@ main(int argc, char *argv[])
png_charp name;
png_charp profile;
png_uint_32 proflen;
int compression_type;
int compression_method;
if (png_get_iCCP(read_ptr, read_info_ptr, &name, &compression_type,
if (png_get_iCCP(read_ptr, read_info_ptr, &name, &compression_method,
&profile, &proflen))
{
P1 ("Got iccp chunk, proflen=%lu\n",proflen);
if(keep_chunk("iCCP",argv))
png_set_iCCP(write_ptr, write_info_ptr, name, compression_type,
png_set_iCCP(write_ptr, write_info_ptr, name, compression_method,
profile, proflen);
}
#ifdef PNG_iCCP_SUPPORTED
else if (iccp_length)
{
png_set_iCCP(write_ptr, write_info_ptr, iccp_name, 0,
iccp_text, iccp_length);
P1 ("Wrote iccp chunk, proflen=%d\n",iccp_length);
}
#endif
}
#endif
#if defined(PNG_READ_oFFs_SUPPORTED) && defined(PNG_WRITE_oFFs_SUPPORTED)
@@ -3014,11 +3175,19 @@ main(int argc, char *argv[])
{
if (png_get_pHYs(read_ptr, read_info_ptr, &res_x, &res_y,
&unit_type))
{
if(res_x == 0 && res_y == 0)
{
if(verbose > 0 && first_trial)
fprintf(STDERR, " Deleting useless pHYs 0 0 chunk\n");
}
else
{
if(keep_chunk("pHYs",argv))
png_set_pHYs(write_ptr, write_info_ptr, res_x, res_y, unit_type);
}
}
}
else
{
unit_type=1;
@@ -3366,12 +3535,12 @@ main(int argc, char *argv[])
{
png_set_compression_level(write_ptr, zlib_level);
if (filter_method == 0)png_set_filter(write_ptr,0,PNG_FILTER_NONE);
else if(filter_method == 1)png_set_filter(write_ptr,0,PNG_FILTER_SUB);
else if(filter_method == 2)png_set_filter(write_ptr,0,PNG_FILTER_UP);
else if(filter_method == 3)png_set_filter(write_ptr,0,PNG_FILTER_AVG);
else if(filter_method == 4)png_set_filter(write_ptr,0,PNG_FILTER_PAETH);
else if(filter_method == 5)png_set_filter(write_ptr,0,PNG_ALL_FILTERS);
if (filter_type == 0)png_set_filter(write_ptr,0,PNG_FILTER_NONE);
else if(filter_type == 1)png_set_filter(write_ptr,0,PNG_FILTER_SUB);
else if(filter_type == 2)png_set_filter(write_ptr,0,PNG_FILTER_UP);
else if(filter_type == 3)png_set_filter(write_ptr,0,PNG_FILTER_AVG);
else if(filter_type == 4)png_set_filter(write_ptr,0,PNG_FILTER_PAETH);
else if(filter_type == 5)png_set_filter(write_ptr,0,PNG_ALL_FILTERS);
else png_set_filter(write_ptr,0,PNG_FILTER_NONE);
@@ -3464,7 +3633,7 @@ main(int argc, char *argv[])
{
/* check for sufficient memory: we need 2*zlib_window
and, if filter_method == 5, 4*rowbytes in separate allocations.
and, if filter_type == 5, 4*rowbytes in separate allocations.
If it's not enough we can drop the "average" filter and
we can reduce the zlib_window for writing. We can't change
the input zlib_window because the input file might have
@@ -3766,6 +3935,8 @@ main(int argc, char *argv[])
if(nosave)
break;
first_trial=0;
if (nosave == 0)
{
png_debug(0, "Opening file for length measurement\n");
@@ -3789,11 +3960,10 @@ main(int argc, char *argv[])
{
fprintf(STDERR,
" IDAT length with method %d (fm %d zl %d zs %d)= %8lu\n",
trial,filter_method,zlib_level,z_strategy,idat_length[trial]);
trial,filter_type,zlib_level,z_strategy,idat_length[trial]);
fflush(STDERR);
}
first_trial=0;
} /* end of trial-loop */
if (fpin)
@@ -3847,6 +4017,10 @@ main(int argc, char *argv[])
free(png_row_filters); png_row_filters=NULL;
}
if(verbose > 0) show_result();
#ifdef PNG_iCCP_SUPPORTED
if(iccp_length)
free(iccp_text);
#endif
if(pngcrush_must_exit)
exit(0);
return(0);
@@ -3874,6 +4048,7 @@ measure_idats(FILE *fpin)
#else
png_set_read_fn(read_ptr, (png_voidp)fpin, png_default_read_data);
#endif
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);
@@ -3898,7 +4073,6 @@ png_measure_idat(png_structp png_ptr)
/* Copyright (C) 1999, 2000 Glenn Randers-Pehrson (randeg@alum.rpi.edu)
See notice in pngcrush.c for conditions of use and distribution */
png_uint_32 sum_idat_length=0;
png_debug(1, "in png_read_info\n");
{
png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
@@ -3909,7 +4083,7 @@ png_measure_idat(png_structp png_ptr)
if (png_sig_cmp(png_signature, 0, 8))
{
if (png_sig_cmp(png_signature, 0, 4))
png_error(png_ptr, "Not a PNG file");
png_error(png_ptr, "Not a PNG file..");
else
png_error(png_ptr, "PNG file corrupted by ASCII conversion");
}
@@ -3927,7 +4101,11 @@ png_measure_idat(png_structp png_ptr)
PNG_IDAT;
PNG_IEND;
PNG_IHDR;
#ifdef PNG_iCCP_SUPPORTED
PNG_iCCP;
#else
const png_byte png_iCCP[5]={105, 67, 67, 80, '\0'};
#endif
#endif
#endif
png_byte chunk_name[5];
@@ -3970,6 +4148,7 @@ png_measure_idat(png_structp png_ptr)
input_color_type=buffer[9];
}
#ifdef PNG_iCCP_SUPPORTED
/* check for bad photoshop iccp chunk */
#ifdef PNG_UINT_IDAT
if (png_get_uint_32(chunk_name) == PNG_UINT_iCCP)
@@ -3977,6 +4156,12 @@ png_measure_idat(png_structp png_ptr)
if (!png_memcmp(chunk_name, png_iCCP, 4))
#endif
{
/* Check for bad Photoshop iCCP chunk. Libpng will reject the
* bad chunk because the Adler-32 bytes are missing, but we check
* here to see if it's really the sRGB profile, and if so, set the
* "intent" flag and gamma so pngcrush will write an sRGB chunk
* and a gamma chunk.
*/
if (length == 2615)
{
png_crc_read(png_ptr, buffer, 22);
@@ -3997,6 +4182,7 @@ png_measure_idat(png_structp png_ptr)
}
}
}
#endif
png_crc_finish(png_ptr, length);
@@ -4016,8 +4202,9 @@ count_colors(FILE *fpin)
{
/* Copyright (C) 2000 Glenn Randers-Pehrson (randeg@alum.rpi.edu)
See notice in pngcrush.c for conditions of use and distribution */
int bit_depth, color_type, interlace_type, filter_type, compression_type;
png_uint_32 rowbytes, channels;
int bit_depth, color_type, interlace_method, filter_method, compression_method;
png_uint_32 rowbytes;
volatile png_uint_32 channels;
int i;
int pass, num_pass;
@@ -4025,6 +4212,7 @@ count_colors(FILE *fpin)
volatile int result, hashmiss, hashinserts;
png_uint_32 rgba_frequency[257];
png_uint_32 rgba_hi[257]; /* Actually contains ARGB not RGBA */
#if 0
png_uint_32 rgba_lo[257]; /* Low bytes of ARGB in 16-bit PNGs */
@@ -4053,7 +4241,9 @@ count_colors(FILE *fpin)
num_rgba=0;
for (i=0; i<257; i++)
{
rgba_frequency[i]=0;
}
P2("Checking alphas:\n");
png_debug(0, "Allocating read structure\n");
@@ -4075,10 +4265,12 @@ count_colors(FILE *fpin)
#ifdef USE_HASHCODE
int hash[16385];
#endif
#ifdef USE_HASHCODE
for (i=0; i<16385; i++)
hash[i]=-1;
#endif
end_info_ptr = NULL;
#if !defined(PNG_NO_STDIO)
@@ -4087,6 +4279,20 @@ count_colors(FILE *fpin)
png_set_read_fn(read_ptr, (png_voidp)fpin, png_default_read_data);
#endif
{
png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
png_read_data(read_ptr, png_signature, 8);
png_set_sig_bytes(read_ptr, 8);
if (png_sig_cmp(png_signature, 0, 8))
{
if (png_sig_cmp(png_signature, 0, 4))
png_error(read_ptr, "Not a PNG file.");
else
png_error(read_ptr, "PNG file corrupted by ASCII conversion");
}
}
png_read_info(read_ptr, read_info_ptr);
#ifdef PNG_CRC_QUIET_USE
@@ -4094,7 +4300,7 @@ count_colors(FILE *fpin)
#endif
png_get_IHDR(read_ptr, read_info_ptr, &width, &height, &bit_depth,
&color_type, &interlace_type, &compression_type, &filter_type);
&color_type, &interlace_method, &compression_method, &filter_method);
if (color_type == 2)
channels = 3;
@@ -4106,11 +4312,11 @@ count_colors(FILE *fpin)
channels=1;
if(color_type == 0 || color_type == 3 || color_type == 4)
reduce_to_gray = 0;
reduce_to_gray = 1;
if(bit_depth == 8)
{
if(interlace_type)
if(interlace_method)
num_pass=7;
else
num_pass = 1;
@@ -4126,7 +4332,7 @@ count_colors(FILE *fpin)
png_uint_32 pass_height, pass_width, y;
png_debug(0, "\nBegin Pass\n");
if (interlace_type)
if (interlace_method)
{
pass_height = (height - png_pass_ystart[pass]
+ png_pass_yinc[pass] - 1) / png_pass_yinc[pass];
@@ -4143,7 +4349,8 @@ count_colors(FILE *fpin)
{
png_uint_32 x;
png_read_row(read_ptr, row_buf, (png_bytep)NULL);
if(result < 2 || it_is_opaque || reduce_to_gray)
if(result < 2 || it_is_opaque ||
reduce_to_gray)
{
if(color_type==2)
{
@@ -4160,6 +4367,11 @@ count_colors(FILE *fpin)
if(reduce_to_gray &&
((*(rp)) != (*(rp+1)) || (*(rp)) != (*(rp+2))))
reduce_to_gray=0;
if (result > 1 || !it_is_opaque)
continue;
#ifdef USE_HASHCODE
/*
* R G B mask
@@ -4242,6 +4454,9 @@ count_colors(FILE *fpin)
reduce_to_gray=0;
if(it_is_opaque && (*(rp+3)) != 255)
it_is_opaque=0;
if (result > 1)
continue;
#ifdef USE_HASHCODE
/*
* A R G B mask
@@ -4384,8 +4599,6 @@ count_colors(FILE *fpin)
}
else /* other color type */
{
/* to do: check color type 3 for max sample that is present
and reduce palette if possible */
result=2;
}
}
@@ -4436,14 +4649,30 @@ count_colors(FILE *fpin)
P2 ("hashcode misses=%d, inserts=%d\n",hashmiss,
hashinserts);
}
if(reduce_to_gray)
P1 ("The truecolor image is all gray and will be reduced.\n");
if(color_type == 0 || color_type == 2)
it_is_opaque=0;
if(reduction_ok)
{
if(reduce_to_gray)
P1 ("The truecolor image is all gray and will be reduced.\n");
if(it_is_opaque)
P1 ("The image is opaque and the alpha channel will be removed.\n");
}
else
{
if(reduce_to_gray)
P1 ("The truecolor image is all gray and could be reduced.\n");
if(it_is_opaque)
P1 ("The image is opaque and the alpha channel could be removed.\n");
if (reduce_to_gray || it_is_opaque)
P1 ("Rerun pngcrush with the \"-reduce\" option to do so.\n");
reduce_to_gray = 0;
it_is_opaque = 0;
}
P2 ("Finished checking alphas, result=%d\n",result);
}
ret=result;
return (ret);
}

View File

@@ -26,6 +26,8 @@
# define PNG_USER_MEM_SUPPORTED
#endif
#define MNG_EXTENSIONS_SUPPORTED /* extra filter types */
#ifndef PNG_NO_LEGACY_SUPPORTED
# define PNG_NO_LEGACY_SUPPORTED
#endif

View File

@@ -1,7 +1,7 @@
/* pngerror.c - stub functions for i/o and memory allocation
*
* libpng 1.0.8 - July 24, 2000
* libpng 1.0.9beta2 - November 19, 2000
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)

2124
pnggccrd.c

File diff suppressed because it is too large Load Diff

View File

@@ -1,7 +1,7 @@
/* pngget.c - retrieval of values from info struct
*
* libpng 1.0.8 - July 24, 2000
* libpng 1.0.9beta2 - November 19, 2000
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)

View File

@@ -1,7 +1,7 @@
/* pngmem.c - stub functions for memory allocation
*
* libpng 1.0.8 - July 24, 2000
* libpng 1.0.9beta2 - November 19, 2000
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)

View File

@@ -1,7 +1,7 @@
/* pngpread.c - read a png file in push mode
*
* libpng 1.0.8 - July 24, 2000
* libpng 1.0.9beta2 - November 19, 2000
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
@@ -894,25 +894,25 @@ png_read_push_finish_row(png_structp png_ptr)
/* arrays to facilitate easy interlacing - use pass (0 - 6) as index */
/* start of interlace block */
const int png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
const int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
/* offset to next interlace block */
const int png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
const int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
/* start of interlace block in the y direction */
const int png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
const int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
/* offset to next interlace block in the y direction */
const int png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
const int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
/* Width of interlace block. This is not currently used - if you need
* it, uncomment it here and in png.h
const int png_pass_width[] = {8, 4, 4, 2, 2, 1, 1};
const int FARDATA png_pass_width[] = {8, 4, 4, 2, 2, 1, 1};
*/
/* Height of interlace block. This is not currently used - if you need
* it, uncomment it here and in png.h
const int png_pass_height[] = {8, 8, 4, 4, 2, 2, 1};
const int FARDATA png_pass_height[] = {8, 8, 4, 4, 2, 2, 1};
*/
#endif
@@ -1429,7 +1429,8 @@ png_progressive_combine_row (png_structp png_ptr,
png_bytep old_row, png_bytep new_row)
{
#ifdef PNG_USE_LOCAL_ARRAYS
const int png_pass_dsp_mask[7] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
const int FARDATA png_pass_dsp_mask[7] =
{0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
#endif
if (new_row != NULL) /* new_row must == png_ptr->row_buf here. */
png_combine_row(png_ptr, old_row, png_pass_dsp_mask[png_ptr->pass]);

View File

@@ -1,7 +1,7 @@
/* pngread.c - read a PNG file
*
* libpng 1.0.8 - July 24, 2000
* libpng 1.0.9beta2 - November 19, 2000
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
@@ -440,6 +440,9 @@ png_read_update_info(png_structp png_ptr, png_infop info_ptr)
/* save jump buffer and error functions */
if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
png_read_start_row(png_ptr);
else
png_warning(png_ptr,
"Ignoring extra png_read_update_info() call; row buffer not reallocated");
png_read_transform_info(png_ptr, info_ptr);
}
@@ -698,7 +701,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.8
* [*] png_handle_alpha() does not exist yet, as of libpng version 1.0.9beta2
*/
void PNGAPI
@@ -747,7 +750,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.8
* [*] png_handle_alpha() does not exist yet, as of libpng version 1.0.9beta2
*/
void PNGAPI
png_read_image(png_structp png_ptr, png_bytepp image)

View File

@@ -1,7 +1,7 @@
/* pngrio.c - functions for data input
*
* libpng 1.0.8 - July 24, 2000
* libpng 1.0.9beta2 - November 19, 2000
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)

View File

@@ -1,7 +1,7 @@
/* pngrtran.c - transforms the data in a row for PNG readers
*
* libpng 1.0.8 - July 24, 2000
* libpng 1.0.9beta2 - November 19, 2000
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
@@ -1090,7 +1090,12 @@ png_read_transform_info(png_structp png_ptr, png_infop info_ptr)
if ((png_ptr->transformations & PNG_FILLER) &&
((info_ptr->color_type == PNG_COLOR_TYPE_RGB) ||
(info_ptr->color_type == PNG_COLOR_TYPE_GRAY)))
{
info_ptr->channels++;
#if 0 /* if adding a true alpha channel not just filler */
info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
#endif
}
#endif
#if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) && \

View File

@@ -1,7 +1,7 @@
/* pngrutil.c - utilities to read a PNG file
*
* libpng 1.0.8 - July 24, 2000
* libpng 1.0.9beta2 - November 19, 2000
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
@@ -976,6 +976,8 @@ png_handle_iCCP(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_byte compression_type;
png_charp profile;
png_uint_32 skip = 0;
png_uint_32 profile_size = 0;
png_uint_32 profile_length = 0;
png_size_t slength, prefix_length, data_length;
png_debug(1, "in png_handle_iCCP\n");
@@ -1027,22 +1029,43 @@ png_handle_iCCP(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
/* there should be at least one zero (the compression type byte)
following the separator, and we should be on it */
if (*profile || profile >= chunkdata + slength)
if ( profile >= chunkdata + slength)
{
png_free(png_ptr, chunkdata);
png_warning(png_ptr, "malformed iCCP chunk");
png_warning(png_ptr, "Malformed iCCP chunk");
return;
}
/* compression_type should always be zero */
compression_type = *profile++;
if (compression_type)
{
png_warning(png_ptr, "Ignoring nonzero compression type in iCCP chunk");
compression_type=0x00; /* Reset it to zero (libpng-1.0.6 through 1.0.8
wrote nonzero) */
}
prefix_length = profile - chunkdata;
chunkdata = png_decompress_chunk(png_ptr, compression_type, chunkdata,
slength, prefix_length, &data_length);
profile_length = data_length - prefix_length;
profile_size = ((*(chunkdata+prefix_length))<<24) |
((*(chunkdata+prefix_length+1))<<16) |
((*(chunkdata+prefix_length+2))<< 8) |
((*(chunkdata+prefix_length+3)) );
if(profile_size < profile_length)
profile_length = profile_size;
if(profile_size > profile_length)
{
png_warning(png_ptr, "Ignoring truncated iCCP profile.\n");
return;
}
png_set_iCCP(png_ptr, info_ptr, chunkdata, compression_type,
chunkdata + prefix_length, data_length);
chunkdata + prefix_length, data_length-prefix_length);
png_free(png_ptr, chunkdata);
}
#endif /* PNG_READ_iCCP_SUPPORTED */
@@ -1336,7 +1359,6 @@ png_handle_bKGD(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
if(buf[0] > info_ptr->num_palette)
{
png_warning(png_ptr, "Incorrect bKGD chunk index value");
png_crc_finish(png_ptr, length);
return;
}
png_ptr->background.red =

View File

@@ -1,7 +1,7 @@
/* pngset.c - storage of image information into info struct
*
* libpng 1.0.8 - July 24, 2000
* libpng 1.0.9beta2 - November 19, 2000
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
@@ -741,10 +741,27 @@ png_set_unknown_chunk_location(png_structp png_ptr, png_infop info_ptr,
void PNGAPI
png_permit_empty_plte (png_structp png_ptr, int empty_plte_permitted)
{
png_debug(1, "in png_permit_empty_plte\n");
/* This function is deprecated in favor of png_permit_mng_features()
and will be removed from libpng-2.0.0 */
png_debug(1, "in png_permit_empty_plte, DEPRECATED.\n");
if (png_ptr == NULL)
return;
png_ptr->empty_plte_permitted=(png_byte)empty_plte_permitted;
png_ptr->mng_features_permitted = (png_byte)
((png_ptr->mng_features_permitted & (~(PNG_FLAG_MNG_EMPTY_PLTE))) |
((empty_plte_permitted & PNG_FLAG_MNG_EMPTY_PLTE)));
}
#endif
#if defined(PNG_MNG_FEATURES_SUPPORTED)
png_uint_32 PNGAPI
png_permit_mng_features (png_structp png_ptr, png_uint_32 mng_features)
{
png_debug(1, "in png_permit_mng_features\n");
if (png_ptr == NULL)
return (png_uint_32)0;
png_ptr->mng_features_permitted =
(png_byte)(mng_features & PNG_ALL_MNG_FEATURES);
return (png_uint_32)png_ptr->mng_features_permitted;
}
#endif
@@ -825,6 +842,8 @@ png_set_compression_buffer_size(png_structp png_ptr, png_uint_32 size)
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(!png_ptr->zbuf)
png_error(png_ptr,"Unable to malloc zbuf");
png_ptr->zstream.next_out = png_ptr->zbuf;
png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
}

View File

@@ -1,7 +1,7 @@
/* pngtrans.c - transforms the data in a row (used by both readers and writers)
*
* libpng 1.0.8 - July 24, 2000
* libpng 1.0.9beta2 - November 19, 2000
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)

View File

@@ -2,7 +2,7 @@
*
* For Intel x86 CPU and Microsoft Visual C++ compiler
*
* libpng 1.0.8 - July 24, 2000
* libpng 1.0.9beta2 - November 19, 2000
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
* Copyright (c) 1998, Intel Corporation
@@ -10,6 +10,8 @@
* Contributed by Nirav Chhatrapati, Intel Corporation, 1998
* Interface to libpng contributed by Gilles Vollant, 1999
*
* [png_read_filter_row_mmx_avg() bpp == 2 bugfix, GRR 20000916]
*
*/
#define PNG_INTERNAL
@@ -2117,8 +2119,8 @@ davg4lp:
case 2:
{
ActiveMask.use = 0x000000000000ffff;
ShiftBpp.use = 24; // == 3 * 8
ShiftRem.use = 40; // == 64 - 24
ShiftBpp.use = 16; // == 2 * 8 [BUGFIX]
ShiftRem.use = 48; // == 64 - 16 [BUGFIX]
_asm {
// Load ActiveMask
movq mm7, ActiveMask
@@ -2133,7 +2135,7 @@ davg4lp:
// (we correct position in loop below)
davg2lp:
movq mm0, [edi + ebx]
psllq mm2, ShiftRem // shift data to position correctly
psrlq mm2, ShiftRem // shift data to position correctly [BUGFIX]
movq mm1, [esi + ebx]
// Add (Prev_row/2) to Average
movq mm3, mm5

View File

@@ -1,7 +1,7 @@
/* pngwio.c - functions for data output
*
* libpng 1.0.8 - July 24, 2000
* libpng 1.0.9beta2 - November 19, 2000
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)

View File

@@ -1,7 +1,7 @@
/* pngwrite.c - general routines to write a PNG file
*
* libpng 1.0.8 - July 24, 2000
* libpng 1.0.9beta2 - November 19, 2000
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
@@ -964,7 +964,6 @@ void PNGAPI
png_set_filter(png_structp png_ptr, int method, int filters)
{
png_debug(1, "in png_set_filter\n");
/* We allow 'method' only for future expansion of the base filter method. */
if (method == PNG_FILTER_TYPE_BASE)
{
switch (filters & (PNG_ALL_FILTERS | 0x07))

View File

@@ -1,7 +1,7 @@
/* pngwtran.c - transforms the data in a row for PNG writers
*
* libpng 1.0.8 - July 24, 2000
* libpng 1.0.9beta2 - November 19, 2000
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)

View File

@@ -1,7 +1,7 @@
/* pngwutil.c - utilities to write a PNG file
*
* libpng 1.0.8 - July 24, 2000
* libpng 1.0.9beta2 - November 19, 2000
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
@@ -514,8 +514,8 @@ png_write_PLTE(png_structp png_ptr, png_colorp palette, png_uint_32 num_pal)
png_debug(1, "in png_write_PLTE\n");
if ((
#ifdef PNG_WRITE_EMPTY_PLTE_SUPPORTED
!png_ptr->empty_plte_permitted &&
#if defined(PNG_MNG_FEATURES_SUPPORTED)
!(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) &&
#endif
num_pal == 0) || num_pal > 256)
{
@@ -670,6 +670,7 @@ png_write_iCCP(png_structp png_ptr, png_charp name, int compression_type,
/* make sure we include the NULL after the name and the compression type */
png_write_chunk_start(png_ptr, (png_bytep)png_iCCP,
(png_uint_32)name_len+profile_len+2);
new_name[name_len+1]=0x00;
png_write_chunk_data(png_ptr, (png_bytep)new_name, name_len + 2);
if (profile_len)
@@ -996,9 +997,9 @@ png_write_bKGD(png_structp png_ptr, png_color_16p back, int color_type)
if (color_type == PNG_COLOR_TYPE_PALETTE)
{
if (
#ifdef PNG_WRITE_EMPTY_PLTE_SUPPORTED
(!png_ptr->empty_plte_permitted ||
(png_ptr->empty_plte_permitted && png_ptr->num_palette)) &&
#if defined(PNG_MNG_FEATURES_SUPPORTED)
(png_ptr->num_palette ||
(!(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE))) &&
#endif
back->index > png_ptr->num_palette)
{
@@ -1083,7 +1084,7 @@ png_check_keyword(png_structp png_ptr, png_charp key, png_charpp new_key)
png_debug1(2, "Keyword to be checked is '%s'\n", key);
*new_key = (png_charp)png_malloc(png_ptr, (png_uint_32)(key_len + 1));
*new_key = (png_charp)png_malloc(png_ptr, (png_uint_32)(key_len + 2));
/* Replace non-printing characters with a blank and print a warning */
for (kp = key, dp = *new_key; *kp != '\0'; kp++, dp++)
@@ -2553,6 +2554,7 @@ png_write_filtered_row(png_structp png_ptr, png_bytep filtered_row)
png_debug(1, "in png_write_filtered_row\n");
png_debug1(2, "filter = %d\n", filtered_row[0]);
/* set up the zlib input buffer */
png_ptr->zstream.next_in = filtered_row;
png_ptr->zstream.avail_in = (uInt)png_ptr->row_info.rowbytes + 1;
/* repeat until we have compressed all the data */