objc2_core_graphics/generated/
CGBitmapContext.rs1use core::ffi::*;
4use core::ptr::NonNull;
5#[cfg(feature = "objc2")]
6use objc2::__framework_prelude::*;
7use objc2_core_foundation::*;
8
9use crate::*;
10
11pub type CGBitmapContextReleaseDataCallback =
13 Option<unsafe extern "C-unwind" fn(*mut c_void, *mut c_void)>;
14
15#[repr(transparent)]
18#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
19pub struct CGColorModel(pub u32);
20bitflags::bitflags! {
21 impl CGColorModel: u32 {
22 #[doc(alias = "kCGColorModelNoColorant")]
23 const NoColorant = 0<<0;
24 #[doc(alias = "kCGColorModelGray")]
25 const Gray = 1<<0;
26 #[doc(alias = "kCGColorModelRGB")]
27 const RGB = 1<<1;
28 #[doc(alias = "kCGColorModelCMYK")]
29 const CMYK = 1<<2;
30 #[doc(alias = "kCGColorModelLab")]
31 const Lab = 1<<3;
32 #[doc(alias = "kCGColorModelDeviceN")]
33 const DeviceN = 1<<4;
34 }
35}
36
37#[cfg(feature = "objc2")]
38unsafe impl Encode for CGColorModel {
39 const ENCODING: Encoding = u32::ENCODING;
40}
41
42#[cfg(feature = "objc2")]
43unsafe impl RefEncode for CGColorModel {
44 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
45}
46
47#[repr(transparent)]
50#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
51pub struct CGComponent(pub u32);
52impl CGComponent {
53 #[doc(alias = "kCGComponentUnknown")]
54 pub const Unknown: Self = Self(0);
55 #[doc(alias = "kCGComponentInteger8Bit")]
56 pub const Integer8Bit: Self = Self(1);
57 #[doc(alias = "kCGComponentInteger10Bit")]
58 pub const Integer10Bit: Self = Self(6);
59 #[doc(alias = "kCGComponentInteger16Bit")]
60 pub const Integer16Bit: Self = Self(2);
61 #[doc(alias = "kCGComponentInteger32Bit")]
62 pub const Integer32Bit: Self = Self(3);
63 #[doc(alias = "kCGComponentFloat16Bit")]
64 pub const Float16Bit: Self = Self(5);
65 #[doc(alias = "kCGComponentFloat32Bit")]
66 pub const Float32Bit: Self = Self(4);
67}
68
69#[cfg(feature = "objc2")]
70unsafe impl Encode for CGComponent {
71 const ENCODING: Encoding = u32::ENCODING;
72}
73
74#[cfg(feature = "objc2")]
75unsafe impl RefEncode for CGComponent {
76 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
77}
78
79#[repr(C)]
81#[derive(Clone, Copy, Debug, PartialEq)]
82pub struct CGContentInfo {
83 pub deepestImageComponent: CGComponent,
84 pub contentColorModels: CGColorModel,
85 pub hasWideGamut: bool,
86 pub hasTransparency: bool,
87 pub largestContentHeadroom: c_float,
88}
89
90#[cfg(feature = "objc2")]
91unsafe impl Encode for CGContentInfo {
92 const ENCODING: Encoding = Encoding::Struct(
93 "?",
94 &[
95 <CGComponent>::ENCODING,
96 <CGColorModel>::ENCODING,
97 Encoding::Bool,
98 Encoding::Bool,
99 <c_float>::ENCODING,
100 ],
101 );
102}
103
104#[cfg(feature = "objc2")]
105unsafe impl RefEncode for CGContentInfo {
106 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
107}
108
109#[repr(transparent)]
112#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
113pub struct CGBitmapLayout(pub u32);
114impl CGBitmapLayout {
115 #[doc(alias = "kCGBitmapLayoutAlphaOnly")]
116 pub const AlphaOnly: Self = Self(0);
117 #[doc(alias = "kCGBitmapLayoutGray")]
118 pub const Gray: Self = Self(1);
119 #[doc(alias = "kCGBitmapLayoutGrayAlpha")]
120 pub const GrayAlpha: Self = Self(2);
121 #[doc(alias = "kCGBitmapLayoutRGBA")]
122 pub const RGBA: Self = Self(3);
123 #[doc(alias = "kCGBitmapLayoutARGB")]
124 pub const ARGB: Self = Self(4);
125 #[doc(alias = "kCGBitmapLayoutRGBX")]
126 pub const RGBX: Self = Self(5);
127 #[doc(alias = "kCGBitmapLayoutXRGB")]
128 pub const XRGB: Self = Self(6);
129 #[doc(alias = "kCGBitmapLayoutBGRA")]
130 pub const BGRA: Self = Self(7);
131 #[doc(alias = "kCGBitmapLayoutBGRX")]
132 pub const BGRX: Self = Self(8);
133 #[doc(alias = "kCGBitmapLayoutABGR")]
134 pub const ABGR: Self = Self(9);
135 #[doc(alias = "kCGBitmapLayoutXBGR")]
136 pub const XBGR: Self = Self(10);
137 #[doc(alias = "kCGBitmapLayoutCMYK")]
138 pub const CMYK: Self = Self(11);
139}
140
141#[cfg(feature = "objc2")]
142unsafe impl Encode for CGBitmapLayout {
143 const ENCODING: Encoding = u32::ENCODING;
144}
145
146#[cfg(feature = "objc2")]
147unsafe impl RefEncode for CGBitmapLayout {
148 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
149}
150
151#[cfg(all(feature = "CGColorSpace", feature = "CGImage"))]
153#[repr(C)]
154#[derive(Clone, Copy, Debug, PartialEq)]
155pub struct CGBitmapParameters {
156 pub width: usize,
157 pub height: usize,
158 pub bytesPerPixel: usize,
159 pub alignedBytesPerRow: usize,
160 pub component: CGComponent,
161 pub layout: CGBitmapLayout,
162 pub format: CGImagePixelFormatInfo,
163 pub colorSpace: NonNull<CGColorSpace>,
164 pub hasPremultipliedAlpha: bool,
165 pub byteOrder: CFByteOrder,
166 pub edrTargetHeadroom: c_float,
167}
168
169#[cfg(all(feature = "CGColorSpace", feature = "CGImage", feature = "objc2"))]
170unsafe impl Encode for CGBitmapParameters {
171 const ENCODING: Encoding = Encoding::Struct(
172 "?",
173 &[
174 <usize>::ENCODING,
175 <usize>::ENCODING,
176 <usize>::ENCODING,
177 <usize>::ENCODING,
178 <CGComponent>::ENCODING,
179 <CGBitmapLayout>::ENCODING,
180 <CGImagePixelFormatInfo>::ENCODING,
181 <NonNull<CGColorSpace>>::ENCODING,
182 Encoding::Bool,
183 <CFByteOrder>::ENCODING,
184 <c_float>::ENCODING,
185 ],
186 );
187}
188
189#[cfg(all(feature = "CGColorSpace", feature = "CGImage", feature = "objc2"))]
190unsafe impl RefEncode for CGBitmapParameters {
191 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
192}
193
194#[cfg(all(
199 feature = "CGColorSpace",
200 feature = "CGContext",
201 feature = "CGImage",
202 feature = "CGRenderingBufferProvider",
203 feature = "block2"
204))]
205#[inline]
206pub unsafe extern "C-unwind" fn CGBitmapContextCreateAdaptive(
207 width: usize,
208 height: usize,
209 auxiliary_info: Option<&CFDictionary>,
210 on_resolve: Option<
211 &block2::DynBlock<dyn Fn(NonNull<CGContentInfo>, NonNull<CGBitmapParameters>) -> bool>,
212 >,
213 on_allocate: Option<
214 &block2::DynBlock<
215 dyn Fn(
216 NonNull<CGContentInfo>,
217 NonNull<CGBitmapParameters>,
218 ) -> *mut CGRenderingBufferProvider,
219 >,
220 >,
221 on_free: Option<
222 &block2::DynBlock<
223 dyn Fn(
224 NonNull<CGRenderingBufferProvider>,
225 NonNull<CGContentInfo>,
226 NonNull<CGBitmapParameters>,
227 ),
228 >,
229 >,
230 on_error: Option<
231 &block2::DynBlock<
232 dyn Fn(NonNull<CFError>, NonNull<CGContentInfo>, NonNull<CGBitmapParameters>),
233 >,
234 >,
235) -> Option<CFRetained<CGContext>> {
236 extern "C-unwind" {
237 fn CGBitmapContextCreateAdaptive(
238 width: usize,
239 height: usize,
240 auxiliary_info: Option<&CFDictionary>,
241 on_resolve: Option<
242 &block2::DynBlock<
243 dyn Fn(NonNull<CGContentInfo>, NonNull<CGBitmapParameters>) -> bool,
244 >,
245 >,
246 on_allocate: Option<
247 &block2::DynBlock<
248 dyn Fn(
249 NonNull<CGContentInfo>,
250 NonNull<CGBitmapParameters>,
251 ) -> *mut CGRenderingBufferProvider,
252 >,
253 >,
254 on_free: Option<
255 &block2::DynBlock<
256 dyn Fn(
257 NonNull<CGRenderingBufferProvider>,
258 NonNull<CGContentInfo>,
259 NonNull<CGBitmapParameters>,
260 ),
261 >,
262 >,
263 on_error: Option<
264 &block2::DynBlock<
265 dyn Fn(NonNull<CFError>, NonNull<CGContentInfo>, NonNull<CGBitmapParameters>),
266 >,
267 >,
268 ) -> Option<NonNull<CGContext>>;
269 }
270 let ret = unsafe {
271 CGBitmapContextCreateAdaptive(
272 width,
273 height,
274 auxiliary_info,
275 on_resolve,
276 on_allocate,
277 on_free,
278 on_error,
279 )
280 };
281 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
282}
283
284extern "C" {
285 pub static kCGAdaptiveMaximumBitDepth: &'static CFString;
287}
288
289#[cfg(feature = "CGContext")]
290#[inline]
291pub extern "C-unwind" fn CGBitmapContextGetData(context: Option<&CGContext>) -> *mut c_void {
292 extern "C-unwind" {
293 fn CGBitmapContextGetData(context: Option<&CGContext>) -> *mut c_void;
294 }
295 unsafe { CGBitmapContextGetData(context) }
296}
297
298#[cfg(feature = "CGContext")]
299#[inline]
300pub extern "C-unwind" fn CGBitmapContextGetWidth(context: Option<&CGContext>) -> usize {
301 extern "C-unwind" {
302 fn CGBitmapContextGetWidth(context: Option<&CGContext>) -> usize;
303 }
304 unsafe { CGBitmapContextGetWidth(context) }
305}
306
307#[cfg(feature = "CGContext")]
308#[inline]
309pub extern "C-unwind" fn CGBitmapContextGetHeight(context: Option<&CGContext>) -> usize {
310 extern "C-unwind" {
311 fn CGBitmapContextGetHeight(context: Option<&CGContext>) -> usize;
312 }
313 unsafe { CGBitmapContextGetHeight(context) }
314}
315
316#[cfg(feature = "CGContext")]
317#[inline]
318pub extern "C-unwind" fn CGBitmapContextGetBitsPerComponent(context: Option<&CGContext>) -> usize {
319 extern "C-unwind" {
320 fn CGBitmapContextGetBitsPerComponent(context: Option<&CGContext>) -> usize;
321 }
322 unsafe { CGBitmapContextGetBitsPerComponent(context) }
323}
324
325#[cfg(feature = "CGContext")]
326#[inline]
327pub extern "C-unwind" fn CGBitmapContextGetBitsPerPixel(context: Option<&CGContext>) -> usize {
328 extern "C-unwind" {
329 fn CGBitmapContextGetBitsPerPixel(context: Option<&CGContext>) -> usize;
330 }
331 unsafe { CGBitmapContextGetBitsPerPixel(context) }
332}
333
334#[cfg(feature = "CGContext")]
335#[inline]
336pub extern "C-unwind" fn CGBitmapContextGetBytesPerRow(context: Option<&CGContext>) -> usize {
337 extern "C-unwind" {
338 fn CGBitmapContextGetBytesPerRow(context: Option<&CGContext>) -> usize;
339 }
340 unsafe { CGBitmapContextGetBytesPerRow(context) }
341}
342
343#[cfg(all(feature = "CGColorSpace", feature = "CGContext"))]
344#[inline]
345pub extern "C-unwind" fn CGBitmapContextGetColorSpace(
346 context: Option<&CGContext>,
347) -> Option<CFRetained<CGColorSpace>> {
348 extern "C-unwind" {
349 fn CGBitmapContextGetColorSpace(
350 context: Option<&CGContext>,
351 ) -> Option<NonNull<CGColorSpace>>;
352 }
353 let ret = unsafe { CGBitmapContextGetColorSpace(context) };
354 ret.map(|ret| unsafe { CFRetained::retain(ret) })
355}
356
357#[cfg(all(feature = "CGContext", feature = "CGImage"))]
358#[inline]
359pub extern "C-unwind" fn CGBitmapContextGetAlphaInfo(
360 context: Option<&CGContext>,
361) -> CGImageAlphaInfo {
362 extern "C-unwind" {
363 fn CGBitmapContextGetAlphaInfo(context: Option<&CGContext>) -> CGImageAlphaInfo;
364 }
365 unsafe { CGBitmapContextGetAlphaInfo(context) }
366}
367
368#[cfg(all(feature = "CGContext", feature = "CGImage"))]
369#[inline]
370pub extern "C-unwind" fn CGBitmapContextGetBitmapInfo(context: Option<&CGContext>) -> CGBitmapInfo {
371 extern "C-unwind" {
372 fn CGBitmapContextGetBitmapInfo(context: Option<&CGContext>) -> CGBitmapInfo;
373 }
374 unsafe { CGBitmapContextGetBitmapInfo(context) }
375}
376
377#[cfg(all(feature = "CGContext", feature = "CGImage"))]
378#[inline]
379pub extern "C-unwind" fn CGBitmapContextCreateImage(
380 context: Option<&CGContext>,
381) -> Option<CFRetained<CGImage>> {
382 extern "C-unwind" {
383 fn CGBitmapContextCreateImage(context: Option<&CGContext>) -> Option<NonNull<CGImage>>;
384 }
385 let ret = unsafe { CGBitmapContextCreateImage(context) };
386 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
387}