Commit 6c76da2e authored by Romain Vimont's avatar Romain Vimont Committed by Thomas Daede

Create regions from Plane

Expose region() and region_mut() to get a PlaneRegion and PlaneRegionMut
from a Plane.

They are similar to Plane::slice() and Plane::mut_slice(), but for
regions.
parent f1e6b3fa
......@@ -14,6 +14,7 @@ use std::marker::PhantomData;
use std::mem;
use std::ops::{Index, IndexMut, Range};
use crate::tiling::*;
use crate::util::*;
/// Plane-specific configuration.
......@@ -264,6 +265,28 @@ impl<T: Pixel> Plane<T> {
self.mut_slice(PlaneOffset { x: 0, y: 0 })
}
#[inline(always)]
pub fn region(&self, area: Area) -> PlaneRegion<'_, T> {
let rect = area.to_rect(
self.cfg.xdec,
self.cfg.ydec,
self.cfg.stride - self.cfg.xorigin as usize,
self.cfg.alloc_height - self.cfg.yorigin as usize,
);
PlaneRegion::new(self, rect)
}
#[inline(always)]
pub fn region_mut(&mut self, area: Area) -> PlaneRegionMut<'_, T> {
let rect = area.to_rect(
self.cfg.xdec,
self.cfg.ydec,
self.cfg.stride - self.cfg.xorigin as usize,
self.cfg.alloc_height - self.cfg.yorigin as usize,
);
PlaneRegionMut::new(self, rect)
}
#[inline]
fn index(&self, x: usize, y: usize) -> usize {
(y + self.cfg.yorigin) * self.cfg.stride + (x + self.cfg.xorigin)
......
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