简体   繁体   中英

write 10 bit values to a char array

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. ie 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.

You can't. The format of a line is decided by the read_line function. You need to read the documentation of this function to find out what format it uses, and then convert the values you get into your internal format using some bit twiddling.

Or otherwise decide that the format the function uses is better than your internal one, and convert your program to use it directly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM