]> git.nihav.org Git - nihav.git/commitdiff
indeo: extend Indeo 2 decoder to support IMA RTV2 as well
authorKostya Shishkov <kostya.shishkov@gmail.com>
Wed, 4 Dec 2024 17:37:11 +0000 (18:37 +0100)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Wed, 4 Dec 2024 17:37:11 +0000 (18:37 +0100)
nihav-indeo/src/codecs/indeo2.rs
nihav-indeo/src/codecs/mod.rs
nihav-registry/src/register.rs

index 50af67a3681bcb3eb9feb0d87b89926ea104ec75..ff17b544a8bb50ed58db66b68c074d8453b3a590 100644 (file)
@@ -188,15 +188,16 @@ struct Indeo2Decoder {
     info:    NACodecInfoRef,
     cb:      Codebook<u8>,
     frmmgr:  HAMShuffler<u8>,
+    rtv2:    bool,
 }
 
 #[allow(clippy::identity_op)]
 impl Indeo2Decoder {
-    fn new() -> Self {
+    fn new(rtv2: bool) -> Self {
         let dummy_info = NACodecInfo::new_dummy();
         let mut coderead = IR2CodeReader{};
         let cb = Codebook::new(&mut coderead, CodebookMode::LSB).unwrap();
-        Indeo2Decoder { info: dummy_info, cb, frmmgr: HAMShuffler::new() }
+        Indeo2Decoder { info: dummy_info, cb, frmmgr: HAMShuffler::new(), rtv2 }
     }
 
     fn decode_plane_intra(&self, br: &mut BitReader,
@@ -311,8 +312,12 @@ const IR2_START: usize = 48;
 impl NADecoder for Indeo2Decoder {
     fn init(&mut self, _supp: &mut NADecoderSupport, info: NACodecInfoRef) -> DecoderResult<()> {
         if let NACodecTypeInfo::Video(vinfo) = info.get_properties() {
-            let w = vinfo.get_width();
-            let h = vinfo.get_height();
+            // The only known RTV2 sample uses conventional Indeo 2 format but codes twice as small picture
+            let (w, h) = if !self.rtv2 {
+                    (vinfo.width, vinfo.height)
+                } else {
+                    (vinfo.width / 2, vinfo.height / 2)
+                };
             let f = vinfo.is_flipped();
             let fmt = formats::YUV410_FORMAT;
             let myinfo = NACodecTypeInfo::Video(NAVideoInfo::new(w, h, f, fmt));
@@ -373,7 +378,11 @@ impl NAOptionHandler for Indeo2Decoder {
 }
 
 pub fn get_decoder() -> Box<dyn NADecoder + Send> {
-    Box::new(Indeo2Decoder::new())
+    Box::new(Indeo2Decoder::new(false))
+}
+
+pub fn get_decoder_rtv2() -> Box<dyn NADecoder + Send> {
+    Box::new(Indeo2Decoder::new(true))
 }
 
 #[cfg(test)]
@@ -381,9 +390,28 @@ mod test {
     use nihav_core::codecs::RegisteredDecoders;
     use nihav_core::demuxers::RegisteredDemuxers;
     use nihav_codec_support::test::dec_video::*;
-    use crate::indeo_register_all_decoders;
+    use crate::*;
     use nihav_commonfmt::generic_register_all_demuxers;
     #[test]
+    fn test_rtv2() {
+        let mut dmx_reg = RegisteredDemuxers::new();
+        indeo_register_all_demuxers(&mut dmx_reg);
+        let mut dec_reg = RegisteredDecoders::new();
+        indeo_register_all_decoders(&mut dec_reg);
+
+        // sample comes from a demo by Digital Video Arts
+        test_decoding("dvi", "ima-rtv2", "assets/Indeo/YULELOG.AVS", Some(7),
+                      &dmx_reg, &dec_reg, ExpectedTestResult::MD5Frames(vec![
+                            [0xcf6c556c, 0x4517cf10, 0x6831ced5, 0xc0d5df2e],
+                            [0x19182a32, 0x0929c079, 0x5ee02d73, 0x8eb2292f],
+                            [0x89fa94fc, 0xf8098a83, 0x9c82e77e, 0x402b4048],
+                            [0xb1aef0a3, 0x27683f69, 0xe6328f7f, 0x810d922f],
+                            [0xaa386982, 0xd205dcd1, 0x74d9ec2b, 0x38c0db83],
+                            [0xc4a43fd2, 0x4b74e5cc, 0x77cb5f03, 0x8b2995e4],
+                            [0xa35a2a2f, 0xf4d811be, 0x6beaa06c, 0x823fdaa3],
+                            [0x4a841217, 0x1f42c091, 0xeeab933f, 0xfab83333]]));
+    }
+    #[test]
     fn test_indeo2() {
         let mut dmx_reg = RegisteredDemuxers::new();
         generic_register_all_demuxers(&mut dmx_reg);
index 78b8eaede5378ae1283906621aa0007fbd675ead..317a636b089ac41b1d96d2ebf30826644d453eec 100644 (file)
@@ -39,6 +39,8 @@ mod ividsp;
 mod imc;
 
 const INDEO_CODECS: &[DecoderInfo] = &[
+#[cfg(feature="decoder_indeo2")]
+    DecoderInfo { name: "ima-rtv2", get_decoder: indeo2::get_decoder_rtv2 },
 #[cfg(feature="decoder_indeo2")]
     DecoderInfo { name: "indeo2", get_decoder: indeo2::get_decoder },
 #[cfg(feature="decoder_indeo3")]
index b9888b907e2872031d71a31e6652cd39948a85d0..ca518987a7900daa96d7148c690325642923745e 100644 (file)
@@ -157,6 +157,7 @@ static CODEC_REGISTER: &[CodecDescription] = &[
 
     desc!(video-im; "indeo1", "Intel Raw IF09"),
     desc!(video;    "indeo2", "Intel Indeo 2"),
+    desc!(video;    "ima-rtv2", "Intel RTV 2 (Indeo 2)"),
     desc!(video;    "indeo3", "Intel Indeo 3"),
     desc!(video;    "indeo4", "Intel Indeo 4", CODEC_CAP_REORDER | CODEC_CAP_SCALABLE),
     desc!(video;    "indeo5", "Intel Indeo 5", CODEC_CAP_REORDER | CODEC_CAP_SCALABLE),