The open imaging DSP library
Loading...
Searching...
No Matches
Data Structures | Functions
mpix/image.h

Main user API. More...

Data Structures

struct  mpix_image
 Represent the image currently being processed. More...
 

Functions

void mpix_image_from_buf (struct mpix_image *img, const uint8_t *buf, size_t size, uint16_t width, uint16_t height, uint32_t format)
 Initialize an image from a memory buffer.
 
int mpix_image_to_buf (struct mpix_image *img, uint8_t *buf, size_t size)
 Convert an image and store it into the output buffer.
 
void mpix_image_free (struct mpix_image *img)
 Free the intermediate buffers of an image.
 
void mpix_image_stats (struct mpix_image *img, struct mpix_stats *stats)
 Collect statistics from an image.
 
int mpix_image_sample_random_rgb (struct mpix_image *img, uint8_t rgb[3])
 Collect a random RGB pixel from an image.
 
int mpix_image_convert (struct mpix_image *img, uint32_t new_format)
 Convert an image to a new pixel format.
 
int mpix_image_palettize (struct mpix_image *img, struct mpix_palette *palette)
 Convert an image to an indexed color format.
 
int mpix_image_depalettize (struct mpix_image *img, struct mpix_palette *palette)
 Convert an image from an indexed color format.
 
void mpix_image_from_palette (struct mpix_image *img, struct mpix_palette *palette)
 Initialize an image from a palette.
 
int mpix_image_to_palette (struct mpix_image *img, struct mpix_palette *palette)
 Convert an image and store it into a color palette.
 
int mpix_image_optimize_palette (struct mpix_image *img, struct mpix_palette *palette, uint16_t num_samples)
 Update the color palette after an input image buffer.
 
int mpix_image_debayer (struct mpix_image *img, uint32_t window_size)
 Convert an image from a bayer array format to RGB24.
 
int mpix_image_qoi_encode (struct mpix_image *img)
 Encode an image to the QOI compressed image format.
 
int mpix_image_jpeg_encode (struct mpix_image *img)
 Encode an image to the JPEG compressed image format.
 
int mpix_image_resize (struct mpix_image *img, enum mpix_resize_type type, uint16_t width, uint16_t height)
 Resize an image.
 
int mpix_image_kernel (struct mpix_image *img, uint32_t kernel_type, int kernel_sz)
 Apply a kernel operation on an image.
 
int mpix_image_correction (struct mpix_image *img, uint32_t type, union mpix_correction_any *corr)
 Apply an Image Signal Processing (ISP) correction operation to an image.
 
void mpix_image_print_truecolor (struct mpix_image *img)
 Print an image using higher quality TRUECOLOR terminal escape codes.
 
void mpix_image_print_256color (struct mpix_image *img)
 Print an image using higher speed 256COLOR terminal escape codes.
 
void mpix_image_print_ops (struct mpix_image *img)
 Print details about an image and its current list of operations.
 
void mpix_image_hexdump (struct mpix_image *img)
 Print a hexdump of the image to the console for debug purpose.
 
int mpix_image_append_op (struct mpix_image *img, const struct mpix_base_op *template, size_t op_sz, size_t buf_sz, size_t threshold)
 Add a operation processing step to an image.
 
int mpix_image_append_uncompressed_op (struct mpix_image *img, const struct mpix_base_op *op, size_t op_sz)
 Add a operation processing step to an image for uncompressed input data.
 
int mpix_image_process (struct mpix_image *img)
 Perform all the processing added to the.
 
int mpix_image_error (struct mpix_image *img, int err)
 Set the error code of the image an error on the image.
 

Detailed Description

Main user API.

SPDX-License-Identifier: Apache-2.0

Function Documentation

◆ mpix_image_convert()

int mpix_image_convert ( struct mpix_image img,
uint32_t  new_format 
)

Convert an image to a new pixel format.

An operation is added to convert the image to a new pixel format. If the operation to convert the image from the current format to a new format does not exist, then the error flag is set, which can be accessed as img->err.

In some cases, converting between two formats requires an intermediate conversion to RGB24.

Parameters
imgImage to convert.
new_formatA four-character-code (FOURCC) as defined by <zephyr/drivers/video.h>.
Returns
0 on success or negative error code.

◆ mpix_image_correction()

int mpix_image_correction ( struct mpix_image img,
uint32_t  type,
union mpix_correction_any corr 
)

Apply an Image Signal Processing (ISP) correction operation to an image.

Kernel operations are working on small blocks of typically 3x3 or 5x5 pixels, repeated over the entire image to apply a desired effect on an image.

Parameters
imgImage to convert.
typeThe type of ISP to apply as defined in mpix/op_correction.h
corrThe correction level to apply.
Returns
0 on success or negative error code.

◆ mpix_image_debayer()

int mpix_image_debayer ( struct mpix_image img,
uint32_t  window_size 
)

Convert an image from a bayer array format to RGB24.

An operation is added to convert the image to RGB24 using the specified window size, such as 2x2 or 3x3.

Note
It is also possible to use mpix_image_convert to convert from bayer to RGB24 but this does not allow to select the window size.
Parameters
imgImage to convert.
window_sizeThe window size for the conversion, usually 2 (faster) or 3 (higher quality).
Returns
0 on success or negative error code.

◆ mpix_image_depalettize()

int mpix_image_depalettize ( struct mpix_image img,
struct mpix_palette palette 
)

Convert an image from an indexed color format.

An operation is added to convert the image from an indexed pixel format given the input palette.

If the palette has up to 2 colors, 8 pixels are packed per byte. If the palette has up to 4 colors, 4 pixels are packed per byte. If the palette has up to 16 colors, 2 pixels are packed per byte. If the palette has up to 256 colors, 1 pixels are packed per byte.

Parameters
imgImage to convert.
paletteThe color palette to use for the conversion.
Returns
0 on success or negative error code.

◆ mpix_image_free()

void mpix_image_free ( struct mpix_image img)

Free the intermediate buffers of an image.

This is only required if not calling any export funcitons such as mpix_image_to_buf.

Parameters
imgImage for which to release resources. Only internal buffers are freed.

◆ mpix_image_from_buf()

void mpix_image_from_buf ( struct mpix_image img,
const uint8_t *  buf,
size_t  size,
uint16_t  width,
uint16_t  height,
uint32_t  format 
)

Initialize an image from a memory buffer.

Parameters
imgImage to initialize.
bufMemory containinig input image data to process.
sizeTotal available size in the buffer, can be bigger/smaller than full width x height.
widthWidth of the complete image in pixels.
heightHeight of the complete image in pixels.
formatFormat of data in the buffer as a four-character-code.

◆ mpix_image_from_palette()

void mpix_image_from_palette ( struct mpix_image img,
struct mpix_palette palette 
)

Initialize an image from a palette.

This permits to process a color palette as if it was an RGB24 image, which leads to far fewer data to process than the full frame.

Parameters
imgImage to convert.
paletteThe color palette to use for the conversion.

◆ mpix_image_hexdump()

void mpix_image_hexdump ( struct mpix_image img)

Print a hexdump of the image to the console for debug purpose.

Parameters
imgImage to print.

◆ mpix_image_jpeg_encode()

int mpix_image_jpeg_encode ( struct mpix_image img)

Encode an image to the JPEG compressed image format.

Note
This is a placeholder and implementation is still in progress
Parameters
imgImage to convert to JPEG format.
Returns
0 on success or negative error code.

◆ mpix_image_kernel()

int mpix_image_kernel ( struct mpix_image img,
uint32_t  kernel_type,
int  kernel_sz 
)

Apply a kernel operation on an image.

Kernel operations are working on small blocks of typically 3x3 or 5x5 pixels, repeated over the entire image to apply a desired effect on an image.

Parameters
imgImage to convert.
kernel_typeThe type of kernel to apply as defined in mpix/op_kernel.h
kernel_szThe size of the kernel operaiton, usually 3 or 5.
Returns
0 on success or negative error code.

◆ mpix_image_optimize_palette()

int mpix_image_optimize_palette ( struct mpix_image img,
struct mpix_palette palette,
uint16_t  num_samples 
)

Update the color palette after an input image buffer.

This is performed on the original input image rather than the current state of the image. The strategy used is the "naive k-mean", and only a single pass. Repeat the function several times to improve accuracy.

Parameters
imgInput image sampled to generate the palette.
paletteThe palette that will be updated with colors fitting the image better.
num_samplesNumber of samples to take from the input image.
Returns
0 on success or negative error code.

◆ mpix_image_palettize()

int mpix_image_palettize ( struct mpix_image img,
struct mpix_palette palette 
)

Convert an image to an indexed color format.

An operation is added to convert the image to an indexed pixel format given the input palette.

If the palette has up to 2 colors, 8 pixels are packed per byte. If the palette has up to 4 colors, 4 pixels are packed per byte. If the palette has up to 16 colors, 2 pixels are packed per byte. If the palette has up to 256 colors, 1 pixels are packed per byte.

Parameters
imgImage to convert.
paletteThe color palette to use for the conversion.
Returns
0 on success or negative error code.

◆ mpix_image_print_256color()

void mpix_image_print_256color ( struct mpix_image img)

Print an image using higher speed 256COLOR terminal escape codes.

Parameters
imgImage to print.

◆ mpix_image_print_ops()

void mpix_image_print_ops ( struct mpix_image img)

Print details about an image and its current list of operations.

Parameters
imgImage to detail.

◆ mpix_image_print_truecolor()

void mpix_image_print_truecolor ( struct mpix_image img)

Print an image using higher quality TRUECOLOR terminal escape codes.

Parameters
imgImage to print.

◆ mpix_image_qoi_encode()

int mpix_image_qoi_encode ( struct mpix_image img)

Encode an image to the QOI compressed image format.

Parameters
imgImage to convert to QOI format.
Returns
0 on success or negative error code.

◆ mpix_image_resize()

int mpix_image_resize ( struct mpix_image img,
enum mpix_resize_type  type,
uint16_t  width,
uint16_t  height 
)

Resize an image.

An operation is added to change the image size. The aspect ratio is not preserved and the output image size is exactly the same as requested.

Parameters
imgImage to convert.
typeType of image resizing to apply.
widthThe new width in pixels.
heightThe new height in pixels.
Returns
0 on success or negative error code.

◆ mpix_image_sample_random_rgb()

int mpix_image_sample_random_rgb ( struct mpix_image img,
uint8_t  rgb[3] 
)

Collect a random RGB pixel from an image.

The image can have any format from this list:

Parameters
imgImage to sample a value from.
rgbBuffer to 3 bytes filled with the red, green, blue value from the image.

◆ mpix_image_stats()

void mpix_image_stats ( struct mpix_image img,
struct mpix_stats stats 
)

Collect statistics from an image.

The image buffer is used to collect statistics into a stats structure.

If the stats field nval is non-zero, this number of pixels will be collected randomly from the image to generate statistics such as histogram and .

Parameters
imgImage to convert.
statsStatistics filled from the image.

◆ mpix_image_to_buf()

int mpix_image_to_buf ( struct mpix_image img,
uint8_t *  buf,
size_t  size 
)

Convert an image and store it into the output buffer.

Parameters
imgImage being processed.
bufMemory that receives the image data.
sizeSize of the buffer.
Returns
0 on success or negative error code.

◆ mpix_image_to_palette()

int mpix_image_to_palette ( struct mpix_image img,
struct mpix_palette palette 
)

Convert an image and store it into a color palette.

This is the reciproqual operation from mpix_image_from_palette.

Parameters
imgImage being processed.
paletteThe color palette to use for the conversion.
Returns
0 on success or negative error code.