From 32ff79442c8f7409843097aaf0dda54d357313bb Mon Sep 17 00:00:00 2001 From: Ana Bobillo Date: Tue, 27 Oct 2026 10:39:33 +0100 Subject: [PATCH] RAS: unpack 1-bit images with a color map 1-bit images with a color map are loaded as Indexed8, but their lines were copied packed: the first (width + 7) / 8 bytes (rounded up to an even number) of each line held packed bits read as indexes, and the rest of the line was not set, so it kept whatever the memory held (images are allocated without being initialized). The bits are now unpacked to one index per pixel. Added the read test pal1bit.ras, which fails without this change. --- autotests/read/ras/pal1bit.png | Bin 0 -> 111 bytes autotests/read/ras/pal1bit.ras | Bin 0 -> 56 bytes src/imageformats/ras.cpp | 13 +++++++++++-- 3 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 autotests/read/ras/pal1bit.png create mode 100644 autotests/read/ras/pal1bit.ras diff --git a/autotests/read/ras/pal1bit.png b/autotests/read/ras/pal1bit.png new file mode 100644 index 0000000000000000000000000000000000000000..42febbc5c78df11fab2decc10699758566b68ca0 GIT binary patch literal 111 zcmeAS@N?(olHy`uVBq!ia0vp@K+MU=3?wgaG0_B4YymzYt_ltZ4j33bah!|3UAjm-`tQR;=W9DqcS8CQvmdK II;Vst07CU62><{9 literal 0 HcmV?d00001 diff --git a/autotests/read/ras/pal1bit.ras b/autotests/read/ras/pal1bit.ras new file mode 100644 index 0000000000000000000000000000000000000000..36f6178615450f009c1fe24b32ceb5f15ae2308f GIT binary patch literal 56 zcma!CmNk`ufq@r@If0lFh=rguh|Q*Oz`@{v!T%rp96T0hPIzi)daPRECE=+70Pfxk AT>t<8 literal 0 HcmV?d00001 diff --git a/src/imageformats/ras.cpp b/src/imageformats/ras.cpp index 5434744..8ad3076 100644 --- a/src/imageformats/ras.cpp +++ b/src/imageformats/ras.cpp @@ -275,8 +275,17 @@ static bool LoadRAS(QDataStream &s, const RasHeader &ras, QImage &img) continue; } - // Image with palette - if (ras.ColorMapType == RAS_COLOR_MAP_TYPE_RGB && (ras.Depth == 1 || ras.Depth == 8)) { + // Image with palette 1-bit (one bit per index, unpacked to an index per byte) + if (ras.ColorMapType == RAS_COLOR_MAP_TYPE_RGB && ras.Depth == 1) { + auto scanLine = img.scanLine(y); + for (quint32 x = 0; x < ras.Width; x++) { + scanLine[x] = (quint8(rasLine.at(x / 8)) >> (7 - (x % 8))) & 1; + } + continue; + } + + // Image with palette 8-bit + if (ras.ColorMapType == RAS_COLOR_MAP_TYPE_RGB && ras.Depth == 8) { std::memcpy(img.scanLine(y), rasLine.constData(), bytesPerLine); continue; }