home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.windows.x
- Path: sparky!uunet!utcsri!newsflash.concordia.ca!sifon!thunder.mcrcim.mcgill.edu!mouse
- From: mouse@thunder.mcrcim.mcgill.edu (der Mouse)
- Subject: Re: Color in XImage?
- Message-ID: <1992Nov10.062411.5487@thunder.mcrcim.mcgill.edu>
- Organization: McGill Research Centre for Intelligent Machines
- References: <1992Nov8.080422.12600@ringer.cs.utsa.edu>
- Date: Tue, 10 Nov 92 06:24:11 GMT
- Lines: 37
-
- In article <1992Nov8.080422.12600@ringer.cs.utsa.edu>, rhanuman@ringer.cs.utsa.edu (Raghu Hanumanthaiah) writes:
-
- > I have an array of pixels and each pixel has 3 8-bit components (red,
- > green, blue) which define the color of the pixel. How do I pass this
- > information to the XImage structure so as to may it recognize the
- > proper RGB values and render them appropriately?
-
- You may not be able to, not directly. The pixel values in an XImage
- are pixel values - which sounds tautological, but when you notice that
- (except for the relatively rare TrueColor and to some extent
- DirectColor visual types), pixel values are not simple RGB triples, it
- indicates your problem.
-
- If you have a TrueColor visual available, constructing pixel values
- from your RGB values will be fairly easy; you just need to shift and
- mask each primary and assemble the pixel value. For DirectColor, the
- same is true, but you also need to make sure that your colormap has
- appropriate ramps loaded into it.
-
- The next easiest visual type is probably StaticColor; for this, you can
- either call XAllocColor for each distinct color in the picture to get
- the pixel values (which will be very time-consuming unless the picture
- is either small or has large areas of constant color) or you can use
- XQueryColors to read back the colormap and pick the colors yourself
- (depending on the picture and the desired effect, dithering may help).
-
- PseudoColor is just like StaticColor except that you have to choose the
- colors. There are various algorithms around to do this; see ppmquant
- for an example.
-
- GrayScale and StaticGray are just like PseudoColor and StaticColor
- except that only shades of gray are available.
-
- der Mouse
-
- mouse@larry.mcrcim.mcgill.edu
-