]> git.imager.perl.org - imager.git/commitdiff
Fixed png transparency handling
authorArnar Mar Hrafnkelsson <addi@cpan.org>
Wed, 9 May 2001 16:54:37 +0000 (16:54 +0000)
committerArnar Mar Hrafnkelsson <addi@cpan.org>
Wed, 9 May 2001 16:54:37 +0000 (16:54 +0000)
Changes
STATUS
png.c

diff --git a/Changes b/Changes
index 7683e34e1ab1a173fada1b41877fdd6cc354311e..f8b553ce24f230a17a440324ebfcd9c23a43b49b 100644 (file)
--- a/Changes
+++ b/Changes
@@ -365,7 +365,7 @@ Revision history for Perl extension Imager.
         - Win32 support for jpeg
         - Win32 support for tiff
         - base level error reporting code added, I still need to modify
-        older code to use it
+          older code to use it
         - fix translate=>'giflib' handling of single-colour images.  
           Previously a single colour image would cause an error in 
           MakeMapObject().
@@ -374,33 +374,35 @@ Revision history for Perl extension Imager.
         - minor doc fixes for transparent gifs
         - make it less error-prone to write transparent gifs
         - documented the options for reading raw images
-       - Changes switched to use spaces for formatting
-       - switch gif.c to new error reporting with related changes to
-         Imager.xs, Imager.pm
+        - Changes switched to use spaces for formatting
+        - switch gif.c to new error reporting with related changes to
+          Imager.xs, Imager.pm
         - each of the image formats now have their own test file,
           extracted from t10formats.t, usually with som extra tests
         - Added flip() and docs to Imager.pm and i_flipxy to image.c.
           Added testcases too.
-       - Fixed an overflow bug in png.c
-       - added the colors parameter to Imager::read() which receives 
-       the arrayref of colours that i_readgif(_scalar) returns
-       - fixed a problem in makemap_addi in quant.c where only the first
-       image was compared against the palette when the palette was being 
-       refined.  I screwed up on this originally (TC).  This is the other
-       half of a fix for Leolo's lmfixed problem <sigh>.
-       - makemap_addi() now only puts colours into the palette that it
-       found while optimizing the palette (so we don't get 256 colour
-       palettes for 2 colour images :)
-       - initial implementation of a row-based interface to low-level
-       images (for performance)
-       - changed Imager::read() for GIF so that the arrayref pointed to 
-       by the ref supplied in colors contains Imager::Color objects 
-       instead of more arrayrefs, keep this interface stable until we 
-       can make an informed choice about i_readgif()
-       - incorporated Micksa's faxable tiff support, treating as a type
-       of tiff rather than a separate format
-       - t/t70newgif.t now checks for gif support
-       - added the convert() method
+        - Fixed an overflow bug in png.c
+        - added the colors parameter to Imager::read() which receives 
+          the arrayref of colours that i_readgif(_scalar) returns
+        - fixed a problem in makemap_addi in quant.c where only the first
+          image was compared against the palette when the palette was being 
+          refined.  I screwed up on this originally (TC).  This is the other
+          half of a fix for Leolo's lmfixed problem <sigh>.
+        - makemap_addi() now only puts colours into the palette that it
+          found while optimizing the palette (so we don't get 256 colour
+          palettes for 2 colour images :)
+        - initial implementation of a row-based interface to low-level
+          images (for performance)
+        - changed Imager::read() for GIF so that the arrayref pointed to 
+          by the ref supplied in colors contains Imager::Color objects 
+          instead of more arrayrefs, keep this interface stable until we 
+          can make an informed choice about i_readgif()
+        - incorporated Micksa's faxable tiff support, treating as a type
+          of tiff rather than a separate format
+        - t/t70newgif.t now checks for gif support
+        - added the convert() method
+        - Added support for transparent to alpha conversion during loading
+          of png files.
 
 ~~~~~~~~~~~~~^ ^ ^~~~~~~~~~~~~~
 
diff --git a/STATUS b/STATUS
index f9ae179bb5916ca4c1058eda52e0a54b02eccd00..5aeb061eb623ea53ce58b4b7a8eacfeebedd1b35 100644 (file)
--- a/STATUS
+++ b/STATUS
@@ -1,4 +1,4 @@
-filters.c             # pod (excpet experimental)
+filters.c             # pod (except experimental)
 font.c                # pod
 gif.c                 # pod
 image.c               # pod
diff --git a/png.c b/png.c
index 1c0a6ab1fa4d6731bd7674c6db593065426dd2ab..41b5f9792528afccddb75bb159c03ee7cecb58d4 100644 (file)
--- a/png.c
+++ b/png.c
@@ -38,11 +38,11 @@ int CC2C[PNG_COLOR_MASK_PALETTE|PNG_COLOR_MASK_COLOR|PNG_COLOR_MASK_ALPHA];
 
 
 /*
-png_set_read_fn(png_structp read_ptr, voidp read_io_ptr, png_rw_ptr read_data_fn)
-png_set_write_fn(png_structp write_ptr, voidp write_io_ptr, png_rw_ptr write_data_fn,
-png_flush_ptr output_flush_fn);
-voidp read_io_ptr = png_get_io_ptr(read_ptr);
-voidp write_io_ptr = png_get_io_ptr(write_ptr);
+  png_set_read_fn(png_structp read_ptr, voidp read_io_ptr, png_rw_ptr read_data_fn)
+  png_set_write_fn(png_structp write_ptr, voidp write_io_ptr, png_rw_ptr write_data_fn,
+  png_flush_ptr output_flush_fn);
+  voidp read_io_ptr = png_get_io_ptr(read_ptr);
+  voidp write_io_ptr = png_get_io_ptr(write_ptr);
 */
 
 struct png_scalar_info {
@@ -73,7 +73,7 @@ user_read_data(png_structp png_ptr,png_bytep data, png_size_t length) {
 /*
 static void
 user_write_data(png_structp png_ptr, png_bytep data, png_uint_32 length) {
-   FIXME: implement these 
+FIXME: implement these 
 }
 
 static void
@@ -190,11 +190,8 @@ i_readpng(int fd) {
   CC2C[PNG_COLOR_TYPE_GRAY_ALPHA]=2;
 
   channels=CC2C[color_type];
-  
   mm_log((1,"channels %d\n", channels));
   
-  im = i_img_empty_ch(NULL, width, height, channels);
-
   /**** Set up the data transformations you want.  Note that these are all
    **** optional.  Only call them if you want/need them.  Many of the
    **** transformations only work on specific types of images, and many
@@ -219,29 +216,34 @@ i_readpng(int fd) {
 
   /* Expand paletted or RGB images with transparency to full alpha channels
    * so the data will be available as RGBA quartets.
-   *
-   * if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) png_set_expand(png_ptr);
-   * 
    */
+
+  if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
+    channels++;
+    mm_log((1, "image has transparency, adding alpha: channels = %d\n", channels));
+    png_set_expand(png_ptr);
+  }
   
   /* Strip alpha bytes from the input data without combining with the
    * background (not recommended).
    */
-  if ( (color_type != PNG_COLOR_TYPE_RGB_ALPHA) && (color_type != PNG_COLOR_TYPE_GRAY_ALPHA) )
+  /*
+    if ( (color_type != PNG_COLOR_TYPE_RGB_ALPHA) && (color_type != PNG_COLOR_TYPE_GRAY_ALPHA) )
     png_set_strip_alpha(png_ptr);
-
+  */
   number_passes = png_set_interlace_handling(png_ptr);
 
   mm_log((1,"number of passes=%d\n",number_passes));
   
   png_read_update_info(png_ptr, info_ptr);
 
+  im = i_img_empty_ch(NULL, width, height, channels);
   for (pass = 0; pass < number_passes; pass++)
     for (y = 0; y < height; y++) {
       png_read_row(png_ptr,(png_bytep) &(im->data[channels*width*y]), NULL);
     }
   /* read rest of file, and get additional chunks in info_ptr - REQUIRED */
-
+  
   png_read_end(png_ptr, info_ptr); 
   /* clean up after the read, and free any memory allocated - REQUIRED */
   png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
@@ -396,7 +398,13 @@ i_readpng_scalar(char *data, int length) {
   png_set_packing(png_ptr);
   if (color_type == PNG_COLOR_TYPE_PALETTE) png_set_expand(png_ptr);
   if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) png_set_expand(png_ptr);
-  if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) png_set_expand(png_ptr);
+
+  if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
+    channels++;
+    mm_log((1, "image has transparency, adding alpha: channels = %d\n", channels));
+    png_set_expand(png_ptr);
+  }
+
   number_passes = png_set_interlace_handling(png_ptr);
   mm_log((1,"number of passes=%d\n",number_passes));
   png_read_update_info(png_ptr, info_ptr);