Commit c9e1affc authored by Raphaël Zumer's avatar Raphaël Zumer Committed by Thomas Daede

Accommodate non-4:2:0 chroma in frame buffers

parent 063c63e3
......@@ -50,7 +50,7 @@ fn write_b_bench(b: &mut Bencher, tx_size: TxSize, qindex: usize) {
let mut w = ec::WriterEncoder::new();
let fc = CDFContext::new(fi.base_q_idx);
let bc = BlockContext::new(fi.sb_width * 16, fi.sb_height * 16);
let mut fs = FrameState::new(&fi);
let mut fs = FrameState::new(&fi, Default::default());
// For now, restoration unit size is locked to superblock size.
let rc = RestorationContext::new(fi.sb_width, fi.sb_height);
let mut cw = ContextWriter::new(fc, bc, rc);
......@@ -114,7 +114,7 @@ fn cdef_frame_bench(b: &mut Bencher, w: usize, h: usize) {
EncoderConfig { quantizer: 100, speed_settings: SpeedSettings::from_preset(10), ..Default::default() };
let fi = FrameInvariants::new(w, h, config);
let mut bc = BlockContext::new(fi.sb_width * 16, fi.sb_height * 16);
let mut fs = FrameState::new(&fi);
let mut fs = FrameState::new(&fi, Default::default());
b.iter(|| cdef_filter_frame(&fi, &mut fs.rec, &mut bc, 8));
}
......@@ -135,7 +135,7 @@ fn cfl_rdo_bench(b: &mut Bencher, bsize: BlockSize) {
let config =
EncoderConfig { quantizer: 100, speed_settings: SpeedSettings::from_preset(10), ..Default::default() };
let fi = FrameInvariants::new(1024, 1024, config);
let mut fs = FrameState::new(&fi);
let mut fs = FrameState::new(&fi, Default::default());
let offset = BlockOffset { x: 1, y: 1 };
b.iter(|| rdo_cfl_alpha(&mut fs, &offset, bsize, 8, Default::default()))
}
......
......@@ -358,7 +358,7 @@ impl fmt::Display for Packet {
impl Context {
pub fn new_frame(&self) -> Arc<Frame> {
Arc::new(Frame::new(self.fi.padded_w, self.fi.padded_h))
Arc::new(Frame::new(self.fi.padded_w, self.fi.padded_h, self.seq.chroma_sampling))
}
pub fn send_frame<F>(&mut self, frame: F) -> Result<(), EncoderStatus>
......@@ -491,7 +491,7 @@ impl Context {
if self.fi.show_existing_frame {
self.idx += 1;
let mut fs = FrameState::new(&self.fi);
let mut fs = FrameState::new(&self.fi, self.seq.chroma_sampling);
let data = encode_frame(&mut self.seq, &mut self.fi, &mut fs);
......@@ -510,7 +510,8 @@ impl Context {
self.idx += 1;
if let Some(frame) = f {
let mut fs = FrameState::new_with_frame(&self.fi, frame.clone());
let mut fs = FrameState::new_with_frame(&self.fi, frame.clone(),
self.seq.chroma_sampling);
let data = encode_frame(&mut self.seq, &mut self.fi, &mut fs);
self.packet_data.extend(data);
......
......@@ -42,7 +42,13 @@ pub struct Frame {
const FRAME_MARGIN: usize = 16 + SUBPEL_FILTER_SIZE;
impl Frame {
pub fn new(width: usize, height:usize) -> 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)
};
Frame {
planes: [
Plane::new(
......@@ -51,12 +57,12 @@ impl Frame {
MAX_SB_SIZE + FRAME_MARGIN, MAX_SB_SIZE + FRAME_MARGIN
),
Plane::new(
width/2, height/2,
chroma_width, chroma_height,
1, 1,
MAX_SB_SIZE/2 + FRAME_MARGIN, MAX_SB_SIZE/2 + FRAME_MARGIN
),
Plane::new(
width/2, height/2,
chroma_width, chroma_height,
1, 1,
MAX_SB_SIZE/2 + FRAME_MARGIN, MAX_SB_SIZE/2 + FRAME_MARGIN
)
......@@ -414,11 +420,13 @@ pub struct FrameState {
}
impl FrameState {
pub fn new(fi: &FrameInvariants) -> FrameState {
FrameState::new_with_frame(fi, Arc::new(Frame::new(fi.padded_w, fi.padded_h)))
pub fn new(fi: &FrameInvariants, chroma_sampling: ChromaSampling) -> FrameState {
FrameState::new_with_frame(fi, Arc::new(Frame::new(
fi.padded_w, fi.padded_h, chroma_sampling)), chroma_sampling)
}
pub fn new_with_frame(fi: &FrameInvariants, frame: Arc<Frame>) -> FrameState {
pub fn new_with_frame(fi: &FrameInvariants, frame: Arc<Frame>,
chroma_sampling: ChromaSampling) -> FrameState {
FrameState {
input: frame,
input_hres: Plane::new(
......@@ -431,7 +439,7 @@ impl FrameState {
2, 2,
(MAX_SB_SIZE + FRAME_MARGIN) / 4, (MAX_SB_SIZE + FRAME_MARGIN) / 4
),
rec: Frame::new(fi.padded_w, fi.padded_h),
rec: Frame::new(fi.padded_w, fi.padded_h, chroma_sampling),
qc: Default::default(),
cdfs: CDFContext::new(0),
deblock: Default::default(),
......@@ -2797,7 +2805,7 @@ mod test {
fn frame_state_window() {
let config = EncoderConfig { ..Default::default() };
let fi = FrameInvariants::new(1024, 1024, config);
let mut fs = FrameState::new(&fi);
let mut fs = FrameState::new(&fi, Default::default());
for p in fs.rec.planes.iter_mut() {
for (i, v) in p
.mut_slice(&PlaneOffset { x: 0, y: 0 })
......
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