diff --git a/ASTCEncoder/include/ASTCCompressor.h b/ASTCEncoder/include/ASTCCompressor.h index 63b5c42..1ff3baf 100644 --- a/ASTCEncoder/include/ASTCCompressor.h +++ b/ASTCEncoder/include/ASTCCompressor.h @@ -57,31 +57,11 @@ namespace ASTCC { - // The size of the block for the ASTC data. This needs to be supplied - // for every block stream, since ASTC defines texel weights to be less - // than or equal to the block size in order to save bits when decompressing - enum EASTCBlockSize { - eASTCBlockSize_4x4, - eASTCBlockSize_5x4, - eASTCBlockSize_5x5, - eASTCBlockSize_6x5, - eASTCBlockSize_6x6, - eASTCBlockSize_8x5, - eASTCBlockSize_8x6, - eASTCBlockSize_8x8, - eASTCBlockSize_10x5, - eASTCBlockSize_10x6, - eASTCBlockSize_10x8, - eASTCBlockSize_10x10, - eASTCBlockSize_12x10, - eASTCBlockSize_12x12, - }; - // Takes a stream of compressed ASTC data and decompresses it into R8G8B8A8 // format. The block size must be specified in order to properly - // decompress the data. - void Decompress(const FasTC::DecompressionJob &, - EASTCBlockSize blockSize); + // decompress the data, but it is included in the format descriptor passed + // by FasTC::DecompressionJob + void Decompress(const FasTC::DecompressionJob &); } // namespace ASTCC diff --git a/ASTCEncoder/src/Decompressor.cpp b/ASTCEncoder/src/Decompressor.cpp index 40ffff8..3c08254 100644 --- a/ASTCEncoder/src/Decompressor.cpp +++ b/ASTCEncoder/src/Decompressor.cpp @@ -960,9 +960,9 @@ namespace ASTCC { } } - void Decompress(const FasTC::DecompressionJob &dcj, EASTCBlockSize blockSize) { - uint32 blockWidth = GetBlockWidth(blockSize); - uint32 blockHeight = GetBlockHeight(blockSize); + void Decompress(const FasTC::DecompressionJob &dcj) { + uint32 blockWidth = GetBlockWidth(dcj.Format()); + uint32 blockHeight = GetBlockHeight(dcj.Format()); uint32 blockIdx = 0; for(uint32 j = 0; j < dcj.Width(); j++) { for(uint32 i = 0; i < dcj.Height(); i++) { diff --git a/ASTCEncoder/src/Utils.h b/ASTCEncoder/src/Utils.h index 8abd507..df4143d 100644 --- a/ASTCEncoder/src/Utils.h +++ b/ASTCEncoder/src/Utils.h @@ -56,54 +56,57 @@ #include "ASTCCompressor.h" #include "TexCompTypes.h" +#include "CompressionFormat.h" #include "Pixel.h" namespace ASTCC { - uint32 GetBlockHeight(EASTCBlockSize blockSize) { - switch(blockSize) { - case eASTCBlockSize_4x4: return 4; - case eASTCBlockSize_5x4: return 4; - case eASTCBlockSize_5x5: return 5; - case eASTCBlockSize_6x5: return 5; - case eASTCBlockSize_6x6: return 6; - case eASTCBlockSize_8x5: return 5; - case eASTCBlockSize_8x6: return 6; - case eASTCBlockSize_8x8: return 8; - case eASTCBlockSize_10x5: return 5; - case eASTCBlockSize_10x6: return 6; - case eASTCBlockSize_10x8: return 8; - case eASTCBlockSize_10x10: return 10; - case eASTCBlockSize_12x10: return 10; - case eASTCBlockSize_12x12: return 12; + static inline uint32 GetBlockHeight(FasTC::ECompressionFormat fmt) { + switch(fmt) { + case FasTC::eCompressionFormat_ASTC4x4: return 4; + case FasTC::eCompressionFormat_ASTC5x4: return 4; + case FasTC::eCompressionFormat_ASTC5x5: return 5; + case FasTC::eCompressionFormat_ASTC6x5: return 5; + case FasTC::eCompressionFormat_ASTC6x6: return 6; + case FasTC::eCompressionFormat_ASTC8x5: return 5; + case FasTC::eCompressionFormat_ASTC8x6: return 6; + case FasTC::eCompressionFormat_ASTC8x8: return 8; + case FasTC::eCompressionFormat_ASTC10x5: return 5; + case FasTC::eCompressionFormat_ASTC10x6: return 6; + case FasTC::eCompressionFormat_ASTC10x8: return 8; + case FasTC::eCompressionFormat_ASTC10x10: return 10; + case FasTC::eCompressionFormat_ASTC12x10: return 10; + case FasTC::eCompressionFormat_ASTC12x12: return 12; + default: assert(false); return -1; } assert(false); return -1; }; - uint32 GetBlockWidth(EASTCBlockSize blockSize) { - switch(blockSize) { - case eASTCBlockSize_4x4: return 4; - case eASTCBlockSize_5x4: return 5; - case eASTCBlockSize_5x5: return 5; - case eASTCBlockSize_6x5: return 6; - case eASTCBlockSize_6x6: return 6; - case eASTCBlockSize_8x5: return 8; - case eASTCBlockSize_8x6: return 8; - case eASTCBlockSize_8x8: return 8; - case eASTCBlockSize_10x5: return 10; - case eASTCBlockSize_10x6: return 10; - case eASTCBlockSize_10x8: return 10; - case eASTCBlockSize_10x10: return 10; - case eASTCBlockSize_12x10: return 12; - case eASTCBlockSize_12x12: return 12; + static inline uint32 GetBlockWidth(FasTC::ECompressionFormat fmt) { + switch(fmt) { + case FasTC::eCompressionFormat_ASTC4x4: return 4; + case FasTC::eCompressionFormat_ASTC5x4: return 5; + case FasTC::eCompressionFormat_ASTC5x5: return 5; + case FasTC::eCompressionFormat_ASTC6x5: return 6; + case FasTC::eCompressionFormat_ASTC6x6: return 6; + case FasTC::eCompressionFormat_ASTC8x5: return 8; + case FasTC::eCompressionFormat_ASTC8x6: return 8; + case FasTC::eCompressionFormat_ASTC8x8: return 8; + case FasTC::eCompressionFormat_ASTC10x5: return 10; + case FasTC::eCompressionFormat_ASTC10x6: return 10; + case FasTC::eCompressionFormat_ASTC10x8: return 10; + case FasTC::eCompressionFormat_ASTC10x10: return 10; + case FasTC::eCompressionFormat_ASTC12x10: return 12; + case FasTC::eCompressionFormat_ASTC12x12: return 12; + default: assert(false); return -1; } assert(false); return -1; }; // Count the number of bits set in a number. - Popcnt(uint32 n) { + static inline Popcnt(uint32 n) { uint32 c; for(c = 0; n; c++) { n &= n-1; @@ -112,7 +115,7 @@ namespace ASTCC { } // Transfers a bit as described in C.2.14 - void BitTransferSigned(int32 &a, int32 &b) { + static inline void BitTransferSigned(int32 &a, int32 &b) { b >>= 1; b |= a & 0x80; a >>= 1; @@ -123,21 +126,21 @@ namespace ASTCC { // Adds more precision to the blue channel as described // in C.2.14 - FasTC::Pixel BlueContract(int32 a, int32 r, int32 g, int32 b) { + static inline FasTC::Pixel BlueContract(int32 a, int32 r, int32 g, int32 b) { return FasTC::Pixel(a, (r + b) >> 1, (g + b) >> 1, b); } // Partition selection functions as specified in // C.2.21 - uint32 hash52(uint32 p) { + static inline uint32 hash52(uint32 p) { p ^= p >> 15; p -= p << 17; p += p << 7; p += p << 4; p ^= p >> 5; p += p << 16; p ^= p >> 7; p ^= p >> 3; p ^= p << 6; p ^= p >> 17; return p; } - int32 SelectPartition(int32 seed, int32 x, int32 y, int32 z, - int32 partitionCount, int32 smallBlock) { + static int32 SelectPartition(int32 seed, int32 x, int32 y, int32 z, + int32 partitionCount, int32 smallBlock) { if(smallBlock) { x <<= 1; y <<= 1; @@ -197,18 +200,18 @@ namespace ASTCC { return 3; } - int32 Select2DPartition(int32 seed, int32 x, int32 y, - int32 partitionCount, int32 smallBlock) { + static inline int32 Select2DPartition(int32 seed, int32 x, int32 y, + int32 partitionCount, int32 smallBlock) { return SelectPartition(seed, x, y, 0, partitionCount, smallBlock); } - int32 SelectSmall2DPartition(int32 seed, int32 x, int32 y, - int32 partitionCount) { + static inline int32 SelectSmall2DPartition(int32 seed, int32 x, int32 y, + int32 partitionCount) { return Select2DPartition(seed, x, y, partitionCount, 1); } - int32 SelectLarge2DPartition(int32 seed, int32 x, int32 y, - int32 partitionCount) { + static inline int32 SelectLarge2DPartition(int32 seed, int32 x, int32 y, + int32 partitionCount) { return Select2DPartition(seed, x, y, partitionCount, 0); } } // namespace ASTCC