diff options
author | Gunnar Sletta <gunnar@trolltech.com> | 2009-08-31 05:19:23 (GMT) |
---|---|---|
committer | Gunnar Sletta <gunnar@trolltech.com> | 2009-08-31 11:07:58 (GMT) |
commit | b0295e82d08605a5a40803895544e57eeb6c8dc3 (patch) | |
tree | 8b21d5d7a5767375822a3e1bac30376b71facb70 | |
parent | 6cf224de00ebf0681cd32a34866bdc3d16e0f45d (diff) | |
download | Qt-b0295e82d08605a5a40803895544e57eeb6c8dc3.zip Qt-b0295e82d08605a5a40803895544e57eeb6c8dc3.tar.gz Qt-b0295e82d08605a5a40803895544e57eeb6c8dc3.tar.bz2 |
Don't crash when convert Indexed8 without colortable to QPixmap
This implicitly adds "grayscale" support for indexed 8, but
only for the conversion. The alternative would be leave the pixels
uninitialized which would be less nice...
Reviewed-by: Samuel
-rw-r--r-- | src/gui/image/qimage.cpp | 6 | ||||
-rw-r--r-- | tests/auto/qpixmap/tst_qpixmap.cpp | 29 |
2 files changed, 35 insertions, 0 deletions
diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp index d48d427..0358ba0 100644 --- a/src/gui/image/qimage.cpp +++ b/src/gui/image/qimage.cpp @@ -2904,6 +2904,12 @@ static void convert_Indexed8_to_X32(QImageData *dest, const QImageData *src, Qt: Q_ASSERT(src->height == dest->height); QVector<QRgb> colorTable = fix_color_table(src->colortable, dest->format); + if (colorTable.size() == 0) { + colorTable.resize(256); + for (int i=0; i<256; ++i) + colorTable[i] = qRgb(i, i, i); + + } int w = src->width; const uchar *src_data = src->data; diff --git a/tests/auto/qpixmap/tst_qpixmap.cpp b/tests/auto/qpixmap/tst_qpixmap.cpp index 8dd5f5f..9422327 100644 --- a/tests/auto/qpixmap/tst_qpixmap.cpp +++ b/tests/auto/qpixmap/tst_qpixmap.cpp @@ -83,6 +83,9 @@ private slots: void fromImage_data(); void fromImage(); + void fromUninitializedImage_data(); + void fromUninitializedImage(); + void convertFromImage_data(); void convertFromImage(); @@ -266,6 +269,32 @@ void tst_QPixmap::fromImage() QCOMPARE(result, image); } + +void tst_QPixmap::fromUninitializedImage_data() +{ + QTest::addColumn<QImage::Format>("format"); + + QTest::newRow("Format_Mono") << QImage::Format_Mono; + QTest::newRow("Format_MonoLSB") << QImage::Format_MonoLSB; + QTest::newRow("Format_Indexed8") << QImage::Format_Indexed8; + QTest::newRow("Format_RGB32") << QImage::Format_RGB32; + QTest::newRow("Format_ARGB32") << QImage::Format_ARGB32; + QTest::newRow("Format_ARGB32_Premultiplied") << QImage::Format_ARGB32_Premultiplied; + QTest::newRow("Format_RGB16") << QImage::Format_RGB16; +} + +void tst_QPixmap::fromUninitializedImage() +{ + QFETCH(QImage::Format, format); + + QImage image(100, 100, format); + QPixmap pix = QPixmap::fromImage(image); + + // it simply shouldn't crash... + QVERIFY(true); + +} + void tst_QPixmap::convertFromImage_data() { QTest::addColumn<QImage>("img1"); |