1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
//! Color and pixel format configuration
//!
//! Methods for configuring color space, pixel format, and background color.
use crate::utils::four_char_code::FourCharCode;
use super::{internal::SCStreamConfiguration, pixel_format::PixelFormat};
impl SCStreamConfiguration {
/// Set the pixel format for captured frames
///
/// # Examples
///
/// ```
/// use screencapturekit::stream::configuration::{SCStreamConfiguration, PixelFormat};
///
/// let mut config = SCStreamConfiguration::default();
/// config.set_pixel_format(PixelFormat::BGRA);
/// ```
pub fn set_pixel_format(&mut self, pixel_format: PixelFormat) -> &mut Self {
let four_char_code: FourCharCode = pixel_format.into();
unsafe {
crate::ffi::sc_stream_configuration_set_pixel_format(
self.as_ptr(),
four_char_code.as_u32(),
);
}
self
}
/// Set the pixel format (builder pattern)
#[must_use]
pub fn with_pixel_format(mut self, pixel_format: PixelFormat) -> Self {
self.set_pixel_format(pixel_format);
self
}
/// Get the current pixel format
pub fn pixel_format(&self) -> PixelFormat {
unsafe {
let value = crate::ffi::sc_stream_configuration_get_pixel_format(self.as_ptr());
PixelFormat::from(value)
}
}
/// Set the background color for captured content
///
/// Available on macOS 13.0+
///
/// # Parameters
///
/// - `r`: Red component (0.0 - 1.0)
/// - `g`: Green component (0.0 - 1.0)
/// - `b`: Blue component (0.0 - 1.0)
pub fn set_background_color(&mut self, r: f32, g: f32, b: f32) -> &mut Self {
unsafe {
crate::ffi::sc_stream_configuration_set_background_color(self.as_ptr(), r, g, b);
}
self
}
/// Set the background color (builder pattern)
#[must_use]
pub fn with_background_color(mut self, r: f32, g: f32, b: f32) -> Self {
self.set_background_color(r, g, b);
self
}
/// Set the color space name for captured content
///
/// Available on macOS 13.0+
pub fn set_color_space_name(&mut self, name: &str) -> &mut Self {
if let Ok(c_name) = std::ffi::CString::new(name) {
unsafe {
crate::ffi::sc_stream_configuration_set_color_space_name(
self.as_ptr(),
c_name.as_ptr(),
);
}
}
self
}
/// Set the color space name (builder pattern)
#[must_use]
pub fn with_color_space_name(mut self, name: &str) -> Self {
self.set_color_space_name(name);
self
}
/// Set the color matrix for captured content
///
/// Available on macOS 13.0+. The matrix should be a 3x3 array in row-major order.
pub fn set_color_matrix(&mut self, matrix: &str) -> &mut Self {
if let Ok(c_matrix) = std::ffi::CString::new(matrix) {
unsafe {
crate::ffi::sc_stream_configuration_set_color_matrix(
self.as_ptr(),
c_matrix.as_ptr(),
);
}
}
self
}
/// Get the color matrix for captured content
///
/// Returns the color matrix as a string, or None if not set.
pub fn color_matrix(&self) -> Option<String> {
let mut buffer = [0i8; 256];
let success = unsafe {
crate::ffi::sc_stream_configuration_get_color_matrix(
self.as_ptr(),
buffer.as_mut_ptr(),
buffer.len(),
)
};
if success {
let c_str = unsafe { std::ffi::CStr::from_ptr(buffer.as_ptr()) };
c_str.to_str().ok().map(ToString::to_string)
} else {
None
}
}
/// Set the color matrix (builder pattern)
#[must_use]
pub fn with_color_matrix(mut self, matrix: &str) -> Self {
self.set_color_matrix(matrix);
self
}
}