/* A perceptual distance metric between two colors. No sqrt needed
* since the square of the distance is still a valid metric. */
/* XXX: This is currently using linear distance in RGB space which is *decidedlynotperceptuallylinear.Ifsomeonecaredalotaboutthe *quality,theymightchoosesomethingelsehere.Thenagain,they
* might also choose not to use a PseudoColor visual... */ staticinlineint
_color_distance (unsignedshort r1, unsignedshort g1, unsignedshort b1, unsignedshort r2, unsignedshort g2, unsignedshort b2)
{
r1 >>= 8; g1 >>= 8; b1 >>= 8;
r2 >>= 8; g2 >>= 8; b2 >>= 8;
for (i = 0; i < CUBE_SIZE; i++)
cube_index_to_short[i] = (0xffff * i + ((CUBE_SIZE-1)>>1)) / (CUBE_SIZE-1); for (i = 0; i < RAMP_SIZE; i++)
ramp_index_to_short[i] = (0xffff * i + ((RAMP_SIZE-1)>>1)) / (RAMP_SIZE-1);
info = _cairo_calloc (sizeof (cairo_xlib_visual_info_t)); if (unlikely (info == NULL)) return _cairo_error (CAIRO_STATUS_NO_MEMORY);
/* XXX: Could do this in a more clever order to have the best *possibleresultsfromearlyfailure.Couldalsochooseacube
* uniformly distributed in a better space than RGB. */ for (red = 0; red < CUBE_SIZE; red++) { for (green = 0; green < CUBE_SIZE; green++) { for (blue = 0; blue < CUBE_SIZE; blue++) {
color.red = cube_index_to_short[red];
color.green = cube_index_to_short[green];
color.blue = cube_index_to_short[blue];
color.pixel = 0;
color.flags = 0;
color.pad = 0; if (! XAllocColor (dpy, colormap, &color)) goto DONE_ALLOCATE;
}
}
}
DONE_ALLOCATE:
for (i = 0; i < ARRAY_LENGTH (colors); i++)
colors[i].pixel = i;
XQueryColors (dpy, colormap, colors, ARRAY_LENGTH (colors));
/* Search for nearest colors within allocated colormap. */ for (gray = 0; gray < RAMP_SIZE; gray++) { for (i = 0; i < 256; i++) {
distance = _color_distance (ramp_index_to_short[gray],
ramp_index_to_short[gray],
ramp_index_to_short[gray],
colors[i].red,
colors[i].green,
colors[i].blue); if (i == 0 || distance < min_distance) {
gray_to_pseudocolor[gray] = colors[i].pixel;
min_distance = distance; if (!min_distance) break;
}
}
} for (red = 0; red < CUBE_SIZE; red++) { for (green = 0; green < CUBE_SIZE; green++) { for (blue = 0; blue < CUBE_SIZE; blue++) { for (i = 0; i < 256; i++) {
distance = _color_distance (cube_index_to_short[red],
cube_index_to_short[green],
cube_index_to_short[blue],
colors[i].red,
colors[i].green,
colors[i].blue); if (i == 0 || distance < min_distance) {
info->cube_to_pseudocolor[red][green][blue] = colors[i].pixel;
min_distance = distance; if (!min_distance) break;
}
}
}
}
}
for (i = 0, j = 0; i < 256; i++) { if (j < CUBE_SIZE - 1 && (((i<<8)+i) - (int)cube_index_to_short[j]) > ((int)cube_index_to_short[j+1] - ((i<<8)+i)))
j++;
info->field8_to_cube[i] = j;
for (i = 0; i < 256; i++) {
info->colors[i].a = 0xff;
info->colors[i].r = colors[i].red >> 8;
info->colors[i].g = colors[i].green >> 8;
info->colors[i].b = colors[i].blue >> 8;
}
*out = info; return CAIRO_STATUS_SUCCESS;
}
void
_cairo_xlib_visual_info_destroy (cairo_xlib_visual_info_t *info)
{ /* No need for XFreeColors() whilst using DefaultColormap */
_cairo_list_del (&info->link);
free (info);
}
#endif/* !CAIRO_HAS_XLIB_XCB_FUNCTIONS */
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.12 Sekunden
(vorverarbeitet am 2026-08-25)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.