Add 2bpp PVRTC compression format

This commit is contained in:
Pavel Krajcevski 2014-03-12 14:01:31 -04:00
parent 0a4726bfe2
commit 7ee0df9a5a
10 changed files with 50 additions and 57 deletions

View File

@ -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;

View File

@ -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) {

View File

@ -123,37 +123,23 @@ bool CompressedImage::DecompressImage(unsigned char *outBuf, unsigned int outBuf
uint8 *byteData = reinterpret_cast<uint8 *>(m_CompressedData);
DecompressionJob dj (m_Format, byteData, outBuf, GetWidth(), GetHeight());
switch(m_Format) {
case FasTC::eCompressionFormat_DXT1:
if(m_Format == FasTC::eCompressionFormat_DXT1) {
DXTC::DecompressDXT1(dj);
break;
case FasTC::eCompressionFormat_ETC1:
} else if(m_Format == FasTC::eCompressionFormat_ETC1) {
ETCC::Decompress(dj);
break;
case FasTC::eCompressionFormat_PVRTC:
{
} 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);
#endif
}
break;
case FasTC::eCompressionFormat_BPTC:
{
} else if(m_Format == FasTC::eCompressionFormat_BPTC) {
BPTCC::Decompress(dj);
}
break;
default:
{
} else {
const char *errStr = "Have not implemented decompression method.";
fprintf(stderr, "%s\n", errStr);
assert(!errStr);
}
return false;
}

View File

@ -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.");

View File

@ -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...

View File

@ -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

View File

@ -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);

View File

@ -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();

View File

@ -81,12 +81,17 @@ class ImageTester {
uint32 *outPixels = new uint32[w * h];
FasTC::DecompressionJob dcj(FasTC::eCompressionFormat_PVRTC,
data, reinterpret_cast<uint8 *>(outPixels), w, h);
FasTC::ECompressionFormat fmt = FasTC::eCompressionFormat_PVRTC4;
if(twobpp) {
fmt = FasTC::eCompressionFormat_PVRTC2;
}
uint8 *outBuf = reinterpret_cast<uint8 *>(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,

View File

@ -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;