From 8469229647468f339bf90ced80459a7b1add5fdd Mon Sep 17 00:00:00 2001 From: Philippe Normand Date: Fri, 29 Mar 2024 13:57:31 +0000 Subject: [PATCH] Add API for ChromaLocation information retrieval --- src/lib.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 556b9e7..b3868db 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -729,6 +729,18 @@ impl Picture { } } } + + /// Sample position for subsampled chroma. + pub fn chroma_location(&self) -> pixel::ChromaLocation { + // According to y4m mapping declared in dav1d's output/y4m2.c and applied from FFmpeg's yuv4mpegdec.c + unsafe { + match (*self.inner.pic.seq_hdr).chr { + DAV1D_CHR_UNKNOWN | DAV1D_CHR_COLOCATED => pixel::ChromaLocation::Center, + DAV1D_CHR_VERTICAL => pixel::ChromaLocation::Left, + _ => unreachable!(), + } + } + } } static_assertions::assert_impl_all!(Picture: Send, Sync);