ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
I know this is possible, i have seen alot of programs do it, but how?
As far as i know (correct me if im wrong) Xlib is pure pallet graphics so does
that mean that i have to allocate every color in a say .tga image file
in order to draw it? I have no internet at the moment (just moved),
only a very old Xlib programming book which doesn't discus color
There's never a full 2^24 size colormap, that would be nonsense, at least until we have more than 4096 x 4096 screens.
TrueColor visuals have 3 colormaps, each 256 entries size, one for each primary color.
Originally posted by jlliagre TrueColor visuals have 3 colormaps, each 256 entries size, one for each primary color.
(Scratches head) Then how is a Color created. For simplicity's sake: I have a color #336699. Therefore it will need R, G, B. But doesnt the color need to be allocated with all three of these values?
I guess I'm just confused. The concept of allocating colors is still a bit odd to me.
Maybe it would help if I explain what I intend to do. I am making a small widget toolkit for flatpanel displays. Currently everything works fine, but it would be nice to test applications in an X session rather than having to have a flat panel attached to one of the computer's ports.
There is a Canvas class and a Screen class. For the X implementation, Canvas basically wraps an XImage and provides functions like DrawLine, DrawRect, etc. A Canvas is bound to a particular Screen. The Screen wraps a drawable such as a Window. Widgets are drawn through the canvas. Somehow I need either the Screen or Canvas to allocate colors, either initially or dynamically. I'm not sure where to start. Most of the resources online don't cover X's color model very well.
Last edited by AngryLlama; 07-09-2005 at 08:32 PM.
If you want to display a color image to an X11 window, you do not need to allocate every color present in the image, just use a true color visual, and pass it your image.
If you need to use X11 primitives (lines, circles, characters, ...), you neither need to allocate a color to be able to draw with it, just pick its wanted rgb value, and set it to the graphic context you use.
Colormaps (lookup tables) are used with R/W visuals (DirectColor, PseudoColor and GrayScale).
There are no real lookup tables when R/O visuals are used (TrueColor, StaticColor, StaticGray).
In both modes, you can allocate a color whan you want to use it, but you only need to do it with R/W visuals.
The display depth is less and less an issue nowadays, as 24 bit tend to be the norm. Anyway, you may still be able to use true color with 8 bits displays (3:2:2) when available, but the result is usually disappointing.
do I need to allocate colors if I want to use an 8 bit image on a 24/32 bit display?
Yes, unless your 8 bit image is already a 3:3:2 true color one (unlikely).
If your 8 bit image has a lookup table, you need to allocate each one of these colors before displaying it.
Alternatively, you can also convert your image to 24 bit true color, in that case no need to allocate any color.
Is there anyway to support transparency in or with the XImage? I either need a function like XPutImage wish will support an XImage with transparency. Or, I need a way to use a separate Transparency mask. Is there another data structure I can use besides XImage? All I need is simple 1bit transparency, no need for alpha blending.
Another option is to use XGetImage to get the image from the window then draw ontop of that. Then, actually draw the image back to the window. The problem with this is that I need to reformulate all of my images whenever the underlaying window changes.
If there isn't a way around this then I guess I will have to write my own rasterizer using XDrawPoints (it will be slow as heck). I've been looking around the forums, google, and man pages and the outlook doesn't look too good.
Last edited by AngryLlama; 07-13-2005 at 01:48 PM.