Trait img::Image
[−]
[src]
pub trait Image: Clone { type PixelT: Pixel; fn width(&self) -> u32; fn height(&self) -> u32; fn pitch(&self) -> u32; fn get_pixel(&self, x: u32, y: u32) -> Option<Self::PixelT>; fn set_pixel(&mut self, x: u32, y: u32, value: Self::PixelT); fn get_size_in_bytes(&self) -> usize; fn load_from_raw_buffer(&mut self, buffer: &[u8]); fn write_into_raw_buffer(&self, buffer: &mut [u8]); }
Trait which defines the minimum requirements for an image implementation.
It is important to note, that usually you want to use ImageVal
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 an Image
. To store actual values use ImageVal
.
Examples
use img::{Image, ImageVal}; struct Foo<T: Image> { data: ImageVal<T>, };
Associated Types
type PixelT: Pixel
The Pixel
type of this image.
With this information we can statically enforce, that an image is only used with the correct pixel layout.
Required Methods
fn width(&self) -> u32
Returns the width of the image in pixels.
fn height(&self) -> u32
Returns the height of the image in pixels.
fn pitch(&self) -> u32
Returns the pitch of the image in bytes.
fn get_pixel(&self, x: u32, y: u32) -> Option<Self::PixelT>
Retrieve the pixel for a given location (x
, y
).
If an location is accessed which is out of bound, the result will be None
.
fn set_pixel(&mut self, x: u32, y: u32, value: Self::PixelT)
Stores a pixel at a location (x
, y
) in the Image
.
Panics
If the location is out of bounds, this function will panic.
fn get_size_in_bytes(&self) -> usize
Returns the memory size for the whole image in bytes.
fn load_from_raw_buffer(&mut self, buffer: &[u8])
Loads an Image
out of a raw buffer.
This is important for input output functionality.
fn write_into_raw_buffer(&self, buffer: &mut [u8])
Writes an Image
into a raw buffer.
This is important for input output functionality.
Implementors
impl<PixelP> Image for ImageBuffer<PixelP> where
PixelP: Pixel,