From 72a12906b921436dad6ff68326ad8b3e526fbe11 Mon Sep 17 00:00:00 2001 From: Kostya Shishkov Date: Tue, 22 Dec 2020 12:22:56 +0100 Subject: [PATCH] codec_support/h263: pred_quant mode implies that AC coefficients should be predicted before quantisation too --- nihav-codec-support/src/codecs/h263/decoder.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/nihav-codec-support/src/codecs/h263/decoder.rs b/nihav-codec-support/src/codecs/h263/decoder.rs index 5918406..6be437b 100644 --- a/nihav-codec-support/src/codecs/h263/decoder.rs +++ b/nihav-codec-support/src/codecs/h263/decoder.rs @@ -295,6 +295,7 @@ impl H263BaseDecoder { } else { i16::from(binfo.get_q() * 2) }; + let qadd = (q + 1) >> 1; let quant_gray = 1024 / q; if apply_acpred && (binfo.acpred != ACPredMode::None) { let has_b = (i == 1) || (i == 3) || !sstate.first_mb; @@ -372,7 +373,19 @@ impl H263BaseDecoder { for t in 0..8 { self.pred_coeffs[mb_pos].ver[i][t] = self.blk[i][t]; } } if apply_acpred { - self.blk[i][0] *= q; + let start = if binfo.get_q() < 8 { + self.blk[i][0] <<= 3; + 1 + } else { + 0 + }; + for el in self.blk[i].iter_mut().skip(start) { + if *el > 0 { + *el = *el * q + qadd; + } else if *el < 0 { + *el = *el * q - qadd; + } + } } bdsp.idct(&mut self.blk[i]); } -- 2.30.2