summaryrefslogtreecommitdiffstats
path: root/src/gui/image/qpnghandler.cpp
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2013-09-17 22:22:30 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-09-18 11:23:35 +0200
commit73b88fccedfe3912649d119bedf8490ab6c41812 (patch)
tree725bc3b161707fed2a8f60c929c8c075bd9fa822 /src/gui/image/qpnghandler.cpp
parent18a08ab8a1c7b88a1b43b8eb54e899a36f70a458 (diff)
PNG: properly handle 1bpp greyscale images with alpha
PNG allows 1bpp greyscale images (PNG_COLOR_TYPE_GRAY) to have an alpha key; so even in this case we need to inquiry if the image has a transparency, and if so modify the color table of the monochrome image accordingly. Task-number: QTBUG-33503 Change-Id: Iab07c8f95ac8865269c48816e222645cdcb6bbc1 Reviewed-by: Nicolas Arnaud-Cormos <nicolas@kdab.com> Reviewed-by: aavit <eirik.aavitsland@digia.com>
Diffstat (limited to 'src/gui/image/qpnghandler.cpp')
-rw-r--r--src/gui/image/qpnghandler.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/gui/image/qpnghandler.cpp b/src/gui/image/qpnghandler.cpp
index 4b016782b1..3ee9e200de 100644
--- a/src/gui/image/qpnghandler.cpp
+++ b/src/gui/image/qpnghandler.cpp
@@ -281,6 +281,15 @@ void setup_qt(QImage& image, png_structp png_ptr, png_infop info_ptr, QSize scal
image.setColorCount(2);
image.setColor(1, qRgb(0,0,0));
image.setColor(0, qRgb(255,255,255));
+ if (png_get_tRNS(png_ptr, info_ptr, &trans_alpha, &num_trans, &trans_color_p) && trans_color_p) {
+ const int g = trans_color_p->gray;
+ // the image has white in the first position of the color table,
+ // black in the second. g is 0 for black, 1 for white.
+ if (g == 0)
+ image.setColor(1, qRgba(0, 0, 0, 0));
+ else if (g == 1)
+ image.setColor(0, qRgba(255, 255, 255, 0));
+ }
} else if (bit_depth == 16 && png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
png_set_expand(png_ptr);
png_set_strip_16(png_ptr);