mirror of
https://github.com/yuzu-emu/FasTC.git
synced 2024-11-28 03:44:18 +01:00
Add LUTs for areas of constant intensity.
This commit is contained in:
parent
89110be602
commit
5fb39cf5c5
@ -64,6 +64,8 @@
|
||||
#include "PVRTCImage.h"
|
||||
#include "Block.h"
|
||||
|
||||
#define USE_CONSTANT_LUTS
|
||||
|
||||
namespace PVRTCC {
|
||||
|
||||
static uint32 Interleave(uint16 inx, uint16 iny) {
|
||||
@ -89,6 +91,78 @@ namespace PVRTCC {
|
||||
return x | (y << 1);
|
||||
}
|
||||
|
||||
#ifdef USE_CONSTANT_LUTS
|
||||
static const uint8 kConstFiveBitLUT[256][2] = {
|
||||
{0, 0}, {0, 0}, {8, 0}, {8, 0}, {8, 0}, {0, 8}, {16, 0}, {8, 8},
|
||||
{8, 8}, {24, 0}, {0, 16}, {16, 8}, {32, 0}, {8, 16}, {24, 8}, {0, 24},
|
||||
{16, 16}, {32, 8}, {8, 24}, {24, 16}, {40, 8}, {16, 24}, {32, 16}, {8, 32},
|
||||
{24, 24}, {40, 16}, {16, 32}, {32, 24}, {48, 16}, {24, 32}, {40, 24}, {16, 40},
|
||||
{72, 8}, {32, 32}, {24, 40}, {0, 56}, {40, 32}, {72, 16}, {32, 40}, {48, 32},
|
||||
{80, 16}, {40, 40}, {56, 32}, {32, 48}, {48, 40}, {64, 32}, {40, 48}, {56, 40},
|
||||
{32, 56}, {48, 48}, {64, 40}, {40, 56}, {56, 48}, {72, 40}, {48, 56}, {64, 48},
|
||||
{40, 64}, {56, 56}, {72, 48}, {48, 64}, {64, 56}, {80, 48}, {56, 64}, {72, 56},
|
||||
{48, 72}, {104, 40}, {64, 64}, {56, 72}, {32, 88}, {72, 64}, {104, 48}, {64, 72},
|
||||
{80, 64}, {112, 48}, {72, 72}, {88, 64}, {64, 80}, {80, 72}, {96, 64}, {72, 80},
|
||||
{88, 72}, {64, 88}, {80, 80}, {96, 72}, {72, 88}, {88, 80}, {104, 72}, {80, 88},
|
||||
{96, 80}, {72, 96}, {88, 88}, {104, 80}, {80, 96}, {96, 88}, {112, 80}, {88, 96},
|
||||
{104, 88}, {80, 104}, {136, 72}, {96, 96}, {88, 104}, {64, 120}, {104, 96}, {136, 80},
|
||||
{96, 104}, {112, 96}, {144, 80}, {104, 104}, {120, 96}, {96, 112}, {112, 104}, {128, 96},
|
||||
{104, 112}, {120, 104}, {96, 120}, {112, 112}, {128, 104}, {104, 120}, {120, 112}, {136, 104},
|
||||
{112, 120}, {128, 112}, {104, 128}, {120, 120}, {136, 112}, {112, 128}, {128, 120}, {144, 112},
|
||||
{120, 128}, {136, 120}, {112, 136}, {168, 104}, {128, 128}, {120, 136}, {96, 152}, {136, 128},
|
||||
{168, 112}, {128, 136}, {144, 128}, {176, 112}, {136, 136}, {152, 128}, {128, 144}, {144, 136},
|
||||
{160, 128}, {136, 144}, {152, 136}, {128, 152}, {144, 144}, {160, 136}, {136, 152}, {152, 144},
|
||||
{168, 136}, {144, 152}, {160, 144}, {136, 160}, {152, 152}, {168, 144}, {144, 160}, {160, 152},
|
||||
{176, 144}, {152, 160}, {168, 152}, {144, 168}, {200, 136}, {160, 160}, {152, 168}, {128, 184},
|
||||
{168, 160}, {200, 144}, {160, 168}, {176, 160}, {208, 144}, {168, 168}, {184, 160}, {160, 176},
|
||||
{176, 168}, {192, 160}, {168, 176}, {184, 168}, {160, 184}, {176, 176}, {192, 168}, {168, 184},
|
||||
{184, 176}, {200, 168}, {176, 184}, {192, 176}, {168, 192}, {184, 184}, {200, 176}, {176, 192},
|
||||
{192, 184}, {208, 176}, {184, 192}, {200, 184}, {176, 200}, {232, 168}, {192, 192}, {184, 200},
|
||||
{160, 216}, {200, 192}, {232, 176}, {192, 200}, {208, 192}, {240, 176}, {200, 200}, {216, 192},
|
||||
{192, 208}, {208, 200}, {224, 192}, {200, 208}, {216, 200}, {192, 216}, {208, 208}, {224, 200},
|
||||
{200, 216}, {216, 208}, {232, 200}, {208, 216}, {224, 208}, {200, 224}, {216, 216}, {232, 208},
|
||||
{208, 224}, {224, 216}, {240, 208}, {216, 224}, {232, 216}, {208, 232}, {184, 248}, {224, 224},
|
||||
{216, 232}, {192, 248}, {232, 224}, {232, 224}, {224, 232}, {240, 224}, {232, 232}, {232, 232},
|
||||
{248, 224}, {224, 240}, {240, 232}, {240, 232}, {232, 240}, {248, 232}, {224, 248}, {240, 240},
|
||||
{240, 240}, {232, 248}, {248, 240}, {248, 240}, {240, 248}, {240, 248}, {248, 248}, {248, 248}
|
||||
};
|
||||
|
||||
static const uint8 kConstFourBitLUT[256][2] = {
|
||||
{0, 0}, {0, 0}, {8, 0}, {8, 0}, {8, 0}, {16, 0}, {16, 0}, {16, 0},
|
||||
{24, 0}, {24, 0}, {0, 16}, {0, 16}, {32, 0}, {8, 16}, {8, 16}, {40, 0},
|
||||
{16, 16}, {16, 16}, {48, 0}, {24, 16}, {0, 32}, {56, 0}, {32, 16}, {8, 32},
|
||||
{64, 0}, {40, 16}, {16, 32}, {72, 0}, {48, 16}, {24, 32}, {0, 48}, {56, 16},
|
||||
{32, 32}, {32, 32}, {64, 16}, {40, 32}, {40, 32}, {72, 16}, {48, 32}, {48, 32},
|
||||
{80, 16}, {0, 64}, {56, 32}, {32, 48}, {8, 64}, {64, 32}, {40, 48}, {16, 64},
|
||||
{72, 32}, {48, 48}, {24, 64}, {80, 32}, {56, 48}, {32, 64}, {88, 32}, {64, 48},
|
||||
{40, 64}, {96, 32}, {72, 48}, {48, 64}, {24, 80}, {80, 48}, {56, 64}, {32, 80},
|
||||
{88, 48}, {144, 16}, {64, 64}, {96, 48}, {152, 16}, {72, 64}, {104, 48}, {0, 112},
|
||||
{80, 64}, {112, 48}, {32, 96}, {88, 64}, {64, 80}, {40, 96}, {96, 64}, {72, 80},
|
||||
{48, 96}, {104, 64}, {80, 80}, {56, 96}, {112, 64}, {88, 80}, {64, 96}, {120, 64},
|
||||
{96, 80}, {72, 96}, {128, 64}, {104, 80}, {80, 96}, {56, 112}, {112, 80}, {88, 96},
|
||||
{64, 112}, {120, 80}, {176, 48}, {96, 96}, {128, 80}, {24, 144}, {104, 96}, {136, 80},
|
||||
{32, 144}, {112, 96}, {144, 80}, {64, 128}, {120, 96}, {96, 112}, {72, 128}, {128, 96},
|
||||
{104, 112}, {80, 128}, {136, 96}, {112, 112}, {88, 128}, {144, 96}, {120, 112}, {96, 128},
|
||||
{152, 96}, {128, 112}, {104, 128}, {160, 96}, {136, 112}, {112, 128}, {88, 144}, {144, 112},
|
||||
{120, 128}, {96, 144}, {152, 112}, {208, 80}, {128, 128}, {160, 112}, {56, 176}, {136, 128},
|
||||
{168, 112}, {64, 176}, {144, 128}, {176, 112}, {96, 160}, {152, 128}, {128, 144}, {104, 160},
|
||||
{160, 128}, {136, 144}, {112, 160}, {168, 128}, {144, 144}, {120, 160}, {176, 128}, {152, 144},
|
||||
{128, 160}, {184, 128}, {160, 144}, {136, 160}, {192, 128}, {168, 144}, {144, 160}, {120, 176},
|
||||
{176, 144}, {152, 160}, {128, 176}, {184, 144}, {240, 112}, {160, 160}, {192, 144}, {88, 208},
|
||||
{168, 160}, {200, 144}, {96, 208}, {176, 160}, {208, 144}, {128, 192}, {184, 160}, {160, 176},
|
||||
{136, 192}, {192, 160}, {168, 176}, {144, 192}, {200, 160}, {176, 176}, {152, 192}, {208, 160},
|
||||
{184, 176}, {160, 192}, {216, 160}, {192, 176}, {168, 192}, {224, 160}, {200, 176}, {176, 192},
|
||||
{152, 208}, {208, 176}, {184, 192}, {160, 208}, {216, 176}, {112, 240}, {192, 192}, {224, 176},
|
||||
{120, 240}, {200, 192}, {232, 176}, {128, 240}, {208, 192}, {240, 176}, {160, 224}, {216, 192},
|
||||
{192, 208}, {168, 224}, {224, 192}, {200, 208}, {176, 224}, {232, 192}, {208, 208}, {184, 224},
|
||||
{240, 192}, {216, 208}, {192, 224}, {248, 192}, {224, 208}, {200, 224}, {176, 240}, {232, 208},
|
||||
{208, 224}, {184, 240}, {240, 208}, {216, 224}, {192, 240}, {248, 208}, {224, 224}, {224, 224},
|
||||
{224, 224}, {232, 224}, {232, 224}, {232, 224}, {240, 224}, {240, 224}, {240, 224}, {248, 224},
|
||||
{248, 224}, {224, 240}, {224, 240}, {232, 240}, {232, 240}, {232, 240}, {240, 240}, {240, 240},
|
||||
{240, 240}, {248, 240}, {248, 240}, {248, 240}, {248, 240}, {248, 240}, {248, 240}, {248, 240}
|
||||
};
|
||||
#endif // USE_CONSTANT_LUTS
|
||||
|
||||
struct Label {
|
||||
uint8 distance;
|
||||
uint8 nLabels;
|
||||
@ -453,33 +527,59 @@ namespace PVRTCC {
|
||||
}
|
||||
}
|
||||
|
||||
// Average all of the values together now...
|
||||
FasTC::Color high, low;
|
||||
for(uint32 y = 0; y < 4; y++)
|
||||
for(uint32 x = 0; x < 4; x++) {
|
||||
uint32 idx = y * 4 + x;
|
||||
FasTC::Color c = blockColors[0][idx];
|
||||
if(c.A() < 0.0f) {
|
||||
c.Unpack(pixels[maxIntensityIdx]);
|
||||
}
|
||||
high += c * (1.0f / 16.0f);
|
||||
|
||||
c = blockColors[1][idx];
|
||||
if(c.A() < 0.0f) {
|
||||
c.Unpack(pixels[minIntensityIdx]);
|
||||
}
|
||||
low += c * (1.0f / 16.0f);
|
||||
}
|
||||
|
||||
// Store them as our endpoints for this block...
|
||||
Block b;
|
||||
FasTC::Pixel p;
|
||||
p.Unpack(high.Pack());
|
||||
b.SetColorA(p);
|
||||
#ifdef USE_CONSTANT_LUTS
|
||||
if(minIntensity == maxIntensity) {
|
||||
// Assume all same color
|
||||
FasTC::Pixel color(pixels[minIntensityIdx]);
|
||||
if(color.A() < 0xFF) {
|
||||
assert(!"Implement me!");
|
||||
} else {
|
||||
FasTC::Pixel high, low;
|
||||
high.A() = low.A() = 0xFF;
|
||||
|
||||
p.Unpack(low.Pack());
|
||||
b.SetColorB(p);
|
||||
high.R() = kConstFiveBitLUT[color.R()][0];
|
||||
low.R() = kConstFiveBitLUT[color.R()][1];
|
||||
|
||||
high.G() = kConstFiveBitLUT[color.G()][0];
|
||||
low.G() = kConstFiveBitLUT[color.G()][1];
|
||||
|
||||
high.B() = kConstFourBitLUT[color.B()][0];
|
||||
low.B() = kConstFourBitLUT[color.B()][1];
|
||||
|
||||
b.SetColorA(high);
|
||||
b.SetColorB(low);
|
||||
}
|
||||
} else {
|
||||
#endif
|
||||
// Average all of the values together now...
|
||||
FasTC::Color high, low;
|
||||
for(uint32 y = 0; y < 4; y++)
|
||||
for(uint32 x = 0; x < 4; x++) {
|
||||
uint32 idx = y * 4 + x;
|
||||
FasTC::Color c = blockColors[0][idx];
|
||||
if(c.A() < 0.0f) {
|
||||
c.Unpack(pixels[maxIntensityIdx]);
|
||||
}
|
||||
high += c * (1.0f / 16.0f);
|
||||
|
||||
c = blockColors[1][idx];
|
||||
if(c.A() < 0.0f) {
|
||||
c.Unpack(pixels[minIntensityIdx]);
|
||||
}
|
||||
low += c * (1.0f / 16.0f);
|
||||
}
|
||||
|
||||
// Store them as our endpoints for this block...
|
||||
FasTC::Pixel p;
|
||||
p.Unpack(high.Pack());
|
||||
b.SetColorA(p);
|
||||
|
||||
p.Unpack(low.Pack());
|
||||
b.SetColorB(p);
|
||||
#ifdef USE_CONSTANT_LUTS
|
||||
}
|
||||
#endif
|
||||
uint64 *outBlocks = reinterpret_cast<uint64 *>(outBuf);
|
||||
outBlocks[GetBlockIndex(i, j)] = b.Pack();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user