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

Raw image data.

The data can be stored in a variety of formats, as represented by the TextureFormat enum.

Supported File Formats

Images can be decoded from various common file formats via the new and from_encoded constructors. Individual decoders can be enabled or disabled via Cargo feature flags.

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

Implementations

Loads image data from the given file.

The format will be determined based on the file extension.

Errors

Creates an ImageData from raw pixel 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

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

Returns the width of the image.

Returns the height of the image.

Returns the size of the image.

Returns the format of the data contained within the image.

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!

Panics

This function will panic if you try to read outside of the image’s bounds.

Creates a new Texture from the stored data.

Errors

Gets the color of the pixel at the specified location.

If the image’s TextureFormat does not contain one of the three color channels, the returned color will have that channel set to zero. Similarly, if the format does not have an alpha channel, the returned color will have an alpha value of one.

Panics

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

Sets the color of the pixel at the specified location.

Any channels of the color that are not supported by the image’s TextureFormat will be ignored. For example, if the image has TextureFormat::R8, only the red channel of the color will be stored.

Panics

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

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

If the image’s TextureFormat does not contain one of the three color channels, the colors provided to the closure will have that channel set to zero. Similarly, if the format does not have an alpha channel, the returned color will have an alpha value of one. The unsupported channels will be ignored when writing back to the image buffer.

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

This can be useful when working with premultiplied alpha blending.

If the image’s data format does not have an alpha component, this function will have no effect.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

Drops the object pointed to by the given pointer. Read more

The resulting type after obtaining ownership.

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

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

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.