Nashville [instagram] And iosinstagram with iOS Filter Implementation

Source: Internet
Author: User

Nashville [instagram] And iosinstagram with iOS Filter Implementation

Nashville is one of the most amazing among Instagram's many filters. Its unique milkshake tones give the photos a fairy tale of beauty.
Applicability: Create a romantic and beautiful feeling.
Indeed.
Two input images
Vertex coloring
There are two sets of coordinates
NSString * const kGPUImageTwoInputTextureVertexShaderString = SHADER_STRING
(Attribute vec4 position;
// Input coordinate attribute vec4 inputTextureCoordinate; attribute vec4 rectangle; // output coordinate, with fragment shader varying vec2 textureCoordinate; varying vec2 textureCoordinate2; void main (){
// Tell the fragment shader which pixels I am processing gl_Position = position; textureCoordinate = inputTextureCoordinate. xy; textureCoordinate2 = inputTextureCoordinate2.xy ;});

Segment coloring
NSString *const kFWNashvilleShaderString = SHADER_STRING( precision lowp float;  varying highp vec2 textureCoordinate;  uniform sampler2D inputImageTexture; uniform sampler2D inputImageTexture2;  void main() {     vec3 texel = texture2D(inputImageTexture, textureCoordinate).rgb;     texel = vec3(                  texture2D(inputImageTexture2, vec2(texel.r, .16666)).r,                  texture2D(inputImageTexture2, vec2(texel.g, .5)).g,                  texture2D(inputImageTexture2, vec2(texel.b, .83333)).b);     gl_FragColor = vec4(texel, 1.0); } );

 

Initialization
- (id)init{    if (!(self = [super init]))    {        return nil;    }        UIImage *image = [UIImage imageNamed:@"nashvilleMap.png"];        imageSource = [[GPUImagePicture alloc] initWithImage:image];    FWFilter1 *filter = [[FWFilter1 alloc] init];        [self addFilter:filter];    [imageSource addTarget:filter atTextureLocation:1];    [imageSource processImage];        self.initialFilters = [NSArray arrayWithObjects:filter, nil];    self.terminalFilter = filter;        return self;}
 
 
/// FWNashvilleFilter. h // FWMeituApp // Created by hzkmn on 16/1/8. // Copyright©2016 ForrestWoo co,. ltd. All rights reserved. // # import "authorization. h" @ interface FWFilter1: reply @ end @ interface FWNashvilleFilter: GPUImageFilterGroup {GPUImagePicture * imageSource;} @ end
 

 

/// FWNashvilleFilter. m // FWMeituApp // Created by hzkmn on 16/1/8. // Copyright©2016 ForrestWoo co ,. ltd. all rights reserved. // # import "FWNashvilleFilter. h "NSString * const inline = SHADER_STRING (precision lowp float; varying highp vec2 inline; uniform sampler2D inline; uniform sampler2D inline; void main () {vec3 texel = texture2D (Inline, textureCoordinate ). rgb; texel = vec3 (texture2D (inputImageTexture2, vec2 (te Xel. r ,. 16666 )). r, texture2D (inputImageTexture2, vec2 (texel. g ,. 5 )). g, texture2D (inputImageTexture2, vec2 (texel. B ,. 83333 )). b); gl_FragColor = vec4 (texel, 1.0) ;}); @ implementation FWFilter1-(id) init; {if (! (Self = [super initWithFragmentShaderFromString: kFWNashvilleShaderString]) {return nil;} return self ;}@ end @ implementation FWNashvilleFilter-(id) init {if (! (Self = [super init]) {return nil;} UIImage * image = [UIImage imageNamed: @ "nashvilleMap.png"]; imageSource = [[GPUImagePicture alloc] initWithImage: image]; FWFilter1 * filter = [FWFilter1 alloc] init]; [self addFilter: filter]; [imageSource addTarget: filter atTextureLocation: 1]; [imageSource processImage]; self. initialFilters = [NSArray arrayWithObjects: filter, nil]; self. terminalFilter = filter; return self;} @ end

 

Source image

View the complete project code on github.

 

Let's take a look at several groups of results.

  

 

 

 

 

 

 

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.