Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] swscale: use configured YUV matrix with paletted-RGB inputs (PR #21174)
@ 2025-12-12  5:20 rcombs via ffmpeg-devel
  0 siblings, 0 replies; only message in thread
From: rcombs via ffmpeg-devel @ 2025-12-12  5:20 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: rcombs

PR #21174 opened by rcombs
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21174
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21174.patch

This replaces hardcoded BT601.


>From 3e4eb15ec7f286f639c438b98322fa30695d9e3b Mon Sep 17 00:00:00 2001
From: rcombs <rcombs@rcombs.me>
Date: Thu, 11 Dec 2025 21:16:46 -0800
Subject: [PATCH] swscale: use configured YUV matrix with paletted-RGB inputs

This replaces hardcoded BT601.
---
 libswscale/swscale.c | 23 ++++++++++-------------
 1 file changed, 10 insertions(+), 13 deletions(-)

diff --git a/libswscale/swscale.c b/libswscale/swscale.c
index 96df4ed3f4..219382505c 100644
--- a/libswscale/swscale.c
+++ b/libswscale/swscale.c
@@ -869,6 +869,12 @@ av_cold void ff_sws_init_xyzdsp(SwsInternal *c)
 
 void ff_update_palette(SwsInternal *c, const uint32_t *pal)
 {
+    uint32_t *rgb2yuv = c->input_rgb2yuv_table;
+
+    int32_t ry = rgb2yuv[RY_IDX], gy = rgb2yuv[GY_IDX], by = rgb2yuv[BY_IDX];
+    int32_t ru = rgb2yuv[RU_IDX], gu = rgb2yuv[GU_IDX], bu = rgb2yuv[BU_IDX];
+    int32_t rv = rgb2yuv[RV_IDX], gv = rgb2yuv[GV_IDX], bv = rgb2yuv[BV_IDX];
+
     for (int i = 0; i < 256; i++) {
         int r, g, b, y, u, v, a = 0xff;
         if (c->opts.src_format == AV_PIX_FMT_PAL8) {
@@ -897,20 +903,11 @@ void ff_update_palette(SwsInternal *c, const uint32_t *pal)
             g = ((i >> 1) & 3) * 85;
             r = ( i       & 1) * 255;
         }
-#define RGB2YUV_SHIFT 15
-#define BY ( (int) (0.114 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
-#define BV (-(int) (0.081 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
-#define BU ( (int) (0.500 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
-#define GY ( (int) (0.587 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
-#define GV (-(int) (0.419 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
-#define GU (-(int) (0.331 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
-#define RY ( (int) (0.299 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
-#define RV ( (int) (0.500 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
-#define RU (-(int) (0.169 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
 
-        y = av_clip_uint8((RY * r + GY * g + BY * b + ( 33 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT);
-        u = av_clip_uint8((RU * r + GU * g + BU * b + (257 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT);
-        v = av_clip_uint8((RV * r + GV * g + BV * b + (257 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT);
+        y = av_clip_uint8((ry * r + gy * g + by * b + ( 33 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT);
+        u = av_clip_uint8((ru * r + gu * g + bu * b + (257 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT);
+        v = av_clip_uint8((rv * r + gv * g + bv * b + (257 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT);
+
         c->pal_yuv[i]= y + (u<<8) + (v<<16) + ((unsigned)a<<24);
 
         switch (c->opts.dst_format) {
-- 
2.49.1

_______________________________________________
ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2025-12-12  5:21 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-12-12  5:20 [FFmpeg-devel] [PATCH] swscale: use configured YUV matrix with paletted-RGB inputs (PR #21174) rcombs via ffmpeg-devel

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