OSDN Git Service

Merge "Import translations. DO NOT MERGE"
authorBaligh Uddin <baligh@google.com>
Tue, 22 Oct 2013 19:55:25 +0000 (19:55 +0000)
committerAndroid (Google) Code Review <android-gerrit@google.com>
Tue, 22 Oct 2013 19:55:25 +0000 (19:55 +0000)
src/com/android/gallery3d/filtershow/cache/ImageLoader.java
src/com/android/gallery3d/filtershow/pipeline/ImagePreset.java
src/com/android/gallery3d/filtershow/tools/SaveImage.java
src/com/android/gallery3d/filtershow/ui/ExportDialog.java

index 69edd60..52c296c 100644 (file)
@@ -129,36 +129,52 @@ public final class ImageLoader {
         } finally {
             Utils.closeSilently(cursor);
         }
-
-        // Fall back to checking EXIF tags in file.
-        if (ContentResolver.SCHEME_FILE.equals(uri.getScheme())) {
-            String mimeType = getMimeType(uri);
-            if (!JPEG_MIME_TYPE.equals(mimeType)) {
-                return ORI_NORMAL;
+        ExifInterface exif = new ExifInterface();
+        InputStream is = null;
+        // Fall back to checking EXIF tags in file or input stream.
+        try {
+            if (ContentResolver.SCHEME_FILE.equals(uri.getScheme())) {
+                String mimeType = getMimeType(uri);
+                if (!JPEG_MIME_TYPE.equals(mimeType)) {
+                    return ORI_NORMAL;
+                }
+                String path = uri.getPath();
+                exif.readExif(path);
+            } else {
+                is = context.getContentResolver().openInputStream(uri);
+                exif.readExif(is);
             }
-            String path = uri.getPath();
-            ExifInterface exif = new ExifInterface();
+            return parseExif(exif);
+        } catch (IOException e) {
+            Log.w(LOGTAG, "Failed to read EXIF orientation", e);
+        } finally {
             try {
-                exif.readExif(path);
-                Integer tagval = exif.getTagIntValue(ExifInterface.TAG_ORIENTATION);
-                if (tagval != null) {
-                    int orientation = tagval;
-                    switch(orientation) {
-                        case ORI_NORMAL:
-                        case ORI_ROTATE_90:
-                        case ORI_ROTATE_180:
-                        case ORI_ROTATE_270:
-                        case ORI_FLIP_HOR:
-                        case ORI_FLIP_VERT:
-                        case ORI_TRANSPOSE:
-                        case ORI_TRANSVERSE:
-                            return orientation;
-                        default:
-                            return ORI_NORMAL;
-                    }
+                if (is != null) {
+                    is.close();
                 }
             } catch (IOException e) {
-                Log.w(LOGTAG, "Failed to read EXIF orientation", e);
+                Log.w(LOGTAG, "Failed to close InputStream", e);
+            }
+        }
+        return ORI_NORMAL;
+    }
+
+    private static int parseExif(ExifInterface exif){
+        Integer tagval = exif.getTagIntValue(ExifInterface.TAG_ORIENTATION);
+        if (tagval != null) {
+            int orientation = tagval;
+            switch(orientation) {
+                case ORI_NORMAL:
+                case ORI_ROTATE_90:
+                case ORI_ROTATE_180:
+                case ORI_ROTATE_270:
+                case ORI_FLIP_HOR:
+                case ORI_FLIP_VERT:
+                case ORI_TRANSPOSE:
+                case ORI_TRANSVERSE:
+                    return orientation;
+                default:
+                    return ORI_NORMAL;
             }
         }
         return ORI_NORMAL;
index 4322ed7..4765a59 100644 (file)
@@ -394,7 +394,7 @@ public class ImagePreset {
                     break;
                 }
             }
-            if (!replaced) {
+            if (!replaced && !isNoneFxFilter(representation)) {
                 mFilters.add(0, representation);
             }
         } else {
index 354081e..c3cdea8 100644 (file)
@@ -402,6 +402,10 @@ public class SaveImage {
                     // if we have a valid size
                     int w = (int) (bitmap.getWidth() * sizeFactor);
                     int h = (int) (bitmap.getHeight() * sizeFactor);
+                    if (w == 0 || h == 0) {
+                        w = 1;
+                        h = 1;
+                    }
                     bitmap = Bitmap.createScaledBitmap(bitmap, w, h, true);
                 }
                 updateProgress();
index f6a84ce..b42c9f3 100644 (file)
@@ -202,8 +202,8 @@ public class ExportDialog extends DialogFragment implements View.OnClickListener
             return;
         }
         mEditing = true;
-        int width = 0;
-        int height = 0;
+        int width = 1;
+        int height = 1;
         if (text.getId() == R.id.editableWidth) {
             if (mWidthText.getText() != null) {
                 String value = String.valueOf(mWidthText.getText());
@@ -213,6 +213,10 @@ public class ExportDialog extends DialogFragment implements View.OnClickListener
                         width = mOriginalBounds.width();
                         mWidthText.setText("" + width);
                     }
+                    if (width <= 0) {
+                        width = (int) Math.ceil(mRatio);
+                        mWidthText.setText("" + width);
+                    }
                     height = (int) (width / mRatio);
                 }
                 mHeightText.setText("" + height);
@@ -226,6 +230,10 @@ public class ExportDialog extends DialogFragment implements View.OnClickListener
                         height = mOriginalBounds.height();
                         mHeightText.setText("" + height);
                     }
+                    if (height <= 0) {
+                        height = 1;
+                        mHeightText.setText("" + height);
+                    }
                     width = (int) (height * mRatio);
                 }
                 mWidthText.setText("" + width);