mirror of
https://github.com/godotengine/godot.git
synced 2024-11-24 21:22:48 +00:00
Merge pull request #88763 from BlueCube3310/image-is-compressed-static
Image: Add static `is_format_compressed` function.
This commit is contained in:
commit
28a18cf1b8
@ -521,7 +521,7 @@ void Image::convert(Format p_new_format) {
|
|||||||
// Includes the main image.
|
// Includes the main image.
|
||||||
const int mipmap_count = get_mipmap_count() + 1;
|
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.");
|
ERR_FAIL_MSG("Cannot convert to <-> from compressed formats. Use compress() and decompress() instead.");
|
||||||
|
|
||||||
} else if (format > FORMAT_RGBA8 || p_new_format > FORMAT_RGBA8) {
|
} 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 {
|
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,
|
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 {
|
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() {
|
Error Image::decompress() {
|
||||||
|
@ -376,6 +376,7 @@ public:
|
|||||||
Error compress_from_channels(CompressMode p_mode, UsedChannels p_channels, ASTCFormat p_astc_format = ASTC_FORMAT_4x4);
|
Error compress_from_channels(CompressMode p_mode, UsedChannels p_channels, ASTCFormat p_astc_format = ASTC_FORMAT_4x4);
|
||||||
Error decompress();
|
Error decompress();
|
||||||
bool is_compressed() const;
|
bool is_compressed() const;
|
||||||
|
static bool is_format_compressed(Format p_format);
|
||||||
|
|
||||||
void fix_alpha_edges();
|
void fix_alpha_edges();
|
||||||
void premultiply_alpha();
|
void premultiply_alpha();
|
||||||
|
@ -41,7 +41,7 @@ void _compress_astc(Image *r_img, Image::ASTCFormat p_format) {
|
|||||||
// TODO: See how to handle lossy quality.
|
// TODO: See how to handle lossy quality.
|
||||||
|
|
||||||
Image::Format img_format = r_img->get_format();
|
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.
|
return; // Do not compress, already compressed.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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;
|
basist::basisu_image_level_info basisu_level;
|
||||||
transcoder.get_image_level_info(src_ptr, src_size, basisu_level, 0, i);
|
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);
|
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);
|
bool result = transcoder.transcode_image_level(src_ptr, src_size, 0, i, dst + ofs, mip_block_or_pixel_count, basisu_format);
|
||||||
|
@ -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) {
|
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
|
return; //do not compress, already compressed
|
||||||
}
|
}
|
||||||
int w = p_image->get_width();
|
int w = p_image->get_width();
|
||||||
|
@ -92,7 +92,7 @@ void _compress_etcpak(EtcpakType p_compresstype, Image *r_img) {
|
|||||||
uint64_t start_time = OS::get_singleton()->get_ticks_msec();
|
uint64_t start_time = OS::get_singleton()->get_ticks_msec();
|
||||||
|
|
||||||
Image::Format img_format = r_img->get_format();
|
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.
|
return; // Do not compress, already compressed.
|
||||||
}
|
}
|
||||||
if (img_format > Image::FORMAT_RGBA8) {
|
if (img_format > Image::FORMAT_RGBA8) {
|
||||||
|
Loading…
Reference in New Issue
Block a user