From 20cec27ae8a3e1ac16d09ee586ace3e739f631c6 Mon Sep 17 00:00:00 2001 From: Freya Lupen Date: Wed, 1 Feb 2023 21:42:04 +0000 Subject: [PATCH] Fix writing TGA alpha depth flag Correctly write alpha channel depth as 8-bit. --- autotests/write/bwa.tga | Bin 4114 -> 4114 bytes autotests/write/rgba.tga | Bin 4114 -> 4114 bytes src/imageformats/tga.cpp | 5 ++++- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/autotests/write/bwa.tga b/autotests/write/bwa.tga index c0b2ab8f1ed2ec3da02a9f070202c3022c6a9ff7..486aad47e663c3508bc0bfbb458b01332568b8f4 100644 GIT binary patch delta 35 jcmbQFFiAm(fq{tu1{4^8P-COw5ypuI{F|RL>hb{qSg{5? delta 35 jcmbQFFiAm(fq{tu1{4^8P-Uay5ypuI{F|RL>hb{qSbYXK diff --git a/autotests/write/rgba.tga b/autotests/write/rgba.tga index d1fe8623d77408233644939f03497e0f1231cee5..ace80159e15c34b9b1f8cc6637a2e8bbe3564301 100644 GIT binary patch delta 33 gcmbQFFiAm(fq{tu1{4^8P-Al;p9te-HO4o507sAo8~^|S delta 33 gcmbQFFiAm(fq{tu1{4^8P-Sx=p9te-HO4o507qm67ytkO diff --git a/src/imageformats/tga.cpp b/src/imageformats/tga.cpp index e067bc8..04127d2 100644 --- a/src/imageformats/tga.cpp +++ b/src/imageformats/tga.cpp @@ -430,6 +430,9 @@ bool TGAHandler::write(const QImage &image) const QImage &img = image; const bool hasAlpha = (img.format() == QImage::Format_ARGB32); + static constexpr quint8 originTopLeft = TGA_ORIGIN_UPPER + TGA_ORIGIN_LEFT; // 0x20 + static constexpr quint8 alphaChannel8Bits = 0x08; + for (int i = 0; i < 12; i++) { s << targaMagic[i]; } @@ -438,7 +441,7 @@ bool TGAHandler::write(const QImage &image) s << quint16(img.width()); // width s << quint16(img.height()); // height s << quint8(hasAlpha ? 32 : 24); // depth (24 bit RGB + 8 bit alpha) - s << quint8(hasAlpha ? 0x24 : 0x20); // top left image (0x20) + 8 bit alpha (0x4) + s << quint8(hasAlpha ? originTopLeft + alphaChannel8Bits : originTopLeft); // top left image (0x20) + 8 bit alpha (0x8) for (int y = 0; y < img.height(); y++) { for (int x = 0; x < img.width(); x++) {