From b19225bfce3dab39f8ce6b1ecf610ea0ba650f99 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Fri, 16 Jun 2017 21:47:28 -0300 Subject: -Fix freezes caused by etccomp2, closes #9183 -Normalmaps are now detected and imported as RGTC, both in S3TC and ETC2, this improves their quality. --- core/global_config.cpp | 8 ++++---- core/image.cpp | 16 ++++++++++------ core/image.h | 15 +++++++++++---- core/io/compression.cpp | 4 ++-- 4 files changed, 27 insertions(+), 16 deletions(-) (limited to 'core') diff --git a/core/global_config.cpp b/core/global_config.cpp index 0729d4c482..ba0a7f3e31 100644 --- a/core/global_config.cpp +++ b/core/global_config.cpp @@ -970,10 +970,10 @@ GlobalConfig::GlobalConfig() { GLOBAL_DEF("debug/profiler/max_functions", 16384); - GLOBAL_DEF("compression/zstd_compression_level", 3); - custom_prop_info["compression/zstd_compression_level"] = PropertyInfo(Variant::INT, "compression/zstd_compression_level", PROPERTY_HINT_RANGE, "1,22,1"); - GLOBAL_DEF("compression/zlib_compression_level", Z_DEFAULT_COMPRESSION); - custom_prop_info["compression/zlib_compression_level"] = PropertyInfo(Variant::INT, "compression/zlib_compression_level", PROPERTY_HINT_RANGE, "-1,9,1"); + GLOBAL_DEF("compression/zstd/compression_level", 3); + custom_prop_info["compression/zstd/compression_level"] = PropertyInfo(Variant::INT, "compression/zstd/compression_level", PROPERTY_HINT_RANGE, "1,22,1"); + GLOBAL_DEF("compression/zlib/compression_level", Z_DEFAULT_COMPRESSION); + custom_prop_info["compression/zlib/compression_level"] = PropertyInfo(Variant::INT, "compression/zlib/compression_level", PROPERTY_HINT_RANGE, "-1,9,1"); using_datapack = false; } diff --git a/core/image.cpp b/core/image.cpp index 380b307020..72d0d3e554 100644 --- a/core/image.cpp +++ b/core/image.cpp @@ -1492,14 +1492,14 @@ Error Image::decompress() { return OK; } -Error Image::compress(CompressMode p_mode, bool p_for_srgb, float p_lossy_quality) { +Error Image::compress(CompressMode p_mode, CompressSource p_source, float p_lossy_quality) { switch (p_mode) { case COMPRESS_S3TC: { ERR_FAIL_COND_V(!_image_compress_bc_func, ERR_UNAVAILABLE); - _image_compress_bc_func(this, p_for_srgb); + _image_compress_bc_func(this, p_source); } break; case COMPRESS_PVRTC2: { @@ -1519,7 +1519,7 @@ Error Image::compress(CompressMode p_mode, bool p_for_srgb, float p_lossy_qualit case COMPRESS_ETC2: { ERR_FAIL_COND_V(!_image_compress_etc2_func, ERR_UNAVAILABLE); - _image_compress_etc2_func(this, p_lossy_quality); + _image_compress_etc2_func(this, p_lossy_quality, p_source); } break; } @@ -1649,11 +1649,11 @@ void Image::blit_rect(const Ref &p_src, const Rect2 &p_src_rect, const Po Ref (*Image::_png_mem_loader_func)(const uint8_t *, int) = NULL; Ref (*Image::_jpg_mem_loader_func)(const uint8_t *, int) = NULL; -void (*Image::_image_compress_bc_func)(Image *, bool) = NULL; +void (*Image::_image_compress_bc_func)(Image *, Image::CompressSource) = NULL; void (*Image::_image_compress_pvrtc2_func)(Image *) = NULL; void (*Image::_image_compress_pvrtc4_func)(Image *) = NULL; void (*Image::_image_compress_etc1_func)(Image *, float) = NULL; -void (*Image::_image_compress_etc2_func)(Image *, float) = NULL; +void (*Image::_image_compress_etc2_func)(Image *, float, Image::CompressSource) = NULL; void (*Image::_image_decompress_pvrtc)(Image *) = NULL; void (*Image::_image_decompress_bc)(Image *) = NULL; void (*Image::_image_decompress_etc1)(Image *) = NULL; @@ -2140,9 +2140,13 @@ void Image::_bind_methods() { BIND_CONSTANT(COMPRESS_PVRTC4); BIND_CONSTANT(COMPRESS_ETC); BIND_CONSTANT(COMPRESS_ETC2); + + BIND_CONSTANT(COMPRESS_SOURCE_GENERIC); + BIND_CONSTANT(COMPRESS_SOURCE_SRGB); + BIND_CONSTANT(COMPRESS_SOURCE_NORMAL); } -void Image::set_compress_bc_func(void (*p_compress_func)(Image *, bool)) { +void Image::set_compress_bc_func(void (*p_compress_func)(Image *, CompressSource)) { _image_compress_bc_func = p_compress_func; } diff --git a/core/image.h b/core/image.h index 790c5de9f6..1bb81c939f 100644 --- a/core/image.h +++ b/core/image.h @@ -109,16 +109,22 @@ public: /* INTERPOLATE GAUSS */ }; + enum CompressSource { + COMPRESS_SOURCE_GENERIC, + COMPRESS_SOURCE_SRGB, + COMPRESS_SOURCE_NORMAL + }; + //some functions provided by something else static Ref (*_png_mem_loader_func)(const uint8_t *p_png, int p_size); static Ref (*_jpg_mem_loader_func)(const uint8_t *p_png, int p_size); - static void (*_image_compress_bc_func)(Image *, bool p_srgb); + static void (*_image_compress_bc_func)(Image *, CompressSource p_source); static void (*_image_compress_pvrtc2_func)(Image *); static void (*_image_compress_pvrtc4_func)(Image *); static void (*_image_compress_etc1_func)(Image *, float); - static void (*_image_compress_etc2_func)(Image *, float); + static void (*_image_compress_etc2_func)(Image *, float, CompressSource p_source); static void (*_image_decompress_pvrtc)(Image *); static void (*_image_decompress_bc)(Image *); @@ -267,7 +273,7 @@ public: COMPRESS_ETC2, }; - Error compress(CompressMode p_mode = COMPRESS_S3TC, bool p_for_srgb = false, float p_lossy_quality = 0.7); + Error compress(CompressMode p_mode = COMPRESS_S3TC, CompressSource p_source = COMPRESS_SOURCE_GENERIC, float p_lossy_quality = 0.7); Error decompress(); bool is_compressed() const; @@ -281,7 +287,7 @@ public: Rect2 get_used_rect() const; Ref get_rect(const Rect2 &p_area) const; - static void set_compress_bc_func(void (*p_compress_func)(Image *, bool)); + static void set_compress_bc_func(void (*p_compress_func)(Image *, CompressSource)); static String get_format_name(Format p_format); Image(const uint8_t *p_mem_png_jpg, int p_len = -1); @@ -322,6 +328,7 @@ public: VARIANT_ENUM_CAST(Image::Format) VARIANT_ENUM_CAST(Image::Interpolation) VARIANT_ENUM_CAST(Image::CompressMode) +VARIANT_ENUM_CAST(Image::CompressSource) VARIANT_ENUM_CAST(Image::AlphaMode) #endif diff --git a/core/io/compression.cpp b/core/io/compression.cpp index 9ae54c38af..f806c4da6d 100644 --- a/core/io/compression.cpp +++ b/core/io/compression.cpp @@ -58,7 +58,7 @@ int Compression::compress(uint8_t *p_dst, const uint8_t *p_src, int p_src_size, strm.zalloc = zipio_alloc; strm.zfree = zipio_free; strm.opaque = Z_NULL; - int level = GLOBAL_GET("compression/zlib_compression_level"); + int level = GLOBAL_GET("compression/zlib/compression_level"); int err = deflateInit(&strm, level); if (err != Z_OK) return -1; @@ -81,7 +81,7 @@ int Compression::compress(uint8_t *p_dst, const uint8_t *p_src, int p_src_size, case MODE_ZSTD: { int max_dst_size = get_max_compressed_buffer_size(p_src_size, MODE_ZSTD); - int level = GLOBAL_GET("compression/zstd_compression_level"); + int level = GLOBAL_GET("compression/zstd/compression_level"); return ZSTD_compress(p_dst, max_dst_size, p_src, p_src_size, level); } break; } -- cgit v1.2.3