Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enum Rav1dChromaSamplePosition: make a real enum #790

Merged
merged 1 commit into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 32 additions & 9 deletions include/dav1d/headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -577,14 +577,37 @@ pub(crate) const _RAV1D_MC_BT709: Rav1dMatrixCoefficients = DAV1D_MC_BT709;
pub(crate) const RAV1D_MC_IDENTITY: Rav1dMatrixCoefficients = DAV1D_MC_IDENTITY;

pub type Dav1dChromaSamplePosition = c_uint;
pub const DAV1D_CHR_COLOCATED: Dav1dChromaSamplePosition = 2;
pub const DAV1D_CHR_VERTICAL: Dav1dChromaSamplePosition = 1;
pub const DAV1D_CHR_UNKNOWN: Dav1dChromaSamplePosition = 0;
pub const DAV1D_CHR_UNKNOWN: Dav1dChromaSamplePosition =
Rav1dChromaSamplePosition::Unknown as Dav1dChromaSamplePosition;
pub const DAV1D_CHR_VERTICAL: Dav1dChromaSamplePosition =
Rav1dChromaSamplePosition::Vertical as Dav1dChromaSamplePosition;
pub const DAV1D_CHR_COLOCATED: Dav1dChromaSamplePosition =
Rav1dChromaSamplePosition::Colocated as Dav1dChromaSamplePosition;

pub(crate) type Rav1dChromaSamplePosition = c_uint;
pub(crate) const _RAV1D_CHR_COLOCATED: Rav1dChromaSamplePosition = DAV1D_CHR_COLOCATED;
pub(crate) const _RAV1D_CHR_VERTICAL: Rav1dChromaSamplePosition = DAV1D_CHR_VERTICAL;
pub(crate) const RAV1D_CHR_UNKNOWN: Rav1dChromaSamplePosition = DAV1D_CHR_UNKNOWN;
#[derive(Clone, Copy, PartialEq, Eq, FromRepr)]
pub enum Rav1dChromaSamplePosition {
Unknown = 0,
/// Horizontally co-located with (0, 0) luma sample, vertical position
/// in the middle between two luma samples
Vertical = 1,
/// co-located with (0, 0) luma sample
Colocated = 2,
_Reserved = 3,
kkysen marked this conversation as resolved.
Show resolved Hide resolved
}

impl From<Rav1dChromaSamplePosition> for Dav1dChromaSamplePosition {
fn from(value: Rav1dChromaSamplePosition) -> Self {
value as Dav1dChromaSamplePosition
}
}

impl TryFrom<Dav1dChromaSamplePosition> for Rav1dChromaSamplePosition {
type Error = ();

fn try_from(value: Dav1dChromaSamplePosition) -> Result<Self, Self::Error> {
Self::from_repr(value as usize).ok_or(())
}
}

#[repr(C)]
pub struct Rav1dContentLightLevel {
Expand Down Expand Up @@ -1075,7 +1098,7 @@ impl From<Dav1dSequenceHeader> for Rav1dSequenceHeader {
pri,
trc,
mtrx,
chr,
chr: chr.try_into().unwrap(),
hbd,
color_range,
num_operating_points,
Expand Down Expand Up @@ -1190,7 +1213,7 @@ impl From<Rav1dSequenceHeader> for Dav1dSequenceHeader {
pri,
trc,
mtrx,
chr,
chr: chr.into(),
hbd,
color_range,
num_operating_points,
Expand Down
9 changes: 4 additions & 5 deletions src/obu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ use crate::include::dav1d::headers::Rav1dTransferCharacteristics;
use crate::include::dav1d::headers::Rav1dTxfmMode;
use crate::include::dav1d::headers::Rav1dWarpedMotionParams;
use crate::include::dav1d::headers::Rav1dWarpedMotionType;
use crate::include::dav1d::headers::RAV1D_CHR_UNKNOWN;
use crate::include::dav1d::headers::RAV1D_COLOR_PRI_BT709;
use crate::include::dav1d::headers::RAV1D_COLOR_PRI_UNKNOWN;
use crate::include::dav1d::headers::RAV1D_MAX_CDEF_STRENGTHS;
Expand Down Expand Up @@ -409,7 +408,7 @@ fn parse_seq_hdr(c: &mut Rav1dContext, gb: &mut GetBits) -> Rav1dResult<Rav1dSeq
layout = Rav1dPixelLayout::I400;
ss_ver = 1;
ss_hor = ss_ver;
chr = RAV1D_CHR_UNKNOWN;
chr = Rav1dChromaSamplePosition::Unknown;
} else if pri == RAV1D_COLOR_PRI_BT709 && trc == RAV1D_TRC_SRGB && mtrx == RAV1D_MC_IDENTITY {
layout = Rav1dPixelLayout::I444;
color_range = 1;
Expand All @@ -420,7 +419,7 @@ fn parse_seq_hdr(c: &mut Rav1dContext, gb: &mut GetBits) -> Rav1dResult<Rav1dSeq
// Default initialization.
ss_hor = Default::default();
ss_ver = Default::default();
chr = Default::default();
chr = Rav1dChromaSamplePosition::Unknown;
} else {
color_range = gb.get_bit() as c_int;
match profile {
Expand Down Expand Up @@ -463,9 +462,9 @@ fn parse_seq_hdr(c: &mut Rav1dContext, gb: &mut GetBits) -> Rav1dResult<Rav1dSeq
}
}
chr = if ss_hor & ss_ver != 0 {
gb.get_bits(2) as Rav1dChromaSamplePosition
Rav1dChromaSamplePosition::from_repr(gb.get_bits(2) as usize).unwrap()
} else {
RAV1D_CHR_UNKNOWN
Rav1dChromaSamplePosition::Unknown
};
}
if c.strict_std_compliance && mtrx == RAV1D_MC_IDENTITY && layout != Rav1dPixelLayout::I444 {
Expand Down
Loading