Skip to content

Commit

Permalink
Downsampler preserves original size for Target.SIZE_ORIGINAL for all …
Browse files Browse the repository at this point in the history
…downsample strategies.

PiperOrigin-RevId: 269628399
  • Loading branch information
sjudd authored and glide-copybara-robot committed Sep 17, 2019
1 parent 24f9c28 commit 79dac0d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}

Expand All @@ -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();
}

Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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();
}

Expand All @@ -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();
}

Expand Down Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 79dac0d

Please sign in to comment.