objc2-photos 0.3.2

Bindings to the Photos/PhotoKit 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-image")]
use objc2_core_image::*;
#[cfg(feature = "objc2-core-media")]
use objc2_core_media::*;
use objc2_foundation::*;
#[cfg(feature = "objc2-image-io")]
use objc2_image_io::*;

use crate::*;

/// A block callback for processing frames of a live photo, including the still image
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/photos/phlivephotoframeprocessingblock?language=objc)
#[cfg(all(feature = "block2", feature = "objc2-core-image"))]
pub type PHLivePhotoFrameProcessingBlock = *mut block2::DynBlock<
    dyn Fn(NonNull<ProtocolObject<dyn PHLivePhotoFrame>>, NonNull<*mut NSError>) -> *mut CIImage,
>;

/// [Apple's documentation](https://developer.apple.com/documentation/photos/phlivephotoeditingoption?language=objc)
// NS_TYPED_ENUM
pub type PHLivePhotoEditingOption = NSString;

extern_class!(
    /// [Apple's documentation](https://developer.apple.com/documentation/photos/phlivephotoeditingcontext?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct PHLivePhotoEditingContext;
);

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

impl PHLivePhotoEditingContext {
    extern_methods!(
        #[cfg(feature = "PHContentEditingInput")]
        /// Initializer from the specified live photo input
        /// Return nil if the specified input is not for a live photo
        #[unsafe(method(initWithLivePhotoEditingInput:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithLivePhotoEditingInput(
            this: Allocated<Self>,
            live_photo_input: &PHContentEditingInput,
        ) -> Option<Retained<Self>>;

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

        #[cfg(feature = "objc2-core-image")]
        /// The original full-size image from the input live photo
        #[unsafe(method(fullSizeImage))]
        #[unsafe(method_family = none)]
        pub unsafe fn fullSizeImage(&self) -> Retained<CIImage>;

        #[cfg(feature = "objc2-core-media")]
        /// The duration of the live photo
        #[unsafe(method(duration))]
        #[unsafe(method_family = none)]
        pub unsafe fn duration(&self) -> CMTime;

        #[cfg(feature = "objc2-core-media")]
        /// The time of the still image within the live photo
        #[unsafe(method(photoTime))]
        #[unsafe(method_family = none)]
        pub unsafe fn photoTime(&self) -> CMTime;

        #[cfg(all(feature = "block2", feature = "objc2-core-image"))]
        /// A block that can be set to process each frame of the live photo
        /// Note that the context uses a copy of the processor block during processing
        ///
        /// # Safety
        ///
        /// - The returned block's argument 1 must be a valid pointer.
        /// - The returned block's argument 2 must be a valid pointer.
        #[unsafe(method(frameProcessor))]
        #[unsafe(method_family = none)]
        pub unsafe fn frameProcessor(&self) -> PHLivePhotoFrameProcessingBlock;

        #[cfg(all(feature = "block2", feature = "objc2-core-image"))]
        /// Setter for [`frameProcessor`][Self::frameProcessor].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        ///
        /// # Safety
        ///
        /// `frame_processor` must be a valid pointer or null.
        #[unsafe(method(setFrameProcessor:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setFrameProcessor(&self, frame_processor: PHLivePhotoFrameProcessingBlock);

        /// Specify the audio volume of the edited live photo
        /// Must be between 0.0 and 1.0
        /// Default to 1.0
        #[unsafe(method(audioVolume))]
        #[unsafe(method_family = none)]
        pub unsafe fn audioVolume(&self) -> c_float;

        /// Setter for [`audioVolume`][Self::audioVolume].
        #[unsafe(method(setAudioVolume:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setAudioVolume(&self, audio_volume: c_float);

        #[cfg(feature = "objc2-image-io")]
        #[unsafe(method(orientation))]
        #[unsafe(method_family = none)]
        pub unsafe fn orientation(&self) -> CGImagePropertyOrientation;

        #[cfg(all(
            feature = "PHLivePhoto",
            feature = "block2",
            feature = "objc2-core-foundation"
        ))]
        /// Asynchronously generate a new live photo suitable for playback in a PHLivePhotoView of the specified target size
        /// The options dictionary can contain additional options, see below
        ///
        /// # Safety
        ///
        /// `options` generic should be of the correct type.
        #[unsafe(method(prepareLivePhotoForPlaybackWithTargetSize:options:completionHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn prepareLivePhotoForPlaybackWithTargetSize_options_completionHandler(
            &self,
            target_size: CGSize,
            options: Option<&NSDictionary<NSString, AnyObject>>,
            handler: &block2::DynBlock<dyn Fn(*mut PHLivePhoto, *mut NSError)>,
        );

        #[cfg(all(feature = "PHContentEditingOutput", feature = "block2"))]
        /// Asynchronously process and save the edited live photo to the specified content editing output
        /// Options dictionary should be nil, reserved for future expansion
        ///
        /// # Safety
        ///
        /// `options` generic should be of the correct type.
        #[unsafe(method(saveLivePhotoToOutput:options:completionHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn saveLivePhotoToOutput_options_completionHandler(
            &self,
            output: &PHContentEditingOutput,
            options: Option<&NSDictionary<NSString, AnyObject>>,
            handler: &block2::DynBlock<dyn Fn(Bool, *mut NSError)>,
        );

        /// Cancel the current asynchronous operation
        /// This is implicitly called whenever prepare or save is called
        /// A canceled operation will call its completion handler with an appropriate error code
        #[unsafe(method(cancel))]
        #[unsafe(method_family = none)]
        pub unsafe fn cancel(&self);
    );
}

/// Methods declared on superclass `NSObject`.
impl PHLivePhotoEditingContext {
    extern_methods!(
        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;
    );
}

/// The type of frame in the Live Photo
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/photos/phlivephotoframetype?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct PHLivePhotoFrameType(pub NSInteger);
impl PHLivePhotoFrameType {
    /// Indicates the still image
    #[doc(alias = "PHLivePhotoFrameTypePhoto")]
    pub const Photo: Self = Self(0);
    /// Indicates a video frame
    #[doc(alias = "PHLivePhotoFrameTypeVideo")]
    pub const Video: Self = Self(1);
}

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

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

extern_protocol!(
    /// Protocol that describes a single frame of a live photo
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/photos/phlivephotoframe?language=objc)
    pub unsafe trait PHLivePhotoFrame {
        #[cfg(feature = "objc2-core-image")]
        /// Input image for the frame
        #[unsafe(method(image))]
        #[unsafe(method_family = none)]
        unsafe fn image(&self) -> Retained<CIImage>;

        #[cfg(feature = "objc2-core-media")]
        /// The time of the frame relative to the beginning of the live photo
        #[unsafe(method(time))]
        #[unsafe(method_family = none)]
        unsafe fn time(&self) -> CMTime;

        /// The type of frame
        #[unsafe(method(type))]
        #[unsafe(method_family = none)]
        unsafe fn r#type(&self) -> PHLivePhotoFrameType;

        #[cfg(feature = "objc2-core-foundation")]
        /// The scale of the frame relative to the full-size image
        #[unsafe(method(renderScale))]
        #[unsafe(method_family = none)]
        unsafe fn renderScale(&self) -> CGFloat;
    }
);

extern "C" {
    /// Indicates whether processing should happen at playback time
    /// If set to NO (the default) the live photo will always be rendered before playback
    /// If set to YES, the editing context might still choose to render first for performance reasons
    /// This option is ignored by the saveLivePhotoToOutput method
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/photos/phlivephotoshouldrenderatplaybacktime?language=objc)
    pub static PHLivePhotoShouldRenderAtPlaybackTime: &'static PHLivePhotoEditingOption;
}

extern "C" {
    /// The error domain for all Live Photo Editing errors (Deprecated).
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/photos/phlivephotoeditingerrordomain?language=objc)
    #[deprecated]
    pub static PHLivePhotoEditingErrorDomain: &'static NSString;
}

/// Error code for Live Photo Editing errors (Deprecated)
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/photos/phlivephotoeditingerrorcode?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct PHLivePhotoEditingErrorCode(pub NSInteger);
impl PHLivePhotoEditingErrorCode {
    #[doc(alias = "PHLivePhotoEditingErrorCodeUnknown")]
    #[deprecated]
    pub const Unknown: Self = Self(0);
    #[doc(alias = "PHLivePhotoEditingErrorCodeAborted")]
    #[deprecated]
    pub const Aborted: Self = Self(1);
}

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

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