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

A byte buffer with dynamic color contents.

Implementations

Create a frame by its layout.

Usage
use image_canvas::Canvas;
use image_canvas::layout::{CanvasLayout, SampleParts, Texel};

// Define what type of color we want to store...
let texel = Texel::new_u8(SampleParts::RgbA);
// and which dimensions to use, chooses a stride for us.
let layout = CanvasLayout::with_texel(&texel, 32, 32)?;

let frame = Canvas::new(layout);

Get a reference to the layout of this frame.

Overwrite the layout, allocate if necessary, and clear the image.

Overwrite the layout, allocate if necessary, do not clear the image.

Return this image’s pixels as a native endian byte slice.

See also Self::as_bytes_mut.

Return this image’s pixels as a mutable native endian byte slice.

The exact interpretation of each byte depends on the layout, which also contains a descriptor of the color types used. This method is for purposes of foreign-function interfaces and as a fallback to process bytes regardless of any restrictions placed by the limits of what other methods are offered.

Mind that the library guarantees that the byte slice is actually aligned with an alignment larger than 1. The exact details depend on the underlying platform but are at least 8.

Still, do not write uninitialized bytes to the buffer. This is UB by Rust’s semantics. (Writing into the buffer by syscalls or assembly most likely never counts as writing uninitialized bytes but take this with a grain of salt).

Return the bytes making up this image as a slice of arbitrary elements.

Return the bytes making up this image as a slice of arbitrary elements.

Get the matrix-like channel descriptor if the channels are u8.

Returns Some only when texel is some multiple of u8.

Get the matrix-like channel descriptor if the channels are u16.

Returns Some only when texel is some multiple of u16.

Get the matrix-like channel descriptor if the channels are f32.

Returns Some only when texel is some multiple of f32.

Get the matrix-like channel descriptor if the channels are u8.

Returns Some only when texel is some multiple of u8.

Get the matrix-like channel descriptor if the channels are u16.

Returns Some only when texel is some multiple of u16.

Get the matrix-like channel descriptor if the channels are f32.

Returns Some only when texel is some multiple of f32.

Return this image’s pixels as a byte vector.

Get the untyped descriptor of the texel matrix.

Returns None if the image contains data that can not be described as a single texel plane, e.g. multiple planes or if the plane is not a matrix.

Get references to multiple planes at the same time.

Get the untyped, mutable reference to the texel matrix.

Returns None if the image contains data that can not be described as a single texel plane, e.g. multiple planes or if the plane is not a matrix.

Get mutable references to multiple planes at the same time.

This works because planes never overlap. Note that all planes are aligned to the same byte boundary as the complete canvas bytes.

Set the color model.

This never changes the physical layout of data and preserves all its bits. It returns an error if the new color is not compatible with the texel’s color channels.

Conversion related methods.

Write into another frame, converting color representation between.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Converts to this type from the input type.

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 resulting type after obtaining ownership.

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

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.