• Stars
    star
    1,726
  • Rank 27,025 (Top 0.6 %)
  • Language
    C
  • License
    MIT License
  • Created about 9 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Android Image & Camera Filters Based on OpenGL.

Android-GPUImage-Plus

A C++ & Java library for Image/Camera/Video filters. PRs are welcomed.

New Feature

See the image deform demo.

screenshots screenshots

Gradle dependency

repositories {
    jcenter()
}

//Choose only one of them
dependencies {
    //All arch: armeabi, armeabi-v7a, arm64-v8a, x86
    compile 'org.wysaid:gpuimage-plus:2.6.3'

    //Pure graphics lib without ffmpeg. (all arch for branch 'min')
    compile 'org.wysaid:gpuimage-plus:2.6.3-min'
}

The jcenter is out of date, please try the source for now. Latest prebuilt versions will be provided soon.

To compile other versions of ffmpeg, see: https://github.com/wysaid/FFmpeg-Android.git

Build

  • Options to know in local.properties:

    • usingCMakeCompile=true: Compile the native library with CMake if set to true. (Default to false, so you can use the prebuilt libs)
    • usingCMakeCompileDebug=true: Compile the native library in Debug Mode if set to true. (Default to false)
    • disableVideoModule=true: Disable the video recording feature(Useful for image only scenarios). The whole jni module size will be very small. (Default to false)
  • Build with Android Studio and CMake: (Recommended)

    • Put usingCMakeCompile=true in your local.properties
    • Open the repo with the latest version of Android Studio
    • Waiting for the initialization. (NDK/cmake install)
    • Done.
  • Using Visual Studio Code: (Requires WSL(Recommended)/MinGW/Cygwin on Windows.)

    • Setup ENV variable ANDROID_HOME to your Android SDK installation directory.
    • Open the repo with Visual Studio Code
    • Press ⌘ + shift + B (Mac) or ctrl + shift + B (Win/Linux), choose the option Enable CMake And Build Project With CMake.
    • Done.
  • Build with preset tasks: (Requires WSL(Recommended)/MinGW/Cygwin on Windows.)

    # define the environment variable "ANDROID_HOME"
    # If using Windows, define ANDROID_HOME in Windows Environment Settings by yourself.
    export ANDROID_HOME=/path/to/android/sdk
    
    # Setup Project
    bash vscode_tasks.sh --setup-project
    
    # Compile with CMake Debug
    bash vscode_tasks.sh --debug --enable-cmake --build
    # Compile with CMake Release
    bash vscode_tasks.sh --release --enable-cmake --build
    
    # Start Demo By Command
    bash vscode_tasks.sh --run
  • Build JNI part with ndk-build: (Not recommended)

    export NDK=path/of/your/ndk
    cd folder/of/jni (android-gpuimage-plus/library/src/main/jni)
    
    #This will make all arch: armeabi, armeabi-v7a arm64-v8a, x86, mips
    ./buildJNI
    #Or use "sh buildJNI"
    
    #Try this if you failed to run the shell above
    export CGE_USE_VIDEO_MODULE=1
    $NDK/ndk-build
    
    #If you don't want anything except the image filter,
    #Do as below to build with only cge module
    #No ffmpeg, opencv or faceTracker.
    #And remove the loading part of ffmpeg&facetracker
    $NDK/ndk-build
    
    #For Windows user, you should include the `.cmd` extension to `ndk-build` like this:
    cd <your\path\to\this\repo>\library\src\main\jni
    <your\path\to\ndk>\ndk-build.cmd
    
    #Also remember to comment out these line in NativeLibraryLoader
    //System.loadLibrary("ffmpeg");
    //CGEFFmpegNativeLibrary.avRegisterAll();

You can find precompiled libs here: android-gpuimage-plus-libs (The precompiled '.so' files are generated with NDK-r23b)

Note that the generated file "libFaceTracker.so" is not necessary. So just remove this file if you don't want any feature of it.

Manual

1. Usage

Sample Code for doing a filter with Bitmap

//Simply apply a filter to a Bitmap.
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Bitmap srcImage = ...;

    //HSL Adjust (hue: 0.02, saturation: -0.31, luminance: -0.17)
    //Please see the manual for more details.
    String ruleString = "@adjust hsl 0.02 -0.31 -0.17";

    Bitmap dstImage = CGENativeLibrary.filterImage_MultipleEffects(src, ruleString, 1.0f);

    //Then the dstImage is applied with the filter.

    //Save the result image to /sdcard/libCGE/rec_???.jpg.
    ImageUtil.saveBitmap(dstImage);
}

2. Custom Shader Filter

2.1 Write your own filter

Your filter must inherit CGEImageFilterInterfaceAbstract or its child class. Most of the filters are inherited from CGEImageFilterInterface because it has many useful functions.

// A simple customized filter to do a color reversal.
class MyCustomFilter : public CGE::CGEImageFilterInterface
{
public:
    
    bool init()
    {
        CGEConstString fragmentShaderString = CGE_SHADER_STRING_PRECISION_H
        (
        varying vec2 textureCoordinate;  //defined in 'g_vshDefaultWithoutTexCoord'
        uniform sampler2D inputImageTexture; // the same to above.

        void main()
        {
            vec4 src = texture2D(inputImageTexture, textureCoordinate);
            src.rgb = 1.0 - src.rgb;  //Simply reverse all channels.
            gl_FragColor = src;
        }
        );

        //m_program is defined in 'CGEImageFilterInterface'
        return m_program.initWithShaderStrings(g_vshDefaultWithoutTexCoord, s_fsh);
    }

    //void render2Texture(CGE::CGEImageHandlerInterface* handler, GLuint srcTexture, GLuint vertexBufferID)
    //{
    //  //Your own render functions here.
    //  //Do not override this function to use the CGEImageFilterInterface's.
    //}
};

Note: To add your own shader filter with c++. Please see the demo for further details.

2.2 Run your own filter

In C++, you can use a CGEImageHandler to do that:

//Assume the gl context already exists:
//JNIEnv* env = ...;
//jobject bitmap = ...;
CGEImageHandlerAndroid handler;
CustomFilterType* customFilter = new CustomFilterType();

//You should handle the return value (false is returned when failed.)
customFilter->init();
handler.initWithBitmap(env, bitmap);

//The customFilter will be released when the handler' destructor is called.
//So you don't have to call 'delete customFilter' if you add it into the handler.
handler.addImageFilter(customFilter);

handler.processingFilters(); //Run the filters.

jobject resultBitmap = handler.getResultBitmap(env);

If no gl context exists, the class CGESharedGLContext may be helpful.

In Java, you can simply follow the sample:

See: CGENativeLibrary.cgeFilterImageWithCustomFilter

Or to do with a CGEImageHandler

3. Filter Rule String

Doc: https://github.com/wysaid/android-gpuimage-plus/wiki

En: https://github.com/wysaid/android-gpuimage-plus/wiki/Parsing-String-Rule-(EN)

Ch: https://github.com/wysaid/android-gpuimage-plus/wiki/Parsing-String-Rule-(ZH)

Tool

Some utils are available for creating filters: https://github.com/wysaid/cge-tools

Tool

License

MIT License

Donate

Alipay:

Alipay

Paypal:

Paypal

More Repositories

1

Android-ffmpeg-CameraRecord

使用JavaCV提供的支持, 使用OpenGL实时处理+显示摄像头采集的图像, 并使用FFMPEG实时录制音视频
Java
352
star
2

ios-gpuimage-plus

GPU accelerated image filters for iOS, based on OpenGL.
C++
239
star
3

cge-tools

tools for cge
88
star
4

NDKOpenGLOffscreenRendering

简单demo, Android下使用NDK(C++)+GLES2.0进行后台绘图,保存到bitmap并交给java层处理. 在安卓下使用PBuffer创建context并实现在ndk下后台处理
C
55
star
5

WebGL-Lessons

A simple introduction to WebGL
JavaScript
35
star
6

SOFT_3D

使用普通C++代码实现了OpenGL矩阵、向量运算。部分代码参考自OpenGL.org,使用EGE图形库做了几个CPU渲染的小demo,欢迎感兴趣的同学参考,希望对你有所帮助
Objective-C
19
star
7

wge

WGE (Web Graphics Engine) 是一个web平台下的图形引擎。主要使用webgl实现,同时编写html5-2d兼容版本
JavaScript
15
star
8

WebImage

GPU accelerated Image processing using WebGL
JavaScript
11
star
9

android-gpuimage-plus-libs

9
star
10

ios-vision-face-detection-demo

A quick demo project exploring the face detection feature in Vision.framework
Objective-C++
8
star
11

MineSweep

Minesweep, a simple game for pc.
C++
7
star
12

ege-opencv

一个demo告诉你如何在ege(https://github.com/misakamm/xege) 里面使用OpenCV.
C++
6
star
13

ege-openal

A simple demo that shows how to record&play audio (via OpenAL) with EGE.
C
6
star
14

OGLPaint

This program achieves basic graphics functions with OpenGL. Hoping it would have something helpful for you.
C++
5
star
15

simple-arithmetic

A simple class for arithmetic parsing & calculating.
C++
5
star
16

SpriteGenerator

A Free Image Merger, supporting images with alpha channel, and configurations
C++
4
star
17

faceTrackerLib

A wrapper lib for Jason Saragih's FaceTracker
C++
4
star
18

MathAndProgramming

A simple demo about programming with Elementary Mathematics
C++
4
star
19

MazeLock

MazeLock of the auto generated maze!
C++
3
star
20

open-xege

Another EGE with GPU acceleration based on OpenGL.
C++
2
star
21

xege.org

xege website
C++
1
star
22

WordWar

A fully implemented 2D game
C++
1
star
23

android-gpuimage-plus-maven

maven repo for https://github.com/wysaid/android-gpuimage-plus
HTML
1
star
24

ios-gpuimage-plus-pod

pod repo for ios-gpuimage-plus
C++
1
star
25

soft_mesh_mapping

A soft uv mesh mapping demo with EGE
C++
1
star
26

MagicWings

A 2D game with map editor.
C++
1
star
27

EGE_Net

网格变形, 算法,思路较原版的清晰多了,但是实现方式大不同。作者依据其原理原创
C++
1
star