mirror of
https://github.com/GerbilSoft/rom-properties.git
synced 2025-06-18 11:35:38 -04:00
[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.
This commit is contained in:
parent
bafc14e792
commit
af03225e3d
@ -98,9 +98,10 @@ rp_image_const_ptr ASTCPrivate::loadImage(void)
|
|||||||
return img;
|
return img;
|
||||||
} else if (!this->isValid || !this->file) {
|
} else if (!this->isValid || !this->file) {
|
||||||
// Can't load the image.
|
// Can't load the image.
|
||||||
return nullptr;
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef ENABLE_ASTC
|
||||||
// NOTE: We can't use astcHeader's width/height fields because
|
// NOTE: We can't use astcHeader's width/height fields because
|
||||||
// they're 24-bit values. Use dimensions[] instead.
|
// they're 24-bit values. Use dimensions[] instead.
|
||||||
|
|
||||||
@ -113,17 +114,17 @@ rp_image_const_ptr ASTCPrivate::loadImage(void)
|
|||||||
dimensions[1] > 32768)
|
dimensions[1] > 32768)
|
||||||
{
|
{
|
||||||
// Invalid image dimensions.
|
// Invalid image dimensions.
|
||||||
return nullptr;
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dimensions[2] > 1) {
|
if (dimensions[2] > 1) {
|
||||||
// 3D textures are not supported.
|
// 3D textures are not supported.
|
||||||
return nullptr;
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (file->size() > 128*1024*1024) {
|
if (file->size() > 128*1024*1024) {
|
||||||
// Sanity check: VTF files shouldn't be more than 128 MB.
|
// Sanity check: VTF files shouldn't be more than 128 MB.
|
||||||
return nullptr;
|
return {};
|
||||||
}
|
}
|
||||||
const uint32_t file_sz = static_cast<uint32_t>(file->size());
|
const uint32_t file_sz = static_cast<uint32_t>(file->size());
|
||||||
|
|
||||||
@ -137,7 +138,7 @@ rp_image_const_ptr ASTCPrivate::loadImage(void)
|
|||||||
astcHeader.blockdimX, astcHeader.blockdimY);
|
astcHeader.blockdimX, astcHeader.blockdimY);
|
||||||
if (expected_size == 0 || expected_size > file_sz) {
|
if (expected_size == 0 || expected_size > file_sz) {
|
||||||
// Invalid image size.
|
// Invalid image size.
|
||||||
return nullptr;
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// The ASTC file format does not support mipmaps.
|
// The ASTC file format does not support mipmaps.
|
||||||
@ -148,7 +149,7 @@ rp_image_const_ptr ASTCPrivate::loadImage(void)
|
|||||||
int ret = file->seek(texDataStartAddr);
|
int ret = file->seek(texDataStartAddr);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
// Seek error.
|
// Seek error.
|
||||||
return nullptr;
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read the texture data.
|
// Read the texture data.
|
||||||
@ -156,7 +157,7 @@ rp_image_const_ptr ASTCPrivate::loadImage(void)
|
|||||||
size_t size = file->read(buf.get(), expected_size);
|
size_t size = file->read(buf.get(), expected_size);
|
||||||
if (size != expected_size) {
|
if (size != expected_size) {
|
||||||
// Read error.
|
// Read error.
|
||||||
return nullptr;
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decode the image.
|
// Decode the image.
|
||||||
@ -165,6 +166,10 @@ rp_image_const_ptr ASTCPrivate::loadImage(void)
|
|||||||
buf.get(), expected_size,
|
buf.get(), expected_size,
|
||||||
astcHeader.blockdimX, astcHeader.blockdimY);
|
astcHeader.blockdimX, astcHeader.blockdimY);
|
||||||
return img;
|
return img;
|
||||||
|
#else /* !ENABLE_ASTC */
|
||||||
|
// ASTC decoder is disabled.
|
||||||
|
return {};
|
||||||
|
#endif /* ENABLE_ASTC */
|
||||||
}
|
}
|
||||||
|
|
||||||
/** ASTC **/
|
/** ASTC **/
|
||||||
|
@ -842,6 +842,7 @@ rp_image_const_ptr GodotSTEXPrivate::loadImage(int mip)
|
|||||||
// TODO
|
// TODO
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
#ifdef ENABLE_ASTC
|
||||||
case STEX4_FORMAT_ASTC_4x4:
|
case STEX4_FORMAT_ASTC_4x4:
|
||||||
img = ImageDecoder::fromASTC(
|
img = ImageDecoder::fromASTC(
|
||||||
mdata.width, mdata.height,
|
mdata.width, mdata.height,
|
||||||
@ -852,6 +853,7 @@ rp_image_const_ptr GodotSTEXPrivate::loadImage(int mip)
|
|||||||
mdata.width, mdata.height,
|
mdata.width, mdata.height,
|
||||||
buf.get(), mdata.size, 8, 8);
|
buf.get(), mdata.size, 8, 8);
|
||||||
break;
|
break;
|
||||||
|
#endif /* ENABLE_ASTC */
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
assert(!"Unsupported stexVersion value.");
|
assert(!"Unsupported stexVersion value.");
|
||||||
|
Loading…
Reference in New Issue
Block a user