avfilter/vf_drawvg: round color values to avoid differences on some platforms

This ensures consistent color conversion between double and u8 and
guarantees that values remain consistent across different platforms,
especially when x87 math is used.

Note that libcairo also performs rounding internally when converting
doubles to integers, see _cairo_color_double_to_short().

Fixes: fate-filter-drawvg-interpreter
Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
This commit is contained in:
Kacper Michajłow
2025-11-25 18:06:33 +01:00
parent 1d84ab331c
commit a75b15a4ab
3 changed files with 6 additions and 6 deletions

View File

@@ -167,7 +167,7 @@ void cairo_set_source(cairo_t *cr, cairo_pattern_t *source) {
printf("%s", __func__); printf("%s", __func__);
#define PRINT_COLOR(prefix) \ #define PRINT_COLOR(prefix) \
printf(prefix "#%02x%02x%02x%02x", (int)(r*255), (int)(g*255), (int)(b*255), (int)(a*255)) printf(prefix "#%02lx%02lx%02lx%02lx", lround(r*255), lround(g*255), lround(b*255), lround(a*255))
switch (cairo_pattern_get_type(source)) { switch (cairo_pattern_get_type(source)) {
case CAIRO_PATTERN_TYPE_SOLID: case CAIRO_PATTERN_TYPE_SOLID:

View File

@@ -1981,7 +1981,7 @@ static int vgs_eval(
b = numerics[3]; b = numerics[3];
} }
#define C(v, o) ((uint32_t)(av_clipd(v, 0, 1) * 255) << o) #define C(v, o) ((uint32_t)lround(av_clipd(v, 0, 1) * 255) << o)
state->vars[user_var] = (double)( state->vars[user_var] = (double)(
C(r, 24) C(r, 24)

View File

@@ -64,16 +64,16 @@ cairo_set_dash [ -1.0 ] 4.0
cairo_set_dash [ ] 0.0 cairo_set_dash [ ] 0.0
cairo_move_to 1.0 2.0 cairo_move_to 1.0 2.0
cairo_rel_line_to -1.0 -2.0 cairo_rel_line_to -1.0 -2.0
cairo_set_source #19334c66 cairo_set_source #1a334d66
cairo_set_fill_rule 0 cairo_set_fill_rule 0
cairo_fill cairo_fill
cairo_set_source #475b3d66 cairo_set_source #475c3d66
cairo_set_fill_rule 0 cairo_set_fill_rule 0
cairo_fill cairo_fill
cairo_set_source #7f99b2cc cairo_set_source #8099b3cc
cairo_set_fill_rule 0 cairo_set_fill_rule 0
cairo_fill cairo_fill
cairo_set_source #a8d7efe5 cairo_set_source #a8d8f0e6
cairo_set_fill_rule 0 cairo_set_fill_rule 0
cairo_fill cairo_fill
cairo_rel_line_to 1.0 3.0 cairo_rel_line_to 1.0 3.0