[SOLVED] How to display gray colors in 24-bit using XWindows
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
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.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How to display gray colors in 24-bit using XWindows
Hi All,
Currently I have a very old application based on 8-bit color depth on Xsun on Solaris platform which displays gray images.
At present its working fine but I want to improve the image quality by going to 24-bit mode, so that I can get more shades of gray color.
I am a newbie in Xlib programming so don't know how to get gray color for my image in 24-bit color depth.
In 8-bit, I used to allocate <=256 pixels from the default colormap and then fill them with gray colors and store this pixel values in a array.
But in 24-bit, I am not sure what to do because it has 16 million colors, I can't allocate them all and can't store them in an array as it doesn't seem to be the logical solution.
I will appreciate if some one provides me the right pointers, to proceed further,as I am really stuck with this problem.
A 24-bit colour is made up of three 8-bit values, Red, Green & Blue. If I remember correctly they come in that order. For grey scale the Red, Green and Blue values will all be equal, hence a (128, 182, 128) triplet will be 50% grey. The (128, 182, 128) triplet will have a hex value of 808080.
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195
Rep:
In addtion to what graemef says, there are only 256 shades of gray in a 24-bit color environment. Surprisingly, this is exactly equal to the number of grey shades you could have in an 8-bit monochrome system.
In this case it could suffice to create any array with 256 entries each containing a value with equal values vor R, G and B.
Thanks for your reply. I really appreciate your response on my issue.
But I am little confused when you say we can have only 256 shades of gray color even on 24-bit color depth. As per my understanding, I thought we will have more shades of colors in 24-bit as compared to 8-bit.
If I still get 256 gray colors in 24-bit, can I expect my image quality to improve.
Also, I am using Xlib/Xwindows calls to display my image, Can I have small program to understand it better as I am still not sure how to modify my code to make it work for 24-bit?
If required, I can provide litle more details on my implementation.
You will only have 256 shades to choose from with the extremes being black and white. However you have the whole depth of different colours as well and certainly some colours that are not true greys may appear that way, for example (128,127,129) #807F81 is not a true grey because it will have more blue than green but it "looks" like a grey.
If you have access to kde look at the KColorChooser program to get an idea of how 24-bit colour works.
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195
Rep:
Quote:
Originally Posted by anurag4u
But I am little confused when you say we can have only 256 shades of gray color even on 24-bit color depth. As per my understanding, I thought we will have more shades of colors in 24-bit as compared to 8-bit.
In 24 bits your color triplets for gray are 010101, 020202, 030303... fefefe, ffffff. Those are really just 256 different values. There is no way to get more gray values, unless you want to try graemef's suggestion, which is mathematically not gray although it might improve your perception.
You get more shades of gray in 24-bit color than in 8-bit color, but the same as in 8-bit monochrome. I think the older Sun's were monochrome. In monochrome you have only one color value, and that happens to be gray (or green, or amber...) So your value is 01,02,03...fe,ff. Exactly the same as gray values in 24-bits.
Old Windows(TM) systems could only display 256 colors at the same time. Even then it was possible to have all of those color be a shade of gray, just by filling the palette only with equal values for R,G and B.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.