Convert from 8 bits to 16 bits

I have an image that captures 8 bits. I want to convert 8-bit values ​​to 16 bits. I used the following

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

where val is an array of 8 bit samples.

The above statement causes noise. Can anyone suggest a method for converting from 8 to 16 bits?

+4
source share
3 answers

Pure bit-lifting will not give you pure white. 0xff <8 == 0xff00, not 0xffff as expected.

One trick is to use val [i] <8 + val [i] and remember the correct data types (size, signature). This way you get 0x00 β†’ 0x0000 and 0xff β†’ 0xffff.

+2
source

Is val [] signed or unsigned 8-bit? Add it to unsigned (if you have the usual convention 0 = darkest, 255 = brightest), then drop it to short short (I assume that what you want is because the usual "short" is signed by default).

+4
source

All Articles