mirror of
https://github.com/wasabeef/glide-transformations.git
synced 2025-10-04 09:53:21 +08:00
@@ -1,37 +1,39 @@
|
||||
apply plugin: 'com.android.library'
|
||||
apply plugin: 'com.novoda.bintray-release'
|
||||
|
||||
android {
|
||||
compileSdkVersion COMPILE_SDK_VERSION as int
|
||||
buildToolsVersion BUILD_TOOLS_VERSION
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion MIN_SDK_VERSION as int
|
||||
targetSdkVersion TARGET_SDK_VERSION as int
|
||||
versionCode "git rev-list origin/master --count".execute().text.toInteger()
|
||||
versionName VERSION_NAME
|
||||
|
||||
renderscriptTargetApi TARGET_SDK_VERSION as int
|
||||
renderscriptSupportModeEnabled true
|
||||
|
||||
consumerProguardFiles 'proguard-rules.txt'
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation "com.github.bumptech.glide:glide:${GLIDE_VERSION}"
|
||||
annotationProcessor "com.github.bumptech.glide:compiler:${GLIDE_VERSION}"
|
||||
compileOnly "jp.co.cyberagent.android.gpuimage:gpuimage-library:${GPUIMAGE_VERSION}"
|
||||
implementation "com.github.bumptech.glide:glide:$glide_version"
|
||||
annotationProcessor "com.github.bumptech.glide:compiler:$glide_version"
|
||||
compileOnly "jp.co.cyberagent.android:gpuimage:$gpuimage_version"
|
||||
}
|
||||
|
||||
publish {
|
||||
userOrg = POM_DEVELOPER_ID
|
||||
groupId = GROUP
|
||||
artifactId = ARTIFACT_ID
|
||||
publishVersion = VERSION_NAME
|
||||
desc = POM_DESCRIPTION
|
||||
website = POM_URL
|
||||
bintrayUser = BINTRAY_USER
|
||||
bintrayKey = BINTRAY_API_KEY
|
||||
autoPublish = false
|
||||
ext {
|
||||
bintrayRepo = 'maven'
|
||||
bintrayName = 'glide-transformations'
|
||||
bintrayUserOrg = 'wasabeef'
|
||||
publishedGroupId = 'jp.wasabeef'
|
||||
libraryName = 'glide-transformations'
|
||||
artifact = 'glide-transformations'
|
||||
libraryDescription = 'Which provides simple Tranformations to Glide'
|
||||
siteUrl = 'https://github.com/wasabeef/glide-transformations'
|
||||
gitUrl = 'https://github.com/wasabeef/glide-transformations.git'
|
||||
issueUrl = 'https://github.com/wasabeef/glide-transformations/issues'
|
||||
libraryVersion = VERSION_NAME
|
||||
developerId = 'wasabeef'
|
||||
developerName = 'Wasabeef'
|
||||
developerEmail = 'dadadada.chop@gmail.com'
|
||||
licenseName = 'The Apache Software License, Version 2.0'
|
||||
licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
|
||||
allLicenses = ["Apache-2.0"]
|
||||
}
|
||||
|
||||
apply from: 'https://gist.githubusercontent.com/wasabeef/cf14805bee509baf7461974582f17d26/raw/bintray-v1.gradle'
|
||||
apply from: 'https://gist.githubusercontent.com/wasabeef/cf14805bee509baf7461974582f17d26/raw/install-v1.gradle'
|
@@ -2,7 +2,7 @@
|
||||
|
||||
-keep public class * implements com.bumptech.glide.module.GlideModule
|
||||
-keep public class * extends com.bumptech.glide.module.AppGlideModule
|
||||
-keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** {
|
||||
-keep public enum com.bumptech.glide.load.ImageHeaderParser$** {
|
||||
**[] $VALUES;
|
||||
public *;
|
||||
}
|
||||
|
@@ -19,7 +19,7 @@ package jp.wasabeef.glide.transformations;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.Transformation;
|
||||
import com.bumptech.glide.load.engine.Resource;
|
||||
@@ -27,8 +27,11 @@ import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
|
||||
import com.bumptech.glide.request.target.Target;
|
||||
import com.bumptech.glide.util.Util;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
public abstract class BitmapTransformation implements Transformation<Bitmap> {
|
||||
|
||||
@NonNull
|
||||
@@ -56,11 +59,14 @@ public abstract class BitmapTransformation implements Transformation<Bitmap> {
|
||||
}
|
||||
|
||||
protected abstract Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
|
||||
@NonNull Bitmap toTransform, int outWidth, int outHeight);
|
||||
@NonNull Bitmap toTransform, int outWidth, int outHeight);
|
||||
|
||||
@Override public abstract void updateDiskCacheKey(@NonNull MessageDigest messageDigest);
|
||||
@Override
|
||||
public abstract void updateDiskCacheKey(@NonNull MessageDigest messageDigest);
|
||||
|
||||
@Override public abstract boolean equals(Object o);
|
||||
@Override
|
||||
public abstract boolean equals(Object o);
|
||||
|
||||
@Override public abstract int hashCode();
|
||||
@Override
|
||||
public abstract int hashCode();
|
||||
}
|
||||
|
@@ -20,13 +20,13 @@ import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.os.Build;
|
||||
import android.renderscript.RSRuntimeException;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import jp.wasabeef.glide.transformations.internal.FastBlur;
|
||||
import jp.wasabeef.glide.transformations.internal.RSBlur;
|
||||
|
||||
public class BlurTransformation extends BitmapTransformation {
|
||||
|
||||
@@ -53,8 +53,9 @@ public class BlurTransformation extends BitmapTransformation {
|
||||
this.sampling = sampling;
|
||||
}
|
||||
|
||||
@Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
|
||||
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
|
||||
@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();
|
||||
@@ -74,21 +75,25 @@ public class BlurTransformation extends BitmapTransformation {
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
@Override public String toString() {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "BlurTransformation(radius=" + radius + ", sampling=" + sampling + ")";
|
||||
}
|
||||
|
||||
@Override public boolean equals(Object o) {
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof BlurTransformation &&
|
||||
((BlurTransformation) o).radius == radius &&
|
||||
((BlurTransformation) o).sampling == sampling;
|
||||
}
|
||||
|
||||
@Override public int hashCode() {
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return ID.hashCode() + radius * 1000 + sampling * 10;
|
||||
}
|
||||
|
||||
@Override public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
|
||||
@Override
|
||||
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
|
||||
messageDigest.update((ID + radius + sampling).getBytes(CHARSET));
|
||||
}
|
||||
}
|
||||
|
@@ -22,10 +22,13 @@ import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.PorterDuffColorFilter;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
public class ColorFilterTransformation extends BitmapTransformation {
|
||||
|
||||
private static final int VERSION = 1;
|
||||
@@ -38,8 +41,9 @@ public class ColorFilterTransformation extends BitmapTransformation {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
@Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
|
||||
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
|
||||
@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();
|
||||
|
||||
@@ -56,20 +60,24 @@ public class ColorFilterTransformation extends BitmapTransformation {
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
@Override public String toString() {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ColorFilterTransformation(color=" + color + ")";
|
||||
}
|
||||
|
||||
@Override public boolean equals(Object o) {
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof ColorFilterTransformation &&
|
||||
((ColorFilterTransformation) o).color == color;
|
||||
}
|
||||
|
||||
@Override public int hashCode() {
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return ID.hashCode() + color * 10;
|
||||
}
|
||||
|
||||
@Override public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
|
||||
@Override
|
||||
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
|
||||
messageDigest.update((ID + color).getBytes(CHARSET));
|
||||
}
|
||||
}
|
||||
|
@@ -18,12 +18,15 @@ package jp.wasabeef.glide.transformations;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||
import com.bumptech.glide.load.resource.bitmap.TransformationUtils;
|
||||
import com.bumptech.glide.request.RequestOptions;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link RequestOptions#circleCrop()}.
|
||||
*/
|
||||
@@ -34,24 +37,29 @@ public class CropCircleTransformation extends BitmapTransformation {
|
||||
private static final String ID =
|
||||
"jp.wasabeef.glide.transformations.CropCircleTransformation." + VERSION;
|
||||
|
||||
@Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
|
||||
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
|
||||
@Override
|
||||
protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
|
||||
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
|
||||
return TransformationUtils.circleCrop(pool, toTransform, outWidth, outHeight);
|
||||
}
|
||||
|
||||
@Override public String toString() {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CropCircleTransformation()";
|
||||
}
|
||||
|
||||
@Override public boolean equals(Object o) {
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof CropCircleTransformation;
|
||||
}
|
||||
|
||||
@Override public int hashCode() {
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return ID.hashCode();
|
||||
}
|
||||
|
||||
@Override public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
|
||||
@Override
|
||||
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
|
||||
messageDigest.update((ID).getBytes(CHARSET));
|
||||
}
|
||||
}
|
||||
|
@@ -18,11 +18,14 @@ package jp.wasabeef.glide.transformations;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||
import com.bumptech.glide.load.resource.bitmap.TransformationUtils;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
public class CropSquareTransformation extends BitmapTransformation {
|
||||
|
||||
private static final int VERSION = 1;
|
||||
@@ -31,25 +34,30 @@ public class CropSquareTransformation extends BitmapTransformation {
|
||||
|
||||
private int size;
|
||||
|
||||
@Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
|
||||
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
|
||||
@Override
|
||||
protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
|
||||
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
|
||||
this.size = Math.max(outWidth, outHeight);
|
||||
return TransformationUtils.centerCrop(pool, toTransform, size, size);
|
||||
}
|
||||
|
||||
@Override public String toString() {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CropSquareTransformation(size=" + size + ")";
|
||||
}
|
||||
|
||||
@Override public boolean equals(Object o) {
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof CropSquareTransformation && ((CropSquareTransformation) o).size == size;
|
||||
}
|
||||
|
||||
@Override public int hashCode() {
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return ID.hashCode() + size * 10;
|
||||
}
|
||||
|
||||
@Override public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
|
||||
@Override
|
||||
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
|
||||
messageDigest.update((ID + size).getBytes(CHARSET));
|
||||
}
|
||||
}
|
||||
|
@@ -20,10 +20,13 @@ import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.RectF;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
public class CropTransformation extends BitmapTransformation {
|
||||
|
||||
private static final int VERSION = 1;
|
||||
@@ -50,8 +53,9 @@ public class CropTransformation extends BitmapTransformation {
|
||||
this.cropType = cropType;
|
||||
}
|
||||
|
||||
@Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
|
||||
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
|
||||
@Override
|
||||
protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
|
||||
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
|
||||
|
||||
width = width == 0 ? toTransform.getWidth() : width;
|
||||
height = height == 0 ? toTransform.getHeight() : height;
|
||||
@@ -91,22 +95,26 @@ public class CropTransformation extends BitmapTransformation {
|
||||
}
|
||||
}
|
||||
|
||||
@Override public String toString() {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CropTransformation(width=" + width + ", height=" + height + ", cropType=" + cropType + ")";
|
||||
}
|
||||
|
||||
@Override public boolean equals(Object o) {
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof CropTransformation &&
|
||||
((CropTransformation) o).width == width &&
|
||||
((CropTransformation) o).height == height &&
|
||||
((CropTransformation) o).cropType == cropType;
|
||||
}
|
||||
|
||||
@Override public int hashCode() {
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return ID.hashCode() + width * 100000 + height * 1000 + cropType.ordinal() * 10;
|
||||
}
|
||||
|
||||
@Override public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
|
||||
@Override
|
||||
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
|
||||
messageDigest.update((ID + width + height + cropType).getBytes(CHARSET));
|
||||
}
|
||||
}
|
||||
|
@@ -22,18 +22,22 @@ import android.graphics.Canvas;
|
||||
import android.graphics.ColorMatrix;
|
||||
import android.graphics.ColorMatrixColorFilter;
|
||||
import android.graphics.Paint;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
public class GrayscaleTransformation extends BitmapTransformation {
|
||||
|
||||
private static final int VERSION = 1;
|
||||
private static final String ID =
|
||||
"jp.wasabeef.glide.transformations.GrayscaleTransformation." + VERSION;
|
||||
|
||||
@Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
|
||||
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
|
||||
@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();
|
||||
|
||||
@@ -51,19 +55,23 @@ public class GrayscaleTransformation extends BitmapTransformation {
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
@Override public String toString() {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "GrayscaleTransformation()";
|
||||
}
|
||||
|
||||
@Override public boolean equals(Object o) {
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof GrayscaleTransformation;
|
||||
}
|
||||
|
||||
@Override public int hashCode() {
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return ID.hashCode();
|
||||
}
|
||||
|
||||
@Override public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
|
||||
@Override
|
||||
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
|
||||
messageDigest.update((ID).getBytes(CHARSET));
|
||||
}
|
||||
}
|
||||
|
@@ -23,9 +23,12 @@ import android.graphics.Paint;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.PorterDuffXfermode;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import jp.wasabeef.glide.transformations.internal.Utils;
|
||||
|
||||
public class MaskTransformation extends BitmapTransformation {
|
||||
@@ -43,15 +46,16 @@ public class MaskTransformation extends BitmapTransformation {
|
||||
|
||||
/**
|
||||
* @param maskId If you change the mask file, please also rename the mask file, or Glide will get
|
||||
* the cache with the old mask. Because key() return the same values if using the
|
||||
* same make file name. If you have a good idea please tell us, thanks.
|
||||
* the cache with the old mask. Because key() return the same values if using the
|
||||
* same make file name. If you have a good idea please tell us, thanks.
|
||||
*/
|
||||
public MaskTransformation(int maskId) {
|
||||
this.maskId = maskId;
|
||||
}
|
||||
|
||||
@Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
|
||||
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
|
||||
@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();
|
||||
|
||||
@@ -68,20 +72,24 @@ public class MaskTransformation extends BitmapTransformation {
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
@Override public String toString() {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "MaskTransformation(maskId=" + maskId + ")";
|
||||
}
|
||||
|
||||
@Override public boolean equals(Object o) {
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof MaskTransformation &&
|
||||
((MaskTransformation) o).maskId == maskId;
|
||||
}
|
||||
|
||||
@Override public int hashCode() {
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return ID.hashCode() + maskId * 10;
|
||||
}
|
||||
|
||||
@Override public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
|
||||
@Override
|
||||
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
|
||||
messageDigest.update((ID + maskId).getBytes(CHARSET));
|
||||
}
|
||||
}
|
||||
|
@@ -23,11 +23,13 @@ import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.RectF;
|
||||
import android.graphics.Shader;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
public class RoundedCornersTransformation extends BitmapTransformation {
|
||||
|
||||
private static final int VERSION = 1;
|
||||
@@ -57,8 +59,9 @@ public class RoundedCornersTransformation extends BitmapTransformation {
|
||||
this.cornerType = cornerType;
|
||||
}
|
||||
|
||||
@Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
|
||||
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
|
||||
@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();
|
||||
|
||||
@@ -203,7 +206,7 @@ public class RoundedCornersTransformation extends BitmapTransformation {
|
||||
}
|
||||
|
||||
private void drawOtherBottomRightRoundRect(Canvas canvas, Paint paint, float right,
|
||||
float bottom) {
|
||||
float bottom) {
|
||||
canvas.drawRoundRect(new RectF(margin, margin, right, margin + diameter), radius, radius,
|
||||
paint);
|
||||
canvas.drawRoundRect(new RectF(margin, margin, margin + diameter, bottom), radius, radius,
|
||||
@@ -212,7 +215,7 @@ public class RoundedCornersTransformation extends BitmapTransformation {
|
||||
}
|
||||
|
||||
private void drawDiagonalFromTopLeftRoundRect(Canvas canvas, Paint paint, float right,
|
||||
float bottom) {
|
||||
float bottom) {
|
||||
canvas.drawRoundRect(new RectF(margin, margin, margin + diameter, margin + diameter), radius,
|
||||
radius, paint);
|
||||
canvas.drawRoundRect(new RectF(right - diameter, bottom - diameter, right, bottom), radius,
|
||||
@@ -222,7 +225,7 @@ public class RoundedCornersTransformation extends BitmapTransformation {
|
||||
}
|
||||
|
||||
private void drawDiagonalFromTopRightRoundRect(Canvas canvas, Paint paint, float right,
|
||||
float bottom) {
|
||||
float bottom) {
|
||||
canvas.drawRoundRect(new RectF(right - diameter, margin, right, margin + diameter), radius,
|
||||
radius, paint);
|
||||
canvas.drawRoundRect(new RectF(margin, bottom - diameter, margin + diameter, bottom), radius,
|
||||
@@ -231,12 +234,14 @@ public class RoundedCornersTransformation extends BitmapTransformation {
|
||||
canvas.drawRect(new RectF(margin + radius, margin + radius, right, bottom), paint);
|
||||
}
|
||||
|
||||
@Override public String toString() {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "RoundedTransformation(radius=" + radius + ", margin=" + margin + ", diameter="
|
||||
+ diameter + ", cornerType=" + cornerType.name() + ")";
|
||||
}
|
||||
|
||||
@Override public boolean equals(Object o) {
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof RoundedCornersTransformation &&
|
||||
((RoundedCornersTransformation) o).radius == radius &&
|
||||
((RoundedCornersTransformation) o).diameter == diameter &&
|
||||
@@ -244,11 +249,13 @@ public class RoundedCornersTransformation extends BitmapTransformation {
|
||||
((RoundedCornersTransformation) o).cornerType == cornerType;
|
||||
}
|
||||
|
||||
@Override public int hashCode() {
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return ID.hashCode() + radius * 10000 + diameter * 1000 + margin * 100 + cornerType.ordinal() * 10;
|
||||
}
|
||||
|
||||
@Override public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
|
||||
@Override
|
||||
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
|
||||
messageDigest.update((ID + radius + diameter + margin + cornerType).getBytes(CHARSET));
|
||||
}
|
||||
}
|
||||
|
@@ -21,82 +21,90 @@ import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.os.Build;
|
||||
import android.support.v8.renderscript.RSRuntimeException;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.renderscript.RSRuntimeException;
|
||||
|
||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import jp.wasabeef.glide.transformations.internal.FastBlur;
|
||||
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 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 static int MAX_RADIUS = 25;
|
||||
private static int DEFAULT_DOWN_SAMPLING = 1;
|
||||
|
||||
private int radius;
|
||||
private int sampling;
|
||||
private int radius;
|
||||
private int sampling;
|
||||
|
||||
public SupportRSBlurTransformation() {
|
||||
this(MAX_RADIUS, DEFAULT_DOWN_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);
|
||||
|
||||
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 (RSRuntimeException e) {
|
||||
bitmap = FastBlur.blur(bitmap, radius, true);
|
||||
}
|
||||
} else {
|
||||
bitmap = FastBlur.blur(bitmap, radius, true);
|
||||
}
|
||||
|
||||
public SupportRSBlurTransformation(int radius) {
|
||||
this(radius, DEFAULT_DOWN_SAMPLING);
|
||||
}
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
public SupportRSBlurTransformation(int radius, int sampling) {
|
||||
this.radius = radius;
|
||||
this.sampling = sampling;
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SupportRSBlurTransformation(radius=" + radius + ", sampling=" + sampling + ")";
|
||||
}
|
||||
|
||||
@Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
|
||||
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof SupportRSBlurTransformation &&
|
||||
((SupportRSBlurTransformation) o).radius == radius &&
|
||||
((SupportRSBlurTransformation) o).sampling == sampling;
|
||||
}
|
||||
|
||||
int width = toTransform.getWidth();
|
||||
int height = toTransform.getHeight();
|
||||
int scaledWidth = width / sampling;
|
||||
int scaledHeight = height / sampling;
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return ID.hashCode() + radius * 1000 + sampling * 10;
|
||||
}
|
||||
|
||||
Bitmap bitmap = pool.get(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
|
||||
|
||||
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 (RSRuntimeException 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));
|
||||
}
|
||||
@Override
|
||||
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
|
||||
messageDigest.update((ID + radius + sampling).getBytes(CHARSET));
|
||||
}
|
||||
}
|
||||
|
@@ -16,10 +16,10 @@ package jp.wasabeef.glide.transformations.gpu;
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImageBrightnessFilter;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import jp.co.cyberagent.android.gpuimage.filter.GPUImageBrightnessFilter;
|
||||
|
||||
/**
|
||||
* brightness value ranges from -1.0 to 1.0, with 0.0 as the normal level
|
||||
@@ -43,20 +43,24 @@ public class BrightnessFilterTransformation extends GPUFilterTransformation {
|
||||
filter.setBrightness(this.brightness);
|
||||
}
|
||||
|
||||
@Override public String toString() {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "BrightnessFilterTransformation(brightness=" + brightness + ")";
|
||||
}
|
||||
|
||||
@Override public boolean equals(Object o) {
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof BrightnessFilterTransformation &&
|
||||
((BrightnessFilterTransformation) o).brightness == brightness;
|
||||
}
|
||||
|
||||
@Override public int hashCode() {
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return ID.hashCode() + (int) ((brightness + 1.0f) * 10);
|
||||
}
|
||||
|
||||
@Override public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
|
||||
@Override
|
||||
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
|
||||
messageDigest.update((ID + brightness).getBytes(CHARSET));
|
||||
}
|
||||
}
|
||||
|
@@ -16,10 +16,10 @@ package jp.wasabeef.glide.transformations.gpu;
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImageContrastFilter;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import jp.co.cyberagent.android.gpuimage.filter.GPUImageContrastFilter;
|
||||
|
||||
/**
|
||||
* contrast value ranges from 0.0 to 4.0, with 1.0 as the normal level
|
||||
@@ -43,19 +43,23 @@ public class ContrastFilterTransformation extends GPUFilterTransformation {
|
||||
filter.setContrast(this.contrast);
|
||||
}
|
||||
|
||||
@Override public String toString() {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ContrastFilterTransformation(contrast=" + contrast + ")";
|
||||
}
|
||||
|
||||
@Override public boolean equals(Object o) {
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof ContrastFilterTransformation;
|
||||
}
|
||||
|
||||
@Override public int hashCode() {
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return ID.hashCode() + (int) (contrast * 10);
|
||||
}
|
||||
|
||||
@Override public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
|
||||
@Override
|
||||
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
|
||||
messageDigest.update((ID + contrast).getBytes(CHARSET));
|
||||
}
|
||||
}
|
||||
|
@@ -18,11 +18,14 @@ package jp.wasabeef.glide.transformations.gpu;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImage;
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImageFilter;
|
||||
import jp.co.cyberagent.android.gpuimage.filter.GPUImageFilter;
|
||||
import jp.wasabeef.glide.transformations.BitmapTransformation;
|
||||
|
||||
public class GPUFilterTransformation extends BitmapTransformation {
|
||||
@@ -38,8 +41,9 @@ public class GPUFilterTransformation extends BitmapTransformation {
|
||||
this.gpuImageFilter = filter;
|
||||
}
|
||||
|
||||
@Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
|
||||
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
|
||||
@Override
|
||||
protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
|
||||
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
|
||||
GPUImage gpuImage = new GPUImage(context);
|
||||
gpuImage.setImage(toTransform);
|
||||
gpuImage.setFilter(gpuImageFilter);
|
||||
@@ -47,23 +51,28 @@ public class GPUFilterTransformation extends BitmapTransformation {
|
||||
return gpuImage.getBitmapWithFilterApplied();
|
||||
}
|
||||
|
||||
@Override public String toString() {
|
||||
@Override
|
||||
public String toString() {
|
||||
return getClass().getSimpleName();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked") public <T> T getFilter() {
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T getFilter() {
|
||||
return (T) gpuImageFilter;
|
||||
}
|
||||
|
||||
@Override public boolean equals(Object o) {
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof GPUFilterTransformation;
|
||||
}
|
||||
|
||||
@Override public int hashCode() {
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return ID.hashCode();
|
||||
}
|
||||
|
||||
@Override public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
|
||||
@Override
|
||||
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
|
||||
messageDigest.update(ID_BYTES);
|
||||
}
|
||||
}
|
||||
|
@@ -16,10 +16,10 @@ package jp.wasabeef.glide.transformations.gpu;
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImageColorInvertFilter;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import jp.co.cyberagent.android.gpuimage.filter.GPUImageColorInvertFilter;
|
||||
|
||||
/**
|
||||
* Invert all the colors in the image.
|
||||
@@ -34,19 +34,23 @@ public class InvertFilterTransformation extends GPUFilterTransformation {
|
||||
super(new GPUImageColorInvertFilter());
|
||||
}
|
||||
|
||||
@Override public String toString() {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "InvertFilterTransformation()";
|
||||
}
|
||||
|
||||
@Override public boolean equals(Object o) {
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof InvertFilterTransformation;
|
||||
}
|
||||
|
||||
@Override public int hashCode() {
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return ID.hashCode();
|
||||
}
|
||||
|
||||
@Override public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
|
||||
@Override
|
||||
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
|
||||
messageDigest.update((ID).getBytes(CHARSET));
|
||||
}
|
||||
}
|
||||
|
@@ -16,10 +16,10 @@ package jp.wasabeef.glide.transformations.gpu;
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImageKuwaharaFilter;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import jp.co.cyberagent.android.gpuimage.filter.GPUImageKuwaharaFilter;
|
||||
|
||||
/**
|
||||
* Kuwahara all the colors in the image.
|
||||
@@ -46,19 +46,23 @@ public class KuwaharaFilterTransformation extends GPUFilterTransformation {
|
||||
filter.setRadius(this.radius);
|
||||
}
|
||||
|
||||
@Override public String toString() {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "KuwaharaFilterTransformation(radius=" + radius + ")";
|
||||
}
|
||||
|
||||
@Override public boolean equals(Object o) {
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof KuwaharaFilterTransformation;
|
||||
}
|
||||
|
||||
@Override public int hashCode() {
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return ID.hashCode() + radius * 10;
|
||||
}
|
||||
|
||||
@Override public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
|
||||
@Override
|
||||
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
|
||||
messageDigest.update((ID + radius).getBytes(CHARSET));
|
||||
}
|
||||
}
|
||||
|
@@ -16,10 +16,10 @@ package jp.wasabeef.glide.transformations.gpu;
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImagePixelationFilter;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import jp.co.cyberagent.android.gpuimage.filter.GPUImagePixelationFilter;
|
||||
|
||||
/**
|
||||
* Applies a Pixelation effect to the image.
|
||||
@@ -45,19 +45,23 @@ public class PixelationFilterTransformation extends GPUFilterTransformation {
|
||||
filter.setPixel(this.pixel);
|
||||
}
|
||||
|
||||
@Override public String toString() {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PixelationFilterTransformation(pixel=" + pixel + ")";
|
||||
}
|
||||
|
||||
@Override public boolean equals(Object o) {
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof PixelationFilterTransformation;
|
||||
}
|
||||
|
||||
@Override public int hashCode() {
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return ID.hashCode() + (int) (pixel * 10);
|
||||
}
|
||||
|
||||
@Override public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
|
||||
@Override
|
||||
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
|
||||
messageDigest.update((ID + pixel).getBytes(CHARSET));
|
||||
}
|
||||
}
|
||||
|
@@ -2,13 +2,13 @@ package jp.wasabeef.glide.transformations.gpu;
|
||||
|
||||
/**
|
||||
* Copyright (C) 2018 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.
|
||||
@@ -16,10 +16,10 @@ package jp.wasabeef.glide.transformations.gpu;
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImageSepiaFilter;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import jp.co.cyberagent.android.gpuimage.filter.GPUImageSepiaToneFilter;
|
||||
|
||||
/**
|
||||
* Applies a simple sepia effect.
|
||||
@@ -39,25 +39,29 @@ public class SepiaFilterTransformation extends GPUFilterTransformation {
|
||||
}
|
||||
|
||||
public SepiaFilterTransformation(float intensity) {
|
||||
super(new GPUImageSepiaFilter());
|
||||
super(new GPUImageSepiaToneFilter());
|
||||
this.intensity = intensity;
|
||||
GPUImageSepiaFilter filter = getFilter();
|
||||
GPUImageSepiaToneFilter filter = getFilter();
|
||||
filter.setIntensity(this.intensity);
|
||||
}
|
||||
|
||||
@Override public String toString() {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SepiaFilterTransformation(intensity=" + intensity + ")";
|
||||
}
|
||||
|
||||
@Override public boolean equals(Object o) {
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof SepiaFilterTransformation;
|
||||
}
|
||||
|
||||
@Override public int hashCode() {
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return ID.hashCode() + (int) (intensity * 10);
|
||||
}
|
||||
|
||||
@Override public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
|
||||
@Override
|
||||
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
|
||||
messageDigest.update((ID + intensity).getBytes(CHARSET));
|
||||
}
|
||||
}
|
||||
|
@@ -16,10 +16,10 @@ package jp.wasabeef.glide.transformations.gpu;
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImageSketchFilter;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import jp.co.cyberagent.android.gpuimage.filter.GPUImageSketchFilter;
|
||||
|
||||
public class SketchFilterTransformation extends GPUFilterTransformation {
|
||||
|
||||
@@ -31,19 +31,23 @@ public class SketchFilterTransformation extends GPUFilterTransformation {
|
||||
super(new GPUImageSketchFilter());
|
||||
}
|
||||
|
||||
@Override public String toString() {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SketchFilterTransformation()";
|
||||
}
|
||||
|
||||
@Override public boolean equals(Object o) {
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof SketchFilterTransformation;
|
||||
}
|
||||
|
||||
@Override public int hashCode() {
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return ID.hashCode();
|
||||
}
|
||||
|
||||
@Override public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
|
||||
@Override
|
||||
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
|
||||
messageDigest.update((ID).getBytes(CHARSET));
|
||||
}
|
||||
}
|
||||
|
@@ -17,10 +17,11 @@ package jp.wasabeef.glide.transformations.gpu;
|
||||
*/
|
||||
|
||||
import android.graphics.PointF;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImageSwirlFilter;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import jp.co.cyberagent.android.gpuimage.filter.GPUImageSwirlFilter;
|
||||
|
||||
/**
|
||||
* Creates a swirl distortion on the image.
|
||||
@@ -41,7 +42,7 @@ public class SwirlFilterTransformation extends GPUFilterTransformation {
|
||||
|
||||
/**
|
||||
* @param radius from 0.0 to 1.0, default 0.5
|
||||
* @param angle minimum 0.0, default 1.0
|
||||
* @param angle minimum 0.0, default 1.0
|
||||
* @param center default (0.5, 0.5)
|
||||
*/
|
||||
public SwirlFilterTransformation(float radius, float angle, PointF center) {
|
||||
@@ -55,23 +56,27 @@ public class SwirlFilterTransformation extends GPUFilterTransformation {
|
||||
filter.setCenter(this.center);
|
||||
}
|
||||
|
||||
@Override public String toString() {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SwirlFilterTransformation(radius=" + radius + ",angle=" + angle + ",center="
|
||||
+ center.toString() + ")";
|
||||
}
|
||||
|
||||
@Override public boolean equals(Object o) {
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof SwirlFilterTransformation &&
|
||||
((SwirlFilterTransformation) o).radius == radius &&
|
||||
((SwirlFilterTransformation) o).angle == radius &&
|
||||
((SwirlFilterTransformation) o).center.equals(center.x, center.y);
|
||||
}
|
||||
|
||||
@Override public int hashCode() {
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return ID.hashCode() + (int) (radius * 1000) + (int) (angle * 10) + center.hashCode();
|
||||
}
|
||||
|
||||
@Override public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
|
||||
@Override
|
||||
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
|
||||
messageDigest.update((ID + radius + angle + center.hashCode()).getBytes(CHARSET));
|
||||
}
|
||||
}
|
||||
|
@@ -16,10 +16,10 @@ package jp.wasabeef.glide.transformations.gpu;
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImageToonFilter;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import jp.co.cyberagent.android.gpuimage.filter.GPUImageToonFilter;
|
||||
|
||||
/**
|
||||
* The threshold at which to apply the edges, default of 0.2.
|
||||
@@ -48,22 +48,26 @@ public class ToonFilterTransformation extends GPUFilterTransformation {
|
||||
filter.setQuantizationLevels(this.quantizationLevels);
|
||||
}
|
||||
|
||||
@Override public String toString() {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ToonFilterTransformation(threshold=" + threshold + ",quantizationLevels="
|
||||
+ quantizationLevels + ")";
|
||||
}
|
||||
|
||||
@Override public boolean equals(Object o) {
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof ToonFilterTransformation &&
|
||||
((ToonFilterTransformation) o).threshold == threshold &&
|
||||
((ToonFilterTransformation) o).quantizationLevels == quantizationLevels;
|
||||
}
|
||||
|
||||
@Override public int hashCode() {
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return ID.hashCode() + (int) (threshold * 1000) + (int) (quantizationLevels * 10);
|
||||
}
|
||||
|
||||
@Override public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
|
||||
@Override
|
||||
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
|
||||
messageDigest.update((ID + threshold + quantizationLevels).getBytes(CHARSET));
|
||||
}
|
||||
}
|
||||
|
@@ -17,11 +17,12 @@ package jp.wasabeef.glide.transformations.gpu;
|
||||
*/
|
||||
|
||||
import android.graphics.PointF;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import java.util.Arrays;
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImageVignetteFilter;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import jp.co.cyberagent.android.gpuimage.filter.GPUImageVignetteFilter;
|
||||
|
||||
/**
|
||||
* Performs a vignetting effect, fading out the image at the edges
|
||||
@@ -40,7 +41,7 @@ public class VignetteFilterTransformation extends GPUFilterTransformation {
|
||||
private float vignetteEnd;
|
||||
|
||||
public VignetteFilterTransformation() {
|
||||
this(new PointF(0.5f, 0.5f), new float[] { 0.0f, 0.0f, 0.0f }, 0.0f, 0.75f);
|
||||
this(new PointF(0.5f, 0.5f), new float[]{0.0f, 0.0f, 0.0f}, 0.0f, 0.75f);
|
||||
}
|
||||
|
||||
public VignetteFilterTransformation(PointF center, float[] color, float start, float end) {
|
||||
@@ -56,25 +57,29 @@ public class VignetteFilterTransformation extends GPUFilterTransformation {
|
||||
filter.setVignetteEnd(vignetteEnd);
|
||||
}
|
||||
|
||||
@Override public String toString() {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "VignetteFilterTransformation(center=" + center.toString() + ",color=" + Arrays.toString(
|
||||
vignetteColor) + ",start=" + vignetteStart + ",end=" + vignetteEnd + ")";
|
||||
}
|
||||
|
||||
@Override public boolean equals(Object o) {
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof VignetteFilterTransformation &&
|
||||
((VignetteFilterTransformation) o).center.equals(center.x, center.y) &&
|
||||
Arrays.equals(((VignetteFilterTransformation) o).vignetteColor, vignetteColor) &&
|
||||
((VignetteFilterTransformation) o).vignetteStart == vignetteStart &&
|
||||
((VignetteFilterTransformation) o).vignetteEnd == vignetteEnd;
|
||||
((VignetteFilterTransformation) o).center.equals(center.x, center.y) &&
|
||||
Arrays.equals(((VignetteFilterTransformation) o).vignetteColor, vignetteColor) &&
|
||||
((VignetteFilterTransformation) o).vignetteStart == vignetteStart &&
|
||||
((VignetteFilterTransformation) o).vignetteEnd == vignetteEnd;
|
||||
}
|
||||
|
||||
@Override public int hashCode() {
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return ID.hashCode() + center.hashCode() + Arrays.hashCode(vignetteColor) +
|
||||
(int) (vignetteStart * 100) + (int) (vignetteEnd * 10);
|
||||
}
|
||||
|
||||
@Override public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
|
||||
@Override
|
||||
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
|
||||
messageDigest.update((ID + center + Arrays.hashCode(vignetteColor) + vignetteStart + vignetteEnd).getBytes(CHARSET));
|
||||
}
|
||||
}
|
||||
|
@@ -4,11 +4,11 @@ import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Build;
|
||||
import android.support.v8.renderscript.Allocation;
|
||||
import android.support.v8.renderscript.Element;
|
||||
import android.support.v8.renderscript.RSRuntimeException;
|
||||
import android.support.v8.renderscript.RenderScript;
|
||||
import android.support.v8.renderscript.ScriptIntrinsicBlur;
|
||||
import android.renderscript.Allocation;
|
||||
import android.renderscript.Element;
|
||||
import android.renderscript.RSRuntimeException;
|
||||
import android.renderscript.RenderScript;
|
||||
import android.renderscript.ScriptIntrinsicBlur;
|
||||
|
||||
/**
|
||||
* Copyright (C) 2018 Wasabeef
|
||||
@@ -28,43 +28,43 @@ import android.support.v8.renderscript.ScriptIntrinsicBlur;
|
||||
|
||||
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));
|
||||
@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();
|
||||
}
|
||||
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();
|
||||
}
|
||||
|
||||
return bitmap;
|
||||
}
|
||||
if (input != null) {
|
||||
input.destroy();
|
||||
}
|
||||
if (output != null) {
|
||||
output.destroy();
|
||||
}
|
||||
if (blur != null) {
|
||||
blur.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
return bitmap;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user