Skip to content

Commit d4cca9f

Browse files
committed
Merge pull request square#401 from square/dimitris/bloo
Fix 90/270 exifrotations to swap dimens
2 parents 12f7b70 + f42c2db commit d4cca9f

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

picasso/src/main/java/com/squareup/picasso/BitmapHunter.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,9 @@ static Bitmap applyCustomTransformations(List<Transformation> transformations, B
342342
}
343343

344344
static Bitmap transformResult(Request data, Bitmap result, int exifRotation) {
345-
int inWidth = result.getWidth();
346-
int inHeight = result.getHeight();
345+
boolean swapDimens = exifRotation == 90 || exifRotation == 270;
346+
int inWidth = swapDimens ? result.getHeight() : result.getWidth();
347+
int inHeight = swapDimens ? result.getWidth() : result.getHeight();
347348

348349
int drawX = 0;
349350
int drawY = 0;

picasso/src/test/java/com/squareup/picasso/BitmapHunterTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,20 @@ public class BitmapHunterTest {
539539
assertThat(shadowMatrix.getPreOperations()).containsOnly("scale 0.5 0.5");
540540
}
541541

542+
@Test public void exif90SwapsDimensions() throws Exception {
543+
Request data = new Request.Builder(URI_1).build();
544+
Bitmap in = Bitmap.createBitmap(30, 40, null);
545+
Bitmap out = transformResult(data, in, 90);
546+
assertThat(out).hasWidth(40).hasHeight(30);
547+
}
548+
549+
@Test public void exif270SwapsDimensions() throws Exception {
550+
Request data = new Request.Builder(URI_1).build();
551+
Bitmap in = Bitmap.createBitmap(30, 40, null);
552+
Bitmap out = transformResult(data, in, 270);
553+
assertThat(out).hasWidth(40).hasHeight(30);
554+
}
555+
542556
@Test public void reusedBitmapIsNotRecycled() throws Exception {
543557
Request data = new Request.Builder(URI_1).build();
544558
Bitmap source = Bitmap.createBitmap(10, 10, ARGB_8888);

0 commit comments

Comments
 (0)