1616static NSString *const FICImageFormatFamilyKey = @" family" ;
1717static NSString *const FICImageFormatWidthKey = @" width" ;
1818static NSString *const FICImageFormatHeightKey = @" height" ;
19- static NSString *const FICImageFormatIsOpaqueKey = @" isOpaque " ;
19+ static NSString *const FICImageFormatStyleKey = @" style " ;
2020static NSString *const FICImageFormatMaximumCountKey = @" maximumCount" ;
2121static NSString *const FICImageFormatDevicesKey = @" devices" ;
2222
@@ -27,7 +27,7 @@ @interface FICImageFormat () {
2727 NSString *_family;
2828 CGSize _imageSize;
2929 CGSize _pixelSize;
30- BOOL _isOpaque ;
30+ FICImageFormatStyle _style ;
3131 NSInteger _maximumCount;
3232 FICImageFormatDevices _devices;
3333}
@@ -42,7 +42,7 @@ @implementation FICImageFormat
4242@synthesize family = _family;
4343@synthesize imageSize = _imageSize;
4444@synthesize pixelSize = _pixelSize;
45- @synthesize opaque = _isOpaque ;
45+ @synthesize style = _style ;
4646@synthesize maximumCount = _maximumCount;
4747@synthesize devices = _devices;
4848
@@ -58,15 +58,75 @@ - (void)setImageSize:(CGSize)imageSize {
5858 }
5959}
6060
61+ - (CGBitmapInfo)bitmapInfo {
62+ CGBitmapInfo info;
63+ switch (_style) {
64+ case FICImageFormatStyle32BitBGRA:
65+ info = kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host ;
66+ break ;
67+ case FICImageFormatStyle16BitBGR:
68+ info = kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder16Host ;
69+ break ;
70+ case FICImageFormatStyle8BitGrayscale:
71+ info = (CGBitmapInfo)kCGImageAlphaNone ;
72+ break ;
73+ }
74+ return info;
75+ }
76+
77+ - (NSInteger )bytesPerPixel {
78+ NSInteger bytesPerPixel;
79+ switch (_style) {
80+ case FICImageFormatStyle32BitBGRA:
81+ bytesPerPixel = 4 ;
82+ break ;
83+ case FICImageFormatStyle16BitBGR:
84+ bytesPerPixel = 2 ;
85+ break ;
86+ case FICImageFormatStyle8BitGrayscale:
87+ bytesPerPixel = 1 ;
88+ break ;
89+ }
90+ return bytesPerPixel;
91+ }
92+
93+ - (NSInteger )bitsPerComponent {
94+ NSInteger bitsPerComponent;
95+ switch (_style) {
96+ case FICImageFormatStyle32BitBGRA:
97+ case FICImageFormatStyle8BitGrayscale:
98+ bitsPerComponent = 8 ;
99+ break ;
100+ case FICImageFormatStyle16BitBGR:
101+ bitsPerComponent = 5 ;
102+ break ;
103+ }
104+ return bitsPerComponent;
105+ }
106+
107+ - (BOOL )isGrayscale {
108+ BOOL isGrayscale;
109+ switch (_style) {
110+ case FICImageFormatStyle32BitBGRA:
111+ case FICImageFormatStyle16BitBGR:
112+ isGrayscale = NO ;
113+ break ;
114+ case FICImageFormatStyle8BitGrayscale:
115+ isGrayscale = YES ;
116+ break ;
117+ }
118+ return isGrayscale;
119+ }
120+
61121#pragma mark - Object Lifecycle
62122
63- + (instancetype )formatWithName : (NSString *)name family : (NSString *)family imageSize : (CGSize)imageSize isOpaque : ( BOOL ) isOpaque maximumCount : (NSInteger )maximumCount devices : (FICImageFormatDevices)devices {
123+ + (instancetype )formatWithName : (NSString *)name family : (NSString *)family imageSize : (CGSize)imageSize style : (FICImageFormatStyle) style maximumCount : (NSInteger )maximumCount devices : (FICImageFormatDevices)devices {
64124 FICImageFormat *imageFormat = [[FICImageFormat alloc ] init ];
65125
66126 [imageFormat setName: name];
67127 [imageFormat setFamily: family];
68128 [imageFormat setImageSize: imageSize];
69- [imageFormat setOpaque: isOpaque ];
129+ [imageFormat setStyle: style ];
70130 [imageFormat setMaximumCount: maximumCount];
71131 [imageFormat setDevices: devices];
72132
@@ -82,7 +142,7 @@ - (NSDictionary *)dictionaryRepresentation {
82142 [dictionaryRepresentation setValue: _family forKey: FICImageFormatFamilyKey];
83143 [dictionaryRepresentation setValue: [NSNumber numberWithUnsignedInteger: _imageSize.width] forKey: FICImageFormatWidthKey];
84144 [dictionaryRepresentation setValue: [NSNumber numberWithUnsignedInteger: _imageSize.height] forKey: FICImageFormatHeightKey];
85- [dictionaryRepresentation setValue: [NSNumber numberWithBool: _isOpaque ] forKey: FICImageFormatIsOpaqueKey ];
145+ [dictionaryRepresentation setValue: [NSNumber numberWithInt: _style ] forKey: FICImageFormatStyleKey ];
86146 [dictionaryRepresentation setValue: [NSNumber numberWithUnsignedInteger: _maximumCount] forKey: FICImageFormatMaximumCountKey];
87147 [dictionaryRepresentation setValue: [NSNumber numberWithInt: _devices] forKey: FICImageFormatDevicesKey];
88148 [dictionaryRepresentation setValue: [NSNumber numberWithFloat: [[UIScreen mainScreen ] scale ]] forKey: FICImageTableScreenScaleKey];
@@ -101,7 +161,7 @@ - (id)copyWithZone:(NSZone *)zone {
101161 [imageFormatCopy setName: [self name ]];
102162 [imageFormatCopy setFamily: [self family ]];
103163 [imageFormatCopy setImageSize: [self imageSize ]];
104- [imageFormatCopy setOpaque : [self isOpaque ]];
164+ [imageFormatCopy setStyle : [self style ]];
105165 [imageFormatCopy setMaximumCount: [self maximumCount ]];
106166 [imageFormatCopy setDevices: [self devices ]];
107167
0 commit comments