Struct riddle_image::Image[][src]

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 load<R: Read>(r: R, format: ImageFormat) -> Result<Self, ImageError>[src]

Load an image from a Read instance which emits image file data in the specified format.

Example

let png_bytes = include_bytes!("../../example_assets/image.png");
let png_img = Image::load(&png_bytes[..], ImageFormat::Png)?;

pub async fn load_async<R>(
    data: R,
    format: ImageFormat
) -> Result<Self, ImageError> where
    R: AsyncRead + Unpin
[src]

Load an image from a AsyncRead instance which emits image file data in the specified format.

Example

let png_bytes = include_bytes!("../../example_assets/image.png");
let png_img = Image::load_async(&png_bytes[..], ImageFormat::Png).await?;

pub fn save<W: Write>(
    &self,
    w: W,
    format: ImageFormat
) -> Result<(), ImageError>
[src]

Save an image to a Write instance, emitting image file data in the specified format.

Example

let img = Image::new(4,4);
let buf: Vec<u8> = vec![];
img.save(buf, ImageFormat::Png)?;

pub fn from_bytes(bytes: &[u8], format: ImageFormat) -> Result<Self, ImageError>[src]

Load an image from a byte slice in the specified format.

Example

let png_bytes = include_bytes!("../../example_assets/image.png");
let png_img = Image::from_bytes(&png_bytes[..], ImageFormat::Png)?;

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<L: Into<Vector2<u32>>>(&self, location: L) -> 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<L: Into<Vector2<u32>>, C: ColorElementConversion<Color<u8>>>(
    &mut self,
    location: L,
    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 copy_rect(&self, source: &Rect<u32>) -> Image[src]

Create a new image containing the contents of some part of the image. The output will be the intersection of the rect provided and the rect enclosing the source image. If the source rect is not completely contained in the image the output image may be smaller than the dimensions of the source rect.

Example

let mut source = Image::new(2,2);
source.fill(Color::<u8>::RED);

let copy = source.copy_rect(&Rect::new([0, 0], [2, 1]));
assert_eq!(Vector2::new(2,1), copy.dimensions());
assert_eq!(Color::<u8>::RED, copy.get_pixel([0, 0]));

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]));

pub fn blit_rect(
    &mut self,
    source: &Image,
    source_rect: &Rect<u32>,
    location: Vector2<i32>
)
[src]

Blit a part of 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(2,2);
source.fill(Color::<u8>::RED);

let mut dest = Image::new(3,3);
dest.fill(Color::<u8>::GREEN);
dest.blit_rect(&source, &Rect::new(Vector2::new(0,0), Vector2::new(2,1)), Vector2::new(0, 0));

assert_eq!(Color::RED, dest.get_pixel([0, 0]));
assert_eq!(Color::GREEN, dest.get_pixel([0, 1]));

pub fn fill_rect<C: ColorElementConversion<Color<u8>>>(
    &mut self,
    rect: Rect<u32>,
    color: C
)
[src]

Fill a rect portion of the image with a given color.

Example

let mut img = Image::new(2,2);
img.fill_rect(Rect::new([0, 0], [2, 1]), Color::<u8>::RED);
img.fill_rect(Rect::new([1, 0], [1, 2]), Color::<u8>::GREEN);

assert_eq!(Color::RED, img.get_pixel([0, 0]));
assert_eq!(Color::ZERO, img.get_pixel([0, 1]));
assert_eq!(Color::GREEN, img.get_pixel([1, 0]));
assert_eq!(Color::GREEN, img.get_pixel([1, 1]));

pub fn fill<C: ColorElementConversion<Color<u8>>>(&mut self, color: C)[src]

Fill the entire image with a certain color.

Example

let mut img = Image::new(2,2);
img.fill(Color::<u8>::RED);

assert_eq!(Color::RED, img.get_pixel([0, 0]));
assert_eq!(Color::RED, img.get_pixel([1, 1]));

Trait Implementations

impl Clone for Image[src]

impl Debug for Image[src]

impl ImageImageExt 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> Pointable for T

type Init = T

The type for initializers.

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.