Skip to main content

zenpixels/
lib.rs

1//! Pixel format interchange types for Rust image codecs.
2//!
3//! This crate provides the type system for describing pixel data: what the
4//! bytes are ([`PixelFormat`]), what they mean ([`PixelDescriptor`]), and where
5//! they live ([`PixelBuffer`], [`PixelSlice`], [`PixelSliceMut`]).
6//!
7//! No conversion logic lives here. For transfer-function-aware conversion,
8//! gamut mapping, and codec format negotiation, see
9//! [`zenpixels-convert`](https://docs.rs/zenpixels-convert).
10//!
11//! # Core types
12//!
13//! - [`PixelFormat`] — flat enum of byte layouts (`Rgb8`, `Rgba16`, `OklabF32`, etc.)
14//! - [`PixelDescriptor`] — format + transfer function + primaries + alpha mode + signal range
15//! - [`PixelBuffer`] — owned pixel storage with SIMD-aligned allocation
16//! - [`PixelSlice`] / [`PixelSliceMut`] — borrowed views with stride support
17//! - [`Pixel`] — trait mapping concrete types to their descriptor
18//! - [`Cicp`] — ITU-T H.273 color signaling codes
19//! - [`ColorContext`] — ICC profile bytes and/or CICP, `Arc`-shared
20//! - [`ConvertOptions`] — policies for lossy operations (alpha removal, depth reduction)
21//!
22//! # Feature flags
23//!
24//! | Feature | What it enables |
25//! |---------|----------------|
26//! | `std` | Standard library (default; currently a no-op, everything is `no_std + alloc`) |
27//! | `rgb` | [`Pixel`] impls for `rgb` crate types, typed `from_pixels()` constructors |
28//! | `imgref` | `From<ImgRef>` / `From<ImgVec>` conversions (implies `rgb`) |
29//! | `planar` | Multi-plane image types (YCbCr, Oklab, gain maps) |
30
31#![cfg_attr(not(feature = "std"), no_std)]
32#![forbid(unsafe_code)]
33
34extern crate alloc;
35
36whereat::define_at_crate_info!(path = "zenpixels/");
37
38pub mod descriptor;
39pub mod orientation;
40#[cfg(feature = "planar")]
41pub mod planar;
42pub mod policy;
43
44pub mod cicp;
45pub mod color;
46pub mod hdr;
47#[cfg(feature = "icc")]
48pub mod icc;
49pub mod pixel_types;
50pub(crate) mod registry;
51
52pub mod buffer;
53
54// Re-export orientation type at crate root.
55pub use orientation::Orientation;
56
57// Re-export key descriptor types at crate root for ergonomics.
58pub use descriptor::{
59    AlphaMode, ByteOrder, ChannelLayout, ChannelType, ColorModel, ColorPrimaries, PixelDescriptor,
60    PixelFormat, SignalRange, TransferFunction,
61};
62
63// Re-export planar types when the `planar` feature is enabled.
64#[cfg(feature = "planar")]
65pub use planar::{
66    MultiPlaneImage, Plane, PlaneDescriptor, PlaneLayout, PlaneMask, PlaneRelationship,
67    PlaneSemantic, Subsampling, YuvMatrix,
68};
69
70// Re-export buffer types at crate root.
71pub use buffer::{Bgrx, BufferError, Pixel, PixelBuffer, PixelSlice, PixelSliceMut, Rgbx};
72
73// Re-export color types at crate root.
74pub use cicp::Cicp;
75pub use color::{
76    ColorAuthority, ColorContext, ColorOrigin, ColorProfileSource, ColorProvenance, NamedProfile,
77};
78
79// Re-export HDR metadata types at crate root.
80pub use hdr::{ContentLightLevel, MasteringDisplay};
81
82// Re-export GrayAlpha pixel types at crate root.
83pub use pixel_types::{GrayAlpha8, GrayAlpha16, GrayAlphaF32};
84
85pub use policy::{AlphaPolicy, ConvertOptions, DepthPolicy, GrayExpand, LumaCoefficients};
86
87// Re-export whereat types for error tracing.
88pub use whereat::{At, ResultAtExt, at};