forked from BradLarson/GPUImage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
54d69e0
commit 16afe14
Showing
8 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#import "GPUImageFilter.h" | ||
|
||
/** Pixels with a luminance above the threshold will invert their color | ||
*/ | ||
@interface GPUImageSolarizeFilter : GPUImageFilter | ||
{ | ||
GLint thresholdUniform; | ||
} | ||
|
||
/** Anything above this luminance will be inverted, and anything below normal. Ranges from 0.0 to 1.0, with 0.5 as the default | ||
*/ | ||
@property(readwrite, nonatomic) CGFloat threshold; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#import "GPUImageSolarizeFilter.h" | ||
|
||
#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE | ||
NSString *const kGPUImageSolarizeFragmentShaderString = SHADER_STRING | ||
( | ||
varying highp vec2 textureCoordinate; | ||
|
||
uniform sampler2D inputImageTexture; | ||
uniform highp float threshold; | ||
|
||
const highp vec3 W = vec3(0.2125, 0.7154, 0.0721); | ||
|
||
void main() | ||
{ | ||
highp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); | ||
highp float luminance = dot(textureColor.rgb, W); | ||
highp float thresholdResult = step(luminance, threshold); | ||
highp vec3 finalColor = abs(thresholdResult - textureColor.rgb); | ||
|
||
gl_FragColor = vec4(finalColor, textureColor.w); | ||
} | ||
); | ||
#else | ||
NSString *const kGPUImageSolarizeFragmentShaderString = SHADER_STRING | ||
( | ||
varying vec2 textureCoordinate; | ||
|
||
uniform sampler2D inputImageTexture; | ||
uniform float threshold; | ||
|
||
const vec3 W = vec3(0.2125, 0.7154, 0.0721); | ||
|
||
void main() | ||
{ | ||
vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); | ||
float luminance = dot(textureColor.rgb, W); | ||
float thresholdResult = step(luminance, threshold); | ||
vec3 finalColor = abs(thresholdResult - textureColor.rgb); | ||
|
||
gl_FragColor = vec4(vec3(finalColor), textureColor.w); | ||
} | ||
); | ||
#endif | ||
|
||
@implementation GPUImageSolarizeFilter; | ||
|
||
@synthesize threshold = _threshold; | ||
|
||
#pragma mark - | ||
#pragma mark Initialization | ||
|
||
- (id)init; | ||
{ | ||
if (!(self = [super initWithFragmentShaderFromString:kGPUImageSolarizeFragmentShaderString])) | ||
{ | ||
return nil; | ||
} | ||
|
||
thresholdUniform = [filterProgram uniformIndex:@"threshold"]; | ||
self.threshold = 0.5; | ||
|
||
return self; | ||
} | ||
|
||
#pragma mark - | ||
#pragma mark Accessors | ||
|
||
- (void)setThreshold:(CGFloat)newValue; | ||
{ | ||
_threshold = newValue; | ||
|
||
[self setFloat:_threshold forUniform:thresholdUniform program:filterProgram]; | ||
} | ||
|
||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters