The open imaging DSP library
Loading...
Searching...
No Matches
How to convert pixel formats

Converting between uncompressed pixel format conversion in libmpix.

Note
This guide is about uncompressed pixel formats. Different guide describe how to work with compressed formats.

The input format is always specified when opening the image and does not need to be specified. What remains to do is to call mpix_image_convert and specify the output pixel format.

First load a buffer into an image struct, specifying the pixel format:

struct mpix_image img;
struct mpix_format fmt = { .width = 640, .height = 480, .fourcc = MPIX_FMT_RGB24 };
mpix_image_from_buf(&img, buf, sizeof(buf), &fmt);
#define MPIX_FMT_RGB24
Definition formats.h:125
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.
Definition image.h:30
Image format description.
Definition types.h:72
uint16_t width
Definition types.h:76
Represent the image currently being processed.
Definition types.h:136

Then convert the image to the destination format:

#define MPIX_FMT_GREY
Definition formats.h:189
static int mpix_image_convert(struct mpix_image *img, uint32_t new_format)
Convert an image to a new pixel format.
Definition image.h:66

Add more processing steps as needed.

See Supported operations for a list of all supported format conversions.