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

Commit

Permalink
Invert Filter has been added
Browse files Browse the repository at this point in the history
Test case added in the preset options
  • Loading branch information
kiichi committed Oct 16, 2011
1 parent bf66bb0 commit d3948fd
Show file tree
Hide file tree
Showing 8 changed files with 3,089 additions and 0 deletions.
1 change: 1 addition & 0 deletions Classes/ImageFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ typedef NSUInteger CurveChannel;
- (UIImage*) opacity:(double)amount;
- (UIImage*) contrast:(double)amount;
- (UIImage*) bias:(double)amount;
- (UIImage*) invert;

/* Color Correction */
- (UIImage*) levels:(NSInteger)black mid:(NSInteger)mid white:(NSInteger)white;
Expand Down
20 changes: 20 additions & 0 deletions Classes/ImageFilter.m
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,21 @@ void filterBias(UInt8 *pixelBuf, UInt32 offset, void *context)
pixelBuf[b] = SAFECOLOR((blue * calcBias(((double)blue / 255.0f), val)));
}

void filterInvert(UInt8 *pixelBuf, UInt32 offset, void *context)
{
int r = offset;
int g = offset+1;
int b = offset+2;

int red = pixelBuf[r];
int green = pixelBuf[g];
int blue = pixelBuf[b];

pixelBuf[r] = SAFECOLOR(255-red);
pixelBuf[g] = SAFECOLOR(255-green);
pixelBuf[b] = SAFECOLOR(255-blue);
}

#pragma mark Filters
-(UIImage*)greyscale
{
Expand Down Expand Up @@ -254,6 +269,11 @@ - (UIImage*)bias:(double)amount
return [self applyFilter:filterBias context:&amount];
}

- (UIImage*)invert
{
return [self applyFilter:filterInvert context:nil];
}

#pragma mark -
#pragma mark Blends
#pragma mark Internals
Expand Down
1 change: 1 addition & 0 deletions Classes/iphone_filtersViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ typedef enum
FilterBrightness,
FilterContrast,
FilterGamma,
FilterInvert,
FilterTotal
} FilterOptions;

Expand Down
5 changes: 5 additions & 0 deletions Classes/iphone_filtersViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ - (IBAction) buttonPackagedClicked:(id)sender
NSLocalizedString(@"Lomo",@""),
NSLocalizedString(@"Vignette",@""),
NSLocalizedString(@"Polaroidish",@""),
NSLocalizedString(@"Invert",@""),
nil] autorelease];
self.actionSheetPackaged.actionSheetStyle = UIActionSheetStyleDefault;
[self.actionSheetPackaged showInView:self.view]; // show from our table view (pops up in the middle of the table)
Expand Down Expand Up @@ -115,6 +116,7 @@ - (IBAction) sliderMoved:(id)sender
ActionSheetPackagedOptionLomo,
ActionSheetPackagedOptionVignette,
ActionSheetPackagedOptionPolaroidish,
ActionSheetPackagedOptionInvert,
ActionSheetPackagedOptionTotal
} ActionSheetPackagedOptions;

Expand Down Expand Up @@ -148,6 +150,9 @@ - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger
case ActionSheetPackagedOptionPolaroidish:
self.imageView.image = [image polaroidish];
break;
case ActionSheetPackagedOptionInvert:
self.imageView.image = [image invert];
break;
default:
break;
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d3948fd

Please sign in to comment.