[Libreoffice] [Patch] Code review fix

Lionel Elie Mamane lionel at mamane.lu
Mon Dec 5 03:41:41 PST 2011


On Mon, Dec 05, 2011 at 05:26:00PM +0530, Muthu Subramanian K wrote:

> During the code digging for one of the bugs, I came across GetXPixel()
> function in vcl. Which seems to be implemented wrong - not sure why it
> is multiplied by 257 - the idea, I believe, is to convert 8bit to 16bit
> values for X11, but I may be wrong.

I think that is the idea, too. But your patch means we will never
output pure white. Let me explain.

Each component in 8 bit is from 0 to 255 (0xFF). In 16 bits, from 0 to
65535 (0xFFFF). When converting, we want to map 00 to 0, and the
maximum value to the maximum value. But your patch maps 255 to 65280
(0xFF00). So it maps pure white (RGB8 0xFF 0xFF 0xFF) to light grey
(RGB16 0xFF00 0xFF00 0xFF00).

OTOH, 255*257 is exactly 65535 :)

Multiplying by 257 maps:

 0x00 to 0x0000
 0x01 to 0x0101
 0x02 to 0x0202
 ..
 0xB3 to 0xB3B3
 ..
 0xFF to 0xFFF

Giving a nice constant 16-bit difference between two consecutive 8-bit
values.

Maybe that code would be more clear if instead of "*257", it did
something like "r<<8  + r" or "r<<8 | r"?

Thanks for raising the question, tough.

-- 
Lionel


More information about the LibreOffice mailing list