From: Kostya Shishkov Date: Wed, 15 Jul 2020 16:23:48 +0000 (+0200) Subject: on2avc: fix scalefactor reading for partially empty band group X-Git-Url: https://git.nihav.org/?a=commitdiff_plain;h=c39708928eaa7eeb53e4b243cb5c18ea6013d82d;p=nihav.git on2avc: fix scalefactor reading for partially empty band group --- diff --git a/nihav-duck/src/codecs/on2avc.rs b/nihav-duck/src/codecs/on2avc.rs index 29ead41..59fa8f8 100644 --- a/nihav-duck/src/codecs/on2avc.rs +++ b/nihav-duck/src/codecs/on2avc.rs @@ -210,21 +210,36 @@ impl AVCDecoder { let mut cur_band = 0; let mut scale = 0; let mut first = true; - for wg in self.win_grp.iter().take(self.windows) { - if *wg { + for wg in 0..self.windows { + if self.win_grp[wg] { for _ in 0..bands { if self.cbs[cur_band] == 0 { - self.scales[cur_band] = 0; - } else { - if first { - scale = br.read(7)? as i16; - first = false - } else { - scale += i16::from(br.read_cb(&self.codebooks.scale_cb)?); - validate!((scale >= 0) && (scale < 128)); + let mut all_zero = true; + let mut band2 = cur_band; + for wg2 in wg + 1..self.windows { + if self.win_grp[wg2] { + break; + } + band2 += bands; + if self.cbs[band2] != 0 { + all_zero = false; + break; + } + } + if all_zero { + self.scales[cur_band] = 0; + cur_band += 1; + continue; } - self.scales[cur_band] = scale as u8; } + if first { + scale = br.read(7)? as i16; + first = false; + } else { + scale += i16::from(br.read_cb(&self.codebooks.scale_cb)?); + validate!((scale >= 0) && (scale < 128)); + } + self.scales[cur_band] = scale as u8; cur_band += 1; } } else {