Skip to content

Commit

Permalink
Fixed the haze and levels filters under iOS 7.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
BradLarson committed Jun 12, 2013
1 parent 6c785e4 commit 4d9f930
Show file tree
Hide file tree
Showing 12 changed files with 143 additions and 33 deletions.
8 changes: 8 additions & 0 deletions framework/GPUImageMac.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
BC78B713172DCCB800342C6A /* GPUImageMissEtikateFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = BC78B70B172DCCB800342C6A /* GPUImageMissEtikateFilter.m */; };
BC78B714172DCCB800342C6A /* GPUImageSoftEleganceFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = BC78B70C172DCCB800342C6A /* GPUImageSoftEleganceFilter.h */; settings = {ATTRIBUTES = (Public, ); }; };
BC78B715172DCCB800342C6A /* GPUImageSoftEleganceFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = BC78B70D172DCCB800342C6A /* GPUImageSoftEleganceFilter.m */; };
BC96A4F1176563C300F215A2 /* GPUImageNonMaximumSuppressionFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = BC96A4EF176563C300F215A2 /* GPUImageNonMaximumSuppressionFilter.h */; };
BC96A4F2176563C300F215A2 /* GPUImageNonMaximumSuppressionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = BC96A4F0176563C300F215A2 /* GPUImageNonMaximumSuppressionFilter.m */; };
BCA20B571746C9EC0097C84A /* GPUImageBuffer.h in Headers */ = {isa = PBXBuildFile; fileRef = BCA20B4F1746C9EC0097C84A /* GPUImageBuffer.h */; settings = {ATTRIBUTES = (Public, ); }; };
BCA20B581746C9EC0097C84A /* GPUImageBuffer.m in Sources */ = {isa = PBXBuildFile; fileRef = BCA20B501746C9EC0097C84A /* GPUImageBuffer.m */; };
BCA20B591746C9EC0097C84A /* GPUImageHighPassFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = BCA20B511746C9EC0097C84A /* GPUImageHighPassFilter.h */; settings = {ATTRIBUTES = (Public, ); }; };
Expand Down Expand Up @@ -326,6 +328,8 @@
BC78B70B172DCCB800342C6A /* GPUImageMissEtikateFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = GPUImageMissEtikateFilter.m; path = Source/GPUImageMissEtikateFilter.m; sourceTree = SOURCE_ROOT; };
BC78B70C172DCCB800342C6A /* GPUImageSoftEleganceFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GPUImageSoftEleganceFilter.h; path = Source/GPUImageSoftEleganceFilter.h; sourceTree = SOURCE_ROOT; };
BC78B70D172DCCB800342C6A /* GPUImageSoftEleganceFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = GPUImageSoftEleganceFilter.m; path = Source/GPUImageSoftEleganceFilter.m; sourceTree = SOURCE_ROOT; };
BC96A4EF176563C300F215A2 /* GPUImageNonMaximumSuppressionFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GPUImageNonMaximumSuppressionFilter.h; path = Source/GPUImageNonMaximumSuppressionFilter.h; sourceTree = SOURCE_ROOT; };
BC96A4F0176563C300F215A2 /* GPUImageNonMaximumSuppressionFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = GPUImageNonMaximumSuppressionFilter.m; path = Source/GPUImageNonMaximumSuppressionFilter.m; sourceTree = SOURCE_ROOT; };
BCA20B4F1746C9EC0097C84A /* GPUImageBuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GPUImageBuffer.h; path = Source/GPUImageBuffer.h; sourceTree = SOURCE_ROOT; };
BCA20B501746C9EC0097C84A /* GPUImageBuffer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = GPUImageBuffer.m; path = Source/GPUImageBuffer.m; sourceTree = SOURCE_ROOT; };
BCA20B511746C9EC0097C84A /* GPUImageHighPassFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GPUImageHighPassFilter.h; path = Source/GPUImageHighPassFilter.h; sourceTree = SOURCE_ROOT; };
Expand Down Expand Up @@ -937,6 +941,8 @@
BC569577174683620081491B /* GPUImageCrosshairGenerator.m */,
BCE2EF8E17459D9300C0628C /* GPUImageColorPackingFilter.h */,
BCE2EF8F17459D9300C0628C /* GPUImageColorPackingFilter.m */,
BC96A4EF176563C300F215A2 /* GPUImageNonMaximumSuppressionFilter.h */,
BC96A4F0176563C300F215A2 /* GPUImageNonMaximumSuppressionFilter.m */,
BCE2EF9017459D9300C0628C /* GPUImageThresholdedNonMaximumSuppressionFilter.h */,
BCE2EF9117459D9300C0628C /* GPUImageThresholdedNonMaximumSuppressionFilter.m */,
BCE2EF9617459E2400C0628C /* GPUImageHoughTransformLineDetector.h */,
Expand Down Expand Up @@ -1197,6 +1203,7 @@
BCA20BC517471C4B0097C84A /* GPUImageMosaicFilter.h in Headers */,
BCA20BC717471C4B0097C84A /* GPUImagePerlinNoiseFilter.h in Headers */,
BCA20BC917471C4B0097C84A /* GPUImageVoronoiConsumerFilter.h in Headers */,
BC96A4F1176563C300F215A2 /* GPUImageNonMaximumSuppressionFilter.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -1409,6 +1416,7 @@
BCA20BC617471C4B0097C84A /* GPUImageMosaicFilter.m in Sources */,
BCA20BC817471C4B0097C84A /* GPUImagePerlinNoiseFilter.m in Sources */,
BCA20BCA17471C4B0097C84A /* GPUImageVoronoiConsumerFilter.m in Sources */,
BC96A4F2176563C300F215A2 /* GPUImageNonMaximumSuppressionFilter.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
5 changes: 0 additions & 5 deletions framework/Source/GPUImageCrosshairGenerator.m
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#import "GPUImageCrosshairGenerator.h"

#define hash #
#define wrappedlabel(x) x
#define escapedhash(a) wrappedlabel(hash)a

NSString *const kGPUImageCrosshairVertexShaderString = SHADER_STRING
(
attribute vec4 position;
Expand All @@ -25,7 +21,6 @@ void main()
#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE
NSString *const kGPUImageCrosshairFragmentShaderString = SHADER_STRING
(

uniform lowp vec3 crosshairColor;

varying highp vec2 centerLocation;
Expand Down
4 changes: 4 additions & 0 deletions framework/Source/GPUImageFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
#define STRINGIZE2(x) STRINGIZE(x)
#define SHADER_STRING(text) @ STRINGIZE2(text)

#define hash #
#define wrappedlabel(x) x
#define escapedhash(a) wrappedlabel(hash)a

extern NSString *const kGPUImageVertexShaderString;
extern NSString *const kGPUImagePassthroughFragmentShaderString;

Expand Down
10 changes: 5 additions & 5 deletions framework/Source/GPUImageHazeFilter.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@

uniform sampler2D inputImageTexture;

uniform lowp float distance;
uniform lowp float hazeDistance;
uniform highp float slope;

void main()
{
//todo reconsider precision modifiers
highp vec4 color = vec4(1.0);//todo reimplement as a parameter

highp float d = textureCoordinate.y * slope + distance;
highp float d = textureCoordinate.y * slope + hazeDistance;

highp vec4 c = texture2D(inputImageTexture, textureCoordinate) ; // consider using unpremultiply

Expand All @@ -31,15 +31,15 @@ void main()

uniform sampler2D inputImageTexture;

uniform float distance;
uniform float hazeDistance;
uniform float slope;

void main()
{
//todo reconsider precision modifiers
vec4 color = vec4(1.0);//todo reimplement as a parameter

float d = textureCoordinate.y * slope + distance;
float d = textureCoordinate.y * slope + hazeDistance;

vec4 c = texture2D(inputImageTexture, textureCoordinate) ; // consider using unpremultiply

Expand Down Expand Up @@ -67,7 +67,7 @@ - (id)init;
return nil;
}

distanceUniform = [filterProgram uniformIndex:@"distance"];
distanceUniform = [filterProgram uniformIndex:@"hazeDistance"];
slopeUniform = [filterProgram uniformIndex:@"slope"];

self.distance = 0.2;
Expand Down
22 changes: 11 additions & 11 deletions framework/Source/GPUImageLevelsFilter.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@
varying highp vec2 textureCoordinate;

uniform sampler2D inputImageTexture;
uniform lowp vec3 min;
uniform lowp vec3 mid;
uniform lowp vec3 max;
uniform lowp vec3 levelMinimum;
uniform lowp vec3 levelMiddle;
uniform lowp vec3 levelMaximum;
uniform lowp vec3 minOutput;
uniform lowp vec3 maxOutput;

void main()
{
lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);

gl_FragColor = vec4(LevelsControl(textureColor.rgb, min, mid, max, minOutput, maxOutput), textureColor.a);
gl_FragColor = vec4(LevelsControl(textureColor.rgb, levelMinimum, levelMiddle, levelMaximum, minOutput, maxOutput), textureColor.a);
}
);
#else
Expand All @@ -42,17 +42,17 @@ void main()
varying vec2 textureCoordinate;

uniform sampler2D inputImageTexture;
uniform vec3 min;
uniform vec3 mid;
uniform vec3 max;
uniform vec3 levelMinimum;
uniform vec3 levelMiddle;
uniform vec3 levelMaximum;
uniform vec3 minOutput;
uniform vec3 maxOutput;

void main()
{
vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);

gl_FragColor = vec4(LevelsControl(textureColor.rgb, min, mid, max, minOutput, maxOutput), textureColor.a);
gl_FragColor = vec4(LevelsControl(textureColor.rgb, levelMinimum, levelMiddle, levelMaximum, minOutput, maxOutput), textureColor.a);
}
);
#endif
Expand All @@ -69,9 +69,9 @@ - (id)init;
return nil;
}

minUniform = [filterProgram uniformIndex:@"min"];
midUniform = [filterProgram uniformIndex:@"mid"];
maxUniform = [filterProgram uniformIndex:@"max"];
minUniform = [filterProgram uniformIndex:@"levelMinimum"];
midUniform = [filterProgram uniformIndex:@"levelMiddle"];
maxUniform = [filterProgram uniformIndex:@"levelMaximum"];
minOutputUniform = [filterProgram uniformIndex:@"minOutput"];
maxOutputUniform = [filterProgram uniformIndex:@"maxOutput"];

Expand Down
45 changes: 45 additions & 0 deletions framework/Source/GPUImageNonMaximumSuppressionFilter.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#import "GPUImageNonMaximumSuppressionFilter.h"

#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE
NSString *const kGPUImageNonMaximumSuppressionFragmentShaderString = SHADER_STRING
(
uniform sampler2D inputImageTexture;
Expand Down Expand Up @@ -42,6 +43,50 @@ void main()
gl_FragColor = vec4((centerColor.rgb * step(maxValue, centerColor.r) * multiplier), 1.0);
}
);
#else
NSString *const kGPUImageNonMaximumSuppressionFragmentShaderString = SHADER_STRING
(
uniform sampler2D inputImageTexture;

varying vec2 textureCoordinate;
varying vec2 leftTextureCoordinate;
varying vec2 rightTextureCoordinate;

varying vec2 topTextureCoordinate;
varying vec2 topLeftTextureCoordinate;
varying vec2 topRightTextureCoordinate;

varying vec2 bottomTextureCoordinate;
varying vec2 bottomLeftTextureCoordinate;
varying vec2 bottomRightTextureCoordinate;

void main()
{
float bottomColor = texture2D(inputImageTexture, bottomTextureCoordinate).r;
float bottomLeftColor = texture2D(inputImageTexture, bottomLeftTextureCoordinate).r;
float bottomRightColor = texture2D(inputImageTexture, bottomRightTextureCoordinate).r;
vec4 centerColor = texture2D(inputImageTexture, textureCoordinate);
float leftColor = texture2D(inputImageTexture, leftTextureCoordinate).r;
float rightColor = texture2D(inputImageTexture, rightTextureCoordinate).r;
float topColor = texture2D(inputImageTexture, topTextureCoordinate).r;
float topRightColor = texture2D(inputImageTexture, topRightTextureCoordinate).r;
float topLeftColor = texture2D(inputImageTexture, topLeftTextureCoordinate).r;

// Use a tiebreaker for pixels to the left and immediately above this one
float multiplier = 1.0 - step(centerColor.r, topColor);
multiplier = multiplier * 1.0 - step(centerColor.r, topLeftColor);
multiplier = multiplier * 1.0 - step(centerColor.r, leftColor);
multiplier = multiplier * 1.0 - step(centerColor.r, bottomLeftColor);

float maxValue = max(centerColor.r, bottomColor);
maxValue = max(maxValue, bottomRightColor);
maxValue = max(maxValue, rightColor);
maxValue = max(maxValue, topRightColor);

gl_FragColor = vec4((centerColor.rgb * step(maxValue, centerColor.r) * multiplier), 1.0);
}
);
#endif

@implementation GPUImageNonMaximumSuppressionFilter

Expand Down
43 changes: 42 additions & 1 deletion framework/Source/GPUImageParallelCoordinateLineTransformFilter.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,20 @@ void main()
gl_FragColor = vec4(0.004, 0.004, 0.004, 1.0);
}
);

// NOTE: See below for where I'm tacking on the required extension as a prefix
NSString *const kGPUImageHoughAccumulationFBOReadFragmentShaderString = SHADER_STRING
(
const lowp float scalingFactor = 1.0 / 256.0;

void main()
{
lowp vec4 previousFragmentData = gl_LastFragData[0];
// gl_FragColor = vec4(scalingFactor, scalingFactor, scalingFactor, 1.0);
gl_FragColor = vec4(0.004, 0.004, 0.004, 1.0);
}
);

#else
NSString *const kGPUImageHoughAccumulationFragmentShaderString = SHADER_STRING
(
Expand All @@ -32,6 +46,17 @@ void main()
gl_FragColor = vec4(0.004, 0.004, 0.004, 1.0);
}
);

NSString *const kGPUImageHoughAccumulationFBOReadFragmentShaderString = SHADER_STRING
(
const float scalingFactor = 1.0 / 256.0;

void main()
{
// gl_FragColor = vec4(scalingFactor, scalingFactor, scalingFactor, 1.0);
gl_FragColor = vec4(0.004, 0.004, 0.004, 1.0);
}
);
#endif

@interface GPUImageParallelCoordinateLineTransformFilter()
Expand All @@ -47,11 +72,27 @@ @implementation GPUImageParallelCoordinateLineTransformFilter

- (id)init;
{
if (!(self = [super initWithVertexShaderFromString:kGPUImageHoughAccumulationVertexShaderString fragmentShaderFromString:kGPUImageHoughAccumulationFragmentShaderString]))
NSString *fragmentShaderToUse = nil;

if ([GPUImageContext deviceSupportsFramebufferReads])
{
fragmentShaderToUse = [NSString stringWithFormat:@"#extension GL_EXT_shader_framebuffer_fetch : require\n %@",kGPUImageHoughAccumulationFBOReadFragmentShaderString];

// NSLog(@"Supports FBO reads: %@", fragmentShaderToUse);
// fragmentShaderToUse = kGPUImageHoughAccumulationFBOReadFragmentShaderString;
}
else
{
// NSLog(@"Doesn't support FBO reads");
fragmentShaderToUse = kGPUImageHoughAccumulationFragmentShaderString;
}

if (!(self = [super initWithVertexShaderFromString:kGPUImageHoughAccumulationVertexShaderString fragmentShaderFromString:fragmentShaderToUse]))
{
return nil;
}


return self;
}

Expand Down
22 changes: 11 additions & 11 deletions framework/Source/GPUImageRGBFilter.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
varying highp vec2 textureCoordinate;

uniform sampler2D inputImageTexture;
uniform highp float red;
uniform highp float green;
uniform highp float blue;
uniform highp float redAdjustment;
uniform highp float greenAdjustment;
uniform highp float blueAdjustment;

void main()
{
highp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);

gl_FragColor = vec4(textureColor.r * red, textureColor.g * green, textureColor.b * blue, textureColor.a);
gl_FragColor = vec4(textureColor.r * redAdjustment, textureColor.g * greenAdjustment, textureColor.b * blueAdjustment, textureColor.a);
}
);
#else
Expand All @@ -23,15 +23,15 @@ void main()
varying vec2 textureCoordinate;

uniform sampler2D inputImageTexture;
uniform float red;
uniform float green;
uniform float blue;
uniform float redAdjustment;
uniform float greenAdjustment;
uniform float blueAdjustment;

void main()
{
vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);

gl_FragColor = vec4(textureColor.r * red, textureColor.g * green, textureColor.b * blue, textureColor.a);
gl_FragColor = vec4(textureColor.r * redAdjustment, textureColor.g * greenAdjustment, textureColor.b * blueAdjustment, textureColor.a);
}
);
#endif
Expand All @@ -50,13 +50,13 @@ - (id)init;
return nil;
}

redUniform = [filterProgram uniformIndex:@"red"];
redUniform = [filterProgram uniformIndex:@"redAdjustment"];
self.red = 1.0;

greenUniform = [filterProgram uniformIndex:@"green"];
greenUniform = [filterProgram uniformIndex:@"greenAdjustment"];
self.green = 1.0;

blueUniform = [filterProgram uniformIndex:@"blue"];
blueUniform = [filterProgram uniformIndex:@"blueAdjustment"];
self.blue = 1.0;

return self;
Expand Down
1 change: 1 addition & 0 deletions framework/Source/Mac/GPUImageContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ typedef enum { kGPUImageNoRotation, kGPUImageRotateLeft, kGPUImageRotateRight, k
+ (GLint)maximumTextureUnitsForThisDevice;
+ (BOOL)deviceSupportsOpenGLESExtension:(NSString *)extension;
+ (BOOL)deviceSupportsRedTextures;
+ (BOOL)deviceSupportsFramebufferReads;
+ (CGSize)sizeThatFitsWithinATextureForSize:(CGSize)inputSize;

- (void)presentBufferForDisplay;
Expand Down
4 changes: 4 additions & 0 deletions framework/Source/Mac/GPUImageContext.m
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ + (BOOL)deviceSupportsOpenGLESExtension:(NSString *)extension;
return [extensionNames containsObject:extension];
}

+ (BOOL)deviceSupportsFramebufferReads;
{
return NO;
}

// http://www.khronos.org/registry/gles/extensions/EXT/EXT_texture_rg.txt

Expand Down
1 change: 1 addition & 0 deletions framework/Source/iOS/GPUImageContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ typedef enum { kGPUImageNoRotation, kGPUImageRotateLeft, kGPUImageRotateRight, k
+ (GLint)maximumTextureUnitsForThisDevice;
+ (BOOL)deviceSupportsOpenGLESExtension:(NSString *)extension;
+ (BOOL)deviceSupportsRedTextures;
+ (BOOL)deviceSupportsFramebufferReads;
+ (CGSize)sizeThatFitsWithinATextureForSize:(CGSize)inputSize;

- (void)presentBufferForDisplay;
Expand Down
Loading

0 comments on commit 4d9f930

Please sign in to comment.