Path: utzoo!attcan!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!nthropy!andy From: andy@nthropy.UUCP (Andy Lowe) Newsgroups: comp.graphics Subject: bug in hls_to_rgb from Foley, van Dam, Feiner, Hughes Message-ID: <9009301931.AA14664@nth.com> Date: 30 Sep 90 19:31:24 GMT Lines: 59 Posted-Date: Sun, 30 Sep 90 14:31:24 CDT To: comp-graphics@cs.utexas.edu Greetings. I had occasion to implement an hls to rgb converter for a research project, and turned to the new Foley, vanDam, Feiner, Hughes book for the algorithm. On p. 596 is a procedure that purports to do the conversion. While studying it, I couldn't see how it worked. In fact, it violated the stated bounds on r, g and b! (try it with h = 0.) Following the references, they cited Metrick in the Status Report of the GSPC from 1979. Having once implemented a subset of the Core proposed standard, I just happened to have this volume handy. Aside from differences in convention (the GSPC put blue at 0 degrees, while Foley et al put red at 0 degrees), I think I found three bugs in this procedure! Can someone tell me I'm wrong? (please.) -------------------- begin quote -------------------- procedure HLS_To_RGB (var r, g, b: real; h, l, s: real); ... function Value (n1, n2, hue) begin if hue > 60 then { should be "if hue < 60 then" !? } ... else if hue < 240 then Value := n1 + (n2 - 1) * (240 - hue) / 60 { should be "Value := n1 + (n2 - n1) * (240 - hue) / 60" } ... end {Value} begin { HLS_To_RGB } if l <= 0.5 then ... else m2 := l + s - l * s; { should be "m2 := l + s + l * s" ?! } m1 := 2 * l - m2 { style nit. indentation indicates this is part of the else. syntactically ok, though. } ... end { HLS_To_RGB } -------------------- end quote -------------------- thanks, and regards. Andy Lowe andy@nth.com p.s. -- please Refer to Computer Graphics -- Principles and Practice Foley, van Dam, Feiner, Hughes Addison-Wesley, 1990 for the complete procedure.