tpt-cv-core
Zero-copy image buffers, color spaces, and pixel math for the
tpt-cv computer-vision framework.
100% pure Rust, no_std-capable, zero FFI, permissively licensed
(MIT or Apache-2.0). This is the foundation every other tpt-cv crate
builds on.
Why
no_std support is not an afterthought: the core math has no alloc
dependency on the no_std path. Allocating types (owned images, vectors) are
gated behind the alloc/std features, so the same code runs on a bare-metal
microcontroller and in a web browser.
All sample buffers are plain, contiguous, cache-friendly slices. Pipeline
operations take caller-provided destination buffers, so a frame-processing
graph never allocates per frame. Row-pitch (stride) support enables sub-image
views and ROI processing without copying.
Features
| Feature | Default | Description |
|---|---|---|
std |
yes | Enable std-only helpers (e.g. file-backed buffers). |
alloc |
yes | Enable owned buffers (ImageBuf) and allocation-based utilities. |
portable-simd |
no | Nightly-only SIMD fast path. A scalar fallback is always present. |
Build with no_std:
Build for a thumb (bare-metal) target:
Quick start
use ;
use Pixel;
// Borrow an existing byte slice as a 2×1 RGB image.
let data = ;
let img = new.unwrap;
assert_eq!;
// Owned, heap-allocated image (requires `alloc`).
let mut buf = new;
buf.as_image_mut.set_pixel;
assert_eq!;
What's inside
image — zero-copy image buffers
Image<'a, T, C>— immutable borrowed view over a&[T]with row-stride support.sub_image/row/iterare all zero-copy.ImageMut<'a, T, C>— mutable borrowed view; writes into the caller's buffer.ImageBuf<T, C>(alloc) — owned, heap-allocated image that can be created once and reused across frames.- Iterators:
iter(pixels),iter_rows/rows(pixel rows),sub_imagefor ROIs.
pixel — the Sample trait and Pixel<T, C>
Sample is implemented for u8, u16, and f32, providing saturating /
wrapping arithmetic, normalized [0,1] conversions, and per-channel math. The
same generic code works across all three sample types.
color — color-space conversions
RGB↔BGR, RGB↔grayscale, RGB↔HSV, and RGB↔YUV (full-range BT.601). Same-channel
conversions run in place; channel-count changes write into a caller-provided
destination. All math is done in normalized [0,1] space internally, so u8,
u16, and f32 use the same matrices.
use color;
use ;
let mut buf = new;
buf.as_image_mut.set_pixel;
rgb_to_gray;
ops — pixel-wise arithmetic
add_sat / sub_sat / mul_sat, add_wrap / sub_wrap / mul_wrap,
scale_sat / scale_wrap, blend (alpha mix), clamp, and absdiff. All
write into a caller-provided destination and return false on size mismatch.
use ImageBuf;
use ops;
let a = with_value;
let b = with_value;
let mut dst = new;
assert!;
assert_eq!; // saturating, not 260
no_std / WASM / embedded
The crate builds with --no-default-features for no_std targets, and the
full workspace compiles to wasm32-unknown-unknown. The portable-simd
feature requires nightly but degrades to the scalar path on stable.
License
Dual-licensed under MIT OR Apache-2.0. Copyright (c) 2026 TPT Solutions. See LICENSE-MIT and LICENSE-APACHE.