objc2_metal_performance_shaders/generated/MPSImage/MPSImageResampling.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::*;
6use objc2_foundation::*;
7use objc2_metal::*;
8
9use crate::*;
10
11extern_class!(
12 /// Resize an image and / or change its aspect ratio
13 ///
14 /// The MPSImageScale filter can be used to resample an existing image
15 /// using a different sampling frequency in each dimension. This can be
16 /// used to enlarge or reduce the size of an image, or change the aspect
17 /// ratio of an image.
18 ///
19 /// The resample methods supported are:
20 /// Bilinear
21 /// Bicubcic
22 /// Lanczos
23 ///
24 /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpsimagescale?language=objc)
25 #[unsafe(super(MPSUnaryImageKernel, MPSKernel, NSObject))]
26 #[derive(Debug, PartialEq, Eq, Hash)]
27 #[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
28 pub struct MPSImageScale;
29);
30
31#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
32extern_conformance!(
33 unsafe impl NSCoding for MPSImageScale {}
34);
35
36#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
37extern_conformance!(
38 unsafe impl NSCopying for MPSImageScale {}
39);
40
41#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
42unsafe impl CopyingHelper for MPSImageScale {
43 type Result = Self;
44}
45
46#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
47extern_conformance!(
48 unsafe impl NSObjectProtocol for MPSImageScale {}
49);
50
51#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
52extern_conformance!(
53 unsafe impl NSSecureCoding for MPSImageScale {}
54);
55
56#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
57impl MPSImageScale {
58 extern_methods!(
59 #[unsafe(method(initWithDevice:))]
60 #[unsafe(method_family = init)]
61 pub unsafe fn initWithDevice(
62 this: Allocated<Self>,
63 device: &ProtocolObject<dyn MTLDevice>,
64 ) -> Retained<Self>;
65
66 #[cfg(feature = "MPSCoreTypes")]
67 /// An optional transform that describes how to scale and translate the source image
68 ///
69 /// If the scaleTransform is NULL, then any image scaling factor such as MPSImageLanczosScale
70 /// will rescale the image so that the source image fits exactly into the destination
71 /// texture. If the transform is not NULL, then the transform is used for determining
72 /// how to map the source image to the destination. Default: NULL
73 ///
74 /// When the scaleTransform is set to non-NULL, the values pointed to by the new
75 /// scaleTransform are copied to object storage, and the pointer is updated to point
76 /// to internal storage. Do not attempt to free it. You may free your copy of
77 /// the MPSScaleTransform as soon as the property set operation is complete.
78 ///
79 /// When calculating a scaleTransform, use the limits of the bounding box for the intended
80 /// source region of interest and the destination clipRect. Adjustments for pixel center
81 /// coordinates are handled internally to the function. For example,
82 /// the scale transform to convert the entire source image to the entire destination image
83 /// size (clipRect = MPSRectNoClip) would be:
84 ///
85 ///
86 /// ```text
87 /// scaleTransform.scaleX = (double) dest.width / source.width;
88 /// scaleTransform.scaleY = (double) dest.height / source.height;
89 /// scaleTransform.translateX = scaleTransform.translateY = 0.0;
90 /// ```
91 ///
92 /// The translation parameters allow you to adjust the region of the source image used
93 /// to create the destination image. They are in destination coordinates. To place the
94 /// top left corner of the destination clipRect to represent the position {x,y} in source
95 /// coordinates, we solve for the translation based on the standard scale matrix operation
96 /// for each axis:
97 ///
98 ///
99 /// ```text
100 /// dest_position = source_position * scale + translation;
101 /// translation = dest_position - source_position * scale;
102 /// ```
103 ///
104 /// For the top left corner of the clipRect, the dest_position is considered to be {0,0}.
105 /// This gives us a translation of:
106 ///
107 ///
108 /// ```text
109 /// scaleTransform.translateX = -source_origin.x * scaleTransform.scaleX;
110 /// scaleTransform.translateY = -source_origin.y * scaleTransform.scaleY;
111 /// ```
112 ///
113 /// One would typically use non-zero translations to do tiling, or provide a resized
114 /// view into a internal segment of an image.
115 ///
116 /// NOTE: Changing the Lanczos scale factor may trigger recalculation of signficant state internal
117 /// to the object when the filter is encoded to the command buffer. The scale factor is
118 /// scaleTransform->scaleX,Y, or the ratio of source and destination image sizes if
119 /// scaleTransform is NULL. Reuse a MPSImageLanczosScale object for frequently used scalings
120 /// to avoid redundantly recreating expensive resampling state.
121 #[unsafe(method(scaleTransform))]
122 #[unsafe(method_family = none)]
123 pub unsafe fn scaleTransform(&self) -> *const MPSScaleTransform;
124
125 #[cfg(feature = "MPSCoreTypes")]
126 /// Setter for [`scaleTransform`][Self::scaleTransform].
127 ///
128 /// # Safety
129 ///
130 /// `scale_transform` must be a valid pointer or null.
131 #[unsafe(method(setScaleTransform:))]
132 #[unsafe(method_family = none)]
133 pub unsafe fn setScaleTransform(&self, scale_transform: *const MPSScaleTransform);
134
135 /// NSSecureCoding compatability
136 ///
137 /// While the standard NSSecureCoding/NSCoding method
138 /// -initWithCoder: should work, since the file can't
139 /// know which device your data is allocated on, we
140 /// have to guess and may guess incorrectly. To avoid
141 /// that problem, use initWithCoder:device instead.
142 ///
143 /// Parameter `aDecoder`: The NSCoder subclass with your serialized MPSKernel
144 ///
145 /// Parameter `device`: The MTLDevice on which to make the MPSKernel
146 ///
147 /// Returns: A new MPSKernel object, or nil if failure.
148 ///
149 /// # Safety
150 ///
151 /// `a_decoder` possibly has further requirements.
152 #[unsafe(method(initWithCoder:device:))]
153 #[unsafe(method_family = init)]
154 pub unsafe fn initWithCoder_device(
155 this: Allocated<Self>,
156 a_decoder: &NSCoder,
157 device: &ProtocolObject<dyn MTLDevice>,
158 ) -> Option<Retained<Self>>;
159 );
160}
161
162/// Methods declared on superclass `MPSKernel`.
163#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
164impl MPSImageScale {
165 extern_methods!(
166 /// Called by NSCoder to decode MPSKernels
167 ///
168 /// This isn't the right interface to decode a MPSKernel, but
169 /// it is the one that NSCoder uses. To enable your NSCoder
170 /// (e.g. NSKeyedUnarchiver) to set which device to use
171 /// extend the object to adopt the MPSDeviceProvider
172 /// protocol. Otherwise, the Metal system default device
173 /// will be used.
174 ///
175 /// # Safety
176 ///
177 /// `a_decoder` possibly has further requirements.
178 #[unsafe(method(initWithCoder:))]
179 #[unsafe(method_family = init)]
180 pub unsafe fn initWithCoder(
181 this: Allocated<Self>,
182 a_decoder: &NSCoder,
183 ) -> Option<Retained<Self>>;
184 );
185}
186
187/// Methods declared on superclass `NSObject`.
188#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
189impl MPSImageScale {
190 extern_methods!(
191 #[unsafe(method(init))]
192 #[unsafe(method_family = init)]
193 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
194
195 #[unsafe(method(new))]
196 #[unsafe(method_family = new)]
197 pub unsafe fn new() -> Retained<Self>;
198 );
199}
200
201extern_class!(
202 /// Resize an image and / or change its aspect ratio
203 ///
204 /// The MPSImageLanczosScale filter can be used to resample an existing image
205 /// using a different sampling frequency in each dimension. This can be
206 /// used to enlarge or reduce the size of an image, or change the aspect
207 /// ratio of an image. The filter uses a Lanczos resampling algorithm
208 /// which typically produces better quality for photographs, but is slower
209 /// than linear sampling using the GPU texture units. Lanczos downsampling
210 /// does not require a low pass filter to be applied before it is used.
211 /// Because the resampling function has negative lobes, Lanczos can result
212 /// in ringing near sharp edges, making it less suitable for vector art.
213 ///
214 /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpsimagelanczosscale?language=objc)
215 #[unsafe(super(MPSImageScale, MPSUnaryImageKernel, MPSKernel, NSObject))]
216 #[derive(Debug, PartialEq, Eq, Hash)]
217 #[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
218 pub struct MPSImageLanczosScale;
219);
220
221#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
222extern_conformance!(
223 unsafe impl NSCoding for MPSImageLanczosScale {}
224);
225
226#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
227extern_conformance!(
228 unsafe impl NSCopying for MPSImageLanczosScale {}
229);
230
231#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
232unsafe impl CopyingHelper for MPSImageLanczosScale {
233 type Result = Self;
234}
235
236#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
237extern_conformance!(
238 unsafe impl NSObjectProtocol for MPSImageLanczosScale {}
239);
240
241#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
242extern_conformance!(
243 unsafe impl NSSecureCoding for MPSImageLanczosScale {}
244);
245
246#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
247impl MPSImageLanczosScale {
248 extern_methods!(
249 #[unsafe(method(initWithDevice:))]
250 #[unsafe(method_family = init)]
251 pub unsafe fn initWithDevice(
252 this: Allocated<Self>,
253 device: &ProtocolObject<dyn MTLDevice>,
254 ) -> Retained<Self>;
255
256 /// NSSecureCoding compatability
257 ///
258 /// While the standard NSSecureCoding/NSCoding method
259 /// -initWithCoder: should work, since the file can't
260 /// know which device your data is allocated on, we
261 /// have to guess and may guess incorrectly. To avoid
262 /// that problem, use initWithCoder:device instead.
263 ///
264 /// Parameter `aDecoder`: The NSCoder subclass with your serialized MPSKernel
265 ///
266 /// Parameter `device`: The MTLDevice on which to make the MPSKernel
267 ///
268 /// Returns: A new MPSKernel object, or nil if failure.
269 ///
270 /// # Safety
271 ///
272 /// `a_decoder` possibly has further requirements.
273 #[unsafe(method(initWithCoder:device:))]
274 #[unsafe(method_family = init)]
275 pub unsafe fn initWithCoder_device(
276 this: Allocated<Self>,
277 a_decoder: &NSCoder,
278 device: &ProtocolObject<dyn MTLDevice>,
279 ) -> Option<Retained<Self>>;
280 );
281}
282
283/// Methods declared on superclass `MPSKernel`.
284#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
285impl MPSImageLanczosScale {
286 extern_methods!(
287 /// Called by NSCoder to decode MPSKernels
288 ///
289 /// This isn't the right interface to decode a MPSKernel, but
290 /// it is the one that NSCoder uses. To enable your NSCoder
291 /// (e.g. NSKeyedUnarchiver) to set which device to use
292 /// extend the object to adopt the MPSDeviceProvider
293 /// protocol. Otherwise, the Metal system default device
294 /// will be used.
295 ///
296 /// # Safety
297 ///
298 /// `a_decoder` possibly has further requirements.
299 #[unsafe(method(initWithCoder:))]
300 #[unsafe(method_family = init)]
301 pub unsafe fn initWithCoder(
302 this: Allocated<Self>,
303 a_decoder: &NSCoder,
304 ) -> Option<Retained<Self>>;
305 );
306}
307
308/// Methods declared on superclass `NSObject`.
309#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
310impl MPSImageLanczosScale {
311 extern_methods!(
312 #[unsafe(method(init))]
313 #[unsafe(method_family = init)]
314 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
315
316 #[unsafe(method(new))]
317 #[unsafe(method_family = new)]
318 pub unsafe fn new() -> Retained<Self>;
319 );
320}
321
322extern_class!(
323 /// Resize an image and / or change its aspect ratio
324 ///
325 /// The MPSImageBilinearScale filter can be used to resample an existing image
326 /// using a bilinear filter. This is typically used to reduce the size of an image.
327 ///
328 /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpsimagebilinearscale?language=objc)
329 #[unsafe(super(MPSImageScale, MPSUnaryImageKernel, MPSKernel, NSObject))]
330 #[derive(Debug, PartialEq, Eq, Hash)]
331 #[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
332 pub struct MPSImageBilinearScale;
333);
334
335#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
336extern_conformance!(
337 unsafe impl NSCoding for MPSImageBilinearScale {}
338);
339
340#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
341extern_conformance!(
342 unsafe impl NSCopying for MPSImageBilinearScale {}
343);
344
345#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
346unsafe impl CopyingHelper for MPSImageBilinearScale {
347 type Result = Self;
348}
349
350#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
351extern_conformance!(
352 unsafe impl NSObjectProtocol for MPSImageBilinearScale {}
353);
354
355#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
356extern_conformance!(
357 unsafe impl NSSecureCoding for MPSImageBilinearScale {}
358);
359
360#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
361impl MPSImageBilinearScale {
362 extern_methods!(
363 #[unsafe(method(initWithDevice:))]
364 #[unsafe(method_family = init)]
365 pub unsafe fn initWithDevice(
366 this: Allocated<Self>,
367 device: &ProtocolObject<dyn MTLDevice>,
368 ) -> Retained<Self>;
369
370 /// NSSecureCoding compatability
371 ///
372 /// While the standard NSSecureCoding/NSCoding method
373 /// -initWithCoder: should work, since the file can't
374 /// know which device your data is allocated on, we
375 /// have to guess and may guess incorrectly. To avoid
376 /// that problem, use initWithCoder:device instead.
377 ///
378 /// Parameter `aDecoder`: The NSCoder subclass with your serialized MPSKernel
379 ///
380 /// Parameter `device`: The MTLDevice on which to make the MPSKernel
381 ///
382 /// Returns: A new MPSKernel object, or nil if failure.
383 ///
384 /// # Safety
385 ///
386 /// `a_decoder` possibly has further requirements.
387 #[unsafe(method(initWithCoder:device:))]
388 #[unsafe(method_family = init)]
389 pub unsafe fn initWithCoder_device(
390 this: Allocated<Self>,
391 a_decoder: &NSCoder,
392 device: &ProtocolObject<dyn MTLDevice>,
393 ) -> Option<Retained<Self>>;
394 );
395}
396
397/// Methods declared on superclass `MPSKernel`.
398#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
399impl MPSImageBilinearScale {
400 extern_methods!(
401 /// Called by NSCoder to decode MPSKernels
402 ///
403 /// This isn't the right interface to decode a MPSKernel, but
404 /// it is the one that NSCoder uses. To enable your NSCoder
405 /// (e.g. NSKeyedUnarchiver) to set which device to use
406 /// extend the object to adopt the MPSDeviceProvider
407 /// protocol. Otherwise, the Metal system default device
408 /// will be used.
409 ///
410 /// # Safety
411 ///
412 /// `a_decoder` possibly has further requirements.
413 #[unsafe(method(initWithCoder:))]
414 #[unsafe(method_family = init)]
415 pub unsafe fn initWithCoder(
416 this: Allocated<Self>,
417 a_decoder: &NSCoder,
418 ) -> Option<Retained<Self>>;
419 );
420}
421
422/// Methods declared on superclass `NSObject`.
423#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
424impl MPSImageBilinearScale {
425 extern_methods!(
426 #[unsafe(method(init))]
427 #[unsafe(method_family = init)]
428 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
429
430 #[unsafe(method(new))]
431 #[unsafe(method_family = new)]
432 pub unsafe fn new() -> Retained<Self>;
433 );
434}