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 area 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
area.
Methods
impl<'a, P, C> View<'a, P, C> where P: Read<C> + Write<C>, C: Channel
[src]
fn area(&self) -> Area
Get the area.
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, area: Builder) -> Read<P, C>
Get a read-only view of the given area.
Panics
Requires that x + width <= self.width()
and y + height <= self.height()
, otherwise it will panic.
fn writable(&mut self, area: Builder) -> Write<P, C>
Get a write-only view of the given area.
Panics
Requires that x + width <= self.width()
and y + height <= self.height()
, otherwise it will panic.
fn view(&mut self, area: Builder) -> View<P, C>
Get a mutable view of the given area.
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::Area; use picto::color::Rgb; let mut image = read::from_path::<Rgb, u8, _>("tests/boat.xyz").unwrap(); let mut view = image.view(Area::new().x(10).y(10).width(20).height(30)); // Make a 20x20 pixel area black at offset 10,10. view.fill(&Rgb::new(0.0, 0.0, 0.0));Run
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::Area; use picto::color::{Mix, Rgb}; let mut image = read::from_path::<Rgb, u8, _>("tests/boat.xyz").unwrap(); let mut view = image.view(Area::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); }Run
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
Convert the View
to a Buffer
with different channel and pixel type.
Example
use picto::read; use picto::Area; use picto::color::{Rgb, Rgba}; let mut image = read::from_path::<Rgba, u8, _>("tests/rainbow.png").unwrap(); let view = image.view(Area::new().x(10).y(10).width(20).height(20)); // Convert the 20x20 area from Rgba to Rgb. view.convert::<Rgb, u8>();Run
fn convert_with<PO, CO, F>(&self, func: F) -> Buffer<PO, CO, Vec<CO>> where 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::Area; use picto::color::{Rgb, Rgba, Srgb}; let mut image = read::from_path::<Rgba, u8, _>("tests/rainbow.png").unwrap(); let view = image.view(Area::new().x(10).y(10).width(20).height(20)); // Convert the 20x20 area from Rgba to sRGB. view.convert_with::<Rgb, u8, _>(|p| Srgb::from(p).into());Run
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]
impl<'a, P: PartialEq, C: PartialEq> PartialEq for View<'a, P, C> where P: Read<C> + Write<C>, C: Channel
[src]
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 !=
.