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

Main user API. More...

Functions

static void mpix_image_from_buf (struct mpix_image *img, const uint8_t *buffer, size_t size, const struct mpix_format *fmt)
 Initialize an image from a memory buffer.
 
static int mpix_image_to_buf (struct mpix_image *img, uint8_t *buffer, size_t size)
 Convert an image and store it into the output buffer.
 
static int mpix_image_convert (struct mpix_image *img, uint32_t new_format)
 Convert an image to a new pixel format.
 
static int mpix_image_palette_encode (struct mpix_image *img, uint32_t fourcc)
 Convert an image to an indexed color format.
 
static int mpix_image_palette_decode (struct mpix_image *img)
 Convert an image from an indexed color format.
 
static int mpix_image_set_palette (struct mpix_image *img, struct mpix_palette *palette)
 Set the palette of every operation currently in the pipeline.
 
static int mpix_image_debayer (struct mpix_image *img, uint32_t window_size)
 Convert an image from a bayer array format to RGB24.
 
static int mpix_image_correct_color_matrix (struct mpix_image *img)
 Apply Color Correction Matrix (CCM) to the image.
 
static int mpix_image_correct_white_balance (struct mpix_image *img)
 Apply White Balance Correction (AWB) to the image.
 
static int mpix_image_correct_black_level (struct mpix_image *img)
 Apply Black Level Correction (BLC) to the image.
 
static int mpix_image_correct_gamma (struct mpix_image *img)
 Apply Gamma Correction (GC) to the image.
 
static int mpix_image_qoi_encode (struct mpix_image *img)
 Encode an image to the QOI compressed image format.
 
static int mpix_image_jpeg_encode (struct mpix_image *img)
 Compressed an image to the JPEG format.
 
static int mpix_image_resize_subsample (struct mpix_image *img, uint16_t width, uint16_t height)
 Resize an image.
 
static int mpix_image_crop (struct mpix_image *img, uint16_t x_offset, uint16_t y_offset, uint16_t crop_width, uint16_t crop_height)
 Crop an image to a smaller region.
 
static int mpix_image_sharpen (struct mpix_image *img, uint8_t level)
 Apply a sharpen operation to an image.
 
static int mpix_image_denoise (struct mpix_image *img, uint8_t level)
 Apply a denoise operation to an image.
 
static int mpix_image_edge_detect (struct mpix_image *img, uint8_t level)
 Apply an edge detection operation to an image.
 
static int mpix_image_gaussian_blur (struct mpix_image *img, uint8_t level)
 Apply a gaussian blur operation to an image.
 
static void mpix_image_from_palette (struct mpix_image *img, const struct mpix_palette *palette)
 Initialize an image from a palette.
 
static 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)
 Optimize a color palette after the values from the image.
 
static void mpix_image_free (struct mpix_image *img)
 Free the resources of an image.
 
static struct mpix_formatmpix_image_format (struct mpix_image *img)
 Get the input format of an image, matching the inage input buffer.
 
static int mpix_image_sample_random_rgb (struct mpix_image *img, uint8_t rgb[3])
 Collect a random RGB pixel from an image.
 
static void mpix_image_stats (struct mpix_image *img, struct mpix_stats *stats)
 Collect statistics from an image.
 
static int mpix_image_ctrl_value (struct mpix_image *img, enum mpix_control_id cid, int32_t value)
 Set a control to a pipeline.
 
static int mpix_image_ctrl_array (struct mpix_image *img, enum mpix_control_id cid, int32_t *array, size_t size)
 Set a control to a pipeline.
 
static int mpix_image_read_output (struct mpix_image *img, const uint8_t **buf, size_t *size)
 Return the output buffer and its size, resetting it to zero.
 

Detailed Description

Main user API.

Function Documentation

◆ mpix_image_convert()

static int mpix_image_convert ( struct mpix_image img,
uint32_t  new_format 
)
inlinestatic

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_correct_black_level()

static int mpix_image_correct_black_level ( struct mpix_image img)
inlinestatic

Apply Black Level Correction (BLC) to the image.

This operation only adds the processing element. To control the correction, use mpix_image_ctrl_value() with MPIX_CID_GAMMA_LEVEL.

Parameters
imgImage to correct.
Returns
0 on success or negative error code.

◆ mpix_image_correct_color_matrix()

static int mpix_image_correct_color_matrix ( struct mpix_image img)
inlinestatic

Apply Color Correction Matrix (CCM) to the image.

This operation only adds the processing element. To control the correction, use mpix_image_ctrl_value() with MPIX_CID_COLOR_MATRIX.

Parameters
imgImage to correct.
Returns
0 on success or negative error code.

◆ mpix_image_correct_gamma()

static int mpix_image_correct_gamma ( struct mpix_image img)
inlinestatic

Apply Gamma Correction (GC) to the image.

This operation only adds the processing element. To control the correction, use mpix_image_ctrl_value() with MPIX_CID_GAMMA_LEVEL.

Parameters
imgImage to correct.
Returns
0 on success or negative error code.

◆ mpix_image_correct_white_balance()

static int mpix_image_correct_white_balance ( struct mpix_image img)
inlinestatic

Apply White Balance Correction (AWB) to the image.

This operation only adds the processing element. To control the correction, use mpix_image_ctrl_value() with MPIX_CID_WHITE_BALANCE.

Parameters
imgImage to correct.
Returns
0 on success or negative error code.

◆ mpix_image_crop()

static int mpix_image_crop ( struct mpix_image img,
uint16_t  x_offset,
uint16_t  y_offset,
uint16_t  crop_width,
uint16_t  crop_height 
)
inlinestatic

Crop an image to a smaller region.

An operation is added to crop the image to a specified rectangular region. The crop region must be within the bounds of the original image.

Parameters
imgImage to crop.
x_offsetX coordinate of the top-left corner of the crop region.
y_offsetY coordinate of the top-left corner of the crop region.
crop_widthWidth of the crop region in pixels.
crop_heightHeight of the crop region in pixels.
Returns
0 on success or negative error code.

◆ mpix_image_ctrl_array()

static int mpix_image_ctrl_array ( struct mpix_image img,
enum mpix_control_id  cid,
int32_t *  array,
size_t  size 
)
inlinestatic

Set a control to a pipeline.

This is to be set after pipeline elements are added, so that their respective controls are added to the image.

Parameters
imgImage to apply the control to
cidControl ID to set if present
valValue to set this control to
Returns
0 on sucess, or negative error code

◆ mpix_image_ctrl_value()

static int mpix_image_ctrl_value ( struct mpix_image img,
enum mpix_control_id  cid,
int32_t  value 
)
inlinestatic

Set a control to a pipeline.

This is to be set after pipeline elements are added, so that their respective controls are added to the image.

Parameters
imgImage to apply the control to
cidControl ID to set if present
valValue to set this control to
Returns
0 on sucess, or negative error code

◆ mpix_image_debayer()

static int mpix_image_debayer ( struct mpix_image img,
uint32_t  window_size 
)
inlinestatic

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_denoise()

static int mpix_image_denoise ( struct mpix_image img,
uint8_t  level 
)
inlinestatic

Apply a denoise operation to an image.

Parameters
imgImage to work on.
levelThe pixel size of operation
Returns
0 on success or negative error code.

◆ mpix_image_edge_detect()

static int mpix_image_edge_detect ( struct mpix_image img,
uint8_t  level 
)
inlinestatic

Apply an edge detection operation to an image.

See also
MPIX_KERNEL_EDGE_DETECT
Parameters
imgImage to work on.
levelThe pixel size of operation
Returns
0 on success or negative error code.

◆ mpix_image_format()

static struct mpix_format * mpix_image_format ( struct mpix_image img)
inlinestatic

Get the input format of an image, matching the inage input buffer.

Parameters
imgThe image to inspect.
Returns
The apropriate image format struct.

◆ mpix_image_free()

static void mpix_image_free ( struct mpix_image img)
inlinestatic

Free the resources of an image.

This frees all intermediate buffers allocated automatically, but not the buffer field of img which is managed by the caller.

Note
The image fields will all be set to zero.
Parameters
imgImage to free.

◆ mpix_image_from_buf()

static void mpix_image_from_buf ( struct mpix_image img,
const uint8_t *  buffer,
size_t  size,
const struct mpix_format fmt 
)
inlinestatic

Initialize an image from a memory buffer.

Note
The image fields will not be reset to zero, which is the responsibility of the caller.
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()

static void mpix_image_from_palette ( struct mpix_image img,
const struct mpix_palette palette 
)
inlinestatic

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_gaussian_blur()

static int mpix_image_gaussian_blur ( struct mpix_image img,
uint8_t  level 
)
inlinestatic

Apply a gaussian blur operation to an image.

See also
MPIX_KERNEL_GAUSSIAN_BLUR
Parameters
imgImage to work on.
levelThe pixel size of operation
Returns
0 on success or negative error code.

◆ mpix_image_jpeg_encode()

static int mpix_image_jpeg_encode ( struct mpix_image img)
inlinestatic

Compressed an image to the JPEG format.

Parameters
imgImage to convert to JPEG.
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 
)

Optimize a color palette after the values from the image.

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 as desired to optimize more.

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_palette_decode()

static int mpix_image_palette_decode ( struct mpix_image img)
inlinestatic

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. The palette must be set once per pipeline before running it.

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

◆ mpix_image_palette_encode()

static int mpix_image_palette_encode ( struct mpix_image img,
uint32_t  fourcc 
)
inlinestatic

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.

The size in bytes of the colors buffer is (3 << bit_depth).

Parameters
imgImage to convert.
fourccPalette format Four Character Code, starting with PLT and then a digit.
Returns
0 on success or negative error code.

◆ mpix_image_qoi_encode()

static int mpix_image_qoi_encode ( struct mpix_image img)
inlinestatic

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_read_output()

static int mpix_image_read_output ( struct mpix_image img,
const uint8_t **  buf,
size_t *  size 
)
inlinestatic

Return the output buffer and its size, resetting it to zero.

This clears the output buffer while preserving all the operations of the pipeline for another round to happen after it.

Parameters
imgImage to flush the output.
sizePointer set to the size of the output buffer.
Returns
Pointer to the buffer or NULL.

◆ mpix_image_resize_subsample()

static int mpix_image_resize_subsample ( struct mpix_image img,
uint16_t  width,
uint16_t  height 
)
inlinestatic

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()

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

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_set_palette()

static int mpix_image_set_palette ( struct mpix_image img,
struct mpix_palette palette 
)
inlinestatic

Set the palette of every operation currently in the pipeline.

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.

See also
mpix_pipeline_set_palette().
Parameters
imgImage to assign a palette to.
paletteThe color palette in RGB24 pixel format.

◆ mpix_image_sharpen()

static int mpix_image_sharpen ( struct mpix_image img,
uint8_t  level 
)
inlinestatic

Apply a sharpen operation to an image.

See also
MPIX_KERNEL_SHARPEN
Parameters
imgImage to work on.
levelThe pixel size of operation
Returns
0 on success or negative error code.

◆ mpix_image_stats()

static void mpix_image_stats ( struct mpix_image img,
struct mpix_stats stats 
)
inlinestatic

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()

static int mpix_image_to_buf ( struct mpix_image img,
uint8_t *  buffer,
size_t  size 
)
inlinestatic

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()

static int mpix_image_to_palette ( struct mpix_image img,
struct mpix_palette palette 
)
inlinestatic

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.