16
16
static NSString *const FICImageFormatFamilyKey = @" family" ;
17
17
static NSString *const FICImageFormatWidthKey = @" width" ;
18
18
static NSString *const FICImageFormatHeightKey = @" height" ;
19
- static NSString *const FICImageFormatIsOpaqueKey = @" isOpaque " ;
19
+ static NSString *const FICImageFormatStyleKey = @" style " ;
20
20
static NSString *const FICImageFormatMaximumCountKey = @" maximumCount" ;
21
21
static NSString *const FICImageFormatDevicesKey = @" devices" ;
22
22
@@ -27,7 +27,7 @@ @interface FICImageFormat () {
27
27
NSString *_family;
28
28
CGSize _imageSize;
29
29
CGSize _pixelSize;
30
- BOOL _isOpaque ;
30
+ FICImageFormatStyle _style ;
31
31
NSInteger _maximumCount;
32
32
FICImageFormatDevices _devices;
33
33
}
@@ -42,7 +42,7 @@ @implementation FICImageFormat
42
42
@synthesize family = _family;
43
43
@synthesize imageSize = _imageSize;
44
44
@synthesize pixelSize = _pixelSize;
45
- @synthesize opaque = _isOpaque ;
45
+ @synthesize style = _style ;
46
46
@synthesize maximumCount = _maximumCount;
47
47
@synthesize devices = _devices;
48
48
@@ -58,15 +58,75 @@ - (void)setImageSize:(CGSize)imageSize {
58
58
}
59
59
}
60
60
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
+
61
121
#pragma mark - Object Lifecycle
62
122
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 {
64
124
FICImageFormat *imageFormat = [[FICImageFormat alloc ] init ];
65
125
66
126
[imageFormat setName: name];
67
127
[imageFormat setFamily: family];
68
128
[imageFormat setImageSize: imageSize];
69
- [imageFormat setOpaque: isOpaque ];
129
+ [imageFormat setStyle: style ];
70
130
[imageFormat setMaximumCount: maximumCount];
71
131
[imageFormat setDevices: devices];
72
132
@@ -82,7 +142,7 @@ - (NSDictionary *)dictionaryRepresentation {
82
142
[dictionaryRepresentation setValue: _family forKey: FICImageFormatFamilyKey];
83
143
[dictionaryRepresentation setValue: [NSNumber numberWithUnsignedInteger: _imageSize.width] forKey: FICImageFormatWidthKey];
84
144
[dictionaryRepresentation setValue: [NSNumber numberWithUnsignedInteger: _imageSize.height] forKey: FICImageFormatHeightKey];
85
- [dictionaryRepresentation setValue: [NSNumber numberWithBool: _isOpaque ] forKey: FICImageFormatIsOpaqueKey ];
145
+ [dictionaryRepresentation setValue: [NSNumber numberWithInt: _style ] forKey: FICImageFormatStyleKey ];
86
146
[dictionaryRepresentation setValue: [NSNumber numberWithUnsignedInteger: _maximumCount] forKey: FICImageFormatMaximumCountKey];
87
147
[dictionaryRepresentation setValue: [NSNumber numberWithInt: _devices] forKey: FICImageFormatDevicesKey];
88
148
[dictionaryRepresentation setValue: [NSNumber numberWithFloat: [[UIScreen mainScreen ] scale ]] forKey: FICImageTableScreenScaleKey];
@@ -101,7 +161,7 @@ - (id)copyWithZone:(NSZone *)zone {
101
161
[imageFormatCopy setName: [self name ]];
102
162
[imageFormatCopy setFamily: [self family ]];
103
163
[imageFormatCopy setImageSize: [self imageSize ]];
104
- [imageFormatCopy setOpaque : [self isOpaque ]];
164
+ [imageFormatCopy setStyle : [self style ]];
105
165
[imageFormatCopy setMaximumCount: [self maximumCount ]];
106
166
[imageFormatCopy setDevices: [self devices ]];
107
167
0 commit comments