mirror of
https://invent.kde.org/frameworks/kimageformats.git
synced 2025-06-03 17:08:08 -04:00
TGA: Fixed GrayA image loading error
Gray TGA images with alpha were loading incorrectly and tests did not detect the error since the BW(A).TGA images were actually RGB(A) images.
This commit is contained in:
parent
7d696a81d2
commit
0378bd67e1
Binary file not shown.
Before Width: | Height: | Size: 3.0 KiB After Width: | Height: | Size: 485 B |
Binary file not shown.
Before Width: | Height: | Size: 4.0 KiB After Width: | Height: | Size: 737 B |
@ -174,15 +174,21 @@ static QImage::Format imageFormat(const TgaHeader &head)
|
|||||||
{
|
{
|
||||||
auto format = QImage::Format_Invalid;
|
auto format = QImage::Format_Invalid;
|
||||||
if (IsSupported(head)) {
|
if (IsSupported(head)) {
|
||||||
|
TgaHeaderInfo info(head);
|
||||||
|
|
||||||
// Bits 0-3 are the numbers of alpha bits (can be zero!)
|
// Bits 0-3 are the numbers of alpha bits (can be zero!)
|
||||||
const int numAlphaBits = head.flags & 0xf;
|
const int numAlphaBits = head.flags & 0xf;
|
||||||
// However alpha exists only in the 32 bit format.
|
// However alpha should exists only in the 32 bit format.
|
||||||
if ((head.pixel_size == 32) && (head.flags & 0xf)) {
|
if ((head.pixel_size == 32) && (numAlphaBits)) {
|
||||||
if (numAlphaBits <= 8) {
|
if (numAlphaBits <= 8) {
|
||||||
format = QImage::Format_ARGB32;
|
format = QImage::Format_ARGB32;
|
||||||
}
|
}
|
||||||
|
// Anyway, GIMP also saves gray images with alpha in TGA format
|
||||||
|
} else if((info.grey) && (head.pixel_size == 16) && (numAlphaBits)) {
|
||||||
|
if (numAlphaBits == 8) {
|
||||||
|
format = QImage::Format_ARGB32;
|
||||||
}
|
}
|
||||||
else {
|
} else {
|
||||||
format = QImage::Format_RGB32;
|
format = QImage::Format_RGB32;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -348,8 +354,7 @@ static bool LoadTGA(QDataStream &s, const TgaHeader &tga, QImage &img)
|
|||||||
uchar *src = image;
|
uchar *src = image;
|
||||||
|
|
||||||
for (int y = y_start; y != y_end; y += y_step) {
|
for (int y = y_start; y != y_end; y += y_step) {
|
||||||
QRgb *scanline = (QRgb *)img.scanLine(y);
|
auto scanline = reinterpret_cast<QRgb *>(img.scanLine(y));
|
||||||
|
|
||||||
if (info.pal) {
|
if (info.pal) {
|
||||||
// Paletted.
|
// Paletted.
|
||||||
for (int x = 0; x < tga.width; x++) {
|
for (int x = 0; x < tga.width; x++) {
|
||||||
@ -359,9 +364,15 @@ static bool LoadTGA(QDataStream &s, const TgaHeader &tga, QImage &img)
|
|||||||
} else if (info.grey) {
|
} else if (info.grey) {
|
||||||
// Greyscale.
|
// Greyscale.
|
||||||
for (int x = 0; x < tga.width; x++) {
|
for (int x = 0; x < tga.width; x++) {
|
||||||
|
if (tga.pixel_size == 16) {
|
||||||
|
scanline[x] = qRgba(*src, *src, *src, *(src + 1));
|
||||||
|
src += 2;
|
||||||
|
}
|
||||||
|
else {
|
||||||
scanline[x] = qRgb(*src, *src, *src);
|
scanline[x] = qRgb(*src, *src, *src);
|
||||||
src++;
|
src++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// True Color.
|
// True Color.
|
||||||
if (tga.pixel_size == 16) {
|
if (tga.pixel_size == 16) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user