Nil Fons Miret
e294b390a0
avfilter/vf_unsharp: fix amount scaling in the high-bit-depth path
...
The 16-bit kernel is dispatched for every non-8-bit pixel format
(9/10/12/16-bit content, all stored in uint16_t). It's supposed to
undo the Q16 scaling that set_filter_param() applies to `amount`:
fp->amount = amount * 65536.0;
but the shift written in the kernel is `>> (8+nbits)`, which for the
nbits=16 instantiation of the macro comes out to `>> 24` instead of
`>> 16`. Because of this, on any non-8-bit input, unsharp applies ~1/256
of the user's requested strength and is effectively a no-op. The
8-bit kernel (nbits=8) happens to be correct because 8+8 == 16.
This commit also widens the intermediate product to int64 before the
shift, to avoid a potential overflow. Take a 16-bit pixel at the
edge of a sharp white/black region, with the user-facing `amount`
set to its declared maximum of 5.0.
*srx = 65535
blur = 32768
diff = *srx - blur = 32767
amount_q16 = 5.0 * 65536 = 327680
Then the kernel computes:
product = diff * amount_q16
= 32767 * 327680 = 10,737,090,560 (~1.07e10)
which overflows INT32_MAX. Widening to int64 keeps the
multiplication in range; the subsequent `>> 16` brings it back to
sample range and the final cast to int32 is then safe. The widening
is a semantic no-op for 8/9/10/12-bit content where the product
always fits in int32 (worst case at 12-bit: 4095 * 327680 ~ 1.34e9).
Introduced by ee792ebe08 (2019-11-08, "avfilter/vf_unsharp: add 10bit
support"). The fate-filter-unsharp-yuv420p10 reference added in the
same series was generated from the broken kernel and is regenerated
here. fate-filter-unsharp (8-bit) is unaffected.
Repro:
python3 -c "import numpy as np; y=np.tile(np.where(np.arange(128)//8 & 1, 512, 256).astype('<u2'), (128,1)); c=np.full((64,64), 512, '<u2'); open('in.yuv','wb').write(y.tobytes()+c.tobytes()*2)"
ffmpeg -f rawvideo -pix_fmt yuv420p10le -s 128x128 -i in.yuv \
-lavfi "split=2[a][b];[b]unsharp=la=1[bs];[a][bs]psnr" \
-f null - 2>&1 | grep PSNR
Before: `PSNR y:66.50 ...` -- the filter is effectively a no-op,
so the sharpened output matches the input almost exactly.
After: `PSNR y:28.27 ...` -- the filter actually sharpens, so
output and input differ as expected.
Signed-off-by: Nil Fons Miret <nilf@netflix.com >
Made-with: Cursor
2026-04-30 21:15:58 +00:00
..
2026-01-09 16:10:10 +00:00
2026-04-04 11:31:16 +00:00
2026-03-21 16:25:40 +08:00
2025-12-16 17:30:29 +02:00
2026-02-03 21:07:29 +00:00
2026-04-22 12:45:45 +02:00
2026-04-06 11:28:49 +02:00
2026-01-24 08:11:19 +00:00
2026-01-24 08:11:19 +00:00
2026-01-24 08:11:19 +00:00
2026-01-24 08:11:19 +00:00
2025-09-04 23:12:34 +00:00
2025-08-12 09:01:39 +00:00
2026-03-10 13:52:19 +01:00
2026-01-24 08:11:19 +00:00
2025-11-30 22:20:13 +01:00
2026-01-24 08:11:19 +00:00
2026-01-24 08:11:19 +00:00
2026-01-24 08:11:19 +00:00
2026-01-24 08:11:19 +00:00
2026-01-24 08:11:19 +00:00
2025-11-30 22:20:13 +01:00
2026-01-24 08:11:19 +00:00
2026-03-10 13:52:19 +01:00
2026-01-24 08:11:19 +00:00
2026-01-24 08:11:19 +00:00
2026-01-24 08:11:19 +00:00
2026-01-24 08:11:19 +00:00
2025-12-03 11:52:54 +01:00
2026-01-24 08:11:19 +00:00
2025-10-07 14:51:46 -07:00
2025-08-03 13:48:47 +02:00
2026-04-28 12:29:37 +00:00
2026-01-24 08:11:19 +00:00
2025-07-25 00:18:07 -03:00
2025-07-03 21:41:53 +02:00
2026-01-24 08:11:19 +00:00
2026-01-24 08:11:19 +00:00
2025-08-03 13:48:47 +02:00
2026-01-24 08:11:19 +00:00
2026-01-24 08:11:19 +00:00
2025-08-07 03:07:44 +02:00
2026-01-24 08:11:19 +00:00
2026-01-24 08:11:19 +00:00
2026-01-24 08:11:19 +00:00
2026-01-24 08:11:19 +00:00
2026-02-26 11:40:16 +08:00
2026-03-13 21:31:54 +01:00
2026-03-21 00:44:30 +00:00
2026-01-24 08:11:19 +00:00
2026-01-24 08:11:19 +00:00
2025-10-07 14:51:46 -07:00
2026-01-24 08:11:19 +00:00
2026-01-24 08:11:19 +00:00
2026-01-24 08:11:19 +00:00
2026-01-24 08:11:19 +00:00
2026-01-24 08:11:19 +00:00
2026-01-24 08:11:19 +00:00
2026-04-08 11:52:44 -03:00
2026-04-21 16:47:05 +00:00
2026-01-24 08:11:19 +00:00
2026-01-24 08:11:19 +00:00
2026-01-24 08:11:19 +00:00
2026-01-24 08:11:19 +00:00
2026-01-24 08:11:19 +00:00
2026-01-24 08:11:19 +00:00
2026-01-24 08:11:19 +00:00
2026-04-10 15:12:18 +02:00
2026-01-24 08:11:19 +00:00
2026-01-24 08:11:19 +00:00
2026-01-24 08:11:19 +00:00
2026-01-24 08:11:19 +00:00
2026-01-24 08:11:19 +00:00
2026-04-28 12:29:37 +00:00
2026-01-24 22:05:34 +00:00
2026-01-24 08:11:19 +00:00
2026-01-24 08:11:19 +00:00
2026-03-10 13:52:19 +01:00
2026-01-24 08:11:19 +00:00
2026-01-24 08:11:19 +00:00
2026-04-10 15:12:18 +02:00
2026-01-21 22:06:12 +00:00
2025-09-02 17:06:08 +02:00
2025-12-09 21:31:58 +00:00
2025-10-04 17:49:08 +02:00
2026-02-28 12:13:02 +00:00
2025-09-02 17:06:25 +02:00
2026-04-12 20:02:18 +00:00
2026-03-29 09:38:01 +00:00
2025-11-30 22:20:13 +01:00
2025-11-30 22:20:13 +01:00
2026-03-06 03:21:37 +01:00
2025-09-02 17:06:25 +02:00
2025-09-02 17:06:25 +02:00
2025-08-12 09:01:39 +00:00
2026-01-24 08:11:19 +00:00
2026-01-24 08:11:19 +00:00
2025-06-21 17:28:39 +02:00
2026-01-24 08:11:19 +00:00
2025-07-22 09:47:18 -03:00
2026-01-24 08:11:19 +00:00
2025-06-11 19:26:22 +02:00
2025-12-14 12:41:00 +05:30
2026-02-10 19:44:43 +01:00
2026-04-28 12:29:37 +00:00
2026-01-19 09:33:49 +00:00
2026-04-10 22:02:00 +02:00
2026-04-10 15:12:18 +02:00
2025-07-14 22:03:36 +02:00
2025-07-14 22:03:36 +02:00
2025-09-26 12:24:04 -03:00
2025-08-03 13:48:47 +02:00
2026-02-10 19:44:46 +01:00
2026-02-10 19:44:46 +01:00
2026-04-21 16:47:05 +00:00
2026-02-14 12:21:10 +00:00
2026-02-14 12:21:10 +00:00
2025-08-03 13:48:47 +02:00
2025-11-30 22:20:13 +01:00
2025-08-03 13:48:47 +02:00
2025-09-02 17:06:25 +02:00
2025-08-03 13:48:47 +02:00
2026-04-28 06:14:38 +00:00
2025-09-30 15:39:39 +00:00
2025-11-30 22:20:13 +01:00
2025-08-21 14:55:12 +02:00
2025-07-03 21:41:53 +02:00
2026-01-24 08:11:19 +00:00
2026-01-05 20:41:59 +00:00
2025-08-11 19:29:53 +00:00
2025-08-03 13:48:47 +02:00
2025-07-29 22:10:05 +02:00
2026-01-24 08:11:19 +00:00
2026-01-24 08:11:19 +00:00
2025-09-26 12:31:39 +00:00
2026-04-21 16:47:05 +00:00
2026-01-24 08:11:19 +00:00
2026-04-28 14:57:34 +00:00
2026-03-13 12:52:57 -03:00
2025-11-30 22:20:13 +01:00
2025-12-03 11:52:54 +01:00
2026-04-21 08:28:45 +02:00
2025-10-07 16:00:27 +00:00
2025-08-03 13:48:47 +02:00
2025-08-12 09:01:39 +00:00
2026-02-10 19:44:43 +01:00
2025-12-16 17:30:23 +02:00
2026-01-15 16:26:09 +00:00
2025-11-30 22:20:13 +01:00
2026-04-22 12:45:45 +02:00
2026-02-26 11:40:16 +08:00
2026-03-10 13:52:19 +01:00
2026-04-21 08:28:45 +02:00
2026-03-14 23:26:51 +08:00
2026-04-21 08:28:50 +02:00
2025-10-07 16:00:27 +00:00
2025-10-07 16:00:27 +00:00
2026-03-10 13:52:19 +01:00
2026-01-24 08:11:19 +00:00
2025-08-03 13:48:47 +02:00
2025-09-21 13:28:58 +02:00
2025-11-30 22:20:13 +01:00
2026-04-28 12:29:37 +00:00
2026-04-28 12:29:37 +00:00
2025-12-03 11:52:54 +01:00
2026-03-06 03:21:37 +01:00
2025-08-03 13:48:47 +02:00
2026-02-10 19:44:46 +01:00
2025-09-26 16:15:46 +00:00
2025-09-02 17:06:25 +02:00
2025-08-12 09:01:39 +00:00
2026-01-24 08:11:19 +00:00
2026-03-06 01:45:09 -05:00
2025-08-12 09:01:39 +00:00
2025-09-04 22:20:58 +02:00
2026-02-26 11:40:16 +08:00
2025-09-26 16:15:46 +00:00
2025-08-12 09:01:39 +00:00
2026-04-22 12:33:26 +00:00
2026-04-28 12:29:37 +00:00
2026-01-24 08:11:19 +00:00
2026-01-24 08:11:19 +00:00
2025-11-30 22:20:13 +01:00
2026-01-24 08:11:19 +00:00
2026-02-10 19:44:43 +01:00
2025-12-03 21:23:51 +00:00
2026-01-24 08:11:19 +00:00
2026-02-10 19:44:46 +01:00
2026-04-21 08:28:50 +02:00
2025-09-02 17:06:25 +02:00
2026-02-26 11:40:16 +08:00
2025-11-30 22:20:13 +01:00
2026-04-21 16:47:05 +00:00
2025-08-12 09:01:39 +00:00
2026-04-30 08:33:31 -05:00
2025-11-17 12:18:12 +01:00
2025-11-17 12:18:12 +01:00
2025-11-30 22:20:13 +01:00
2025-11-30 22:20:13 +01:00
2026-04-21 08:28:50 +02:00
2026-01-24 08:11:19 +00:00
2025-11-30 22:20:13 +01:00
2025-11-30 22:20:13 +01:00
2026-01-24 08:11:19 +00:00
2026-03-09 19:07:34 +01:00
2026-01-24 08:11:19 +00:00
2026-01-24 08:11:19 +00:00
2025-07-17 12:26:05 +02:00
2025-09-21 11:02:41 +00:00
2025-11-30 22:20:13 +01:00
2025-09-21 11:02:41 +00:00
2026-04-21 08:28:49 +02:00
2026-03-27 21:00:53 -03:00
2026-01-02 23:46:42 +08:00
2026-04-28 06:14:38 +00:00
2025-08-12 09:01:39 +00:00
2025-11-30 22:20:13 +01:00
2026-01-24 08:11:19 +00:00
2025-11-30 22:20:13 +01:00
2026-04-28 12:29:37 +00:00
2025-11-30 22:20:13 +01:00
2025-11-30 22:20:13 +01:00
2025-06-14 23:41:38 +02:00
2026-01-27 17:05:27 +00:00
2026-02-26 11:40:16 +08:00
2026-04-26 16:05:11 +08:00
2026-04-28 12:29:37 +00:00
2025-12-08 21:31:13 +00:00
2026-01-09 16:10:10 +00:00
2025-06-15 21:00:38 +05:30
2026-02-19 19:42:31 +01:00
2026-01-09 16:10:10 +00:00
2025-10-16 19:10:51 +02:00
2025-10-16 18:41:19 +02:00
2026-02-14 12:21:10 +00:00
2025-07-11 17:49:58 +02:00
2025-08-03 13:48:47 +02:00
2026-01-24 08:11:19 +00:00
2025-08-03 13:48:47 +02:00
2026-04-22 12:45:45 +02:00
2026-02-10 19:44:43 +01:00
2025-09-02 17:06:25 +02:00
2025-07-04 01:32:27 +02:00
2025-07-04 01:32:27 +02:00
2025-09-02 17:06:25 +02:00
2026-01-24 08:11:19 +00:00
2026-01-24 08:11:19 +00:00
2025-08-12 09:01:39 +00:00
2025-10-07 14:51:46 -07:00
2025-11-30 22:20:13 +01:00
2026-01-24 08:11:19 +00:00
2025-12-03 11:52:54 +01:00
2025-11-30 22:20:13 +01:00
2025-08-03 13:48:47 +02:00
2026-01-24 08:11:19 +00:00
2025-11-30 22:20:13 +01:00
2026-02-10 19:44:46 +01:00
2025-09-02 17:06:25 +02:00
2026-04-28 06:14:38 +00:00
2026-04-04 11:31:16 +00:00
2025-11-27 22:11:57 +01:00
2025-08-03 13:48:47 +02:00
2026-04-28 06:14:38 +00:00
2026-04-28 06:14:38 +00:00
2026-04-28 06:14:38 +00:00
2026-04-28 06:14:38 +00:00
2026-04-28 06:14:38 +00:00
2026-03-06 23:09:44 +01:00
2026-04-22 12:45:40 +02:00
2025-08-12 09:01:39 +00:00
2025-08-12 09:01:39 +00:00
2025-10-28 20:46:21 +01:00
2025-09-26 12:31:39 +00:00
2025-09-02 17:06:25 +02:00
2025-12-03 11:52:54 +01:00
2026-01-24 08:11:19 +00:00
2025-08-03 13:48:47 +02:00
2025-08-03 13:48:47 +02:00
2025-08-03 13:48:47 +02:00
2025-10-15 19:43:37 +02:00
2026-03-11 10:23:35 +01:00
2026-04-13 19:49:32 +08:00
2025-11-30 22:20:13 +01:00
2026-01-03 21:31:30 -03:00
2026-01-24 08:11:19 +00:00
2025-09-02 17:06:25 +02:00
2025-11-30 22:20:13 +01:00
2026-01-24 08:11:19 +00:00
2025-09-02 17:06:25 +02:00
2026-03-27 19:42:08 -03:00
2026-02-10 19:44:43 +01:00
2026-02-26 11:40:16 +08:00
2026-02-26 11:40:16 +08:00
2025-09-02 17:06:25 +02:00
2026-04-20 21:08:21 +02:00
2026-04-20 21:08:21 +02:00
2025-09-26 12:31:39 +00:00
2026-04-21 08:28:50 +02:00
2025-11-30 22:20:13 +01:00
2025-12-03 11:52:54 +01:00
2026-04-30 21:15:58 +00:00
2025-08-03 13:48:47 +02:00
2026-04-21 08:28:45 +02:00
2026-04-28 12:29:37 +00:00
2026-01-24 08:11:19 +00:00
2025-07-31 19:51:23 +08:00
2026-04-01 21:56:37 +08:00
2025-08-12 09:01:39 +00:00
2026-03-31 11:17:51 +00:00
2026-01-24 08:11:19 +00:00
2025-11-30 22:20:13 +01:00
2026-01-24 08:11:19 +00:00
2026-04-21 09:39:54 +02:00
2025-11-30 22:20:13 +01:00
2026-01-24 08:11:19 +00:00
2026-04-10 15:12:18 +02:00
2026-01-29 22:33:33 +01:00
2025-09-17 14:50:41 +00:00
2025-09-14 11:45:11 +00:00
2025-09-18 03:55:54 +02:00
2025-09-18 01:04:59 +00:00
2025-09-14 11:45:11 +00:00
2025-09-14 20:33:24 +02:00
2026-01-24 08:11:19 +00:00
2026-02-26 11:40:16 +08:00
2026-04-21 08:28:50 +02:00
2026-04-28 12:29:37 +00:00
2026-04-21 08:28:45 +02:00
2026-04-21 08:28:45 +02:00