diff options
-rw-r--r-- | src/gui/image/qimage_conversions.cpp | 5 | ||||
-rw-r--r-- | tests/auto/gui/image/qimage/tst_qimage.cpp | 15 |
2 files changed, 18 insertions, 2 deletions
diff --git a/src/gui/image/qimage_conversions.cpp b/src/gui/image/qimage_conversions.cpp index 1b4d3e63dd..d981c43711 100644 --- a/src/gui/image/qimage_conversions.cpp +++ b/src/gui/image/qimage_conversions.cpp @@ -1194,7 +1194,7 @@ static QVector<QRgb> fix_color_table(const QVector<QRgb> &ctbl, QImage::Format f if (format == QImage::Format_RGB32) { // check if the color table has alpha for (int i = 0; i < colorTable.size(); ++i) - if (qAlpha(colorTable.at(i) != 0xff)) + if (qAlpha(colorTable.at(i)) != 0xff) colorTable[i] = colorTable.at(i) | 0xff000000; } else if (format == QImage::Format_ARGB32_Premultiplied) { // check if the color table has alpha @@ -1796,8 +1796,9 @@ static void convert_Indexed8_to_X32(QImageData *dest, const QImageData *src, Qt: if (colorTable.size() < 256) { int tableSize = colorTable.size(); colorTable.resize(256); + QRgb fallbackColor = (dest->format == QImage::Format_RGB32) ? 0xff000000 : 0; for (int i=tableSize; i<256; ++i) - colorTable[i] = 0; + colorTable[i] = fallbackColor; } int w = src->width; diff --git a/tests/auto/gui/image/qimage/tst_qimage.cpp b/tests/auto/gui/image/qimage/tst_qimage.cpp index 7ad4a9e9bb..34b20a5cca 100644 --- a/tests/auto/gui/image/qimage/tst_qimage.cpp +++ b/tests/auto/gui/image/qimage/tst_qimage.cpp @@ -222,6 +222,8 @@ private slots: void hugeQImage(); + void convertColorTable(); + private: const QString m_prefix; }; @@ -3458,5 +3460,18 @@ void tst_QImage::hugeQImage() #endif } +void tst_QImage::convertColorTable() +{ + QImage image(10, 10, QImage::Format_Indexed8); + image.setColor(0, 0x80ffffff); + image.fill(0); + QImage argb32 = image.convertToFormat(QImage::Format_ARGB32); + QCOMPARE(argb32.pixel(0,0), 0x80ffffff); + QImage argb32pm = image.convertToFormat(QImage::Format_ARGB32_Premultiplied); + QCOMPARE(argb32pm.pixel(0,0), 0x80808080); + QImage rgb32 = image.convertToFormat(QImage::Format_RGB32); + QCOMPARE(rgb32.pixel(0,0), 0xffffffff); +} + QTEST_GUILESS_MAIN(tst_QImage) #include "tst_qimage.moc" |