From 808aeaedf18532f04210c7c35ed1c9b74496e52a Mon Sep 17 00:00:00 2001 From: Hayaki Saito Date: Tue, 17 Feb 2015 00:20:18 +0900 Subject: [PATCH] Use png_set_packing to expand 1/2/4bpp paletted PNG (for Issue #29) --- converters/loader.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/converters/loader.c b/converters/loader.c index 683824fe..a38f26f9 100644 --- a/converters/loader.c +++ b/converters/loader.c @@ -343,7 +343,10 @@ load_png(unsigned char *buffer, int size, switch (png_get_color_type(png_ptr, info_ptr)) { case PNG_COLOR_TYPE_PALETTE: palette_bitdepth = png_get_PLTE(png_ptr, info_ptr, &png_palette, pncolors); - if (ppalette && png_palette && bitdepth == 8 && palette_bitdepth == 8 && *pncolors <= reqcolors) { + if (ppalette && png_palette && palette_bitdepth == 8 && *pncolors <= reqcolors) { + if (bitdepth != 8) { + png_set_packing(png_ptr); + } *ppalette = malloc(*pncolors * 3); if (*ppalette == NULL) { goto cleanup; @@ -356,6 +359,7 @@ load_png(unsigned char *buffer, int size, *pcomp = 1; *pixelformat = PIXELFORMAT_PAL8; } else { + png_set_packing(png_ptr); png_set_palette_to_rgb(png_ptr); *pcomp = 3; *pixelformat = PIXELFORMAT_RGB888;