From: pandeng@telepath.com (Steve Schafer (TeamB)) Subject: Re: How to make bitmap black/white Date: 30 Jul 1999 00:00:00 GMT Message-ID: <37b13016.261527215@90.0.0.40> Content-Transfer-Encoding: 7bit References: <7npulk\$add14@forums.borland.com> <7nq23p\$adk15@forums.borland.com> <7nqe38\$aon12@forums.borland.com> <37b42e1a.195472753@90.0.0.40> <7nrecr\$bk34@forums.borland.com> Content-Type: text/plain; charset=us-ascii Organization: TeamB Mime-Version: 1.0 Reply-To: pandeng@telepath.com Newsgroups: borland.public.delphi.graphics On Fri, 30 Jul 1999 00:43:20 -0500, "Earl F. Glynn" wrote: >Contemporary CRT phosphors are standardized today with CIE luminance from >linear red, green and blue to be: > >Y = 0.212671R + 0.715160G + 0.072169B True, but in reality, monitor calibration has an effect large enough to swamp the differences between this and the other formula. Also, color perception depends strongly on background illumination; perceived luminance values from a monitor image viewed in a brightly-lit room are not the same as those perceived when the same monitor is viewed in a darkened room. The above formulas are also only accurate when applied to linear (gamma-corrected) RGB values. Including the conversion from device RGB to gamma-corrected RGB and back (assuming a gamma of 2.2) yields the following: function Gray(R, G, B: Byte): Byte; function Linearize(C: Byte): Double; begin Result := C / 255; if Result <= 0.03928 then Result := Result / 12.92 else Result := Exp(2.4 * Ln((Result + 0.055) / 1.055)) end; function Unlinearize(D: Double): Byte; var T: Double; begin if D <= 0.00304 then T := 12.92 * D else T := 1.055 * Exp(Ln(D) / 2.4) - 0.055; Result := Round(255 * T) end; begin Result := Unlinearize(0.2126 * Linearize(R) + 0.7152 * Linearize(G) + 0.0722 * Linearize(B)) end; -Steve