Skip to content
This repository was archived by the owner on Mar 14, 2020. It is now read-only.

Commit d829baf

Browse files
committed
Add new example filters
1 parent cf9eda3 commit d829baf

4 files changed

+68
-11
lines changed

Classes/ImageFilter.h

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ typedef NSUInteger CurveChannel;
4242
- (UIImage*) gaussianBlur:(NSUInteger)radius;
4343
- (UIImage*) vignette;
4444
- (UIImage*) darkVignette;
45+
- (UIImage*) polaroidish;
4546

4647
/* Blend Operations */
4748
- (UIImage*) overlay:(UIImage*)other;

Classes/ImageFilter.m

+37-2
Original file line numberDiff line numberDiff line change
@@ -809,8 +809,8 @@ - (UIImage*) vignette
809809
UIImage *finalImage = [UIImage imageWithCGImage:imageRef];
810810
CGImageRelease(imageRef);
811811

812-
UIImage *mask = [finalImage gaussianBlur:5];
813-
UIImage *blurredSelf = [self gaussianBlur:5];
812+
UIImage *mask = [finalImage gaussianBlur:10];
813+
UIImage *blurredSelf = [self gaussianBlur:2];
814814
UIImage *maskedSelf = [self mask:mask];
815815
return [blurredSelf merge:maskedSelf];
816816
}
@@ -868,4 +868,39 @@ - (UIImage*) darkVignette
868868
return [self overlay:[maskedSquare opacity:1.0]];
869869
}
870870

871+
// This filter is not done...
872+
- (UIImage*) polaroidish
873+
{
874+
NSArray *redPoints = [NSArray arrayWithObjects:
875+
[NSValue valueWithCGPoint:CGPointMake(0, 0)],
876+
[NSValue valueWithCGPoint:CGPointMake(93, 81)],
877+
[NSValue valueWithCGPoint:CGPointMake(247, 241)],
878+
[NSValue valueWithCGPoint:CGPointMake(255, 255)],
879+
nil];
880+
NSArray *bluePoints = [NSArray arrayWithObjects:
881+
[NSValue valueWithCGPoint:CGPointMake(0, 0)],
882+
[NSValue valueWithCGPoint:CGPointMake(57, 59)],
883+
[NSValue valueWithCGPoint:CGPointMake(223, 205)],
884+
[NSValue valueWithCGPoint:CGPointMake(255, 241)],
885+
nil];
886+
UIImage *image = [[self applyCurve:redPoints toChannel:CurveChannelRed]
887+
applyCurve:bluePoints toChannel:CurveChannelBlue];
888+
889+
redPoints = [NSArray arrayWithObjects:
890+
[NSValue valueWithCGPoint:CGPointMake(0, 0)],
891+
[NSValue valueWithCGPoint:CGPointMake(93, 76)],
892+
[NSValue valueWithCGPoint:CGPointMake(232, 226)],
893+
[NSValue valueWithCGPoint:CGPointMake(255, 255)],
894+
nil];
895+
bluePoints = [NSArray arrayWithObjects:
896+
[NSValue valueWithCGPoint:CGPointMake(0, 0)],
897+
[NSValue valueWithCGPoint:CGPointMake(57, 59)],
898+
[NSValue valueWithCGPoint:CGPointMake(220, 202)],
899+
[NSValue valueWithCGPoint:CGPointMake(255, 255)],
900+
nil];
901+
image = [[image applyCurve:redPoints toChannel:CurveChannelRed]
902+
applyCurve:bluePoints toChannel:CurveChannelBlue];
903+
904+
return image;
905+
}
871906
@end

Classes/iphone_filtersViewController.h

+2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ typedef enum
1414
{
1515
FilterPosterize = 0,
1616
FilterSaturate,
17+
FilterBrightness,
1718
FilterContrast,
19+
FilterGamma,
1820
FilterTotal
1921
} FilterOptions;
2022

Classes/iphone_filtersViewController.m

+28-9
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ - (IBAction) buttonAdjustableClicked:(id)sender
5050
otherButtonTitles:
5151
NSLocalizedString(@"Posterize",@""),
5252
NSLocalizedString(@"Saturate",@""),
53+
NSLocalizedString(@"Brightness",@""),
5354
NSLocalizedString(@"Contrast",@""),
55+
NSLocalizedString(@"Gamma",@""),
5456
nil];
5557
self.actionSheetAdjustable.actionSheetStyle = UIActionSheetStyleDefault;
5658
[self.actionSheetAdjustable showInView:self.view]; // show from our table view (pops up in the middle of the table)
@@ -59,15 +61,18 @@ - (IBAction) buttonAdjustableClicked:(id)sender
5961
- (IBAction) buttonPackagedClicked:(id)sender
6062
{
6163
// open a dialog with two custom buttons
62-
self.actionSheetPackaged = [[UIActionSheet alloc] initWithTitle:NSLocalizedString(@"Apply Filter",@"")
63-
delegate:self
64-
cancelButtonTitle:NSLocalizedString(@"Cancel",@"")
65-
destructiveButtonTitle:NSLocalizedString(@"Reset",@"")
66-
otherButtonTitles:
67-
NSLocalizedString(@"Sharpen",@""),
68-
NSLocalizedString(@"Sepia",@""),
69-
NSLocalizedString(@"Lomo",@""),
70-
nil];
64+
self.actionSheetPackaged =
65+
[[UIActionSheet alloc] initWithTitle:NSLocalizedString(@"Apply Filter",@"")
66+
delegate:self
67+
cancelButtonTitle:NSLocalizedString(@"Cancel",@"")
68+
destructiveButtonTitle:NSLocalizedString(@"Reset",@"")
69+
otherButtonTitles:
70+
NSLocalizedString(@"Sharpen",@""),
71+
NSLocalizedString(@"Sepia",@""),
72+
NSLocalizedString(@"Lomo",@""),
73+
NSLocalizedString(@"Vignette",@""),
74+
NSLocalizedString(@"Polaroidish",@""),
75+
nil];
7176
self.actionSheetPackaged.actionSheetStyle = UIActionSheetStyleDefault;
7277
[self.actionSheetPackaged showInView:self.view]; // show from our table view (pops up in the middle of the table)
7378

@@ -86,9 +91,15 @@ - (IBAction) sliderMoved:(id)sender
8691
case FilterSaturate:
8792
self.imageView.image = [image saturate:(1+value-0.5)];
8893
break;
94+
case FilterBrightness:
95+
self.imageView.image = [image brightness:(1+value-0.5)];
96+
break;
8997
case FilterContrast:
9098
self.imageView.image = [image contrast:(1+value-0.5)];
9199
break;
100+
case FilterGamma:
101+
self.imageView.image = [image gamma:(1+value-0.5)];
102+
break;
92103
default:
93104
break;
94105
}
@@ -102,6 +113,8 @@ - (IBAction) sliderMoved:(id)sender
102113
ActionSheetPackagedOptionSharpen,
103114
ActionSheetPackagedOptionSepia,
104115
ActionSheetPackagedOptionLomo,
116+
ActionSheetPackagedOptionVignette,
117+
ActionSheetPackagedOptionPolaroidish,
105118
ActionSheetPackagedOptionTotal
106119
} ActionSheetPackagedOptions;
107120

@@ -129,6 +142,12 @@ - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger
129142
case ActionSheetPackagedOptionLomo:
130143
self.imageView.image = [image lomo];
131144
break;
145+
case ActionSheetPackagedOptionVignette:
146+
self.imageView.image = [image vignette];
147+
break;
148+
case ActionSheetPackagedOptionPolaroidish:
149+
self.imageView.image = [image polaroidish];
150+
break;
132151
default:
133152
break;
134153
}

0 commit comments

Comments
 (0)