Commit 8c00a25b authored by Romain Vimont's avatar Romain Vimont Committed by Luca Barbato

Expose separate rows from PlaneSlice

Currently, many functions access rectangular regions of planes (spanning
multiple rows) via a primitive slice to the whole plane along with the
stride information.

This strategy is not compatible with tiling, since this borrows the
memory belonging to other tiles.

As a first step, add PlaneSlice methods to access rows separetely.

See <https://github.com/xiph/rav1e/issues/631#issuecomment-456088577>.
parent 542482e3
......@@ -10,6 +10,7 @@
use std::iter::FusedIterator;
use std::fmt::{Debug, Display, Formatter};
use std::mem;
use std::ops::Range;
use crate::util::*;
......@@ -315,6 +316,25 @@ impl<'a, T: Pixel> ExactSizeIterator for IterWidth<'a, T> { }
impl<'a, T: Pixel> FusedIterator for IterWidth<'a, T> { }
impl<'a, T: Pixel> PlaneSlice<'a, T> {
#[inline]
fn slice_range(&self, y_offset: usize) -> Range<usize> {
assert!(self.plane.cfg.yorigin as isize + self.y + y_offset as isize >= 0);
let base_y = (self.plane.cfg.yorigin as isize + self.y + y_offset as isize) as usize;
let base_x = (self.plane.cfg.xorigin as isize + self.x) as usize;
let base = base_y * self.plane.cfg.stride + base_x;
let width = self.plane.cfg.stride - base_x;
base..base + width
}
pub fn row(&self, y: usize) -> &[T] {
let range = self.slice_range(y);
&self.plane.data[range]
}
pub fn as_ptr(&self) -> *const T {
self.row(0).as_ptr()
}
pub fn as_slice(&self) -> &'a [T] {
let stride = self.plane.cfg.stride;
let base = (self.y + self.plane.cfg.yorigin as isize) as usize * stride
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment