Commit 9675a3f1 authored by Raphaël Zumer's avatar Raphaël Zumer Committed by Thomas Daede
Browse files

Provide 2D sampling period in ChromaSampling

parent 2b5e9bb5
......@@ -310,11 +310,11 @@ pub fn process_frame(
if let Some(y4m_enc_uw) = y4m_enc.as_mut() {
if let Some(ref rec) = pkt.rec {
let pitch_y = if bit_depth > 8 { width * 2 } else { width };
let (pitch_uv, height_uv) = match map_y4m_color_space(y4m_color_space).0 {
ChromaSampling::Cs420 => (pitch_y / 2, height / 2),
ChromaSampling::Cs422 => (pitch_y / 2, height),
ChromaSampling::Cs444 => (pitch_y, height)
};
let chroma_sampling_period = map_y4m_color_space(y4m_color_space).0.sampling_period();
let (pitch_uv, height_uv) = (
pitch_y / chroma_sampling_period.0,
height / chroma_sampling_period.1
);
let (mut rec_y, mut rec_u, mut rec_v) = (
vec![128u8; pitch_y * height],
......
......@@ -43,11 +43,11 @@ const FRAME_MARGIN: usize = 16 + SUBPEL_FILTER_SIZE;
impl Frame {
pub fn new(width: usize, height: usize, chroma_sampling: ChromaSampling) -> Frame {
let (chroma_width, chroma_height) = match chroma_sampling {
ChromaSampling::Cs420 => (width / 2, height / 2),
ChromaSampling::Cs422 => (width / 2, height),
ChromaSampling::Cs444 => (width, height)
};
let chroma_sampling_period = chroma_sampling.sampling_period();
let (chroma_width, chroma_height) = (
width / chroma_sampling_period.0,
height / chroma_sampling_period.1
);
Frame {
planes: [
......@@ -206,6 +206,17 @@ impl Default for ChromaSampling {
}
}
impl ChromaSampling {
// Provides the sampling period in the horizontal and vertical axes.
pub fn sampling_period(self) -> (usize, usize) {
match self {
ChromaSampling::Cs420 => (2, 2),
ChromaSampling::Cs422 => (2, 1),
ChromaSampling::Cs444 => (1, 1)
}
}
}
#[derive(Copy, Clone, Debug, PartialEq)]
#[repr(C)]
pub enum ChromaSamplePosition {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment