Code Monkey home page Code Monkey logo

metalimage's Introduction

MetalImage Library

OverView

This library is highly inspired by famous library GPUImage && Colleague's OpenglESImage

一个基于苹果 Metal 搭建的图片处理库.用于实时镜头滤镜处理,图片效果处理等.

Usage

Base Filter

GPUImage 使用方法类似,基于滤镜链形式实现效果.

MIFilter *filter = [[MIFilter alloc]init];

//或者

MIFilter *filter = [[MIFilter alloc] initWithContentSize:Size];

MIFilter 是最基本的滤镜基类,使用者可以根据基类滤镜扩展所需要的自定义滤镜(库中包含了几个滤镜Filter可供使用).

ContentSize 与 OutputFrame

OutputFrameContentSize 的概念来源于上一级滤镜纹理大小与下一级滤镜画布大小,然后计算出 相对的顶点坐标 , 如上一级输出纹理(如摄像头),输出纹理比下一级初始化的画布要大,那么就将上一级纹理按比例缩小绘制到下一级画布大小上,可以通过调节 OutputFramexy 坐标计算 相对顶点坐标.默认是(0,0);意思就是以下一级画布左上角点开始绘制,相对比例画上去. 若 MIFilter 不指定 ContentSize 初始化, 则默认的画布大小(ContentSize) 为上一级纹理输出的大小.

Filter Chain

滤镜链使用与 GPUImage 相似

MIFilter *filterOne = [[MIFilter alloc]init];

MIFilter *filterTwo= [[MIFilter alloc]init];

[filterOne addConsumer:filterTwo];

Shader

MetalShader 语言与 OpenGLES 不一样,他是基于类 C++ 语言。 由于不是图像处理领域方面,库中很多算法都是参考网上,不做更多深究。

Shader 使用起来也是非常方便,只需要新建 Shader 的文件 xxx.metal , 在里面编写图像处理算法.新建一个继承与 MIFilter 的滤镜类,重写里面读取 Shader 方法:

+ (NSString *)vertexShaderFunction {
    static NSString *vFunction = @"此处写着色器中Vertex的Function名字";
    return vFunction;
}

+ (NSString *)fragmentShaderFunction {
    static NSString *fFunction = @"此处写着色器中Fragment的Function名字";
    return fFunction;
}

然后重写 - (void)setVertexFragmentBufferOrTexture:(id<MTLRenderCommandEncoder>)commandEncoder 方法,可自定义滤镜传入参数.

ToDo

  1. 添加更多滤镜效果
  2. 添加图片读取处理功能
  3. 添加视频录制写入功能
  4. 添加Demo

metalimage's People

Contributors

swlfigo avatar

Stargazers

echo avatar 愚非愚余 avatar WL avatar AfryMask avatar HSS avatar  avatar  avatar Louis avatar AshBass avatar 47号同学 avatar

Watchers

James Cloos avatar xcstudio avatar  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.