Skip to main content

Crate edgefirst_image

Crate edgefirst_image 

Source
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_DISABLE_GL: If set to 1, disables the use of OpenGL for image conversion, forcing the use of CPU or other available hardware methods.
  • EDGEFIRST_DISABLE_G2D: If set to 1, disables the use of G2D for image conversion, forcing the use of CPU or other available hardware methods.
  • EDGEFIRST_DISABLE_CPU: If set to 1, 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 an ImageProcessor.

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
G2DProcessor
G2DConverter implements the ImageProcessor trait using the NXP G2D library for hardware-accelerated image processing on i.MX platforms.
GLProcessorThreaded
OpenGL multi-threaded image converter. The actual conversion is done in a separate rendering thread, as OpenGL contexts are not thread-safe. This can be safely sent between threads. The convert() call sends the conversion request to the rendering thread and waits for the result.
ImageProcessor
Image converter that uses available hardware acceleration or CPU as a fallback.
Rect
TensorImage
An image represented as a tensor with associated format information.
TensorImageRef
A borrowed view of an image tensor for zero-copy preprocessing.

Enums§

Error
Flip
Rotation

Constants§

GREY
8 bit grayscale, full range
NV12
8 bit planar YUV420, limited range
NV16
8 bit planar YUV422, limited range
PLANAR_RGB
PLANAR_RGBA
RGB
8 bit RGB
RGBA
8 bit RGBA
YUYV
8 bit interleaved YUV422, limited range

Traits§

ImageProcessorTrait
TensorImageDst
Trait for types that can be used as destination images for conversion.

Type Aliases§

Result