From dd625fca7180f2bb150da9a8698bb08d44bb1ca7 Mon Sep 17 00:00:00 2001 From: Pavel Krajcevski Date: Tue, 10 Sep 2013 13:22:53 -0400 Subject: [PATCH] When going from 344(3/4) pixels to 4555, the alpha channel only has a zero appended to it. Hence we must clear that bit for each pixel that was transparent during decoding. --- PVRTCEncoder/src/Decompressor.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/PVRTCEncoder/src/Decompressor.cpp b/PVRTCEncoder/src/Decompressor.cpp index 5bed541..6f43700 100644 --- a/PVRTCEncoder/src/Decompressor.cpp +++ b/PVRTCEncoder/src/Decompressor.cpp @@ -143,6 +143,30 @@ namespace PVRTCC { if(bDebugImages) imgB.DebugOutput("UnscaledImgB"); + // Go through and change the alpha value of any pixel that came from + // a transparent block. For some reason, alpha is not treated the same + // as the other channels (to minimize hardware costs?) and the channels + // do not their MSBs replicated. + for(uint32 j = 0; j < blocksH; j++) { + for(uint32 i = 0; i < blocksW; i++) { + const uint32 blockIdx = j * blocksW + i; + Block &b = blocks[blockIdx]; + + uint8 bitDepths[4]; + b.GetColorA().GetBitDepth(bitDepths); + if(bitDepths[0] > 0) { + Pixel &p = imgA(i, j); + p.A() = p.A() & 0xFE; + } + + b.GetColorB().GetBitDepth(bitDepths); + if(bitDepths[0] > 0) { + Pixel &p = imgB(i, j); + p.A() = p.A() & 0xFE; + } + } + } + // Bilinearly upscale the images. imgA.BilinearUpscale(2, wrapMode); imgB.BilinearUpscale(2, wrapMode);