core_video_sys/
pixel_buffer.rs1use core_foundation_sys::{
2 array::CFArrayRef,
3 base::{Boolean, CFAllocatorRef, CFTypeID},
4 dictionary::CFDictionaryRef,
5 string::CFStringRef,
6};
7use libc::{c_void, size_t};
8
9use crate::{base::CVOptionFlags, image_buffer::CVImageBufferRef, return_::CVReturn, OSType};
10
11const fn as_u32_be(array: &[u8; 4]) -> u32 {
12 ((array[0] as u32) << 24)
13 + ((array[1] as u32) << 16)
14 + ((array[2] as u32) << 8)
15 + ((array[3] as u32) << 0)
16}
17
18pub type CVPixelBufferLockFlags = u64;
19pub type CVPixelBufferRef = CVImageBufferRef;
20
21pub const kCVPixelFormatType_1Monochrome: OSType = 0x00000001; pub const kCVPixelFormatType_2Indexed: OSType = 0x00000002; pub const kCVPixelFormatType_4Indexed: OSType = 0x00000004; pub const kCVPixelFormatType_8Indexed: OSType = 0x00000008; pub const kCVPixelFormatType_1IndexedGray_WhiteIsZero: OSType = 0x00000021; pub const kCVPixelFormatType_2IndexedGray_WhiteIsZero: OSType = 0x00000022; pub const kCVPixelFormatType_4IndexedGray_WhiteIsZero: OSType = 0x00000024; pub const kCVPixelFormatType_8IndexedGray_WhiteIsZero: OSType = 0x00000028; pub const kCVPixelFormatType_16BE555: OSType = 0x00000010; pub const kCVPixelFormatType_16LE555: OSType = as_u32_be(b"L555"); pub const kCVPixelFormatType_16LE5551: OSType = as_u32_be(b"5551"); pub const kCVPixelFormatType_16BE565: OSType = as_u32_be(b"B565"); pub const kCVPixelFormatType_16LE565: OSType = as_u32_be(b"L565"); pub const kCVPixelFormatType_24RGB: OSType = 0x00000018; pub const kCVPixelFormatType_24BGR: OSType = as_u32_be(b"24BG"); pub const kCVPixelFormatType_32ARGB: OSType = 0x00000020; pub const kCVPixelFormatType_32BGRA: OSType = as_u32_be(b"BGRA"); pub const kCVPixelFormatType_32ABGR: OSType = as_u32_be(b"ABGR"); pub const kCVPixelFormatType_32RGBA: OSType = as_u32_be(b"RGBA"); pub const kCVPixelFormatType_64ARGB: OSType = as_u32_be(b"b64a"); pub const kCVPixelFormatType_48RGB: OSType = as_u32_be(b"b48r"); pub const kCVPixelFormatType_32AlphaGray: OSType = as_u32_be(b"b32a"); pub const kCVPixelFormatType_16Gray: OSType = as_u32_be(b"b16g"); pub const kCVPixelFormatType_30RGB: OSType = as_u32_be(b"R10k"); pub const kCVPixelFormatType_422YpCbCr8: OSType = as_u32_be(b"2vuy"); pub const kCVPixelFormatType_4444YpCbCrA8: OSType = as_u32_be(b"v408"); pub const kCVPixelFormatType_4444YpCbCrA8R: OSType = as_u32_be(b"r408"); pub const kCVPixelFormatType_4444AYpCbCr8: OSType = as_u32_be(b"y408"); pub const kCVPixelFormatType_4444AYpCbCr16: OSType = as_u32_be(b"y416"); pub const kCVPixelFormatType_444YpCbCr8: OSType = as_u32_be(b"v308"); pub const kCVPixelFormatType_422YpCbCr16: OSType = as_u32_be(b"v216"); pub const kCVPixelFormatType_422YpCbCr10: OSType = as_u32_be(b"v210"); pub const kCVPixelFormatType_444YpCbCr10: OSType = as_u32_be(b"v410"); pub const kCVPixelFormatType_420YpCbCr8Planar: OSType = as_u32_be(b"y420"); pub const kCVPixelFormatType_420YpCbCr8PlanarFullRange: OSType = as_u32_be(b"f420"); pub const kCVPixelFormatType_422YpCbCr_4A_8BiPlanar: OSType = as_u32_be(b"a2vy"); pub const kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange: OSType = as_u32_be(b"420v"); pub const kCVPixelFormatType_420YpCbCr8BiPlanarFullRange: OSType = as_u32_be(b"420f"); pub const kCVPixelFormatType_422YpCbCr8_yuvs: OSType = as_u32_be(b"yuvs"); pub const kCVPixelFormatType_422YpCbCr8FullRange: OSType = as_u32_be(b"yuvf"); pub const kCVPixelFormatType_OneComponent8: OSType = as_u32_be(b"L008"); pub const kCVPixelFormatType_TwoComponent8: OSType = as_u32_be(b"2C08"); pub const kCVPixelFormatType_30RGBLEPackedWideGamut: OSType = as_u32_be(b"w30r"); pub const kCVPixelFormatType_ARGB2101010LEPacked: OSType = as_u32_be(b"l10r"); pub const kCVPixelFormatType_OneComponent16Half: OSType = as_u32_be(b"L00h"); pub const kCVPixelFormatType_OneComponent32Float: OSType = as_u32_be(b"L00f"); pub const kCVPixelFormatType_TwoComponent16Half: OSType = as_u32_be(b"2C0h"); pub const kCVPixelFormatType_TwoComponent32Float: OSType = as_u32_be(b"2C0f"); pub const kCVPixelFormatType_64RGBAHalf: OSType = as_u32_be(b"RGhA"); pub const kCVPixelFormatType_128RGBAFloat: OSType = as_u32_be(b"RGfA"); pub const kCVPixelFormatType_14Bayer_GRBG: OSType = as_u32_be(b"grb4"); pub const kCVPixelFormatType_14Bayer_RGGB: OSType = as_u32_be(b"rgg4"); pub const kCVPixelFormatType_14Bayer_BGGR: OSType = as_u32_be(b"bgg4"); pub const kCVPixelFormatType_14Bayer_GBRG: OSType = as_u32_be(b"gbr4"); pub const kCVPixelFormatType_DisparityFloat16: OSType = as_u32_be(b"hdis"); pub const kCVPixelFormatType_DisparityFloat32: OSType = as_u32_be(b"fdis"); pub const kCVPixelFormatType_DepthFloat16: OSType = as_u32_be(b"hdep"); pub const kCVPixelFormatType_DepthFloat32: OSType = as_u32_be(b"fdep"); pub const kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange: OSType = as_u32_be(b"x420"); pub const kCVPixelFormatType_422YpCbCr10BiPlanarVideoRange: OSType = as_u32_be(b"x422"); pub const kCVPixelFormatType_444YpCbCr10BiPlanarVideoRange: OSType = as_u32_be(b"x444"); pub const kCVPixelFormatType_420YpCbCr10BiPlanarFullRange: OSType = as_u32_be(b"xf20"); pub const kCVPixelFormatType_422YpCbCr10BiPlanarFullRange: OSType = as_u32_be(b"xf22"); pub const kCVPixelFormatType_444YpCbCr10BiPlanarFullRange: OSType = as_u32_be(b"xf44"); pub const kCVPixelBufferLock_ReadOnly: CVPixelBufferLockFlags = 1;
87
88#[repr(C)]
89#[derive(Debug, Clone, Copy)]
90pub struct CVPlanarComponentInfo {
91 pub offset: i32,
93 pub rowBytes: u32,
95}
96
97#[repr(C)]
98#[derive(Debug, Clone, Copy)]
99pub struct CVPlanarPixelBufferInfo {
100 pub componentInfo: [CVPlanarComponentInfo; 1],
101}
102
103#[repr(C)]
104#[derive(Debug, Clone, Copy)]
105pub struct CVPlanarPixelBufferInfo_YCbCrPlanar {
106 pub componentInfoY: CVPlanarComponentInfo,
107 pub componentInfoCb: CVPlanarComponentInfo,
108 pub componentInfoCr: CVPlanarComponentInfo,
109}
110
111#[repr(C)]
112#[derive(Debug, Clone, Copy)]
113pub struct CVPlanarPixelBufferInfo_YCbCrBiPlanar {
114 pub componentInfoY: CVPlanarComponentInfo,
115 pub componentInfoCbCr: CVPlanarComponentInfo,
116}
117
118pub type CVPixelBufferReleaseBytesCallback =
119 extern "C" fn(releaseRefCon: *mut c_void, baseAddress: *const *const c_void);
120pub type CVPixelBufferReleasePlanarBytesCallback = extern "C" fn(
121 releaseRefCon: *mut c_void,
122 dataPtr: *const *const c_void,
123 dataSize: size_t,
124 numberOfPlanes: size_t,
125 planeAddresses: *const *const c_void,
126);
127
128extern "C" {
129 pub static kCVPixelBufferPixelFormatTypeKey: CFStringRef;
130 pub static kCVPixelBufferMemoryAllocatorKey: CFStringRef;
131 pub static kCVPixelBufferWidthKey: CFStringRef;
132 pub static kCVPixelBufferHeightKey: CFStringRef;
133 pub static kCVPixelBufferExtendedPixelsLeftKey: CFStringRef;
134 pub static kCVPixelBufferExtendedPixelsTopKey: CFStringRef;
135 pub static kCVPixelBufferExtendedPixelsRightKey: CFStringRef;
136 pub static kCVPixelBufferExtendedPixelsBottomKey: CFStringRef;
137 pub static kCVPixelBufferBytesPerRowAlignmentKey: CFStringRef;
138 pub static kCVPixelBufferCGBitmapContextCompatibilityKey: CFStringRef;
139 pub static kCVPixelBufferCGImageCompatibilityKey: CFStringRef;
140 pub static kCVPixelBufferOpenGLCompatibilityKey: CFStringRef;
141 pub static kCVPixelBufferPlaneAlignmentKey: CFStringRef;
142 pub static kCVPixelBufferIOSurfacePropertiesKey: CFStringRef;
143 pub static kCVPixelBufferOpenGLESCompatibilityKey: CFStringRef;
144 pub static kCVPixelBufferMetalCompatibilityKey: CFStringRef;
145 pub static kCVPixelBufferOpenGLTextureCacheCompatibilityKey: CFStringRef;
146 pub static kCVPixelBufferOpenGLESTextureCacheCompatibilityKey: CFStringRef;
147
148 pub fn CVBufferGetTypeID() -> CFTypeID;
149 pub fn CVPixelBufferRetain(texture: CVPixelBufferRef) -> CVPixelBufferRef;
150 pub fn CVPixelBufferRelease(texture: CVPixelBufferRef);
151 pub fn CVPixelBufferCreateResolvedAttributesDictionary(
152 allocator: CFAllocatorRef,
153 attributes: CFArrayRef,
154 resolvedDictionaryOut: *mut CFDictionaryRef,
155 ) -> CVReturn;
156 pub fn CVPixelBufferCreate(
157 allocator: CFAllocatorRef,
158 width: size_t,
159 height: size_t,
160 pixelFormatType: OSType,
161 pixelBufferAttributes: CFDictionaryRef,
162 pixelBufferOut: *mut CVPixelBufferRef,
163 ) -> CVReturn;
164 pub fn CVPixelBufferLockBaseAddress(
185 pixelBuffer: CVPixelBufferRef,
186 lockFlags: CVOptionFlags,
187 ) -> CVReturn;
188 pub fn CVPixelBufferUnlockBaseAddress(
189 pixelBuffer: CVPixelBufferRef,
190 unlockFlags: CVOptionFlags,
191 ) -> CVReturn;
192 pub fn CVPixelBufferGetWidth(pixelBuffer: CVPixelBufferRef) -> size_t;
193 pub fn CVPixelBufferGetHeight(pixelBuffer: CVPixelBufferRef) -> size_t;
194 pub fn CVPixelBufferGetPixelFormatType(pixelBuffer: CVPixelBufferRef) -> OSType;
195
196 pub fn CVPixelBufferGetBaseAddress(pixelBuffer: CVPixelBufferRef) -> *mut c_void;
197 pub fn CVPixelBufferGetBytesPerRow(pixelBuffer: CVPixelBufferRef) -> size_t;
198 pub fn CVPixelBufferIsPlanar(pixelBuffer: CVPixelBufferRef) -> Boolean;
199 pub fn CVPixelBufferGetPlaneCount(pixelBuffer: CVPixelBufferRef) -> size_t;
200 pub fn CVPixelBufferGetWidthOfPlane(
201 pixelBuffer: CVPixelBufferRef,
202 planeIndex: size_t,
203 ) -> size_t;
204 pub fn CVPixelBufferGetHeightOfPlane(
205 pixelBuffer: CVPixelBufferRef,
206 planeIndex: size_t,
207 ) -> size_t;
208 pub fn CVPixelBufferGetBaseAddressOfPlane(
209 pixelBuffer: CVPixelBufferRef,
210 planeIndex: size_t,
211 ) -> *mut c_void;
212 pub fn CVPixelBufferGetBytesPerRowOfPlane(
213 pixelBuffer: CVPixelBufferRef,
214 planeIndex: size_t,
215 ) -> size_t;
216
217 pub fn CVPixelBufferGetExtendedPixels(
218 pixelBuffer: CVPixelBufferRef,
219 extraColumnsOnLeft: *const size_t,
220 extraColumnsOnRight: *const size_t,
221 extraRowsOnTop: *const size_t,
222 extraRowsOnBottom: *const size_t,
223 );
224 pub fn CVPixelBufferFillExtendedPixels(pixelBuffer: CVPixelBufferRef) -> CVReturn;
225}