From 3590a43fc506afca40a20b09fb6e8007b6dcf5b8 Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Wed, 17 Jul 2024 21:56:30 +0200 Subject: [PATCH] pcx: Read 16 color images that are 4bpp and 1 plane We had code for 1bpp and 4 planes but gimp is generating this format --- autotests/read/pcx/indexed4.pcx | Bin 0 -> 506 bytes autotests/read/pcx/indexed4.png | Bin 0 -> 593 bytes src/imageformats/pcx.cpp | 42 ++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 autotests/read/pcx/indexed4.pcx create mode 100644 autotests/read/pcx/indexed4.png diff --git a/autotests/read/pcx/indexed4.pcx b/autotests/read/pcx/indexed4.pcx new file mode 100644 index 0000000000000000000000000000000000000000..d79b033d0db3ab872e198cb3150d32d55f3355e7 GIT binary patch literal 506 zcmbV{u}cDR6vuxDh7b+bEc6dJgpoMdR1RV^Wl>{`+EO?-9uX8xS)|z#NP;cWP^iJX z(jRn|{Q=$`E=7ah6hz+n>%FsE8vDKBefYlL`+j-jW0HsAo5l)A0cmadrLtLTCo}5B zX-tKUcDlkBYW4f=x1;k;p=G45-t}(xE4wPa2pYuxwCsrD}fmGJJfO%Y*KSmS-;&P56Qd`D}Hi?nNM>9v$CVI|AFa=K~&K9`Si`UR^5?M3zF0lz`X0bRqC|W2DMw60s=!KHRGr^-;+9Lvv$HRv&S3JKr=g!=X`q6p1u42|Np<&;Q<>^J7bc!yNkfoO}sil4rhT! zWHAGSo-znCRxGtI0}8U2c>21szhD;>7G*S=BEkn0dgSTi7-DgH>EzSXm=!r(L|qQJ z|NdVueWJ&5Z^lWbt(S|Ja$T9?WBGgw>r2OYTIczfKGwFnAPjzbDX~dnWxT)7S zA^2r%Nspm)d~%0SuicgdyepnKWan<`kV;fHOAuofynCpj^?&xCh&_v=NywRnQs4v;~odDe`Wr#ZH6(!C39}}WAP_ym@))f zM6=dU_$=v=C&OGeJJExA%N*tzJH8it8J8!x<~m$FZ*9$>WEilUSBWX($l{jN^-@75 zE4LnUl>MK#K%Ci`ZN|YxO2AlPP%UwdC`m~yNwrEYN(E93Mg~SEx(4RDhUOuLmR3My zYOHNwU}a!n7wYy1MMG|WN@iLmZVmn%|KfleG~hOrWag$8mn7yEpy@F(v@$S+SmGQ0 R%o3=F!PC{xWt~$(69AiW)9C;J literal 0 HcmV?d00001 diff --git a/src/imageformats/pcx.cpp b/src/imageformats/pcx.cpp index 44a64b0..c3ac535 100644 --- a/src/imageformats/pcx.cpp +++ b/src/imageformats/pcx.cpp @@ -344,6 +344,46 @@ static bool readImage4(QImage &img, QDataStream &s, const PCXHEADER &header) return true; } +static bool readImage4v2(QImage &img, QDataStream &s, const PCXHEADER &header) +{ + QByteArray buf(header.BytesPerLine, 0); + + img = imageAlloc(header.width(), header.height(), QImage::Format_Indexed8); + img.setColorCount(16); + + if (img.isNull()) { + qWarning() << "Failed to allocate image, invalid dimensions?" << QSize(header.width(), header.height()); + return false; + } + + for (int y = 0; y < header.height(); ++y) { + if (s.atEnd()) { + return false; + } + + if (!readLine(s, buf, header)) { + return false; + } + + uchar *p = img.scanLine(y); + if (!p) { + return false; + } + + for (unsigned int x = 0; x < header.BytesPerLine; ++x) { + p[x * 2] = (buf[x] & 240) >> 4; + p[x * 2 + 1] = buf[x] & 15; + } + } + + // Read the palette + for (int i = 0; i < 16; ++i) { + img.setColor(i, header.ColorMap.color(i)); + } + + return (s.status() == QDataStream::Ok); +} + static bool readImage8(QImage &img, QDataStream &s, const PCXHEADER &header) { QByteArray buf(header.BytesPerLine, 0); @@ -672,6 +712,8 @@ bool PCXHandler::read(QImage *outImage) ok = readImage1(img, s, header); } else if (header.Bpp == 1 && header.NPlanes == 4) { ok = readImage4(img, s, header); + } else if (header.Bpp == 4 && header.NPlanes == 1) { + ok = readImage4v2(img, s, header); } else if (header.Bpp == 8 && header.NPlanes == 1) { ok = readImage8(img, s, header); } else if (header.Bpp == 8 && header.NPlanes == 3) {