Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 85f460b8 authored by John Hoford's avatar John Hoford
Browse files

fix crop not supporting non-normal orientation

bug:11324471
Change-Id: Ib4a76ac1540700eeaa4ddd727b06f9a29b999827
parent 5a1d760b
Loading
Loading
Loading
Loading
+42 −26
Original line number Diff line number Diff line
@@ -129,17 +129,37 @@ public final class ImageLoader {
        } finally {
            Utils.closeSilently(cursor);
        }

        // Fall back to checking EXIF tags in file.
        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();
            ExifInterface exif = new ExifInterface();
            try {
                exif.readExif(path);
            } else {
                is = context.getContentResolver().openInputStream(uri);
                exif.readExif(is);
            }
            return parseExif(exif);
        } catch (IOException e) {
            Log.w(LOGTAG, "Failed to read EXIF orientation", e);
        } finally {
            try {
                if (is != null) {
                    is.close();
                }
            } catch (IOException 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;
@@ -157,10 +177,6 @@ public final class ImageLoader {
                    return ORI_NORMAL;
            }
        }
            } catch (IOException e) {
                Log.w(LOGTAG, "Failed to read EXIF orientation", e);
            }
        }
        return ORI_NORMAL;
    }