Texture2D: RGB888 -> A8 conversion (white - full opacity, black - full transparency)

This commit is contained in:
Mikhail Shulepov 2016-02-12 17:23:56 +03:00
parent 8ad49c1bbc
commit 112fceae81
2 changed files with 15 additions and 0 deletions

View File

@ -322,6 +322,15 @@ void Texture2D::convertRGBA8888ToRGB565(const unsigned char* data, ssize_t dataL
}
}
// RRRRRRRRGGGGGGGGBBBBBBBB -> AAAAAAAA
void Texture2D::convertRGB888ToA8(const unsigned char* data, ssize_t dataLen, unsigned char* outData)
{
for (ssize_t i = 0, l = dataLen - 2; i < l; i += 3)
{
*outData++ = (data[i] * 299 + data[i + 1] * 587 + data[i + 2] * 114 + 500) / 1000; //A = (R*299 + G*587 + B*114 + 500) / 1000
}
}
// RRRRRRRRGGGGGGGGBBBBBBBB -> IIIIIIII
void Texture2D::convertRGB888ToI8(const unsigned char* data, ssize_t dataLen, unsigned char* outData)
{
@ -917,6 +926,11 @@ Texture2D::PixelFormat Texture2D::convertRGB888ToFormat(const unsigned char* dat
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
convertRGB888ToRGB565(data, dataLen, *outData);
break;
case PixelFormat::A8:
*outDataLen = dataLen/3;
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
convertRGB888ToA8(data, dataLen, *outData);
break;
case PixelFormat::I8:
*outDataLen = dataLen/3;
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));

View File

@ -489,6 +489,7 @@ private:
//RGB888 to XXX
static void convertRGB888ToRGBA8888(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
static void convertRGB888ToRGB565(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
static void convertRGB888ToA8(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
static void convertRGB888ToI8(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
static void convertRGB888ToAI88(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
static void convertRGB888ToRGBA4444(const unsigned char* data, ssize_t dataLen, unsigned char* outData);