forge
Explore
Log in

Don't you dare go Hollow

S8: Sample::FORMATS const replaces the (chroma type, IS_8) frame-format match

Browse files at this commit

ee455d59c7fa39ec6331154d741dbb4b993b8d01Ahmet Kaan GümüşParent: 9d32686
crates/ec-h264/src/decoder.rsmodified+5 -8
@@ -826,14 +826,11 @@ impl<S: Sample> Core<S> {
826 copy(&pic.cr, cx_c, cy_c, cw_c, ch_c),826 copy(&pic.cr, cx_c, cy_c, cw_c, ch_c),
827 ];827 ];
828 let mut frame = VideoFrame::try_new(828 let mut frame = VideoFrame::try_new(
829- match (pic.cat, S::IS_8) {829+ S::FORMATS[match pic.cat {
830- (3, true) => PixelFormat::I444,830+ 3 => 0,
831- (3, false) => PixelFormat::I410,831+ 2 => 1,
832- (2, true) => PixelFormat::I422,832+ _ => 2,
833- (2, false) => PixelFormat::I210,833+ }],
834- (_, true) => PixelFormat::I420,
835- (_, false) => PixelFormat::I010,
836- },
837 w as u32,834 w as u32,
838 h as u32,835 h as u32,
839 planes,836 planes,
crates/ec-h264/src/sample.rsmodified+4 -0
@@ -10,6 +10,7 @@ use crate::decoder::SliceCtx;
10 use crate::mc::{compensate8, compensate16};10 use crate::mc::{compensate8, compensate16};
11 use crate::dpb::Picture;11 use crate::dpb::Picture;
12 use ec_core::error::Result;12 use ec_core::error::Result;
13+use ec_core::frame::PixelFormat;
13 14
14 /// A picture sample.15 /// A picture sample.
15 pub(crate) trait Sample:16 pub(crate) trait Sample:
@@ -17,6 +18,7 @@ pub(crate) trait Sample:
17 {18 {
18 /// True for the 8-bit instantiation.19 /// True for the 8-bit instantiation.
19 const IS_8: bool;20 const IS_8: bool;
21+ const FORMATS: [PixelFormat; 3];
20 /// Bytes per sample in an output frame.22 /// Bytes per sample in an output frame.
21 const BYTES: usize;23 const BYTES: usize;
22 /// Append `src` to an output plane, little-endian, shifted left by `shift`.24 /// Append `src` to an output plane, little-endian, shifted left by `shift`.
@@ -74,6 +76,7 @@ pub(crate) trait Sample:
74 76
75 impl Sample for u8 {77 impl Sample for u8 {
76 const IS_8: bool = true;78 const IS_8: bool = true;
79+ const FORMATS: [PixelFormat; 3] = [PixelFormat::I444, PixelFormat::I422, PixelFormat::I420];
77 const BYTES: usize = 1;80 const BYTES: usize = 1;
78 #[inline]81 #[inline]
79 fn extend_bytes(out: &mut Vec<u8>, src: &[u8], _shift: u32) {82 fn extend_bytes(out: &mut Vec<u8>, src: &[u8], _shift: u32) {
@@ -131,6 +134,7 @@ impl Sample for u8 {
131 134
132 impl Sample for u16 {135 impl Sample for u16 {
133 const IS_8: bool = false;136 const IS_8: bool = false;
137+ const FORMATS: [PixelFormat; 3] = [PixelFormat::I410, PixelFormat::I210, PixelFormat::I010];
134 const BYTES: usize = 2;138 const BYTES: usize = 2;
135 #[inline]139 #[inline]
136 fn extend_bytes(out: &mut Vec<u8>, src: &[u16], shift: u32) {140 fn extend_bytes(out: &mut Vec<u8>, src: &[u16], shift: u32) {