From e515f4781ec508671f21263f4de29e49e3f96945 Mon Sep 17 00:00:00 2001 From: judds Date: Tue, 23 Oct 2018 11:47:45 -0700 Subject: [PATCH] Retain the hasAlphaBit when rotating images in TransformationUtils. This fixes a bug where camera images written with non-zero exif orientations are cached in Glide's disk cache as slower PNGs instead of JPEGs. Camera images without exif orientaiton or with 0 values for the exif orientation are unaffected. Images with exif orientations are always rotated by Downsampler using this method when they're decoded. The modified method writes the rotated image into a Bitmap acquired from the BitmapPool. Bitmaps in the pool default to having hasAlpha true because it's safer to retain transparency than not. The modified method previously did not update the newly obtained bitmap's hasAlpha flag with the value from the unrotated original. As a result, every image with exif orientation ended up in a bitmap with the hasAlpha flag set to true. In turn, BitmapEncoder would write all of these images to disk as PNGs because it assumes images with hasAlpha set to true might have transparency. Writing and reading PNGs is much slower than writing/reading JPEGs in general, so this causes a performance issue for Camera images, which, as a rule, do not have transparency (and have hasAlpha set to false). To avoid the performance hit, this change sets the hasAlpha flag on rotated Bitmaps based on the value from the original unmodified Bitmap. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=218380242 --- .../glide/load/resource/bitmap/TransformationUtils.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/library/src/main/java/com/bumptech/glide/load/resource/bitmap/TransformationUtils.java b/library/src/main/java/com/bumptech/glide/load/resource/bitmap/TransformationUtils.java index fa0b17e40d..2244500ee3 100644 --- a/library/src/main/java/com/bumptech/glide/load/resource/bitmap/TransformationUtils.java +++ b/library/src/main/java/com/bumptech/glide/load/resource/bitmap/TransformationUtils.java @@ -331,6 +331,9 @@ public static Bitmap rotateImageExif(@NonNull BitmapPool pool, @NonNull Bitmap i matrix.postTranslate(-newRect.left, -newRect.top); applyMatrix(inBitmap, result, matrix); + + result.setHasAlpha(inBitmap.hasAlpha()); + return result; }