From f68108cfa85fdfeb769716ee237afc39f2f1be3b Mon Sep 17 00:00:00 2001 From: Ana Bobillo Date: Thu, 22 Oct 2026 14:23:28 +0200 Subject: [PATCH] PCX: fix writing of indexed images with few colors The palette was filled with 16 (1 bit, 4 planes) or 256 (8 bits) entries read with QImage::color(), reading past the end of the color table of images with fewer colors. Entries past the color table (all of them for an image without one) are now written as black, as the DDS plugin does. The 4-plane writer set BytesPerLine to width / 8, so for widths not a multiple of 8 the last pixels of each line were set one byte past the end of the line buffers (an assertion in debug builds) and dropped from the file, which the plugin then could not read back. Images narrower than 8 pixels could not be saved at all. It is now (width + 7) / 8. The 1-bit and 8-bit writers copied whole scanlines of the image into the file, including their uninitialized padding bytes. Only the bytes used by the pixels are copied now. Added indexed images with 3, 5, 16 and 40 colors (6, 13, 16 and 17 pixels wide) to autotests/write/basic, with the .qoi and .rgb files of the formats whose output is checked byte for byte. writetest now compares indexed images as RGB32 or ARGB32, since fuzzyeq() only takes 24, 32 and 64 bit images. --- autotests/write/basic/indexed16.png | Bin 0 -> 165 bytes autotests/write/basic/indexed16.qoi | Bin 0 -> 339 bytes autotests/write/basic/indexed16.rgb | Bin 0 -> 752 bytes autotests/write/basic/indexed3.png | Bin 0 -> 119 bytes autotests/write/basic/indexed3.qoi | Bin 0 -> 47 bytes autotests/write/basic/indexed3.rgb | Bin 0 -> 584 bytes autotests/write/basic/indexed40.png | Bin 0 -> 275 bytes autotests/write/basic/indexed40.qoi | Bin 0 -> 295 bytes autotests/write/basic/indexed40.rgb | Bin 0 -> 971 bytes autotests/write/basic/indexed5.png | Bin 0 -> 155 bytes autotests/write/basic/indexed5.qoi | Bin 0 -> 139 bytes autotests/write/basic/indexed5.rgb | Bin 0 -> 863 bytes autotests/writetest.cpp | 4 ++++ src/imageformats/pcx.cpp | 16 +++++++++++----- 14 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 autotests/write/basic/indexed16.png create mode 100644 autotests/write/basic/indexed16.qoi create mode 100644 autotests/write/basic/indexed16.rgb create mode 100644 autotests/write/basic/indexed3.png create mode 100644 autotests/write/basic/indexed3.qoi create mode 100644 autotests/write/basic/indexed3.rgb create mode 100644 autotests/write/basic/indexed40.png create mode 100644 autotests/write/basic/indexed40.qoi create mode 100644 autotests/write/basic/indexed40.rgb create mode 100644 autotests/write/basic/indexed5.png create mode 100644 autotests/write/basic/indexed5.qoi create mode 100644 autotests/write/basic/indexed5.rgb diff --git a/autotests/write/basic/indexed16.png b/autotests/write/basic/indexed16.png new file mode 100644 index 0000000000000000000000000000000000000000..8608c5b11a9de10d26955b57d8ad1110b2d75e7d GIT binary patch literal 165 zcmeAS@N?(olHy`uVBq!ia0vp^0zk~l!VDz$9V@H?QU(D&A+8Mn83f)3DBNFQaQ=hC zeused6B6b>DCjq6sBf5%e_=tq!Uq3>1NH|l=nFiMPx!#Uq1euIEl@9Kfk$L90|Va? z5N4dJ%_j{Ml=gIS45^rtoD$N+pr)bAlFH%e+Oizopr0My4axBvhE literal 0 HcmV?d00001 diff --git a/autotests/write/basic/indexed16.qoi b/autotests/write/basic/indexed16.qoi new file mode 100644 index 0000000000000000000000000000000000000000..2927b582fbbf5449dda9e0e790f4a8685b2a2963 GIT binary patch literal 339 zcmXTS&rD-rU=RReR%V8@e**6V{wdsF@Xz4Kpz| z$iMJ!LA=7h4gLlH4%i>~cR^p^-vjxCe;@cakgbp5KLglaQtgB3gSnSjccSZq*-OZO Oxb#8o1qLAqFaiJz&BVe0 literal 0 HcmV?d00001 diff --git a/autotests/write/basic/indexed16.rgb b/autotests/write/basic/indexed16.rgb new file mode 100644 index 0000000000000000000000000000000000000000..d43ac67c851eb1774ecd9620d10fb736f62a9291 GIT binary patch literal 752 zcmZR)#lXnG%pkzP3M3)mKa?J&MnDKOOjxktz=a1N7z7jy90C#w5(-d7Kw`)u5LE~f zm_C?DeSW;Zy}msE|M&OL?_WQ^e||rz2uKWB1fmKd0@DW*X}F+Ja6lko14F=q4-OL^ V7(6gQ6#b|fr28QE{-7;bCRcgNO)wJ00dJ$0L{~7Wc>d}XD(2l!PC{x JWt~$(696Tu9&`Wz literal 0 HcmV?d00001 diff --git a/autotests/write/basic/indexed3.qoi b/autotests/write/basic/indexed3.qoi new file mode 100644 index 0000000000000000000000000000000000000000..3efa3679707d21c7dc0ed80e1f3141e6c472b532 GIT binary patch literal 47 tcmXTS&rD-rU|<7c7G{R9e+&)(|1~f;=<1p3n(BejQ6Njt6etY>i~tUx3FH6( literal 0 HcmV?d00001 diff --git a/autotests/write/basic/indexed3.rgb b/autotests/write/basic/indexed3.rgb new file mode 100644 index 0000000000000000000000000000000000000000..c645e76e9092763f0b842674b048fd8a94d92805 GIT binary patch literal 584 zcmZR)#lXnG%)rLL0wf{eKa?J&MnDMsXJ`N+2xwsV4@3|V2pb}fB*O6D0fZpH;XeZq Gfkgmj`zKBS literal 0 HcmV?d00001 diff --git a/autotests/write/basic/indexed40.png b/autotests/write/basic/indexed40.png new file mode 100644 index 0000000000000000000000000000000000000000..88c0670c972448b12f5a05cdb8470eaeb7740467 GIT binary patch literal 275 zcmeAS@N?(olHy`uVBq!ia0vp^fqkw5ow<{`V}=QCq@zJwe42ZpWku4Z*zkYImwx8*A_WBx*2lQZg( z>WXzu(u?nko>(Fl19DJ-M`SSr1K$x4W}K?cCk+&I^mK6yshAUbd@ExE0|U#(!*}n> ze!D;6*JW0o%bR4ce{MGDnrw3VqF8F{w!Ekb+^>VMjyOaBFIm@g!!WyZuOrDkNuC8nhJuatY{ zzgcOM|Ls56izIBtCiL%#O#461^2UF9m#Sf^fxXves literal 0 HcmV?d00001 diff --git a/autotests/write/basic/indexed40.rgb b/autotests/write/basic/indexed40.rgb new file mode 100644 index 0000000000000000000000000000000000000000..ed61e1170d04adf8b181b9f322cae4f1461ec14d GIT binary patch literal 971 zcmZR)#lXnG%pl0X2_zxlKa?J&MnDKu%sup+$1tpV!O>UzCXscE894QVQN?EMe}XEe z9Z-rYw&x)ms+e!lbX2i>%o?a-`BQeHiZQ5qp^9}pwww9Ie-&%OZn45M>P>eU$}j1n zilrTtK@|(#z>O;AGXEEnJ}Imc1O7^1hKisfe}$A$-byV_eC>#8eC xi~et{E=3ia+}n;SwsihXRI%+FSEGuZJiHfG?Dp03sA6xQKSUM#|MN4d7y!D$Q0B4XG_W%F@ literal 0 HcmV?d00001 diff --git a/autotests/write/basic/indexed5.rgb b/autotests/write/basic/indexed5.rgb new file mode 100644 index 0000000000000000000000000000000000000000..ccb58aafd82f0b910dd8a496b4cdd8a5d7d1a7d0 GIT binary patch literal 863 zcmZR)#lXnG%)raQ2_zxlKa?J&MnVYuX8^`Glz=lpLI`0{f