[][src]Struct riddle_image::Image

pub struct Image { /* fields omitted */ }

A representation of an image stored in main memory. The image is stored as RGBA32.

Implementations

impl Image[src]

pub fn new_from_png<R: Read + Seek>(r: R) -> Result<Self, ImageError>[src]

Load an image from a Read + Seek instance which emits png file data.

Example

let png_bytes = include_bytes!("../../example_assets/image.png");
let png_img = Image::new_from_png(std::io::Cursor::new(&png_bytes[..]))?;

pub fn new(width: u32, height: u32) -> Self[src]

Create a new image with the given dimensions, all pixels are initialized to 0x00000000.

Example

// Create a single pixel image
let img = Image::new(1,1);

pub fn get_pixel(&self, x: u32, y: u32) -> Color<u8>[src]

Get the color of the pixel at the given coordinates

Example

let img = Image::new(1,1);
assert_eq!(Color::rgba(0,0,0,0), img.get_pixel(0, 0));

pub fn set_pixel<C: ColorElementConversion<Color<u8>>>(
    &mut self,
    x: u32,
    y: u32,
    color: C
)
[src]

Set the color of the pixel at the given coordinates

Example

let mut img = Image::new(1,1);
img.set_pixel(0, 0, Color::rgba(1.0, 0.0, 0.0, 1.0));
assert_eq!(Color::rgba(255,0,0,255), img.get_pixel(0, 0));

pub fn as_rgba8(&self) -> &[u8][src]

Borrow the bytes representing the entire image, encoded as RGBA8

Example

let img = Image::new(1,1);
assert_eq!(0x00u8, img.as_rgba8()[0]);

pub fn as_rgba8_mut(&mut self) -> &mut [u8][src]

Mutably borrow the bytes representing the entire image, encoded as RGBA8

Example

let mut img = Image::new(1,1);
let bytes = img.as_rgba8_mut();
bytes[0] = 0xFF;
assert_eq!(Color::rgba(255, 0, 0, 0), img.get_pixel(0,0));

pub fn byte_count(&self) -> usize[src]

Get the byte count of the entire image encoded as RGBA8

Example

let img = Image::new(1,1);
assert_eq!(4, img.byte_count());

pub fn width(&self) -> u32[src]

Width of the image in pixels

Example

let img = Image::new(1,1);
assert_eq!(1, img.width());

pub fn height(&self) -> u32[src]

Height of the image in pixels

Example

let img = Image::new(1,1);
assert_eq!(1, img.height());

pub fn dimensions(&self) -> Vector2<u32>[src]

Dimension of the image in pixels

Example

let img = Image::new(1,1);
assert_eq!(Vector2::new(1, 1), img.dimensions());

pub fn rect(&self) -> Rect<u32>[src]

Get the bounding rect for the image, located at (0,0) and having size equal to the image's dimensions.

Example

let img = Image::new(1,1);
assert_eq!(Rect::new(Vector2::new(0, 0), Vector2::new(1, 1)), img.rect());

pub fn blit(&mut self, source: &Image, location: Vector2<i32>)[src]

Blit another image on to self. The location is the relative offset of the (0,0) pixel of the source image relative to self's (0,0) pixel.

Example

let mut source = Image::new(1,1);
source.set_pixel(0, 0, Color::<u8>::RED);

let mut dest = Image::new(2,1);
dest.blit(&source, Vector2::new(1, 0));

assert_eq!(Color::ZERO, dest.get_pixel(0,0));
assert_eq!(Color::RED, dest.get_pixel(1, 0));

Trait Implementations

impl Clone for Image[src]

Auto Trait Implementations

impl RefUnwindSafe for Image

impl Send for Image

impl Sync for Image

impl Unpin for Image

impl UnwindSafe for Image

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> SetParameter for T

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.