diff --git a/instrumentation/src/androidTest/java/com/bumptech/glide/load/resource/bitmap/DownsamplerEmulatorTest.java b/instrumentation/src/androidTest/java/com/bumptech/glide/load/resource/bitmap/DownsamplerEmulatorTest.java index 463dd6a87b..deaceae8c3 100644 --- a/instrumentation/src/androidTest/java/com/bumptech/glide/load/resource/bitmap/DownsamplerEmulatorTest.java +++ b/instrumentation/src/androidTest/java/com/bumptech/glide/load/resource/bitmap/DownsamplerEmulatorTest.java @@ -28,6 +28,7 @@ import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPoolAdapter; import com.bumptech.glide.load.engine.bitmap_recycle.LruArrayPool; +import com.bumptech.glide.request.target.Target; import com.bumptech.glide.util.Preconditions; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; @@ -121,6 +122,9 @@ public void calculateScaling_withAtMost() throws IOException { .givenSquareImageWithDimensionOf(200, onAllApisAndAllFormatsExpect(200, 200)) .givenSquareImageWithDimensionOf(450, onAllApisAndAllFormatsExpect(450, 450)) .givenImageWithDimensionsOf(200, 450, onAllApisAndAllFormatsExpect(200, 450)) + // Original scaling + .setTargetDimensions(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL) + .givenImageWithDimensionsOf(1821, 2634, onAllApisAndAllFormatsExpect(1821, 2634)) .run(); } @@ -144,6 +148,9 @@ public void calculateScaling_withAtLeast() throws IOException { .givenSquareImageWithDimensionOf(200, onAllApisAndAllFormatsExpect(200, 200)) .givenSquareImageWithDimensionOf(450, onAllApisAndAllFormatsExpect(450, 450)) .givenImageWithDimensionsOf(200, 450, onAllApisAndAllFormatsExpect(200, 450)) + // Original scaling + .setTargetDimensions(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL) + .givenImageWithDimensionsOf(1821, 2634, onAllApisAndAllFormatsExpect(1821, 2634)) .run(); } @@ -207,6 +214,9 @@ public void calculateScaling_withCenterInside() throws IOException { .givenSquareImageWithDimensionOf(200, onAllApisAndAllFormatsExpect(200, 200)) .givenSquareImageWithDimensionOf(450, onAllApisAndAllFormatsExpect(450, 450)) .givenImageWithDimensionsOf(200, 450, onAllApisAndAllFormatsExpect(200, 450)) + // Original scaling + .setTargetDimensions(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL) + .givenImageWithDimensionsOf(1821, 2634, onAllApisAndAllFormatsExpect(1821, 2634)) .run(); } @@ -253,6 +263,9 @@ public void calculateScaling_withCenterOutside() throws IOException { 450, atAndAbove(KITKAT).with(allFormats().expect(500, 1125)), below(KITKAT).with(allFormats().expect(200, 450))) + // Original scaling + .setTargetDimensions(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL) + .givenImageWithDimensionsOf(1821, 2634, onAllApisAndAllFormatsExpect(1821, 2634)) .run(); } @@ -276,6 +289,9 @@ public void calculateScaling_withNone() throws IOException { .givenSquareImageWithDimensionOf(200, onAllApisAndAllFormatsExpect(200, 200)) .givenSquareImageWithDimensionOf(450, onAllApisAndAllFormatsExpect(450, 450)) .givenImageWithDimensionsOf(200, 450, onAllApisAndAllFormatsExpect(200, 450)) + // Original scaling + .setTargetDimensions(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL) + .givenImageWithDimensionsOf(1821, 2634, onAllApisAndAllFormatsExpect(1821, 2634)) .run(); } @@ -386,6 +402,9 @@ public void calculateScaling_withFitCenter() throws IOException { 450, atAndAbove(KITKAT).with(allFormats().expect(222, 500)), below(KITKAT).with(allFormats().expect(200, 450))) + // Original scaling + .setTargetDimensions(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL) + .givenImageWithDimensionsOf(1821, 2634, onAllApisAndAllFormatsExpect(1821, 2634)) .run(); } diff --git a/library/src/main/java/com/bumptech/glide/load/resource/bitmap/Downsampler.java b/library/src/main/java/com/bumptech/glide/load/resource/bitmap/Downsampler.java index c5ff4959e6..98a1e46470 100644 --- a/library/src/main/java/com/bumptech/glide/load/resource/bitmap/Downsampler.java +++ b/library/src/main/java/com/bumptech/glide/load/resource/bitmap/Downsampler.java @@ -270,8 +270,14 @@ private Bitmap decodeFromWrappedStreams( int degreesToRotate = TransformationUtils.getExifOrientationDegrees(orientation); boolean isExifOrientationRequired = TransformationUtils.isExifOrientationRequired(orientation); - int targetWidth = requestedWidth == Target.SIZE_ORIGINAL ? sourceWidth : requestedWidth; - int targetHeight = requestedHeight == Target.SIZE_ORIGINAL ? sourceHeight : requestedHeight; + int targetWidth = + requestedWidth == Target.SIZE_ORIGINAL + ? (isRotationRequired(degreesToRotate) ? sourceHeight : sourceWidth) + : requestedWidth; + int targetHeight = + requestedHeight == Target.SIZE_ORIGINAL + ? (isRotationRequired(degreesToRotate) ? sourceWidth : sourceHeight) + : requestedHeight; ImageType imageType = ImageHeaderParserUtils.getType(parsers, is, byteArrayPool); @@ -422,7 +428,7 @@ private static void calculateScaling( // width is decreased to near our target's height and the image height is decreased to near // our target width. //noinspection SuspiciousNameCombination - if (degreesToRotate == 90 || degreesToRotate == 270) { + if (isRotationRequired(degreesToRotate)) { orientedSourceWidth = sourceHeight; orientedSourceHeight = sourceWidth; } @@ -906,4 +912,8 @@ public interface DecodeCallbacks { void onDecodeComplete(BitmapPool bitmapPool, Bitmap downsampled) throws IOException; } + + private static boolean isRotationRequired(int degreesToRotate) { + return degreesToRotate == 90 || degreesToRotate == 270; + } }