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.
This commit is contained in:
Ana Bobillo
2026-10-27 10:39:33 +01:00
parent e07c5386ff
commit 32ff79442c
3 changed files with 11 additions and 2 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 111 B

Binary file not shown.
+11 -2
View File
@@ -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;
}