提交 bc22b026 编写于 作者: J judds 提交者: Sam Judd

Automated g4 rollback of changelist 192690571.

*** Reason for rollback ***

b/78110139

*** Original change description ***

Use ExifInterface to parse orientation data on OMR1+ in Glide.

***

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=193431565
上级 a3f8114d
......@@ -11,7 +11,6 @@ import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.os.ParcelFileDescriptor;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
......@@ -55,7 +54,6 @@ import com.bumptech.glide.load.resource.bitmap.BitmapEncoder;
import com.bumptech.glide.load.resource.bitmap.ByteBufferBitmapDecoder;
import com.bumptech.glide.load.resource.bitmap.DefaultImageHeaderParser;
import com.bumptech.glide.load.resource.bitmap.Downsampler;
import com.bumptech.glide.load.resource.bitmap.ExifInterfaceImageHeaderParser;
import com.bumptech.glide.load.resource.bitmap.ResourceBitmapDecoder;
import com.bumptech.glide.load.resource.bitmap.StreamBitmapDecoder;
import com.bumptech.glide.load.resource.bitmap.UnitBitmapDecoder;
......@@ -333,13 +331,6 @@ public class Glide implements ComponentCallbacks2 {
final Resources resources = context.getResources();
registry = new Registry();
// Right now we're only using this parser for HEIF images, which are only supported on OMR1+.
// If we need this for other file types, we should consider removing this restriction.
// Note that order here matters. We want to check the ExifInterface parser first for orientation
// and then fall back to DefaultImageHeaderParser for other fields.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
registry.register(new ExifInterfaceImageHeaderParser());
}
registry.register(new DefaultImageHeaderParser());
Downsampler downsampler = new Downsampler(registry.getImageHeaderParsers(),
......
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);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册