Expand description
§EdgeFirst HAL - Image Converter
The edgefirst_image crate is part of the EdgeFirst Hardware Abstraction
Layer (HAL) and provides functionality for converting images between
different formats and sizes. The crate is designed to work with hardware
acceleration when available, but also provides a CPU-based fallback for
environments where hardware acceleration is not present or not suitable.
The main features of the edgefirst_image crate include:
- Support for various image formats, including YUYV, RGB, RGBA, and GREY.
- Support for source crop, destination crop, rotation, and flipping.
- Image conversion using hardware acceleration (G2D, OpenGL) when available.
- CPU-based image conversion as a fallback option.
The crate defines a TensorImage struct that represents an image as a
tensor, along with its format information. It also provides an
ImageProcessor struct that manages the conversion process, selecting
the appropriate conversion method based on the available hardware.
§Examples
let image = include_bytes!("../../../testdata/zidane.jpg");
let img = TensorImage::load(image, Some(RGBA), None)?;
let mut converter = ImageProcessor::new()?;
let mut dst = TensorImage::new(640, 480, RGB, None)?;
converter.convert(&img, &mut dst, Rotation::None, Flip::None, Crop::default())?;§Environment Variables
The behavior of the edgefirst_image::ImageProcessor struct can be influenced by the
following environment variables:
EDGEFIRST_FORCE_BACKEND: When set tocpu,g2d, oropengl(case-insensitive), only that single backend is initialized and no fallback chain is used. If the forced backend fails to initialize, an error is returned immediately. This is useful for benchmarking individual backends in isolation. When this variable is set, theEDGEFIRST_DISABLE_*variables are ignored.EDGEFIRST_DISABLE_GL: If set to1, disables the use of OpenGL for image conversion, forcing the use of CPU or other available hardware methods.EDGEFIRST_DISABLE_G2D: If set to1, disables the use of G2D for image conversion, forcing the use of CPU or other available hardware methods.EDGEFIRST_DISABLE_CPU: If set to1, disables the use of CPU for image conversion, forcing the use of hardware acceleration methods. If no hardware acceleration methods are available, an error will be returned when attempting to create anImageProcessor.
Additionally the TensorMemory used by default allocations can be controlled using the
EDGEFIRST_TENSOR_FORCE_MEM environment variable. If set to 1, default tensor memory
uses system memory. This will disable the use of specialized memory regions for tensors
and hardware acceleration. However, this will increase the performance of the CPU converter.
Structs§
- CPUProcessor
- CPUConverter implements the ImageProcessor trait using the fallback CPU implementation for image processing.
- Crop
- Image
Processor - Image converter that uses available hardware acceleration or CPU as a fallback.
- Image
Processor Config - Configuration for
ImageProcessorconstruction. - Mask
Region - Region metadata for a single detection within a compact mask atlas.
- Rect
- Tensor
Image - An image represented as a tensor with associated format information.
- Tensor
Image Ref - A borrowed view of an image tensor for zero-copy preprocessing.
Enums§
Constants§
- BGRA
- 8 bit BGRA (byte order: B, G, R, A). Used by Cairo/Wayland (ARGB32 on little-endian).
- GREY
- 8 bit grayscale, full range
- NV12
- 8 bit planar YUV420, limited range
- NV16
- 8 bit planar YUV422, limited range
- PLANAR_
RGB - PLANAR_
RGBA - PLANAR_
RGB_ INT8 - Planar RGB (channels-first) with uint8→int8 XOR 0x80 reinterpretation.
The underlying bytes are uint8 with MSB flipped; when cast to i8, values
map correctly: uint8 0 → int8 -128, uint8 128 → int8 0, uint8 255 → int8 127.
Tensor shape is
[3, H, W](channels-first). - RGB
- 8 bit RGB
- RGBA
- 8 bit RGBA
- RGB_
INT8 - Packed RGB with uint8→int8 XOR 0x80 reinterpretation. The underlying bytes are uint8 with MSB flipped; when cast to i8, values map correctly: uint8 0 → int8 -128, uint8 128 → int8 0, uint8 255 → int8 127.
- VYUY
- 8 bit interleaved YUV422 (VYUY byte order), limited range
- YUYV
- 8 bit interleaved YUV422, limited range
Traits§
- Image
Processor Trait - Tensor
Image Dst - Trait for types that can be used as destination images for conversion.