27 rgb.
r = r; rgb.
g = g; rgb.
b = b;
33 xyz.
x = x; xyz.
y = y; xyz.
z =
z;
40 lab.
l = l; lab.
a = a; lab.
b = b;
53 if (n > 0.04045)
return 100*pow((n + 0.055)/1.055, 2.4);
61 return color_xyz_init(r*0.4124 + g*0.3576 + b*0.1805, r*0.2126 + g*0.7152 + b*0.0722, r*0.0193 + g*0.1192 + b*0.9505);
70 double L =
MAX(0, 116*y - 16);
71 double A = 500*(x - y);
72 double B = 200*(y -
z);
90 double y = (
color.l + 16.0)/116.0;
91 double x =
color.a/500.0 + y;
98 t1 = (x - 16.0/116.0)/7.787;
101 t2 = pow(((
color.l + 16.0)/116.0), 3.);
108 t3 = (
z - 16.0/116.0)/7.787;
115 double x =
color.x/100.0;
116 double y =
color.y/100.0;
118 double r = x*3.2406 + y*(-1.5372) +
z*(-0.4986);
119 double g = x*(-0.9689) + y*1.8758 +
z*0.0415;
120 double b = x*0.0557 + y*(-0.2040) +
z*1.0570;
122 r = 1.055*pow(r, 1/2.4) - 0.055;
127 g = 1.055*pow(g, 1/2.4) - 0.055;
132 b = 1.055*pow(b, 1/2.4) - 0.055;
151 int l1 = lightness[0];
152 int l2 = lightness[1];
155 if (l2 > 100) l2 = 100;
156 if (l1 > l2) l1 = l2;
159 fprintf(stderr,
"LAB color lightness range = %d,%d\n", l1, l2);
166 size_t m = ((size_t)l2 - (
size_t)l1 + 1) * 256 * 256 * 3;
175 for (
int b = b_lower; b <= b_upper; ++b) {
189 int max_qtree_level) {
205 return sqrt((x.
l-y.
l)*(x.
l-y.
l) +(x.
a-y.
a)*(x.
a-y.
a) +(x.
b-y.
b)*(x.
b-y.
b));
209 colors[0] = lab1.
l + t*(lab2.
l - lab1.
l);
210 colors[1] = lab1.
a + t*(lab2.
a - lab1.
a);
211 colors[2] = lab1.
b + t*(lab2.
b - lab1.
b);
220 int nc = 1, r, g, b, i, ii, jj, cdim = 3;
222 double step, dist_current;
228 if (maxpoints <= 0)
return NULL;
230 const char *cl = color_list;
231 while ((cl=strchr(cl,
',')) !=
NULL){
240 if (sscanf(cl,
"#%02X%02X%02X", &r, &g, &b) != 3)
break;
241 rgb.
r = r; rgb.
g = g; rgb.
b = b;
243 }
while ((cl=strchr(cl,
',')) !=
NULL);
247 for (i = 0; i < nc - 1; i++){
248 dists[i+1] =
lab_dist(lab[i], lab[i+1]);
251 for (i = 0; i < nc - 1; i++){
252 dists[i+1] += dists[i];
255 fprintf(stderr,
"sum = %f\n", dists[nc-1]);
257 double *colors =
gv_calloc(maxpoints * cdim,
sizeof(
double));
259 colors[0] = lab[0].
l;
260 colors[1] = lab[0].
a;
261 colors[2] = lab[0].
b;
263 step = dists[nc-1]/(maxpoints - 1);
264 ii = 0; jj = 0; dist_current = 0;
265 while (dists[jj] < dists[ii] + step) jj++;
267 double *colors_ptr = colors;
268 for (i = 0; i < maxpoints; i++){
270 MAX(0.001, (dists[jj] - dists[ii])), colors_ptr);
271 dist_current += step;
273 if (dist_current > dists[jj]) ii = jj;
274 while (jj < nc -1 && dists[jj] < dists[ii] + step) jj++;
QuadTree QuadTree_new_from_point_list(int dim, int n, int max_level, double *coord)
Memory allocation wrappers that exit on failure.
static void * gv_calloc(size_t nmemb, size_t size)
const char * color_palettes_get(const char *color_palette_name)
static void color(Agraph_t *g)
QuadTree lab_gamut_quadtree(const int *lightness, int max_qtree_level)
construct a quadtree of the LAB gamut points
double * lab_gamut(const int *lightness, int *n)
color_xyz RGB2XYZ(color_rgb color)
void LAB2RGB_real_01(double *color)
static double PivotXYZ(double n)
color_rgb color_rgb_init(double r, double g, double b)
color_rgb XYZ2RGB(color_xyz color)
color_lab color_lab_init(double l, double a, double b)
static double PivotRgb(double n)
color_lab RGB2LAB(color_rgb color)
static double lab_dist(color_lab x, color_lab y)
color_xyz color_xyz_init(double x, double y, double z)
double * color_blend_rgb2lab(const char *color_list, const int maxpoints)
static void lab_interpolate(color_lab lab1, color_lab lab2, double t, double *colors)
color_rgb LAB2RGB(color_lab color)
const signed char lab_gamut_data[]
const size_t lab_gamut_data_size
double b
l: 0 to 100, a,b: -128 to 128