mirror of
https://invent.kde.org/frameworks/kimageformats.git
synced 2025-05-28 00:30:23 -04:00
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
This commit is contained in:
parent
f5a6de7280
commit
3590a43fc5
BIN
autotests/read/pcx/indexed4.pcx
Normal file
BIN
autotests/read/pcx/indexed4.pcx
Normal file
Binary file not shown.
BIN
autotests/read/pcx/indexed4.png
Normal file
BIN
autotests/read/pcx/indexed4.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 593 B |
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user