目前在手持設備上,Raw Sensor吐出的數據通常都是RAW10,即一個像素用10 bit來存儲,下面經過用位域的方式來簡單的對兩塊RAW10數據進行相加運算,以此來達到像素疊加的效果。code
typedef unsigned long long MUINT64; typedef unsigned int MUINT32; typedef unsigned char MUINT8; struct pixel16 { MUINT64 p1 : 10; MUINT64 p2 : 10; MUINT64 p3 : 10; MUINT64 p4 : 10; MUINT64 p5 : 10; MUINT64 p6 : 10; }; struct pixel78 { MUINT32 pad : 4; MUINT32 p7 : 10; MUINT32 p8 : 10; }; void composePixel(MUINT8 *buf1, MUINT8 buf2) { MUINT8 pixel[8] = { 0 }; ... pixel[0] = ((struct pixel16 *) buf1)->p1 + ((struct pixel16 *) buf2)->p1; pixel[1] = ((struct pixel16 *) buf1)->p2 + ((struct pixel16 *) buf2)->p2; pixel[2] = ((struct pixel16 *) buf1)->p3 + ((struct pixel16 *) buf2)->p3; pixel[3] = ((struct pixel16 *) buf1)->p4 + ((struct pixel16 *) buf2)->p4; pixel[4] = ((struct pixel16 *) buf1)->p5 + ((struct pixel16 *) buf2)->p5; pixel[5] = ((struct pixel16 *) buf1)->p6 + ((struct pixel16 *) buf2)->p6; pixel[6] = ((struct pixel78 *) (buf1 + 7))->p7 + ((struct pixel78 *) (buf2 + 7))->p7; pixel[7] = ((struct pixel78 *) (buf1 + 7))->p8 + ((struct pixel78 *) (buf2 + 7))->p8; ... }
僅僅選取了 0 號字節單元到7 號字節單元部分運算。內存
數據在內存中是連續存放的,因此定義兩個pixel16和pixel78結構體,方便從內存中取出數據,而後解析爲對應的像素。it
經過上述代碼可知,class
[0... 59] --- pixel1~pixel6 [60...80] --- pixel7~pixel7, [56...59] --- pad
即 第0號字節單元的 bit0 到第7號字節單元的bit59,就是pixel 1 ~pixel 6,一共60 bit(6個像素)數據
而後從第7號字節單元開始取數據,但第7號字節單元的bit56... bit59 一個四位數據是pixel 6的後四位數據,所以用pad來佔位。從 第7號單元的bit60...bit 80爲pixel 7 和pixel 8的數據。co
則能夠很方便的將數據從buf中取出,而後對單個像素進行處理運算。結構體