Created
November 21, 2013 05:16
-
-
Save JRHeaton/7576429 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)analyzeImageWithCompletion:(void (^)())block { | |
NSParameterAssert(block); | |
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ | |
CFDataRef data = CGDataProviderCopyData(CGImageGetDataProvider(self.image.CGImage)); | |
UInt8 *buf = (UInt8 *)CFDataGetBytePtr(data); | |
size_t width = CGImageGetWidth(self.image.CGImage); | |
size_t height = CGImageGetHeight(self.image.CGImage); | |
NSMutableArray *amps = [NSMutableArray array]; | |
for(NSInteger x=0;x<width;++x) { | |
for(NSInteger y=0;y<(height/2);++y) { | |
UInt8 red, green, blue, alpha; | |
red = buf[(x * 4) + ((width * 4) * y) + 0]; | |
green = buf[(x * 4) + ((width * 4) * y) + 1]; | |
blue = buf[(x * 4) + ((width * 4) * y) + 2]; | |
alpha = buf[(x * 4) + ((width * 4) * y) + 3]; | |
if(!red && !green && !blue && !alpha) { | |
[amps addObject:[NSNumber numberWithFloat:1.f - (float)y/(height/2)]]; | |
break; | |
} | |
} | |
} | |
self.amplitudes = amps.copy; | |
CFRelease(data); | |
block(); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment