1// Copyright (c) 2017-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
10use crate::tiling::*;
11use crate::util::*;
12
13pub use v_frame::plane::*;
14
15pub trait AsRegion<T: Pixel> {
16 fn as_region(&self) -> PlaneRegion<'_, T>;
17 fn as_region_mut(&mut self) -> PlaneRegionMut<'_, T>;
18 fn region_mut(&mut self, area: Area) -> PlaneRegionMut<'_, T>;
19 fn region(&self, area: Area) -> PlaneRegion<'_, T>;
20}
21
22impl<T: Pixel> AsRegion<T> for Plane<T> {
23 #[inline(always)]
24 fn region(&self, area: Area) -> PlaneRegion<'_, T> {
25 let rect = area.to_rect(
26 self.cfg.xdec,
27 self.cfg.ydec,
28 self.cfg.stride - self.cfg.xorigin,
29 self.cfg.alloc_height - self.cfg.yorigin,
30 );
31 PlaneRegion::new(self, rect)
32 }
33
34 #[inline(always)]
35 fn region_mut(&mut self, area: Area) -> PlaneRegionMut<'_, T> {
36 let rect = area.to_rect(
37 self.cfg.xdec,
38 self.cfg.ydec,
39 self.cfg.stride - self.cfg.xorigin,
40 self.cfg.alloc_height - self.cfg.yorigin,
41 );
42 PlaneRegionMut::new(self, rect)
43 }
44
45 #[inline(always)]
46 fn as_region(&self) -> PlaneRegion<'_, T> {
47 PlaneRegion::new_from_plane(self)
48 }
49
50 #[inline(always)]
51 fn as_region_mut(&mut self) -> PlaneRegionMut<'_, T> {
52 PlaneRegionMut::new_from_plane(self)
53 }
54}
55