Extract some explicit loops into calls to color conversion functions.

This commit is contained in:
Henrik Rydgard 2015-04-08 19:59:12 +02:00
parent c2cf2bd97e
commit b5acf15cc9
4 changed files with 50 additions and 51 deletions

View file

@ -131,7 +131,7 @@ void ConvertBGRA8888ToRGBA8888(u32 *dst, const u32 *src, const u32 numPixels) {
for (; i < numPixels; i++) {
const u32 c = src[i];
dst[i] = ((c >> 16) & 0x000000FF) |
((c >> 0) & 0xFF00FF00) |
(c & 0xFF00FF00) |
((c << 16) & 0x00FF0000);
}
}
@ -219,3 +219,27 @@ void ConvertBGRA8888ToRGBA5551(u16 *dst, const u32 *src, const u32 numPixels) {
dst[i] = BGRA8888toRGBA5551(src[i]);
}
}
void ConvertBGRA8888ToRGB565(u16 *dst, const u32 *src, const u32 numPixels) {
for (u32 i = 0; i < numPixels; i++) {
dst[i] = BGRA8888toRGB565(src[i]);
}
}
void ConvertBGRA8888ToRGBA4444(u16 *dst, const u32 *src, const u32 numPixels) {
for (u32 i = 0; i < numPixels; i++) {
dst[i] = BGRA8888toRGBA4444(src[i]);
}
}
void ConvertRGBA8888ToRGB565(u16 *dst, const u32 *src, const u32 numPixels) {
for (u32 x = 0; x < numPixels; ++x) {
dst[x] = RGBA8888toRGB565(src[x]);
}
}
void ConvertRGBA8888ToRGBA4444(u16 *dst, const u32 *src, const u32 numPixels) {
for (u32 x = 0; x < numPixels; ++x) {
dst[x] = RGBA8888toRGBA4444(src[x]);
}
}

View file

@ -20,20 +20,17 @@
#include "CommonTypes.h"
inline u8 Convert4To8(u8 v)
{
inline u8 Convert4To8(u8 v) {
// Swizzle bits: 00001234 -> 12341234
return (v << 4) | (v);
}
inline u8 Convert5To8(u8 v)
{
inline u8 Convert5To8(u8 v) {
// Swizzle bits: 00012345 -> 12345123
return (v << 3) | (v >> 2);
}
inline u8 Convert6To8(u8 v)
{
inline u8 Convert6To8(u8 v) {
// Swizzle bits: 00123456 -> 12345612
return (v << 2) | (v >> 4);
}
@ -74,7 +71,6 @@ inline void ARGB8From5551(u16 c, u32 * dst) {
*dst = ((c & 0x001f) << 19) | (((c >> 5) & 0x001f) << 11) | ((((c >> 10) & 0x001f) << 3)) | 0xFF000000;
}
// TODO: Swizzle the texture access instead.
inline u32 RGBA2BGRA(u32 src) {
const u32 r = (src & 0x000000FF) << 16;
const u32 ga = src & 0xFF00FF00;
@ -82,9 +78,7 @@ inline u32 RGBA2BGRA(u32 src) {
return r | ga | b;
}
inline u32 DecodeRGBA4444(u16 src)
{
inline u32 DecodeRGBA4444(u16 src) {
const u32 r = (src & 0x000F) << 0;
const u32 g = (src & 0x00F0) << 4;
const u32 b = (src & 0x0F00) << 8;
@ -94,8 +88,7 @@ inline u32 DecodeRGBA4444(u16 src)
return c | (c << 4);
}
inline u32 DecodeRGBA5551(u16 src)
{
inline u32 DecodeRGBA5551(u16 src) {
u8 r = Convert5To8((src >> 0) & 0x1F);
u8 g = Convert5To8((src >> 5) & 0x1F);
u8 b = Convert5To8((src >> 10) & 0x1F);
@ -104,8 +97,7 @@ inline u32 DecodeRGBA5551(u16 src)
return (a << 24) | (b << 16) | (g << 8) | r;
}
inline u32 DecodeRGB565(u16 src)
{
inline u32 DecodeRGB565(u16 src) {
u8 r = Convert5To8((src >> 0) & 0x1F);
u8 g = Convert6To8((src >> 5) & 0x3F);
u8 b = Convert5To8((src >> 11) & 0x1F);
@ -113,8 +105,7 @@ inline u32 DecodeRGB565(u16 src)
return (a << 24) | (b << 16) | (g << 8) | r;
}
inline u32 DecodeRGBA8888(u32 src)
{
inline u32 DecodeRGBA8888(u32 src) {
#if 1
return src;
#else
@ -127,8 +118,7 @@ inline u32 DecodeRGBA8888(u32 src)
#endif
}
inline u16 RGBA8888To565(u32 value)
{
inline u16 RGBA8888To565(u32 value) {
u8 r = value & 0xFF;
u8 g = (value >> 8) & 0xFF;
u8 b = (value >> 16) & 0xFF;
@ -138,8 +128,7 @@ inline u16 RGBA8888To565(u32 value)
return (u16)r | ((u16)g << 5) | ((u16)b << 11);
}
inline u16 RGBA8888To5551(u32 value)
{
inline u16 RGBA8888To5551(u32 value) {
u8 r = value & 0xFF;
u8 g = (value >> 8) & 0xFF;
u8 b = (value >> 16) & 0xFF;
@ -151,8 +140,7 @@ inline u16 RGBA8888To5551(u32 value)
return (u16)r | ((u16)g << 5) | ((u16)b << 10) | ((u16)a << 15);
}
inline u16 RGBA8888To4444(u32 value)
{
inline u16 RGBA8888To4444(u32 value) {
const u32 c = value >> 4;
const u16 r = (c >> 0) & 0x000F;
const u16 g = (c >> 4) & 0x00F0;
@ -170,5 +158,11 @@ void convert565_dx9(u16* data, u32* out, int width, int l, int u);
void convert5551_dx9(u16* data, u32* out, int width, int l, int u);
void ConvertBGRA8888ToRGBA8888(u32 *dst, const u32 *src, const u32 numPixels);
void ConvertRGBA8888ToRGBA5551(u16 *dst, const u32 *src, const u32 numPixels);
void ConvertRGBA8888ToRGB565(u16 *dst, const u32 *src, const u32 numPixels);
void ConvertRGBA8888ToRGBA4444(u16 *dst, const u32 *src, const u32 numPixels);
void ConvertBGRA8888ToRGBA5551(u16 *dst, const u32 *src, const u32 numPixels);
void ConvertBGRA8888ToRGB565(u16 *dst, const u32 *src, const u32 numPixels);
void ConvertBGRA8888ToRGBA4444(u16 *dst, const u32 *src, const u32 numPixels);

View file

@ -195,8 +195,7 @@ namespace DX9 {
{
const u16_le *src = (const u16_le *)srcPixels + srcStride * y;
u8 *dst = (u8 *)(convBuf + rect.Pitch * y);
for (int x = 0; x < width; x++)
{
for (int x = 0; x < width; x++) {
u16_le col = src[x];
dst[x * 4 + 0] = (col >> 12) << 4;
dst[x * 4 + 1] = ((col >> 8) & 0xf) << 4;
@ -210,10 +209,7 @@ namespace DX9 {
{
const u32_le *src = (const u32_le *)srcPixels + srcStride * y;
u32 *dst = (u32 *)(convBuf + rect.Pitch * y);
for (int x = 0; x < width; x++)
{
dst[x] = RGBA2BGRA(src[x]);
}
ConvertBGRA8888ToRGBA8888(dst, src, width);
}
break;
}
@ -222,10 +218,7 @@ namespace DX9 {
for (int y = 0; y < height; y++) {
const u32_le *src = (const u32_le *)srcPixels + srcStride * y;
u32 *dst = (u32 *)(convBuf + rect.Pitch * y);
for (int x = 0; x < width; x++)
{
dst[x] = RGBA2BGRA(src[x]);
}
ConvertBGRA8888ToRGBA8888(dst, src, width);
}
}
@ -992,9 +985,7 @@ namespace DX9 {
switch (format) {
case GE_FORMAT_565: // BGR 565
for (u32 y = 0; y < height; ++y) {
for (u32 x = 0; x < width; ++x) {
dst16[x] = BGRA8888toRGB565(src32[x]);
}
ConvertBGRA8888ToRGB565(dst16, src32, width);
src32 += srcStride;
dst16 += dstStride;
}
@ -1008,9 +999,7 @@ namespace DX9 {
break;
case GE_FORMAT_4444: // ABGR 4444
for (u32 y = 0; y < height; ++y) {
for (u32 x = 0; x < width; ++x) {
dst16[x] = BGRA8888toRGBA4444(src32[x]);
}
ConvertBGRA8888ToRGBA4444(dst16, src32, width);
src32 += srcStride;
dst16 += dstStride;
}

View file

@ -1458,17 +1458,13 @@ void ConvertFromRGBA8888(u8 *dst, const u8 *src, u32 dstStride, u32 srcStride, u
case GE_FORMAT_565: // BGR 565
if (UseBGRA8888()) {
for (u32 y = 0; y < height; ++y) {
for (u32 x = 0; x < width; ++x) {
dst16[x] = BGRA8888toRGB565(src32[x]);
}
ConvertBGRA8888ToRGB565(dst16, src32, width);
src32 += srcStride;
dst16 += dstStride;
}
} else {
for (u32 y = 0; y < height; ++y) {
for (u32 x = 0; x < width; ++x) {
dst16[x] = RGBA8888toRGB565(src32[x]);
}
ConvertRGBA8888ToRGB565(dst16, src32, width);
src32 += srcStride;
dst16 += dstStride;
}
@ -1492,17 +1488,13 @@ void ConvertFromRGBA8888(u8 *dst, const u8 *src, u32 dstStride, u32 srcStride, u
case GE_FORMAT_4444: // ABGR 4444
if (UseBGRA8888()) {
for (u32 y = 0; y < height; ++y) {
for (u32 x = 0; x < width; ++x) {
dst16[x] = BGRA8888toRGBA4444(src32[x]);
}
ConvertBGRA8888ToRGBA4444(dst16, src32, width);
src32 += srcStride;
dst16 += dstStride;
}
} else {
for (u32 y = 0; y < height; ++y) {
for (u32 x = 0; x < width; ++x) {
dst16[x] = RGBA8888toRGBA4444(src32[x]);
}
ConvertRGBA8888ToRGBA4444(dst16, src32, width);
src32 += srcStride;
dst16 += dstStride;
}