diff options
Diffstat (limited to 'subprojects/packagefiles/s3tc-dxt-decompression')
3 files changed, 304 insertions, 0 deletions
diff --git a/subprojects/packagefiles/s3tc-dxt-decompression/compiler_warnings.diff b/subprojects/packagefiles/s3tc-dxt-decompression/compiler_warnings.diff new file mode 100644 index 0000000..7d84683 --- /dev/null +++ b/subprojects/packagefiles/s3tc-dxt-decompression/compiler_warnings.diff @@ -0,0 +1,26 @@ +diff --git a/s3tc.cpp b/s3tc.cpp +index f2642fc..66b0029 100644 +--- a/s3tc.cpp ++++ b/s3tc.cpp +@@ -105,8 +105,8 @@ void BlockDecompressImageDXT1(uint32_t width, uint32_t height, const uint8_t *bl + { + uint32_t blockCountX = (width + 3) / 4; + uint32_t blockCountY = (height + 3) / 4; +- uint32_t blockWidth = (width < 4) ? width : 4; +- uint32_t blockHeight = (height < 4) ? height : 4; ++ //uint32_t blockWidth = (width < 4) ? width : 4; ++ //uint32_t blockHeight = (height < 4) ? height : 4; + + for (uint32_t j = 0; j < blockCountY; j++) + { +@@ -236,8 +236,8 @@ void BlockDecompressImageDXT5(uint32_t width, uint32_t height, const uint8_t *bl + { + uint32_t blockCountX = (width + 3) / 4; + uint32_t blockCountY = (height + 3) / 4; +- uint32_t blockWidth = (width < 4) ? width : 4; +- uint32_t blockHeight = (height < 4) ? height : 4; ++ //uint32_t blockWidth = (width < 4) ? width : 4; ++ //uint32_t blockHeight = (height < 4) ? height : 4; + + for (uint32_t j = 0; j < blockCountY; j++) + { diff --git a/subprojects/packagefiles/s3tc-dxt-decompression/explicit_type_sizes.diff b/subprojects/packagefiles/s3tc-dxt-decompression/explicit_type_sizes.diff new file mode 100644 index 0000000..52cdae3 --- /dev/null +++ b/subprojects/packagefiles/s3tc-dxt-decompression/explicit_type_sizes.diff @@ -0,0 +1,273 @@ +diff --git a/s3tc.cpp b/s3tc.cpp +index a5618c0..f2642fc 100644 +--- a/s3tc.cpp ++++ b/s3tc.cpp +@@ -1,53 +1,55 @@ +-// unsigned long PackRGBA(): Helper method that packs RGBA channels into a single 4 byte pixel. ++#include "s3tc.h" ++ ++// uint32_t PackRGBA(): Helper method that packs RGBA channels into a single 4 byte pixel. + // +-// unsigned char r: red channel. +-// unsigned char g: green channel. +-// unsigned char b: blue channel. +-// unsigned char a: alpha channel. ++// uint8_t r: red channel. ++// uint8_t g: green channel. ++// uint8_t b: blue channel. ++// uint8_t a: alpha channel. + +-unsigned long PackRGBA(unsigned char r, unsigned char g, unsigned char b, unsigned char a) ++uint32_t PackRGBA(uint8_t r, uint8_t g, uint8_t b, uint8_t a) + { + return ((r << 24) | (g << 16) | (b << 8) | a); + } + + // void DecompressBlockDXT1(): Decompresses one block of a DXT1 texture and stores the resulting pixels at the appropriate offset in 'image'. + // +-// unsigned long x: x-coordinate of the first pixel in the block. +-// unsigned long y: y-coordinate of the first pixel in the block. +-// unsigned long width: width of the texture being decompressed. +-// unsigned long height: height of the texture being decompressed. +-// const unsigned char *blockStorage: pointer to the block to decompress. +-// unsigned long *image: pointer to image where the decompressed pixel data should be stored. +- +-void DecompressBlockDXT1(unsigned long x, unsigned long y, unsigned long width, const unsigned char *blockStorage, unsigned long *image) ++// uint32_t x: x-coordinate of the first pixel in the block. ++// uint32_t y: y-coordinate of the first pixel in the block. ++// uint32_t width: width of the texture being decompressed. ++// uint32_t height: height of the texture being decompressed. ++// const uint8_t *blockStorage: pointer to the block to decompress. ++// uint32_t *image: pointer to image where the decompressed pixel data should be stored. ++ ++void DecompressBlockDXT1(uint32_t x, uint32_t y, uint32_t width, const uint8_t *blockStorage, uint32_t *image) + { +- unsigned short color0 = *reinterpret_cast<const unsigned short *>(blockStorage); +- unsigned short color1 = *reinterpret_cast<const unsigned short *>(blockStorage + 2); ++ uint16_t color0 = *reinterpret_cast<const uint16_t *>(blockStorage); ++ uint16_t color1 = *reinterpret_cast<const uint16_t *>(blockStorage + 2); + +- unsigned long temp; ++ uint32_t temp; + + temp = (color0 >> 11) * 255 + 16; +- unsigned char r0 = (unsigned char)((temp/32 + temp)/32); ++ uint8_t r0 = (uint8_t)((temp/32 + temp)/32); + temp = ((color0 & 0x07E0) >> 5) * 255 + 32; +- unsigned char g0 = (unsigned char)((temp/64 + temp)/64); ++ uint8_t g0 = (uint8_t)((temp/64 + temp)/64); + temp = (color0 & 0x001F) * 255 + 16; +- unsigned char b0 = (unsigned char)((temp/32 + temp)/32); ++ uint8_t b0 = (uint8_t)((temp/32 + temp)/32); + + temp = (color1 >> 11) * 255 + 16; +- unsigned char r1 = (unsigned char)((temp/32 + temp)/32); ++ uint8_t r1 = (uint8_t)((temp/32 + temp)/32); + temp = ((color1 & 0x07E0) >> 5) * 255 + 32; +- unsigned char g1 = (unsigned char)((temp/64 + temp)/64); ++ uint8_t g1 = (uint8_t)((temp/64 + temp)/64); + temp = (color1 & 0x001F) * 255 + 16; +- unsigned char b1 = (unsigned char)((temp/32 + temp)/32); ++ uint8_t b1 = (uint8_t)((temp/32 + temp)/32); + +- unsigned long code = *reinterpret_cast<const unsigned long *>(blockStorage + 4); ++ uint32_t code = *reinterpret_cast<const uint32_t *>(blockStorage + 4); + +- for (int j=0; j < 4; j++) ++ for (int32_t j=0; j < 4; j++) + { +- for (int i=0; i < 4; i++) ++ for (int32_t i=0; i < 4; i++) + { +- unsigned long finalColor = 0; +- unsigned char positionCode = (code >> 2*(4*j+i)) & 0x03; ++ uint32_t finalColor = 0; ++ uint8_t positionCode = (code >> 2*(4*j+i)) & 0x03; + + if (color0 > color1) + { +@@ -94,70 +96,70 @@ void DecompressBlockDXT1(unsigned long x, unsigned long y, unsigned long width, + + // void BlockDecompressImageDXT1(): Decompresses all the blocks of a DXT1 compressed texture and stores the resulting pixels in 'image'. + // +-// unsigned long width: Texture width. +-// unsigned long height: Texture height. +-// const unsigned char *blockStorage: pointer to compressed DXT1 blocks. +-// unsigned long *image: pointer to the image where the decompressed pixels will be stored. ++// uint32_t width: Texture width. ++// uint32_t height: Texture height. ++// const uint8_t *blockStorage: pointer to compressed DXT1 blocks. ++// uint32_t *image: pointer to the image where the decompressed pixels will be stored. + +-void BlockDecompressImageDXT1(unsigned long width, unsigned long height, const unsigned char *blockStorage, unsigned long *image) ++void BlockDecompressImageDXT1(uint32_t width, uint32_t height, const uint8_t *blockStorage, uint32_t *image) + { +- unsigned long blockCountX = (width + 3) / 4; +- unsigned long blockCountY = (height + 3) / 4; +- unsigned long blockWidth = (width < 4) ? width : 4; +- unsigned long blockHeight = (height < 4) ? height : 4; ++ uint32_t blockCountX = (width + 3) / 4; ++ uint32_t blockCountY = (height + 3) / 4; ++ uint32_t blockWidth = (width < 4) ? width : 4; ++ uint32_t blockHeight = (height < 4) ? height : 4; + +- for (unsigned long j = 0; j < blockCountY; j++) ++ for (uint32_t j = 0; j < blockCountY; j++) + { +- for (unsigned long i = 0; i < blockCountX; i++) DecompressBlockDXT1(i*4, j*4, width, blockStorage + i * 8, image); ++ for (uint32_t i = 0; i < blockCountX; i++) DecompressBlockDXT1(i*4, j*4, width, blockStorage + i * 8, image); + blockStorage += blockCountX * 8; + } + } + + // void DecompressBlockDXT5(): Decompresses one block of a DXT5 texture and stores the resulting pixels at the appropriate offset in 'image'. + // +-// unsigned long x: x-coordinate of the first pixel in the block. +-// unsigned long y: y-coordinate of the first pixel in the block. +-// unsigned long width: width of the texture being decompressed. +-// unsigned long height: height of the texture being decompressed. +-// const unsigned char *blockStorage: pointer to the block to decompress. +-// unsigned long *image: pointer to image where the decompressed pixel data should be stored. +- +-void DecompressBlockDXT5(unsigned long x, unsigned long y, unsigned long width, const unsigned char *blockStorage, unsigned long *image) ++// uint32_t x: x-coordinate of the first pixel in the block. ++// uint32_t y: y-coordinate of the first pixel in the block. ++// uint32_t width: width of the texture being decompressed. ++// uint32_t height: height of the texture being decompressed. ++// const uint8_t *blockStorage: pointer to the block to decompress. ++// uint32_t *image: pointer to image where the decompressed pixel data should be stored. ++ ++void DecompressBlockDXT5(uint32_t x, uint32_t y, uint32_t width, const uint8_t *blockStorage, uint32_t *image) + { +- unsigned char alpha0 = *reinterpret_cast<const unsigned char *>(blockStorage); +- unsigned char alpha1 = *reinterpret_cast<const unsigned char *>(blockStorage + 1); ++ uint8_t alpha0 = *reinterpret_cast<const uint8_t *>(blockStorage); ++ uint8_t alpha1 = *reinterpret_cast<const uint8_t *>(blockStorage + 1); + +- const unsigned char *bits = blockStorage + 2; +- unsigned long alphaCode1 = bits[2] | (bits[3] << 8) | (bits[4] << 16) | (bits[5] << 24); +- unsigned short alphaCode2 = bits[0] | (bits[1] << 8); ++ const uint8_t *bits = blockStorage + 2; ++ uint32_t alphaCode1 = bits[2] | (bits[3] << 8) | (bits[4] << 16) | (bits[5] << 24); ++ uint16_t alphaCode2 = bits[0] | (bits[1] << 8); + +- unsigned short color0 = *reinterpret_cast<const unsigned short *>(blockStorage + 8); +- unsigned short color1 = *reinterpret_cast<const unsigned short *>(blockStorage + 10); ++ uint16_t color0 = *reinterpret_cast<const uint16_t *>(blockStorage + 8); ++ uint16_t color1 = *reinterpret_cast<const uint16_t *>(blockStorage + 10); + +- unsigned long temp; ++ uint32_t temp; + + temp = (color0 >> 11) * 255 + 16; +- unsigned char r0 = (unsigned char)((temp/32 + temp)/32); ++ uint8_t r0 = (uint8_t)((temp/32 + temp)/32); + temp = ((color0 & 0x07E0) >> 5) * 255 + 32; +- unsigned char g0 = (unsigned char)((temp/64 + temp)/64); ++ uint8_t g0 = (uint8_t)((temp/64 + temp)/64); + temp = (color0 & 0x001F) * 255 + 16; +- unsigned char b0 = (unsigned char)((temp/32 + temp)/32); ++ uint8_t b0 = (uint8_t)((temp/32 + temp)/32); + + temp = (color1 >> 11) * 255 + 16; +- unsigned char r1 = (unsigned char)((temp/32 + temp)/32); ++ uint8_t r1 = (uint8_t)((temp/32 + temp)/32); + temp = ((color1 & 0x07E0) >> 5) * 255 + 32; +- unsigned char g1 = (unsigned char)((temp/64 + temp)/64); ++ uint8_t g1 = (uint8_t)((temp/64 + temp)/64); + temp = (color1 & 0x001F) * 255 + 16; +- unsigned char b1 = (unsigned char)((temp/32 + temp)/32); ++ uint8_t b1 = (uint8_t)((temp/32 + temp)/32); + +- unsigned long code = *reinterpret_cast<const unsigned long *>(blockStorage + 12); ++ uint32_t code = *reinterpret_cast<const uint32_t *>(blockStorage + 12); + +- for (int j=0; j < 4; j++) ++ for (int32_t j=0; j < 4; j++) + { +- for (int i=0; i < 4; i++) ++ for (int32_t i=0; i < 4; i++) + { +- int alphaCodeIndex = 3*(4*j+i); +- int alphaCode; ++ int32_t alphaCodeIndex = 3*(4*j+i); ++ int32_t alphaCode; + + if (alphaCodeIndex <= 12) + { +@@ -172,7 +174,7 @@ void DecompressBlockDXT5(unsigned long x, unsigned long y, unsigned long width, + alphaCode = (alphaCode1 >> (alphaCodeIndex - 16)) & 0x07; + } + +- unsigned char finalAlpha; ++ uint8_t finalAlpha; + if (alphaCode == 0) + { + finalAlpha = alpha0; +@@ -198,9 +200,9 @@ void DecompressBlockDXT5(unsigned long x, unsigned long y, unsigned long width, + } + } + +- unsigned char colorCode = (code >> 2*(4*j+i)) & 0x03; ++ uint8_t colorCode = (code >> 2*(4*j+i)) & 0x03; + +- unsigned long finalColor; ++ uint32_t finalColor; + switch (colorCode) + { + case 0: +@@ -225,21 +227,21 @@ void DecompressBlockDXT5(unsigned long x, unsigned long y, unsigned long width, + + // void BlockDecompressImageDXT5(): Decompresses all the blocks of a DXT5 compressed texture and stores the resulting pixels in 'image'. + // +-// unsigned long width: Texture width. +-// unsigned long height: Texture height. +-// const unsigned char *blockStorage: pointer to compressed DXT5 blocks. +-// unsigned long *image: pointer to the image where the decompressed pixels will be stored. ++// uint32_t width: Texture width. ++// uint32_t height: Texture height. ++// const uint8_t *blockStorage: pointer to compressed DXT5 blocks. ++// uint32_t *image: pointer to the image where the decompressed pixels will be stored. + +-void BlockDecompressImageDXT5(unsigned long width, unsigned long height, const unsigned char *blockStorage, unsigned long *image) ++void BlockDecompressImageDXT5(uint32_t width, uint32_t height, const uint8_t *blockStorage, uint32_t *image) + { +- unsigned long blockCountX = (width + 3) / 4; +- unsigned long blockCountY = (height + 3) / 4; +- unsigned long blockWidth = (width < 4) ? width : 4; +- unsigned long blockHeight = (height < 4) ? height : 4; ++ uint32_t blockCountX = (width + 3) / 4; ++ uint32_t blockCountY = (height + 3) / 4; ++ uint32_t blockWidth = (width < 4) ? width : 4; ++ uint32_t blockHeight = (height < 4) ? height : 4; + +- for (unsigned long j = 0; j < blockCountY; j++) ++ for (uint32_t j = 0; j < blockCountY; j++) + { +- for (unsigned long i = 0; i < blockCountX; i++) DecompressBlockDXT5(i*4, j*4, width, blockStorage + i * 16, image); ++ for (uint32_t i = 0; i < blockCountX; i++) DecompressBlockDXT5(i*4, j*4, width, blockStorage + i * 16, image); + blockStorage += blockCountX * 16; + } + } +diff --git a/s3tc.h b/s3tc.h +index 08a9d05..65d39ba 100644 +--- a/s3tc.h ++++ b/s3tc.h +@@ -1,10 +1,12 @@ + #ifndef S3TC_H + #define S3TC_H + +-unsigned long PackRGBA(unsigned char r, unsigned char g, unsigned char b, unsigned char a); +-void DecompressBlockDXT1(unsigned long x, unsigned long y, unsigned long width, const unsigned char *blockStorage, unsigned long *image); +-void BlockDecompressImageDXT1(unsigned long width, unsigned long height, const unsigned char *blockStorage, unsigned long *image); +-void DecompressBlockDXT5(unsigned long x, unsigned long y, unsigned long width, const unsigned char *blockStorage, unsigned long *image); +-void BlockDecompressImageDXT5(unsigned long width, unsigned long height, const unsigned char *blockStorage, unsigned long *image); ++#include <stdint.h> ++ ++uint32_t PackRGBA(uint8_t r, uint8_t g, uint8_t b, uint8_t a); ++void DecompressBlockDXT1(uint32_t x, uint32_t y, uint32_t width, const uint8_t *blockStorage, uint32_t *image); ++void BlockDecompressImageDXT1(uint32_t width, uint32_t height, const uint8_t *blockStorage, uint32_t *image); ++void DecompressBlockDXT5(uint32_t x, uint32_t y, uint32_t width, const uint8_t *blockStorage, uint32_t *image); ++void BlockDecompressImageDXT5(uint32_t width, uint32_t height, const uint8_t *blockStorage, uint32_t *image); + + #endif // S3TC_H diff --git a/subprojects/packagefiles/s3tc-dxt-decompression/meson.build b/subprojects/packagefiles/s3tc-dxt-decompression/meson.build new file mode 100644 index 0000000..cffe15e --- /dev/null +++ b/subprojects/packagefiles/s3tc-dxt-decompression/meson.build @@ -0,0 +1,5 @@ +project('s3tc', 'cpp', version: 'git-17074c2') + +s3tc_inc = include_directories('.') +s3tc_lib = static_library('s3tc', 's3tc.cpp', include_directories: s3tc_inc) +s3tc = declare_dependency(link_with: s3tc_lib, include_directories: s3tc_inc) |