Skip to content

Commit

Permalink
Added a high pass and a low pass filter. Fixed compilation issues wit…
Browse files Browse the repository at this point in the history
…h GPUImageBuffer on older Xcode versions.
  • Loading branch information
BradLarson committed Sep 2, 2012
1 parent 09dcd46 commit 46fa7df
Show file tree
Hide file tree
Showing 13 changed files with 203 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
case GPUIMAGE_NOBLECORNERDETECTION: cell.textLabel.text = @"Noble corner detection"; break;
case GPUIMAGE_SHITOMASIFEATUREDETECTION: cell.textLabel.text = @"Shi-Tomasi feature detection"; break;
case GPUIMAGE_BUFFER: cell.textLabel.text = @"Image buffer"; break;
case GPUIMAGE_LOWPASS: cell.textLabel.text = @"Low pass"; break;
case GPUIMAGE_HIGHPASS: cell.textLabel.text = @"High pass"; break;
case GPUIMAGE_SKETCH: cell.textLabel.text = @"Sketch"; break;
case GPUIMAGE_TOON: cell.textLabel.text = @"Toon"; break;
case GPUIMAGE_SMOOTHTOON: cell.textLabel.text = @"Smooth toon"; break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ typedef enum {
GPUIMAGE_NOBLECORNERDETECTION,
GPUIMAGE_SHITOMASIFEATUREDETECTION,
GPUIMAGE_BUFFER,
GPUIMAGE_LOWPASS,
GPUIMAGE_HIGHPASS,
GPUIMAGE_SKETCH,
GPUIMAGE_TOON,
GPUIMAGE_SMOOTHTOON,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,28 @@ - (void)setupFilter;

filter = [[GPUImageBuffer alloc] init];
}; break;
case GPUIMAGE_LOWPASS:
{
self.title = @"Low Pass";
self.filterSettingsSlider.hidden = NO;

[self.filterSettingsSlider setMinimumValue:0.0];
[self.filterSettingsSlider setMaximumValue:1.0];
[self.filterSettingsSlider setValue:0.5];

filter = [[GPUImageLowPassFilter alloc] init];
}; break;
case GPUIMAGE_HIGHPASS:
{
self.title = @"High Pass";
self.filterSettingsSlider.hidden = NO;

[self.filterSettingsSlider setMinimumValue:0.0];
[self.filterSettingsSlider setMaximumValue:1.0];
[self.filterSettingsSlider setValue:0.5];

filter = [[GPUImageHighPassFilter alloc] init];
}; break;
case GPUIMAGE_SKETCH:
{
self.title = @"Sketch";
Expand Down Expand Up @@ -1281,6 +1303,8 @@ - (IBAction)updateFilterFromSlider:(id)sender;
case GPUIMAGE_ADAPTIVETHRESHOLD: [(GPUImageAdaptiveThresholdFilter *)filter setBlurSize:[(UISlider*)sender value]]; break;
case GPUIMAGE_AVERAGELUMINANCETHRESHOLD: [(GPUImageAverageLuminanceThresholdFilter *)filter setThresholdMultiplier:[(UISlider *)sender value]]; break;
case GPUIMAGE_DISSOLVE: [(GPUImageDissolveBlendFilter *)filter setMix:[(UISlider *)sender value]]; break;
case GPUIMAGE_LOWPASS: [(GPUImageLowPassFilter *)filter setFilterStrength:[(UISlider *)sender value]]; break;
case GPUIMAGE_HIGHPASS: [(GPUImageHighPassFilter *)filter setFilterStrength:[(UISlider *)sender value]]; break;
case GPUIMAGE_CHROMAKEY: [(GPUImageChromaKeyBlendFilter *)filter setThresholdSensitivity:[(UISlider *)sender value]]; break;
case GPUIMAGE_CHROMAKEYNONBLEND: [(GPUImageChromaKeyFilter *)filter setThresholdSensitivity:[(UISlider *)sender value]]; break;
case GPUIMAGE_KUWAHARA: [(GPUImageKuwaharaFilter *)filter setRadius:round([(UISlider *)sender value])]; break;
Expand Down
16 changes: 16 additions & 0 deletions framework/GPUImage.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@
BCAD4D1D1571B410001E50E1 /* GPUImageDirectionalNonMaximumSuppressionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = BCAD4D1B1571B410001E50E1 /* GPUImageDirectionalNonMaximumSuppressionFilter.m */; };
BCAD4D201571CB50001E50E1 /* GPUImageWeakPixelInclusionFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = BCAD4D1E1571CB48001E50E1 /* GPUImageWeakPixelInclusionFilter.h */; };
BCAD4D211571CB50001E50E1 /* GPUImageWeakPixelInclusionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = BCAD4D1F1571CB4C001E50E1 /* GPUImageWeakPixelInclusionFilter.m */; };
BCB3B46515F2BA9300EDA3BE /* GPUImageLowPassFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = BCB3B46315F2BA9300EDA3BE /* GPUImageLowPassFilter.h */; };
BCB3B46615F2BA9300EDA3BE /* GPUImageLowPassFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = BCB3B46415F2BA9300EDA3BE /* GPUImageLowPassFilter.m */; };
BCB3B46A15F2FD1B00EDA3BE /* GPUImageHighPassFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = BCB3B46815F2FD1B00EDA3BE /* GPUImageHighPassFilter.h */; };
BCB3B46B15F2FD1B00EDA3BE /* GPUImageHighPassFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = BCB3B46915F2FD1B00EDA3BE /* GPUImageHighPassFilter.m */; };
BCB5DE0D14E87F32000AF3C2 /* GPUImagePixellateFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = BCB5DE0B14E87F32000AF3C2 /* GPUImagePixellateFilter.h */; };
BCB5DE0E14E87F32000AF3C2 /* GPUImagePixellateFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = BCB5DE0C14E87F32000AF3C2 /* GPUImagePixellateFilter.m */; };
BCB5E75C14E2086300701302 /* GPUImageView.h in Headers */ = {isa = PBXBuildFile; fileRef = BCB5E75A14E2086300701302 /* GPUImageView.h */; };
Expand Down Expand Up @@ -456,6 +460,10 @@
BCAD4D1B1571B410001E50E1 /* GPUImageDirectionalNonMaximumSuppressionFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = GPUImageDirectionalNonMaximumSuppressionFilter.m; path = Source/GPUImageDirectionalNonMaximumSuppressionFilter.m; sourceTree = SOURCE_ROOT; };
BCAD4D1E1571CB48001E50E1 /* GPUImageWeakPixelInclusionFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GPUImageWeakPixelInclusionFilter.h; path = Source/GPUImageWeakPixelInclusionFilter.h; sourceTree = SOURCE_ROOT; };
BCAD4D1F1571CB4C001E50E1 /* GPUImageWeakPixelInclusionFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = GPUImageWeakPixelInclusionFilter.m; path = Source/GPUImageWeakPixelInclusionFilter.m; sourceTree = SOURCE_ROOT; };
BCB3B46315F2BA9300EDA3BE /* GPUImageLowPassFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GPUImageLowPassFilter.h; path = Source/GPUImageLowPassFilter.h; sourceTree = SOURCE_ROOT; };
BCB3B46415F2BA9300EDA3BE /* GPUImageLowPassFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = GPUImageLowPassFilter.m; path = Source/GPUImageLowPassFilter.m; sourceTree = SOURCE_ROOT; };
BCB3B46815F2FD1B00EDA3BE /* GPUImageHighPassFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GPUImageHighPassFilter.h; path = Source/GPUImageHighPassFilter.h; sourceTree = SOURCE_ROOT; };
BCB3B46915F2FD1B00EDA3BE /* GPUImageHighPassFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = GPUImageHighPassFilter.m; path = Source/GPUImageHighPassFilter.m; sourceTree = SOURCE_ROOT; };
BCB5DE0B14E87F32000AF3C2 /* GPUImagePixellateFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GPUImagePixellateFilter.h; path = Source/GPUImagePixellateFilter.h; sourceTree = SOURCE_ROOT; };
BCB5DE0C14E87F32000AF3C2 /* GPUImagePixellateFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = GPUImagePixellateFilter.m; path = Source/GPUImagePixellateFilter.m; sourceTree = SOURCE_ROOT; };
BCB5E75A14E2086300701302 /* GPUImageView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GPUImageView.h; path = Source/GPUImageView.h; sourceTree = SOURCE_ROOT; };
Expand Down Expand Up @@ -935,6 +943,10 @@
BCF851BE15CF5D59000EBC8B /* GPUImageLocalBinaryPatternFilter.m */,
BCFB588515E03E4F00750F12 /* GPUImageLanczosResamplingFilter.h */,
BCFB588615E03E4F00750F12 /* GPUImageLanczosResamplingFilter.m */,
BCB3B46315F2BA9300EDA3BE /* GPUImageLowPassFilter.h */,
BCB3B46415F2BA9300EDA3BE /* GPUImageLowPassFilter.m */,
BCB3B46815F2FD1B00EDA3BE /* GPUImageHighPassFilter.h */,
BCB3B46915F2FD1B00EDA3BE /* GPUImageHighPassFilter.m */,
);
name = "Image processing";
sourceTree = "<group>";
Expand Down Expand Up @@ -1159,6 +1171,8 @@
BCB79E7A15EC2A8400965D92 /* GPUImageAverageLuminanceThresholdFilter.h in Headers */,
BC99234E15EFFC8700ED2C8C /* GPUImageChromaKeyFilter.h in Headers */,
BC99235315EFFC9700ED2C8C /* GPUImageWhiteBalanceFilter.h in Headers */,
BCB3B46515F2BA9300EDA3BE /* GPUImageLowPassFilter.h in Headers */,
BCB3B46A15F2FD1B00EDA3BE /* GPUImageHighPassFilter.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -1406,6 +1420,8 @@
BCB79E7B15EC2A8400965D92 /* GPUImageAverageLuminanceThresholdFilter.m in Sources */,
BC99234F15EFFC8700ED2C8C /* GPUImageChromaKeyFilter.m in Sources */,
BC99235415EFFC9700ED2C8C /* GPUImageWhiteBalanceFilter.m in Sources */,
BCB3B46615F2BA9300EDA3BE /* GPUImageLowPassFilter.m in Sources */,
BCB3B46B15F2FD1B00EDA3BE /* GPUImageHighPassFilter.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
4 changes: 3 additions & 1 deletion framework/Source/GPUImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,6 @@
#import "GPUImageLuminosity.h"
#import "GPUImageAverageLuminanceThresholdFilter.h"
#import "GPUImageWhiteBalanceFilter.h"
#import "GPUImageChromaKeyFilter.h"
#import "GPUImageChromaKeyFilter.h"
#import "GPUImageLowPassFilter.h"
#import "GPUImageHighPassFilter.h"
8 changes: 8 additions & 0 deletions framework/Source/GPUImageBuffer.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
#import "GPUImageBuffer.h"

@interface GPUImageBuffer()

//Texture management
- (GLuint)generateTexture;
- (void)removeTexture:(GLuint)textureToRemove;

@end

@implementation GPUImageBuffer

@synthesize bufferSize = _bufferSize;
Expand Down
14 changes: 14 additions & 0 deletions framework/Source/GPUImageHighPassFilter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#import "GPUImageFilterGroup.h"
#import "GPUImageLowPassFilter.h"
#import "GPUImageDifferenceBlendFilter.h"

@interface GPUImageHighPassFilter : GPUImageFilterGroup
{
GPUImageLowPassFilter *lowPassFilter;
GPUImageDifferenceBlendFilter *differenceBlendFilter;
}

// This controls the degree by which the previous accumulated frames are blended and then subtracted from the current one. This ranges from 0.0 to 1.0, with a default of 0.5.
@property(readwrite, nonatomic) CGFloat filterStrength;

@end
44 changes: 44 additions & 0 deletions framework/Source/GPUImageHighPassFilter.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#import "GPUImageHighPassFilter.h"

@implementation GPUImageHighPassFilter

- (id)init;
{
if (!(self = [super init]))
{
return nil;
}

// Start with a low pass filter to define the component to be removed
lowPassFilter = [[GPUImageLowPassFilter alloc] init];
[self addFilter:lowPassFilter];

// Take the difference of the current frame from the low pass filtered result to get the high pass
differenceBlendFilter = [[GPUImageDifferenceBlendFilter alloc] init];
[self addFilter:differenceBlendFilter];

// Texture location 0 needs to be the original image for the difference blend
[lowPassFilter addTarget:differenceBlendFilter atTextureLocation:1];

self.initialFilters = [NSArray arrayWithObjects:lowPassFilter, differenceBlendFilter, nil];
self.terminalFilter = differenceBlendFilter;

self.filterStrength = 0.5;

return self;
}

#pragma mark -
#pragma mark Accessors

- (void)setFilterStrength:(CGFloat)newValue;
{
lowPassFilter.filterStrength = newValue;
}

- (CGFloat)filterStrength;
{
return lowPassFilter.filterStrength;
}

@end
14 changes: 14 additions & 0 deletions framework/Source/GPUImageLowPassFilter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#import "GPUImageFilterGroup.h"
#import "GPUImageBuffer.h"
#import "GPUImageDissolveBlendFilter.h"

@interface GPUImageLowPassFilter : GPUImageFilterGroup
{
GPUImageBuffer *bufferFilter;
GPUImageDissolveBlendFilter *dissolveBlendFilter;
}

// This controls the degree by which the previous accumulated frames are blended with the current one. This ranges from 0.0 to 1.0, with a default of 0.5.
@property(readwrite, nonatomic) CGFloat filterStrength;

@end
50 changes: 50 additions & 0 deletions framework/Source/GPUImageLowPassFilter.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#import "GPUImageLowPassFilter.h"

@implementation GPUImageLowPassFilter

- (id)init;
{
if (!(self = [super init]))
{
return nil;
}

// Take in the frame and blend it with the previous one
dissolveBlendFilter = [[GPUImageDissolveBlendFilter alloc] init];
[self addFilter:dissolveBlendFilter];

// Buffer the result to be fed back into the blend
bufferFilter = [[GPUImageBuffer alloc] init];
[self addFilter:bufferFilter];

// Texture location 0 needs to be the original image for the dissolve blend
[bufferFilter addTarget:dissolveBlendFilter atTextureLocation:1];
[dissolveBlendFilter addTarget:bufferFilter];

[dissolveBlendFilter disableSecondFrameCheck];

// To prevent double updating of this filter, disable updates from the sharp image side
// self.inputFilterToIgnoreForUpdates = unsharpMaskFilter;

self.initialFilters = [NSArray arrayWithObject:dissolveBlendFilter];
self.terminalFilter = dissolveBlendFilter;

self.filterStrength = 0.5;

return self;
}

#pragma mark -
#pragma mark Accessors

- (void)setFilterStrength:(CGFloat)newValue;
{
dissolveBlendFilter.mix = newValue;
}

- (CGFloat)filterStrength;
{
return dissolveBlendFilter.mix;
}

@end
4 changes: 4 additions & 0 deletions framework/Source/GPUImageTwoInputFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ extern NSString *const kGPUImageTwoInputTextureVertexShaderString;
CMTime firstFrameTime, secondFrameTime;

BOOL hasSetFirstTexture, hasReceivedFirstFrame, hasReceivedSecondFrame, firstFrameWasVideo, secondFrameWasVideo;
BOOL firstFrameCheckDisabled, secondFrameCheckDisabled;
}

- (void)disableFirstFrameCheck;
- (void)disableSecondFrameCheck;

@end
23 changes: 22 additions & 1 deletion framework/Source/GPUImageTwoInputFilter.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ - (id)initWithVertexShaderFromString:(NSString *)vertexShaderString fragmentShad
hasReceivedSecondFrame = NO;
firstFrameWasVideo = NO;
secondFrameWasVideo = NO;
firstFrameCheckDisabled = NO;
secondFrameCheckDisabled = NO;

firstFrameTime = kCMTimeInvalid;
secondFrameTime = kCMTimeInvalid;
Expand All @@ -69,6 +71,16 @@ - (void)initializeAttributes;
[filterProgram addAttribute:@"inputTextureCoordinate2"];
}

- (void)disableFirstFrameCheck;
{
firstFrameCheckDisabled = YES;
}

- (void)disableSecondFrameCheck;
{
secondFrameCheckDisabled = YES;
}

#pragma mark -
#pragma mark Rendering

Expand Down Expand Up @@ -192,6 +204,10 @@ - (void)newFrameReadyAtTime:(CMTime)frameTime atIndex:(NSInteger)textureIndex;
{
hasReceivedFirstFrame = YES;
firstFrameTime = frameTime;
if (secondFrameCheckDisabled)
{
hasReceivedSecondFrame = YES;
}

if (!CMTIME_IS_INDEFINITE(frameTime))
{
Expand All @@ -205,6 +221,10 @@ - (void)newFrameReadyAtTime:(CMTime)frameTime atIndex:(NSInteger)textureIndex;
{
hasReceivedSecondFrame = YES;
secondFrameTime = frameTime;
if (firstFrameCheckDisabled)
{
hasReceivedSecondFrame = YES;
}

if (!CMTIME_IS_INDEFINITE(frameTime))
{
Expand All @@ -214,7 +234,8 @@ - (void)newFrameReadyAtTime:(CMTime)frameTime atIndex:(NSInteger)textureIndex;
}
}
}


// || (hasReceivedFirstFrame && secondFrameCheckDisabled) || (hasReceivedSecondFrame && firstFrameCheckDisabled)
if ((hasReceivedFirstFrame && hasReceivedSecondFrame) || updatedMovieFrameOppositeStillImage)
{
[super newFrameReadyAtTime:frameTime atIndex:0];
Expand Down
3 changes: 0 additions & 3 deletions framework/Source/GPUImageUnsharpMaskFilter.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ - (id)init;
// Texture location 0 needs to be the sharp image for both the blur and the second stage processing
[blurFilter addTarget:unsharpMaskFilter atTextureLocation:1];

// To prevent double updating of this filter, disable updates from the sharp image side
// self.inputFilterToIgnoreForUpdates = unsharpMaskFilter;

self.initialFilters = [NSArray arrayWithObjects:blurFilter, unsharpMaskFilter, nil];
self.terminalFilter = unsharpMaskFilter;

Expand Down

0 comments on commit 46fa7df

Please sign in to comment.