diff --git a/autotests/write/basic/indexed16.png b/autotests/write/basic/indexed16.png new file mode 100644 index 0000000..8608c5b Binary files /dev/null and b/autotests/write/basic/indexed16.png differ diff --git a/autotests/write/basic/indexed16.qoi b/autotests/write/basic/indexed16.qoi new file mode 100644 index 0000000..2927b58 Binary files /dev/null and b/autotests/write/basic/indexed16.qoi differ diff --git a/autotests/write/basic/indexed16.rgb b/autotests/write/basic/indexed16.rgb new file mode 100644 index 0000000..d43ac67 Binary files /dev/null and b/autotests/write/basic/indexed16.rgb differ diff --git a/autotests/write/basic/indexed3.png b/autotests/write/basic/indexed3.png new file mode 100644 index 0000000..9d170f0 Binary files /dev/null and b/autotests/write/basic/indexed3.png differ diff --git a/autotests/write/basic/indexed3.qoi b/autotests/write/basic/indexed3.qoi new file mode 100644 index 0000000..3efa367 Binary files /dev/null and b/autotests/write/basic/indexed3.qoi differ diff --git a/autotests/write/basic/indexed3.rgb b/autotests/write/basic/indexed3.rgb new file mode 100644 index 0000000..c645e76 Binary files /dev/null and b/autotests/write/basic/indexed3.rgb differ diff --git a/autotests/write/basic/indexed40.png b/autotests/write/basic/indexed40.png new file mode 100644 index 0000000..88c0670 Binary files /dev/null and b/autotests/write/basic/indexed40.png differ diff --git a/autotests/write/basic/indexed40.qoi b/autotests/write/basic/indexed40.qoi new file mode 100644 index 0000000..a06a64b Binary files /dev/null and b/autotests/write/basic/indexed40.qoi differ diff --git a/autotests/write/basic/indexed40.rgb b/autotests/write/basic/indexed40.rgb new file mode 100644 index 0000000..ed61e11 Binary files /dev/null and b/autotests/write/basic/indexed40.rgb differ diff --git a/autotests/write/basic/indexed5.png b/autotests/write/basic/indexed5.png new file mode 100644 index 0000000..57afe8a Binary files /dev/null and b/autotests/write/basic/indexed5.png differ diff --git a/autotests/write/basic/indexed5.qoi b/autotests/write/basic/indexed5.qoi new file mode 100644 index 0000000..d6cdffd Binary files /dev/null and b/autotests/write/basic/indexed5.qoi differ diff --git a/autotests/write/basic/indexed5.rgb b/autotests/write/basic/indexed5.rgb new file mode 100644 index 0000000..ccb58aa Binary files /dev/null and b/autotests/write/basic/indexed5.rgb differ diff --git a/autotests/writetest.cpp b/autotests/writetest.cpp index fcbeed0..1fc7cb6 100644 --- a/autotests/writetest.cpp +++ b/autotests/writetest.cpp @@ -230,6 +230,10 @@ int basicTest(const QString &suffix, bool lossless, bool ignoreDataCheck, bool s reReadImage.convertToColorSpace(QColorSpace(QColorSpace::SRgb)); } } + // fuzzyeq() compares images of 24, 32 or 64 bits per pixel only (e.g. not the indexed ones) + if (pngImage.depth() < 24) { + pngImage.convertTo(pngImage.hasAlphaChannel() ? QImage::Format_ARGB32 : QImage::Format_RGB32); + } reReadImage = reReadImage.convertToFormat(pngImage.format()); } diff --git a/src/imageformats/pcx.cpp b/src/imageformats/pcx.cpp index c5818c7..5b61ab2 100644 --- a/src/imageformats/pcx.cpp +++ b/src/imageformats/pcx.cpp @@ -645,12 +645,14 @@ static bool writeImage1(const QImage &image, QDataStream &s, PCXHEADER &header) auto rgb = image.color(0); auto minIsBlack = (qRed(rgb) + qGreen(rgb) + qBlue(rgb)) / 3 < 127; + // only the bytes used by the pixels are copied: the scanline padding is not initialized + const int bpl = std::min(int(header.BytesPerLine), (header.width() + 7) / 8); QByteArray buf(header.BytesPerLine, 0); for (int y = 0; y < header.height(); ++y) { auto p = scl.convertedScanLine(image, y); // Invert as QImage uses reverse palette for monochrome images? - for (int i = 0; i < header.BytesPerLine; ++i) { + for (int i = 0; i < bpl; ++i) { buf[i] = minIsBlack ? p[i] : ~p[i]; } @@ -665,13 +667,14 @@ static bool writeImage4(const QImage &image, QDataStream &s, PCXHEADER &header) { header.Bpp = 1; header.NPlanes = 4; - header.BytesPerLine = header.width() / 8; + header.BytesPerLine = (header.width() + 7) / 8; if (header.BytesPerLine == 0) { return false; } + const auto colorTable = image.colorTable(); for (int i = 0; i < 16; ++i) { - header.ColorMap.setColor(i, image.color(i)); + header.ColorMap.setColor(i, i < colorTable.size() ? colorTable.at(i) : qRgb(0, 0, 0)); } s << header; @@ -729,12 +732,14 @@ static bool writeImage8(const QImage &image, QDataStream &s, PCXHEADER &header) s << header; + // only the bytes used by the pixels are copied: the scanline padding is not initialized + const int bpl = std::min(int(header.BytesPerLine), header.width()); QByteArray buf(header.BytesPerLine, 0); for (int y = 0; y < header.height(); ++y) { auto p = scl.convertedScanLine(image, y); - for (int i = 0; i < header.BytesPerLine; ++i) { + for (int i = 0; i < bpl; ++i) { buf[i] = p[i]; } @@ -748,11 +753,12 @@ static bool writeImage8(const QImage &image, QDataStream &s, PCXHEADER &header) s << byte; // Write palette + const auto colorTable = image.colorTable(); for (int i = 0; i < 256; ++i) { if (tfmt != QImage::Format_Indexed8) s << RGB::from(qRgb(i, i, i)); else - s << RGB::from(image.color(i)); + s << RGB::from(i < colorTable.size() ? colorTable.at(i) : qRgb(0, 0, 0)); } return (s.status() == QDataStream::Ok);