]> git.nihav.org Git - nihav.git/blobdiff - nihav-indeo/src/codecs/ivibr.rs
core/io: allow skipping right to the bitstream end
[nihav.git] / nihav-indeo / src / codecs / ivibr.rs
index d501953225066ebb320513d0231aaaec7487d8b7..5831f801693d23181716b4ecc4e00c7f305432e5 100644 (file)
@@ -488,10 +488,12 @@ pub struct IVIDecoder {
     tiles:      Vec<IVITile>,
     num_tiles:  [[usize; 4]; 4],
     tile_start: [[usize; 4]; 4],
+
+    scalable:   bool,
 }
 
 impl IVIDecoder {
-    pub fn new() -> Self {
+    pub fn new(scalable: bool) -> Self {
         let mut bands: Vec<BandHeader> = Vec::with_capacity(12);
         bands.resize(12, BandHeader::new_empty(42, 42));
         IVIDecoder {
@@ -506,6 +508,8 @@ impl IVIDecoder {
             bands,
             band_tiles: 0,
             tiles: Vec::new(), tile_start: [[0; 4]; 4], num_tiles: [[0; 4]; 4],
+
+            scalable,
         }
     }
 
@@ -601,7 +605,7 @@ impl IVIDecoder {
                 }
                 br.align();
                 validate!(len > 0);
-                let tile_end = tile_start + len * 8;
+                let tile_end = (tile_start & !7) + len * 8;
                 validate!(tile_end > br.tell());
                 validate!(tile_end <= br.tell() + (br.left() as usize));
                 {
@@ -943,6 +947,11 @@ br.skip(skip_part as u32)?;
                 self.ftype = IVIFrameType::Intra;
             }
         }
+        if self.bref.is_some() && self.ftype == IVIFrameType::Inter {
+            let mut bref: Option<NABufferType> = Some(res.unwrap());
+            mem::swap(&mut bref, &mut self.bref);
+            return Ok(bref.unwrap());
+        }
         if let Ok(NABufferType::None) = res {
             if self.bref.is_some() {
                 let mut bref: Option<NABufferType> = None;