The open imaging DSP library
Loading...
Searching...
No Matches
Macros | Functions
mpix/formats.h

Pixel format definitions. More...

Macros

#define MPIX_FOURCC_TO_STR(fourcc)
 Generate a string out of a pixel format.
 
#define MPIX_FOURCC(a, b, c, d)    ((uint32_t)(a) | ((uint32_t)(b) << 8) | ((uint32_t)(c) << 16) | ((uint32_t)(d) << 24))
 Define a new pixel format, with defaults for most common values.
 

Functions

static uint8_t mpix_palette_bit_depth (uint32_t fourcc)
 Convert an image and store it into a color palette.
 
static uint32_t mpix_palette_fourcc (uint8_t bit_depth)
 Convert an image and store it into a color palette.
 
static uint8_t mpix_bits_per_pixel (uint32_t fourcc)
 Get the average number of bits per pixel of a pixel format.
 
static size_t mpix_format_pitch (const struct mpix_format *fmt)
 Get the pitch for a given pixel format.
 
static uint32_t mpix_format_line_down (uint32_t fourcc)
 Get the pixel format of the buffer if looking one line below.
 

RGB formats

Formats with red, green, blue channels, each pixel contain each channel.

#define MPIX_FMT_RGB332   MPIX_FOURCC('R', 'G', 'B', '1')
 
#define MPIX_FMT_RGB565   MPIX_FOURCC('R', 'G', 'B', 'P')
 
#define MPIX_FMT_RGB565X   MPIX_FOURCC('R', 'G', 'B', 'R')
 
#define MPIX_FMT_RGB24   MPIX_FOURCC('R', 'G', 'B', '3')
 
#define MPIX_FMT_XRGB32   MPIX_FOURCC('B', 'X', '2', '4')
 

YUV formats

Formats with Luma (Y), Cb (U), and Cr (V) channels, sometimes with chroma subsampling.

#define MPIX_FMT_YUV12   MPIX_FOURCC('Y', 'U', 'V', 'C')
 12-bit per pixel, 2 pixels every 3 bytes, 4-bit per component.
 
#define MPIX_FMT_YUV24   MPIX_FOURCC('Y', 'U', 'V', '3')
 
#define MPIX_FMT_YUYV   MPIX_FOURCC('Y', 'U', 'Y', 'V')
 

Luma-only formats

Formats with only a luma (Y) channel, grayscale.

#define MPIX_FMT_GREY   MPIX_FOURCC('G', 'R', 'E', 'Y')
 
#define MPIX_FMT_Y10   MPIX_FOURCC('Y', '1', '0', ' ')
 
#define MPIX_FMT_Y12   MPIX_FOURCC('Y', '1', '2', ' ')
 
#define MPIX_FMT_Y14   MPIX_FOURCC('Y', '1', '4', ' ')
 
#define MPIX_FMT_Y16   MPIX_FOURCC('Y', '1', '6', ' ')
 

Bayer formats

Formats with bayer color filter array, one channel per pixel, red, green or blue.

#define MPIX_FMT_SBGGR8   MPIX_FOURCC('B', 'A', '8', '1')
 
#define MPIX_FMT_SGBRG8   MPIX_FOURCC('G', 'B', 'R', 'G')
 
#define MPIX_FMT_SGRBG8   MPIX_FOURCC('G', 'R', 'B', 'G')
 
#define MPIX_FMT_SRGGB8   MPIX_FOURCC('R', 'G', 'G', 'B')
 

IR Bayer formats

Formats with bayer color filter array featuring Red, Gren, Blue, Infrared

#define MPIX_FMT_SRGGI8   MPIX_FOURCC('R', 'G', 'I', '8')
 
#define MPIX_FMT_SGRIG8   MPIX_FOURCC('G', 'R', 'I', '8')
 
#define MPIX_FMT_SBGGI8   MPIX_FOURCC('B', 'G', 'I', '8')
 
#define MPIX_FMT_SGBIG8   MPIX_FOURCC('G', 'B', 'I', '8')
 
#define MPIX_FMT_SGIRG8   MPIX_FOURCC('G', 'I', 'R', '8')
 
#define MPIX_FMT_SIGGR8   MPIX_FOURCC('I', 'G', 'R', '8')
 
#define MPIX_FMT_SGIBG8   MPIX_FOURCC('G', 'I', 'B', '8')
 
#define MPIX_FMT_SIGGB8   MPIX_FOURCC('I', 'G', 'B', '8')
 
#define MPIX_FMT_SRGGI10   MPIX_FOURCC('R', 'G', 'I', '0')
 
#define MPIX_FMT_SGRIG10   MPIX_FOURCC('G', 'R', 'I', '0')
 
#define MPIX_FMT_SBGGI10   MPIX_FOURCC('B', 'G', 'I', '0')
 
#define MPIX_FMT_SGBIG10   MPIX_FOURCC('G', 'B', 'I', '0')
 
#define MPIX_FMT_SGIRG10   MPIX_FOURCC('G', 'I', 'R', '0')
 
#define MPIX_FMT_SIGGR10   MPIX_FOURCC('I', 'G', 'R', '0')
 
#define MPIX_FMT_SGIBG10   MPIX_FOURCC('G', 'I', 'B', '0')
 
#define MPIX_FMT_SIGGB10   MPIX_FOURCC('I', 'G', 'B', '0')
 

Indexed color formats

Formats where each pixel is a reference to a color palette.

#define MPIX_FMT_PALETTE1   MPIX_FOURCC('P', 'L', 'T', '1')
 
#define MPIX_FMT_PALETTE2   MPIX_FOURCC('P', 'L', 'T', '2')
 
#define MPIX_FMT_PALETTE3   MPIX_FOURCC('P', 'L', 'T', '3')
 
#define MPIX_FMT_PALETTE4   MPIX_FOURCC('P', 'L', 'T', '4')
 
#define MPIX_FMT_PALETTE5   MPIX_FOURCC('P', 'L', 'T', '5')
 
#define MPIX_FMT_PALETTE6   MPIX_FOURCC('P', 'L', 'T', '6')
 
#define MPIX_FMT_PALETTE7   MPIX_FOURCC('P', 'L', 'T', '7')
 
#define MPIX_FMT_PALETTE8   MPIX_FOURCC('P', 'L', 'T', '8')
 

Compressed formats

Lossy and non-lossy compressed formats. The bits per pixel is defined as zero.

#define MPIX_FMT_JPEG   MPIX_FOURCC('J', 'P', 'E', 'G')
 
#define MPIX_FMT_QOI   MPIX_FOURCC('Q', 'O', 'I', 'F')
 

Detailed Description

Pixel format definitions.

SPDX-License-Identifier: Apache-2.0

Macro Definition Documentation

◆ MPIX_FMT_GREY

#define MPIX_FMT_GREY   MPIX_FOURCC('G', 'R', 'E', 'Y')

Same as Y8 (8-bit luma-only) following the standard FOURCC naming, or L8 in some graphics libraries.

0 1 2 3
| Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | ...

◆ MPIX_FMT_JPEG

#define MPIX_FMT_JPEG   MPIX_FOURCC('J', 'P', 'E', 'G')

Compressed frame using the JPEG format. Multiple JPEG frames can be sent back-to-back to make an MJPEG stream.

◆ MPIX_FMT_PALETTE1

#define MPIX_FMT_PALETTE1   MPIX_FOURCC('P', 'L', 'T', '1')

1-bit color palette pixel format, 2 colors in total like a bitmap. 8 pixels shown below:

0 1 2 3 4 5 6 7
| P|P|P|P|P|P|P|P | ...

◆ MPIX_FMT_PALETTE2

#define MPIX_FMT_PALETTE2   MPIX_FOURCC('P', 'L', 'T', '2')

2-bit color palette pixel format, 4 colors in total. 8 pixels shown below:

0 1 2 3 4 5 6 7
| Pp|Pp|Pp|Pp | Pp|Pp|Pp|Pp | ...

◆ MPIX_FMT_PALETTE3

#define MPIX_FMT_PALETTE3   MPIX_FOURCC('P', 'L', 'T', '3')

3-bit color palette pixel format, 8 colors in total. Padded by 1 bit to fit a 4 bit packing. 8 pixels shown below:

0 1 2 3 4 5 6 7
| -Ppp|-Ppp | -Ppp|-Ppp | -Ppp|-Ppp | -Ppp|-Ppp | ...

◆ MPIX_FMT_PALETTE4

#define MPIX_FMT_PALETTE4   MPIX_FOURCC('P', 'L', 'T', '4')

4-bit color palette pixel format, 16 colors in total. 8 pixels shown below:

0 1 2 3 4 5 6 7
| Pppp|Pppp | Pppp|Pppp | Pppp|Pppp | Pppp|Pppp | ...

◆ MPIX_FMT_PALETTE5

#define MPIX_FMT_PALETTE5   MPIX_FOURCC('P', 'L', 'T', '5')

5-bit color palette pixel format, 32 colors in total. Padded by 3 bit to fit a 8 bit packing. 8 pixels shown below:

0 1 2 3 4 5 6 7
| ---Ppppp | ---Ppppp | ---Ppppp | ---Ppppp | ---Ppppp | ---Ppppp | ---Ppppp | ---Ppppp | ...

◆ MPIX_FMT_PALETTE6

#define MPIX_FMT_PALETTE6   MPIX_FOURCC('P', 'L', 'T', '6')

6-bit color palette pixel format, 64 colors in total. Padded by 2 bit to fit a 8 bit packing. 8 pixels shown below:

0 1 2 3 4 5 6 7
| --Pppppp | --Pppppp | --Pppppp | --Pppppp | --Pppppp | --Pppppp | --Pppppp | --Pppppp | ...

◆ MPIX_FMT_PALETTE7

#define MPIX_FMT_PALETTE7   MPIX_FOURCC('P', 'L', 'T', '7')

7-bit color palette pixel format, 128 colors in total. Padded by 1 bit to fit a 8 bit packing. 8 pixels shown below:

0 1 2 3 4 5 6 7
| -Ppppppp | -Ppppppp | -Ppppppp | -Ppppppp | -Ppppppp | -Ppppppp | -Ppppppp | -Ppppppp | ...

◆ MPIX_FMT_PALETTE8

#define MPIX_FMT_PALETTE8   MPIX_FOURCC('P', 'L', 'T', '8')

8-bit color palette pixel format, 256 colors in total. 8 pixels shown below:

0 1 2 3 4 5 6 7
| Pppppppp | Pppppppp | Pppppppp | Pppppppp | Pppppppp | Pppppppp | Pppppppp | Pppppppp | ...

◆ MPIX_FMT_QOI

#define MPIX_FMT_QOI   MPIX_FOURCC('Q', 'O', 'I', 'F')

Compressed frame using the QOI format. Multiple QOI frames can be sent back-to-back to make an QOIF stream.

◆ MPIX_FMT_RGB24

#define MPIX_FMT_RGB24   MPIX_FOURCC('R', 'G', 'B', '3')

24 bit RGB format with 8 bit per component

| Rrrrrrrr Gggggggg Bbbbbbbb | ...

◆ MPIX_FMT_RGB332

#define MPIX_FMT_RGB332   MPIX_FOURCC('R', 'G', 'B', '1')

8 bit RGB format with 3 or 2 bit per component

| RrrGggBb | ...

◆ MPIX_FMT_RGB565

#define MPIX_FMT_RGB565   MPIX_FOURCC('R', 'G', 'B', 'P')

5 red bits [15:11], 6 green bits [10:5], 5 blue bits [4:0]. This 16-bit integer is then packed in little endian format over two bytes:

7......0 15.....8
| gggBbbbb RrrrrGgg | ...

◆ MPIX_FMT_RGB565X

#define MPIX_FMT_RGB565X   MPIX_FOURCC('R', 'G', 'B', 'R')

5 red bits [15:11], 6 green bits [10:5], 5 blue bits [4:0]. This 16-bit integer is then packed in big endian format over two bytes:

15.....8 7......0
| RrrrrGgg gggBbbbb | ...

◆ MPIX_FMT_SBGGI10

#define MPIX_FMT_SBGGI10   MPIX_FOURCC('B', 'G', 'I', '0')
0 1 2 3

◆ MPIX_FMT_SBGGI8

#define MPIX_FMT_SBGGI8   MPIX_FOURCC('B', 'G', 'I', '8')
0 1 2 3

◆ MPIX_FMT_SBGGR8

#define MPIX_FMT_SBGGR8   MPIX_FOURCC('B', 'A', '8', '1')
0 1 2 3
| Bbbbbbbb | Gggggggg | Bbbbbbbb | Gggggggg | ...
| Gggggggg | Rrrrrrrr | Gggggggg | Rrrrrrrr | ...

◆ MPIX_FMT_SGBIG10

#define MPIX_FMT_SGBIG10   MPIX_FOURCC('G', 'B', 'I', '0')
0 1 2 3

◆ MPIX_FMT_SGBIG8

#define MPIX_FMT_SGBIG8   MPIX_FOURCC('G', 'B', 'I', '8')
0 1 2 3

◆ MPIX_FMT_SGBRG8

#define MPIX_FMT_SGBRG8   MPIX_FOURCC('G', 'B', 'R', 'G')
0 1 2 3
| Gggggggg | Bbbbbbbb | Gggggggg | Bbbbbbbb | ...
| Rrrrrrrr | Gggggggg | Rrrrrrrr | Gggggggg | ...

◆ MPIX_FMT_SGIBG10

#define MPIX_FMT_SGIBG10   MPIX_FOURCC('G', 'I', 'B', '0')
0 1 2 3

◆ MPIX_FMT_SGIBG8

#define MPIX_FMT_SGIBG8   MPIX_FOURCC('G', 'I', 'B', '8')
0 1 2 3

◆ MPIX_FMT_SGIRG10

#define MPIX_FMT_SGIRG10   MPIX_FOURCC('G', 'I', 'R', '0')
0 1 2 3

◆ MPIX_FMT_SGIRG8

#define MPIX_FMT_SGIRG8   MPIX_FOURCC('G', 'I', 'R', '8')
0 1 2 3

◆ MPIX_FMT_SGRBG8

#define MPIX_FMT_SGRBG8   MPIX_FOURCC('G', 'R', 'B', 'G')
0 1 2 3
| Gggggggg | Rrrrrrrr | Gggggggg | Rrrrrrrr | ...
| Bbbbbbbb | Gggggggg | Bbbbbbbb | Gggggggg | ...

◆ MPIX_FMT_SGRIG10

#define MPIX_FMT_SGRIG10   MPIX_FOURCC('G', 'R', 'I', '0')
0 1 2 3

◆ MPIX_FMT_SGRIG8

#define MPIX_FMT_SGRIG8   MPIX_FOURCC('G', 'R', 'I', '8')
0 1 2 3
| Gggggggg | Rrrrrrrr | Gggggggg | Bbbbbbbb |
| Iiiiiiii | Gggggggg | Iiiiiiii | Gggggggg |
| Gggggggg | Bbbbbbbb | Gggggggg | Rrrrrrrr |
| Iiiiiiii | Gggggggg | Iiiiiiii | Gggggggg |

◆ MPIX_FMT_SIGGB10

#define MPIX_FMT_SIGGB10   MPIX_FOURCC('I', 'G', 'B', '0')
0 1 2 3

◆ MPIX_FMT_SIGGB8

#define MPIX_FMT_SIGGB8   MPIX_FOURCC('I', 'G', 'B', '8')
0 1 2 3

◆ MPIX_FMT_SIGGR10

#define MPIX_FMT_SIGGR10   MPIX_FOURCC('I', 'G', 'R', '0')
0 1 2 3

◆ MPIX_FMT_SIGGR8

#define MPIX_FMT_SIGGR8   MPIX_FOURCC('I', 'G', 'R', '8')
0 1 2 3

◆ MPIX_FMT_SRGGB8

#define MPIX_FMT_SRGGB8   MPIX_FOURCC('R', 'G', 'G', 'B')
0 1 2 3
| Rrrrrrrr | Gggggggg | Rrrrrrrr | Gggggggg | ...
| Gggggggg | Bbbbbbbb | Gggggggg | Bbbbbbbb | ...

◆ MPIX_FMT_SRGGI10

#define MPIX_FMT_SRGGI10   MPIX_FOURCC('R', 'G', 'I', '0')
0 1 2 3
| rrrrrrrr | 000000Rr | gggggggg | 000000Gg | bbbbbbbb | 000000Bb | gggggggg | 000000Gg |
| gggggggg | 000000Gg | iiiiiiii | 000000Ii | gggggggg | 000000Gg | iiiiiiii | 000000Ii |
| bbbbbbbb | 000000Bb | gggggggg | 000000Gg | rrrrrrrr | 000000Rr | gggggggg | 000000Gg |
| gggggggg | 000000Gg | iiiiiiii | 000000Ii | gggggggg | 000000Gg | iiiiiiii | 000000Ii |

◆ MPIX_FMT_SRGGI8

#define MPIX_FMT_SRGGI8   MPIX_FOURCC('R', 'G', 'I', '8')
0 1 2 3
| Rrrrrrrr | Gggggggg | Bbbbbbbb | Gggggggg |
| Gggggggg | Iiiiiiii | Gggggggg | Iiiiiiii |
| Bbbbbbbb | Gggggggg | Rrrrrrrr | Gggggggg |
| Gggggggg | Iiiiiiii | Gggggggg | Iiiiiiii |

◆ MPIX_FMT_XRGB32

#define MPIX_FMT_XRGB32   MPIX_FOURCC('B', 'X', '2', '4')

The first byte is empty (X) for each pixel.

| Xxxxxxxx Rrrrrrrr Gggggggg Bbbbbbbb | ...

◆ MPIX_FMT_Y10

#define MPIX_FMT_Y10   MPIX_FOURCC('Y', '1', '0', ' ')

Little endian, with the 6 most significant bits set to Zero.

0 1 2 3
| yyyyyyyy 000000Yy | yyyyyyyy 000000Yy | yyyyyyyy 000000Yy | yyyyyyyy 000000Yy | ...
| yyyyyyyy 000000Yy | yyyyyyyy 000000Yy | yyyyyyyy 000000Yy | yyyyyyyy 000000Yy | ...

◆ MPIX_FMT_Y12

#define MPIX_FMT_Y12   MPIX_FOURCC('Y', '1', '2', ' ')

Little endian, with the 4 most significant bits set to Zero.

0 1 2 3
| yyyyyyyy 0000Yyyy | yyyyyyyy 0000Yyyy | yyyyyyyy 0000Yyyy | yyyyyyyy 0000Yyyy | ...
| yyyyyyyy 0000Yyyy | yyyyyyyy 0000Yyyy | yyyyyyyy 0000Yyyy | yyyyyyyy 0000Yyyy | ...

◆ MPIX_FMT_Y14

#define MPIX_FMT_Y14   MPIX_FOURCC('Y', '1', '4', ' ')

Little endian, with the 2 most significant bits set to Zero.

0 1 2 3
| yyyyyyyy 00Yyyyyy | yyyyyyyy 00Yyyyyy | yyyyyyyy 00Yyyyyy | yyyyyyyy 00Yyyyyy | ...
| yyyyyyyy 00Yyyyyy | yyyyyyyy 00Yyyyyy | yyyyyyyy 00Yyyyyy | yyyyyyyy 00Yyyyyy | ...

◆ MPIX_FMT_Y16

#define MPIX_FMT_Y16   MPIX_FOURCC('Y', '1', '6', ' ')

Little endian.

0 1 2 3
| yyyyyyyy Yyyyyyyy | yyyyyyyy Yyyyyyyy | yyyyyyyy Yyyyyyyy | yyyyyyyy Yyyyyyyy | ...
| yyyyyyyy Yyyyyyyy | yyyyyyyy Yyyyyyyy | yyyyyyyy Yyyyyyyy | yyyyyyyy Yyyyyyyy | ...

◆ MPIX_FMT_YUV12

#define MPIX_FMT_YUV12   MPIX_FOURCC('Y', 'U', 'V', 'C')

12-bit per pixel, 2 pixels every 3 bytes, 4-bit per component.

2 pixels shown below:

| YyyyUuuu Vvvv|Yyyy UuuuVvvv| ...

◆ MPIX_FMT_YUV24

#define MPIX_FMT_YUV24   MPIX_FOURCC('Y', 'U', 'V', '3')
| Yyyyyyyy Uuuuuuuu Vvvvvvvv | ...

◆ MPIX_FMT_YUYV

#define MPIX_FMT_YUYV   MPIX_FOURCC('Y', 'U', 'Y', 'V')

There is either a missing channel per pixel, U or V. The value is to be averaged over 2 pixels to get the value of individual pixel.

| Yyyyyyyy Uuuuuuuu | Yyyyyyyy Vvvvvvvv | ...

◆ MPIX_FOURCC

#define MPIX_FOURCC (   a,
  b,
  c,
 
)     ((uint32_t)(a) | ((uint32_t)(b) << 8) | ((uint32_t)(c) << 16) | ((uint32_t)(d) << 24))

Define a new pixel format, with defaults for most common values.

Parameters
a1st character of the Four Character Code
b2nd character of the Four Character Code
c3rd character of the Four Character Code
d4th character of the Four Character Code

◆ MPIX_FOURCC_TO_STR

#define MPIX_FOURCC_TO_STR (   fourcc)
Value:
((char[5]){ \
(char)(((fourcc) >> 0) & 0xFF), \
(char)(((fourcc) >> 8) & 0xFF), \
(char)(((fourcc) >> 16) & 0xFF), \
(char)(((fourcc) >> 24) & 0xFF), \
'\0', \
})

Generate a string out of a pixel format.

Parameters
fourccFormat as a 32-bit four character code.
Returns
A local nul-terminated string for this four character code.

Function Documentation

◆ mpix_bits_per_pixel()

static uint8_t mpix_bits_per_pixel ( uint32_t  fourcc)
inlinestatic

Get the average number of bits per pixel of a pixel format.

For compressed/variablle pitch formats, the convention is that the result is 0.

Returns
Average number of bits per pixel.

◆ mpix_format_line_down()

static uint32_t mpix_format_line_down ( uint32_t  fourcc)
inlinestatic

Get the pixel format of the buffer if looking one line below.

Returns
The new four character code (FourCC) or zero if not a bayer format.

◆ mpix_format_pitch()

static size_t mpix_format_pitch ( const struct mpix_format fmt)
inlinestatic

Get the pitch for a given pixel format.

This assumes a format without padding, and returns 0 for variable pitch formats, such as compressed formats.

Returns
Number of bytes used to store a line of this format.

◆ mpix_palette_bit_depth()

static uint8_t mpix_palette_bit_depth ( uint32_t  fourcc)
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.
fourccThe pixel format of the palette
Returns
0 on success or negative error code.

◆ mpix_palette_fourcc()

static uint32_t mpix_palette_fourcc ( uint8_t  bit_depth)
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.
depthThe color palette to use for the conversion.
Returns
0 on success or negative error code.