Struct picto::Buffer
[−]
[src]
pub struct Buffer<C, P, D> where C: Channel, P: Pixel<C> { /* fields omitted */ }
Buffer for an image.
Methods
impl<C, P> Buffer<C, P, Vec<C>> where C: Channel, P: Pixel<C>
[src]
impl<C, P> Buffer<C, P, Vec<C>> where C: Channel, P: Write<C>
[src]
fn from_pixel(width: u32, height: u32, pixel: &P) -> Self
Create a new Buffer
with the request space allocated and filled with
the given pixel.
Example
use picto::Buffer; use picto::color::Rgb; Buffer::<u8, Rgb, _>::from_pixel(1024, 1024, &Rgb::new(1.0, 0.0, 0.0));Run
fn from_fn<T, F>(width: u32, height: u32, func: F) -> Self where T: Into<P>, F: FnMut(u32, u32) -> T
Create a new Buffer
with the request space allocated and filled with
the pixel returned by the given function.
The function takes the coordinates and returns a pixel.
Example
use picto::Buffer; use picto::color::Rgb; Buffer::<u8, Rgb, _>::from_fn(1024, 1024, |x, y| { let w = (x as f32 + y as f32) / 2048.0; Rgb::new(w, w, w) });Run
impl<C, P> Buffer<C, P, Vec<C>> where C: Channel, P: Write<C> + Mix + Clone
[src]
fn from_gradient(width: u32, height: u32, mode: Orientation, gradient: Gradient<P>) -> Self
Create a Buffer
from an orientation and a gradient.
Example
use picto::{Buffer, Orientation}; use picto::color::{Rgb, Gradient}; Buffer::<u8, Rgb, _>::from_gradient(1024, 1024, Orientation::Horizontal, Gradient::new( vec![Rgb::new(0.0, 0.0, 0.0), Rgb::new(1.0, 1.0, 1.0), Rgb::new(0.0, 0.0, 0.0)]));Run
impl<C, P, D> Buffer<C, P, D> where C: Channel, P: Pixel<C>, D: Deref<Target=[C]>
[src]
fn from_raw(width: u32, height: u32, data: D) -> Result<Self, ()>
Use an existing container as backing storage for an image Buffer
.
The size of the storage is compared against the supplied dimensions and
P::channel()
.
Example
use picto::Buffer; use picto::color::Rgb; Buffer::<u8, Rgb, _>::from_raw(2, 2, vec![ 255, 0, 0, 0, 255, 0, 0, 0, 255, 255, 0, 255, ]).unwrap();Run
impl<C, P, D> Buffer<C, P, D> where C: Channel, P: Pixel<C>
[src]
fn into_raw(self) -> D
Get the backing storage of the Buffer
.
fn area(&self) -> Area
Get the Area
of the Buffer
.
fn dimensions(&self) -> (u32, u32)
Get the dimensions as a tuple containing width and height.
fn width(&self) -> u32
Get the width.
fn height(&self) -> u32
Get the height.
impl<C, P, D> Buffer<C, P, D> where C: Channel, P: Read<C>, D: Deref<Target=[C]>
[src]
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 readable(&self, area: Builder) -> Read<C, P>
Get a read-only of the given area.
Panics
Requires that x + width <= self.width()
and y + height <= self.height()
, otherwise it will panic.
fn pixels(&self) -> Pixels<C, P>
Get an immutable Iterator
over the pixels.
fn convert<CO, PO>(&self) -> Buffer<CO, PO, Vec<CO>> where CO: Channel, PO: Write<CO>, P: Into<PO>
Convert the Buffer
to another Buffer
with different channel and pixel type.
Example
use picto::read; use picto::Area; use picto::color::{Rgb, Lumaa}; let image = read::from_path::<u8, Rgb, _>("tests/boat.xyz").unwrap(); // Convert the `Buffer` from Rgb to grayscale with alpha. image.convert::<u8, Lumaa>();Run
impl<C, P, D> Buffer<C, P, D> where C: Channel, P: Write<C>, D: DerefMut<Target=[C]>
[src]
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 writable(&mut self, area: Builder) -> Write<C, P>
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 fill(&mut self, pixel: &P)
impl<C, P, D> Buffer<C, P, D> where C: Channel, P: Write<C> + Read<C>, D: DerefMut<Target=[C]>
[src]
fn view(&mut self, area: Builder) -> View<C, P>
Get a view of the given area.
Panics
Requires that x + width <= self.width()
and y + height <= self.height()
,
otherwise it will panic.
Example
use picto::read; use picto::Area; use picto::color::Rgba; let mut image = read::from_path::<u8, Rgba, _>("tests/boat.xyz").unwrap(); let mut view = image.view(Area::new().x(10).y(10).width(20).height(30)); for (_, _, mut px) in view.pixels_mut() { // Get the current value. let p = px.get(); // Make it opaque. px.set(&Rgba { alpha: 0.5, .. p }); }Run
fn pixels_mut(&mut self) -> PixelsMut<C, P>
Get a mutable Iterator
over the pixels.
Example
use picto::read; use picto::color::{IntoColor, Hue, RgbHue, Rgb}; let mut image = read::from_path::<u8, Rgb, _>("tests/boat.xyz").unwrap(); for (x, y, mut px) in image.pixels_mut() { // Get the pixel value. let p = px.get(); // Convert to HSL and shift the hue. let p = p.into_hsl().shift_hue(RgbHue::from_radians(90.0)); // Set the pixel value. px.set(&p.into()); }Run
Trait Implementations
impl<C: PartialEq, P: PartialEq, D: PartialEq> PartialEq for Buffer<C, P, D> where C: Channel, P: Pixel<C>
[src]
fn eq(&self, __arg_0: &Buffer<C, P, D>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &Buffer<C, P, D>) -> bool
This method tests for !=
.
impl<C: Debug, P: Debug, D: Debug> Debug for Buffer<C, P, D> where C: Channel, P: Pixel<C>
[src]
impl<C, P, D> Deref for Buffer<C, P, D> where C: Channel, P: Pixel<C>, D: Deref<Target=[C]>
[src]
type Target = D::Target
The resulting type after dereferencing
fn deref(&self) -> &Self::Target
The method called to dereference a value
impl<C, P, D> DerefMut for Buffer<C, P, D> where C: Channel, P: Pixel<C>, D: DerefMut<Target=[C]>
[src]
fn deref_mut(&mut self) -> &mut Self::Target
The method called to mutably dereference a value
impl<C, P, D> Clone for Buffer<C, P, D> where C: Channel, P: Pixel<C>, D: Clone
[src]
fn clone(&self) -> Self
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl<CI, PI, DI, CO, PO> Into<CO, PO> for Buffer<CI, PI, DI> where CI: Channel, PI: Read<CI>, DI: Deref<Target=[CI]>, CO: Channel, PO: Write<CO>, PO: From<PI>
[src]
impl<CI, PI, DI, PO> Bytes<PO> for Buffer<CI, PI, DI> where CI: Channel, PI: Read<CI>, PI: Into<PO>, DI: Deref<Target=[CI]>, PO: Write<u8>
[src]
impl<C, P> Shade for Buffer<C, P, Vec<C>> where C: Channel, P: Read<C> + Write<C>, P: Shade
[src]
type Scalar = P::Scalar
The type of the lighten/darken amount.
fn lighten(&self, amount: Self::Scalar) -> Self
Lighten the color by amount
.
fn darken(&self, amount: Self::Scalar) -> Self
Darken the color by amount
.
impl<C, P> Mix for Buffer<C, P, Vec<C>> where C: Channel, P: Read<C> + Write<C>, P: Mix
[src]
type Scalar = P::Scalar
The type of the mixing factor.
fn mix(&self, other: &Self, factor: Self::Scalar) -> Self
Mix the color with an other color, by factor
. Read more
impl<C, P> Limited for Buffer<C, P, Vec<C>> where C: Channel, P: Read<C> + Write<C>, P: Limited
[src]
fn is_valid(&self) -> bool
Check if the color's components are within the expected ranges.
fn clamp(&self) -> Self
Return a new color where the components has been clamped to the nearest valid values. Read more
fn clamp_self(&mut self)
Clamp the color's components to the nearest valid values.
impl<C, P> ComponentWise for Buffer<C, P, Vec<C>> where C: Channel, P: Read<C> + Write<C>, P: ComponentWise
[src]
type Scalar = P::Scalar
The scalar type for color components.
fn component_wise<F>(&self, other: &Self, f: F) -> Self where F: FnMut(Self::Scalar, Self::Scalar) -> Self::Scalar
Perform a binary operation on this and an other color.
fn component_wise_self<F>(&self, f: F) -> Self where F: FnMut(Self::Scalar) -> Self::Scalar
Perform a unary operation on this color.
impl<C, P> Saturate for Buffer<C, P, Vec<C>> where C: Channel, P: Read<C> + Write<C>, P: Saturate
[src]
type Scalar = P::Scalar
The type of the (de)saturation factor.
fn saturate(&self, amount: Self::Scalar) -> Self
Increase the saturation by factor
.
fn desaturate(&self, factor: Self::Scalar) -> Self
Decrease the saturation by factor
.