objc2_core_graphics/
bitmap_context.rs

1#![allow(warnings, clippy)]
2use core::ffi::c_void;
3use core::ptr::NonNull;
4use objc2_core_foundation::*;
5
6use crate::*;
7
8/// # Safety
9///
10/// - `data` must be a valid pointer or null.
11/// - `release_callback` must be implemented correctly.
12/// - `release_info` must be a valid pointer or null.
13#[cfg(all(feature = "CGColorSpace", feature = "CGContext", feature = "CGImage"))]
14#[inline]
15pub unsafe extern "C-unwind" fn CGBitmapContextCreateWithData(
16    data: *mut c_void,
17    width: usize,
18    height: usize,
19    bits_per_component: usize,
20    bytes_per_row: usize,
21    space: Option<&CGColorSpace>,
22    bitmap_info: u32,
23    release_callback: CGBitmapContextReleaseDataCallback,
24    release_info: *mut c_void,
25) -> Option<CFRetained<CGContext>> {
26    extern "C-unwind" {
27        fn CGBitmapContextCreateWithData(
28            data: *mut c_void,
29            width: usize,
30            height: usize,
31            bits_per_component: usize,
32            bytes_per_row: usize,
33            space: Option<&CGColorSpace>,
34            bitmap_info: u32,
35            release_callback: CGBitmapContextReleaseDataCallback,
36            release_info: *mut c_void,
37        ) -> Option<NonNull<CGContext>>;
38    }
39    let ret = unsafe {
40        CGBitmapContextCreateWithData(
41            data,
42            width,
43            height,
44            bits_per_component,
45            bytes_per_row,
46            space,
47            bitmap_info,
48            release_callback,
49            release_info,
50        )
51    };
52    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
53}
54
55/// # Safety
56///
57/// `data` must be a valid pointer or null.
58#[cfg(all(feature = "CGColorSpace", feature = "CGContext", feature = "CGImage"))]
59#[inline]
60pub unsafe extern "C-unwind" fn CGBitmapContextCreate(
61    data: *mut c_void,
62    width: usize,
63    height: usize,
64    bits_per_component: usize,
65    bytes_per_row: usize,
66    space: Option<&CGColorSpace>,
67    bitmap_info: u32,
68) -> Option<CFRetained<CGContext>> {
69    extern "C-unwind" {
70        fn CGBitmapContextCreate(
71            data: *mut c_void,
72            width: usize,
73            height: usize,
74            bits_per_component: usize,
75            bytes_per_row: usize,
76            space: Option<&CGColorSpace>,
77            bitmap_info: u32,
78        ) -> Option<NonNull<CGContext>>;
79    }
80    let ret = unsafe {
81        CGBitmapContextCreate(
82            data,
83            width,
84            height,
85            bits_per_component,
86            bytes_per_row,
87            space,
88            bitmap_info,
89        )
90    };
91    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
92}