Clone in a terminal:
Commit 880124a
Johan Mattsson - 2015-06-13T09:23:49+00:00
880124a5633a141677e755da96b4d8a71873ba10johan.mattsson.m@gmail.com

Rgb to hsv

Changed files (2)

Diff

diff --git a/libbirdfont/Color.vala b/libbirdfont/Color.valaindex 4a1f8e8..0924b59 100644--- a/libbirdfont/Color.vala+++ b/libbirdfont/Color.vala@@ -102,6 +102,69 @@ public class Color { 		} 	} +	public void to_hsva (out double h, out double s, out double v, out double a) {+		double red, green, blue;+		double min, max;+		double delta;++		a = this.a;+		+		red = r;+		green = g;+		blue = b;++		h = 0.0;++		if (red > green) {+			if (red > blue)+				max = red;+			else+				max = blue;++			if (green < blue)+				min = green;+			else+				min = blue;+		} else {+			if (green > blue)+				max = green;+			else+				max = blue;++			if (red < blue)+				min = red;+			else+				min = blue;+		}++		v = max;++		if (max != 0.0)+			s = (max - min) / max;+		else+			s = 0.0;++		if (s == 0.0)+			h = 0.0;+		else {+			delta = max - min;++			if (red == max)+				h = (green - blue) / delta;+			else if (green == max)+				h = 2 + (blue - red) / delta;+			else if (blue == max)+				h = 4 + (red - green) / delta;++			h /= 6.0;++			if (h < 0.0)+				h += 1.0;+			else if (h > 1.0)+				h -= 1.0;+		}+	}+ 	public static Color black () { 		return new Color (0, 0, 0, 1); 	}diff --git a/libbirdfont/ColorPicker.vala b/libbirdfont/ColorPicker.valaindex 84dc0b7..dade593 100644--- a/libbirdfont/ColorPicker.vala+++ b/libbirdfont/ColorPicker.vala@@ -70,8 +70,7 @@ public class ColorPicker : Tool { 	} 	 	public void set_color (Color c) {-		c.get_hsba (out hue, out s, out b, out a);-		print (@"hue $hue s $s b $b a $a\n");+		c.to_hsva (out hue, out s, out b, out a); 	} 	 	public void set_color_from_pointer (double tx) {

Contact

Email: johan.mattsson.m@gmail.com
Mastodon: typo.social/@birdfont
GitHub: johanmattssonm
LinkedIn: johan-mattsson-2ab324112