diff --git a/src/lib.rs b/src/lib.rs index c67ad0a..1438342 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -101,6 +101,7 @@ pub struct Packet { pub frame_type: FrameType, } +type PixelRange=rav1e::PixelRange; type ChromaSamplePosition=rav1e::ChromaSamplePosition; type ChromaSampling=rav1e::ChromaSampling; type MatrixCoefficients=rav1e::MatrixCoefficients; @@ -122,6 +123,33 @@ pub unsafe extern "C" fn rav1e_config_default() -> *mut Config { Box::into_raw(c) } + +/// Set pixel format of the stream. +/// +/// Supported values for subsampling and chromapos are defined by the +/// enum types RaChromaSampling and RaChromaSamplePosition respectively. +/// Valid values for fullrange are 0 and 1. +/// +/// Reuturns a negative value on error or 0. +#[no_mangle] +pub unsafe extern "C" fn rav1e_config_set_pixel_format(cfg: *mut Config, + bit_depth: u8, + subsampling: ChromaSampling, + chroma_pos: ChromaSamplePosition, + pixel_range: PixelRange +) -> c_int { + if bit_depth != 8 && bit_depth != 10 && bit_depth != 12 { + return -1 + } + + (*cfg).cfg.enc.bit_depth = bit_depth as usize; + (*cfg).cfg.enc.chroma_sampling = subsampling; + (*cfg).cfg.enc.chroma_sample_position = chroma_pos; + (*cfg).cfg.enc.pixel_range = pixel_range; + + 0 +} + /// Set color properties of the stream. /// /// Supported values are defined by the enum types