From cb7eaa7723140a90c0c1f75d42f62f45e34626a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86lla=20Chiana=20Moskopp?= Date: Tue, 5 Nov 2024 22:07:24 +0100 Subject: [PATCH] Correctly render transparency in TGA type 1 with color format A1R5G5B5 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The branch removed in this patch handled color format A1R5G5B5 specially when creating a texture from a TGA type 1 file, i.e. an image that has a colormap. It did not handle the 1-bit alpha channel correctly, rendering transparent pixels black instead. Since the colormap is converted to A8R8G8B8 earlier anyways, the code for the general case is able to handle this scenario already – at the expense of making the created texture use twice as much GPU memory as necessary. --- irr/src/CImageLoaderTGA.cpp | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/irr/src/CImageLoaderTGA.cpp b/irr/src/CImageLoaderTGA.cpp index 1fd5dddc8..274b15543 100644 --- a/irr/src/CImageLoaderTGA.cpp +++ b/irr/src/CImageLoaderTGA.cpp @@ -181,27 +181,16 @@ IImage *CImageLoaderTGA::loadImage(io::IReadFile *file) const header.ImageWidth, header.ImageHeight, 0, 0, (header.ImageDescriptor & 0x20) == 0); } else { - switch (header.ColorMapEntrySize) { - case 16: - image = new CImage(ECF_A1R5G5B5, core::dimension2d(header.ImageWidth, header.ImageHeight)); - if (image) - CColorConverter::convert8BitTo16Bit((u8 *)data, - (s16 *)image->getData(), - header.ImageWidth, header.ImageHeight, - (s32 *)palette, 0, - (header.ImageDescriptor & 0x20) == 0); - break; - // Note: 24 bit with palette would need a 24 bit palette, too lazy doing that now (textures will prefer 32-bit later anyway) - default: - image = new CImage(ECF_A8R8G8B8, core::dimension2d(header.ImageWidth, header.ImageHeight)); - if (image) - CColorConverter::convert8BitTo32Bit((u8 *)data, - (u8 *)image->getData(), - header.ImageWidth, header.ImageHeight, - (u8 *)palette, 0, - (header.ImageDescriptor & 0x20) == 0); - break; - } + // Colormap is converted to A8R8G8B8 at this point – thus the code can handle all color formats. + // This wastes some texture memory, but is less of a third of the code that does this optimally. + // If you want to refactor this: The possible color formats here are A1R5G5B5, B8G8R8, B8G8R8A8. + image = new CImage(ECF_A8R8G8B8, core::dimension2d(header.ImageWidth, header.ImageHeight)); + if (image) + CColorConverter::convert8BitTo32Bit((u8 *)data, + (u8 *)image->getData(), + header.ImageWidth, header.ImageHeight, + (u8 *)palette, 0, + (header.ImageDescriptor & 0x20) == 0); } } break; case 16: -- 2.30.2