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]

Get the stride.

Get the region.

Get the width.

Get the height.

Get the Pixel at the given coordinates.

Panics

Requires that x < self.width() and y < self.height(), otherwise it will panic.

Set the Pixel at the given coordinates.

Panics

Requires that x < self.width() and y < self.height(), otherwise it will panic.

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.

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.

Get a mutable view of the given region.

Panics

Requires that x + width <= self.width() and y + height <= self.height(), otherwise it will panic.

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));

Get a mutable Iterator over the pixels.

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);
}

Create a Buffer from the View.

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>();

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]

Performs the conversion.

impl<'a, P: PartialEq, C: PartialEq> PartialEq for View<'a, P, C> where
    P: Read<C> + Write<C>,
    C: Channel
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

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]

Formats the value using the given formatter.

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]

Performs the conversion.