]> git.cworth.org Git - acre/blobdiff - acre.c
Use CIE L*a*b colors instead of HSV
[acre] / acre.c
diff --git a/acre.c b/acre.c
index bda8e81996c3e72cdfad5e634a7ddf132ee0902e..b844d755153911710ebad19570b710a06d37a2db 100644 (file)
--- a/acre.c
+++ b/acre.c
@@ -28,6 +28,8 @@
 #include <stdarg.h>
 #include <math.h>
 
+#include <lcms.h>
+
 typedef struct _acre_data_point_2d {
     double x;
     double y;
@@ -569,8 +571,18 @@ _acre_color_from_hsv (acre_color_t *color,
 static void
 _choose_colors (acre_t *acre)
 {
-    double hue, saturation, value;
+    cmsHPROFILE lab_profile, srgb_profile;
+    cmsHTRANSFORM lab_to_srgb;
     int i;
+    double theta, radius, srgb[3];
+    cmsCIELab lab;
+
+    lab_profile = cmsCreateLabProfile (NULL); /* D50 */
+    srgb_profile = cmsCreate_sRGBProfile ();
+
+    lab_to_srgb = cmsCreateTransform (lab_profile, TYPE_Lab_DBL,
+                                     srgb_profile, TYPE_RGB_DBL,
+                                     INTENT_PERCEPTUAL, 0);
 
     acre->num_colors = acre->num_data;
 
@@ -580,13 +592,23 @@ _choose_colors (acre_t *acre)
                                 acre->colors_size * sizeof (acre_color_t));
     }
 
-    saturation = 1.0;
-    value = 0.7;
+    lab.L = 36;
+    radius = 130;
     for (i = 0; i < acre->num_colors; i++) {
-       hue = 360 * (double) i / acre->num_colors;
-       _acre_color_from_hsv (&acre->colors[i],
-                             hue, saturation, value);
+       theta = 0.713 + 2 * M_PI * (double) i / acre->num_colors;
+       lab.a = radius * cos (theta);
+       lab.b = radius * sin (theta);
+
+       cmsDoTransform (lab_to_srgb, &lab, srgb, 1);
+
+       acre->colors[i].red = srgb[0];
+       acre->colors[i].green = srgb[1];
+       acre->colors[i].blue = srgb[2];
     }
+
+    cmsDeleteTransform (lab_to_srgb);
+    cmsCloseProfile (lab_profile);
+    cmsCloseProfile (srgb_profile);
 }
 
 static void