Finding the bayer pattern for Canon T2i (550D)

I am using libraw for a CR2toFits conversion program i wrote. It extracts either a raw CFA image or a debayered RGB colour image and creates a FITs file. And since it's just for me, it only handles the Canon T2i CR2 files. I had been using libraw v0.19.2 but just upgraded to libraw v0.20.0.

I use librawFile.unpack() to load the raw data.
Then access the raw data use librawFile.imgdata.rawdata.raw_image[b] to read the sensor pixel values.

I note that there was a change in reporting the margins for the Canon T2i. In v0.19.2, top_margin = 51 and left_margin = 142. With v0.20.0 top_margin = 51 and left_margin = 142. (Curiously the exif meta data from the CR2 file reports topMargin = 56, leftMargin = 152. Why not use the exif data?).

So, with this shift in top_margin, the bayer pattern is also shifted. The first 2x2 group using v0.19.2 was RG1G2B. With v0.20.0 the bayer pattern is now G2BRG1.

I had hard coded the RGGB bayer pattern in my 1st implementation, but now i would to automate the process to i don't get caught again if margins change. But i can't find a place where the bayer pattern and/or raw pixel colour is identified.

I checked librawFile.imgdata.idata.cdesc but it is "RGBG" in both v0.19.20 and v0.20.0. I was expecting it to reflect actual bayer pattern. It does not reflect the bayer pattern for the 1st 2x2 square using either version.

I checked LibRaw::COLOR(row, col) but again the 1st 2x2 square is always "3 2 0 1" in both libraw versions.

So, how i can i recover the bayer pattern and colour of a pixel from the raw data?

Forums: 

cdesc describes color index

cdesc describes color index to color name translation, this is not pattern.

LibRaw::COLOR(row,col) returns color index for given row,col; It is not the same for LibRaw 0.19 and 0.20, please recheck (at least, imgdata.idata.filters are different, so COLOR() output should be different also)

-- Alex Tutubalin @LibRaw LLC