summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2017-09-13 11:07:58 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2017-09-14 08:13:46 +0000
commit590e71a69cc74b4e7da1ccb19a1304047dbaecb8 (patch)
tree126f11c43cc86ea01bbca345ebf43f70e08cf489
parentb6e99ec056387e8720ef5acff824089fe585e00a (diff)
Fix convertToFormat with color-tables
The function was only well defined from RGB32 and ARGB32PM formats, this patch fixes it so it behaves well from all formats. Task-number: QTBUG-63163 Change-Id: Id892531d9aaf997b707b430196c1166493792a2a Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
-rw-r--r--src/gui/image/qimage.cpp23
-rw-r--r--tests/auto/gui/image/qimage/tst_qimage.cpp13
2 files changed, 19 insertions, 17 deletions
diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp
index b2e5ac93b1..43b77a862d 100644
--- a/src/gui/image/qimage.cpp
+++ b/src/gui/image/qimage.cpp
@@ -2096,8 +2096,8 @@ static QImage convertWithPalette(const QImage &src, QImage::Format format,
Returns a copy of the image converted to the given \a format,
using the specified \a colorTable.
- Conversion from 32 bit to 8 bit indexed is a slow operation and
- will use a straightforward nearest color approach, with no
+ Conversion from RGB formats to indexed formats is a slow operation
+ and will use a straightforward nearest color approach, with no
dithering.
*/
QImage QImage::convertToFormat(Format format, const QVector<QRgb> &colorTable, Qt::ImageConversionFlags flags) const
@@ -2105,23 +2105,12 @@ QImage QImage::convertToFormat(Format format, const QVector<QRgb> &colorTable, Q
if (!d || d->format == format)
return *this;
- if (format <= QImage::Format_Indexed8 && depth() == 32) {
- return convertWithPalette(*this, format, colorTable);
- }
-
- const Image_Converter *converterPtr = &qimage_converter_map[d->format][format];
- Image_Converter converter = *converterPtr;
- if (!converter)
+ if (format == QImage::Format_Invalid)
return QImage();
+ if (format <= QImage::Format_Indexed8)
+ return convertWithPalette(convertToFormat(QImage::Format_ARGB32, flags), format, colorTable);
- QImage image(d->width, d->height, format);
- QIMAGE_SANITYCHECK_MEMORY(image);
-
- image.d->offset = offset();
- copyMetadata(image.d, d);
-
- converter(image.d, d, flags);
- return image;
+ return convertToFormat(format, flags);
}
/*!
diff --git a/tests/auto/gui/image/qimage/tst_qimage.cpp b/tests/auto/gui/image/qimage/tst_qimage.cpp
index fac785ac86..73e11e7cc7 100644
--- a/tests/auto/gui/image/qimage/tst_qimage.cpp
+++ b/tests/auto/gui/image/qimage/tst_qimage.cpp
@@ -69,6 +69,7 @@ private slots:
void convertToFormat_data();
void convertToFormat();
+ void convertToFormatWithColorTable();
void convertToFormatRgb888ToRGB32();
@@ -958,6 +959,18 @@ void tst_QImage::convertToFormat()
QFile::remove(QLatin1String("expected2.xpm"));
}
+void tst_QImage::convertToFormatWithColorTable()
+{
+ QVector<QRgb> colors(2);
+ colors[0] = 0xFF000000;
+ colors[1] = 0xFFFFFFFF;
+ for (int format = QImage::Format_RGB32; format < QImage::Format_Alpha8; ++format) {
+ QImage fromImage(10, 10, (QImage::Format)format);
+ QImage bitmap = fromImage.convertToFormat(QImage::Format_Mono, colors);
+ QVERIFY(!bitmap.isNull());
+ }
+}
+
void tst_QImage::convertToFormatRgb888ToRGB32()
{
// 545 so width % 4 != 0. This ensure there is padding at the end of the scanlines