Skip to content

Commit

Permalink
Expose separate rows from PlaneSlice
Browse files Browse the repository at this point in the history
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 <xiph#631 (comment)>.
  • Loading branch information
rom1v authored and lu-zero committed Feb 27, 2019
1 parent 3ba5407 commit 3d814c6
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/plane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use std::iter::FusedIterator;
use std::fmt::{Debug, Display, Formatter};
use std::mem;
use std::ops::Range;

use crate::util::*;

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3d814c6

Please sign in to comment.