Skip to content

Instantly share code, notes, and snippets.

View hasanadil's full-sized avatar

hasanadil

  • Portland, Maine, USA
View GitHub Profile
//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
//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;
#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