Skip to content
Browse files

Sped up general Gaussian blur by 20X on iPhone 4, Gaussian selective …

…blur by 2X.
  • Loading branch information...
1 parent a702c4c commit 471bbbc4fda93d034753197e1287b6450eb9f586 @BradLarson committed Mar 26, 2012
View
2 examples/SimpleImageFilter/SimpleImageFilter/SimpleImageViewController.h
@@ -4,7 +4,7 @@
@interface SimpleImageViewController : UIViewController
{
GPUImagePicture *sourcePicture;
- GPUImageSepiaFilter *sepiaFilter, *sepiaFilter2;
+ GPUImageFilter *sepiaFilter, *sepiaFilter2;
}
// Image filtering
View
9 examples/SimpleImageFilter/SimpleImageFilter/SimpleImageViewController.m
@@ -45,14 +45,12 @@ - (void)setupDisplayFiltering;
sourcePicture = [[GPUImagePicture alloc] initWithImage:inputImage smoothlyScaleOutput:YES];
sepiaFilter = [[GPUImageSepiaFilter alloc] init];
- sepiaFilter2 = [[GPUImageSepiaFilter alloc] init];
GPUImageView *imageView = (GPUImageView *)self.view;
[sourcePicture addTarget:sepiaFilter];
- [sepiaFilter addTarget:sepiaFilter2];
- [sepiaFilter2 addTarget:imageView];
-
+ [sepiaFilter addTarget:imageView];
+
[sourcePicture processImage];
}
@@ -96,8 +94,7 @@ - (void)setupImageFilteringToDisk;
if (![dataForPNGFile2 writeToFile:[documentsDirectory stringByAppendingPathComponent:@"Lambeau-filtered2.png"] options:NSAtomicWrite error:&error])
{
return;
- }
-
+ }
}
@end
View
18 framework/Source/GPUImageGaussianBlurFilter.m
@@ -62,18 +62,22 @@ void main() {
const lowp int GAUSSIAN_SAMPLES = 9;
- uniform mediump float gaussianValues[9];
-
varying highp vec2 textureCoordinate;
varying highp vec2 blurCoordinates[GAUSSIAN_SAMPLES];
void main() {
- highp vec4 sum = vec4(0.0);
-
- for (lowp int i = 0; i < GAUSSIAN_SAMPLES; i++) {
- sum += texture2D(inputImageTexture, blurCoordinates[i]) * gaussianValues[i];
- }
+ lowp vec4 sum = vec4(0.0);
+ sum += texture2D(inputImageTexture, blurCoordinates[0]) * 0.05;
+ sum += texture2D(inputImageTexture, blurCoordinates[1]) * 0.09;
+ sum += texture2D(inputImageTexture, blurCoordinates[2]) * 0.12;
+ sum += texture2D(inputImageTexture, blurCoordinates[3]) * 0.15;
+ sum += texture2D(inputImageTexture, blurCoordinates[4]) * 0.18;
+ sum += texture2D(inputImageTexture, blurCoordinates[5]) * 0.15;
+ sum += texture2D(inputImageTexture, blurCoordinates[6]) * 0.12;
+ sum += texture2D(inputImageTexture, blurCoordinates[7]) * 0.09;
+ sum += texture2D(inputImageTexture, blurCoordinates[8]) * 0.05;
+
gl_FragColor = sum;
}
);
View
18 framework/Source/GPUImageGaussianSelectiveBlurFilter.m
@@ -18,13 +18,19 @@
void main() {
- highp vec4 sum = vec4(0.0);
-
- for (lowp int i = 0; i < GAUSSIAN_SAMPLES; i++) {
- sum += texture2D(inputImageTexture, blurCoordinates[i]) * gaussianValues[i];
- }
+ lowp vec4 sum = vec4(0.0);
+
+ sum += texture2D(inputImageTexture, blurCoordinates[0]) * 0.05;
+ sum += texture2D(inputImageTexture, blurCoordinates[1]) * 0.09;
+ sum += texture2D(inputImageTexture, blurCoordinates[2]) * 0.12;
+ sum += texture2D(inputImageTexture, blurCoordinates[3]) * 0.15;
+ sum += texture2D(inputImageTexture, blurCoordinates[4]) * 0.18;
+ sum += texture2D(inputImageTexture, blurCoordinates[5]) * 0.15;
+ sum += texture2D(inputImageTexture, blurCoordinates[6]) * 0.12;
+ sum += texture2D(inputImageTexture, blurCoordinates[7]) * 0.09;
+ sum += texture2D(inputImageTexture, blurCoordinates[8]) * 0.05;
- highp vec4 overlay = texture2D(inputImageTexture2, textureCoordinate);
+ lowp vec4 overlay = texture2D(inputImageTexture2, textureCoordinate);
lowp float d = distance(textureCoordinate, excludeCirclePoint);
sum = mix(overlay, sum, smoothstep(excludeCircleRadius - excludeBlurSize, excludeCircleRadius, d));

0 comments on commit 471bbbc

Please sign in to comment.
Something went wrong with that request. Please try again.