Merge pull request #88763 from BlueCube3310/image-is-compressed-static

Image: Add static `is_format_compressed` function.
This commit is contained in:
Rémi Verschelde 2024-05-02 14:01:18 +02:00
commit 28a18cf1b8
No known key found for this signature in database
GPG Key ID: C3336907360768E1
6 changed files with 12 additions and 7 deletions

View File

@ -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 <typename Component, int CC, bool renormalize,
@ -2616,7 +2616,11 @@ int Image::get_image_mipmap_offset_and_dimensions(int p_width, int p_height, For
}
bool Image::is_compressed() const {
return format > FORMAT_RGBE9995;
return is_format_compressed(format);
}
bool Image::is_format_compressed(Format p_format) {
return p_format > FORMAT_RGBE9995;
}
Error Image::decompress() {

View File

@ -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();

View File

@ -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.
}

View File

@ -299,7 +299,7 @@ Ref<Image> 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);

View File

@ -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();

View File

@ -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) {