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);
85 double y = (
color.l + 16.0)/116.0;
86 double x =
color.a/500.0 + y;
93 t1 = (x - 16.0/116.0)/7.787;
96 t2 = pow(((
color.l + 16.0)/116.0), 3.);
103 t3 = (
z - 16.0/116.0)/7.787;
110 double x =
color.x/100.0;
111 double y =
color.y/100.0;
113 double r = x*3.2406 + y*(-1.5372) +
z*(-0.4986);
114 double g = x*(-0.9689) + y*1.8758 +
z*0.0415;
115 double b = x*0.0557 + y*(-0.2040) +
z*1.0570;
117 r = 1.055*pow(r, 1/2.4) - 0.055;
122 g = 1.055*pow(g, 1/2.4) - 0.055;
127 b = 1.055*pow(b, 1/2.4) - 0.055;
146 int l1 = lightness[0];
147 int l2 = lightness[1];
150 if (l2 > 100) l2 = 100;
151 if (l1 > l2) l1 = l2;
154 fprintf(stderr,
"LAB color lightness range = %d,%d\n", l1, l2);
161 size_t m = ((size_t)l2 - (
size_t)l1 + 1) * 256 * 256 * 3;
170 for (
int b = b_lower; b <= b_upper; ++b) {
184 int max_qtree_level) {
200 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));
204 colors[0] = lab1.
l + t*(lab2.
l - lab1.
l);
205 colors[1] = lab1.
a + t*(lab2.
a - lab1.
a);
206 colors[2] = lab1.
b + t*(lab2.
b - lab1.
b);
215 int nc = 1, r, g, b, i, ii, jj, cdim = 3;
217 double step, dist_current;
223 if (maxpoints <= 0)
return NULL;
225 const char *cl = color_list;
226 while ((cl=strchr(cl,
',')) !=
NULL){
235 if (sscanf(cl,
"#%02X%02X%02X", &r, &g, &b) != 3)
break;
236 rgb.
r = r; rgb.
g = g; rgb.
b = b;
238 }
while ((cl=strchr(cl,
',')) !=
NULL);
242 for (i = 0; i < nc - 1; i++){
243 dists[i+1] =
lab_dist(lab[i], lab[i+1]);
246 for (i = 0; i < nc - 1; i++){
247 dists[i+1] += dists[i];
250 fprintf(stderr,
"sum = %f\n", dists[nc-1]);
252 double *colors =
gv_calloc(maxpoints * cdim,
sizeof(
double));
254 colors[0] = lab[0].
l;
255 colors[1] = lab[0].
a;
256 colors[2] = lab[0].
b;
258 step = dists[nc-1]/(maxpoints - 1);
259 ii = 0; jj = 0; dist_current = 0;
260 while (dists[jj] < dists[ii] + step) jj++;
262 double *colors_ptr = colors;
263 for (i = 0; i < maxpoints; i++){
265 MAX(0.001, (dists[jj] - dists[ii])), colors_ptr);
266 dist_current += step;
268 if (dist_current > dists[jj]) ii = jj;
269 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