swift - Bitwise operations with CGBitmapInfo and CGImageAlphaInfo -


i'm having trouble performing bitwise operations cgimagealphainfo , cgbitmapinfo in swift.

in particular, don't know how port objective-c code:

bitmapinfo &= ~kcgbitmapalphainfomask; bitmapinfo |= kcgimagealphanoneskipfirst; 

the following straightforward swift port produces cryptic compiler error 'cgbitmapinfo' not identical 'bool' on last line:

bitmapinfo &= ~cgbitmapinfo.alphainfomask bitmapinfo |= cgimagealphainfo.noneskipfirst 

looking @ source code noticed cgbitmapinfo declared rawoptionsettype while cgimagealphainfo isn't. maybe has it?

it doesn't official documentation on bitwise operators doesn't cover enums.

you have right equivalent swift code:

bitmapinfo &= ~cgbitmapinfo.alphainfomask bitmapinfo |= cgbitmapinfo(cgimagealphainfo.noneskipfirst.rawvalue) 

it's little strange because cgimagealphainfo isn't bitmask -- it's uint32 enum (or cf_enum/ns_enum type uint32_t, in c parlance), values 0 through 7.

what's happening first line clears first 5 bits of bitmapinfo, is bitmask (aka rawoptionsettype in swift), since cgbitmapinfo.alphainfomask 31, or 0b11111. second line sticks raw value of cgimagealphainfo enum cleared bits.

i haven't seen enums , bitmasks combined anywhere else, if explains why there isn't documentation. since cgimagealphainfo enum, values mutually exclusive. wouldn't make sense:

bitmapinfo &= ~cgbitmapinfo.alphainfomask bitmapinfo |= cgbitmapinfo(cgimagealphainfo.noneskipfirst.rawvalue) bitmapinfo |= cgbitmapinfo(cgimagealphainfo.premultipliedlast.rawvalue) 

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -