Struct tetra::graphics::ImageData[][src]

pub struct ImageData { /* fields omitted */ }
Expand description

Raw image data.

Supported Formats

Various file formats are supported, and can be enabled or disabled via Cargo features:

FormatCargo featureEnabled by default?
PNGtexture_pngYes
JPEGtexture_jpegYes
GIFtexture_gifYes
BMPtexture_bmpYes
TIFFtexture_tiffNo
TGAtexture_tgaNo
WebPtexture_webpNo
ICOtexture_icoNo
PNMtexture_pnmNo
DDS/DXTtexture_ddsNo

Performance

Creating or cloning an ImageData is a relatively expensive operation. If you can, store them in your State struct rather than recreating them each frame.

Implementations

impl ImageData[src]

pub fn from_file<P>(path: P) -> Result<ImageData> where
    P: AsRef<Path>, 
[src]

Loads image data from the given file.

The format will be determined based on the file extension.

Errors

pub fn from_file_data(data: &[u8]) -> Result<ImageData>[src]

Decodes image data that is encoded in one of Tetra’s supported file formats (except for TGA).

This is useful in combination with include_bytes, as it allows you to include your image data directly in the binary.

The format will be determined based on the ‘magic bytes’ at the beginning of the data. Note that TGA files do not have recognizable magic bytes, so this function will not recognize them.

Errors

pub fn from_rgba8<D>(width: i32, height: i32, data: D) -> Result<ImageData> where
    D: Into<Vec<u8>>, 
[src]

Creates an ImageData from raw RGBA8 data.

This function takes Into<Vec<u8>>. If you pass a Vec<u8>, that Vec will be reused for the created ImageData without reallocating. Otherwise, the data will be copied.

This function requires you to provide enough data to fill the image’s bounds. If you provide too little data, an error will be returned. If you provide too much data, it will be truncated.

Errors

pub fn from_rgba<D>(width: i32, height: i32, data: D) -> Result<ImageData> where
    D: Into<Vec<u8>>, 
[src]

👎 Deprecated since 0.6.4:

renamed to from_rgba8 for consistency

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

Returns the width of the image.

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

Returns the height of the image.

pub fn size(&self) -> (i32, i32)[src]

Returns the size of the image.

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

Returns the image’s data, as a slice of raw bytes.

pub fn into_bytes(self) -> Vec<u8>[src]

Returns the image’s underlying buffer.

pub fn region(&self, region: Rectangle<i32>) -> ImageData[src]

Creates a new ImageData from a region.

This will copy the data into a new buffer - as such, calling this function can be expensive!

pub fn to_texture(&self, ctx: &mut Context) -> Result<Texture>[src]

Creates a new Texture from the stored data.

Errors

pub fn get_pixel_color(&self, position: Vec2<i32>) -> Color[src]

Gets the color of the pixel at the specified location.

Panics

Panics if the location is outside the bounds of the image.

pub fn set_pixel_color(&mut self, position: Vec2<i32>, color: Color)[src]

Sets the color of the pixel at the specified location.

Panics

Panics if the location is outside the bounds of the image.

pub fn transform<F>(&mut self, func: F) where
    F: FnMut(Vec2<i32>, Color) -> Color
[src]

Transforms the image data by applying a function to each pixel.

pub fn premultiply(&mut self)[src]

Multiplies the RGB components of each pixel by the alpha component.

This can be useful when working with premultiplied alpha blending.

Trait Implementations

impl Clone for ImageData[src]

fn clone(&self) -> ImageData[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Debug for ImageData[src]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

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

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

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

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

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

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

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

pub fn from(t: T) -> T[src]

Performs the conversion.

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

pub fn into(self) -> U[src]

Performs the conversion.

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

type Owned = T

The resulting type after obtaining ownership.

pub fn to_owned(&self) -> T[src]

Creates owned data from borrowed data, usually by cloning. Read more

pub fn clone_into(&self, target: &mut T)[src]

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

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.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

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.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.