| 1 |
use v_frame::{pixel::Pixel, plane::Plane}; |
| 2 |
|
| 3 |
use crate::{ |
| 4 |
data::{ |
| 5 |
plane::{Area, AsRegion}, |
| 6 |
satd::get_satd, |
| 7 |
}, |
| 8 |
CpuFeatureLevel, |
| 9 |
}; |
| 10 |
|
| 11 |
// Generate plane data for get_sad_same() |
| 12 |
fn setup_planes<T: Pixel>() -> (Plane<T>, Plane<T>) { |
| 13 |
// Two planes with different strides |
| 14 |
let mut input_plane = Plane::new(640, 480, 0, 0, 128 + 8, 128 + 8); |
| 15 |
let mut rec_plane = Plane::new(640, 480, 0, 0, 2 * 128 + 8, 2 * 128 + 8); |
| 16 |
|
| 17 |
// Make the test pattern robust to data alignment |
| 18 |
let xpad_off = (input_plane.cfg.xorigin - input_plane.cfg.xpad) as i32 - 8i32; |
| 19 |
|
| 20 |
for (i, row) in input_plane |
| 21 |
.data |
| 22 |
.chunks_mut(input_plane.cfg.stride) |
| 23 |
.enumerate() |
| 24 |
{ |
| 25 |
for (j, pixel) in row.iter_mut().enumerate() { |
| 26 |
let val = ((j + i) as i32 - xpad_off) & 255i32; |
| 27 |
assert!(val >= u8::MIN.into() && val <= u8::MAX.into()); |
| 28 |
*pixel = T::cast_from(val); |
| 29 |
} |
| 30 |
} |
| 31 |
|
| 32 |
for (i, row) in rec_plane.data.chunks_mut(rec_plane.cfg.stride).enumerate() { |
| 33 |
for (j, pixel) in row.iter_mut().enumerate() { |
| 34 |
let val = (j as i32 - i as i32 - xpad_off) & 255i32; |
| 35 |
assert!(val >= u8::MIN.into() && val <= u8::MAX.into()); |
| 36 |
*pixel = T::cast_from(val); |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
(input_plane, rec_plane) |
| 41 |
} |
| 42 |
|
| 43 |
fn get_satd_same_inner<T: Pixel>() { |
| 44 |
let blocks: Vec<(usize, usize, u32)> = vec![ |
| 45 |
(4, 4, 1408), |
| 46 |
(4, 8, 2016), |
| 47 |
(8, 4, 1816), |
| 48 |
(8, 8, 3984), |
| 49 |
(8, 16, 5136), |
| 50 |
(16, 8, 4864), |
| 51 |
(16, 16, 9984), |
| 52 |
(16, 32, 13824), |
| 53 |
(32, 16, 13760), |
| 54 |
(32, 32, 27952), |
| 55 |
(32, 64, 37168), |
| 56 |
(64, 32, 45104), |
| 57 |
(64, 64, 84176), |
| 58 |
(64, 128, 127920), |
| 59 |
(128, 64, 173680), |
| 60 |
(128, 128, 321456), |
| 61 |
(4, 16, 3136), |
| 62 |
(16, 4, 2632), |
| 63 |
(8, 32, 7056), |
| 64 |
(32, 8, 6624), |
| 65 |
(16, 64, 18432), |
| 66 |
(64, 16, 21312), |
| 67 |
]; |
| 68 |
|
| 69 |
let bit_depth: usize = 8; |
| 70 |
let (input_plane, rec_plane) = setup_planes::<T>(); |
| 71 |
|
| 72 |
for (w, h, distortion) in blocks { |
| 73 |
let area = Area::StartingAt { x: 32, y: 40 }; |
| 74 |
|
| 75 |
let input_region = input_plane.region(area); |
| 76 |
let rec_region = rec_plane.region(area); |
| 77 |
|
| 78 |
assert_eq!( |
| 79 |
distortion, |
| 80 |
get_satd( |
| 81 |
&input_region, |
| 82 |
&rec_region, |
| 83 |
w, |
| 84 |
h, |
| 85 |
bit_depth, |
| 86 |
CpuFeatureLevel::default() |
| 87 |
) |
| 88 |
); |
| 89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
#[test] |
| 93 |
fn get_satd_same_u8() { |
| 94 |
get_satd_same_inner::<u8>(); |
| 95 |
} |
| 96 |
|
| 97 |
#[test] |
| 98 |
fn get_satd_same_u16() { |
| 99 |
get_satd_same_inner::<u16>(); |
| 100 |
} |