Skip to content

Commit

Permalink
Experimenting with some fixes for iOS 7 issues. This does not solve t…
Browse files Browse the repository at this point in the history
…hem.
  • Loading branch information
BradLarson committed Jun 25, 2013
1 parent 6921f09 commit ec99dcc
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 35 deletions.
19 changes: 11 additions & 8 deletions framework/Source/GPUImageHoughTransformLineDetector.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,20 @@ - (id)init;
#endif

// First pass: do edge detection and threshold that to just have white pixels for edges
if ([GPUImageContext deviceSupportsFramebufferReads])
{
// if ([GPUImageContext deviceSupportsFramebufferReads])
// if ([GPUImageContext deviceSupportsFramebufferReads])
// {
thresholdEdgeDetectionFilter = [[GPUImageThresholdEdgeDetectionFilter alloc] init];
// thresholdEdgeDetectionFilter = [[GPUImageSobelEdgeDetectionFilter alloc] init];
[(GPUImageThresholdEdgeDetectionFilter *)thresholdEdgeDetectionFilter setThreshold:0.8];
[(GPUImageThresholdEdgeDetectionFilter *)thresholdEdgeDetectionFilter setThreshold:0.4];
// [(GPUImageThresholdEdgeDetectionFilter *)thresholdEdgeDetectionFilter setEdgeStrength:0.25];
[(GPUImageThresholdEdgeDetectionFilter *)thresholdEdgeDetectionFilter setEdgeStrength:1.0];
// thresholdEdgeDetectionFilter = [[GPUImageCannyEdgeDetectionFilter alloc] init];
}
else
{
thresholdEdgeDetectionFilter = [[GPUImageCannyEdgeDetectionFilter alloc] init];
}
// }
// else
// {
// thresholdEdgeDetectionFilter = [[GPUImageCannyEdgeDetectionFilter alloc] init];
// }
[self addFilter:thresholdEdgeDetectionFilter];

#ifdef DEBUGLINEDETECTION
Expand Down
34 changes: 22 additions & 12 deletions framework/Source/GPUImageSobelEdgeDetectionFilter.m
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,28 @@ - (id)initWithFragmentShaderFromString:(NSString *)fragmentShaderString;

- (void)setupFilterForSize:(CGSize)filterFrameSize;
{
runSynchronouslyOnVideoProcessingQueue(^{
if (!hasOverriddenImageSizeFactor)
{
_texelWidth = 1.0 / filterFrameSize.width;
_texelHeight = 1.0 / filterFrameSize.height;

runSynchronouslyOnVideoProcessingQueue(^{
[self setFloat:_texelWidth forUniform:texelWidthUniform program:secondFilterProgram];
[self setFloat:_texelHeight forUniform:texelHeightUniform program:secondFilterProgram];
});
}
});
if (!hasOverriddenImageSizeFactor)
{
_texelWidth = 1.0 / filterFrameSize.width;
_texelHeight = 1.0 / filterFrameSize.height;

runSynchronouslyOnVideoProcessingQueue(^{
[GPUImageContext setActiveShaderProgram:secondFilterProgram];
glUniform1f(texelWidthUniform, _texelWidth);
glUniform1f(texelHeightUniform, _texelHeight);
});
}
}

- (void)setUniformsForProgramAtIndex:(NSUInteger)programIndex;
{
[super setUniformsForProgramAtIndex:programIndex];

if (programIndex == 1)
{
glUniform1f(texelWidthUniform, _texelWidth);
glUniform1f(texelHeightUniform, _texelHeight);
}
}

- (BOOL)wantsMonochromeInput;
Expand Down
37 changes: 25 additions & 12 deletions framework/Source/GPUImageThresholdEdgeDetectionFilter.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,38 @@ @implementation GPUImageThresholdEdgeDetectionFilter

uniform float edgeStrength;

const highp vec3 W = vec3(0.2125, 0.7154, 0.0721);

void main()
{
float bottomLeftIntensity = texture2D(inputImageTexture, bottomLeftTextureCoordinate).r;
float topRightIntensity = texture2D(inputImageTexture, topRightTextureCoordinate).r;
float topLeftIntensity = texture2D(inputImageTexture, topLeftTextureCoordinate).r;
float bottomRightIntensity = texture2D(inputImageTexture, bottomRightTextureCoordinate).r;
// float bottomLeftIntensity = texture2D(inputImageTexture, bottomLeftTextureCoordinate).r;
// float topRightIntensity = texture2D(inputImageTexture, topRightTextureCoordinate).r;
// float topLeftIntensity = texture2D(inputImageTexture, topLeftTextureCoordinate).r;
// float bottomRightIntensity = texture2D(inputImageTexture, bottomRightTextureCoordinate).r;
float leftIntensity = texture2D(inputImageTexture, leftTextureCoordinate).r;
float rightIntensity = texture2D(inputImageTexture, rightTextureCoordinate).r;
float bottomIntensity = texture2D(inputImageTexture, bottomTextureCoordinate).r;
float topIntensity = texture2D(inputImageTexture, topTextureCoordinate).r;
float h = -topLeftIntensity - 2.0 * topIntensity - topRightIntensity + bottomLeftIntensity + 2.0 * bottomIntensity + bottomRightIntensity;
float v = -bottomLeftIntensity - 2.0 * leftIntensity - topLeftIntensity + bottomRightIntensity + 2.0 * rightIntensity + topRightIntensity;
float centerIntensity = texture2D(inputImageTexture, textureCoordinate).r;
// float h = -topLeftIntensity - 2.0 * topIntensity - topRightIntensity + bottomLeftIntensity + 2.0 * bottomIntensity + bottomRightIntensity;
// float v = -bottomLeftIntensity - 2.0 * leftIntensity - topLeftIntensity + bottomRightIntensity + 2.0 * rightIntensity + topRightIntensity;
// float h = -topLeftIntensity - 2.0 * topIntensity - topRightIntensity + leftIntensity + 2.0 * centerIntensity + rightIntensity;
// float v = -bottomLeftIntensity - 2.0 * leftIntensity - topLeftIntensity + bottomIntensity + 2.0 * centerIntensity + topIntensity;
float h = (centerIntensity - topIntensity) + (bottomIntensity - centerIntensity);
float v = (centerIntensity - leftIntensity) + (rightIntensity - centerIntensity);
// float h = (centerIntensity - topIntensity);
// float j = (topIntensity - centerIntensity);
// h = max(h,j);
// j = abs(h);
// float v = (centerIntensity - leftIntensity);

float mag = length(vec2(h, v)) * edgeStrength;
float mag = length(vec2(h, v)) * edgeStrength;
mag = step(threshold, mag);

gl_FragColor = vec4(vec3(mag), 1.0);
// float mag = abs(h);

// gl_FragColor = vec4(h, h, h, 1.0);
// gl_FragColor = vec4(texture2D(inputImageTexture, textureCoordinate));
// gl_FragColor = vec4(h, centerIntensity, j, 1.0);
gl_FragColor = vec4(mag, mag, mag, 1.0);
}
);
#else
Expand All @@ -66,8 +79,6 @@ void main()

uniform float edgeStrength;

const vec3 W = vec3(0.2125, 0.7154, 0.0721);

void main()
{
float bottomLeftIntensity = texture2D(inputImageTexture, bottomLeftTextureCoordinate).r;
Expand All @@ -79,7 +90,9 @@ void main()
float bottomIntensity = texture2D(inputImageTexture, bottomTextureCoordinate).r;
float topIntensity = texture2D(inputImageTexture, topTextureCoordinate).r;
float h = -topLeftIntensity - 2.0 * topIntensity - topRightIntensity + bottomLeftIntensity + 2.0 * bottomIntensity + bottomRightIntensity;
h = max(0.0, h);
float v = -bottomLeftIntensity - 2.0 * leftIntensity - topLeftIntensity + bottomRightIntensity + 2.0 * rightIntensity + topRightIntensity;
v = max(0.0, v);

float mag = length(vec2(h, v)) * edgeStrength;
mag = step(threshold, mag);
Expand Down
11 changes: 8 additions & 3 deletions framework/Source/GPUImageTwoPassFilter.m
Original file line number Diff line number Diff line change
Expand Up @@ -347,12 +347,14 @@ - (void)renderToTextureWithVertices:(const GLfloat *)vertices textureCoordinates

// Run the second stage of the two-pass filter
[GPUImageContext setActiveShaderProgram:secondFilterProgram];
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, 0);
glActiveTexture(GL_TEXTURE3);
glBindTexture(GL_TEXTURE_2D, 0);
[self setSecondFilterFBO];

[self setUniformsForProgramAtIndex:1];

glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);

if (!currentlyReceivingMonochromeInput)
{
glActiveTexture(GL_TEXTURE3);
Expand All @@ -370,6 +372,9 @@ - (void)renderToTextureWithVertices:(const GLfloat *)vertices textureCoordinates

glVertexAttribPointer(secondFilterPositionAttribute, 2, GL_FLOAT, 0, 0, vertices);

glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);

glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

// Release the first FBO early
Expand Down

0 comments on commit ec99dcc

Please sign in to comment.