mirror of
https://github.com/yuzu-emu/FasTC.git
synced 2025-01-24 01:31:05 +00:00
Two enhancements:
1. Make sure to use the same lerping code for both modulation modes when decompressing. 2. Accept a flag during decompression that outputs the debug images that were computed during decompression.
This commit is contained in:
parent
7403e77d4d
commit
db914018f1
|
@ -68,7 +68,9 @@ namespace PVRTCC {
|
||||||
// Takes a stream of compressed PVRTC data and decompresses it into R8G8B8A8
|
// Takes a stream of compressed PVRTC data and decompresses it into R8G8B8A8
|
||||||
// format. The width and height must be specified in order to properly
|
// format. The width and height must be specified in order to properly
|
||||||
// decompress the data.
|
// decompress the data.
|
||||||
void Decompress(const DecompressionJob &, const EWrapMode wrapMode = eWrapMode_Clamp);
|
void Decompress(const DecompressionJob &,
|
||||||
|
const EWrapMode wrapMode = eWrapMode_Clamp,
|
||||||
|
bool bDebugImages = false);
|
||||||
|
|
||||||
} // namespace PVRTCC
|
} // namespace PVRTCC
|
||||||
|
|
||||||
|
|
|
@ -84,7 +84,9 @@ namespace PVRTCC {
|
||||||
return x | (y << 1);
|
return x | (y << 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Decompress(const DecompressionJob &dcj, const EWrapMode wrapMode) {
|
void Decompress(const DecompressionJob &dcj,
|
||||||
|
const EWrapMode wrapMode,
|
||||||
|
bool bDebugImages) {
|
||||||
const uint32 w = dcj.width;
|
const uint32 w = dcj.width;
|
||||||
const uint32 h = dcj.height;
|
const uint32 h = dcj.height;
|
||||||
|
|
||||||
|
@ -134,19 +136,27 @@ namespace PVRTCC {
|
||||||
// bit depth.
|
// bit depth.
|
||||||
const uint8 scaleDepths[4] = { 4, 5, 5, 5 };
|
const uint8 scaleDepths[4] = { 4, 5, 5, 5 };
|
||||||
imgA.ChangeBitDepth(scaleDepths);
|
imgA.ChangeBitDepth(scaleDepths);
|
||||||
|
if(bDebugImages)
|
||||||
|
imgA.DebugOutput("UnscaledImgA");
|
||||||
imgB.ChangeBitDepth(scaleDepths);
|
imgB.ChangeBitDepth(scaleDepths);
|
||||||
|
if(bDebugImages)
|
||||||
|
imgB.DebugOutput("UnscaledImgB");
|
||||||
|
|
||||||
// Bilinearly upscale the images.
|
// Bilinearly upscale the images.
|
||||||
imgA.BilinearUpscale(2, wrapMode);
|
imgA.BilinearUpscale(2, wrapMode);
|
||||||
imgB.BilinearUpscale(2, wrapMode);
|
imgB.BilinearUpscale(2, wrapMode);
|
||||||
|
|
||||||
// Change the bitdepth to full resolution
|
// Change the bitdepth to full resolution
|
||||||
const uint8 fullDepths[4] = { 8, 8, 8, 8 };
|
imgA.ExpandTo8888();
|
||||||
imgA.ChangeBitDepth(fullDepths);
|
if(bDebugImages)
|
||||||
imgB.ChangeBitDepth(fullDepths);
|
imgA.DebugOutput("ScaledImgA");
|
||||||
|
imgB.ExpandTo8888();
|
||||||
|
if(bDebugImages)
|
||||||
|
imgB.DebugOutput("ScaledImgB");
|
||||||
|
|
||||||
// Pack the pixels based on their modulation into the resulting buffer
|
// Pack the pixels based on their modulation into the resulting buffer
|
||||||
// in RGBA format...
|
// in RGBA format...
|
||||||
|
Image modulation(h, w);
|
||||||
for(uint32 j = 0; j < h; j++) {
|
for(uint32 j = 0; j < h; j++) {
|
||||||
for(uint32 i = 0; i < w; i++) {
|
for(uint32 i = 0; i < w; i++) {
|
||||||
const uint32 blockIdx = (j/4) * blocksW + (i / 4);
|
const uint32 blockIdx = (j/4) * blocksW + (i / 4);
|
||||||
|
@ -157,10 +167,11 @@ namespace PVRTCC {
|
||||||
const Pixel &pb = imgB(i, j);
|
const Pixel &pb = imgB(i, j);
|
||||||
|
|
||||||
Pixel result;
|
Pixel result;
|
||||||
if(b.GetModeBit()) {
|
|
||||||
const uint8 lerpVals[3] = { 0, 4, 8 };
|
|
||||||
uint8 modVal = b.GetLerpValue(texelIndex);
|
|
||||||
bool punchThrough = false;
|
bool punchThrough = false;
|
||||||
|
uint8 lerpVal = 0;
|
||||||
|
if(b.GetModeBit()) {
|
||||||
|
const uint8 lerpVals[3] = { 8, 4, 0 };
|
||||||
|
uint8 modVal = b.GetLerpValue(texelIndex);
|
||||||
|
|
||||||
if(modVal == 2) {
|
if(modVal == 2) {
|
||||||
modVal = 1;
|
modVal = 1;
|
||||||
|
@ -169,35 +180,47 @@ namespace PVRTCC {
|
||||||
modVal = 2;
|
modVal = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint8 lerpVal = lerpVals[modVal];
|
lerpVal = lerpVals[modVal];
|
||||||
|
|
||||||
|
} else {
|
||||||
|
const uint8 lerpVals[4] = { 8, 5, 3, 0 };
|
||||||
|
lerpVal = lerpVals[b.GetLerpValue(texelIndex)];
|
||||||
|
}
|
||||||
|
|
||||||
for(uint32 c = 0; c < 4; c++) {
|
for(uint32 c = 0; c < 4; c++) {
|
||||||
int16 va = static_cast<int16>(pa.Component(c));
|
uint16 va = static_cast<uint16>(pa.Component(c));
|
||||||
int16 vb = static_cast<int16>(pb.Component(c));
|
uint16 vb = static_cast<uint16>(pb.Component(c));
|
||||||
|
|
||||||
result.Component(c) = va + ((vb - va) * lerpVal) / 8;
|
uint16 res = (va * (8 - lerpVal) + vb * lerpVal) / 8;
|
||||||
|
result.Component(c) = static_cast<uint8>(res);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(bDebugImages) {
|
||||||
|
Pixel iv;
|
||||||
|
const uint8 modDepth[4] = { 8, 3, 3, 3 };
|
||||||
|
iv.ChangeBitDepth(modDepth);
|
||||||
|
iv.A() = punchThrough? 0 : 0xFF;
|
||||||
|
for(int i = 1; i < 4; i++) {
|
||||||
|
if(lerpVal == 8) {
|
||||||
|
iv.Component(i) = 7;
|
||||||
|
} else {
|
||||||
|
iv.Component(i) = lerpVal;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
modulation(i, j) = iv;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(punchThrough) {
|
if(punchThrough) {
|
||||||
result.A() = 0;
|
result.A() = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
|
||||||
const uint8 lerpVals[4] = { 8, 5, 3, 0 };
|
|
||||||
const uint8 lerpVal = lerpVals[b.GetLerpValue(texelIndex)];
|
|
||||||
|
|
||||||
for(uint32 c = 0; c < 4; c++) {
|
|
||||||
int16 va = static_cast<int16>(pa.Component(c));
|
|
||||||
int16 vb = static_cast<int16>(pb.Component(c));
|
|
||||||
|
|
||||||
result.Component(c) = (va * (8 - lerpVal) + vb * lerpVal) / 8;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32 *outPixels = reinterpret_cast<uint32 *>(dcj.outBuf);
|
uint32 *outPixels = reinterpret_cast<uint32 *>(dcj.outBuf);
|
||||||
outPixels[(j * h) + i] = result.PackRGBA();
|
outPixels[(j * h) + i] = result.PackRGBA();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(bDebugImages) {
|
||||||
|
modulation.DebugOutput("DebugModulation");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace PVRTCC
|
} // namespace PVRTCC
|
||||||
|
|
Loading…
Reference in a new issue