Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Completed the average color filter and created a solid color fill gen…
…erator.
- Loading branch information
1 parent
7ca3b66
commit f73c5d8
Showing
8 changed files
with
173 additions
and
42 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
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,17 @@ | ||
#import "GPUImageFilter.h" | ||
|
||
// This outputs an image with a constant color. You need to use -forceProcessingAtSize: in order to set the output image | ||
// dimensions, or this won't work correctly | ||
|
||
|
||
@interface GPUImageSolidColorGenerator : GPUImageFilter | ||
{ | ||
GLint colorUniform; | ||
} | ||
|
||
// This color dictates what the output image will be filled with | ||
@property(readwrite, nonatomic) GPUVector4 color; | ||
|
||
- (void)setColorRed:(GLfloat)redComponent green:(GLfloat)greenComponent blue:(GLfloat)blueComponent alpha:(GLfloat)alphaComponent; | ||
|
||
@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,81 @@ | ||
#import "GPUImageSolidColorGenerator.h" | ||
|
||
NSString *const kGPUSolidColorFragmentShaderString = SHADER_STRING | ||
( | ||
precision lowp float; | ||
|
||
varying highp vec2 textureCoordinate; | ||
|
||
uniform sampler2D inputImageTexture; | ||
uniform vec4 color; | ||
|
||
void main() | ||
{ | ||
gl_FragColor = color; | ||
} | ||
); | ||
|
||
@implementation GPUImageSolidColorGenerator | ||
|
||
@synthesize color = _color; | ||
|
||
- (id)init; | ||
{ | ||
if (!(self = [super initWithFragmentShaderFromString:kGPUSolidColorFragmentShaderString])) | ||
{ | ||
return nil; | ||
} | ||
|
||
colorUniform = [filterProgram uniformIndex:@"color"]; | ||
|
||
self.color = (GPUVector4){0.0f, 0.0f, 0.5f, 1.0f}; | ||
|
||
return self; | ||
} | ||
|
||
|
||
#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:_color.one green:_color.two blue:_color.three alpha:_color.four]; | ||
} | ||
|
||
- (void)setColorRed:(GLfloat)redComponent green:(GLfloat)greenComponent blue:(GLfloat)blueComponent alpha:(GLfloat)alphaComponent; | ||
{ | ||
_color.one = redComponent; | ||
_color.two = greenComponent; | ||
_color.three = blueComponent; | ||
_color.four = alphaComponent; | ||
|
||
[self setVec4:_color forUniform:colorUniform program:filterProgram]; | ||
|
||
if (!CGSizeEqualToSize(inputTextureSize, CGSizeZero)) | ||
{ | ||
[self newFrameReadyAtTime:kCMTimeIndefinite atIndex:0]; | ||
} | ||
} | ||
|
||
@end |