From 186efb07d7cdcad4ca99c5f631000674b68a5433 Mon Sep 17 00:00:00 2001 From: David Michael Barr <b@rr-dav.id.au> Date: Mon, 22 Oct 2018 20:28:50 +0900 Subject: [PATCH] Make smooth predictors generic over u8 and u16 --- src/predict.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/predict.rs b/src/predict.rs index de856a2d..c65c5b50 100644 --- a/src/predict.rs +++ b/src/predict.rs @@ -309,7 +309,7 @@ where #[cfg_attr(feature = "comparative_bench", inline(never))] fn pred_smooth( - output: &mut [u16], stride: usize, above: &[u16], left: &[u16] + output: &mut [T], stride: usize, above: &[T], left: &[T] ) { let below_pred = left[Self::H - 1]; // estimated by bottom-left pixel let right_pred = above[Self::W - 1]; // estimated by top-right pixel @@ -346,20 +346,20 @@ where let mut this_pred: u32 = weights .iter() .zip(pixels.iter()) - .map(|(w, p)| (*w as u32) * (*p as u32)) + .map(|(w, p)| { let p: u32 = (*p).into(); (*w as u32) * p }) .sum(); this_pred = (this_pred + (1 << (log2_scale - 1))) >> log2_scale; let output_index = r * stride + c; - output[output_index] = this_pred as u16; + output[output_index] = this_pred.as_(); } } } #[cfg_attr(feature = "comparative_bench", inline(never))] fn pred_smooth_h( - output: &mut [u16], stride: usize, above: &[u16], left: &[u16] + output: &mut [T], stride: usize, above: &[T], left: &[T] ) { let right_pred = above[Self::W - 1]; // estimated by top-right pixel let sm_weights = &sm_weight_arrays[Self::W..]; @@ -382,20 +382,20 @@ where let mut this_pred: u32 = weights .iter() .zip(pixels.iter()) - .map(|(w, p)| (*w as u32) * (*p as u32)) + .map(|(w, p)| { let p: u32 = (*p).into(); (*w as u32) * p }) .sum(); this_pred = (this_pred + (1 << (log2_scale - 1))) >> log2_scale; let output_index = r * stride + c; - output[output_index] = this_pred as u16; + output[output_index] = this_pred.as_(); } } } #[cfg_attr(feature = "comparative_bench", inline(never))] fn pred_smooth_v( - output: &mut [u16], stride: usize, above: &[u16], left: &[u16] + output: &mut [T], stride: usize, above: &[T], left: &[T] ) { let below_pred = left[Self::H - 1]; // estimated by bottom-left pixel let sm_weights = &sm_weight_arrays[Self::H..]; @@ -418,13 +418,13 @@ where let mut this_pred: u32 = weights .iter() .zip(pixels.iter()) - .map(|(w, p)| (*w as u32) * (*p as u32)) + .map(|(w, p)| { let p: u32 = (*p).into(); (*w as u32) * p }) .sum(); this_pred = (this_pred + (1 << (log2_scale - 1))) >> log2_scale; let output_index = r * stride + c; - output[output_index] = this_pred as u16; + output[output_index] = this_pred.as_(); } } } -- GitLab