25 rgb.
r = r; rgb.
g = g; rgb.
b = b;
31 xyz.
x = x; xyz.
y = y; xyz.
z =
z;
38 lab.
l = l; lab.
a = a; lab.
b = b;
51 if (n > 0.04045)
return 100*pow((n + 0.055)/1.055, 2.4);
59 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);
68 double L =
MAX(0, 116*y - 16);
69 double A = 500*(x - y);
70 double B = 200*(y -
z);
88 double y = (
color.l + 16.0)/116.0;
89 double x =
color.a/500.0 + y;
96 t1 = (x - 16.0/116.0)/7.787;
99 t2 = pow(((
color.l + 16.0)/116.0), 3.);
106 t3 = (
z - 16.0/116.0)/7.787;
113 double x =
color.x/100.0;
114 double y =
color.y/100.0;
116 double r = x*3.2406 + y*(-1.5372) +
z*(-0.4986);
117 double g = x*(-0.9689) + y*1.8758 +
z*0.0415;
118 double b = x*0.0557 + y*(-0.2040) +
z*1.0570;
120 r = 1.055*pow(r, 1/2.4) - 0.055;
125 g = 1.055*pow(g, 1/2.4) - 0.055;
130 b = 1.055*pow(b, 1/2.4) - 0.055;
149 int l1 = lightness[0];
150 int l2 = lightness[1];
153 if (l2 > 100) l2 = 100;
154 if (l1 > l2) l1 = l2;
157 fprintf(stderr,
"LAB color lightness range = %d,%d\n", l1, l2);
164 size_t m = ((size_t)l2 - (
size_t)l1 + 1) * 256 * 256 * 3;
173 for (
int b = b_lower; b <= b_upper; ++b) {
187 int max_qtree_level) {
203 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));
207 colors[0] = lab1.
l + t*(lab2.
l - lab1.
l);
208 colors[1] = lab1.
a + t*(lab2.
a - lab1.
a);
209 colors[2] = lab1.
b + t*(lab2.
b - lab1.
b);
218 int nc = 1, r, g, b, i, ii, jj, cdim = 3;
220 double step, dist_current;
226 if (maxpoints <= 0)
return NULL;
228 const char *cl = color_list;
229 while ((cl=strchr(cl,
',')) !=
NULL){
238 if (sscanf(cl,
"#%02X%02X%02X", &r, &g, &b) != 3)
break;
239 rgb.
r = r; rgb.
g = g; rgb.
b = b;
241 }
while ((cl=strchr(cl,
',')) !=
NULL);
245 for (i = 0; i < nc - 1; i++){
246 dists[i+1] =
lab_dist(lab[i], lab[i+1]);
249 for (i = 0; i < nc - 1; i++){
250 dists[i+1] += dists[i];
253 fprintf(stderr,
"sum = %f\n", dists[nc-1]);
255 double *colors =
gv_calloc(maxpoints * cdim,
sizeof(
double));
257 colors[0] = lab[0].
l;
258 colors[1] = lab[0].
a;
259 colors[2] = lab[0].
b;
261 step = dists[nc-1]/(maxpoints - 1);
262 ii = 0; jj = 0; dist_current = 0;
263 while (dists[jj] < dists[ii] + step) jj++;
265 double *colors_ptr = colors;
266 for (i = 0; i < maxpoints; i++){
268 MAX(0.001, (dists[jj] - dists[ii])), colors_ptr);
269 dist_current += step;
271 if (dist_current > dists[jj]) ii = jj;
272 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
#define PRISIZE_T
PRIu64 alike for printing size_t
double b
l: 0 to 100, a,b: -128 to 128