Skip to content

Instantly share code, notes, and snippets.

@dwbuiten
Last active May 26, 2019 15:20
Show Gist options
  • Save dwbuiten/0713aab0775f81bc7e634f858d0ba0a1 to your computer and use it in GitHub Desktop.
Save dwbuiten/0713aab0775f81bc7e634f858d0ba0a1 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment