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> {
826826 copy(&pic.cr, cx_c, cy_c, cw_c, ch_c),
827827 ];
828828 let mut frame = VideoFrame::try_new(
829- match (pic.cat, S::IS_8) {
830- (3, true) => PixelFormat::I444,
831- (3, false) => PixelFormat::I410,
832- (2, true) => PixelFormat::I422,
833- (2, false) => PixelFormat::I210,
834- (_, true) => PixelFormat::I420,
835- (_, false) => PixelFormat::I010,
836- },
829+ S::FORMATS[match pic.cat {
830+ 3 => 0,
831+ 2 => 1,
832+ _ => 2,
833+ }],
837834 w as u32,
838835 h as u32,
839836 planes,
crates/ec-h264/src/sample.rsmodified+4 -0
@@ -10,6 +10,7 @@ use crate::decoder::SliceCtx;
1010 use crate::mc::{compensate8, compensate16};
1111 use crate::dpb::Picture;
1212 use ec_core::error::Result;
13+use ec_core::frame::PixelFormat;
1314
1415 /// A picture sample.
1516 pub(crate) trait Sample:
@@ -17,6 +18,7 @@ pub(crate) trait Sample:
1718 {
1819 /// True for the 8-bit instantiation.
1920 const IS_8: bool;
21+ const FORMATS: [PixelFormat; 3];
2022 /// Bytes per sample in an output frame.
2123 const BYTES: usize;
2224 /// Append `src` to an output plane, little-endian, shifted left by `shift`.
@@ -74,6 +76,7 @@ pub(crate) trait Sample:
7476
7577 impl Sample for u8 {
7678 const IS_8: bool = true;
79+ const FORMATS: [PixelFormat; 3] = [PixelFormat::I444, PixelFormat::I422, PixelFormat::I420];
7780 const BYTES: usize = 1;
7881 #[inline]
7982 fn extend_bytes(out: &mut Vec<u8>, src: &[u8], _shift: u32) {
@@ -131,6 +134,7 @@ impl Sample for u8 {
131134
132135 impl Sample for u16 {
133136 const IS_8: bool = false;
137+ const FORMATS: [PixelFormat; 3] = [PixelFormat::I410, PixelFormat::I210, PixelFormat::I010];
134138 const BYTES: usize = 2;
135139 #[inline]
136140 fn extend_bytes(out: &mut Vec<u8>, src: &[u16], shift: u32) {