Xref: utzoo comp.graphics:3864 comp.windows.x:6513 Path: utzoo!attcan!uunet!seismo!sundc!pitstop!sun!decwrl!karlton From: karlton@decwrl.dec.com (Philip Karlton) Newsgroups: comp.graphics,comp.windows.x Subject: Re: Luminance from RGB Message-ID: <964@bacchus.dec.com> Date: 6 Dec 88 02:52:32 GMT References: <8811042303.AA21505@dawn.steinmetz.GE.COM> <8811070533.AA08904@vector.sun.com> <8811080030.AA14681@EXPO.LCS.MIT.EDU> <76649@sun.uucp> <6698@watcgl.waterloo.edu> Organization: DEC Western Software Lab, Palo Alto, CA Lines: 42 I found the entire discussion on luminance last month quite interesting. What I would like now from the experts is what they would do to convert an RGB value as specified in the X protocol into a gray level. The particular problem I have in mind is that of a StaticGray display with N equally spaced intensities arranged in a ramp with black at 0 and white at N-1. I have access to hardware with N of 2, 4, 16, and 256. Two different expressions for computing the appropriate pixel value come immediately to (my) mind: For r, g, b in [0..1] floor((.299r + .587g + .114b)(n - 1) + 0.5) (a) or for r, g, b in [0..1) floor((.299r + .587g + .114b)(n)) (b) (a) and (b) produce almost identical results for N=2. For N=256, the resulting differences are probably not detectable by the human eye, certainly not mine. For N=4, the differences are observable. The correct thing is for the client to have done the appropriate dithering and present the pixmap to the server. For those clients that ignore the visual type of the root window, the server has to do the mapping of RGB (in X's terms) to some pixel value. Is either (a) or (b) the appropriate choice. Is some better function around that I should use? For the numerically curious: r, g, and b above could be computed using r = ((float) screenRed) / maxColor; b = ((float) screenBlue) / maxColor; g = ((float) screenGreen) / maxColor; where maxColor is dependent upon which of (a) or (b) is chosen: float maxColor = (float) (0xFFFF); /* (a) */ or float maxColor = (float) (0x10000); /* (b) */ PK