Struct picto::View
[−]
[src]
pub struct View<'a, P, C> where
P: Read<C> + Write<C>,
C: Channel, { /* fields omitted */ }
A view into a Buffer
.
The View
is a readable and writable borrowed region within a Buffer
and
it's parametrized over two types, the Pixel
and Channel
.
The same details on those types from Buffer
hold true for View
, except
it doesn't own any Data
.
There is no functional difference between a Buffer
and a View
that
encompasses the whole Buffer
region.
Methods
impl<'a, P, C> View<'a, P, C> where
P: Read<C> + Write<C>,
C: Channel,
[src]
P: Read<C> + Write<C>,
C: Channel,
fn from_raw(width: u32, height: u32, data: &mut [C]) -> Result<View<P, C>, ()>
fn with_stride(
width: u32,
height: u32,
stride: usize,
data: &mut [C]
) -> Result<View<P, C>, ()>
width: u32,
height: u32,
stride: usize,
data: &mut [C]
) -> Result<View<P, C>, ()>
fn stride(&self) -> usize
Get the stride.
fn region(&self) -> Region
Get the region.
fn width(&self) -> u32
Get the width.
fn height(&self) -> u32
Get the height.
fn get(&self, x: u32, y: u32) -> P
Get the Pixel
at the given coordinates.
Panics
Requires that x < self.width()
and y < self.height()
, otherwise it will panic.
fn set(&mut self, x: u32, y: u32, pixel: &P)
Set the Pixel
at the given coordinates.
Panics
Requires that x < self.width()
and y < self.height()
, otherwise it will panic.
fn readable(&self, region: Builder) -> Read<P, C>
Get a read-only view of the given region.
Panics
Requires that x + width <= self.width()
and y + height <= self.height()
, otherwise it will panic.
fn writable(&mut self, region: Builder) -> Write<P, C>
Get a write-only view of the given region.
Panics
Requires that x + width <= self.width()
and y + height <= self.height()
, otherwise it will panic.
fn view(&mut self, region: Builder) -> View<P, C>
Get a mutable view of the given region.
Panics
Requires that x + width <= self.width()
and y + height <= self.height()
, otherwise it will panic.
fn fill(&mut self, pixel: &P)
Fill the view with the given pixel.
Example
use picto::read; use picto::Region; use picto::color::Rgb; let mut image = read::from_path::<Rgb, u8, _>("tests/boat.xyz").unwrap(); let mut view = image.view(Region::new().x(10).y(10).width(20).height(30)); // Make a 20x20 pixel region black at offset 10,10. view.fill(&Rgb::new(0.0, 0.0, 0.0));
fn pixels(&self) -> Pixels<P, C>
Get a mutable Iterator
over the pixels.
fn pixels_mut(&mut self) -> PixelsMut<P, C>
Get a mutable Iterator
over the pixels.
Example
use picto::read; use picto::Region; use picto::color::{Mix, Rgb}; let mut image = read::from_path::<Rgb, u8, _>("tests/boat.xyz").unwrap(); let mut view = image.view(Region::new().x(50).y(20)); for (_, _, mut px) in view.pixels_mut() { // Get the pixel value. let p = px.get(); // Mix the color with red. let p = p.mix(&Rgb::new(1.0, 0.0, 0.0), 0.5); // Set the pixel value. px.set(&p); }
fn into_owned(&self) -> Buffer<P, C, Vec<C>>
Create a Buffer
from the View
.
fn convert<PO, CO>(&self) -> Buffer<PO, CO, Vec<CO>> where
P: Into<PO>,
PO: Write<CO>,
CO: Channel,
P: Into<PO>,
PO: Write<CO>,
CO: Channel,
Convert the View
to a Buffer
with different channel and pixel type.
Example
use picto::read; use picto::Region; use picto::color::{Rgb, Rgba}; let mut image = read::from_path::<Rgba, u8, _>("tests/rainbow.png").unwrap(); let view = image.view(Region::new().x(10).y(10).width(20).height(20)); // Convert the 20x20 region from Rgba to Rgb. view.convert::<Rgb, u8>();
fn convert_with<PO, CO, F>(&self, func: F) -> Buffer<PO, CO, Vec<CO>> where
F: FnMut(P) -> PO,
PO: Write<CO>,
CO: Channel,
F: FnMut(P) -> PO,
PO: Write<CO>,
CO: Channel,
Convert the View
to a Buffer
with a closure handling the conversion.
Example
use picto::read; use picto::Region; use picto::color::{Rgb, Rgba, Srgb}; let mut image = read::from_path::<Rgba, u8, _>("tests/rainbow.png").unwrap(); let view = image.view(Region::new().x(10).y(10).width(20).height(20)); // Convert the 20x20 region from Rgba to sRGB. view.convert_with::<Rgb, f32, _>(|p| Srgb::new(p.red, p.green, p.blue).into());
Trait Implementations
impl<'a, P, C, D> From<&'a mut Buffer<P, C, D>> for View<'a, P, C> where
P: Write<C> + Read<C>,
C: Channel,
D: DerefMut<Target = [C]>,
[src]
P: Write<C> + Read<C>,
C: Channel,
D: DerefMut<Target = [C]>,
impl<'a, P: PartialEq, C: PartialEq> PartialEq for View<'a, P, C> where
P: Read<C> + Write<C>,
C: Channel,
[src]
P: Read<C> + Write<C>,
C: Channel,
fn eq(&self, __arg_0: &View<'a, P, C>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &View<'a, P, C>) -> bool
This method tests for !=
.
impl<'a, P: Debug, C: Debug> Debug for View<'a, P, C> where
P: Read<C> + Write<C>,
C: Channel,
[src]
P: Read<C> + Write<C>,
C: Channel,
impl<'a, P, C> From<&'a mut View<'a, P, C>> for View<'a, P, C> where
P: Read<C> + Write<C>,
C: Channel,
[src]
P: Read<C> + Write<C>,
C: Channel,