GPUimage port for android

牧云@^-^@ 提交于 2019-12-02 21:35:59
vanloi999

GPUImage for Android Idea from: iOS GPUImage framework

Goal is to have something as similar to GPUImage as possible. Vertex and fragment shaders are exactly the same. That way it makes it easier to port filters from GPUImage iOS to Android.

The link is below:

This lib is implemented using Android OpenGL ES 2.0

you can use Gpuimage for video preview and take picture also, just compile the jni file in gpuimage library with ndk and put the method for YuvtoRgb convert in GPUImageNativeLibrary.java class in GPUImageLibrary for android.

public static void YUVtoRBGA(byte[] yuv, int width, int height, int[] rgb) {



final int frameSize = width * height;
    int r, g, b, y1192, y, i, uvp, u, v;
    for (int j = 0, yp = 0; j < height; j++) {
        uvp = frameSize + (j >> 1) * width;
        u = 0;
        v = 0;
        for (i = 0; i < width; i++, yp++) {
            y = (0xff & ((int) yuv[yp])) - 16;
            if (y < 0)
                y = 0;
            if ((i & 1) == 0) {
                v = (0xff & yuv[uvp++]) - 128;
                u = (0xff & yuv[uvp++]) - 128;
            }

            y1192 = 1192 * y;
            r = (y1192 + 1634 * v);
            g = (y1192 - 833 * v - 400 * u);
            b = (y1192 + 2066 * u);

            // Java's functions are faster then 'IFs'
            r = Math.max(0, Math.min(r, 262143));
            g = Math.max(0, Math.min(g, 262143));
            b = Math.max(0, Math.min(b, 262143));

            rgb[yp] = 0xff000000 | ((r << 6) & 0xff0000)
                    | ((g >> 2) & 0xff00) | ((b >> 10) & 0xff);
            // rgba, divide 2^10 ( >> 10)
            /*
             * rgb[yp] = 0xff000000 |((r << 14) & 0xff000000) | ((g << 6) &
             * 0xff0000) | ((b >> 2) | 0xff00);
             */
        }
    }
}

replace the method in GPUImageNativeLibrary.java class's public static Native YUVtoRBGA with this, and you have done.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!