PR #25170 opened by Marti2203
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25170
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25170.patch
With `nb_patches=1`, `build_map()` stores the per-channel gain in
`icoeff[c][1+c]` instead of `icoeff[1+c][c]`. The identity initialised by
`icoeff[c+1][c] = 1` therefore stays in place, and the three gains end up in
green's constant term (`icoeff[0][1]`), a red-to-blue term (`icoeff[1][2]`) and
a column that `colormap_slice()` never reads (`icoeff[2][3]`). A single patch
leaves the colours almost unchanged.
Reproduction (uniform 64x64 frames, one patch mapping 0xA06040 to 0x503020):
```
ffmpeg -f lavfi -i color=c=0xA06040:s=64x64:d=0.04 \
-f lavfi -i color=c=0xA06040:s=64x64:d=0.04 \
-f lavfi -i color=c=0x503020:s=64x64:d=0.04 \
-filter_complex
"[0][1][2]colormap=patch_size=64x64:nb_patches=1,format=rgb24" \
-frames:v 1 -f rawvideo - | head -c 3 | od -An -tu1
```
| input | master | patched | expected |
|----------|-------------|------------|------------|
| 0xA06040 | 160 97 63 | 80 48 32 | 80 48 32 |
| 0x204060 | 33 64 97 | 16 32 48 | 16 32 48 |
The two-patch path (adding a black-to-black patch) already gives 80 48 32 on
master. The fix uses the same `icoeff[1+c][c]` layout as that case.
This issue was found by an LLM-Enhanced Static Analysis Engine and verified
manually.
>From e4219902dcacd2c5ebe871ec17eb15611f316508 Mon Sep 17 00:00:00 2001
From: Martin Mirchev <[email protected]>
Date: Sun, 18 Oct 2026 16:13:01 +0800
Subject: [PATCH] avfilter/vf_colormap: fix single-patch coefficient index
With nb_patches=1 the per-channel gain was stored in icoeff[c][1+c]
instead of icoeff[1+c][c], so the identity mapping stayed in place and
the gains landed in a constant term, a cross-channel term and an unused
column. A single patch therefore left the colours almost unchanged:
mapping 0xA06040 to 0x503020 turned 0xA06040 into (160,97,63) instead of
(80,48,32). Use the same layout as the two-patch case.
Signed-off-by: Martin Mirchev <[email protected]>
---
libavfilter/vf_colormap.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libavfilter/vf_colormap.c b/libavfilter/vf_colormap.c
index 4680a7b501..dbb3a2b9e4 100644
--- a/libavfilter/vf_colormap.c
+++ b/libavfilter/vf_colormap.c
@@ -192,7 +192,7 @@ static void build_map(AVFilterContext *ctx)
case 1:
{
float div = fabsf(s->source[0][c]) < 1e-6f ? 1e-6f :
s->source[0][c];
- s->icoeff[c][1+c] = s->target[0][c] / div;
+ s->icoeff[1+c][c] = s->target[0][c] / div;
}
break;
case 2:
--
2.54.0
_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]