From 99c4e91dfa14f1a81f85062eae03a3d04a157817 Mon Sep 17 00:00:00 2001 From: Joseph Artsimovich Date: Fri, 20 Jul 2012 11:31:06 +0100 Subject: [PATCH] dnxhd: Fix 10-bit DNxHD quant matrices Convert them to zigzag order, as the rest of them are. When I was adding support for 10-bit DNxHD, I just copy-pasted the missing quant matrices from the spec. Now it turns out the existing matrices in dnxhddata.c were in zigzag order. This resulted in wrong quantization for 10-bit DNxHD. The attached patch fixes the problem by converting 10-bit quant matrices to zigzag order. Signed-off-by: Michael Niedermayer --- libavcodec/dnxhddata.c | 66 +++++++++++++------------ tests/ref/fate/vsynth1-dnxhd-720p-10bit | 4 +- tests/ref/fate/vsynth2-dnxhd-720p-10bit | 6 +-- 3 files changed, 39 insertions(+), 37 deletions(-) diff --git a/libavcodec/dnxhddata.c b/libavcodec/dnxhddata.c index 2652df16fa..8cb58b3104 100644 --- a/libavcodec/dnxhddata.c +++ b/libavcodec/dnxhddata.c @@ -22,26 +22,28 @@ #include "avcodec.h" #include "dnxhddata.h" +/* The quantization tables below are in zigzag order! */ + static const uint8_t dnxhd_1235_luma_weight[] = { - 0, 32, 32, 32, 33, 35, 38, 39, - 32, 33, 32, 33, 36, 36, 39, 42, - 32, 32, 33, 36, 35, 37, 41, 43, - 31, 33, 34, 36, 36, 40, 42, 48, - 32, 34, 36, 37, 39, 42, 46, 51, - 36, 37, 37, 39, 41, 46, 51, 55, - 37, 39, 41, 41, 47, 50, 55, 56, - 41, 42, 41, 44, 50, 53, 60, 60 + 0, 32, 32, 32, 33, 32, 32, 32, + 32, 31, 32, 33, 33, 33, 33, 35, + 36, 36, 34, 34, 36, 37, 37, 36, + 36, 35, 36, 38, 39, 39, 37, 36, + 37, 37, 39, 41, 42, 41, 39, 39, + 40, 41, 42, 43, 42, 42, 41, 41, + 41, 44, 47, 46, 46, 48, 51, 51, + 50, 50, 53, 55, 55, 56, 60, 60, }; static const uint8_t dnxhd_1235_chroma_weight[] = { - 0, 32, 33, 34, 39, 41, 54, 59, - 33, 34, 35, 38, 43, 49, 58, 84, - 34, 37, 39, 44, 46, 55, 74, 87, - 40, 42, 47, 48, 58, 70, 87, 86, - 43, 50, 56, 63, 72, 94, 91, 82, - 55, 63, 65, 75, 93, 89, 85, 73, - 61, 67, 82, 81, 83, 90, 79, 73, - 74, 84, 75, 78, 90, 85, 73, 73 + 0, 32, 33, 34, 34, 33, 34, 35, + 37, 40, 43, 42, 39, 38, 39, 41, + 43, 44, 47, 50, 55, 61, 63, 56, + 48, 46, 49, 54, 59, 58, 55, 58, + 63, 65, 67, 74, 84, 82, 75, 72, + 70, 74, 84, 87, 87, 94, 93, 81, + 75, 78, 83, 89, 91, 86, 82, 85, + 90, 90, 85, 79, 73, 73, 73, 73, }; static const uint8_t dnxhd_1237_luma_weight[] = { @@ -155,25 +157,25 @@ static const uint8_t dnxhd_1243_chroma_weight[] = { }; static const uint8_t dnxhd_1250_luma_weight[] = { - 0, 32, 35, 35, 36, 36, 41, 43, - 32, 34, 35, 36, 37, 39, 43, 47, - 33, 34, 36, 38, 38, 42, 42, 50, - 34, 36, 38, 38, 41, 40, 47, 54, - 35, 38, 39, 40, 39, 45, 49, 58, - 38, 39, 40, 39, 46, 47, 54, 60, - 38, 39, 41, 46, 46, 48, 57, 62, - 40, 41, 44, 45, 49, 54, 63, 63 + 0, 32, 32, 33, 34, 35, 35, 35, + 34, 34, 35, 36, 36, 36, 36, 36, + 37, 38, 38, 38, 38, 38, 39, 39, + 38, 38, 39, 41, 43, 43, 42, 41, + 40, 40, 39, 40, 41, 41, 39, 39, + 40, 42, 47, 50, 47, 45, 46, 46, + 44, 45, 46, 47, 49, 54, 58, 54, + 48, 49, 54, 57, 60, 62, 63, 63, }; static const uint8_t dnxhd_1250_chroma_weight[] = { - 0, 32, 35, 36, 40, 42, 51, 51, - 35, 36, 39, 39, 43, 51, 52, 55, - 36, 41, 41, 43, 51, 53, 54, 56, - 43, 44, 45, 50, 54, 54, 55, 57, - 45, 48, 50, 51, 55, 58, 59, 58, - 49, 52, 49, 57, 58, 62, 58, 60, - 51, 51, 56, 58, 62, 61, 59, 62, - 52, 52, 60, 61, 59, 59, 63, 63 + 0, 32, 35, 36, 36, 35, 36, 39, + 41, 43, 45, 44, 41, 39, 40, 42, + 43, 43, 45, 48, 49, 51, 52, 50, + 50, 51, 51, 51, 51, 52, 53, 54, + 51, 49, 51, 52, 52, 56, 57, 55, + 54, 54, 55, 56, 55, 58, 58, 58, + 60, 61, 62, 62, 59, 57, 58, 58, + 61, 59, 59, 59, 60, 62, 63, 63, }; static const uint8_t dnxhd_1251_luma_weight[] = { diff --git a/tests/ref/fate/vsynth1-dnxhd-720p-10bit b/tests/ref/fate/vsynth1-dnxhd-720p-10bit index a667b9d144..59423e7279 100644 --- a/tests/ref/fate/vsynth1-dnxhd-720p-10bit +++ b/tests/ref/fate/vsynth1-dnxhd-720p-10bit @@ -1,4 +1,4 @@ -b5e24a055af02edec8674333260214fd *tests/data/fate/vsynth1-dnxhd-720p-10bit.dnxhd +f8c4b7aa165a80df2485d526161290a3 *tests/data/fate/vsynth1-dnxhd-720p-10bit.dnxhd 2293760 tests/data/fate/vsynth1-dnxhd-720p-10bit.dnxhd -4466ff3d73d01bbe75ea25001d379b63 *tests/data/fate/vsynth1-dnxhd-720p-10bit.out.rawvideo +790777baa4bb70c4e32cb13649cc26bf *tests/data/fate/vsynth1-dnxhd-720p-10bit.out.rawvideo stddev: 6.27 PSNR: 32.18 MAXDIFF: 64 bytes: 7603200/ 760320 diff --git a/tests/ref/fate/vsynth2-dnxhd-720p-10bit b/tests/ref/fate/vsynth2-dnxhd-720p-10bit index f087c133b1..cf3ba7b2fa 100644 --- a/tests/ref/fate/vsynth2-dnxhd-720p-10bit +++ b/tests/ref/fate/vsynth2-dnxhd-720p-10bit @@ -1,4 +1,4 @@ -4b57da2c0c1280469ff3579f7151c227 *tests/data/fate/vsynth2-dnxhd-720p-10bit.dnxhd +e96fc4a7d994b9369c50da32fd325822 *tests/data/fate/vsynth2-dnxhd-720p-10bit.dnxhd 2293760 tests/data/fate/vsynth2-dnxhd-720p-10bit.dnxhd -31a6aa8b8702e85fa3b48e73f035c4e4 *tests/data/fate/vsynth2-dnxhd-720p-10bit.out.rawvideo -stddev: 1.35 PSNR: 45.46 MAXDIFF: 23 bytes: 7603200/ 760320 +a57ce32ab22ae60bf21655b0d1ba3b07 *tests/data/fate/vsynth2-dnxhd-720p-10bit.out.rawvideo +stddev: 1.35 PSNR: 45.47 MAXDIFF: 22 bytes: 7603200/ 760320