From 1d3213f5ae787f54e86ac5dcbb10b0ca182fbeda Mon Sep 17 00:00:00 2001 From: Nick Hollinghurst Date: Thu, 24 Jul 2025 17:55:24 +0100 Subject: [PATCH] backend: Don't enable Resample for unity scale Our default Resample kernels introduce a slight sharpening even at unity scale and zero phase. Resample itself will truncate to 12-bit precision. So it's best to disable it in this case. Signed-off-by: Nick Hollinghurst --- src/libpisp/backend/backend_prepare.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/libpisp/backend/backend_prepare.cpp b/src/libpisp/backend/backend_prepare.cpp index 6328c08..fcb4191 100644 --- a/src/libpisp/backend/backend_prepare.cpp +++ b/src/libpisp/backend/backend_prepare.cpp @@ -617,10 +617,13 @@ void BackEnd::updateSmartResize() be_config_.global.rgb_enables &= ~PISP_BE_RGB_ENABLE_DOWNSCALE(i); } - pisp_be_resample_config resample; - pisp_be_resample_extra resample_extra; - memset(&resample, 0, sizeof(resample)); - memset(&resample_extra, 0, sizeof(resample_extra)); + // Don't resample by unity: it needlessly reduces bit-depth, and can over-sharpen + if (resampler_input_width == resampler_output_width && + resampler_input_height == resampler_output_height) + { + be_config_.global.rgb_enables &= ~PISP_BE_RGB_ENABLE_RESAMPLE(i); + continue; + } // Finally program up the resampler block. // If the following conditions are met: @@ -634,6 +637,9 @@ void BackEnd::updateSmartResize() // on image quality for larger downscale factors. double scale_factor_x = (double)(resampler_input_width - 1) / (resampler_output_width - 1); double scale_factor_y = (double)(resampler_input_height - 1) / (resampler_output_height - 1); + pisp_be_resample_config resample = {}; + pisp_be_resample_extra resample_extra = {}; + if (scale_factor_x > 2.1 && scale_factor_x < scale_factor_y * 1.1 && scale_factor_y < scale_factor_x * 1.1) {