Skip to content

Commit

Permalink
Add new example filters
Browse files Browse the repository at this point in the history
  • Loading branch information
esilverberg committed Jun 19, 2011
1 parent cf9eda3 commit d829baf
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 11 deletions.
1 change: 1 addition & 0 deletions Classes/ImageFilter.h
Expand Up @@ -42,6 +42,7 @@ typedef NSUInteger CurveChannel;
- (UIImage*) gaussianBlur:(NSUInteger)radius;
- (UIImage*) vignette;
- (UIImage*) darkVignette;
- (UIImage*) polaroidish;

/* Blend Operations */
- (UIImage*) overlay:(UIImage*)other;
Expand Down
39 changes: 37 additions & 2 deletions Classes/ImageFilter.m
Expand Up @@ -809,8 +809,8 @@ - (UIImage*) vignette
UIImage *finalImage = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);

UIImage *mask = [finalImage gaussianBlur:5];
UIImage *blurredSelf = [self gaussianBlur:5];
UIImage *mask = [finalImage gaussianBlur:10];
UIImage *blurredSelf = [self gaussianBlur:2];
UIImage *maskedSelf = [self mask:mask];
return [blurredSelf merge:maskedSelf];
}
Expand Down Expand Up @@ -868,4 +868,39 @@ - (UIImage*) darkVignette
return [self overlay:[maskedSquare opacity:1.0]];
}

// This filter is not done...
- (UIImage*) polaroidish
{
NSArray *redPoints = [NSArray arrayWithObjects:
[NSValue valueWithCGPoint:CGPointMake(0, 0)],
[NSValue valueWithCGPoint:CGPointMake(93, 81)],
[NSValue valueWithCGPoint:CGPointMake(247, 241)],
[NSValue valueWithCGPoint:CGPointMake(255, 255)],
nil];
NSArray *bluePoints = [NSArray arrayWithObjects:
[NSValue valueWithCGPoint:CGPointMake(0, 0)],
[NSValue valueWithCGPoint:CGPointMake(57, 59)],
[NSValue valueWithCGPoint:CGPointMake(223, 205)],
[NSValue valueWithCGPoint:CGPointMake(255, 241)],
nil];
UIImage *image = [[self applyCurve:redPoints toChannel:CurveChannelRed]
applyCurve:bluePoints toChannel:CurveChannelBlue];

redPoints = [NSArray arrayWithObjects:
[NSValue valueWithCGPoint:CGPointMake(0, 0)],
[NSValue valueWithCGPoint:CGPointMake(93, 76)],
[NSValue valueWithCGPoint:CGPointMake(232, 226)],
[NSValue valueWithCGPoint:CGPointMake(255, 255)],
nil];
bluePoints = [NSArray arrayWithObjects:
[NSValue valueWithCGPoint:CGPointMake(0, 0)],
[NSValue valueWithCGPoint:CGPointMake(57, 59)],
[NSValue valueWithCGPoint:CGPointMake(220, 202)],
[NSValue valueWithCGPoint:CGPointMake(255, 255)],
nil];
image = [[image applyCurve:redPoints toChannel:CurveChannelRed]
applyCurve:bluePoints toChannel:CurveChannelBlue];

return image;
}
@end
2 changes: 2 additions & 0 deletions Classes/iphone_filtersViewController.h
Expand Up @@ -14,7 +14,9 @@ typedef enum
{
FilterPosterize = 0,
FilterSaturate,
FilterBrightness,
FilterContrast,
FilterGamma,
FilterTotal
} FilterOptions;

Expand Down
37 changes: 28 additions & 9 deletions Classes/iphone_filtersViewController.m
Expand Up @@ -50,7 +50,9 @@ - (IBAction) buttonAdjustableClicked:(id)sender
otherButtonTitles:
NSLocalizedString(@"Posterize",@""),
NSLocalizedString(@"Saturate",@""),
NSLocalizedString(@"Brightness",@""),
NSLocalizedString(@"Contrast",@""),
NSLocalizedString(@"Gamma",@""),
nil];
self.actionSheetAdjustable.actionSheetStyle = UIActionSheetStyleDefault;
[self.actionSheetAdjustable showInView:self.view]; // show from our table view (pops up in the middle of the table)
Expand All @@ -59,15 +61,18 @@ - (IBAction) buttonAdjustableClicked:(id)sender
- (IBAction) buttonPackagedClicked:(id)sender
{
// open a dialog with two custom buttons
self.actionSheetPackaged = [[UIActionSheet alloc] initWithTitle:NSLocalizedString(@"Apply Filter",@"")
delegate:self
cancelButtonTitle:NSLocalizedString(@"Cancel",@"")
destructiveButtonTitle:NSLocalizedString(@"Reset",@"")
otherButtonTitles:
NSLocalizedString(@"Sharpen",@""),
NSLocalizedString(@"Sepia",@""),
NSLocalizedString(@"Lomo",@""),
nil];
self.actionSheetPackaged =
[[UIActionSheet alloc] initWithTitle:NSLocalizedString(@"Apply Filter",@"")
delegate:self
cancelButtonTitle:NSLocalizedString(@"Cancel",@"")
destructiveButtonTitle:NSLocalizedString(@"Reset",@"")
otherButtonTitles:
NSLocalizedString(@"Sharpen",@""),
NSLocalizedString(@"Sepia",@""),
NSLocalizedString(@"Lomo",@""),
NSLocalizedString(@"Vignette",@""),
NSLocalizedString(@"Polaroidish",@""),
nil];
self.actionSheetPackaged.actionSheetStyle = UIActionSheetStyleDefault;
[self.actionSheetPackaged showInView:self.view]; // show from our table view (pops up in the middle of the table)

Expand All @@ -86,9 +91,15 @@ - (IBAction) sliderMoved:(id)sender
case FilterSaturate:
self.imageView.image = [image saturate:(1+value-0.5)];
break;
case FilterBrightness:
self.imageView.image = [image brightness:(1+value-0.5)];
break;
case FilterContrast:
self.imageView.image = [image contrast:(1+value-0.5)];
break;
case FilterGamma:
self.imageView.image = [image gamma:(1+value-0.5)];
break;
default:
break;
}
Expand All @@ -102,6 +113,8 @@ - (IBAction) sliderMoved:(id)sender
ActionSheetPackagedOptionSharpen,
ActionSheetPackagedOptionSepia,
ActionSheetPackagedOptionLomo,
ActionSheetPackagedOptionVignette,
ActionSheetPackagedOptionPolaroidish,
ActionSheetPackagedOptionTotal
} ActionSheetPackagedOptions;

Expand Down Expand Up @@ -129,6 +142,12 @@ - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger
case ActionSheetPackagedOptionLomo:
self.imageView.image = [image lomo];
break;
case ActionSheetPackagedOptionVignette:
self.imageView.image = [image vignette];
break;
case ActionSheetPackagedOptionPolaroidish:
self.imageView.image = [image polaroidish];
break;
default:
break;
}
Expand Down

0 comments on commit d829baf

Please sign in to comment.