diff --git a/core/io/image.cpp b/core/io/image.cpp index 6096211cff0..5498b448d71 100644 --- a/core/io/image.cpp +++ b/core/io/image.cpp @@ -521,7 +521,7 @@ void Image::convert(Format p_new_format) { // Includes the main image. const int mipmap_count = get_mipmap_count() + 1; - if (format > FORMAT_RGBE9995 || p_new_format > FORMAT_RGBE9995) { + if (Image::is_format_compressed(format) || Image::is_format_compressed(p_new_format)) { ERR_FAIL_MSG("Cannot convert to <-> from compressed formats. Use compress() and decompress() instead."); } else if (format > FORMAT_RGBA8 || p_new_format > FORMAT_RGBA8) { @@ -1662,7 +1662,7 @@ int Image::_get_dst_image_size(int p_width, int p_height, Format p_format, int & } bool Image::_can_modify(Format p_format) const { - return p_format <= FORMAT_RGBE9995; + return !Image::is_format_compressed(p_format); } template FORMAT_RGBE9995; + return is_format_compressed(format); +} + +bool Image::is_format_compressed(Format p_format) { + return p_format > FORMAT_RGBE9995; } Error Image::decompress() { diff --git a/core/io/image.h b/core/io/image.h index 2cabbb767a5..daddfac59d7 100644 --- a/core/io/image.h +++ b/core/io/image.h @@ -376,6 +376,7 @@ public: Error compress_from_channels(CompressMode p_mode, UsedChannels p_channels, ASTCFormat p_astc_format = ASTC_FORMAT_4x4); Error decompress(); bool is_compressed() const; + static bool is_format_compressed(Format p_format); void fix_alpha_edges(); void premultiply_alpha(); diff --git a/modules/astcenc/image_compress_astcenc.cpp b/modules/astcenc/image_compress_astcenc.cpp index 31df83efae8..941c1f44be1 100644 --- a/modules/astcenc/image_compress_astcenc.cpp +++ b/modules/astcenc/image_compress_astcenc.cpp @@ -41,7 +41,7 @@ void _compress_astc(Image *r_img, Image::ASTCFormat p_format) { // TODO: See how to handle lossy quality. Image::Format img_format = r_img->get_format(); - if (img_format >= Image::FORMAT_DXT1) { + if (Image::is_format_compressed(img_format)) { return; // Do not compress, already compressed. } diff --git a/modules/basis_universal/image_compress_basisu.cpp b/modules/basis_universal/image_compress_basisu.cpp index 531b738041b..d8ef1c04148 100644 --- a/modules/basis_universal/image_compress_basisu.cpp +++ b/modules/basis_universal/image_compress_basisu.cpp @@ -299,7 +299,7 @@ Ref basis_universal_unpacker_ptr(const uint8_t *p_data, int p_size) { basist::basisu_image_level_info basisu_level; transcoder.get_image_level_info(src_ptr, src_size, basisu_level, 0, i); - uint32_t mip_block_or_pixel_count = image_format >= Image::FORMAT_DXT1 ? basisu_level.m_total_blocks : basisu_level.m_orig_width * basisu_level.m_orig_height; + uint32_t mip_block_or_pixel_count = Image::is_format_compressed(image_format) ? basisu_level.m_total_blocks : basisu_level.m_orig_width * basisu_level.m_orig_height; int ofs = Image::get_image_mipmap_offset(basisu_info.m_width, basisu_info.m_height, image_format, i); bool result = transcoder.transcode_image_level(src_ptr, src_size, 0, i, dst + ofs, mip_block_or_pixel_count, basisu_format); diff --git a/modules/cvtt/image_compress_cvtt.cpp b/modules/cvtt/image_compress_cvtt.cpp index e9a7009d7ca..7335315c512 100644 --- a/modules/cvtt/image_compress_cvtt.cpp +++ b/modules/cvtt/image_compress_cvtt.cpp @@ -142,7 +142,7 @@ static void _digest_job_queue(void *p_job_queue, uint32_t p_index) { } void image_compress_cvtt(Image *p_image, Image::UsedChannels p_channels) { - if (p_image->get_format() >= Image::FORMAT_BPTC_RGBA) { + if (p_image->is_compressed()) { return; //do not compress, already compressed } int w = p_image->get_width(); diff --git a/modules/etcpak/image_compress_etcpak.cpp b/modules/etcpak/image_compress_etcpak.cpp index dcd73101c20..4ce0cf50d9a 100644 --- a/modules/etcpak/image_compress_etcpak.cpp +++ b/modules/etcpak/image_compress_etcpak.cpp @@ -92,7 +92,7 @@ void _compress_etcpak(EtcpakType p_compresstype, Image *r_img) { uint64_t start_time = OS::get_singleton()->get_ticks_msec(); Image::Format img_format = r_img->get_format(); - if (img_format >= Image::FORMAT_DXT1) { + if (Image::is_format_compressed(img_format)) { return; // Do not compress, already compressed. } if (img_format > Image::FORMAT_RGBA8) {