diff options
author | Alan Newberger <alann@google.com> | 2014-11-12 22:36:10 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2014-11-12 22:36:10 +0000 |
commit | 62e688ab880e9e3efd02315c02b920f550b675d8 (patch) | |
tree | b19d5942e109aa1a7a3a24a624d7be944a50b7b7 | |
parent | 820d09d658a629f204563c469899a98ce74cddaa (diff) | |
parent | f4eee98d06c2f8da42f998f89d7e82d0665f55ba (diff) | |
download | glide-62e688ab880e9e3efd02315c02b920f550b675d8.tar.gz |
am f4eee98d: Ensure overdraw, not overdraw, of reused bitmaps
* commit 'f4eee98d06c2f8da42f998f89d7e82d0665f55ba':
Ensure overdraw, not overdraw, of reused bitmaps
-rw-r--r-- | library/src/main/java/com/bumptech/glide/load/resource/bitmap/TransformationUtils.java | 25 |
1 files changed, 23 insertions, 2 deletions
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 2714b6a6..9cffbd8f 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 @@ -79,20 +79,41 @@ public class TransformationUtils { */ public static Bitmap fitCenter(Bitmap toFit, BitmapPool pool, int width, int height) { if (toFit.getWidth() == width && toFit.getHeight() == height) { + if (Log.isLoggable(TAG, Log.VERBOSE)) { + Log.v(TAG, "requested target size matches input, returning input"); + } return toFit; } final float widthPercentage = width / (float) toFit.getWidth(); final float heightPercentage = height / (float) toFit.getHeight(); final float minPercentage = Math.min(widthPercentage, heightPercentage); - final int targetWidth = Math.round(minPercentage * toFit.getWidth()); - final int targetHeight = Math.round(minPercentage * toFit.getHeight()); + // take the floor of the target width/height, not round. If the matrix + // passed into drawBitmap rounds differently, we want to slightly + // overdraw, not underdraw, to avoid artifacts from bitmap reuse. + final int targetWidth = (int) (minPercentage * toFit.getWidth()); + final int targetHeight = (int) (minPercentage * toFit.getHeight()); + + if (toFit.getWidth() == targetWidth && toFit.getHeight() == targetHeight) { + if (Log.isLoggable(TAG, Log.VERBOSE)) { + Log.v(TAG, "adjusted target size matches input, returning input"); + } + return toFit; + } Bitmap.Config config = toFit.getConfig() != null ? toFit.getConfig() : Bitmap.Config.ARGB_8888; Bitmap toReuse = pool.get(targetWidth, targetHeight, config); if (toReuse == null) { toReuse = Bitmap.createBitmap(targetWidth, targetHeight, config); } + + if (Log.isLoggable(TAG, Log.VERBOSE)) { + Log.v(TAG, "request: " + width + "x" + height); + Log.v(TAG, "toFit: " + toFit.getWidth() + "x" + toFit.getHeight()); + Log.v(TAG, "toReuse: " + toReuse.getWidth() + "x" + toReuse.getHeight()); + Log.v(TAG, "minPct: " + minPercentage); + } + Canvas canvas = new Canvas(toReuse); Matrix matrix = new Matrix(); matrix.setScale(minPercentage, minPercentage); |