IOS Filter Implementation: LOMO (Classic LOMO of meitu xiuxiu) and ioslomo
LOMO's pursuit of a colorful, casual, and free attitude is a frequently used filter. Today I will introduce the implementation of LOMO filters in iOS.
First, it has three input images.
1. images to be processed. That is, we want to apply the LOMO filter to the image.
2
3
You need to write the filters for multiple input images in gpuimage. Here, I wrote the GPUImageThreeInputFilter by referring to the GPUImageTwoInputFilter provided by myself, which is used to receive the filters of three input images. They are all implemented through the inheritance of filter groups and multiple filters.
Fragment shader
NSString * const numeric = SHADER_STRING (precision lowp float; varying highp vec2 numeric; uniform sampler2D numeric; uniform sampler2D numeric; void main () {vec3 texel = texture2D (numeric, textureCoordinate ). rgb; // obtain the rgb value vector vec2 red = vec2 (texel. r, 0.16666); vec2 green = vec2 (texel. g, 0.5); vec2 blue = vec2 (texel. b, 0.83333); // mix the image to be processed with the soft light to generate a new Pixel texel. rgb = vec3 (texture2D (inputImageTexture2, red ). r, texture2D (inputImageTexture2, green ). g, texture2D (inputImageTexture2, blue ). B ); // a new Pixel is generated before and then mixed with the pixel of the second input image // use the third image as the hidden corner template and the preceding pixel mix vec2 tc = (2.0 * textureCoordinate) -1.0; float d = dot (tc, tc); vec2 lookup = vec2 (d, texel. r); texel. r = texture2D (inputImageTexture3, lookup ). r; lookup. y = texel. g; texel. g = texture2D (inputImageTexture3, lookup ). g; lookup. y = texel. b; texel. B = texture2D (inputImageTexture3, lookup ). b;
// Generate the final LOMO Effect
gl_FragColor = vec4(texel,1.0); } );
@ Implementation FWLomofiFilter-(id) init {if (! (Self = [super init]) {return nil;} FWFilter6 * filter = [[FWFilter6 alloc] init]; [self addFilter: filter]; // set the second input image UIImage * image = [UIImage imageNamed: @ "lomoMap"]; imageSource1 = [[GPUImagePicture alloc] initWithImage: image]; [imageSource1 addTarget: filter atTextureLocation: 1]; [imageSource1 processImage];
// Set the third input image
UIImage *image1 = [UIImage imageNamed:@"vignetteMap"]; imageSource2 = [[GPUImagePicture alloc] initWithImage:image1]; [imageSource2 addTarget:filter atTextureLocation:2]; [imageSource2 processImage]; self.initialFilters = [NSArray arrayWithObjects:filter, nil]; self.terminalFilter = filter; return self; }
+ (UIImage *) applyLomofiFilter :( UIImage *) image
{
FWLomofiFilter * filter = [[FWLomofiFilter alloc] init];
[Filter forceProcessingAtSize: image. size];
// The first input image
GPUImagePicture * pic = [[GPUImagePicture alloc] initWithImage: image];
[Pic addTarget: filter];
[Pic processImage];
[Filter useNextFrameForImageCapture];
// Get
Return [filter imageFromCurrentFramebuffer];
}
Source image
Lomo
Complete code can be downloaded on GITHUB!
Below is nonsense
It is so difficult for a person without good words to enter the homepage of the blog garden. How much nonsense can I write? Can this document be used? Regardless of the amount of text, you can check the source code of the LOMO filter implemented by ios on the Internet. In the previous generation of GPUImage, I tried Multiple Image filters over one month.