CImage::getPixel wrong for A8R8G8B8 (red/blue flipped)
3D Engine c++
Brought to you by:
cutealien,
nimphoenix2
Byte order of A8R8G8B8 in memory is RGBA, and SColor(u32 value) wants alpha to be in highest bits and blue to be in lowest bits of value (i.e. 0xAARRGGBB). However CImage::getPixel does this
return ((u32*)Data)[y*Size.Width + x];
which assumes little-endian and returns a u32 value 0xAABBGGRR -> flip of red and blue.
The following fix makes it both endianness-independent and correct:
{
u8 p = Data+4(y*Size.Width + x);
return SColor(p[3], p[0], p[1], p[2]);
}
Oops, forgot to format my post, here's the correct one: