Permalink
Browse files

Colorblind filter

  • Loading branch information...
1 parent f4f6cee commit 6d01a662a2b4095f2a17d2669d94f94f3c6ffe34 @aleffert committed May 23, 2012
Showing with 38 additions and 1 deletion.
  1. BIN Appstagram.zip
  2. +1 −1 Appstagram/Source/AppstagramDelegate.m
  3. +37 −0 Appstagram/Source/AppstagramFilter.m
View
Binary file not shown.
@@ -36,7 +36,7 @@ @implementation AppstagramDelegate
@synthesize statusItem = mStatusItem;
- (NSArray*)filterNames {
- return [NSArray arrayWithObjects:@"Boring", @"Ennui", @"Shootout", @"La Vie en Rose", @"Cobb", @"Haze", @"Wastebasket", @"Apollo", @"Glow", @"Roebling", @"Spring", nil];
+ return [NSArray arrayWithObjects:@"Boring", @"Ennui", @"Shootout", @"La Vie en Rose", @"Cobb", @"Haze", @"Wastebasket", @"Apollo", @"Colorblind", @"Glow", @"Roebling", @"Spring", nil];
}
- (void)makeFilterMenu {
@@ -29,6 +29,7 @@ + (AppstagramFilter*)paperFilter;
+ (AppstagramFilter*)glowFilter;
+ (AppstagramFilter*)blueRedFilter;
+ (AppstagramFilter*)sunFilter;
++ (AppstagramFilter*)colorblindFilter;
+ (AppstagramFilter*)vibranceFilter;
+ (AppstagramFilter*)peachFilter;
@@ -54,6 +55,7 @@ + (NSDictionary*)filterMap {
[AppstagramFilter blueRedFilter], @"Roebling",
[AppstagramFilter glowFilter], @"Glow",
[AppstagramFilter sunFilter], @"Apollo",
+ [AppstagramFilter colorblindFilter], @"Colorblind",
[AppstagramFilter vibranceFilter], @"Spring",
[AppstagramFilter peachFilter], @"Cobb",
nil];
@@ -167,6 +169,41 @@ + (AppstagramFilter*)blurFilter {
return result;
}
++ (AppstagramFilter*)colorblindFilter {
+ AppstagramFilter* result = [[[AppstagramFilter alloc] init] autorelease];
+ CGSWindowFilterRef filter = NULL;
+ CGSConnection connection = _CGSDefaultConnection();
+
+ CIVector* rVector = [CIVector vectorWithX:.45 Y:.55 Z:0 W:0];
+ CIVector* gVector = [CIVector vectorWithX:.45 Y:.55 Z:0 W:0];
+ CIVector* bVector = [CIVector vectorWithX:0 Y:0 Z:1 W:0];
+ CIVector* aVector = [CIVector vectorWithX:0 Y:0 Z:0 W:1];
+ CIVector* biasVector = [CIVector vectorWithX:0 Y:0 Z:0 W:0];
+
+ NSDictionary* parameters = [NSDictionary dictionaryWithObjectsAndKeys:
+ rVector.stringRepresentation, @"inputRVector",
+ gVector.stringRepresentation, @"inputGVector",
+ bVector.stringRepresentation, @"inputBVector",
+ aVector.stringRepresentation, @"inputAVector",
+ biasVector.stringRepresentation, @"inputBiasVector",
+ nil];
+
+ CGSNewCIFilterByName(connection, (CFStringRef)@"CIColorMatrix", &filter);
+ CGSSetCIFilterValuesFromDictionary(connection, filter, (CFDictionaryRef)parameters);
+
+ result.applyBlock = ^(NSWindow* window) {
+ CGSAddWindowFilter(connection, (int)window.windowNumber, filter, 4);
+ };
+ result.removeBlock = ^(NSWindow* window) {
+ CGSRemoveWindowFilter(connection, (int)window.windowNumber, filter);
+ };
+ result.cleanupBlock = ^ {
+ CGSReleaseCIFilter(connection, filter);
+ };
+
+ return result;
+}
+
+ (AppstagramFilter*)roseFilter {
__block AppstagramFilter* result = [[[AppstagramFilter alloc] init] autorelease];
CGSWindowFilterRef filter = NULL;

0 comments on commit 6d01a66

Please sign in to comment.