Skip to content

Commit

Permalink
Allow matching existing alpha value in color generator filter
Browse files Browse the repository at this point in the history
  • Loading branch information
jjxtra committed Jun 13, 2013
1 parent 158bb79 commit 9039aa7
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 99 deletions.
1 change: 0 additions & 1 deletion framework/Source/GPUImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#import "GPUImagePixellateFilter.h"
#import "GPUImagePixellatePositionFilter.h"
#import "GPUImageSepiaFilter.h"
#import "GPUImageColorFilter.h"
#import "GPUImageColorInvertFilter.h"
#import "GPUImageSaturationFilter.h"
#import "GPUImageContrastFilter.h"
Expand Down
12 changes: 0 additions & 12 deletions framework/Source/GPUImageColorFilter.h

This file was deleted.

53 changes: 0 additions & 53 deletions framework/Source/GPUImageColorFilter.m

This file was deleted.

2 changes: 2 additions & 0 deletions framework/Source/GPUImageSolidColorGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
@interface GPUImageSolidColorGenerator : GPUImageFilter
{
GLint colorUniform;
GLint useExistingAlphaUniform;
}

// This color dictates what the output image will be filled with
@property(readwrite, nonatomic) GPUVector4 color;
@property(readwrite, nonatomic, assign) BOOL useExistingAlpha; // whether to use the alpha of the existing image or not, default is NO

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

Expand Down
65 changes: 32 additions & 33 deletions framework/Source/GPUImageSolidColorGenerator.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,43 @@
(
precision lowp float;

varying highp vec2 textureCoordinate;

varying highp vec2 textureCoordinate;
uniform sampler2D inputImageTexture;
uniform vec4 color;
uniform int useExistingAlpha;

void main()
{
gl_FragColor = color;
if (useExistingAlpha == 1)
{
lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);
gl_FragColor = vec4(color.rgb, textureColor.a);
}
else
{
gl_FragColor = color;
}
}
);
#else
NSString *const kGPUSolidColorFragmentShaderString = SHADER_STRING
(
varying vec2 textureCoordinate;

varying vec2 textureCoordinate;
uniform sampler2D inputImageTexture;
uniform vec4 color;

uniform int useExistingAlpha;

void main()
{
gl_FragColor = color;
if (useExistingAlpha == 1)
{
lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);
gl_FragColor = vec4(color.rgb, textureColor.a);
}
else
{
gl_FragColor = color;
}
}
);
#endif
Expand All @@ -42,8 +58,10 @@ - (id)init;
}

colorUniform = [filterProgram uniformIndex:@"color"];
useExistingAlphaUniform = [filterProgram uniformIndex:@"useExistingAlpha"];

self.color = (GPUVector4){0.0f, 0.0f, 0.5f, 1.0f};
self.useExistingAlpha = NO;

return self;
}
Expand All @@ -52,27 +70,6 @@ - (id)init;
#pragma mark -
#pragma mark Accessors

- (void)forceProcessingAtSize:(CGSize)frameSize;
{
[super forceProcessingAtSize:frameSize];

if (!CGSizeEqualToSize(inputTextureSize, CGSizeZero))
{
[self newFrameReadyAtTime:kCMTimeIndefinite atIndex:0];
}
}

- (void)addTarget:(id<GPUImageInput>)newTarget atTextureLocation:(NSInteger)textureLocation;
{
[super addTarget:newTarget atTextureLocation:textureLocation];

if (!CGSizeEqualToSize(inputTextureSize, CGSizeZero))
{
[newTarget setInputSize:inputTextureSize atIndex:textureLocation];
[newTarget newFrameReadyAtTime:kCMTimeIndefinite atIndex:textureLocation];
}
}

- (void)setColor:(GPUVector4)newValue;
{
[self setColorRed:newValue.one green:newValue.two blue:newValue.three alpha:newValue.four];
Expand All @@ -86,11 +83,13 @@ - (void)setColorRed:(GLfloat)redComponent green:(GLfloat)greenComponent blue:(GL
_color.four = alphaComponent;

[self setVec4:_color forUniform:colorUniform program:filterProgram];

if (!CGSizeEqualToSize(inputTextureSize, CGSizeZero))
{
[self newFrameReadyAtTime:kCMTimeIndefinite atIndex:0];
}
}

- (void)setUseExistingAlpha:(BOOL)useExistingAlpha;
{
_useExistingAlpha = useExistingAlpha;

[self setInteger:(useExistingAlpha ? 1 : 0) forUniform:useExistingAlphaUniform program:filterProgram];
}

@end

0 comments on commit 9039aa7

Please sign in to comment.