From 7ee0df9a5a384a22d02dbadbcba0a730cf1dfa24 Mon Sep 17 00:00:00 2001 From: Pavel Krajcevski Date: Wed, 12 Mar 2014 14:01:31 -0400 Subject: [PATCH] Add 2bpp PVRTC compression format --- Base/include/CompressionFormat.h | 16 ++++++++-- CLTool/src/tc.cpp | 8 ++--- Core/src/CompressedImage.cpp | 42 +++++++++----------------- Core/src/TexComp.cpp | 13 ++------ IO/src/ImageWriterKTX.cpp | 4 +-- PVRTCEncoder/include/PVRTCCompressor.h | 2 -- PVRTCEncoder/src/Compressor.cpp | 5 ++- PVRTCEncoder/src/Decompressor.cpp | 2 +- PVRTCEncoder/test/DecompTestPVR.cpp | 13 +++++--- PVRTCEncoder/test/DecompressorTest.cpp | 2 +- 10 files changed, 50 insertions(+), 57 deletions(-) diff --git a/Base/include/CompressionFormat.h b/Base/include/CompressionFormat.h index 0e43eef..ba52f24 100644 --- a/Base/include/CompressionFormat.h +++ b/Base/include/CompressionFormat.h @@ -63,7 +63,11 @@ namespace FasTC { eCompressionFormat_DXT5, eCompressionFormat_ETC1, eCompressionFormat_BPTC, - eCompressionFormat_PVRTC, + + eCompressionFormat_PVRTC2, + eCompressionFormat_PVRTC4, + COMPRESSION_FORMAT_PVRTC_BEGIN = eCompressionFormat_PVRTC2, + COMPRESSION_FORMAT_PVRTC_END = eCompressionFormat_PVRTC4, kNumCompressionFormats }; @@ -75,11 +79,16 @@ namespace FasTC { case eCompressionFormat_DXT1: case eCompressionFormat_DXT5: case eCompressionFormat_BPTC: - case eCompressionFormat_PVRTC: + case eCompressionFormat_PVRTC4: case eCompressionFormat_ETC1: outSz[0] = 4; outSz[1] = 4; break; + + case eCompressionFormat_PVRTC2: + outSz[0] = 8; + outSz[1] = 4; + break; } } @@ -88,7 +97,8 @@ namespace FasTC { switch(fmt) { default: case eCompressionFormat_DXT1: - case eCompressionFormat_PVRTC: + case eCompressionFormat_PVRTC4: + case eCompressionFormat_PVRTC2: case eCompressionFormat_ETC1: return 8; break; diff --git a/CLTool/src/tc.cpp b/CLTool/src/tc.cpp index 9c91dce..bff90f2 100644 --- a/CLTool/src/tc.cpp +++ b/CLTool/src/tc.cpp @@ -159,9 +159,9 @@ int main(int argc, char **argv) { exit(1); } else { if(!strcmp(argv[fileArg], "PVRTC")) { - format = FasTC::eCompressionFormat_PVRTC; + format = FasTC::eCompressionFormat_PVRTC4; } else if(!strcmp(argv[fileArg], "PVRTCLib")) { - format = FasTC::eCompressionFormat_PVRTC; + format = FasTC::eCompressionFormat_PVRTC4; bUsePVRTexLib = true; } else if(!strcmp(argv[fileArg], "BPTCLib")) { format = FasTC::eCompressionFormat_BPTC; @@ -347,8 +347,8 @@ int main(int argc, char **argv) { memcpy(basename, decompressedOutput, 256); } else if(format == FasTC::eCompressionFormat_BPTC) { strcat(basename, "-bptc.png"); - } else if(format == FasTC::eCompressionFormat_PVRTC) { - strcat(basename, "-pvrtc.png"); + } else if(format == FasTC::eCompressionFormat_PVRTC4) { + strcat(basename, "-pvrtc-4bpp.png"); } else if(format == FasTC::eCompressionFormat_DXT1) { strcat(basename, "-dxt1.png"); } else if(format == FasTC::eCompressionFormat_ETC1) { diff --git a/Core/src/CompressedImage.cpp b/Core/src/CompressedImage.cpp index 499d3ec..0e47720 100644 --- a/Core/src/CompressedImage.cpp +++ b/Core/src/CompressedImage.cpp @@ -123,37 +123,23 @@ bool CompressedImage::DecompressImage(unsigned char *outBuf, unsigned int outBuf uint8 *byteData = reinterpret_cast(m_CompressedData); DecompressionJob dj (m_Format, byteData, outBuf, GetWidth(), GetHeight()); - switch(m_Format) { - case FasTC::eCompressionFormat_DXT1: - DXTC::DecompressDXT1(dj); - break; - - case FasTC::eCompressionFormat_ETC1: - ETCC::Decompress(dj); - break; - - case FasTC::eCompressionFormat_PVRTC: - { + if(m_Format == FasTC::eCompressionFormat_DXT1) { + DXTC::DecompressDXT1(dj); + } else if(m_Format == FasTC::eCompressionFormat_ETC1) { + ETCC::Decompress(dj); + } else if(FasTC::COMPRESSION_FORMAT_PVRTC_BEGIN <= m_Format && + FasTC::COMPRESSION_FORMAT_PVRTC_END >= m_Format) { #ifndef NDEBUG - PVRTCC::Decompress(dj, false, PVRTCC::eWrapMode_Wrap, true); + PVRTCC::Decompress(dj, PVRTCC::eWrapMode_Wrap, true); #else - PVRTCC::Decompress(dj); + PVRTCC::Decompress(dj); #endif - } - break; - - case FasTC::eCompressionFormat_BPTC: - { - BPTCC::Decompress(dj); - } - break; - - default: - { - const char *errStr = "Have not implemented decompression method."; - fprintf(stderr, "%s\n", errStr); - assert(!errStr); - } + } else if(m_Format == FasTC::eCompressionFormat_BPTC) { + BPTCC::Decompress(dj); + } else { + const char *errStr = "Have not implemented decompression method."; + fprintf(stderr, "%s\n", errStr); + assert(!errStr); return false; } diff --git a/Core/src/TexComp.cpp b/Core/src/TexComp.cpp index 0353cfd..9cd6d5f 100644 --- a/Core/src/TexComp.cpp +++ b/Core/src/TexComp.cpp @@ -113,15 +113,6 @@ static CompressionFuncWithStats ChooseFuncFromSettingsWithStats(const SCompress } break; - case FasTC::eCompressionFormat_ETC1: - case FasTC::eCompressionFormat_DXT1: - case FasTC::eCompressionFormat_DXT5: - case FasTC::eCompressionFormat_PVRTC: - { - // !FIXME! actually implement one of these methods... - return NULL; - } - default: { assert(!"Not implemented!"); @@ -157,7 +148,7 @@ static CompressionFunc ChooseFuncFromSettings(const SCompressionSettings &s) { case FasTC::eCompressionFormat_DXT5: return DXTC::CompressImageDXT5; - case FasTC::eCompressionFormat_PVRTC: + case FasTC::eCompressionFormat_PVRTC4: { if(s.bUsePVRTexLib) { return CompressPVRTCLib; @@ -458,7 +449,7 @@ bool CompressImageData( } uint32 numThreads = settings.iNumThreads; - if(settings.format == FasTC::eCompressionFormat_PVRTC && + if(settings.format == FasTC::eCompressionFormat_PVRTC4 && (settings.iNumThreads > 1 || settings.logStream)) { if(settings.iNumThreads > 1) { ReportError("WARNING - PVRTC compressor does not support multithreading."); diff --git a/IO/src/ImageWriterKTX.cpp b/IO/src/ImageWriterKTX.cpp index e9aa7e1..7603eac 100644 --- a/IO/src/ImageWriterKTX.cpp +++ b/IO/src/ImageWriterKTX.cpp @@ -130,7 +130,7 @@ bool ImageWriterKTX::WriteImage() { wtr.Write(GL_RGBA); // glBaseFormat break; - case FasTC::eCompressionFormat_PVRTC: + case FasTC::eCompressionFormat_PVRTC4: wtr.Write(COMPRESSED_RGBA_PVRTC_4BPPV1_IMG); // glInternalFormat wtr.Write(GL_RGBA); // glBaseFormat break; @@ -163,7 +163,7 @@ bool ImageWriterKTX::WriteImage() { static const uint32 kImageSize = m_Width * m_Height; wtr.Write(kImageSize); // imageSize wtr.Write(ci->GetCompressedData(), kImageSize); // imagedata... - } else if(ci && ci->GetFormat() == FasTC::eCompressionFormat_PVRTC) { + } else if(ci && ci->GetFormat() == FasTC::eCompressionFormat_PVRTC4) { static const uint32 kImageSize = m_Width * m_Height >> 1; wtr.Write(kImageSize); // imageSize wtr.Write(ci->GetCompressedData(), kImageSize); // imagedata... diff --git a/PVRTCEncoder/include/PVRTCCompressor.h b/PVRTCEncoder/include/PVRTCCompressor.h index 43b1952..f9b627e 100644 --- a/PVRTCEncoder/include/PVRTCCompressor.h +++ b/PVRTCEncoder/include/PVRTCCompressor.h @@ -70,7 +70,6 @@ namespace PVRTCC { // format. The width and height must be specified in order to properly // decompress the data. void Decompress(const FasTC::DecompressionJob &, - bool bTwoBitMode = false, const EWrapMode wrapMode = eWrapMode_Wrap, bool bDebugImages = false); @@ -78,7 +77,6 @@ namespace PVRTCC { // version one. The width and height must be specified in order to properly // decompress the data. void Compress(const FasTC::CompressionJob &, - bool bTwoBitMode = false, const EWrapMode wrapMode = eWrapMode_Wrap); #ifdef PVRTEXLIB_FOUND diff --git a/PVRTCEncoder/src/Compressor.cpp b/PVRTCEncoder/src/Compressor.cpp index e67c4e8..a4f87e9 100644 --- a/PVRTCEncoder/src/Compressor.cpp +++ b/PVRTCEncoder/src/Compressor.cpp @@ -919,10 +919,13 @@ namespace PVRTCC { } #endif - void Compress(const FasTC::CompressionJob &cj, bool bTwoBit, EWrapMode wrapMode) { + void Compress(const FasTC::CompressionJob &cj, EWrapMode wrapMode) { const uint32 width = cj.Width(); const uint32 height = cj.Height(); + // We only support 4bpp currently + assert(cj.Format() == FasTC::eCompressionFormat_PVRTC4); + // Make sure that width and height are a power of two. assert((width & (width - 1)) == 0); assert((height & (height - 1)) == 0); diff --git a/PVRTCEncoder/src/Decompressor.cpp b/PVRTCEncoder/src/Decompressor.cpp index 50e0e37..53b32fe 100644 --- a/PVRTCEncoder/src/Decompressor.cpp +++ b/PVRTCEncoder/src/Decompressor.cpp @@ -274,9 +274,9 @@ namespace PVRTCC { } void Decompress(const FasTC::DecompressionJob &dcj, - const bool bTwoBitMode, const EWrapMode wrapMode, bool bDebugImages) { + const bool bTwoBitMode = dcj.Format() == FasTC::eCompressionFormat_PVRTC2; const uint32 w = dcj.Width(); const uint32 h = dcj.Height(); diff --git a/PVRTCEncoder/test/DecompTestPVR.cpp b/PVRTCEncoder/test/DecompTestPVR.cpp index 90d6ee2..af909d9 100644 --- a/PVRTCEncoder/test/DecompTestPVR.cpp +++ b/PVRTCEncoder/test/DecompTestPVR.cpp @@ -81,12 +81,17 @@ class ImageTester { uint32 *outPixels = new uint32[w * h]; - FasTC::DecompressionJob dcj(FasTC::eCompressionFormat_PVRTC, - data, reinterpret_cast(outPixels), w, h); + FasTC::ECompressionFormat fmt = FasTC::eCompressionFormat_PVRTC4; + if(twobpp) { + fmt = FasTC::eCompressionFormat_PVRTC2; + } + + uint8 *outBuf = reinterpret_cast(outPixels); + FasTC::DecompressionJob dcj(fmt, data, outBuf, w, h); #ifdef OUTPUT_DEBUG_IMAGE - PVRTCC::Decompress(dcj, twobpp, PVRTCC::eWrapMode_Wrap, true); + PVRTCC::Decompress(dcj, PVRTCC::eWrapMode_Wrap, true); #else - PVRTCC::Decompress(dcj, twobpp, PVRTCC::eWrapMode_Wrap); + PVRTCC::Decompress(dcj, PVRTCC::eWrapMode_Wrap); #endif bool result = pvrtexture::Transcode(pvrTex, diff --git a/PVRTCEncoder/test/DecompressorTest.cpp b/PVRTCEncoder/test/DecompressorTest.cpp index 7642a01..d1c2319 100644 --- a/PVRTCEncoder/test/DecompressorTest.cpp +++ b/PVRTCEncoder/test/DecompressorTest.cpp @@ -56,7 +56,7 @@ #include "PVRTCCompressor.h" -static const FasTC::ECompressionFormat kFmt = FasTC::eCompressionFormat_PVRTC; +static const FasTC::ECompressionFormat kFmt = FasTC::eCompressionFormat_PVRTC4; TEST(Decompressor, DecompressWhite) { const uint32 kWidth = 32;