Fix large images sometimes not respecting EXIF orientation.

Fixes #11614
fork-5.53.8
Art Chaidarun 2022-01-01 22:12:27 -05:00 zatwierdzone przez Greyson Parrelli
rodzic ac90eeb42f
commit 49a1a4a123
3 zmienionych plików z 31 dodań i 9 usunięć

Wyświetl plik

@ -8,6 +8,7 @@ import android.view.View;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.exifinterface.media.ExifInterface;
import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.target.Target; import com.bumptech.glide.request.target.Target;
@ -66,9 +67,6 @@ public class ZoomingImageView extends FrameLayout {
this.photoView = findViewById(R.id.image_view); this.photoView = findViewById(R.id.image_view);
this.subsamplingImageView = findViewById(R.id.subsampling_image_view); this.subsamplingImageView = findViewById(R.id.subsampling_image_view);
this.subsamplingImageView.setOrientation(SubsamplingScaleImageView.ORIENTATION_USE_EXIF);
this.subsamplingImageView.setOrientation(SubsamplingScaleImageView.ORIENTATION_USE_EXIF);
this.photoView.setZoomTransitionDuration(ZOOM_TRANSITION_DURATION); this.photoView.setZoomTransitionDuration(ZOOM_TRANSITION_DURATION);
this.photoView.setScaleLevels(ZOOM_LEVEL_MIN, SMALL_IMAGES_ZOOM_LEVEL_MID, SMALL_IMAGES_ZOOM_LEVEL_MAX); this.photoView.setScaleLevels(ZOOM_LEVEL_MIN, SMALL_IMAGES_ZOOM_LEVEL_MID, SMALL_IMAGES_ZOOM_LEVEL_MAX);
@ -129,6 +127,26 @@ public class ZoomingImageView extends FrameLayout {
subsamplingImageView.setVisibility(View.VISIBLE); subsamplingImageView.setVisibility(View.VISIBLE);
photoView.setVisibility(View.GONE); photoView.setVisibility(View.GONE);
// We manually set the orientation ourselves because using
// SubsamplingScaleImageView.ORIENTATION_USE_EXIF is unreliable:
// https://github.com/signalapp/Signal-Android/issues/11732#issuecomment-963203545
try {
final InputStream inputStream = PartAuthority.getAttachmentStream(getContext(), uri);
final int orientation = BitmapUtil.getExifOrientation(new ExifInterface(inputStream));
inputStream.close();
if (orientation == ExifInterface.ORIENTATION_ROTATE_90) {
subsamplingImageView.setOrientation(SubsamplingScaleImageView.ORIENTATION_90);
} else if (orientation == ExifInterface.ORIENTATION_ROTATE_180) {
subsamplingImageView.setOrientation(SubsamplingScaleImageView.ORIENTATION_180);
} else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) {
subsamplingImageView.setOrientation(SubsamplingScaleImageView.ORIENTATION_270);
} else {
subsamplingImageView.setOrientation(SubsamplingScaleImageView.ORIENTATION_0);
}
} catch (IOException e) {
Log.w(TAG, e);
}
subsamplingImageView.setImage(ImageSource.uri(uri)); subsamplingImageView.setImage(ImageSource.uri(uri));
} }

Wyświetl plik

@ -244,16 +244,19 @@ public class BitmapUtil {
return options; return options;
} }
public static int getExifOrientation(ExifInterface exif) {
return exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED);
}
@Nullable @Nullable
public static Pair<Integer, Integer> getExifDimensions(InputStream inputStream) throws IOException { public static Pair<Integer, Integer> getExifDimensions(ExifInterface exif) {
ExifInterface exif = new ExifInterface(inputStream);
int width = exif.getAttributeInt(ExifInterface.TAG_IMAGE_WIDTH, 0); int width = exif.getAttributeInt(ExifInterface.TAG_IMAGE_WIDTH, 0);
int height = exif.getAttributeInt(ExifInterface.TAG_IMAGE_LENGTH, 0); int height = exif.getAttributeInt(ExifInterface.TAG_IMAGE_LENGTH, 0);
if (width == 0 || height == 0) { if (width == 0 || height == 0) {
return null; return null;
} }
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 0); int orientation = getExifOrientation(exif);
if (orientation == ExifInterface.ORIENTATION_ROTATE_90 || if (orientation == ExifInterface.ORIENTATION_ROTATE_90 ||
orientation == ExifInterface.ORIENTATION_ROTATE_270 || orientation == ExifInterface.ORIENTATION_ROTATE_270 ||
orientation == ExifInterface.ORIENTATION_TRANSVERSE || orientation == ExifInterface.ORIENTATION_TRANSVERSE ||

Wyświetl plik

@ -17,6 +17,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi; import androidx.annotation.RequiresApi;
import androidx.annotation.WorkerThread; import androidx.annotation.WorkerThread;
import androidx.exifinterface.media.ExifInterface;
import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.resource.gif.GifDrawable; import com.bumptech.glide.load.resource.gif.GifDrawable;
@ -189,7 +190,7 @@ public class MediaUtil {
try { try {
if (MediaUtil.isJpegType(contentType)) { if (MediaUtil.isJpegType(contentType)) {
attachmentStream = PartAuthority.getAttachmentStream(context, uri); attachmentStream = PartAuthority.getAttachmentStream(context, uri);
dimens = BitmapUtil.getExifDimensions(attachmentStream); dimens = BitmapUtil.getExifDimensions(new ExifInterface(attachmentStream));
attachmentStream.close(); attachmentStream.close();
attachmentStream = null; attachmentStream = null;
} }