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
// SPDX-License-Identifier: MIT OR Apache-2.0
//! `tpt-cv-core` — zero-copy image buffers, color spaces, and pixel math.
//!
//! This crate is `no_std` capable: the core math has zero `alloc` dependency in
//! the `no_std` path. Allocating types (owned images, vectors) require the
//! `alloc` or `std` features.
//!
//! # Example
//!
//! ```
//! use tpt_cv_core::image::{Image, ImageBuf};
//! use tpt_cv_core::pixel::Pixel;
//! use tpt_cv_core::ops;
//!
//! // Borrow a byte slice as a 2×1 RGB image (zero-copy).
//! let img = Image::<_, 3>::new(&[10u8, 20, 30, 40, 50, 60], 2, 1).unwrap();
//! assert_eq!(img.pixel(1, 0).channels, [40, 50, 60]);
//!
//! // Owned image + saturating arithmetic into a caller-provided destination.
//! let a = ImageBuf::<u8, 1>::with_value(2, 1, 250);
//! let b = ImageBuf::<u8, 1>::with_value(2, 1, 10);
//! let mut dst = ImageBuf::<u8, 1>::new(2, 1);
//! assert!(ops::add_sat(&a.as_image(), &b.as_image(), &mut dst.as_image_mut()));
//! assert_eq!(dst.as_image().pixel(0, 0).scalar(), 255); // saturating, not 260
//! ```
extern crate alloc;