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

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, 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)
 Initialize an image from a memory buffer.
 
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.
 
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, size_t max_sz)
 Convert an image from a bayer array format to RGB24.
 
int mpix_image_resize (struct mpix_image *img, 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.
 
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.
 

Detailed Description

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>.

◆ 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).

◆ 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.

◆ mpix_image_from_buf()

void mpix_image_from_buf ( struct mpix_image img,
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_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/kernel.h>
kernel_szThe size of the kernel operaiton, usually 3 or 5.

◆ 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.

◆ 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.

◆ 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_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,
size_t  max_sz 
)

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.
max_szMaximum QOI image size, too big wastes spaces, too small causes truncation.

◆ mpix_image_resize()

int mpix_image_resize ( struct mpix_image img,
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.
widthThe new width in pixels.
heightThe new height in pixels.

◆ mpix_image_to_buf()

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

Initialize an image from a memory buffer.

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