Skip to content
This repository
Browse code

Refactor out native static library code so native part is only needed…

… for camera
  • Loading branch information...
commit abc45bf280f077201b309e7c95c3c91d366d5aff 1 parent ee92146
Patrick Boos authored December 17, 2012
13  README.md
Source Rendered
@@ -12,12 +12,11 @@ Goal is to have something as similar to GPUImage as possible. Vertex and fragmen
12 12
 ### Include in own project
13 13
 GPUImage can be used as a library project or by copying the following files/folders to your libs folder.
14 14
 
15  
-* library/libs/armeabi
  15
+* library/libs/armeabi (only needed for camera live preview)
16 16
 * library/bin/gpuimage.jar
17 17
 
18 18
 ### Maven dependency
19 19
 
20  
-
21 20
     <dependency>
22 21
       <groupId>jp.co.cyberagent.android.gpuimage</groupId>
23 22
       <artifactId>gpuimage-library</artifactId>
@@ -25,6 +24,16 @@ GPUImage can be used as a library project or by copying the following files/fold
25 24
       <version>(use current version here)</version>
26 25
     </dependency>
27 26
 
  27
+If you want to use it with live camera preview, than you will need to add the following as well:
  28
+
  29
+    <dependency>
  30
+      <groupId>jp.co.cyberagent.android.gpuimage</groupId>
  31
+      <artifactId>gpuimage-library</artifactId>
  32
+      <classifier>armeabi</classifier>
  33
+      <type>so</type>
  34
+      <version>(use current version here)</version>
  35
+    </dependency>
  36
+
28 37
 
29 38
 ### Sample Code
30 39
 With preview:
4  library/jni/yuv-decoder.c
@@ -2,7 +2,7 @@
2 2
 #include <android/log.h>
3 3
 
4 4
 
5  
-JNIEXPORT void JNICALL Java_jp_co_cyberagent_android_gpuimage_OpenGlUtils_YUVtoRBGA(JNIEnv * env, jobject obj, jbyteArray yuv420sp, jint width, jint height, jintArray rgbOut)
  5
+JNIEXPORT void JNICALL Java_jp_co_cyberagent_android_gpuimage_GPUImageNativeLibrary_YUVtoRBGA(JNIEnv * env, jobject obj, jbyteArray yuv420sp, jint width, jint height, jintArray rgbOut)
6 6
 {
7 7
     int             sz;
8 8
     int             i;
@@ -50,7 +50,7 @@ JNIEXPORT void JNICALL Java_jp_co_cyberagent_android_gpuimage_OpenGlUtils_YUVtoR
50 50
     (*env)->ReleasePrimitiveArrayCritical(env, yuv420sp, yuv, 0);
51 51
 }
52 52
 
53  
-JNIEXPORT void JNICALL Java_jp_cyberagent_android_base_media_filter_opengl_OpenGlUtils_YUVtoARBG(JNIEnv * env, jobject obj, jbyteArray yuv420sp, jint width, jint height, jintArray rgbOut)
  53
+JNIEXPORT void JNICALL Java_jp_co_cyberagent_android_gpuimage_GPUImageNativeLibrary_YUVtoARBG(JNIEnv * env, jobject obj, jbyteArray yuv420sp, jint width, jint height, jintArray rgbOut)
54 54
 {
55 55
     int             sz;
56 56
     int             i;
BIN  library/libs/armeabi/libgpuimage-library.so
Binary file not shown
27  library/src/jp/co/cyberagent/android/gpuimage/GPUImageNativeLibrary.java
... ...
@@ -0,0 +1,27 @@
  1
+/*
  2
+ * Copyright (C) 2012 CyberAgent
  3
+ *
  4
+ * Licensed under the Apache License, Version 2.0 (the "License");
  5
+ * you may not use this file except in compliance with the License.
  6
+ * You may obtain a copy of the License at
  7
+ *
  8
+ * http://www.apache.org/licenses/LICENSE-2.0
  9
+ *
  10
+ * Unless required by applicable law or agreed to in writing, software
  11
+ * distributed under the License is distributed on an "AS IS" BASIS,
  12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13
+ * See the License for the specific language governing permissions and
  14
+ * limitations under the License.
  15
+ */
  16
+
  17
+package jp.co.cyberagent.android.gpuimage;
  18
+
  19
+public class GPUImageNativeLibrary {
  20
+    static {
  21
+        System.loadLibrary("gpuimage-library");
  22
+    }
  23
+
  24
+    public static native void YUVtoRBGA(byte[] yuv, int width, int height, int[] out);
  25
+
  26
+    public static native void YUVtoARBG(byte[] yuv, int width, int height, int[] out);
  27
+}
2  library/src/jp/co/cyberagent/android/gpuimage/GPUImageRenderer.java
@@ -147,7 +147,7 @@ public void onPreviewFrame(final byte[] data, final Camera camera) {
147 147
             runOnDraw(new Runnable() {
148 148
                 @Override
149 149
                 public void run() {
150  
-                    OpenGlUtils.YUVtoRBGA(data, previewSize.width, previewSize.height,
  150
+                    GPUImageNativeLibrary.YUVtoRBGA(data, previewSize.width, previewSize.height,
151 151
                             mGLRgbBuffer.array());
152 152
                     mGLTextureId = OpenGlUtils.loadTexture(mGLRgbBuffer, previewSize, mGLTextureId);
153 153
                     camera.addCallbackBuffer(data);
78  library/src/jp/co/cyberagent/android/gpuimage/OpenGlUtils.java
@@ -28,10 +28,6 @@
28 28
 public class OpenGlUtils {
29 29
     public static final int NO_TEXTURE = -1;
30 30
 
31  
-    static {
32  
-        System.loadLibrary("gpuimage-library");
33  
-    }
34  
-
35 31
     public static int loadTexture(final Bitmap img, final int usedTexId) {
36 32
         return loadTexture(img, usedTexId, true);
37 33
     }
@@ -91,80 +87,6 @@ public static int loadTextureAsBitmap(final IntBuffer data, final Size size, fin
91 87
         return loadTexture(bitmap, usedTexId);
92 88
     }
93 89
 
94  
-    public static native void YUVtoRBGA(byte[] yuv, int width, int height, int[] out);
95  
-
96  
-    public static native void YUVtoARBG(byte[] yuv, int width, int height, int[] out);
97  
-
98  
-    // decode Y, U, and V values on the YUV 420 buffer described as YCbCr_422_SP
99  
-    // by Android
100  
-    // David Manpearl 081201
101  
-    public static void decodeYUV(final int[] out, final byte[] fg, final int width, final int height)
102  
-            throws NullPointerException, IllegalArgumentException {
103  
-        int sz = width * height;
104  
-        if (out == null) {
105  
-            throw new NullPointerException("buffer out is null");
106  
-        }
107  
-        if (out.length < sz) {
108  
-            throw new IllegalArgumentException("buffer out size " + out.length
109  
-                    + " < minimum " + sz);
110  
-        }
111  
-        if (fg == null) {
112  
-            throw new NullPointerException("buffer 'fg' is null");
113  
-        }
114  
-        if (fg.length < sz) {
115  
-            throw new IllegalArgumentException("buffer fg size " + fg.length
116  
-                    + " < minimum " + sz * 3 / 2);
117  
-        }
118  
-        int i, j;
119  
-        int Y, Cr = 0, Cb = 0;
120  
-        for (j = 0; j < height; j++) {
121  
-            int pixPtr = j * width;
122  
-            final int jDiv2 = j >> 1;
123  
-            for (i = 0; i < width; i++) {
124  
-                Y = fg[pixPtr];
125  
-                if (Y < 0) {
126  
-                    Y += 255;
127  
-                }
128  
-                if ((i & 0x1) != 1) {
129  
-                    final int cOff = sz + jDiv2 * width + (i >> 1) * 2;
130  
-                    Cb = fg[cOff];
131  
-                    if (Cb < 0) {
132  
-                        Cb += 127;
133  
-                    } else {
134  
-                        Cb -= 128;
135  
-                    }
136  
-                    Cr = fg[cOff + 1];
137  
-                    if (Cr < 0) {
138  
-                        Cr += 127;
139  
-                    } else {
140  
-                        Cr -= 128;
141  
-                    }
142  
-                }
143  
-                int R = Y + Cr + (Cr >> 2) + (Cr >> 3) + (Cr >> 5);
144  
-                if (R < 0) {
145  
-                    R = 0;
146  
-                } else if (R > 255) {
147  
-                    R = 255;
148  
-                }
149  
-                int G = Y - (Cb >> 2) + (Cb >> 4) + (Cb >> 5) - (Cr >> 1)
150  
-                        + (Cr >> 3) + (Cr >> 4) + (Cr >> 5);
151  
-                if (G < 0) {
152  
-                    G = 0;
153  
-                } else if (G > 255) {
154  
-                    G = 255;
155  
-                }
156  
-                int B = Y + Cb + (Cb >> 1) + (Cb >> 2) + (Cb >> 6);
157  
-                if (B < 0) {
158  
-                    B = 0;
159  
-                } else if (B > 255) {
160  
-                    B = 255;
161  
-                }
162  
-                out[pixPtr++] = 0xff000000 + (B << 16) + (G << 8) + R;
163  
-            }
164  
-        }
165  
-
166  
-    }
167  
-
168 90
     public static int loadShader(final String strSource, final int iType) {
169 91
         int[] compiled = new int[1];
170 92
         int iShader = GLES20.glCreateShader(iType);

0 notes on commit abc45bf

Please sign in to comment.
Something went wrong with that request. Please try again.