use std::ffi::c_void;
use crate::{arc, cf, cv, define_opts, four_cc_fmt_debug, os};
#[cfg(feature = "io_surface")]
use crate::io;
#[cfg(feature = "ns")]
use crate::ns;
#[doc(alias = "CVPixelBuffer")]
pub type PixelBuf = cv::ImageBuf;
pub type ReleaseCallback =
extern "C" fn(release_ref_con: *mut c_void, base_address: *const *const c_void);
impl PixelBuf {
#[doc(alias = "CVPixelBufferGetTypeID")]
#[inline]
pub fn type_id() -> cf::TypeId {
unsafe { CVPixelBufferGetTypeID() }
}
#[doc(alias = "CVPixelBufferGetWidth")]
#[inline]
pub fn width(&self) -> usize {
unsafe { CVPixelBufferGetWidth(self) }
}
#[doc(alias = "CVPixelBufferGetHeight")]
#[inline]
pub fn height(&self) -> usize {
unsafe { CVPixelBufferGetHeight(self) }
}
#[doc(alias = "CVPixelBufferGetPixelFormatType")]
#[inline]
pub fn pixel_format(&self) -> PixelFormat {
unsafe { CVPixelBufferGetPixelFormatType(self) }
}
#[doc(alias = "CVPixelBufferGetPlaneCount")]
#[inline]
pub fn plane_count(&self) -> usize {
unsafe { CVPixelBufferGetPlaneCount(self) }
}
#[doc(alias = "CVPixelBufferGetWidthOfPlane")]
#[inline]
pub fn plane_width(&self, plane_index: usize) -> usize {
unsafe { CVPixelBufferGetWidthOfPlane(self, plane_index) }
}
#[doc(alias = "CVPixelBufferGetHeightOfPlane")]
#[inline]
pub fn plane_height(&self, plane_index: usize) -> usize {
unsafe { CVPixelBufferGetHeightOfPlane(self, plane_index) }
}
#[doc(alias = "CVPixelBufferGetBaseAddressOfPlane")]
#[inline]
pub fn plane_base_address(&self, plane_index: usize) -> *const u8 {
unsafe { CVPixelBufferGetBaseAddressOfPlane(self, plane_index) }
}
#[doc(alias = "CVPixelBufferGetBytesPerRowOfPlane")]
#[inline]
pub fn plane_bytes_per_row(&self, plane_index: usize) -> usize {
unsafe { CVPixelBufferGetBytesPerRowOfPlane(self, plane_index) }
}
pub fn new(
width: usize,
height: usize,
pixel_format_type: cv::PixelFormat,
pixel_buf_attrs: Option<&cf::Dictionary>,
) -> os::Result<arc::R<PixelBuf>> {
unsafe {
os::result_unchecked(|res| {
Self::create_in(width, height, pixel_format_type, pixel_buf_attrs, res, None)
})
}
}
#[doc(alias = "CVPixelBufferCreateWithBytes")]
pub fn with_bytes(
width: usize,
height: usize,
base_address: *mut c_void,
bytes_per_row: usize,
release_callback: ReleaseCallback,
release_ref_con: *mut c_void,
pixel_format_type: cv::PixelFormat,
pixel_buf_attrs: Option<&cf::Dictionary>,
) -> os::Result<arc::R<PixelBuf>> {
unsafe {
os::result_unchecked(|res| {
Self::create_with_bytes_in(
width,
height,
pixel_format_type,
base_address,
bytes_per_row,
release_callback,
release_ref_con,
pixel_buf_attrs,
res,
None,
)
})
}
}
pub fn create_in(
width: usize,
height: usize,
pixel_format_type: cv::PixelFormat,
pixel_buf_attrs: Option<&cf::Dictionary>,
pixel_buf_out: *mut Option<arc::R<PixelBuf>>,
allocator: Option<&cf::Allocator>,
) -> cv::Return {
unsafe {
CVPixelBufferCreate(
allocator,
width,
height,
pixel_format_type,
pixel_buf_attrs,
pixel_buf_out,
)
}
}
#[doc(alias = "CVPixelBufferCreateWithBytes")]
pub fn create_with_bytes_in(
width: usize,
height: usize,
pixel_format_type: cv::PixelFormat,
base_address: *mut c_void,
bytes_per_row: usize,
release_callback: ReleaseCallback,
release_ref_con: *mut c_void,
pixel_buf_attrs: Option<&cf::Dictionary>,
pixel_buf_out: *mut Option<arc::R<PixelBuf>>,
allocator: Option<&cf::Allocator>,
) -> cv::Return {
unsafe {
CVPixelBufferCreateWithBytes(
allocator,
width,
height,
pixel_format_type,
base_address,
bytes_per_row,
release_callback,
release_ref_con,
pixel_buf_attrs,
pixel_buf_out,
)
}
}
#[doc(alias = "CVPixelBufferLockBaseAddress")]
#[inline]
pub unsafe fn lock_base_addr(&mut self, flags: LockFlags) -> cv::Return {
unsafe { CVPixelBufferLockBaseAddress(self, flags) }
}
#[doc(alias = "CVPixelBufferUnlockBaseAddress")]
#[inline]
pub unsafe fn unlock_lock_base_addr(&mut self, flags: LockFlags) -> cv::Return {
unsafe { CVPixelBufferUnlockBaseAddress(self, flags) }
}
#[inline]
pub fn base_address_lock(&mut self, flags: LockFlags) -> os::Result<BaseAddrLockGuard> {
unsafe {
self.lock_base_addr(flags).result()?;
Ok(BaseAddrLockGuard(self, flags))
}
}
#[cfg(feature = "io_surface")]
#[inline]
pub fn io_surf(&self) -> Option<&io::Surf> {
unsafe { CVPixelBufferGetIOSurface(self) }
}
#[cfg(feature = "io_surface")]
#[inline]
pub fn io_surf_mut(&mut self) -> Option<&mut io::Surf> {
unsafe { std::mem::transmute(CVPixelBufferGetIOSurface(self)) }
}
#[cfg(feature = "io_surface")]
#[inline]
pub fn with_io_surf(
surface: &io::Surf,
pixel_buffer_attributes: Option<&cf::Dictionary>,
) -> os::Result<arc::R<Self>> {
Self::with_io_surf_in(surface, pixel_buffer_attributes, None)
}
#[cfg(feature = "io_surface")]
#[inline]
pub fn with_io_surf_in(
surface: &io::Surf,
pixel_buf_attrs: Option<&cf::Dictionary>,
allocator: Option<&cf::Allocator>,
) -> os::Result<arc::R<Self>> {
unsafe {
os::result_unchecked(|res| {
CVPixelBufferCreateWithIOSurface(allocator, surface, pixel_buf_attrs, res)
})
}
}
}
pub struct BaseAddrLockGuard<'a>(&'a mut PixelBuf, LockFlags);
impl<'a> Drop for BaseAddrLockGuard<'a> {
#[inline]
fn drop(&mut self) {
let flags = self.1;
let res = unsafe { self.0.unlock_lock_base_addr(flags) };
debug_assert!(res.is_ok());
}
}
define_opts!(pub LockFlags(cv::OptionFlags));
impl LockFlags {
pub const DEFAULT: Self = Self(0);
pub const READ_ONLY: Self = Self(1);
}
#[doc(alias = "CVPixelFormatType")]
#[derive(Clone, Copy, PartialEq, Eq)]
#[repr(transparent)]
pub struct PixelFormat(pub os::Type);
impl PixelFormat {
#[doc(alias = "kCVPixelFormatType_1Monochrome")]
pub const _1_MONOCHROME: Self = Self(0x00000001);
#[doc(alias = "kCVPixelFormatType_2Indexed")]
pub const _2_INDEXED: Self = Self(0x00000002);
#[doc(alias = "kCVPixelFormatType_4Indexed")]
pub const _4_INDEXED: Self = Self(0x00000004);
#[doc(alias = "kCVPixelFormatType_8Indexed")]
pub const _8_INDEXED: Self = Self(0x00000008);
#[doc(alias = "kCVPixelFormatType_1IndexedGray_WhiteIsZero")]
pub const _1_INDEXED_GREY_WHITE_IS_ZERO: Self = Self(0x000000021);
#[doc(alias = "kCVPixelFormatType_2IndexedGray_WhiteIsZero")]
pub const _2_INDEXED_GREY_WHITE_IS_ZERO: Self = Self(0x000000022);
#[doc(alias = "kCVPixelFormatType_4IndexedGray_WhiteIsZero")]
pub const _4_INDEXED_GREY_WHITE_IS_ZERO: Self = Self(0x000000024);
#[doc(alias = "kCMPixelFormat_8IndexedGray_WhiteIsZero")]
#[doc(alias = "kCVPixelFormatType_8IndexedGray_WhiteIsZero")]
pub const _8_INDEXED_GREY_WHITE_IS_ZERO: Self = Self(0x000000028);
#[doc(alias = "kCVPixelFormatType_16BE555")]
pub const _16_BE_555: Self = Self(0x00000010);
#[doc(alias = "kCVPixelFormatType_16LE555")]
pub const _16_LE_555: Self = Self(os::Type::from_be_bytes(*b"L555"));
#[doc(alias = "kCVPixelFormatType_16LE5551")]
pub const _16_LE_5551: Self = Self(os::Type::from_be_bytes(*b"5551"));
#[doc(alias = "kCVPixelFormatType_16BE565")]
pub const _16_BE_565: Self = Self(os::Type::from_be_bytes(*b"B565"));
#[doc(alias = "kCVPixelFormatType_16LE565")]
pub const _16_LE_565: Self = Self(os::Type::from_be_bytes(*b"L565"));
#[doc(alias = "kCVPixelFormatType_24RGB")]
pub const _24_RGB: Self = Self(0x00000018);
#[doc(alias = "kCVPixelFormatType_24BGR")]
pub const _24_BGR: Self = Self(os::Type::from_be_bytes(*b"24BG"));
#[doc(alias = "kCVPixelFormatType_32ARGB")]
pub const _32_ARGB: Self = Self(0x00000020);
#[doc(alias = "kCMPixelFormat_32BGRA")]
#[doc(alias = "kCVPixelFormatType_32BGRA")]
pub const _32_BGRA: Self = Self(os::Type::from_be_bytes(*b"BGRA"));
#[doc(alias = "kCVPixelFormatType_32ABGR")]
pub const _32_ABGR: Self = Self(os::Type::from_be_bytes(*b"ABGR"));
#[doc(alias = "kCVPixelFormatType_32RGBA")]
pub const _32_RGBA: Self = Self(os::Type::from_be_bytes(*b"RGBA"));
#[doc(alias = "kCVPixelFormatType_64ARGB")]
pub const _64_ARGB: Self = Self(os::Type::from_be_bytes(*b"b64a"));
#[doc(alias = "kCVPixelFormatType_64RGBALE")]
pub const _64_RGBALE: Self = Self(os::Type::from_be_bytes(*b"l64r"));
#[doc(alias = "kCVPixelFormatType_30RGB")]
pub const _30_RGB: Self = Self(os::Type::from_be_bytes(*b"R10k"));
#[doc(alias = "kCVPixelFormatType_30RGB_r210")]
pub const _30_RGB_R210: Self = Self(os::Type::from_be_bytes(*b"r210"));
#[doc(alias = "kCVPixelFormatType_422YpCbCr8")]
pub const _422_YP_CB_CR_8: Self = Self(os::Type::from_be_bytes(*b"2vuy"));
#[doc(alias = "kCVPixelFormatType_422YpCbCr8")]
pub const _2VUY: Self = Self::_422_YP_CB_CR_8;
#[doc(alias = "kCVPixelFormatType_4444YpCbCrA8")]
pub const _4444_YP_CB_CR_A_8: Self = Self(os::Type::from_be_bytes(*b"v408"));
#[doc(alias = "kCVPixelFormatType_4444YpCbCrA8R")]
pub const _4444_YP_CB_CR_A_8_R: Self = Self(os::Type::from_be_bytes(*b"r408"));
#[doc(alias = "kCVPixelFormatType_4444AYpCbCr8")]
pub const _4444_A_YP_CB_CR_8: Self = Self(os::Type::from_be_bytes(*b"y408"));
#[doc(alias = "kCVPixelFormatType_4444AYpCbCr16")]
pub const _4444_A_YP_CB_CR_16: Self = Self(os::Type::from_be_bytes(*b"y416"));
#[doc(alias = "kCVPixelFormatType_4444AYpCbCrFloat")]
pub const _4444_A_YP_CB_CR_FLOAT: Self = Self(os::Type::from_be_bytes(*b"r4fl"));
#[doc(alias = "kCVPixelFormatType_444YpCbCr8")]
pub const _444_YP_CB_CR_8: Self = Self(os::Type::from_be_bytes(*b"v308"));
#[doc(alias = "kCVPixelFormatType_422YpCbCr16")]
pub const _422_YP_CB_CR_16: Self = Self(os::Type::from_be_bytes(*b"v216"));
#[doc(alias = "kCVPixelFormatType_422YpCbCr10")]
pub const _422_YP_CB_CR_10: Self = Self(os::Type::from_be_bytes(*b"v210"));
#[doc(alias = "kCVPixelFormatType_444YpCbCr10")]
pub const _444_YP_CB_CR_10: Self = Self(os::Type::from_be_bytes(*b"v410"));
#[doc(alias = "kCVPixelFormatType_420YpCbCr8PlanarFullRange")]
pub const _420_YP_CB_CR_8_PLANAR_FULL_RANGE: Self = Self(os::Type::from_be_bytes(*b"f420"));
#[doc(alias = "kCVPixelFormatType_422YpCbCr_4A_8BiPlanar")]
pub const _422_YP_CB_CR_4_A_8_BI_PLANAR: Self = Self(os::Type::from_be_bytes(*b"a2vy"));
#[doc(alias = "kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange")]
pub const _420_YP_CB_CR_8_BI_PLANAR_VIDEO_RANGE: Self = Self(os::Type::from_be_bytes(*b"420v"));
#[doc(alias = "kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange")]
pub const _420V: Self = Self::_420_YP_CB_CR_8_BI_PLANAR_VIDEO_RANGE;
#[doc(alias = "kCVPixelFormatType_420YpCbCr8BiPlanarFullRange")]
pub const _420_YP_CB_CR_8_BI_PLANAR_FULL_RANGE: Self = Self(os::Type::from_be_bytes(*b"420f"));
#[doc(alias = "kCVPixelFormatType_420YpCbCr8BiPlanarFullRange")]
pub const _420F: Self = Self::_420_YP_CB_CR_8_BI_PLANAR_FULL_RANGE;
#[doc(alias = "kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange")]
pub const _420_YP_CB_CR_10_BI_PLANAR_VIDEO_RANGE: Self =
Self(os::Type::from_be_bytes(*b"x420"));
#[doc(alias = "kCVPixelFormatType_422YpCbCr10BiPlanarVideoRange")]
pub const _422_YP_CB_CR_10_BI_PLANAR_VIDEO_RANGE: Self =
Self(os::Type::from_be_bytes(*b"x422"));
#[doc(alias = "kCVPixelFormatType_444YpCbCr10BiPlanarVideoRange")]
pub const _444_YP_CB_CR_10_BI_PLANAR_VIDEO_RANGE: Self =
Self(os::Type::from_be_bytes(*b"x444"));
#[doc(alias = "kCVPixelFormatType_420YpCbCr10BiPlanarFullRange")]
pub const _420_YP_CB_CR_10_BI_PLANAR_FULL_RANGE: Self = Self(os::Type::from_be_bytes(*b"xf20"));
#[doc(alias = "kCVPixelFormatType_422YpCbCr10BiPlanarFullRange")]
pub const _422_YP_CB_CR_10_BI_PLANAR_FULL_RANGE: Self = Self(os::Type::from_be_bytes(*b"xf22"));
#[doc(alias = "kCVPixelFormatType_444YpCbCr10BiPlanarFullRange")]
pub const _444_YP_CB_CR_10_BI_PLANAR_FULL_RANGE: Self = Self(os::Type::from_be_bytes(*b"xf44"));
#[doc(alias = "kCVPixelFormatType_ARGB2101010LEPacked")]
pub const ARGB_2101010_LE_PACKED: Self = Self(os::Type::from_be_bytes(*b"l10r"));
#[doc(alias = "kCVPixelFormatType_OneComponent8")]
pub const ONE_COMPONENT_8: Self = Self(os::Type::from_be_bytes(*b"L008"));
#[doc(alias = "kCVPixelFormatType_OneComponent16Half")]
pub const ONE_COMPONENT_H16: Self = Self(os::Type::from_be_bytes(*b"L00h"));
#[doc(alias = "kCVPixelFormatType_OneComponent32Float")]
pub const ONE_COMPONENT_F32: Self = Self(os::Type::from_be_bytes(*b"L00f"));
#[doc(alias = "kCVPixelFormatType_TwoComponent16Half")]
pub const TWO_COMPONENT_H16: Self = Self(os::Type::from_be_bytes(*b"2C0h"));
#[doc(alias = "kCVPixelFormatType_TwoComponent32Float")]
pub const TWO_COMPONENT_F32: Self = Self(os::Type::from_be_bytes(*b"2C0f"));
#[doc(alias = "kCVPixelFormatType_64RGBAHalf")]
pub const _64_RGBA_HALF: Self = Self(os::Type::from_be_bytes(*b"RGhA"));
#[doc(alias = "kCVPixelFormatType_128RGBAFloat")]
pub const _128_RGBA_FLOAT: Self = Self(os::Type::from_be_bytes(*b"RGfA"));
pub fn from_cf_number(number: &cf::Number) -> Self {
Self(number.to_i32().unwrap_or(0) as u32)
}
pub fn to_desc(&self) -> Option<arc::R<cf::Dictionary>> {
cv::pixel_format_desc_create(*self)
}
#[inline]
pub fn to_cf_number(&self) -> &'static cf::Number {
cf::Number::from_four_char_code(self.0)
}
#[cfg(feature = "ns")]
#[inline]
pub fn to_ns_number(&self) -> &'static ns::Number {
cf::Number::from_four_char_code(self.0).as_ns()
}
#[doc(alias = "CVIsCompressedPixelFormatAvailable")]
#[inline]
pub fn is_compressed_avaliable(&self) -> bool {
unsafe { CVIsCompressedPixelFormatAvailable(*self) }
}
}
impl PixelFormat {
#[doc(alias = "kCVPixelFormatType_Lossless_32BGRA")]
pub const LOSSLESS_32_BGRA: Self = Self(os::Type::from_be_bytes(*b"&BGA"));
#[doc(alias = "kCVPixelFormatType_Lossless_64RGBAHalf")]
pub const LOSSLESS_64_RGBA_HALF: Self = Self(os::Type::from_be_bytes(*b"&RhA"));
#[doc(alias = "kCVPixelFormatType_Lossless_420YpCbCr8BiPlanarVideoRange")]
pub const LOSSLESS_420_YP_CB_CR_8_BI_PLANAR_VIDEO_RANGE: Self =
Self(os::Type::from_be_bytes(*b"&8v0"));
#[doc(alias = "kCVPixelFormatType_Lossless_420YpCbCr8BiPlanarVideoRange")]
pub const LOSSLESS_420V: Self = Self::LOSSLESS_420_YP_CB_CR_8_BI_PLANAR_VIDEO_RANGE;
#[doc(alias = "kCVPixelFormatType_Lossless_420YpCbCr8BiPlanarFullRange")]
pub const LOSSLESS_420_YP_CB_CR_8_BI_PLANAR_FULL_RANGE: Self =
Self(os::Type::from_be_bytes(*b"&8f0"));
#[doc(alias = "kCVPixelFormatType_Lossless_420YpCbCr8BiPlanarFullRange")]
pub const LOSSLESS_420F: Self = Self::LOSSLESS_420_YP_CB_CR_8_BI_PLANAR_FULL_RANGE;
#[doc(alias = "kCVPixelFormatType_Lossless_420YpCbCr10PackedBiPlanarVideoRange")]
pub const LOSSLESS_420_YP_CB_CR_10_PACKED_BI_PLANAR_VIDEO_RANGE: Self =
Self(os::Type::from_be_bytes(*b"&xv0"));
#[doc(alias = "kCVPixelFormatType_Lossless_422YpCbCr10PackedBiPlanarVideoRange")]
pub const LOSSLESS_422_YP_CB_CR_10_PACKED_BI_PLANAR_VIDEO_RANGE: Self =
Self(os::Type::from_be_bytes(*b"&xv2"));
}
impl PixelFormat {
#[doc(alias = "kCVPixelFormatType_Lossy_32BGRA")]
pub const LOSSY_32_BGRA: Self = Self(os::Type::from_be_bytes(*b"-BGA"));
#[doc(alias = "kCVPixelFormatType_Lossy_420YpCbCr8BiPlanarVideoRange")]
pub const LOSSY_420_YP_CB_CR_8_BI_PLANAR_VIDEO_RANGE: Self =
Self(os::Type::from_be_bytes(*b"-8v0"));
#[doc(alias = "kCVPixelFormatType_Lossy_420YpCbCr8BiPlanarVideoRange")]
pub const LOSSY_420V: Self = Self::LOSSY_420_YP_CB_CR_8_BI_PLANAR_VIDEO_RANGE;
#[doc(alias = "kCVPixelFormatType_Lossy_420YpCbCr8BiPlanarFullRange")]
pub const LOSSY_420_YP_CB_CR_8_BI_PLANAR_FULL_RANGE: Self =
Self(os::Type::from_be_bytes(*b"-8f0"));
#[doc(alias = "kCVPixelFormatType_Lossy_420YpCbCr8BiPlanarFullRange")]
pub const LOSSY_420F: Self = Self::LOSSY_420_YP_CB_CR_8_BI_PLANAR_FULL_RANGE;
#[doc(alias = "kCVPixelFormatType_Lossy_420YpCbCr10PackedBiPlanarVideoRange")]
pub const LOSSY_420_YP_CB_CR_10_PACKED_BI_PLANAR_VIDEO_RANGE: Self =
Self(os::Type::from_be_bytes(*b"-xv0"));
#[doc(alias = "kCVPixelFormatType_Lossy_422YpCbCr10PackedBiPlanarVideoRange")]
pub const LOSSY_422_YP_CB_CR_10_PACKED_BI_PLANAR_VIDEO_RANGE: Self =
Self(os::Type::from_be_bytes(*b"-xv2"));
}
impl std::fmt::Debug for PixelFormat {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
four_cc_fmt_debug(self.0, "cv::PixelFormat", f)
}
}
impl AsRef<cf::Type> for PixelFormat {
fn as_ref(&self) -> &'static cf::Type {
self.to_cf_number().as_type_ref()
}
}
#[cfg(feature = "ns")]
impl AsRef<ns::Id> for PixelFormat {
fn as_ref(&self) -> &'static ns::Id {
self.to_ns_number().as_id_ref()
}
}
#[link(name = "CoreVideo", kind = "framework")]
unsafe extern "C-unwind" {
fn CVPixelBufferGetTypeID() -> cf::TypeId;
fn CVPixelBufferCreate(
allocator: Option<&cf::Allocator>,
width: usize,
height: usize,
pixel_format_type: PixelFormat,
pixel_buf_attrs: Option<&cf::Dictionary>,
pixel_buf_out: *mut Option<arc::R<PixelBuf>>,
) -> cv::Return;
fn CVPixelBufferCreateWithBytes(
allocator: Option<&cf::Allocator>,
width: usize,
height: usize,
pixel_format_type: PixelFormat,
base_address: *mut c_void,
bytes_per_row: usize,
release_callback: ReleaseCallback,
release_ref_con: *mut c_void,
pixel_buf_attrs: Option<&cf::Dictionary>,
pixel_buf_out: *mut Option<arc::R<PixelBuf>>,
) -> cv::Return;
fn CVPixelBufferGetWidth(pixel_buffer: &PixelBuf) -> usize;
fn CVPixelBufferGetHeight(pixel_buffer: &PixelBuf) -> usize;
fn CVPixelBufferGetPixelFormatType(pixel_buffer: &PixelBuf) -> PixelFormat;
fn CVPixelBufferGetPlaneCount(pixel_buffer: &PixelBuf) -> usize;
fn CVPixelBufferGetWidthOfPlane(pixel_buffer: &PixelBuf, plane_index: usize) -> usize;
fn CVPixelBufferGetHeightOfPlane(pixel_buffer: &PixelBuf, plane_index: usize) -> usize;
fn CVPixelBufferGetBaseAddressOfPlane(pixel_buffer: &PixelBuf, plane_index: usize)
-> *const u8;
fn CVPixelBufferGetBytesPerRowOfPlane(pixel_buffer: &PixelBuf, plane_index: usize) -> usize;
fn CVPixelBufferLockBaseAddress(
pixel_buffer: &mut PixelBuf,
lock_flags: LockFlags,
) -> cv::Return;
fn CVPixelBufferUnlockBaseAddress(
pixel_buffer: &mut PixelBuf,
lock_flags: LockFlags,
) -> cv::Return;
#[cfg(feature = "io_surface")]
fn CVPixelBufferGetIOSurface(pixel_buffer: &PixelBuf) -> Option<&io::Surf>;
#[cfg(feature = "io_surface")]
fn CVPixelBufferCreateWithIOSurface(
allocator: Option<&cf::Allocator>,
surface: &io::Surf,
pixel_buffer_attributes: Option<&cf::Dictionary>,
pixel_buffer_out: *mut Option<arc::R<cv::PixelBuf>>,
) -> cv::Return;
fn CVIsCompressedPixelFormatAvailable(pixel_format: PixelFormat) -> bool;
}
pub mod keys {
use crate::cf;
#[doc(alias = "kCVPixelBufferPixelFormatTypeKey")]
#[inline]
pub fn pixel_format() -> &'static cf::String {
unsafe { kCVPixelBufferPixelFormatTypeKey }
}
#[doc(alias = "kCVPixelBufferWidthKey")]
#[inline]
pub fn width() -> &'static cf::String {
unsafe { kCVPixelBufferWidthKey }
}
#[doc(alias = "kCVPixelBufferHeightKey")]
#[inline]
pub fn height() -> &'static cf::String {
unsafe { kCVPixelBufferHeightKey }
}
#[doc(alias = "kCVPixelBufferIOSurfacePropertiesKey")]
#[inline]
pub fn io_surf_props() -> &'static cf::String {
unsafe { kCVPixelBufferIOSurfacePropertiesKey }
}
#[doc(alias = "kCVPixelBufferMetalCompatibilityKey")]
#[inline]
pub fn metal_compatability() -> &'static cf::String {
unsafe { kCVPixelBufferMetalCompatibilityKey }
}
#[doc(alias = "kCVPixelBufferPlaneAlignmentKey")]
#[inline]
pub fn plane_aligment() -> &'static cf::String {
unsafe { kCVPixelBufferPlaneAlignmentKey }
}
#[doc(alias = "kCVPixelBufferExtendedPixelsBottomKey")]
#[inline]
pub fn extended_pixels_bottom() -> &'static cf::String {
unsafe { kCVPixelBufferExtendedPixelsBottomKey }
}
#[doc(alias = "kCVPixelBufferCGImageCompatibilityKey")]
#[inline]
pub fn cg_image_comaptibility() -> &'static cf::String {
unsafe { kCVPixelBufferCGImageCompatibilityKey }
}
unsafe extern "C" {
static kCVPixelBufferPixelFormatTypeKey: &'static cf::String;
static kCVPixelBufferWidthKey: &'static cf::String;
static kCVPixelBufferHeightKey: &'static cf::String;
static kCVPixelBufferIOSurfacePropertiesKey: &'static cf::String;
static kCVPixelBufferMetalCompatibilityKey: &'static cf::String;
static kCVPixelBufferPlaneAlignmentKey: &'static cf::String;
static kCVPixelBufferExtendedPixelsBottomKey: &'static cf::String;
static kCVPixelBufferCGImageCompatibilityKey: &'static cf::String;
}
}
#[cfg(test)]
mod tests {
use crate::{cv::PixelFormat, objc::Obj};
#[test]
fn basics() {
let number = PixelFormat::_1_MONOCHROME.to_cf_number();
assert!(number.is_tagged_ptr());
number.show();
let number = PixelFormat::_420V.to_ns_number();
assert!(number.is_tagged_ptr());
}
#[test]
fn compressed() {
assert!(PixelFormat::LOSSY_32_BGRA.is_compressed_avaliable());
assert!(PixelFormat::LOSSY_420V.is_compressed_avaliable());
assert!(PixelFormat::LOSSY_420F.is_compressed_avaliable());
assert!(
PixelFormat::LOSSY_420_YP_CB_CR_10_PACKED_BI_PLANAR_VIDEO_RANGE
.is_compressed_avaliable()
);
assert!(PixelFormat::LOSSLESS_32_BGRA.is_compressed_avaliable());
assert!(PixelFormat::LOSSLESS_420V.is_compressed_avaliable());
assert!(PixelFormat::LOSSLESS_420F.is_compressed_avaliable());
assert!(
PixelFormat::LOSSLESS_420_YP_CB_CR_10_PACKED_BI_PLANAR_VIDEO_RANGE
.is_compressed_avaliable()
);
assert!(
PixelFormat::LOSSLESS_422_YP_CB_CR_10_PACKED_BI_PLANAR_VIDEO_RANGE
.is_compressed_avaliable()
);
}
}