Increase blurred image size

Today's screens have a much better resolution than a few years ago when this code was created.
Use 1/3 of the target size of the image instead of a fixed size. The transformed image
is cached by Glide, so the transformation does not need to be done multiple times.

This way, the images look a lot better (because they are not stretched to be displayed).
This commit is contained in:
ByteHamster 2020-02-12 12:21:16 +01:00
parent 25fbff6afd
commit f34430eb28
1 changed files with 10 additions and 14 deletions

View File

@ -14,19 +14,15 @@ public class FastBlurTransformation extends BitmapTransformation {
private static final String TAG = FastBlurTransformation.class.getSimpleName();
private static final int STACK_BLUR_RADIUS = 1;
private static final int BLUR_IMAGE_WIDTH = 150;
private static final int STACK_BLUR_RADIUS = 5;
public FastBlurTransformation() {
super();
}
@Override
protected Bitmap transform(BitmapPool pool, Bitmap source,
int outWidth, int outHeight) {
int targetWidth = BLUR_IMAGE_WIDTH;
int targetHeight = (int) (1.0 * outHeight * targetWidth / outWidth);
Bitmap resized = ThumbnailUtils.extractThumbnail(source, targetWidth, targetHeight);
protected Bitmap transform(BitmapPool pool, Bitmap source, int outWidth, int outHeight) {
Bitmap resized = ThumbnailUtils.extractThumbnail(source, outWidth / 3, outHeight / 3);
Bitmap result = fastBlur(resized, STACK_BLUR_RADIUS);
if (result == null) {
Log.w(TAG, "result was null");
@ -80,9 +76,9 @@ public class FastBlurTransformation extends BitmapTransformation {
int wh = w * h;
int div = radius + radius + 1;
int r[] = new int[wh];
int g[] = new int[wh];
int b[] = new int[wh];
int[] r = new int[wh];
int[] g = new int[wh];
int[] b = new int[wh];
int rsum;
int gsum;
int bsum;
@ -93,11 +89,11 @@ public class FastBlurTransformation extends BitmapTransformation {
int yp;
int yi;
int yw;
int vmin[] = new int[Math.max(w, h)];
int[] vmin = new int[Math.max(w, h)];
int divsum = (div + 1) >> 1;
divsum *= divsum;
int dv[] = new int[256 * divsum];
int[] dv = new int[256 * divsum];
for (i = 0; i < 256 * divsum; i++) {
dv[i] = (i / divsum);
}
@ -225,8 +221,8 @@ public class FastBlurTransformation extends BitmapTransformation {
yi = x;
stackpointer = radius;
for (y = 0; y < h; y++) {
// Preserve alpha channel: ( 0xff000000 & pix[yi] )
pix[yi] = (0xff000000 & pix[yi]) | (dv[rsum] << 16) | (dv[gsum] << 8) | dv[bsum];
// Set alpha to 1
pix[yi] = 0xff000000 | (dv[rsum] << 16) | (dv[gsum] << 8) | dv[bsum];
rsum -= routsum;
gsum -= goutsum;