Question

Compose two raw image buffers:

  1. The Bayer raw data including 10 bits per one pixel;
  2. a raw buffer has 4192x3104 pixels
  3. simply add the corresponding bit data
  4. using C/C++ lang
  5. on the Android mobile platform

How to compose the two raw buffers effectively?

Now, I try to do it like this:

  1. read 8 pixels from rawBuf1 and rawBuf2, since I can use a 16 bit array (unsigned short pixelWord[5]) with 5 lengths to store them( 8X10 bits = 5x16 bits)
  2. I do like this: the p0 unsigned short p0 = (unsigned short )((pixelWord1[0] & 0X03FF) +(pixelWord2[0] & 0X03FF)), etc.

But the upper is too inefficient.

Was it helpful?

Solution

The pixel data comes as a stream of bytes, stored in a raw buffer

unsigned char rawBuf1[100], rawBuf2[100];

Depending on the endianness of your platform, you might try bit fields and let the compiler figure out, how to access the pixels

struct pixels0 {
    unsigned long long p0 : 10;
    unsigned long long p1 : 10;
    unsigned long long p2 : 10;
    unsigned long long p3 : 10;
    unsigned long long p4 : 10;
    unsigned long long p5 : 10;
};

struct pixels6 {
    unsigned long long pad : 4;
    unsigned long long p6 : 10;
    unsigned long long p7 : 10;
};

You would use this as

unsigned short p0 = ((struct pixels0*)&rawBuf1[0])->p0 + ((struct pixels0*)&rawBuf2[0])->p0;
/* ... */
unsigned short p5 = ((struct pixels0*)&rawBuf1[0])->p5 + ((struct pixels0*)&rawBuf2[0])->p5;
unsigned short p6 = ((struct pixels6*)&rawBuf1[7])->p6 + ((struct pixels6*)&rawBuf2[7])->p6;
unsigned short p7 = ((struct pixels6*)&rawBuf1[7])->p7 + ((struct pixels6*)&rawBuf2[7])->p;

But be aware, that this is highly platform and compiler dependent, if it works at all.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top