diff --git a/ANNOUNCE b/ANNOUNCE index 195b64581..78a83b585 100644 --- a/ANNOUNCE +++ b/ANNOUNCE @@ -1,5 +1,5 @@ -Libpng 1.4.1alpha01 - November 27, 2009 +Libpng 1.4.1alpha02 - November 28, 2009 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. @@ -9,25 +9,33 @@ Files available for download: Source files with LF line endings (for Unix/Linux) and with a "configure" script - 1.4.1alpha01.tar.xz (LZMA-compressed, recommended) - 1.4.1alpha01.tar.gz - 1.4.1alpha01.tar.bz2 + 1.4.1alpha02.tar.xz (LZMA-compressed, recommended) + 1.4.1alpha02.tar.gz + 1.4.1alpha02.tar.bz2 Source files with CRLF line endings (for Windows), without the "configure" script - lp141a01.zip - lp141a01.7z + lp141a02.zip + lp141a02.7z Other information: - 1.4.1alpha01-README.txt - 1.4.1alpha01-LICENSE.txt + 1.4.1alpha02-README.txt + 1.4.1alpha02-LICENSE.txt Changes since the last public release (1.4.0beta107): version 1.4.1alpha01 [November 27, 2009] - Based on version 1.4.0beta107 + Based on 1.4.0beta107 + +version 1.4.1alpha02 [November 28, 2009] + Restored premultiplied alpha feature from version 1.4.0beta105. + Added "double gamma" to parameters for png_set_premultiply_alpha(). + Added "float gamma_premultiply" member to the png_struct. + Moved PNG_DIVIDE_BY_255, PNG_8_BIT_PREMULTIPLY(), etc., from + png.h to pngpriv.h + Updated documentation about png_set_premultiply_alpha(). Send comments/corrections/commendations to png-mng-implement at lists.sf.net (subscription required; visit diff --git a/CHANGES b/CHANGES index e1e58784e..9798141fc 100644 --- a/CHANGES +++ b/CHANGES @@ -2396,8 +2396,9 @@ version 1.4.0beta104 [November 22, 2009] Rebuilt configure scripts with autoconf-2.65 version 1.4.0beta105 [November 25, 2009] - Use fast integer PNG_DIVIDE_BY_255() or PNG_DIVIDE_BY_65535() to accomplish - alpha premultiplication when PNG_READ_COMPOSITE_NODIV_SUPPORTED is defined. + Use fast integer PNG_DIVIDE_BY_255() or PNG_DIVIDE_BY_65535() to + accomplish alpha premultiplication when + PNG_READ_COMPOSITE_NODIV_SUPPORTED is defined. Changed "/255" to "/255.0" in background calculations to make it clear that the 255 is used as a double. @@ -2408,6 +2409,15 @@ version 1.4.0beta107 [November 27, 2009] Updated README version 1.4.1alpha01 [November 27, 2009] + Based on 1.4.0beta107 + +version 1.4.1alpha02 [November 28, 2009] + Restored premultiplied alpha feature from version 1.4.0beta105. + Added "double gamma" to parameters for png_set_premultiply_alpha(). + Added "float gamma_premultiply" member to the png_struct. + Moved PNG_DIVIDE_BY_255, PNG_8_BIT_PREMULTIPLY(), etc., from + png.h to pngpriv.h + Updated documentation about png_set_premultiply_alpha(). Send comments/corrections/commendations to png-mng-implement at lists.sf.net (subscription required; visit diff --git a/libpng-1.4.1alpha02.txt b/libpng-1.4.1alpha02.txt index 51d931602..80e70573b 100644 --- a/libpng-1.4.1alpha02.txt +++ b/libpng-1.4.1alpha02.txt @@ -1,6 +1,6 @@ libpng.txt - A description on how to use and modify libpng - libpng version 1.4.1alpha02 - November 27, 2009 + libpng version 1.4.1alpha02 - November 28, 2009 Updated and distributed by Glenn Randers-Pehrson Copyright (c) 1998-2009 Glenn Randers-Pehrson @@ -11,7 +11,7 @@ libpng.txt - A description on how to use and modify libpng Based on: - libpng versions 0.97, January 1998, through 1.4.1alpha02 - November 27, 2009 + libpng versions 0.97, January 1998, through 1.4.1alpha02 - November 28, 2009 Updated and distributed by Glenn Randers-Pehrson Copyright (c) 1998-2009 Glenn Randers-Pehrson @@ -938,6 +938,21 @@ images) is fully transparent, with png_set_invert_alpha(png_ptr); +The PNG format only supports pixels with postmultiplied alpha. +If you want to replace the pixels, after reading them, with pixels +that have premultiplied color samples, you can do this with + + png_set_premultiply_alpha(png_ptr, output_gamma); + +where gamma is a double containing the gamma associated with the +premultiplied pixels. The gamma of the input must also be available +when the premultiplication takes place, via a gAMA chunk in the +input file or via png_set_gAMA(). If neither is present, the +premultiplication will assume input_gamma==(1/2.2) + +If you do this, any input with a tRNS chunk will be expanded to +have an alpha channel. + PNG files pack pixels of bit depths 1, 2, and 4 into bytes as small as they can, resulting in, for example, 8 pixels per byte for 1 bit files. This code expands to 1 pixel per byte without changing the @@ -3026,6 +3041,9 @@ after the png_malloc() to set the pointers to NULL. We added PNG_TRANSFORM_GRAY_TO_RGB to the available high-level input transforms. +We added the png_set_premultiply_alpha and +png_do_read_premultiply_alpha() functions. + The call to png_do_chop() in pngrtran.c, which reduces 16-bit input files to 8-bit bit depth, was relocated ahead of the building of gamma tables. This allows us to build 8-bit tables instead @@ -3213,7 +3231,7 @@ Other rules can be inferred by inspecting the libpng source. XIII. Y2K Compliance in libpng -November 27, 2009 +November 28, 2009 Since the PNG Development group is an ad-hoc body, we can't make an official declaration. diff --git a/libpng.3 b/libpng.3 index 5bee9ae5d..2a9fc4783 100644 --- a/libpng.3 +++ b/libpng.3 @@ -1,6 +1,6 @@ -.TH LIBPNG 3 "November 27, 2009" +.TH LIBPNG 3 "November 28, 2009" .SH NAME -libpng \- Portable Network Graphics (PNG) Reference Library 1.4.1alpha01 +libpng \- Portable Network Graphics (PNG) Reference Library 1.4.1alpha02 .SH SYNOPSIS \fI\fB @@ -566,6 +566,10 @@ libpng \- Portable Network Graphics (PNG) Reference Library 1.4.1alpha01 \fI\fB +\fBvoid png_set_premultiply_alpha (png_structp \fP\fIpng_ptr\fP\fB, double \fIgamma\fP\fB);\fP + +\fI\fB + \fBvoid png_set_progressive_read_fn (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fIprogressive_ptr\fP\fB, png_progressive_info_ptr \fP\fIinfo_fn\fP\fB, png_progressive_row_ptr \fP\fIrow_fn\fP\fB, png_progressive_end_ptr \fIend_fn\fP\fB);\fP \fI\fB @@ -777,7 +781,7 @@ Following is a copy of the libpng.txt file that accompanies libpng. .SH LIBPNG.TXT libpng.txt - A description on how to use and modify libpng - libpng version 1.4.1alpha01 - November 27, 2009 + libpng version 1.4.1alpha02 - November 28, 2009 Updated and distributed by Glenn Randers-Pehrson Copyright (c) 1998-2009 Glenn Randers-Pehrson @@ -788,7 +792,7 @@ libpng.txt - A description on how to use and modify libpng Based on: - libpng versions 0.97, January 1998, through 1.4.1alpha01 - November 27, 2009 + libpng versions 0.97, January 1998, through 1.4.1alpha02 - November 28, 2009 Updated and distributed by Glenn Randers-Pehrson Copyright (c) 1998-2009 Glenn Randers-Pehrson @@ -1655,7 +1659,7 @@ things. As of libpng version 1.2.9, png_set_expand_gray_1_2_4_to_8() was added. It expands the sample depth without changing tRNS to alpha. -As of libpng version 1.4.1alpha01, not all possible expansions are supported. +As of libpng version 1.4.1alpha02, not all possible expansions are supported. In the following table, the 01 means grayscale with depth<8, 31 means indexed with depth<8, other numerals represent the color type, "T" means @@ -1715,6 +1719,21 @@ images) is fully transparent, with png_set_invert_alpha(png_ptr); +The PNG format only supports pixels with postmultiplied alpha. +If you want to replace the pixels, after reading them, with pixels +that have premultiplied color samples, you can do this with + + png_set_premultiply_alpha(png_ptr, output_gamma); + +where gamma is a double containing the gamma associated with the +premultiplied pixels. The gamma of the input must also be available +when the premultiplication takes place, via a gAMA chunk in the +input file or via png_set_gAMA(). If neither is present, the +premultiplication will assume input_gamma==(1/2.2) + +If you do this, any input with a tRNS chunk will be expanded to +have an alpha channel. + PNG files pack pixels of bit depths 1, 2, and 4 into bytes as small as they can, resulting in, for example, 8 pixels per byte for 1 bit files. This code expands to 1 pixel per byte without changing the @@ -3803,6 +3822,9 @@ after the png_malloc() to set the pointers to NULL. We added PNG_TRANSFORM_GRAY_TO_RGB to the available high-level input transforms. +We added the png_set_premultiply_alpha and +png_do_read_premultiply_alpha() functions. + The call to png_do_chop() in pngrtran.c, which reduces 16-bit input files to 8-bit bit depth, was relocated ahead of the building of gamma tables. This allows us to build 8-bit tables instead @@ -3990,13 +4012,13 @@ Other rules can be inferred by inspecting the libpng source. .SH XIII. Y2K Compliance in libpng -November 27, 2009 +November 28, 2009 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.4.1alpha01 are Y2K compliant. It is my belief that earlier +upward through 1.4.1alpha02 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 that @@ -4167,7 +4189,7 @@ the first widely used release: 1.4.0beta37-87 14 10400 14.so.14.0[.0] 1.4.0rc01 14 10400 14.so.14.0[.0] 1.4.0beta88-107 14 10400 14.so.14.0[.0] - 1.4.1alpha01 14 10401 14.so.14.0[.0] + 1.4.1alpha01-02 14 10401 14.so.14.0[.0] Henceforth the source version will match the shared-library minor and patch numbers; the shared-library major version number will be @@ -4223,7 +4245,7 @@ possible without all of you. Thanks to Frank J. T. Wojcik for helping with the documentation. -Libpng version 1.4.1alpha01 - November 27, 2009: +Libpng version 1.4.1alpha02 - November 28, 2009: Initially created in 1995 by Guy Eric Schalnat, then of Group 42, Inc. Currently maintained by Glenn Randers-Pehrson (glennrp at users.sourceforge.net). @@ -4246,7 +4268,7 @@ this sentence. This code is released under the libpng license. -libpng versions 1.2.6, August 15, 2004, through 1.4.1alpha01, November 27, 2009, are +libpng versions 1.2.6, August 15, 2004, through 1.4.1alpha02, November 28, 2009, are Copyright (c) 2004,2006-2007 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 @@ -4345,7 +4367,7 @@ certification mark of the Open Source Initiative. Glenn Randers-Pehrson glennrp at users.sourceforge.net -November 27, 2009 +November 28, 2009 .\" end of man page diff --git a/libpngpf.3 b/libpngpf.3 index bd7080883..62d4c28fd 100644 --- a/libpngpf.3 +++ b/libpngpf.3 @@ -1,6 +1,6 @@ -.TH LIBPNGPF 3 "November 27, 2009" +.TH LIBPNGPF 3 "November 28, 2009" .SH NAME -libpng \- Portable Network Graphics (PNG) Reference Library 1.4.1alpha01 +libpng \- Portable Network Graphics (PNG) Reference Library 1.4.1alpha02 (private functions) .SH SYNOPSIS \fB#include \fP @@ -211,6 +211,10 @@ libpng \- Portable Network Graphics (PNG) Reference Library 1.4.1alpha01 \fI\fB +\fBvoid png_do_read_premultiply_alpha (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP + +\fI\fB + \fBvoid png_do_read_swap_alpha (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP \fI\fB diff --git a/png.h b/png.h index f85d50520..c4c5d24cd 100644 --- a/png.h +++ b/png.h @@ -1,7 +1,7 @@ /* png.h - header file for PNG reference library * - * libpng version 1.4.1alpha01 - November 27, 2009 + * libpng version 1.4.1alpha02 - November 28, 2009 * Copyright (c) 1998-2009 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.4.1alpha01 - November 27, 2009: Glenn + * libpng versions 0.97, January 1998, through 1.4.1alpha02 - November 28, 2009: Glenn * See also "Contributing Authors", below. * * Note about libpng version numbers: @@ -132,7 +132,7 @@ * 1.4.0beta37-87 14 10400 14.so.14.0[.0] * 1.4.0rc01 14 10400 14.so.14.0[.0] * 1.4.0beta88-107 14 10400 14.so.14.0[.0] - * 1.4.1alpha01 14 10401 14.so.14.0[.0] + * 1.4.1alpha01-02 14 10401 14.so.14.0[.0] * * Henceforth the source version will match the shared-library major * and minor numbers; the shared-library major version number will be @@ -164,7 +164,7 @@ * * This code is released under the libpng license. * - * libpng versions 1.2.6, August 15, 2004, through 1.4.1alpha01, November 27, 2009, are + * libpng versions 1.2.6, August 15, 2004, through 1.4.1alpha02, November 28, 2009, are * Copyright (c) 2004, 2006-2007 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: @@ -282,7 +282,7 @@ * an official declaration. * * This is your unofficial assurance that libpng from version 0.71 and - * upward through 1.4.1alpha01 are Y2K compliant. It is my belief that earlier + * upward through 1.4.1alpha02 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 @@ -338,9 +338,9 @@ */ /* Version information for png.h - this should match the version in png.c */ -#define PNG_LIBPNG_VER_STRING "1.4.1alpha01" +#define PNG_LIBPNG_VER_STRING "1.4.1alpha02" #define PNG_HEADER_VERSION_STRING \ - " libpng version 1.4.1alpha01 - November 27, 2009\n" + " libpng version 1.4.1alpha02 - November 28, 2009\n" #define PNG_LIBPNG_VER_SONUM 14 #define PNG_LIBPNG_VER_DLLNUM 14 @@ -353,7 +353,7 @@ * PNG_LIBPNG_VER_STRING, omitting any leading zero: */ -#define PNG_LIBPNG_VER_BUILD 01 +#define PNG_LIBPNG_VER_BUILD 02 /* Release Status */ #define PNG_LIBPNG_BUILD_ALPHA 1 @@ -1332,17 +1332,22 @@ struct png_struct_def /* New member added in libpng-1.2.30 */ png_charp chunkdata PNG_DEPSTRUCT; /* buffer for reading chunk data */ -/* New member added in libpng-1.4.0 */ +/* New member added in libpng-1.2.41 */ #ifdef PNG_IO_STATE_SUPPORTED png_uint_32 io_state PNG_DEPSTRUCT; #endif + +/* New member added in libpng-1.4.1 */ +#ifdef PNG_READ_PREMULTIPLY_ALPHA_SUPPORTED + float gamma_premultiply; +#endif }; /* This triggers a compiler error in png.c, if png.c and png.h * do not agree upon the version number. */ -typedef png_structp version_1_4_1alpha01; +typedef png_structp version_1_4_1alpha02; typedef png_struct FAR * FAR * png_structpp; @@ -1524,6 +1529,11 @@ extern PNG_EXPORT(void,png_set_swap_alpha) PNGARG((png_structp png_ptr)); extern PNG_EXPORT(void,png_set_invert_alpha) PNGARG((png_structp png_ptr)); #endif +#ifdef PNG_READ_PREMULTIPLY_ALPHA_SUPPORTED +extern PNG_EXPORT(void,png_set_premultiply_alpha) + PNGARG((png_structp png_ptr, double gamma)); +#endif + #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED) /* Add a filler byte to 8-bit Gray or 24-bit RGB images. */ extern PNG_EXPORT(void,png_set_filler) PNGARG((png_structp png_ptr, diff --git a/pngconf.h b/pngconf.h index 9917534c4..9c29604f3 100644 --- a/pngconf.h +++ b/pngconf.h @@ -1,7 +1,7 @@ /* pngconf.h - machine configurable file for libpng * - * libpng version 1.4.1alpha01 - November 27, 2009 + * libpng version 1.4.1alpha02 - November 28, 2009 * For conditions of distribution and use, see copyright notice in png.h * Copyright (c) 1998-2009 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) @@ -523,6 +523,9 @@ # ifndef PNG_NO_READ_INVERT_ALPHA # define PNG_READ_INVERT_ALPHA_SUPPORTED # endif +# ifndef PNG_NO_READ_PREMULTIPLY_ALPHA +# define PNG_READ_PREMULTIPLY_ALPHA_SUPPORTED +# endif # ifndef PNG_NO_READ_STRIP_ALPHA # define PNG_READ_STRIP_ALPHA_SUPPORTED # endif diff --git a/pngpriv.h b/pngpriv.h index 82c14e5a0..f5d762dc7 100644 --- a/pngpriv.h +++ b/pngpriv.h @@ -1,7 +1,7 @@ /* pngpriv.h - private declarations for use inside libpng * - * libpng version 1.4.1alpha01 - November 27, 2009 + * libpng version 1.4.1alpha02 - November 28, 2009 * For conditions of distribution and use, see copyright notice in png.h * Copyright (c) 1998-2009 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) @@ -127,7 +127,8 @@ /* 0x800000L Unused */ #define PNG_ADD_ALPHA 0x1000000L /* Added to libpng-1.2.7 */ #define PNG_EXPAND_tRNS 0x2000000L /* Added to libpng-1.2.9 */ - /* 0x4000000L unused */ +#define PNG_PREMULTIPLY_ALPHA 0x4000000L /* Added to libpng-1.4.0 */ + /* by volker */ /* 0x8000000L unused */ /* 0x10000000L unused */ /* 0x20000000L unused */ @@ -551,6 +552,11 @@ PNG_EXTERN void png_do_strip_filler PNGARG((png_row_infop row_info, png_bytep row, png_uint_32 flags)); #endif +#ifdef PNG_READ_PREMULTIPLY_ALPHA_SUPPORTED +PNG_EXTERN void png_do_read_premultiply_alpha + PNGARG((png_row_infop row_info, png_bytep row)); +#endif + #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED) PNG_EXTERN void png_do_swap PNGARG((png_row_infop row_info, png_bytep row)); #endif @@ -944,9 +950,24 @@ extern void *png_far_to_near PNGARG((png_structp png_ptr,png_voidp ptr, #define png_debug2(l, m, p1, p2) #endif -#if 0 -extern PNG_EXPORT(png_bytep,png_sig_bytes) PNGARG((void)); -#endif +#ifdef PNG_READ_PREMULTIPLY_ALPHA_SUPPORTED +# ifdef PNG_READ_COMPOSITE_NODIV_SUPPORTED +# define PNG_DIVIDE_BY_255(v) \ + ((png_byte)(((png_uint_16)(v) + \ + (((png_uint_16)(v) + 128) >> 8) + 128) >> 8)) +# define PNG_DIVIDE_BY_65535(v) \ + ((png_byte)(((png_uint_32)(v) + \ + (((png_uint_32)(v) + 32768L) >> 16) + 32768L) >> 16)) +# else +# define PNG_DIVIDE_BY_255(v) (((png_uint_16)(v))/255) +# define PNG_DIVIDE_BY_65535(v) (((png_uint_32)(v))/65535L) +# endif /* PNG_READ_COMPOSITE_NODIV_SUPPORTED */ + +# define PNG_8_BIT_PREMULTIPLY(color,alpha) \ + PNG_DIVIDE_BY_255((color)*(alpha)) +# define PNG_16_BIT_PREMULTIPLY(color,alpha)\ + PNG_DIVIDE_BY_65535((color)*(alpha)) +#endif /* PNG_READ_PREMULTIPLY_ALPHA_SUPPORTED */ /* Maintainer: Put new private prototypes here ^ and in libpngpf.3 */ diff --git a/pngrtran.c b/pngrtran.c index 2289c238f..32248c018 100644 --- a/pngrtran.c +++ b/pngrtran.c @@ -1,7 +1,7 @@ /* pngrtran.c - transforms the data in a row for PNG readers * - * Last changed in libpng 1.4.0 [November 27, 2009] + * Last changed in libpng 1.4.0 [November 28, 2009] * Copyright (c) 1998-2009 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.) @@ -140,6 +140,26 @@ png_set_strip_alpha(png_structp png_ptr) } #endif +#ifdef PNG_READ_PREMULTIPLY_ALPHA_SUPPORTED +void PNGAPI +png_set_premultiply_alpha(png_structp png_ptr, double gamma) +{ + png_debug(1, "in png_set_premultiply_alpha"); + + if(png_ptr == NULL) + return; + png_ptr->transformations |= + (PNG_PREMULTIPLY_ALPHA | PNG_EXPAND_tRNS); + png_ptr->transformations |= + PNG_EXPAND; /* This shouldn't be necessary */ + png_ptr->flags &= ~PNG_FLAG_ROW_INIT; + /* Check for overflow */ + if (gamma == 0 || gamma > 21474.83) + png_error(png_ptr, "Invalid gamma for premultiply"); + png_ptr->gamma_premultiply = (float)gamma; +} +#endif + #ifdef PNG_READ_DITHER_SUPPORTED /* Dither file to 8 bit. Supply a palette, the current number * of elements in the palette, the maximum number of elements @@ -1492,6 +1512,12 @@ png_do_read_transformations(png_structp png_ptr) (png_uint_32)png_ptr->filler, png_ptr->flags); #endif +#ifdef PNG_READ_PREMULTIPLY_ALPHA_SUPPORTED + if (png_ptr->transformations & PNG_PREMULTIPLY_ALPHA) + png_do_read_premultiply_alpha(&(png_ptr->row_info), + png_ptr->row_buf + 1); +#endif + #ifdef PNG_READ_INVERT_ALPHA_SUPPORTED if (png_ptr->transformations & PNG_INVERT_ALPHA) png_do_read_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1); @@ -1978,6 +2004,84 @@ png_do_read_invert_alpha(png_row_infop row_info, png_bytep row) } #endif +#ifdef PNG_READ_PREMULTIPLY_ALPHA_SUPPORTED +void /* PRIVATE */ +png_do_read_premultiply_alpha(png_row_infop row_info, png_bytep row) +{ + png_debug(1, "in png_do_read_premultiply_alpha"); + + { + png_uint_32 row_width = row_info->width; + if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) + { + /* This premultiplies the pixels with the alpha channel in RGBA */ + if (row_info->bit_depth == 8) + { + png_bytep sp = row + row_info->rowbytes; + png_bytep dp = sp; + png_uint_16 a = 0; + png_uint_32 i; + + for (i = 0; i < row_width; i++) + { + a = *(--sp); --dp; + sp--; *(--dp) = PNG_8_BIT_PREMULTIPLY((*sp), a); + sp--; *(--dp) = PNG_8_BIT_PREMULTIPLY((*sp), a); + sp--; *(--dp) = PNG_8_BIT_PREMULTIPLY((*sp), a); + } + } + /* This premultiplies the pixels with the alpha channel in RRGGBBAA */ + else + { + png_uint_16p sp = (png_uint_16p)(row + row_info->rowbytes); + png_uint_16p dp = sp; + png_uint_32 a = 0; + png_uint_32 i; + + for (i = 0; i < row_width; i++) + { + a = *(--sp); --dp; + sp--; *(--dp) = PNG_16_BIT_PREMULTIPLY((*sp), a); + sp--; *(--dp) = PNG_16_BIT_PREMULTIPLY((*sp), a); + sp--; *(--dp) = PNG_16_BIT_PREMULTIPLY((*sp), a); + } + } + } + else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) + { + /* This premultiplies the pixels with the alpha channel in GA */ + if (row_info->bit_depth == 8) + { + png_bytep sp = row + row_info->rowbytes; + png_bytep dp = sp; + png_uint_16 a = 0; + png_uint_32 i; + + for (i = 0; i < row_width; i++) + { + a = *(--sp); --dp; + sp--; *(--dp) = PNG_8_BIT_PREMULTIPLY((*sp), a); + } + } + /* This premultiplies the pixels with the alpha channel in GGAA */ + else + { + png_uint_16p sp = (png_uint_16p) (row + row_info->rowbytes); + png_uint_16p dp = sp; + png_uint_32 a = 0; + png_uint_32 i; + + for (i = 0; i < row_width; i++) + { + a = *(--sp); --dp; + sp--; *(--dp) = PNG_16_BIT_PREMULTIPLY((*sp), a); + } + } + } + } +} +#endif + #ifdef PNG_READ_FILLER_SUPPORTED /* Add filler channel if we have RGB color */ void /* PRIVATE */