]> git.nihav.org Git - nihav.git/blobdiff - nihav-itu/src/codecs/h264/types.rs
avimux: do not record palette change chunks in OpenDML index
[nihav.git] / nihav-itu / src / codecs / h264 / types.rs
index 4cc1fca3b880085b2b7c216eff38e4eb156ac311..577cefe93685843413861115bb3c036749db9b38 100644 (file)
@@ -1,9 +1,31 @@
-use nihav_core::frame::NASimpleVideoFrame;
+use nihav_core::frame::{NAVideoBuffer, NASimpleVideoFrame};
 use nihav_codec_support::codecs::{MV, ZERO_MV};
 use nihav_codec_support::data::GenericCache;
-use super::SliceRefs;
+use super::SimplifiedSliceRefs;
 use super::pic_ref::FrameMBInfo;
 
+#[derive(Clone,Copy)]
+pub struct SimpleFrame<'a> {
+    pub data:   &'a [u8],
+    pub offset: [usize; 3],
+    pub stride: [usize; 3],
+}
+
+impl<'a> SimpleFrame<'a> {
+    pub fn new(buf: &'a NAVideoBuffer<u8>) -> Self {
+        let mut offset = [0; 3];
+        let mut stride = [0; 3];
+        for (plane, (offs, strd)) in offset.iter_mut().zip(stride.iter_mut()).enumerate() {
+            *offs = buf.get_offset(plane);
+            *strd = buf.get_stride(plane);
+        }
+        Self {
+            data:   buf.get_data(),
+            offset, stride
+        }
+    }
+}
+
 #[repr(u8)]
 #[derive(Clone,Copy,Debug,PartialEq)]
 pub enum BMode {
@@ -361,8 +383,9 @@ pub struct MBData {
 }
 
 pub fn blk4_to_blk8(blk4: usize) -> usize {
-    const MAP: [usize; 16] = [ 0, 0, 1, 1, 0, 0, 1, 1, 2, 2, 3, 3, 2, 2, 3, 3 ];
-    MAP[blk4 & 0xF]
+    /*const MAP: [usize; 16] = [ 0, 0, 1, 1, 0, 0, 1, 1, 2, 2, 3, 3, 2, 2, 3, 3 ];
+    MAP[blk4 & 0xF]*/
+    ((blk4 & 2) >> 1) | ((blk4 & 8) >> 2)
 }
 
 #[derive(Clone,Copy)]
@@ -478,7 +501,7 @@ impl SliceState {
             }
         }
     }
-    pub fn fill_deblock(&mut self, frefs: &SliceRefs, deblock_mode: u8, is_s: bool) {
+    pub fn fill_deblock(&mut self, frefs: &SimplifiedSliceRefs, deblock_mode: u8, is_s: bool) {
         if deblock_mode == 1 {
             return;
         }
@@ -548,13 +571,17 @@ impl SliceState {
                                 cur_mvs[1..].iter().zip(top_mvs[1..].iter())).zip(
                             cur_refs[1..].iter().zip(
                                 top_refs[1..].iter())).take(4).enumerate() {
+                        let mut mask = 0;
                         if cur_cc || top_cc {
-                            self.deblock[y * 4 + x] |= 0x20;
+                            mask = 0x20;
                         } else {
                             if mvdiff4(cur_mv, top_mv) || !frefs.cmp_refs(cur_ref, top_ref) {
-                                self.deblock[y * 4 + x] |= 0x10;
+                                mask = 0x10;
                             }
                         }
+                        if mask != 0 {
+                            self.deblock[y * 4 + x] = mask;
+                        }
                     }
                 }
             }
@@ -568,16 +595,20 @@ impl SliceState {
                 if !can_do_left {
                     continue;
                 }
+                let mut mask = 0;
                 if skip_8 {
                 } else if is_s || cur_intra || lleft_intra {
-                    self.deblock[y * 4 + x] |= if x == 0 { 4 } else { 3 };
+                    mask = if x == 0 { 4 } else { 3 };
                 } else if cur_cc || left_cc {
-                    self.deblock[y * 4 + x] |= 2;
+                    mask = 2;
                 } else {
                     if mvdiff4(cur_mv, left_mv) || !frefs.cmp_refs(cur_ref, left_ref) {
-                        self.deblock[y * 4 + x] |= 1;
+                        mask = 1;
                     }
                 }
+                if mask != 0 {
+                    self.deblock[y * 4 + x] |= mask;
+                }
                 lleft_intra = cur_intra;
             }
             top_intra = cur_intra;
@@ -773,7 +804,7 @@ impl SliceState {
         self.fill_mv (0, 0, 16, 16, 0, mv);
         self.fill_ref(0, 0, 16, 16, 0, ref_idx);
     }
-    pub fn predict_direct_mb(&mut self, frame_refs: &SliceRefs, temporal_mv: bool, direct_8x8: bool, cur_id: u16) {
+    pub fn predict_direct_mb(&mut self, frame_refs: &SimplifiedSliceRefs, temporal_mv: bool, direct_8x8: bool, cur_id: u16) {
         let (col_mb, r1_poc, r1_long) = frame_refs.get_colocated_info(self.mb_x, self.mb_y);
         if direct_8x8 {
             for blk4 in 0..16 {
@@ -793,7 +824,7 @@ impl SliceState {
             }
         }
     }
-    pub fn predict_direct_sub(&mut self, frame_refs: &SliceRefs, temporal_mv: bool, direct8x8: bool, cur_id: u16, blk4: usize) {
+    pub fn predict_direct_sub(&mut self, frame_refs: &SimplifiedSliceRefs, temporal_mv: bool, direct8x8: bool, cur_id: u16, blk4: usize) {
         let src_blk = if !direct8x8 { blk4 } else { BLK4_TO_D8[blk4] };
         let (mbi, r1_poc, r1_long) = frame_refs.get_colocated_info(self.mb_x, self.mb_y);
         let (mv0, ref0, mv1, ref1) = self.get_direct_mv(frame_refs, &mbi, r1_poc, r1_long, temporal_mv, cur_id, src_blk);
@@ -801,7 +832,7 @@ impl SliceState {
         self.get_cur_blk8(blk4_to_blk8(blk4)).ref_idx = [ref0, ref1];
     }
     #[allow(clippy::nonminimal_bool)]
-    pub fn get_direct_mv(&self, frame_refs: &SliceRefs, mbi: &FrameMBInfo, r1_poc: u16, r1_long: bool, temporal_mv: bool, cur_id: u16, blk4: usize) -> (MV, PicRef, MV, PicRef) {
+    pub fn get_direct_mv(&self, frame_refs: &SimplifiedSliceRefs, mbi: &FrameMBInfo, r1_poc: u16, r1_long: bool, temporal_mv: bool, cur_id: u16, blk4: usize) -> (MV, PicRef, MV, PicRef) {
         let blk8 = blk4_to_blk8(blk4);
         let (col_mv, r0_poc, col_idx) = if mbi.ref_poc[blk8] == [MISSING_POC; 2] {
                 (ZERO_MV, MISSING_POC, MISSING_REF)