[cairo-commit] cairo-5c ChangeLog,1.8,1.9 cairo.5c,1.2,1.3
Keith Packard
commit at pdx.freedesktop.org
Fri Dec 17 01:50:18 PST 2004
Committed by: keithp
Update of /cvs/cairo/cairo-5c
In directory gabe:/tmp/cvs-serv25433
Modified Files:
ChangeLog cairo.5c
Log Message:
2004-12-17 Keith Packard <keithp at keithp.com>
* cairo.5c:
Add HSV color space routine to cairo.5c
Index: ChangeLog
===================================================================
RCS file: /cvs/cairo/cairo-5c/ChangeLog,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- ChangeLog 17 Dec 2004 09:40:43 -0000 1.8
+++ ChangeLog 17 Dec 2004 09:50:16 -0000 1.9
@@ -1,5 +1,10 @@
2004-12-17 Keith Packard <keithp at keithp.com>
+ * cairo.5c:
+ Add HSV color space routine to cairo.5c
+
+2004-12-17 Keith Packard <keithp at keithp.com>
+
* cairo-5c.h:
* cairo.5c:
* draw.c: (path_new), (path_box), (cairo_5c_move_to),
Index: cairo.5c
===================================================================
RCS file: /cvs/cairo/cairo-5c/cairo.5c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- cairo.5c 17 Dec 2004 09:40:43 -0000 1.2
+++ cairo.5c 17 Dec 2004 09:50:16 -0000 1.3
@@ -105,5 +105,55 @@
walk_path (current_path_flat_list (cr),
move_to, line_to, no_curve_to, close_path);
}
-}
+ real[3] to_hsv(real r, real g, real b)
+ {
+ real minimum = min (r, g, b);
+ real maximum = max (r, g, b);
+ real v = maximum;
+ real s = (maximum == 0) ? 0 : (maximum - minimum) / maximum;
+ real h = 0;
+ if (s != 0)
+ {
+ switch (maximum) {
+ case r: h = (g - b) / (maximum - minimum); break;
+ case g: h = 2.0 + (b - r) / (maximum - minimum); break;
+ case b: h = 4.0 + (r - g) / (maximum - minimum); break;
+ }
+ h = h / 6;
+ }
+ return (real[3]) { h, s, v };
+ }
+
+ /* convert hsv to rgb */
+
+ real[3] from_hsv(real h, real s, real v)
+ {
+ if (v == 0.0)
+ return (real[3]) { 0 ... };
+ else if (s == 0.0) {
+ return (real[3]) { v ... };
+ } else {
+ real h6 = (h * 6) % 6;
+ int i = floor (h6);
+ real f = h6 - i;
+ real p = v * (1 - s);
+ real q = v * (1 - (s * f));
+ real t = v * (1 - (s * (1 - f)));
+
+ switch(i) {
+ default:return (real[3]) { v, t, p };
+ case 1: return (real[3]) { q, v, p };
+ case 2: return (real[3]) { p, v, t };
+ case 3: return (real[3]) { p, q, v };
+ case 4: return (real[3]) { t, p, v };
+ case 5: return (real[3]) { v, p, q };
+ }
+ }
+ }
+
+ public void set_hsv_color (cairo_t cr, real h, real s, real v)
+ {
+ Cairo::set_rgb_color (cr, from_hsv (h, s, v) ...);
+ }
+}
More information about the cairo-commit
mailing list