mirror of
https://github.com/yuzu-emu/FasTC.git
synced 2024-11-27 21:34:20 +01:00
Add 2bpp PVRTC compression format
This commit is contained in:
parent
0a4726bfe2
commit
7ee0df9a5a
@ -63,7 +63,11 @@ namespace FasTC {
|
|||||||
eCompressionFormat_DXT5,
|
eCompressionFormat_DXT5,
|
||||||
eCompressionFormat_ETC1,
|
eCompressionFormat_ETC1,
|
||||||
eCompressionFormat_BPTC,
|
eCompressionFormat_BPTC,
|
||||||
eCompressionFormat_PVRTC,
|
|
||||||
|
eCompressionFormat_PVRTC2,
|
||||||
|
eCompressionFormat_PVRTC4,
|
||||||
|
COMPRESSION_FORMAT_PVRTC_BEGIN = eCompressionFormat_PVRTC2,
|
||||||
|
COMPRESSION_FORMAT_PVRTC_END = eCompressionFormat_PVRTC4,
|
||||||
|
|
||||||
kNumCompressionFormats
|
kNumCompressionFormats
|
||||||
};
|
};
|
||||||
@ -75,11 +79,16 @@ namespace FasTC {
|
|||||||
case eCompressionFormat_DXT1:
|
case eCompressionFormat_DXT1:
|
||||||
case eCompressionFormat_DXT5:
|
case eCompressionFormat_DXT5:
|
||||||
case eCompressionFormat_BPTC:
|
case eCompressionFormat_BPTC:
|
||||||
case eCompressionFormat_PVRTC:
|
case eCompressionFormat_PVRTC4:
|
||||||
case eCompressionFormat_ETC1:
|
case eCompressionFormat_ETC1:
|
||||||
outSz[0] = 4;
|
outSz[0] = 4;
|
||||||
outSz[1] = 4;
|
outSz[1] = 4;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case eCompressionFormat_PVRTC2:
|
||||||
|
outSz[0] = 8;
|
||||||
|
outSz[1] = 4;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,7 +97,8 @@ namespace FasTC {
|
|||||||
switch(fmt) {
|
switch(fmt) {
|
||||||
default:
|
default:
|
||||||
case eCompressionFormat_DXT1:
|
case eCompressionFormat_DXT1:
|
||||||
case eCompressionFormat_PVRTC:
|
case eCompressionFormat_PVRTC4:
|
||||||
|
case eCompressionFormat_PVRTC2:
|
||||||
case eCompressionFormat_ETC1:
|
case eCompressionFormat_ETC1:
|
||||||
return 8;
|
return 8;
|
||||||
break;
|
break;
|
||||||
|
@ -159,9 +159,9 @@ int main(int argc, char **argv) {
|
|||||||
exit(1);
|
exit(1);
|
||||||
} else {
|
} else {
|
||||||
if(!strcmp(argv[fileArg], "PVRTC")) {
|
if(!strcmp(argv[fileArg], "PVRTC")) {
|
||||||
format = FasTC::eCompressionFormat_PVRTC;
|
format = FasTC::eCompressionFormat_PVRTC4;
|
||||||
} else if(!strcmp(argv[fileArg], "PVRTCLib")) {
|
} else if(!strcmp(argv[fileArg], "PVRTCLib")) {
|
||||||
format = FasTC::eCompressionFormat_PVRTC;
|
format = FasTC::eCompressionFormat_PVRTC4;
|
||||||
bUsePVRTexLib = true;
|
bUsePVRTexLib = true;
|
||||||
} else if(!strcmp(argv[fileArg], "BPTCLib")) {
|
} else if(!strcmp(argv[fileArg], "BPTCLib")) {
|
||||||
format = FasTC::eCompressionFormat_BPTC;
|
format = FasTC::eCompressionFormat_BPTC;
|
||||||
@ -347,8 +347,8 @@ int main(int argc, char **argv) {
|
|||||||
memcpy(basename, decompressedOutput, 256);
|
memcpy(basename, decompressedOutput, 256);
|
||||||
} else if(format == FasTC::eCompressionFormat_BPTC) {
|
} else if(format == FasTC::eCompressionFormat_BPTC) {
|
||||||
strcat(basename, "-bptc.png");
|
strcat(basename, "-bptc.png");
|
||||||
} else if(format == FasTC::eCompressionFormat_PVRTC) {
|
} else if(format == FasTC::eCompressionFormat_PVRTC4) {
|
||||||
strcat(basename, "-pvrtc.png");
|
strcat(basename, "-pvrtc-4bpp.png");
|
||||||
} else if(format == FasTC::eCompressionFormat_DXT1) {
|
} else if(format == FasTC::eCompressionFormat_DXT1) {
|
||||||
strcat(basename, "-dxt1.png");
|
strcat(basename, "-dxt1.png");
|
||||||
} else if(format == FasTC::eCompressionFormat_ETC1) {
|
} else if(format == FasTC::eCompressionFormat_ETC1) {
|
||||||
|
@ -123,37 +123,23 @@ bool CompressedImage::DecompressImage(unsigned char *outBuf, unsigned int outBuf
|
|||||||
|
|
||||||
uint8 *byteData = reinterpret_cast<uint8 *>(m_CompressedData);
|
uint8 *byteData = reinterpret_cast<uint8 *>(m_CompressedData);
|
||||||
DecompressionJob dj (m_Format, byteData, outBuf, GetWidth(), GetHeight());
|
DecompressionJob dj (m_Format, byteData, outBuf, GetWidth(), GetHeight());
|
||||||
switch(m_Format) {
|
if(m_Format == FasTC::eCompressionFormat_DXT1) {
|
||||||
case FasTC::eCompressionFormat_DXT1:
|
DXTC::DecompressDXT1(dj);
|
||||||
DXTC::DecompressDXT1(dj);
|
} else if(m_Format == FasTC::eCompressionFormat_ETC1) {
|
||||||
break;
|
ETCC::Decompress(dj);
|
||||||
|
} else if(FasTC::COMPRESSION_FORMAT_PVRTC_BEGIN <= m_Format &&
|
||||||
case FasTC::eCompressionFormat_ETC1:
|
FasTC::COMPRESSION_FORMAT_PVRTC_END >= m_Format) {
|
||||||
ETCC::Decompress(dj);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case FasTC::eCompressionFormat_PVRTC:
|
|
||||||
{
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
PVRTCC::Decompress(dj, false, PVRTCC::eWrapMode_Wrap, true);
|
PVRTCC::Decompress(dj, PVRTCC::eWrapMode_Wrap, true);
|
||||||
#else
|
#else
|
||||||
PVRTCC::Decompress(dj);
|
PVRTCC::Decompress(dj);
|
||||||
#endif
|
#endif
|
||||||
}
|
} else if(m_Format == FasTC::eCompressionFormat_BPTC) {
|
||||||
break;
|
BPTCC::Decompress(dj);
|
||||||
|
} else {
|
||||||
case FasTC::eCompressionFormat_BPTC:
|
const char *errStr = "Have not implemented decompression method.";
|
||||||
{
|
fprintf(stderr, "%s\n", errStr);
|
||||||
BPTCC::Decompress(dj);
|
assert(!errStr);
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
const char *errStr = "Have not implemented decompression method.";
|
|
||||||
fprintf(stderr, "%s\n", errStr);
|
|
||||||
assert(!errStr);
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,15 +113,6 @@ static CompressionFuncWithStats ChooseFuncFromSettingsWithStats(const SCompress
|
|||||||
}
|
}
|
||||||
break;
|
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:
|
default:
|
||||||
{
|
{
|
||||||
assert(!"Not implemented!");
|
assert(!"Not implemented!");
|
||||||
@ -157,7 +148,7 @@ static CompressionFunc ChooseFuncFromSettings(const SCompressionSettings &s) {
|
|||||||
case FasTC::eCompressionFormat_DXT5:
|
case FasTC::eCompressionFormat_DXT5:
|
||||||
return DXTC::CompressImageDXT5;
|
return DXTC::CompressImageDXT5;
|
||||||
|
|
||||||
case FasTC::eCompressionFormat_PVRTC:
|
case FasTC::eCompressionFormat_PVRTC4:
|
||||||
{
|
{
|
||||||
if(s.bUsePVRTexLib) {
|
if(s.bUsePVRTexLib) {
|
||||||
return CompressPVRTCLib;
|
return CompressPVRTCLib;
|
||||||
@ -458,7 +449,7 @@ bool CompressImageData(
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint32 numThreads = settings.iNumThreads;
|
uint32 numThreads = settings.iNumThreads;
|
||||||
if(settings.format == FasTC::eCompressionFormat_PVRTC &&
|
if(settings.format == FasTC::eCompressionFormat_PVRTC4 &&
|
||||||
(settings.iNumThreads > 1 || settings.logStream)) {
|
(settings.iNumThreads > 1 || settings.logStream)) {
|
||||||
if(settings.iNumThreads > 1) {
|
if(settings.iNumThreads > 1) {
|
||||||
ReportError("WARNING - PVRTC compressor does not support multithreading.");
|
ReportError("WARNING - PVRTC compressor does not support multithreading.");
|
||||||
|
@ -130,7 +130,7 @@ bool ImageWriterKTX::WriteImage() {
|
|||||||
wtr.Write(GL_RGBA); // glBaseFormat
|
wtr.Write(GL_RGBA); // glBaseFormat
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FasTC::eCompressionFormat_PVRTC:
|
case FasTC::eCompressionFormat_PVRTC4:
|
||||||
wtr.Write(COMPRESSED_RGBA_PVRTC_4BPPV1_IMG); // glInternalFormat
|
wtr.Write(COMPRESSED_RGBA_PVRTC_4BPPV1_IMG); // glInternalFormat
|
||||||
wtr.Write(GL_RGBA); // glBaseFormat
|
wtr.Write(GL_RGBA); // glBaseFormat
|
||||||
break;
|
break;
|
||||||
@ -163,7 +163,7 @@ bool ImageWriterKTX::WriteImage() {
|
|||||||
static const uint32 kImageSize = m_Width * m_Height;
|
static const uint32 kImageSize = m_Width * m_Height;
|
||||||
wtr.Write(kImageSize); // imageSize
|
wtr.Write(kImageSize); // imageSize
|
||||||
wtr.Write(ci->GetCompressedData(), kImageSize); // imagedata...
|
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;
|
static const uint32 kImageSize = m_Width * m_Height >> 1;
|
||||||
wtr.Write(kImageSize); // imageSize
|
wtr.Write(kImageSize); // imageSize
|
||||||
wtr.Write(ci->GetCompressedData(), kImageSize); // imagedata...
|
wtr.Write(ci->GetCompressedData(), kImageSize); // imagedata...
|
||||||
|
@ -70,7 +70,6 @@ namespace PVRTCC {
|
|||||||
// 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 FasTC::DecompressionJob &,
|
void Decompress(const FasTC::DecompressionJob &,
|
||||||
bool bTwoBitMode = false,
|
|
||||||
const EWrapMode wrapMode = eWrapMode_Wrap,
|
const EWrapMode wrapMode = eWrapMode_Wrap,
|
||||||
bool bDebugImages = false);
|
bool bDebugImages = false);
|
||||||
|
|
||||||
@ -78,7 +77,6 @@ namespace PVRTCC {
|
|||||||
// version one. The width and height must be specified in order to properly
|
// version one. The width and height must be specified in order to properly
|
||||||
// decompress the data.
|
// decompress the data.
|
||||||
void Compress(const FasTC::CompressionJob &,
|
void Compress(const FasTC::CompressionJob &,
|
||||||
bool bTwoBitMode = false,
|
|
||||||
const EWrapMode wrapMode = eWrapMode_Wrap);
|
const EWrapMode wrapMode = eWrapMode_Wrap);
|
||||||
|
|
||||||
#ifdef PVRTEXLIB_FOUND
|
#ifdef PVRTEXLIB_FOUND
|
||||||
|
@ -919,10 +919,13 @@ namespace PVRTCC {
|
|||||||
}
|
}
|
||||||
#endif
|
#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 width = cj.Width();
|
||||||
const uint32 height = cj.Height();
|
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.
|
// Make sure that width and height are a power of two.
|
||||||
assert((width & (width - 1)) == 0);
|
assert((width & (width - 1)) == 0);
|
||||||
assert((height & (height - 1)) == 0);
|
assert((height & (height - 1)) == 0);
|
||||||
|
@ -274,9 +274,9 @@ namespace PVRTCC {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Decompress(const FasTC::DecompressionJob &dcj,
|
void Decompress(const FasTC::DecompressionJob &dcj,
|
||||||
const bool bTwoBitMode,
|
|
||||||
const EWrapMode wrapMode,
|
const EWrapMode wrapMode,
|
||||||
bool bDebugImages) {
|
bool bDebugImages) {
|
||||||
|
const bool bTwoBitMode = dcj.Format() == FasTC::eCompressionFormat_PVRTC2;
|
||||||
const uint32 w = dcj.Width();
|
const uint32 w = dcj.Width();
|
||||||
const uint32 h = dcj.Height();
|
const uint32 h = dcj.Height();
|
||||||
|
|
||||||
|
@ -81,12 +81,17 @@ class ImageTester {
|
|||||||
|
|
||||||
uint32 *outPixels = new uint32[w * h];
|
uint32 *outPixels = new uint32[w * h];
|
||||||
|
|
||||||
FasTC::DecompressionJob dcj(FasTC::eCompressionFormat_PVRTC,
|
FasTC::ECompressionFormat fmt = FasTC::eCompressionFormat_PVRTC4;
|
||||||
data, reinterpret_cast<uint8 *>(outPixels), w, h);
|
if(twobpp) {
|
||||||
|
fmt = FasTC::eCompressionFormat_PVRTC2;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8 *outBuf = reinterpret_cast<uint8 *>(outPixels);
|
||||||
|
FasTC::DecompressionJob dcj(fmt, data, outBuf, w, h);
|
||||||
#ifdef OUTPUT_DEBUG_IMAGE
|
#ifdef OUTPUT_DEBUG_IMAGE
|
||||||
PVRTCC::Decompress(dcj, twobpp, PVRTCC::eWrapMode_Wrap, true);
|
PVRTCC::Decompress(dcj, PVRTCC::eWrapMode_Wrap, true);
|
||||||
#else
|
#else
|
||||||
PVRTCC::Decompress(dcj, twobpp, PVRTCC::eWrapMode_Wrap);
|
PVRTCC::Decompress(dcj, PVRTCC::eWrapMode_Wrap);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool result = pvrtexture::Transcode(pvrTex,
|
bool result = pvrtexture::Transcode(pvrTex,
|
||||||
|
@ -56,7 +56,7 @@
|
|||||||
|
|
||||||
#include "PVRTCCompressor.h"
|
#include "PVRTCCompressor.h"
|
||||||
|
|
||||||
static const FasTC::ECompressionFormat kFmt = FasTC::eCompressionFormat_PVRTC;
|
static const FasTC::ECompressionFormat kFmt = FasTC::eCompressionFormat_PVRTC4;
|
||||||
|
|
||||||
TEST(Decompressor, DecompressWhite) {
|
TEST(Decompressor, DecompressWhite) {
|
||||||
const uint32 kWidth = 32;
|
const uint32 kWidth = 32;
|
||||||
|
Loading…
Reference in New Issue
Block a user