What is the standard way of using Q15 values?

Posted by Alex on Game Development See other posts from Game Development or by Alex
Published on 2012-08-29T15:00:28Z Indexed on 2012/08/29 15:50 UTC
Read the original article Hit count: 193

Filed under:

To process 8-bit pixels, to do things like gamma correction without losing information, we normally upsample the values, work in 16 bits or whatever, and then downsample them to 8 bits.

Now, this is a somewhat new area for me, so please excuse incorrect terminology etc.

For my needs I have chosen to work in "non-standard" Q15, where I only use the upper half of the range (0.0-1.0), and 0x8000 represents 1.0 instead of -1.0. This makes it much easier to calculate things in C.

But I ran into a problem with SSSE3. It has the PMULHRSW instruction which multiplies Q15 numbers, but it uses the "standard" range of Q15 is [-1,1-2?¹5], so multplying (my) 0x8000 (1.0) by 0x4000 (0.5) gives 0xC000 (-0.5), because it thinks 0x8000 is -1. This is quite annoying.

What am I doing wrong? Should I keep my pixel values in the 0000-7FFF range? This kind of defeats the purpose of it being a fixed-point format. Is there a way around this? Maybe some trick?

Is there some kind of definitive treatise on Q15 which discusses all this?

© Game Development or respective owner

Related posts about pixel