Struct picto::View [−][src]
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
pub fn with_stride(
width: u32,
height: u32,
stride: usize,
data: &mut [C]
) -> Result<View<'_, P, C>, ()>
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
Auto Trait Implementations
impl<'a, P, C> RefUnwindSafe for View<'a, P, C> where
C: RefUnwindSafe,
P: RefUnwindSafe,
impl<'a, P, C> !UnwindSafe for View<'a, P, C>
Blanket Implementations
Mutably borrows from an owned value. Read more
Sample in the given direction. Read more
pub fn sample_with<'o, F, O>(Self, O, Orientation, f32, F) where
F: FnMut(f32) -> f32,
O: Into<Write<'o, PO, CO>>,
pub fn sample_with<'o, F, O>(Self, O, Orientation, f32, F) where
F: FnMut(f32) -> f32,
O: Into<Write<'o, PO, CO>>,
Sample in the given direction with the given support and kernel function. Read more