From fa0bf3b78f4aa27ad941b7c8d60c902d4f0a5dec Mon Sep 17 00:00:00 2001 From: Radzivon Bartoshyk Date: Sat, 2 Nov 2024 12:08:15 +0000 Subject: [PATCH] Update src/codecs/avif/yuv.rs Co-authored-by: Andreas Molzer --- src/codecs/avif/yuv.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/codecs/avif/yuv.rs b/src/codecs/avif/yuv.rs index 747cce8381..ffaecf1be6 100644 --- a/src/codecs/avif/yuv.rs +++ b/src/codecs/avif/yuv.rs @@ -727,9 +727,15 @@ where let cb_value = u_src.as_() - bias_uv; let cr_value = v_src.as_() - bias_uv; - let r = ((y_value + cr_coef * cr_value + ROUNDING) >> PRECISION).clamp(0, max_value); - let b = ((y_value + cb_coef * cb_value + ROUNDING) >> PRECISION).clamp(0, max_value); - let g = ((y_value - g_coef_1 * cr_value - g_coef_2 * cb_value + ROUNDING) >> PRECISION) +#[inline(always)] +fn round(val: i32) -> i32 { + let ROUNDING: i32 = 1 << (PRECISION - 1); + ((val + ROUNDING) >> PRECISION).clamp(0, MAX) +} + + let r = round::(y_value + cr_coef * cr_value); + let b = round::(y_value + cb_coef * cb_value); + let g = round::(y_value - g_coef_1 * cr_value - g_coef_2 * cb_value); .clamp(0, max_value); if CHANNELS == 4 {