Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image: Add static is_format_compressed function. #88763

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions core/io/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 <class Component, int CC, bool renormalize,
Expand Down Expand Up @@ -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() {
Expand Down
1 change: 1 addition & 0 deletions core/io/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ class Image : public Resource {
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();
Expand Down
2 changes: 1 addition & 1 deletion modules/astcenc/image_compress_astcenc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}

Expand Down
2 changes: 1 addition & 1 deletion modules/basis_universal/image_compress_basisu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,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);
Expand Down
2 changes: 1 addition & 1 deletion modules/cvtt/image_compress_cvtt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion modules/etcpak/image_compress_etcpak.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading