-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use ExifInterface to parse orientation data on OMR1+ in Glide.
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=192690571
- Loading branch information
Showing
2 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...src/main/java/com/bumptech/glide/load/resource/bitmap/ExifInterfaceImageHeaderParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.bumptech.glide.load.resource.bitmap; | ||
|
||
import android.media.ExifInterface; | ||
import android.support.annotation.NonNull; | ||
import com.bumptech.glide.load.ImageHeaderParser; | ||
import com.bumptech.glide.load.engine.bitmap_recycle.ArrayPool; | ||
import com.bumptech.glide.util.ByteBufferUtil; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.nio.ByteBuffer; | ||
|
||
/** | ||
* Uses {@link ExifInterface} to parse orientation data. | ||
* | ||
* <p>ExifInterface supports the HEIF format on OMR1+. Glide's {@link DefaultImageHeaderParser} | ||
* doesn't currently support HEIF. In the future we should reconcile these two classes, but for | ||
* now this is a simple way to ensure that HEIF files are oriented correctly on platforms where | ||
* they're supported. | ||
*/ | ||
public final class ExifInterfaceImageHeaderParser implements ImageHeaderParser { | ||
|
||
@NonNull | ||
@Override | ||
public ImageType getType(@NonNull InputStream is) throws IOException { | ||
return ImageType.UNKNOWN; | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public ImageType getType(@NonNull ByteBuffer byteBuffer) throws IOException { | ||
return ImageType.UNKNOWN; | ||
} | ||
|
||
@Override | ||
public int getOrientation(@NonNull InputStream is, @NonNull ArrayPool byteArrayPool) | ||
throws IOException { | ||
ExifInterface exifInterface = new ExifInterface(is); | ||
return exifInterface.getAttributeInt( | ||
ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); | ||
} | ||
|
||
@Override | ||
public int getOrientation(@NonNull ByteBuffer byteBuffer, @NonNull ArrayPool byteArrayPool) | ||
throws IOException { | ||
return getOrientation(ByteBufferUtil.toStream(byteBuffer), byteArrayPool); | ||
} | ||
} |