[Texture2D Test17/18] add methods to convert BGRA8888 format (#19716)

* [Texture2D Test17/18] add methods to convert BGRA8888 format

* use size_t and ssize_t when necessary

* fix compile error
This commit is contained in:
coulsonwang 2019-05-16 09:17:26 +08:00 committed by minggo
parent a572d088d1
commit 2a0ded38a2
8 changed files with 161 additions and 123 deletions

View File

@ -359,9 +359,9 @@ bool Texture2D::initWithMipmaps(MipmapInfo* mipmaps, int mipmapsNum, PixelFormat
unsigned char *data = mipmaps[0].address; unsigned char *data = mipmaps[0].address;
ssize_t dataLen = mipmaps[0].len; size_t dataLen = mipmaps[0].len;
unsigned char *outData = data; unsigned char *outData = data;
ssize_t outDataLen; size_t outDataLen;
if(renderFormat != pixelFormat) //need conversion if(renderFormat != pixelFormat) //need conversion
{ {
@ -594,7 +594,7 @@ bool Texture2D::initWithString(const char *text, const FontDefinition& textDefin
PixelFormat pixelFormat = g_defaultAlphaPixelFormat; PixelFormat pixelFormat = g_defaultAlphaPixelFormat;
unsigned char* outTempData = nullptr; unsigned char* outTempData = nullptr;
ssize_t outTempDataLen = 0; size_t outTempDataLen = 0;
int imageWidth; int imageWidth;
int imageHeight; int imageHeight;

View File

@ -261,7 +261,7 @@ bool TextureCube::init(const std::string& positive_x, const std::string& negativ
//convert pixel format to RGBA //convert pixel format to RGBA
if (ePixelFmt != Texture2D::PixelFormat::RGBA8888) if (ePixelFmt != Texture2D::PixelFormat::RGBA8888)
{ {
ssize_t len = 0; size_t len = 0;
backend::PixelFormatUtils::convertDataToFormat(pData, img->getDataLen(), ePixelFmt, Texture2D::PixelFormat::RGBA8888, &cData, &len); backend::PixelFormatUtils::convertDataToFormat(pData, img->getDataLen(), ePixelFmt, Texture2D::PixelFormat::RGBA8888, &cData, &len);
if (cData != pData) //convert error if (cData != pData) //convert error
{ {

View File

@ -9,9 +9,9 @@ namespace backend { namespace PixelFormatUtils {
//convertor function //convertor function
// IIIIIIII -> RRRRRRRRGGGGGGGGGBBBBBBBB // IIIIIIII -> RRRRRRRRGGGGGGGGGBBBBBBBB
void convertI8ToRGB888(const unsigned char* data, ssize_t dataLen, unsigned char* outData) void convertI8ToRGB888(const unsigned char* data, size_t dataLen, unsigned char* outData)
{ {
for (ssize_t i = 0; i < dataLen; ++i) for (size_t i = 0; i < dataLen; ++i)
{ {
*outData++ = data[i]; //R *outData++ = data[i]; //R
*outData++ = data[i]; //G *outData++ = data[i]; //G
@ -20,7 +20,7 @@ namespace backend { namespace PixelFormatUtils {
} }
// IIIIIIIIAAAAAAAA -> RRRRRRRRGGGGGGGGBBBBBBBB // IIIIIIIIAAAAAAAA -> RRRRRRRRGGGGGGGGBBBBBBBB
void convertAI88ToRGB888(const unsigned char* data, ssize_t dataLen, unsigned char* outData) void convertAI88ToRGB888(const unsigned char* data, size_t dataLen, unsigned char* outData)
{ {
for (ssize_t i = 0, l = dataLen - 1; i < l; i += 2) for (ssize_t i = 0, l = dataLen - 1; i < l; i += 2)
{ {
@ -31,9 +31,9 @@ namespace backend { namespace PixelFormatUtils {
} }
// IIIIIIII -> RRRRRRRRGGGGGGGGGBBBBBBBBAAAAAAAA // IIIIIIII -> RRRRRRRRGGGGGGGGGBBBBBBBBAAAAAAAA
void convertI8ToRGBA8888(const unsigned char* data, ssize_t dataLen, unsigned char* outData) void convertI8ToRGBA8888(const unsigned char* data, size_t dataLen, unsigned char* outData)
{ {
for (ssize_t i = 0; i < dataLen; ++i) for (size_t i = 0; i < dataLen; ++i)
{ {
*outData++ = data[i]; //R *outData++ = data[i]; //R
*outData++ = data[i]; //G *outData++ = data[i]; //G
@ -43,7 +43,7 @@ namespace backend { namespace PixelFormatUtils {
} }
// IIIIIIIIAAAAAAAA -> RRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA // IIIIIIIIAAAAAAAA -> RRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA
void convertAI88ToRGBA8888(const unsigned char* data, ssize_t dataLen, unsigned char* outData) void convertAI88ToRGBA8888(const unsigned char* data, size_t dataLen, unsigned char* outData)
{ {
for (ssize_t i = 0, l = dataLen - 1; i < l; i += 2) for (ssize_t i = 0, l = dataLen - 1; i < l; i += 2)
{ {
@ -55,10 +55,10 @@ namespace backend { namespace PixelFormatUtils {
} }
// IIIIIIII -> RRRRRGGGGGGBBBBB // IIIIIIII -> RRRRRGGGGGGBBBBB
void convertI8ToRGB565(const unsigned char* data, ssize_t dataLen, unsigned char* outData) void convertI8ToRGB565(const unsigned char* data, size_t dataLen, unsigned char* outData)
{ {
unsigned short* out16 = (unsigned short*)outData; unsigned short* out16 = (unsigned short*)outData;
for (int i = 0; i < dataLen; ++i) for (size_t i = 0; i < dataLen; ++i)
{ {
*out16++ = (data[i] & 0x00F8) << 8 //R *out16++ = (data[i] & 0x00F8) << 8 //R
| (data[i] & 0x00FC) << 3 //G | (data[i] & 0x00FC) << 3 //G
@ -67,7 +67,7 @@ namespace backend { namespace PixelFormatUtils {
} }
// IIIIIIIIAAAAAAAA -> RRRRRGGGGGGBBBBB // IIIIIIIIAAAAAAAA -> RRRRRGGGGGGBBBBB
void convertAI88ToRGB565(const unsigned char* data, ssize_t dataLen, unsigned char* outData) void convertAI88ToRGB565(const unsigned char* data, size_t dataLen, unsigned char* outData)
{ {
unsigned short* out16 = (unsigned short*)outData; unsigned short* out16 = (unsigned short*)outData;
for (ssize_t i = 0, l = dataLen - 1; i < l; i += 2) for (ssize_t i = 0, l = dataLen - 1; i < l; i += 2)
@ -79,10 +79,10 @@ namespace backend { namespace PixelFormatUtils {
} }
// IIIIIIII -> RRRRGGGGBBBBAAAA // IIIIIIII -> RRRRGGGGBBBBAAAA
void convertI8ToRGBA4444(const unsigned char* data, ssize_t dataLen, unsigned char* outData) void convertI8ToRGBA4444(const unsigned char* data, size_t dataLen, unsigned char* outData)
{ {
unsigned short* out16 = (unsigned short*)outData; unsigned short* out16 = (unsigned short*)outData;
for (ssize_t i = 0; i < dataLen; ++i) for (size_t i = 0; i < dataLen; ++i)
{ {
*out16++ = (data[i] & 0x00F0) << 8 //R *out16++ = (data[i] & 0x00F0) << 8 //R
| (data[i] & 0x00F0) << 4 //G | (data[i] & 0x00F0) << 4 //G
@ -92,7 +92,7 @@ namespace backend { namespace PixelFormatUtils {
} }
// IIIIIIIIAAAAAAAA -> RRRRGGGGBBBBAAAA // IIIIIIIIAAAAAAAA -> RRRRGGGGBBBBAAAA
void convertAI88ToRGBA4444(const unsigned char* data, ssize_t dataLen, unsigned char* outData) void convertAI88ToRGBA4444(const unsigned char* data, size_t dataLen, unsigned char* outData)
{ {
unsigned short* out16 = (unsigned short*)outData; unsigned short* out16 = (unsigned short*)outData;
for (ssize_t i = 0, l = dataLen - 1; i < l; i += 2) for (ssize_t i = 0, l = dataLen - 1; i < l; i += 2)
@ -105,7 +105,7 @@ namespace backend { namespace PixelFormatUtils {
} }
// IIIIIIIIAAAAAAAA -> BBBBBGGG GGGRRRR // IIIIIIIIAAAAAAAA -> BBBBBGGG GGGRRRR
void convertAI88ToBGR565(const unsigned char* data, ssize_t dataLen, unsigned char* outData) void convertAI88ToBGR565(const unsigned char* data, size_t dataLen, unsigned char* outData)
{ {
uint16_t* out16 = (uint16_t*)outData; uint16_t* out16 = (uint16_t*)outData;
for (ssize_t i = 0, l = dataLen - 1; i < l; i += 2) for (ssize_t i = 0, l = dataLen - 1; i < l; i += 2)
@ -117,7 +117,7 @@ namespace backend { namespace PixelFormatUtils {
} }
// IIIIIIIIAAAAAAAA -> BBBBBGGG GGRRRRRA // IIIIIIIIAAAAAAAA -> BBBBBGGG GGRRRRRA
void convertAI88ToBGR5A1(const unsigned char* data, ssize_t dataLen, unsigned char* outData) void convertAI88ToBGR5A1(const unsigned char* data, size_t dataLen, unsigned char* outData)
{ {
uint16_t* out16 = (uint16_t*)outData; uint16_t* out16 = (uint16_t*)outData;
for (ssize_t i = 0, l = dataLen - 1; i < l; i += 2) for (ssize_t i = 0, l = dataLen - 1; i < l; i += 2)
@ -130,7 +130,7 @@ namespace backend { namespace PixelFormatUtils {
} }
// IIIIIIIIAAAAAAAA -> AAAABBBB GGGGRRRR // IIIIIIIIAAAAAAAA -> AAAABBBB GGGGRRRR
void convertAI88ToABGR4(const unsigned char* data, ssize_t dataLen, unsigned char* outData) void convertAI88ToABGR4(const unsigned char* data, size_t dataLen, unsigned char* outData)
{ {
uint16_t* out16 = (uint16_t*)outData; uint16_t* out16 = (uint16_t*)outData;
for (ssize_t i = 0, l = dataLen - 1; i < l; i += 2) for (ssize_t i = 0, l = dataLen - 1; i < l; i += 2)
@ -144,10 +144,10 @@ namespace backend { namespace PixelFormatUtils {
// IIIIIIII -> RRRRRGGGGGBBBBBA // IIIIIIII -> RRRRRGGGGGBBBBBA
void convertI8ToRGB5A1(const unsigned char* data, ssize_t dataLen, unsigned char* outData) void convertI8ToRGB5A1(const unsigned char* data, size_t dataLen, unsigned char* outData)
{ {
unsigned short* out16 = (unsigned short*)outData; unsigned short* out16 = (unsigned short*)outData;
for (int i = 0; i < dataLen; ++i) for (size_t i = 0; i < dataLen; ++i)
{ {
*out16++ = (data[i] & 0x00F8) << 8 //R *out16++ = (data[i] & 0x00F8) << 8 //R
| (data[i] & 0x00F8) << 3 //G | (data[i] & 0x00F8) << 3 //G
@ -157,10 +157,10 @@ namespace backend { namespace PixelFormatUtils {
} }
/// IIIIIIII -> BBBBBGGG GGRRRRRA /// IIIIIIII -> BBBBBGGG GGRRRRRA
void convertI8ToBGR5A1(const unsigned char* data, ssize_t dataLen, unsigned char* outData) void convertI8ToBGR5A1(const unsigned char* data, size_t dataLen, unsigned char* outData)
{ {
uint16_t *out16 = (uint16_t*)outData; uint16_t *out16 = (uint16_t*)outData;
for (int i = 0; i < dataLen; ++i) for (size_t i = 0; i < dataLen; ++i)
{ {
*out16++ = (data[i] & 0xF8) << 7 //R *out16++ = (data[i] & 0xF8) << 7 //R
| (data[i] & 0xF8) << 2 //G | (data[i] & 0xF8) << 2 //G
@ -170,10 +170,10 @@ namespace backend { namespace PixelFormatUtils {
} }
// IIIIIIIII -> BBBBBGGG GGGRRRRR // IIIIIIIII -> BBBBBGGG GGGRRRRR
void convertI8ToBGR565(const unsigned char* data, ssize_t dataLen, unsigned char* outData) void convertI8ToBGR565(const unsigned char* data, size_t dataLen, unsigned char* outData)
{ {
uint16_t *out16 = (uint16_t*)outData; uint16_t *out16 = (uint16_t*)outData;
for (int i = 0; i < dataLen; ++i) for (size_t i = 0; i < dataLen; ++i)
{ {
*out16++ = (data[i] & 0xF8) << 8 //R *out16++ = (data[i] & 0xF8) << 8 //R
| (data[i] & 0xFC) << 3 //G | (data[i] & 0xFC) << 3 //G
@ -183,10 +183,10 @@ namespace backend { namespace PixelFormatUtils {
} }
// IIIIIIIII -> AAAABBBBB GGGGRRRR // IIIIIIIII -> AAAABBBBB GGGGRRRR
void convertI8ToABGR4(const unsigned char* data, ssize_t dataLen, unsigned char* outData) void convertI8ToABGR4(const unsigned char* data, size_t dataLen, unsigned char* outData)
{ {
uint16_t *out16 = (uint16_t*)outData; uint16_t *out16 = (uint16_t*)outData;
for (int i = 0; i < dataLen; ++i) for (size_t i = 0; i < dataLen; ++i)
{ {
*out16++ = (data[i] & 0xF0) << 8 //R *out16++ = (data[i] & 0xF0) << 8 //R
| (data[i] & 0xF0) << 4 //G | (data[i] & 0xF0) << 4 //G
@ -196,7 +196,7 @@ namespace backend { namespace PixelFormatUtils {
} }
// IIIIIIIIAAAAAAAA -> RRRRRGGGGGBBBBBA // IIIIIIIIAAAAAAAA -> RRRRRGGGGGBBBBBA
void convertAI88ToRGB5A1(const unsigned char* data, ssize_t dataLen, unsigned char* outData) void convertAI88ToRGB5A1(const unsigned char* data, size_t dataLen, unsigned char* outData)
{ {
unsigned short* out16 = (unsigned short*)outData; unsigned short* out16 = (unsigned short*)outData;
for (ssize_t i = 0, l = dataLen - 1; i < l; i += 2) for (ssize_t i = 0, l = dataLen - 1; i < l; i += 2)
@ -209,10 +209,10 @@ namespace backend { namespace PixelFormatUtils {
} }
// IIIIIIII -> IIIIIIIIAAAAAAAA // IIIIIIII -> IIIIIIIIAAAAAAAA
void convertI8ToAI88(const unsigned char* data, ssize_t dataLen, unsigned char* outData) void convertI8ToAI88(const unsigned char* data, size_t dataLen, unsigned char* outData)
{ {
unsigned short* out16 = (unsigned short*)outData; unsigned short* out16 = (unsigned short*)outData;
for (ssize_t i = 0; i < dataLen; ++i) for (size_t i = 0; i < dataLen; ++i)
{ {
*out16++ = 0xFF00 //A *out16++ = 0xFF00 //A
| data[i]; //I | data[i]; //I
@ -220,16 +220,16 @@ namespace backend { namespace PixelFormatUtils {
} }
// IIIIIIIIAAAAAAAA -> AAAAAAAA // IIIIIIIIAAAAAAAA -> AAAAAAAA
void convertAI88ToA8(const unsigned char* data, ssize_t dataLen, unsigned char* outData) void convertAI88ToA8(const unsigned char* data, size_t dataLen, unsigned char* outData)
{ {
for (ssize_t i = 1; i < dataLen; i += 2) for (size_t i = 1; i < dataLen; i += 2)
{ {
*outData++ = data[i]; //A *outData++ = data[i]; //A
} }
} }
// IIIIIIIIAAAAAAAA -> IIIIIIII // IIIIIIIIAAAAAAAA -> IIIIIIII
void convertAI88ToI8(const unsigned char* data, ssize_t dataLen, unsigned char* outData) void convertAI88ToI8(const unsigned char* data, size_t dataLen, unsigned char* outData)
{ {
for (ssize_t i = 0, l = dataLen - 1; i < l; i += 2) for (ssize_t i = 0, l = dataLen - 1; i < l; i += 2)
{ {
@ -238,7 +238,7 @@ namespace backend { namespace PixelFormatUtils {
} }
// RRRRRRRRGGGGGGGGBBBBBBBB -> RRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA // RRRRRRRRGGGGGGGGBBBBBBBB -> RRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA
void convertRGB888ToRGBA8888(const unsigned char* data, ssize_t dataLen, unsigned char* outData) void convertRGB888ToRGBA8888(const unsigned char* data, size_t dataLen, unsigned char* outData)
{ {
for (ssize_t i = 0, l = dataLen - 2; i < l; i += 3) for (ssize_t i = 0, l = dataLen - 2; i < l; i += 3)
{ {
@ -250,7 +250,7 @@ namespace backend { namespace PixelFormatUtils {
} }
// RRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA -> RRRRRRRRGGGGGGGGBBBBBBBB // RRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA -> RRRRRRRRGGGGGGGGBBBBBBBB
void convertRGBA8888ToRGB888(const unsigned char* data, ssize_t dataLen, unsigned char* outData) void convertRGBA8888ToRGB888(const unsigned char* data, size_t dataLen, unsigned char* outData)
{ {
for (ssize_t i = 0, l = dataLen - 3; i < l; i += 4) for (ssize_t i = 0, l = dataLen - 3; i < l; i += 4)
{ {
@ -261,7 +261,7 @@ namespace backend { namespace PixelFormatUtils {
} }
// RRRRRRRRGGGGGGGGBBBBBBBB -> RRRRRGGGGGGBBBBB // RRRRRRRRGGGGGGGGBBBBBBBB -> RRRRRGGGGGGBBBBB
void convertRGB888ToRGB565(const unsigned char* data, ssize_t dataLen, unsigned char* outData) void convertRGB888ToRGB565(const unsigned char* data, size_t dataLen, unsigned char* outData)
{ {
unsigned short* out16 = (unsigned short*)outData; unsigned short* out16 = (unsigned short*)outData;
for (ssize_t i = 0, l = dataLen - 2; i < l; i += 3) for (ssize_t i = 0, l = dataLen - 2; i < l; i += 3)
@ -273,7 +273,7 @@ namespace backend { namespace PixelFormatUtils {
} }
// RRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA -> RRRRRGGGGGGBBBBB // RRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA -> RRRRRGGGGGGBBBBB
void convertRGBA8888ToRGB565(const unsigned char* data, ssize_t dataLen, unsigned char* outData) void convertRGBA8888ToRGB565(const unsigned char* data, size_t dataLen, unsigned char* outData)
{ {
unsigned short* out16 = (unsigned short*)outData; unsigned short* out16 = (unsigned short*)outData;
for (ssize_t i = 0, l = dataLen - 3; i < l; i += 4) for (ssize_t i = 0, l = dataLen - 3; i < l; i += 4)
@ -285,7 +285,7 @@ namespace backend { namespace PixelFormatUtils {
} }
// RRRRRRRRGGGGGGGGBBBBBBBB -> AAAAAAAA // RRRRRRRRGGGGGGGGBBBBBBBB -> AAAAAAAA
void convertRGB888ToA8(const unsigned char* data, ssize_t dataLen, unsigned char* outData) void convertRGB888ToA8(const unsigned char* data, size_t dataLen, unsigned char* outData)
{ {
for (ssize_t i = 0, l = dataLen - 2; i < l; i += 3) for (ssize_t i = 0, l = dataLen - 2; i < l; i += 3)
{ {
@ -294,7 +294,7 @@ namespace backend { namespace PixelFormatUtils {
} }
// RRRRRRRRGGGGGGGGBBBBBBBB -> IIIIIIII // RRRRRRRRGGGGGGGGBBBBBBBB -> IIIIIIII
void convertRGB888ToI8(const unsigned char* data, ssize_t dataLen, unsigned char* outData) void convertRGB888ToI8(const unsigned char* data, size_t dataLen, unsigned char* outData)
{ {
for (ssize_t i = 0, l = dataLen - 2; i < l; i += 3) for (ssize_t i = 0, l = dataLen - 2; i < l; i += 3)
{ {
@ -303,7 +303,7 @@ namespace backend { namespace PixelFormatUtils {
} }
// RRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA -> IIIIIIII // RRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA -> IIIIIIII
void convertRGBA8888ToI8(const unsigned char* data, ssize_t dataLen, unsigned char* outData) void convertRGBA8888ToI8(const unsigned char* data, size_t dataLen, unsigned char* outData)
{ {
for (ssize_t i = 0, l = dataLen - 3; i < l; i += 4) for (ssize_t i = 0, l = dataLen - 3; i < l; i += 4)
{ {
@ -312,7 +312,7 @@ namespace backend { namespace PixelFormatUtils {
} }
// RRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA -> AAAAAAAA // RRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA -> AAAAAAAA
void convertRGBA8888ToA8(const unsigned char* data, ssize_t dataLen, unsigned char* outData) void convertRGBA8888ToA8(const unsigned char* data, size_t dataLen, unsigned char* outData)
{ {
for (ssize_t i = 0, l = dataLen - 3; i < l; i += 4) for (ssize_t i = 0, l = dataLen - 3; i < l; i += 4)
{ {
@ -321,7 +321,7 @@ namespace backend { namespace PixelFormatUtils {
} }
// RRRRRRRRGGGGGGGGBBBBBBBB -> IIIIIIIIAAAAAAAA // RRRRRRRRGGGGGGGGBBBBBBBB -> IIIIIIIIAAAAAAAA
void convertRGB888ToAI88(const unsigned char* data, ssize_t dataLen, unsigned char* outData) void convertRGB888ToAI88(const unsigned char* data, size_t dataLen, unsigned char* outData)
{ {
for (ssize_t i = 0, l = dataLen - 2; i < l; i += 3) for (ssize_t i = 0, l = dataLen - 2; i < l; i += 3)
{ {
@ -332,7 +332,7 @@ namespace backend { namespace PixelFormatUtils {
// RRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA -> IIIIIIIIAAAAAAAA // RRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA -> IIIIIIIIAAAAAAAA
void convertRGBA8888ToAI88(const unsigned char* data, ssize_t dataLen, unsigned char* outData) void convertRGBA8888ToAI88(const unsigned char* data, size_t dataLen, unsigned char* outData)
{ {
for (ssize_t i = 0, l = dataLen - 3; i < l; i += 4) for (ssize_t i = 0, l = dataLen - 3; i < l; i += 4)
{ {
@ -342,7 +342,7 @@ namespace backend { namespace PixelFormatUtils {
} }
// RRRRRRRRGGGGGGGGBBBBBBBB -> RRRRGGGGBBBBAAAA // RRRRRRRRGGGGGGGGBBBBBBBB -> RRRRGGGGBBBBAAAA
void convertRGB888ToRGBA4444(const unsigned char* data, ssize_t dataLen, unsigned char* outData) void convertRGB888ToRGBA4444(const unsigned char* data, size_t dataLen, unsigned char* outData)
{ {
unsigned short* out16 = (unsigned short*)outData; unsigned short* out16 = (unsigned short*)outData;
for (ssize_t i = 0, l = dataLen - 2; i < l; i += 3) for (ssize_t i = 0, l = dataLen - 2; i < l; i += 3)
@ -355,7 +355,7 @@ namespace backend { namespace PixelFormatUtils {
} }
// RRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA -> RRRRGGGGBBBBAAAA // RRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA -> RRRRGGGGBBBBAAAA
void convertRGBA8888ToRGBA4444(const unsigned char* data, ssize_t dataLen, unsigned char* outData) void convertRGBA8888ToRGBA4444(const unsigned char* data, size_t dataLen, unsigned char* outData)
{ {
unsigned short* out16 = (unsigned short*)outData; unsigned short* out16 = (unsigned short*)outData;
for (ssize_t i = 0, l = dataLen - 3; i < l; i += 4) for (ssize_t i = 0, l = dataLen - 3; i < l; i += 4)
@ -368,7 +368,7 @@ namespace backend { namespace PixelFormatUtils {
} }
// RRRRRRRRGGGGGGGGBBBBBBBB -> RRRRRGGGGGBBBBBA // RRRRRRRRGGGGGGGGBBBBBBBB -> RRRRRGGGGGBBBBBA
void convertRGB888ToRGB5A1(const unsigned char* data, ssize_t dataLen, unsigned char* outData) void convertRGB888ToRGB5A1(const unsigned char* data, size_t dataLen, unsigned char* outData)
{ {
unsigned short* out16 = (unsigned short*)outData; unsigned short* out16 = (unsigned short*)outData;
for (ssize_t i = 0, l = dataLen - 2; i < l; i += 3) for (ssize_t i = 0, l = dataLen - 2; i < l; i += 3)
@ -381,10 +381,10 @@ namespace backend { namespace PixelFormatUtils {
} }
// RRRRRRRRGGGGGGGGBBBBBBBB -> BBBBBGGG GGGRRRRR // RRRRRRRRGGGGGGGGBBBBBBBB -> BBBBBGGG GGGRRRRR
void convertRGB888ToB5G6R5(const unsigned char *data, ssize_t dataLen, unsigned char *out) void convertRGB888ToB5G6R5(const unsigned char *data, size_t dataLen, unsigned char *out)
{ {
uint16_t *outData = (uint16_t*) out; uint16_t *outData = (uint16_t*) out;
for(int i = 0;i < dataLen ; i += 3) for(size_t i = 0;i < dataLen ; i += 3)
{ {
*outData++ = ((data[i] & 0xF8) << 8)| *outData++ = ((data[i] & 0xF8) << 8)|
((data[i + 1] &0xFC) << 3) | ((data[i + 1] &0xFC) << 3) |
@ -393,10 +393,10 @@ namespace backend { namespace PixelFormatUtils {
} }
// RRRRRRRRGGGGGGGGBBBBBBBB -> BBBBBGGG GGRRRRRA // RRRRRRRRGGGGGGGGBBBBBBBB -> BBBBBGGG GGRRRRRA
void convertRGB888ToBGR5A1(const unsigned char *data, ssize_t dataLen, unsigned char *out) void convertRGB888ToBGR5A1(const unsigned char *data, size_t dataLen, unsigned char *out)
{ {
uint16_t *outData = (uint16_t*) out; uint16_t *outData = (uint16_t*) out;
for(int i = 0;i < dataLen ; i += 3) for(size_t i = 0;i < dataLen ; i += 3)
{ {
*outData++ = ((data[i] & 0xF8) << 7) | *outData++ = ((data[i] & 0xF8) << 7) |
((data[i + 1] & 0xF8) << 2) | ((data[i + 1] & 0xF8) << 2) |
@ -405,10 +405,10 @@ namespace backend { namespace PixelFormatUtils {
} }
// RRRRRRRRGGGGGGGGBBBBBBBB -> AAAABBBB GGGGRRRR // RRRRRRRRGGGGGGGGBBBBBBBB -> AAAABBBB GGGGRRRR
void convertRGB888ToABGR4(const unsigned char *data, ssize_t dataLen, unsigned char *out) void convertRGB888ToABGR4(const unsigned char *data, size_t dataLen, unsigned char *out)
{ {
uint16_t *outData = (uint16_t*) out; uint16_t *outData = (uint16_t*) out;
for(int i = 0;i < dataLen ; i += 3) for(size_t i = 0;i < dataLen ; i += 3)
{ {
*outData++ = ((data[i] & 0xF0) << 8) | //r *outData++ = ((data[i] & 0xF0) << 8) | //r
((data[i + 1] & 0xF0) << 4) | //g ((data[i + 1] & 0xF0) << 4) | //g
@ -418,7 +418,7 @@ namespace backend { namespace PixelFormatUtils {
} }
// RRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA -> RRRRRGGG GGBBBBBA // RRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA -> RRRRRGGG GGBBBBBA
void convertRGBA8888ToRGB5A1(const unsigned char* data, ssize_t dataLen, unsigned char* outData) void convertRGBA8888ToRGB5A1(const unsigned char* data, size_t dataLen, unsigned char* outData)
{ {
unsigned short* out16 = (unsigned short*)outData; unsigned short* out16 = (unsigned short*)outData;
for (ssize_t i = 0, l = dataLen - 2; i < l; i += 4) for (ssize_t i = 0, l = dataLen - 2; i < l; i += 4)
@ -431,11 +431,11 @@ namespace backend { namespace PixelFormatUtils {
} }
// RRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA -> BBBBBGGG GGGRRRR // RRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA -> BBBBBGGG GGGRRRR
void convertRGBA8888ToBGR565(const unsigned char *data, ssize_t dataLen, unsigned char *out) void convertRGBA8888ToBGR565(const unsigned char *data, size_t dataLen, unsigned char *out)
{ {
uint16_t *outData = (uint16_t*)out; uint16_t *outData = (uint16_t*)out;
const ssize_t pixelCnt = dataLen / 4; const size_t pixelCnt = dataLen / 4;
for(int i=0;i < pixelCnt; i++ ) for(size_t i=0;i < pixelCnt; i++ )
{ {
outData[i] = ((data[i*4 + 2] & 0xF8) >> 3) | //b outData[i] = ((data[i*4 + 2] & 0xF8) >> 3) | //b
((data[i * 4 + 1] & 0xFC ) << 3) | //g ((data[i * 4 + 1] & 0xFC ) << 3) | //g
@ -444,10 +444,10 @@ namespace backend { namespace PixelFormatUtils {
} }
// RRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA -> AAAABBBB GGGGRRRR // RRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA -> AAAABBBB GGGGRRRR
void convertRGBA8888ToABGR4(const unsigned char *data, ssize_t dataLen, unsigned char *out) void convertRGBA8888ToABGR4(const unsigned char *data, size_t dataLen, unsigned char *out)
{ {
uint16_t *outData = (uint16_t*)out; uint16_t *outData = (uint16_t*)out;
for(int i=0;i < dataLen; i+=4 ) for(size_t i=0;i < dataLen; i+=4 )
{ {
*outData++ = ((data[i] & 0xF0) << 8) | //r *outData++ = ((data[i] & 0xF0) << 8) | //r
((data[i + 1] & 0xF0) << 4) | //g ((data[i + 1] & 0xF0) << 4) | //g
@ -457,10 +457,10 @@ namespace backend { namespace PixelFormatUtils {
} }
// RRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA -> BBBBBGGG GGRRRRRA // RRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA -> BBBBBGGG GGRRRRRA
void convertRGBA8888ToBGR5A1(const unsigned char *data, ssize_t dataLen, unsigned char *out) void convertRGBA8888ToBGR5A1(const unsigned char *data, size_t dataLen, unsigned char *out)
{ {
uint16_t *outData = (uint16_t*)out; uint16_t *outData = (uint16_t*)out;
for(int i = 0; i < dataLen; i += 4) for(size_t i = 0; i < dataLen; i += 4)
{ {
*outData++ = ((data[i + 2] & 0xF8) >> 3)| //b *outData++ = ((data[i + 2] & 0xF8) >> 3)| //b
((data[i + 1] & 0xF8 ) << 2) | //g ((data[i + 1] & 0xF8 ) << 2) | //g
@ -470,12 +470,12 @@ namespace backend { namespace PixelFormatUtils {
} }
void convertRGB5A1ToRGBA8888(const unsigned char* data, ssize_t dataLen, unsigned char* outData) void convertRGB5A1ToRGBA8888(const unsigned char* data, size_t dataLen, unsigned char* outData)
{ {
uint16_t *inData = (uint16_t*)data; uint16_t *inData = (uint16_t*)data;
const uint16_t pixelLen = dataLen / 2; const size_t pixelLen = dataLen / 2;
uint16_t pixel; uint16_t pixel;
for (uint32_t i = 0; i < pixelLen; i++) for (size_t i = 0; i < pixelLen; i++)
{ {
pixel = inData[i]; pixel = inData[i];
*outData++ = (pixel & (0x001F << 11)) >> 8; *outData++ = (pixel & (0x001F << 11)) >> 8;
@ -486,13 +486,13 @@ namespace backend { namespace PixelFormatUtils {
} }
// ABBBBBGG GGGRRRRR -> BBBBBGGG GGRRRRRA // ABBBBBGG GGGRRRRR -> BBBBBGGG GGRRRRRA
void convertRGB5A1ToBGR5A1(const unsigned char *data, ssize_t dataLen, unsigned char *out) void convertRGB5A1ToBGR5A1(const unsigned char *data, size_t dataLen, unsigned char *out)
{ {
const size_t pixelLen = dataLen / 2; const size_t pixelLen = dataLen / 2;
const uint16_t *inData = (uint16_t*) data; const uint16_t *inData = (uint16_t*) data;
uint16_t *outData = (uint16_t*) out; uint16_t *outData = (uint16_t*) out;
uint16_t pixel; uint16_t pixel;
for (uint32_t i = 0; i < pixelLen; i++ ) for (size_t i = 0; i < pixelLen; i++ )
{ {
pixel = inData[i]; pixel = inData[i];
outData[i] = (pixel >> 1) | ((pixel & 0x0001) << 15); outData[i] = (pixel >> 1) | ((pixel & 0x0001) << 15);
@ -500,12 +500,12 @@ namespace backend { namespace PixelFormatUtils {
} }
void convertRGB565ToRGBA8888(const unsigned char* data, ssize_t dataLen, unsigned char* outData) void convertRGB565ToRGBA8888(const unsigned char* data, size_t dataLen, unsigned char* outData)
{ {
uint16_t *inData = (uint16_t*)data; uint16_t *inData = (uint16_t*)data;
const uint16_t pixelLen = dataLen / 2; const size_t pixelLen = dataLen / 2;
uint16_t pixel; uint16_t pixel;
for (uint32_t i = 0; i < pixelLen; i++) for (size_t i = 0; i < pixelLen; i++)
{ {
pixel = inData[i]; pixel = inData[i];
*outData++ = (pixel & (0x001F << 11)) >> 8; *outData++ = (pixel & (0x001F << 11)) >> 8;
@ -519,12 +519,12 @@ namespace backend { namespace PixelFormatUtils {
// void convertRGB565ToB5G6R5(const unsigned char *data, ssize_t dataLen, unsigned char *out) // void convertRGB565ToB5G6R5(const unsigned char *data, ssize_t dataLen, unsigned char *out)
void convertRGBA4444ToRGBA8888(const unsigned char* data, ssize_t dataLen, unsigned char* outData) void convertRGBA4444ToRGBA8888(const unsigned char* data, size_t dataLen, unsigned char* outData)
{ {
uint16_t *inData = (uint16_t*)data; uint16_t *inData = (uint16_t*)data;
const uint16_t pixelLen = dataLen / 2; const size_t pixelLen = dataLen / 2;
uint16_t pixel; uint16_t pixel;
for (uint32_t i = 0; i < pixelLen; i++) for (size_t i = 0; i < pixelLen; i++)
{ {
pixel = inData[i]; pixel = inData[i];
*outData++ = ((pixel & 0xF000) >> 12) * 17; *outData++ = ((pixel & 0xF000) >> 12) * 17;
@ -538,9 +538,9 @@ namespace backend { namespace PixelFormatUtils {
// AAAABBBBGGGGRRRR -> AAAABBBB GGGGRRRR // AAAABBBBGGGGRRRR -> AAAABBBB GGGGRRRR
//void convertRGBA4444ToABGR4444(const unsigned char *data, ssize_t dataLen, unsigned char *out) //void convertRGBA4444ToABGR4444(const unsigned char *data, ssize_t dataLen, unsigned char *out)
void convertA8ToRGBA8888(const unsigned char* data, ssize_t dataLen, unsigned char* outData) void convertA8ToRGBA8888(const unsigned char* data, size_t dataLen, unsigned char* outData)
{ {
for (uint32_t i = 0; i < dataLen; i++) for (size_t i = 0; i < dataLen; i++)
{ {
*outData++ = 0; *outData++ = 0;
*outData++ = 0; *outData++ = 0;
@ -549,13 +549,24 @@ namespace backend { namespace PixelFormatUtils {
} }
} }
void convertBGRA8888ToRGBA8888(const unsigned char* data, size_t dataLen, unsigned char* outData)
{
const size_t pixelCounts = dataLen / 4;
for (size_t i = 0; i < pixelCounts; i++)
{
*outData++ = data[i*4 + 2];
*outData++ = data[i*4 + 1];
*outData++ = data[i*4 + 0];
*outData++ = data[i*4 + 3];
}
}
// converter function end // converter function end
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
cocos2d::Texture2D::PixelFormat convertI8ToFormat(const unsigned char* data, ssize_t dataLen, PixelFormat format, unsigned char** outData, ssize_t* outDataLen) cocos2d::Texture2D::PixelFormat convertI8ToFormat(const unsigned char* data, size_t dataLen, PixelFormat format, unsigned char** outData, size_t* outDataLen)
{ {
switch (format) switch (format)
{ {
@ -623,7 +634,7 @@ namespace backend { namespace PixelFormatUtils {
return format; return format;
} }
cocos2d::Texture2D::PixelFormat convertAI88ToFormat(const unsigned char* data, ssize_t dataLen, PixelFormat format, unsigned char** outData, ssize_t* outDataLen) cocos2d::Texture2D::PixelFormat convertAI88ToFormat(const unsigned char* data, size_t dataLen, PixelFormat format, unsigned char** outData, size_t* outDataLen)
{ {
switch (format) switch (format)
{ {
@ -693,7 +704,7 @@ namespace backend { namespace PixelFormatUtils {
return format; return format;
} }
cocos2d::Texture2D::PixelFormat convertRGB888ToFormat(const unsigned char* data, ssize_t dataLen, PixelFormat format, unsigned char** outData, ssize_t* outDataLen) cocos2d::Texture2D::PixelFormat convertRGB888ToFormat(const unsigned char* data, size_t dataLen, PixelFormat format, unsigned char** outData, size_t* outDataLen)
{ {
switch (format) switch (format)
{ {
@ -761,7 +772,7 @@ namespace backend { namespace PixelFormatUtils {
return format; return format;
} }
cocos2d::Texture2D::PixelFormat convertRGBA8888ToFormat(const unsigned char* data, ssize_t dataLen, PixelFormat format, unsigned char** outData, ssize_t* outDataLen) cocos2d::Texture2D::PixelFormat convertRGBA8888ToFormat(const unsigned char* data, size_t dataLen, PixelFormat format, unsigned char** outData, size_t* outDataLen)
{ {
switch (format) switch (format)
@ -831,7 +842,7 @@ namespace backend { namespace PixelFormatUtils {
return format; return format;
} }
cocos2d::Texture2D::PixelFormat convertRGB5A1ToFormat(const unsigned char* data, ssize_t dataLen, PixelFormat format, unsigned char** outData, ssize_t* outDataLen) cocos2d::Texture2D::PixelFormat convertRGB5A1ToFormat(const unsigned char* data, size_t dataLen, PixelFormat format, unsigned char** outData, size_t* outDataLen)
{ {
switch (format) switch (format)
{ {
@ -859,7 +870,7 @@ namespace backend { namespace PixelFormatUtils {
return format; return format;
} }
cocos2d::Texture2D::PixelFormat convertRGB565ToFormat(const unsigned char* data, ssize_t dataLen, PixelFormat format, unsigned char** outData, ssize_t* outDataLen) cocos2d::Texture2D::PixelFormat convertRGB565ToFormat(const unsigned char* data, size_t dataLen, PixelFormat format, unsigned char** outData, size_t* outDataLen)
{ {
switch (format) switch (format)
{ {
@ -888,7 +899,7 @@ namespace backend { namespace PixelFormatUtils {
return format; return format;
} }
cocos2d::Texture2D::PixelFormat convertA8ToFormat(const unsigned char* data, ssize_t dataLen, PixelFormat format, unsigned char** outData, ssize_t* outDataLen) cocos2d::Texture2D::PixelFormat convertA8ToFormat(const unsigned char* data, size_t dataLen, PixelFormat format, unsigned char** outData, size_t* outDataLen)
{ {
switch (format) switch (format)
{ {
@ -911,7 +922,7 @@ namespace backend { namespace PixelFormatUtils {
return format; return format;
} }
cocos2d::Texture2D::PixelFormat convertRGBA4444ToFormat(const unsigned char* data, ssize_t dataLen, PixelFormat format, unsigned char** outData, ssize_t* outDataLen) cocos2d::Texture2D::PixelFormat convertRGBA4444ToFormat(const unsigned char* data, size_t dataLen, PixelFormat format, unsigned char** outData, size_t* outDataLen)
{ {
switch (format) switch (format)
{ {
@ -938,6 +949,22 @@ namespace backend { namespace PixelFormatUtils {
return format; return format;
} }
PixelFormat convertBGRA8888ToFormat(const unsigned char* data, size_t dataLen, PixelFormat format, unsigned char** outData, size_t* outDataLen)
{
switch (format) {
case PixelFormat::RGBA8888:
*outDataLen = dataLen;
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
convertBGRA8888ToRGBA8888(data, dataLen, *outData);
break;
default:
break;
}
return format;
}
/* /*
convert map: convert map:
1.PixelFormat::RGBA8888 1.PixelFormat::RGBA8888
@ -955,7 +982,7 @@ namespace backend { namespace PixelFormatUtils {
rgba(1) -> 12345678 rgba(1) -> 12345678
*/ */
cocos2d::Texture2D::PixelFormat convertDataToFormat(const unsigned char* data, ssize_t dataLen, PixelFormat originFormat, PixelFormat format, unsigned char** outData, ssize_t* outDataLen) cocos2d::Texture2D::PixelFormat convertDataToFormat(const unsigned char* data, size_t dataLen, PixelFormat originFormat, PixelFormat format, unsigned char** outData, size_t* outDataLen)
{ {
// don't need to convert // don't need to convert
if (format == originFormat || format == PixelFormat::AUTO) if (format == originFormat || format == PixelFormat::AUTO)
@ -986,6 +1013,8 @@ namespace backend { namespace PixelFormatUtils {
return convertA8ToFormat(data, dataLen, format, outData, outDataLen); return convertA8ToFormat(data, dataLen, format, outData, outDataLen);
#endif #endif
case PixelFormat::BGRA8888:
return convertBGRA8888ToFormat(data, dataLen, format, outData, outDataLen);
default: default:
CCLOG("unsupported conversion from format %d to format %d", static_cast<int>(originFormat), static_cast<int>(format)); CCLOG("unsupported conversion from format %d to format %d", static_cast<int>(originFormat), static_cast<int>(format));
*outData = (unsigned char*)data; *outData = (unsigned char*)data;
@ -993,7 +1022,6 @@ namespace backend { namespace PixelFormatUtils {
return originFormat; return originFormat;
} }
} }
} }
} }

View File

@ -15,57 +15,61 @@ namespace backend {
Convert the format to the format param you specified, if the format is PixelFormat::Automatic, it will detect it automatically and convert to the closest format for you. Convert the format to the format param you specified, if the format is PixelFormat::Automatic, it will detect it automatically and convert to the closest format for you.
It will return the converted format to you. if the outData != data, you must delete it manually. It will return the converted format to you. if the outData != data, you must delete it manually.
*/ */
PixelFormat convertDataToFormat(const unsigned char* data, ssize_t dataLen, PixelFormat originFormat, PixelFormat format, unsigned char** outData, ssize_t* outDataLen); PixelFormat convertDataToFormat(const unsigned char* data, size_t dataLen, PixelFormat originFormat, PixelFormat format, unsigned char** outData, size_t* outDataLen);
PixelFormat convertI8ToFormat(const unsigned char* data, ssize_t dataLen, PixelFormat format, unsigned char** outData, ssize_t* outDataLen); PixelFormat convertI8ToFormat(const unsigned char* data, size_t dataLen, PixelFormat format, unsigned char** outData, size_t* outDataLen);
PixelFormat convertAI88ToFormat(const unsigned char* data, ssize_t dataLen, PixelFormat format, unsigned char** outData, ssize_t* outDataLen); PixelFormat convertAI88ToFormat(const unsigned char* data, size_t dataLen, PixelFormat format, unsigned char** outData, size_t* outDataLen);
PixelFormat convertRGB888ToFormat(const unsigned char* data, ssize_t dataLen, PixelFormat format, unsigned char** outData, ssize_t* outDataLen); PixelFormat convertRGB888ToFormat(const unsigned char* data, size_t dataLen, PixelFormat format, unsigned char** outData, size_t* outDataLen);
PixelFormat convertRGBA8888ToFormat(const unsigned char* data, ssize_t dataLen, PixelFormat format, unsigned char** outData, ssize_t* outDataLen); PixelFormat convertRGBA8888ToFormat(const unsigned char* data, size_t dataLen, PixelFormat format, unsigned char** outData, size_t* outDataLen);
PixelFormat convertRGB5A1ToFormat(const unsigned char* data, ssize_t dataLen, PixelFormat format, unsigned char** outData, ssize_t* outDataLen); PixelFormat convertRGB5A1ToFormat(const unsigned char* data, size_t dataLen, PixelFormat format, unsigned char** outData, size_t* outDataLen);
PixelFormat convertRGB565ToFormat(const unsigned char* data, ssize_t dataLen, PixelFormat format, unsigned char** outData, ssize_t* outDataLen); PixelFormat convertRGB565ToFormat(const unsigned char* data, size_t dataLen, PixelFormat format, unsigned char** outData, size_t* outDataLen);
PixelFormat convertA8ToFormat(const unsigned char* data, ssize_t dataLen, PixelFormat format, unsigned char** outData, ssize_t* outDataLen); PixelFormat convertA8ToFormat(const unsigned char* data, size_t dataLen, PixelFormat format, unsigned char** outData, size_t* outDataLen);
PixelFormat convertRGBA4444ToFormat(const unsigned char* data, ssize_t dataLen, PixelFormat format, unsigned char** outData, ssize_t* outDataLen); PixelFormat convertRGBA4444ToFormat(const unsigned char* data, size_t dataLen, PixelFormat format, unsigned char** outData, size_t* outDataLen);
PixelFormat convertBGRA8888ToFormat(const unsigned char* data, size_t dataLen, PixelFormat format, unsigned char** outData, size_t* outDataLen);
//I8 to XXX //I8 to XXX
void convertI8ToRGB888(const unsigned char* data, ssize_t dataLen, unsigned char* outData); void convertI8ToRGB888(const unsigned char* data, size_t dataLen, unsigned char* outData);
void convertI8ToRGBA8888(const unsigned char* data, ssize_t dataLen, unsigned char* outData); void convertI8ToRGBA8888(const unsigned char* data, size_t dataLen, unsigned char* outData);
void convertI8ToRGB565(const unsigned char* data, ssize_t dataLen, unsigned char* outData); void convertI8ToRGB565(const unsigned char* data, size_t dataLen, unsigned char* outData);
void convertI8ToRGBA4444(const unsigned char* data, ssize_t dataLen, unsigned char* outData); void convertI8ToRGBA4444(const unsigned char* data, size_t dataLen, unsigned char* outData);
void convertI8ToRGB5A1(const unsigned char* data, ssize_t dataLen, unsigned char* outData); void convertI8ToRGB5A1(const unsigned char* data, size_t dataLen, unsigned char* outData);
void convertI8ToAI88(const unsigned char* data, ssize_t dataLen, unsigned char* outData); void convertI8ToAI88(const unsigned char* data, size_t dataLen, unsigned char* outData);
//AI88 to XXX //AI88 to XXX
void convertAI88ToRGB888(const unsigned char* data, ssize_t dataLen, unsigned char* outData); void convertAI88ToRGB888(const unsigned char* data, size_t dataLen, unsigned char* outData);
void convertAI88ToRGBA8888(const unsigned char* data, ssize_t dataLen, unsigned char* outData); void convertAI88ToRGBA8888(const unsigned char* data, size_t dataLen, unsigned char* outData);
void convertAI88ToRGB565(const unsigned char* data, ssize_t dataLen, unsigned char* outData); void convertAI88ToRGB565(const unsigned char* data, size_t dataLen, unsigned char* outData);
void convertAI88ToRGBA4444(const unsigned char* data, ssize_t dataLen, unsigned char* outData); void convertAI88ToRGBA4444(const unsigned char* data, size_t dataLen, unsigned char* outData);
void convertAI88ToRGB5A1(const unsigned char* data, ssize_t dataLen, unsigned char* outData); void convertAI88ToRGB5A1(const unsigned char* data, size_t dataLen, unsigned char* outData);
void convertAI88ToA8(const unsigned char* data, ssize_t dataLen, unsigned char* outData); void convertAI88ToA8(const unsigned char* data, size_t dataLen, unsigned char* outData);
void convertAI88ToI8(const unsigned char* data, ssize_t dataLen, unsigned char* outData); void convertAI88ToI8(const unsigned char* data, size_t dataLen, unsigned char* outData);
//RGB888 to XXX //RGB888 to XXX
void convertRGB888ToRGBA8888(const unsigned char* data, ssize_t dataLen, unsigned char* outData); void convertRGB888ToRGBA8888(const unsigned char* data, size_t dataLen, unsigned char* outData);
void convertRGB888ToRGB565(const unsigned char* data, ssize_t dataLen, unsigned char* outData); void convertRGB888ToRGB565(const unsigned char* data, size_t dataLen, unsigned char* outData);
void convertRGB888ToA8(const unsigned char* data, ssize_t dataLen, unsigned char* outData); void convertRGB888ToA8(const unsigned char* data, size_t dataLen, unsigned char* outData);
void convertRGB888ToI8(const unsigned char* data, ssize_t dataLen, unsigned char* outData); void convertRGB888ToI8(const unsigned char* data, size_t dataLen, unsigned char* outData);
void convertRGB888ToAI88(const unsigned char* data, ssize_t dataLen, unsigned char* outData); void convertRGB888ToAI88(const unsigned char* data, size_t dataLen, unsigned char* outData);
void convertRGB888ToRGBA4444(const unsigned char* data, ssize_t dataLen, unsigned char* outData); void convertRGB888ToRGBA4444(const unsigned char* data, size_t dataLen, unsigned char* outData);
void convertRGB888ToRGB5A1(const unsigned char* data, ssize_t dataLen, unsigned char* outData); void convertRGB888ToRGB5A1(const unsigned char* data, size_t dataLen, unsigned char* outData);
//RGBA8888 to XXX //RGBA8888 to XXX
void convertRGBA8888ToRGB888(const unsigned char* data, ssize_t dataLen, unsigned char* outData); void convertRGBA8888ToRGB888(const unsigned char* data, size_t dataLen, unsigned char* outData);
void convertRGBA8888ToRGB565(const unsigned char* data, ssize_t dataLen, unsigned char* outData); void convertRGBA8888ToRGB565(const unsigned char* data, size_t dataLen, unsigned char* outData);
void convertRGBA8888ToI8(const unsigned char* data, ssize_t dataLen, unsigned char* outData); void convertRGBA8888ToI8(const unsigned char* data, size_t dataLen, unsigned char* outData);
void convertRGBA8888ToA8(const unsigned char* data, ssize_t dataLen, unsigned char* outData); void convertRGBA8888ToA8(const unsigned char* data, size_t dataLen, unsigned char* outData);
void convertRGBA8888ToAI88(const unsigned char* data, ssize_t dataLen, unsigned char* outData); void convertRGBA8888ToAI88(const unsigned char* data, size_t dataLen, unsigned char* outData);
void convertRGBA8888ToRGBA4444(const unsigned char* data, ssize_t dataLen, unsigned char* outData); void convertRGBA8888ToRGBA4444(const unsigned char* data, size_t dataLen, unsigned char* outData);
void convertRGBA8888ToRGB5A1(const unsigned char* data, ssize_t dataLen, unsigned char* outData); void convertRGBA8888ToRGB5A1(const unsigned char* data, size_t dataLen, unsigned char* outData);
void convertRGB5A1ToRGBA8888(const unsigned char* data, ssize_t dataLen, unsigned char* outData); void convertRGB5A1ToRGBA8888(const unsigned char* data, size_t dataLen, unsigned char* outData);
void convertRGB565ToRGBA8888(const unsigned char* data, ssize_t dataLen, unsigned char* outData); void convertRGB565ToRGBA8888(const unsigned char* data, size_t dataLen, unsigned char* outData);
void convertA8ToRGBA8888(const unsigned char* data, ssize_t dataLen, unsigned char* outData); void convertA8ToRGBA8888(const unsigned char* data, size_t dataLen, unsigned char* outData);
void convertRGBA4444ToRGBA8888(const unsigned char* data, ssize_t dataLen, unsigned char* outData); void convertRGBA4444ToRGBA8888(const unsigned char* data, size_t dataLen, unsigned char* outData);
//BGRA8888 to XXX
void convertBGRA8888ToRGBA8888(const unsigned char* data, size_t dataLen, unsigned char* outData);
}; };
} }
NS_CC_END NS_CC_END

View File

@ -200,6 +200,8 @@ std::string StringUtils::BlendFactor2String(const BlendFactor& blendFactor)
TextureFormat StringUtils::PixelFormat2TextureFormat(const PixelFormat& pixleFormat) TextureFormat StringUtils::PixelFormat2TextureFormat(const PixelFormat& pixleFormat)
{ {
switch (pixleFormat) { switch (pixleFormat) {
case PixelFormat::BGRA8888:
return TextureFormat::BGRA8888;
case PixelFormat::RGBA8888: case PixelFormat::RGBA8888:
return TextureFormat::R8G8B8A8; return TextureFormat::R8G8B8A8;
case PixelFormat::RGB888: case PixelFormat::RGB888:

View File

@ -11,6 +11,7 @@ namespace
switch (textureFormat) switch (textureFormat)
{ {
case TextureFormat::R8G8B8A8: case TextureFormat::R8G8B8A8:
case TextureFormat::BGRA8888:
return byte(4); return byte(4);
case TextureFormat::R8G8B8: case TextureFormat::R8G8B8:
return byte(3); return byte(3);

View File

@ -44,6 +44,7 @@ enum class VertexFormat : uint32_t
enum class TextureFormat : uint32_t enum class TextureFormat : uint32_t
{ {
NONE, NONE,
BGRA8888,
// Four 8-bit normalized unsigned integer components in RGBA order. // Four 8-bit normalized unsigned integer components in RGBA order.
R8G8B8A8, R8G8B8A8,
// Three 8-bit normalized unsigned integer components in RGB order. // Three 8-bit normalized unsigned integer components in RGB order.

View File

@ -99,6 +99,8 @@ MTLPixelFormat Utils::toMTLPixelFormat(TextureFormat textureFormat)
return MTLPixelFormatRGBA8Unorm; return MTLPixelFormatRGBA8Unorm;
case TextureFormat::A8: case TextureFormat::A8:
return MTLPixelFormatA8Unorm; return MTLPixelFormatA8Unorm;
case TextureFormat::BGRA8888:
return MTLPixelFormatBGRA8Unorm;
//on mac, D24S8 means MTLPixelFormatDepth24Unorm_Stencil8, while on ios it means MTLPixelFormatDepth32Float_Stencil8 //on mac, D24S8 means MTLPixelFormatDepth24Unorm_Stencil8, while on ios it means MTLPixelFormatDepth32Float_Stencil8
case TextureFormat::D24S8: case TextureFormat::D24S8: