BradLarson / GPUImage

An open source iOS framework for GPU-based image and video processing
http://www.sunsetlakesoftware.com/2012/02/12/introducing-gpuimage-framework
BSD 3-Clause "New" or "Revised" License
20.25k stars 4.61k forks source link

GPUImageToneCurveFilter ignores RGB combined color channel #417

Open andrewagain opened 12 years ago

andrewagain commented 12 years ago

BACKGROUND: In the Photoshop curves tool there are 4 channels: Red, Green, Blue and a composite "RGB" channel. All 4 channels are combined to affect the output of the image.

PROBLEM: The GPUImageToneCurveFilter class internally maintains only 3 channels: Red, Green, and Blue. The initWithACV and setPointsWithACV methods ignore the composite RGB channel that is present in the ACV file.

Some things to note:

I have fixed this issue so that when using all 4 channels the resulting images look very similar to the resulting images from Photoshop. Should I send a pull request?

BradLarson commented 12 years ago

Sure, go right ahead. I didn't write the tone curve filter or the ACV input, so I rely on others to verify their functionality.

iamcam commented 12 years ago

@ahfarmer That would be a fantastic addition. Thanks for tackling it.

andrewagain commented 12 years ago

Cool! I made a pull request: https://github.com/BradLarson/GPUImage/pull/428

s5 commented 12 years ago

Having some trouble with ACV curves, and I think it might be related? I'm getting strange results that don't look like what I get in Photoshop. Perhaps these pictures will help.

Here's the original photo: https://www.dropbox.com/s/otsdr4pfglnw4i1/1%20original.png

Here's what I get in Photoshop, which is more or less what I expect to get back: https://www.dropbox.com/s/t2qzphtjvujh2v3/2%20correct-from-photoshop.png

But here's what I get back after using GPUImageToneCurveFilter: https://www.dropbox.com/s/luu2hc2u59uvllq/3%20wrong-via-GPUImageToneCurveFilter.jpg

Apart from all the weird artifacts, it's close but the overall tone still seems wrong.

Here's the ACV file: https://www.dropbox.com/s/j11j7ymgj87rmh2/Curve.acv

If it helps, I'm using code that is based loosely on https://github.com/gobackspaces/DLCImagePickerController (everything but the UI code).

My install of GPUImage includes the @ahfarmer's fix.

Any thoughts? I've run out of things to try.

s5 commented 12 years ago

FWIW, when I say "I think it might be related", I mean that I tried overriding this line:

[self setRgbCompositeControlPoints:curve.rgbCompositeCurvePoints];

with:

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];

in - initWithACV: just to see what would happen. While the filter effect doesn't look the same as it does in Photoshop, there are no artifacts.

bradtheappguy commented 12 years ago

@s5 I'm working on correcting a few issues I've uncovered with GPUImageToneCurveFilter. Your dropbox links have gone 404. Could you re-post your files. I would like to see if the behavior you are seeing is the same as me.

s5 commented 12 years ago

@bradsmithinc Whoops, they should be again working now. My designer reshuffled our Dropbox around. :)