pub struct CVPixelBuffer(/* private fields */);Implementations§
Source§impl CVPixelBuffer
impl CVPixelBuffer
pub fn from_raw(ptr: *mut c_void) -> Option<Self>
Sourcepub unsafe fn from_ptr(ptr: *mut c_void) -> Self
pub unsafe fn from_ptr(ptr: *mut c_void) -> Self
§Safety
The caller must ensure the pointer is a valid CVPixelBuffer pointer.
pub fn as_ptr(&self) -> *mut c_void
Sourcepub fn create(
width: usize,
height: usize,
pixel_format: u32,
) -> Result<Self, i32>
pub fn create( width: usize, height: usize, pixel_format: u32, ) -> Result<Self, i32>
Create a new pixel buffer with the specified dimensions and pixel format
§Arguments
width- Width of the pixel buffer in pixelsheight- Height of the pixel buffer in pixelspixel_format- Pixel format type (e.g., 0x42475241 for BGRA)
§Errors
Returns a Core Video error code if the pixel buffer creation fails.
§Examples
use screencapturekit::cm::CVPixelBuffer;
// Create a 1920x1080 BGRA pixel buffer
let buffer = CVPixelBuffer::create(1920, 1080, 0x42475241)
.expect("Failed to create pixel buffer");
assert_eq!(buffer.width(), 1920);
assert_eq!(buffer.height(), 1080);
assert_eq!(buffer.pixel_format(), 0x42475241);Sourcepub unsafe fn create_with_bytes(
width: usize,
height: usize,
pixel_format: u32,
base_address: *mut c_void,
bytes_per_row: usize,
) -> Result<Self, i32>
pub unsafe fn create_with_bytes( width: usize, height: usize, pixel_format: u32, base_address: *mut c_void, bytes_per_row: usize, ) -> Result<Self, i32>
Create a pixel buffer from existing memory
§Arguments
width- Width of the pixel buffer in pixelsheight- Height of the pixel buffer in pixelspixel_format- Pixel format type (e.g., 0x42475241 for BGRA)base_address- Pointer to pixel databytes_per_row- Number of bytes per row
§Safety
The caller must ensure that:
base_addresspoints to valid memory- Memory remains valid for the lifetime of the pixel buffer
bytes_per_rowcorrectly represents the memory layout
§Errors
Returns a Core Video error code if the pixel buffer creation fails.
§Examples
use screencapturekit::cm::CVPixelBuffer;
// Create pixel data (100x100 BGRA image)
let width = 100;
let height = 100;
let bytes_per_pixel = 4; // BGRA
let bytes_per_row = width * bytes_per_pixel;
let mut pixel_data = vec![0u8; width * height * bytes_per_pixel];
// Fill with blue color
for y in 0..height {
for x in 0..width {
let offset = y * bytes_per_row + x * bytes_per_pixel;
pixel_data[offset] = 255; // B
pixel_data[offset + 1] = 0; // G
pixel_data[offset + 2] = 0; // R
pixel_data[offset + 3] = 255; // A
}
}
// Create pixel buffer from the data
let buffer = unsafe {
CVPixelBuffer::create_with_bytes(
width,
height,
0x42475241, // BGRA
pixel_data.as_mut_ptr() as *mut std::ffi::c_void,
bytes_per_row,
)
}.expect("Failed to create pixel buffer");
assert_eq!(buffer.width(), width);
assert_eq!(buffer.height(), height);Sourcepub fn fill_extended_pixels(&self) -> Result<(), i32>
pub fn fill_extended_pixels(&self) -> Result<(), i32>
Fill the extended pixels of a pixel buffer
This is useful for pixel buffers that have been created with extended pixels enabled, to ensure proper edge handling for effects and filters.
§Errors
Returns a Core Video error code if the operation fails.
Sourcepub unsafe fn create_with_planar_bytes(
width: usize,
height: usize,
pixel_format: u32,
plane_base_addresses: &[*mut c_void],
plane_widths: &[usize],
plane_heights: &[usize],
plane_bytes_per_row: &[usize],
) -> Result<Self, i32>
pub unsafe fn create_with_planar_bytes( width: usize, height: usize, pixel_format: u32, plane_base_addresses: &[*mut c_void], plane_widths: &[usize], plane_heights: &[usize], plane_bytes_per_row: &[usize], ) -> Result<Self, i32>
Create a pixel buffer with planar bytes
§Safety
The caller must ensure that:
plane_base_addressespoints to valid memory for each plane- Memory remains valid for the lifetime of the pixel buffer
- All plane parameters correctly represent the memory layout
§Errors
Returns a Core Video error code if the pixel buffer creation fails.
Sourcepub fn create_with_io_surface(surface: &IOSurface) -> Result<Self, i32>
pub fn create_with_io_surface(surface: &IOSurface) -> Result<Self, i32>
Create a pixel buffer from an IOSurface
§Errors
Returns a Core Video error code if the pixel buffer creation fails.
Sourcepub fn get_type_id() -> usize
pub fn get_type_id() -> usize
Get the Core Foundation type ID for CVPixelBuffer
Sourcepub fn get_data_size(&self) -> usize
pub fn get_data_size(&self) -> usize
Get the data size of the pixel buffer
Sourcepub fn get_plane_count(&self) -> usize
pub fn get_plane_count(&self) -> usize
Get the number of planes in the pixel buffer
Sourcepub fn get_width_of_plane(&self, plane_index: usize) -> usize
pub fn get_width_of_plane(&self, plane_index: usize) -> usize
Get the width of a specific plane
Sourcepub fn get_height_of_plane(&self, plane_index: usize) -> usize
pub fn get_height_of_plane(&self, plane_index: usize) -> usize
Get the height of a specific plane
Sourcepub fn get_base_address_of_plane(&self, plane_index: usize) -> Option<*mut u8>
pub fn get_base_address_of_plane(&self, plane_index: usize) -> Option<*mut u8>
Get the base address of a specific plane
Sourcepub fn get_bytes_per_row_of_plane(&self, plane_index: usize) -> usize
pub fn get_bytes_per_row_of_plane(&self, plane_index: usize) -> usize
Get the bytes per row of a specific plane
Sourcepub fn get_extended_pixels(&self) -> (usize, usize, usize, usize)
pub fn get_extended_pixels(&self) -> (usize, usize, usize, usize)
Get the extended pixel information (left, right, top, bottom)
Sourcepub fn is_backed_by_io_surface(&self) -> bool
pub fn is_backed_by_io_surface(&self) -> bool
Check if the pixel buffer is backed by an IOSurface
pub fn get_width(&self) -> usize
pub fn get_height(&self) -> usize
pub fn get_pixel_format_type(&self) -> u32
pub fn get_bytes_per_row(&self) -> usize
pub fn get_base_address(&self) -> Option<*mut u8>
pub fn get_iosurface(&self) -> Option<IOSurface>
pub fn width(&self) -> usize
pub fn height(&self) -> usize
pub fn pixel_format(&self) -> u32
pub fn bytes_per_row(&self) -> usize
Sourcepub fn lock_raw(&self, flags: u32) -> Result<(), i32>
pub fn lock_raw(&self, flags: u32) -> Result<(), i32>
Lock the base address for raw access
§Errors
Returns a Core Video error code if the lock operation fails.
Sourcepub fn unlock_raw(&self, flags: u32) -> Result<(), i32>
pub fn unlock_raw(&self, flags: u32) -> Result<(), i32>
Unlock the base address after raw access
§Errors
Returns a Core Video error code if the unlock operation fails.
pub fn base_address(&self) -> Option<*mut u8>
pub fn get_io_surface(&self) -> Option<IOSurface>
Sourcepub fn lock_base_address(
&self,
read_only: bool,
) -> Result<CVPixelBufferLockGuard<'_>, i32>
pub fn lock_base_address( &self, read_only: bool, ) -> Result<CVPixelBufferLockGuard<'_>, i32>
Lock the base address and return a guard for RAII-style access
§Errors
Returns a Core Video error code if the lock operation fails.