Commit 18129cdc authored by Nathan E. Egge's avatar Nathan E. Egge Committed by Nathan Egge

Encapsulate the padding to 8x8 inside Frame::new().

This commit does not require the caller of Frame::new() to know to pad
 the width and height to multiples of 8x8 so that the internal buffers
 are allocated properly.
When filling the allocated buffers, callers should use the
 PlaneConfig.stride variable which is set by Frame::new().
parent 9391a6d0
......@@ -17,7 +17,6 @@ use self::EncoderStatus::*;
use std::{cmp, fmt, io};
use std::collections::BTreeMap;
use std::sync::Arc;
use crate::util::Fixed;
use std::collections::BTreeSet;
const LOOKAHEAD_FRAMES: u64 = 10;
......@@ -416,8 +415,8 @@ impl fmt::Display for Packet {
impl Context {
pub fn new_frame(&self) -> Arc<Frame> {
Arc::new(Frame::new(
self.config.enc.width.align_power_of_two(3),
self.config.enc.height.align_power_of_two(3),
self.config.enc.width,
self.config.enc.height,
self.config.enc.chroma_sampling
))
}
......
......@@ -7,7 +7,6 @@ use crate::decoder::VideoDetails;
use crate::encoder::ChromaSamplePosition;
use crate::encoder::ChromaSampling;
use crate::encoder::Frame;
use crate::util::Fixed;
impl Decoder for y4m::Decoder<'_, Box<dyn Read>> {
fn get_video_details(&self) -> VideoDetails {
......@@ -33,11 +32,7 @@ impl Decoder for y4m::Decoder<'_, Box<dyn Read>> {
let bytes = self.get_bytes_per_sample();
self.read_frame()
.map(|frame| {
let mut f = Frame::new(
cfg.width.align_power_of_two(3),
cfg.height.align_power_of_two(3),
cfg.chroma_sampling
);
let mut f = Frame::new(cfg.width, cfg.height, cfg.chroma_sampling);
let (chroma_period, _) = cfg.chroma_sampling.sampling_period();
......
......@@ -47,12 +47,15 @@ const FRAME_MARGIN: usize = 16 + SUBPEL_FILTER_SIZE;
impl Frame {
pub fn new(width: usize, height: usize, chroma_sampling: ChromaSampling) -> Frame {
let (luma_width, luma_height, luma_padding) = (
width.align_power_of_two(3),
height.align_power_of_two(3),
MAX_SB_SIZE + FRAME_MARGIN);
let (chroma_sampling_period_h, chroma_sampling_period_v) =
chroma_sampling.sampling_period();
let luma_padding = MAX_SB_SIZE + FRAME_MARGIN;
let (chroma_width, chroma_height, chroma_padding, chroma_xdec, chroma_ydec) = (
width / chroma_sampling_period_h,
height / chroma_sampling_period_v,
luma_width / chroma_sampling_period_h,
luma_height / chroma_sampling_period_v,
luma_padding / chroma_sampling_period_h,
chroma_sampling_period_h - 1,
chroma_sampling_period_v - 1
......@@ -61,7 +64,7 @@ impl Frame {
Frame {
planes: [
Plane::new(
width, height,
luma_width, luma_height,
0, 0,
luma_padding, luma_padding
),
......@@ -441,8 +444,9 @@ pub struct FrameState {
impl FrameState {
pub fn new(fi: &FrameInvariants) -> FrameState {
// TODO(negge): Use fi.cfg.chroma_sampling when we store VideoDetails in FrameInvariants
FrameState::new_with_frame(fi, Arc::new(Frame::new(
fi.padded_w, fi.padded_h, fi.sequence.chroma_sampling)))
fi.width, fi.height, fi.sequence.chroma_sampling)))
}
pub fn new_with_frame(fi: &FrameInvariants, frame: Arc<Frame>) -> FrameState {
......
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