andy@nthropy.UUCP (Andy Lowe) (10/01/90)
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.ellswort@sargent.cs.unc.edu (David Ellsworth) (10/02/90)
In article <9009301931.AA14664@nth.com> andy@nthropy.UUCP (Andy Lowe) writes: > >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. (various problems omitted) > >Can someone tell me I'm wrong? (please.) > > (pseudocode on how the algorithm is wrong deleted) Sorry, you are right. The bug list for the book lists these problems with the figure you are referencing: 596, Fig. 13.37, line 4: "n1, n2, hue" -> "n1, n2, hue: real" 596, Fig. 13.37, line 8: "if" -> "else if" 596, Fig. 13.37, line 10: ">" -> "<" 596, Fig. 13.37, line 15: "n2 - 1" -> "n2 - n1" 596, Fig. 13.37, line 22: "l + s - l * s" -> "l + s + l * s" 596, Fig. 13.37, line 23: move line left, flush with "else" two lines above I got the bug list by sending a message to graphtext@cs.brown.edu with a subject of "Get-Text-Bug-List" (as described in a posting about 80 articles back by ethan@thinc.UUCP (Ethan Lish)). --------------- David Ellsworth ellswort@cs.unc.edu