简体   繁体   中英

8bit to 16bit conversion

I have an image which captures 8 bit. I'm looking to convert the 8 bit values to 16 bit. I used the following

short temp16 =  (short)val[i] << 8 ;

where val is an array of 8 bit samples.

The above statement makes noisy. Can anybody suggest a method for 8bit to 16bit conversion?

Is val[] signed or unsigned 8bit? Cast it to unsigned (assuming you've got the usual convention of 0=darkest, 255=brightest) then cast it to signed short (I assume that's what you want, since plain 'short' is by default signed).

Pure bitshifting won't give you pure white. 0xff << 8 == 0xff00, not 0xffff as expected.

One trick is to use val[i] << 8 + val[i] and remember proper datatypes (size, signedness). That way you get 0x00 -> 0x0000 and 0xff -> 0xffff.

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