今天来学习一下一个简单滤镜使用的流程,通过调节亮度滤镜来了解。先将GPUImage库导入到项目中,引入头文件"GPUImage.h"

     一、创建亮度滤镜对象

    GPUImageBrightnessFilter *filter = [[GPUImageBrightnessFilter alloc] init],经过alloc init之后,程序为我们创建了顶点数组以及帧缓冲区,纹理,并绑定为当前使用的对象。

  1.为顶点着色添加属性

   首先我们来看一该滤镜的顶点着色器字符串

 attribute vec4 position;
attribute vec4 inputTextureCoordinate; varying vec2 textureCoordinate; void main()
{
gl_Position = position;
textureCoordinate = inputTextureCoordinate.xy;
}

我们了解到该顶点有2个需要添加的属性position,inputTextureCoordinate.我们需要在程序中添加这2个属性,通过下列方法来添加

- (void)initializeAttributes;
{
[filterProgram addAttribute:@"position"];
[filterProgram addAttribute:@"inputTextureCoordinate"]; // Override this, calling back to this super method, in order to add new attributes to your vertex shader
}
  2.片段着色提供uniform
  
 varying highp vec2 textureCoordinate;

 uniform sampler2D inputImageTexture;
uniform lowp float brightness; void main()
{
lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); gl_FragColor = vec4((textureColor.rgb + vec3(brightness)), textureColor.w);
}  

  brightnessUniform = [filterProgram uniformIndex:@"brightness"]

  filterInputTextureUniform = [filterProgram uniformIndex:@"inputImageTexture"]

  3.启用顶点数组

  glEnableVertexAttribArray(filterPositionAttribute);

glEnableVertexAttribArray(filterTextureCoordinateAttribute)

 4.创建纹理
- (void)generateTexture;
{
glActiveTexture(GL_TEXTURE1);
glGenTextures(, &_texture);
glBindTexture(GL_TEXTURE_2D, _texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, _textureOptions.minFilter);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, _textureOptions.magFilter);
// This is necessary for non-power-of-two textures
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, _textureOptions.wrapS);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, _textureOptions.wrapT); // TODO: Handle mipmaps
}
 
  5.创建帧缓冲区

     glGenFramebuffers(1, &framebuffer)

  6.帧缓冲绑定纹理

  glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _texture, 0);


  二、设置亮度值

  filter.brightness = value

  三、设置纹理尺寸

    [filter forceProcessingAtSize:image.size]

  四、创建GPUImagePicture对象

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

  五、向创建好的GPUImagePicture对象添加target

  六,处理图像

  [pic processImage]

进行图像渲染并绘制

    glClearColor(backgroundColorRed, backgroundColorGreen, backgroundColorBlue, backgroundColorAlpha);
glClear(GL_COLOR_BUFFER_BIT); glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, [firstInputFramebuffer texture]); glUniform1i(filterInputTextureUniform, 2); glVertexAttribPointer(filterPositionAttribute, 2, GL_FLOAT, 0, 0, vertices);
glVertexAttribPointer(filterTextureCoordinateAttribute, 2, GL_FLOAT, 0, 0, textureCoordinates); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

  七、[filter useNextFrameForImageCapture]

  八、获取处理后的图像

  image = [filter imageFromCurrentFramebuffer]

    GPUImageBrightnessFilter *filter = [[GPUImageBrightnessFilter alloc] init];
filter.brightness = value;
[filter forceProcessingAtSize:image.size];
GPUImagePicture *pic = [[GPUImagePicture alloc] initWithImage:image];
[pic addTarget:filter]; [pic processImage];
[filter useNextFrameForImageCapture];
image = [filter imageFromCurrentFramebuffer];

  

GPUImage简单滤镜使用(一)的更多相关文章

  1. GPUImage简单滤镜使用(二)

    GPUImage中,提供了许多简单的的常用的滤镜.在上一篇文章讲了如何调节图像的亮度这片文章讲一下如何通过GPUImage调节图像的对比度,饱和度,曝光度,和白平衡(美图秀秀中的色温). 原图像 调整 ...

  2. GPUImage简单滤镜使用之色阶(三)

    色阶是表示图像亮度强弱的指数标准,图像的色彩丰满度和精细度是由色阶决定的.在GPUImage中GPUImageLevelsFilter提供了此功能. GPUImageLevelsFilter定义了修改 ...

  3. GPUImage 自定义滤镜

    GPUImage 自定义滤镜 GPUImage 是一个基于 GPU 图像和视频处理的开源 iOS 框架.由于使用 GPU 来处理图像和视频,所以速度非常快,它的作者 BradLarson 称在 iPh ...

  4. GPUImage处理图片(滤镜)

    GPUImage 是基于 GPU 处理图像的一个开源库, 提供了各种图像处理滤镜,例如调 亮度/饱和度/曝光度/白平衡/锐化等滤镜. 并且支持照相机/摄像机 的实时滤镜. GPUImage采用链式方式 ...

  5. ffmpeg第2篇:简单滤镜与复杂滤镜的区别

    在ffmpeg的滤镜中,有简单滤镜(simple filter)和复杂滤镜(complex filter)两种. 使用简单滤镜时,用-vf选项,使用复杂滤镜时,使用-filter_complex或-l ...

  6. GPUimage实时滤镜的实现

    GPUIMAGE中GPUImageStillCamera可以调用系统相机,并实现实时滤镜,但是我没有找到相机全屏的方法,望知道的说一下 GPUImageStillCamera继承自GPUImageVi ...

  7. 导入GPUImage,实时滤镜相机,GUPImage遇到的问题解决,_OBJC_METACLASS_$_GBGPUImageView in GBGPUImageView.o

    导入方法转自:http://www.cnblogs.com/S2-huai/p/3881349.html.. (原文:http://www.cnblogs.com/YouXianMing/p/3709 ...

  8. 图像处理库GPUImage简单使用

    一.介绍 GPUImage是一个基于OpenGL ES 2.0的开源的图像处理库,作者是Brad Larson.GPUImage将OpenGL ES封装为简洁的Objective-C或Swift接口, ...

  9. GpuImage简单使用

    声明变量 @interface ********** { GPUImageVideoCamera *Camera; GPUImageOutput *Filters; GPUImageView *Cam ...

随机推荐

  1. 找不到包含 OwinStartupAttribute 的程序集

    配置一个 MVC 项目时 遇到的  vs 2013 解决办法:在 webconfig 中 <appSettings> <add key="owin:AutomaticApp ...

  2. Visual Studio 2015 update 2 setup fails with "missing or damaged package kb3022398"

    Question     Hi, I wanted to install Visual Studio Professional 2015 Update 2 from my MSDN abo (web ...

  3. Ioc:Autofac Registration Concepts

    Reflection Components When using reflection-based components, Autofac automatically uses the constru ...

  4. SharePoint 获取详细Log信息

    在SharePoint的运维当中,我们可能经常会遇到排错,但是即使找到日志,也不是特别的详细,我们还是需要各种无厘头的猜测. 其实,SharePoint是可以打开详细的日志的,尤其是面对一些服务产生的 ...

  5. 用开源项目PhotoView实现图片的双指缩放和双击放大缩小

    项目地址:https://github.com/chrisbanes/PhotoView 用开源项目有个好处,一是实现简单,二是bug少.那么我们就来说下这个项目能够实现的效果: 1.单个图片的双指缩 ...

  6. .NET零基础入门06:面向对象入门

    一:前言 在本系列课程的第一部分,我们说明为了要选择C#作为你成为程序员的第一门语言: • 首先,C#是一门非常优秀的面向对象编程的语言: 凡是对编码感兴趣的同学一定听说过"面向对象编程&q ...

  7. python三大web框架Django,Flask,Flask,Python几种主流框架,13个Python web框架比较,2018年Python web五大主流框架

    Python几种主流框架 从GitHub中整理出的15个最受欢迎的Python开源框架.这些框架包括事件I/O,OLAP,Web开发,高性能网络通信,测试,爬虫等. Django: Python We ...

  8. SVG Path路径使用(一)

    一.<path> 标签 <path> 标签用来定义路径. 下面的命令可用于路径数据: M = moveto L = lineto H = horizontal lineto V ...

  9. 虚拟机内存复用技术的比较(XEN系统)

    技术途径 业界就该问题定义为虚拟机内存复用(复用干嘛? 当然是为了跑更多的虚拟机呀!) :memory overcommit.围绕次问题主要有4种技术手段,下面简要介绍和分析: 1 气泡驱动(ball ...

  10. PHP xhprof性能优化

    xhprof window http://dev.freshsite.pl/php-extensions/xhprof.html http://php.net/manual/en/book.xhpro ...