• iOS滤镜实现之Nashville【instagram】


    Nashville是Instagram众多滤镜中最惊艳的一款,独特的奶昔色调赋予照片童话般的唯美感觉。
    适用范围:营造浪漫唯美的感觉。
    的确如此啊
    有2张输入图像
    顶点着色
    有2组坐标
    NSString *const kGPUImageTwoInputTextureVertexShaderString = SHADER_STRING
    (
     attribute vec4 position;
    //输入的坐标 attribute vec4 inputTextureCoordinate; attribute vec4 inputTextureCoordinate2; //输出的坐标,与片段着色器 varying vec2 textureCoordinate; varying vec2 textureCoordinate2; void main() {
    //告诉片段着色器,我在处理哪些像素 gl_Position = position; textureCoordinate = inputTextureCoordinate.xy; textureCoordinate2 = inputTextureCoordinate2.xy; } );

    片段着色
    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);
     }
     );
     初始化
    - (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 "GPUImageTwoInputFilter.h"
    
    @interface FWFilter1 : GPUImageTwoInputFilter
    
    
    
    @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 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);
     }
     );
    
    @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

    原图

    效果图

    完整项目代码查看我在github

     我们再来看几组效果

      

     
  • 相关阅读:
    此网站的安全证书有问题
    WebBrowser控件打开https站点
    C# 调Win32 API SendMessage简单用法及wMsg常量
    sendmessage和postmessage的区别
    C# 使用Win32 API模拟键盘鼠标操作网页
    WebBrowser控件跨域访问页面内容
    获取webbrowser中元素的屏幕坐标
    一行js代码识别Selenium+Webdriver及其应对方案
    用Selenium自动化测试时,让ChromeDriver中不显示“正受到自动测试软件控制”
    Java Selenium Actions模拟鼠标拖动dragAndDrop总结
  • 原文地址:https://www.cnblogs.com/salam/p/5929243.html
Copyright © 2020-2023  润新知