From 7d3e6732fbf529be0571fb89a5f778d89b2553ac Mon Sep 17 00:00:00 2001 From: Glenn Randers-Pehrson Date: Thu, 26 Aug 2010 17:14:07 -0500 Subject: [PATCH] [devel] Added PNG_WRITE_16BIT_SUPPORTED option. --- ANNOUNCE | 1 + CHANGES | 3 ++- pngwtran.c | 10 ++++++++++ pngwutil.c | 18 ++++++++++++++++++ scripts/pnglibconf.dfa | 4 +++- scripts/pnglibconf.h.prebuilt | 1 + scripts/pngwin.dfn | 2 +- 7 files changed, 36 insertions(+), 3 deletions(-) diff --git a/ANNOUNCE b/ANNOUNCE index 4cbd57ad8..056431e6d 100644 --- a/ANNOUNCE +++ b/ANNOUNCE @@ -390,6 +390,7 @@ Version 1.5.0beta45 [August 26, 2010] Version 1.5.0beta46 [August 26, 2010] Added new private header files to libpng_sources in CMakeLists.txt + Added PNG_WRITE_16BIT_SUPPORTED option. Send comments/corrections/commendations to png-mng-implement at lists.sf.net: (subscription required; visit diff --git a/CHANGES b/CHANGES index fd6aa317e..42deec3ac 100644 --- a/CHANGES +++ b/CHANGES @@ -3026,7 +3026,8 @@ Version 1.5.0beta45 [August 26, 2010] in pngpriv.h in case the user neglected to define them in their pngusr.h Version 1.5.0beta46 [August 26, 2010] -[devel] Added new private header files to libpng_sources in CMakeLists.txt + Added new private header files to libpng_sources in CMakeLists.txt + Added PNG_WRITE_16BIT_SUPPORTED option. Send comments/corrections/commendations to png-mng-implement at lists.sf.net (subscription required; visit diff --git a/pngwtran.c b/pngwtran.c index 8293a5941..1c2e7afb7 100644 --- a/pngwtran.c +++ b/pngwtran.c @@ -393,6 +393,7 @@ png_do_write_swap_alpha(png_row_infop row_info, png_bytep row) } } +#ifdef PNG_WRITE_16BIT_SUPPORTED else { /* This converts from AARRGGBB to RRGGBBAA */ @@ -415,6 +416,7 @@ png_do_write_swap_alpha(png_row_infop row_info, png_bytep row) *(dp++) = save[1]; } } +#endif /* PNG_WRITE_16BIT_SUPPORTED */ } else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) @@ -434,6 +436,7 @@ png_do_write_swap_alpha(png_row_infop row_info, png_bytep row) } } +#ifdef PNG_WRITE_16BIT_SUPPORTED else { /* This converts from AAGG to GGAA */ @@ -452,6 +455,7 @@ png_do_write_swap_alpha(png_row_infop row_info, png_bytep row) *(dp++) = save[1]; } } +#endif /* PNG_WRITE_16BIT_SUPPORTED */ } } } @@ -485,6 +489,7 @@ png_do_write_invert_alpha(png_row_infop row_info, png_bytep row) } } +#ifdef PNG_WRITE_16BIT_SUPPORTED else { /* This inverts the alpha channel in RRGGBBAA */ @@ -507,6 +512,7 @@ png_do_write_invert_alpha(png_row_infop row_info, png_bytep row) *(dp++) = (png_byte)(255 - *(sp++)); } } +#endif /* PNG_WRITE_16BIT_SUPPORTED */ } else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) @@ -525,6 +531,7 @@ png_do_write_invert_alpha(png_row_infop row_info, png_bytep row) } } +#ifdef PNG_WRITE_16BIT_SUPPORTED else { /* This inverts the alpha channel in GGAA */ @@ -543,6 +550,7 @@ png_do_write_invert_alpha(png_row_infop row_info, png_bytep row) *(dp++) = (png_byte)(255 - *(sp++)); } } +#endif /* PNG_WRITE_16BIT_SUPPORTED */ } } } @@ -580,6 +588,7 @@ png_do_write_intrapixel(png_row_infop row_info, png_bytep row) } } +#ifdef PNG_WRITE_16BIT_SUPPORTED else if (row_info->bit_depth == 16) { png_bytep rp; @@ -607,6 +616,7 @@ png_do_write_intrapixel(png_row_infop row_info, png_bytep row) *(rp + 5) = (png_byte)(blue & 0xff); } } +#endif /* PNG_WRITE_16BIT_SUPPORTED */ } } #endif /* PNG_MNG_FEATURES_SUPPORTED */ diff --git a/pngwutil.c b/pngwutil.c index 89fb22b41..eb60ef6c0 100644 --- a/pngwutil.c +++ b/pngwutil.c @@ -449,7 +449,9 @@ png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height, case 2: case 4: case 8: +#ifdef PNG_WRITE_16BIT_SUPPORTED case 16: +#endif png_ptr->channels = 1; break; default: png_error(png_ptr, @@ -458,7 +460,11 @@ png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height, break; case PNG_COLOR_TYPE_RGB: +#ifdef PNG_WRITE_16BIT_SUPPORTED if (bit_depth != 8 && bit_depth != 16) +#else + if (bit_depth != 8) +#endif png_error(png_ptr, "Invalid bit depth for RGB image"); png_ptr->channels = 3; @@ -486,7 +492,11 @@ png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height, break; case PNG_COLOR_TYPE_RGB_ALPHA: +#ifdef PNG_WRITE_16BIT_SUPPORTED if (bit_depth != 8 && bit_depth != 16) +#else + if (bit_depth != 8) +#endif png_error(png_ptr, "Invalid bit depth for RGBA image"); png_ptr->channels = 4; @@ -1106,7 +1116,11 @@ png_write_tRNS(png_structp png_ptr, png_const_bytep trans_alpha, png_save_uint_16(buf, tran->red); png_save_uint_16(buf + 2, tran->green); png_save_uint_16(buf + 4, tran->blue); +#ifdef PNG_WRITE_16BIT_SUPPORTED if (png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4])) +#else + if (buf[0] | buf[2] | buf[4]) +#endif { png_warning(png_ptr, "Ignoring attempt to write 16-bit tRNS chunk when bit_depth is 8"); @@ -1154,7 +1168,11 @@ png_write_bKGD(png_structp png_ptr, png_const_color_16p back, int color_type) png_save_uint_16(buf, back->red); png_save_uint_16(buf + 2, back->green); png_save_uint_16(buf + 4, back->blue); +#ifdef PNG_WRITE_16BIT_SUPPORTED if (png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4])) +#else + if (buf[0] | buf[2] | buf[4]) +#endif { png_warning(png_ptr, "Ignoring attempt to write 16-bit bKGD chunk when bit_depth is 8"); diff --git a/scripts/pnglibconf.dfa b/scripts/pnglibconf.dfa index 172a7ae80..ffde44bc9 100644 --- a/scripts/pnglibconf.dfa +++ b/scripts/pnglibconf.dfa @@ -6,7 +6,7 @@ # com pnglibconf.h - library build configuration com -com libpng version PNGLIB_VERSION - last changed on August 26, 2010 +com libpng version 1.5.0beta46 - last changed on August 26, 2010 com com Copyright (c) 1998-2010 Glenn Randers-Pehrson com @@ -314,6 +314,8 @@ option READ_16_TO_8_ACCURATE_SCALE requires READ disabled # WRITE options option WRITE +option WRITE_16BIT requires WRITE + option WRITE_TRANSFORMS requires WRITE = NO_WRITE_TRANSFORMS PNG_WRITE_TRANSFORMS_NOT_SUPPORTED diff --git a/scripts/pnglibconf.h.prebuilt b/scripts/pnglibconf.h.prebuilt index df9d1da30..3d20f9603 100644 --- a/scripts/pnglibconf.h.prebuilt +++ b/scripts/pnglibconf.h.prebuilt @@ -39,6 +39,7 @@ #define PNG_WARNINGS_SUPPORTED #define PNG_FLOATING_ARITHMETIC_SUPPORTED #define PNG_WRITE_SUPPORTED +#define PNG_WRITE_16BIT_SUPPORTED #define PNG_WRITE_INTERLACING_SUPPORTED #define PNG_EASY_ACCESS_SUPPORTED #define PNG_ALIGN_MEMORY_SUPPORTED diff --git a/scripts/pngwin.dfn b/scripts/pngwin.dfn index 45cbd9753..3dddc98f8 100644 --- a/scripts/pngwin.dfn +++ b/scripts/pngwin.dfn @@ -29,7 +29,7 @@ PNG_DEFN_MAGIC-;OS2 DESCRIPTION "PNG image compression library"-PNG_DEFN_END PNG_DEFN_MAGIC-;OS2 CODE PRELOAD MOVEABLE DISCARDABLE-PNG_DEFN_END PNG_DEFN_MAGIC--PNG_DEFN_END PNG_DEFN_MAGIC-EXPORTS-PNG_DEFN_END -PNG_DEFN_MAGIC-;Version PNGLIB_VERSION-PNG_DEFN_END +PNG_DEFN_MAGIC-;Version 1.5.0beta46-PNG_DEFN_END /* Read the defaults, but use scripts/pnglibconf.h.prebuilt; the 'standard' * header file.