首页 技术 正文
技术 2022年11月8日
0 收藏 334 点赞 1,590 浏览 2203 个字

  LOMO追求鲜艳色彩,随意、自由的态度,是一种经常使用的滤镜,今天介绍一下iOS 中LOMO滤镜的实现

首先它有3张输入图像

1.我们要处理的图像。即我们要应用LOMO滤镜的图像

2iOS滤镜实现之LOMO(美图秀秀经典LOMO)      

3iOS滤镜实现之LOMO(美图秀秀经典LOMO)

在gpuimage中多张输入图像的滤镜需要自己写。在这里我参照本身提供的GPUImageTwoInputFilter,自己写了GPUImageThreeInputFilter,用于接收3张输入图像的滤镜。它们都是通过滤镜组的继承来实现,多重滤镜。

  

  片段着色器

NSString *const kFWLomofiShaderString = SHADER_STRING
(
precision lowp float; varying highp vec2 textureCoordinate; uniform sampler2D inputImageTexture;
uniform sampler2D inputImageTexture2;
uniform sampler2D inputImageTexture3; void main()
{ vec3 texel = texture2D(inputImageTexture, textureCoordinate).rgb;//获取要处理图像的rgb值向量 vec2 red = vec2(texel.r, 0.16666);
vec2 green = vec2(texel.g, 0.5);
vec2 blue = vec2(texel.b, 0.83333);//使要处理的图像和柔光混合,生成新的像素 texel.rgb = vec3(
texture2D(inputImageTexture2, red).r,
texture2D(inputImageTexture2, green).g,
texture2D(inputImageTexture2, blue).b);
//前面生成新的像素再与第二个输入图像的像素进行混合
//使用第三个图像作为暗角模板与前面的像素混合
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;
//生成最终的LOMO效果
gl_FragColor = vec4(texel,1.0); } );
@implementation FWLomofiFilter- (id)init
{
if (!(self = [super init]))
{
return nil;
} FWFilter6 *filter = [[FWFilter6 alloc] init];
[self addFilter:filter];
//设置第二个输入图像
UIImage *image = [UIImage imageNamed:@"lomoMap"];
imageSource1 = [[GPUImagePicture alloc] initWithImage:image];
[imageSource1 addTarget:filter atTextureLocation:];
[imageSource1 processImage];
//设置第三个输入图像
UIImage *image1 = [UIImage imageNamed:@"vignetteMap"]; imageSource2 = [[GPUImagePicture alloc] initWithImage:image1]; [imageSource2 addTarget:filter atTextureLocation:]; [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];

//第一个输入图像

GPUImagePicture *pic = [[GPUImagePicture alloc] initWithImage:image];

[pic addTarget:filter];

[pic processImage];

[filter useNextFrameForImageCapture];

//得到效果图

return [filter imageFromCurrentFramebuffer];

}

原图

iOS滤镜实现之LOMO(美图秀秀经典LOMO) 

lomo效果图

iOS滤镜实现之LOMO(美图秀秀经典LOMO) 

完整代码可以在本人的GITHUB上下载源码!

下面是废话

不善言辞的人进博客园首页就这么难,我得写多少废话才能进?这篇可以吗? 不管文字多少,你上网查查ios实现LOMO滤镜的源码,本滤镜纯自己琢磨,在上一代GPUImage中我通过1个多月的摸索,将多图像滤镜实现的。

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,111
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,584
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,431
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,203
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,838
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,922