mirror of
https://github.com/minetest/irrlicht.git
synced 2024-12-24 23:22:26 +01:00
Change all CColorConverter functions to work with u32 instead of s32 for sizes.
Nothing good could come out of putting negative values into any of those functions. And they are used a lot in image loaders which often can be tricked into passing large enough values to make those functions be called with negative numbers. git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6389 dfc29bdd-3216-0410-991c-e03cc46cb475
This commit is contained in:
parent
f64732cd7e
commit
10f0e39e46
@ -13,21 +13,21 @@ namespace video
|
||||
{
|
||||
|
||||
//! converts a monochrome bitmap to A1R5G5B5 data
|
||||
void CColorConverter::convert1BitTo16Bit(const u8* in, s16* out, s32 width, s32 height, s32 linepad, bool flip)
|
||||
void CColorConverter::convert1BitTo16Bit(const u8* in, s16* out, u32 width, u32 height, u32 linepad, bool flip)
|
||||
{
|
||||
if (!in || !out)
|
||||
return;
|
||||
|
||||
if (flip)
|
||||
out += width * height;
|
||||
out += (size_t)width * height;
|
||||
|
||||
for (s32 y=0; y<height; ++y)
|
||||
for (u32 y=0; y<height; ++y)
|
||||
{
|
||||
s32 shift = 7;
|
||||
if (flip)
|
||||
out -= width;
|
||||
|
||||
for (s32 x=0; x<width; ++x)
|
||||
for (u32 x=0; x<width; ++x)
|
||||
{
|
||||
out[x] = *in>>shift & 0x01 ? (s16)0xffff : (s16)0x8000;
|
||||
|
||||
@ -50,21 +50,21 @@ void CColorConverter::convert1BitTo16Bit(const u8* in, s16* out, s32 width, s32
|
||||
|
||||
|
||||
//! converts a 4 bit palettized image to A1R5G5B5
|
||||
void CColorConverter::convert4BitTo16Bit(const u8* in, s16* out, s32 width, s32 height, const s32* palette, s32 linepad, bool flip)
|
||||
void CColorConverter::convert4BitTo16Bit(const u8* in, s16* out, u32 width, u32 height, const s32* palette, u32 linepad, bool flip)
|
||||
{
|
||||
if (!in || !out || !palette)
|
||||
return;
|
||||
|
||||
if (flip)
|
||||
out += width*height;
|
||||
out += (size_t)width*height;
|
||||
|
||||
for (s32 y=0; y<height; ++y)
|
||||
for (u32 y=0; y<height; ++y)
|
||||
{
|
||||
s32 shift = 4;
|
||||
if (flip)
|
||||
out -= width;
|
||||
|
||||
for (s32 x=0; x<width; ++x)
|
||||
for (u32 x=0; x<width; ++x)
|
||||
{
|
||||
out[x] = X8R8G8B8toA1R5G5B5(palette[(u8)((*in >> shift) & 0xf)]);
|
||||
|
||||
@ -89,19 +89,19 @@ void CColorConverter::convert4BitTo16Bit(const u8* in, s16* out, s32 width, s32
|
||||
|
||||
|
||||
//! converts a 8 bit palettized image into A1R5G5B5
|
||||
void CColorConverter::convert8BitTo16Bit(const u8* in, s16* out, s32 width, s32 height, const s32* palette, s32 linepad, bool flip)
|
||||
void CColorConverter::convert8BitTo16Bit(const u8* in, s16* out, u32 width, u32 height, const s32* palette, u32 linepad, bool flip)
|
||||
{
|
||||
if (!in || !out || !palette)
|
||||
return;
|
||||
|
||||
if (flip)
|
||||
out += width * height;
|
||||
out += (size_t)width * height;
|
||||
|
||||
for (s32 y=0; y<height; ++y)
|
||||
for (u32 y=0; y<height; ++y)
|
||||
{
|
||||
if (flip)
|
||||
out -= width; // one line back
|
||||
for (s32 x=0; x<width; ++x)
|
||||
for (u32 x=0; x<width; ++x)
|
||||
{
|
||||
out[x] = X8R8G8B8toA1R5G5B5(palette[(u8)(*in)]);
|
||||
++in;
|
||||
@ -113,20 +113,20 @@ void CColorConverter::convert8BitTo16Bit(const u8* in, s16* out, s32 width, s32
|
||||
}
|
||||
|
||||
//! converts a 8 bit palettized or non palettized image (A8) into R8G8B8
|
||||
void CColorConverter::convert8BitTo24Bit(const u8* in, u8* out, s32 width, s32 height, const u8* palette, s32 linepad, bool flip)
|
||||
void CColorConverter::convert8BitTo24Bit(const u8* in, u8* out, u32 width, u32 height, const u8* palette, u32 linepad, bool flip)
|
||||
{
|
||||
if (!in || !out )
|
||||
return;
|
||||
|
||||
const s32 lineWidth = 3 * width;
|
||||
const u32 lineWidth = 3 * width;
|
||||
if (flip)
|
||||
out += lineWidth * height;
|
||||
out += (size_t)lineWidth * height;
|
||||
|
||||
for (s32 y=0; y<height; ++y)
|
||||
for (u32 y=0; y<height; ++y)
|
||||
{
|
||||
if (flip)
|
||||
out -= lineWidth; // one line back
|
||||
for (s32 x=0; x< lineWidth; x += 3)
|
||||
for (u32 x=0; x< lineWidth; x += 3)
|
||||
{
|
||||
if ( palette )
|
||||
{
|
||||
@ -155,25 +155,25 @@ void CColorConverter::convert8BitTo24Bit(const u8* in, u8* out, s32 width, s32 h
|
||||
}
|
||||
|
||||
//! converts a 8 bit palettized or non palettized image (A8) into R8G8B8
|
||||
void CColorConverter::convert8BitTo32Bit(const u8* in, u8* out, s32 width, s32 height, const u8* palette, s32 linepad, bool flip)
|
||||
void CColorConverter::convert8BitTo32Bit(const u8* in, u8* out, u32 width, u32 height, const u8* palette, u32 linepad, bool flip)
|
||||
{
|
||||
if (!in || !out )
|
||||
return;
|
||||
|
||||
const u32 lineWidth = 4 * width;
|
||||
if (flip)
|
||||
out += lineWidth * height;
|
||||
out += (size_t)lineWidth * height;
|
||||
|
||||
u32 x;
|
||||
u32 c;
|
||||
for (u32 y=0; y < (u32) height; ++y)
|
||||
for (u32 y=0; y < height; ++y)
|
||||
{
|
||||
if (flip)
|
||||
out -= lineWidth; // one line back
|
||||
|
||||
if ( palette )
|
||||
{
|
||||
for (x=0; x < (u32) width; x += 1)
|
||||
for (x=0; x < width; x += 1)
|
||||
{
|
||||
c = in[x];
|
||||
((u32*)out)[x] = ((u32*)palette)[ c ];
|
||||
@ -181,7 +181,7 @@ void CColorConverter::convert8BitTo32Bit(const u8* in, u8* out, s32 width, s32 h
|
||||
}
|
||||
else
|
||||
{
|
||||
for (x=0; x < (u32) width; x += 1)
|
||||
for (x=0; x < width; x += 1)
|
||||
{
|
||||
c = in[x];
|
||||
#ifdef __BIG_ENDIAN__
|
||||
@ -202,20 +202,20 @@ void CColorConverter::convert8BitTo32Bit(const u8* in, u8* out, s32 width, s32 h
|
||||
|
||||
|
||||
//! converts 16bit data to 16bit data
|
||||
void CColorConverter::convert16BitTo16Bit(const s16* in, s16* out, s32 width, s32 height, s32 linepad, bool flip)
|
||||
void CColorConverter::convert16BitTo16Bit(const s16* in, s16* out, u32 width, u32 height, u32 linepad, bool flip)
|
||||
{
|
||||
if (!in || !out)
|
||||
return;
|
||||
|
||||
if (flip)
|
||||
out += width * height;
|
||||
out += (size_t)width * height;
|
||||
|
||||
for (s32 y=0; y<height; ++y)
|
||||
for (u32 y=0; y<height; ++y)
|
||||
{
|
||||
if (flip)
|
||||
out -= width;
|
||||
#ifdef __BIG_ENDIAN__
|
||||
for (s32 x=0; x<width; ++x)
|
||||
for (u32 x=0; x<width; ++x)
|
||||
out[x]=os::Byteswap::byteswap(in[x]);
|
||||
#else
|
||||
memcpy(out, in, width*sizeof(s16));
|
||||
@ -230,22 +230,22 @@ void CColorConverter::convert16BitTo16Bit(const s16* in, s16* out, s32 width, s3
|
||||
|
||||
|
||||
//! copies R8G8B8 24bit data to 24bit data
|
||||
void CColorConverter::convert24BitTo24Bit(const u8* in, u8* out, s32 width, s32 height, s32 linepad, bool flip, bool bgr)
|
||||
void CColorConverter::convert24BitTo24Bit(const u8* in, u8* out, u32 width, u32 height, u32 linepad, bool flip, bool bgr)
|
||||
{
|
||||
if (!in || !out)
|
||||
return;
|
||||
|
||||
const s32 lineWidth = 3 * width;
|
||||
const u32 lineWidth = 3 * width;
|
||||
if (flip)
|
||||
out += lineWidth * height;
|
||||
out += (size_t)lineWidth * height;
|
||||
|
||||
for (s32 y=0; y<height; ++y)
|
||||
for (u32 y=0; y<height; ++y)
|
||||
{
|
||||
if (flip)
|
||||
out -= lineWidth;
|
||||
if (bgr)
|
||||
{
|
||||
for (s32 x=0; x<lineWidth; x+=3)
|
||||
for (u32 x=0; x<lineWidth; x+=3)
|
||||
{
|
||||
out[x+0] = in[x+2];
|
||||
out[x+1] = in[x+1];
|
||||
@ -267,7 +267,7 @@ void CColorConverter::convert24BitTo24Bit(const u8* in, u8* out, s32 width, s32
|
||||
|
||||
//! Resizes the surface to a new size and converts it at the same time
|
||||
//! to an A8R8G8B8 format, returning the pointer to the new buffer.
|
||||
void CColorConverter::convert16bitToA8R8G8B8andResize(const s16* in, s32* out, s32 newWidth, s32 newHeight, s32 currentWidth, s32 currentHeight)
|
||||
void CColorConverter::convert16bitToA8R8G8B8andResize(const s16* in, s32* out, u32 newWidth, u32 newHeight, u32 currentWidth, u32 currentHeight)
|
||||
{
|
||||
if (!newWidth || !newHeight)
|
||||
return;
|
||||
@ -280,11 +280,11 @@ void CColorConverter::convert16bitToA8R8G8B8andResize(const s16* in, s32* out, s
|
||||
f32 sy;
|
||||
s32 t;
|
||||
|
||||
for (s32 x=0; x<newWidth; ++x)
|
||||
for (u32 x=0; x<newWidth; ++x)
|
||||
{
|
||||
sy = 0.0f;
|
||||
|
||||
for (s32 y=0; y<newHeight; ++y)
|
||||
for (u32 y=0; y<newHeight; ++y)
|
||||
{
|
||||
t = in[(s32)(((s32)sy)*currentWidth + x*sourceXStep)];
|
||||
t = (((t >> 15)&0x1)<<31) | (((t >> 10)&0x1F)<<19) |
|
||||
@ -299,20 +299,20 @@ void CColorConverter::convert16bitToA8R8G8B8andResize(const s16* in, s32* out, s
|
||||
|
||||
|
||||
//! copies X8R8G8B8 32 bit data
|
||||
void CColorConverter::convert32BitTo32Bit(const s32* in, s32* out, s32 width, s32 height, s32 linepad, bool flip)
|
||||
void CColorConverter::convert32BitTo32Bit(const s32* in, s32* out, u32 width, u32 height, u32 linepad, bool flip)
|
||||
{
|
||||
if (!in || !out)
|
||||
return;
|
||||
|
||||
if (flip)
|
||||
out += width * height;
|
||||
out += (size_t)width * height;
|
||||
|
||||
for (s32 y=0; y<height; ++y)
|
||||
for (u32 y=0; y<height; ++y)
|
||||
{
|
||||
if (flip)
|
||||
out -= width;
|
||||
#ifdef __BIG_ENDIAN__
|
||||
for (s32 x=0; x<width; ++x)
|
||||
for (u32 x=0; x<width; ++x)
|
||||
out[x]=os::Byteswap::byteswap(in[x]);
|
||||
#else
|
||||
memcpy(out, in, width*sizeof(s32));
|
||||
@ -326,12 +326,12 @@ void CColorConverter::convert32BitTo32Bit(const s32* in, s32* out, s32 width, s3
|
||||
|
||||
|
||||
|
||||
void CColorConverter::convert_A1R5G5B5toR8G8B8(const void* sP, s32 sN, void* dP)
|
||||
void CColorConverter::convert_A1R5G5B5toR8G8B8(const void* sP, u32 sN, void* dP)
|
||||
{
|
||||
u16* sB = (u16*)sP;
|
||||
u8 * dB = (u8 *)dP;
|
||||
|
||||
for (s32 x = 0; x < sN; ++x)
|
||||
for (u32 x = 0; x < sN; ++x)
|
||||
{
|
||||
dB[2] = (*sB & 0x7c00) >> 7;
|
||||
dB[1] = (*sB & 0x03e0) >> 2;
|
||||
@ -342,12 +342,12 @@ void CColorConverter::convert_A1R5G5B5toR8G8B8(const void* sP, s32 sN, void* dP)
|
||||
}
|
||||
}
|
||||
|
||||
void CColorConverter::convert_A1R5G5B5toB8G8R8(const void* sP, s32 sN, void* dP)
|
||||
void CColorConverter::convert_A1R5G5B5toB8G8R8(const void* sP, u32 sN, void* dP)
|
||||
{
|
||||
u16* sB = (u16*)sP;
|
||||
u8 * dB = (u8 *)dP;
|
||||
|
||||
for (s32 x = 0; x < sN; ++x)
|
||||
for (u32 x = 0; x < sN; ++x)
|
||||
{
|
||||
dB[0] = (*sB & 0x7c00) >> 7;
|
||||
dB[1] = (*sB & 0x03e0) >> 2;
|
||||
@ -358,35 +358,35 @@ void CColorConverter::convert_A1R5G5B5toB8G8R8(const void* sP, s32 sN, void* dP)
|
||||
}
|
||||
}
|
||||
|
||||
void CColorConverter::convert_A1R5G5B5toA8R8G8B8(const void* sP, s32 sN, void* dP)
|
||||
void CColorConverter::convert_A1R5G5B5toA8R8G8B8(const void* sP, u32 sN, void* dP)
|
||||
{
|
||||
u16* sB = (u16*)sP;
|
||||
u32* dB = (u32*)dP;
|
||||
|
||||
for (s32 x = 0; x < sN; ++x)
|
||||
for (u32 x = 0; x < sN; ++x)
|
||||
*dB++ = A1R5G5B5toA8R8G8B8(*sB++);
|
||||
}
|
||||
|
||||
void CColorConverter::convert_A1R5G5B5toA1R5G5B5(const void* sP, s32 sN, void* dP)
|
||||
void CColorConverter::convert_A1R5G5B5toA1R5G5B5(const void* sP, u32 sN, void* dP)
|
||||
{
|
||||
memcpy(dP, sP, sN * 2);
|
||||
}
|
||||
|
||||
void CColorConverter::convert_A1R5G5B5toR5G6B5(const void* sP, s32 sN, void* dP)
|
||||
void CColorConverter::convert_A1R5G5B5toR5G6B5(const void* sP, u32 sN, void* dP)
|
||||
{
|
||||
u16* sB = (u16*)sP;
|
||||
u16* dB = (u16*)dP;
|
||||
|
||||
for (s32 x = 0; x < sN; ++x)
|
||||
for (u32 x = 0; x < sN; ++x)
|
||||
*dB++ = A1R5G5B5toR5G6B5(*sB++);
|
||||
}
|
||||
|
||||
void CColorConverter::convert_A8R8G8B8toR8G8B8(const void* sP, s32 sN, void* dP)
|
||||
void CColorConverter::convert_A8R8G8B8toR8G8B8(const void* sP, u32 sN, void* dP)
|
||||
{
|
||||
u8* sB = (u8*)sP;
|
||||
u8* dB = (u8*)dP;
|
||||
|
||||
for (s32 x = 0; x < sN; ++x)
|
||||
for (u32 x = 0; x < sN; ++x)
|
||||
{
|
||||
// sB[3] is alpha
|
||||
dB[0] = sB[2];
|
||||
@ -398,12 +398,12 @@ void CColorConverter::convert_A8R8G8B8toR8G8B8(const void* sP, s32 sN, void* dP)
|
||||
}
|
||||
}
|
||||
|
||||
void CColorConverter::convert_A8R8G8B8toB8G8R8(const void* sP, s32 sN, void* dP)
|
||||
void CColorConverter::convert_A8R8G8B8toB8G8R8(const void* sP, u32 sN, void* dP)
|
||||
{
|
||||
u8* sB = (u8*)sP;
|
||||
u8* dB = (u8*)dP;
|
||||
|
||||
for (s32 x = 0; x < sN; ++x)
|
||||
for (u32 x = 0; x < sN; ++x)
|
||||
{
|
||||
// sB[3] is alpha
|
||||
dB[0] = sB[0];
|
||||
@ -415,26 +415,26 @@ void CColorConverter::convert_A8R8G8B8toB8G8R8(const void* sP, s32 sN, void* dP)
|
||||
}
|
||||
}
|
||||
|
||||
void CColorConverter::convert_A8R8G8B8toA8R8G8B8(const void* sP, s32 sN, void* dP)
|
||||
void CColorConverter::convert_A8R8G8B8toA8R8G8B8(const void* sP, u32 sN, void* dP)
|
||||
{
|
||||
memcpy(dP, sP, sN * 4);
|
||||
}
|
||||
|
||||
void CColorConverter::convert_A8R8G8B8toA1R5G5B5(const void* sP, s32 sN, void* dP)
|
||||
void CColorConverter::convert_A8R8G8B8toA1R5G5B5(const void* sP, u32 sN, void* dP)
|
||||
{
|
||||
u32* sB = (u32*)sP;
|
||||
u16* dB = (u16*)dP;
|
||||
|
||||
for (s32 x = 0; x < sN; ++x)
|
||||
for (u32 x = 0; x < sN; ++x)
|
||||
*dB++ = A8R8G8B8toA1R5G5B5(*sB++);
|
||||
}
|
||||
|
||||
void CColorConverter::convert_A8R8G8B8toA1B5G5R5(const void* sP, s32 sN, void* dP)
|
||||
void CColorConverter::convert_A8R8G8B8toA1B5G5R5(const void* sP, u32 sN, void* dP)
|
||||
{
|
||||
u8 * sB = (u8 *)sP;
|
||||
u16* dB = (u16*)dP;
|
||||
|
||||
for (s32 x = 0; x < sN; ++x)
|
||||
for (u32 x = 0; x < sN; ++x)
|
||||
{
|
||||
s32 r = sB[0] >> 3;
|
||||
s32 g = sB[1] >> 3;
|
||||
@ -448,12 +448,12 @@ void CColorConverter::convert_A8R8G8B8toA1B5G5R5(const void* sP, s32 sN, void* d
|
||||
}
|
||||
}
|
||||
|
||||
void CColorConverter::convert_A8R8G8B8toR5G6B5(const void* sP, s32 sN, void* dP)
|
||||
void CColorConverter::convert_A8R8G8B8toR5G6B5(const void* sP, u32 sN, void* dP)
|
||||
{
|
||||
u8 * sB = (u8 *)sP;
|
||||
u16* dB = (u16*)dP;
|
||||
|
||||
for (s32 x = 0; x < sN; ++x)
|
||||
for (u32 x = 0; x < sN; ++x)
|
||||
{
|
||||
s32 r = sB[2] >> 3;
|
||||
s32 g = sB[1] >> 2;
|
||||
@ -466,12 +466,12 @@ void CColorConverter::convert_A8R8G8B8toR5G6B5(const void* sP, s32 sN, void* dP)
|
||||
}
|
||||
}
|
||||
|
||||
void CColorConverter::convert_A8R8G8B8toR3G3B2(const void* sP, s32 sN, void* dP)
|
||||
void CColorConverter::convert_A8R8G8B8toR3G3B2(const void* sP, u32 sN, void* dP)
|
||||
{
|
||||
u8* sB = (u8*)sP;
|
||||
u8* dB = (u8*)dP;
|
||||
|
||||
for (s32 x = 0; x < sN; ++x)
|
||||
for (u32 x = 0; x < sN; ++x)
|
||||
{
|
||||
u8 r = sB[2] & 0xe0;
|
||||
u8 g = (sB[1] & 0xe0) >> 3;
|
||||
@ -484,17 +484,17 @@ void CColorConverter::convert_A8R8G8B8toR3G3B2(const void* sP, s32 sN, void* dP)
|
||||
}
|
||||
}
|
||||
|
||||
void CColorConverter::convert_R8G8B8toR8G8B8(const void* sP, s32 sN, void* dP)
|
||||
void CColorConverter::convert_R8G8B8toR8G8B8(const void* sP, u32 sN, void* dP)
|
||||
{
|
||||
memcpy(dP, sP, sN * 3);
|
||||
}
|
||||
|
||||
void CColorConverter::convert_R8G8B8toA8R8G8B8(const void* sP, s32 sN, void* dP)
|
||||
void CColorConverter::convert_R8G8B8toA8R8G8B8(const void* sP, u32 sN, void* dP)
|
||||
{
|
||||
u8* sB = (u8* )sP;
|
||||
u32* dB = (u32*)dP;
|
||||
|
||||
for (s32 x = 0; x < sN; ++x)
|
||||
for (u32 x = 0; x < sN; ++x)
|
||||
{
|
||||
*dB = 0xff000000 | (sB[0]<<16) | (sB[1]<<8) | sB[2];
|
||||
|
||||
@ -503,12 +503,12 @@ void CColorConverter::convert_R8G8B8toA8R8G8B8(const void* sP, s32 sN, void* dP)
|
||||
}
|
||||
}
|
||||
|
||||
void CColorConverter::convert_R8G8B8toA1R5G5B5(const void* sP, s32 sN, void* dP)
|
||||
void CColorConverter::convert_R8G8B8toA1R5G5B5(const void* sP, u32 sN, void* dP)
|
||||
{
|
||||
u8 * sB = (u8 *)sP;
|
||||
u16* dB = (u16*)dP;
|
||||
|
||||
for (s32 x = 0; x < sN; ++x)
|
||||
for (u32 x = 0; x < sN; ++x)
|
||||
{
|
||||
s32 r = sB[0] >> 3;
|
||||
s32 g = sB[1] >> 3;
|
||||
@ -521,12 +521,12 @@ void CColorConverter::convert_R8G8B8toA1R5G5B5(const void* sP, s32 sN, void* dP)
|
||||
}
|
||||
}
|
||||
|
||||
void CColorConverter::convert_B8G8R8toA8R8G8B8(const void* sP, s32 sN, void* dP)
|
||||
void CColorConverter::convert_B8G8R8toA8R8G8B8(const void* sP, u32 sN, void* dP)
|
||||
{
|
||||
u8* sB = (u8* )sP;
|
||||
u32* dB = (u32*)dP;
|
||||
|
||||
for (s32 x = 0; x < sN; ++x)
|
||||
for (u32 x = 0; x < sN; ++x)
|
||||
{
|
||||
*dB = 0xff000000 | (sB[2]<<16) | (sB[1]<<8) | sB[0];
|
||||
|
||||
@ -535,12 +535,12 @@ void CColorConverter::convert_B8G8R8toA8R8G8B8(const void* sP, s32 sN, void* dP)
|
||||
}
|
||||
}
|
||||
|
||||
void CColorConverter::convert_B8G8R8A8toA8R8G8B8(const void* sP, s32 sN, void* dP)
|
||||
void CColorConverter::convert_B8G8R8A8toA8R8G8B8(const void* sP, u32 sN, void* dP)
|
||||
{
|
||||
u8* sB = (u8*)sP;
|
||||
u8* dB = (u8*)dP;
|
||||
|
||||
for (s32 x = 0; x < sN; ++x)
|
||||
for (u32 x = 0; x < sN; ++x)
|
||||
{
|
||||
dB[0] = sB[3];
|
||||
dB[1] = sB[2];
|
||||
@ -553,24 +553,24 @@ void CColorConverter::convert_B8G8R8A8toA8R8G8B8(const void* sP, s32 sN, void* d
|
||||
|
||||
}
|
||||
|
||||
void CColorConverter::convert_A8R8G8B8toA8B8G8R8(const void* sP, s32 sN, void* dP)
|
||||
void CColorConverter::convert_A8R8G8B8toA8B8G8R8(const void* sP, u32 sN, void* dP)
|
||||
{
|
||||
const u32* sB = (const u32*)sP;
|
||||
u32* dB = (u32*)dP;
|
||||
|
||||
for (s32 x = 0; x < sN; ++x)
|
||||
for (u32 x = 0; x < sN; ++x)
|
||||
{
|
||||
*dB++ = (*sB & 0xff00ff00) | ((*sB & 0x00ff0000) >> 16) | ((*sB & 0x000000ff) << 16);
|
||||
++sB;
|
||||
}
|
||||
}
|
||||
|
||||
void CColorConverter::convert_R8G8B8toR5G6B5(const void* sP, s32 sN, void* dP)
|
||||
void CColorConverter::convert_R8G8B8toR5G6B5(const void* sP, u32 sN, void* dP)
|
||||
{
|
||||
u8 * sB = (u8 *)sP;
|
||||
u16* dB = (u16*)dP;
|
||||
|
||||
for (s32 x = 0; x < sN; ++x)
|
||||
for (u32 x = 0; x < sN; ++x)
|
||||
{
|
||||
s32 r = sB[0] >> 3;
|
||||
s32 g = sB[1] >> 2;
|
||||
@ -583,17 +583,17 @@ void CColorConverter::convert_R8G8B8toR5G6B5(const void* sP, s32 sN, void* dP)
|
||||
}
|
||||
}
|
||||
|
||||
void CColorConverter::convert_R5G6B5toR5G6B5(const void* sP, s32 sN, void* dP)
|
||||
void CColorConverter::convert_R5G6B5toR5G6B5(const void* sP, u32 sN, void* dP)
|
||||
{
|
||||
memcpy(dP, sP, sN * 2);
|
||||
}
|
||||
|
||||
void CColorConverter::convert_R5G6B5toR8G8B8(const void* sP, s32 sN, void* dP)
|
||||
void CColorConverter::convert_R5G6B5toR8G8B8(const void* sP, u32 sN, void* dP)
|
||||
{
|
||||
u16* sB = (u16*)sP;
|
||||
u8 * dB = (u8 *)dP;
|
||||
|
||||
for (s32 x = 0; x < sN; ++x)
|
||||
for (u32 x = 0; x < sN; ++x)
|
||||
{
|
||||
dB[0] = (*sB & 0xf800) >> 8;
|
||||
dB[1] = (*sB & 0x07e0) >> 3;
|
||||
@ -604,12 +604,12 @@ void CColorConverter::convert_R5G6B5toR8G8B8(const void* sP, s32 sN, void* dP)
|
||||
}
|
||||
}
|
||||
|
||||
void CColorConverter::convert_R5G6B5toB8G8R8(const void* sP, s32 sN, void* dP)
|
||||
void CColorConverter::convert_R5G6B5toB8G8R8(const void* sP, u32 sN, void* dP)
|
||||
{
|
||||
u16* sB = (u16*)sP;
|
||||
u8 * dB = (u8 *)dP;
|
||||
|
||||
for (s32 x = 0; x < sN; ++x)
|
||||
for (u32 x = 0; x < sN; ++x)
|
||||
{
|
||||
dB[2] = (*sB & 0xf800) >> 8;
|
||||
dB[1] = (*sB & 0x07e0) >> 3;
|
||||
@ -620,21 +620,21 @@ void CColorConverter::convert_R5G6B5toB8G8R8(const void* sP, s32 sN, void* dP)
|
||||
}
|
||||
}
|
||||
|
||||
void CColorConverter::convert_R5G6B5toA8R8G8B8(const void* sP, s32 sN, void* dP)
|
||||
void CColorConverter::convert_R5G6B5toA8R8G8B8(const void* sP, u32 sN, void* dP)
|
||||
{
|
||||
u16* sB = (u16*)sP;
|
||||
u32* dB = (u32*)dP;
|
||||
|
||||
for (s32 x = 0; x < sN; ++x)
|
||||
for (u32 x = 0; x < sN; ++x)
|
||||
*dB++ = R5G6B5toA8R8G8B8(*sB++);
|
||||
}
|
||||
|
||||
void CColorConverter::convert_R5G6B5toA1R5G5B5(const void* sP, s32 sN, void* dP)
|
||||
void CColorConverter::convert_R5G6B5toA1R5G5B5(const void* sP, u32 sN, void* dP)
|
||||
{
|
||||
u16* sB = (u16*)sP;
|
||||
u16* dB = (u16*)dP;
|
||||
|
||||
for (s32 x = 0; x < sN; ++x)
|
||||
for (u32 x = 0; x < sN; ++x)
|
||||
*dB++ = R5G6B5toA1R5G5B5(*sB++);
|
||||
}
|
||||
|
||||
@ -696,7 +696,7 @@ bool CColorConverter::canConvertFormat(ECOLOR_FORMAT sourceFormat, ECOLOR_FORMAT
|
||||
return false;
|
||||
}
|
||||
|
||||
void CColorConverter::convert_viaFormat(const void* sP, ECOLOR_FORMAT sF, s32 sN,
|
||||
void CColorConverter::convert_viaFormat(const void* sP, ECOLOR_FORMAT sF, u32 sN,
|
||||
void* dP, ECOLOR_FORMAT dF)
|
||||
{
|
||||
// please also update can_convert_viaFormat when adding new conversions
|
||||
|
@ -18,34 +18,34 @@ class CColorConverter
|
||||
public:
|
||||
|
||||
//! converts a monochrome bitmap to A1R5G5B5
|
||||
static void convert1BitTo16Bit(const u8* in, s16* out, s32 width, s32 height, s32 linepad=0, bool flip=false);
|
||||
static void convert1BitTo16Bit(const u8* in, s16* out, u32 width, u32 height, u32 linepad=0, bool flip=false);
|
||||
|
||||
//! converts a 4 bit palettized image to A1R5G5B5
|
||||
static void convert4BitTo16Bit(const u8* in, s16* out, s32 width, s32 height, const s32* palette, s32 linepad=0, bool flip=false);
|
||||
static void convert4BitTo16Bit(const u8* in, s16* out, u32 width, u32 height, const s32* palette, u32 linepad=0, bool flip=false);
|
||||
|
||||
//! converts a 8 bit palettized image to A1R5G5B5
|
||||
static void convert8BitTo16Bit(const u8* in, s16* out, s32 width, s32 height, const s32* palette, s32 linepad=0, bool flip=false);
|
||||
static void convert8BitTo16Bit(const u8* in, s16* out, u32 width, u32 height, const s32* palette, u32 linepad=0, bool flip=false);
|
||||
|
||||
//! converts a 8 bit palettized or non palettized image (A8) into R8G8B8
|
||||
static void convert8BitTo24Bit(const u8* in, u8* out, s32 width, s32 height, const u8* palette, s32 linepad = 0, bool flip=false);
|
||||
static void convert8BitTo24Bit(const u8* in, u8* out, u32 width, u32 height, const u8* palette, u32 linepad = 0, bool flip=false);
|
||||
|
||||
//! converts a 8 bit palettized or non palettized image (A8) into A8R8G8B8
|
||||
static void convert8BitTo32Bit(const u8* in, u8* out, s32 width, s32 height, const u8* palette, s32 linepad = 0, bool flip=false);
|
||||
static void convert8BitTo32Bit(const u8* in, u8* out, u32 width, u32 height, const u8* palette, u32 linepad = 0, bool flip=false);
|
||||
|
||||
//! converts R8G8B8 16 bit data to A1R5G5B5 data
|
||||
static void convert16BitTo16Bit(const s16* in, s16* out, s32 width, s32 height, s32 linepad=0, bool flip=false);
|
||||
static void convert16BitTo16Bit(const s16* in, s16* out, u32 width, u32 height, u32 linepad=0, bool flip=false);
|
||||
|
||||
//! copies R8G8B8 24 bit data to 24 data, and flips and
|
||||
//! mirrors the image during the process.
|
||||
static void convert24BitTo24Bit(const u8* in, u8* out, s32 width, s32 height, s32 linepad=0, bool flip=false, bool bgr=false);
|
||||
static void convert24BitTo24Bit(const u8* in, u8* out, u32 width, u32 height, u32 linepad=0, bool flip=false, bool bgr=false);
|
||||
|
||||
//! Resizes the surface to a new size and converts it at the same time
|
||||
//! to an A8R8G8B8 format, returning the pointer to the new buffer.
|
||||
static void convert16bitToA8R8G8B8andResize(const s16* in, s32* out, s32 newWidth, s32 newHeight, s32 currentWidth, s32 currentHeight);
|
||||
static void convert16bitToA8R8G8B8andResize(const s16* in, s32* out, u32 newWidth, u32 newHeight, u32 currentWidth, u32 currentHeight);
|
||||
|
||||
//! copies X8R8G8B8 32 bit data, and flips and
|
||||
//! mirrors the image during the process.
|
||||
static void convert32BitTo32Bit(const s32* in, s32* out, s32 width, s32 height, s32 linepad, bool flip=false);
|
||||
static void convert32BitTo32Bit(const s32* in, s32* out, u32 width, u32 height, u32 linepad, bool flip=false);
|
||||
|
||||
|
||||
//! Functions for converting one image format to another efficiently
|
||||
@ -57,34 +57,34 @@ public:
|
||||
//! \param sN number of source pixels to copy
|
||||
//! \param dP pointer to destination data buffer. must be big enough
|
||||
//! to hold sN pixels in the output format.
|
||||
static void convert_A1R5G5B5toR8G8B8(const void* sP, s32 sN, void* dP);
|
||||
static void convert_A1R5G5B5toB8G8R8(const void* sP, s32 sN, void* dP);
|
||||
static void convert_A1R5G5B5toA8R8G8B8(const void* sP, s32 sN, void* dP);
|
||||
static void convert_A1R5G5B5toA1R5G5B5(const void* sP, s32 sN, void* dP);
|
||||
static void convert_A1R5G5B5toR5G6B5(const void* sP, s32 sN, void* dP);
|
||||
static void convert_A1R5G5B5toR8G8B8(const void* sP, u32 sN, void* dP);
|
||||
static void convert_A1R5G5B5toB8G8R8(const void* sP, u32 sN, void* dP);
|
||||
static void convert_A1R5G5B5toA8R8G8B8(const void* sP, u32 sN, void* dP);
|
||||
static void convert_A1R5G5B5toA1R5G5B5(const void* sP, u32 sN, void* dP);
|
||||
static void convert_A1R5G5B5toR5G6B5(const void* sP, u32 sN, void* dP);
|
||||
|
||||
static void convert_A8R8G8B8toR8G8B8(const void* sP, s32 sN, void* dP);
|
||||
static void convert_A8R8G8B8toB8G8R8(const void* sP, s32 sN, void* dP);
|
||||
static void convert_A8R8G8B8toA8R8G8B8(const void* sP, s32 sN, void* dP);
|
||||
static void convert_A8R8G8B8toA1R5G5B5(const void* sP, s32 sN, void* dP);
|
||||
static void convert_A8R8G8B8toA1B5G5R5(const void* sP, s32 sN, void* dP);
|
||||
static void convert_A8R8G8B8toR5G6B5(const void* sP, s32 sN, void* dP);
|
||||
static void convert_A8R8G8B8toR8G8B8(const void* sP, u32 sN, void* dP);
|
||||
static void convert_A8R8G8B8toB8G8R8(const void* sP, u32 sN, void* dP);
|
||||
static void convert_A8R8G8B8toA8R8G8B8(const void* sP, u32 sN, void* dP);
|
||||
static void convert_A8R8G8B8toA1R5G5B5(const void* sP, u32 sN, void* dP);
|
||||
static void convert_A8R8G8B8toA1B5G5R5(const void* sP, u32 sN, void* dP);
|
||||
static void convert_A8R8G8B8toR5G6B5(const void* sP, u32 sN, void* dP);
|
||||
|
||||
static void convert_A8R8G8B8toR3G3B2(const void* sP, s32 sN, void* dP);
|
||||
static void convert_R8G8B8toR8G8B8(const void* sP, s32 sN, void* dP);
|
||||
static void convert_R8G8B8toA8R8G8B8(const void* sP, s32 sN, void* dP);
|
||||
static void convert_R8G8B8toA1R5G5B5(const void* sP, s32 sN, void* dP);
|
||||
static void convert_R8G8B8toR5G6B5(const void* sP, s32 sN, void* dP);
|
||||
static void convert_B8G8R8toA8R8G8B8(const void* sP, s32 sN, void* dP);
|
||||
static void convert_B8G8R8A8toA8R8G8B8(const void* sP, s32 sN, void* dP);
|
||||
static void convert_A8R8G8B8toA8B8G8R8(const void* sP, s32 sN, void* dP);
|
||||
static void convert_A8R8G8B8toR3G3B2(const void* sP, u32 sN, void* dP);
|
||||
static void convert_R8G8B8toR8G8B8(const void* sP, u32 sN, void* dP);
|
||||
static void convert_R8G8B8toA8R8G8B8(const void* sP, u32 sN, void* dP);
|
||||
static void convert_R8G8B8toA1R5G5B5(const void* sP, u32 sN, void* dP);
|
||||
static void convert_R8G8B8toR5G6B5(const void* sP, u32 sN, void* dP);
|
||||
static void convert_B8G8R8toA8R8G8B8(const void* sP, u32 sN, void* dP);
|
||||
static void convert_B8G8R8A8toA8R8G8B8(const void* sP, u32 sN, void* dP);
|
||||
static void convert_A8R8G8B8toA8B8G8R8(const void* sP, u32 sN, void* dP);
|
||||
|
||||
static void convert_R5G6B5toR5G6B5(const void* sP, s32 sN, void* dP);
|
||||
static void convert_R5G6B5toR8G8B8(const void* sP, s32 sN, void* dP);
|
||||
static void convert_R5G6B5toB8G8R8(const void* sP, s32 sN, void* dP);
|
||||
static void convert_R5G6B5toA8R8G8B8(const void* sP, s32 sN, void* dP);
|
||||
static void convert_R5G6B5toA1R5G5B5(const void* sP, s32 sN, void* dP);
|
||||
static void convert_viaFormat(const void* sP, ECOLOR_FORMAT sF, s32 sN,
|
||||
static void convert_R5G6B5toR5G6B5(const void* sP, u32 sN, void* dP);
|
||||
static void convert_R5G6B5toR8G8B8(const void* sP, u32 sN, void* dP);
|
||||
static void convert_R5G6B5toB8G8R8(const void* sP, u32 sN, void* dP);
|
||||
static void convert_R5G6B5toA8R8G8B8(const void* sP, u32 sN, void* dP);
|
||||
static void convert_R5G6B5toA1R5G5B5(const void* sP, u32 sN, void* dP);
|
||||
static void convert_viaFormat(const void* sP, ECOLOR_FORMAT sF, u32 sN,
|
||||
void* dP, ECOLOR_FORMAT dF);
|
||||
// Check if convert_viaFormat is usable
|
||||
static bool canConvertFormat(ECOLOR_FORMAT sourceFormat, ECOLOR_FORMAT destFormat);
|
||||
|
@ -62,7 +62,7 @@ bool CImageWriterBMP::writeImage(io::IWriteFile* file, IImage* image, u32 param)
|
||||
imageHeader.FileSize = imageHeader.BitmapDataOffset + imageHeader.BitmapDataSize;
|
||||
|
||||
// bitmaps are stored upside down and padded so we always do this
|
||||
void (*CColorConverter_convertFORMATtoFORMAT)(const void*, s32, void*) = 0;
|
||||
void (*CColorConverter_convertFORMATtoFORMAT)(const void*, u32, void*) = 0;
|
||||
switch(image->getColorFormat())
|
||||
{
|
||||
case ECF_R8G8B8:
|
||||
|
@ -107,7 +107,7 @@ static void jpeg_file_dest(j_compress_ptr cinfo, io::IWriteFile* file)
|
||||
*/
|
||||
static bool writeJPEGFile(io::IWriteFile* file, IImage* image, u32 quality)
|
||||
{
|
||||
void (*format)(const void*, s32, void*) = 0;
|
||||
void (*format)(const void*, u32, void*) = 0;
|
||||
switch( image->getColorFormat () )
|
||||
{
|
||||
case ECF_R8G8B8:
|
||||
|
@ -55,10 +55,10 @@ bool CImageWriterTGA::writeImage(io::IWriteFile *file, IImage *image,u32 param)
|
||||
// be fixed to only swap/flip
|
||||
imageHeader.ImageDescriptor = (1 << 5);
|
||||
|
||||
// chances are good we'll need to swizzle data, so i'm going
|
||||
// chances are good we'll need to swizzle data, so I'm going
|
||||
// to convert and write one scan line at a time. it's also
|
||||
// a bit cleaner this way
|
||||
void (*CColorConverter_convertFORMATtoFORMAT)(const void*, s32, void*) = 0;
|
||||
void (*CColorConverter_convertFORMATtoFORMAT)(const void*, u32, void*) = 0;
|
||||
switch(image->getColorFormat())
|
||||
{
|
||||
case ECF_A8R8G8B8:
|
||||
|
@ -1,4 +1,4 @@
|
||||
Tests finished. 72 tests of 72 passed.
|
||||
Compiled as RELEASE
|
||||
Test suite pass at GMT Wed May 4 10:25:42 2022
|
||||
Compiled as DEBUG
|
||||
Test suite pass at GMT Sun May 08 15:37:29 2022
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user