Struct picto::View[][src]

pub struct View<'a, P, C> where
    P: Read<C> + Write<C>,
    C: Channel
{ /* fields omitted */ }
Expand description

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.

Implementations

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

Formats the value using the given formatter. Read more

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

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

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Blur by the given radius. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Dither to the given number of colors. Read more

Flip on the given orientation in-place. Read more

Flip on the given orientation. Read more

Performs the conversion.

Performs the conversion.

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

Drops the object pointed to by the given pointer. Read more

Rotate by the given degree, negative degrees will turn counter-clockwise. Read more

Sample in the given direction. Read more

Sample in the given direction with the given support and kernel function. Read more

Resize to the given width and height. Read more

Scale by the given factor. Read more

Scale to the given width and height, maintaining the aspect ratio. Read more

Sets value as a parameter of self.

Sharpen by the given radius and threshold. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.