CVPixelBuffer

Struct CVPixelBuffer 

Source
pub struct CVPixelBuffer(/* private fields */);

Implementations§

Source§

impl CVPixelBuffer

Source

pub fn from_raw(ptr: *mut c_void) -> Option<Self>

Source

pub unsafe fn from_ptr(ptr: *mut c_void) -> Self

§Safety

The caller must ensure the pointer is a valid CVPixelBuffer pointer.

Source

pub fn as_ptr(&self) -> *mut c_void

Source

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 pixels
  • height - Height of the pixel buffer in pixels
  • pixel_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);
Source

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 pixels
  • height - Height of the pixel buffer in pixels
  • pixel_format - Pixel format type (e.g., 0x42475241 for BGRA)
  • base_address - Pointer to pixel data
  • bytes_per_row - Number of bytes per row
§Safety

The caller must ensure that:

  • base_address points to valid memory
  • Memory remains valid for the lifetime of the pixel buffer
  • bytes_per_row correctly 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);
Source

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.

Source

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_addresses points 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.

Source

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.

Source

pub fn get_type_id() -> usize

Get the Core Foundation type ID for CVPixelBuffer

Source

pub fn get_data_size(&self) -> usize

Get the data size of the pixel buffer

Source

pub fn is_planar(&self) -> bool

Check if the pixel buffer is planar

Source

pub fn get_plane_count(&self) -> usize

Get the number of planes in the pixel buffer

Source

pub fn get_width_of_plane(&self, plane_index: usize) -> usize

Get the width of a specific plane

Source

pub fn get_height_of_plane(&self, plane_index: usize) -> usize

Get the height of a specific plane

Source

pub fn get_base_address_of_plane(&self, plane_index: usize) -> Option<*mut u8>

Get the base address of a specific plane

Source

pub fn get_bytes_per_row_of_plane(&self, plane_index: usize) -> usize

Get the bytes per row of a specific plane

Source

pub fn get_extended_pixels(&self) -> (usize, usize, usize, usize)

Get the extended pixel information (left, right, top, bottom)

Source

pub fn is_backed_by_io_surface(&self) -> bool

Check if the pixel buffer is backed by an IOSurface

Source

pub fn get_width(&self) -> usize

Source

pub fn get_height(&self) -> usize

Source

pub fn get_pixel_format_type(&self) -> u32

Source

pub fn get_bytes_per_row(&self) -> usize

Source

pub fn get_base_address(&self) -> Option<*mut u8>

Source

pub fn get_iosurface(&self) -> Option<IOSurface>

Source

pub fn width(&self) -> usize

Source

pub fn height(&self) -> usize

Source

pub fn pixel_format(&self) -> u32

Source

pub fn bytes_per_row(&self) -> usize

Source

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.

Source

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.

Source

pub fn base_address(&self) -> Option<*mut u8>

Source

pub fn get_io_surface(&self) -> Option<IOSurface>

Source

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.

Trait Implementations§

Source§

impl CVImageBufferLockExt for CVPixelBuffer

Source§

fn lock( &self, flags: PixelBufferLockFlags, ) -> Result<PixelBufferLockGuard<'_>, SCError>

Lock the buffer and provide a guard for safe access Read more
Source§

impl CVPixelBufferIOSurface for CVPixelBuffer

Source§

fn iosurface(&self) -> Option<IOSurface>

Get the underlying IOSurface if the pixel buffer is backed by one
Source§

fn is_backed_by_iosurface(&self) -> bool

Check if this pixel buffer is backed by an IOSurface
Source§

impl Clone for CVPixelBuffer

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Display for CVPixelBuffer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for CVPixelBuffer

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Hash for CVPixelBuffer

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for CVPixelBuffer

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for CVPixelBuffer

Source§

impl Send for CVPixelBuffer

Source§

impl Sync for CVPixelBuffer

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.