Updated: October 28, 2024 |
Format for all Bayer video formats
#include <sensor/sensor_api.h>
typedef struct sensor_format_video_bayer_t { uint64_t bufsize; uint32_t height; uint32_t width; uint32_t stride; sensor_bayerformat_t format; uint32_t packing; uint32_t bpp; bool le; uint32_t cadence_length; uint32_t pixels_per_cadence; sensor_bayerjustify_t justification; } sensor_format_video_bayer_t;
Stride is often called pitch.
When le is true, the bytes are packed in little-endian; when le is false, the bytes are packed in big-endian.
For more information see sensor_bayerjustify_t.
Each pixel in the Bayer frame is part of a Bayer macro-pixel. A Bayer macro-pixel is made up of four color components: one red, one blue, and two green. We refer to the color components as pixels, and the group of four as a macro-pixel.
A macro-pixel is stored across two lines in the frame. The first two pixels are stored contiguously on the first line. The stride field indicates how many bytes separate the first pixel from the third, and the second pixel from the fourth.
Each pixel of the Bayer macro-pixel comprises bpp number of bits. These bits can be packed into larger words with a size indicated by the packing field. In addition, groups of pixels may be tightly packed into a cadence which is defined by cadence_length and pixels_per_cadence. The ordering of the bits is determined by the justification field.
le = true bpp = 10 packing = 16 cadence_length = 16 pixels_per_cadence = 1 justification = SENSOR_BAYERJUSTIFY_RIGHT_BIT0LSB format = SENSOR_BAYERFORMAT_RGGBThis example describes a 10-bit Bayer frame where each color component is stored as 10 bits packed into 16-bit words. The word is stored in little- endian byte order. Bit 0 represents the least significant bit, and the bits are justified to the right of each byte. This leaves six unused bits per pixel.
Bit: 76543210 Scanline n, byte 0: RRRRRRRR P1Lo(Red) Scanline n, byte 1: 000000RR P1Hi(Red) Scanline n, byte 2: GGGGGGGG P2Lo(Green) Scanline n, byte 3: 000000GG P2Hi(Green) ...and repeats. Scanline n+1, byte 0: GGGGGGGG P1Lo(Green) Scanline n+1, byte 1: 000000GG P1Hi(Green) Scanline n+1, byte 2: BBBBBBBB P2Lo(Blue) Scanline n+1, byte 3: 000000BB P2Hi(Blue) ...and repeats.
le = false bpp = 10 packing = 10 justification = SENSOR_BAYERJUSTIFY_LEFT_BIT0LSB cadence_length = 10 pixels_per_cadence = 1 format = SENSOR_BAYERFORMAT_RGGBThis example describes a 10-bit Bayer frame where each 10-bit pixel is tightly packed into a 10-bit word. There are no wasted bits in between pixels in this example. Each word is stored in big-endian byte order. Bit 0 represents the least significant bit, and the bits are justified to the left of each byte.
The Bayer macro-pixels in one cadence would be stored like so, with PxHi indicating the most significant bits of pixel x, and PxLo indicating the least significant bits of pixel x:
Bits: 76543210 Scanline n, byte 0: RRRRRRRR P1Hi(Red) Scanline n, byte 1: RRGGGGGG P1Lo(Red) & P2Hi(Green) Scanline n, byte 2: GGGGRRRR P2Lo(Green) & P3Hi(Red) Scanline n, byte 3: RRRRRRGG P3Lo(Red) & P4Hi(Green) Scanline n, byte 4: GGGGGGGG P4Lo(Green) ...and repeats. Scanline n+1, byte 0: GGGGGGGG P1Hi(Green) Scanline n+1, byte 1: GGBBBBBB P1Lo(Green) & P2Hi(Blue) Scanline n+1, byte 2: BBBBGGGG P2Lo(Blue) & P3Hi(Green) Scanline n+1, byte 3: GGGGGGBB P3Lo(Green) & P4Hi(Blue) Scanline n+1, byte 4: BBBBBBBB P4Lo(Blue) ...and repeats.
le = true bpp = 10 packing = 10 justification = SENSOR_BAYERJUSTIFY_RIGHT_BIT0LSB cadence_length = 64 pixels_per_cadence = 6 format = SENSOR_BAYERFORMAT_RGGBThis example describes a 10-bit Bayer frame where each 10-bit pixel is tightly packed into a 10-bit word, and six pixels are packed into a 64-bit cadence. The word is stored in little-endian byte order. Bit 0 represents the least significant bit and the bits are justified to the right of each byte. This leaves four unused bits for each six-pixel cadence.
Bits: 76543210 Scanline n, byte 0: RRRRRRRR P1Lo(Red) Scanline n, byte 1: GGGGGGRR P2Lo(Green) & P1Hi(Red) Scanline n, byte 2: RRRRGGGG P3Lo(Red) & P2Hi(Green) Scanline n, byte 3: GGRRRRRR P4Lo(Green) & P3Hi(Red) Scanline n, byte 4: GGGGGGGG P4Hi(Green) Scanline n, byte 5: RRRRRRRR P5Lo(Red) Scanline n, byte 6: GGGGGGRR P6Lo(Green) & P5Hi(Red) Scanline n, byte 7: 0000GGGG 4 bits unused & P6Hi(Green) ...and repeats. Scanline n+1, byte 0: GGGGGGGG P1Lo(Green) Scanline n+1, byte 1: BBBBBBGG P2Lo(Blue) & P1Hi(Green) Scanline n+1, byte 2: GGGGBBBB P3Lo(Green) & P2Hi(Blue) Scanline n+1, byte 3: BBGGGGGG P4Lo(Blue) & P3Hi(Green) Scanline n+1, byte 4: BBBBBBBB P4Hi(Blue) Scanline n+1, byte 5: GGGGGGGG P5Lo(Green) Scanline n+1, byte 6: BBBBBBGG P6Lo(Blue) & P5Hi(Green) Scanline n+1, byte 7: 0000BBBB 4 bits unused & P6Hi(Blue) ...and repeats.
Looking at Scanline n, byte 1, you should see that the P1Hi bits (the most significant bits of pixel 1) begin at the right of the byte. The reason is because right justification is indicated by SENSOR_BAYERJUSTIFY_RIGHT_BIT0LSB. This example is in contrast to Example 2 where the bits are justified to the left, and occupy the upper bits of Scanline n, byte 1.