rv20: use proper DC quant in AIC mode
authorKostya Shishkov <kostya.shishkov@gmail.com>
Sun, 26 Nov 2017 17:53:38 +0000 (18:53 +0100)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Sun, 26 Nov 2017 17:53:38 +0000 (18:53 +0100)
src/codecs/h263/data.rs
src/codecs/h263/rv20.rs

index 98c0a816a4bf319e6ec126d5c2f8ec2ab46804ba..928b1cf57150d4d42d838972e3230676564d0a79 100644 (file)
@@ -4,6 +4,10 @@ use io::codebook::CodebookDescReader;
 pub const H263_SCALES: &[u8] = &[
     0, 1, 2, 3, 4, 5, 6, 6, 7, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 13, 13, 13, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15 ];
 
+#[allow(dead_code)]
+pub const H263_DC_SCALES: &[u8] = &[
+    0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62 ];
+
 pub const H263_ZIGZAG: &[usize] = &[
     0,   1,  8, 16,  9,  2,  3, 10,
     17, 24, 32, 25, 18, 11,  4,  5,
index 753a166acf2d8787b6dcad7e8276d8a5c80e7a3c..6836759f3739c77896876df4a61c5911b1e03443 100644 (file)
@@ -137,7 +137,11 @@ impl<'a> RealVideo20BR<'a> {
                 level = code.get_level();
                 last  = code.is_last();
                 if br.read_bool().unwrap() { level = -level; }
-                level = (level * q) + q_add;
+                if (idx != 0) || !sstate.is_iframe {
+                    level = (level * q) + q_add;
+                } else {
+                    level = level * (H263_DC_SCALES[quant as usize] as i16);
+                }
             } else {
                 last  = br.read_bool().unwrap();
                 run   = br.read(6).unwrap() as u8;
@@ -147,7 +151,11 @@ impl<'a> RealVideo20BR<'a> {
                     let top = br.read_s(6).unwrap() as i16;
                     level = (top << 5) | low;
                 }
-                level = (level * q) + q_add;
+                if (idx != 0) || !sstate.is_iframe {
+                    level = (level * q) + q_add;
+                } else {
+                    level = level * (H263_DC_SCALES[quant as usize] as i16);
+                }
                 if level < -2048 { level = -2048; }
                 if level >  2047 { level =  2047; }
             }
@@ -487,6 +495,6 @@ mod test {
     use test::dec_video::test_file_decoding;
     #[test]
     fn test_rv20() {
-         test_file_decoding("realmedia", "assets/RV/rv20_cook_640x352_realproducer_plus_8.51.rm", /*None*/Some(1000), true, false, Some("rv20"));
+        test_file_decoding("realmedia", "assets/RV/rv20_cook_640x352_realproducer_plus_8.51.rm", /*None*/Some(1000), true, false, Some("rv20"));
     }
 }