- Implementing RGB666-to-Palette colormatching for textures.

This commit is contained in:
Rachael Alexanderson 2016-12-19 07:18:20 -05:00 committed by Christoph Oelckers
parent f6b0f2648c
commit 5d85990d5f
8 changed files with 30 additions and 15 deletions

View file

@ -551,7 +551,7 @@ void FDDSTexture::ReadRGB (FWadLump &lump, BYTE *tcbuf)
DWORD r = (c & RMask) << RShiftL; r |= r >> RShiftR;
DWORD g = (c & GMask) << GShiftL; g |= g >> GShiftR;
DWORD b = (c & BMask) << BShiftL; b |= b >> BShiftR;
*pixelp = RGB32k.RGB[r >> 27][g >> 27][b >> 27];
*pixelp = RGB256k.RGB[r >> 26][g >> 26][b >> 26];
}
else
{
@ -637,7 +637,7 @@ void FDDSTexture::DecompressDXT1 (FWadLump &lump, BYTE *tcbuf)
// Pick colors from the palette for each of the four colors.
/*if (!tcbuf)*/ for (i = 3; i >= 0; --i)
{
palcol[i] = color[i].a ? RGB32k.RGB[color[i].r >> 3][color[i].g >> 3][color[i].b >> 3] : 0;
palcol[i] = color[i].a ? RGB256k.RGB[color[i].r >> 2][color[i].g >> 2][color[i].b >> 2] : 0;
}
// Now decode this 4x4 block to the pixel buffer.
for (y = 0; y < 4; ++y)
@ -717,7 +717,7 @@ void FDDSTexture::DecompressDXT3 (FWadLump &lump, bool premultiplied, BYTE *tcbu
// Pick colors from the palette for each of the four colors.
if (!tcbuf) for (i = 3; i >= 0; --i)
{
palcol[i] = RGB32k.RGB[color[i].r >> 3][color[i].g >> 3][color[i].b >> 3];
palcol[i] = RGB256k.RGB[color[i].r >> 2][color[i].g >> 2][color[i].b >> 2];
}
// Now decode this 4x4 block to the pixel buffer.
for (y = 0; y < 4; ++y)
@ -822,7 +822,7 @@ void FDDSTexture::DecompressDXT5 (FWadLump &lump, bool premultiplied, BYTE *tcbu
// Pick colors from the palette for each of the four colors.
if (!tcbuf) for (i = 3; i >= 0; --i)
{
palcol[i] = RGB32k.RGB[color[i].r >> 3][color[i].g >> 3][color[i].b >> 3];
palcol[i] = RGB256k.RGB[color[i].r >> 2][color[i].g >> 2][color[i].b >> 2];
}
// Now decode this 4x4 block to the pixel buffer.
for (y = 0; y < 4; ++y)

View file

@ -406,7 +406,7 @@ void FJPEGTexture::MakeTexture ()
case JCS_RGB:
for (int x = Width; x > 0; --x)
{
*out = RGB32k.RGB[in[0]>>3][in[1]>>3][in[2]>>3];
*out = RGB256k.RGB[in[0]>>2][in[1]>>2][in[2]>>2];
out += Height;
in += 3;
}
@ -430,7 +430,7 @@ void FJPEGTexture::MakeTexture ()
int r = in[3] - (((256-in[0])*in[3]) >> 8);
int g = in[3] - (((256-in[1])*in[3]) >> 8);
int b = in[3] - (((256-in[2])*in[3]) >> 8);
*out = RGB32k.RGB[r >> 3][g >> 3][b >> 3];
*out = RGB256k.RGB[r >> 2][g >> 2][b >> 2];
out += Height;
in += 4;
}

View file

@ -531,7 +531,7 @@ void FMultiPatchTexture::MakeTexture ()
{
if (*out == 0 && in[3] != 0)
{
*out = RGB32k.RGB[in[2]>>3][in[1]>>3][in[0]>>3];
*out = RGB256k.RGB[in[2]>>2][in[1]>>2][in[0]>>2];
}
out += Height;
in += 4;

View file

@ -528,7 +528,7 @@ void FPCXTexture::MakeTexture()
{
for(int x=0; x < Width; x++)
{
Pixels[y+Height*x] = RGB32k.RGB[row[0]>>3][row[1]>>3][row[2]>>3];
Pixels[y+Height*x] = RGB256k.RGB[row[0]>>2][row[1]>>2][row[2]>>2];
row+=3;
}
}

View file

@ -536,7 +536,7 @@ void FPNGTexture::MakeTexture ()
{
if (!HaveTrans)
{
*out++ = RGB32k.RGB[in[0]>>3][in[1]>>3][in[2]>>3];
*out++ = RGB256k.RGB[in[0]>>2][in[1]>>2][in[2]>>2];
}
else
{
@ -548,7 +548,7 @@ void FPNGTexture::MakeTexture ()
}
else
{
*out++ = RGB32k.RGB[in[0]>>3][in[1]>>3][in[2]>>3];
*out++ = RGB256k.RGB[in[0]>>2][in[1]>>2][in[2]>>2];
}
}
in += pitch;
@ -593,7 +593,7 @@ void FPNGTexture::MakeTexture ()
{
for (y = Height; y > 0; --y)
{
*out++ = in[3] < 128 ? 0 : RGB32k.RGB[in[0]>>3][in[1]>>3][in[2]>>3];
*out++ = in[3] < 128 ? 0 : RGB256k.RGB[in[0]>>2][in[1]>>2][in[2]>>2];
in += pitch;
}
in -= backstep;

View file

@ -393,7 +393,7 @@ void FTGATexture::MakeTexture ()
for(int x=0;x<Width;x++)
{
int v = LittleLong(*p);
Pixels[x*Height+y] = RGB32k.RGB[(v>>10) & 0x1f][(v>>5) & 0x1f][v & 0x1f];
Pixels[x*Height+y] = RGB256k.RGB[((v>>10) & 0x1f)*2][((v>>5) & 0x1f)*2][(v & 0x1f)*2];
p+=step_x;
}
}
@ -405,7 +405,7 @@ void FTGATexture::MakeTexture ()
BYTE * p = ptr + y * Pitch;
for(int x=0;x<Width;x++)
{
Pixels[x*Height+y] = RGB32k.RGB[p[2]>>3][p[1]>>3][p[0]>>3];
Pixels[x*Height+y] = RGB256k.RGB[p[2]>>2][p[1]>>2][p[0]>>2];
p+=step_x;
}
}
@ -419,7 +419,7 @@ void FTGATexture::MakeTexture ()
BYTE * p = ptr + y * Pitch;
for(int x=0;x<Width;x++)
{
Pixels[x*Height+y] = RGB32k.RGB[p[2]>>3][p[1]>>3][p[0]>>3];
Pixels[x*Height+y] = RGB256k.RGB[p[2]>>2][p[1]>>2][p[0]>>2];
p+=step_x;
}
}
@ -431,7 +431,7 @@ void FTGATexture::MakeTexture ()
BYTE * p = ptr + y * Pitch;
for(int x=0;x<Width;x++)
{
Pixels[x*Height+y] = p[3] >= 128? RGB32k.RGB[p[2]>>3][p[1]>>3][p[0]>>3] : 0;
Pixels[x*Height+y] = p[3] >= 128? RGB256k.RGB[p[2]>>2][p[1]>>2][p[0]>>2] : 0;
p+=step_x;
}
}

View file

@ -144,8 +144,10 @@ DWORD Col2RGB8[65][256];
DWORD *Col2RGB8_LessPrecision[65];
DWORD Col2RGB8_Inverse[65][256];
ColorTable32k RGB32k;
ColorTable256k RGB256k;
}
static DWORD Col2RGB8_2[63][256];
// [RH] The framebuffer is no longer a mere byte array.
@ -669,6 +671,11 @@ static void BuildTransTable (const PalEntry *palette)
for (g = 0; g < 32; g++)
for (b = 0; b < 32; b++)
RGB32k.RGB[r][g][b] = ColorMatcher.Pick ((r<<3)|(r>>2), (g<<3)|(g>>2), (b<<3)|(b>>2));
// create the RGB666 lookup table
for (r = 0; r < 64; r++)
for (g = 0; g < 64; g++)
for (b = 0; b < 64; b++)
RGB256k.RGB[r][g][b] = ColorMatcher.Pick ((r<<2)|(r>>4), (g<<2)|(g>>4), (b<<2)|(b>>4));
int x, y;

View file

@ -462,6 +462,14 @@ union ColorTable32k
};
extern "C" ColorTable32k RGB32k;
// [SP] RGB666 support
union ColorTable256k
{
BYTE RGB[64][64][64];
BYTE All[64 *64 *64];
};
extern "C" ColorTable256k RGB256k;
// Col2RGB8 is a pre-multiplied palette for color lookup. It is stored in a
// special R10B10G10 format for efficient blending computation.
// --RRRRRrrr--BBBBBbbb--GGGGGggg-- at level 64