[cairo] rcairo's RGB -> HSV conversion has an error

Yuta Taniguchi yuta.taniguchi.y.t at gmail.com
Sun Jan 10 01:18:53 PST 2010


Hi,

Using rcairo's Color::RGB#to_hsv, I tried to convert a RGB color to a
HSV color, but it returns a wrong color.

I found that RGB#to_hsv has an error that uses wrong conditions in its
case expression. I also checked the latest version (1.8.1), but the
error still exists. So, I decided to report this problem.

This bug can be fixed just by swapping @blue and @green like:

--- /usr/lib/ruby/site_ruby/1.8/cairo/color.rb  2009-09-08
20:29:58.000000000 +0900
+++ color.rb    2010-01-10 15:26:07.922112290 +0900
@@ -123,10 +123,10 @@
           when @red
             numerator = @green - @blue
             angle = 0
-          when @blue
+          when @green
             numerator = @blue - @red
             angle = 120
-          when @green
+          when @blue
             numerator = @red - @green
             angle = 240
           end

Thanks,

Yuta Taniguchi


More information about the cairo mailing list