GPUimage port for android
Asked Answered
M

2

19

Has anyone ported this to android yet? More the framework than the shaders. Stuff like bringing camera data into openGL. I have worked with it on iOS and it is very fast. Any help is much appreciated.

Missile answered 10/7, 2012 at 0:45 Comment(4)
Before you ask, I'm not working on an Android version any time soon. However, someone did port the basics of it to AS3 a couple of months ago: github.com/inspirit/GPUImage . The fragment shaders can come across mostly untouched, but the rest is going to require a complete rewrite for Android's camera and supporting OpenGL ES architecture. Also, it'll need to deal with the much wider variety of device hardware for that platform, where I can make certain assumptions about iOS devices and their PowerVR hardware.Rumelia
I'm currently experimenting with a quick C++ port of GPUImage which can be found on github here: github.com/Dexterp37/GPUImage . At the moment it just allows to use the Grayscale filter by loading from a file and Android (through NDK) support is not in just yet, but I plan to start working on that as soon as possible.Ejaculate
You may want to read a little into Renderscript before getting started. There are intrinsics for image processing in the API.Inna
It seems that android library only work on images (no video)?Feudality
C
9

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

Contrasty answered 23/12, 2012 at 8:54 Comment(6)
It seems that android library only work on images (no video)?Feudality
Is there any other library able to do both image and videos?Feudality
android-gpuimage also works on live preview so I assume that you can somehow manipulate videos with it, too.Hysteric
@haythemsouissi Where is the difference of processing images and processing many imges (i.e. video)? You will have to deal with re-encoding the video anyways.Rakish
@jesses.co.tt did you finished implementing video?Deborahdeborath
Kind of... but it was hacky. The company I was working for continued on with it and may be releasing it, but not until it is more mature...Spermatozoon
H
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.

Herson answered 6/11, 2015 at 4:39 Comment(2)
Does this work for applying filters to Video and save them?Deborahdeborath
yes i did it, just change the following in GPUImageNativeLibrary.java class, but it will lag for marshmallow. if you can further something else, please let me know.Herson

© 2022 - 2024 — McMap. All rights reserved.