From bed0e58916a622b1b66f5dedcda121e7e848355b Mon Sep 17 00:00:00 2001 From: Pavel Charvat Date: Mon, 31 Jul 2006 14:22:44 +0200 Subject: [PATCH] added support for PNG with transparent colors in the palette --- images/alpha.c | 2 +- images/io-libpng.c | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/images/alpha.c b/images/alpha.c index 5c75e69f..9f6dfd14 100644 --- a/images/alpha.c +++ b/images/alpha.c @@ -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" diff --git a/images/io-libpng.c b/images/io-libpng.c index fe60fef6..a1705a37 100644 --- a/images/io-libpng.c +++ b/images/io-libpng.c @@ -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) -- 2.39.2