Trait img::Pixel
[−]
[src]
pub trait Pixel: Copy + Clone + Debug + PartialEq<Self> { fn calc_minimum_pitch(width: u32, height: u32) -> usize; fn calc_size_in_bytes(width: u32, height: u32, pitch: u32) -> Option<usize>; fn load_from_raw_buffer(x: u32, y: u32, pitch: u32, buffer: &[u8]) -> Self; fn write_into_raw_buffer(
&self,
x: u32,
y: u32,
pitch: u32,
buffer: &mut [u8]
); }
Trait which defines the minimum requirements for a pixel layout implementation.
It is important to note, that usually you want to use PixelVal
instead of directly use this trait. Use this trait directly if you want to describe a type
bound. This is for example necessary if you want to define a type with a parameter,
which has to be a Pixel
. To store actual values use PixelVal
.
Examples
use img::{Pixel, PixelVal}; struct Foo<T: Pixel> { data: PixelVal<T>, };
Required Methods
fn calc_minimum_pitch(width: u32, height: u32) -> usize
For a given image size, this function calculates the minimum pitch in bytes.
Pitch is defined as the size a row in bytes.
Examples
use img::{Pixel, Gray8U, Gray16U, Gray32U}; assert_eq!(Gray8U::calc_minimum_pitch(10, 1), 10); assert_eq!(Gray16U::calc_minimum_pitch(10, 1), 20); assert_eq!(Gray32U::calc_minimum_pitch(10, 1), 40);
fn calc_size_in_bytes(width: u32, height: u32, pitch: u32) -> Option<usize>
For a given image size, this function calculates the image size in bytes.
Because the combination of width
, height
and pitch
is not always valid,
there are cases where the result is None
. A common case for this to happen
is when the given pitch
is smaller than calc_minimum_pitch(width, height)
.
fn load_from_raw_buffer(x: u32, y: u32, pitch: u32, buffer: &[u8]) -> Self
Loads a Pixel
out of a raw buffer.
This is important for input output functionality.
fn write_into_raw_buffer(&self, x: u32, y: u32, pitch: u32, buffer: &mut [u8])
Writes a Pixel
into a raw buffer.
This is important for input output functionality.