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
i = 1 |
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
#import <Foundation/Foundation.h> | |
#import <AppKit/AppKit.h> | |
@interface HAColorFinder : NSObject | |
/* | |
Return the color in the image that is most dominant. | |
Where dominant is defined as the most number of pixels which contain the same color. | |
*/ | |
-(void) fetchDominantColorFromImage:(NSImage*)image |
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
//wait on everything to be completed | |
dispatch_barrier_async(weakMe.concurrentQueue, ^{ | |
//Get the highest count amont the worker results | |
NSArray* allCounts = [workerResults allValues]; | |
NSSortDescriptor* countSort = [[NSSortDescriptor alloc] initWithKey:@"count" ascending:NO]; | |
NSArray* sortedCounts = [allCounts sortedArrayUsingDescriptors:@[countSort]]; | |
HAColorComponentsCount* colorComponentCount = [sortedCounts firstObject]; | |
HAColorComponents *components = colorComponentCount.components; | |
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
//Divide up the work among workers | |
NSUInteger numberOfWorkers = 4; | |
NSUInteger pixelsPerWorker = pixelCount/numberOfWorkers; | |
for (NSUInteger worker = 0; worker < numberOfWorkers; worker++) { | |
//Submit work blocks to be executed concurrently | |
dispatch_async(weakMe.concurrentQueue, ^{ | |
//Add the colors result to a trie data strucuture whose leaf is the counter, O(1) baby |
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
//Divide up the work among workers | |
NSUInteger numberOfWorkers = 4; | |
NSUInteger pixelsPerWorker = pixelCount/numberOfWorkers; | |
for (NSUInteger worker = 0; worker < numberOfWorkers; worker++) { | |
//Submit work blocks to be executed concurrently | |
dispatch_async(weakMe.concurrentQueue, ^{ | |
//Add the colors result to a trie data strucuture whose leaf is the counter, O(1) baby |
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) fetchDominantColorFromImage:(NSImage*)image withCompletion:(void(^)(NSColor *color, NSTimeInterval processingTime))completion { | |
... | |
__weak typeof(self) weakMe = self; | |
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{ | |
[weakMe pixelsFromImage:image withCompletion:^(UInt32 *pixels, NSUInteger pixelCount) { | |
.... |
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) pixelsFromImage:(NSImage*)image | |
withCompletion:(void(^)(UInt32 *pixels, NSUInteger pixelCount))completion { | |
//Extract pixels from the image in a 1D array | |
CFDataRef inputData = (__bridge CFDataRef)[image TIFFRepresentation]; | |
CGImageSourceRef inputSource = CGImageSourceCreateWithData(inputData, NULL); | |
CGImageRef inputCGImage = CGImageSourceCreateImageAtIndex(inputSource, 0, NULL); | |
NSUInteger width = CGImageGetWidth(inputCGImage); | |
NSUInteger height = CGImageGetHeight(inputCGImage); | |
NSUInteger numberOfPixels = height * width; |
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
class ๐ฉ๐ฉ๐ฉ๐ฉ { | |
func ๐ฉ๐ฉ๐ฉ(๐: Int, ๐ฏ: Int) -> Int { | |
return ๐ + ๐ฏ; | |
} | |
} | |
let ๐ = 3; | |
let ๐ฅ = ๐ + 2; | |
let ๐ฉ = ๐ฉ๐ฉ๐ฉ๐ฉ(); | |
print(๐ฉ.๐ฉ๐ฉ๐ฉ(๐, ๐ฏ:๐ฅ)); |
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
let camera = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeVideo) | |
var error : NSError? = nil | |
let cameraInput : AVCaptureDeviceInput? = AVCaptureDeviceInput.deviceInputWithDevice(camera, error: &error) as? AVCaptureDeviceInput | |
self.session.addInput(cameraInput) | |
if error != nil || cameraInput == nil { | |
//Awesome error handling :D | |
println(error!.localizedDescription) | |
} | |
else { |
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
let allowedBarcodes = [AVMetadataObjectTypeUPCECode, | |
AVMetadataObjectTypeCode39Code, | |
AVMetadataObjectTypeCode39Mod43Code, | |
AVMetadataObjectTypeEAN13Code, | |
AVMetadataObjectTypeEAN8Code, | |
AVMetadataObjectTypeCode93Code, | |
AVMetadataObjectTypeCode128Code, | |
AVMetadataObjectTypePDF417Code, | |
AVMetadataObjectTypeQRCode, | |
AVMetadataObjectTypeAztecCode |
NewerOlder