Dr Andrew C Aitchison <[EMAIL PROTECTED]> wrote:
>
> On Wed, 23 Oct 2002, Kunxiu Gao wrote:
>
> > Hi,
> >
> > I currently have XFree86 4.1.0 on the redhat 7.2 machine. I am trying to
> > program for the 16bit color display, but I just could not get the color
> > right. I already have the correct display for 8bit and 24bit on this
> > machine. Some help is needed and will be appreciated.
> >
> > Since the display is 16bit, according to the result of xdpyinfo (see
> > below), the masks for r,g,b are 0xf800, 0x7e0, 0x1f. Does it mean
> > the following formula should generate the correct entry for a color
> > with r, g, b value red, green and blue?
> > red && 0xf800 + green && 0x7e0 + blue && 0x1f
>
> I think you want:
> ((red << 11) && 0xf800) + ((green << 5) && 0x7e0) + (blue && 0x1f)
Actually, you want to take the most significant 5 or 6 bits from each
red/green/blue value. And the bitwise AND operator is &, not &&.
Assuming the red/green/blue values are in the range 0-65535 (as they
would be in an XColor struct), the formula would be...
(red & 0xf800) + ((green >> 5) & 0x7e0) + ((blue >> 11) & 0x1f)
But I'm surprised you would need to do anything special for a 16-bit
screen. The XAllocColor(3X) function should do the conversion for
you, and for TrueColor visuals it doesn't even need to send a request
to the server -- it does the conversion locally via the above formula,
or something similar. Using an inline formula would be faster though,
which might matter if you're converting all the pixels in an image.
_______________________________________________
Xpert mailing list
[EMAIL PROTECTED]
http://XFree86.Org/mailman/listinfo/xpert