]> mj.ucw.cz Git - libucw.git/commitdiff
added support for PNG with transparent colors in the palette
authorPavel Charvat <pavel.charvat@netcentrum.cz>
Mon, 31 Jul 2006 12:22:44 +0000 (14:22 +0200)
committerPavel Charvat <pavel.charvat@netcentrum.cz>
Mon, 31 Jul 2006 12:22:44 +0000 (14:22 +0200)
images/alpha.c
images/io-libpng.c

index 5c75e69f3cd1c4b7e313a5e4cac04884931c5664..9f6dfd14ff64bef46879263f127ae394d023e3f8 100644 (file)
@@ -7,7 +7,7 @@
  *     of the GNU Lesser General Public License.
  */
 
-#define LOCAL_DEBUG
+#undef LOCAL_DEBUG
 
 #include "lib/lib.h"
 #include "images/images.h"
index fe60fef60437ae765dee89a3821d38da5ca509ec..a1705a376a467b044bad77a6f478cd8fec29d612 100644 (file)
@@ -217,7 +217,6 @@ libpng_read_data(struct image_io *io)
   switch (rd->color_type)
     {
       case PNG_COLOR_TYPE_PALETTE:
-       /* FIXME: add support for palette with colors */
        if ((io->flags & IMAGE_COLOR_SPACE) == COLOR_SPACE_GRAYSCALE)
          {
            png_set_palette_to_rgb(rd->png_ptr);
@@ -225,10 +224,20 @@ libpng_read_data(struct image_io *io)
          }
        else
          png_set_palette_to_rgb(rd->png_ptr);
-       if ((io->flags & IMAGE_ALPHA) || (io->flags & IMAGE_PIXEL_FORMAT) == (COLOR_SPACE_RGB | IMAGE_PIXELS_ALIGNED))
-          png_set_add_alpha(rd->png_ptr, 255, PNG_FILLER_AFTER);
+       if (!(io->flags & IMAGE_ALPHA))
+         {
+           if (io->flags & IMAGE_IO_USE_BACKGROUND)
+             {
+                png_set_add_alpha(rd->png_ptr, 255, PNG_FILLER_AFTER);
+               read_flags |= IMAGE_ALPHA;
+             }
+           else if ((io->flags & IMAGE_PIXEL_FORMAT) == (COLOR_SPACE_RGB | IMAGE_PIXELS_ALIGNED))
+              png_set_add_alpha(rd->png_ptr, 255, PNG_FILLER_AFTER);
+            else
+             png_set_strip_alpha(rd->png_ptr);
+         }
        else
-         png_set_strip_alpha(rd->png_ptr);
+          png_set_add_alpha(rd->png_ptr, 255, PNG_FILLER_AFTER);
        break;
       case PNG_COLOR_TYPE_GRAY:
        if ((io->flags & IMAGE_COLOR_SPACE) == COLOR_SPACE_RGB)