Prefer upsizing a down-sampled picture if size is close enough
Bug:7185973
Change-Id: Ia3809df23085207f179861a0b4a73f2612dff4a0
diff --git a/src/com/android/contacts/util/BitmapUtil.java b/src/com/android/contacts/util/BitmapUtil.java
index 6f6650f..87eeb3c 100644
--- a/src/com/android/contacts/util/BitmapUtil.java
+++ b/src/com/android/contacts/util/BitmapUtil.java
@@ -52,10 +52,14 @@
if (targetExtent < 1) return 1;
if (originalSmallerExtent < 1) return 1;
- // test what the best sample size is
+ // Test what the best sample size is. To do that, we find the sample size that gives us
+ // the best trade-off between resulting image size and memory requirement. We allow
+ // the down-sampled image to be 20% smaller than the target size. That way we can get around
+ // unfortunate cases where e.g. a 720 picture is requested for 362 and not down-sampled at
+ // all. Why 20%? Why not. Prove me wrong.
int extent = originalSmallerExtent;
int sampleSize = 1;
- while ((extent >> 1) >= targetExtent) {
+ while ((extent >> 1) >= targetExtent * 0.8f) {
sampleSize <<= 1;
extent >>= 1;
}