mirror of
https://invent.kde.org/frameworks/kimageformats.git
synced 2026-11-01 00:48:49 -04:00
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:
Binary file not shown.
|
After Width: | Height: | Size: 111 B |
Binary file not shown.
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user