Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

8bit to 16bit conversion

Tags:

c

image

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?

like image 958
sontnh Avatar asked Jun 22 '11 04:06

sontnh


1 Answers

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.

like image 87
kauppi Avatar answered Sep 25 '22 00:09

kauppi