From af03225e3d1a3751e024ac7b81e2837907f43f26 Mon Sep 17 00:00:00 2001 From: David Korth Date: Sat, 29 Mar 2025 22:37:47 -0400 Subject: [PATCH] [librptexture] ASTC, GodotSTEX: Fix build with ASTC decoding disabled. Note that the ASTC container parser is still available even if ASTC decoding is disabled, since it can at least get metadata, e.g. the image dimensions. --- src/librptexture/fileformat/ASTC.cpp | 19 ++++++++++++------- src/librptexture/fileformat/GodotSTEX.cpp | 2 ++ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/librptexture/fileformat/ASTC.cpp b/src/librptexture/fileformat/ASTC.cpp index 88305d6f8..9eb3d3cfd 100644 --- a/src/librptexture/fileformat/ASTC.cpp +++ b/src/librptexture/fileformat/ASTC.cpp @@ -98,9 +98,10 @@ rp_image_const_ptr ASTCPrivate::loadImage(void) return img; } else if (!this->isValid || !this->file) { // Can't load the image. - return nullptr; + return {}; } +#ifdef ENABLE_ASTC // NOTE: We can't use astcHeader's width/height fields because // they're 24-bit values. Use dimensions[] instead. @@ -113,17 +114,17 @@ rp_image_const_ptr ASTCPrivate::loadImage(void) dimensions[1] > 32768) { // Invalid image dimensions. - return nullptr; + return {}; } if (dimensions[2] > 1) { // 3D textures are not supported. - return nullptr; + return {}; } if (file->size() > 128*1024*1024) { // Sanity check: VTF files shouldn't be more than 128 MB. - return nullptr; + return {}; } const uint32_t file_sz = static_cast(file->size()); @@ -137,7 +138,7 @@ rp_image_const_ptr ASTCPrivate::loadImage(void) astcHeader.blockdimX, astcHeader.blockdimY); if (expected_size == 0 || expected_size > file_sz) { // Invalid image size. - return nullptr; + return {}; } // The ASTC file format does not support mipmaps. @@ -148,7 +149,7 @@ rp_image_const_ptr ASTCPrivate::loadImage(void) int ret = file->seek(texDataStartAddr); if (ret != 0) { // Seek error. - return nullptr; + return {}; } // Read the texture data. @@ -156,7 +157,7 @@ rp_image_const_ptr ASTCPrivate::loadImage(void) size_t size = file->read(buf.get(), expected_size); if (size != expected_size) { // Read error. - return nullptr; + return {}; } // Decode the image. @@ -165,6 +166,10 @@ rp_image_const_ptr ASTCPrivate::loadImage(void) buf.get(), expected_size, astcHeader.blockdimX, astcHeader.blockdimY); return img; +#else /* !ENABLE_ASTC */ + // ASTC decoder is disabled. + return {}; +#endif /* ENABLE_ASTC */ } /** ASTC **/ diff --git a/src/librptexture/fileformat/GodotSTEX.cpp b/src/librptexture/fileformat/GodotSTEX.cpp index 4eb5ef6be..4f52ea178 100644 --- a/src/librptexture/fileformat/GodotSTEX.cpp +++ b/src/librptexture/fileformat/GodotSTEX.cpp @@ -842,6 +842,7 @@ rp_image_const_ptr GodotSTEXPrivate::loadImage(int mip) // TODO break; +#ifdef ENABLE_ASTC case STEX4_FORMAT_ASTC_4x4: img = ImageDecoder::fromASTC( mdata.width, mdata.height, @@ -852,6 +853,7 @@ rp_image_const_ptr GodotSTEXPrivate::loadImage(int mip) mdata.width, mdata.height, buf.get(), mdata.size, 8, 8); break; +#endif /* ENABLE_ASTC */ } } else { assert(!"Unsupported stexVersion value.");