I am trying to implement some image filters, like polaroid, in iphone. I searched on how to filter an existing UIImage to convert it into a polaroid style and come across th
int step=10;// variable value that changes the level of saturation
int red = pixelRedVal;
int green = pixelGreenVal;
int blue = pixelBlueVal;
int avg = (red + green + blue) / 3;
pixelBuf[r] = SAFECOLOR((avg + step * (red - avg)));
pixelBuf[g] = SAFECOLOR((avg + step * (green - avg)));
pixelBuf[b] = SAFECOLOR((avg + step * (blue - avg)));
where SAFECOLOR is a macro
define SAFECOLOR(color) MIN(255,MAX(0,color))
and for Brightness int step=10;// variable value that changes the level of saturation
int red = pixelRedVal;
int green = pixelGreenVal;
int blue = pixelBlueVal;
pixelBuf[r] = SAFECOLOR(red * step);
pixelBuf[g] = SAFECOLOR(green * step);
pixelBuf[b] = SAFECOLOR(blue * step);
You can simply use this: with different parameters
// Note: the hue input ranges from 0.0 to 1.0, both red. Values outside this range will be clamped to 0.0 or 1.0.
//Polaroid with HSB parameter
- (UIImage*) polaroidishEffectWithHue:(CGFloat)hue saturation:(CGFloat)sat brightness:(CGFloat)bright alpha:(CGFloat)alpha
{
// Find the image dimensions.
CGSize imageSize = [self size];
CGRect imageExtent = CGRectMake(0,0,imageSize.width,imageSize.height);
// Create a context containing the image.
UIGraphicsBeginImageContext(imageSize);
CGContextRef context = UIGraphicsGetCurrentContext();
[self drawAtPoint:CGPointMake(0,0)];
// Draw the hue on top of the image.
CGContextSetBlendMode(context, kCGBlendModeHue);
[[UIColor colorWithHue:hue saturation:sat brightness:bright alpha:alpha] set];
UIBezierPath *imagePath = [UIBezierPath bezierPathWithRect:imageExtent];
[imagePath fill];
// Retrieve the new image.
UIImage *result = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return result;
}
This might be helpful, from Camera+ taking filters from photoshop and reproducing them for iOS.
http://taptaptap.com/blog/creating-a-camera-plus-fx/