Merge "SnapdragonGallery: fix blank gray picture after modify"
diff --git a/src/com/android/gallery3d/filtershow/FilterShowActivity.java b/src/com/android/gallery3d/filtershow/FilterShowActivity.java
index 0f0604a..cfce7c5 100644
--- a/src/com/android/gallery3d/filtershow/FilterShowActivity.java
+++ b/src/com/android/gallery3d/filtershow/FilterShowActivity.java
@@ -1156,6 +1156,16 @@
                 Bitmap originalHires = ImageLoader.loadOrientedConstrainedBitmap(master.getUri(),
                         master.getActivity(), highresPreviewSize,
                         master.getOrientation(), bounds);
+
+                // Force the bitmap to even width and height which is required by beautification algo
+                Bitmap tempBmp = MasterImage.convertToEvenNumberWidthImage(originalHires);
+                if(tempBmp != null && originalHires != null) {
+                    if(!originalHires.isRecycled() && originalHires != tempBmp) {
+                        originalHires.recycle();
+                    }
+                    originalHires = tempBmp;
+                }
+
                 master.setOriginalBounds(bounds);
                 master.setOriginalBitmapHighres(originalHires);
                 Log.d(LOGTAG, "FilterShowActivity.LoadHighresBitmapTask.doInBackground(): originalHires.WH is (" + originalHires.getWidth()
diff --git a/src/com/android/gallery3d/filtershow/imageshow/MasterImage.java b/src/com/android/gallery3d/filtershow/imageshow/MasterImage.java
index b2aae85..fa82989 100644
--- a/src/com/android/gallery3d/filtershow/imageshow/MasterImage.java
+++ b/src/com/android/gallery3d/filtershow/imageshow/MasterImage.java
@@ -272,6 +272,24 @@
         }
     };
 
+    public static Bitmap convertToEvenNumberWidthImage(Bitmap bmp) {
+        Bitmap retBmp = null;
+        if (bmp != null) {
+            int w = bmp.getWidth();
+            int h = bmp.getHeight();
+            boolean bWidthIsEven = (w & 0x01) == 0;
+            boolean bHeightIsEven = (h & 0x01) == 0;
+            Log.v(LOGTAG, "ori bitmap w="+w+" h="+h);
+            if( !bWidthIsEven || !bHeightIsEven){
+                w = w - (w & 0x01);
+                h = h - (h & 0x01);
+                retBmp = Bitmap.createBitmap(bmp, 0, 0, w, h);
+                Log.v(LOGTAG, "new bitmap w="+retBmp.getWidth()+" h="+retBmp.getHeight());
+            }
+        }
+        return retBmp;
+    }
+
     public boolean loadBitmap(Uri uri, int size) {
         setUri(uri);
         mEXIF = ImageLoader.getExif(getActivity(), uri);
@@ -280,6 +298,14 @@
         mOriginalBitmapLarge = ImageLoader.loadOrientedConstrainedBitmap(uri, mActivity,
                 Math.min(MAX_BITMAP_DIM, size),
                 mOrientation, originalBounds);
+        // Force bitmap width and height to even number for beautification algo.
+        Bitmap tempBmp = convertToEvenNumberWidthImage(mOriginalBitmapLarge);
+        if(tempBmp != null && mOriginalBitmapLarge != null) {
+            if(!mOriginalBitmapLarge.isRecycled() && mOriginalBitmapLarge != tempBmp) {
+                mOriginalBitmapLarge.recycle();
+            }
+            mOriginalBitmapLarge = tempBmp;
+        }
         setOriginalBounds(originalBounds);
         if (mOriginalBitmapLarge == null) {
             return false;
diff --git a/src/com/thundersoft/hz/selfportrait/detect/FaceDetect.java b/src/com/thundersoft/hz/selfportrait/detect/FaceDetect.java
index a5c7fb0..99eb33e 100644
--- a/src/com/thundersoft/hz/selfportrait/detect/FaceDetect.java
+++ b/src/com/thundersoft/hz/selfportrait/detect/FaceDetect.java
@@ -24,7 +24,7 @@
 public class FaceDetect {
     private static final String TAG = "FaceDetect";
 
-    private int mHandle = 0;
+    private long mHandle = 0;
 
     static {
         try {
@@ -71,9 +71,9 @@
         return res;
     }
 
-    private static native int native_create();
-    private static native void native_destroy(int handle);
-    private static native int native_detect(int handle, Bitmap bmp);
-    private static native int native_face_info(int handle, int index, Rect face, Rect eye1,
+    private static native long native_create();
+    private static native void native_destroy(long handle);
+    private static native int native_detect(long handle, Bitmap bmp);
+    private static native int native_face_info(long handle, int index, Rect face, Rect eye1,
             Rect eye2, Rect mouth);
 }