Fix conversion from transparent indexed8 to RGB32
A typo meant the color-table was not fixed. For safety fallback colors are also made opaque. Change-Id: I3e609882177604910c4343c86f00221a89af9078 Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>bb10
parent
cdf154e65a
commit
65cd6f2e82
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Reference in New Issue