diff options
author | Ivan Komissarov <ABBAPOH@gmail.com> | 2014-01-12 10:59:54 +0400 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-01-13 09:31:56 +0100 |
commit | 8b675522a2ba5514a73e0b015ff272f61a2affda (patch) | |
tree | 353ac5d47968b559207dbcd62e18425747f785b2 | |
parent | a9d13d79298ec7f7c7f69fb38f97b0f48ca45323 (diff) | |
download | qtimageformats-8b675522a2ba5514a73e0b015ff272f61a2affda.tar.gz |
Fix reading palette images in DDS handler.
Change-Id: I039a5f3376a8ebe7230f30a0df31c4a355f22349
Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>
Reviewed-by: Alex Char <prevedtest@gmail.com>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
-rw-r--r-- | src/plugins/imageformats/dds/ddsheader.h | 4 | ||||
-rw-r--r-- | src/plugins/imageformats/dds/qddshandler.cpp | 39 | ||||
-rw-r--r-- | tests/auto/dds/tst_qdds.cpp | 1 | ||||
-rw-r--r-- | tests/shared/images/dds.qrc | 1 | ||||
-rw-r--r-- | tests/shared/images/dds/P4.dds | bin | 0 -> 2240 bytes | |||
-rw-r--r-- | tests/shared/images/dds/P8.dds | bin | 16512 -> 5248 bytes |
6 files changed, 41 insertions, 4 deletions
diff --git a/src/plugins/imageformats/dds/ddsheader.h b/src/plugins/imageformats/dds/ddsheader.h index 7f6df06..7b2b80c 100644 --- a/src/plugins/imageformats/dds/ddsheader.h +++ b/src/plugins/imageformats/dds/ddsheader.h @@ -134,6 +134,9 @@ enum Format { FormatA2B10G10R10_XR_BIAS = 119, FormatBinaryBuffer = 199, + FormatP4, + FormatA4P4, + FormatLast = 0x7fffffff }; @@ -143,6 +146,7 @@ struct DDSPixelFormat FlagAlphaPixels = 0x00000001, FlagAlpha = 0x00000002, FlagFourCC = 0x00000004, + FlagPaletteIndexed4 = 0x00000008, FlagPaletteIndexed8 = 0x00000020, FlagRGB = 0x00000040, FlagYUV = 0x00000200, diff --git a/src/plugins/imageformats/dds/qddshandler.cpp b/src/plugins/imageformats/dds/qddshandler.cpp index c85e75d..13bb9aa 100644 --- a/src/plugins/imageformats/dds/qddshandler.cpp +++ b/src/plugins/imageformats/dds/qddshandler.cpp @@ -221,7 +221,11 @@ static inline QRgb yuv2rgb(quint8 Y, quint8 U, quint8 V) static Format getFormat(const DDSHeader &dds) { const DDSPixelFormat &format = dds.pixelFormat; - if (format.flags & DDSPixelFormat::FlagFourCC) { + if (format.flags & DDSPixelFormat::FlagPaletteIndexed4) { + return FormatP4; + } else if (format.flags & DDSPixelFormat::FlagPaletteIndexed8) { + return FormatP8; + } else if (format.flags & DDSPixelFormat::FlagFourCC) { for (size_t i = 0; i < knownFourCCsSize; ++i) { if (dds.pixelFormat.fourCC == knownFourCCs[i]) return knownFourCCs[i]; @@ -729,7 +733,7 @@ static QImage readCxV8U8(QDataStream &s, const quint32 width, const quint32 heig return image; } -static QImage readPaletteImage(QDataStream &s, quint32 width, quint32 height) +static QImage readPalette8Image(QDataStream &s, quint32 width, quint32 height) { QImage image(width, height, QImage::Format_Indexed8); for (int i = 0; i < 256; ++i) { @@ -749,6 +753,31 @@ static QImage readPaletteImage(QDataStream &s, quint32 width, quint32 height) return image; } +static QImage readPalette4Image(QDataStream &s, quint32 width, quint32 height) +{ + QImage image(width, height, QImage::Format_Indexed8); + for (int i = 0; i < 16; ++i) { + quint8 r, g, b, a; + s >> r >> g >> b >> a; + image.setColor(i, qRgba(r, g, b, a)); + } + + for (quint32 y = 0; y < height; y++) { + quint8 index; + for (quint32 x = 0; x < width - 1; ) { + s >> index; + image.setPixel(x++, y, (index & 0x0f) >> 0); + image.setPixel(x++, y, (index & 0xf0) >> 4); + } + if (width % 2 == 1) { + s >> index; + image.setPixel(width - 1, y, (index & 0x0f) >> 0); + } + } + + return image; +} + static QImage readARGB16(QDataStream &s, quint32 width, quint32 height) { QImage image(width, height, QImage::Format_ARGB32); @@ -1004,9 +1033,11 @@ static QImage readLayer(QDataStream &s, const DDSHeader &dds, const int format, case FormatA2B10G10R10: return readA2R10G10B10(s, dds, width, height); case FormatP8: - return readPaletteImage(s, width, height); case FormatA8P8: - break; + return readPalette8Image(s, width, height); + case FormatP4: + case FormatA4P4: + return readPalette4Image(s, width, height); case FormatA16B16G16R16: return readARGB16(s, width, height); case FormatV8U8: diff --git a/tests/auto/dds/tst_qdds.cpp b/tests/auto/dds/tst_qdds.cpp index 4464b99..eb25849 100644 --- a/tests/auto/dds/tst_qdds.cpp +++ b/tests/auto/dds/tst_qdds.cpp @@ -108,6 +108,7 @@ void tst_qdds::readImage_data() QTest::newRow("45") << QString("YUY2") << QSize(64, 64); QTest::newRow("46") << QString("RXGB") << QSize(64, 64); QTest::newRow("47") << QString("ATI2") << QSize(64, 64); + QTest::newRow("48") << QString("P4") << QSize(64, 64); } void tst_qdds::readImage() diff --git a/tests/shared/images/dds.qrc b/tests/shared/images/dds.qrc index e19eee9..128a38d 100644 --- a/tests/shared/images/dds.qrc +++ b/tests/shared/images/dds.qrc @@ -28,6 +28,7 @@ <file>dds/L8.dds</file> <file>dds/L16.dds</file> <file>dds/mipmaps.dds</file> + <file>dds/P4.dds</file> <file>dds/P8.dds</file> <file>dds/Q8W8V8U8.dds</file> <file>dds/Q16W16V16U16.dds</file> diff --git a/tests/shared/images/dds/P4.dds b/tests/shared/images/dds/P4.dds Binary files differnew file mode 100644 index 0000000..c8c3e90 --- /dev/null +++ b/tests/shared/images/dds/P4.dds diff --git a/tests/shared/images/dds/P8.dds b/tests/shared/images/dds/P8.dds Binary files differindex 936b870..4bef9ec 100644 --- a/tests/shared/images/dds/P8.dds +++ b/tests/shared/images/dds/P8.dds |