Giter VIP home page Giter VIP logo

softlightblendfilterdemo's Introduction

SoftLightBlendFilterDemo

GPUImage录制加美颜、柔光的demo

说明文章

GPUImage录制加美颜、柔光

GPUImage录制加美颜、柔光

柔光就是加了一层滤镜,如果是图片上面加柔光,看这个文章就可以了《IOS使用GPUImage滤镜初级试水》。如果是为了给录制的视频加柔光,也是使用的GPUImageSoftLightBlendFilter这个滤镜效果。

一、柔光滤镜

因为GPUImageSoftLightBlendFilterGPUImageTwoInputFilter的子类,而GPUImageTwoInputFilterGPUImageFilter的子类,对两个输入纹理进行通用的处理,需要继承它并准备自己的片元着色器。所以为了方便,就封装了一个柔光类,里面使用一个图片blend.png,专门对视频用。

DSoftLightBlendFilter.h文件

#import "GPUImageFilterGroup.h"
#import "GPUImage.h"

@interface DSoftLightBlendFilter : GPUImageFilterGroup
{
    GPUImagePicture *imageSource ;
}
@end

DSoftLightBlendFilter.m文件

#import "DSoftLightBlendFilter.h"


@implementation DSoftLightBlendFilter
- (id)init
{
    if (!(self = [super init]))
    {
        return nil;
    }
    
    UIImage *image = [UIImage imageNamed:@"blend.png"];
    
    imageSource = [[GPUImagePicture alloc] initWithImage:image];
    
    GPUImageSoftLightBlendFilter *filter = [[GPUImageSoftLightBlendFilter alloc] init];
    
    [self addFilter:filter];
    [imageSource addTarget:filter atTextureLocation:1];
    [imageSource processImage];
    
    self.initialFilters = [NSArray arrayWithObjects:filter, nil];
    self.terminalFilter = filter;
    
    return self;
}
@end

视频使用的时候就像使用一个普通的filter加到GPUImageVideoCamera、GPUImageMovieWriter上面即可。

二、美颜滤镜

美颜滤镜是使用的这个GPUImageBeautifyFilter,在这个基础上我调低了效果,加了一个美颜参数的设置。

//设置美化强度
- (id)initWithDegree:(float)degree;

这样就可以设置不同的美颜强度了。

三、使用

使用两个可以叠加使用,新建一个GPUImageFilterGroup *filterGroup;,然后叠加

filterGroup = [[GPUImageFilterGroup alloc] init];
[filterGroup addFilter:beautifyFilter];
[filterGroup addFilter:m_softLightBlendFilter];
[beautifyFilter addTarget:m_softLightBlendFilter];
[filterGroup setInitialFilters:[NSArray arrayWithObject: beautifyFilter]];
[filterGroup setTerminalFilter:m_softLightBlendFilter];

[filterGroup addTarget:m_filteredVideoView];
[m_videoCamera addTarget:filterGroup];

[m_videoCamera startCameraCapture];

记得录视频把moviewriter加上

//写入加上滤镜
[filterGroup addTarget:m_movieWriter];

四、Demo下载

这个demo同时加入了光度、曝光、对比度、饱和度、柔光、美颜的调节,可以看下效果。

Github下载:https://github.com/DamonHu/SoftLightBlendFilterDemo

Gitosc下载:http://git.oschina.net/DamonHoo/SoftLightBlendFilterDemo

五、demo演示

softlightblendfilterdemo's People

Contributors

damonhu avatar

Watchers

James Cloos avatar depthlove avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.