From: Carl Worth Date: Tue, 3 Feb 2009 16:45:01 +0000 (-0800) Subject: Use CIE L*a*b colors instead of HSV X-Git-Url: https://git.cworth.org/git?p=acre;a=commitdiff_plain;h=473e49a97c96edf99c4adaca72b017b632eae7fb Use CIE L*a*b colors instead of HSV This gives perceptually uniform colors, (rather than totally different lightness as one gets with HSV---which is based on RGB primaries). Thanks to LittleCMS for the colorspace conversion. --- diff --git a/Makefile b/Makefile index 1d5beef..d17e7d9 100644 --- a/Makefile +++ b/Makefile @@ -7,9 +7,9 @@ acre_test_SOURCES = \ xmalloc.c \ xmalloc.h -acre_test_LDFLAGS=$$(pkg-config --libs pangocairo) +acre_test_LDFLAGS=$$(pkg-config --libs pangocairo lcms) -acre_test_CFLAGS=$$(pkg-config --cflags pangocairo) \ +acre_test_CFLAGS=$$(pkg-config --cflags pangocairo lcms) \ -Wall -Wextra -Wpointer-arith -Wstrict-prototypes \ -Wmissing-prototypes -Wmissing-declarations \ -Wnested-externs -Wno-unused-parameter diff --git a/acre.c b/acre.c index bda8e81..b844d75 100644 --- a/acre.c +++ b/acre.c @@ -28,6 +28,8 @@ #include #include +#include + 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