Skip to content

Commit 79dac0d

Browse files
sjuddglide-copybara-robot
authored andcommittedSep 17, 2019
Downsampler preserves original size for Target.SIZE_ORIGINAL for all downsample strategies.
PiperOrigin-RevId: 269628399
1 parent 24f9c28 commit 79dac0d

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed
 

‎instrumentation/src/androidTest/java/com/bumptech/glide/load/resource/bitmap/DownsamplerEmulatorTest.java

+19
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
2929
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPoolAdapter;
3030
import com.bumptech.glide.load.engine.bitmap_recycle.LruArrayPool;
31+
import com.bumptech.glide.request.target.Target;
3132
import com.bumptech.glide.util.Preconditions;
3233
import java.io.BufferedInputStream;
3334
import java.io.BufferedOutputStream;
@@ -121,6 +122,9 @@ public void calculateScaling_withAtMost() throws IOException {
121122
.givenSquareImageWithDimensionOf(200, onAllApisAndAllFormatsExpect(200, 200))
122123
.givenSquareImageWithDimensionOf(450, onAllApisAndAllFormatsExpect(450, 450))
123124
.givenImageWithDimensionsOf(200, 450, onAllApisAndAllFormatsExpect(200, 450))
125+
// Original scaling
126+
.setTargetDimensions(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
127+
.givenImageWithDimensionsOf(1821, 2634, onAllApisAndAllFormatsExpect(1821, 2634))
124128
.run();
125129
}
126130

@@ -144,6 +148,9 @@ public void calculateScaling_withAtLeast() throws IOException {
144148
.givenSquareImageWithDimensionOf(200, onAllApisAndAllFormatsExpect(200, 200))
145149
.givenSquareImageWithDimensionOf(450, onAllApisAndAllFormatsExpect(450, 450))
146150
.givenImageWithDimensionsOf(200, 450, onAllApisAndAllFormatsExpect(200, 450))
151+
// Original scaling
152+
.setTargetDimensions(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
153+
.givenImageWithDimensionsOf(1821, 2634, onAllApisAndAllFormatsExpect(1821, 2634))
147154
.run();
148155
}
149156

@@ -207,6 +214,9 @@ public void calculateScaling_withCenterInside() throws IOException {
207214
.givenSquareImageWithDimensionOf(200, onAllApisAndAllFormatsExpect(200, 200))
208215
.givenSquareImageWithDimensionOf(450, onAllApisAndAllFormatsExpect(450, 450))
209216
.givenImageWithDimensionsOf(200, 450, onAllApisAndAllFormatsExpect(200, 450))
217+
// Original scaling
218+
.setTargetDimensions(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
219+
.givenImageWithDimensionsOf(1821, 2634, onAllApisAndAllFormatsExpect(1821, 2634))
210220
.run();
211221
}
212222

@@ -253,6 +263,9 @@ public void calculateScaling_withCenterOutside() throws IOException {
253263
450,
254264
atAndAbove(KITKAT).with(allFormats().expect(500, 1125)),
255265
below(KITKAT).with(allFormats().expect(200, 450)))
266+
// Original scaling
267+
.setTargetDimensions(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
268+
.givenImageWithDimensionsOf(1821, 2634, onAllApisAndAllFormatsExpect(1821, 2634))
256269
.run();
257270
}
258271

@@ -276,6 +289,9 @@ public void calculateScaling_withNone() throws IOException {
276289
.givenSquareImageWithDimensionOf(200, onAllApisAndAllFormatsExpect(200, 200))
277290
.givenSquareImageWithDimensionOf(450, onAllApisAndAllFormatsExpect(450, 450))
278291
.givenImageWithDimensionsOf(200, 450, onAllApisAndAllFormatsExpect(200, 450))
292+
// Original scaling
293+
.setTargetDimensions(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
294+
.givenImageWithDimensionsOf(1821, 2634, onAllApisAndAllFormatsExpect(1821, 2634))
279295
.run();
280296
}
281297

@@ -386,6 +402,9 @@ public void calculateScaling_withFitCenter() throws IOException {
386402
450,
387403
atAndAbove(KITKAT).with(allFormats().expect(222, 500)),
388404
below(KITKAT).with(allFormats().expect(200, 450)))
405+
// Original scaling
406+
.setTargetDimensions(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
407+
.givenImageWithDimensionsOf(1821, 2634, onAllApisAndAllFormatsExpect(1821, 2634))
389408
.run();
390409
}
391410

‎library/src/main/java/com/bumptech/glide/load/resource/bitmap/Downsampler.java

+13-3
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,14 @@ private Bitmap decodeFromWrappedStreams(
270270
int degreesToRotate = TransformationUtils.getExifOrientationDegrees(orientation);
271271
boolean isExifOrientationRequired = TransformationUtils.isExifOrientationRequired(orientation);
272272

273-
int targetWidth = requestedWidth == Target.SIZE_ORIGINAL ? sourceWidth : requestedWidth;
274-
int targetHeight = requestedHeight == Target.SIZE_ORIGINAL ? sourceHeight : requestedHeight;
273+
int targetWidth =
274+
requestedWidth == Target.SIZE_ORIGINAL
275+
? (isRotationRequired(degreesToRotate) ? sourceHeight : sourceWidth)
276+
: requestedWidth;
277+
int targetHeight =
278+
requestedHeight == Target.SIZE_ORIGINAL
279+
? (isRotationRequired(degreesToRotate) ? sourceWidth : sourceHeight)
280+
: requestedHeight;
275281

276282
ImageType imageType = ImageHeaderParserUtils.getType(parsers, is, byteArrayPool);
277283

@@ -422,7 +428,7 @@ private static void calculateScaling(
422428
// width is decreased to near our target's height and the image height is decreased to near
423429
// our target width.
424430
//noinspection SuspiciousNameCombination
425-
if (degreesToRotate == 90 || degreesToRotate == 270) {
431+
if (isRotationRequired(degreesToRotate)) {
426432
orientedSourceWidth = sourceHeight;
427433
orientedSourceHeight = sourceWidth;
428434
}
@@ -906,4 +912,8 @@ public interface DecodeCallbacks {
906912

907913
void onDecodeComplete(BitmapPool bitmapPool, Bitmap downsampled) throws IOException;
908914
}
915+
916+
private static boolean isRotationRequired(int degreesToRotate) {
917+
return degreesToRotate == 90 || degreesToRotate == 270;
918+
}
909919
}

0 commit comments

Comments
 (0)
Please sign in to comment.