summaryrefslogtreecommitdiff
path: root/core/src/main
diff options
context:
space:
mode:
authorMartin Fietz <Martin.Fietz@gmail.com>2015-07-31 10:50:38 +0200
committerMartin Fietz <Martin.Fietz@gmail.com>2015-07-31 21:08:28 +0200
commit4f7566ddfca14754ebe28cd49e63a1db0c992d78 (patch)
treeaaf2594ef95cd94b850edd0cdb848adb1817d67e /core/src/main
parent66e5c4fdf1325758e03a6146703ae2fd2c68f3db (diff)
downloadAntennaPod-4f7566ddfca14754ebe28cd49e63a1db0c992d78.zip
Improved blurring
Diffstat (limited to 'core/src/main')
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/glide/FastBlurTransformation.java40
-rw-r--r--core/src/main/res/values/strings.xml1
2 files changed, 15 insertions, 26 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/glide/FastBlurTransformation.java b/core/src/main/java/de/danoeh/antennapod/core/glide/FastBlurTransformation.java
index f5e645535..ee58c2f39 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/glide/FastBlurTransformation.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/glide/FastBlurTransformation.java
@@ -2,6 +2,7 @@ package de.danoeh.antennapod.core.glide;
import android.content.Context;
import android.graphics.Bitmap;
+import android.media.ThumbnailUtils;
import android.util.Log;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
@@ -9,33 +10,35 @@ import com.bumptech.glide.load.resource.bitmap.BitmapTransformation;
public class FastBlurTransformation extends BitmapTransformation {
- private static final String TAG = "BlurTransformation";
+ private static final String TAG = FastBlurTransformation.class.getSimpleName();
- private static final int RADIUS = 1;
- private static final int IMAGE_SIZE = 192;
+ private static final int STACK_BLUR_RADIUS = 1;
+ private static final int BLUR_IMAGE_WIDTH = 150;
public FastBlurTransformation(Context context) {
super(context);
}
@Override
- protected Bitmap transform(BitmapPool pool, Bitmap toTransform,
+ protected Bitmap transform(BitmapPool pool, Bitmap source,
int outWidth, int outHeight) {
- Bitmap resizedBitmap = Bitmap.createScaledBitmap(toTransform, IMAGE_SIZE, IMAGE_SIZE, true);
- Bitmap transformed = fastBlur(resizedBitmap, RADIUS);
- if (transformed == null) {
- Log.w(TAG, "transformed was null");
- return toTransform;
+ int targetWidth = BLUR_IMAGE_WIDTH;
+ int targetHeight = (int) (1.0 * outHeight * targetWidth / outWidth);
+ Bitmap resized = ThumbnailUtils.extractThumbnail(source, targetWidth, targetHeight);
+ Bitmap result = fastBlur(resized, STACK_BLUR_RADIUS);
+ if (result == null) {
+ Log.w(TAG, "result was null");
+ return source;
}
- return transformed;
+ return result;
}
@Override
public String getId() {
- return "FastBlurTransformation-" + IMAGE_SIZE + "x" + IMAGE_SIZE + "-" + RADIUS;
+ return "FastBlurTransformation[width=" + BLUR_IMAGE_WIDTH + "px,radius=" + STACK_BLUR_RADIUS +"]";
}
- private static Bitmap fastBlur(Bitmap original, int radius) {
+ private static Bitmap fastBlur(Bitmap bitmap, int radius) {
// Stack Blur v1.0 from
// http://www.quasimondo.com/StackBlurForCanvas/StackBlurDemo.html
@@ -65,15 +68,6 @@ public class FastBlurTransformation extends BitmapTransformation {
//
// Stack Blur Algorithm by Mario Klingemann <mario@quasimondo.com>
- Bitmap.Config config = original.getConfig();
- if (config == null) {
- // Sometimes the config can be null, in those cases
- // we don't do a transform.
- return null;
- }
-
- Bitmap bitmap = original.copy(config, true);
-
if (radius < 1) {
return null;
}
@@ -82,7 +76,6 @@ public class FastBlurTransformation extends BitmapTransformation {
int h = bitmap.getHeight();
int[] pix = new int[w * h];
- Log.e("pix", w + " " + h + " " + pix.length);
bitmap.getPixels(pix, 0, w, 0, 0, w, h);
int wm = w - 1;
@@ -267,10 +260,7 @@ public class FastBlurTransformation extends BitmapTransformation {
yi += w;
}
}
-
- Log.e("pix", w + " " + h + " " + pix.length);
bitmap.setPixels(pix, 0, w, 0, 0, w, h);
-
return bitmap;
}
diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml
index e91030e93..21a35cdb7 100644
--- a/core/src/main/res/values/strings.xml
+++ b/core/src/main/res/values/strings.xml
@@ -465,7 +465,6 @@
<!-- Progress information -->
<string name="progress_upgrading_database">Upgrading the database</string>
- <string name="progress_clearing_image_cache">Clearing old image cache</string>
<!-- AntennaPodSP -->