mirror of
https://github.com/wasabeef/glide-transformations.git
synced 2025-10-04 18:03:21 +08:00
Release 4.3.0 (#184)
* refactor: clean code * update: gpuimage * update: min sdk to 21 * refactor: remove support rs * update: gradle plugin * style: fix xml format * update: update gradle properties * release 4.2.1 * update: samples * update: sample * update:changelog * remove comments * change release version
This commit is contained in:
@@ -1 +1 @@
|
||||
<manifest package="jp.wasabeef.glide.transformations"></manifest>
|
||||
<manifest package="jp.wasabeef.glide.transformations" />
|
||||
|
@@ -20,6 +20,7 @@ import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.renderscript.RSRuntimeException;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
@@ -28,6 +29,7 @@ import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||
import java.security.MessageDigest;
|
||||
|
||||
import jp.wasabeef.glide.transformations.internal.FastBlur;
|
||||
import jp.wasabeef.glide.transformations.internal.RSBlur;
|
||||
|
||||
public class BlurTransformation extends BitmapTransformation {
|
||||
|
||||
@@ -35,11 +37,11 @@ public class BlurTransformation extends BitmapTransformation {
|
||||
private static final String ID =
|
||||
"jp.wasabeef.glide.transformations.BlurTransformation." + VERSION;
|
||||
|
||||
private static int MAX_RADIUS = 25;
|
||||
private static int DEFAULT_DOWN_SAMPLING = 1;
|
||||
private static final int MAX_RADIUS = 25;
|
||||
private static final int DEFAULT_DOWN_SAMPLING = 1;
|
||||
|
||||
private int radius;
|
||||
private int sampling;
|
||||
private final int radius;
|
||||
private final int sampling;
|
||||
|
||||
public BlurTransformation() {
|
||||
this(MAX_RADIUS, DEFAULT_DOWN_SAMPLING);
|
||||
@@ -73,7 +75,11 @@ public class BlurTransformation extends BitmapTransformation {
|
||||
paint.setFlags(Paint.FILTER_BITMAP_FLAG);
|
||||
canvas.drawBitmap(toTransform, 0, 0, paint);
|
||||
|
||||
bitmap = FastBlur.blur(bitmap, radius, true);
|
||||
try {
|
||||
bitmap = RSBlur.blur(context, bitmap, radius);
|
||||
} catch (RSRuntimeException e) {
|
||||
bitmap = FastBlur.blur(bitmap, radius, true);
|
||||
}
|
||||
|
||||
return bitmap;
|
||||
}
|
||||
|
@@ -35,7 +35,7 @@ public class ColorFilterTransformation extends BitmapTransformation {
|
||||
private static final String ID =
|
||||
"jp.wasabeef.glide.transformations.ColorFilterTransformation." + VERSION;
|
||||
|
||||
private int color;
|
||||
private final int color;
|
||||
|
||||
public ColorFilterTransformation(int color) {
|
||||
this.color = color;
|
||||
|
@@ -38,8 +38,8 @@ public class CropCircleWithBorderTransformation extends BitmapTransformation {
|
||||
private static final int VERSION = 1;
|
||||
private static final String ID = "jp.wasabeef.glide.transformations.CropCircleWithBorderTransformation." + VERSION;
|
||||
|
||||
private int borderSize;
|
||||
private int borderColor;
|
||||
private final int borderSize;
|
||||
private final int borderColor;
|
||||
|
||||
|
||||
public CropCircleWithBorderTransformation() {
|
||||
|
@@ -30,16 +30,14 @@ import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
|
||||
import jp.wasabeef.glide.transformations.internal.Utils;
|
||||
|
||||
public class MaskTransformation extends BitmapTransformation {
|
||||
|
||||
private static final int VERSION = 1;
|
||||
private static final String ID =
|
||||
"jp.wasabeef.glide.transformations.MaskTransformation." + VERSION;
|
||||
|
||||
private static Paint paint = new Paint();
|
||||
private int maskId;
|
||||
private static final Paint paint = new Paint();
|
||||
private final int maskId;
|
||||
|
||||
static {
|
||||
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
|
||||
@@ -63,7 +61,7 @@ public class MaskTransformation extends BitmapTransformation {
|
||||
Bitmap bitmap = pool.get(width, height, Bitmap.Config.ARGB_8888);
|
||||
bitmap.setHasAlpha(true);
|
||||
|
||||
Drawable mask = Utils.getMaskDrawable(context.getApplicationContext(), maskId);
|
||||
Drawable mask = context.getDrawable(maskId);
|
||||
|
||||
setCanvasBitmapDensity(toTransform, bitmap);
|
||||
|
||||
|
@@ -43,10 +43,10 @@ public class RoundedCornersTransformation extends BitmapTransformation {
|
||||
DIAGONAL_FROM_TOP_LEFT, DIAGONAL_FROM_TOP_RIGHT
|
||||
}
|
||||
|
||||
private int radius;
|
||||
private int diameter;
|
||||
private int margin;
|
||||
private CornerType cornerType;
|
||||
private final int radius;
|
||||
private final int diameter;
|
||||
private final int margin;
|
||||
private final CornerType cornerType;
|
||||
|
||||
public RoundedCornersTransformation(int radius, int margin) {
|
||||
this(radius, margin, CornerType.ALL);
|
||||
|
@@ -1,115 +0,0 @@
|
||||
package jp.wasabeef.glide.transformations;
|
||||
|
||||
/**
|
||||
* Copyright (C) 2020 Wasabeef
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.os.Build;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
|
||||
import jp.wasabeef.glide.transformations.internal.FastBlur;
|
||||
import jp.wasabeef.glide.transformations.internal.RSBlur;
|
||||
import jp.wasabeef.glide.transformations.internal.SupportRSBlur;
|
||||
|
||||
public class SupportRSBlurTransformation extends BitmapTransformation {
|
||||
|
||||
private static final int VERSION = 1;
|
||||
private static final String ID =
|
||||
"jp.wasabeef.glide.transformations.SupportRSBlurTransformation." + VERSION;
|
||||
|
||||
private static int MAX_RADIUS = 25;
|
||||
private static int DEFAULT_DOWN_SAMPLING = 1;
|
||||
|
||||
private int radius;
|
||||
private int sampling;
|
||||
|
||||
public SupportRSBlurTransformation() {
|
||||
this(MAX_RADIUS, DEFAULT_DOWN_SAMPLING);
|
||||
}
|
||||
|
||||
public SupportRSBlurTransformation(int radius) {
|
||||
this(radius, DEFAULT_DOWN_SAMPLING);
|
||||
}
|
||||
|
||||
public SupportRSBlurTransformation(int radius, int sampling) {
|
||||
this.radius = radius;
|
||||
this.sampling = sampling;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
|
||||
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
|
||||
|
||||
int width = toTransform.getWidth();
|
||||
int height = toTransform.getHeight();
|
||||
int scaledWidth = width / sampling;
|
||||
int scaledHeight = height / sampling;
|
||||
|
||||
Bitmap bitmap = pool.get(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
|
||||
|
||||
setCanvasBitmapDensity(toTransform, bitmap);
|
||||
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
canvas.scale(1 / (float) sampling, 1 / (float) sampling);
|
||||
Paint paint = new Paint();
|
||||
paint.setFlags(Paint.FILTER_BITMAP_FLAG);
|
||||
canvas.drawBitmap(toTransform, 0, 0, paint);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
|
||||
try {
|
||||
bitmap = SupportRSBlur.blur(context, bitmap, radius);
|
||||
} catch (NoClassDefFoundError e) {
|
||||
bitmap = RSBlur.blur(context, bitmap, radius);
|
||||
} catch (RuntimeException e) {
|
||||
bitmap = FastBlur.blur(bitmap, radius, true);
|
||||
}
|
||||
} else {
|
||||
bitmap = FastBlur.blur(bitmap, radius, true);
|
||||
}
|
||||
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SupportRSBlurTransformation(radius=" + radius + ", sampling=" + sampling + ")";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof SupportRSBlurTransformation &&
|
||||
((SupportRSBlurTransformation) o).radius == radius &&
|
||||
((SupportRSBlurTransformation) o).sampling == sampling;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return ID.hashCode() + radius * 1000 + sampling * 10;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
|
||||
messageDigest.update((ID + radius + sampling).getBytes(CHARSET));
|
||||
}
|
||||
}
|
@@ -31,7 +31,7 @@ public class BrightnessFilterTransformation extends GPUFilterTransformation {
|
||||
private static final String ID =
|
||||
"jp.wasabeef.glide.transformations.gpu.BrightnessFilterTransformation." + VERSION;
|
||||
|
||||
private float brightness;
|
||||
private final float brightness;
|
||||
|
||||
public BrightnessFilterTransformation() {
|
||||
this(0.0f);
|
||||
|
@@ -31,7 +31,7 @@ public class ContrastFilterTransformation extends GPUFilterTransformation {
|
||||
private static final String ID =
|
||||
"jp.wasabeef.glide.transformations.gpu.ContrastFilterTransformation." + VERSION;
|
||||
|
||||
private float contrast;
|
||||
private final float contrast;
|
||||
|
||||
public ContrastFilterTransformation() {
|
||||
this(1.0f);
|
||||
|
@@ -36,7 +36,7 @@ public class GPUFilterTransformation extends BitmapTransformation {
|
||||
"jp.wasabeef.glide.transformations.gpu.GPUFilterTransformation." + VERSION;
|
||||
private static final byte[] ID_BYTES = ID.getBytes(CHARSET);
|
||||
|
||||
private GPUImageFilter gpuImageFilter;
|
||||
private final GPUImageFilter gpuImageFilter;
|
||||
|
||||
public GPUFilterTransformation(GPUImageFilter filter) {
|
||||
this.gpuImageFilter = filter;
|
||||
|
@@ -34,7 +34,7 @@ public class KuwaharaFilterTransformation extends GPUFilterTransformation {
|
||||
private static final String ID =
|
||||
"jp.wasabeef.glide.transformations.gpu.KuwaharaFilterTransformation." + VERSION;
|
||||
|
||||
private int radius;
|
||||
private final int radius;
|
||||
|
||||
public KuwaharaFilterTransformation() {
|
||||
this(25);
|
||||
|
@@ -33,7 +33,7 @@ public class PixelationFilterTransformation extends GPUFilterTransformation {
|
||||
private static final String ID =
|
||||
"jp.wasabeef.glide.transformations.gpu.PixelationFilterTransformation." + VERSION;
|
||||
|
||||
private float pixel;
|
||||
private final float pixel;
|
||||
|
||||
public PixelationFilterTransformation() {
|
||||
this(10f);
|
||||
|
@@ -33,7 +33,7 @@ public class SepiaFilterTransformation extends GPUFilterTransformation {
|
||||
private static final String ID =
|
||||
"jp.wasabeef.glide.transformations.gpu.SepiaFilterTransformation." + VERSION;
|
||||
|
||||
private float intensity;
|
||||
private final float intensity;
|
||||
|
||||
public SepiaFilterTransformation() {
|
||||
this(1.0f);
|
||||
|
@@ -33,9 +33,9 @@ public class SwirlFilterTransformation extends GPUFilterTransformation {
|
||||
private static final String ID =
|
||||
"jp.wasabeef.glide.transformations.gpu.SwirlFilterTransformation." + VERSION;
|
||||
|
||||
private float radius;
|
||||
private float angle;
|
||||
private PointF center;
|
||||
private final float radius;
|
||||
private final float angle;
|
||||
private final PointF center;
|
||||
|
||||
public SwirlFilterTransformation() {
|
||||
this(.5f, 1.0f, new PointF(0.5f, 0.5f));
|
||||
|
@@ -33,8 +33,8 @@ public class ToonFilterTransformation extends GPUFilterTransformation {
|
||||
private static final String ID =
|
||||
"jp.wasabeef.glide.transformations.gpu.ToonFilterTransformation." + VERSION;
|
||||
|
||||
private float threshold;
|
||||
private float quantizationLevels;
|
||||
private final float threshold;
|
||||
private final float quantizationLevels;
|
||||
|
||||
public ToonFilterTransformation() {
|
||||
this(.2f, 10.0f);
|
||||
|
@@ -36,10 +36,10 @@ public class VignetteFilterTransformation extends GPUFilterTransformation {
|
||||
private static final String ID =
|
||||
"jp.wasabeef.glide.transformations.gpu.VignetteFilterTransformation." + VERSION;
|
||||
|
||||
private PointF center;
|
||||
private float[] vignetteColor;
|
||||
private float vignetteStart;
|
||||
private float vignetteEnd;
|
||||
private final PointF center;
|
||||
private final float[] vignetteColor;
|
||||
private final float vignetteStart;
|
||||
private final float vignetteEnd;
|
||||
|
||||
public VignetteFilterTransformation() {
|
||||
this(new PointF(0.5f, 0.5f), new float[]{0.0f, 0.0f, 0.0f}, 0.0f, 0.75f);
|
||||
|
@@ -28,7 +28,6 @@ import android.renderscript.ScriptIntrinsicBlur;
|
||||
|
||||
public class RSBlur {
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
|
||||
public static Bitmap blur(Context context, Bitmap bitmap, int radius) throws RSRuntimeException {
|
||||
RenderScript rs = null;
|
||||
Allocation input = null;
|
||||
|
@@ -1,71 +0,0 @@
|
||||
package jp.wasabeef.glide.transformations.internal;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Build;
|
||||
|
||||
import androidx.renderscript.Allocation;
|
||||
import androidx.renderscript.Element;
|
||||
import androidx.renderscript.RSRuntimeException;
|
||||
import androidx.renderscript.RenderScript;
|
||||
import androidx.renderscript.ScriptIntrinsicBlur;
|
||||
|
||||
/**
|
||||
* Copyright (C) 2020 Wasabeef
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
public class SupportRSBlur {
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
|
||||
public static Bitmap blur(Context context, Bitmap bitmap, int radius) throws RSRuntimeException {
|
||||
RenderScript rs = null;
|
||||
Allocation input = null;
|
||||
Allocation output = null;
|
||||
ScriptIntrinsicBlur blur = null;
|
||||
try {
|
||||
rs = RenderScript.create(context);
|
||||
rs.setMessageHandler(new RenderScript.RSMessageHandler());
|
||||
input = Allocation.createFromBitmap(rs, bitmap, Allocation.MipmapControl.MIPMAP_NONE,
|
||||
Allocation.USAGE_SCRIPT);
|
||||
output = Allocation.createTyped(rs, input.getType());
|
||||
blur = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
|
||||
|
||||
blur.setInput(input);
|
||||
blur.setRadius(radius);
|
||||
blur.forEach(output);
|
||||
output.copyTo(bitmap);
|
||||
} finally {
|
||||
if (rs != null) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
RenderScript.releaseAllContexts();
|
||||
} else {
|
||||
rs.destroy();
|
||||
}
|
||||
}
|
||||
if (input != null) {
|
||||
input.destroy();
|
||||
}
|
||||
if (output != null) {
|
||||
output.destroy();
|
||||
}
|
||||
if (blur != null) {
|
||||
blur.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
return bitmap;
|
||||
}
|
||||
}
|
@@ -27,21 +27,6 @@ public final class Utils {
|
||||
// Utility class.
|
||||
}
|
||||
|
||||
public static Drawable getMaskDrawable(Context context, int maskId) {
|
||||
Drawable drawable;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
drawable = context.getDrawable(maskId);
|
||||
} else {
|
||||
drawable = context.getResources().getDrawable(maskId);
|
||||
}
|
||||
|
||||
if (drawable == null) {
|
||||
throw new IllegalArgumentException("maskId is invalid");
|
||||
}
|
||||
|
||||
return drawable;
|
||||
}
|
||||
|
||||
public static int toDp(int px) {
|
||||
return px * (int) Resources.getSystem().getDisplayMetrics().density;
|
||||
}
|
||||
|
Reference in New Issue
Block a user