Reputation: 659
In Objective-C, the CGBitmapInfo contains:
kCGBitmapAlphaInfoMask = 0x1F,
kCGBitmapFloatInfoMask = 0xF00,
kCGBitmapFloatComponents = (1 << 8),
kCGBitmapByteOrderMask = kCGImageByteOrderMask,
kCGBitmapByteOrderDefault = (0 << 12),
kCGBitmapByteOrder16Little = kCGImageByteOrder16Little,
kCGBitmapByteOrder32Little = kCGImageByteOrder32Little,
kCGBitmapByteOrder16Big = kCGImageByteOrder16Big,
kCGBitmapByteOrder32Big = kCGImageByteOrder32Big
However, in Swift 3.0, CGBitmapInfo removed the kCGBitmapByteOrderDefault:
public struct CGBitmapInfo : OptionSet {
public init(rawValue: UInt32)
public static var alphaInfoMask: CGBitmapInfo { get }
public static var floatInfoMask: CGBitmapInfo { get }
public static var floatComponents: CGBitmapInfo { get }
public static var byteOrderMask: CGBitmapInfo { get }
public static var byteOrder16Little: CGBitmapInfo { get }
public static var byteOrder32Little: CGBitmapInfo { get }
public static var byteOrder16Big: CGBitmapInfo { get }
public static var byteOrder32Big: CGBitmapInfo { get }
}
That's why?
Can I init the CGBitmapInfo
like CGBitmapInfo(rawValue: 0)
to replace the kCGBitmapByteOrderDefault
?
Upvotes: 2
Views: 1894
Reputation: 561
see CGBitmapInfo or CGImageByteOrderInfo https://developer.apple.com/documentation/coregraphics/cgimagebyteorderinfo https://developer.apple.com/documentation/coregraphics/cgbitmapinfo
As long as the 3 bits in the ByteOrderMask are 0, you are good. I have not found any doc stating what a byte order of 0 does. The following result in the same 0 value.
let b: CGBitmapInfo = []
let b = CGBitmapInfo(rawValue: 0)
111000000000000 byteOrder mask
you can grab the possible values for ByteOrder from
001000000000000 == CGBitmapInfo.byteOrder16Little.rawValue
010000000000000 == CGBitmapInfo.byteOrder32Little.rawValue
011000000000000 == CGBitmapInfo.byteOrder16Big.rawValue
100000000000000 == CGBitmapInfo.byteOrder32Big.rawValue
example setting value
let b: CGBitmapInfo = [ .byteOrder32Big]
print("\(b.contains(.byteOrder32Big))") // true
print("\(b.contains(.byteOrder16Little))") // false
print("\(b.rawValue)") // 16384
Upvotes: 1
Reputation: 47886
Can I init the CGBitmapInfo
like CGBitmapInfo(rawValue: 0)
to replace the kCGBitmapByteOrderDefault
?
The answer is YES.
Swift omits some 0-value enum label in some cases. (details depend on the version of Swift).
If you find some enum label is not imported into Swift, check the original source in Objective-C and confirm it really has integer value 0, then replace it with init(rawValue: 0)
.
I cannot have found much about That's why?, only one you can find is in the Xcode Release Notes (>Xcode 8.0>Swift):
- The
None
members of importedNS_OPTIONS
option sets are marked as unavailable when they are imported. Use[]
to make an empty option set, instead of aNone
member.
It is not clear enough what None
member means, but it seems the designer of Swift importer prefers the empty set literal []
for OptionSet
types when representing default or none.
So, the first half of this answer should be modified:
You can use CGBitmapInfo(rawValue: 0)
to replace kCGBitmapByteOrderDefault
, but the empty set literal is preferred:
let myBitmapInfo: CGBitmapInfo = []
Upvotes: 3