From: "Kacper Michajłow via ffmpeg-devel" <ffmpeg-devel@ffmpeg.org>
To: ffmpeg-devel@ffmpeg.org
Cc: "Kacper Michajłow" <code@ffmpeg.org>
Subject: [FFmpeg-devel] [PATCH] avfilter/vf_drawvg: round color values and avoid intermediate casting to double (PR #21010)
Date: Tue, 25 Nov 2025 01:12:05 -0000
Message-ID: <176403312622.39.1000431791304225073@2cb04c0e5124> (raw)
PR #21010 opened by Kacper Michajłow (kasper93)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21010
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21010.patch
This makes consistent colors conversion between double and u8 and makes
sure that values are consistent across different platforms. Especially
when x87 math was used.
Note that libcairo internally also rounds when converting double to
integers, see _cairo_color_double_to_short().
Fixes: filter-drawvg-interpreter
From f8d26097e7a9244f70f0bec4796de07067b527b6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= <kasper93@gmail.com>
Date: Tue, 25 Nov 2025 02:03:47 +0100
Subject: [PATCH] avfilter/vf_drawvg: round color values and avoid intermediate
casting to double
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
This makes consistent colors conversion between double and u8 and makes
sure that values are consistent across different platforms. Especially
when x87 math was used.
Note that libcairo internally also rounds when converting double to
integers, see _cairo_color_double_to_short().
Fixes: filter-drawvg-interpreter
Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
---
libavfilter/tests/drawvg.c | 2 +-
libavfilter/vf_drawvg.c | 14 ++++++--------
tests/ref/fate/filter-drawvg-interpreter | 8 ++++----
3 files changed, 11 insertions(+), 13 deletions(-)
diff --git a/libavfilter/tests/drawvg.c b/libavfilter/tests/drawvg.c
index 2d151bf4d2..3d98448531 100644
--- a/libavfilter/tests/drawvg.c
+++ b/libavfilter/tests/drawvg.c
@@ -167,7 +167,7 @@ void cairo_set_source(cairo_t *cr, cairo_pattern_t *source) {
printf("%s", __func__);
#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*0xFF), lround(g*0xFF), lround(b*0xFF), lround(a*0xFF))
switch (cairo_pattern_get_type(source)) {
case CAIRO_PATTERN_TYPE_SOLID:
diff --git a/libavfilter/vf_drawvg.c b/libavfilter/vf_drawvg.c
index fd9270ee13..5e47ac8a21 100644
--- a/libavfilter/vf_drawvg.c
+++ b/libavfilter/vf_drawvg.c
@@ -1838,7 +1838,9 @@ static int vgs_eval(
if (a->type == ARG_COLOR) {
memcpy(color, a->color, sizeof(color));
} else {
- uint32_t c = av_be2ne32((uint32_t)state->vars[a->variable]);
+ uint32_t c;
+ memcpy(&c, &state->vars[a->variable], sizeof(c));
+ c = av_be2ne32(c);
memcpy(color, &c, sizeof(color));
}
@@ -1981,14 +1983,10 @@ static int vgs_eval(
b = numerics[3];
}
- #define C(v, o) ((uint32_t)(av_clipd(v, 0, 1) * 255) << o)
+ #define C(v, o) (lround(av_clipd(v, 0, 1) * 0xFF) << o)
- state->vars[user_var] = (double)(
- C(r, 24)
- | C(g, 16)
- | C(b, 8)
- | C(numerics[4], 0)
- );
+ uint32_t color = C(r, 24) | C(g, 16) | C(b, 8) | C(numerics[4], 0);
+ memcpy(&state->vars[user_var], &color, sizeof(color));
#undef C
diff --git a/tests/ref/fate/filter-drawvg-interpreter b/tests/ref/fate/filter-drawvg-interpreter
index 21c6ccd848..3fc33e9c07 100644
--- a/tests/ref/fate/filter-drawvg-interpreter
+++ b/tests/ref/fate/filter-drawvg-interpreter
@@ -64,16 +64,16 @@ cairo_set_dash [ -1.0 ] 4.0
cairo_set_dash [ ] 0.0
cairo_move_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_fill
-cairo_set_source #475b3d66
+cairo_set_source #475c3d66
cairo_set_fill_rule 0
cairo_fill
-cairo_set_source #7f99b2cc
+cairo_set_source #8099b3cc
cairo_set_fill_rule 0
cairo_fill
-cairo_set_source #a8d7efe5
+cairo_set_source #a8d8f0e6
cairo_set_fill_rule 0
cairo_fill
cairo_rel_line_to 1.0 3.0
--
2.49.1
_______________________________________________
ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org
reply other threads:[~2025-11-25 1:12 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=176403312622.39.1000431791304225073@2cb04c0e5124 \
--to=ffmpeg-devel@ffmpeg.org \
--cc=code@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git