diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/etc/image_etc.cpp | 32 | ||||
-rw-r--r-- | modules/squish/image_compress_squish.cpp | 9 | ||||
-rw-r--r-- | modules/squish/image_compress_squish.h | 2 |
3 files changed, 33 insertions, 10 deletions
diff --git a/modules/etc/image_etc.cpp b/modules/etc/image_etc.cpp index 4ccd5c8d89..948f50b782 100644 --- a/modules/etc/image_etc.cpp +++ b/modules/etc/image_etc.cpp @@ -94,10 +94,20 @@ static void _decompress_etc2(Image *p_img) { // not implemented, to be removed } -static void _compress_etc(Image *p_img, float p_lossy_quality, bool force_etc1_format) { +static void _compress_etc(Image *p_img, float p_lossy_quality, bool force_etc1_format, Image::CompressSource p_source) { Image::Format img_format = p_img->get_format(); Image::DetectChannels detected_channels = p_img->get_detected_channels(); + if (p_source == Image::COMPRESS_SOURCE_SRGB && (detected_channels == Image::DETECTED_R || detected_channels == Image::DETECTED_RG)) { + //R and RG do not support SRGB + detected_channels = Image::DETECTED_RGB; + } + + if (p_source == Image::COMPRESS_SOURCE_NORMAL) { + //use RG channels only for normal + detected_channels = Image::DETECTED_RG; + } + if (img_format >= Image::FORMAT_DXT1) { return; //do not compress, already compressed } @@ -128,10 +138,18 @@ static void _compress_etc(Image *p_img, float p_lossy_quality, bool force_etc1_f PoolVector<uint8_t>::Write w = dst_data.write(); // prepare parameters to be passed to etc2comp - int num_cpus = OS::get_singleton()->get_processor_count(); + int num_cpus = OS::get_singleton()->get_processor_count() * 2; //generally some cpus have 2 threads int encoding_time = 0; - float effort = CLAMP(p_lossy_quality * 100, 0, 100); - Etc::ErrorMetric error_metric = Etc::ErrorMetric::BT709; // NOTE: we can experiment with other error metrics + float effort = 0.0; //default, reasonable time + + if (p_lossy_quality > 0.75) + effort = 0.4; + else if (p_lossy_quality > 0.85) + effort = 0.6; + else if (p_lossy_quality > 0.95) + effort = 0.8; + + Etc::ErrorMetric error_metric = Etc::ErrorMetric::RGBX; // NOTE: we can experiment with other error metrics Etc::Image::Format etc2comp_etc_format = _image_format_to_etc2comp_format(etc_format); int wofs = 0; @@ -164,11 +182,11 @@ static void _compress_etc(Image *p_img, float p_lossy_quality, bool force_etc1_f } static void _compress_etc1(Image *p_img, float p_lossy_quality) { - _compress_etc(p_img, p_lossy_quality, true); + _compress_etc(p_img, p_lossy_quality, true, Image::COMPRESS_SOURCE_GENERIC); } -static void _compress_etc2(Image *p_img, float p_lossy_quality) { - _compress_etc(p_img, p_lossy_quality, false); +static void _compress_etc2(Image *p_img, float p_lossy_quality, Image::CompressSource p_source) { + _compress_etc(p_img, p_lossy_quality, false, p_source); } void _register_etc_compress_func() { diff --git a/modules/squish/image_compress_squish.cpp b/modules/squish/image_compress_squish.cpp index 32772e0cd2..efce76c805 100644 --- a/modules/squish/image_compress_squish.cpp +++ b/modules/squish/image_compress_squish.cpp @@ -80,7 +80,7 @@ void image_decompress_squish(Image *p_image) { p_image->create(p_image->get_width(), p_image->get_height(), p_image->has_mipmaps(), target_format, data); } -void image_compress_squish(Image *p_image, bool p_srgb) { +void image_compress_squish(Image *p_image, Image::CompressSource p_source) { if (p_image->get_format() >= Image::FORMAT_DXT1) return; //do not compress, already compressed @@ -97,11 +97,16 @@ void image_compress_squish(Image *p_image, bool p_srgb) { p_image->convert(Image::FORMAT_RGBA8); //still uses RGBA to convert - if (p_srgb && (dc == Image::DETECTED_R || dc == Image::DETECTED_RG)) { + if (p_source == Image::COMPRESS_SOURCE_SRGB && (dc == Image::DETECTED_R || dc == Image::DETECTED_RG)) { //R and RG do not support SRGB dc = Image::DETECTED_RGB; } + if (p_source == Image::COMPRESS_SOURCE_NORMAL) { + //R and RG do not support SRGB + dc = Image::DETECTED_RG; + } + switch (dc) { case Image::DETECTED_L: { diff --git a/modules/squish/image_compress_squish.h b/modules/squish/image_compress_squish.h index 8d859b8e0b..68aaeefc30 100644 --- a/modules/squish/image_compress_squish.h +++ b/modules/squish/image_compress_squish.h @@ -32,7 +32,7 @@ #include "image.h" -void image_compress_squish(Image *p_image, bool p_srgb); +void image_compress_squish(Image *p_image, Image::CompressSource p_source); void image_decompress_squish(Image *p_image); #endif // IMAGE_COMPRESS_SQUISH_H |