Giter VIP home page Giter VIP logo

gpuimage-x's Introduction

招聘

阿里巴巴职位(Java,算法等)内推,联系邮箱:[email protected]

GPUImage-x

License

Idea from: iOS GPUImage framework and Android GPUImage framework

The GPUImage-x framework is a cross-platform (for both Android and iOS) library, which aims to have something similar to GPUImage that let you apply GPU-accelerated filters to images, live camera video. Part of vertex and fragment shaders is taken from GPUImage.

The greatest strength of GPUImage-x is that it enables you to develop your Android and iOS project with one library. The core code of this framework is written in C++, and is exactly the same for both iOS and Android projects, which locates in GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/*.cpp and GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/*.cpp respectively. Also, you can extend your customized filters easily.

Requirements

  • Android 2.2 or higher
  • iPhone 4 or later
  • OpenGL ES 2.0

Usage - iOS

Frameworks Dependency

Following frameworks are required to be added to your project.

  • AVFoundation.framework
  • CoreMedia.framework

Sample Code

Filtering An Image

GPUImage::SourceImage* sourceImage;
GPUImage::Filter* filter;
GPUImageView* filterView = (GPUImageView*)self.view;
UIImage* inputImage = [UIImage imageNamed:@"test.jpg"];
GPUImage::Context::getInstance()->runSync([&]{
    // 1. create image source
    sourceImage = GPUImage::SourceImage::create(inputImage); 

    // 2. create a filter
    filter = GPUImage::GaussianBlurFilter::create();         

    // 3. build pipeline
    sourceImage->addTarget(filter)->addTarget(filterView);   

    // 4. proceed
    sourceImage->proceed();                                  
});

This will filter an image with Gaussian Blur effect. GPUImage-x function calls must be embraced between GPUImage::Context::getInstance()->runSync([&]{ and });, as GPUImage-x code should run in a seperate thread.

Filtering Camera Video

GPUImage::SourceCamera* camera;
GPUImage::Filter* filter;
GPUImageView* filterView = (GPUImageView*)self.view;
GPUImage::Context::getInstance()->runSync([&]{
    // 1. create camera source
    camera = GPUImage::SourceCamera::create(); 

    // 2. create a filter
    filter = GPUImage::BeautifyFilter::create();  

    // 3. build pipeline      
    camera->addTarget(filter)->addTarget(filterView);   

    // 4. start the camera and proceed
    camera->start();                                    
});

This will filter a camera video in real time with Beautify Effect.

Usage - Android

Gradle Dependency

repositories {
    jcenter()
}

dependencies {
    compile 'com.jin.gpuimage-x:gpuimage-x:1.0.1'
}

Sample Code

Filtering An Image

// 1. create image source
Bitmap bmp = BitmapFactory.decodeStream(getAssets().open("test.jpg"));
GPUImageSourceImage sourceImage = new GPUImageSourceImage(bmp);   

// 2. create a filter
GPUImageFilter filter = GPUImageFilter.create("GrayscaleFilter");

// 3. build the pipeline
sourceImage.addTarget(filter).addTarget((GPUImageView) findViewById(R.id.gpuimagexview));

// 4. let the GPUImage-x know which source to use
GPUImage.getInstance().setSource(sourceImage);

// 5. proceed
sourceImage.proceed();

This will filter an image with Graysacle effect. More filters can be applied in sequence if you want, e.g. sourceImage.addTarget(filter1).addTarget(filter2). ... .addTarget(filterN).addTarget((GPUImageView) findViewById(R.id.gpuimagexview));

Filtering Camera Video

// 1. create the camera source
GPUImageSourceCamera sourceCamera = new GPUImageSourceCamera(CameraSampleActivity.this);

// 2. create a filter
GPUImageFilter filter = GPUImageFilter.create("EmbossFilter");

// 3. build the pipeline
sourceCamera.addTarget(filter).addTarget((GPUImageView) findViewById(R.id.gpuimagexview));

// 4. let the GPUImage-x know which source to use
GPUImage.getInstance().setSource(sourceCamera);

This will filter a camera video in real time with Emboss Effect.

Sample Results

Here is a few samples of images applied by filters:

License

Copyright (C) 2017 Yijin Wang, Yiqian Wang

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

TODO

  • More filters and features will be added.
  • More platforms will be supported.

Donate

Your donation will be greatly appreciated :)

Alipay

Contact Info

gpuimage-x's People

Contributors

wangyijin 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.