Crate image_canvas

Source
Expand description

An opinionated in-memory buffer for image data.

§General Usage

Let us start by creating a simple RgbA buffer. For this we need to:

  1. Specify the texel type with the right depth and channels.
  2. Define the layout, a plain matrix with width and height
  3. Allocate the frame with the layout
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);

Converting to a different color is also possible:

  1. Explicitly assign a fitting Color to source and target
  2. Call the conversion method.
use image_canvas::Canvas;
use image_canvas::color::Color;
use image_canvas::layout::{CanvasLayout, SampleParts, Texel};

let layout = CanvasLayout::with_texel(&Texel::new_u8(SampleParts::Lab), 32, 32)?;
let mut from = Canvas::new(layout.clone());
from.set_color(Color::Oklab)?;

let layout = CanvasLayout::with_texel(&Texel::new_u8(SampleParts::Rgb), 32, 32)?;
let mut into = Canvas::new(layout);
into.set_color(Color::SRGB)?;

// … omitted: some pixel initialization
from.convert(&mut into);

// Now read the sRGB frame, e.g. to initialize an HTTP canvas
into.as_bytes();

Modules§

canvas
color
Putting it all together with a buffer type.
layout
The layout implementation, builders, descriptors. Defines layout and buffer of our images.

Structs§

Canvas
A byte buffer with dynamic color contents.
Converter
State for converting colors between canvas.
ConverterPlaneHandle
An entry of data in a ConverterRun.
ConverterRun
A planner / builder for converting frame colors.
Plane
A byte buffer containing a single plane.

Enums§

ConversionError