Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!cs.utexas.edu!uunet!ingr!b11!doyle From: doyle@b11.ingr.com (Doyle Davidson) Newsgroups: comp.windows.x Subject: Color to Grayscale mapping Message-ID: <5631@b11.ingr.com> Date: 4 Aug 89 21:25:21 GMT Organization: Intergraph Corp. Huntsville, AL Lines: 67 I have a question about how color allocation is done on a StaticGray color display. I have a client (twm for example) that has its color parameters specified by names like "red", "blue", "thistle" etc... Upon running this on a StaticGray display, I discovered that the following occurs: Color R G B Gray level -------- --- --- --- ------------- "red" 255 0 0 33% "blue" 0 0 255 33% "green" 0 255 0 33% "black" 0 0 0 0% "white" 255 255 255 100% Now, I have read several interpretations and none really match this except for the code itself! 1) O'Reilly & Assoc: p.207 intensity = (0.30 * red) + (0.59 * green) + (0.11 * blue) really happens? WRONG! (no flame intended at O'Reilly & Assoc) 2) O'Reilly & Assoc: p.207 next sentence: "If only a GrayScale visual is available, the red value ONLY will be used for gray scale intensity" really happens? WRONG! I thought that #1 just said... owell. If #2 is right then "green" and "blue" should map to black. 3) I read the protocal on the distribution tape: nothing that I found said anything specific and is not part of the DDX layer :-( I remember reading in something that R G and B should all be set to the same value by the client because it cannot be sure which one of these three that the server will use as an intensity. I cannot find it now to quote from it unfortunately. 4) I looked at the code: it searches through the RGB values for the Grayscale color table (which are all the same) and finds the color that minimizes the following (in pseudocode): in dix/colormap.c: FindBestPixel() for (all RGB pixel values in table) value = (red_asked - red_table)^2 + (greed_asked - green_table)^2 + (blue_asked - blue_table)^2 /* like a 3D distance formula but no square root */ if (value < best_so_far) { pixel = current_pixel_being_testing_from_table; best_so_far = value; } really happens? Yes!! Hey this is it but not documented ANYWHERE Hey you guys at MIT, got the answer? Thanks in advance, Doyle (I RTFMs and am still confused :-O ) Davidson ------------------------------------------------------------------ Doyle C. Davidson | Intergraph Corp. | These comments are... Workstation Graphics Standards | 1 Madison Industrial Park | Huntsville, AL 35806 | (205) 772-2000 | X-clusively my own. | ..!uunet!ingr!b11!doyled!doyle | ------------------------------------------------------------------