objc2_photos/generated/
PHLivePhotoEditingContext.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6#[cfg(feature = "objc2-core-foundation")]
7use objc2_core_foundation::*;
8#[cfg(feature = "objc2-core-image")]
9use objc2_core_image::*;
10#[cfg(feature = "objc2-core-media")]
11use objc2_core_media::*;
12use objc2_foundation::*;
13#[cfg(feature = "objc2-image-io")]
14use objc2_image_io::*;
15
16use crate::*;
17
18/// A block callback for processing frames of a live photo, including the still image
19///
20/// See also [Apple's documentation](https://developer.apple.com/documentation/photos/phlivephotoframeprocessingblock?language=objc)
21#[cfg(all(feature = "block2", feature = "objc2-core-image"))]
22pub type PHLivePhotoFrameProcessingBlock = *mut block2::DynBlock<
23    dyn Fn(NonNull<ProtocolObject<dyn PHLivePhotoFrame>>, NonNull<*mut NSError>) -> *mut CIImage,
24>;
25
26/// [Apple's documentation](https://developer.apple.com/documentation/photos/phlivephotoeditingoption?language=objc)
27// NS_TYPED_ENUM
28pub type PHLivePhotoEditingOption = NSString;
29
30extern_class!(
31    /// [Apple's documentation](https://developer.apple.com/documentation/photos/phlivephotoeditingcontext?language=objc)
32    #[unsafe(super(NSObject))]
33    #[derive(Debug, PartialEq, Eq, Hash)]
34    pub struct PHLivePhotoEditingContext;
35);
36
37extern_conformance!(
38    unsafe impl NSObjectProtocol for PHLivePhotoEditingContext {}
39);
40
41impl PHLivePhotoEditingContext {
42    extern_methods!(
43        #[cfg(feature = "PHContentEditingInput")]
44        /// Initializer from the specified live photo input
45        /// Return nil if the specified input is not for a live photo
46        #[unsafe(method(initWithLivePhotoEditingInput:))]
47        #[unsafe(method_family = init)]
48        pub unsafe fn initWithLivePhotoEditingInput(
49            this: Allocated<Self>,
50            live_photo_input: &PHContentEditingInput,
51        ) -> Option<Retained<Self>>;
52
53        #[unsafe(method(init))]
54        #[unsafe(method_family = init)]
55        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
56
57        #[cfg(feature = "objc2-core-image")]
58        /// The original full-size image from the input live photo
59        #[unsafe(method(fullSizeImage))]
60        #[unsafe(method_family = none)]
61        pub unsafe fn fullSizeImage(&self) -> Retained<CIImage>;
62
63        #[cfg(feature = "objc2-core-media")]
64        /// The duration of the live photo
65        #[unsafe(method(duration))]
66        #[unsafe(method_family = none)]
67        pub unsafe fn duration(&self) -> CMTime;
68
69        #[cfg(feature = "objc2-core-media")]
70        /// The time of the still image within the live photo
71        #[unsafe(method(photoTime))]
72        #[unsafe(method_family = none)]
73        pub unsafe fn photoTime(&self) -> CMTime;
74
75        #[cfg(all(feature = "block2", feature = "objc2-core-image"))]
76        /// A block that can be set to process each frame of the live photo
77        /// Note that the context uses a copy of the processor block during processing
78        ///
79        /// # Safety
80        ///
81        /// - The returned block's argument 1 must be a valid pointer.
82        /// - The returned block's argument 2 must be a valid pointer.
83        #[unsafe(method(frameProcessor))]
84        #[unsafe(method_family = none)]
85        pub unsafe fn frameProcessor(&self) -> PHLivePhotoFrameProcessingBlock;
86
87        #[cfg(all(feature = "block2", feature = "objc2-core-image"))]
88        /// Setter for [`frameProcessor`][Self::frameProcessor].
89        ///
90        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
91        ///
92        /// # Safety
93        ///
94        /// `frame_processor` must be a valid pointer or null.
95        #[unsafe(method(setFrameProcessor:))]
96        #[unsafe(method_family = none)]
97        pub unsafe fn setFrameProcessor(&self, frame_processor: PHLivePhotoFrameProcessingBlock);
98
99        /// Specify the audio volume of the edited live photo
100        /// Must be between 0.0 and 1.0
101        /// Default to 1.0
102        #[unsafe(method(audioVolume))]
103        #[unsafe(method_family = none)]
104        pub unsafe fn audioVolume(&self) -> c_float;
105
106        /// Setter for [`audioVolume`][Self::audioVolume].
107        #[unsafe(method(setAudioVolume:))]
108        #[unsafe(method_family = none)]
109        pub unsafe fn setAudioVolume(&self, audio_volume: c_float);
110
111        #[cfg(feature = "objc2-image-io")]
112        #[unsafe(method(orientation))]
113        #[unsafe(method_family = none)]
114        pub unsafe fn orientation(&self) -> CGImagePropertyOrientation;
115
116        #[cfg(all(
117            feature = "PHLivePhoto",
118            feature = "block2",
119            feature = "objc2-core-foundation"
120        ))]
121        /// Asynchronously generate a new live photo suitable for playback in a PHLivePhotoView of the specified target size
122        /// The options dictionary can contain additional options, see below
123        ///
124        /// # Safety
125        ///
126        /// `options` generic should be of the correct type.
127        #[unsafe(method(prepareLivePhotoForPlaybackWithTargetSize:options:completionHandler:))]
128        #[unsafe(method_family = none)]
129        pub unsafe fn prepareLivePhotoForPlaybackWithTargetSize_options_completionHandler(
130            &self,
131            target_size: CGSize,
132            options: Option<&NSDictionary<NSString, AnyObject>>,
133            handler: &block2::DynBlock<dyn Fn(*mut PHLivePhoto, *mut NSError)>,
134        );
135
136        #[cfg(all(feature = "PHContentEditingOutput", feature = "block2"))]
137        /// Asynchronously process and save the edited live photo to the specified content editing output
138        /// Options dictionary should be nil, reserved for future expansion
139        ///
140        /// # Safety
141        ///
142        /// `options` generic should be of the correct type.
143        #[unsafe(method(saveLivePhotoToOutput:options:completionHandler:))]
144        #[unsafe(method_family = none)]
145        pub unsafe fn saveLivePhotoToOutput_options_completionHandler(
146            &self,
147            output: &PHContentEditingOutput,
148            options: Option<&NSDictionary<NSString, AnyObject>>,
149            handler: &block2::DynBlock<dyn Fn(Bool, *mut NSError)>,
150        );
151
152        /// Cancel the current asynchronous operation
153        /// This is implicitly called whenever prepare or save is called
154        /// A canceled operation will call its completion handler with an appropriate error code
155        #[unsafe(method(cancel))]
156        #[unsafe(method_family = none)]
157        pub unsafe fn cancel(&self);
158    );
159}
160
161/// Methods declared on superclass `NSObject`.
162impl PHLivePhotoEditingContext {
163    extern_methods!(
164        #[unsafe(method(new))]
165        #[unsafe(method_family = new)]
166        pub unsafe fn new() -> Retained<Self>;
167    );
168}
169
170/// The type of frame in the Live Photo
171///
172/// See also [Apple's documentation](https://developer.apple.com/documentation/photos/phlivephotoframetype?language=objc)
173// NS_ENUM
174#[repr(transparent)]
175#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
176pub struct PHLivePhotoFrameType(pub NSInteger);
177impl PHLivePhotoFrameType {
178    /// Indicates the still image
179    #[doc(alias = "PHLivePhotoFrameTypePhoto")]
180    pub const Photo: Self = Self(0);
181    /// Indicates a video frame
182    #[doc(alias = "PHLivePhotoFrameTypeVideo")]
183    pub const Video: Self = Self(1);
184}
185
186unsafe impl Encode for PHLivePhotoFrameType {
187    const ENCODING: Encoding = NSInteger::ENCODING;
188}
189
190unsafe impl RefEncode for PHLivePhotoFrameType {
191    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
192}
193
194extern_protocol!(
195    /// Protocol that describes a single frame of a live photo
196    ///
197    /// See also [Apple's documentation](https://developer.apple.com/documentation/photos/phlivephotoframe?language=objc)
198    pub unsafe trait PHLivePhotoFrame {
199        #[cfg(feature = "objc2-core-image")]
200        /// Input image for the frame
201        #[unsafe(method(image))]
202        #[unsafe(method_family = none)]
203        unsafe fn image(&self) -> Retained<CIImage>;
204
205        #[cfg(feature = "objc2-core-media")]
206        /// The time of the frame relative to the beginning of the live photo
207        #[unsafe(method(time))]
208        #[unsafe(method_family = none)]
209        unsafe fn time(&self) -> CMTime;
210
211        /// The type of frame
212        #[unsafe(method(type))]
213        #[unsafe(method_family = none)]
214        unsafe fn r#type(&self) -> PHLivePhotoFrameType;
215
216        #[cfg(feature = "objc2-core-foundation")]
217        /// The scale of the frame relative to the full-size image
218        #[unsafe(method(renderScale))]
219        #[unsafe(method_family = none)]
220        unsafe fn renderScale(&self) -> CGFloat;
221    }
222);
223
224extern "C" {
225    /// Indicates whether processing should happen at playback time
226    /// If set to NO (the default) the live photo will always be rendered before playback
227    /// If set to YES, the editing context might still choose to render first for performance reasons
228    /// This option is ignored by the saveLivePhotoToOutput method
229    ///
230    /// See also [Apple's documentation](https://developer.apple.com/documentation/photos/phlivephotoshouldrenderatplaybacktime?language=objc)
231    pub static PHLivePhotoShouldRenderAtPlaybackTime: &'static PHLivePhotoEditingOption;
232}
233
234extern "C" {
235    /// The error domain for all Live Photo Editing errors (Deprecated).
236    ///
237    /// See also [Apple's documentation](https://developer.apple.com/documentation/photos/phlivephotoeditingerrordomain?language=objc)
238    #[deprecated]
239    pub static PHLivePhotoEditingErrorDomain: &'static NSString;
240}
241
242/// Error code for Live Photo Editing errors (Deprecated)
243///
244/// See also [Apple's documentation](https://developer.apple.com/documentation/photos/phlivephotoeditingerrorcode?language=objc)
245// NS_ENUM
246#[repr(transparent)]
247#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
248pub struct PHLivePhotoEditingErrorCode(pub NSInteger);
249impl PHLivePhotoEditingErrorCode {
250    #[doc(alias = "PHLivePhotoEditingErrorCodeUnknown")]
251    #[deprecated]
252    pub const Unknown: Self = Self(0);
253    #[doc(alias = "PHLivePhotoEditingErrorCodeAborted")]
254    #[deprecated]
255    pub const Aborted: Self = Self(1);
256}
257
258unsafe impl Encode for PHLivePhotoEditingErrorCode {
259    const ENCODING: Encoding = NSInteger::ENCODING;
260}
261
262unsafe impl RefEncode for PHLivePhotoEditingErrorCode {
263    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
264}