[devel] Added "bit_depth" parameter to the private png_build_gamma_table()

function.  Pass bit_depth=8 to png_build_gamma_table() when bit_depth is 16
but the PNG_16_TO_8 transform has been set, to avoid unnecessary build of
16-bit tables.
diff --git a/ANNOUNCE b/ANNOUNCE
index 278ca28..52b4417 100644
--- a/ANNOUNCE
+++ b/ANNOUNCE
@@ -1,5 +1,5 @@
 
-Libpng 1.4.0beta108 - December 11, 2009
+Libpng 1.4.0beta109 - December 13, 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,20 +9,20 @@
 Source files with LF line endings (for Unix/Linux) and with a
 "configure" script
 
-   1.4.0beta108.tar.xz (LZMA-compressed, recommended)
-   1.4.0beta108.tar.gz
-   1.4.0beta108.tar.bz2
+   1.4.0beta109.tar.xz (LZMA-compressed, recommended)
+   1.4.0beta109.tar.gz
+   1.4.0beta109.tar.bz2
 
 Source files with CRLF line endings (for Windows), without the
 "configure" script
 
-   lp140b108.zip
-   lp140b108.7z
+   lp140b109.zip
+   lp140b109.7z
 
 Other information:
 
-   1.4.0beta108-README.txt
-   1.4.0beta108-LICENSE.txt
+   1.4.0beta109-README.txt
+   1.4.0beta109-LICENSE.txt
 
 Changes since the last public release (1.2.10):
 
@@ -734,6 +734,12 @@
     change in version 1.2.41beta08 caused transparency to be handled wrong
     in some 16-bit datastreams (Yusaku Sugai).
 
+version 1.4.0beta109 [December 13, 2009]
+  Added "bit_depth" parameter to the private png_build_gamma_table() function.
+  Pass bit_depth=8 to png_build_gamma_table() when bit_depth is 16 but the
+    PNG_16_TO_8 transform has been set, to avoid unnecessary build of 16-bit
+    tables.
+
 Send comments/corrections/commendations to png-mng-implement at lists.sf.net
 (subscription required; visit
 https://lists.sourceforge.net/lists/listinfo/png-mng-implement
diff --git a/CHANGES b/CHANGES
index 78e5e1c..24d54f0 100644
--- a/CHANGES
+++ b/CHANGES
@@ -2421,6 +2421,12 @@
     change in version 1.2.41beta08 caused transparency to be handled wrong
     in some 16-bit datastreams (Yusaku Sugai).
 
+version 1.4.0beta109 [December 13, 2009]
+  Added "bit_depth" parameter to the private png_build_gamma_table() function.
+  Pass bit_depth=8 to png_build_gamma_table() when bit_depth is 16 but the
+    PNG_16_TO_8 transform has been set, to avoid unnecessary build of 16-bit
+    tables.
+
 Send comments/corrections/commendations to png-mng-implement at lists.sf.net
 (subscription required; visit
 https://lists.sourceforge.net/lists/listinfo/png-mng-implement
diff --git a/libpngpf.3 b/libpngpf.3
index 6e8cb83..8ef1f8f 100644
--- a/libpngpf.3
+++ b/libpngpf.3
@@ -1,4 +1,4 @@
-.TH LIBPNGPF 3 "December 11, 2009"
+.TH LIBPNGPF 3 "December 13, 2009"
 .SH NAME
 libpng \- Portable Network Graphics (PNG) Reference Library 1.4.0beta108
 (private functions)
@@ -15,7 +15,7 @@
 
 \fI\fB
 
-\fBvoid png_build_gamma_table (png_structp \fIpng_ptr\fP\fB);\fP
+\fBvoid png_build_gamma_table (png_structp \fP\fIpng_ptr\fP\fB, png_byte \fIbit_depth\fP\fB);\fP
 
 \fI\fB
 
diff --git a/pngpriv.h b/pngpriv.h
index bbff625..ea8b613 100644
--- a/pngpriv.h
+++ b/pngpriv.h
@@ -1,7 +1,7 @@
 
 /* pngpriv.h - private declarations for use inside libpng
  *
- * libpng version 1.4.0beta108 - December 11, 2009
+ * libpng version 1.4.0beta109 - December 13, 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)
@@ -475,7 +475,8 @@
 PNG_EXTERN void png_write_start_row PNGARG((png_structp png_ptr));
 
 #ifdef PNG_READ_GAMMA_SUPPORTED
-PNG_EXTERN void png_build_gamma_table PNGARG((png_structp png_ptr));
+PNG_EXTERN void png_build_gamma_table PNGARG((png_structp png_ptr,
+   png_byte bit_depth));
 #endif
 
 /* Combine a row of data, dealing with alpha, etc. if requested */
diff --git a/pngrtran.c b/pngrtran.c
index 31a1022..ebd447c 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 [December 11, 2009]
+ * Last changed in libpng 1.4.0 [December 13, 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.)
@@ -886,7 +886,11 @@
    if ((png_ptr->transformations & (PNG_GAMMA | PNG_RGB_TO_GRAY)) &&
         png_ptr->gamma != 0.0)
    {
-      png_build_gamma_table(png_ptr);
+      if (png_ptr->transformations & PNG_16_TO_8)
+         png_build_gamma_table(png_ptr, 8);
+      else
+         png_build_gamma_table(png_ptr, png_ptr->bit_depth);
+
 #ifdef PNG_READ_BACKGROUND_SUPPORTED
       if (png_ptr->transformations & PNG_BACKGROUND)
       {
@@ -3910,11 +3914,11 @@
  */
 
 void /* PRIVATE */
-png_build_gamma_table(png_structp png_ptr)
+png_build_gamma_table(png_structp png_ptr, png_byte bit_depth)
 {
   png_debug(1, "in png_build_gamma_table");
 
-  if (png_ptr->bit_depth <= 8)
+  if (bit_depth <= 8)
   {
      int i;
      double g;