Skip to content

Commit

Permalink
the GPUImageToneCurveFilter now can take into account the rgbcomposit…
Browse files Browse the repository at this point in the history
…e channel together with the separate r, g, and b channels
  • Loading branch information
Andrew Farmer committed Aug 27, 2012
1 parent f67cbd9 commit 5baf9b5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
6 changes: 5 additions & 1 deletion framework/Source/GPUImageToneCurveFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@
@property(readwrite, nonatomic, copy) NSArray *redControlPoints;
@property(readwrite, nonatomic, copy) NSArray *greenControlPoints;
@property(readwrite, nonatomic, copy) NSArray *blueControlPoints;
@property(readwrite, nonatomic, copy) NSArray *rgbCompositeControlPoints;

// Initialization and teardown
- (id)initWithACV:(NSString*)curveFile;

// This lets you set all three red, green, and blue tone curves at once.
- (void)setRGBControlPoints:(NSArray *)points;
// NOTE: Deprecated this function because this effect can be accomplished
// using the rgbComposite channel rather then setting all 3 R, G, and B channels.
- (void)setRGBControlPoints:(NSArray *)points DEPRECATED_ATTRIBUTE;

- (void)setPointsWithACV:(NSString*)curveFile;

// Curve calculation
Expand Down
28 changes: 22 additions & 6 deletions framework/Source/GPUImageToneCurveFilter.m
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,14 @@ @interface GPUImageToneCurveFilter()
GLuint toneCurveTexture;
GLubyte *toneCurveByteArray;

NSArray *_redCurve, *_greenCurve, *_blueCurve;
NSArray *_redCurve, *_greenCurve, *_blueCurve, *_rgbCompositeCurve;
}

@end

@implementation GPUImageToneCurveFilter

@synthesize rgbCompositeControlPoints = _rgbCompositeControlPoints;
@synthesize redControlPoints = _redControlPoints;
@synthesize greenControlPoints = _greenControlPoints;
@synthesize blueControlPoints = _blueControlPoints;
Expand All @@ -151,7 +152,11 @@ - (id)init;

toneCurveTextureUniform = [filterProgram uniformIndex:@"toneCurveTexture"];

[self setRGBControlPoints:[NSArray arrayWithObjects:[NSValue valueWithCGPoint:CGPointMake(0.0, 0.0)], [NSValue valueWithCGPoint:CGPointMake(0.5, 0.5)], [NSValue valueWithCGPoint:CGPointMake(1.0, 1.0)], nil]];
NSArray *defaultCurve = [NSArray arrayWithObjects:[NSValue valueWithCGPoint:CGPointMake(0.0, 0.0)], [NSValue valueWithCGPoint:CGPointMake(0.5, 0.5)], [NSValue valueWithCGPoint:CGPointMake(1.0, 1.0)], nil];
[self setRgbCompositeControlPoints:defaultCurve];
[self setRedControlPoints:defaultCurve];
[self setGreenControlPoints:defaultCurve];
[self setBlueControlPoints:defaultCurve];

return self;
}
Expand All @@ -168,6 +173,7 @@ - (id)initWithACV:(NSString*)curveFile

GPUImageACVFile *curve = [[GPUImageACVFile alloc] initWithCurveFile:curveFile];

[self setRgbCompositeControlPoints:curve.rgbCompositeCurvePoints];
[self setRedControlPoints:curve.redCurvePoints];
[self setGreenControlPoints:curve.greenCurvePoints];
[self setBlueControlPoints:curve.blueCurvePoints];
Expand All @@ -181,6 +187,7 @@ - (void)setPointsWithACV:(NSString*)curveFile
{
GPUImageACVFile *curve = [[GPUImageACVFile alloc] initWithCurveFile:curveFile];

[self setRgbCompositeControlPoints:curve.rgbCompositeCurvePoints];
[self setRedControlPoints:curve.redCurvePoints];
[self setGreenControlPoints:curve.greenCurvePoints];
[self setBlueControlPoints:curve.blueCurvePoints];
Expand Down Expand Up @@ -401,14 +408,14 @@ - (void)updateToneCurveTexture;
glBindTexture(GL_TEXTURE_2D, toneCurveTexture);
}

if ( ([_redCurve count] >= 256) && ([_greenCurve count] >= 256) && ([_blueCurve count] >= 256) )
if ( ([_redCurve count] >= 256) && ([_greenCurve count] >= 256) && ([_blueCurve count] >= 256) && ([_rgbCompositeCurve count] >= 256))
{
for (unsigned int currentCurveIndex = 0; currentCurveIndex < 256; currentCurveIndex++)
{
// BGRA for upload to texture
toneCurveByteArray[currentCurveIndex * 4] = currentCurveIndex + [[_blueCurve objectAtIndex:currentCurveIndex] floatValue];
toneCurveByteArray[currentCurveIndex * 4 + 1] = currentCurveIndex + [[_greenCurve objectAtIndex:currentCurveIndex] floatValue];
toneCurveByteArray[currentCurveIndex * 4 + 2] = currentCurveIndex + [[_redCurve objectAtIndex:currentCurveIndex] floatValue];
toneCurveByteArray[currentCurveIndex * 4] = fmax(currentCurveIndex + [[_blueCurve objectAtIndex:currentCurveIndex] floatValue] + [[_rgbCompositeCurve objectAtIndex:currentCurveIndex] floatValue], 0);
toneCurveByteArray[currentCurveIndex * 4 + 1] = fmax(currentCurveIndex + [[_greenCurve objectAtIndex:currentCurveIndex] floatValue] + [[_rgbCompositeCurve objectAtIndex:currentCurveIndex] floatValue], 0);
toneCurveByteArray[currentCurveIndex * 4 + 2] = fmax(currentCurveIndex + [[_redCurve objectAtIndex:currentCurveIndex] floatValue] + [[_rgbCompositeCurve objectAtIndex:currentCurveIndex] floatValue], 0);
toneCurveByteArray[currentCurveIndex * 4 + 3] = 255;
}

Expand Down Expand Up @@ -465,6 +472,15 @@ - (void)setRGBControlPoints:(NSArray *)points
}


- (void)setRgbCompositeControlPoints:(NSArray *)newValue
{
_rgbCompositeControlPoints = [newValue copy];
_rgbCompositeCurve = [self getPreparedSplineCurve:_rgbCompositeControlPoints];

[self updateToneCurveTexture];
}


- (void)setRedControlPoints:(NSArray *)newValue;
{
_redControlPoints = [newValue copy];
Expand Down

0 comments on commit 5baf9b5

Please sign in to comment.