GPUImage简单滤镜使用(一)
今天来学习一下一个简单滤镜使用的流程,通过调节亮度滤镜来了解。先将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简单滤镜使用(一)的更多相关文章
- GPUImage简单滤镜使用(二)
GPUImage中,提供了许多简单的的常用的滤镜.在上一篇文章讲了如何调节图像的亮度这片文章讲一下如何通过GPUImage调节图像的对比度,饱和度,曝光度,和白平衡(美图秀秀中的色温). 原图像 调整 ...
- GPUImage简单滤镜使用之色阶(三)
色阶是表示图像亮度强弱的指数标准,图像的色彩丰满度和精细度是由色阶决定的.在GPUImage中GPUImageLevelsFilter提供了此功能. GPUImageLevelsFilter定义了修改 ...
- GPUImage 自定义滤镜
GPUImage 自定义滤镜 GPUImage 是一个基于 GPU 图像和视频处理的开源 iOS 框架.由于使用 GPU 来处理图像和视频,所以速度非常快,它的作者 BradLarson 称在 iPh ...
- GPUImage处理图片(滤镜)
GPUImage 是基于 GPU 处理图像的一个开源库, 提供了各种图像处理滤镜,例如调 亮度/饱和度/曝光度/白平衡/锐化等滤镜. 并且支持照相机/摄像机 的实时滤镜. GPUImage采用链式方式 ...
- ffmpeg第2篇:简单滤镜与复杂滤镜的区别
在ffmpeg的滤镜中,有简单滤镜(simple filter)和复杂滤镜(complex filter)两种. 使用简单滤镜时,用-vf选项,使用复杂滤镜时,使用-filter_complex或-l ...
- GPUimage实时滤镜的实现
GPUIMAGE中GPUImageStillCamera可以调用系统相机,并实现实时滤镜,但是我没有找到相机全屏的方法,望知道的说一下 GPUImageStillCamera继承自GPUImageVi ...
- 导入GPUImage,实时滤镜相机,GUPImage遇到的问题解决,_OBJC_METACLASS_$_GBGPUImageView in GBGPUImageView.o
导入方法转自:http://www.cnblogs.com/S2-huai/p/3881349.html.. (原文:http://www.cnblogs.com/YouXianMing/p/3709 ...
- 图像处理库GPUImage简单使用
一.介绍 GPUImage是一个基于OpenGL ES 2.0的开源的图像处理库,作者是Brad Larson.GPUImage将OpenGL ES封装为简洁的Objective-C或Swift接口, ...
- GpuImage简单使用
声明变量 @interface ********** { GPUImageVideoCamera *Camera; GPUImageOutput *Filters; GPUImageView *Cam ...
随机推荐
- [置顶] 九度笔记之 1494:Dota
题目1494:Dota 1 秒 内存限制:128 兆 特殊判题:否 提交:559 解决:122 题目描述: 大家都知道在dota游戏中,装备是对于英雄来说十分重要的要素. 英雄们不仅可以购买单个的装备 ...
- Java基础加强总结(三)——代理(Proxy)
一.代理的概念 动态代理技术是整个java技术中最重要的一个技术,它是学习java框架的基础,不会动态代理技术,那么在学习Spring这些框架时是学不明白的. 动态代理技术就是用来产生一个对象的代理对 ...
- 使用Edge模式通知Internet Explorer以最高级别的可用模式显示内容
一.EasyUI$的window('open')在IE8下兼容性问题 今天在公司使用EasyUI的$('#win').window('open');方法打开一个window窗体时发现EaysUI的脚本 ...
- CentOS 安装 Jenkins
原文:https://www.sunjianhua.cn/archives/centos-jenkins.html 1.更换源 mv /etc/yum.repos.d/CentOS-Base.repo ...
- Android 实时视频编码—H.264硬编码
from://http://www.cnblogs.com/skyseraph/archive/2012/04/04/2431771.html 1 硬编码 & 软编码 硬编码:通过调用And ...
- Android ormlite like() function is not working
//http://stackoverflow.com/questions/7642161/android-ormlite-like-function-is-not-working try { Quer ...
- Python:Opening Python Classes
I won’t reply to that post much, because it’s mostly… well, not useful to respond to. But people oft ...
- python测试开发django-43.session机制(登录/注销)
前言 当我们登录访问一个网站时,服务器需要识别到你已经登录了,才有相应的权限访问登录之后的页面.用户退出登录后,将无权限访问再访问登录后的页面. 从登录到退出的一整个流程,可以看成是与服务器的一次会话 ...
- 【伊利丹】Hadoop2.0 NN HA实验记录
1.关于Hadoop2.2.0中HA的介绍 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxNDUxMjEyNA==/font/5a6L5L2T/fo ...
- GO -- 正则表达式
str := "880218end" match, _ := regexp.MatchString("\\d{16}", str) //六位连续的数字 fmt. ...