From 3e096a4a50715292d6ef3f6a3c993464d28b324f Mon Sep 17 00:00:00 2001 From: Raziel Alphadios Date: Wed, 26 Oct 2022 02:34:33 +0300 Subject: [PATCH] Add support for remaining unsupported ASTC formats --- include/bimg/bimg.h | 8 +++ src/image.cpp | 120 +++++++++++++++++++++++++++++++++++++------ src/image_encode.cpp | 8 +++ 3 files changed, 120 insertions(+), 16 deletions(-) diff --git a/include/bimg/bimg.h b/include/bimg/bimg.h index 8597b7f..07a5db6 100644 --- a/include/bimg/bimg.h +++ b/include/bimg/bimg.h @@ -69,11 +69,19 @@ namespace bimg ATCE, //!< ATCE RGBA 8 BPP explicit alpha ATCI, //!< ATCI RGBA 8 BPP interpolated alpha ASTC4x4, //!< ASTC 4x4 8.0 BPP + ASTC5x4, //!< ASTC 5x4 6.40 BPP ASTC5x5, //!< ASTC 5x5 5.12 BPP + ASTC6x5, //!< ASTC 6x5 4.27 BPP ASTC6x6, //!< ASTC 6x6 3.56 BPP ASTC8x5, //!< ASTC 8x5 3.20 BPP ASTC8x6, //!< ASTC 8x6 2.67 BPP + ASTC8x8, //!< ASTC 8x8 2.00 BPP ASTC10x5, //!< ASTC 10x5 2.56 BPP + ASTC10x6, //!< ASTC 10x6 2.13 BPP + ASTC10x8, //!< ASTC 10x8 1.60 BPP + ASTC10x10, //!< ASTC 10x10 1.28 BPP + ASTC12x10, //!< ASTC 12x10 1.07 BPP + ASTC12x12, //!< ASTC 12x12 0.89 BPP Unknown, // Compressed formats above. diff --git a/src/image.cpp b/src/image.cpp index a35da10..4c02ef5 100644 --- a/src/image.cpp +++ b/src/image.cpp @@ -46,11 +46,19 @@ namespace bimg { 8, 4, 4, 16, 1, 1, 0, 0, 0, 0, 0, 0, uint8_t(bx::EncodingType::Unorm) }, // ATCE { 8, 4, 4, 16, 1, 1, 0, 0, 0, 0, 0, 0, uint8_t(bx::EncodingType::Unorm) }, // ATCI { 8, 4, 4, 16, 1, 1, 0, 0, 0, 0, 0, 0, uint8_t(bx::EncodingType::Unorm) }, // ASTC4x4 + { 6, 5, 4, 16, 1, 1, 0, 0, 0, 0, 0, 0, uint8_t(bx::EncodingType::Unorm) }, // ASTC5x4 { 6, 5, 5, 16, 1, 1, 0, 0, 0, 0, 0, 0, uint8_t(bx::EncodingType::Unorm) }, // ASTC5x5 + { 4, 6, 5, 16, 1, 1, 0, 0, 0, 0, 0, 0, uint8_t(bx::EncodingType::Unorm) }, // ASTC6x5 { 4, 6, 6, 16, 1, 1, 0, 0, 0, 0, 0, 0, uint8_t(bx::EncodingType::Unorm) }, // ASTC6x6 { 4, 8, 5, 16, 1, 1, 0, 0, 0, 0, 0, 0, uint8_t(bx::EncodingType::Unorm) }, // ASTC8x5 { 3, 8, 6, 16, 1, 1, 0, 0, 0, 0, 0, 0, uint8_t(bx::EncodingType::Unorm) }, // ASTC8x6 + { 2, 8, 8, 16, 1, 1, 0, 0, 0, 0, 0, 0, uint8_t(bx::EncodingType::Unorm) }, // ASTC8x8 { 3, 10, 5, 16, 1, 1, 0, 0, 0, 0, 0, 0, uint8_t(bx::EncodingType::Unorm) }, // ASTC10x5 + { 2, 10, 6, 16, 1, 1, 0, 0, 0, 0, 0, 0, uint8_t(bx::EncodingType::Unorm) }, // ASTC10x6 + { 2, 10, 8, 16, 1, 1, 0, 0, 0, 0, 0, 0, uint8_t(bx::EncodingType::Unorm) }, // ASTC10x8 + { 1, 10,10, 16, 1, 1, 0, 0, 0, 0, 0, 0, uint8_t(bx::EncodingType::Unorm) }, // ASTC10x10 + { 1, 12,10, 16, 1, 1, 0, 0, 0, 0, 0, 0, uint8_t(bx::EncodingType::Unorm) }, // ASTC12x10 + { 1, 12,12, 16, 1, 1, 0, 0, 0, 0, 0, 0, uint8_t(bx::EncodingType::Unorm) }, // ASTC12x12 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, uint8_t(bx::EncodingType::Count) }, // Unknown { 1, 8, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, uint8_t(bx::EncodingType::Unorm) }, // R1 { 8, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 8, uint8_t(bx::EncodingType::Unorm) }, // A8 @@ -139,11 +147,19 @@ namespace bimg "ATCE", // ATCE "ATCI", // ATCI "ASTC4x4", // ASTC4x4 + "ASTC5x4", // ASTC5x4 "ASTC5x5", // ASTC5x5 + "ASTC6x5", // ASTC6x5 "ASTC6x6", // ASTC6x6 "ASTC8x5", // ASTC8x5 "ASTC8x6", // ASTC8x6 + "ASTC8x8", // ASTC8x8 "ASTC10x5", // ASTC10x5 + "ASTC10x6", // ASTC10x6 + "ASTC10x8", // ASTC10x8 + "ASTC10x10", // ASTC10x10 + "ASTC12x10", // ASTC12x10 + "ASTC12x12", // ASTC12x12 "", // Unknown "R1", // R1 "A8", // A8 @@ -1064,11 +1080,19 @@ namespace bimg { NULL, NULL }, // ATCE { NULL, NULL }, // ATCI { NULL, NULL }, // ASTC4x4 + { NULL, NULL }, // ASTC5x4 { NULL, NULL }, // ASTC5x5 + { NULL, NULL }, // ASTC6x5 { NULL, NULL }, // ASTC6x6 { NULL, NULL }, // ASTC8x5 { NULL, NULL }, // ASTC8x6 + { NULL, NULL }, // ASTC8x8 { NULL, NULL }, // ASTC10x5 + { NULL, NULL }, // ASTC10x6 + { NULL, NULL }, // ASTC10x8 + { NULL, NULL }, // ASTC10x10 + { NULL, NULL }, // ASTC12x10 + { NULL, NULL }, // ASTC12x12 { NULL, NULL }, // Unknown { NULL, NULL }, // R1 { bx::packA8, bx::unpackA8 }, // A8 @@ -3324,20 +3348,28 @@ namespace bimg #define DDS_BC5U BX_MAKEFOURCC('B', 'C', '5', 'U') #define DDS_DX10 BX_MAKEFOURCC('D', 'X', '1', '0') -#define DDS_ETC1 BX_MAKEFOURCC('E', 'T', 'C', '1') -#define DDS_ETC2 BX_MAKEFOURCC('E', 'T', 'C', '2') -#define DDS_ET2A BX_MAKEFOURCC('E', 'T', '2', 'A') -#define DDS_PTC2 BX_MAKEFOURCC('P', 'T', 'C', '2') -#define DDS_PTC4 BX_MAKEFOURCC('P', 'T', 'C', '4') -#define DDS_ATC BX_MAKEFOURCC('A', 'T', 'C', ' ') -#define DDS_ATCE BX_MAKEFOURCC('A', 'T', 'C', 'E') -#define DDS_ATCI BX_MAKEFOURCC('A', 'T', 'C', 'I') -#define DDS_ASTC4x4 BX_MAKEFOURCC('A', 'S', '4', '4') -#define DDS_ASTC5x5 BX_MAKEFOURCC('A', 'S', '5', '5') -#define DDS_ASTC6x6 BX_MAKEFOURCC('A', 'S', '6', '6') -#define DDS_ASTC8x5 BX_MAKEFOURCC('A', 'S', '8', '5') -#define DDS_ASTC8x6 BX_MAKEFOURCC('A', 'S', '8', '6') -#define DDS_ASTC10x5 BX_MAKEFOURCC('A', 'S', ':', '5') +#define DDS_ETC1 BX_MAKEFOURCC('E', 'T', 'C', '1') +#define DDS_ETC2 BX_MAKEFOURCC('E', 'T', 'C', '2') +#define DDS_ET2A BX_MAKEFOURCC('E', 'T', '2', 'A') +#define DDS_PTC2 BX_MAKEFOURCC('P', 'T', 'C', '2') +#define DDS_PTC4 BX_MAKEFOURCC('P', 'T', 'C', '4') +#define DDS_ATC BX_MAKEFOURCC('A', 'T', 'C', ' ') +#define DDS_ATCE BX_MAKEFOURCC('A', 'T', 'C', 'E') +#define DDS_ATCI BX_MAKEFOURCC('A', 'T', 'C', 'I') +#define DDS_ASTC4x4 BX_MAKEFOURCC('A', 'S', '4', '4') +#define DDS_ASTC5x4 BX_MAKEFOURCC('A', 'S', '5', '4') +#define DDS_ASTC5x5 BX_MAKEFOURCC('A', 'S', '5', '5') +#define DDS_ASTC6x5 BX_MAKEFOURCC('A', 'S', '6', '5') +#define DDS_ASTC6x6 BX_MAKEFOURCC('A', 'S', '6', '6') +#define DDS_ASTC8x5 BX_MAKEFOURCC('A', 'S', '8', '5') +#define DDS_ASTC8x6 BX_MAKEFOURCC('A', 'S', '8', '6') +#define DDS_ASTC8x8 BX_MAKEFOURCC('A', 'S', '8', '8') +#define DDS_ASTC10x5 BX_MAKEFOURCC('A', 'S', ':', '5') +#define DDS_ASTC10x6 BX_MAKEFOURCC('A', 'S', ':', '6') +#define DDS_ASTC10x8 BX_MAKEFOURCC('A', 'S', ':', '8') +#define DDS_ASTC10x10 BX_MAKEFOURCC('A', 'S', ':', ':') +#define DDS_ASTC12x10 BX_MAKEFOURCC('A', 'S', '<', ':') +#define DDS_ASTC12x12 BX_MAKEFOURCC('A', 'S', '<', '<') #define DDS_R8G8B8 20 #define DDS_A8R8G8B8 21 @@ -3465,11 +3497,19 @@ namespace bimg { DDS_ATCE, TextureFormat::ATCE, false }, { DDS_ATCI, TextureFormat::ATCI, false }, { DDS_ASTC4x4, TextureFormat::ASTC4x4, false }, + { DDS_ASTC5x4, TextureFormat::ASTC5x4, false }, { DDS_ASTC5x5, TextureFormat::ASTC5x5, false }, + { DDS_ASTC6x5, TextureFormat::ASTC6x5, false }, { DDS_ASTC6x6, TextureFormat::ASTC6x6, false }, { DDS_ASTC8x5, TextureFormat::ASTC8x5, false }, { DDS_ASTC8x6, TextureFormat::ASTC8x6, false }, + { DDS_ASTC8x8, TextureFormat::ASTC8x8, false }, { DDS_ASTC10x5, TextureFormat::ASTC10x5, false }, + { DDS_ASTC10x6, TextureFormat::ASTC10x6, false }, + { DDS_ASTC10x8, TextureFormat::ASTC10x8, false }, + { DDS_ASTC10x10, TextureFormat::ASTC10x10,false }, + { DDS_ASTC12x10, TextureFormat::ASTC12x10,false }, + { DDS_ASTC12x12, TextureFormat::ASTC12x12,false }, { DDS_A16B16G16R16, TextureFormat::RGBA16, false }, { DDS_A16B16G16R16F, TextureFormat::RGBA16F, false }, @@ -3811,18 +3851,34 @@ namespace bimg #define KTX_ATC_RGB_AMD 0x8C92 #define KTX_ATC_RGBA_EXPLICIT_ALPHA_AMD 0x8C93 #define KTX_ATC_RGBA_INTERPOLATED_ALPHA_AMD 0x87EE -#define KTX_COMPRESSED_RGBA_ASTC_4x4_KHR 0x93B0 +#define KTX_COMPRESSED_RGBA_ASTC_4x4_KHR 0x93B0 +#define KTX_COMPRESSED_RGBA_ASTC_5x4_KHR 0x93B1 #define KTX_COMPRESSED_RGBA_ASTC_5x5_KHR 0x93B2 +#define KTX_COMPRESSED_RGBA_ASTC_6x5_KHR 0x93B3 #define KTX_COMPRESSED_RGBA_ASTC_6x6_KHR 0x93B4 #define KTX_COMPRESSED_RGBA_ASTC_8x5_KHR 0x93B5 #define KTX_COMPRESSED_RGBA_ASTC_8x6_KHR 0x93B6 +#define KTX_COMPRESSED_RGBA_ASTC_8x8_KHR 0x93B7 #define KTX_COMPRESSED_RGBA_ASTC_10x5_KHR 0x93B8 +#define KTX_COMPRESSED_RGBA_ASTC_10x6_KHR 0x93B9 +#define KTX_COMPRESSED_RGBA_ASTC_10x8_KHR 0x93BA +#define KTX_COMPRESSED_RGBA_ASTC_10x10_KHR 0x93BB +#define KTX_COMPRESSED_RGBA_ASTC_12x10_KHR 0x93BC +#define KTX_COMPRESSED_RGBA_ASTC_12x12_KHR 0x93BD #define KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR 0x93D0 +#define KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR 0x93D1 #define KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR 0x93D2 +#define KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR 0x93D3 #define KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR 0x93D4 #define KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR 0x93D5 #define KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR 0x93D6 +#define KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR 0x93D7 #define KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR 0x93D8 +#define KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR 0x93D9 +#define KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR 0x93DA +#define KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR 0x93DB +#define KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR 0x93DC +#define KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR 0x93DD #define KTX_A8 0x803C #define KTX_R8 0x8229 @@ -3936,11 +3992,19 @@ namespace bimg { KTX_ATC_RGBA_EXPLICIT_ALPHA_AMD, KTX_ZERO, KTX_ATC_RGBA_EXPLICIT_ALPHA_AMD, KTX_ZERO, }, // ATCE { KTX_ATC_RGBA_INTERPOLATED_ALPHA_AMD, KTX_ZERO, KTX_ATC_RGBA_INTERPOLATED_ALPHA_AMD, KTX_ZERO, }, // ATCI { KTX_COMPRESSED_RGBA_ASTC_4x4_KHR, KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR, KTX_COMPRESSED_RGBA_ASTC_4x4_KHR, KTX_ZERO, }, // ASTC4x4 + { KTX_COMPRESSED_RGBA_ASTC_5x4_KHR, KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR, KTX_COMPRESSED_RGBA_ASTC_5x4_KHR, KTX_ZERO, }, // ASTC5x4 { KTX_COMPRESSED_RGBA_ASTC_5x5_KHR, KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR, KTX_COMPRESSED_RGBA_ASTC_5x5_KHR, KTX_ZERO, }, // ASTC5x5 + { KTX_COMPRESSED_RGBA_ASTC_6x5_KHR, KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR, KTX_COMPRESSED_RGBA_ASTC_6x5_KHR, KTX_ZERO, }, // ASTC6x5 { KTX_COMPRESSED_RGBA_ASTC_6x6_KHR, KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR, KTX_COMPRESSED_RGBA_ASTC_6x6_KHR, KTX_ZERO, }, // ASTC6x6 { KTX_COMPRESSED_RGBA_ASTC_8x5_KHR, KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR, KTX_COMPRESSED_RGBA_ASTC_8x5_KHR, KTX_ZERO, }, // ASTC8x5 { KTX_COMPRESSED_RGBA_ASTC_8x6_KHR, KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR, KTX_COMPRESSED_RGBA_ASTC_8x6_KHR, KTX_ZERO, }, // ASTC8x6 + { KTX_COMPRESSED_RGBA_ASTC_8x8_KHR, KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR, KTX_COMPRESSED_RGBA_ASTC_8x8_KHR, KTX_ZERO, }, // ASTC8x8 { KTX_COMPRESSED_RGBA_ASTC_10x5_KHR, KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR, KTX_COMPRESSED_RGBA_ASTC_10x5_KHR, KTX_ZERO, }, // ASTC10x5 + { KTX_COMPRESSED_RGBA_ASTC_10x6_KHR, KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR, KTX_COMPRESSED_RGBA_ASTC_10x6_KHR, KTX_ZERO, }, // ASTC10x6 + { KTX_COMPRESSED_RGBA_ASTC_10x8_KHR, KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR, KTX_COMPRESSED_RGBA_ASTC_10x8_KHR, KTX_ZERO, }, // ASTC10x8 + { KTX_COMPRESSED_RGBA_ASTC_10x10_KHR, KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR, KTX_COMPRESSED_RGBA_ASTC_10x10_KHR, KTX_ZERO, }, // ASTC10x10 + { KTX_COMPRESSED_RGBA_ASTC_12x10_KHR, KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR, KTX_COMPRESSED_RGBA_ASTC_12x10_KHR, KTX_ZERO, }, // ASTC12x10 + { KTX_COMPRESSED_RGBA_ASTC_12x12_KHR, KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR, KTX_COMPRESSED_RGBA_ASTC_12x12_KHR, KTX_ZERO, }, // ASTC12x12 { KTX_ZERO, KTX_ZERO, KTX_ZERO, KTX_ZERO, }, // Unknown { KTX_ZERO, KTX_ZERO, KTX_ZERO, KTX_ZERO, }, // R1 { KTX_ALPHA, KTX_ZERO, KTX_ALPHA, KTX_UNSIGNED_BYTE, }, // A8 @@ -4773,11 +4837,19 @@ namespace bimg break; case TextureFormat::ASTC4x4: + case TextureFormat::ASTC5x4: case TextureFormat::ASTC5x5: + case TextureFormat::ASTC6x5: case TextureFormat::ASTC6x6: case TextureFormat::ASTC8x5: case TextureFormat::ASTC8x6: + case TextureFormat::ASTC8x8: case TextureFormat::ASTC10x5: + case TextureFormat::ASTC10x6: + case TextureFormat::ASTC10x8: + case TextureFormat::ASTC10x10: + case TextureFormat::ASTC12x10: + case TextureFormat::ASTC12x12: imageDecodeToRgba8(_allocator, _dst, _src, _width, _height, _dstPitch, _srcFormat); imageSwizzleBgra8(_dst, _dstPitch, _width, _height, _dst, _dstPitch); break; @@ -4831,11 +4903,19 @@ namespace bimg break; case TextureFormat::ASTC4x4: + case TextureFormat::ASTC5x4: case TextureFormat::ASTC5x5: + case TextureFormat::ASTC6x5: case TextureFormat::ASTC6x6: case TextureFormat::ASTC8x5: case TextureFormat::ASTC8x6: + case TextureFormat::ASTC8x8: case TextureFormat::ASTC10x5: + case TextureFormat::ASTC10x6: + case TextureFormat::ASTC10x8: + case TextureFormat::ASTC10x10: + case TextureFormat::ASTC12x10: + case TextureFormat::ASTC12x12: if (BX_ENABLED(BIMG_DECODE_ASTC) ) { if (!astc_codec::ASTCDecompressToRGBA( @@ -4844,11 +4924,19 @@ namespace bimg , _width , _height , TextureFormat::ASTC4x4 == _srcFormat ? astc_codec::FootprintType::k4x4 + : TextureFormat::ASTC5x4 == _srcFormat ? astc_codec::FootprintType::k5x4 : TextureFormat::ASTC5x5 == _srcFormat ? astc_codec::FootprintType::k5x5 + : TextureFormat::ASTC6x5 == _srcFormat ? astc_codec::FootprintType::k6x5 : TextureFormat::ASTC6x6 == _srcFormat ? astc_codec::FootprintType::k6x6 : TextureFormat::ASTC8x5 == _srcFormat ? astc_codec::FootprintType::k8x5 : TextureFormat::ASTC8x6 == _srcFormat ? astc_codec::FootprintType::k8x6 - : astc_codec::FootprintType::k10x5 + : TextureFormat::ASTC8x8 == _srcFormat ? astc_codec::FootprintType::k8x8 + : TextureFormat::ASTC10x5 == _srcFormat ? astc_codec::FootprintType::k10x5 + : TextureFormat::ASTC10x6 == _srcFormat ? astc_codec::FootprintType::k10x6 + : TextureFormat::ASTC10x8 == _srcFormat ? astc_codec::FootprintType::k10x8 + : TextureFormat::ASTC10x10== _srcFormat ? astc_codec::FootprintType::k10x10 + : TextureFormat::ASTC12x10== _srcFormat ? astc_codec::FootprintType::k12x10 + : astc_codec::FootprintType::k12x12 , (uint8_t*)_dst , _width*_height*4 , _dstPitch diff --git a/src/image_encode.cpp b/src/image_encode.cpp index 72eb51c..1dfedaa 100644 --- a/src/image_encode.cpp +++ b/src/image_encode.cpp @@ -142,11 +142,19 @@ namespace bimg break; case TextureFormat::ASTC4x4: + case TextureFormat::ASTC5x4: case TextureFormat::ASTC5x5: + case TextureFormat::ASTC6x5: case TextureFormat::ASTC6x6: case TextureFormat::ASTC8x5: case TextureFormat::ASTC8x6: + case TextureFormat::ASTC8x8: case TextureFormat::ASTC10x5: + case TextureFormat::ASTC10x6: + case TextureFormat::ASTC10x8: + case TextureFormat::ASTC10x10: + case TextureFormat::ASTC12x10: + case TextureFormat::ASTC12x12: { const unsigned int thread_count = 1; const bimg::ImageBlockInfo& astcBlockInfo = bimg::getBlockInfo(_format);