Skip to content

Commit

Permalink
The pixellation filter now uses square pixels. The GPUImageGaussianSe…
Browse files Browse the repository at this point in the history
…lectiveBlur now works over a circular region, although this can be overridden.
  • Loading branch information
BradLarson committed Aug 5, 2012
1 parent 533ec0d commit 5b9a028
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 17 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ Documentation is generated from header comments using appledoc. To build the doc
- *shadows*: Increase to lighten shadows, from 0.0 to 1.0, with 0.0 as the default.
- *highlights*: Decrease to darken highlights, from 0.0 to 1.0, with 1.0 as the default.

- **GPUImageLookupFilter**: Uses an RGB color lookup image to remap the colors in an image. First, use your favourite photo editing application to apply a filter to lookup.png from GPUImage/framework/Resources. For this to work properly each pixel color must not depend on other pixels (e.g. blur will not work). If you need a more complex filter you can create as many lookup tables as required. Once ready, use your new lookup.png file as a second input for GPUImageLookupFilter.

- **GPUImageLookupFilter**: A photo filter based on a Photoshop action by Amatorka: http://amatorka.deviantart.com/art/Amatorka-Action-2-121069631 . If you want to use this effect you have to add lookup_amatorka.png from the GPUImage Resources folder to your application bundle.

- **GPUImageMissEtikateFilter**: A photo filter based on a Photoshop action by Miss Etikate: http://miss-etikate.deviantart.com/art/Photoshop-Action-15-120151961 . If you want to use this effect you have to add lookup_miss_etikate.png from the GPUImage Resources folder to your application bundle.

- **GPUImageSoftEleganceFilter**: Another lookup-based color remapping filter. If you want to use this effect you have to add lookup_soft_elegance_1.png and lookup_soft_elegance_2.png from the GPUImage Resources folder to your application bundle.

- **GPUImageColorInvertFilter**: Inverts the colors of an image

- **GPUImageGrayscaleFilter**: Converts an image to grayscale (a slightly faster implementation of the saturation filter, without the ability to vary the color contribution)
Expand Down Expand Up @@ -138,6 +146,7 @@ Documentation is generated from header comments using appledoc. To build the doc
- *excludeCircleRadius*: The radius of the circular area being excluded from the blur
- *excludeCirclePoint*: The center of the circular area being excluded from the blur
- *excludeBlurSize*: The size of the area between the blurred portion and the clear circle
- *aspectRatio*: The aspect ratio of the image, used to adjust the circularity of the in-focus region. By default, this matches the image aspect ratio, but you can override this value.

- **GPUImageTiltShiftFilter**: A simulated tilt shift lens effect
- *blurSize*: A multiplier for the size of the out-of-focus blur, ranging from 0.0 on up, with a default of 2.0
Expand Down Expand Up @@ -210,6 +219,10 @@ Documentation is generated from header comments using appledoc. To build the doc

- **GPUImageMultiplyBlendFilter**: Applies a multiply blend of two images

- **GPUImageAddBlendFilter**: Applies an additive blend of two images

- **GPUImageDivideBlendFilter**: Applies a division blend of two images

- **GPUImageOverlayBlendFilter**: Applies an overlay blend of two images

- **GPUImageDarkenBlendFilter**: Blends two images by taking the minimum value of each color component between the images
Expand Down
22 changes: 11 additions & 11 deletions framework/GPUImage.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -599,8 +599,6 @@
children = (
BC982B7714F098CC0001FF6F /* GPUImageBrightnessFilter.h */,
BC982B7814F098CC0001FF6F /* GPUImageBrightnessFilter.m */,
96DD3C1215C2780500DF637E /* GPUImageLookupFilter.h */,
96DD3C1315C2780500DF637E /* GPUImageLookupFilter.m */,
BCB6B833150400030041703B /* GPUImageExposureFilter.h */,
BCB6B834150400030041703B /* GPUImageExposureFilter.m */,
BC982B6514F092EF0001FF6F /* GPUImageContrastFilter.h */,
Expand All @@ -612,11 +610,9 @@
B81521A014F1BA6A00F105F8 /* GPUImageColorMatrixFilter.h */,
B81521A114F1BA6A00F105F8 /* GPUImageColorMatrixFilter.m */,
BEBE83B3155C092A00EEF8C3 /* GPUImageRGBFilter.h */,
BEBE83B4155C092A00EEF8C3 /* GPUImageRGBFilter.m */,
C2EDA90415BB136D007CBA0F /* GPUImageHueFilter.h */,
C2EDA90515BB136D007CBA0F /* GPUImageHueFilter.m */,
BEBE83B4155C092A00EEF8C3 /* GPUImageRGBFilter.m */,
BCC46E5C15B9EFE8005519B9 /* GPUImageHighlightShadowFilter.h */,
BCC46E5D15B9EFE8005519B9 /* GPUImageHighlightShadowFilter.m */,
BCBCE9971595021B00E0ED33 /* GPUImageMonochromeFilter.h */,
BCBCE9981595021B00E0ED33 /* GPUImageMonochromeFilter.m */,
BCC46E6115BA095F005519B9 /* GPUImageFalseColorFilter.h */,
Expand All @@ -639,6 +635,16 @@
BCC11D71154B44DC0044F5A0 /* GPUImageHistogramGenerator.m */,
BCF1E57915673599006B155F /* GPUImageToneCurveFilter.h */,
BCF1E57A15673599006B155F /* GPUImageToneCurveFilter.m */,
BCC46E5C15B9EFE8005519B9 /* GPUImageHighlightShadowFilter.h */,
BCC46E5D15B9EFE8005519B9 /* GPUImageHighlightShadowFilter.m */,
96DD3C1215C2780500DF637E /* GPUImageLookupFilter.h */,
96DD3C1315C2780500DF637E /* GPUImageLookupFilter.m */,
96781B2D15C38DCF005FA0D7 /* GPUImageAmatorkaFilter.h */,
96781B2E15C38DCF005FA0D7 /* GPUImageAmatorkaFilter.m */,
96781B3215C39E80005FA0D7 /* GPUImageMissEtikateFilter.h */,
96781B3315C39E80005FA0D7 /* GPUImageMissEtikateFilter.m */,
96781B4415C3A6F0005FA0D7 /* GPUImageSoftEleganceFilter.h */,
96781B4515C3A6F0005FA0D7 /* GPUImageSoftEleganceFilter.m */,
BCF6B40F15A7849F00FC6F58 /* GPUImageOpacityFilter.h */,
BCF6B41015A7849F00FC6F58 /* GPUImageOpacityFilter.m */,
);
Expand Down Expand Up @@ -735,12 +741,6 @@
BCF1E53D15669907006B155F /* GPUImageMosaicFilter.m */,
BCF1E53E15669907006B155F /* GPUImageVoroniConsumerFilter.h */,
BCF1E53F15669907006B155F /* GPUImageVoroniConsumerFilter.m */,
96781B2D15C38DCF005FA0D7 /* GPUImageAmatorkaFilter.h */,
96781B2E15C38DCF005FA0D7 /* GPUImageAmatorkaFilter.m */,
96781B3215C39E80005FA0D7 /* GPUImageMissEtikateFilter.h */,
96781B3315C39E80005FA0D7 /* GPUImageMissEtikateFilter.m */,
96781B4415C3A6F0005FA0D7 /* GPUImageSoftEleganceFilter.h */,
96781B4515C3A6F0005FA0D7 /* GPUImageSoftEleganceFilter.m */,
);
name = Effects;
sourceTree = "<group>";
Expand Down
4 changes: 4 additions & 0 deletions framework/Source/GPUImageGaussianSelectiveBlurFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
{
GPUImageGaussianBlurFilter *blurFilter;
GPUImageFilter *selectiveFocusFilter;
BOOL hasOverriddenAspectRatio;
}

/** The radius of the circular area being excluded from the blur
Expand All @@ -22,5 +23,8 @@
/** A multiplier for the size of the blur, ranging from 0.0 on up, with a default of 1.0
*/
@property (readwrite, nonatomic) CGFloat blurSize;
/** The aspect ratio of the image, used to adjust the circularity of the in-focus region. By default, this matches the image aspect ratio, but you can override this value.
*/
@property (readwrite, nonatomic) CGFloat aspectRatio;

@end
30 changes: 27 additions & 3 deletions framework/Source/GPUImageGaussianSelectiveBlurFilter.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@
uniform lowp float excludeCircleRadius;
uniform lowp vec2 excludeCirclePoint;
uniform lowp float excludeBlurSize;

uniform highp float aspectRatio;

void main()
{
lowp vec4 sharpImageColor = texture2D(inputImageTexture, textureCoordinate);
lowp vec4 blurredImageColor = texture2D(inputImageTexture2, textureCoordinate2);

lowp float d = distance(textureCoordinate2, excludeCirclePoint);
highp vec2 textureCoordinateToUse = vec2(textureCoordinate2.x, (textureCoordinate2.y * aspectRatio + 0.5 - 0.5 * aspectRatio));
highp float distanceFromCenter = distance(excludeCirclePoint, textureCoordinateToUse);

gl_FragColor = mix(sharpImageColor, blurredImageColor, smoothstep(excludeCircleRadius - excludeBlurSize, excludeCircleRadius, d));
gl_FragColor = mix(sharpImageColor, blurredImageColor, smoothstep(excludeCircleRadius - excludeBlurSize, excludeCircleRadius, distanceFromCenter));
}
);

Expand All @@ -37,6 +39,8 @@ - (id)init;
return nil;
}

hasOverriddenAspectRatio = NO;

// First pass: apply a variable Gaussian blur
blurFilter = [[GPUImageGaussianBlurFilter alloc] init];
[self addFilter:blurFilter];
Expand All @@ -61,6 +65,19 @@ - (id)init;
return self;
}

- (void)setInputSize:(CGSize)newSize atIndex:(NSInteger)textureIndex;
{
CGSize oldInputSize = inputTextureSize;
[super setInputSize:newSize atIndex:textureIndex];
inputTextureSize = newSize;

if ( (!CGSizeEqualToSize(oldInputSize, inputTextureSize)) && (!hasOverriddenAspectRatio) )
{
_aspectRatio = (inputTextureSize.width / inputTextureSize.height);
[selectiveFocusFilter setFloat:_aspectRatio forUniform:@"aspectRatio"];
}
}

#pragma mark -
#pragma mark Accessors

Expand Down Expand Up @@ -92,4 +109,11 @@ - (void)setExcludeBlurSize:(CGFloat)newValue;
[selectiveFocusFilter setFloat:newValue forUniform:@"excludeBlurSize"];
}

- (void)setAspectRatio:(CGFloat)newValue;
{
hasOverriddenAspectRatio = YES;
_aspectRatio = newValue;
[selectiveFocusFilter setFloat:_aspectRatio forUniform:@"aspectRatio"];
}

@end
2 changes: 1 addition & 1 deletion framework/Source/GPUImagePixellateFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

@interface GPUImagePixellateFilter : GPUImageFilter
{
GLint fractionalWidthOfAPixelUniform;
GLint fractionalWidthOfAPixelUniform, aspectRatioUniform;
}

// The fractional width of the image to use as a size for the pixels in the resulting image. Values below one pixel width in the source image are ignored.
Expand Down
33 changes: 31 additions & 2 deletions framework/Source/GPUImagePixellateFilter.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,27 @@
uniform sampler2D inputImageTexture;

uniform highp float fractionalWidthOfPixel;

uniform highp float aspectRatio;

void main()
{
highp vec2 sampleDivisor = vec2(fractionalWidthOfPixel);
highp vec2 sampleDivisor = vec2(fractionalWidthOfPixel, fractionalWidthOfPixel / aspectRatio);

highp vec2 samplePos = textureCoordinate - mod(textureCoordinate, sampleDivisor);
gl_FragColor = texture2D(inputImageTexture, samplePos );
}
);

@interface GPUImagePixellateFilter ()

@property (readwrite, nonatomic) CGFloat aspectRatio;

@end

@implementation GPUImagePixellateFilter

@synthesize fractionalWidthOfAPixel = _fractionalWidthOfAPixel;
@synthesize aspectRatio = _aspectRatio;

#pragma mark -
#pragma mark Initialization and teardown
Expand All @@ -32,12 +40,24 @@ - (id)init;
}

fractionalWidthOfAPixelUniform = [filterProgram uniformIndex:@"fractionalWidthOfPixel"];
aspectRatioUniform = [filterProgram uniformIndex:@"aspectRatio"];

self.fractionalWidthOfAPixel = 0.05;

return self;
}

- (void)setInputSize:(CGSize)newSize atIndex:(NSInteger)textureIndex;
{
CGSize oldInputSize = inputTextureSize;
[super setInputSize:newSize atIndex:textureIndex];

if (!CGSizeEqualToSize(oldInputSize, inputTextureSize))
{
[self setAspectRatio:(inputTextureSize.width / inputTextureSize.height)];
}
}

#pragma mark -
#pragma mark Accessors

Expand Down Expand Up @@ -67,4 +87,13 @@ - (void)setFractionalWidthOfAPixel:(CGFloat)newValue;
glUniform1f(fractionalWidthOfAPixelUniform, _fractionalWidthOfAPixel);
}

- (void)setAspectRatio:(CGFloat)newValue;
{
_aspectRatio = newValue;

[GPUImageOpenGLESContext useImageProcessingContext];
[filterProgram use];
glUniform1f(aspectRatioUniform, _aspectRatio);
}

@end

0 comments on commit 5b9a028

Please sign in to comment.