mirror of
https://github.com/yuzu-emu/FasTC.git
synced 2024-11-24 03:25:44 +01:00
Change interface of compression/decompression jobs.
This commit is contained in:
parent
8e76d149ba
commit
f70b26a47f
@ -1628,16 +1628,16 @@ namespace BC7C {
|
||||
// large enough to store the compressed image. This implementation has an 4:1
|
||||
// compression ratio.
|
||||
void Compress(const CompressionJob &cj) {
|
||||
const uint32 *inPixels = reinterpret_cast<const uint32 *>(cj.inBuf);
|
||||
unsigned char *outBuf = cj.outBuf;
|
||||
for(uint32 j = 0; j < cj.height; j += 4) {
|
||||
for(uint32 i = 0; i < cj.width; i += 4) {
|
||||
const uint32 *inPixels = reinterpret_cast<const uint32 *>(cj.InBuf());
|
||||
unsigned char *outBuf = cj.OutBuf();
|
||||
for(uint32 j = 0; j < cj.Height(); j += 4) {
|
||||
for(uint32 i = 0; i < cj.Width(); i += 4) {
|
||||
|
||||
uint32 block[16];
|
||||
memcpy(block, inPixels + j*cj.width + i, 4 * sizeof(uint32));
|
||||
memcpy(block + 4, inPixels + (j+1)*cj.width + i, 4 * sizeof(uint32));
|
||||
memcpy(block + 8, inPixels + (j+2)*cj.width + i, 4 * sizeof(uint32));
|
||||
memcpy(block + 12, inPixels + (j+3)*cj.width + i, 4 * sizeof(uint32));
|
||||
memcpy(block, inPixels + j*cj.RowBytes() + i, 4 * sizeof(uint32));
|
||||
memcpy(block + 4, inPixels + (j+1)*cj.RowBytes() + i, 4 * sizeof(uint32));
|
||||
memcpy(block + 8, inPixels + (j+2)*cj.RowBytes() + i, 4 * sizeof(uint32));
|
||||
memcpy(block + 12, inPixels + (j+3)*cj.RowBytes() + i, 4 * sizeof(uint32));
|
||||
|
||||
CompressBC7Block(block, outBuf);
|
||||
|
||||
@ -1723,20 +1723,20 @@ namespace BC7C {
|
||||
#endif // HAS_ATOMICS
|
||||
|
||||
void CompressWithStats(const CompressionJob &cj, std::ostream *logStream) {
|
||||
const uint32 *inPixels = reinterpret_cast<const uint32 *>(cj.inBuf);
|
||||
unsigned char *outBuf = cj.outBuf;
|
||||
const uint32 *inPixels = reinterpret_cast<const uint32 *>(cj.InBuf());
|
||||
unsigned char *outBuf = cj.OutBuf();
|
||||
|
||||
for(uint32 j = 0; j < cj.height; j += 4) {
|
||||
for(uint32 i = 0; i < cj.width; i += 4) {
|
||||
for(uint32 j = 0; j < cj.Height(); j += 4) {
|
||||
for(uint32 i = 0; i < cj.Width(); i += 4) {
|
||||
|
||||
uint32 block[16];
|
||||
memcpy(block, inPixels + j*cj.width + i, 4 * sizeof(uint32));
|
||||
memcpy(block + 4, inPixels + (j+1)*cj.width + i, 4 * sizeof(uint32));
|
||||
memcpy(block + 8, inPixels + (j+2)*cj.width + i, 4 * sizeof(uint32));
|
||||
memcpy(block + 12, inPixels + (j+3)*cj.width + i, 4 * sizeof(uint32));
|
||||
memcpy(block, inPixels + j*cj.RowBytes() + i, 4 * sizeof(uint32));
|
||||
memcpy(block + 4, inPixels + (j+1)*cj.RowBytes() + i, 4 * sizeof(uint32));
|
||||
memcpy(block + 8, inPixels + (j+2)*cj.RowBytes() + i, 4 * sizeof(uint32));
|
||||
memcpy(block + 12, inPixels + (j+3)*cj.RowBytes() + i, 4 * sizeof(uint32));
|
||||
|
||||
if(logStream) {
|
||||
uint64 blockIdx = reinterpret_cast<uint64>(inPixels + j*cj.width + i);
|
||||
uint64 blockIdx = reinterpret_cast<uint64>(inPixels + j*cj.Width() + i);
|
||||
CompressBC7Block(block, outBuf, BlockLogger(blockIdx, *logStream));
|
||||
} else {
|
||||
CompressBC7Block(block, outBuf);
|
||||
@ -2757,19 +2757,19 @@ namespace BC7C {
|
||||
// Convert the image from a BC7 buffer to a RGBA8 buffer
|
||||
void Decompress(const DecompressionJob &dj) {
|
||||
|
||||
const uint8 *inBuf = dj.inBuf;
|
||||
uint32 *outBuf = reinterpret_cast<uint32 *>(dj.outBuf);
|
||||
const uint8 *inBuf = dj.InBuf();
|
||||
uint32 *outBuf = reinterpret_cast<uint32 *>(dj.OutBuf());
|
||||
|
||||
for(unsigned int j = 0; j < dj.height; j += 4) {
|
||||
for(unsigned int i = 0; i < dj.width; i += 4) {
|
||||
for(unsigned int j = 0; j < dj.Height(); j += 4) {
|
||||
for(unsigned int i = 0; i < dj.Width(); i += 4) {
|
||||
|
||||
uint32 pixels[16];
|
||||
DecompressBC7Block(inBuf, pixels);
|
||||
|
||||
memcpy(outBuf + j*dj.width + i, pixels, 4 * sizeof(pixels[0]));
|
||||
memcpy(outBuf + (j+1)*dj.width + i, pixels+4, 4 * sizeof(pixels[0]));
|
||||
memcpy(outBuf + (j+2)*dj.width + i, pixels+8, 4 * sizeof(pixels[0]));
|
||||
memcpy(outBuf + (j+3)*dj.width + i, pixels+12, 4 * sizeof(pixels[0]));
|
||||
memcpy(outBuf + j*dj.Width() + i, pixels, 4 * sizeof(pixels[0]));
|
||||
memcpy(outBuf + (j+1)*dj.Width() + i, pixels+4, 4 * sizeof(pixels[0]));
|
||||
memcpy(outBuf + (j+2)*dj.Width() + i, pixels+8, 4 * sizeof(pixels[0]));
|
||||
memcpy(outBuf + (j+3)*dj.Width() + i, pixels+12, 4 * sizeof(pixels[0]));
|
||||
|
||||
inBuf += 16;
|
||||
}
|
||||
|
@ -61,40 +61,70 @@
|
||||
// inBuf - (width * height * 4) bytes
|
||||
// outBuf - (width * height) bytes
|
||||
struct CompressionJob {
|
||||
const unsigned char *inBuf;
|
||||
unsigned char *outBuf;
|
||||
const uint32 width;
|
||||
const uint32 height;
|
||||
private:
|
||||
const uint8 *m_InBuf;
|
||||
uint8 *m_OutBuf;
|
||||
const uint32 m_Width;
|
||||
const uint32 m_Height;
|
||||
const uint32 m_RowBytes;
|
||||
|
||||
public:
|
||||
const uint8 *InBuf() const { return m_InBuf; }
|
||||
uint8 *OutBuf() const { return m_OutBuf; }
|
||||
uint32 Width() const { return m_Width; }
|
||||
uint32 Height() const { return m_Height; }
|
||||
uint32 RowBytes() const { return m_RowBytes; }
|
||||
|
||||
CompressionJob(
|
||||
const unsigned char *_inBuf,
|
||||
const uint8 *_inBuf,
|
||||
unsigned char *_outBuf,
|
||||
const uint32 _width,
|
||||
const uint32 _height)
|
||||
: inBuf(_inBuf)
|
||||
, outBuf(_outBuf)
|
||||
, width(_width)
|
||||
, height(_height)
|
||||
: m_InBuf(_inBuf)
|
||||
, m_OutBuf(_outBuf)
|
||||
, m_Width(_width)
|
||||
, m_Height(_height)
|
||||
, m_RowBytes(_width)
|
||||
{ }
|
||||
|
||||
CompressionJob(
|
||||
const uint8 *_inBuf,
|
||||
unsigned char *_outBuf,
|
||||
const uint32 _width,
|
||||
const uint32 _height,
|
||||
const uint32 _rowbytes)
|
||||
: m_InBuf(_inBuf)
|
||||
, m_OutBuf(_outBuf)
|
||||
, m_Width(_width)
|
||||
, m_Height(_height)
|
||||
, m_RowBytes(_rowbytes)
|
||||
{ }
|
||||
};
|
||||
|
||||
// This struct mirrors that for a compression job, but is used to decompress a BC7 stream. Here, inBuf
|
||||
// is a buffer of BC7 data, and outBuf is the destination where we will copy the decompressed R8G8B8A8 data
|
||||
struct DecompressionJob {
|
||||
const unsigned char *const inBuf;
|
||||
unsigned char *const outBuf;
|
||||
const uint32 width;
|
||||
const uint32 height;
|
||||
private:
|
||||
const uint8 *m_InBuf;
|
||||
uint8 *m_OutBuf;
|
||||
const uint32 m_Width;
|
||||
const uint32 m_Height;
|
||||
|
||||
public:
|
||||
const uint8 *InBuf() const { return m_InBuf; }
|
||||
uint8 *OutBuf() const { return m_OutBuf; }
|
||||
uint32 Width() const { return m_Width; }
|
||||
uint32 Height() const { return m_Height; }
|
||||
|
||||
DecompressionJob(
|
||||
const unsigned char *_inBuf,
|
||||
const uint8 *_inBuf,
|
||||
unsigned char *_outBuf,
|
||||
const uint32 _width,
|
||||
const uint32 _height)
|
||||
: inBuf(_inBuf)
|
||||
, outBuf(_outBuf)
|
||||
, width(_width)
|
||||
, height(_height)
|
||||
: m_InBuf(_inBuf)
|
||||
, m_OutBuf(_outBuf)
|
||||
, m_Width(_width)
|
||||
, m_Height(_height)
|
||||
{ }
|
||||
};
|
||||
|
||||
|
@ -40,13 +40,13 @@ namespace DXTC
|
||||
uint8 minColor[4];
|
||||
uint8 maxColor[4];
|
||||
|
||||
uint8 *outBuf = cj.outBuf;
|
||||
const uint8 *inBuf = cj.inBuf;
|
||||
for(int j = 0; j < cj.height; j += 4, inBuf += cj.width * 4 * 4)
|
||||
uint8 *outBuf = cj.OutBuf();
|
||||
const uint8 *inBuf = cj.InBuf();
|
||||
for(int j = 0; j < cj.Height(); j += 4, inBuf += cj.Width() * 4 * 4)
|
||||
{
|
||||
for(int i = 0; i < cj.width; i += 4)
|
||||
for(int i = 0; i < cj.Width(); i += 4)
|
||||
{
|
||||
ExtractBlock(inBuf + i * 4, cj.width, block);
|
||||
ExtractBlock(inBuf + i * 4, cj.Width(), block);
|
||||
GetMinMaxColors(block, minColor, maxColor);
|
||||
EmitWord(outBuf, ColorTo565(maxColor));
|
||||
EmitWord(outBuf, ColorTo565(minColor));
|
||||
@ -64,13 +64,13 @@ namespace DXTC
|
||||
uint8 minColor[4];
|
||||
uint8 maxColor[4];
|
||||
|
||||
uint8 *outBuf = cj.outBuf;
|
||||
const uint8 *inBuf = cj.inBuf;
|
||||
for(int j = 0; j < cj.height; j += 4, inBuf += cj.width * 4 * 4)
|
||||
uint8 *outBuf = cj.OutBuf();
|
||||
const uint8 *inBuf = cj.InBuf();
|
||||
for(int j = 0; j < cj.Height(); j += 4, inBuf += cj.Width() * 4 * 4)
|
||||
{
|
||||
for(int i = 0; i < cj.width; i += 4)
|
||||
for(int i = 0; i < cj.Width(); i += 4)
|
||||
{
|
||||
ExtractBlock(inBuf + i * 4, cj.width, block);
|
||||
ExtractBlock(inBuf + i * 4, cj.Width(), block);
|
||||
GetMinMaxColorsWithAlpha(block, minColor, maxColor);
|
||||
EmitByte(outBuf, maxColor[3]);
|
||||
EmitByte(outBuf, minColor[3]);
|
||||
|
@ -92,26 +92,26 @@ namespace DXTC
|
||||
|
||||
void DecompressDXT1(const DecompressionJob &dcj)
|
||||
{
|
||||
assert(!(dcj.height & 3));
|
||||
assert(!(dcj.width & 3));
|
||||
assert(!(dcj.Height() & 3));
|
||||
assert(!(dcj.Width() & 3));
|
||||
|
||||
uint32 blockW = dcj.width >> 2;
|
||||
uint32 blockH = dcj.height >> 2;
|
||||
uint32 blockW = dcj.Width() >> 2;
|
||||
uint32 blockH = dcj.Height() >> 2;
|
||||
|
||||
const uint32 blockSz = 8;
|
||||
|
||||
uint32 *outPixels = reinterpret_cast<uint32 *>(dcj.outBuf);
|
||||
uint32 *outPixels = reinterpret_cast<uint32 *>(dcj.OutBuf());
|
||||
|
||||
uint32 outBlock[16];
|
||||
for(int j = 0; j < blockH; j++) {
|
||||
for(int i = 0; i < blockW; i++) {
|
||||
|
||||
uint32 offset = (j * blockW + i) * blockSz;
|
||||
DecompressDXT1Block(dcj.inBuf + offset, outBlock);
|
||||
DecompressDXT1Block(dcj.InBuf() + offset, outBlock);
|
||||
|
||||
for(uint32 y = 0; y < 4; y++)
|
||||
for(uint32 x = 0; x < 4; x++) {
|
||||
offset = (j*4 + y)*dcj.width + ((i*4)+x);
|
||||
offset = (j*4 + y)*dcj.Width() + ((i*4)+x);
|
||||
outPixels[offset] = outBlock[y*4 + x];
|
||||
}
|
||||
}
|
||||
|
@ -62,8 +62,8 @@ namespace ETCC {
|
||||
rg_etc1::pack_etc1_block_init();
|
||||
|
||||
// Assume block-stream order
|
||||
uint32 blockSizeX = cj.width / 4;
|
||||
uint32 blockSizeY = cj.height / 4;
|
||||
uint32 blockSizeX = cj.Width() / 4;
|
||||
uint32 blockSizeY = cj.Height() / 4;
|
||||
|
||||
for(uint32 j = 0; j < blockSizeY; j++)
|
||||
for(uint32 i = 0; i < blockSizeX; i++) {
|
||||
@ -72,12 +72,12 @@ namespace ETCC {
|
||||
|
||||
for(uint32 y = 0; y < 4; y++) {
|
||||
for(uint32 x = 0; x < 4; x++) {
|
||||
const uint32 *in = reinterpret_cast<const uint32 *>(cj.inBuf);
|
||||
pixels[y*4 + x] = in[(j*4 + y)*cj.width + (i*4 + x)];
|
||||
const uint32 *in = reinterpret_cast<const uint32 *>(cj.InBuf());
|
||||
pixels[y*4 + x] = in[(j*4 + y)*cj.Width() + (i*4 + x)];
|
||||
}
|
||||
}
|
||||
|
||||
pack_etc1_block(cj.outBuf + blockIdx * 8, pixels, params);
|
||||
pack_etc1_block(cj.OutBuf() + blockIdx * 8, pixels, params);
|
||||
}
|
||||
}
|
||||
} // namespace PVRTCC
|
||||
|
@ -57,18 +57,18 @@ namespace ETCC {
|
||||
|
||||
void Decompress(const DecompressionJob &cj) {
|
||||
|
||||
uint32 blocksX = cj.width / 4;
|
||||
uint32 blocksY = cj.width / 4;
|
||||
uint32 blocksX = cj.Width() / 4;
|
||||
uint32 blocksY = cj.Height() / 4;
|
||||
|
||||
for(uint32 j = 0; j < blocksX; j++) {
|
||||
for(uint32 i = 0; i < blocksY; i++) {
|
||||
uint32 pixels[16];
|
||||
uint32 blockIdx = j*blocksX + i;
|
||||
rg_etc1::unpack_etc1_block(cj.inBuf + blockIdx * 8, pixels);
|
||||
rg_etc1::unpack_etc1_block(cj.InBuf() + blockIdx * 8, pixels);
|
||||
for(uint32 y = 0; y < 4; y++)
|
||||
for(uint32 x = 0; x < 4; x++) {
|
||||
uint32 *out = reinterpret_cast<uint32 *>(cj.outBuf);
|
||||
out[(j*4 + y)*cj.width + (i*4 + x)] = pixels[y*4 + x];
|
||||
uint32 *out = reinterpret_cast<uint32 *>(cj.OutBuf());
|
||||
out[(j*4 + y)*cj.Width() + (i*4 + x)] = pixels[y*4 + x];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -918,8 +918,8 @@ namespace PVRTCC {
|
||||
#endif
|
||||
|
||||
void Compress(const CompressionJob &cj, bool bTwoBit, EWrapMode wrapMode) {
|
||||
const uint32 width = cj.width;
|
||||
const uint32 height = cj.height;
|
||||
const uint32 width = cj.Width();
|
||||
const uint32 height = cj.Height();
|
||||
|
||||
// Make sure that width and height are a power of two.
|
||||
assert((width & (width - 1)) == 0);
|
||||
@ -929,10 +929,10 @@ namespace PVRTCC {
|
||||
(CompressionLabel *)calloc(width * height, sizeof(CompressionLabel));
|
||||
|
||||
// First traverse forward...
|
||||
LabelImageForward(labels, cj.inBuf, width, height);
|
||||
LabelImageForward(labels, cj.InBuf(), width, height);
|
||||
|
||||
#ifndef NDEBUG
|
||||
gDbgPixels = reinterpret_cast<const uint32 *>(cj.inBuf);
|
||||
gDbgPixels = reinterpret_cast<const uint32 *>(cj.InBuf());
|
||||
|
||||
Image original(width, height);
|
||||
for(uint32 j = 0; j < height; j++)
|
||||
@ -961,10 +961,10 @@ namespace PVRTCC {
|
||||
#endif
|
||||
|
||||
// Then combine everything...
|
||||
GenerateLowHighImages(labels, cj.inBuf, cj.outBuf, width, height);
|
||||
GenerateLowHighImages(labels, cj.InBuf(), cj.OutBuf(), width, height);
|
||||
|
||||
// Then compute modulation values
|
||||
GenerateModulationValues(cj.outBuf, cj.inBuf, width, height);
|
||||
GenerateModulationValues(cj.OutBuf(), cj.InBuf(), width, height);
|
||||
|
||||
// Cleanup
|
||||
free(labels);
|
||||
|
@ -65,12 +65,12 @@ namespace PVRTCC {
|
||||
const EWrapMode) {
|
||||
pvrtexture::CPVRTextureHeader pvrTexHdr;
|
||||
pvrTexHdr.setPixelFormat(pvrtexture::PVRStandard8PixelType);
|
||||
pvrTexHdr.setWidth(cj.width);
|
||||
pvrTexHdr.setHeight(cj.height);
|
||||
pvrTexHdr.setWidth(cj.Width());
|
||||
pvrTexHdr.setHeight(cj.Height());
|
||||
pvrTexHdr.setIsFileCompressed(false);
|
||||
pvrTexHdr.setIsPreMultiplied(false);
|
||||
|
||||
pvrtexture::CPVRTexture pvrTex = pvrtexture::CPVRTexture(pvrTexHdr, cj.inBuf);
|
||||
pvrtexture::CPVRTexture pvrTex = pvrtexture::CPVRTexture(pvrTexHdr, cj.InBuf());
|
||||
bool result = pvrtexture::Transcode(pvrTex,
|
||||
ePVRTPF_PVRTCI_4bpp_RGBA,
|
||||
ePVRTVarTypeUnsignedByte,
|
||||
@ -79,7 +79,7 @@ namespace PVRTCC {
|
||||
assert(result);
|
||||
(void)result;
|
||||
|
||||
memcpy(cj.outBuf, static_cast<uint8 *>(pvrTex.getDataPtr()), cj.width * cj.height / 2);
|
||||
memcpy(cj.OutBuf(), static_cast<uint8 *>(pvrTex.getDataPtr()), cj.Width() * cj.Height() / 2);
|
||||
}
|
||||
|
||||
} // namespace PVRTCC
|
||||
|
@ -277,8 +277,8 @@ namespace PVRTCC {
|
||||
const bool bTwoBitMode,
|
||||
const EWrapMode wrapMode,
|
||||
bool bDebugImages) {
|
||||
const uint32 w = dcj.width;
|
||||
const uint32 h = dcj.height;
|
||||
const uint32 w = dcj.Width();
|
||||
const uint32 h = dcj.Height();
|
||||
|
||||
assert(w > 0);
|
||||
assert(h > 0);
|
||||
@ -301,7 +301,7 @@ namespace PVRTCC {
|
||||
uint32 idx = Interleave(j, i);
|
||||
|
||||
uint32 offset = idx * kBlockSize;
|
||||
blocks.push_back( Block(dcj.inBuf + offset) );
|
||||
blocks.push_back( Block(dcj.InBuf() + offset) );
|
||||
}
|
||||
}
|
||||
|
||||
@ -381,9 +381,9 @@ namespace PVRTCC {
|
||||
}
|
||||
|
||||
if(bTwoBitMode) {
|
||||
Decompress2BPP(imgA, imgB, blocks, dcj.outBuf, bDebugImages);
|
||||
Decompress2BPP(imgA, imgB, blocks, dcj.OutBuf(), bDebugImages);
|
||||
} else {
|
||||
Decompress4BPP(imgA, imgB, blocks, dcj.outBuf, bDebugImages);
|
||||
Decompress4BPP(imgA, imgB, blocks, dcj.OutBuf(), bDebugImages);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user