summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn Randers-Pehrson <glennrp at users.sourceforge.net>2014-12-22 11:50:18 -0600
committerGlenn Randers-Pehrson <glennrp at users.sourceforge.net>2014-12-22 11:50:18 -0600
commitc4a27f3e8c188a7f0ac1044bb1e1384ef5ad69cb (patch)
tree1c9a3bf0f37ac319f1ede7edeb820b377c07b1ab
parentf99e4436b0ef993233a269b7b40e3be9aa984d45 (diff)
downloadlibpng-c4a27f3e8c188a7f0ac1044bb1e1384ef5ad69cb.tar.gz
[pngcrush] Updated libpng to version 1.6.16v1.7.82
-rw-r--r--png.c49
-rw-r--r--png.h23
-rw-r--r--pngconf.h2
-rw-r--r--pngcrush.c518
-rw-r--r--pngcrush.h2
-rw-r--r--pnglibconf.h4
-rw-r--r--pngrutil.c12
7 files changed, 336 insertions, 274 deletions
diff --git a/png.c b/png.c
index 62cc4bc6a..4d93dfa91 100644
--- a/png.c
+++ b/png.c
@@ -1,7 +1,7 @@
/* png.c - location for general purpose libpng functions
*
- * Last changed in libpng 1.6.15 [November 20, 2014]
+ * Last changed in libpng 1.6.16 [December 22, 2014]
* Copyright (c) 1998-2014 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.)
@@ -14,7 +14,7 @@
#include "pngpriv.h"
/* Generate a compiler error if there is an old png.h in the search path. */
-typedef png_libpng_version_1_6_15 Your_png_h_is_not_version_1_6_15;
+typedef png_libpng_version_1_6_16 Your_png_h_is_not_version_1_6_16;
/* Tells libpng that we have already handled the first "num_bytes" bytes
* of the PNG file signature. If the PNG data is embedded into another
@@ -769,13 +769,13 @@ png_get_copyright(png_const_structrp png_ptr)
#else
# ifdef __STDC__
return PNG_STRING_NEWLINE \
- "libpng version 1.6.15 - November 20, 2014" PNG_STRING_NEWLINE \
+ "libpng version 1.6.16 - December 22, 2014" PNG_STRING_NEWLINE \
"Copyright (c) 1998-2014 Glenn Randers-Pehrson" PNG_STRING_NEWLINE \
"Copyright (c) 1996-1997 Andreas Dilger" PNG_STRING_NEWLINE \
"Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc." \
PNG_STRING_NEWLINE;
# else
- return "libpng version 1.6.15 - November 20, 2014\
+ return "libpng version 1.6.16 - December 22, 2014\
Copyright (c) 1998-2014 Glenn Randers-Pehrson\
Copyright (c) 1996-1997 Andreas Dilger\
Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.";
@@ -1075,7 +1075,7 @@ png_colorspace_set_gamma(png_const_structrp png_ptr,
png_colorspacerp colorspace, png_fixed_point gAMA)
{
/* Changed in libpng-1.5.4 to limit the values to ensure overflow can't
- * occur. Since the fixed point representation is assymetrical it is
+ * occur. Since the fixed point representation is asymetrical it is
* possible for 1/gamma to overflow the limit of 21474 and this means the
* gamma value must be at least 5/100000 and hence at most 20000.0. For
* safety the limits here are a little narrower. The values are 0.00016 to
@@ -1324,7 +1324,7 @@ png_XYZ_from_xy(png_XYZ *XYZ, const png_xy *xy)
* (1/white-y), so we can immediately see that as white-y approaches 0 the
* accuracy inherent in the cHRM chunk drops off substantially.
*
- * libpng arithmetic: a simple invertion of the above equations
+ * libpng arithmetic: a simple inversion of the above equations
* ------------------------------------------------------------
*
* white_scale = 1/white-y
@@ -1817,7 +1817,7 @@ png_icc_profile_error(png_const_structrp png_ptr, png_colorspacerp colorspace,
PNG_UNUSED(pos)
/* This is recoverable, but make it unconditionally an app_error on write to
- * avoid writing invalid ICC profiles into PNG files. (I.e. we handle them
+ * avoid writing invalid ICC profiles into PNG files (i.e., we handle them
* on read, with a warning, but on write unless the app turns off
* application errors the PNG won't be written.)
*/
@@ -1836,7 +1836,7 @@ png_colorspace_set_sRGB(png_const_structrp png_ptr, png_colorspacerp colorspace,
/* sRGB sets known gamma, end points and (from the chunk) intent. */
/* IMPORTANT: these are not necessarily the values found in an ICC profile
* because ICC profiles store values adapted to a D50 environment; it is
- * expected that the ICC profile mediaWhitePointTag will be D50, see the
+ * expected that the ICC profile mediaWhitePointTag will be D50; see the
* checks and code elsewhere to understand this better.
*
* These XYZ values, which are accurate to 5dp, produce rgb to gray
@@ -2461,6 +2461,17 @@ png_colorspace_set_rgb_coefficients(png_structrp png_ptr)
#endif /* COLORSPACE */
+#ifdef __GNUC__
+/* This exists solely to work round a warning from GNU C. */
+static int /* PRIVATE */
+png_gt(size_t a, size_t b)
+{
+ return a > b;
+}
+#else
+# define png_gt(a,b) ((a) > (b))
+#endif
+
void /* PRIVATE */
png_check_IHDR(png_const_structrp png_ptr,
png_uint_32 width, png_uint_32 height, int bit_depth,
@@ -2480,6 +2491,28 @@ png_check_IHDR(png_const_structrp png_ptr,
png_warning(png_ptr, "Invalid image width in IHDR");
error = 1;
}
+
+ else if (png_gt(width,
+ (PNG_SIZE_MAX >> 3) /* 8-byte RGBA pixels */
+ - 48 /* big_row_buf hack */
+ - 1 /* filter byte */
+ - 7*8 /* rounding width to multiple of 8 pix */
+ - 8)) /* extra max_pixel_depth pad */
+ {
+ /* The size of the row must be within the limits of this architecture.
+ * Because the read code can perform arbitrary transformations the
+ * maximum size is checked here. Because the code in png_read_start_row
+ * adds extra space "for safety's sake" in several places a conservative
+ * limit is used here.
+ *
+ * NOTE: it would be far better to check the size that is actually used,
+ * but the effect in the real world is minor and the changes are more
+ * extensive, therefore much more dangerous and much more difficult to
+ * write in a way that avoids compiler warnings.
+ */
+ png_warning(png_ptr, "Image width is too large for this architecture");
+ error = 1;
+ }
else
{
# ifdef PNG_SET_USER_LIMITS_SUPPORTED
diff --git a/png.h b/png.h
index e8602f653..997130d38 100644
--- a/png.h
+++ b/png.h
@@ -1,7 +1,7 @@
/* png.h - header file for PNG reference library
*
- * libpng version 1.6.15, November 20, 2014
+ * libpng version 1.6.16, December 22, 2014
* Copyright (c) 1998-2014 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
@@ -11,7 +11,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.6.15, November 20, 2014: Glenn
+ * libpng versions 0.97, January 1998, through 1.6.16, December 22, 2014: Glenn
* See also "Contributing Authors", below.
*
* Note about libpng version numbers:
@@ -209,6 +209,9 @@
* 1.6.15beta01-08 16 10615 16.so.16.15[.0]
* 1.6.15rc01-03 16 10615 16.so.16.15[.0]
* 1.6.15 16 10615 16.so.16.15[.0]
+ * 1.6.16beta01-03 16 10616 16.so.16.16[.0]
+ * 1.6.16rc01-02 16 10616 16.so.16.16[.0]
+ * 1.6.16 16 10616 16.so.16.16[.0]
*
* Henceforth the source version will match the shared-library major
* and minor numbers; the shared-library major version number will be
@@ -240,7 +243,7 @@
*
* This code is released under the libpng license.
*
- * libpng versions 1.2.6, August 15, 2004, through 1.6.15, November 20, 2014, are
+ * libpng versions 1.2.6, August 15, 2004, through 1.6.16, December 22, 2014, are
* Copyright (c) 2004, 2006-2014 Glenn Randers-Pehrson, and are
* distributed according to the same disclaimer and license as libpng-1.2.5
* with the following individual added to the list of Contributing Authors:
@@ -352,13 +355,13 @@
* Y2K compliance in libpng:
* =========================
*
- * November 20, 2014
+ * December 22, 2014
*
* 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.6.15 are Y2K compliant. It is my belief that
+ * upward through 1.6.16 are Y2K compliant. It is my belief that
* earlier versions were also Y2K compliant.
*
* Libpng only has two year fields. One is a 2-byte unsigned integer
@@ -420,9 +423,9 @@
*/
/* Version information for png.h - this should match the version in png.c */
-#define PNG_LIBPNG_VER_STRING "1.6.15"
+#define PNG_LIBPNG_VER_STRING "1.6.16"
#define PNG_HEADER_VERSION_STRING \
- " libpng version 1.6.15 - November 20, 2014\n"
+ " libpng version 1.6.16 - December 22, 2014\n"
#define PNG_LIBPNG_VER_SONUM 16
#define PNG_LIBPNG_VER_DLLNUM 16
@@ -430,7 +433,7 @@
/* These should match the first 3 components of PNG_LIBPNG_VER_STRING: */
#define PNG_LIBPNG_VER_MAJOR 1
#define PNG_LIBPNG_VER_MINOR 6
-#define PNG_LIBPNG_VER_RELEASE 15
+#define PNG_LIBPNG_VER_RELEASE 16
/* This should match the numeric part of the final component of
* PNG_LIBPNG_VER_STRING, omitting any leading zero:
@@ -461,7 +464,7 @@
* 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 10615 /* 1.6.15 */
+#define PNG_LIBPNG_VER 10616 /* 1.6.16 */
/* Library configuration: these options cannot be changed after
* the library has been built.
@@ -566,7 +569,7 @@ extern "C" {
/* This triggers a compiler error in png.c, if png.c and png.h
* do not agree upon the version number.
*/
-typedef char* png_libpng_version_1_6_15;
+typedef char* png_libpng_version_1_6_16;
/* Basic control structions. Read libpng-manual.txt or libpng.3 for more info.
*
diff --git a/pngconf.h b/pngconf.h
index c043e9349..3637c1427 100644
--- a/pngconf.h
+++ b/pngconf.h
@@ -1,7 +1,7 @@
/* pngconf.h - machine configurable file for libpng
*
- * libpng version 1.6.15,November 20, 2014
+ * libpng version 1.6.16,December 22, 2014
*
* Copyright (c) 1998-2014 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
diff --git a/pngcrush.c b/pngcrush.c
index 3daf8dbdb..d1f4b5dd5 100644
--- a/pngcrush.c
+++ b/pngcrush.c
@@ -80,7 +80,7 @@
*
*/
-#define PNGCRUSH_VERSION "1.7.81"
+#define PNGCRUSH_VERSION "1.7.82"
/* Experimental: define these if you wish, but, good luck.
#define PNGCRUSH_COUNT_COLORS
@@ -308,8 +308,11 @@
Change log:
+Version 1.7.82 (built with libpng-1.6.16 and zlib-1.2.8)
+
Version 1.7.81 (built with libpng-1.6.15 and zlib-1.2.8)
- Fixed off-by-one error in calculation of plte_len. Bug report by Ivan Kuchin.
+ Fixed off-by-one error in calculation of plte_len. Bug reports by
+ Ivan Kuchin and Frederic Kayser.
Version 1.7.80 (built with libpng-1.6.14 and zlib-1.2.8)
Added "-reduce_palette" and "-noreduce_palette" options. Enable
@@ -1709,8 +1712,13 @@ static png_uint_32 pngcrush_best_byte_count=0xffffffff;
static int verbose = 1;
static int salvage = 0;
static int bail = 0; /* if 0, bail out of trials early */
+
+
static int blacken = 0; /* if 0, or 2 after the first trial,
do not blacken color samples */
+
+/* Delete these in pngcrush-1.8.0 */
+#if 1
static int make_gray = 0; /* if 0, 2, or 3 after the first trial,
do not change color_type to gray */
static int make_opaque = 0; /* if 0, 2, or 3 after the first trial,
@@ -1718,8 +1726,29 @@ static int make_opaque = 0; /* if 0, 2, or 3 after the first trial,
static int make_8_bit = 0; /* if 0, 2, or 3 after the first trial,
do not reduce bit_depth from 16 */
static int reduce_palette = 0;
+#endif
+
+/* Activate these in pngcrush-1.8.0 */
+#if 0
+static int make_gray = 1; /* if 0, 2, or 3 after the first trial,
+ do not change color_type to gray */
+static int make_opaque = 1; /* if 0, 2, or 3 after the first trial,
+ do not change color_type to opaque */
+static int make_8_bit = 1; /* if 0, 2, or 3 after the first trial,
+ do not reduce bit_depth from 16 */
+static int reduce_palette = 1;
+#endif
+
+/* TO DO: do this another way. "things_have_changed" is an attempt
+ * to preserve the IDAT from the original file (by preserving the
+ * entire input file) when it is smaller than that achieved by any
+ * of the pngcrush trials. Better would be to handle the editing
+ * functions separately from the compression, i.e., just preserve
+ * the IDAT from the original file if it is smaller than any trial.
+ */
static int things_have_changed = 0;
static int global_things_have_changed = 0;
+
static int compression_window;
static int default_compression_window = 15;
static int force_compression_window = 0;
@@ -2120,7 +2149,7 @@ pngcrush_default_read_data(png_structp png_ptr, png_bytep data,
#if 0
if (salvage)
{
- found_IDAT == 1)
+ if (found_IDAT == 1)
{
/* replace first two bytes */
printf(" Input CMF = 0x%x,0x%x\n",buf[0],buf[1]);
@@ -2552,8 +2581,9 @@ int keep_chunk(png_const_charp name, char *argv[])
allb++; /* all ancillaries but gamma... */
if (!strncmp(argv[i], "alla", 4))
alla++; /* ...no, all ancillaries, period */
- } else if (!strncmp(argv[i], "text", 4))
+ } else if (!strncmp(argv[i], "text", 4)) {
allt++; /* all forms of text chunk */
+ }
if (!strncmp(argv[i], name, 4) /* exact chunk-name match in args
* ...or exact match for one of known set, plus args included
* either "alla", "allb", or all-lowercase form of "name": */
@@ -2604,7 +2634,7 @@ int keep_chunk(png_const_charp name, char *argv[])
|| (!strncmp(name, "zTXt", 4)
&& (!strncmp(argv[i], "ztxt", 4) || allt)) )
{
- things_have_changed = 1;
+ global_things_have_changed = 1;
/* (caller actually does the removal--by failing to create
* copy) */
if (verbose > 0 && last_trial)
@@ -4317,22 +4347,6 @@ int main(int argc, char *argv[])
}
output_color_type = force_output_color_type;
-#if 0
- /* TO DO: have we got the right plte_len now? */
- if (plte_len > 0 && output_color_type == 3 &&
- force_output_bit_depth == 0)
- {
- if (plte_len <= 2)
- force_output_bit_depth = 1;
- else if (plte_len <= 4)
- force_output_bit_depth = 2;
- else if (plte_len <= 16)
- force_output_bit_depth = 4;
- else
- force_output_bit_depth = 8;
- }
-#endif /* 0 */
-
output_bit_depth = force_output_bit_depth;
if (!methods_specified || try10 != 0)
@@ -4340,21 +4354,15 @@ int main(int argc, char *argv[])
for (i = 0; i <= DEFAULT_METHODS; i++)
try_method[i] = 0;
- /*
- Uncomment these in pngcrush-1.8.0
- make_gray = 1;
- make_opaque = 1;
- make_8_bit = 1;
- */
try_method[6] = try10;
}
best_of_three = 1;
pngcrush_best_byte_count=0xffffffff;
- if (blacken)
+ if (blacken == 1 || make_gray == 1 || make_opaque == 1 ||
+ reduce_palette == 1)
{
- blacken = 1;
try_method[0] = 0;
}
@@ -4384,7 +4392,7 @@ int main(int argc, char *argv[])
(found_sBIT_different_RGB_bits &&
keep_unknown_chunk("sBIT", argv)))
{
- fprintf(STDERR, "Cannot change colortype to gray when iCCP,"
+ P1 ("Cannot change colortype to gray when iCCP,"
" acTL, bKGD with color, or sBIT chunk is present\n");
make_gray = 0;
}
@@ -4399,7 +4407,7 @@ int main(int argc, char *argv[])
{
if (found_tRNS || found_acTL_chunk == 1)
{
- fprintf(STDERR, "Cannot remove the alpha channel when tRNS"
+ P1("Cannot remove the alpha channel when tRNS"
" or acTL chunk is present\n");
make_opaque = 0;
}
@@ -4416,7 +4424,7 @@ int main(int argc, char *argv[])
found_acTL_chunk == 1 ||
(found_sBIT_max > 8 && keep_unknown_chunk("sBIT", argv)))
{
- fprintf(STDERR, "Cannot reduce bit depth to 8 when bKGD,"
+ P1 ("Cannot reduce bit depth to 8 when bKGD,"
" sBIT or acTL chunk is present\n");
make_8_bit = 0;
}
@@ -4432,7 +4440,7 @@ int main(int argc, char *argv[])
if ((found_hIST && keep_unknown_chunk("hIST", argv)) ||
found_acTL_chunk == 1)
{
- fprintf(STDERR, "Cannot reduce palette length when hIST"
+ P1("Cannot reduce palette length when hIST"
" or acTL chunk is present\n");
reduce_palette = 0;
plte_len = -1;
@@ -5152,268 +5160,286 @@ int main(int argc, char *argv[])
P1(" new plte_len = %d\n",plte_len);
}
- /* { GRR added for quick %-navigation (1) */
-
- /* Start of chunk-copying/removal code, in order:
- * - IHDR
- * - bKGD
- * - cHRM
- * - gAMA
- * - sRGB
- * - iCCP
- * - oFFs
- * - pCAL
- * - pHYs
- * - hIST
- * - tRNS
- * - PLTE
- * - sBIT
- * - sCAL
- * - sPLT
- * - sTER
- * - tEXt/zTXt/iTXt
- * - tIME
- * - unknown chunks
- */
- {
- int compression_method,
- filter_method;
+ /* { GRR added for quick %-navigation (1) */
+
+ /* Start of chunk-copying/removal code, in order:
+ * - IHDR
+ * - bKGD
+ * - cHRM
+ * - gAMA
+ * - sRGB
+ * - iCCP
+ * - oFFs
+ * - pCAL
+ * - pHYs
+ * - hIST
+ * - tRNS
+ * - PLTE
+ * - sBIT
+ * - sCAL
+ * - sPLT
+ * - sTER
+ * - tEXt/zTXt/iTXt
+ * - tIME
+ * - unknown chunks
+ */
+ {
+ int compression_method,
+ filter_method;
- P1( "Transferring info struct\n");
+ P1( "Transferring info struct\n");
- if (png_get_IHDR(read_ptr, read_info_ptr, &width, &height,
- &bit_depth, &color_type, &interlace_method,
- &compression_method, &filter_method))
- {
- int need_expand = 0;
- input_color_type = color_type;
- input_bit_depth = bit_depth;
+ if (png_get_IHDR(read_ptr, read_info_ptr, &width, &height,
+ &bit_depth, &color_type, &interlace_method,
+ &compression_method, &filter_method))
+ {
+ int need_expand = 0;
+ input_color_type = color_type;
+ input_bit_depth = bit_depth;
- if (output_color_type > 7)
- {
- output_color_type = input_color_type;
- }
+ if (output_color_type > 7)
+ {
+ output_color_type = input_color_type;
+ }
- /* if (verbose > 1 && last_trial) */
- if (verbose > 1 && trial == 0)
- {
- fprintf(STDERR, " IHDR chunk data:\n");
+ /* if (verbose > 1 && last_trial) */
+ if (verbose > 1 && trial == 0)
+ {
+ fprintf(STDERR, " IHDR chunk data:\n");
+ fprintf(STDERR,
+ " Width=%lu, height=%lu\n",
+ (unsigned long)width,
+ (unsigned long)height);
+ fprintf(STDERR, " Bit depth =%d\n",
+ bit_depth);
+ fprintf(STDERR, " Color type=%d\n",
+ color_type);
+ if (output_color_type != color_type)
fprintf(STDERR,
- " Width=%lu, height=%lu\n",
- (unsigned long)width,
- (unsigned long)height);
- fprintf(STDERR, " Bit depth =%d\n",
- bit_depth);
- fprintf(STDERR, " Color type=%d\n",
- color_type);
- if (output_color_type != color_type)
- fprintf(STDERR,
- " Output color type=%d\n",
- output_color_type);
- fprintf(STDERR, " Interlace =%d\n",
- interlace_method);
- }
-
+ " Output color type=%d\n",
+ output_color_type);
+ fprintf(STDERR, " Interlace =%d\n",
+ interlace_method);
+ }
- output_bit_depth = input_bit_depth;
+ output_bit_depth = input_bit_depth;
- if ((output_color_type != 3 || output_bit_depth > 8)
- && output_bit_depth >= 8
- && output_bit_depth > input_bit_depth)
- need_expand = 1;
+ if ((output_color_type != 3 || output_bit_depth > 8)
+ && output_bit_depth >= 8
+ && output_bit_depth > input_bit_depth)
+ need_expand = 1;
#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
- if ((color_type == 2 ||
- color_type == 6 ||
- color_type == 3) &&
- (output_color_type == 0 ||
- output_color_type == 4))
+ if ((color_type == 2 ||
+ color_type == 6 ||
+ color_type == 3) &&
+ (output_color_type == 0 ||
+ output_color_type == 4))
+ {
+ if (verbose > 0 && last_trial)
{
- if (verbose > 0 && last_trial)
- {
- fprintf(STDERR, " Reducing truecolor "
- "image to grayscale.\n");
- }
+ fprintf(STDERR, " Reducing truecolor "
+ "image to grayscale.\n");
+ }
#ifdef PNG_FIXED_POINT_SUPPORTED
- png_set_rgb_to_gray_fixed(read_ptr, 1,
- 21260, 71520);
+ png_set_rgb_to_gray_fixed(read_ptr, 1,
+ 21260, 71520);
#else
- png_set_rgb_to_gray(read_ptr, 1,
- 0.21260, 0.71520);
+ png_set_rgb_to_gray(read_ptr, 1,
+ 0.21260, 0.71520);
#endif
- if (output_bit_depth < 8)
- output_bit_depth = 8;
- if (color_type == 3)
- need_expand = 1;
- }
+ if (output_bit_depth < 8)
+ output_bit_depth = 8;
+ if (color_type == 3)
+ need_expand = 1;
+ }
#endif /* PNG_READ_RGB_TO_GRAY_SUPPORTED */
- if (color_type != 3 && output_color_type == 3)
- {
- fprintf(STDERR," Cannot change to indexed color "
- "(color_type 3)\n");
- output_color_type = input_color_type;
- }
+ if (color_type != 3 && output_color_type == 3)
+ {
+ fprintf(STDERR," Cannot change to indexed color "
+ "(color_type 3)\n");
+ output_color_type = input_color_type;
+ }
- if ((color_type == 0 || color_type == 4) &&
- (output_color_type == 2
- || output_color_type == 6))
- {
- png_set_gray_to_rgb(read_ptr);
- }
+ if ((color_type == 0 || color_type == 4) &&
+ (output_color_type == 2
+ || output_color_type == 6))
+ {
+ png_set_gray_to_rgb(read_ptr);
+ }
- if ((color_type == 4 || color_type == 6) &&
- (output_color_type != 4
- && output_color_type != 6))
+ if ((color_type == 4 || color_type == 6) &&
+ (output_color_type != 4
+ && output_color_type != 6))
+ {
+ if (verbose > 0 && last_trial)
{
- if (verbose > 0 && last_trial)
- {
- fprintf(STDERR,
- " Stripping existing alpha channel.\n");
- }
+ fprintf(STDERR,
+ " Stripping existing alpha channel.\n");
+ }
#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED
- png_set_strip_alpha(read_ptr);
+ png_set_strip_alpha(read_ptr);
#endif
- }
+ }
- if ((output_color_type == 4
- || output_color_type == 6) && (color_type != 4
- && color_type
- != 6))
- {
- if (verbose > 0 && last_trial)
- fprintf(STDERR,
- " Adding an opaque alpha channel.\n");
+ if ((output_color_type == 4
+ || output_color_type == 6) && (color_type != 4
+ && color_type != 6))
+ {
+ if (verbose > 0 && last_trial)
+ fprintf(STDERR,
+ " Adding an opaque alpha channel.\n");
#ifdef PNG_READ_FILLER_SUPPORTED
- png_set_filler(read_ptr, (png_uint_32) 65535L,
- PNG_FILLER_AFTER);
+ png_set_filler(read_ptr, (png_uint_32) 65535L,
+ PNG_FILLER_AFTER);
#endif
- need_expand = 1;
- }
+ need_expand = 1;
+ }
- if (output_color_type != 0 &&
- output_color_type != 3 &&
- output_bit_depth < 8)
- output_bit_depth = 8;
+ if (output_color_type != 0 && output_color_type != 3 &&
+ output_bit_depth < 8)
+ output_bit_depth = 8;
- if ((output_color_type == 2
- || output_color_type == 6)
- && color_type == 3)
- {
- if (verbose > 0 && last_trial)
- fprintf(STDERR,
- " Expanding indexed color file.\n");
- need_expand = 1;
- }
+ if ((output_color_type == 2
+ || output_color_type == 6)
+ && color_type == 3)
+ {
+ if (verbose > 0 && last_trial)
+ fprintf(STDERR,
+ " Expanding indexed color file.\n");
+ need_expand = 1;
+ }
#ifdef PNG_READ_EXPAND_SUPPORTED
- if (need_expand == 1)
- png_set_expand(read_ptr);
+ if (need_expand == 1)
+ png_set_expand(read_ptr);
#endif
#ifdef PNG_READ_PACK_SUPPORTED
- if (input_bit_depth < 8)
- {
- png_set_packing(read_ptr);
- }
+ if (input_bit_depth < 8)
+ {
+ png_set_packing(read_ptr);
+ }
- if (output_color_type == 0 && output_bit_depth < 8)
- {
- png_color_8 true_bits;
- true_bits.gray = (png_byte) (output_bit_depth);
- png_set_shift(read_ptr, &true_bits);
- }
+ if (output_color_type == 0 && output_bit_depth < 8)
+ {
+ png_color_8 true_bits;
+ true_bits.gray = (png_byte) (output_bit_depth);
+ png_set_shift(read_ptr, &true_bits);
+ }
#endif
+
+ if (trial > 0)
+ {
+#if 1
+ /* TO DO: have we got the right plte_len now? */
+ if (plte_len > 0 && output_color_type == 3 &&
+ force_output_bit_depth == 0)
+ {
+ if (plte_len <= 2)
+ force_output_bit_depth = 1;
+ else if (plte_len <= 4)
+ force_output_bit_depth = 2;
+ else if (plte_len <= 16)
+ force_output_bit_depth = 4;
+ else
+ force_output_bit_depth = 8;
+ }
+#endif /* 1 */
- if (trial > 0 && make_8_bit == 1)
- {
+ if (make_8_bit == 1)
+ {
#if defined(PNG_READ_SCALE_16_TO_8_SUPPORTED) || \
- defined(PNG_READ_STRIP_16_TO_8_SUPPORTED)
- output_bit_depth = 8;
- force_output_bit_depth = 8;
- if (verbose > 0 && last_trial)
- fprintf(STDERR,
- " Stripping 16-bit depth to 8, trial = %d\n",
- trial);
+defined(PNG_READ_STRIP_16_TO_8_SUPPORTED)
+ output_bit_depth = 8;
+ force_output_bit_depth = 8;
+ if (verbose > 0 && last_trial)
+ fprintf(STDERR,
+ " Stripping 16-bit depth to 8, trial = %d\n",
+ trial);
#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED
- png_set_strip_16(read_ptr);
+ png_set_strip_16(read_ptr);
#else
#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
- png_set_scale_16(read_ptr);
+ png_set_scale_16(read_ptr);
#else
- fprintf(STDERR,
- " PNG_READ_STRIP_16_TO_8 NOT SUPPORTED\n");
+ fprintf(STDERR,
+ " PNG_READ_STRIP_16_TO_8 NOT SUPPORTED\n");
#endif
#endif
#endif
- }
+ }
+ P1("force_output_bit_depth=%d\n",force_output_bit_depth);
+ }
- if (last_trial == 1)
- {
- if (save_apng_chunks == 1 || found_acTL_chunk == 1)
- {
- if (save_apng_chunks == 0)
- {
- if (verbose > 0) fprintf(STDERR,
- " pngcrush will only save APNG chunks in an\n");
- if (verbose > 0) fprintf(STDERR,
- " output file with the \".apng\" extension\n");
- }
- if (input_color_type != output_color_type)
- {
- if (verbose > 0) fprintf(STDERR,
- " Cannot save APNG chunks with a color_type\n");
- if (verbose > 0) fprintf(STDERR,
- " different from that of the main image.\n");
- save_apng_chunks = 2;
- }
- if (input_bit_depth != output_bit_depth)
- {
- if (verbose > 0) fprintf(STDERR,
- " Cannot save APNG chunks with a bit_depth\n");
- if (verbose > 0) fprintf(STDERR,
- " different from that of the main image.\n");
- save_apng_chunks = 2;
- }
- if (save_apng_chunks != 1 && found_acTL_chunk == 1)
- found_acTL_chunk = 2;
- }
- }
- if (verbose > 1)
- fprintf(STDERR, " Setting IHDR\n");
+ if (last_trial == 1)
+ {
+ if (save_apng_chunks == 1 || found_acTL_chunk == 1)
+ {
+ if (save_apng_chunks == 0)
+ {
+ if (verbose > 0) fprintf(STDERR,
+ " pngcrush will only save APNG chunks in an\n");
+ if (verbose > 0) fprintf(STDERR,
+ " output file with the \".apng\" extension\n");
+ }
+ if (input_color_type != output_color_type)
+ {
+ if (verbose > 0) fprintf(STDERR,
+ " Cannot save APNG chunks with a color_type\n");
+ if (verbose > 0) fprintf(STDERR,
+ " different from that of the main image.\n");
+ save_apng_chunks = 2;
+ }
+ if (input_bit_depth != output_bit_depth)
+ {
+ if (verbose > 0) fprintf(STDERR,
+ " Cannot save APNG chunks with a bit_depth\n");
+ if (verbose > 0) fprintf(STDERR,
+ " different from that of the main image.\n");
+ save_apng_chunks = 2;
+ }
+ if (save_apng_chunks != 1 && found_acTL_chunk == 1)
+ found_acTL_chunk = 2;
+ }
+ }
+
+ if (verbose > 1)
+ fprintf(STDERR, " Setting IHDR\n");
#ifdef PNGCRUSH_LOCO
- output_format = 0;
- if (do_loco)
+ output_format = 0;
+ if (do_loco)
+ {
+ if (output_color_type == 2
+ || output_color_type == 6)
{
- if (output_color_type == 2
- || output_color_type == 6)
- {
- output_format = 1;
- filter_method = 64;
- if (nosave == 0 && last_trial == 1)
- png_permit_mng_features(write_ptr,
- PNG_FLAG_MNG_FILTER_64);
+ output_format = 1;
+ filter_method = 64;
+ if (nosave == 0 && last_trial == 1)
+ png_permit_mng_features(write_ptr,
+ PNG_FLAG_MNG_FILTER_64);
- }
- } else
- filter_method = 0;
- if (input_format != output_format)
- things_have_changed = 1;
+ }
+ } else
+ filter_method = 0;
+ if (input_format != output_format)
+ things_have_changed = 1;
#endif
- png_set_IHDR(write_ptr, write_info_ptr, width,
- height, output_bit_depth,
- output_color_type, interlace_method,
- compression_method, filter_method);
+ png_set_IHDR(write_ptr, write_info_ptr, width,
+ height, output_bit_depth,
+ output_color_type, interlace_method,
+ compression_method, filter_method);
- if (output_color_type != input_color_type ||
- output_bit_depth != input_bit_depth)
- things_have_changed = 1;
+ if (output_color_type != input_color_type ||
+ output_bit_depth != input_bit_depth)
+ things_have_changed = 1;
- } /* IHDR */
- }
+ } /* IHDR */
+ }
if (premultiply == 1 || premultiply == 2)
{
@@ -7990,8 +8016,8 @@ struct options_help pngcrush_options[] = {
{0, FAKE_PAUSE_STRING},
- {0, " -fix (salvage PNG with otherwise fatal conditions such"},
- {2, " as bad CRCs and adaptive filter bytes)"},
+ {0, " -fix (salvage PNG with otherwise fatal conditions"},
+ {2, " such as bad CRCs and adaptive filter bytes)"},
{2, ""},
{0, " -force (write a new output file even if larger than input)"},
diff --git a/pngcrush.h b/pngcrush.h
index a93367834..7fd543a22 100644
--- a/pngcrush.h
+++ b/pngcrush.h
@@ -5,7 +5,7 @@
* license (see LICENSE, in pngcrush.c).
*/
-/* Special defines for pngcrush version 1.7.81 */
+/* Special defines for pngcrush version 1.7.82 */
#ifndef PNGCRUSH_H
#define PNGCRUSH_H
diff --git a/pnglibconf.h b/pnglibconf.h
index 325ef39bd..da3b22921 100644
--- a/pnglibconf.h
+++ b/pnglibconf.h
@@ -1,8 +1,8 @@
-/* libpng 1.6.15 STANDARD API DEFINITION */
+/* libpng 1.6.16 STANDARD API DEFINITION */
/* pnglibconf.h - library build configuration */
-/* Libpng version 1.6.15 - November 20, 2014 */
+/* Libpng version 1.6.16 - December 22, 2014 */
/* Copyright (c) 1998-2014 Glenn Randers-Pehrson */
diff --git a/pngrutil.c b/pngrutil.c
index b0385fc78..4c26be48c 100644
--- a/pngrutil.c
+++ b/pngrutil.c
@@ -788,6 +788,7 @@ png_inflate_read(png_structrp png_ptr, png_bytep read_buffer, uInt read_size,
#endif
/* Read and check the IDHR chunk */
+
void /* PRIVATE */
png_handle_IHDR(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
{
@@ -852,8 +853,7 @@ png_handle_IHDR(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
}
/* Set up other useful info */
- png_ptr->pixel_depth = (png_byte)(png_ptr->bit_depth *
- png_ptr->channels);
+ png_ptr->pixel_depth = (png_byte)(png_ptr->bit_depth * png_ptr->channels);
png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, png_ptr->width);
png_debug1(3, "bit_depth = %d", png_ptr->bit_depth);
png_debug1(3, "channels = %d", png_ptr->channels);
@@ -3003,7 +3003,7 @@ png_combine_row(png_const_structrp png_ptr, png_bytep dp, int display)
{
unsigned int pixel_depth = png_ptr->transformed_pixel_depth;
png_const_bytep sp = png_ptr->row_buf + 1;
- png_uint_32 row_width = png_ptr->width;
+ png_alloc_size_t row_width = png_ptr->width;
unsigned int pass = png_ptr->pass;
png_bytep end_ptr = 0;
png_byte end_byte = 0;
@@ -3278,7 +3278,7 @@ png_combine_row(png_const_structrp png_ptr, png_bytep dp, int display)
/* But don't allow this number to exceed the actual row width. */
if (bytes_to_copy > row_width)
- bytes_to_copy = row_width;
+ bytes_to_copy = (unsigned int)/*SAFE*/row_width;
}
else /* normal row; Adam7 only ever gives us one pixel to copy. */
@@ -3458,7 +3458,7 @@ png_combine_row(png_const_structrp png_ptr, png_bytep dp, int display)
dp += bytes_to_jump;
row_width -= bytes_to_jump;
if (bytes_to_copy > row_width)
- bytes_to_copy = row_width;
+ bytes_to_copy = (unsigned int)/*SAFE*/row_width;
}
}
@@ -4228,7 +4228,7 @@ png_read_start_row(png_structrp png_ptr)
max_pixel_depth = png_ptr->pixel_depth;
- /* WARNING: * png_read_transform_info (pngrtran.c) performs a simpliar set of
+ /* WARNING: * png_read_transform_info (pngrtran.c) performs a simpler set of
* calculations to calculate the final pixel depth, then
* png_do_read_transforms actually does the transforms. This means that the
* code which effectively calculates this value is actually repeated in three