objc2-cinematic 0.3.2

Bindings to the Cinematic framework
Documentation
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ffi::*;
use core::ptr::NonNull;
use objc2::__framework_prelude::*;
#[cfg(feature = "objc2-core-foundation")]
use objc2_core_foundation::*;
#[cfg(feature = "objc2-core-media")]
use objc2_core_media::*;
#[cfg(feature = "objc2-core-video")]
use objc2_core_video::*;
use objc2_foundation::*;

use crate::*;

/// [Apple's documentation](https://developer.apple.com/documentation/cinematic/cndetectionid?language=objc)
// NS_TYPED_EXTENSIBLE_ENUM
pub type CNDetectionID = i64;

/// [Apple's documentation](https://developer.apple.com/documentation/cinematic/cndetectiongroupid?language=objc)
// NS_TYPED_EXTENSIBLE_ENUM
pub type CNDetectionGroupID = i64;

/// The type of object that was detected.
///
/// Special detection types include:
/// - autoFocus: from the autofocus system of the camera
/// - fixedFocus: an explicit request to focus at a fixed disparity
/// - custom: an object tracked via a custom tracker
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/cinematic/cndetectiontype?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct CNDetectionType(pub NSInteger);
impl CNDetectionType {
    #[doc(alias = "CNDetectionTypeUnknown")]
    pub const Unknown: Self = Self(0);
    #[doc(alias = "CNDetectionTypeHumanFace")]
    pub const HumanFace: Self = Self(1);
    #[doc(alias = "CNDetectionTypeHumanHead")]
    pub const HumanHead: Self = Self(2);
    #[doc(alias = "CNDetectionTypeHumanTorso")]
    pub const HumanTorso: Self = Self(3);
    #[doc(alias = "CNDetectionTypeCatBody")]
    pub const CatBody: Self = Self(4);
    #[doc(alias = "CNDetectionTypeDogBody")]
    pub const DogBody: Self = Self(5);
    #[doc(alias = "CNDetectionTypeCatHead")]
    pub const CatHead: Self = Self(9);
    #[doc(alias = "CNDetectionTypeDogHead")]
    pub const DogHead: Self = Self(10);
    #[doc(alias = "CNDetectionTypeSportsBall")]
    pub const SportsBall: Self = Self(11);
    #[doc(alias = "CNDetectionTypeAutoFocus")]
    pub const AutoFocus: Self = Self(100);
    #[doc(alias = "CNDetectionTypeFixedFocus")]
    pub const FixedFocus: Self = Self(101);
    #[doc(alias = "CNDetectionTypeCustom")]
    pub const Custom: Self = Self(102);
}

unsafe impl Encode for CNDetectionType {
    const ENCODING: Encoding = NSInteger::ENCODING;
}

unsafe impl RefEncode for CNDetectionType {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

extern_class!(
    /// A cinematic detection of a subject.
    ///
    /// Specifies the type, distance (as disparity), bounds (as a normalized rectangle), and time (as CMTime) of the detection.
    /// Detections obtained from the cinematic script include a detectionID that can be used to track the detection over time.
    /// Some types of detections also include a detectionGroupID that associates related detections (e.g. the face and torso of the same person).
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/cinematic/cndetection?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct CNDetection;
);

unsafe impl Send for CNDetection {}

unsafe impl Sync for CNDetection {}

extern_conformance!(
    unsafe impl NSCopying for CNDetection {}
);

unsafe impl CopyingHelper for CNDetection {
    type Result = Self;
}

extern_conformance!(
    unsafe impl NSObjectProtocol for CNDetection {}
);

impl CNDetection {
    extern_methods!(
        #[cfg(all(feature = "objc2-core-foundation", feature = "objc2-core-media"))]
        /// Initialize a cinematic detection.
        ///
        /// For playback and edit, most detections are obtained by from the cinematic script rather than being created.
        /// However, if you need to add a custom track, you can build an array of detections to create one.
        /// Any detections you create will not have a valid detectionID until the custom track is added to the cinematic script.
        /// Doing so will return the assigned detectionID. Any detections newly obtained from the cinematic script will have their assigned detectionID.
        ///
        /// - Parameters:
        /// - time: the presentation time of the frame in which the detection occurred
        /// - detectionType: the type of object that was detected (face, torso, cat, dog, etc.)
        /// - normalizedRect: the rectangle within the image where the object occurs, normalized such that (0.0, 0.0) is the top-left and (1.0, 1.0) is the bottom-right
        /// - focusDisparity: the disparity to use in order to focus on the object (use the static `disparity` method to compute if unknown)
        #[unsafe(method(initWithTime:detectionType:normalizedRect:focusDisparity:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithTime_detectionType_normalizedRect_focusDisparity(
            this: Allocated<Self>,
            time: CMTime,
            detection_type: CNDetectionType,
            normalized_rect: CGRect,
            focus_disparity: c_float,
        ) -> Retained<Self>;

        #[cfg(feature = "objc2-core-media")]
        /// The presentation time of the frame in which the detection occurred.
        #[unsafe(method(time))]
        #[unsafe(method_family = none)]
        pub unsafe fn time(&self) -> CMTime;

        /// The type of object that was detected (face, torso, cat, dog, etc.)
        #[unsafe(method(detectionType))]
        #[unsafe(method_family = none)]
        pub unsafe fn detectionType(&self) -> CNDetectionType;

        #[cfg(feature = "objc2-core-foundation")]
        /// The rectangle within the image where the object occurs, normalized such that (0.0, 0.0) is the top-left and (1.0, 1.0) is the bottom-right.
        #[unsafe(method(normalizedRect))]
        #[unsafe(method_family = none)]
        pub unsafe fn normalizedRect(&self) -> CGRect;

        /// The disparity to use in order to focus on the object.
        /// If the disparity is unknown, use the class method to find it: `disparityInNormalizedRect:sourceDisparity:detectionType:priorDisparity:`.
        #[unsafe(method(focusDisparity))]
        #[unsafe(method_family = none)]
        pub unsafe fn focusDisparity(&self) -> c_float;

        /// An unique identifier assigned by the cinematic script to all detections of the same subject and detection type across time.
        /// If you build a custom detection track, the detectionID will be assigned when you add it to the script.
        #[unsafe(method(detectionID))]
        #[unsafe(method_family = none)]
        pub unsafe fn detectionID(&self) -> CNDetectionID;

        /// An unique identifier assigned by the cinematic script to all detections of the same subject and related detection types across time.
        /// For example, the face/torso detections of the same person are assigned the same detectionGroupID.
        #[unsafe(method(detectionGroupID))]
        #[unsafe(method_family = none)]
        pub unsafe fn detectionGroupID(&self) -> CNDetectionGroupID;

        /// Determine whether a given detectionID is valid
        #[unsafe(method(isValidDetectionID:))]
        #[unsafe(method_family = none)]
        pub unsafe fn isValidDetectionID(detection_id: CNDetectionID) -> bool;

        /// Determine whether a given detectionGroupID is valid
        #[unsafe(method(isValidDetectionGroupID:))]
        #[unsafe(method_family = none)]
        pub unsafe fn isValidDetectionGroupID(detection_group_id: CNDetectionGroupID) -> bool;

        /// A localized accessibility label converting a specific detection type into a broad category (person, pet, etc.).
        #[unsafe(method(accessibilityLabelForDetectionType:))]
        #[unsafe(method_family = none)]
        pub unsafe fn accessibilityLabelForDetectionType(
            detection_type: CNDetectionType,
        ) -> Retained<NSString>;

        #[cfg(all(feature = "objc2-core-foundation", feature = "objc2-core-video"))]
        /// Determine the disparity to use to focus on the object in the rectangle.
        /// - Parameters:
        /// - disparityBuffer: A pixel buffer from the cinematic disparity track for the frame in which the object occurs.
        /// - normalizedRect: The rectangle within the disparity buffer where the object occurs, normalized such that (0.0, 0.0) is the top-left and (1.0, 1.0) is the bottom-right of the disparity buffer.
        /// - detectionType: The type of object expected within the rectangle. Pass `CNDetectionTypeUnknown` if unknown.
        /// - priorDisparity: The disparity of the object in the prior frame. This helps ensure the object is not mistaken for another that enters the same rectangle. Pass `NAN` if there is no known prior, such as in the first frame in which the object is being tracked.
        #[unsafe(method(disparityInNormalizedRect:sourceDisparity:detectionType:priorDisparity:))]
        #[unsafe(method_family = none)]
        pub unsafe fn disparityInNormalizedRect_sourceDisparity_detectionType_priorDisparity(
            normalized_rect: CGRect,
            source_disparity: &CVPixelBuffer,
            detection_type: CNDetectionType,
            prior_disparity: c_float,
        ) -> c_float;

        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;
    );
}