Skip to content

Commit 8c351ac

Browse files
committed
Added a false color filter. Incorporated the shadows and highlights filter into the showcase.
1 parent 6d2b072 commit 8c351ac

12 files changed

+177
-45
lines changed

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ Documentation is generated from header comments using appledoc. To build the doc
7878
- *greenControlPoints*:
7979
- *blueControlPoints*: The tone curve takes in a series of control points that define the spline curve for each color component. These are stored as NSValue-wrapped CGPoints in an NSArray, with normalized X and Y coordinates from 0 - 1. The defaults are (0,0), (0.5,0.5), (1,1).
8080

81+
- **GPUImageHighlightShadowFilter**: Adjusts the shadows and highlights of an image
82+
- *shadows*: Increase to lighten shadows, from 0.0 to 1.0, with 0.0 as the default.
83+
- *highlights*: Decrease to darken highlights, from 0.0 to 1.0, with 1.0 as the default.
84+
8185
- **GPUImageColorInvertFilter**: Inverts the colors of an image
8286

8387
- **GPUImageGrayscaleFilter**: Converts an image to grayscale (a slightly faster implementation of the saturation filter, without the ability to vary the color contribution)
@@ -86,6 +90,10 @@ Documentation is generated from header comments using appledoc. To build the doc
8690
- *intensity*: The degree to which the specific color replaces the normal image color (0.0 - 1.0, with 1.0 as the default)
8791
- *color*: The color to use as the basis for the effect, with (0.6, 0.45, 0.3, 1.0) as the default.
8892

93+
- **GPUImageFalseColorFilter**: Uses the luminance of the image to mix between two user-specified colors
94+
- *firstColor*: The first and second colors specify what colors replace the dark and light areas of the image, respectively. The defaults are (0.0, 0.0, 0.5) amd (1.0, 0.0, 0.0).
95+
- *secondColor*:
96+
8997
- **GPUImageSepiaFilter**: Simple sepia tone filter
9098
- *intensity*: The degree to which the sepia tone replaces the normal image color (0.0 - 1.0, with 1.0 as the default)
9199

examples/FilterShowcase/FilterShowcase/ShowcaseFilterListController.m

+2
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,12 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
6767
case GPUIMAGE_EXPOSURE: cell.textLabel.text = @"Exposure"; break;
6868
case GPUIMAGE_RGB: cell.textLabel.text = @"RGB"; break;
6969
case GPUIMAGE_MONOCHROME: cell.textLabel.text = @"Monochrome"; break;
70+
case GPUIMAGE_FALSECOLOR: cell.textLabel.text = @"False color"; break;
7071
case GPUIMAGE_SHARPEN: cell.textLabel.text = @"Sharpen"; break;
7172
case GPUIMAGE_UNSHARPMASK: cell.textLabel.text = @"Unsharp mask"; break;
7273
case GPUIMAGE_GAMMA: cell.textLabel.text = @"Gamma"; break;
7374
case GPUIMAGE_TONECURVE: cell.textLabel.text = @"Tone curve"; break;
75+
case GPUIMAGE_HIGHLIGHTSHADOW: cell.textLabel.text = @"Highlights and shadows"; break;
7476
case GPUIMAGE_HAZE: cell.textLabel.text = @"Haze"; break;
7577
case GPUIMAGE_HISTOGRAM: cell.textLabel.text = @"Histogram"; break;
7678
case GPUIMAGE_THRESHOLD: cell.textLabel.text = @"Threshold"; break;

examples/FilterShowcase/FilterShowcase/ShowcaseFilterViewController.h

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ typedef enum {
88
GPUIMAGE_EXPOSURE,
99
GPUIMAGE_RGB,
1010
GPUIMAGE_MONOCHROME,
11+
GPUIMAGE_FALSECOLOR,
1112
GPUIMAGE_SHARPEN,
1213
GPUIMAGE_UNSHARPMASK,
1314
GPUIMAGE_TRANSFORM,
@@ -16,6 +17,7 @@ typedef enum {
1617
GPUIMAGE_MASK,
1718
GPUIMAGE_GAMMA,
1819
GPUIMAGE_TONECURVE,
20+
GPUIMAGE_HIGHLIGHTSHADOW,
1921
GPUIMAGE_HAZE,
2022
GPUIMAGE_SEPIA,
2123
GPUIMAGE_COLORINVERT,

examples/FilterShowcase/FilterShowcase/ShowcaseFilterViewController.m

+21-2
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,13 @@ - (void)setupFilter;
128128
filter = [[GPUImageMonochromeFilter alloc] init];
129129
[(GPUImageMonochromeFilter *)filter setColor:(GPUVector4){0.0f, 0.0f, 1.0f, 1.f}];
130130
}; break;
131+
case GPUIMAGE_FALSECOLOR:
132+
{
133+
self.title = @"False Color";
134+
self.filterSettingsSlider.hidden = YES;
135+
136+
filter = [[GPUImageFalseColorFilter alloc] init];
137+
}; break;
131138
case GPUIMAGE_SATURATION:
132139
{
133140
self.title = @"Saturation";
@@ -229,6 +236,17 @@ - (void)setupFilter;
229236

230237
filter = [[GPUImageToneCurveFilter alloc] init];
231238
[(GPUImageToneCurveFilter *)filter setBlueControlPoints:[NSArray arrayWithObjects:[NSValue valueWithCGPoint:CGPointMake(0.0, 0.0)], [NSValue valueWithCGPoint:CGPointMake(0.5, 0.5)], [NSValue valueWithCGPoint:CGPointMake(1.0, 0.75)], nil]];
239+
}; break;
240+
case GPUIMAGE_HIGHLIGHTSHADOW:
241+
{
242+
self.title = @"Highlights and Shadows";
243+
self.filterSettingsSlider.hidden = NO;
244+
245+
[self.filterSettingsSlider setValue:1.0];
246+
[self.filterSettingsSlider setMinimumValue:0.0];
247+
[self.filterSettingsSlider setMaximumValue:1.0];
248+
249+
filter = [[GPUImageHighlightShadowFilter alloc] init];
232250
}; break;
233251
case GPUIMAGE_HAZE:
234252
{
@@ -1074,8 +1092,8 @@ - (IBAction)updateFilterFromSlider:(id)sender;
10741092
case GPUIMAGE_GAMMA: [(GPUImageGammaFilter *)filter setGamma:[(UISlider *)sender value]]; break;
10751093
case GPUIMAGE_CROSSHATCH: [(GPUImageCrosshatchFilter *)filter setCrossHatchSpacing:[(UISlider *)sender value]]; break;
10761094
case GPUIMAGE_POSTERIZE: [(GPUImagePosterizeFilter *)filter setColorLevels:round([(UISlider*)sender value])]; break;
1077-
case GPUIMAGE_HAZE: [(GPUImageHazeFilter *)filter setDistance:[(UISlider *)sender value]]; break;
1078-
case GPUIMAGE_THRESHOLD: [(GPUImageLuminanceThresholdFilter *)filter setThreshold:[(UISlider *)sender value]]; break;
1095+
case GPUIMAGE_HAZE: [(GPUImageHazeFilter *)filter setDistance:[(UISlider *)sender value]]; break;
1096+
case GPUIMAGE_THRESHOLD: [(GPUImageLuminanceThresholdFilter *)filter setThreshold:[(UISlider *)sender value]]; break;
10791097
case GPUIMAGE_ADAPTIVETHRESHOLD: [(GPUImageAdaptiveThresholdFilter *)filter setBlurSize:[(UISlider*)sender value]]; break;
10801098
case GPUIMAGE_DISSOLVE: [(GPUImageDissolveBlendFilter *)filter setMix:[(UISlider *)sender value]]; break;
10811099
case GPUIMAGE_CHROMAKEY: [(GPUImageChromaKeyBlendFilter *)filter setThresholdSensitivity:[(UISlider *)sender value]]; break;
@@ -1093,6 +1111,7 @@ - (IBAction)updateFilterFromSlider:(id)sender;
10931111
case GPUIMAGE_BULGE: [(GPUImageBulgeDistortionFilter *)filter setScale:[(UISlider *)sender value]]; break;
10941112
case GPUIMAGE_SPHEREREFRACTION: [(GPUImageSphereRefractionFilter *)filter setRadius:[(UISlider *)sender value]]; break;
10951113
case GPUIMAGE_TONECURVE: [(GPUImageToneCurveFilter *)filter setBlueControlPoints:[NSArray arrayWithObjects:[NSValue valueWithCGPoint:CGPointMake(0.0, 0.0)], [NSValue valueWithCGPoint:CGPointMake(0.5, [(UISlider *)sender value])], [NSValue valueWithCGPoint:CGPointMake(1.0, 0.75)], nil]]; break;
1114+
case GPUIMAGE_HIGHLIGHTSHADOW: [(GPUImageHighlightShadowFilter *)filter setHighlights:[(UISlider *)sender value]]; break;
10961115
case GPUIMAGE_PINCH: [(GPUImagePinchDistortionFilter *)filter setScale:[(UISlider *)sender value]]; break;
10971116
case GPUIMAGE_PERLINNOISE: [(GPUImagePerlinNoiseFilter *)filter setScale:[(UISlider *)sender value]]; break;
10981117
case GPUIMAGE_MOSAIC: [(GPUImageMosaicFilter *)filter setDisplayTileSize:CGSizeMake([(UISlider *)sender value], [(UISlider *)sender value])]; break;

framework/GPUImage.xcodeproj/project.pbxproj

+20-4
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,10 @@
212212
BCC1E66D152368130006EFA5 /* GPUImageCrosshatchFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = BCC1E669152368130006EFA5 /* GPUImageCrosshatchFilter.h */; };
213213
BCC1E66E152368130006EFA5 /* GPUImageCrosshatchFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = BCC1E66A152368130006EFA5 /* GPUImageCrosshatchFilter.m */; };
214214
BCC1E67C152368840006EFA5 /* GPUImageCGAColorspaceFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = BCC1E67B152368840006EFA5 /* GPUImageCGAColorspaceFilter.m */; };
215+
BCC46E5E15B9EFE8005519B9 /* GPUImageHighlightShadowFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = BCC46E5C15B9EFE8005519B9 /* GPUImageHighlightShadowFilter.h */; };
216+
BCC46E5F15B9EFE8005519B9 /* GPUImageHighlightShadowFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = BCC46E5D15B9EFE8005519B9 /* GPUImageHighlightShadowFilter.m */; };
217+
BCC46E6315BA095F005519B9 /* GPUImageFalseColorFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = BCC46E6115BA095F005519B9 /* GPUImageFalseColorFilter.h */; };
218+
BCC46E6415BA095F005519B9 /* GPUImageFalseColorFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = BCC46E6215BA095F005519B9 /* GPUImageFalseColorFilter.m */; };
215219
BCC93A0F1501D1BF00958B26 /* GPUImageFastBlurFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = BCC93A0D1501D1BF00958B26 /* GPUImageFastBlurFilter.h */; };
216220
BCC93A101501D1BF00958B26 /* GPUImageFastBlurFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = BCC93A0E1501D1BF00958B26 /* GPUImageFastBlurFilter.m */; };
217221
BCC93A1E1501E42F00958B26 /* GPUImageTwoPassFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = BCC93A1C1501E42E00958B26 /* GPUImageTwoPassFilter.h */; };
@@ -466,6 +470,10 @@
466470
BCC1E669152368130006EFA5 /* GPUImageCrosshatchFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GPUImageCrosshatchFilter.h; path = Source/GPUImageCrosshatchFilter.h; sourceTree = SOURCE_ROOT; };
467471
BCC1E66A152368130006EFA5 /* GPUImageCrosshatchFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = GPUImageCrosshatchFilter.m; path = Source/GPUImageCrosshatchFilter.m; sourceTree = SOURCE_ROOT; };
468472
BCC1E67B152368840006EFA5 /* GPUImageCGAColorspaceFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = GPUImageCGAColorspaceFilter.m; path = Source/GPUImageCGAColorspaceFilter.m; sourceTree = SOURCE_ROOT; };
473+
BCC46E5C15B9EFE8005519B9 /* GPUImageHighlightShadowFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GPUImageHighlightShadowFilter.h; path = Source/GPUImageHighlightShadowFilter.h; sourceTree = SOURCE_ROOT; };
474+
BCC46E5D15B9EFE8005519B9 /* GPUImageHighlightShadowFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = GPUImageHighlightShadowFilter.m; path = Source/GPUImageHighlightShadowFilter.m; sourceTree = SOURCE_ROOT; };
475+
BCC46E6115BA095F005519B9 /* GPUImageFalseColorFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GPUImageFalseColorFilter.h; path = Source/GPUImageFalseColorFilter.h; sourceTree = SOURCE_ROOT; };
476+
BCC46E6215BA095F005519B9 /* GPUImageFalseColorFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = GPUImageFalseColorFilter.m; path = Source/GPUImageFalseColorFilter.m; sourceTree = SOURCE_ROOT; };
469477
BCC93A0D1501D1BF00958B26 /* GPUImageFastBlurFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GPUImageFastBlurFilter.h; path = Source/GPUImageFastBlurFilter.h; sourceTree = SOURCE_ROOT; };
470478
BCC93A0E1501D1BF00958B26 /* GPUImageFastBlurFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = GPUImageFastBlurFilter.m; path = Source/GPUImageFastBlurFilter.m; sourceTree = SOURCE_ROOT; };
471479
BCC93A1C1501E42E00958B26 /* GPUImageTwoPassFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GPUImageTwoPassFilter.h; path = Source/GPUImageTwoPassFilter.h; sourceTree = SOURCE_ROOT; };
@@ -553,10 +561,6 @@
553561
BC1B715D14F4AFFF00ACA2AB /* Color processing */ = {
554562
isa = PBXGroup;
555563
children = (
556-
BCBCE9971595021B00E0ED33 /* GPUImageMonochromeFilter.h */,
557-
BCBCE9981595021B00E0ED33 /* GPUImageMonochromeFilter.m */,
558-
BEBE83B3155C092A00EEF8C3 /* GPUImageRGBFilter.h */,
559-
BEBE83B4155C092A00EEF8C3 /* GPUImageRGBFilter.m */,
560564
BC982B7714F098CC0001FF6F /* GPUImageBrightnessFilter.h */,
561565
BC982B7814F098CC0001FF6F /* GPUImageBrightnessFilter.m */,
562566
BCB6B833150400030041703B /* GPUImageExposureFilter.h */,
@@ -569,6 +573,14 @@
569573
BC982B7D14F09F980001FF6F /* GPUImageGammaFilter.m */,
570574
B81521A014F1BA6A00F105F8 /* GPUImageColorMatrixFilter.h */,
571575
B81521A114F1BA6A00F105F8 /* GPUImageColorMatrixFilter.m */,
576+
BEBE83B3155C092A00EEF8C3 /* GPUImageRGBFilter.h */,
577+
BEBE83B4155C092A00EEF8C3 /* GPUImageRGBFilter.m */,
578+
BCC46E5C15B9EFE8005519B9 /* GPUImageHighlightShadowFilter.h */,
579+
BCC46E5D15B9EFE8005519B9 /* GPUImageHighlightShadowFilter.m */,
580+
BCBCE9971595021B00E0ED33 /* GPUImageMonochromeFilter.h */,
581+
BCBCE9981595021B00E0ED33 /* GPUImageMonochromeFilter.m */,
582+
BCC46E6115BA095F005519B9 /* GPUImageFalseColorFilter.h */,
583+
BCC46E6215BA095F005519B9 /* GPUImageFalseColorFilter.m */,
572584
6D13DBE4151AA804000B23BA /* GPUImageHazeFilter.h */,
573585
6D13DBE5151AA804000B23BA /* GPUImageHazeFilter.m */,
574586
BCB5E7C014E4B6D400701302 /* GPUImageSepiaFilter.h */,
@@ -1019,6 +1031,8 @@
10191031
BCBCE9991595021B00E0ED33 /* GPUImageMonochromeFilter.h in Headers */,
10201032
BCBCE9D5159944AC00E0ED33 /* GPUImageBuffer.h in Headers */,
10211033
BCF6B41115A7849F00FC6F58 /* GPUImageOpacityFilter.h in Headers */,
1034+
BCC46E5E15B9EFE8005519B9 /* GPUImageHighlightShadowFilter.h in Headers */,
1035+
BCC46E6315BA095F005519B9 /* GPUImageFalseColorFilter.h in Headers */,
10221036
);
10231037
runOnlyForDeploymentPostprocessing = 0;
10241038
};
@@ -1246,6 +1260,8 @@
12461260
BCBCE99A1595021B00E0ED33 /* GPUImageMonochromeFilter.m in Sources */,
12471261
BCBCE9D6159944AC00E0ED33 /* GPUImageBuffer.m in Sources */,
12481262
BCF6B41215A7849F00FC6F58 /* GPUImageOpacityFilter.m in Sources */,
1263+
BCC46E5F15B9EFE8005519B9 /* GPUImageHighlightShadowFilter.m in Sources */,
1264+
BCC46E6415BA095F005519B9 /* GPUImageFalseColorFilter.m in Sources */,
12491265
);
12501266
runOnlyForDeploymentPostprocessing = 0;
12511267
};

framework/Source/GPUImage.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,6 @@
104104
#import "GPUImageColorPackingFilter.h"
105105
#import "GPUImageSphereRefractionFilter.h"
106106
#import "GPUImageMonochromeFilter.h"
107-
#import "GPUImageOpacityFilter.h"
107+
#import "GPUImageOpacityFilter.h"
108+
#import "GPUImageHighlightShadowFilter.h"
109+
#import "GPUImageFalseColorFilter.h"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#import "GPUImageFilter.h"
2+
3+
@interface GPUImageFalseColorFilter : GPUImageFilter
4+
{
5+
GLint firstColorUniform, secondColorUniform;
6+
}
7+
8+
// The first and second colors specify what colors replace the dark and light areas of the image, respectively. The defaults are (0.0, 0.0, 0.5) amd (1.0, 0.0, 0.0).
9+
@property(readwrite, nonatomic) GPUVector4 firstColor;
10+
@property(readwrite, nonatomic) GPUVector4 secondColor;
11+
12+
- (void)setFirstColorRed:(GLfloat)redComponent green:(GLfloat)greenComponent blue:(GLfloat)blueComponent;
13+
- (void)setSecondColorRed:(GLfloat)redComponent green:(GLfloat)greenComponent blue:(GLfloat)blueComponent;
14+
15+
@end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#import "GPUImageFalseColorFilter.h"
2+
3+
NSString *const kGPUFalseColorFragmentShaderString = SHADER_STRING
4+
(
5+
precision lowp float;
6+
7+
varying highp vec2 textureCoordinate;
8+
9+
uniform sampler2D inputImageTexture;
10+
uniform float intensity;
11+
uniform vec3 firstColor;
12+
uniform vec3 secondColor;
13+
14+
const mediump vec3 luminanceWeighting = vec3(0.2125, 0.7154, 0.0721);
15+
16+
void main()
17+
{
18+
lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);
19+
float luminance = dot(textureColor.rgb, luminanceWeighting);
20+
21+
gl_FragColor = vec4( mix(firstColor.rgb, secondColor.rgb, luminance), textureColor.a);
22+
}
23+
);
24+
25+
@implementation GPUImageFalseColorFilter
26+
27+
@synthesize secondColor = _secondColor;
28+
@synthesize firstColor = _firstColor;
29+
30+
- (id)init;
31+
{
32+
if (!(self = [super initWithFragmentShaderFromString:kGPUFalseColorFragmentShaderString]))
33+
{
34+
return nil;
35+
}
36+
37+
firstColorUniform = [filterProgram uniformIndex:@"firstColor"];
38+
secondColorUniform = [filterProgram uniformIndex:@"secondColor"];
39+
40+
self.firstColor = (GPUVector4){0.0f, 0.0f, 0.5f, 1.0f};
41+
self.secondColor = (GPUVector4){1.0f, 0.0f, 0.0f, 1.0f};
42+
43+
return self;
44+
}
45+
46+
47+
#pragma mark -
48+
#pragma mark Accessors
49+
50+
- (void)setFirstColor:(GPUVector4)newValue;
51+
{
52+
_firstColor = newValue;
53+
54+
[self setFirstColorRed:_firstColor.one green:_firstColor.two blue:_firstColor.three];
55+
}
56+
57+
- (void)setSecondColor:(GPUVector4)newValue;
58+
{
59+
_secondColor = newValue;
60+
61+
[self setSecondColorRed:_secondColor.one green:_secondColor.two blue:_secondColor.three];
62+
}
63+
64+
- (void)setFirstColorRed:(GLfloat)redComponent green:(GLfloat)greenComponent blue:(GLfloat)blueComponent;
65+
{
66+
GLfloat filterColor[3];
67+
filterColor[0] = redComponent;
68+
filterColor[1] = greenComponent;
69+
filterColor[2] = blueComponent;
70+
71+
[GPUImageOpenGLESContext useImageProcessingContext];
72+
[filterProgram use];
73+
glUniform3fv(firstColorUniform, 1, filterColor);
74+
}
75+
76+
- (void)setSecondColorRed:(GLfloat)redComponent green:(GLfloat)greenComponent blue:(GLfloat)blueComponent;
77+
{
78+
GLfloat filterColor[3];
79+
filterColor[0] = redComponent;
80+
filterColor[1] = greenComponent;
81+
filterColor[2] = blueComponent;
82+
83+
[GPUImageOpenGLESContext useImageProcessingContext];
84+
[filterProgram use];
85+
glUniform3fv(secondColorUniform, 1, filterColor);
86+
}
87+
88+
@end

framework/Source/GPUImageHighlightShadowFilter.h

-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
11
#import "GPUImageFilter.h"
22

3-
/**
4-
* This is an attempt to replicate CIHighlightShadowAdjust
5-
*
6-
*
7-
* @author Alaric Cole
8-
* @creationDate 07/10/12
9-
*
10-
*/
11-
12-
133
@interface GPUImageHighlightShadowFilter : GPUImageFilter
144
{
155
GLint shadowsUniform, highlightsUniform;

framework/Source/GPUImageMonochromeFilter.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
@property(readwrite, nonatomic) CGFloat intensity;
99
@property(readwrite, nonatomic) GPUVector4 color;
10-
//@property(readwrite, nonatomic) CIColor* color;
10+
1111
- (void)setColorRed:(GLfloat)redComponent green:(GLfloat)greenComponent blue:(GLfloat)blueComponent;
1212

1313
@end

framework/Source/GPUImageMonochromeFilter.m

+16-27
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,35 @@
22

33
NSString *const kGPUMonochromeFragmentShaderString = SHADER_STRING
44
(
5-
precision lowp float;
6-
7-
varying highp vec2 textureCoordinate;
5+
precision lowp float;
86

9-
uniform sampler2D inputImageTexture;
10-
uniform float intensity;
11-
uniform vec3 filterColor;
12-
13-
const mediump vec3 luminanceWeighting = vec3(0.2125, 0.7154, 0.0721);
7+
varying highp vec2 textureCoordinate;
148

15-
9+
uniform sampler2D inputImageTexture;
10+
uniform float intensity;
11+
uniform vec3 filterColor;
1612

17-
void main()
18-
{
19-
20-
13+
const mediump vec3 luminanceWeighting = vec3(0.2125, 0.7154, 0.0721);
14+
15+
void main()
16+
{
2117
//desat, then apply overlay blend
2218
lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);
2319
float luminance = dot(textureColor.rgb, luminanceWeighting);
2420

2521
lowp vec4 desat = vec4(vec3(luminance), 1.0);
2622

27-
28-
2923
//overlay
3024
lowp vec4 outputColor = vec4(
31-
(desat.r < 0.5 ? (2.0 * desat.r * filterColor.r) : (1.0 - 2.0 * (1.0 - desat.r) * (1.0 - filterColor.r))),
32-
(desat.g < 0.5 ? (2.0 * desat.g * filterColor.g) : (1.0 - 2.0 * (1.0 - desat.g) * (1.0 - filterColor.g))),
33-
(desat.b < 0.5 ? (2.0 * desat.b * filterColor.b) : (1.0 - 2.0 * (1.0 - desat.b) * (1.0 - filterColor.b))),
34-
1.0
35-
);
25+
(desat.r < 0.5 ? (2.0 * desat.r * filterColor.r) : (1.0 - 2.0 * (1.0 - desat.r) * (1.0 - filterColor.r))),
26+
(desat.g < 0.5 ? (2.0 * desat.g * filterColor.g) : (1.0 - 2.0 * (1.0 - desat.g) * (1.0 - filterColor.g))),
27+
(desat.b < 0.5 ? (2.0 * desat.b * filterColor.b) : (1.0 - 2.0 * (1.0 - desat.b) * (1.0 - filterColor.b))),
28+
1.0
29+
);
3630

3731
//which is better, or are they equal?
38-
gl_FragColor = vec4( mix(textureColor.rgb, outputColor.rgb, intensity), 1.0 );
39-
//gl_FragColor = (intensity * outputColor) + ((1.0 - intensity) * textureColor);
40-
41-
42-
43-
44-
}
32+
gl_FragColor = vec4( mix(textureColor.rgb, outputColor.rgb, intensity), textureColor.a);
33+
}
4534
);
4635

4736
@implementation GPUImageMonochromeFilter

framework/Source/GPUImageRGBFilter.h

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
GLint blueUniform;
88
}
99

10+
// Normalized values by which each color channel is multiplied. The range is from 0.0 up, with 1.0 as the default.
1011
@property (readwrite, nonatomic) CGFloat red;
1112
@property (readwrite, nonatomic) CGFloat green;
1213
@property (readwrite, nonatomic) CGFloat blue;

0 commit comments

Comments
 (0)