Explicitly handle Image AlphaMode enum instead of treating as bool

Co-authored-by: K. S. Ernest (iFire) Lee <ernest.lee@chibifire.com>
This commit is contained in:
Aaron Franke 2025-04-24 10:41:07 -07:00
parent be3ecaeb3c
commit 19e6bc68aa
No known key found for this signature in database
GPG key ID: 40A1750B977E56BF
3 changed files with 3 additions and 3 deletions

View file

@ -152,7 +152,7 @@ Error image_to_png(const Ref<Image> &p_image, Vector<uint8_t> &p_buffer) {
png_img.format = PNG_FORMAT_RGBA; png_img.format = PNG_FORMAT_RGBA;
break; break;
default: default:
if (source_image->detect_alpha()) { if (source_image->detect_alpha() != Image::ALPHA_NONE) {
source_image->convert(Image::FORMAT_RGBA8); source_image->convert(Image::FORMAT_RGBA8);
png_img.format = PNG_FORMAT_RGBA; png_img.format = PNG_FORMAT_RGBA;
} else { } else {

View file

@ -349,7 +349,7 @@ Error ResourceImporterLayeredTexture::import(ResourceUID::ID p_source_id, const
//if using video ram, optimize //if using video ram, optimize
if (channel_pack == 0) { if (channel_pack == 0) {
//remove alpha if not needed, so compression is more efficient //remove alpha if not needed, so compression is more efficient
if (image->get_format() == Image::FORMAT_RGBA8 && !image->detect_alpha()) { if (image->get_format() == Image::FORMAT_RGBA8 && image->detect_alpha() == Image::ALPHA_NONE) {
image->convert(Image::FORMAT_RGB8); image->convert(Image::FORMAT_RGB8);
} }
} else if (image->get_format() < Image::FORMAT_RGBA8) { } else if (image->get_format() < Image::FORMAT_RGBA8) {

View file

@ -60,7 +60,7 @@ Vector<uint8_t> _webp_packer(const Ref<Image> &p_image, float p_quality, bool p_
Error error = img->decompress(); Error error = img->decompress();
ERR_FAIL_COND_V_MSG(error != OK, Vector<uint8_t>(), "Couldn't decompress image."); ERR_FAIL_COND_V_MSG(error != OK, Vector<uint8_t>(), "Couldn't decompress image.");
} }
if (img->detect_alpha()) { if (img->detect_alpha() != Image::ALPHA_NONE) {
img->convert(Image::FORMAT_RGBA8); img->convert(Image::FORMAT_RGBA8);
} else { } else {
img->convert(Image::FORMAT_RGB8); img->convert(Image::FORMAT_RGB8);