write 10 bit values to a char array

Viewed 487

I am trying to write 10 bit values (image with a high dynamic range) to a char * array. So, if I have an image which is size 10 x 10, I am assigning an array as:

char * buffer = [10 * 10 * 2];

The idea is that each pixel can be stored in 2 bytes. Now, on my device I have an API call that can read one line of the image. i.e. I can do something like:

for(int i = 0; i < 10; ++i)
{
    char * current = &buffer[i * 10 * 2];
    read_line(current);
    // Map to 10-bit here...
}

Now, this function reads in the byte stream. How can I ensure that each 2 byte word is mapped correctly to the 10 bit value, so that when I case this array to a short type, each value is the 10 bit pixel value before 0-1023.

1 Answers
Related