libmpix
The open imaging DSP library
|
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. | |
User API.
SPDX-License-Identifier: Apache-2.0
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.
img | Image to convert. |
new_format | A four-character-code (FOURCC) as defined by <zephyr/drivers/video.h> . |
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.
img | Image to convert. |
window_size | The window size for the conversion, usually 2 (faster) or 3 (higher quality). |
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.
img | Image to convert. |
palette | The color palette to use for the conversion. |
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.
img | Image to initialize. |
buf | Memory containinig input image data to process. |
size | Total available size in the buffer, can be bigger/smaller than full width x height. |
width | Width of the complete image in pixels. |
height | Height of the complete image in pixels. |
format | Format of data in the buffer as a four-character-code. |
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.
img | Image to convert. |
kernel_type | The type of kernel to apply as defined in <mpix/kernel.h> |
kernel_sz | The size of the kernel operaiton, usually 3 or 5. |
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.
img | Input image sampled to generate the palette. |
palette | The palette that will be updated with colors fitting the image better |
num_samples | Number of samples to take from the input image. |
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.
img | Image to convert. |
palette | The color palette to use for the conversion. |
void mpix_image_print_256color | ( | struct mpix_image * | img | ) |
Print an image using higher speed 256COLOR terminal escape codes.
img | Image to print. |
void mpix_image_print_truecolor | ( | struct mpix_image * | img | ) |
Print an image using higher quality TRUECOLOR terminal escape codes.
img | Image to print. |
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.
img | Image to convert. |
max_sz | Maximum QOI image size, too big wastes spaces, too small causes truncation. |
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.
img | Image to convert. |
width | The new width in pixels. |
height | The new height in pixels. |
int mpix_image_to_buf | ( | struct mpix_image * | img, |
uint8_t * | buf, | ||
size_t | size | ||
) |
Initialize an image from a memory buffer.
img | Image being processed. |
buf | Memory that receives the image data. |
size | Size of the buffer. |