• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps How to demosaic a bayer RAW image?

Reto

Lurker
Feb 28, 2018
1
0
Hi,

I have a proprietary bayer RAW image which I need to demosaic on Android to display the image. I am reading the file header byte by byte to retrieve the resolution info (imageWidth/imageHeight). After the header there is the pixel data from byte 2000 and following. How can I demosaic this bayer pixel data on Android to display the image?

Here is my code which reads the byte data and retreives the resolution:

Java:
File file = new File(path);
int size = (int) file.length();
byte[] bytes = new byte[size];
try {
   BufferedInputStream buf = new BufferedInputStream(new FileInputStream(file));
   buf.read(bytes, 0, bytes.length);
   buf.close();
} catch (FileNotFoundException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
} catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
}

int x1 = bytes[1056];
int x2 = bytes[1057];
int x3 = bytes[1058];
int x4 = bytes[1059];
int imageWidth = (x1 << 24) + (x2 << 16) + (x3 << 8) + x4;

int y1 = bytes[1056];
int y2 = bytes[1057];
int y3 = bytes[1058];
int y4 = bytes[1059];
int imageHeigth = (y1 << 24) + (y2 << 16) + (y3 << 8) + y4;

// image data bytes[2000] and following, one pixel per byte
//
// bayer format:
//
// BGBGBGBG....
// GRGRGRGR....
// BGBGBGBG....
// ............
// ............
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones