[cairo] rewriting libpixman

James Cloos cloos at jhcloos.com
Thu Apr 5 13:49:40 PDT 2007

>>>>> "Jeff" == Jeff Muizelaar <jeff at infidigm.net> writes:

Jeff> Why should we prefer:

Jeff> 28*256/31 = 231.225806451

Jeff> instead of

Jeff> 28*255/31 = 230.322580645

Jeff> when:

Jeff> 28/31 = .903225806
Jeff> and
Jeff> 231/255 = .905882352
Jeff> 230/255 = .901960784

First of all, I want to reiterate that my initial reply was (only) an
hypothesis of an explanation using only multiplication and division of
the effect of the shifts and ORs.

I'm concerned that I obfuscated that by explaining why I came to that
hypothesis.  The float to/from int conversions are orthogonal to
converting between integer samples of different sizes.

The correct way to expand a 5-bit sample of 28 (decimal) into an 8-bit
sample is to note that 28 is 11100 in binary, so shift that (8-5) bits
left (resulting in 11100000) and also (8-5-5) bits left (which is of
course 2 bits right) (resulting in 111) and OR them (11100111).
Converting back to decimal we get 231.

So out goal is to get 231 as our result.  And your math shows that
multiplying by 256/31 does give that result.

James Cloos <cloos at jhcloos.com>         OpenPGP: 1024D/ED7DAEA6

More information about the cairo mailing list