zenpixels_convert/lib.rs
1//! # zenpixels-convert 0.5 — Pixel Conversion Engine
2//!
3//! Composable, `no_std + alloc` (disable default `std` feature), `#![forbid(unsafe_code)]`
4//! pixel conversion, HDR tone mapping, gamut compression, ICC/CMS routing, gain-map
5//! reconstruction, EXIF orientation, planar YCbCr/RGB/monochrome reconstruction, and codec
6//! format negotiation for [`zenpixels`].
7//!
8//! Re-exports the entire [`zenpixels`] core surface (`pub use zenpixels::*;`) at
9//! the crate root without shadowing a single module name.
10//!
11//! ## Which Entry Point Should I Use?
12//!
13//! - **Unified one-shot conversion (recommended):** [`ImagePlan::convert`],
14//! [`ImagePlan::convert_into`], [`ImagePlan::to_rgba8`], [`ImagePlan::to_rgb8_if_opaque`],
15//! [`ImagePlan::to_gray8_if_opaque`], [`ImagePlan::to_bgra8`] — or the matching method syntax
16//! via [`PixelConvertExt`] (`src.convert_to(...)`, `src.convert_into(&mut dst, ...)`,
17//! `src.to_rgba8()`, etc.). Works uniformly on [`PixelBuf`], [`PixelView`], and [`BandedBuf`]
18//! without `.as_view()` and with zero monomorphization bloat across carrier combinations.
19//! Defaults to [`PeakSource::Measured`] only when HDR tone mapping needs a peak; use
20//! `*_with_peak` for explicit [`PeakSource`].
21//! - **Sample claims & checks:** [`PixelScanExt::measure_claims`] scans a buffer or view. The
22//! carrier's `attached_claims()` accessor reads the claims already attached to it.
23//! [`PixelScanExt::measure_and_attach_claims`] refreshes those claims in place;
24//! [`PixelScanExt::check_nominal_samples`] and [`PixelScanExt::check_samples`] locate
25//! out-of-bounds samples.
26//! - **Reusable image plan:** [`ImagePlan::build`] (accepts [`PeakSource`], works on
27//! [`PixelView`], [`PixelBuf`], and [`BandedBuf`]).
28//! - **Streaming row loop (zero heap scratch):** [`RowPlan::build`] (accepts
29//! resolved `Option<Nits>` and executes rows via `convert_row` / `convert_row_at`).
30//! - **Planar YCbCr / GBR / RGB / monochrome reconstruction:**
31//! [`PlanarConvertExt`] on [`PlanarView`].
32//! - **ISO 21496-1 / UltraHDR gain maps (`gainmap` feature):**
33//! `gainmap::apply_gain_map_with`, `gainmap::extract_gain_map_only`,
34//! `gainmap::GainMapApplier`, `gainmap::GainMapRowExtractor`.
35//! - **Content compaction:** [`CompactionReport::measure`], [`compact_to_buf`], [`compact_in_place`].
36//! - **Encoder output + CICP/ICC signaling:** [`OutputPlan::adapt_for_encode`] or
37//! reusable [`OutputPlan::build`] with [`OutputSignaling`].
38//!
39//! [`ConvertPolicy::default()`] equals [`ConvertPolicy::lossless()`], a strict permission
40//! preset that forbids lossy depth, gamut, range, and alpha changes. Opt in explicitly to
41//! [`ConvertPolicy::permissive()`], [`ConvertPolicy::working_linear()`], or
42//! [`ConvertPolicy::display_sdr`] when lossy conversion is desired.
43//!
44//! ## Quick Example
45//!
46//! ```rust
47//! use zenpixels_convert::{ConvertPolicy, PixelBuf, PixelConvertExt, PixelFormat, formats};
48//!
49//! let src = PixelBuf::from_typed(vec![255u8, 0, 0, 0, 255, 0], 2, 1, PixelFormat::RGB8_SRGB)?;
50//! let linear = src.convert_to(&formats::RGBF32_LINEAR, &ConvertPolicy::lossless())?;
51//! assert_eq!(linear.format(), &formats::RGBF32_LINEAR);
52//! # Ok::<(), Box<dyn std::error::Error>>(())
53//! ```
54//!
55//! ## Opt-in SIMD (`const` [`Accelerators`])
56//!
57//! Native pairs default to a compact scalar core with verified 0-bit parity
58//! against SIMD kernels. Use [`Accelerators::install_global`] to install a bundle
59//! process-wide, or [`ConvertPolicy::with_accelerators`] to set it per policy.
60
61#![cfg_attr(not(test), no_std)]
62#![forbid(unsafe_code)]
63
64extern crate alloc;
65
66whereat::define_at_crate_info!(path = "zenpixels-convert/");
67
68/// Full re-export of [`zenpixels`] core types (zero module name collisions!).
69pub use zenpixels::*;
70
71pub mod accelerators;
72pub mod cms;
73pub mod codes;
74pub mod compact;
75pub mod error;
76pub(crate) mod f16_scalar;
77#[cfg(feature = "gainmap")]
78pub mod gainmap;
79#[cfg(feature = "gainmap")]
80pub(crate) mod gainmap_simd;
81pub mod gamut;
82#[cfg(feature = "hdr-transfers")]
83pub(crate) mod hlg_render;
84pub mod icc_profiles;
85pub mod measure;
86pub mod negotiate;
87#[cfg(feature = "oklab")]
88pub mod oklab;
89pub mod orient;
90pub mod output;
91#[cfg(feature = "perceptual")]
92pub mod perceptual;
93pub mod plan;
94pub mod planar;
95pub mod planar_capture;
96pub mod policy;
97pub(crate) mod pulse;
98pub mod scan;
99pub(crate) mod strip;
100pub(crate) mod strip_simd;
101pub mod tonemap;
102pub(crate) mod transfers;
103pub mod ycbcr;
104
105// Ergonomic top-level re-exports.
106pub use accelerators::Accelerators;
107#[cfg(feature = "cms-moxcms")]
108pub use cms::MoxCms;
109pub use cms::{CmsBackend, CmsBinding, CmsChoice, CmsQuote, CmsTransform, ColorServices};
110#[cfg(feature = "cms-lcms")]
111pub use cms::{Lcms, LcmsUnoptimized};
112pub use codes::{CodeMap, CodeMapError, CodeRole, CodesError, unpack_code_planes_into};
113pub use compact::{
114 AlphaCompaction, CompactOutcome, CompactionReport, compact_in_place,
115 compact_in_place_with_pulse, compact_to_buf, compact_to_buf_with_pulse,
116};
117pub use enough::{AsStopReason, Stop, StopReason, Unstoppable};
118pub use error::ConvertError;
119pub use gamut::GamutMatrix;
120pub use how_far::{NoPulse, Pulse, StopOnly};
121pub use measure::{
122 LightLevelHistogram, LightLevelMethod, measure_content_light_level,
123 measure_content_light_level_with_pulse, measure_histogram, measure_histogram_with_pulse,
124 measure_max_smoothed, measure_max_smoothed_with_pulse, measure_peak, measure_peak_with_pulse,
125};
126pub use negotiate::{FormatCost, LossKind, Negotiate, NegotiatedFormat};
127pub use orient::{
128 apply_orientation, apply_orientation_banded, apply_orientation_banded_into,
129 apply_orientation_banded_into_with_pulse, apply_orientation_banded_with_pulse,
130 apply_orientation_into, apply_orientation_into_with_pulse, apply_orientation_owned,
131 apply_orientation_owned_with_pulse, apply_orientation_with_pulse, bake_orientation,
132 bake_orientation_banded, bake_orientation_owned,
133};
134pub use output::{EncodeReady, OutputPlan, OutputSignaling, ResolvedSignaling};
135pub use plan::{ImagePlan, PixelConvertExt, RowPlan};
136pub use planar::{
137 ChromaUpsample, PlanarConvertExt, PlanarReconstructionOptions, reconstruct_planar_f32,
138 reconstruct_planar_f32_with_pulse, reconstruct_planar_into, reconstruct_planar_into_with_pulse,
139 reconstruct_planar_to_buf, reconstruct_planar_to_buf_with_pulse,
140};
141pub use planar_capture::{
142 CaptureScratch, ChromaDownsample, PlanarCaptureOptions, PlanarCapturePlan, PlanarCaptureSpec,
143};
144pub use policy::{
145 AlphaPolicy, ConvertPolicy, DepthPolicy, GamutPolicy, LumaCoefficients, LumaDomain, RangePolicy,
146};
147pub use scan::{
148 ClaimVerificationError, PixelCheckError, PixelScanExt, SampleBounds, SampleValidationError,
149};
150#[cfg(feature = "oklab")]
151pub use tonemap::SoftCompress;
152#[cfg(feature = "bt2446a")]
153pub use tonemap::{Bt2446A, Bt2446APipelineManaged};
154pub use tonemap::{PreparedMapper, Requirements, StripMapper, ToneMapContext, ToneMapper};
155pub use ycbcr::YcbcrMatrix;