Skip to content

Commit

Permalink
Merge pull request BradLarson#2133 from r3mus/master
Browse files Browse the repository at this point in the history
Added 3 new filters, some corrections to readme for vignette and highlight/shadow
  • Loading branch information
BradLarson committed Dec 3, 2015
2 parents 57047fd + dc6b5cb commit 0674173
Show file tree
Hide file tree
Showing 7 changed files with 574 additions and 3 deletions.
25 changes: 22 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,9 @@ There are currently 125 built-in filters, divided into the following categories:
- **GPUImageHueFilter**: Adjusts the hue of an image
- *hue*: The hue angle, in degrees. 90 degrees by default

- **GPUImageVibranceFilter**: Adjusts the vibrance of an image
- *vibrance*: The vibrance adjustment to apply, using 0.0 as the default, and a suggested min/max of around -1.2 and 1.2, respectively.

- **GPUImageWhiteBalanceFilter**: Adjusts the white balance of an image.
- *temperature*: The temperature to adjust the image by, in ºK. A value of 4000 is very cool and 7000 very warm. The default value is 5000. Note that the scale between 4000 and 5000 is nearly as visually significant as that between 5000 and 7000.
- *tint*: The tint to adjust the image by. A value of -200 is *very* green and 200 is *very* pink. The default value is 0.
Expand All @@ -306,7 +309,13 @@ There are currently 125 built-in filters, divided into the following categories:

- **GPUImageHighlightShadowFilter**: Adjusts the shadows and highlights of an image
- *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.
- *highlights*: Decrease to darken highlights, from 1.0 to 0.0, with 1.0 as the default.

- **GPUImageHighlightShadowTintFilter**: Allows you to tint the shadows and highlights of an image independently using a color and intensity
- *shadowTintColor*: Shadow tint RGB color (GPUVector4). Default: `{1.0f, 0.0f, 0.0f, 1.0f}` (red).
- *highlightTintColor*: Highlight tint RGB color (GPUVector4). Default: `{0.0f, 0.0f, 1.0f, 1.0f}` (blue).
- *shadowTintIntensity*: Shadow tint intensity, from 0.0 to 1.0. Default: 0.0
- *highlightTintIntensity*: Highlight tint intensity, from 0.0 to 1.0, with 0.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.

Expand All @@ -316,6 +325,14 @@ There are currently 125 built-in filters, divided into the following categories:

- **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.

- **GPUImageSkinToneFilter**: A skin-tone adjustment filter that affects a unique range of light skin-tone colors and adjusts the pink/green or pink/orange range accordingly. Default values are targetted at fair caucasian skin, but can be adjusted as required.
- *skinToneAdjust*: Amount to adjust skin tone. Default: 0.0, suggested min/max: -0.3 and 0.3 respectively.
- *skinHue*: Skin hue to be detected. Default: 0.05 (fair caucasian to reddish skin).
- *skinHueThreshold*: Amount of variance in skin hue. Default: 40.0.
- *maxHueShift*: Maximum amount of hue shifting allowed. Default: 0.25.
- *maxSaturationShift* = Maximum amount of saturation to be shifted (when using orange). Default: 0.4.
- *upperSkinToneColor* = `GPUImageSkinToneUpperColorGreen` or `GPUImageSkinToneUpperColorOrange`

- **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 @@ -667,8 +684,10 @@ There are currently 125 built-in filters, divided into the following categories:
- *refractiveIndex*: The index of refraction for the sphere, with a default of 0.71

- **GPUImageVignetteFilter**: Performs a vignetting effect, fading out the image at the edges
- *x*:
- *y*: The directional intensity of the vignetting, with a default of x = 0.75, y = 0.5
- *vignetteCenter*: The center for the vignette in tex coords (CGPoint), with a default of 0.5, 0.5
- *vignetteColor*: The color to use for the vignette (GPUVector3), with a default of black
- *vignetteStart*: The normalized distance from the center where the vignette effect starts, with a default of 0.5
- *vignetteEnd*: The normalized distance from the center where the vignette effect ends, with a default of 0.75

- **GPUImageKuwaharaFilter**: Kuwahara image abstraction, drawn from the work of Kyprianidis, et. al. in their publication "Anisotropic Kuwahara Filtering on the GPU" within the GPU Pro collection. This produces an oil-painting-like image, but it is extremely computationally expensive, so it can take seconds to render a frame on an iPad 2. This might be best used for still images.
- *radius*: In integer specifying the number of pixels out from the center pixel to test when applying the filter, with a default of 4. A higher value creates a more abstracted image, but at the cost of much greater processing time.
Expand Down
25 changes: 25 additions & 0 deletions framework/Source/GPUImageHighlightShadowTintFilter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// GPUImageHighlightShadowTintFilter.h
//
//
// Created by github.com/r3mus on 8/14/15.
//
//

#import "GPUImageFilter.h"

@interface GPUImageHighlightShadowTintFilter : GPUImageFilter
{
GLint shadowTintIntensityUniform, highlightTintIntensityUniform, shadowTintColorUniform, highlightTintColorUniform;
}

// The shadowTint and highlightTint colors specify what colors replace the dark and light areas of the image, respectively. The defaults for shadows are black, highlighs white.
@property(readwrite, nonatomic) GLfloat shadowTintIntensity;
@property(readwrite, nonatomic) GPUVector4 shadowTintColor;
@property(readwrite, nonatomic) GLfloat highlightTintIntensity;
@property(readwrite, nonatomic) GPUVector4 highlightTintColor;

- (void)setShadowTintColorRed:(GLfloat)redComponent green:(GLfloat)greenComponent blue:(GLfloat)blueComponent alpha:(GLfloat)alphaComponent;
- (void)setHighlightTintColorRed:(GLfloat)redComponent green:(GLfloat)greenComponent blue:(GLfloat)blueComponent alpha:(GLfloat)alphaComponent;

@end
136 changes: 136 additions & 0 deletions framework/Source/GPUImageHighlightShadowTintFilter.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
//
// GPUImageHighlightShadowTintFilter.m
//
// Created by github.com/r3mus on 8/14/15.
//
//

#import "GPUImageHighlightShadowTintFilter.h"

#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE
NSString *const kGPUHighlightShadowTintFragmentShaderString = SHADER_STRING
(
precision lowp float;

varying highp vec2 textureCoordinate;

uniform sampler2D inputImageTexture;
uniform lowp float shadowTintIntensity;
uniform lowp float highlightTintIntensity;
uniform highp vec4 shadowTintColor;
uniform highp vec4 highlightTintColor;

const mediump vec3 luminanceWeighting = vec3(0.2125, 0.7154, 0.0721);

void main()
{
lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);
highp float luminance = dot(textureColor.rgb, luminanceWeighting);

highp vec4 shadowResult = mix(textureColor, max(textureColor, vec4( mix(shadowTintColor.rgb, textureColor.rgb, luminance), textureColor.a)), shadowTintIntensity);
highp vec4 highlightResult = mix(textureColor, min(shadowResult, vec4( mix(shadowResult.rgb, highlightTintColor.rgb, luminance), textureColor.a)), highlightTintIntensity);

gl_FragColor = vec4( mix(shadowResult.rgb, highlightResult.rgb, luminance), textureColor.a);
}
);
#else
NSString *const kGPUHighlightShadowTintFragmentShaderString = SHADER_STRING
(
varying vec2 textureCoordinate;

uniform sampler2D inputImageTexture;
uniform float shadowTintIntensity;
uniform float highlightTintIntensity;
uniform vec3 shadowTintColor;
uniform vec3 highlightTintColor;

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

void main()
{
vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);
float luminance = dot(textureColor.rgb, luminanceWeighting);

vec4 shadowResult = mix(textureColor, max(textureColor, vec4( mix(shadowTintColor.rgb, textureColor.rgb, luminance), textureColor.a)), shadowTintIntensity);
vec4 highlightResult = mix(textureColor, min(shadowResult, vec4( mix(shadowResult.rgb, highlightTintColor.rgb, luminance), textureColor.a)), highlightTintIntensity);

gl_FragColor = vec4( mix(shadowResult.rgb, highlightResult.rgb, luminance), textureColor.a);
}
);
#endif


@implementation GPUImageHighlightShadowTintFilter

@synthesize shadowTintIntensity = _shadowTintIntensity;
@synthesize highlightTintIntensity = _highlightTintIntensity;
@synthesize shadowTintColor = _shadowTintColor;
@synthesize highlightTintColor = _highlightTintColor;

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

shadowTintIntensityUniform = [filterProgram uniformIndex:@"shadowTintIntensity"];
highlightTintIntensityUniform = [filterProgram uniformIndex:@"highlightTintIntensity"];
shadowTintColorUniform = [filterProgram uniformIndex:@"shadowTintColor"];
highlightTintColorUniform = [filterProgram uniformIndex:@"highlightTintColor"];

self.shadowTintIntensity = 0.0f;
self.highlightTintIntensity = 0.0f;
self.shadowTintColor = (GPUVector4){1.0f, 0.0f, 0.0f, 1.0f};
self.highlightTintColor = (GPUVector4){0.0f, 0.0f, 1.0f, 1.0f};

return self;
}


#pragma mark -
#pragma mark Accessors

- (void)setShadowTintIntensity:(GLfloat)newValue
{
_shadowTintIntensity = newValue;

[self setFloat:_shadowTintIntensity forUniform:shadowTintIntensityUniform program:filterProgram];
}

- (void)setHighlightTintIntensity:(GLfloat)newValue
{
_highlightTintIntensity = newValue;

[self setFloat:_highlightTintIntensity forUniform:highlightTintIntensityUniform program:filterProgram];
}

- (void)setShadowTintColor:(GPUVector4)newValue;
{
_shadowTintColor = newValue;

[self setShadowTintColorRed:_shadowTintColor.one green:_shadowTintColor.two blue:_shadowTintColor.three alpha:_shadowTintColor.four];
}

- (void)setHighlightTintColor:(GPUVector4)newValue;
{
_highlightTintColor = newValue;

[self setHighlightTintColorRed:_highlightTintColor.one green:_highlightTintColor.two blue:_highlightTintColor.three alpha:_highlightTintColor.four];
}

- (void)setShadowTintColorRed:(GLfloat)redComponent green:(GLfloat)greenComponent blue:(GLfloat)blueComponent alpha:(GLfloat)alphaComponent;
{
GPUVector4 shadowTintColor = {redComponent, greenComponent, blueComponent, alphaComponent};

[self setVec4:shadowTintColor forUniform:shadowTintColorUniform program:filterProgram];
}

- (void)setHighlightTintColorRed:(GLfloat)redComponent green:(GLfloat)greenComponent blue:(GLfloat)blueComponent alpha:(GLfloat)alphaComponent;
{
GPUVector4 highlightTintColor = {redComponent, greenComponent, blueComponent, alphaComponent};

[self setVec4:highlightTintColor forUniform:highlightTintColorUniform program:filterProgram];
}

@end
47 changes: 47 additions & 0 deletions framework/Source/GPUImageSkinToneFilter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//
// GPUImageSkinToneFilter.h
//
//
// Created by github.com/r3mus on 8/14/15.
//
//

#import "GPUImageTwoInputFilter.h"

typedef NS_ENUM(NSUInteger, GPUImageSkinToneUpperColor) {
GPUImageSkinToneUpperColorGreen,

};

extern NSString *const kGPUImageSkinToneFragmentShaderString;

@interface GPUImageSkinToneFilter : GPUImageFilter
{
GLint skinToneAdjustUniform;
GLint skinHueUniform;
GLint skinHueThresholdUniform;
GLint maxHueShiftUniform;
GLint maxSaturationShiftUniform;
GLint upperSkinToneColorUniform;
}

// The amount of effect to apply, between -1.0 (pink) and +1.0 (orange OR green). Default is 0.0.
@property (nonatomic, readwrite) CGFloat skinToneAdjust;

// The initial hue of skin to adjust. Default is 0.05 (a common skin red).
@property (nonatomic, readwrite) CGFloat skinHue;

// The bell curve "breadth" of the skin hue adjustment (i.e. how different from the original skinHue will the modifications effect).
// Default is 40.0
@property (nonatomic, readwrite) CGFloat skinHueThreshold;

// The maximum amount of hue shift allowed in the adjustments that affect hue (pink, green). Default = 0.25.
@property (nonatomic, readwrite) CGFloat maxHueShift;

// The maximum amount of saturation shift allowed in the adjustments that affect saturation (orange). Default = 0.4.
@property (nonatomic, readwrite) CGFloat maxSaturationShift;

// Defines whether the upper range (> 0.0) will change the skin tone to green (hue) or orange (saturation)
@property (nonatomic, readwrite) GPUImageSkinToneUpperColor upperSkinToneColor;

@end
Loading

0 comments on commit 0674173

Please sign in to comment.