I'm using Irrlicht under Android, and I run into a problem trying to save a screenshot in png. The only one that works is .tga. I debugged(traces) the engine, and I found that the method: CColorConverter::convert_R5G6B5toB8G8R8 is incorrect, it does bad bit operations and pointer arithmetic. So, instead of the code:
Code: Select all
void CColorConverter::convert_R5G6B5toR8G8B8(const void* sP, s32 sN, void* dP)
{
u16* sB = (u16*)sP;
u8 * dB = (u8 *)dP;
for (s32 x = 0; x < sN; ++x)
{
dB[0] = (*sB & 0xf800) << 8;
dB[1] = (*sB & 0x07e0) << 2;
dB[2] = (*sB & 0x001f) << 3;
sB += 4;
dB += 3;
}
}
Code: Select all
void CColorConverter::convert_R5G6B5toB8G8R8(const void* sP, s32 sN, void* dP)
{
u16* sB = (u16*)sP;
u8 * dB = (u8 *)dP;
for (s32 x = 0; x < sN; ++x)
{
dB[2] = (*sB & 0xf800) >> 8;
dB[1] = (*sB & 0x07e0) >> 2;
dB[0] = (*sB & 0x001f) << 3;
sB += 1;
dB += 3;
}
}
If there is an svn, I can try to commit the correction, if not, please someone correct this and put there a warning message about the correctness of the other code.
P.S. Hope this will save some headache to others.
The correction that I made is based on the fact that in PNG writer, the dB is u8* with the size: h*w*3, and sB += 1 because one u16 is used to construct 3 u8.