1use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6#[cfg(feature = "objc2-core-foundation")]
7use objc2_core_foundation::*;
8#[cfg(feature = "objc2-core-graphics")]
9#[cfg(target_vendor = "apple")]
10use objc2_core_graphics::*;
11#[cfg(feature = "objc2-core-image")]
12#[cfg(target_vendor = "apple")]
13use objc2_core_image::*;
14use objc2_foundation::*;
15
16use crate::*;
17
18#[repr(transparent)]
21#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
22pub struct NSTIFFCompression(pub NSUInteger);
23impl NSTIFFCompression {
24 #[doc(alias = "NSTIFFCompressionNone")]
25 pub const None: Self = Self(1);
26 #[doc(alias = "NSTIFFCompressionCCITTFAX3")]
27 pub const CCITTFAX3: Self = Self(3);
28 #[doc(alias = "NSTIFFCompressionCCITTFAX4")]
29 pub const CCITTFAX4: Self = Self(4);
30 #[doc(alias = "NSTIFFCompressionLZW")]
31 pub const LZW: Self = Self(5);
32 #[doc(alias = "NSTIFFCompressionJPEG")]
33 pub const JPEG: Self = Self(6);
34 #[doc(alias = "NSTIFFCompressionNEXT")]
35 pub const NEXT: Self = Self(32766);
36 #[doc(alias = "NSTIFFCompressionPackBits")]
37 pub const PackBits: Self = Self(32773);
38 #[doc(alias = "NSTIFFCompressionOldJPEG")]
39 pub const OldJPEG: Self = Self(32865);
40}
41
42unsafe impl Encode for NSTIFFCompression {
43 const ENCODING: Encoding = NSUInteger::ENCODING;
44}
45
46unsafe impl RefEncode for NSTIFFCompression {
47 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
48}
49
50#[repr(transparent)]
53#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
54pub struct NSBitmapImageFileType(pub NSUInteger);
55impl NSBitmapImageFileType {
56 #[doc(alias = "NSBitmapImageFileTypeTIFF")]
57 pub const TIFF: Self = Self(0);
58 #[doc(alias = "NSBitmapImageFileTypeBMP")]
59 pub const BMP: Self = Self(1);
60 #[doc(alias = "NSBitmapImageFileTypeGIF")]
61 pub const GIF: Self = Self(2);
62 #[doc(alias = "NSBitmapImageFileTypeJPEG")]
63 pub const JPEG: Self = Self(3);
64 #[doc(alias = "NSBitmapImageFileTypePNG")]
65 pub const PNG: Self = Self(4);
66 #[doc(alias = "NSBitmapImageFileTypeJPEG2000")]
67 pub const JPEG2000: Self = Self(5);
68}
69
70unsafe impl Encode for NSBitmapImageFileType {
71 const ENCODING: Encoding = NSUInteger::ENCODING;
72}
73
74unsafe impl RefEncode for NSBitmapImageFileType {
75 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
76}
77
78#[repr(transparent)]
81#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
82pub struct NSImageRepLoadStatus(pub NSInteger);
83impl NSImageRepLoadStatus {
84 #[doc(alias = "NSImageRepLoadStatusUnknownType")]
85 pub const UnknownType: Self = Self(-1);
86 #[doc(alias = "NSImageRepLoadStatusReadingHeader")]
87 pub const ReadingHeader: Self = Self(-2);
88 #[doc(alias = "NSImageRepLoadStatusWillNeedAllData")]
89 pub const WillNeedAllData: Self = Self(-3);
90 #[doc(alias = "NSImageRepLoadStatusInvalidData")]
91 pub const InvalidData: Self = Self(-4);
92 #[doc(alias = "NSImageRepLoadStatusUnexpectedEOF")]
93 pub const UnexpectedEOF: Self = Self(-5);
94 #[doc(alias = "NSImageRepLoadStatusCompleted")]
95 pub const Completed: Self = Self(-6);
96}
97
98unsafe impl Encode for NSImageRepLoadStatus {
99 const ENCODING: Encoding = NSInteger::ENCODING;
100}
101
102unsafe impl RefEncode for NSImageRepLoadStatus {
103 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
104}
105
106#[repr(transparent)]
109#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
110pub struct NSBitmapFormat(pub NSUInteger);
111bitflags::bitflags! {
112 impl NSBitmapFormat: NSUInteger {
113 #[doc(alias = "NSBitmapFormatAlphaFirst")]
114 const AlphaFirst = 1<<0;
115 #[doc(alias = "NSBitmapFormatAlphaNonpremultiplied")]
116 const AlphaNonpremultiplied = 1<<1;
117 #[doc(alias = "NSBitmapFormatFloatingPointSamples")]
118 const FloatingPointSamples = 1<<2;
119 #[doc(alias = "NSBitmapFormatSixteenBitLittleEndian")]
120 const SixteenBitLittleEndian = 1<<8;
121 #[doc(alias = "NSBitmapFormatThirtyTwoBitLittleEndian")]
122 const ThirtyTwoBitLittleEndian = 1<<9;
123 #[doc(alias = "NSBitmapFormatSixteenBitBigEndian")]
124 const SixteenBitBigEndian = 1<<10;
125 #[doc(alias = "NSBitmapFormatThirtyTwoBitBigEndian")]
126 const ThirtyTwoBitBigEndian = 1<<11;
127 }
128}
129
130unsafe impl Encode for NSBitmapFormat {
131 const ENCODING: Encoding = NSUInteger::ENCODING;
132}
133
134unsafe impl RefEncode for NSBitmapFormat {
135 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
136}
137
138pub type NSBitmapImageRepPropertyKey = NSString;
141
142extern "C" {
143 pub static NSImageCompressionMethod: &'static NSBitmapImageRepPropertyKey;
145}
146
147extern "C" {
148 pub static NSImageCompressionFactor: &'static NSBitmapImageRepPropertyKey;
150}
151
152extern "C" {
153 pub static NSImageDitherTransparency: &'static NSBitmapImageRepPropertyKey;
155}
156
157extern "C" {
158 pub static NSImageRGBColorTable: &'static NSBitmapImageRepPropertyKey;
160}
161
162extern "C" {
163 pub static NSImageInterlaced: &'static NSBitmapImageRepPropertyKey;
165}
166
167extern "C" {
168 pub static NSImageColorSyncProfileData: &'static NSBitmapImageRepPropertyKey;
170}
171
172extern "C" {
173 pub static NSImageFrameCount: &'static NSBitmapImageRepPropertyKey;
175}
176
177extern "C" {
178 pub static NSImageCurrentFrame: &'static NSBitmapImageRepPropertyKey;
180}
181
182extern "C" {
183 pub static NSImageCurrentFrameDuration: &'static NSBitmapImageRepPropertyKey;
185}
186
187extern "C" {
188 pub static NSImageLoopCount: &'static NSBitmapImageRepPropertyKey;
190}
191
192extern "C" {
193 pub static NSImageGamma: &'static NSBitmapImageRepPropertyKey;
195}
196
197extern "C" {
198 pub static NSImageProgressive: &'static NSBitmapImageRepPropertyKey;
200}
201
202extern "C" {
203 pub static NSImageEXIFData: &'static NSBitmapImageRepPropertyKey;
205}
206
207extern "C" {
208 pub static NSImageIPTCData: &'static NSBitmapImageRepPropertyKey;
210}
211
212extern "C" {
213 pub static NSImageFallbackBackgroundColor: &'static NSBitmapImageRepPropertyKey;
215}
216
217extern_class!(
218 #[unsafe(super(NSImageRep, NSObject))]
220 #[derive(Debug, PartialEq, Eq, Hash)]
221 #[cfg(feature = "NSImageRep")]
222 pub struct NSBitmapImageRep;
223);
224
225#[cfg(feature = "NSImageRep")]
226extern_conformance!(
227 unsafe impl NSCoding for NSBitmapImageRep {}
228);
229
230#[cfg(feature = "NSImageRep")]
231extern_conformance!(
232 unsafe impl NSCopying for NSBitmapImageRep {}
233);
234
235#[cfg(feature = "NSImageRep")]
236unsafe impl CopyingHelper for NSBitmapImageRep {
237 type Result = Self;
238}
239
240#[cfg(feature = "NSImageRep")]
241extern_conformance!(
242 unsafe impl NSObjectProtocol for NSBitmapImageRep {}
243);
244
245#[cfg(feature = "NSImageRep")]
246extern_conformance!(
247 unsafe impl NSSecureCoding for NSBitmapImageRep {}
248);
249
250#[cfg(feature = "NSImageRep")]
251impl NSBitmapImageRep {
252 extern_methods!(
253 #[deprecated = "Use -[NSView cacheDisplayInRect:toBitmapImageRep:] to snapshot a view."]
254 #[unsafe(method(initWithFocusedViewRect:))]
255 #[unsafe(method_family = init)]
256 pub unsafe fn initWithFocusedViewRect(
257 this: Allocated<Self>,
258 rect: NSRect,
259 ) -> Option<Retained<Self>>;
260
261 #[cfg(feature = "NSGraphics")]
262 #[unsafe(method(initWithBitmapDataPlanes:pixelsWide:pixelsHigh:bitsPerSample:samplesPerPixel:hasAlpha:isPlanar:colorSpaceName:bytesPerRow:bitsPerPixel:))]
263 #[unsafe(method_family = init)]
264 pub unsafe fn initWithBitmapDataPlanes_pixelsWide_pixelsHigh_bitsPerSample_samplesPerPixel_hasAlpha_isPlanar_colorSpaceName_bytesPerRow_bitsPerPixel(
265 this: Allocated<Self>,
266 planes: *mut *mut c_uchar,
267 width: NSInteger,
268 height: NSInteger,
269 bps: NSInteger,
270 spp: NSInteger,
271 alpha: bool,
272 is_planar: bool,
273 color_space_name: &NSColorSpaceName,
274 r_bytes: NSInteger,
275 p_bits: NSInteger,
276 ) -> Option<Retained<Self>>;
277
278 #[cfg(feature = "NSGraphics")]
279 #[unsafe(method(initWithBitmapDataPlanes:pixelsWide:pixelsHigh:bitsPerSample:samplesPerPixel:hasAlpha:isPlanar:colorSpaceName:bitmapFormat:bytesPerRow:bitsPerPixel:))]
280 #[unsafe(method_family = init)]
281 pub unsafe fn initWithBitmapDataPlanes_pixelsWide_pixelsHigh_bitsPerSample_samplesPerPixel_hasAlpha_isPlanar_colorSpaceName_bitmapFormat_bytesPerRow_bitsPerPixel(
282 this: Allocated<Self>,
283 planes: *mut *mut c_uchar,
284 width: NSInteger,
285 height: NSInteger,
286 bps: NSInteger,
287 spp: NSInteger,
288 alpha: bool,
289 is_planar: bool,
290 color_space_name: &NSColorSpaceName,
291 bitmap_format: NSBitmapFormat,
292 r_bytes: NSInteger,
293 p_bits: NSInteger,
294 ) -> Option<Retained<Self>>;
295
296 #[cfg(feature = "objc2-core-graphics")]
297 #[cfg(target_vendor = "apple")]
298 #[unsafe(method(initWithCGImage:))]
299 #[unsafe(method_family = init)]
300 pub unsafe fn initWithCGImage(this: Allocated<Self>, cg_image: &CGImage) -> Retained<Self>;
301
302 #[cfg(feature = "objc2-core-image")]
303 #[cfg(target_vendor = "apple")]
304 #[unsafe(method(initWithCIImage:))]
305 #[unsafe(method_family = init)]
306 pub unsafe fn initWithCIImage(this: Allocated<Self>, ci_image: &CIImage) -> Retained<Self>;
307
308 #[unsafe(method(imageRepsWithData:))]
309 #[unsafe(method_family = none)]
310 pub unsafe fn imageRepsWithData(data: &NSData) -> Retained<NSArray<NSImageRep>>;
311
312 #[unsafe(method(imageRepWithData:))]
313 #[unsafe(method_family = none)]
314 pub unsafe fn imageRepWithData(data: &NSData) -> Option<Retained<Self>>;
315
316 #[unsafe(method(initWithData:))]
317 #[unsafe(method_family = init)]
318 pub unsafe fn initWithData(this: Allocated<Self>, data: &NSData) -> Option<Retained<Self>>;
319
320 #[unsafe(method(bitmapData))]
321 #[unsafe(method_family = none)]
322 pub unsafe fn bitmapData(&self) -> *mut c_uchar;
323
324 #[unsafe(method(getBitmapDataPlanes:))]
325 #[unsafe(method_family = none)]
326 pub unsafe fn getBitmapDataPlanes(&self, data: NonNull<*mut c_uchar>);
327
328 #[unsafe(method(isPlanar))]
329 #[unsafe(method_family = none)]
330 pub unsafe fn isPlanar(&self) -> bool;
331
332 #[unsafe(method(samplesPerPixel))]
333 #[unsafe(method_family = none)]
334 pub unsafe fn samplesPerPixel(&self) -> NSInteger;
335
336 #[unsafe(method(bitsPerPixel))]
337 #[unsafe(method_family = none)]
338 pub unsafe fn bitsPerPixel(&self) -> NSInteger;
339
340 #[unsafe(method(bytesPerRow))]
341 #[unsafe(method_family = none)]
342 pub unsafe fn bytesPerRow(&self) -> NSInteger;
343
344 #[unsafe(method(bytesPerPlane))]
345 #[unsafe(method_family = none)]
346 pub unsafe fn bytesPerPlane(&self) -> NSInteger;
347
348 #[unsafe(method(numberOfPlanes))]
349 #[unsafe(method_family = none)]
350 pub unsafe fn numberOfPlanes(&self) -> NSInteger;
351
352 #[unsafe(method(bitmapFormat))]
353 #[unsafe(method_family = none)]
354 pub unsafe fn bitmapFormat(&self) -> NSBitmapFormat;
355
356 #[unsafe(method(getCompression:factor:))]
357 #[unsafe(method_family = none)]
358 pub unsafe fn getCompression_factor(
359 &self,
360 compression: *mut NSTIFFCompression,
361 factor: *mut c_float,
362 );
363
364 #[unsafe(method(setCompression:factor:))]
365 #[unsafe(method_family = none)]
366 pub unsafe fn setCompression_factor(&self, compression: NSTIFFCompression, factor: c_float);
367
368 #[unsafe(method(TIFFRepresentation))]
369 #[unsafe(method_family = none)]
370 pub unsafe fn TIFFRepresentation(&self) -> Option<Retained<NSData>>;
371
372 #[unsafe(method(TIFFRepresentationUsingCompression:factor:))]
373 #[unsafe(method_family = none)]
374 pub unsafe fn TIFFRepresentationUsingCompression_factor(
375 &self,
376 comp: NSTIFFCompression,
377 factor: c_float,
378 ) -> Option<Retained<NSData>>;
379
380 #[unsafe(method(TIFFRepresentationOfImageRepsInArray:))]
381 #[unsafe(method_family = none)]
382 pub unsafe fn TIFFRepresentationOfImageRepsInArray(
383 array: &NSArray<NSImageRep>,
384 ) -> Option<Retained<NSData>>;
385
386 #[unsafe(method(TIFFRepresentationOfImageRepsInArray:usingCompression:factor:))]
387 #[unsafe(method_family = none)]
388 pub unsafe fn TIFFRepresentationOfImageRepsInArray_usingCompression_factor(
389 array: &NSArray<NSImageRep>,
390 comp: NSTIFFCompression,
391 factor: c_float,
392 ) -> Option<Retained<NSData>>;
393
394 #[unsafe(method(getTIFFCompressionTypes:count:))]
395 #[unsafe(method_family = none)]
396 pub unsafe fn getTIFFCompressionTypes_count(
397 list: NonNull<*const NSTIFFCompression>,
398 num_types: NonNull<NSInteger>,
399 );
400
401 #[unsafe(method(localizedNameForTIFFCompressionType:))]
402 #[unsafe(method_family = none)]
403 pub unsafe fn localizedNameForTIFFCompressionType(
404 compression: NSTIFFCompression,
405 ) -> Option<Retained<NSString>>;
406
407 #[unsafe(method(canBeCompressedUsing:))]
408 #[unsafe(method_family = none)]
409 pub unsafe fn canBeCompressedUsing(&self, compression: NSTIFFCompression) -> bool;
410
411 #[cfg(all(feature = "NSColor", feature = "objc2-core-foundation"))]
412 #[unsafe(method(colorizeByMappingGray:toColor:blackMapping:whiteMapping:))]
413 #[unsafe(method_family = none)]
414 pub unsafe fn colorizeByMappingGray_toColor_blackMapping_whiteMapping(
415 &self,
416 mid_point: CGFloat,
417 mid_point_color: Option<&NSColor>,
418 shadow_color: Option<&NSColor>,
419 light_color: Option<&NSColor>,
420 );
421
422 #[unsafe(method(initForIncrementalLoad))]
423 #[unsafe(method_family = init)]
424 pub unsafe fn initForIncrementalLoad(this: Allocated<Self>) -> Retained<Self>;
425
426 #[unsafe(method(incrementalLoadFromData:complete:))]
427 #[unsafe(method_family = none)]
428 pub unsafe fn incrementalLoadFromData_complete(
429 &self,
430 data: &NSData,
431 complete: bool,
432 ) -> NSInteger;
433
434 #[cfg(feature = "NSColor")]
435 #[unsafe(method(setColor:atX:y:))]
436 #[unsafe(method_family = none)]
437 pub unsafe fn setColor_atX_y(&self, color: &NSColor, x: NSInteger, y: NSInteger);
438
439 #[cfg(feature = "NSColor")]
440 #[unsafe(method(colorAtX:y:))]
441 #[unsafe(method_family = none)]
442 pub unsafe fn colorAtX_y(&self, x: NSInteger, y: NSInteger) -> Option<Retained<NSColor>>;
443
444 #[unsafe(method(getPixel:atX:y:))]
445 #[unsafe(method_family = none)]
446 pub unsafe fn getPixel_atX_y(&self, p: NonNull<NSUInteger>, x: NSInteger, y: NSInteger);
447
448 #[unsafe(method(setPixel:atX:y:))]
449 #[unsafe(method_family = none)]
450 pub unsafe fn setPixel_atX_y(&self, p: NonNull<NSUInteger>, x: NSInteger, y: NSInteger);
451
452 #[cfg(feature = "objc2-core-graphics")]
453 #[cfg(target_vendor = "apple")]
454 #[unsafe(method(CGImage))]
455 #[unsafe(method_family = none)]
456 pub unsafe fn CGImage(&self) -> Option<Retained<CGImage>>;
457
458 #[cfg(feature = "NSColorSpace")]
459 #[unsafe(method(colorSpace))]
460 #[unsafe(method_family = none)]
461 pub unsafe fn colorSpace(&self) -> Retained<NSColorSpace>;
462
463 #[cfg(all(feature = "NSColorSpace", feature = "NSGraphics"))]
464 #[unsafe(method(bitmapImageRepByConvertingToColorSpace:renderingIntent:))]
465 #[unsafe(method_family = none)]
466 pub unsafe fn bitmapImageRepByConvertingToColorSpace_renderingIntent(
467 &self,
468 target_space: &NSColorSpace,
469 rendering_intent: NSColorRenderingIntent,
470 ) -> Option<Retained<NSBitmapImageRep>>;
471
472 #[cfg(feature = "NSColorSpace")]
473 #[unsafe(method(bitmapImageRepByRetaggingWithColorSpace:))]
474 #[unsafe(method_family = none)]
475 pub unsafe fn bitmapImageRepByRetaggingWithColorSpace(
476 &self,
477 new_space: &NSColorSpace,
478 ) -> Option<Retained<NSBitmapImageRep>>;
479 );
480}
481
482#[cfg(feature = "NSImageRep")]
484impl NSBitmapImageRep {
485 extern_methods!(
486 #[unsafe(method(init))]
487 #[unsafe(method_family = init)]
488 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
489
490 #[unsafe(method(initWithCoder:))]
491 #[unsafe(method_family = init)]
492 pub unsafe fn initWithCoder(
493 this: Allocated<Self>,
494 coder: &NSCoder,
495 ) -> Option<Retained<Self>>;
496 );
497}
498
499#[cfg(feature = "NSImageRep")]
501impl NSBitmapImageRep {
502 extern_methods!(
503 #[unsafe(method(new))]
504 #[unsafe(method_family = new)]
505 pub unsafe fn new() -> Retained<Self>;
506 );
507}
508
509#[cfg(feature = "NSImageRep")]
511impl NSBitmapImageRep {
512 extern_methods!(
513 #[unsafe(method(representationOfImageRepsInArray:usingType:properties:))]
514 #[unsafe(method_family = none)]
515 pub unsafe fn representationOfImageRepsInArray_usingType_properties(
516 image_reps: &NSArray<NSImageRep>,
517 storage_type: NSBitmapImageFileType,
518 properties: &NSDictionary<NSBitmapImageRepPropertyKey, AnyObject>,
519 ) -> Option<Retained<NSData>>;
520
521 #[unsafe(method(representationUsingType:properties:))]
522 #[unsafe(method_family = none)]
523 pub unsafe fn representationUsingType_properties(
524 &self,
525 storage_type: NSBitmapImageFileType,
526 properties: &NSDictionary<NSBitmapImageRepPropertyKey, AnyObject>,
527 ) -> Option<Retained<NSData>>;
528
529 #[unsafe(method(setProperty:withValue:))]
530 #[unsafe(method_family = none)]
531 pub unsafe fn setProperty_withValue(
532 &self,
533 property: &NSBitmapImageRepPropertyKey,
534 value: Option<&AnyObject>,
535 );
536
537 #[unsafe(method(valueForProperty:))]
538 #[unsafe(method_family = none)]
539 pub unsafe fn valueForProperty(
540 &self,
541 property: &NSBitmapImageRepPropertyKey,
542 ) -> Option<Retained<AnyObject>>;
543 );
544}
545
546pub static NSTIFFFileType: NSBitmapImageFileType =
548 NSBitmapImageFileType(NSBitmapImageFileType::TIFF.0);
549
550pub static NSBMPFileType: NSBitmapImageFileType =
552 NSBitmapImageFileType(NSBitmapImageFileType::BMP.0);
553
554pub static NSGIFFileType: NSBitmapImageFileType =
556 NSBitmapImageFileType(NSBitmapImageFileType::GIF.0);
557
558pub static NSJPEGFileType: NSBitmapImageFileType =
560 NSBitmapImageFileType(NSBitmapImageFileType::JPEG.0);
561
562pub static NSPNGFileType: NSBitmapImageFileType =
564 NSBitmapImageFileType(NSBitmapImageFileType::PNG.0);
565
566pub static NSJPEG2000FileType: NSBitmapImageFileType =
568 NSBitmapImageFileType(NSBitmapImageFileType::JPEG2000.0);
569
570pub static NSAlphaFirstBitmapFormat: NSBitmapFormat = NSBitmapFormat(NSBitmapFormat::AlphaFirst.0);
572
573pub static NSAlphaNonpremultipliedBitmapFormat: NSBitmapFormat =
575 NSBitmapFormat(NSBitmapFormat::AlphaNonpremultiplied.0);
576
577pub static NSFloatingPointSamplesBitmapFormat: NSBitmapFormat =
579 NSBitmapFormat(NSBitmapFormat::FloatingPointSamples.0);
580
581pub static NS16BitLittleEndianBitmapFormat: NSBitmapFormat =
583 NSBitmapFormat(NSBitmapFormat::SixteenBitLittleEndian.0);
584
585pub static NS32BitLittleEndianBitmapFormat: NSBitmapFormat =
587 NSBitmapFormat(NSBitmapFormat::ThirtyTwoBitLittleEndian.0);
588
589pub static NS16BitBigEndianBitmapFormat: NSBitmapFormat =
591 NSBitmapFormat(NSBitmapFormat::SixteenBitBigEndian.0);
592
593pub static NS32BitBigEndianBitmapFormat: NSBitmapFormat =
595 NSBitmapFormat(NSBitmapFormat::ThirtyTwoBitBigEndian.0);