Access pixels from MIPI camera


I am going to receive a new camera, the FSM-IMX304M ( The bit depth is 12, the chromacity is mono.
I need to access at each pixel one by one.

From my reading and discussions, when we call :


the buffer is filled like that :

|              16 bits                          |

To obtain the value of each pixel, I have to change the bitmap like that :

D5-D4-D3-D2-D1-D0-D11-D10-0-0-D11-D10-D9-D8-D7-D6 → D0-D1-D2-D3-D4-D5-D6-D7-D8-D9-D10-D11

Is it right ?

Notice that I use a streamlined V4L2.

Thank you for your help

Hi @anon79190853,

From the TRF (Technical Reference Manual), section 27.10.6 RAW Memory Formats, you can refer to the following image

So, indeed for a bit depth of 12, the valid data are the bits D0-D1-D2-D3-D4-D5-D6-D7-D8-D9-D10-D11


Hi Fabian,

Thank for your answer.
It is my first time and I do not have access to pixel’s value …

I use V4L2 to capture image.

First problem :

The resolution of my camera is 4112*3008. The pixel format is RG12, and it is monochrome sensor. I expect a .raw of 24737792 B, but it is 25411584 B. This difference is from padding, but what it is exactly ?

Second problem :

To read pixel value, first I cast the void* by an unsigned short*. Then, I just remove the MSB replicate :

unsigned short GetPixel(const void* data, const int heightIndice, const int widthIndice)
unsigned short* pixel = (unsigned short*) data ;
unsigned short mask = 16364 ;
pixel[heightIndicewidth+widthIndice] = pixel[heightIndicewidth+widthIndice] & mask ;

return pixel[heightIndice*width+widthIndice] ;


For example, if I want the read the pixel[i,j], I call the function like that :

unsigned short value = GetPixel(buffer, i, j) ;

My code doesn’t work because of padding (I hope), but is it the right method ?

Thank you