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")]
226unsafe impl NSCoding for NSBitmapImageRep {}
227
228#[cfg(feature = "NSImageRep")]
229unsafe impl NSCopying for NSBitmapImageRep {}
230
231#[cfg(feature = "NSImageRep")]
232unsafe impl CopyingHelper for NSBitmapImageRep {
233 type Result = Self;
234}
235
236#[cfg(feature = "NSImageRep")]
237unsafe impl NSObjectProtocol for NSBitmapImageRep {}
238
239#[cfg(feature = "NSImageRep")]
240unsafe impl NSSecureCoding for NSBitmapImageRep {}
241
242#[cfg(feature = "NSImageRep")]
243impl NSBitmapImageRep {
244 extern_methods!(
245 #[deprecated = "Use -[NSView cacheDisplayInRect:toBitmapImageRep:] to snapshot a view."]
246 #[unsafe(method(initWithFocusedViewRect:))]
247 #[unsafe(method_family = init)]
248 pub unsafe fn initWithFocusedViewRect(
249 this: Allocated<Self>,
250 rect: NSRect,
251 ) -> Option<Retained<Self>>;
252
253 #[cfg(feature = "NSGraphics")]
254 #[unsafe(method(initWithBitmapDataPlanes:pixelsWide:pixelsHigh:bitsPerSample:samplesPerPixel:hasAlpha:isPlanar:colorSpaceName:bytesPerRow:bitsPerPixel:))]
255 #[unsafe(method_family = init)]
256 pub unsafe fn initWithBitmapDataPlanes_pixelsWide_pixelsHigh_bitsPerSample_samplesPerPixel_hasAlpha_isPlanar_colorSpaceName_bytesPerRow_bitsPerPixel(
257 this: Allocated<Self>,
258 planes: *mut *mut c_uchar,
259 width: NSInteger,
260 height: NSInteger,
261 bps: NSInteger,
262 spp: NSInteger,
263 alpha: bool,
264 is_planar: bool,
265 color_space_name: &NSColorSpaceName,
266 r_bytes: NSInteger,
267 p_bits: NSInteger,
268 ) -> Option<Retained<Self>>;
269
270 #[cfg(feature = "NSGraphics")]
271 #[unsafe(method(initWithBitmapDataPlanes:pixelsWide:pixelsHigh:bitsPerSample:samplesPerPixel:hasAlpha:isPlanar:colorSpaceName:bitmapFormat:bytesPerRow:bitsPerPixel:))]
272 #[unsafe(method_family = init)]
273 pub unsafe fn initWithBitmapDataPlanes_pixelsWide_pixelsHigh_bitsPerSample_samplesPerPixel_hasAlpha_isPlanar_colorSpaceName_bitmapFormat_bytesPerRow_bitsPerPixel(
274 this: Allocated<Self>,
275 planes: *mut *mut c_uchar,
276 width: NSInteger,
277 height: NSInteger,
278 bps: NSInteger,
279 spp: NSInteger,
280 alpha: bool,
281 is_planar: bool,
282 color_space_name: &NSColorSpaceName,
283 bitmap_format: NSBitmapFormat,
284 r_bytes: NSInteger,
285 p_bits: NSInteger,
286 ) -> Option<Retained<Self>>;
287
288 #[cfg(feature = "objc2-core-graphics")]
289 #[cfg(target_vendor = "apple")]
290 #[unsafe(method(initWithCGImage:))]
291 #[unsafe(method_family = init)]
292 pub unsafe fn initWithCGImage(this: Allocated<Self>, cg_image: &CGImage) -> Retained<Self>;
293
294 #[cfg(feature = "objc2-core-image")]
295 #[cfg(target_vendor = "apple")]
296 #[unsafe(method(initWithCIImage:))]
297 #[unsafe(method_family = init)]
298 pub unsafe fn initWithCIImage(this: Allocated<Self>, ci_image: &CIImage) -> Retained<Self>;
299
300 #[unsafe(method(imageRepsWithData:))]
301 #[unsafe(method_family = none)]
302 pub unsafe fn imageRepsWithData(data: &NSData) -> Retained<NSArray<NSImageRep>>;
303
304 #[unsafe(method(imageRepWithData:))]
305 #[unsafe(method_family = none)]
306 pub unsafe fn imageRepWithData(data: &NSData) -> Option<Retained<Self>>;
307
308 #[unsafe(method(initWithData:))]
309 #[unsafe(method_family = init)]
310 pub unsafe fn initWithData(this: Allocated<Self>, data: &NSData) -> Option<Retained<Self>>;
311
312 #[unsafe(method(bitmapData))]
313 #[unsafe(method_family = none)]
314 pub unsafe fn bitmapData(&self) -> *mut c_uchar;
315
316 #[unsafe(method(getBitmapDataPlanes:))]
317 #[unsafe(method_family = none)]
318 pub unsafe fn getBitmapDataPlanes(&self, data: NonNull<*mut c_uchar>);
319
320 #[unsafe(method(isPlanar))]
321 #[unsafe(method_family = none)]
322 pub unsafe fn isPlanar(&self) -> bool;
323
324 #[unsafe(method(samplesPerPixel))]
325 #[unsafe(method_family = none)]
326 pub unsafe fn samplesPerPixel(&self) -> NSInteger;
327
328 #[unsafe(method(bitsPerPixel))]
329 #[unsafe(method_family = none)]
330 pub unsafe fn bitsPerPixel(&self) -> NSInteger;
331
332 #[unsafe(method(bytesPerRow))]
333 #[unsafe(method_family = none)]
334 pub unsafe fn bytesPerRow(&self) -> NSInteger;
335
336 #[unsafe(method(bytesPerPlane))]
337 #[unsafe(method_family = none)]
338 pub unsafe fn bytesPerPlane(&self) -> NSInteger;
339
340 #[unsafe(method(numberOfPlanes))]
341 #[unsafe(method_family = none)]
342 pub unsafe fn numberOfPlanes(&self) -> NSInteger;
343
344 #[unsafe(method(bitmapFormat))]
345 #[unsafe(method_family = none)]
346 pub unsafe fn bitmapFormat(&self) -> NSBitmapFormat;
347
348 #[unsafe(method(getCompression:factor:))]
349 #[unsafe(method_family = none)]
350 pub unsafe fn getCompression_factor(
351 &self,
352 compression: *mut NSTIFFCompression,
353 factor: *mut c_float,
354 );
355
356 #[unsafe(method(setCompression:factor:))]
357 #[unsafe(method_family = none)]
358 pub unsafe fn setCompression_factor(&self, compression: NSTIFFCompression, factor: c_float);
359
360 #[unsafe(method(TIFFRepresentation))]
361 #[unsafe(method_family = none)]
362 pub unsafe fn TIFFRepresentation(&self) -> Option<Retained<NSData>>;
363
364 #[unsafe(method(TIFFRepresentationUsingCompression:factor:))]
365 #[unsafe(method_family = none)]
366 pub unsafe fn TIFFRepresentationUsingCompression_factor(
367 &self,
368 comp: NSTIFFCompression,
369 factor: c_float,
370 ) -> Option<Retained<NSData>>;
371
372 #[unsafe(method(TIFFRepresentationOfImageRepsInArray:))]
373 #[unsafe(method_family = none)]
374 pub unsafe fn TIFFRepresentationOfImageRepsInArray(
375 array: &NSArray<NSImageRep>,
376 ) -> Option<Retained<NSData>>;
377
378 #[unsafe(method(TIFFRepresentationOfImageRepsInArray:usingCompression:factor:))]
379 #[unsafe(method_family = none)]
380 pub unsafe fn TIFFRepresentationOfImageRepsInArray_usingCompression_factor(
381 array: &NSArray<NSImageRep>,
382 comp: NSTIFFCompression,
383 factor: c_float,
384 ) -> Option<Retained<NSData>>;
385
386 #[unsafe(method(getTIFFCompressionTypes:count:))]
387 #[unsafe(method_family = none)]
388 pub unsafe fn getTIFFCompressionTypes_count(
389 list: NonNull<*const NSTIFFCompression>,
390 num_types: NonNull<NSInteger>,
391 );
392
393 #[unsafe(method(localizedNameForTIFFCompressionType:))]
394 #[unsafe(method_family = none)]
395 pub unsafe fn localizedNameForTIFFCompressionType(
396 compression: NSTIFFCompression,
397 ) -> Option<Retained<NSString>>;
398
399 #[unsafe(method(canBeCompressedUsing:))]
400 #[unsafe(method_family = none)]
401 pub unsafe fn canBeCompressedUsing(&self, compression: NSTIFFCompression) -> bool;
402
403 #[cfg(all(feature = "NSColor", feature = "objc2-core-foundation"))]
404 #[unsafe(method(colorizeByMappingGray:toColor:blackMapping:whiteMapping:))]
405 #[unsafe(method_family = none)]
406 pub unsafe fn colorizeByMappingGray_toColor_blackMapping_whiteMapping(
407 &self,
408 mid_point: CGFloat,
409 mid_point_color: Option<&NSColor>,
410 shadow_color: Option<&NSColor>,
411 light_color: Option<&NSColor>,
412 );
413
414 #[unsafe(method(initForIncrementalLoad))]
415 #[unsafe(method_family = init)]
416 pub unsafe fn initForIncrementalLoad(this: Allocated<Self>) -> Retained<Self>;
417
418 #[unsafe(method(incrementalLoadFromData:complete:))]
419 #[unsafe(method_family = none)]
420 pub unsafe fn incrementalLoadFromData_complete(
421 &self,
422 data: &NSData,
423 complete: bool,
424 ) -> NSInteger;
425
426 #[cfg(feature = "NSColor")]
427 #[unsafe(method(setColor:atX:y:))]
428 #[unsafe(method_family = none)]
429 pub unsafe fn setColor_atX_y(&self, color: &NSColor, x: NSInteger, y: NSInteger);
430
431 #[cfg(feature = "NSColor")]
432 #[unsafe(method(colorAtX:y:))]
433 #[unsafe(method_family = none)]
434 pub unsafe fn colorAtX_y(&self, x: NSInteger, y: NSInteger) -> Option<Retained<NSColor>>;
435
436 #[unsafe(method(getPixel:atX:y:))]
437 #[unsafe(method_family = none)]
438 pub unsafe fn getPixel_atX_y(&self, p: NonNull<NSUInteger>, x: NSInteger, y: NSInteger);
439
440 #[unsafe(method(setPixel:atX:y:))]
441 #[unsafe(method_family = none)]
442 pub unsafe fn setPixel_atX_y(&self, p: NonNull<NSUInteger>, x: NSInteger, y: NSInteger);
443
444 #[cfg(feature = "objc2-core-graphics")]
445 #[cfg(target_vendor = "apple")]
446 #[unsafe(method(CGImage))]
447 #[unsafe(method_family = none)]
448 pub unsafe fn CGImage(&self) -> Option<Retained<CGImage>>;
449
450 #[cfg(feature = "NSColorSpace")]
451 #[unsafe(method(colorSpace))]
452 #[unsafe(method_family = none)]
453 pub unsafe fn colorSpace(&self) -> Retained<NSColorSpace>;
454
455 #[cfg(all(feature = "NSColorSpace", feature = "NSGraphics"))]
456 #[unsafe(method(bitmapImageRepByConvertingToColorSpace:renderingIntent:))]
457 #[unsafe(method_family = none)]
458 pub unsafe fn bitmapImageRepByConvertingToColorSpace_renderingIntent(
459 &self,
460 target_space: &NSColorSpace,
461 rendering_intent: NSColorRenderingIntent,
462 ) -> Option<Retained<NSBitmapImageRep>>;
463
464 #[cfg(feature = "NSColorSpace")]
465 #[unsafe(method(bitmapImageRepByRetaggingWithColorSpace:))]
466 #[unsafe(method_family = none)]
467 pub unsafe fn bitmapImageRepByRetaggingWithColorSpace(
468 &self,
469 new_space: &NSColorSpace,
470 ) -> Option<Retained<NSBitmapImageRep>>;
471 );
472}
473
474#[cfg(feature = "NSImageRep")]
476impl NSBitmapImageRep {
477 extern_methods!(
478 #[unsafe(method(init))]
479 #[unsafe(method_family = init)]
480 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
481
482 #[unsafe(method(initWithCoder:))]
483 #[unsafe(method_family = init)]
484 pub unsafe fn initWithCoder(
485 this: Allocated<Self>,
486 coder: &NSCoder,
487 ) -> Option<Retained<Self>>;
488 );
489}
490
491#[cfg(feature = "NSImageRep")]
493impl NSBitmapImageRep {
494 extern_methods!(
495 #[unsafe(method(new))]
496 #[unsafe(method_family = new)]
497 pub unsafe fn new() -> Retained<Self>;
498 );
499}
500
501#[cfg(feature = "NSImageRep")]
503impl NSBitmapImageRep {
504 extern_methods!(
505 #[unsafe(method(representationOfImageRepsInArray:usingType:properties:))]
506 #[unsafe(method_family = none)]
507 pub unsafe fn representationOfImageRepsInArray_usingType_properties(
508 image_reps: &NSArray<NSImageRep>,
509 storage_type: NSBitmapImageFileType,
510 properties: &NSDictionary<NSBitmapImageRepPropertyKey, AnyObject>,
511 ) -> Option<Retained<NSData>>;
512
513 #[unsafe(method(representationUsingType:properties:))]
514 #[unsafe(method_family = none)]
515 pub unsafe fn representationUsingType_properties(
516 &self,
517 storage_type: NSBitmapImageFileType,
518 properties: &NSDictionary<NSBitmapImageRepPropertyKey, AnyObject>,
519 ) -> Option<Retained<NSData>>;
520
521 #[unsafe(method(setProperty:withValue:))]
522 #[unsafe(method_family = none)]
523 pub unsafe fn setProperty_withValue(
524 &self,
525 property: &NSBitmapImageRepPropertyKey,
526 value: Option<&AnyObject>,
527 );
528
529 #[unsafe(method(valueForProperty:))]
530 #[unsafe(method_family = none)]
531 pub unsafe fn valueForProperty(
532 &self,
533 property: &NSBitmapImageRepPropertyKey,
534 ) -> Option<Retained<AnyObject>>;
535 );
536}
537
538pub static NSTIFFFileType: NSBitmapImageFileType =
540 NSBitmapImageFileType(NSBitmapImageFileType::TIFF.0);
541
542pub static NSBMPFileType: NSBitmapImageFileType =
544 NSBitmapImageFileType(NSBitmapImageFileType::BMP.0);
545
546pub static NSGIFFileType: NSBitmapImageFileType =
548 NSBitmapImageFileType(NSBitmapImageFileType::GIF.0);
549
550pub static NSJPEGFileType: NSBitmapImageFileType =
552 NSBitmapImageFileType(NSBitmapImageFileType::JPEG.0);
553
554pub static NSPNGFileType: NSBitmapImageFileType =
556 NSBitmapImageFileType(NSBitmapImageFileType::PNG.0);
557
558pub static NSJPEG2000FileType: NSBitmapImageFileType =
560 NSBitmapImageFileType(NSBitmapImageFileType::JPEG2000.0);
561
562pub static NSAlphaFirstBitmapFormat: NSBitmapFormat = NSBitmapFormat(NSBitmapFormat::AlphaFirst.0);
564
565pub static NSAlphaNonpremultipliedBitmapFormat: NSBitmapFormat =
567 NSBitmapFormat(NSBitmapFormat::AlphaNonpremultiplied.0);
568
569pub static NSFloatingPointSamplesBitmapFormat: NSBitmapFormat =
571 NSBitmapFormat(NSBitmapFormat::FloatingPointSamples.0);
572
573pub static NS16BitLittleEndianBitmapFormat: NSBitmapFormat =
575 NSBitmapFormat(NSBitmapFormat::SixteenBitLittleEndian.0);
576
577pub static NS32BitLittleEndianBitmapFormat: NSBitmapFormat =
579 NSBitmapFormat(NSBitmapFormat::ThirtyTwoBitLittleEndian.0);
580
581pub static NS16BitBigEndianBitmapFormat: NSBitmapFormat =
583 NSBitmapFormat(NSBitmapFormat::SixteenBitBigEndian.0);
584
585pub static NS32BitBigEndianBitmapFormat: NSBitmapFormat =
587 NSBitmapFormat(NSBitmapFormat::ThirtyTwoBitBigEndian.0);