/**
* Multispectral Sensor 10bit(16bit from HAL) raw to gray image, and 1/16 downsampling.
*
* @param imgSrc 16bit raw(actually 10bit valid data.
* @param isFullSize
* @param isGray
* @param channel 0-15
*/
public int[] Raw2Gray(byte[] imgSrc, boolean isFullSize, boolean isGray, int channel) {
// 2608 x 1960 = 5111680 pixel
// 652 x 490 = 319480 pixel 1/16 binning
int display_width;
int display_height;
int row_offset;
int col_offset;
int[] imgInt;
if(isFullSize == true) {
// Full size
display_width = 2608;
display_height = 1960;
imgInt = new int[display_width * display_height];
for(int i = 0; i < display_width * display_height; i++) {
// Big-Endian
// full size
if(isGray == false) {
imgInt[i] = (imgSrc[1 + 2*i] & 0xFF) |
((imgSrc[2*i] & 0xFF) << 8) |
(0x00 << 16) |
(0xFF << 24);
//other way
// imgInt[i] = (imgSrc[2*i] & 0xFF) | (imgSrc[1+2*i] & 0xFF <<8) |
// (0x00 << 16) |
// (0xFF << 24);//this means Alpha,0xFF means opaque
} else {
byte gray_pixel = (byte) (((imgSrc[1 + 2*i] << 6) & 0xC0) | ((imgSrc[2*i] & 0xFF) >>> 2));
imgInt[i] = gray_pixel & 0xFF |
(gray_pixel & 0xFF) << 8 |
(gray_pixel & 0xFF) << 16 |
0xFF << 24;
}
}
}
else {
// 1/16 Downsampling
display_width = 652;
display_height = 490;
row_offset = channel / 4 * 2608;
col_offset = channel % 4;//columns
Log.e(TAG, "Raw2Gray--row: " + row_offset + "col: " + col_offset+", channel = "+channel);
imgInt = new int[display_width * display_height];
for(int h = 0; h < display_height; h++)
{
int tmp = h * display_width;
int tmp_src = 16 * tmp;
for(int w = 0; w < display_width; w++)
{
// Big-Endian
// 1/16 binning
if(isGray == false) {
/*
imgInt[tmp + w] = (imgSrc[1 + 2*(tmp_src + row_offset + 4*w + col_offset)] & 0xFF) |
((imgSrc[2*(tmp_src + row_offset + + 4*w + col_offset)] & 0xFF) << 8) |
(0x00 << 16)|
(0xFF << 24);
*/
//xll
imgInt[w + h * display_width] = (imgSrc[1+ 2*(w*4+ col_offset + row_offset + h*display_width*16)]& 0xFF) |
((imgSrc[2*(w*4+ col_offset + row_offset + h*display_width*16)] & 0xFF) <<8) |
(0x00 << 16)|
(0xFF << 24);
} else {
// 1/16 binning & gray
byte gray_pixel = (byte) (((imgSrc[1 + 2*(tmp_src + row_offset + 4*w + col_offset)] << 6) & 0xC0) |
((imgSrc[2*(tmp_src + row_offset + + 4*w + col_offset)] & 0xFF) >>> 2));
imgInt[tmp + w] = gray_pixel & 0xFF |
(gray_pixel & 0xFF) << 8 |
(gray_pixel & 0xFF) << 16 |
0xFF << 24;
}
}
}
}
return imgInt;
}
转灰度值