OSDN Git Service

Add stop check in ImageFilterFX
authornicolasroard <nicolasroard@google.com>
Tue, 2 Jul 2013 20:21:31 +0000 (13:21 -0700)
committernicolasroard <nicolasroard@google.com>
Tue, 2 Jul 2013 20:22:38 +0000 (13:22 -0700)
speed up switching / interrupting of rendering.

Change-Id: I3ef4b1d16047b00a062c86d72cdfff2bfe9817a2

jni/filters/fx.c
src/com/android/gallery3d/filtershow/filters/IconUtilities.java
src/com/android/gallery3d/filtershow/filters/ImageFilterFx.java

index 24fa5e0..c3c9cbd 100644 (file)
@@ -29,7 +29,9 @@ __inline__ int  interp(unsigned char  *src, int p , int *off ,float dr,float dg,
     return (int)frbg ;
 }
 
-void JNIFUNCF(ImageFilterFx, nativeApplyFilter, jobject bitmap, jint width, jint height, jobject lutbitmap,jint lutwidth, jint lutheight )
+void JNIFUNCF(ImageFilterFx, nativeApplyFilter, jobject bitmap, jint width, jint height,
+        jobject lutbitmap, jint lutwidth, jint lutheight,
+        jint start, jint end)
 {
     char* destination = 0;
     char* lut = 0;
@@ -58,9 +60,7 @@ void JNIFUNCF(ImageFilterFx, nativeApplyFilter, jobject bitmap, jint width, jint
     float scale_B = (lutdim_b-1.f)/256.f;
 
     int i;
-    int len = width * height * STEP;
-
-    for (i = 0; i < len; i+=STEP)
+    for (i = start; i < end; i+= STEP)
     {
         int r = rgb[RED];
         int g = rgb[GREEN];
index 38211f3..e2a0147 100644 (file)
@@ -64,8 +64,9 @@ public class IconUtilities {
                 int h = bitmap.getHeight();
                 int fxw = fxBitmap.getWidth();
                 int fxh = fxBitmap.getHeight();
-
-                nativeApplyFilter(bitmap, w, h, fxBitmap, fxw, fxh);
+                int start = 0;
+                int end = w * h * 4;
+                nativeApplyFilter(bitmap, w, h, fxBitmap, fxw, fxh, start, end);
                 return bitmap;
             }
         };
index 51c6612..19bea59 100644 (file)
@@ -51,7 +51,9 @@ public class ImageFilterFx extends ImageFilter {
         return mParameters;
     }
 
-    native protected void nativeApplyFilter(Bitmap bitmap, int w, int h,Bitmap  fxBitmap, int fxw, int fxh);
+    native protected void nativeApplyFilter(Bitmap bitmap, int w, int h,
+                                            Bitmap fxBitmap, int fxw, int fxh,
+                                            int start, int end);
 
     @Override
     public Bitmap apply(Bitmap bitmap, float scaleFactor, int quality) {
@@ -85,7 +87,20 @@ public class ImageFilterFx extends ImageFilter {
         int fxw = mFxBitmap.getWidth();
         int fxh = mFxBitmap.getHeight();
 
-        nativeApplyFilter(bitmap, w, h, mFxBitmap, fxw, fxh);
+        int stride = w * 4;
+        int max = stride * h;
+        int increment = stride * 256; // 256 lines
+        for (int i = 0; i < max; i += increment) {
+            int start = i;
+            int end = i + increment;
+            if (end > max) {
+                end = max;
+            }
+            if (!getEnvironment().needsStop()) {
+                nativeApplyFilter(bitmap, w, h, mFxBitmap, fxw, fxh, start, end);
+            }
+        }
+
         return bitmap;
     }