1 | // Copyright (c) 2021-2022, The rav1e contributors. All rights reserved |
2 | // |
3 | // This source code is subject to the terms of the BSD 2 Clause License and |
4 | // the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License |
5 | // was not distributed with this source code in the LICENSE file, you can |
6 | // obtain it at www.aomedia.org/license/software. If the Alliance for Open |
7 | // Media Patent License 1.0 was not distributed with this source code in the |
8 | // PATENTS file, you can obtain it at www.aomedia.org/license/patent. |
9 | |
10 | cfg_if::cfg_if! { |
11 | if #[cfg(nasm_x86_64)] { |
12 | use crate::asm::x86::sad_plane::*; |
13 | } else { |
14 | use self::rust::*; |
15 | } |
16 | } |
17 | |
18 | use v_frame::plane::Plane; |
19 | |
20 | use crate::cpu_features::CpuFeatureLevel; |
21 | use crate::util::{CastFromPrimitive, Pixel}; |
22 | |
23 | pub(crate) mod rust { |
24 | use super::*; |
25 | use crate::cpu_features::CpuFeatureLevel; |
26 | |
27 | #[inline ] |
28 | pub(crate) fn sad_plane_internal<T: Pixel>( |
29 | src: &Plane<T>, dst: &Plane<T>, _cpu: CpuFeatureLevel, |
30 | ) -> u64 { |
31 | debug_assert!(src.cfg.width == dst.cfg.width); |
32 | debug_assert!(src.cfg.height == dst.cfg.height); |
33 | |
34 | srcimpl Iterator |
35 | .rows_iter() |
36 | .zip(dst.rows_iter()) |
37 | .map(|(src: &[T], dst: &[T])| { |
38 | srcimpl Iterator |
39 | .iter() |
40 | .zip(dst.iter()) |
41 | .map(|(&p1: T, &p2: T)| i32::cast_from(p1).abs_diff(i32::cast_from(p2))) |
42 | .sum::<u32>() as u64 |
43 | }) |
44 | .sum() |
45 | } |
46 | } |
47 | |
48 | /// Compute the sum of absolute differences (SADs) on 2 rows of pixels |
49 | /// |
50 | /// This differs from other SAD functions in that it operates over a row |
51 | /// (or line) of unknown length rather than a `PlaneRegion<T>`. |
52 | pub(crate) fn sad_plane<T: Pixel>( |
53 | src: &Plane<T>, dst: &Plane<T>, cpu: CpuFeatureLevel, |
54 | ) -> u64 { |
55 | sad_plane_internal(src, dst, cpu) |
56 | } |
57 | |