objc2_metal_performance_shaders/generated/MPSImage/MPSImageConvolution.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 /// The MPSImageConvolution convolves an image with given filter of odd width and height.
13 /// The center of the kernel aligns with the MPSImageConvolution.offset. That is, the position
14 /// of the top left corner of the area covered by the kernel is given by
15 /// MPSImageConvolution.offset - {kernel_width>>1, kernel_height>>1, 0}
16 ///
17 /// Optimized cases include 3x3,5x5,7x7,9x9,11x11, 1xN and Nx1. If a convolution kernel
18 /// does not fall into one of these cases but is a rank-1 matrix (a.k.a. separable)
19 /// then it will fall on an optimzied separable path. Other convolutions will execute with
20 /// full MxN complexity.
21 ///
22 /// If there are multiple channels in the source image, each channel is processed independently.
23 ///
24 ///
25 /// Performance: Separable convolution filters may perform better when done in two passes. A convolution filter
26 /// is separable if the ratio of filter values between all rows is constant over the whole row. For
27 /// example, this edge detection filter:
28 ///
29 /// ```text
30 /// -1 0 1
31 /// -2 0 2
32 /// -1 0 1
33 /// ```
34 ///
35 /// can be separated into the product of two vectors:
36 ///
37 /// ```text
38 /// 1
39 /// 2 x [-1 0 1]
40 /// 1
41 /// ```
42 ///
43 /// and consequently can be done as two, one-dimensional convolution passes back to back on the same image.
44 /// In this way, the number of multiplies (ignoring the fact that we could skip zeros here) is reduced from
45 /// 3*3=9 to 3+3 = 6. There are similar savings for addition. For large filters, the savings can be profound.
46 ///
47 /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpsimageconvolution?language=objc)
48 #[unsafe(super(MPSUnaryImageKernel, MPSKernel, NSObject))]
49 #[derive(Debug, PartialEq, Eq, Hash)]
50 #[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
51 pub struct MPSImageConvolution;
52);
53
54#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
55extern_conformance!(
56 unsafe impl NSCoding for MPSImageConvolution {}
57);
58
59#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
60extern_conformance!(
61 unsafe impl NSCopying for MPSImageConvolution {}
62);
63
64#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
65unsafe impl CopyingHelper for MPSImageConvolution {
66 type Result = Self;
67}
68
69#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
70extern_conformance!(
71 unsafe impl NSObjectProtocol for MPSImageConvolution {}
72);
73
74#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
75extern_conformance!(
76 unsafe impl NSSecureCoding for MPSImageConvolution {}
77);
78
79#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
80impl MPSImageConvolution {
81 extern_methods!(
82 /// The height of the filter window. Must be an odd number.
83 #[unsafe(method(kernelHeight))]
84 #[unsafe(method_family = none)]
85 pub unsafe fn kernelHeight(&self) -> NSUInteger;
86
87 /// The width of the filter window. Must be an odd number.
88 #[unsafe(method(kernelWidth))]
89 #[unsafe(method_family = none)]
90 pub unsafe fn kernelWidth(&self) -> NSUInteger;
91
92 /// The bias is a value to be added to convolved pixel before it is converted back to the storage format.
93 /// It can be used to convert negative values into a representable range for a unsigned MTLPixelFormat.
94 /// For example, many edge detection filters produce results in the range [-k,k]. By scaling the filter
95 /// weights by 0.5/k and adding 0.5, the results will be in range [0,1] suitable for use with unorm formats.
96 /// It can be used in combination with renormalization of the filter weights to do video ranging as part
97 /// of the convolution effect. It can also just be used to increase the brightness of the image.
98 ///
99 /// Default value is 0.0f.
100 #[unsafe(method(bias))]
101 #[unsafe(method_family = none)]
102 pub unsafe fn bias(&self) -> c_float;
103
104 /// Setter for [`bias`][Self::bias].
105 #[unsafe(method(setBias:))]
106 #[unsafe(method_family = none)]
107 pub unsafe fn setBias(&self, bias: c_float);
108
109 /// Initialize a convolution filter
110 ///
111 /// Parameter `device`: The device the filter will run on
112 ///
113 /// Parameter `kernelWidth`: the width of the kernel
114 ///
115 /// Parameter `kernelHeight`: the height of the kernel
116 ///
117 /// Parameter `kernelWeights`: A pointer to an array of kernelWidth * kernelHeight values to be used as the kernel.
118 /// These are in row major order.
119 ///
120 /// Returns: A valid MPSImageConvolution object or nil, if failure.
121 ///
122 /// # Safety
123 ///
124 /// `kernel_weights` must be a valid pointer.
125 #[unsafe(method(initWithDevice:kernelWidth:kernelHeight:weights:))]
126 #[unsafe(method_family = init)]
127 pub unsafe fn initWithDevice_kernelWidth_kernelHeight_weights(
128 this: Allocated<Self>,
129 device: &ProtocolObject<dyn MTLDevice>,
130 kernel_width: NSUInteger,
131 kernel_height: NSUInteger,
132 kernel_weights: NonNull<c_float>,
133 ) -> Retained<Self>;
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 `MPSUnaryImageKernel`.
163#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
164impl MPSImageConvolution {
165 extern_methods!(
166 /// Standard init with default properties per filter type
167 ///
168 /// Parameter `device`: The device that the filter will be used on. May not be NULL.
169 ///
170 /// Returns: a pointer to the newly initialized object. This will fail, returning
171 /// nil if the device is not supported. Devices must be
172 /// MTLFeatureSet_iOS_GPUFamily2_v1 or later.
173 #[unsafe(method(initWithDevice:))]
174 #[unsafe(method_family = init)]
175 pub unsafe fn initWithDevice(
176 this: Allocated<Self>,
177 device: &ProtocolObject<dyn MTLDevice>,
178 ) -> Retained<Self>;
179 );
180}
181
182/// Methods declared on superclass `MPSKernel`.
183#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
184impl MPSImageConvolution {
185 extern_methods!(
186 /// Called by NSCoder to decode MPSKernels
187 ///
188 /// This isn't the right interface to decode a MPSKernel, but
189 /// it is the one that NSCoder uses. To enable your NSCoder
190 /// (e.g. NSKeyedUnarchiver) to set which device to use
191 /// extend the object to adopt the MPSDeviceProvider
192 /// protocol. Otherwise, the Metal system default device
193 /// will be used.
194 ///
195 /// # Safety
196 ///
197 /// `a_decoder` possibly has further requirements.
198 #[unsafe(method(initWithCoder:))]
199 #[unsafe(method_family = init)]
200 pub unsafe fn initWithCoder(
201 this: Allocated<Self>,
202 a_decoder: &NSCoder,
203 ) -> Option<Retained<Self>>;
204 );
205}
206
207/// Methods declared on superclass `NSObject`.
208#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
209impl MPSImageConvolution {
210 extern_methods!(
211 #[unsafe(method(init))]
212 #[unsafe(method_family = init)]
213 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
214
215 #[unsafe(method(new))]
216 #[unsafe(method_family = new)]
217 pub unsafe fn new() -> Retained<Self>;
218 );
219}
220
221extern_class!(
222 /// The MPSImageLaplacian is an optimized variant of the MPSImageConvolution filter provided primarily for ease of use.
223 /// This filter uses an optimized convolution filter with a 3 x 3 kernel with the following weights:
224 /// [ 0 1 0
225 /// 1 -4 1
226 /// 0 1 0 ]
227 ///
228 /// The optimized convolution filter used by MPSImageLaplacian can also be used by creating a MPSImageConvolution
229 /// object with kernelWidth = 3, kernelHeight = 3 and weights as specified above.
230 ///
231 /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpsimagelaplacian?language=objc)
232 #[unsafe(super(MPSUnaryImageKernel, MPSKernel, NSObject))]
233 #[derive(Debug, PartialEq, Eq, Hash)]
234 #[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
235 pub struct MPSImageLaplacian;
236);
237
238#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
239extern_conformance!(
240 unsafe impl NSCoding for MPSImageLaplacian {}
241);
242
243#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
244extern_conformance!(
245 unsafe impl NSCopying for MPSImageLaplacian {}
246);
247
248#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
249unsafe impl CopyingHelper for MPSImageLaplacian {
250 type Result = Self;
251}
252
253#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
254extern_conformance!(
255 unsafe impl NSObjectProtocol for MPSImageLaplacian {}
256);
257
258#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
259extern_conformance!(
260 unsafe impl NSSecureCoding for MPSImageLaplacian {}
261);
262
263#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
264impl MPSImageLaplacian {
265 extern_methods!(
266 /// The bias is a value to be added to convolved pixel before it is converted back to the storage format.
267 /// It can be used to convert negative values into a representable range for a unsigned MTLPixelFormat.
268 /// For example, many edge detection filters produce results in the range [-k,k]. By scaling the filter
269 /// weights by 0.5/k and adding 0.5, the results will be in range [0,1] suitable for use with unorm formats.
270 /// It can be used in combination with renormalization of the filter weights to do video ranging as part
271 /// of the convolution effect. It can also just be used to increase the brightness of the image.
272 ///
273 /// Default value is 0.0f.
274 #[unsafe(method(bias))]
275 #[unsafe(method_family = none)]
276 pub unsafe fn bias(&self) -> c_float;
277
278 /// Setter for [`bias`][Self::bias].
279 #[unsafe(method(setBias:))]
280 #[unsafe(method_family = none)]
281 pub unsafe fn setBias(&self, bias: c_float);
282 );
283}
284
285/// Methods declared on superclass `MPSUnaryImageKernel`.
286#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
287impl MPSImageLaplacian {
288 extern_methods!(
289 /// Standard init with default properties per filter type
290 ///
291 /// Parameter `device`: The device that the filter will be used on. May not be NULL.
292 ///
293 /// Returns: a pointer to the newly initialized object. This will fail, returning
294 /// nil if the device is not supported. Devices must be
295 /// MTLFeatureSet_iOS_GPUFamily2_v1 or later.
296 #[unsafe(method(initWithDevice:))]
297 #[unsafe(method_family = init)]
298 pub unsafe fn initWithDevice(
299 this: Allocated<Self>,
300 device: &ProtocolObject<dyn MTLDevice>,
301 ) -> Retained<Self>;
302
303 /// NSSecureCoding compatability
304 ///
305 /// While the standard NSSecureCoding/NSCoding method
306 /// -initWithCoder: should work, since the file can't
307 /// know which device your data is allocated on, we
308 /// have to guess and may guess incorrectly. To avoid
309 /// that problem, use initWithCoder:device instead.
310 ///
311 /// Parameter `aDecoder`: The NSCoder subclass with your serialized MPSKernel
312 ///
313 /// Parameter `device`: The MTLDevice on which to make the MPSKernel
314 ///
315 /// Returns: A new MPSKernel object, or nil if failure.
316 ///
317 /// # Safety
318 ///
319 /// `a_decoder` possibly has further requirements.
320 #[unsafe(method(initWithCoder:device:))]
321 #[unsafe(method_family = init)]
322 pub unsafe fn initWithCoder_device(
323 this: Allocated<Self>,
324 a_decoder: &NSCoder,
325 device: &ProtocolObject<dyn MTLDevice>,
326 ) -> Option<Retained<Self>>;
327 );
328}
329
330/// Methods declared on superclass `MPSKernel`.
331#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
332impl MPSImageLaplacian {
333 extern_methods!(
334 /// Called by NSCoder to decode MPSKernels
335 ///
336 /// This isn't the right interface to decode a MPSKernel, but
337 /// it is the one that NSCoder uses. To enable your NSCoder
338 /// (e.g. NSKeyedUnarchiver) to set which device to use
339 /// extend the object to adopt the MPSDeviceProvider
340 /// protocol. Otherwise, the Metal system default device
341 /// will be used.
342 ///
343 /// # Safety
344 ///
345 /// `a_decoder` possibly has further requirements.
346 #[unsafe(method(initWithCoder:))]
347 #[unsafe(method_family = init)]
348 pub unsafe fn initWithCoder(
349 this: Allocated<Self>,
350 a_decoder: &NSCoder,
351 ) -> Option<Retained<Self>>;
352 );
353}
354
355/// Methods declared on superclass `NSObject`.
356#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
357impl MPSImageLaplacian {
358 extern_methods!(
359 #[unsafe(method(init))]
360 #[unsafe(method_family = init)]
361 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
362
363 #[unsafe(method(new))]
364 #[unsafe(method_family = new)]
365 pub unsafe fn new() -> Retained<Self>;
366 );
367}
368
369extern_class!(
370 /// The MPSImageBox convolves an image with given filter of odd width and height. The kernel elements
371 /// all have equal weight, achieving a blur effect. (Each result is the unweighted average of the
372 /// surrounding pixels.) This allows for much faster algorithms, espcially for larger blur radii.
373 /// The box height and width must be odd numbers. The box blur is a separable filter. The implementation
374 /// is aware of this and will act accordingly to give best performance for multi-dimensional blurs.
375 ///
376 /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpsimagebox?language=objc)
377 #[unsafe(super(MPSUnaryImageKernel, MPSKernel, NSObject))]
378 #[derive(Debug, PartialEq, Eq, Hash)]
379 #[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
380 pub struct MPSImageBox;
381);
382
383#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
384extern_conformance!(
385 unsafe impl NSCoding for MPSImageBox {}
386);
387
388#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
389extern_conformance!(
390 unsafe impl NSCopying for MPSImageBox {}
391);
392
393#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
394unsafe impl CopyingHelper for MPSImageBox {
395 type Result = Self;
396}
397
398#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
399extern_conformance!(
400 unsafe impl NSObjectProtocol for MPSImageBox {}
401);
402
403#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
404extern_conformance!(
405 unsafe impl NSSecureCoding for MPSImageBox {}
406);
407
408#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
409impl MPSImageBox {
410 extern_methods!(
411 /// The height of the filter window.
412 #[unsafe(method(kernelHeight))]
413 #[unsafe(method_family = none)]
414 pub unsafe fn kernelHeight(&self) -> NSUInteger;
415
416 /// The width of the filter window.
417 #[unsafe(method(kernelWidth))]
418 #[unsafe(method_family = none)]
419 pub unsafe fn kernelWidth(&self) -> NSUInteger;
420
421 /// Initialize a filter for a particular kernel size and device
422 ///
423 /// Parameter `device`: The device the filter will run on
424 ///
425 /// Parameter `kernelWidth`: the width of the kernel. Must be an odd number.
426 ///
427 /// Parameter `kernelHeight`: the height of the kernel. Must be an odd number.
428 ///
429 /// Returns: A valid object or nil, if failure.
430 #[unsafe(method(initWithDevice:kernelWidth:kernelHeight:))]
431 #[unsafe(method_family = init)]
432 pub unsafe fn initWithDevice_kernelWidth_kernelHeight(
433 this: Allocated<Self>,
434 device: &ProtocolObject<dyn MTLDevice>,
435 kernel_width: NSUInteger,
436 kernel_height: NSUInteger,
437 ) -> Retained<Self>;
438
439 /// NSSecureCoding compatability
440 ///
441 /// While the standard NSSecureCoding/NSCoding method
442 /// -initWithCoder: should work, since the file can't
443 /// know which device your data is allocated on, we
444 /// have to guess and may guess incorrectly. To avoid
445 /// that problem, use initWithCoder:device instead.
446 ///
447 /// Parameter `aDecoder`: The NSCoder subclass with your serialized MPSKernel
448 ///
449 /// Parameter `device`: The MTLDevice on which to make the MPSKernel
450 ///
451 /// Returns: A new MPSKernel object, or nil if failure.
452 ///
453 /// # Safety
454 ///
455 /// `a_decoder` possibly has further requirements.
456 #[unsafe(method(initWithCoder:device:))]
457 #[unsafe(method_family = init)]
458 pub unsafe fn initWithCoder_device(
459 this: Allocated<Self>,
460 a_decoder: &NSCoder,
461 device: &ProtocolObject<dyn MTLDevice>,
462 ) -> Option<Retained<Self>>;
463
464 #[unsafe(method(initWithDevice:))]
465 #[unsafe(method_family = init)]
466 pub unsafe fn initWithDevice(
467 this: Allocated<Self>,
468 device: &ProtocolObject<dyn MTLDevice>,
469 ) -> Retained<Self>;
470 );
471}
472
473/// Methods declared on superclass `MPSKernel`.
474#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
475impl MPSImageBox {
476 extern_methods!(
477 /// Called by NSCoder to decode MPSKernels
478 ///
479 /// This isn't the right interface to decode a MPSKernel, but
480 /// it is the one that NSCoder uses. To enable your NSCoder
481 /// (e.g. NSKeyedUnarchiver) to set which device to use
482 /// extend the object to adopt the MPSDeviceProvider
483 /// protocol. Otherwise, the Metal system default device
484 /// will be used.
485 ///
486 /// # Safety
487 ///
488 /// `a_decoder` possibly has further requirements.
489 #[unsafe(method(initWithCoder:))]
490 #[unsafe(method_family = init)]
491 pub unsafe fn initWithCoder(
492 this: Allocated<Self>,
493 a_decoder: &NSCoder,
494 ) -> Option<Retained<Self>>;
495 );
496}
497
498/// Methods declared on superclass `NSObject`.
499#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
500impl MPSImageBox {
501 extern_methods!(
502 #[unsafe(method(init))]
503 #[unsafe(method_family = init)]
504 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
505
506 #[unsafe(method(new))]
507 #[unsafe(method_family = new)]
508 pub unsafe fn new() -> Retained<Self>;
509 );
510}
511
512extern_class!(
513 /// The box filter, while fast, may yield square-ish looking blur effects. However, multiple
514 /// passes of the box filter tend to smooth out with each additional pass. For example, two 3-wide
515 /// box blurs produces the same effective convolution as a 5-wide tent blur:
516 ///
517 /// ```text
518 /// 1 1 1
519 /// 1 1 1
520 /// + 1 1 1
521 /// =================
522 /// 1 2 3 2 1
523 /// ```
524 ///
525 /// Addition passes tend to approximate a gaussian line shape.
526 ///
527 /// The MPSImageTent convolves an image with a tent filter. These form a tent shape with incrementally
528 /// increasing sides, for example:
529 ///
530 /// 1 2 3 2 1
531 ///
532 /// 1 2 1
533 /// 2 4 2
534 /// 1 2 1
535 ///
536 /// Like the box filter, this arrangement allows for much faster algorithms, espcially for for larger blur
537 /// radii but with a more pleasing appearance.
538 ///
539 /// The tent blur is a separable filter. The implementation is aware of this and will act accordingly
540 /// to give best performance for multi-dimensional blurs.
541 ///
542 /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpsimagetent?language=objc)
543 #[unsafe(super(MPSImageBox, MPSUnaryImageKernel, MPSKernel, NSObject))]
544 #[derive(Debug, PartialEq, Eq, Hash)]
545 #[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
546 pub struct MPSImageTent;
547);
548
549#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
550extern_conformance!(
551 unsafe impl NSCoding for MPSImageTent {}
552);
553
554#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
555extern_conformance!(
556 unsafe impl NSCopying for MPSImageTent {}
557);
558
559#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
560unsafe impl CopyingHelper for MPSImageTent {
561 type Result = Self;
562}
563
564#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
565extern_conformance!(
566 unsafe impl NSObjectProtocol for MPSImageTent {}
567);
568
569#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
570extern_conformance!(
571 unsafe impl NSSecureCoding for MPSImageTent {}
572);
573
574#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
575impl MPSImageTent {
576 extern_methods!();
577}
578
579/// Methods declared on superclass `MPSImageBox`.
580#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
581impl MPSImageTent {
582 extern_methods!(
583 /// Initialize a filter for a particular kernel size and device
584 ///
585 /// Parameter `device`: The device the filter will run on
586 ///
587 /// Parameter `kernelWidth`: the width of the kernel. Must be an odd number.
588 ///
589 /// Parameter `kernelHeight`: the height of the kernel. Must be an odd number.
590 ///
591 /// Returns: A valid object or nil, if failure.
592 #[unsafe(method(initWithDevice:kernelWidth:kernelHeight:))]
593 #[unsafe(method_family = init)]
594 pub unsafe fn initWithDevice_kernelWidth_kernelHeight(
595 this: Allocated<Self>,
596 device: &ProtocolObject<dyn MTLDevice>,
597 kernel_width: NSUInteger,
598 kernel_height: NSUInteger,
599 ) -> Retained<Self>;
600
601 /// NSSecureCoding compatability
602 ///
603 /// While the standard NSSecureCoding/NSCoding method
604 /// -initWithCoder: should work, since the file can't
605 /// know which device your data is allocated on, we
606 /// have to guess and may guess incorrectly. To avoid
607 /// that problem, use initWithCoder:device instead.
608 ///
609 /// Parameter `aDecoder`: The NSCoder subclass with your serialized MPSKernel
610 ///
611 /// Parameter `device`: The MTLDevice on which to make the MPSKernel
612 ///
613 /// Returns: A new MPSKernel object, or nil if failure.
614 ///
615 /// # Safety
616 ///
617 /// `a_decoder` possibly has further requirements.
618 #[unsafe(method(initWithCoder:device:))]
619 #[unsafe(method_family = init)]
620 pub unsafe fn initWithCoder_device(
621 this: Allocated<Self>,
622 a_decoder: &NSCoder,
623 device: &ProtocolObject<dyn MTLDevice>,
624 ) -> Option<Retained<Self>>;
625
626 #[unsafe(method(initWithDevice:))]
627 #[unsafe(method_family = init)]
628 pub unsafe fn initWithDevice(
629 this: Allocated<Self>,
630 device: &ProtocolObject<dyn MTLDevice>,
631 ) -> Retained<Self>;
632 );
633}
634
635/// Methods declared on superclass `MPSKernel`.
636#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
637impl MPSImageTent {
638 extern_methods!(
639 /// Called by NSCoder to decode MPSKernels
640 ///
641 /// This isn't the right interface to decode a MPSKernel, but
642 /// it is the one that NSCoder uses. To enable your NSCoder
643 /// (e.g. NSKeyedUnarchiver) to set which device to use
644 /// extend the object to adopt the MPSDeviceProvider
645 /// protocol. Otherwise, the Metal system default device
646 /// will be used.
647 ///
648 /// # Safety
649 ///
650 /// `a_decoder` possibly has further requirements.
651 #[unsafe(method(initWithCoder:))]
652 #[unsafe(method_family = init)]
653 pub unsafe fn initWithCoder(
654 this: Allocated<Self>,
655 a_decoder: &NSCoder,
656 ) -> Option<Retained<Self>>;
657 );
658}
659
660/// Methods declared on superclass `NSObject`.
661#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
662impl MPSImageTent {
663 extern_methods!(
664 #[unsafe(method(init))]
665 #[unsafe(method_family = init)]
666 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
667
668 #[unsafe(method(new))]
669 #[unsafe(method_family = new)]
670 pub unsafe fn new() -> Retained<Self>;
671 );
672}
673
674extern_class!(
675 /// The MPSImageGaussianBlur convolves an image with gaussian of given sigma in both x and y direction.
676 ///
677 /// The MPSImageGaussianBlur utilizes a very fast algorith that typically runs at approximately
678 /// 1/2 of copy speeds. Notably, it is faster than either the tent or box blur except perhaps
679 /// for very large filter windows. Mathematically, it is an approximate gaussian. Some
680 /// non-gaussian behavior may be detectable with advanced analytical methods such as FFT.
681 /// If a analytically clean gaussian filter is required, please use the MPSImageConvolution
682 /// filter instead with an appropriate set of weights. The MPSImageGaussianBlur is intended
683 /// to be suitable for all common image processing needs demanding ~10 bits of precision or
684 /// less.
685 ///
686 /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpsimagegaussianblur?language=objc)
687 #[unsafe(super(MPSUnaryImageKernel, MPSKernel, NSObject))]
688 #[derive(Debug, PartialEq, Eq, Hash)]
689 #[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
690 pub struct MPSImageGaussianBlur;
691);
692
693#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
694extern_conformance!(
695 unsafe impl NSCoding for MPSImageGaussianBlur {}
696);
697
698#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
699extern_conformance!(
700 unsafe impl NSCopying for MPSImageGaussianBlur {}
701);
702
703#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
704unsafe impl CopyingHelper for MPSImageGaussianBlur {
705 type Result = Self;
706}
707
708#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
709extern_conformance!(
710 unsafe impl NSObjectProtocol for MPSImageGaussianBlur {}
711);
712
713#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
714extern_conformance!(
715 unsafe impl NSSecureCoding for MPSImageGaussianBlur {}
716);
717
718#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
719impl MPSImageGaussianBlur {
720 extern_methods!(
721 /// Initialize a gaussian blur filter for a particular sigma and device
722 ///
723 /// Parameter `device`: The device the filter will run on
724 ///
725 /// Parameter `sigma`: The standard deviation of gaussian blur filter.
726 /// Gaussian weight, centered at 0, at integer grid i is given as
727 /// w(i) = 1/sqrt(2*pi*sigma) * exp(-i^2/(2*sigma^2))
728 /// If we take cut off at 1% of w(0) (max weight) beyond which weights
729 /// are considered 0, we have
730 /// ceil (sqrt(-log(0.01)*2)*sigma) ~ ceil(3.7*sigma)
731 /// as rough estimate of filter width
732 ///
733 /// Returns: A valid object or nil, if failure.
734 #[unsafe(method(initWithDevice:sigma:))]
735 #[unsafe(method_family = init)]
736 pub unsafe fn initWithDevice_sigma(
737 this: Allocated<Self>,
738 device: &ProtocolObject<dyn MTLDevice>,
739 sigma: c_float,
740 ) -> Retained<Self>;
741
742 /// NSSecureCoding compatability
743 ///
744 /// While the standard NSSecureCoding/NSCoding method
745 /// -initWithCoder: should work, since the file can't
746 /// know which device your data is allocated on, we
747 /// have to guess and may guess incorrectly. To avoid
748 /// that problem, use initWithCoder:device instead.
749 ///
750 /// Parameter `aDecoder`: The NSCoder subclass with your serialized MPSKernel
751 ///
752 /// Parameter `device`: The MTLDevice on which to make the MPSKernel
753 ///
754 /// Returns: A new MPSKernel object, or nil if failure.
755 ///
756 /// # Safety
757 ///
758 /// `a_decoder` possibly has further requirements.
759 #[unsafe(method(initWithCoder:device:))]
760 #[unsafe(method_family = init)]
761 pub unsafe fn initWithCoder_device(
762 this: Allocated<Self>,
763 a_decoder: &NSCoder,
764 device: &ProtocolObject<dyn MTLDevice>,
765 ) -> Option<Retained<Self>>;
766
767 #[unsafe(method(initWithDevice:))]
768 #[unsafe(method_family = init)]
769 pub unsafe fn initWithDevice(
770 this: Allocated<Self>,
771 device: &ProtocolObject<dyn MTLDevice>,
772 ) -> Retained<Self>;
773
774 /// Read-only sigma value with which filter was created
775 #[unsafe(method(sigma))]
776 #[unsafe(method_family = none)]
777 pub unsafe fn sigma(&self) -> c_float;
778 );
779}
780
781/// Methods declared on superclass `MPSKernel`.
782#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
783impl MPSImageGaussianBlur {
784 extern_methods!(
785 /// Called by NSCoder to decode MPSKernels
786 ///
787 /// This isn't the right interface to decode a MPSKernel, but
788 /// it is the one that NSCoder uses. To enable your NSCoder
789 /// (e.g. NSKeyedUnarchiver) to set which device to use
790 /// extend the object to adopt the MPSDeviceProvider
791 /// protocol. Otherwise, the Metal system default device
792 /// will be used.
793 ///
794 /// # Safety
795 ///
796 /// `a_decoder` possibly has further requirements.
797 #[unsafe(method(initWithCoder:))]
798 #[unsafe(method_family = init)]
799 pub unsafe fn initWithCoder(
800 this: Allocated<Self>,
801 a_decoder: &NSCoder,
802 ) -> Option<Retained<Self>>;
803 );
804}
805
806/// Methods declared on superclass `NSObject`.
807#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
808impl MPSImageGaussianBlur {
809 extern_methods!(
810 #[unsafe(method(init))]
811 #[unsafe(method_family = init)]
812 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
813
814 #[unsafe(method(new))]
815 #[unsafe(method_family = new)]
816 pub unsafe fn new() -> Retained<Self>;
817 );
818}
819
820extern_class!(
821 /// The MPSImageSobel implements the Sobel filter.
822 /// When the color model (e.g. RGB, two-channel, grayscale, etc.) of source
823 /// and destination textures match, the filter is applied to each channel
824 /// separately. If the destination is monochrome (single channel) but source
825 /// multichannel, the pixel values are converted to grayscale before applying Sobel
826 /// operator using the linear gray color transform vector (v).
827 ///
828 /// Luminance = v[0] * pixel.x + v[1] * pixel.y + v[2] * pixel.z;
829 ///
830 /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpsimagesobel?language=objc)
831 #[unsafe(super(MPSUnaryImageKernel, MPSKernel, NSObject))]
832 #[derive(Debug, PartialEq, Eq, Hash)]
833 #[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
834 pub struct MPSImageSobel;
835);
836
837#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
838extern_conformance!(
839 unsafe impl NSCoding for MPSImageSobel {}
840);
841
842#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
843extern_conformance!(
844 unsafe impl NSCopying for MPSImageSobel {}
845);
846
847#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
848unsafe impl CopyingHelper for MPSImageSobel {
849 type Result = Self;
850}
851
852#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
853extern_conformance!(
854 unsafe impl NSObjectProtocol for MPSImageSobel {}
855);
856
857#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
858extern_conformance!(
859 unsafe impl NSSecureCoding for MPSImageSobel {}
860);
861
862#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
863impl MPSImageSobel {
864 extern_methods!(
865 /// Initialize a Sobel filter on a given device using the default color
866 /// transform. Default: BT.601/JPEG {0.299f, 0.587f, 0.114f}
867 ///
868 /// For non-default conversion matrices, use -initWithDevice:linearGrayColorTransform:
869 ///
870 ///
871 /// Parameter `device`: The device the filter will run on
872 ///
873 /// Returns: A valid object or nil, if failure.
874 #[unsafe(method(initWithDevice:))]
875 #[unsafe(method_family = init)]
876 pub unsafe fn initWithDevice(
877 this: Allocated<Self>,
878 device: &ProtocolObject<dyn MTLDevice>,
879 ) -> Retained<Self>;
880
881 /// Initialize a Sobel filter on a given device with a non-default color transform
882 ///
883 /// Parameter `device`: The device the filter will run on
884 ///
885 /// Parameter `transform`: Array of three floats describing the rgb to gray scale color transform.
886 ///
887 /// ```text
888 /// Luminance = transform[0] * pixel.x +
889 /// transform[1] * pixel.y +
890 /// transform[2] * pixel.z;
891 /// ```
892 ///
893 ///
894 /// Returns: A valid object or nil, if failure.
895 ///
896 /// # Safety
897 ///
898 /// `transform` must be a valid pointer.
899 #[unsafe(method(initWithDevice:linearGrayColorTransform:))]
900 #[unsafe(method_family = init)]
901 pub unsafe fn initWithDevice_linearGrayColorTransform(
902 this: Allocated<Self>,
903 device: &ProtocolObject<dyn MTLDevice>,
904 transform: NonNull<c_float>,
905 ) -> Retained<Self>;
906
907 /// NSSecureCoding compatability
908 ///
909 /// While the standard NSSecureCoding/NSCoding method
910 /// -initWithCoder: should work, since the file can't
911 /// know which device your data is allocated on, we
912 /// have to guess and may guess incorrectly. To avoid
913 /// that problem, use initWithCoder:device instead.
914 ///
915 /// Parameter `aDecoder`: The NSCoder subclass with your serialized MPSKernel
916 ///
917 /// Parameter `device`: The MTLDevice on which to make the MPSKernel
918 ///
919 /// Returns: A new MPSKernel object, or nil if failure.
920 ///
921 /// # Safety
922 ///
923 /// `a_decoder` possibly has further requirements.
924 #[unsafe(method(initWithCoder:device:))]
925 #[unsafe(method_family = init)]
926 pub unsafe fn initWithCoder_device(
927 this: Allocated<Self>,
928 a_decoder: &NSCoder,
929 device: &ProtocolObject<dyn MTLDevice>,
930 ) -> Option<Retained<Self>>;
931
932 /// Returns a pointer to the array of three floats used to convert RGBA, RGB or RG images
933 /// to the destination format when the destination is monochrome.
934 #[unsafe(method(colorTransform))]
935 #[unsafe(method_family = none)]
936 pub unsafe fn colorTransform(&self) -> NonNull<c_float>;
937 );
938}
939
940/// Methods declared on superclass `MPSKernel`.
941#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
942impl MPSImageSobel {
943 extern_methods!(
944 /// Called by NSCoder to decode MPSKernels
945 ///
946 /// This isn't the right interface to decode a MPSKernel, but
947 /// it is the one that NSCoder uses. To enable your NSCoder
948 /// (e.g. NSKeyedUnarchiver) to set which device to use
949 /// extend the object to adopt the MPSDeviceProvider
950 /// protocol. Otherwise, the Metal system default device
951 /// will be used.
952 ///
953 /// # Safety
954 ///
955 /// `a_decoder` possibly has further requirements.
956 #[unsafe(method(initWithCoder:))]
957 #[unsafe(method_family = init)]
958 pub unsafe fn initWithCoder(
959 this: Allocated<Self>,
960 a_decoder: &NSCoder,
961 ) -> Option<Retained<Self>>;
962 );
963}
964
965/// Methods declared on superclass `NSObject`.
966#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
967impl MPSImageSobel {
968 extern_methods!(
969 #[unsafe(method(init))]
970 #[unsafe(method_family = init)]
971 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
972
973 #[unsafe(method(new))]
974 #[unsafe(method_family = new)]
975 pub unsafe fn new() -> Retained<Self>;
976 );
977}
978
979extern_class!(
980 /// The MPSImageCanny implements the Canny edge detection algorithm.
981 /// When the color model of the source and destination textures match, the
982 /// filter is applied to each channel seperately. If the destination is monochrome
983 /// but source multichannel, the source will be converted to grayscale using the
984 /// linear gray color transform vector (v).
985 /// Luminance = v[0] * pixel.x + v[1] * pixel.y + v[2] * pixel.z;
986 ///
987 /// The canny edge detection algorithm consists of 5 steps:
988 /// 1. Blur the source image using a Gaussian blur with a sigma parameter
989 /// 2. Use horizontal and vertical Sobel filters to find a gradient magnitude and
990 /// direction.
991 /// G = sqrt(Sx^2 + Sy^2)
992 /// G_ang = arctan(Sy / Sx)
993 /// 3. Perform non-maximum suppression to thin edges to single pixel widths.
994 /// A pixel is considered to be a maxium along the edge if it has the largest
995 /// gradient magnitude along the positive and negatve gradient direction. That
996 /// is, if the gradient direction is 90°, if the gradient magnitude of a pixel is
997 /// greater than its neighbors at -90° and 90° it is the maximum. Any pixel
998 /// which is not a maximum will have its value suppressed, by setting it's
999 /// magnitude to 0.
1000 /// 4. Double thresholding is preformed with two values ht and lt with ht > lt
1001 /// to classify a pixel as part of a weak or strong edge. A pixel with gradient
1002 /// value G is classified as:
1003 /// Strong edge: G > ht
1004 /// Weak edge: ht >= G > lt
1005 /// Not an edge: lt >= G
1006 /// 5. Edge tracking is performed along all weak edges to determine if they
1007 /// are part of a strong edge. Any weak edges which are connected to a
1008 /// strong edge are labelled true edges, along with strong edges themselves.
1009 /// A pixel can be connected through any of its 8 neighbors. Any pixel marked
1010 /// as a true edge is output with a high value, and all others are considered
1011 /// background and output with a low value.
1012 ///
1013 /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpsimagecanny?language=objc)
1014 #[unsafe(super(MPSUnaryImageKernel, MPSKernel, NSObject))]
1015 #[derive(Debug, PartialEq, Eq, Hash)]
1016 #[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
1017 pub struct MPSImageCanny;
1018);
1019
1020#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
1021extern_conformance!(
1022 unsafe impl NSCoding for MPSImageCanny {}
1023);
1024
1025#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
1026extern_conformance!(
1027 unsafe impl NSCopying for MPSImageCanny {}
1028);
1029
1030#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
1031unsafe impl CopyingHelper for MPSImageCanny {
1032 type Result = Self;
1033}
1034
1035#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
1036extern_conformance!(
1037 unsafe impl NSObjectProtocol for MPSImageCanny {}
1038);
1039
1040#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
1041extern_conformance!(
1042 unsafe impl NSSecureCoding for MPSImageCanny {}
1043);
1044
1045#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
1046impl MPSImageCanny {
1047 extern_methods!(
1048 /// Initialize a Canny filter on a given device using the default color
1049 /// transform and default sigma value for Gaussian blur.
1050 /// Default transform: BT.601/JPEG {0.299f, 0.587f, 0.114f}
1051 /// Default sigma: sqrt(2)
1052 ///
1053 /// For non-default parameters, use
1054 /// -initWithDevice:linearGrayColorTransform:sigma:
1055 ///
1056 ///
1057 /// Parameter `device`: The device the filter will run on
1058 ///
1059 /// Returns: A valid object or nil, if failure.
1060 #[unsafe(method(initWithDevice:))]
1061 #[unsafe(method_family = init)]
1062 pub unsafe fn initWithDevice(
1063 this: Allocated<Self>,
1064 device: &ProtocolObject<dyn MTLDevice>,
1065 ) -> Retained<Self>;
1066
1067 /// Initialize a Canny filter on a given device with a non-default color transform and
1068 /// non-default sigma.
1069 ///
1070 /// Parameter `device`: The device the filter will run on
1071 ///
1072 /// Parameter `transform`: Array of three floats describing the rgb to gray scale color transform.
1073 ///
1074 /// ```text
1075 /// Luminance = transform[0] * pixel.x +
1076 /// transform[1] * pixel.y +
1077 /// transform[2] * pixel.z;
1078 /// ```
1079 ///
1080 ///
1081 /// Parameter `sigma`: The standard deviation of gaussian blur filter.
1082 /// Gaussian weight, centered at 0, at integer grid n is given as
1083 ///
1084 /// ```text
1085 /// w(i) = 1/sqrt(2*pi*sigma) * exp(-n^2/2*sigma^2)
1086 /// ```
1087 ///
1088 /// If we take cut off at 1% of w(0) (max weight) beyond which weights
1089 /// are considered 0, we have
1090 ///
1091 /// ```text
1092 /// ceil (sqrt(-log(0.01)*2)*sigma) ~ ceil(3.7*sigma)
1093 /// ```
1094 ///
1095 /// as rough estimate of filter width
1096 ///
1097 /// Returns: A valid object or nil, if failure.
1098 ///
1099 /// # Safety
1100 ///
1101 /// `transform` must be a valid pointer.
1102 #[unsafe(method(initWithDevice:linearToGrayScaleTransform:sigma:))]
1103 #[unsafe(method_family = init)]
1104 pub unsafe fn initWithDevice_linearToGrayScaleTransform_sigma(
1105 this: Allocated<Self>,
1106 device: &ProtocolObject<dyn MTLDevice>,
1107 transform: NonNull<c_float>,
1108 sigma: c_float,
1109 ) -> Retained<Self>;
1110
1111 /// NSSecureCoding compatability
1112 ///
1113 /// While the standard NSSecureCoding/NSCoding method
1114 /// -initWithCoder: should work, since the file can't
1115 /// know which device your data is allocated on, we
1116 /// have to guess and may guess incorrectly. To avoid
1117 /// that problem, use initWithCoder:device instead.
1118 ///
1119 /// Parameter `aDecoder`: The NSCoder subclass with your serialized MPSKernel
1120 ///
1121 /// Parameter `device`: The MTLDevice on which to make the MPSKernel
1122 ///
1123 /// Returns: A new MPSKernel object, or nil if failure.
1124 ///
1125 /// # Safety
1126 ///
1127 /// `a_decoder` possibly has further requirements.
1128 #[unsafe(method(initWithCoder:device:))]
1129 #[unsafe(method_family = init)]
1130 pub unsafe fn initWithCoder_device(
1131 this: Allocated<Self>,
1132 a_decoder: &NSCoder,
1133 device: &ProtocolObject<dyn MTLDevice>,
1134 ) -> Option<Retained<Self>>;
1135
1136 /// Returns a pointer to the array of three floats used to convert RGBA, RGB or RG images
1137 /// to the destination format when the destination is monochrome.
1138 /// Value is readonly and user should not modify or free.
1139 #[unsafe(method(colorTransform))]
1140 #[unsafe(method_family = none)]
1141 pub unsafe fn colorTransform(&self) -> NonNull<c_float>;
1142
1143 /// Read-only sigma value used in performing Gaussian blur of the image
1144 #[unsafe(method(sigma))]
1145 #[unsafe(method_family = none)]
1146 pub unsafe fn sigma(&self) -> c_float;
1147
1148 /// Read-write value used to set the high threshold for double thresholding, value is normalized.
1149 /// Default is 0.4
1150 #[unsafe(method(highThreshold))]
1151 #[unsafe(method_family = none)]
1152 pub unsafe fn highThreshold(&self) -> c_float;
1153
1154 /// Setter for [`highThreshold`][Self::highThreshold].
1155 #[unsafe(method(setHighThreshold:))]
1156 #[unsafe(method_family = none)]
1157 pub unsafe fn setHighThreshold(&self, high_threshold: c_float);
1158
1159 /// Read-write value used to set the low threshold for double thresholding, value is normalized.
1160 /// Default is 0.2
1161 #[unsafe(method(lowThreshold))]
1162 #[unsafe(method_family = none)]
1163 pub unsafe fn lowThreshold(&self) -> c_float;
1164
1165 /// Setter for [`lowThreshold`][Self::lowThreshold].
1166 #[unsafe(method(setLowThreshold:))]
1167 #[unsafe(method_family = none)]
1168 pub unsafe fn setLowThreshold(&self, low_threshold: c_float);
1169
1170 /// Read-write value used to change algorithm to an approximation of the true Canny Edge detection Algorithm.
1171 /// When true, a limit is placed on how far a single strong edge can extend. The result will be similar to a true output
1172 /// but some edges may terminate early, resulting in minor differences for cases with long, weak edges. The performance
1173 /// for the approximate canny implementation is improved and should provide similar enough results for most cases.
1174 /// Extra tuning of the high and low thresholds as well as sigma may help achieve a more similar output in this mode.
1175 /// Default is YES
1176 #[unsafe(method(useFastMode))]
1177 #[unsafe(method_family = none)]
1178 pub unsafe fn useFastMode(&self) -> bool;
1179
1180 /// Setter for [`useFastMode`][Self::useFastMode].
1181 #[unsafe(method(setUseFastMode:))]
1182 #[unsafe(method_family = none)]
1183 pub unsafe fn setUseFastMode(&self, use_fast_mode: bool);
1184 );
1185}
1186
1187/// Methods declared on superclass `MPSKernel`.
1188#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
1189impl MPSImageCanny {
1190 extern_methods!(
1191 /// Called by NSCoder to decode MPSKernels
1192 ///
1193 /// This isn't the right interface to decode a MPSKernel, but
1194 /// it is the one that NSCoder uses. To enable your NSCoder
1195 /// (e.g. NSKeyedUnarchiver) to set which device to use
1196 /// extend the object to adopt the MPSDeviceProvider
1197 /// protocol. Otherwise, the Metal system default device
1198 /// will be used.
1199 ///
1200 /// # Safety
1201 ///
1202 /// `a_decoder` possibly has further requirements.
1203 #[unsafe(method(initWithCoder:))]
1204 #[unsafe(method_family = init)]
1205 pub unsafe fn initWithCoder(
1206 this: Allocated<Self>,
1207 a_decoder: &NSCoder,
1208 ) -> Option<Retained<Self>>;
1209 );
1210}
1211
1212/// Methods declared on superclass `NSObject`.
1213#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
1214impl MPSImageCanny {
1215 extern_methods!(
1216 #[unsafe(method(init))]
1217 #[unsafe(method_family = init)]
1218 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
1219
1220 #[unsafe(method(new))]
1221 #[unsafe(method_family = new)]
1222 pub unsafe fn new() -> Retained<Self>;
1223 );
1224}
1225
1226extern_class!(
1227 /// The MPSImagePyramid is a base class for creating different kinds of pyramid images
1228 ///
1229 /// Currently supported pyramid-types are:
1230 /// MPSImageGaussianPyramid
1231 /// The Gaussian image pyramid kernel is enqueued as a in-place operation using
1232 /// MPSUnaryImageKernel::encodeToCommandBuffer:inPlaceTexture:fallbackCopyAllocator:and all mipmap levels after level=1, present in the provided image are filled using
1233 /// the provided filtering kernel. The fallbackCopyAllocator parameter is not used.
1234 ///
1235 /// The Gaussian image pyramid filter ignores
1236 /// clipRectand
1237 /// offsetand fills
1238 /// the entire mipmap levels.
1239 ///
1240 ///
1241 /// Note: Make sure your texture type is compatible with mipmapping and supports texture views
1242 /// (see
1243 /// MTLTextureUsagePixelFormatView).
1244 /// Note: Recall the size of the nth mipmap level:
1245 ///
1246 /// ```text
1247 /// w_n = max(1, floor(w_0 / 2^n))
1248 /// h_n = max(1, floor(h_0 / 2^n)),
1249 /// ```
1250 ///
1251 /// where w_0, h_0 are the zeroth level width and height. ie the image dimensions themselves.
1252 ///
1253 /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpsimagepyramid?language=objc)
1254 #[unsafe(super(MPSUnaryImageKernel, MPSKernel, NSObject))]
1255 #[derive(Debug, PartialEq, Eq, Hash)]
1256 #[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
1257 pub struct MPSImagePyramid;
1258);
1259
1260#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
1261extern_conformance!(
1262 unsafe impl NSCoding for MPSImagePyramid {}
1263);
1264
1265#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
1266extern_conformance!(
1267 unsafe impl NSCopying for MPSImagePyramid {}
1268);
1269
1270#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
1271unsafe impl CopyingHelper for MPSImagePyramid {
1272 type Result = Self;
1273}
1274
1275#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
1276extern_conformance!(
1277 unsafe impl NSObjectProtocol for MPSImagePyramid {}
1278);
1279
1280#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
1281extern_conformance!(
1282 unsafe impl NSSecureCoding for MPSImagePyramid {}
1283);
1284
1285#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
1286impl MPSImagePyramid {
1287 extern_methods!(
1288 /// Initialize a downwards 5-tap image pyramid with the default filter kernel and device
1289 ///
1290 /// Parameter `device`: The device the filter will run on
1291 ///
1292 ///
1293 /// The filter kernel is the outer product of w = [ 1/16, 1/4, 3/8, 1/4, 1/16 ]^T, with itself
1294 ///
1295 ///
1296 /// Returns: A valid object or nil, if failure.
1297 #[unsafe(method(initWithDevice:))]
1298 #[unsafe(method_family = init)]
1299 pub unsafe fn initWithDevice(
1300 this: Allocated<Self>,
1301 device: &ProtocolObject<dyn MTLDevice>,
1302 ) -> Retained<Self>;
1303
1304 /// Initialize a downwards 5-tap image pyramid with a central weight parameter and device
1305 ///
1306 /// Parameter `device`: The device the filter will run on
1307 ///
1308 /// Parameter `centerWeight`: Defines form of the filter-kernel through the outer product ww^T, where
1309 /// w = [ (1/4 - a/2), 1/4, a, 1/4, (1/4 - a/2) ]^T and 'a' is centerWeight.
1310 ///
1311 ///
1312 /// Returns: A valid object or nil, if failure.
1313 #[unsafe(method(initWithDevice:centerWeight:))]
1314 #[unsafe(method_family = init)]
1315 pub unsafe fn initWithDevice_centerWeight(
1316 this: Allocated<Self>,
1317 device: &ProtocolObject<dyn MTLDevice>,
1318 center_weight: c_float,
1319 ) -> Retained<Self>;
1320
1321 /// Initialize a downwards n-tap pyramid with a custom filter kernel and device
1322 ///
1323 /// Parameter `device`: The device the filter will run on
1324 ///
1325 /// Parameter `kernelWidth`: The width of the filtering kernel. See
1326 /// MPSImageConvolution.
1327 /// Parameter `kernelHeight`: The height of the filtering kernel. See
1328 /// MPSImageConvolution.
1329 /// Parameter `kernelWeights`: A pointer to an array of kernelWidth * kernelHeight values to be
1330 /// used as the kernel.
1331 /// These are in row major order. See
1332 /// MPSImageConvolution.
1333 ///
1334 /// Returns: A valid object or nil, if failure.
1335 ///
1336 /// # Safety
1337 ///
1338 /// `kernel_weights` must be a valid pointer.
1339 #[unsafe(method(initWithDevice:kernelWidth:kernelHeight:weights:))]
1340 #[unsafe(method_family = init)]
1341 pub unsafe fn initWithDevice_kernelWidth_kernelHeight_weights(
1342 this: Allocated<Self>,
1343 device: &ProtocolObject<dyn MTLDevice>,
1344 kernel_width: NSUInteger,
1345 kernel_height: NSUInteger,
1346 kernel_weights: NonNull<c_float>,
1347 ) -> Retained<Self>;
1348
1349 /// The height of the filter window. Must be an odd number.
1350 #[unsafe(method(kernelHeight))]
1351 #[unsafe(method_family = none)]
1352 pub unsafe fn kernelHeight(&self) -> NSUInteger;
1353
1354 /// The width of the filter window. Must be an odd number.
1355 #[unsafe(method(kernelWidth))]
1356 #[unsafe(method_family = none)]
1357 pub unsafe fn kernelWidth(&self) -> NSUInteger;
1358
1359 /// NSSecureCoding compatability
1360 ///
1361 /// See
1362 /// MPSKernel#initWithCoder.
1363 /// Parameter `aDecoder`: The NSCoder subclass with your serialized MPSCNNPooling
1364 ///
1365 /// Parameter `device`: The MTLDevice on which to make the MPSCNNPooling
1366 ///
1367 /// Returns: A new MPSCNNPooling object, or nil if failure.
1368 ///
1369 /// # Safety
1370 ///
1371 /// `a_decoder` possibly has further requirements.
1372 #[unsafe(method(initWithCoder:device:))]
1373 #[unsafe(method_family = init)]
1374 pub unsafe fn initWithCoder_device(
1375 this: Allocated<Self>,
1376 a_decoder: &NSCoder,
1377 device: &ProtocolObject<dyn MTLDevice>,
1378 ) -> Option<Retained<Self>>;
1379 );
1380}
1381
1382/// Methods declared on superclass `MPSKernel`.
1383#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
1384impl MPSImagePyramid {
1385 extern_methods!(
1386 /// Called by NSCoder to decode MPSKernels
1387 ///
1388 /// This isn't the right interface to decode a MPSKernel, but
1389 /// it is the one that NSCoder uses. To enable your NSCoder
1390 /// (e.g. NSKeyedUnarchiver) to set which device to use
1391 /// extend the object to adopt the MPSDeviceProvider
1392 /// protocol. Otherwise, the Metal system default device
1393 /// will be used.
1394 ///
1395 /// # Safety
1396 ///
1397 /// `a_decoder` possibly has further requirements.
1398 #[unsafe(method(initWithCoder:))]
1399 #[unsafe(method_family = init)]
1400 pub unsafe fn initWithCoder(
1401 this: Allocated<Self>,
1402 a_decoder: &NSCoder,
1403 ) -> Option<Retained<Self>>;
1404 );
1405}
1406
1407/// Methods declared on superclass `NSObject`.
1408#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
1409impl MPSImagePyramid {
1410 extern_methods!(
1411 #[unsafe(method(init))]
1412 #[unsafe(method_family = init)]
1413 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
1414
1415 #[unsafe(method(new))]
1416 #[unsafe(method_family = new)]
1417 pub unsafe fn new() -> Retained<Self>;
1418 );
1419}
1420
1421extern_class!(
1422 /// A Gaussian image pyramid is constructed as follows:
1423 /// The mipmap level zero is the source of the operation and is left untouched and
1424 /// the subsequent mipmap levels are constructed from it recursively:
1425 ///
1426 /// ```text
1427 /// mip[ level = n + 1 ] = Downsample( filter( mip[ level = n ] ) ), where
1428 /// ```
1429 ///
1430 /// "filter()" applies a filter with the specified convolution kernel and
1431 /// "Downsample()" removes odd rows and columns from the input image.
1432 /// The default convolution filter kernel for this operation is
1433 ///
1434 /// ```text
1435 /// k = w w^T, where w = [ 1/16, 1/4, 3/8, 1/4, 1/16 ]^T,
1436 /// ```
1437 ///
1438 /// but the user may also tweak this kernel with a
1439 /// centerWeightparameter: 'a':
1440 ///
1441 /// ```text
1442 /// k = w w^T, where w = [ (1/4 - a/2), 1/4, a, 1/4, (1/4 - a/2) ]^T
1443 /// ```
1444 ///
1445 /// or the user can provide a completely custom kernel.
1446 ///
1447 /// This procedure is continued until every mipmap level present in the image texture are
1448 /// filled with the pyramid levels.
1449 ///
1450 /// In case of the Gaussian pyramid the user must run the operation in-place using:
1451 /// MPSUnaryImageKernel::encodeToCommandBuffer:inPlaceTexture:fallbackCopyAllocator:,where the fallback allocator is ignored.
1452 ///
1453 /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpsimagegaussianpyramid?language=objc)
1454 #[unsafe(super(MPSImagePyramid, MPSUnaryImageKernel, MPSKernel, NSObject))]
1455 #[derive(Debug, PartialEq, Eq, Hash)]
1456 #[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
1457 pub struct MPSImageGaussianPyramid;
1458);
1459
1460#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
1461extern_conformance!(
1462 unsafe impl NSCoding for MPSImageGaussianPyramid {}
1463);
1464
1465#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
1466extern_conformance!(
1467 unsafe impl NSCopying for MPSImageGaussianPyramid {}
1468);
1469
1470#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
1471unsafe impl CopyingHelper for MPSImageGaussianPyramid {
1472 type Result = Self;
1473}
1474
1475#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
1476extern_conformance!(
1477 unsafe impl NSObjectProtocol for MPSImageGaussianPyramid {}
1478);
1479
1480#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
1481extern_conformance!(
1482 unsafe impl NSSecureCoding for MPSImageGaussianPyramid {}
1483);
1484
1485#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
1486impl MPSImageGaussianPyramid {
1487 extern_methods!();
1488}
1489
1490/// Methods declared on superclass `MPSImagePyramid`.
1491#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
1492impl MPSImageGaussianPyramid {
1493 extern_methods!(
1494 /// Initialize a downwards 5-tap image pyramid with the default filter kernel and device
1495 ///
1496 /// Parameter `device`: The device the filter will run on
1497 ///
1498 ///
1499 /// The filter kernel is the outer product of w = [ 1/16, 1/4, 3/8, 1/4, 1/16 ]^T, with itself
1500 ///
1501 ///
1502 /// Returns: A valid object or nil, if failure.
1503 #[unsafe(method(initWithDevice:))]
1504 #[unsafe(method_family = init)]
1505 pub unsafe fn initWithDevice(
1506 this: Allocated<Self>,
1507 device: &ProtocolObject<dyn MTLDevice>,
1508 ) -> Retained<Self>;
1509
1510 /// Initialize a downwards 5-tap image pyramid with a central weight parameter and device
1511 ///
1512 /// Parameter `device`: The device the filter will run on
1513 ///
1514 /// Parameter `centerWeight`: Defines form of the filter-kernel through the outer product ww^T, where
1515 /// w = [ (1/4 - a/2), 1/4, a, 1/4, (1/4 - a/2) ]^T and 'a' is centerWeight.
1516 ///
1517 ///
1518 /// Returns: A valid object or nil, if failure.
1519 #[unsafe(method(initWithDevice:centerWeight:))]
1520 #[unsafe(method_family = init)]
1521 pub unsafe fn initWithDevice_centerWeight(
1522 this: Allocated<Self>,
1523 device: &ProtocolObject<dyn MTLDevice>,
1524 center_weight: c_float,
1525 ) -> Retained<Self>;
1526
1527 /// Initialize a downwards n-tap pyramid with a custom filter kernel and device
1528 ///
1529 /// Parameter `device`: The device the filter will run on
1530 ///
1531 /// Parameter `kernelWidth`: The width of the filtering kernel. See
1532 /// MPSImageConvolution.
1533 /// Parameter `kernelHeight`: The height of the filtering kernel. See
1534 /// MPSImageConvolution.
1535 /// Parameter `kernelWeights`: A pointer to an array of kernelWidth * kernelHeight values to be
1536 /// used as the kernel.
1537 /// These are in row major order. See
1538 /// MPSImageConvolution.
1539 ///
1540 /// Returns: A valid object or nil, if failure.
1541 ///
1542 /// # Safety
1543 ///
1544 /// `kernel_weights` must be a valid pointer.
1545 #[unsafe(method(initWithDevice:kernelWidth:kernelHeight:weights:))]
1546 #[unsafe(method_family = init)]
1547 pub unsafe fn initWithDevice_kernelWidth_kernelHeight_weights(
1548 this: Allocated<Self>,
1549 device: &ProtocolObject<dyn MTLDevice>,
1550 kernel_width: NSUInteger,
1551 kernel_height: NSUInteger,
1552 kernel_weights: NonNull<c_float>,
1553 ) -> Retained<Self>;
1554
1555 /// NSSecureCoding compatability
1556 ///
1557 /// See
1558 /// MPSKernel#initWithCoder.
1559 /// Parameter `aDecoder`: The NSCoder subclass with your serialized MPSCNNPooling
1560 ///
1561 /// Parameter `device`: The MTLDevice on which to make the MPSCNNPooling
1562 ///
1563 /// Returns: A new MPSCNNPooling object, or nil if failure.
1564 ///
1565 /// # Safety
1566 ///
1567 /// `a_decoder` possibly has further requirements.
1568 #[unsafe(method(initWithCoder:device:))]
1569 #[unsafe(method_family = init)]
1570 pub unsafe fn initWithCoder_device(
1571 this: Allocated<Self>,
1572 a_decoder: &NSCoder,
1573 device: &ProtocolObject<dyn MTLDevice>,
1574 ) -> Option<Retained<Self>>;
1575 );
1576}
1577
1578/// Methods declared on superclass `MPSKernel`.
1579#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
1580impl MPSImageGaussianPyramid {
1581 extern_methods!(
1582 /// Called by NSCoder to decode MPSKernels
1583 ///
1584 /// This isn't the right interface to decode a MPSKernel, but
1585 /// it is the one that NSCoder uses. To enable your NSCoder
1586 /// (e.g. NSKeyedUnarchiver) to set which device to use
1587 /// extend the object to adopt the MPSDeviceProvider
1588 /// protocol. Otherwise, the Metal system default device
1589 /// will be used.
1590 ///
1591 /// # Safety
1592 ///
1593 /// `a_decoder` possibly has further requirements.
1594 #[unsafe(method(initWithCoder:))]
1595 #[unsafe(method_family = init)]
1596 pub unsafe fn initWithCoder(
1597 this: Allocated<Self>,
1598 a_decoder: &NSCoder,
1599 ) -> Option<Retained<Self>>;
1600 );
1601}
1602
1603/// Methods declared on superclass `NSObject`.
1604#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
1605impl MPSImageGaussianPyramid {
1606 extern_methods!(
1607 #[unsafe(method(init))]
1608 #[unsafe(method_family = init)]
1609 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
1610
1611 #[unsafe(method(new))]
1612 #[unsafe(method_family = new)]
1613 pub unsafe fn new() -> Retained<Self>;
1614 );
1615}
1616
1617extern_class!(
1618 /// Laplacian pyramid levels are constructed as difference between the current source level and 2x interpolated version of the
1619 /// half-resolution source level immediately above it.
1620 ///
1621 /// LaplacianMipLevel[l] := GaussianMipLevel[l] – Interpolate(GaussianMipLevel[l + 1])
1622 ///
1623 /// The Interpolate function is the classical 2x signal interpolation procedure applied
1624 /// to all color channels of the source mip-level in both dimensions.
1625 /// It is logically equivalent to the following two-step process :
1626 /// 1) Zero-stuffing (sometimes called "upsampling").
1627 /// It is the process of interleaving source pixel values with zero values:
1628 /// dst.at(x, y) := src.at(x, y) if even(x) and even(y) else 0
1629 /// 2) Filtering (sometimes called "interpolation").
1630 /// It is the same procedure as implemented by the MPSImageConvolution class,
1631 /// using filter weights provided by the initializer methods inherited from MPSImagePyramid.
1632 ///
1633 /// The source for Laplacian pyramid construction is typically produced
1634 /// by the Gaussian pyramid algorithm -- a closely related image processing technique,
1635 /// but the Laplacian pyramid construction itself makes no assumptions neither about
1636 /// the data stored in the source texture nor about the interpolation filter weights,
1637 /// so Gaussian pyramid is just a conventional name for the source texture.
1638 ///
1639 /// Please refer to the classical "The Laplacian Pyramid as a Compact Image Code" whitepaper
1640 /// by Burt
1641 /// &
1642 /// Anderson, originally published in 532 IEEE TRANSACTIONS ON COMMUNICATIONS, VOL. COM-3l, NO. 4, APRIL 1983
1643 /// for more detailed discussion.
1644 ///
1645 /// Since the subtraction operation extends the value range of LaplacianMipLevelRaw
1646 /// relative to the value range of GaussianMipLevel (even for the case of
1647 /// normalized interpolation filter), in order to avoid unwanted range clamping
1648 /// when working with normalized texture types, laplacianBias and laplacianScale class properties
1649 /// specify point-wise linear mapping of the LaplacianMipLevelRaw result data
1650 /// into the value range of the destination texture :
1651 /// LaplacianRangeScale(pixel, laplacianBias, laplacianScale) := laplacianBias + pixel * laplacianScale,
1652 /// LaplacianMipLevelStored[j] := LaplacianRangeScale(LaplacianMipLevel[j], laplacianBias, laplacianScale),
1653 /// with the default values being laplacianBias = 0.0, laplacianScale = 1.0
1654 ///
1655 /// Limitations of the current software revision :
1656 /// 1) In-place operation is not supported, e.g. source and destination textures need
1657 /// to have separate storage and can't be aliased.
1658 /// 2) The number of channels, bit depth and resolution of the source and destination textures need to match.
1659 /// 3) Values of the offset and clipRect properties are fixed to the defaults provided by MPSUnaryImageKernel
1660 /// (from which they are inherited), corresponding to no offset applied to the source and unbounded region of interest
1661 /// in every destination mip-level; all updates to these properties are ignored.
1662 ///
1663 /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpsimagelaplacianpyramid?language=objc)
1664 #[unsafe(super(MPSImagePyramid, MPSUnaryImageKernel, MPSKernel, NSObject))]
1665 #[derive(Debug, PartialEq, Eq, Hash)]
1666 #[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
1667 pub struct MPSImageLaplacianPyramid;
1668);
1669
1670#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
1671extern_conformance!(
1672 unsafe impl NSCoding for MPSImageLaplacianPyramid {}
1673);
1674
1675#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
1676extern_conformance!(
1677 unsafe impl NSCopying for MPSImageLaplacianPyramid {}
1678);
1679
1680#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
1681unsafe impl CopyingHelper for MPSImageLaplacianPyramid {
1682 type Result = Self;
1683}
1684
1685#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
1686extern_conformance!(
1687 unsafe impl NSObjectProtocol for MPSImageLaplacianPyramid {}
1688);
1689
1690#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
1691extern_conformance!(
1692 unsafe impl NSSecureCoding for MPSImageLaplacianPyramid {}
1693);
1694
1695#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
1696impl MPSImageLaplacianPyramid {
1697 extern_methods!(
1698 #[unsafe(method(getLaplacianBias))]
1699 #[unsafe(method_family = none)]
1700 pub unsafe fn getLaplacianBias(&self) -> c_float;
1701
1702 /// Setter for [`getLaplacianBias`][Self::getLaplacianBias].
1703 #[unsafe(method(setLaplacianBias:))]
1704 #[unsafe(method_family = none)]
1705 pub unsafe fn setLaplacianBias(&self, laplacian_bias: c_float);
1706
1707 #[unsafe(method(getLaplacianScale))]
1708 #[unsafe(method_family = none)]
1709 pub unsafe fn getLaplacianScale(&self) -> c_float;
1710
1711 /// Setter for [`getLaplacianScale`][Self::getLaplacianScale].
1712 #[unsafe(method(setLaplacianScale:))]
1713 #[unsafe(method_family = none)]
1714 pub unsafe fn setLaplacianScale(&self, laplacian_scale: c_float);
1715 );
1716}
1717
1718/// Methods declared on superclass `MPSImagePyramid`.
1719#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
1720impl MPSImageLaplacianPyramid {
1721 extern_methods!(
1722 /// Initialize a downwards 5-tap image pyramid with the default filter kernel and device
1723 ///
1724 /// Parameter `device`: The device the filter will run on
1725 ///
1726 ///
1727 /// The filter kernel is the outer product of w = [ 1/16, 1/4, 3/8, 1/4, 1/16 ]^T, with itself
1728 ///
1729 ///
1730 /// Returns: A valid object or nil, if failure.
1731 #[unsafe(method(initWithDevice:))]
1732 #[unsafe(method_family = init)]
1733 pub unsafe fn initWithDevice(
1734 this: Allocated<Self>,
1735 device: &ProtocolObject<dyn MTLDevice>,
1736 ) -> Retained<Self>;
1737
1738 /// Initialize a downwards 5-tap image pyramid with a central weight parameter and device
1739 ///
1740 /// Parameter `device`: The device the filter will run on
1741 ///
1742 /// Parameter `centerWeight`: Defines form of the filter-kernel through the outer product ww^T, where
1743 /// w = [ (1/4 - a/2), 1/4, a, 1/4, (1/4 - a/2) ]^T and 'a' is centerWeight.
1744 ///
1745 ///
1746 /// Returns: A valid object or nil, if failure.
1747 #[unsafe(method(initWithDevice:centerWeight:))]
1748 #[unsafe(method_family = init)]
1749 pub unsafe fn initWithDevice_centerWeight(
1750 this: Allocated<Self>,
1751 device: &ProtocolObject<dyn MTLDevice>,
1752 center_weight: c_float,
1753 ) -> Retained<Self>;
1754
1755 /// Initialize a downwards n-tap pyramid with a custom filter kernel and device
1756 ///
1757 /// Parameter `device`: The device the filter will run on
1758 ///
1759 /// Parameter `kernelWidth`: The width of the filtering kernel. See
1760 /// MPSImageConvolution.
1761 /// Parameter `kernelHeight`: The height of the filtering kernel. See
1762 /// MPSImageConvolution.
1763 /// Parameter `kernelWeights`: A pointer to an array of kernelWidth * kernelHeight values to be
1764 /// used as the kernel.
1765 /// These are in row major order. See
1766 /// MPSImageConvolution.
1767 ///
1768 /// Returns: A valid object or nil, if failure.
1769 ///
1770 /// # Safety
1771 ///
1772 /// `kernel_weights` must be a valid pointer.
1773 #[unsafe(method(initWithDevice:kernelWidth:kernelHeight:weights:))]
1774 #[unsafe(method_family = init)]
1775 pub unsafe fn initWithDevice_kernelWidth_kernelHeight_weights(
1776 this: Allocated<Self>,
1777 device: &ProtocolObject<dyn MTLDevice>,
1778 kernel_width: NSUInteger,
1779 kernel_height: NSUInteger,
1780 kernel_weights: NonNull<c_float>,
1781 ) -> Retained<Self>;
1782
1783 /// NSSecureCoding compatability
1784 ///
1785 /// See
1786 /// MPSKernel#initWithCoder.
1787 /// Parameter `aDecoder`: The NSCoder subclass with your serialized MPSCNNPooling
1788 ///
1789 /// Parameter `device`: The MTLDevice on which to make the MPSCNNPooling
1790 ///
1791 /// Returns: A new MPSCNNPooling object, or nil if failure.
1792 ///
1793 /// # Safety
1794 ///
1795 /// `a_decoder` possibly has further requirements.
1796 #[unsafe(method(initWithCoder:device:))]
1797 #[unsafe(method_family = init)]
1798 pub unsafe fn initWithCoder_device(
1799 this: Allocated<Self>,
1800 a_decoder: &NSCoder,
1801 device: &ProtocolObject<dyn MTLDevice>,
1802 ) -> Option<Retained<Self>>;
1803 );
1804}
1805
1806/// Methods declared on superclass `MPSKernel`.
1807#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
1808impl MPSImageLaplacianPyramid {
1809 extern_methods!(
1810 /// Called by NSCoder to decode MPSKernels
1811 ///
1812 /// This isn't the right interface to decode a MPSKernel, but
1813 /// it is the one that NSCoder uses. To enable your NSCoder
1814 /// (e.g. NSKeyedUnarchiver) to set which device to use
1815 /// extend the object to adopt the MPSDeviceProvider
1816 /// protocol. Otherwise, the Metal system default device
1817 /// will be used.
1818 ///
1819 /// # Safety
1820 ///
1821 /// `a_decoder` possibly has further requirements.
1822 #[unsafe(method(initWithCoder:))]
1823 #[unsafe(method_family = init)]
1824 pub unsafe fn initWithCoder(
1825 this: Allocated<Self>,
1826 a_decoder: &NSCoder,
1827 ) -> Option<Retained<Self>>;
1828 );
1829}
1830
1831/// Methods declared on superclass `NSObject`.
1832#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
1833impl MPSImageLaplacianPyramid {
1834 extern_methods!(
1835 #[unsafe(method(init))]
1836 #[unsafe(method_family = init)]
1837 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
1838
1839 #[unsafe(method(new))]
1840 #[unsafe(method_family = new)]
1841 pub unsafe fn new() -> Retained<Self>;
1842 );
1843}
1844
1845extern_class!(
1846 /// [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpsimagelaplacianpyramidsubtract?language=objc)
1847 #[unsafe(super(
1848 MPSImageLaplacianPyramid,
1849 MPSImagePyramid,
1850 MPSUnaryImageKernel,
1851 MPSKernel,
1852 NSObject
1853 ))]
1854 #[derive(Debug, PartialEq, Eq, Hash)]
1855 #[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
1856 pub struct MPSImageLaplacianPyramidSubtract;
1857);
1858
1859#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
1860extern_conformance!(
1861 unsafe impl NSCoding for MPSImageLaplacianPyramidSubtract {}
1862);
1863
1864#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
1865extern_conformance!(
1866 unsafe impl NSCopying for MPSImageLaplacianPyramidSubtract {}
1867);
1868
1869#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
1870unsafe impl CopyingHelper for MPSImageLaplacianPyramidSubtract {
1871 type Result = Self;
1872}
1873
1874#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
1875extern_conformance!(
1876 unsafe impl NSObjectProtocol for MPSImageLaplacianPyramidSubtract {}
1877);
1878
1879#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
1880extern_conformance!(
1881 unsafe impl NSSecureCoding for MPSImageLaplacianPyramidSubtract {}
1882);
1883
1884#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
1885impl MPSImageLaplacianPyramidSubtract {
1886 extern_methods!();
1887}
1888
1889/// Methods declared on superclass `MPSImagePyramid`.
1890#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
1891impl MPSImageLaplacianPyramidSubtract {
1892 extern_methods!(
1893 /// Initialize a downwards 5-tap image pyramid with the default filter kernel and device
1894 ///
1895 /// Parameter `device`: The device the filter will run on
1896 ///
1897 ///
1898 /// The filter kernel is the outer product of w = [ 1/16, 1/4, 3/8, 1/4, 1/16 ]^T, with itself
1899 ///
1900 ///
1901 /// Returns: A valid object or nil, if failure.
1902 #[unsafe(method(initWithDevice:))]
1903 #[unsafe(method_family = init)]
1904 pub unsafe fn initWithDevice(
1905 this: Allocated<Self>,
1906 device: &ProtocolObject<dyn MTLDevice>,
1907 ) -> Retained<Self>;
1908
1909 /// Initialize a downwards 5-tap image pyramid with a central weight parameter and device
1910 ///
1911 /// Parameter `device`: The device the filter will run on
1912 ///
1913 /// Parameter `centerWeight`: Defines form of the filter-kernel through the outer product ww^T, where
1914 /// w = [ (1/4 - a/2), 1/4, a, 1/4, (1/4 - a/2) ]^T and 'a' is centerWeight.
1915 ///
1916 ///
1917 /// Returns: A valid object or nil, if failure.
1918 #[unsafe(method(initWithDevice:centerWeight:))]
1919 #[unsafe(method_family = init)]
1920 pub unsafe fn initWithDevice_centerWeight(
1921 this: Allocated<Self>,
1922 device: &ProtocolObject<dyn MTLDevice>,
1923 center_weight: c_float,
1924 ) -> Retained<Self>;
1925
1926 /// Initialize a downwards n-tap pyramid with a custom filter kernel and device
1927 ///
1928 /// Parameter `device`: The device the filter will run on
1929 ///
1930 /// Parameter `kernelWidth`: The width of the filtering kernel. See
1931 /// MPSImageConvolution.
1932 /// Parameter `kernelHeight`: The height of the filtering kernel. See
1933 /// MPSImageConvolution.
1934 /// Parameter `kernelWeights`: A pointer to an array of kernelWidth * kernelHeight values to be
1935 /// used as the kernel.
1936 /// These are in row major order. See
1937 /// MPSImageConvolution.
1938 ///
1939 /// Returns: A valid object or nil, if failure.
1940 ///
1941 /// # Safety
1942 ///
1943 /// `kernel_weights` must be a valid pointer.
1944 #[unsafe(method(initWithDevice:kernelWidth:kernelHeight:weights:))]
1945 #[unsafe(method_family = init)]
1946 pub unsafe fn initWithDevice_kernelWidth_kernelHeight_weights(
1947 this: Allocated<Self>,
1948 device: &ProtocolObject<dyn MTLDevice>,
1949 kernel_width: NSUInteger,
1950 kernel_height: NSUInteger,
1951 kernel_weights: NonNull<c_float>,
1952 ) -> Retained<Self>;
1953
1954 /// NSSecureCoding compatability
1955 ///
1956 /// See
1957 /// MPSKernel#initWithCoder.
1958 /// Parameter `aDecoder`: The NSCoder subclass with your serialized MPSCNNPooling
1959 ///
1960 /// Parameter `device`: The MTLDevice on which to make the MPSCNNPooling
1961 ///
1962 /// Returns: A new MPSCNNPooling object, or nil if failure.
1963 ///
1964 /// # Safety
1965 ///
1966 /// `a_decoder` possibly has further requirements.
1967 #[unsafe(method(initWithCoder:device:))]
1968 #[unsafe(method_family = init)]
1969 pub unsafe fn initWithCoder_device(
1970 this: Allocated<Self>,
1971 a_decoder: &NSCoder,
1972 device: &ProtocolObject<dyn MTLDevice>,
1973 ) -> Option<Retained<Self>>;
1974 );
1975}
1976
1977/// Methods declared on superclass `MPSKernel`.
1978#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
1979impl MPSImageLaplacianPyramidSubtract {
1980 extern_methods!(
1981 /// Called by NSCoder to decode MPSKernels
1982 ///
1983 /// This isn't the right interface to decode a MPSKernel, but
1984 /// it is the one that NSCoder uses. To enable your NSCoder
1985 /// (e.g. NSKeyedUnarchiver) to set which device to use
1986 /// extend the object to adopt the MPSDeviceProvider
1987 /// protocol. Otherwise, the Metal system default device
1988 /// will be used.
1989 ///
1990 /// # Safety
1991 ///
1992 /// `a_decoder` possibly has further requirements.
1993 #[unsafe(method(initWithCoder:))]
1994 #[unsafe(method_family = init)]
1995 pub unsafe fn initWithCoder(
1996 this: Allocated<Self>,
1997 a_decoder: &NSCoder,
1998 ) -> Option<Retained<Self>>;
1999 );
2000}
2001
2002/// Methods declared on superclass `NSObject`.
2003#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
2004impl MPSImageLaplacianPyramidSubtract {
2005 extern_methods!(
2006 #[unsafe(method(init))]
2007 #[unsafe(method_family = init)]
2008 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
2009
2010 #[unsafe(method(new))]
2011 #[unsafe(method_family = new)]
2012 pub unsafe fn new() -> Retained<Self>;
2013 );
2014}
2015
2016extern_class!(
2017 /// [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpsimagelaplacianpyramidadd?language=objc)
2018 #[unsafe(super(
2019 MPSImageLaplacianPyramid,
2020 MPSImagePyramid,
2021 MPSUnaryImageKernel,
2022 MPSKernel,
2023 NSObject
2024 ))]
2025 #[derive(Debug, PartialEq, Eq, Hash)]
2026 #[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
2027 pub struct MPSImageLaplacianPyramidAdd;
2028);
2029
2030#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
2031extern_conformance!(
2032 unsafe impl NSCoding for MPSImageLaplacianPyramidAdd {}
2033);
2034
2035#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
2036extern_conformance!(
2037 unsafe impl NSCopying for MPSImageLaplacianPyramidAdd {}
2038);
2039
2040#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
2041unsafe impl CopyingHelper for MPSImageLaplacianPyramidAdd {
2042 type Result = Self;
2043}
2044
2045#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
2046extern_conformance!(
2047 unsafe impl NSObjectProtocol for MPSImageLaplacianPyramidAdd {}
2048);
2049
2050#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
2051extern_conformance!(
2052 unsafe impl NSSecureCoding for MPSImageLaplacianPyramidAdd {}
2053);
2054
2055#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
2056impl MPSImageLaplacianPyramidAdd {
2057 extern_methods!();
2058}
2059
2060/// Methods declared on superclass `MPSImagePyramid`.
2061#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
2062impl MPSImageLaplacianPyramidAdd {
2063 extern_methods!(
2064 /// Initialize a downwards 5-tap image pyramid with the default filter kernel and device
2065 ///
2066 /// Parameter `device`: The device the filter will run on
2067 ///
2068 ///
2069 /// The filter kernel is the outer product of w = [ 1/16, 1/4, 3/8, 1/4, 1/16 ]^T, with itself
2070 ///
2071 ///
2072 /// Returns: A valid object or nil, if failure.
2073 #[unsafe(method(initWithDevice:))]
2074 #[unsafe(method_family = init)]
2075 pub unsafe fn initWithDevice(
2076 this: Allocated<Self>,
2077 device: &ProtocolObject<dyn MTLDevice>,
2078 ) -> Retained<Self>;
2079
2080 /// Initialize a downwards 5-tap image pyramid with a central weight parameter and device
2081 ///
2082 /// Parameter `device`: The device the filter will run on
2083 ///
2084 /// Parameter `centerWeight`: Defines form of the filter-kernel through the outer product ww^T, where
2085 /// w = [ (1/4 - a/2), 1/4, a, 1/4, (1/4 - a/2) ]^T and 'a' is centerWeight.
2086 ///
2087 ///
2088 /// Returns: A valid object or nil, if failure.
2089 #[unsafe(method(initWithDevice:centerWeight:))]
2090 #[unsafe(method_family = init)]
2091 pub unsafe fn initWithDevice_centerWeight(
2092 this: Allocated<Self>,
2093 device: &ProtocolObject<dyn MTLDevice>,
2094 center_weight: c_float,
2095 ) -> Retained<Self>;
2096
2097 /// Initialize a downwards n-tap pyramid with a custom filter kernel and device
2098 ///
2099 /// Parameter `device`: The device the filter will run on
2100 ///
2101 /// Parameter `kernelWidth`: The width of the filtering kernel. See
2102 /// MPSImageConvolution.
2103 /// Parameter `kernelHeight`: The height of the filtering kernel. See
2104 /// MPSImageConvolution.
2105 /// Parameter `kernelWeights`: A pointer to an array of kernelWidth * kernelHeight values to be
2106 /// used as the kernel.
2107 /// These are in row major order. See
2108 /// MPSImageConvolution.
2109 ///
2110 /// Returns: A valid object or nil, if failure.
2111 ///
2112 /// # Safety
2113 ///
2114 /// `kernel_weights` must be a valid pointer.
2115 #[unsafe(method(initWithDevice:kernelWidth:kernelHeight:weights:))]
2116 #[unsafe(method_family = init)]
2117 pub unsafe fn initWithDevice_kernelWidth_kernelHeight_weights(
2118 this: Allocated<Self>,
2119 device: &ProtocolObject<dyn MTLDevice>,
2120 kernel_width: NSUInteger,
2121 kernel_height: NSUInteger,
2122 kernel_weights: NonNull<c_float>,
2123 ) -> Retained<Self>;
2124
2125 /// NSSecureCoding compatability
2126 ///
2127 /// See
2128 /// MPSKernel#initWithCoder.
2129 /// Parameter `aDecoder`: The NSCoder subclass with your serialized MPSCNNPooling
2130 ///
2131 /// Parameter `device`: The MTLDevice on which to make the MPSCNNPooling
2132 ///
2133 /// Returns: A new MPSCNNPooling object, or nil if failure.
2134 ///
2135 /// # Safety
2136 ///
2137 /// `a_decoder` possibly has further requirements.
2138 #[unsafe(method(initWithCoder:device:))]
2139 #[unsafe(method_family = init)]
2140 pub unsafe fn initWithCoder_device(
2141 this: Allocated<Self>,
2142 a_decoder: &NSCoder,
2143 device: &ProtocolObject<dyn MTLDevice>,
2144 ) -> Option<Retained<Self>>;
2145 );
2146}
2147
2148/// Methods declared on superclass `MPSKernel`.
2149#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
2150impl MPSImageLaplacianPyramidAdd {
2151 extern_methods!(
2152 /// Called by NSCoder to decode MPSKernels
2153 ///
2154 /// This isn't the right interface to decode a MPSKernel, but
2155 /// it is the one that NSCoder uses. To enable your NSCoder
2156 /// (e.g. NSKeyedUnarchiver) to set which device to use
2157 /// extend the object to adopt the MPSDeviceProvider
2158 /// protocol. Otherwise, the Metal system default device
2159 /// will be used.
2160 ///
2161 /// # Safety
2162 ///
2163 /// `a_decoder` possibly has further requirements.
2164 #[unsafe(method(initWithCoder:))]
2165 #[unsafe(method_family = init)]
2166 pub unsafe fn initWithCoder(
2167 this: Allocated<Self>,
2168 a_decoder: &NSCoder,
2169 ) -> Option<Retained<Self>>;
2170 );
2171}
2172
2173/// Methods declared on superclass `NSObject`.
2174#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
2175impl MPSImageLaplacianPyramidAdd {
2176 extern_methods!(
2177 #[unsafe(method(init))]
2178 #[unsafe(method_family = init)]
2179 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
2180
2181 #[unsafe(method(new))]
2182 #[unsafe(method_family = new)]
2183 pub unsafe fn new() -> Retained<Self>;
2184 );
2185}