From 99708d560f8690b7ad83546cfe2072956730b567 Mon Sep 17 00:00:00 2001 From: Glenn Randers-Pehrson Date: Mon, 29 Jun 2009 17:30:00 -0500 Subject: [PATCH] [devel] Added high-level PNG_TRANSFORM_GRAY_TO_RGB transform. --- ANNOUNCE | 4 ++-- CHANGES | 4 ++-- libpng-1.4.0beta67.txt | 9 ++++++++- libpng.3 | 9 ++++++++- png.h | 6 ++++-- pngread.c | 7 +++++++ pngwrite.c | 6 ++++++ 7 files changed, 37 insertions(+), 8 deletions(-) diff --git a/ANNOUNCE b/ANNOUNCE index 354735aa1..8f3d6efba 100644 --- a/ANNOUNCE +++ b/ANNOUNCE @@ -495,8 +495,8 @@ version 1.4.0beta66 [June 27, 2009] Refer to the libpng license instead of the libpng license in each file. version 1.4.0beta67 [June 29, 2009] - Relocated INVERT_ALPHA within png_read_png() and png_write_png() - to match its position in pngrtran.c. + Relocated INVERT_ALPHA within png_read_png() and png_write_png(). + Added high-level API transform PNG_TRANSFORM_GRAY_TO_RGB. version 1.4.0betaN [future] Build shared libraries with -lz and sometimes -lm. diff --git a/CHANGES b/CHANGES index c82f3e48a..056675fa5 100644 --- a/CHANGES +++ b/CHANGES @@ -2172,8 +2172,8 @@ version 1.4.0beta66 [June 27, 2009] Refer to the libpng license instead of the libpng license in each file. version 1.4.0beta67 [June 29, 2009] - Relocated INVERT_ALPHA within png_read_png() and png_write_png() - to match its position in pngrtran.c. + Relocated INVERT_ALPHA within png_read_png() and png_write_png(). + Added high-level API transform PNG_TRANSFORM_GRAY_TO_RGB. version 1.4.0betaN [future] Build shared libraries with -lz and sometimes -lm. diff --git a/libpng-1.4.0beta67.txt b/libpng-1.4.0beta67.txt index ce7d7f8ad..6b2be1fe4 100644 --- a/libpng-1.4.0beta67.txt +++ b/libpng-1.4.0beta67.txt @@ -447,6 +447,8 @@ you want to do are limited to the following set: PNG_TRANSFORM_INVERT_ALPHA Change alpha from opacity to transparency PNG_TRANSFORM_SWAP_ENDIAN Byte-swap 16-bit samples + PNG_TRANSFORM_GRAY_TO_RGB Expand grayscale samples + to RGB (or GA to RGBA) (This excludes setting a background color, doing gamma transformation, dithering, and setting filler.) If this is the case, simply do this: @@ -3028,13 +3030,18 @@ The png_calloc() function was added. We removed the trailing '.' from the warning and error messages. +We added PNG_TRANSFORM_GRAY_TO_RGB to the available high-level +input transforms. + X. Detecting libpng The png_get_io_ptr() function has been present since libpng-0.88, has never changed, and is unaffected by conditional compilation macros. It is the best choice for use in configure scripts for detecting the presence of any -libpng version since 0.88. +libpng version since 0.88. In an autoconf "configure.in" you could use + + AC_CHECK_LIB(png, png_get_io_ptr, ... XI. Source code repository diff --git a/libpng.3 b/libpng.3 index 1a1e0fc26..89575d28d 100644 --- a/libpng.3 +++ b/libpng.3 @@ -1256,6 +1256,8 @@ you want to do are limited to the following set: PNG_TRANSFORM_INVERT_ALPHA Change alpha from opacity to transparency PNG_TRANSFORM_SWAP_ENDIAN Byte-swap 16-bit samples + PNG_TRANSFORM_GRAY_TO_RGB Expand grayscale samples + to RGB (or GA to RGBA) (This excludes setting a background color, doing gamma transformation, dithering, and setting filler.) If this is the case, simply do this: @@ -3837,13 +3839,18 @@ The png_calloc() function was added. We removed the trailing '.' from the warning and error messages. +We added PNG_TRANSFORM_GRAY_TO_RGB to the available high-level +input transforms. + .SH X. Detecting libpng The png_get_io_ptr() function has been present since libpng-0.88, has never changed, and is unaffected by conditional compilation macros. It is the best choice for use in configure scripts for detecting the presence of any -libpng version since 0.88. +libpng version since 0.88. In an autoconf "configure.in" you could use + + AC_CHECK_LIB(png, png_get_io_ptr, ... .SH XI. Source code repository diff --git a/png.h b/png.h index fb3fd32e2..29874021d 100644 --- a/png.h +++ b/png.h @@ -1046,10 +1046,12 @@ typedef void (PNGAPI *png_unknown_chunk_ptr) PNGARG((png_structp)); #define PNG_TRANSFORM_SWAP_ALPHA 0x0100 /* read and write */ #define PNG_TRANSFORM_SWAP_ENDIAN 0x0200 /* read and write */ #define PNG_TRANSFORM_INVERT_ALPHA 0x0400 /* read and write */ -#define PNG_TRANSFORM_STRIP_FILLER 0x0800 /* WRITE only */ +#define PNG_TRANSFORM_STRIP_FILLER 0x0800 /* write only */ /* Added to libpng-1.2.34 */ #define PNG_TRANSFORM_STRIP_FILLER_BEFORE PNG_TRANSFORM_STRIP_FILLER -#define PNG_TRANSFORM_STRIP_FILLER_AFTER 0x1000 /* WRITE only */ +#define PNG_TRANSFORM_STRIP_FILLER_AFTER 0x1000 /* write only */ +/* Added to libpng-1.4.0 */ +#define PNG_TRANSFORM_GRAY_TO_RGB 0x2000 /* read only */ /* Flags for MNG supported features */ #define PNG_FLAG_MNG_EMPTY_PLTE 0x01 diff --git a/pngread.c b/pngread.c index 9ef8fd76d..3120b44a5 100644 --- a/pngread.c +++ b/pngread.c @@ -1302,6 +1302,13 @@ png_read_png(png_structp png_ptr, png_infop info_ptr, png_set_invert_alpha(png_ptr); #endif +#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED) + /* Expand grayscale image to RGB + */ + if (transforms & PNG_TRANSFORM_GRAY_TO_RGB) + png_set_gray_to_rgb(png_structp png_ptr); +#endif + /* We don't handle adding filler bytes */ /* Optional call to gamma correct and add the background to the palette diff --git a/pngwrite.c b/pngwrite.c index 27744a7b5..526c5056b 100644 --- a/pngwrite.c +++ b/pngwrite.c @@ -1406,6 +1406,12 @@ png_write_png(png_structp png_ptr, png_infop info_ptr, png_set_packswap(png_ptr); #endif +#if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED) + /* Invert the alpha channel from opacity to transparency */ + if (transforms & PNG_TRANSFORM_INVERT_ALPHA) + png_set_invert_alpha(png_ptr); +#endif + #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED) /* Invert the alpha channel from opacity to transparency */ if (transforms & PNG_TRANSFORM_INVERT_ALPHA)