Skip to main content

tpt_cv_core/
lib.rs

1// SPDX-License-Identifier: MIT OR Apache-2.0
2
3//! `tpt-cv-core` — zero-copy image buffers, color spaces, and pixel math.
4//!
5//! This crate is `no_std` capable: the core math has zero `alloc` dependency in
6//! the `no_std` path. Allocating types (owned images, vectors) require the
7//! `alloc` or `std` features.
8//!
9//! # Example
10//!
11//! ```
12//! use tpt_cv_core::image::{Image, ImageBuf};
13//! use tpt_cv_core::pixel::Pixel;
14//! use tpt_cv_core::ops;
15//!
16//! // Borrow a byte slice as a 2×1 RGB image (zero-copy).
17//! let img = Image::<_, 3>::new(&[10u8, 20, 30, 40, 50, 60], 2, 1).unwrap();
18//! assert_eq!(img.pixel(1, 0).channels, [40, 50, 60]);
19//!
20//! // Owned image + saturating arithmetic into a caller-provided destination.
21//! let a = ImageBuf::<u8, 1>::with_value(2, 1, 250);
22//! let b = ImageBuf::<u8, 1>::with_value(2, 1, 10);
23//! let mut dst = ImageBuf::<u8, 1>::new(2, 1);
24//! assert!(ops::add_sat(&a.as_image(), &b.as_image(), &mut dst.as_image_mut()));
25//! assert_eq!(dst.as_image().pixel(0, 0).scalar(), 255); // saturating, not 260
26//! ```
27
28#![cfg_attr(not(feature = "std"), no_std)]
29#![cfg_attr(feature = "portable-simd", feature(portable_simd))]
30#![deny(missing_docs)]
31#![deny(unsafe_op_in_unsafe_fn)]
32
33extern crate alloc;
34
35pub mod color;
36pub mod image;
37pub mod ops;
38pub mod pixel;