VideoCommon: Use avg(color1, color2) for color3 in CMPR textures
This commit is contained in:
parent
989cdc0929
commit
344f2e57f6
|
@ -654,6 +654,11 @@ void TexDecoder_DecodeTexel(u8* dst, const u8* src, int s, int t, int imageWidth
|
||||||
int red1 = Convert5To8((c1 >> 11) & 0x1F);
|
int red1 = Convert5To8((c1 >> 11) & 0x1F);
|
||||||
int red2 = Convert5To8((c2 >> 11) & 0x1F);
|
int red2 = Convert5To8((c2 >> 11) & 0x1F);
|
||||||
|
|
||||||
|
// Approximation of x/3: 3/8 (1/2 - 1/8)
|
||||||
|
int blue3 = ((blue2 - blue1) >> 1) - ((blue2 - blue1) >> 3);
|
||||||
|
int green3 = ((green2 - green1) >> 1) - ((green2 - green1) >> 3);
|
||||||
|
int red3 = ((red2 - red1) >> 1) - ((red2 - red1) >> 3);
|
||||||
|
|
||||||
u16 ss = s & 3;
|
u16 ss = s & 3;
|
||||||
u16 tt = t & 3;
|
u16 tt = t & 3;
|
||||||
|
|
||||||
|
@ -675,19 +680,20 @@ void TexDecoder_DecodeTexel(u8* dst, const u8* src, int s, int t, int imageWidth
|
||||||
color = MakeRGBA(red2, green2, blue2, 255);
|
color = MakeRGBA(red2, green2, blue2, 255);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
color = MakeRGBA(red1 + (red2 - red1) / 3, green1 + (green2 - green1) / 3,
|
color = MakeRGBA(red1 + red3, green1 + green3, blue1 + blue3, 255);
|
||||||
blue1 + (blue2 - blue1) / 3, 255);
|
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
color = MakeRGBA(red2 + (red1 - red2) / 3, green2 + (green1 - green2) / 3,
|
color = MakeRGBA(red2 - red3, green2 - green3, blue2 - blue3, 255);
|
||||||
blue2 + (blue1 - blue2) / 3, 255);
|
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
color = MakeRGBA((int)ceil((float)(red1 + red2) / 2), (int)ceil((float)(green1 + green2) / 2),
|
color =
|
||||||
(int)ceil((float)(blue1 + blue2) / 2), 255);
|
MakeRGBA((red1 + red2 + 1) / 2, (green1 + green2 + 1) / 2, (blue1 + blue2 + 1) / 2, 255);
|
||||||
break;
|
break;
|
||||||
case 7:
|
case 7:
|
||||||
color = MakeRGBA(red2, green2, blue2, 0);
|
// color[3] is the same as color[2] (average of both colors), but transparent.
|
||||||
|
// This differs from DXT1 where color[3] is transparent black.
|
||||||
|
color =
|
||||||
|
MakeRGBA((red1 + red2 + 1) / 2, (green1 + green2 + 1) / 2, (blue1 + blue2 + 1) / 2, 0);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
color = 0;
|
color = 0;
|
||||||
|
|
|
@ -169,6 +169,7 @@ static void DecodeDXTBlock(u32* dst, const DXTBlock* src, int pitch)
|
||||||
colors[1] = MakeRGBA(red2, green2, blue2, 255);
|
colors[1] = MakeRGBA(red2, green2, blue2, 255);
|
||||||
if (c1 > c2)
|
if (c1 > c2)
|
||||||
{
|
{
|
||||||
|
// Approximation of x/3: 3/8 (1/2 - 1/8)
|
||||||
int blue3 = ((blue2 - blue1) >> 1) - ((blue2 - blue1) >> 3);
|
int blue3 = ((blue2 - blue1) >> 1) - ((blue2 - blue1) >> 3);
|
||||||
int green3 = ((green2 - green1) >> 1) - ((green2 - green1) >> 3);
|
int green3 = ((green2 - green1) >> 1) - ((green2 - green1) >> 3);
|
||||||
int red3 = ((red2 - red1) >> 1) - ((red2 - red1) >> 3);
|
int red3 = ((red2 - red1) >> 1) - ((red2 - red1) >> 3);
|
||||||
|
@ -177,9 +178,12 @@ static void DecodeDXTBlock(u32* dst, const DXTBlock* src, int pitch)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
colors[2] = MakeRGBA((red1 + red2 + 1) / 2, // Average
|
// color[3] is the same as color[2] (average of both colors), but transparent.
|
||||||
(green1 + green2 + 1) / 2, (blue1 + blue2 + 1) / 2, 255);
|
// This differs from DXT1 where color[3] is transparent black.
|
||||||
colors[3] = MakeRGBA(red2, green2, blue2, 0); // Color2 but transparent
|
colors[2] =
|
||||||
|
MakeRGBA((red1 + red2 + 1) / 2, (green1 + green2 + 1) / 2, (blue1 + blue2 + 1) / 2, 255);
|
||||||
|
colors[3] =
|
||||||
|
MakeRGBA((red1 + red2 + 1) / 2, (green1 + green2 + 1) / 2, (blue1 + blue2 + 1) / 2, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int y = 0; y < 4; y++)
|
for (int y = 0; y < 4; y++)
|
||||||
|
|
|
@ -167,7 +167,7 @@ static inline void DecodeBytes_IA4(u32* dst, const u8* src)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CHECK
|
#ifdef CHECK
|
||||||
static inline u32 makeRGBA(int r, int g, int b, int a)
|
static inline u32 MakeRGBA(int r, int g, int b, int a)
|
||||||
{
|
{
|
||||||
return (a << 24) | (b << 16) | (g << 8) | r;
|
return (a << 24) | (b << 16) | (g << 8) | r;
|
||||||
}
|
}
|
||||||
|
@ -189,6 +189,7 @@ static void DecodeDXTBlock(u32* dst, const DXTBlock* src, int pitch)
|
||||||
colors[1] = MakeRGBA(red2, green2, blue2, 255);
|
colors[1] = MakeRGBA(red2, green2, blue2, 255);
|
||||||
if (c1 > c2)
|
if (c1 > c2)
|
||||||
{
|
{
|
||||||
|
// Approximation of x/3: 3/8 (1/2 - 1/8)
|
||||||
int blue3 = ((blue2 - blue1) >> 1) - ((blue2 - blue1) >> 3);
|
int blue3 = ((blue2 - blue1) >> 1) - ((blue2 - blue1) >> 3);
|
||||||
int green3 = ((green2 - green1) >> 1) - ((green2 - green1) >> 3);
|
int green3 = ((green2 - green1) >> 1) - ((green2 - green1) >> 3);
|
||||||
int red3 = ((red2 - red1) >> 1) - ((red2 - red1) >> 3);
|
int red3 = ((red2 - red1) >> 1) - ((red2 - red1) >> 3);
|
||||||
|
@ -197,9 +198,12 @@ static void DecodeDXTBlock(u32* dst, const DXTBlock* src, int pitch)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
colors[2] = MakeRGBA((red1 + red2 + 1) / 2, // Average
|
// color[3] is the same as color[2] (average of both colors), but transparent.
|
||||||
(green1 + green2 + 1) / 2, (blue1 + blue2 + 1) / 2, 255);
|
// This differs from DXT1 where color[3] is transparent black.
|
||||||
colors[3] = MakeRGBA(red2, green2, blue2, 0); // Color2 but transparent
|
colors[2] =
|
||||||
|
MakeRGBA((red1 + red2 + 1) / 2, (green1 + green2 + 1) / 2, (blue1 + blue2 + 1) / 2, 255);
|
||||||
|
colors[3] =
|
||||||
|
MakeRGBA((red1 + red2 + 1) / 2, (green1 + green2 + 1) / 2, (blue1 + blue2 + 1) / 2, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int y = 0; y < 4; y++)
|
for (int y = 0; y < 4; y++)
|
||||||
|
@ -1225,9 +1229,7 @@ void _TexDecoder_DecodeImpl(u32* dst, const u8* src, int width, int height, int
|
||||||
const __m128i rrggbb21 = _mm_avg_epu16(rrggbb0, rrggbb1);
|
const __m128i rrggbb21 = _mm_avg_epu16(rrggbb0, rrggbb1);
|
||||||
const __m128i rgb210 = _mm_srli_si128(_mm_packus_epi16(rrggbb21, rrggbb21), 8);
|
const __m128i rgb210 = _mm_srli_si128(_mm_packus_epi16(rrggbb21, rrggbb21), 8);
|
||||||
rgb2 = rgb210;
|
rgb2 = rgb210;
|
||||||
rgb3 = _mm_and_si128(
|
rgb3 = _mm_and_si128(rgb210, _mm_srli_epi32(allFFs128, 8));
|
||||||
_mm_srli_si128(_mm_shuffle_epi32(argb888x4, _MM_SHUFFLE(1, 1, 1, 1)), 8),
|
|
||||||
_mm_srli_epi32(allFFs128, 8));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (rgb0 > rgb1):
|
// if (rgb0 > rgb1):
|
||||||
|
@ -1262,7 +1264,7 @@ void _TexDecoder_DecodeImpl(u32* dst, const u8* src, int width, int height, int
|
||||||
// 0x00FFFFFF)
|
// 0x00FFFFFF)
|
||||||
// Make this color fully transparent:
|
// Make this color fully transparent:
|
||||||
rgb3 = _mm_or_si128(rgb3,
|
rgb3 = _mm_or_si128(rgb3,
|
||||||
_mm_and_si128(_mm_and_si128(rgb1, _mm_srli_epi32(allFFs128, 8)),
|
_mm_and_si128(_mm_and_si128(rgb2, _mm_srli_epi32(allFFs128, 8)),
|
||||||
_mm_slli_si128(allFFs128, 8)));
|
_mm_slli_si128(allFFs128, 8)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1284,8 +1286,12 @@ void _TexDecoder_DecodeImpl(u32* dst, const u8* src, int width, int height, int
|
||||||
// REFERENCE:
|
// REFERENCE:
|
||||||
u32 tmp0[4][4], tmp1[4][4];
|
u32 tmp0[4][4], tmp1[4][4];
|
||||||
|
|
||||||
DecodeDXTBlock(&(tmp0[0][0]), (const DXTBlock*)src, 4);
|
DecodeDXTBlock(&(tmp0[0][0]),
|
||||||
DecodeDXTBlock(&(tmp1[0][0]), (const DXTBlock*)(src + 8), 4);
|
reinterpret_cast<const DXTBlock*>(src + sizeof(DXTBlock) * 2 * xStep),
|
||||||
|
4);
|
||||||
|
DecodeDXTBlock(
|
||||||
|
&(tmp1[0][0]),
|
||||||
|
reinterpret_cast<const DXTBlock*>((src + sizeof(DXTBlock) * 2 * xStep) + 8), 4);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
u32* dst32 = (dst + (y + z * 4) * width + x);
|
u32* dst32 = (dst + (y + z * 4) * width + x);
|
||||||
|
|
Loading…
Reference in New Issue