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:
Format | Cargo feature | Enabled by default? |
---|---|---|
PNG | texture_png | Yes |
JPEG | texture_jpeg | Yes |
GIF | texture_gif | Yes |
BMP | texture_bmp | Yes |
TIFF | texture_tiff | No |
TGA | texture_tga | No |
WebP | texture_webp | No |
ICO | texture_ico | No |
PNM | texture_pnm | No |
DDS/DXT | texture_dds | No |
Implementations
Loads image data from the given file.
The format will be determined based on the file extension.
Errors
TetraError::FailedToLoadAsset
will be returned if the file could not be loaded.TetraError::InvalidTexture
will be returned if the image data was invalid.
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
TetraError::InvalidTexture
will be returned if the image data was invalid.
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
TetraError::NotEnoughData
will be returned if not enough data is provided to fill the image.
renamed to from_rgba8 for consistency
Returns the image’s data, as a slice of raw bytes.
Returns the image’s underlying buffer.
Creates a new ImageData
from a region.
This will copy the data into a new buffer - as such, calling this function can be expensive!
Creates a new Texture
from the stored data.
Errors
TetraError::PlatformError
will be returned if the underlying graphics API encounters an error.
Gets the color of the pixel at the specified location.
Panics
Panics if the location is outside the bounds of the image.
Sets the color of the pixel at the specified location.
Panics
Panics if the location is outside the bounds of the image.
Transforms the image data by applying a function to each pixel.
Multiplies the RGB components of each pixel by the alpha component.
This can be useful when working with premultiplied alpha blending.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for ImageData
impl UnwindSafe for ImageData
Blanket Implementations
Mutably borrows from an owned value. Read more