From 18a08ab8a1c7b88a1b43b8eb54e899a36f70a458 Mon Sep 17 00:00:00 2001 From: Samuel Gaist Date: Mon, 16 Sep 2013 23:06:02 +0200 Subject: Add missing initialization before requesting png data for scaled read Initialize all values read to sensible default in case reading them fails in read_image_scaled. It has already been done for a normal image read Task-number: QTBUG-32674 Change-Id: I19dccad7ef342f1b1bba6b513c04d3661d128a54 Reviewed-by: aavit --- src/gui/image/qpnghandler.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src/gui') diff --git a/src/gui/image/qpnghandler.cpp b/src/gui/image/qpnghandler.cpp index 7838b7df8e..4b016782b1 100644 --- a/src/gui/image/qpnghandler.cpp +++ b/src/gui/image/qpnghandler.cpp @@ -1,5 +1,6 @@ /**************************************************************************** ** +** Copyright (C) 2013 Samuel Gaist ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** @@ -406,14 +407,14 @@ static void read_image_scaled(QImage *outImage, png_structp png_ptr, png_infop i QPngHandlerPrivate::AllocatedMemoryPointers &, QSize scaledSize) { - png_uint_32 width; - png_uint_32 height; - png_int_32 offset_x; - png_int_32 offset_y; + png_uint_32 width = 0; + png_uint_32 height = 0; + png_int_32 offset_x = 0; + png_int_32 offset_y = 0; - int bit_depth; - int color_type; - int unit_type; + int bit_depth = 0; + int color_type = 0; + int unit_type = PNG_OFFSET_PIXEL; png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, 0, 0, 0); png_get_oFFs(png_ptr, info_ptr, &offset_x, &offset_y, &unit_type); uchar *data = outImage->bits(); -- cgit v1.2.3 From 73b88fccedfe3912649d119bedf8490ab6c41812 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Tue, 17 Sep 2013 22:22:30 +0200 Subject: 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 Reviewed-by: aavit --- src/gui/image/qpnghandler.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/gui') 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); -- cgit v1.2.3 From fdd843d5a76f2bba5c4ebdd5813c97f5105c5765 Mon Sep 17 00:00:00 2001 From: Balazs Domjan Date: Thu, 22 Aug 2013 15:37:17 +0200 Subject: Fix transform (rotation matrix) uniform scale testing. The rotation matrix is different according to the order of scale and rotate operations. The fix takes into account this. Task-number: QTBUG-31822 Change-Id: Ia1c9068e54966ec083af9c165af29caa87c510f6 Reviewed-by: Gunnar Sletta --- src/gui/painting/qtransform.cpp | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'src/gui') diff --git a/src/gui/painting/qtransform.cpp b/src/gui/painting/qtransform.cpp index 5088e9cdc8..a07b5def5d 100644 --- a/src/gui/painting/qtransform.cpp +++ b/src/gui/painting/qtransform.cpp @@ -2293,13 +2293,30 @@ bool qt_scaleForTransform(const QTransform &transform, qreal *scale) return qFuzzyCompare(xScale, yScale); } - const qreal xScale = transform.m11() * transform.m11() + // rotate then scale: compare columns + const qreal xScale1 = transform.m11() * transform.m11() + transform.m21() * transform.m21(); - const qreal yScale = transform.m12() * transform.m12() + const qreal yScale1 = transform.m12() * transform.m12() + transform.m22() * transform.m22(); - if (scale) - *scale = qSqrt(qMax(xScale, yScale)); - return type == QTransform::TxRotate && qFuzzyCompare(xScale, yScale); + + // scale then rotate: compare rows + const qreal xScale2 = transform.m11() * transform.m11() + + transform.m12() * transform.m12(); + const qreal yScale2 = transform.m21() * transform.m21() + + transform.m22() * transform.m22(); + + // decide the order of rotate and scale operations + if (qAbs(xScale1 - yScale1) > qAbs(xScale2 - yScale2)) { + if (scale) + *scale = qSqrt(qMax(xScale1, yScale1)); + + return type == QTransform::TxRotate && qFuzzyCompare(xScale1, yScale1); + } else { + if (scale) + *scale = qSqrt(qMax(xScale2, yScale2)); + + return type == QTransform::TxRotate && qFuzzyCompare(xScale2, yScale2); + } } QT_END_NAMESPACE -- cgit v1.2.3