objc2_metal_performance_shaders/generated/MPSImage/MPSImageHistogram.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 MPSImageHistogram computes the histogram of an image.
13 ///
14 /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpsimagehistogram?language=objc)
15 #[unsafe(super(MPSKernel, NSObject))]
16 #[derive(Debug, PartialEq, Eq, Hash)]
17 #[cfg(all(feature = "MPSCore", feature = "MPSKernel"))]
18 pub struct MPSImageHistogram;
19);
20
21#[cfg(all(feature = "MPSCore", feature = "MPSKernel"))]
22extern_conformance!(
23 unsafe impl NSCoding for MPSImageHistogram {}
24);
25
26#[cfg(all(feature = "MPSCore", feature = "MPSKernel"))]
27extern_conformance!(
28 unsafe impl NSCopying for MPSImageHistogram {}
29);
30
31#[cfg(all(feature = "MPSCore", feature = "MPSKernel"))]
32unsafe impl CopyingHelper for MPSImageHistogram {
33 type Result = Self;
34}
35
36#[cfg(all(feature = "MPSCore", feature = "MPSKernel"))]
37extern_conformance!(
38 unsafe impl NSObjectProtocol for MPSImageHistogram {}
39);
40
41#[cfg(all(feature = "MPSCore", feature = "MPSKernel"))]
42extern_conformance!(
43 unsafe impl NSSecureCoding for MPSImageHistogram {}
44);
45
46#[cfg(all(feature = "MPSCore", feature = "MPSKernel"))]
47impl MPSImageHistogram {
48 extern_methods!(
49 /// The source rectangle to use when reading data.
50 ///
51 /// A MTLRegion that indicates which part of the source to read. If the clipRectSource does not lie
52 /// completely within the source image, the intersection of the image bounds and clipRectSource will
53 /// be used. The clipRectSource replaces the MPSUnaryImageKernel offset parameter for this filter.
54 /// The latter is ignored. Default: MPSRectNoClip, use the entire source texture.
55 #[unsafe(method(clipRectSource))]
56 #[unsafe(method_family = none)]
57 pub unsafe fn clipRectSource(&self) -> MTLRegion;
58
59 /// Setter for [`clipRectSource`][Self::clipRectSource].
60 #[unsafe(method(setClipRectSource:))]
61 #[unsafe(method_family = none)]
62 pub unsafe fn setClipRectSource(&self, clip_rect_source: MTLRegion);
63
64 /// Zero-initalize the histogram results
65 ///
66 /// Indicates that the memory region in which the histogram results are to be written in the
67 /// histogram buffer are to be zero-initialized or not. Default: YES.
68 #[unsafe(method(zeroHistogram))]
69 #[unsafe(method_family = none)]
70 pub unsafe fn zeroHistogram(&self) -> bool;
71
72 /// Setter for [`zeroHistogram`][Self::zeroHistogram].
73 #[unsafe(method(setZeroHistogram:))]
74 #[unsafe(method_family = none)]
75 pub unsafe fn setZeroHistogram(&self, zero_histogram: bool);
76
77 /// NSSecureCoding compatability
78 ///
79 /// While the standard NSSecureCoding/NSCoding method
80 /// -initWithCoder: should work, since the file can't
81 /// know which device your data is allocated on, we
82 /// have to guess and may guess incorrectly. To avoid
83 /// that problem, use initWithCoder:device instead.
84 ///
85 /// Parameter `aDecoder`: The NSCoder subclass with your serialized MPSKernel
86 ///
87 /// Parameter `device`: The MTLDevice on which to make the MPSKernel
88 ///
89 /// Returns: A new MPSKernel object, or nil if failure.
90 ///
91 /// # Safety
92 ///
93 /// `a_decoder` possibly has further requirements.
94 #[unsafe(method(initWithCoder:device:))]
95 #[unsafe(method_family = init)]
96 pub unsafe fn initWithCoder_device(
97 this: Allocated<Self>,
98 a_decoder: &NSCoder,
99 device: &ProtocolObject<dyn MTLDevice>,
100 ) -> Option<Retained<Self>>;
101
102 /// Encode the filter to a command buffer using a MTLComputeCommandEncoder.
103 ///
104 /// The filter will not begin to execute until after the command
105 /// buffer has been enqueued and committed.
106 ///
107 ///
108 /// Parameter `commandBuffer`: A valid MTLCommandBuffer.
109 ///
110 /// Parameter `source`: A valid MTLTexture containing the source image for the filter
111 ///
112 /// Parameter `histogram`: A valid MTLBuffer to receive the histogram results.
113 ///
114 /// Parameter `histogramOffset`: Byte offset into histogram buffer at which to write the histogram results. Must be a multiple of 32 bytes.
115 /// The histogram results / channel are stored together. The number of channels for which
116 /// histogram results are stored is determined by the number of channels in the image.
117 /// If histogramInfo.histogramForAlpha is false and the source image is RGBA then only histogram
118 /// results for RGB channels are stored.
119 ///
120 /// The histogram results are stored in the histogram buffer as follows:
121 /// - histogram results for the R channel for all bins followed by
122 /// - histogram results for the G channel for all bins followed by
123 /// - histogram results for the B channel for all bins followed by
124 /// - histogram results for the A channel for all bins
125 ///
126 /// # Safety
127 ///
128 /// - `source` may need to be synchronized.
129 /// - `source` may be unretained, you must ensure it is kept alive while in use.
130 /// - `histogram` may need to be synchronized.
131 /// - `histogram` may be unretained, you must ensure it is kept alive while in use.
132 /// - `histogram` contents should be of the correct type.
133 #[unsafe(method(encodeToCommandBuffer:sourceTexture:histogram:histogramOffset:))]
134 #[unsafe(method_family = none)]
135 pub unsafe fn encodeToCommandBuffer_sourceTexture_histogram_histogramOffset(
136 &self,
137 command_buffer: &ProtocolObject<dyn MTLCommandBuffer>,
138 source: &ProtocolObject<dyn MTLTexture>,
139 histogram: &ProtocolObject<dyn MTLBuffer>,
140 histogram_offset: NSUInteger,
141 );
142
143 /// The amount of space in the output MTLBuffer the histogram will take up.
144 ///
145 /// This convenience function calculates the minimum amount of space
146 /// needed in the output histogram for the results. The MTLBuffer should
147 /// be at least this length, longer if histogramOffset is non-zero.
148 ///
149 /// Parameter `sourceFormat`: The MTLPixelFormat of the source image. This is
150 /// the source parameter of -encodeToCommandBuffer:
151 /// sourceTexture:histogram:histogramOffset
152 ///
153 /// Returns: The number of bytes needed to store the result histograms.
154 #[unsafe(method(histogramSizeForSourceFormat:))]
155 #[unsafe(method_family = none)]
156 pub unsafe fn histogramSizeForSourceFormat(&self, source_format: MTLPixelFormat) -> usize;
157 );
158}
159
160/// Methods declared on superclass `MPSKernel`.
161#[cfg(all(feature = "MPSCore", feature = "MPSKernel"))]
162impl MPSImageHistogram {
163 extern_methods!(
164 /// Standard init with default properties per filter type
165 ///
166 /// Parameter `device`: The device that the filter will be used on. May not be NULL.
167 ///
168 /// Returns: a pointer to the newly initialized object. This will fail, returning
169 /// nil if the device is not supported. Devices must be
170 /// MTLFeatureSet_iOS_GPUFamily2_v1 or later.
171 #[unsafe(method(initWithDevice:))]
172 #[unsafe(method_family = init)]
173 pub unsafe fn initWithDevice(
174 this: Allocated<Self>,
175 device: &ProtocolObject<dyn MTLDevice>,
176 ) -> Retained<Self>;
177
178 /// Called by NSCoder to decode MPSKernels
179 ///
180 /// This isn't the right interface to decode a MPSKernel, but
181 /// it is the one that NSCoder uses. To enable your NSCoder
182 /// (e.g. NSKeyedUnarchiver) to set which device to use
183 /// extend the object to adopt the MPSDeviceProvider
184 /// protocol. Otherwise, the Metal system default device
185 /// will be used.
186 ///
187 /// # Safety
188 ///
189 /// `a_decoder` possibly has further requirements.
190 #[unsafe(method(initWithCoder:))]
191 #[unsafe(method_family = init)]
192 pub unsafe fn initWithCoder(
193 this: Allocated<Self>,
194 a_decoder: &NSCoder,
195 ) -> Option<Retained<Self>>;
196 );
197}
198
199/// Methods declared on superclass `NSObject`.
200#[cfg(all(feature = "MPSCore", feature = "MPSKernel"))]
201impl MPSImageHistogram {
202 extern_methods!(
203 #[unsafe(method(init))]
204 #[unsafe(method_family = init)]
205 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
206
207 #[unsafe(method(new))]
208 #[unsafe(method_family = new)]
209 pub unsafe fn new() -> Retained<Self>;
210 );
211}
212
213extern_class!(
214 /// The MPSImageNormalizedHistogram computes the normalized histogram of an image.
215 /// The minimum and maximum pixel values for a given region of an image are first computed.
216 /// The max(computed minimum pixel value, MPSImageHistogramInfo.minPixelValue) and the
217 /// min(computed maximum pixel value, MPSImageHistogramInfo.maxPixelValue) are used to
218 /// compute the normalized histogram.
219 ///
220 /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpsimagenormalizedhistogram?language=objc)
221 #[unsafe(super(MPSKernel, NSObject))]
222 #[derive(Debug, PartialEq, Eq, Hash)]
223 #[cfg(all(feature = "MPSCore", feature = "MPSKernel"))]
224 pub struct MPSImageNormalizedHistogram;
225);
226
227#[cfg(all(feature = "MPSCore", feature = "MPSKernel"))]
228extern_conformance!(
229 unsafe impl NSCoding for MPSImageNormalizedHistogram {}
230);
231
232#[cfg(all(feature = "MPSCore", feature = "MPSKernel"))]
233extern_conformance!(
234 unsafe impl NSCopying for MPSImageNormalizedHistogram {}
235);
236
237#[cfg(all(feature = "MPSCore", feature = "MPSKernel"))]
238unsafe impl CopyingHelper for MPSImageNormalizedHistogram {
239 type Result = Self;
240}
241
242#[cfg(all(feature = "MPSCore", feature = "MPSKernel"))]
243extern_conformance!(
244 unsafe impl NSObjectProtocol for MPSImageNormalizedHistogram {}
245);
246
247#[cfg(all(feature = "MPSCore", feature = "MPSKernel"))]
248extern_conformance!(
249 unsafe impl NSSecureCoding for MPSImageNormalizedHistogram {}
250);
251
252#[cfg(all(feature = "MPSCore", feature = "MPSKernel"))]
253impl MPSImageNormalizedHistogram {
254 extern_methods!(
255 /// The source rectangle to use when reading data.
256 ///
257 /// A MTLRegion that indicates which part of the source to read. If the clipRectSource does not lie
258 /// completely within the source image, the intersection of the image bounds and clipRectSource will
259 /// be used. The clipRectSource replaces the MPSUnaryImageKernel offset parameter for this filter.
260 /// The latter is ignored. Default: MPSRectNoClip, use the entire source texture.
261 #[unsafe(method(clipRectSource))]
262 #[unsafe(method_family = none)]
263 pub unsafe fn clipRectSource(&self) -> MTLRegion;
264
265 /// Setter for [`clipRectSource`][Self::clipRectSource].
266 #[unsafe(method(setClipRectSource:))]
267 #[unsafe(method_family = none)]
268 pub unsafe fn setClipRectSource(&self, clip_rect_source: MTLRegion);
269
270 /// Zero-initalize the histogram results
271 ///
272 /// Indicates that the memory region in which the histogram results are to be written in the
273 /// histogram buffer are to be zero-initialized or not. Default: YES.
274 #[unsafe(method(zeroHistogram))]
275 #[unsafe(method_family = none)]
276 pub unsafe fn zeroHistogram(&self) -> bool;
277
278 /// Setter for [`zeroHistogram`][Self::zeroHistogram].
279 #[unsafe(method(setZeroHistogram:))]
280 #[unsafe(method_family = none)]
281 pub unsafe fn setZeroHistogram(&self, zero_histogram: bool);
282
283 /// NSSecureCoding compatability
284 ///
285 /// While the standard NSSecureCoding/NSCoding method
286 /// -initWithCoder: should work, since the file can't
287 /// know which device your data is allocated on, we
288 /// have to guess and may guess incorrectly. To avoid
289 /// that problem, use initWithCoder:device instead.
290 ///
291 /// Parameter `aDecoder`: The NSCoder subclass with your serialized MPSKernel
292 ///
293 /// Parameter `device`: The MTLDevice on which to make the MPSKernel
294 ///
295 /// Returns: A new MPSKernel object, or nil if failure.
296 ///
297 /// # Safety
298 ///
299 /// `a_decoder` possibly has further requirements.
300 #[unsafe(method(initWithCoder:device:))]
301 #[unsafe(method_family = init)]
302 pub unsafe fn initWithCoder_device(
303 this: Allocated<Self>,
304 a_decoder: &NSCoder,
305 device: &ProtocolObject<dyn MTLDevice>,
306 ) -> Option<Retained<Self>>;
307
308 /// Encode the filter to a command buffer using a MTLComputeCommandEncoder.
309 ///
310 /// The filter will not begin to execute until after the command
311 /// buffer has been enqueued and committed.
312 ///
313 ///
314 /// Parameter `commandBuffer`: A valid MTLCommandBuffer.
315 ///
316 /// Parameter `source`: A valid MTLTexture containing the source image for the filter
317 ///
318 /// Parameter `minmaxTexture`: A valid MTLTexture in which the min/max pixel values from source will be returned
319 ///
320 /// Parameter `histogram`: A valid MTLBuffer to receive the histogram results.
321 ///
322 /// Parameter `histogramOffset`: Byte offset into histogram buffer at which to write the histogram results. Must be a multiple of 32 bytes.
323 /// The histogram results / channel are stored together. The number of channels for which
324 /// histogram results are stored is determined by the number of channels in the image.
325 /// If histogramInfo.histogramForAlpha is false and the source image is RGBA then only histogram
326 /// results for RGB channels are stored.
327 ///
328 /// The histogram results are stored in the histogram buffer as follows:
329 /// - histogram results for the R channel for all bins followed by
330 /// - histogram results for the G channel for all bins followed by
331 /// - histogram results for the B channel for all bins followed by
332 /// - histogram results for the A channel for all bins
333 ///
334 /// # Safety
335 ///
336 /// - `source` may need to be synchronized.
337 /// - `source` may be unretained, you must ensure it is kept alive while in use.
338 /// - `minmax_texture` may need to be synchronized.
339 /// - `minmax_texture` may be unretained, you must ensure it is kept alive while in use.
340 /// - `histogram` may need to be synchronized.
341 /// - `histogram` may be unretained, you must ensure it is kept alive while in use.
342 /// - `histogram` contents should be of the correct type.
343 #[unsafe(method(encodeToCommandBuffer:sourceTexture:minmaxTexture:histogram:histogramOffset:))]
344 #[unsafe(method_family = none)]
345 pub unsafe fn encodeToCommandBuffer_sourceTexture_minmaxTexture_histogram_histogramOffset(
346 &self,
347 command_buffer: &ProtocolObject<dyn MTLCommandBuffer>,
348 source: &ProtocolObject<dyn MTLTexture>,
349 minmax_texture: &ProtocolObject<dyn MTLTexture>,
350 histogram: &ProtocolObject<dyn MTLBuffer>,
351 histogram_offset: NSUInteger,
352 );
353
354 /// The amount of space in the output MTLBuffer the histogram will take up.
355 ///
356 /// This convenience function calculates the minimum amount of space
357 /// needed in the output histogram for the results. The MTLBuffer should
358 /// be at least this length, longer if histogramOffset is non-zero.
359 ///
360 /// Parameter `sourceFormat`: The MTLPixelFormat of the source image. This is
361 /// the source parameter of -encodeToCommandBuffer:
362 /// sourceTexture:histogram:histogramOffset
363 ///
364 /// Returns: The number of bytes needed to store the result histograms.
365 #[unsafe(method(histogramSizeForSourceFormat:))]
366 #[unsafe(method_family = none)]
367 pub unsafe fn histogramSizeForSourceFormat(&self, source_format: MTLPixelFormat) -> usize;
368 );
369}
370
371/// Methods declared on superclass `MPSKernel`.
372#[cfg(all(feature = "MPSCore", feature = "MPSKernel"))]
373impl MPSImageNormalizedHistogram {
374 extern_methods!(
375 /// Standard init with default properties per filter type
376 ///
377 /// Parameter `device`: The device that the filter will be used on. May not be NULL.
378 ///
379 /// Returns: a pointer to the newly initialized object. This will fail, returning
380 /// nil if the device is not supported. Devices must be
381 /// MTLFeatureSet_iOS_GPUFamily2_v1 or later.
382 #[unsafe(method(initWithDevice:))]
383 #[unsafe(method_family = init)]
384 pub unsafe fn initWithDevice(
385 this: Allocated<Self>,
386 device: &ProtocolObject<dyn MTLDevice>,
387 ) -> Retained<Self>;
388
389 /// Called by NSCoder to decode MPSKernels
390 ///
391 /// This isn't the right interface to decode a MPSKernel, but
392 /// it is the one that NSCoder uses. To enable your NSCoder
393 /// (e.g. NSKeyedUnarchiver) to set which device to use
394 /// extend the object to adopt the MPSDeviceProvider
395 /// protocol. Otherwise, the Metal system default device
396 /// will be used.
397 ///
398 /// # Safety
399 ///
400 /// `a_decoder` possibly has further requirements.
401 #[unsafe(method(initWithCoder:))]
402 #[unsafe(method_family = init)]
403 pub unsafe fn initWithCoder(
404 this: Allocated<Self>,
405 a_decoder: &NSCoder,
406 ) -> Option<Retained<Self>>;
407 );
408}
409
410/// Methods declared on superclass `NSObject`.
411#[cfg(all(feature = "MPSCore", feature = "MPSKernel"))]
412impl MPSImageNormalizedHistogram {
413 extern_methods!(
414 #[unsafe(method(init))]
415 #[unsafe(method_family = init)]
416 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
417
418 #[unsafe(method(new))]
419 #[unsafe(method_family = new)]
420 pub unsafe fn new() -> Retained<Self>;
421 );
422}
423
424extern_class!(
425 /// The MPSImageHistogramEqualization performs equalizes the histogram of an image.
426 /// The process is divided into three steps.
427 ///
428 /// -# Call -initWithDevice:histogramInfo: This creates a MPSImageHistogramEqualization
429 /// object. It is done when the method returns.
430 ///
431 /// -# Call -encodeTransform:sourceTexture:histogram:histogramOffset: This creates a privately held
432 /// image transform (i.e. a cumulative distribution function of the histogram) which will be used to
433 /// equalize the distribution of the histogram of the source image. This process runs on a MTLCommandBuffer
434 /// when it is committed to a MTLCommandQueue. It must complete before the next step can be run.
435 /// It may be performed on the same MTLCommandBuffer. The histogram argument specifies the histogram
436 /// buffer which contains the histogram values for sourceTexture. The sourceTexture argument is used by
437 /// encodeTransform to determine the number of channels and therefore which histogram data in histogram
438 /// buffer to use. The histogram for sourceTexture must have been computed either on the CPU or using
439 /// the MPSImageHistogram kernel
440 ///
441 /// -# Call -encodeToCommandBuffer:sourceTexture:destinationTexture: to read data from
442 /// sourceTexture, apply the equalization transform to it and write to destination texture.
443 /// This step is also done on the GPU on a MTLCommandQueue.
444 ///
445 /// You can reuse the same equalization transform on other images to perform the
446 /// same transform on those images. (Since their distribution is probably different,
447 /// they will probably not be equalized by it.) This filter usually will not be able
448 /// to work in place.
449 ///
450 /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpsimagehistogramequalization?language=objc)
451 #[unsafe(super(MPSUnaryImageKernel, MPSKernel, NSObject))]
452 #[derive(Debug, PartialEq, Eq, Hash)]
453 #[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
454 pub struct MPSImageHistogramEqualization;
455);
456
457#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
458extern_conformance!(
459 unsafe impl NSCoding for MPSImageHistogramEqualization {}
460);
461
462#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
463extern_conformance!(
464 unsafe impl NSCopying for MPSImageHistogramEqualization {}
465);
466
467#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
468unsafe impl CopyingHelper for MPSImageHistogramEqualization {
469 type Result = Self;
470}
471
472#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
473extern_conformance!(
474 unsafe impl NSObjectProtocol for MPSImageHistogramEqualization {}
475);
476
477#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
478extern_conformance!(
479 unsafe impl NSSecureCoding for MPSImageHistogramEqualization {}
480);
481
482#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
483impl MPSImageHistogramEqualization {
484 extern_methods!(
485 /// NSSecureCoding compatability
486 ///
487 /// While the standard NSSecureCoding/NSCoding method
488 /// -initWithCoder: should work, since the file can't
489 /// know which device your data is allocated on, we
490 /// have to guess and may guess incorrectly. To avoid
491 /// that problem, use initWithCoder:device instead.
492 ///
493 /// Parameter `aDecoder`: The NSCoder subclass with your serialized MPSKernel
494 ///
495 /// Parameter `device`: The MTLDevice on which to make the MPSKernel
496 ///
497 /// Returns: A new MPSKernel object, or nil if failure.
498 ///
499 /// # Safety
500 ///
501 /// `a_decoder` possibly has further requirements.
502 #[unsafe(method(initWithCoder:device:))]
503 #[unsafe(method_family = init)]
504 pub unsafe fn initWithCoder_device(
505 this: Allocated<Self>,
506 a_decoder: &NSCoder,
507 device: &ProtocolObject<dyn MTLDevice>,
508 ) -> Option<Retained<Self>>;
509
510 /// Encode the transform function to a command buffer using a MTLComputeCommandEncoder.
511 /// The transform function computes the equalization lookup table.
512 ///
513 /// The transform function will not begin to execute until after the command
514 /// buffer has been enqueued and committed. This step will need to be repeated
515 /// with the new MPSKernel if -copyWithZone:device or -copyWithZone: is called.
516 /// The transform is stored as internal state to the object. You still need to
517 /// call -encodeToCommandBuffer:sourceTexture:destinationTexture: afterward
518 /// to apply the transform to produce a result texture.
519 ///
520 ///
521 /// Parameter `commandBuffer`: A valid MTLCommandBuffer.
522 ///
523 /// Parameter `source`: A valid MTLTexture containing the source image for the filter.
524 ///
525 /// Parameter `histogram`: A valid MTLBuffer containing the histogram results for an image. This filter
526 /// will use these histogram results to generate the cumulative histogram for equalizing
527 /// the image. The histogram results / channel are stored together. The number of channels
528 /// for which histogram results are stored is determined by the number of channels in the image.
529 /// If histogramInfo.histogramForAlpha is false and the source image is RGBA then only histogram
530 /// results for RGB channels are stored.
531 ///
532 /// Parameter `histogramOffset`: A byte offset into the histogram MTLBuffer where the histogram starts. Must conform to
533 /// alignment requirements for [MTLComputeCommandEncoder setBuffer:offset:atIndex:] offset
534 /// parameter.
535 ///
536 /// # Safety
537 ///
538 /// - `source` may need to be synchronized.
539 /// - `source` may be unretained, you must ensure it is kept alive while in use.
540 /// - `histogram` may need to be synchronized.
541 /// - `histogram` may be unretained, you must ensure it is kept alive while in use.
542 /// - `histogram` contents should be of the correct type.
543 #[unsafe(method(encodeTransformToCommandBuffer:sourceTexture:histogram:histogramOffset:))]
544 #[unsafe(method_family = none)]
545 pub unsafe fn encodeTransformToCommandBuffer_sourceTexture_histogram_histogramOffset(
546 &self,
547 command_buffer: &ProtocolObject<dyn MTLCommandBuffer>,
548 source: &ProtocolObject<dyn MTLTexture>,
549 histogram: &ProtocolObject<dyn MTLBuffer>,
550 histogram_offset: NSUInteger,
551 );
552 );
553}
554
555/// Methods declared on superclass `MPSUnaryImageKernel`.
556#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
557impl MPSImageHistogramEqualization {
558 extern_methods!(
559 /// Standard init with default properties per filter type
560 ///
561 /// Parameter `device`: The device that the filter will be used on. May not be NULL.
562 ///
563 /// Returns: a pointer to the newly initialized object. This will fail, returning
564 /// nil if the device is not supported. Devices must be
565 /// MTLFeatureSet_iOS_GPUFamily2_v1 or later.
566 #[unsafe(method(initWithDevice:))]
567 #[unsafe(method_family = init)]
568 pub unsafe fn initWithDevice(
569 this: Allocated<Self>,
570 device: &ProtocolObject<dyn MTLDevice>,
571 ) -> Retained<Self>;
572 );
573}
574
575/// Methods declared on superclass `MPSKernel`.
576#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
577impl MPSImageHistogramEqualization {
578 extern_methods!(
579 /// Called by NSCoder to decode MPSKernels
580 ///
581 /// This isn't the right interface to decode a MPSKernel, but
582 /// it is the one that NSCoder uses. To enable your NSCoder
583 /// (e.g. NSKeyedUnarchiver) to set which device to use
584 /// extend the object to adopt the MPSDeviceProvider
585 /// protocol. Otherwise, the Metal system default device
586 /// will be used.
587 ///
588 /// # Safety
589 ///
590 /// `a_decoder` possibly has further requirements.
591 #[unsafe(method(initWithCoder:))]
592 #[unsafe(method_family = init)]
593 pub unsafe fn initWithCoder(
594 this: Allocated<Self>,
595 a_decoder: &NSCoder,
596 ) -> Option<Retained<Self>>;
597 );
598}
599
600/// Methods declared on superclass `NSObject`.
601#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
602impl MPSImageHistogramEqualization {
603 extern_methods!(
604 #[unsafe(method(init))]
605 #[unsafe(method_family = init)]
606 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
607
608 #[unsafe(method(new))]
609 #[unsafe(method_family = new)]
610 pub unsafe fn new() -> Retained<Self>;
611 );
612}
613
614extern_class!(
615 /// The MPSImageHistogramSpecification performs a histogram specification operation on an image.
616 /// It is a generalized version of histogram equalization operation. The histogram specificaiton filter
617 /// converts the image so that its histogram matches the desired histogram.
618 ///
619 /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpsimagehistogramspecification?language=objc)
620 #[unsafe(super(MPSUnaryImageKernel, MPSKernel, NSObject))]
621 #[derive(Debug, PartialEq, Eq, Hash)]
622 #[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
623 pub struct MPSImageHistogramSpecification;
624);
625
626#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
627extern_conformance!(
628 unsafe impl NSCoding for MPSImageHistogramSpecification {}
629);
630
631#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
632extern_conformance!(
633 unsafe impl NSCopying for MPSImageHistogramSpecification {}
634);
635
636#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
637unsafe impl CopyingHelper for MPSImageHistogramSpecification {
638 type Result = Self;
639}
640
641#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
642extern_conformance!(
643 unsafe impl NSObjectProtocol for MPSImageHistogramSpecification {}
644);
645
646#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
647extern_conformance!(
648 unsafe impl NSSecureCoding for MPSImageHistogramSpecification {}
649);
650
651#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
652impl MPSImageHistogramSpecification {
653 extern_methods!(
654 /// NSSecureCoding compatability
655 ///
656 /// While the standard NSSecureCoding/NSCoding method
657 /// -initWithCoder: should work, since the file can't
658 /// know which device your data is allocated on, we
659 /// have to guess and may guess incorrectly. To avoid
660 /// that problem, use initWithCoder:device instead.
661 ///
662 /// Parameter `aDecoder`: The NSCoder subclass with your serialized MPSKernel
663 ///
664 /// Parameter `device`: The MTLDevice on which to make the MPSKernel
665 ///
666 /// Returns: A new MPSKernel object, or nil if failure.
667 ///
668 /// # Safety
669 ///
670 /// `a_decoder` possibly has further requirements.
671 #[unsafe(method(initWithCoder:device:))]
672 #[unsafe(method_family = init)]
673 pub unsafe fn initWithCoder_device(
674 this: Allocated<Self>,
675 a_decoder: &NSCoder,
676 device: &ProtocolObject<dyn MTLDevice>,
677 ) -> Option<Retained<Self>>;
678
679 /// Encode the transform function to a command buffer using a MTLComputeCommandEncoder.
680 /// The transform function computes the specification lookup table.
681 ///
682 /// The transform function will not begin to execute until after the command
683 /// buffer has been enqueued and committed. This step will need to be repeated
684 /// with the new MPSKernel if -copyWithZone:device or -copyWithZone: is called.
685 ///
686 ///
687 /// Parameter `commandBuffer`: A valid MTLCommandBuffer.
688 ///
689 /// Parameter `source`: A valid MTLTexture containing the source image for the filter.
690 ///
691 /// Parameter `sourceHistogram`: A valid MTLBuffer containing the histogram results for the source image. This filter
692 /// will use these histogram results to generate the cumulative histogram for equalizing
693 /// the image. The histogram results / channel are stored together. The number of channels
694 /// for which histogram results are stored is determined by the number of channels in the image.
695 /// If histogramInfo.histogramForAlpha is false and the source image is RGBA then only histogram
696 /// results for RGB channels are stored.
697 ///
698 /// Parameter `sourceHistogramOffset`: A byte offset into the sourceHistogram MTLBuffer where the histogram starts. Must conform to
699 /// alignment requirements for [MTLComputeCommandEncoder setBuffer:offset:atIndex:] offset
700 /// parameter.
701 ///
702 /// Parameter `desiredHistogram`: A valid MTLBuffer containing the desired histogram results for the source image.
703 /// The histogram results / channel are stored together. The number of channels
704 /// for which histogram results are stored is determined by the number of channels in the image.
705 /// If histogramInfo.histogramForAlpha is false and the source image is RGBA then only histogram
706 /// results for RGB channels are stored.
707 ///
708 /// Parameter `desiredHistogramOffset`: A byte offset into the desiredHistogram MTLBuffer where the histogram starts. Must conform to
709 /// alignment requirements for [MTLComputeCommandEncoder setBuffer:offset:atIndex:] offset
710 /// parameter.
711 ///
712 /// # Safety
713 ///
714 /// - `source` may need to be synchronized.
715 /// - `source` may be unretained, you must ensure it is kept alive while in use.
716 /// - `source_histogram` may need to be synchronized.
717 /// - `source_histogram` may be unretained, you must ensure it is kept alive while in use.
718 /// - `source_histogram` contents should be of the correct type.
719 /// - `desired_histogram` may need to be synchronized.
720 /// - `desired_histogram` may be unretained, you must ensure it is kept alive while in use.
721 /// - `desired_histogram` contents should be of the correct type.
722 #[unsafe(method(encodeTransformToCommandBuffer:sourceTexture:sourceHistogram:sourceHistogramOffset:desiredHistogram:desiredHistogramOffset:))]
723 #[unsafe(method_family = none)]
724 pub unsafe fn encodeTransformToCommandBuffer_sourceTexture_sourceHistogram_sourceHistogramOffset_desiredHistogram_desiredHistogramOffset(
725 &self,
726 command_buffer: &ProtocolObject<dyn MTLCommandBuffer>,
727 source: &ProtocolObject<dyn MTLTexture>,
728 source_histogram: &ProtocolObject<dyn MTLBuffer>,
729 source_histogram_offset: NSUInteger,
730 desired_histogram: &ProtocolObject<dyn MTLBuffer>,
731 desired_histogram_offset: NSUInteger,
732 );
733 );
734}
735
736/// Methods declared on superclass `MPSUnaryImageKernel`.
737#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
738impl MPSImageHistogramSpecification {
739 extern_methods!(
740 /// Standard init with default properties per filter type
741 ///
742 /// Parameter `device`: The device that the filter will be used on. May not be NULL.
743 ///
744 /// Returns: a pointer to the newly initialized object. This will fail, returning
745 /// nil if the device is not supported. Devices must be
746 /// MTLFeatureSet_iOS_GPUFamily2_v1 or later.
747 #[unsafe(method(initWithDevice:))]
748 #[unsafe(method_family = init)]
749 pub unsafe fn initWithDevice(
750 this: Allocated<Self>,
751 device: &ProtocolObject<dyn MTLDevice>,
752 ) -> Retained<Self>;
753 );
754}
755
756/// Methods declared on superclass `MPSKernel`.
757#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
758impl MPSImageHistogramSpecification {
759 extern_methods!(
760 /// Called by NSCoder to decode MPSKernels
761 ///
762 /// This isn't the right interface to decode a MPSKernel, but
763 /// it is the one that NSCoder uses. To enable your NSCoder
764 /// (e.g. NSKeyedUnarchiver) to set which device to use
765 /// extend the object to adopt the MPSDeviceProvider
766 /// protocol. Otherwise, the Metal system default device
767 /// will be used.
768 ///
769 /// # Safety
770 ///
771 /// `a_decoder` possibly has further requirements.
772 #[unsafe(method(initWithCoder:))]
773 #[unsafe(method_family = init)]
774 pub unsafe fn initWithCoder(
775 this: Allocated<Self>,
776 a_decoder: &NSCoder,
777 ) -> Option<Retained<Self>>;
778 );
779}
780
781/// Methods declared on superclass `NSObject`.
782#[cfg(all(feature = "MPSCore", feature = "MPSImageKernel", feature = "MPSKernel"))]
783impl MPSImageHistogramSpecification {
784 extern_methods!(
785 #[unsafe(method(init))]
786 #[unsafe(method_family = init)]
787 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
788
789 #[unsafe(method(new))]
790 #[unsafe(method_family = new)]
791 pub unsafe fn new() -> Retained<Self>;
792 );
793}