[devel] Added png_set_chop_16() API.

This commit is contained in:
Glenn Randers-Pehrson 2011-06-13 22:07:37 -05:00
parent 74945f2f04
commit 413138a5ca
9 changed files with 105 additions and 55 deletions

View File

@ -1,5 +1,5 @@
Libpng 1.5.4beta01 - June 14, 2011 Libpng 1.5.4beta02 - June 14, 2011
This is not intended to be a public release. It will be replaced This is not intended to be a public release. It will be replaced
within a few weeks by a public version or by another test version. within a few weeks by a public version or by another test version.
@ -9,20 +9,20 @@ Files available for download:
Source files with LF line endings (for Unix/Linux) and with a Source files with LF line endings (for Unix/Linux) and with a
"configure" script "configure" script
1.5.4beta01.tar.xz (LZMA-compressed, recommended) 1.5.4beta02.tar.xz (LZMA-compressed, recommended)
1.5.4beta01.tar.gz 1.5.4beta02.tar.gz
1.5.4beta01.tar.bz2 1.5.4beta02.tar.bz2
Source files with CRLF line endings (for Windows), without the Source files with CRLF line endings (for Windows), without the
"configure" script "configure" script
lp154b01.7z (LZMA-compressed, recommended) lp154b02.7z (LZMA-compressed, recommended)
lp154b01.zip lp154b02.zip
Other information: Other information:
1.5.4beta01-README.txt 1.5.4beta02-README.txt
1.5.4beta01-LICENSE.txt 1.5.4beta02-LICENSE.txt
Changes since the last public release (1.5.2): Changes since the last public release (1.5.2):
@ -193,6 +193,10 @@ Version 1.5.4beta01 [June 14, 2011]
outside of an unknown-chunk block in png.h because they are also outside of an unknown-chunk block in png.h because they are also
needed for other uses. needed for other uses.
Version 1.5.4beta02 [June 14, 2011]
Fixed and clarified LEGACY 16-to-8 scaling code.
Added png_set_chop_16() API.
Send comments/corrections/commendations to png-mng-implement at lists.sf.net: Send comments/corrections/commendations to png-mng-implement at lists.sf.net:
(subscription required; visit (subscription required; visit
https://lists.sourceforge.net/lists/listinfo/png-mng-implement https://lists.sourceforge.net/lists/listinfo/png-mng-implement

View File

@ -3456,6 +3456,10 @@ Version 1.5.4beta01 [June 14, 2011]
outside of an unknown-chunk block in png.h because they are also outside of an unknown-chunk block in png.h because they are also
needed for other uses. needed for other uses.
Version 1.5.4beta02 [June 14, 2011]
Fixed and clarified LEGACY 16-to-8 scaling code.
Added png_set_chop_16() API.
Send comments/corrections/commendations to png-mng-implement at lists.sf.net Send comments/corrections/commendations to png-mng-implement at lists.sf.net
(subscription required; visit (subscription required; visit
https://lists.sourceforge.net/lists/listinfo/png-mng-implement https://lists.sourceforge.net/lists/listinfo/png-mng-implement

View File

@ -1,6 +1,6 @@
libpng-manual.txt - A description on how to use and modify libpng libpng-manual.txt - A description on how to use and modify libpng
libpng version 1.5.4beta01 - June 14, 2011 libpng version 1.5.4beta02 - June 14, 2011
Updated and distributed by Glenn Randers-Pehrson Updated and distributed by Glenn Randers-Pehrson
<glennrp at users.sourceforge.net> <glennrp at users.sourceforge.net>
Copyright (c) 1998-2011 Glenn Randers-Pehrson Copyright (c) 1998-2011 Glenn Randers-Pehrson
@ -11,7 +11,7 @@ libpng-manual.txt - A description on how to use and modify libpng
Based on: Based on:
libpng versions 0.97, January 1998, through 1.5.4beta01 - June 14, 2011 libpng versions 0.97, January 1998, through 1.5.4beta02 - June 14, 2011
Updated and distributed by Glenn Randers-Pehrson Updated and distributed by Glenn Randers-Pehrson
Copyright (c) 1998-2011 Glenn Randers-Pehrson Copyright (c) 1998-2011 Glenn Randers-Pehrson
@ -4423,7 +4423,7 @@ Since the PNG Development group is an ad-hoc body, we can't make
an official declaration. an official declaration.
This is your unofficial assurance that libpng from version 0.71 and This is your unofficial assurance that libpng from version 0.71 and
upward through 1.5.4beta01 are Y2K compliant. It is my belief that earlier upward through 1.5.4beta02 are Y2K compliant. It is my belief that earlier
versions were also Y2K compliant. versions were also Y2K compliant.
Libpng only has three year fields. One is a 2-byte unsigned integer that Libpng only has three year fields. One is a 2-byte unsigned integer that

View File

@ -1,6 +1,6 @@
.TH LIBPNG 3 "June 14, 2011" .TH LIBPNG 3 "June 14, 2011"
.SH NAME .SH NAME
libpng \- Portable Network Graphics (PNG) Reference Library 1.5.4beta01 libpng \- Portable Network Graphics (PNG) Reference Library 1.5.4beta02
.SH SYNOPSIS .SH SYNOPSIS
\fI\fB \fI\fB
@ -672,6 +672,10 @@ libpng \- Portable Network Graphics (PNG) Reference Library 1.5.4beta01
\fI\fB \fI\fB
\fBvoid png_set_strip_16 (png_structp \fIpng_ptr\fP\fB);\fP
\fI\fB
\fBvoid png_set_chunk_malloc_max (png_structp \fP\fIpng_ptr\fP\fB, png_alloc_size_t \fIuser_chunk_cache_max\fP\fB);\fP \fBvoid png_set_chunk_malloc_max (png_structp \fP\fIpng_ptr\fP\fB, png_alloc_size_t \fIuser_chunk_cache_max\fP\fB);\fP
\fI\fB \fI\fB
@ -951,7 +955,7 @@ Following is a copy of the libpng-manual.txt file that accompanies libpng.
.SH LIBPNG.TXT .SH LIBPNG.TXT
libpng-manual.txt - A description on how to use and modify libpng libpng-manual.txt - A description on how to use and modify libpng
libpng version 1.5.4beta01 - June 14, 2011 libpng version 1.5.4beta02 - June 14, 2011
Updated and distributed by Glenn Randers-Pehrson Updated and distributed by Glenn Randers-Pehrson
<glennrp at users.sourceforge.net> <glennrp at users.sourceforge.net>
Copyright (c) 1998-2011 Glenn Randers-Pehrson Copyright (c) 1998-2011 Glenn Randers-Pehrson
@ -962,7 +966,7 @@ libpng-manual.txt - A description on how to use and modify libpng
Based on: Based on:
libpng versions 0.97, January 1998, through 1.5.4beta01 - June 14, 2011 libpng versions 0.97, January 1998, through 1.5.4beta02 - June 14, 2011
Updated and distributed by Glenn Randers-Pehrson Updated and distributed by Glenn Randers-Pehrson
Copyright (c) 1998-2011 Glenn Randers-Pehrson Copyright (c) 1998-2011 Glenn Randers-Pehrson
@ -5374,7 +5378,7 @@ Since the PNG Development group is an ad-hoc body, we can't make
an official declaration. an official declaration.
This is your unofficial assurance that libpng from version 0.71 and This is your unofficial assurance that libpng from version 0.71 and
upward through 1.5.4beta01 are Y2K compliant. It is my belief that earlier upward through 1.5.4beta02 are Y2K compliant. It is my belief that earlier
versions were also Y2K compliant. versions were also Y2K compliant.
Libpng only has three year fields. One is a 2-byte unsigned integer that Libpng only has three year fields. One is a 2-byte unsigned integer that
@ -5565,8 +5569,9 @@ the first widely used release:
1.5.2 15 10502 15.so.15.2[.0] 1.5.2 15 10502 15.so.15.2[.0]
1.5.3beta01-10 15 10503 15.so.15.3[.0] 1.5.3beta01-10 15 10503 15.so.15.3[.0]
1.5.3rc01-02 15 10503 15.so.15.3[.0] 1.5.3rc01-02 15 10503 15.so.15.3[.0]
1.5.3beta11 [no 1.5.3] 15 10503 15.so.15.3[.0] 1.5.3beta11 15 10503 15.so.15.3[.0]
1.5.4beta01 15 10504 15.so.15.4[.0] 1.5.3 [omitted]
1.5.4beta01-02 15 10504 15.so.15.4[.0]
Henceforth the source version will match the shared-library minor Henceforth the source version will match the shared-library minor
and patch numbers; the shared-library major version number will be and patch numbers; the shared-library major version number will be
@ -5623,7 +5628,7 @@ possible without all of you.
Thanks to Frank J. T. Wojcik for helping with the documentation. Thanks to Frank J. T. Wojcik for helping with the documentation.
Libpng version 1.5.4beta01 - June 14, 2011: Libpng version 1.5.4beta02 - June 14, 2011:
Initially created in 1995 by Guy Eric Schalnat, then of Group 42, Inc. Initially created in 1995 by Guy Eric Schalnat, then of Group 42, Inc.
Currently maintained by Glenn Randers-Pehrson (glennrp at users.sourceforge.net). Currently maintained by Glenn Randers-Pehrson (glennrp at users.sourceforge.net).
@ -5646,7 +5651,7 @@ this sentence.
This code is released under the libpng license. This code is released under the libpng license.
libpng versions 1.2.6, August 15, 2004, through 1.5.4beta01, June 14, 2011, are libpng versions 1.2.6, August 15, 2004, through 1.5.4beta02, June 14, 2011, are
Copyright (c) 2004,2006-2007 Glenn Randers-Pehrson, and are Copyright (c) 2004,2006-2007 Glenn Randers-Pehrson, and are
distributed according to the same disclaimer and license as libpng-1.2.5 distributed according to the same disclaimer and license as libpng-1.2.5
with the following individual added to the list of Contributing Authors with the following individual added to the list of Contributing Authors

12
png.c
View File

@ -1,7 +1,7 @@
/* png.c - location for general purpose libpng functions /* png.c - location for general purpose libpng functions
* *
* Last changed in libpng 1.5.3 [(PENDING RELEASE)] * Last changed in libpng 1.5.4 [(PENDING RELEASE)]
* Copyright (c) 1998-2011 Glenn Randers-Pehrson * Copyright (c) 1998-2011 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
@ -14,7 +14,7 @@
#include "pngpriv.h" #include "pngpriv.h"
/* Generate a compiler error if there is an old png.h in the search path. */ /* Generate a compiler error if there is an old png.h in the search path. */
typedef png_libpng_version_1_5_4beta01 Your_png_h_is_not_version_1_5_4beta01; typedef png_libpng_version_1_5_4beta02 Your_png_h_is_not_version_1_5_4beta02;
/* Tells libpng that we have already handled the first "num_bytes" bytes /* 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 * of the PNG file signature. If the PNG data is embedded into another
@ -617,13 +617,13 @@ png_get_copyright(png_const_structp png_ptr)
#else #else
# ifdef __STDC__ # ifdef __STDC__
return PNG_STRING_NEWLINE \ return PNG_STRING_NEWLINE \
"libpng version 1.5.4beta01 - June 14, 2011" PNG_STRING_NEWLINE \ "libpng version 1.5.4beta02 - June 14, 2011" PNG_STRING_NEWLINE \
"Copyright (c) 1998-2011 Glenn Randers-Pehrson" PNG_STRING_NEWLINE \ "Copyright (c) 1998-2011 Glenn Randers-Pehrson" PNG_STRING_NEWLINE \
"Copyright (c) 1996-1997 Andreas Dilger" PNG_STRING_NEWLINE \ "Copyright (c) 1996-1997 Andreas Dilger" PNG_STRING_NEWLINE \
"Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc." \ "Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc." \
PNG_STRING_NEWLINE; PNG_STRING_NEWLINE;
# else # else
return "libpng version 1.5.4beta01 - June 14, 2011\ return "libpng version 1.5.4beta02 - June 14, 2011\
Copyright (c) 1998-2011 Glenn Randers-Pehrson\ Copyright (c) 1998-2011 Glenn Randers-Pehrson\
Copyright (c) 1996-1997 Andreas Dilger\ Copyright (c) 1996-1997 Andreas Dilger\
Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc."; Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.";
@ -2369,7 +2369,7 @@ png_build_gamma_table(png_structp png_ptr, int bit_depth)
else else
shift = 0; /* keep all 16 bits */ shift = 0; /* keep all 16 bits */
if (png_ptr->transformations & PNG_16_TO_8) if (png_ptr->transformations & (PNG_16_TO_8 | PNG_CHOP_16_TO_8))
{ {
/* PNG_MAX_GAMMA_8 is the number of bits to keep - effectively /* PNG_MAX_GAMMA_8 is the number of bits to keep - effectively
* the significant bits in the *input* when the output will * the significant bits in the *input* when the output will
@ -2390,7 +2390,7 @@ png_build_gamma_table(png_structp png_ptr, int bit_depth)
* 16-bit output because the 8-bit table assumes the result will be reduced * 16-bit output because the 8-bit table assumes the result will be reduced
* to 8 bits. * to 8 bits.
*/ */
if (png_ptr->transformations & PNG_16_TO_8) if (png_ptr->transformations & (PNG_16_TO_8 | PNG_CHOP_16_TO_8))
#endif #endif
png_build_16to8_table(png_ptr, &png_ptr->gamma_16_table, shift, png_build_16to8_table(png_ptr, &png_ptr->gamma_16_table, shift,
png_ptr->screen_gamma > 0 ? png_product2(png_ptr->gamma, png_ptr->screen_gamma > 0 ? png_product2(png_ptr->gamma,

27
png.h
View File

@ -1,7 +1,7 @@
/* png.h - header file for PNG reference library /* png.h - header file for PNG reference library
* *
* libpng version 1.5.4beta01 - June 14, 2011 * libpng version 1.5.4beta02 - June 14, 2011
* Copyright (c) 1998-2011 Glenn Randers-Pehrson * Copyright (c) 1998-2011 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
@ -11,7 +11,7 @@
* Authors and maintainers: * Authors and maintainers:
* libpng versions 0.71, May 1995, through 0.88, January 1996: Guy Schalnat * 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.89c, June 1996, through 0.96, May 1997: Andreas Dilger
* libpng versions 0.97, January 1998, through 1.5.4beta01 - June 14, 2011: Glenn * libpng versions 0.97, January 1998, through 1.5.4beta02 - June 14, 2011: Glenn
* See also "Contributing Authors", below. * See also "Contributing Authors", below.
* *
* Note about libpng version numbers: * Note about libpng version numbers:
@ -152,8 +152,9 @@
* 1.5.2 15 10502 15.so.15.2[.0] * 1.5.2 15 10502 15.so.15.2[.0]
* 1.5.3beta01-10 15 10503 15.so.15.3[.0] * 1.5.3beta01-10 15 10503 15.so.15.3[.0]
* 1.5.3rc01-02 15 10503 15.so.15.3[.0] * 1.5.3rc01-02 15 10503 15.so.15.3[.0]
* 1.5.3beta11 [no 1.5.3] 15 10503 15.so.15.3[.0] * 1.5.3beta11 15 10503 15.so.15.3[.0]
* 1.5.4beta01 15 10504 15.so.15.4[.0] * 1.5.3 [omitted]
* 1.5.4beta01-02 15 10504 15.so.15.4[.0]
* *
* Henceforth the source version will match the shared-library major * Henceforth the source version will match the shared-library major
* and minor numbers; the shared-library major version number will be * and minor numbers; the shared-library major version number will be
@ -185,7 +186,7 @@
* *
* This code is released under the libpng license. * This code is released under the libpng license.
* *
* libpng versions 1.2.6, August 15, 2004, through 1.5.4beta01, June 14, 2011, are * libpng versions 1.2.6, August 15, 2004, through 1.5.4beta02, June 14, 2011, are
* Copyright (c) 2004, 2006-2011 Glenn Randers-Pehrson, and are * Copyright (c) 2004, 2006-2011 Glenn Randers-Pehrson, and are
* distributed according to the same disclaimer and license as libpng-1.2.5 * distributed according to the same disclaimer and license as libpng-1.2.5
* with the following individual added to the list of Contributing Authors: * with the following individual added to the list of Contributing Authors:
@ -303,7 +304,7 @@
* an official declaration. * an official declaration.
* *
* This is your unofficial assurance that libpng from version 0.71 and * This is your unofficial assurance that libpng from version 0.71 and
* upward through 1.5.4beta01 are Y2K compliant. It is my belief that * upward through 1.5.4beta02 are Y2K compliant. It is my belief that
* earlier versions were also Y2K compliant. * earlier versions were also Y2K compliant.
* *
* Libpng only has two year fields. One is a 2-byte unsigned integer * Libpng only has two year fields. One is a 2-byte unsigned integer
@ -358,9 +359,9 @@
*/ */
/* Version information for png.h - this should match the version in png.c */ /* Version information for png.h - this should match the version in png.c */
#define PNG_LIBPNG_VER_STRING "1.5.4beta01" #define PNG_LIBPNG_VER_STRING "1.5.4beta02"
#define PNG_HEADER_VERSION_STRING \ #define PNG_HEADER_VERSION_STRING \
" libpng version 1.5.4beta01 - June 14, 2011\n" " libpng version 1.5.4beta02 - June 14, 2011\n"
#define PNG_LIBPNG_VER_SONUM 15 #define PNG_LIBPNG_VER_SONUM 15
#define PNG_LIBPNG_VER_DLLNUM 15 #define PNG_LIBPNG_VER_DLLNUM 15
@ -373,7 +374,7 @@
* PNG_LIBPNG_VER_STRING, omitting any leading zero: * PNG_LIBPNG_VER_STRING, omitting any leading zero:
*/ */
#define PNG_LIBPNG_VER_BUILD 01 #define PNG_LIBPNG_VER_BUILD 02
/* Release Status */ /* Release Status */
#define PNG_LIBPNG_BUILD_ALPHA 1 #define PNG_LIBPNG_BUILD_ALPHA 1
@ -520,7 +521,7 @@ extern "C" {
/* This triggers a compiler error in png.c, if png.c and png.h /* This triggers a compiler error in png.c, if png.c and png.h
* do not agree upon the version number. * do not agree upon the version number.
*/ */
typedef char* png_libpng_version_1_5_4beta01; typedef char* png_libpng_version_1_5_4beta02;
/* Three color definitions. The order of the red, green, and blue, (and the /* Three color definitions. The order of the red, green, and blue, (and the
* exact size) is not important, although the size of the fields need to * exact size) is not important, although the size of the fields need to
@ -1422,8 +1423,10 @@ PNG_FIXED_EXPORT(215, void, png_set_background_fixed, (png_structp png_ptr,
#endif #endif
#ifdef PNG_READ_16_TO_8_SUPPORTED #ifdef PNG_READ_16_TO_8_SUPPORTED
/* Strip the second byte of information from a 16-bit depth file. */ /* Scale a 16-bit depth file down to 8-bit, accurately. */
PNG_EXPORT(48, void, png_set_strip_16, (png_structp png_ptr)); PNG_EXPORT(48, void, png_set_strip_16, (png_structp png_ptr));
/* Strip the second byte of information from a 16-bit depth file. */
PNG_EXPORT(229, void, png_set_chop_16, (png_structp png_ptr));
#endif #endif
#ifdef PNG_READ_QUANTIZE_SUPPORTED #ifdef PNG_READ_QUANTIZE_SUPPORTED
@ -2566,7 +2569,7 @@ PNG_EXPORT(207, void, png_save_uint_16, (png_bytep buf, unsigned int i));
* scripts/symbols.def as well. * scripts/symbols.def as well.
*/ */
#ifdef PNG_EXPORT_LAST_ORDINAL #ifdef PNG_EXPORT_LAST_ORDINAL
PNG_EXPORT_LAST_ORDINAL(228); PNG_EXPORT_LAST_ORDINAL(229);
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -133,7 +133,7 @@ png_set_background(png_structp png_ptr,
#endif /* READ_BACKGROUND */ #endif /* READ_BACKGROUND */
#ifdef PNG_READ_16_TO_8_SUPPORTED #ifdef PNG_READ_16_TO_8_SUPPORTED
/* Strip 16-bit depth files to 8-bit depth */ /* Scale 16-bit depth files to 8-bit depth */
void PNGAPI void PNGAPI
png_set_strip_16(png_structp png_ptr) png_set_strip_16(png_structp png_ptr)
{ {
@ -143,6 +143,20 @@ png_set_strip_16(png_structp png_ptr)
return; return;
png_ptr->transformations |= PNG_16_TO_8; png_ptr->transformations |= PNG_16_TO_8;
png_ptr->transformations &= ~PNG_CHOP_16_TO_8;
}
/* Chop 16-bit depth files to 8-bit depth */
void PNGAPI
png_set_chop_16(png_structp png_ptr)
{
png_debug(1, "in png_set_chop_16");
if (png_ptr == NULL)
return;
png_ptr->transformations |= PNG_CHOP_16_TO_8;
png_ptr->transformations &= ~PNG_16_TO_8;
} }
#endif #endif
@ -1312,7 +1326,7 @@ png_init_read_transformations(png_structp png_ptr)
* 6) PNG_GAMMA * 6) PNG_GAMMA
* 7) PNG_STRIP_ALPHA (if compose) * 7) PNG_STRIP_ALPHA (if compose)
* 8) PNG_ENCODE_ALPHA * 8) PNG_ENCODE_ALPHA
* 9) PNG_16_TO_8 (strip16) * 9) PNG_16_TO_8 or PNG_CHOP_16_TO_8 (strip16/chop16)
* 10) PNG_QUANTIZE (converts to palette) * 10) PNG_QUANTIZE (converts to palette)
* 11) PNG_EXPAND_16 * 11) PNG_EXPAND_16
* 12) PNG_GRAY_TO_RGB iff PNG_BACKGROUND_IS_GRAY * 12) PNG_GRAY_TO_RGB iff PNG_BACKGROUND_IS_GRAY
@ -1851,13 +1865,15 @@ png_read_transform_info(png_structp png_ptr, png_infop info_ptr)
#ifdef PNG_READ_16_TO_8_SUPPORTED #ifdef PNG_READ_16_TO_8_SUPPORTED
#ifdef PNG_READ_16BIT_SUPPORTED #ifdef PNG_READ_16BIT_SUPPORTED
if ((png_ptr->transformations & PNG_16_TO_8) && (info_ptr->bit_depth == 16)) if ((png_ptr->transformations & (PNG_16_TO_8 | PNG_CHOP_16_TO_8)) &&
(info_ptr->bit_depth == 16))
info_ptr->bit_depth = 8; info_ptr->bit_depth = 8;
#else #else
/* Force chopping 16-bit input down to 8 */ /* Force chopping 16-bit input down to 8 */
if (info_ptr->bit_depth == 16) if (info_ptr->bit_depth == 16)
{ {
png_ptr->transformations |=PNG_16_TO_8; if (!(png_ptr->transformations & PNG_CHOP_16_TO_8))
png_ptr->transformations |=PNG_16_TO_8;
info_ptr->bit_depth = 8; info_ptr->bit_depth = 8;
} }
#endif #endif
@ -2123,6 +2139,8 @@ png_do_read_transformations(png_structp png_ptr)
#ifdef PNG_READ_16_TO_8_SUPPORTED #ifdef PNG_READ_16_TO_8_SUPPORTED
if (png_ptr->transformations & PNG_16_TO_8) if (png_ptr->transformations & PNG_16_TO_8)
png_do_scale_16_to_8(&(png_ptr->row_info), png_ptr->row_buf + 1);
else if (png_ptr->transformations & PNG_CHOP_16_TO_8)
png_do_chop(&(png_ptr->row_info), png_ptr->row_buf + 1); png_do_chop(&(png_ptr->row_info), png_ptr->row_buf + 1);
#endif #endif
@ -2453,11 +2471,11 @@ png_do_unshift(png_row_infop row_info, png_bytep row,
#endif #endif
#ifdef PNG_READ_16_TO_8_SUPPORTED #ifdef PNG_READ_16_TO_8_SUPPORTED
/* Chop rows of bit depth 16 down to 8 */ /* Scale rows of bit depth 16 down to 8 accurately */
void /* PRIVATE */ void /* PRIVATE */
png_do_chop(png_row_infop row_info, png_bytep row) png_do_scale_16_to_8(png_row_infop row_info, png_bytep row)
{ {
png_debug(1, "in png_do_chop"); png_debug(1, "in png_do_scale_16_to_8");
if (row_info->bit_depth == 16) if (row_info->bit_depth == 16)
{ {
@ -2500,15 +2518,7 @@ png_do_chop(png_row_infop row_info, png_bytep row)
*/ */
png_int_32 tmp = *sp++; /* must be signed! */ png_int_32 tmp = *sp++; /* must be signed! */
#ifdef PNG_LEGACY_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED
tmp += (((int)*sp++ - tmp) > 128) ? 1 : 0;
#else
# ifdef PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED
tmp += (((int)*sp++ - tmp + 128) * 65535) >> 24; tmp += (((int)*sp++ - tmp + 128) * 65535) >> 24;
# else
sp++;
# endif
#endif
*dp++ = (png_byte)tmp; *dp++ = (png_byte)tmp;
} }
@ -2517,7 +2527,33 @@ png_do_chop(png_row_infop row_info, png_bytep row)
row_info->rowbytes = row_info->width * row_info->channels; row_info->rowbytes = row_info->width * row_info->channels;
} }
} }
#endif
void /* PRIVATE */
/* Simply discard the low byte. This was the default behavior prior
* to libpng-1.5.4.
*/
png_do_chop(png_row_infop row_info, png_bytep row)
{
png_debug(1, "in png_do_chop");
if (row_info->bit_depth == 16)
{
png_bytep sp = row; /* source */
png_bytep dp = row; /* destinaton */
png_bytep ep = sp + row_info->rowbytes; /* end+1 */
while (sp < ep)
{
*dp++ = *sp++;
sp++;
}
row_info->bit_depth = 8;
row_info->pixel_depth = (png_byte)(8 * row_info->channels);
row_info->rowbytes = row_info->width * row_info->channels;
}
}
#endif /* PNG_READ_16_TO_8_SUPPORTED */
#ifdef PNG_READ_SWAP_ALPHA_SUPPORTED #ifdef PNG_READ_SWAP_ALPHA_SUPPORTED
void /* PRIVATE */ void /* PRIVATE */

View File

@ -347,7 +347,6 @@ option INCH_CONVERSIONS
option BUILD_GRAYSCALE_PALETTE option BUILD_GRAYSCALE_PALETTE
option READ_16_TO_8_ACCURATE_SCALE requires READ option READ_16_TO_8_ACCURATE_SCALE requires READ
option LEGACY_READ_16_TO_8_ACCURATE_SCALE disabled
# IN DEVELOPMENT # IN DEVELOPMENT
# These are currently experimental features; define them if you want # These are currently experimental features; define them if you want

View File

@ -61,7 +61,6 @@
#define PNG_INFO_IMAGE_SUPPORTED #define PNG_INFO_IMAGE_SUPPORTED
#define PNG_IO_STATE_SUPPORTED #define PNG_IO_STATE_SUPPORTED
#define PNG_iTXt_SUPPORTED #define PNG_iTXt_SUPPORTED
/*#undef PNG_LEGACY_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED*/
#define PNG_MNG_FEATURES_SUPPORTED #define PNG_MNG_FEATURES_SUPPORTED
#define PNG_oFFs_SUPPORTED #define PNG_oFFs_SUPPORTED
#define PNG_pCAL_SUPPORTED #define PNG_pCAL_SUPPORTED