mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Fix rendering regression with TGA type 1 files with BGRA8 color (#15402)
TGA uses BGR(A)8, stored in memory in that order. Irrlicht typically expects 0xAARRGGBB, which depends on endianness. (This means that on little endian, no [B][G][R][A] -> 0xAARRGGBB conversion needs to be done, but Irrlicht was swapping the bytes.) This makes both conversion functions consistently convert from [B][G][R]([A]) to 0xAARRGGBB (SColor), documents them properly and moves them to CImageLoaderTGA.cpp so no poor soul shall be fooled by them in the near future. --------- Co-authored-by: Ælla Chiana Moskopp <erle@dieweltistgarnichtso.net>
This commit is contained in:
parent
138052adfc
commit
15e8f9e6a0
4 changed files with 32 additions and 33 deletions
|
@ -7,6 +7,15 @@
|
|||
#include "os.h"
|
||||
#include "irrString.h"
|
||||
|
||||
// Warning: The naming of Irrlicht color formats
|
||||
// is not consistent regarding actual component order in memory.
|
||||
// E.g. in CImage, ECF_R8G8B8 is handled per-byte and stored as [R][G][B] in memory
|
||||
// while ECF_A8R8G8B8 is handled as an u32 0xAARRGGBB so [B][G][R][A] (little endian) in memory.
|
||||
// The conversions suffer from the same inconsistencies, e.g.
|
||||
// convert_R8G8B8toA8R8G8B8 converts [R][G][B] into 0xFFRRGGBB = [B][G][R][FF] (little endian);
|
||||
// convert_A1R5G5B5toR8G8B8 converts 0bARRRRRGGGGGBBBBB into [R][G][B].
|
||||
// This also means many conversions may be broken on big endian.
|
||||
|
||||
namespace irr
|
||||
{
|
||||
namespace video
|
||||
|
@ -393,19 +402,6 @@ void CColorConverter::convert_R8G8B8toA1R5G5B5(const void *sP, s32 sN, void *dP)
|
|||
}
|
||||
}
|
||||
|
||||
void CColorConverter::convert_B8G8R8toA8R8G8B8(const void *sP, s32 sN, void *dP)
|
||||
{
|
||||
u8 *sB = (u8 *)sP;
|
||||
u32 *dB = (u32 *)dP;
|
||||
|
||||
for (s32 x = 0; x < sN; ++x) {
|
||||
*dB = 0xff000000 | (sB[2] << 16) | (sB[1] << 8) | sB[0];
|
||||
|
||||
sB += 3;
|
||||
++dB;
|
||||
}
|
||||
}
|
||||
|
||||
void CColorConverter::convert_A8R8G8B8toR8G8B8A8(const void *sP, s32 sN, void *dP)
|
||||
{
|
||||
const u32 *sB = (const u32 *)sP;
|
||||
|
@ -428,22 +424,6 @@ void CColorConverter::convert_A8R8G8B8toA8B8G8R8(const void *sP, s32 sN, void *d
|
|||
}
|
||||
}
|
||||
|
||||
void CColorConverter::convert_B8G8R8A8toA8R8G8B8(const void *sP, s32 sN, void *dP)
|
||||
{
|
||||
u8 *sB = (u8 *)sP;
|
||||
u8 *dB = (u8 *)dP;
|
||||
|
||||
for (s32 x = 0; x < sN; ++x) {
|
||||
dB[0] = sB[3];
|
||||
dB[1] = sB[2];
|
||||
dB[2] = sB[1];
|
||||
dB[3] = sB[0];
|
||||
|
||||
sB += 4;
|
||||
dB += 4;
|
||||
}
|
||||
}
|
||||
|
||||
void CColorConverter::convert_R8G8B8toB8G8R8(const void *sP, s32 sN, void *dP)
|
||||
{
|
||||
u8 *sB = (u8 *)sP;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue