//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::cell::UnsafeCell;
use core::ffi::*;
use core::marker::{PhantomData, PhantomPinned};
use core::ptr::NonNull;
#[cfg(feature = "objc2")]
use objc2::__framework_prelude::*;
use objc2_core_foundation::*;

use crate::*;

/// [Apple's documentation](https://developer.apple.com/documentation/coregraphics/cgcolorconversioninfo?language=objc)
#[doc(alias = "CGColorConversionInfoRef")]
#[repr(C)]
pub struct CGColorConversionInfo {
    inner: [u8; 0],
    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}

cf_type!(
    unsafe impl CGColorConversionInfo {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
    unsafe impl RefEncode<"CGColorConversionInfo"> for CGColorConversionInfo {}
);

unsafe impl ConcreteType for CGColorConversionInfo {
    #[doc(alias = "CGColorConversionInfoGetTypeID")]
    #[inline]
    fn type_id() -> CFTypeID {
        extern "C-unwind" {
            fn CGColorConversionInfoGetTypeID() -> CFTypeID;
        }
        unsafe { CGColorConversionInfoGetTypeID() }
    }
}

/// [Apple's documentation](https://developer.apple.com/documentation/coregraphics/cgcolorconversioninfotransformtype?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct CGColorConversionInfoTransformType(pub u32);
impl CGColorConversionInfoTransformType {
    #[doc(alias = "kCGColorConversionTransformFromSpace")]
    pub const TransformFromSpace: Self = Self(0);
    #[doc(alias = "kCGColorConversionTransformToSpace")]
    pub const TransformToSpace: Self = Self(1);
    #[doc(alias = "kCGColorConversionTransformApplySpace")]
    pub const TransformApplySpace: Self = Self(2);
}

#[cfg(feature = "objc2")]
unsafe impl Encode for CGColorConversionInfoTransformType {
    const ENCODING: Encoding = u32::ENCODING;
}

#[cfg(feature = "objc2")]
unsafe impl RefEncode for CGColorConversionInfoTransformType {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

impl CGColorConversionInfo {
    #[doc(alias = "CGColorConversionInfoCreate")]
    #[cfg(feature = "CGColorSpace")]
    #[inline]
    pub fn new(
        src: Option<&CGColorSpace>,
        dst: Option<&CGColorSpace>,
    ) -> Option<CFRetained<CGColorConversionInfo>> {
        extern "C-unwind" {
            fn CGColorConversionInfoCreate(
                src: Option<&CGColorSpace>,
                dst: Option<&CGColorSpace>,
            ) -> Option<NonNull<CGColorConversionInfo>>;
        }
        let ret = unsafe { CGColorConversionInfoCreate(src, dst) };
        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
    }

    /// # Safety
    ///
    /// `options` generics must be of the correct type.
    #[doc(alias = "CGColorConversionInfoCreateWithOptions")]
    #[cfg(feature = "CGColorSpace")]
    #[inline]
    pub unsafe fn with_options(
        src: &CGColorSpace,
        dst: &CGColorSpace,
        options: Option<&CFDictionary>,
    ) -> Option<CFRetained<CGColorConversionInfo>> {
        extern "C-unwind" {
            fn CGColorConversionInfoCreateWithOptions(
                src: &CGColorSpace,
                dst: &CGColorSpace,
                options: Option<&CFDictionary>,
            ) -> Option<NonNull<CGColorConversionInfo>>;
        }
        let ret = unsafe { CGColorConversionInfoCreateWithOptions(src, dst, options) };
        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
    }

    /// # Safety
    ///
    /// - `options` generics must be of the correct type.
    /// - `error` must be a valid pointer or null.
    #[doc(alias = "CGColorConversionInfoCreateForToneMapping")]
    #[cfg(all(feature = "CGColorSpace", feature = "CGToneMapping"))]
    #[inline]
    pub unsafe fn new_for_tone_mapping(
        from: &CGColorSpace,
        source_headroom: c_float,
        to: &CGColorSpace,
        target_headroom: c_float,
        method: CGToneMapping,
        options: Option<&CFDictionary>,
        error: *mut *mut CFError,
    ) -> Option<CFRetained<CGColorConversionInfo>> {
        extern "C-unwind" {
            fn CGColorConversionInfoCreateForToneMapping(
                from: &CGColorSpace,
                source_headroom: c_float,
                to: &CGColorSpace,
                target_headroom: c_float,
                method: CGToneMapping,
                options: Option<&CFDictionary>,
                error: *mut *mut CFError,
            ) -> Option<NonNull<CGColorConversionInfo>>;
        }
        let ret = unsafe {
            CGColorConversionInfoCreateForToneMapping(
                from,
                source_headroom,
                to,
                target_headroom,
                method,
                options,
                error,
            )
        };
        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
    }
}

/// [Apple's documentation](https://developer.apple.com/documentation/coregraphics/cgcolorbufferformat?language=objc)
#[cfg(feature = "CGImage")]
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct CGColorBufferFormat {
    pub version: u32,
    pub bitmapInfo: CGBitmapInfo,
    pub bitsPerComponent: usize,
    pub bitsPerPixel: usize,
    pub bytesPerRow: usize,
}

#[cfg(all(feature = "CGImage", feature = "objc2"))]
unsafe impl Encode for CGColorBufferFormat {
    const ENCODING: Encoding = Encoding::Struct(
        "?",
        &[
            <u32>::ENCODING,
            <CGBitmapInfo>::ENCODING,
            <usize>::ENCODING,
            <usize>::ENCODING,
            <usize>::ENCODING,
        ],
    );
}

#[cfg(all(feature = "CGImage", feature = "objc2"))]
unsafe impl RefEncode for CGColorBufferFormat {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

impl CGColorConversionInfo {
    /// # Safety
    ///
    /// - `dst_data` must be a valid pointer.
    /// - `src_data` must be a valid pointer.
    /// - `options` generics must be of the correct type.
    #[doc(alias = "CGColorConversionInfoConvertData")]
    #[cfg(feature = "CGImage")]
    #[inline]
    pub unsafe fn convert_data(
        &self,
        width: usize,
        height: usize,
        dst_data: NonNull<c_void>,
        dst_format: CGColorBufferFormat,
        src_data: NonNull<c_void>,
        src_format: CGColorBufferFormat,
        options: Option<&CFDictionary>,
    ) -> bool {
        extern "C-unwind" {
            fn CGColorConversionInfoConvertData(
                info: &CGColorConversionInfo,
                width: usize,
                height: usize,
                dst_data: NonNull<c_void>,
                dst_format: CGColorBufferFormat,
                src_data: NonNull<c_void>,
                src_format: CGColorBufferFormat,
                options: Option<&CFDictionary>,
            ) -> bool;
        }
        unsafe {
            CGColorConversionInfoConvertData(
                self, width, height, dst_data, dst_format, src_data, src_format, options,
            )
        }
    }
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/coregraphics/kcgcolorconversionblackpointcompensation?language=objc)
    pub static kCGColorConversionBlackPointCompensation: &'static CFString;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/coregraphics/kcgcolorconversiontrcsize?language=objc)
    pub static kCGColorConversionTRCSize: &'static CFString;
}

#[cfg(feature = "CGColorSpace")]
#[deprecated = "renamed to `CGColorConversionInfo::new`"]
#[inline]
pub extern "C-unwind" fn CGColorConversionInfoCreate(
    src: Option<&CGColorSpace>,
    dst: Option<&CGColorSpace>,
) -> Option<CFRetained<CGColorConversionInfo>> {
    extern "C-unwind" {
        fn CGColorConversionInfoCreate(
            src: Option<&CGColorSpace>,
            dst: Option<&CGColorSpace>,
        ) -> Option<NonNull<CGColorConversionInfo>>;
    }
    let ret = unsafe { CGColorConversionInfoCreate(src, dst) };
    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}

#[cfg(feature = "CGColorSpace")]
#[deprecated = "renamed to `CGColorConversionInfo::with_options`"]
#[inline]
pub unsafe extern "C-unwind" fn CGColorConversionInfoCreateWithOptions(
    src: &CGColorSpace,
    dst: &CGColorSpace,
    options: Option<&CFDictionary>,
) -> Option<CFRetained<CGColorConversionInfo>> {
    extern "C-unwind" {
        fn CGColorConversionInfoCreateWithOptions(
            src: &CGColorSpace,
            dst: &CGColorSpace,
            options: Option<&CFDictionary>,
        ) -> Option<NonNull<CGColorConversionInfo>>;
    }
    let ret = unsafe { CGColorConversionInfoCreateWithOptions(src, dst, options) };
    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}

#[cfg(all(feature = "CGColorSpace", feature = "CGToneMapping"))]
#[deprecated = "renamed to `CGColorConversionInfo::new_for_tone_mapping`"]
#[inline]
pub unsafe extern "C-unwind" fn CGColorConversionInfoCreateForToneMapping(
    from: &CGColorSpace,
    source_headroom: c_float,
    to: &CGColorSpace,
    target_headroom: c_float,
    method: CGToneMapping,
    options: Option<&CFDictionary>,
    error: *mut *mut CFError,
) -> Option<CFRetained<CGColorConversionInfo>> {
    extern "C-unwind" {
        fn CGColorConversionInfoCreateForToneMapping(
            from: &CGColorSpace,
            source_headroom: c_float,
            to: &CGColorSpace,
            target_headroom: c_float,
            method: CGToneMapping,
            options: Option<&CFDictionary>,
            error: *mut *mut CFError,
        ) -> Option<NonNull<CGColorConversionInfo>>;
    }
    let ret = unsafe {
        CGColorConversionInfoCreateForToneMapping(
            from,
            source_headroom,
            to,
            target_headroom,
            method,
            options,
            error,
        )
    };
    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}

extern "C-unwind" {
    #[cfg(feature = "CGImage")]
    #[deprecated = "renamed to `CGColorConversionInfo::convert_data`"]
    pub fn CGColorConversionInfoConvertData(
        info: &CGColorConversionInfo,
        width: usize,
        height: usize,
        dst_data: NonNull<c_void>,
        dst_format: CGColorBufferFormat,
        src_data: NonNull<c_void>,
        src_format: CGColorBufferFormat,
        options: Option<&CFDictionary>,
    ) -> bool;
}
