1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
//! A color-accurate software frame buffer.
//!
//! Please note, color is a work-in-progress with spotty support. See all locations marked with
//! `FIXME(color):` for progress. See `FIXME(perf)` for known suboptimal performance.
//!
//! Separately, planar support is also a work-in-progress. See `FIXME(planar)` for progress.
//!
//! # Usage
//!
//! Creating a simple RgbA frame buffer is as a easy as:
//! 1. Specifying a texel with the right depth and channels
//! 2. Defining the layout, with width and height
//! 3. Allocating the frame utilizing 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);
//! # use image_canvas::layout::LayoutError;
//! # Ok::<(), LayoutError>(())
//! ```
//!
//! 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();
//!
//! # use image_canvas::layout::LayoutError;
//! # Ok::<(), LayoutError>(())
//! ```
// Deny, not forbid, unsafe code. In `arch` module we have inherently unsafe code, for the moment.
// Maybe at a future point we gain some possibility to write such code safely.
#![deny(unsafe_code)]
mod arch;
mod bits;
/// Putting it all together with a buffer type.
pub mod color;
mod color_matrix;
/// The main frame module.
mod frame;
/// The layout implementation, builders, descriptors.
pub mod layout;
/// Conversion operation.
mod shader;
#[cfg(test)]
mod tests;
pub use self::frame::{Canvas, Plane};
pub mod canvas {
pub use crate::frame::{
BytePlaneMut, BytePlaneRef, BytePlaneRef as BytePlane, ChannelsMut, ChannelsRef, PlaneMut,
PlaneRef,
};
}
#[doc(hidden)]
pub use self::canvas::{PlaneMut, PlaneRef};