Skip to content

Commit

Permalink
Update src/codecs/avif/yuv.rs
Browse files Browse the repository at this point in the history
Co-authored-by: Andreas Molzer <[email protected]>
  • Loading branch information
awxkee and HeroicKatora authored Nov 2, 2024
1 parent b2e7a73 commit fa0bf3b
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/codecs/avif/yuv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<const PRECISION: i32, const MAX: i32>(val: i32) -> i32 {
let ROUNDING: i32 = 1 << (PRECISION - 1);
((val + ROUNDING) >> PRECISION).clamp(0, MAX)
}

let r = round::<PRECISION, MAX>(y_value + cr_coef * cr_value);
let b = round::<PRECISION, MAX>(y_value + cb_coef * cb_value);
let g = round::<PRECISION, MAX>(y_value - g_coef_1 * cr_value - g_coef_2 * cb_value);
.clamp(0, max_value);

if CHANNELS == 4 {
Expand Down

0 comments on commit fa0bf3b

Please sign in to comment.