Format definitions

General references:

RGB formats

BGRx

Full-string: video/x-raw,format=BGRx

8-bit BGRx format, aka RGB32

uint8_t[0,3]: [blue][green][red][x]

struct BGRx {
    uint8_t b;
    uint8_t g;
    uint8_t r;
    uint8_t x; // This is always 0xFF
};

BGR

Full-string: video/x-raw,format=BGR

8-bit BGR format, aka RGB24

uint8_t[0,2]: [blue][green][red]

struct BGRx {
    uint8_t b;
    uint8_t g;
    uint8_t r;
};

RGBx64

Full-string: video/x-raw,format=RGBx64

16-bit BGRx little endian format

uint16_t[0,3]: [blue][green][red][x]

struct RGBx64 {
    uint16_t b;
    uint16_t g;
    uint16_t r;
    uint16_t x; // This is always 0xFF
};

Monochrome formats

GRAY16_LE

Full-string: video/x-raw,format=GRAY16_LE

8-bit GRAY little endian format, aka Y16, Mono16

struct GRAY16_LE {
    uint16_t y;
};

GRAY8

Full-string: video/x-raw,format=GRAY8

8-bit GRAY, aka Mono8

struct GRAY8_LE {
    uint8_t y;
};

GRAY10

Full-string: video/x-raw,format=GRAY10

16-bit format, with lower 10 bits valid

uint16_t* src = ..;
uint16_t pixel0 = src[0] & 0x3FF;

GRAY10sp

Full-string: video/x-raw,format=GRAY10sp

GRAY10m

Full-string: video/x-raw,format=GRAY10m

10-bit MIPI packed format layout

uint8_t [0,4]: [pix0_hi][pix1_hi][pix2_hi][pix3_hi][pix0_lo|pix1_lo|pix2_lo|pix3_lo]

Example code to convert 10 bit formats to 4 uint16_t values:

uint8_t* src = ..;
uint16_t pixel0 = (src[0] << 8) | (src[4] & 0b00000011) << 6;
uint16_t pixel1 = (src[1] << 8) | (src[4] & 0b00001100) << 4;
uint16_t pixel2 = (src[2] << 8) | (src[4] & 0b00110000) << 2;
uint16_t pixel3 = (src[3] << 8) | (src[4] & 0b11000000) << 0;

GRAY12

Full-string: video/x-raw,format=GRAY12

16-bit format, with lower 12 bits valid

uint16_t* src = ..;
uint16_t pixel0 = src[0] & 0xFFF;

GRAY12p

Full-string: video/x-raw,format=GRAY12p

GRAY12m

Full-string: video/x-raw,format=GRAY12m

12-bit MIPI packed format layout

uint8_t [0,2]: [pix0_hi][pix1_hi][pix0_lo|pix1_lo]

Example code to convert 12 bit formats to 2 uint16_t values:

uint8_t* src = ..;
uint16_t pixel0 = (src[0] << 8) | (src[2] & 0x0F) << 4;
uint16_t pixel1 = (src[1] << 8) | (src[2] & 0xF0) << 0;

GRAY12sp

Full-string: video/x-raw,format=GRAY12sp

Bayer raw formats

These are always setup in one line the xg pixels next line the gy pixels. This makes the image for bggr like this:

line 0, [b][g][b][g][b][g][b][g] ...
line 1, [g][r][g][r][g][r][g][r] ...
line 2, [b][g][b][g][b][g][b][g] ...
line 3, [g][r][g][r][g][r][g][r] ...
...

bggr, gbrg, grbg, rggb

Full-string: video/x-bayer,format=bggr (for bggr bayer layout)

8-bit bayer formats

// Example for bggr
uint8_t* line0 = ..;
uint8_t* line1 = ..;
uint8_t r = line1[1];
uint8_t g = (line0[1] + line1[0]) / 2;
uint8_t b = line0[0];

bggr10, gbrg10, grbg10, rggb10

Full-string: video/x-bayer,format=bggr10 (for bggr bayer layout)

16-bit formats, with lower 10 bits valid.

See GREY10

bggr10sp, gbrg10sp, grbg10sp, rggb10sp

Full-string: video/x-bayer,format=bggr10sp (for bggr bayer layout)

10-bit formats, packed.

See GREY10sp

bggr10m, gbrg10m, grbg10m, rggb10m

Full-string: video/x-bayer,format=bggr10m (for bggr bayer layout)

10-bit formats, packed.

See GREY10m

bggr12, gbrg12, grbg12, rggb12

Full-string: video/x-bayer,format=bggr12 (for bggr bayer layout)

16-bit formats, with lower 12 bits valid.

See GREY12

bggr12sp, gbrg12sp, grbg12sp, rggb12sp

Full-string: video/x-bayer,format=bggr12sp (for bggr bayer layout)

12-bit formats, packed.

See GREY12sp

bggr12p, gbrg12p, grbg12p, rggb12p

Full-string: video/x-bayer,format=bggr12p (for bggr bayer layout)

12-bit formats, packed.

See GREY12p

bggr12m, gbrg12m, grbg12m, rggb12m

Full-string: video/x-bayer,format=bggr12p (for bggr bayer layout)

12-bit formats, packed.

See GREY12m

bggr16, gbrg16, grbg16, rggb16

Full-string: video/x-bayer,format=bggr16 (for bggr bayer layout)

16-bit formats

// Example for bggr
uint16_t* line0 = ..;
uint16_t* line1 = ..;
uint16_t r = line1[1];
uint16_t g = (line0[1] + line1[0]) / 2;
uint16_t b = line0[0];

rggbf

Full-string: video/x-bayer,format=rggbf

32-bit float bayer formats

// Example for bggr
float* line0 = ..;
float* line1 = ..;
float r = line1[1];
float g = (line0[1] + line1[0]) / 2;
float b = line0[0];

YUV packed formats

YUY2

Full-string: video/x-raw,format=YUY2

IYU1

Full-string: video/x-raw,format=YUY2

YV12

Full-string: video/x-raw,format=YV12

PWL raw formats

pwl-rggb12m

Full-string: video/x-bayer,format=pwl-rggb12m

pwl-rggb12

Full-string: video/x-bayer,format=pwl-rggb12

pwl-rggb16H12

Full-string: video/x-bayer,format=pwl-rggb16H12

Polarization formats

polarized-bggr8-v0,polarized-bggr16-v0,polarized-bggr12p-v0,polarized-bggr12sp-v0

Full-string: video/x-bayer,format=polarized-bggr8-v0 (for bggr8)

8/12/16 bit raw camera formats, line + 0 [P90][P45], line + 1 [P135][P0]

Actual image size is width+height / 2

polarized-GRAY8-v0,polarized-GRAY16-v0,polarized-GRAY12p-v0,polarized-GRAY12sp-v0

Full-string: video/x-raw,format=polarized-GRAY8-v0 (for GRAY8)

8/12/16 bit raw camera formats, line + 0 [P90][P45], line + 1 [P135][P0]

Actual image size is width+height / 2

polarization-ADI-GRAY8, polarization-ADI-GRAY16

Full-string: video/x-bayer,format=polarized-ADI-GRAY8

Polarization result image, packed uint8_t/uint16_t

uint8_t[0,3] or uint16_t[0,3]: [angleOfMaxPolarization, linearityOfPolarization, intensity, unused]

struct ADI_GRAY8 {
    uint8_t angleOfMaxPolarization;
    uint8_t linearityOfPolarization;
    uint8_t intensity;
    uint8_t unused;
};

struct ADI_GRAY16 {
    uint16_t angleOfMaxPolarization;
    uint16_t linearityOfPolarization;
    uint16_t intensity;
    uint16_t unused;
};

polarization-ADI-RGB8, polarization-ADI-RGB16

Full-string: video/tis,format=polarized-ADI-GRAY8

Polarization result image, packed uint8_t or uint16_t

uint8_t[0,8] or uint16_t[0,8]: [angleOfMaxPolarization, linearityOfPolarization, r0, g0, b0, r1, g1, b1]

struct ADI_RGB8 {
    uint8_t angleOfMaxPolarization;
    uint8_t linearityOfPolarization;
    uint8_t r0, g0, b0;
    uint8_t r1, g1, b1;
};

struct ADI_RGB16 {
    uint16_t angleOfMaxPolarization;
    uint16_t linearityOfPolarization;
    uint16_t r0, g0, b0;
    uint16_t r1, g1, b1;
};

polarized-packed-GRAY8,polarized-packed-GRAY16

Full-string: video/tis,format=polarized-packed-GRAY8

Polarization result image, packed angles

struct polarization_packed_gray8 {
    uint8_t angle_0;
    uint8_t angle_45;
    uint8_t angle_90;
    uint8_t angle_135;
};

polarized-packed-bggr8,polarized-packed-bggr16

Full-string: video/x-bayer,format=polarized-packed-bggr8

Polarization result image, packed angles in bayer layout

struct polarization_packed_bggr8 {
    uint8_t angle_0;
    uint8_t angle_45;
    uint8_t angle_90;
    uint8_t angle_135;
};