screencapturekit/stream/configuration/
colors.rs1use crate::utils::four_char_code::FourCharCode;
6
7use super::{internal::SCStreamConfiguration, pixel_format::PixelFormat};
8
9impl SCStreamConfiguration {
10 pub fn set_pixel_format(&mut self, pixel_format: PixelFormat) -> &mut Self {
21 let four_char_code: FourCharCode = pixel_format.into();
22 unsafe {
23 crate::ffi::sc_stream_configuration_set_pixel_format(
24 self.as_ptr(),
25 four_char_code.as_u32(),
26 );
27 }
28 self
29 }
30
31 #[must_use]
33 pub fn with_pixel_format(mut self, pixel_format: PixelFormat) -> Self {
34 self.set_pixel_format(pixel_format);
35 self
36 }
37
38 pub fn pixel_format(&self) -> PixelFormat {
40 unsafe {
41 let value = crate::ffi::sc_stream_configuration_get_pixel_format(self.as_ptr());
42 PixelFormat::from(value)
43 }
44 }
45
46 pub fn set_background_color(&mut self, r: f32, g: f32, b: f32) -> &mut Self {
56 unsafe {
57 crate::ffi::sc_stream_configuration_set_background_color(self.as_ptr(), r, g, b);
58 }
59 self
60 }
61
62 #[must_use]
64 pub fn with_background_color(mut self, r: f32, g: f32, b: f32) -> Self {
65 self.set_background_color(r, g, b);
66 self
67 }
68
69 pub fn set_color_space_name(&mut self, name: &str) -> &mut Self {
73 if let Ok(c_name) = std::ffi::CString::new(name) {
74 unsafe {
75 crate::ffi::sc_stream_configuration_set_color_space_name(
76 self.as_ptr(),
77 c_name.as_ptr(),
78 );
79 }
80 }
81 self
82 }
83
84 #[must_use]
86 pub fn with_color_space_name(mut self, name: &str) -> Self {
87 self.set_color_space_name(name);
88 self
89 }
90
91 pub fn set_color_matrix(&mut self, matrix: &str) -> &mut Self {
95 if let Ok(c_matrix) = std::ffi::CString::new(matrix) {
96 unsafe {
97 crate::ffi::sc_stream_configuration_set_color_matrix(
98 self.as_ptr(),
99 c_matrix.as_ptr(),
100 );
101 }
102 }
103 self
104 }
105
106 pub fn color_matrix(&self) -> Option<String> {
110 let mut buffer = [0i8; 256];
111 let success = unsafe {
112 crate::ffi::sc_stream_configuration_get_color_matrix(
113 self.as_ptr(),
114 buffer.as_mut_ptr(),
115 buffer.len(),
116 )
117 };
118 if success {
119 let c_str = unsafe { std::ffi::CStr::from_ptr(buffer.as_ptr()) };
120 c_str.to_str().ok().map(ToString::to_string)
121 } else {
122 None
123 }
124 }
125
126 #[must_use]
128 pub fn with_color_matrix(mut self, matrix: &str) -> Self {
129 self.set_color_matrix(matrix);
130 self
131 }
132}