I have three CGLayers who\'s data I\'d like to compare.
void *a = CGBitmapContextGetData(CGLayerGetContext(layerA));
void *b = CGBitmapContextGetData(CGLayerGetC
What about the CGBlendModes? kCGBlendModeDestinationOver
acts as OR
for A and B, and then you can use kCGBlendModeDestinationIn
to AND
that result with C.
Here's a naive implementation, assuming all three are the same size:
unsigned char *a = CGBitmapContextGetData(CGLayerGetContext(layerA));
unsigned char *b = CGBitmapContextGetData(CGLayerGetContext(layerB));
CGContextRef context = CGLayerGetContext(layerC);
unsigned char *c = CGBitmapContextGetData(context);
size_t bytesPerRow = CGBitmapContextGetBytesPerRow(context);
size_t height = CGBitmapContextGetHeight(context);
size_t len = bytesPerRow * height;
BOOL bitsFound = NO;
for (int i = 0; i < len; i++) {
if ((a[i] | b[i]) & c[i]) { bitsFound = YES; break; }
}
Since you're hankering for QuickDraw, I assume you could have written that yourself, and you know that will probably be slow.
If you can guarantee the bitmap sizes, you could use int
instead of char
and operate on four bytes at a time.
For more serious optimization, you should check out the Accelerate framework.