mirror of
https://gitlab.freedesktop.org/cairo/cairo.git
synced 2026-01-06 05:00:17 +01:00
color: Special case comparing color stops.
color stops are not premultiplied so we need to handle them carefully when comparing. The next step will be to make cairo_color_stop_t a unique type to prevent this mistake again.
This commit is contained in:
parent
4741d33cf6
commit
dfa2544f15
6 changed files with 42 additions and 8 deletions
|
|
@ -174,3 +174,33 @@ _cairo_color_equal (const cairo_color_t *color_a,
|
|||
color_a->blue_short == color_b->blue_short &&
|
||||
color_a->alpha_short == color_b->alpha_short;
|
||||
}
|
||||
|
||||
cairo_bool_t
|
||||
_cairo_color_stop_equal (const cairo_color_t *color_a,
|
||||
const cairo_color_t *color_b)
|
||||
{
|
||||
uint16_t a, b;
|
||||
|
||||
if (color_a == color_b)
|
||||
return TRUE;
|
||||
|
||||
if (color_a->alpha_short != color_b->alpha_short)
|
||||
return FALSE;
|
||||
|
||||
a = _cairo_color_double_to_short (color_a->red * color_a->alpha);
|
||||
b = _cairo_color_double_to_short (color_b->red * color_b->alpha);
|
||||
if (a != b)
|
||||
return FALSE;
|
||||
|
||||
a = _cairo_color_double_to_short (color_a->green * color_a->alpha);
|
||||
b = _cairo_color_double_to_short (color_b->green * color_b->alpha);
|
||||
if (a != b)
|
||||
return FALSE;
|
||||
|
||||
a = _cairo_color_double_to_short (color_a->blue * color_a->alpha);
|
||||
b = _cairo_color_double_to_short (color_b->blue * color_b->alpha);
|
||||
if (a != b)
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1253,8 +1253,8 @@ _cairo_gl_gradient_operand_init(cairo_gl_context_t *ctx,
|
|||
* Happens more often than you would believe.
|
||||
*/
|
||||
for (i = 1; i < gradient->n_stops; i++) {
|
||||
if (! _cairo_color_equal (&gradient->stops[0].color,
|
||||
&gradient->stops[i].color))
|
||||
if (! _cairo_color_stop_equal (&gradient->stops[0].color,
|
||||
&gradient->stops[i].color))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -887,8 +887,8 @@ _cairo_gstate_copy_pattern (cairo_pattern_t *pattern,
|
|||
* Happens more often than you would believe.
|
||||
*/
|
||||
for (i = 1; i < src->n_stops; i++) {
|
||||
if (! _cairo_color_equal (&src->stops[0].color,
|
||||
&src->stops[i].color))
|
||||
if (! _cairo_color_stop_equal (&src->stops[0].color,
|
||||
&src->stops[i].color))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2294,8 +2294,8 @@ _cairo_pattern_acquire_surface (const cairo_pattern_t *pattern,
|
|||
* Happens more often than you would believe.
|
||||
*/
|
||||
for (i = 1; i < src->n_stops; i++) {
|
||||
if (! _cairo_color_equal (&src->stops[0].color,
|
||||
&src->stops[i].color))
|
||||
if (! _cairo_color_stop_equal (&src->stops[0].color,
|
||||
&src->stops[i].color))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
|
@ -2767,7 +2767,7 @@ _cairo_gradient_color_stops_equal (const cairo_gradient_pattern_t *a,
|
|||
for (n = 0; n < a->n_stops; n++) {
|
||||
if (a->stops[n].offset != b->stops[n].offset)
|
||||
return FALSE;
|
||||
if (! _cairo_color_equal (&a->stops[n].color, &b->stops[n].color))
|
||||
if (! _cairo_color_stop_equal (&a->stops[n].color, &b->stops[n].color))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1309,6 +1309,10 @@ cairo_private cairo_bool_t
|
|||
_cairo_color_equal (const cairo_color_t *color_a,
|
||||
const cairo_color_t *color_b) cairo_pure;
|
||||
|
||||
cairo_private cairo_bool_t
|
||||
_cairo_color_stop_equal (const cairo_color_t *color_a,
|
||||
const cairo_color_t *color_b) cairo_pure;
|
||||
|
||||
/* cairo-font-face.c */
|
||||
|
||||
extern const cairo_private cairo_font_face_t _cairo_font_face_nil;
|
||||
|
|
|
|||
|
|
@ -1421,7 +1421,7 @@ _gradient_color_stops_equal (const cairo_gradient_pattern_t *a,
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
if (! _cairo_color_equal (&a->stops[n].color, &b->stops[n].color))
|
||||
if (! _cairo_color_stop_equal (&a->stops[n].color, &b->stops[n].color))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue