(CenterCrop(),
+ MaskTransformation(R.drawable.mask_chat_right))))
+ .into(holder.image)
+ }
+
+ CropTop -> Glide.with(context)
+ .load(R.drawable.demo)
+ .apply(bitmapTransform(CropTransformation(300.px, 100.px, CropType.TOP)))
+ .into(holder.image)
+
+ CropCenter -> Glide.with(context)
+ .load(R.drawable.demo)
+ .apply(bitmapTransform(CropTransformation(300.px, 100.px, CropType.CENTER)))
+ .into(holder.image)
+
+ CropBottom -> Glide.with(context)
+ .load(R.drawable.demo)
+ .apply(bitmapTransform(CropTransformation(300.px, 100.px, CropType.BOTTOM)))
+ .into(holder.image)
+
+ CropSquare -> Glide.with(context)
+ .load(R.drawable.demo)
+ .apply(bitmapTransform(CropSquareTransformation()))
+ .into(holder.image)
+
+ CropCircle -> Glide.with(context)
+ .load(R.drawable.demo)
+ .apply(bitmapTransform(CropCircleTransformation()))
+ .into(holder.image)
+
+ CropCircleWithBorder -> Glide.with(context)
+ .load(R.drawable.demo)
+ .apply(bitmapTransform(
+ CropCircleWithBorderTransformation(Utils.toDp(4), Color.rgb(0, 145, 86))))
+ .into(holder.image)
+
+ ColorFilter -> Glide.with(context)
+ .load(R.drawable.demo)
+ .apply(bitmapTransform(ColorFilterTransformation(Color.argb(80, 255, 0, 0))))
+ .into(holder.image)
+
+ Grayscale -> Glide.with(context)
+ .load(R.drawable.demo)
+ .apply(bitmapTransform(GrayscaleTransformation()))
+ .into(holder.image)
+
+ RoundedCorners -> Glide.with(context)
+ .load(R.drawable.demo)
+ .apply(bitmapTransform(RoundedCornersTransformation(120, 0,
+ RoundedCornersTransformation.CornerType.DIAGONAL_FROM_TOP_LEFT)))
+ .into(holder.image)
+
+ BlurLight -> Glide.with(context)
+ .load(R.drawable.check)
+ .apply(bitmapTransform(BlurTransformation(25)))
+ .into(holder.image)
+
+ BlurDeep -> Glide.with(context)
+ .load(R.drawable.check)
+ .apply(bitmapTransform(BlurTransformation(25, 8)))
+ .into(holder.image)
+
+ Toon -> Glide.with(context)
+ .load(R.drawable.demo)
+ .apply(bitmapTransform(ToonFilterTransformation()))
+ .into(holder.image)
+
+ Sepia -> Glide.with(context)
+ .load(R.drawable.check)
+ .apply(bitmapTransform(SepiaFilterTransformation()))
+ .into(holder.image)
+
+ Contrast -> Glide.with(context)
+ .load(R.drawable.check)
+ .apply(bitmapTransform(ContrastFilterTransformation(2.0f)))
+ .into(holder.image)
+
+ Invert -> Glide.with(context)
+ .load(R.drawable.check)
+ .apply(bitmapTransform(InvertFilterTransformation()))
+ .into(holder.image)
+
+ Pixel -> Glide.with(context)
+ .load(R.drawable.check)
+ .apply(bitmapTransform(PixelationFilterTransformation(20f)))
+ .into(holder.image)
+
+ Sketch -> Glide.with(context)
+ .load(R.drawable.check)
+ .apply(bitmapTransform(SketchFilterTransformation()))
+ .into(holder.image)
+
+ Swirl -> Glide.with(context)
+ .load(R.drawable.check)
+ .apply(bitmapTransform(
+ SwirlFilterTransformation(0.5f, 1.0f, PointF(0.5f, 0.5f))).dontAnimate())
+ .into(holder.image)
+
+ Brightness -> Glide.with(context)
+ .load(R.drawable.check)
+ .apply(bitmapTransform(BrightnessFilterTransformation(0.5f)).dontAnimate())
+ .into(holder.image)
+
+ Kuawahara -> Glide.with(context)
+ .load(R.drawable.check)
+ .apply(bitmapTransform(KuwaharaFilterTransformation(25)).dontAnimate())
+ .into(holder.image)
+
+ Vignette -> Glide.with(context)
+ .load(R.drawable.check)
+ .apply(bitmapTransform(VignetteFilterTransformation(PointF(0.5f, 0.5f),
+ floatArrayOf(0.0f, 0.0f, 0.0f), 0f, 0.75f)).dontAnimate())
+ .into(holder.image)
+ }
+ holder.title.text = dataSet[position].name
+ }
+
+ class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
+ var image: ImageView = itemView.findViewById(R.id.image)
+ var title: TextView = itemView.findViewById(R.id.title)
+ }
+}
diff --git a/example/src/main/res/layout/activity_main.xml b/example/src/main/res/layout/activity_main.xml
index 528d0d9..f05bb14 100644
--- a/example/src/main/res/layout/activity_main.xml
+++ b/example/src/main/res/layout/activity_main.xml
@@ -1,15 +1,15 @@
-
+
+ android:layout_height="match_parent">
-
-
-
+ android:layout_width="0dp"
+ android:layout_height="0dp"
+ app:layout_constraintBottom_toBottomOf="parent"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toTopOf="parent" />
+
diff --git a/example/src/main/res/layout/layout_list_item.xml b/example/src/main/res/layout/layout_list_item.xml
index 8e6f497..395a426 100644
--- a/example/src/main/res/layout/layout_list_item.xml
+++ b/example/src/main/res/layout/layout_list_item.xml
@@ -1,26 +1,32 @@
-
+ android:layout_height="wrap_content">
+ android:layout_width="250dp"
+ android:layout_height="250dp"
+ android:layout_marginBottom="8dp"
+ android:layout_marginEnd="8dp"
+ android:layout_marginStart="8dp"
+ android:layout_marginTop="8dp"
+ android:cropToPadding="false"
+ android:scaleType="fitCenter"
+ app:layout_constraintBottom_toTopOf="@+id/title"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toTopOf="parent" />
-
-
\ No newline at end of file
+ android:layout_marginBottom="8dp"
+ android:layout_marginEnd="8dp"
+ android:layout_marginStart="8dp"
+ app:layout_constraintBottom_toBottomOf="parent"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintStart_toStartOf="parent" />
+
diff --git a/example/src/main/res/values/colors.xml b/example/src/main/res/values/colors.xml
new file mode 100644
index 0000000..5a077b3
--- /dev/null
+++ b/example/src/main/res/values/colors.xml
@@ -0,0 +1,6 @@
+
+
+ #3F51B5
+ #303F9F
+ #FF4081
+
diff --git a/example/src/main/res/values/styles.xml b/example/src/main/res/values/styles.xml
index 1355d09..a64d1a6 100644
--- a/example/src/main/res/values/styles.xml
+++ b/example/src/main/res/values/styles.xml
@@ -3,6 +3,9 @@
-
+
\ No newline at end of file
diff --git a/gradle.properties b/gradle.properties
index 293d3c4..700c510 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -1,26 +1,16 @@
-VERSION_NAME=2.0.2
-GROUP=jp.wasabeef
-ARTIFACT_ID=glide-transformations
-
-COMPILE_SDK_VERSION=25
-BUILD_TOOLS_VERSION=25.0.2
-TARGET_SDK_VERSION=25
-MIN_SDK_VERSION=11
+org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=1024m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
+org.gradle.parallel=true
+org.gradle.daemon=true
+org.gradle.configureondemand=true
+org.gradle.caching=true
+android.enableBuildCache=true
+android.useAndroidX=true
+# Use R8 instead of ProGuard for code shrinking.
+android.enableR8.fullMode=true
-POM_DESCRIPTION=which provides simple Tranformations to Glide
-POM_URL=https://github.com/wasabeef/glide-transformations
-POM_SCM_URL=scm:git@github.com:wasabeef/glide-transformations.git
-POM_SCM_CONNECTION=scm:git@github.com:wasabeef/glide-transformations.git
-POM_SCM_DEV_CONNECTION=scm:git@github.com:wasabeef/glide-transformations.git
-POM_LICENCE_NAME=The Apache Software License, Version 2.0
-POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
-POM_LICENCE_DIST=repo
-POM_DEVELOPER_ID=wasabeef
-POM_DEVELOPER_NAME=Wasabeef
-POM_DEVELOPER_EMAIL=dadadada.chop@gmail.com
-POM_DEVELOPER_URL=wasabeef.jp
-ISSUE_URL=https://github.com/wasabeef/glide-transformations/issues
-
-SUPPORT_PACKAGE_VERSION=25.3.0
-GLIDE_VERSION=3.7.0
-GPUIMAGE_VERSION=1.4.1
\ No newline at end of file
+VERSION_NAME=4.3.0
+VERSION_CODE=421
+GROUP=jp.wasabeef
+COMPILE_SDK_VERSION=30
+TARGET_SDK_VERSION=30
+MIN_SDK_VERSION=21
diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar
index 04763f9..e708b1c 100644
Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 01ec31c..5a491c5 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,5 @@
-#Tue Mar 21 11:51:07 PDT 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
+distributionUrl=https://services.gradle.org/distributions/gradle-6.7.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-bin.zip
diff --git a/gradlew b/gradlew
index 4453cce..4f906e0 100755
--- a/gradlew
+++ b/gradlew
@@ -1,5 +1,21 @@
#!/usr/bin/env sh
+#
+# Copyright 2015 the original author or authors.
+#
+# 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
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# 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.
+#
+
##############################################################################
##
## Gradle start up script for UN*X
@@ -28,16 +44,16 @@ APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
-DEFAULT_JVM_OPTS=""
+DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
-warn ( ) {
+warn () {
echo "$*"
}
-die ( ) {
+die () {
echo
echo "$*"
echo
@@ -66,6 +82,7 @@ esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
@@ -109,10 +126,11 @@ if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
-# For Cygwin, switch paths to Windows format before running java
-if $cygwin ; then
+# For Cygwin or MSYS, switch paths to Windows format before running java
+if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
@@ -138,35 +156,30 @@ if $cygwin ; then
else
eval `echo args$i`="\"$arg\""
fi
- i=$((i+1))
+ i=`expr $i + 1`
done
case $i in
- (0) set -- ;;
- (1) set -- "$args0" ;;
- (2) set -- "$args0" "$args1" ;;
- (3) set -- "$args0" "$args1" "$args2" ;;
- (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
- (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
- (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
- (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
- (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
- (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+ 0) set -- ;;
+ 1) set -- "$args0" ;;
+ 2) set -- "$args0" "$args1" ;;
+ 3) set -- "$args0" "$args1" "$args2" ;;
+ 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+ 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+ 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+ 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+ 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+ 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Escape application args
-save ( ) {
+save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
-APP_ARGS=$(save "$@")
+APP_ARGS=`save "$@"`
# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
-# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
-if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
- cd "$(dirname "$0")"
-fi
-
exec "$JAVACMD" "$@"
diff --git a/gradlew.bat b/gradlew.bat
index e95643d..ac1b06f 100644
--- a/gradlew.bat
+++ b/gradlew.bat
@@ -1,3 +1,19 @@
+@rem
+@rem Copyright 2015 the original author or authors.
+@rem
+@rem Licensed under the Apache License, Version 2.0 (the "License");
+@rem you may not use this file except in compliance with the License.
+@rem You may obtain a copy of the License at
+@rem
+@rem https://www.apache.org/licenses/LICENSE-2.0
+@rem
+@rem Unless required by applicable law or agreed to in writing, software
+@rem distributed under the License is distributed on an "AS IS" BASIS,
+@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+@rem See the License for the specific language governing permissions and
+@rem limitations under the License.
+@rem
+
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@@ -13,15 +29,18 @@ if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
+@rem Resolve any "." and ".." in APP_HOME to make it shorter.
+for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
+
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
-set DEFAULT_JVM_OPTS=
+set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
-if "%ERRORLEVEL%" == "0" goto init
+if "%ERRORLEVEL%" == "0" goto execute
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
@@ -35,7 +54,7 @@ goto fail
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
-if exist "%JAVA_EXE%" goto init
+if exist "%JAVA_EXE%" goto execute
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
@@ -45,28 +64,14 @@ echo location of your Java installation.
goto fail
-:init
-@rem Get command-line arguments, handling Windows variants
-
-if not "%OS%" == "Windows_NT" goto win9xME_args
-
-:win9xME_args
-@rem Slurp the command line arguments.
-set CMD_LINE_ARGS=
-set _SKIP=2
-
-:win9xME_args_slurp
-if "x%~1" == "x" goto execute
-
-set CMD_LINE_ARGS=%*
-
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
@rem Execute Gradle
-"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
:end
@rem End local scope for the variables with windows NT shell
diff --git a/signingConfigs/debug.gradle b/signingConfigs/debug.gradle
new file mode 100644
index 0000000..d3bd148
--- /dev/null
+++ b/signingConfigs/debug.gradle
@@ -0,0 +1,14 @@
+signingConfigs {
+ debug {
+ storeFile file("debug.keystore")
+ storePassword "android"
+ keyAlias "androiddebugkey"
+ keyPassword "android"
+ }
+}
+
+// $ keytool -v -list -keystore
+// Certificate fingerprints:
+// MD5: 28:22:7C:A4:B9:2F:6E:C7:D5:58:62:48:EB:7E:82:C3
+// SHA1: 94:25:A9:50:9C:0E:AE:AA:00:37:5E:D6:71:E3:BC:ED:17:E5:0C:A3
+// SHA256: 04:92:39:09:3D:1C:B6:16:BE:55:58:A3:5F:3B:BB:CB:0B:E7:F1:DA:AA:26:C5:2D:BD:2F:44:CF:AE:47:CF:87
diff --git a/signingConfigs/debug.keystore b/signingConfigs/debug.keystore
new file mode 100644
index 0000000..e9341eb
Binary files /dev/null and b/signingConfigs/debug.keystore differ
diff --git a/transformations/build.gradle b/transformations/build.gradle
index 56a4038..9cdc4fb 100644
--- a/transformations/build.gradle
+++ b/transformations/build.gradle
@@ -1,33 +1,44 @@
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
consumerProguardFiles 'proguard-rules.txt'
}
}
dependencies {
- compile "com.github.bumptech.glide:glide:${GLIDE_VERSION}"
- provided "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 Transformations 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"]
}
+
+// TODO: Close JCenter on May 1st https://jfrog.com/blog/into-the-sunset-bintray-jcenter-gocenter-and-chartcenter/
+// apply from: 'https://gist.githubusercontent.com/wasabeef/cf14805bee509baf7461974582f17d26/raw/bintray-v1.gradle'
+// apply from: 'https://gist.githubusercontent.com/wasabeef/cf14805bee509baf7461974582f17d26/raw/install-v1.gradle'
+
+apply from: 'https://gist.githubusercontent.com/wasabeef/2f2ae8d97b429e7d967128125dc47854/raw/maven-central-v1.gradle'
diff --git a/transformations/proguard-rules.txt b/transformations/proguard-rules.txt
index 32ba203..a8038c9 100644
--- a/transformations/proguard-rules.txt
+++ b/transformations/proguard-rules.txt
@@ -1 +1,8 @@
--dontwarn jp.co.cyberagent.android.gpuimage.**
\ No newline at end of file
+-dontwarn jp.co.cyberagent.android.gpuimage.**
+
+-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.ImageHeaderParser$** {
+ **[] $VALUES;
+ public *;
+}
diff --git a/transformations/src/main/AndroidManifest.xml b/transformations/src/main/AndroidManifest.xml
index c31b1c7..7201703 100644
--- a/transformations/src/main/AndroidManifest.xml
+++ b/transformations/src/main/AndroidManifest.xml
@@ -1 +1 @@
-
+
diff --git a/transformations/src/main/java/jp/wasabeef/glide/transformations/BitmapTransformation.java b/transformations/src/main/java/jp/wasabeef/glide/transformations/BitmapTransformation.java
new file mode 100755
index 0000000..f5a35f2
--- /dev/null
+++ b/transformations/src/main/java/jp/wasabeef/glide/transformations/BitmapTransformation.java
@@ -0,0 +1,76 @@
+package jp.wasabeef.glide.transformations;
+
+/**
+ * Copyright (C) 2020 Wasabeef
+ * Copyright 2014 Google, Inc. All rights reserved.
+ *
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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 androidx.annotation.NonNull;
+
+import com.bumptech.glide.Glide;
+import com.bumptech.glide.load.Transformation;
+import com.bumptech.glide.load.engine.Resource;
+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;
+
+public abstract class BitmapTransformation implements Transformation {
+
+ @NonNull
+ @Override
+ public final Resource transform(@NonNull Context context, @NonNull Resource resource,
+ int outWidth, int outHeight) {
+ if (!Util.isValidDimensions(outWidth, outHeight)) {
+ throw new IllegalArgumentException(
+ "Cannot apply transformation on width: " + outWidth + " or height: " + outHeight
+ + " less than or equal to zero and not Target.SIZE_ORIGINAL");
+ }
+ BitmapPool bitmapPool = Glide.get(context).getBitmapPool();
+ Bitmap toTransform = resource.get();
+ int targetWidth = outWidth == Target.SIZE_ORIGINAL ? toTransform.getWidth() : outWidth;
+ int targetHeight = outHeight == Target.SIZE_ORIGINAL ? toTransform.getHeight() : outHeight;
+ Bitmap transformed = transform(context.getApplicationContext(), bitmapPool, toTransform, targetWidth, targetHeight);
+
+ final Resource result;
+ if (toTransform.equals(transformed)) {
+ result = resource;
+ } else {
+ result = BitmapResource.obtain(transformed, bitmapPool);
+ }
+ return result;
+ }
+
+ void setCanvasBitmapDensity(@NonNull Bitmap toTransform, @NonNull Bitmap canvasBitmap) {
+ canvasBitmap.setDensity(toTransform.getDensity());
+ }
+
+ protected abstract Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
+ @NonNull Bitmap toTransform, int outWidth, int outHeight);
+
+ @Override
+ public abstract void updateDiskCacheKey(@NonNull MessageDigest messageDigest);
+
+ @Override
+ public abstract boolean equals(Object o);
+
+ @Override
+ public abstract int hashCode();
+}
diff --git a/transformations/src/main/java/jp/wasabeef/glide/transformations/BlurTransformation.java b/transformations/src/main/java/jp/wasabeef/glide/transformations/BlurTransformation.java
old mode 100644
new mode 100755
index 842ce54..7623646
--- a/transformations/src/main/java/jp/wasabeef/glide/transformations/BlurTransformation.java
+++ b/transformations/src/main/java/jp/wasabeef/glide/transformations/BlurTransformation.java
@@ -1,14 +1,14 @@
package jp.wasabeef.glide.transformations;
/**
- * Copyright (C) 2017 Wasabeef
- *
+ * Copyright (C) 2020 Wasabeef
+ *
* 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
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* 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.
@@ -20,88 +20,89 @@
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
-import android.os.Build;
import android.renderscript.RSRuntimeException;
-import com.bumptech.glide.Glide;
-import com.bumptech.glide.load.Transformation;
-import com.bumptech.glide.load.engine.Resource;
-import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
-import com.bumptech.glide.load.resource.bitmap.BitmapResource;
-import jp.wasabeef.glide.transformations.internal.FastBlur;
-import jp.wasabeef.glide.transformations.internal.RSBlur;
-public class BlurTransformation implements Transformation {
+import androidx.annotation.NonNull;
- private static int MAX_RADIUS = 25;
- private static int DEFAULT_DOWN_SAMPLING = 1;
+import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
+
+import java.security.MessageDigest;
- private Context mContext;
- private BitmapPool mBitmapPool;
+import jp.wasabeef.glide.transformations.internal.FastBlur;
+import jp.wasabeef.glide.transformations.internal.RSBlur;
- private int mRadius;
- private int mSampling;
+public class BlurTransformation extends BitmapTransformation {
- public BlurTransformation(Context context) {
- this(context, Glide.get(context).getBitmapPool(), MAX_RADIUS, DEFAULT_DOWN_SAMPLING);
- }
+ private static final int VERSION = 1;
+ private static final String ID =
+ "jp.wasabeef.glide.transformations.BlurTransformation." + VERSION;
- public BlurTransformation(Context context, BitmapPool pool) {
- this(context, pool, MAX_RADIUS, DEFAULT_DOWN_SAMPLING);
- }
+ private static final int MAX_RADIUS = 25;
+ private static final int DEFAULT_DOWN_SAMPLING = 1;
- public BlurTransformation(Context context, BitmapPool pool, int radius) {
- this(context, pool, radius, DEFAULT_DOWN_SAMPLING);
- }
+ private final int radius;
+ private final int sampling;
- public BlurTransformation(Context context, int radius) {
- this(context, Glide.get(context).getBitmapPool(), radius, DEFAULT_DOWN_SAMPLING);
+ public BlurTransformation() {
+ this(MAX_RADIUS, DEFAULT_DOWN_SAMPLING);
}
- public BlurTransformation(Context context, int radius, int sampling) {
- this(context, Glide.get(context).getBitmapPool(), radius, sampling);
+ public BlurTransformation(int radius) {
+ this(radius, DEFAULT_DOWN_SAMPLING);
}
- public BlurTransformation(Context context, BitmapPool pool, int radius, int sampling) {
- mContext = context.getApplicationContext();
- mBitmapPool = pool;
- mRadius = radius;
- mSampling = sampling;
+ public BlurTransformation(int radius, int sampling) {
+ this.radius = radius;
+ this.sampling = sampling;
}
@Override
- public Resource transform(Resource resource, int outWidth, int outHeight) {
- Bitmap source = resource.get();
+ protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
+ @NonNull Bitmap toTransform, int outWidth, int outHeight) {
- int width = source.getWidth();
- int height = source.getHeight();
- int scaledWidth = width / mSampling;
- int scaledHeight = height / mSampling;
+ int width = toTransform.getWidth();
+ int height = toTransform.getHeight();
+ int scaledWidth = width / sampling;
+ int scaledHeight = height / sampling;
- Bitmap bitmap = mBitmapPool.get(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
- if (bitmap == null) {
- bitmap = Bitmap.createBitmap(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
- }
+ Bitmap bitmap = pool.get(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
+
+ setCanvasBitmapDensity(toTransform, bitmap);
Canvas canvas = new Canvas(bitmap);
- canvas.scale(1 / (float) mSampling, 1 / (float) mSampling);
+ canvas.scale(1 / (float) sampling, 1 / (float) sampling);
Paint paint = new Paint();
paint.setFlags(Paint.FILTER_BITMAP_FLAG);
- canvas.drawBitmap(source, 0, 0, paint);
-
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
- try {
- bitmap = RSBlur.blur(mContext, bitmap, mRadius);
- } catch (RSRuntimeException e) {
- bitmap = FastBlur.blur(bitmap, mRadius, true);
- }
- } else {
- bitmap = FastBlur.blur(bitmap, mRadius, true);
+ canvas.drawBitmap(toTransform, 0, 0, paint);
+
+ try {
+ bitmap = RSBlur.blur(context, bitmap, radius);
+ } catch (RSRuntimeException e) {
+ bitmap = FastBlur.blur(bitmap, radius, true);
}
- return BitmapResource.obtain(bitmap, mBitmapPool);
+ return bitmap;
+ }
+
+ @Override
+ public String toString() {
+ return "BlurTransformation(radius=" + radius + ", sampling=" + sampling + ")";
}
- @Override public String getId() {
- return "BlurTransformation(radius=" + mRadius + ", sampling=" + mSampling + ")";
+ @Override
+ public boolean equals(Object o) {
+ return o instanceof BlurTransformation &&
+ ((BlurTransformation) o).radius == radius &&
+ ((BlurTransformation) 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));
}
}
diff --git a/transformations/src/main/java/jp/wasabeef/glide/transformations/ColorFilterTransformation.java b/transformations/src/main/java/jp/wasabeef/glide/transformations/ColorFilterTransformation.java
old mode 100644
new mode 100755
index 899fd26..1a6f972
--- a/transformations/src/main/java/jp/wasabeef/glide/transformations/ColorFilterTransformation.java
+++ b/transformations/src/main/java/jp/wasabeef/glide/transformations/ColorFilterTransformation.java
@@ -1,14 +1,14 @@
package jp.wasabeef.glide.transformations;
/**
- * Copyright (C) 2017 Wasabeef
- *
+ * Copyright (C) 2020 Wasabeef
+ *
* 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
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* 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.
@@ -22,51 +22,64 @@
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
-import com.bumptech.glide.Glide;
-import com.bumptech.glide.load.Transformation;
-import com.bumptech.glide.load.engine.Resource;
+
+import androidx.annotation.NonNull;
+
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
-import com.bumptech.glide.load.resource.bitmap.BitmapResource;
-public class ColorFilterTransformation implements Transformation {
+import java.security.MessageDigest;
- private BitmapPool mBitmapPool;
+public class ColorFilterTransformation extends BitmapTransformation {
- private int mColor;
+ private static final int VERSION = 1;
+ private static final String ID =
+ "jp.wasabeef.glide.transformations.ColorFilterTransformation." + VERSION;
- public ColorFilterTransformation(Context context, int color) {
- this(Glide.get(context).getBitmapPool(), color);
- }
+ private final int color;
- public ColorFilterTransformation(BitmapPool pool, int color) {
- mBitmapPool = pool;
- mColor = color;
+ public ColorFilterTransformation(int color) {
+ this.color = color;
}
@Override
- public Resource transform(Resource resource, int outWidth, int outHeight) {
- Bitmap source = resource.get();
-
- int width = source.getWidth();
- int height = source.getHeight();
+ protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
+ @NonNull Bitmap toTransform, int outWidth, int outHeight) {
+ int width = toTransform.getWidth();
+ int height = toTransform.getHeight();
Bitmap.Config config =
- source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
- Bitmap bitmap = mBitmapPool.get(width, height, config);
- if (bitmap == null) {
- bitmap = Bitmap.createBitmap(width, height, config);
- }
+ toTransform.getConfig() != null ? toTransform.getConfig() : Bitmap.Config.ARGB_8888;
+ Bitmap bitmap = pool.get(width, height, config);
+
+ setCanvasBitmapDensity(toTransform, bitmap);
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint();
paint.setAntiAlias(true);
- paint.setColorFilter(new PorterDuffColorFilter(mColor, PorterDuff.Mode.SRC_ATOP));
- canvas.drawBitmap(source, 0, 0, paint);
+ paint.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP));
+ canvas.drawBitmap(toTransform, 0, 0, paint);
+
+ return bitmap;
+ }
- return BitmapResource.obtain(bitmap, mBitmapPool);
+ @Override
+ public String toString() {
+ return "ColorFilterTransformation(color=" + color + ")";
}
- @Override public String getId() {
- return "ColorFilterTransformation(color=" + mColor + ")";
+ @Override
+ public boolean equals(Object o) {
+ return o instanceof ColorFilterTransformation &&
+ ((ColorFilterTransformation) o).color == color;
+ }
+
+ @Override
+ public int hashCode() {
+ return ID.hashCode() + color * 10;
+ }
+
+ @Override
+ public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
+ messageDigest.update((ID + color).getBytes(CHARSET));
}
}
diff --git a/transformations/src/main/java/jp/wasabeef/glide/transformations/CropCircleTransformation.java b/transformations/src/main/java/jp/wasabeef/glide/transformations/CropCircleTransformation.java
old mode 100644
new mode 100755
index 5228fc9..0a681e1
--- a/transformations/src/main/java/jp/wasabeef/glide/transformations/CropCircleTransformation.java
+++ b/transformations/src/main/java/jp/wasabeef/glide/transformations/CropCircleTransformation.java
@@ -1,14 +1,14 @@
package jp.wasabeef.glide.transformations;
/**
- * Copyright (C) 2017 Wasabeef
- *
+ * Copyright (C) 2020 Wasabeef
+ *
* 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
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* 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.
@@ -18,61 +18,48 @@
import android.content.Context;
import android.graphics.Bitmap;
-import android.graphics.BitmapShader;
-import android.graphics.Canvas;
-import android.graphics.Matrix;
-import android.graphics.Paint;
-import com.bumptech.glide.Glide;
-import com.bumptech.glide.load.Transformation;
-import com.bumptech.glide.load.engine.Resource;
+
+import androidx.annotation.NonNull;
+
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
-import com.bumptech.glide.load.resource.bitmap.BitmapResource;
+import com.bumptech.glide.load.resource.bitmap.TransformationUtils;
+import com.bumptech.glide.request.RequestOptions;
-public class CropCircleTransformation implements Transformation {
+import java.security.MessageDigest;
- private BitmapPool mBitmapPool;
+/**
+ * @deprecated Use {@link RequestOptions#circleCrop()}.
+ */
+@Deprecated
+public class CropCircleTransformation extends BitmapTransformation {
- public CropCircleTransformation(Context context) {
- this(Glide.get(context).getBitmapPool());
- }
+ private static final int VERSION = 1;
+ private static final String ID =
+ "jp.wasabeef.glide.transformations.CropCircleTransformation." + VERSION;
- public CropCircleTransformation(BitmapPool pool) {
- this.mBitmapPool = pool;
+ @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 Resource transform(Resource resource, int outWidth, int outHeight) {
- Bitmap source = resource.get();
- int size = Math.min(source.getWidth(), source.getHeight());
-
- int width = (source.getWidth() - size) / 2;
- int height = (source.getHeight() - size) / 2;
-
- Bitmap bitmap = mBitmapPool.get(size, size, Bitmap.Config.ARGB_8888);
- if (bitmap == null) {
- bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
- }
-
- Canvas canvas = new Canvas(bitmap);
- Paint paint = new Paint();
- BitmapShader shader =
- new BitmapShader(source, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP);
- if (width != 0 || height != 0) {
- // source isn't square, move viewport to center
- Matrix matrix = new Matrix();
- matrix.setTranslate(-width, -height);
- shader.setLocalMatrix(matrix);
- }
- paint.setShader(shader);
- paint.setAntiAlias(true);
+ public String toString() {
+ return "CropCircleTransformation()";
+ }
- float r = size / 2f;
- canvas.drawCircle(r, r, r, paint);
+ @Override
+ public boolean equals(Object o) {
+ return o instanceof CropCircleTransformation;
+ }
- return BitmapResource.obtain(bitmap, mBitmapPool);
+ @Override
+ public int hashCode() {
+ return ID.hashCode();
}
- @Override public String getId() {
- return "CropCircleTransformation()";
+ @Override
+ public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
+ messageDigest.update((ID).getBytes(CHARSET));
}
}
diff --git a/transformations/src/main/java/jp/wasabeef/glide/transformations/CropCircleWithBorderTransformation.java b/transformations/src/main/java/jp/wasabeef/glide/transformations/CropCircleWithBorderTransformation.java
new file mode 100644
index 0000000..ca6cb9b
--- /dev/null
+++ b/transformations/src/main/java/jp/wasabeef/glide/transformations/CropCircleWithBorderTransformation.java
@@ -0,0 +1,96 @@
+package jp.wasabeef.glide.transformations;
+
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.Paint;
+
+import androidx.annotation.ColorInt;
+import androidx.annotation.NonNull;
+
+import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
+import com.bumptech.glide.load.resource.bitmap.TransformationUtils;
+
+import java.security.MessageDigest;
+
+import jp.wasabeef.glide.transformations.internal.Utils;
+
+/**
+ * Copyright (C) 2020 Wasabeef
+ *
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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 CropCircleWithBorderTransformation extends BitmapTransformation {
+
+
+ private static final int VERSION = 1;
+ private static final String ID = "jp.wasabeef.glide.transformations.CropCircleWithBorderTransformation." + VERSION;
+
+ private final int borderSize;
+ private final int borderColor;
+
+
+ public CropCircleWithBorderTransformation() {
+ this.borderSize = Utils.toDp(4);
+ this.borderColor = Color.BLACK;
+ }
+
+ public CropCircleWithBorderTransformation(int borderSize, @ColorInt int borderColor) {
+ this.borderSize = borderSize;
+ this.borderColor = borderColor;
+ }
+
+ @Override
+ protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
+ @NonNull Bitmap toTransform, int outWidth, int outHeight) {
+
+ Bitmap bitmap = TransformationUtils.circleCrop(pool, toTransform, outWidth, outHeight);
+
+ setCanvasBitmapDensity(toTransform, bitmap);
+
+ Paint paint = new Paint();
+ paint.setColor(borderColor);
+ paint.setStyle(Paint.Style.STROKE);
+ paint.setStrokeWidth(borderSize);
+ paint.setAntiAlias(true);
+
+ Canvas canvas = new Canvas(bitmap);
+ canvas.drawCircle(
+ outWidth / 2f,
+ outHeight / 2f,
+ Math.max(outWidth, outHeight) / 2f - borderSize / 2f,
+ paint
+ );
+
+ return bitmap;
+ }
+
+ @Override
+ public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
+ messageDigest.update((ID + borderSize + borderColor).getBytes(CHARSET));
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ return o instanceof CropCircleWithBorderTransformation &&
+ ((CropCircleWithBorderTransformation) o).borderSize == borderSize &&
+ ((CropCircleWithBorderTransformation) o).borderColor == borderColor;
+ }
+
+ @Override
+ public int hashCode() {
+ return ID.hashCode() + borderSize * 100 + borderColor + 10;
+ }
+}
diff --git a/transformations/src/main/java/jp/wasabeef/glide/transformations/CropSquareTransformation.java b/transformations/src/main/java/jp/wasabeef/glide/transformations/CropSquareTransformation.java
old mode 100644
new mode 100755
index f71dca9..b8f41d9
--- a/transformations/src/main/java/jp/wasabeef/glide/transformations/CropSquareTransformation.java
+++ b/transformations/src/main/java/jp/wasabeef/glide/transformations/CropSquareTransformation.java
@@ -1,14 +1,14 @@
package jp.wasabeef.glide.transformations;
/**
- * Copyright (C) 2017 Wasabeef
- *
+ * Copyright (C) 2020 Wasabeef
+ *
* 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
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* 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.
@@ -18,45 +18,46 @@
import android.content.Context;
import android.graphics.Bitmap;
-import com.bumptech.glide.Glide;
-import com.bumptech.glide.load.Transformation;
-import com.bumptech.glide.load.engine.Resource;
+
+import androidx.annotation.NonNull;
+
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
-import com.bumptech.glide.load.resource.bitmap.BitmapResource;
+import com.bumptech.glide.load.resource.bitmap.TransformationUtils;
-public class CropSquareTransformation implements Transformation {
+import java.security.MessageDigest;
- private BitmapPool mBitmapPool;
- private int mWidth;
- private int mHeight;
+public class CropSquareTransformation extends BitmapTransformation {
- public CropSquareTransformation(Context context) {
- this(Glide.get(context).getBitmapPool());
- }
+ private static final int VERSION = 1;
+ private static final String ID =
+ "jp.wasabeef.glide.transformations.CropSquareTransformation." + VERSION;
- public CropSquareTransformation(BitmapPool pool) {
- this.mBitmapPool = pool;
- }
+ private int size;
@Override
- public Resource transform(Resource resource, int outWidth, int outHeight) {
- Bitmap source = resource.get();
- int size = Math.min(source.getWidth(), source.getHeight());
+ 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);
+ }
- mWidth = (source.getWidth() - size) / 2;
- mHeight = (source.getHeight() - size) / 2;
+ @Override
+ public String toString() {
+ return "CropSquareTransformation(size=" + size + ")";
+ }
- Bitmap.Config config =
- source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
- Bitmap bitmap = mBitmapPool.get(mWidth, mHeight, config);
- if (bitmap == null) {
- bitmap = Bitmap.createBitmap(source, mWidth, mHeight, size, size);
- }
+ @Override
+ public boolean equals(Object o) {
+ return o instanceof CropSquareTransformation && ((CropSquareTransformation) o).size == size;
+ }
- return BitmapResource.obtain(bitmap, mBitmapPool);
+ @Override
+ public int hashCode() {
+ return ID.hashCode() + size * 10;
}
- @Override public String getId() {
- return "CropSquareTransformation(width=" + mWidth + ", height=" + mHeight + ")";
+ @Override
+ public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
+ messageDigest.update((ID + size).getBytes(CHARSET));
}
}
diff --git a/transformations/src/main/java/jp/wasabeef/glide/transformations/CropTransformation.java b/transformations/src/main/java/jp/wasabeef/glide/transformations/CropTransformation.java
old mode 100644
new mode 100755
index 97ecb20..8dbcd4b
--- a/transformations/src/main/java/jp/wasabeef/glide/transformations/CropTransformation.java
+++ b/transformations/src/main/java/jp/wasabeef/glide/transformations/CropTransformation.java
@@ -1,14 +1,14 @@
package jp.wasabeef.glide.transformations;
/**
- * Copyright (C) 2017 Wasabeef
- *
+ * Copyright (C) 2020 Wasabeef
+ *
* 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
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* 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.
@@ -20,13 +20,17 @@
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.RectF;
-import com.bumptech.glide.Glide;
-import com.bumptech.glide.load.Transformation;
-import com.bumptech.glide.load.engine.Resource;
+
+import androidx.annotation.NonNull;
+
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
-import com.bumptech.glide.load.resource.bitmap.BitmapResource;
-public class CropTransformation implements Transformation {
+import java.security.MessageDigest;
+
+public class CropTransformation extends BitmapTransformation {
+
+ private static final int VERSION = 1;
+ private static final String ID = "jp.wasabeef.glide.transformations.CropTransformation." + VERSION;
public enum CropType {
TOP,
@@ -34,83 +38,85 @@ public enum CropType {
BOTTOM
}
- private BitmapPool mBitmapPool;
- private int mWidth;
- private int mHeight;
+ private int width;
+ private int height;
- private CropType mCropType = CropType.CENTER;
-
- public CropTransformation(Context context) {
- this(Glide.get(context).getBitmapPool());
- }
-
- public CropTransformation(BitmapPool pool) {
- this(pool, 0, 0);
- }
+ private CropType cropType = CropType.CENTER;
- public CropTransformation(Context context, int width, int height) {
- this(Glide.get(context).getBitmapPool(), width, height);
+ public CropTransformation(int width, int height) {
+ this(width, height, CropType.CENTER);
}
- public CropTransformation(BitmapPool pool, int width, int height) {
- this(pool, width, height, CropType.CENTER);
- }
-
- public CropTransformation(Context context, int width, int height, CropType cropType) {
- this(Glide.get(context).getBitmapPool(), width, height, cropType);
- }
-
- public CropTransformation(BitmapPool pool, int width, int height, CropType cropType) {
- mBitmapPool = pool;
- mWidth = width;
- mHeight = height;
- mCropType = cropType;
+ public CropTransformation(int width, int height, CropType cropType) {
+ this.width = width;
+ this.height = height;
+ this.cropType = cropType;
}
@Override
- public Resource transform(Resource resource, int outWidth, int outHeight) {
- Bitmap source = resource.get();
- mWidth = mWidth == 0 ? source.getWidth() : mWidth;
- mHeight = mHeight == 0 ? source.getHeight() : mHeight;
+ 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;
Bitmap.Config config =
- source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
- Bitmap bitmap = mBitmapPool.get(mWidth, mHeight, config);
- if (bitmap == null) {
- bitmap = Bitmap.createBitmap(mWidth, mHeight, config);
- }
+ toTransform.getConfig() != null ? toTransform.getConfig() : Bitmap.Config.ARGB_8888;
+ Bitmap bitmap = pool.get(width, height, config);
+
+ bitmap.setHasAlpha(true);
- float scaleX = (float) mWidth / source.getWidth();
- float scaleY = (float) mHeight / source.getHeight();
+ float scaleX = (float) width / toTransform.getWidth();
+ float scaleY = (float) height / toTransform.getHeight();
float scale = Math.max(scaleX, scaleY);
- float scaledWidth = scale * source.getWidth();
- float scaledHeight = scale * source.getHeight();
- float left = (mWidth - scaledWidth) / 2;
+ float scaledWidth = scale * toTransform.getWidth();
+ float scaledHeight = scale * toTransform.getHeight();
+ float left = (width - scaledWidth) / 2;
float top = getTop(scaledHeight);
RectF targetRect = new RectF(left, top, left + scaledWidth, top + scaledHeight);
- Canvas canvas = new Canvas(bitmap);
- canvas.drawBitmap(source, null, targetRect, null);
+ setCanvasBitmapDensity(toTransform, bitmap);
- return BitmapResource.obtain(bitmap, mBitmapPool);
- }
+ Canvas canvas = new Canvas(bitmap);
+ canvas.drawBitmap(toTransform, null, targetRect, null);
- @Override public String getId() {
- return "CropTransformation(width=" + mWidth + ", height=" + mHeight + ", cropType=" + mCropType
- + ")";
+ return bitmap;
}
private float getTop(float scaledHeight) {
- switch (mCropType) {
+ switch (cropType) {
case TOP:
return 0;
case CENTER:
- return (mHeight - scaledHeight) / 2;
+ return (height - scaledHeight) / 2;
case BOTTOM:
- return mHeight - scaledHeight;
+ return height - scaledHeight;
default:
return 0;
}
}
+
+ @Override
+ public String toString() {
+ return "CropTransformation(width=" + width + ", height=" + height + ", cropType=" + cropType + ")";
+ }
+
+ @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() {
+ return ID.hashCode() + width * 100000 + height * 1000 + cropType.ordinal() * 10;
+ }
+
+ @Override
+ public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
+ messageDigest.update((ID + width + height + cropType).getBytes(CHARSET));
+ }
}
diff --git a/transformations/src/main/java/jp/wasabeef/glide/transformations/GrayscaleTransformation.java b/transformations/src/main/java/jp/wasabeef/glide/transformations/GrayscaleTransformation.java
old mode 100644
new mode 100755
index f02c848..1a2fe43
--- a/transformations/src/main/java/jp/wasabeef/glide/transformations/GrayscaleTransformation.java
+++ b/transformations/src/main/java/jp/wasabeef/glide/transformations/GrayscaleTransformation.java
@@ -1,14 +1,14 @@
package jp.wasabeef.glide.transformations;
/**
- * Copyright (C) 2017 Wasabeef
- *
+ * Copyright (C) 2020 Wasabeef
+ *
* 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
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* 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.
@@ -22,49 +22,58 @@
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.Paint;
-import com.bumptech.glide.Glide;
-import com.bumptech.glide.load.Transformation;
-import com.bumptech.glide.load.engine.Resource;
-import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
-import com.bumptech.glide.load.resource.bitmap.BitmapResource;
-public class GrayscaleTransformation implements Transformation {
+import androidx.annotation.NonNull;
- private BitmapPool mBitmapPool;
+import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
- public GrayscaleTransformation(Context context) {
- this(Glide.get(context).getBitmapPool());
- }
+import java.security.MessageDigest;
- public GrayscaleTransformation(BitmapPool pool) {
- mBitmapPool = pool;
- }
+public class GrayscaleTransformation extends BitmapTransformation {
- @Override
- public Resource transform(Resource resource, int outWidth, int outHeight) {
- Bitmap source = resource.get();
+ private static final int VERSION = 1;
+ private static final String ID =
+ "jp.wasabeef.glide.transformations.GrayscaleTransformation." + VERSION;
- int width = source.getWidth();
- int height = source.getHeight();
+ @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();
Bitmap.Config config =
- source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
- Bitmap bitmap = mBitmapPool.get(width, height, config);
- if (bitmap == null) {
- bitmap = Bitmap.createBitmap(width, height, config);
- }
+ toTransform.getConfig() != null ? toTransform.getConfig() : Bitmap.Config.ARGB_8888;
+ Bitmap bitmap = pool.get(width, height, config);
+
+ setCanvasBitmapDensity(toTransform, bitmap);
Canvas canvas = new Canvas(bitmap);
ColorMatrix saturation = new ColorMatrix();
saturation.setSaturation(0f);
Paint paint = new Paint();
paint.setColorFilter(new ColorMatrixColorFilter(saturation));
- canvas.drawBitmap(source, 0, 0, paint);
+ canvas.drawBitmap(toTransform, 0, 0, paint);
- return BitmapResource.obtain(bitmap, mBitmapPool);
+ return bitmap;
}
- @Override public String getId() {
+ @Override
+ public String toString() {
return "GrayscaleTransformation()";
}
+
+ @Override
+ public boolean equals(Object o) {
+ return o instanceof GrayscaleTransformation;
+ }
+
+ @Override
+ public int hashCode() {
+ return ID.hashCode();
+ }
+
+ @Override
+ public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
+ messageDigest.update((ID).getBytes(CHARSET));
+ }
}
diff --git a/transformations/src/main/java/jp/wasabeef/glide/transformations/MaskTransformation.java b/transformations/src/main/java/jp/wasabeef/glide/transformations/MaskTransformation.java
old mode 100644
new mode 100755
index 6248ad6..78201f2
--- a/transformations/src/main/java/jp/wasabeef/glide/transformations/MaskTransformation.java
+++ b/transformations/src/main/java/jp/wasabeef/glide/transformations/MaskTransformation.java
@@ -1,14 +1,14 @@
package jp.wasabeef.glide.transformations;
/**
- * Copyright (C) 2017 Wasabeef
- *
+ * Copyright (C) 2020 Wasabeef
+ *
* 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
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* 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.
@@ -23,63 +23,74 @@
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.drawable.Drawable;
-import com.bumptech.glide.Glide;
-import com.bumptech.glide.load.Transformation;
-import com.bumptech.glide.load.engine.Resource;
+
+import androidx.annotation.NonNull;
+
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
-import com.bumptech.glide.load.resource.bitmap.BitmapResource;
-import jp.wasabeef.glide.transformations.internal.Utils;
-public class MaskTransformation implements Transformation {
+import java.security.MessageDigest;
+
+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 sMaskingPaint = new Paint();
- private Context mContext;
- private BitmapPool mBitmapPool;
- private int mMaskId;
+ private static final Paint paint = new Paint();
+ private final int maskId;
static {
- sMaskingPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
+ paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
}
/**
* @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 getId() 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(Context context, int maskId) {
- this(context, Glide.get(context).getBitmapPool(), maskId);
- }
-
- public MaskTransformation(Context context, BitmapPool pool, int maskId) {
- mBitmapPool = pool;
- mContext = context.getApplicationContext();
- mMaskId = maskId;
+ public MaskTransformation(int maskId) {
+ this.maskId = maskId;
}
@Override
- public Resource transform(Resource resource, int outWidth, int outHeight) {
- Bitmap source = resource.get();
+ 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 width = source.getWidth();
- int height = source.getHeight();
+ Bitmap bitmap = pool.get(width, height, Bitmap.Config.ARGB_8888);
+ bitmap.setHasAlpha(true);
- Bitmap result = mBitmapPool.get(width, height, Bitmap.Config.ARGB_8888);
- if (result == null) {
- result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
- }
+ Drawable mask = context.getDrawable(maskId);
- Drawable mask = Utils.getMaskDrawable(mContext, mMaskId);
+ setCanvasBitmapDensity(toTransform, bitmap);
- Canvas canvas = new Canvas(result);
+ Canvas canvas = new Canvas(bitmap);
mask.setBounds(0, 0, width, height);
mask.draw(canvas);
- canvas.drawBitmap(source, 0, 0, sMaskingPaint);
+ canvas.drawBitmap(toTransform, 0, 0, paint);
+
+ return bitmap;
+ }
- return BitmapResource.obtain(result, mBitmapPool);
+ @Override
+ public String toString() {
+ return "MaskTransformation(maskId=" + maskId + ")";
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ return o instanceof MaskTransformation &&
+ ((MaskTransformation) o).maskId == maskId;
}
- @Override public String getId() {
- return "MaskTransformation(maskId=" + mContext.getResources().getResourceEntryName(mMaskId)
- + ")";
+ @Override
+ public int hashCode() {
+ return ID.hashCode() + maskId * 10;
+ }
+
+ @Override
+ public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
+ messageDigest.update((ID + maskId).getBytes(CHARSET));
}
}
diff --git a/transformations/src/main/java/jp/wasabeef/glide/transformations/RoundedCornersTransformation.java b/transformations/src/main/java/jp/wasabeef/glide/transformations/RoundedCornersTransformation.java
old mode 100644
new mode 100755
index e12c826..c7c64c3
--- a/transformations/src/main/java/jp/wasabeef/glide/transformations/RoundedCornersTransformation.java
+++ b/transformations/src/main/java/jp/wasabeef/glide/transformations/RoundedCornersTransformation.java
@@ -1,14 +1,14 @@
package jp.wasabeef.glide.transformations;
/**
- * Copyright (C) 2017 Wasabeef
- *
+ * Copyright (C) 2020 Wasabeef
+ *
* 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
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* 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.
@@ -23,13 +23,17 @@
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.Shader;
-import com.bumptech.glide.Glide;
-import com.bumptech.glide.load.Transformation;
-import com.bumptech.glide.load.engine.Resource;
+
+import androidx.annotation.NonNull;
+
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
-import com.bumptech.glide.load.resource.bitmap.BitmapResource;
-public class RoundedCornersTransformation implements Transformation {
+import java.security.MessageDigest;
+
+public class RoundedCornersTransformation extends BitmapTransformation {
+
+ private static final int VERSION = 1;
+ private static final String ID = "jp.wasabeef.glide.transformations.RoundedCornersTransformation." + VERSION;
public enum CornerType {
ALL,
@@ -39,61 +43,48 @@ public enum CornerType {
DIAGONAL_FROM_TOP_LEFT, DIAGONAL_FROM_TOP_RIGHT
}
- private BitmapPool mBitmapPool;
- private int mRadius;
- private int mDiameter;
- private int mMargin;
- private CornerType mCornerType;
-
- public RoundedCornersTransformation(Context context, int radius, int margin) {
- this(context, radius, margin, CornerType.ALL);
- }
+ private final int radius;
+ private final int diameter;
+ private final int margin;
+ private final CornerType cornerType;
- public RoundedCornersTransformation(BitmapPool pool, int radius, int margin) {
- this(pool, radius, margin, CornerType.ALL);
+ public RoundedCornersTransformation(int radius, int margin) {
+ this(radius, margin, CornerType.ALL);
}
- public RoundedCornersTransformation(Context context, int radius, int margin,
- CornerType cornerType) {
- this(Glide.get(context).getBitmapPool(), radius, margin, cornerType);
- }
-
- public RoundedCornersTransformation(BitmapPool pool, int radius, int margin,
- CornerType cornerType) {
- mBitmapPool = pool;
- mRadius = radius;
- mDiameter = mRadius * 2;
- mMargin = margin;
- mCornerType = cornerType;
+ public RoundedCornersTransformation(int radius, int margin, CornerType cornerType) {
+ this.radius = radius;
+ this.diameter = this.radius * 2;
+ this.margin = margin;
+ this.cornerType = cornerType;
}
@Override
- public Resource transform(Resource resource, int outWidth, int outHeight) {
- Bitmap source = resource.get();
+ 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 width = source.getWidth();
- int height = source.getHeight();
+ Bitmap bitmap = pool.get(width, height, Bitmap.Config.ARGB_8888);
+ bitmap.setHasAlpha(true);
- Bitmap bitmap = mBitmapPool.get(width, height, Bitmap.Config.ARGB_8888);
- if (bitmap == null) {
- bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
- }
+ setCanvasBitmapDensity(toTransform, bitmap);
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint();
paint.setAntiAlias(true);
- paint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
+ paint.setShader(new BitmapShader(toTransform, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
drawRoundRect(canvas, paint, width, height);
- return BitmapResource.obtain(bitmap, mBitmapPool);
+ return bitmap;
}
private void drawRoundRect(Canvas canvas, Paint paint, float width, float height) {
- float right = width - mMargin;
- float bottom = height - mMargin;
+ float right = width - margin;
+ float bottom = height - margin;
- switch (mCornerType) {
+ switch (cornerType) {
case ALL:
- canvas.drawRoundRect(new RectF(mMargin, mMargin, right, bottom), mRadius, mRadius, paint);
+ canvas.drawRoundRect(new RectF(margin, margin, right, bottom), radius, radius, paint);
break;
case TOP_LEFT:
drawTopLeftRoundRect(canvas, paint, right, bottom);
@@ -138,118 +129,135 @@ private void drawRoundRect(Canvas canvas, Paint paint, float width, float height
drawDiagonalFromTopRightRoundRect(canvas, paint, right, bottom);
break;
default:
- canvas.drawRoundRect(new RectF(mMargin, mMargin, right, bottom), mRadius, mRadius, paint);
+ canvas.drawRoundRect(new RectF(margin, margin, right, bottom), radius, radius, paint);
break;
}
}
private void drawTopLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
- canvas.drawRoundRect(new RectF(mMargin, mMargin, mMargin + mDiameter, mMargin + mDiameter),
- mRadius, mRadius, paint);
- canvas.drawRect(new RectF(mMargin, mMargin + mRadius, mMargin + mRadius, bottom), paint);
- canvas.drawRect(new RectF(mMargin + mRadius, mMargin, right, bottom), paint);
+ canvas.drawRoundRect(new RectF(margin, margin, margin + diameter, margin + diameter), radius,
+ radius, paint);
+ canvas.drawRect(new RectF(margin, margin + radius, margin + radius, bottom), paint);
+ canvas.drawRect(new RectF(margin + radius, margin, right, bottom), paint);
}
private void drawTopRightRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
- canvas.drawRoundRect(new RectF(right - mDiameter, mMargin, right, mMargin + mDiameter), mRadius,
- mRadius, paint);
- canvas.drawRect(new RectF(mMargin, mMargin, right - mRadius, bottom), paint);
- canvas.drawRect(new RectF(right - mRadius, mMargin + mRadius, right, bottom), paint);
+ canvas.drawRoundRect(new RectF(right - diameter, margin, right, margin + diameter), radius,
+ radius, paint);
+ canvas.drawRect(new RectF(margin, margin, right - radius, bottom), paint);
+ canvas.drawRect(new RectF(right - radius, margin + radius, right, bottom), paint);
}
private void drawBottomLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
- canvas.drawRoundRect(new RectF(mMargin, bottom - mDiameter, mMargin + mDiameter, bottom),
- mRadius, mRadius, paint);
- canvas.drawRect(new RectF(mMargin, mMargin, mMargin + mDiameter, bottom - mRadius), paint);
- canvas.drawRect(new RectF(mMargin + mRadius, mMargin, right, bottom), paint);
+ canvas.drawRoundRect(new RectF(margin, bottom - diameter, margin + diameter, bottom), radius,
+ radius, paint);
+ canvas.drawRect(new RectF(margin, margin, margin + diameter, bottom - radius), paint);
+ canvas.drawRect(new RectF(margin + radius, margin, right, bottom), paint);
}
private void drawBottomRightRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
- canvas.drawRoundRect(new RectF(right - mDiameter, bottom - mDiameter, right, bottom), mRadius,
- mRadius, paint);
- canvas.drawRect(new RectF(mMargin, mMargin, right - mRadius, bottom), paint);
- canvas.drawRect(new RectF(right - mRadius, mMargin, right, bottom - mRadius), paint);
+ canvas.drawRoundRect(new RectF(right - diameter, bottom - diameter, right, bottom), radius,
+ radius, paint);
+ canvas.drawRect(new RectF(margin, margin, right - radius, bottom), paint);
+ canvas.drawRect(new RectF(right - radius, margin, right, bottom - radius), paint);
}
private void drawTopRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
- canvas.drawRoundRect(new RectF(mMargin, mMargin, right, mMargin + mDiameter), mRadius, mRadius,
- paint);
- canvas.drawRect(new RectF(mMargin, mMargin + mRadius, right, bottom), paint);
+ canvas.drawRoundRect(new RectF(margin, margin, right, margin + diameter), radius, radius,
+ paint);
+ canvas.drawRect(new RectF(margin, margin + radius, right, bottom), paint);
}
private void drawBottomRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
- canvas.drawRoundRect(new RectF(mMargin, bottom - mDiameter, right, bottom), mRadius, mRadius,
- paint);
- canvas.drawRect(new RectF(mMargin, mMargin, right, bottom - mRadius), paint);
+ canvas.drawRoundRect(new RectF(margin, bottom - diameter, right, bottom), radius, radius,
+ paint);
+ canvas.drawRect(new RectF(margin, margin, right, bottom - radius), paint);
}
private void drawLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
- canvas.drawRoundRect(new RectF(mMargin, mMargin, mMargin + mDiameter, bottom), mRadius, mRadius,
- paint);
- canvas.drawRect(new RectF(mMargin + mRadius, mMargin, right, bottom), paint);
+ canvas.drawRoundRect(new RectF(margin, margin, margin + diameter, bottom), radius, radius,
+ paint);
+ canvas.drawRect(new RectF(margin + radius, margin, right, bottom), paint);
}
private void drawRightRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
- canvas.drawRoundRect(new RectF(right - mDiameter, mMargin, right, bottom), mRadius, mRadius,
- paint);
- canvas.drawRect(new RectF(mMargin, mMargin, right - mRadius, bottom), paint);
+ canvas.drawRoundRect(new RectF(right - diameter, margin, right, bottom), radius, radius, paint);
+ canvas.drawRect(new RectF(margin, margin, right - radius, bottom), paint);
}
private void drawOtherTopLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
- canvas.drawRoundRect(new RectF(mMargin, bottom - mDiameter, right, bottom), mRadius, mRadius,
- paint);
- canvas.drawRoundRect(new RectF(right - mDiameter, mMargin, right, bottom), mRadius, mRadius,
- paint);
- canvas.drawRect(new RectF(mMargin, mMargin, right - mRadius, bottom - mRadius), paint);
+ canvas.drawRoundRect(new RectF(margin, bottom - diameter, right, bottom), radius, radius,
+ paint);
+ canvas.drawRoundRect(new RectF(right - diameter, margin, right, bottom), radius, radius, paint);
+ canvas.drawRect(new RectF(margin, margin, right - radius, bottom - radius), paint);
}
private void drawOtherTopRightRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
- canvas.drawRoundRect(new RectF(mMargin, mMargin, mMargin + mDiameter, bottom), mRadius, mRadius,
- paint);
- canvas.drawRoundRect(new RectF(mMargin, bottom - mDiameter, right, bottom), mRadius, mRadius,
- paint);
- canvas.drawRect(new RectF(mMargin + mRadius, mMargin, right, bottom - mRadius), paint);
+ canvas.drawRoundRect(new RectF(margin, margin, margin + diameter, bottom), radius, radius,
+ paint);
+ canvas.drawRoundRect(new RectF(margin, bottom - diameter, right, bottom), radius, radius,
+ paint);
+ canvas.drawRect(new RectF(margin + radius, margin, right, bottom - radius), paint);
}
private void drawOtherBottomLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
- canvas.drawRoundRect(new RectF(mMargin, mMargin, right, mMargin + mDiameter), mRadius, mRadius,
- paint);
- canvas.drawRoundRect(new RectF(right - mDiameter, mMargin, right, bottom), mRadius, mRadius,
- paint);
- canvas.drawRect(new RectF(mMargin, mMargin + mRadius, right - mRadius, bottom), paint);
+ canvas.drawRoundRect(new RectF(margin, margin, right, margin + diameter), radius, radius,
+ paint);
+ canvas.drawRoundRect(new RectF(right - diameter, margin, right, bottom), radius, radius, paint);
+ canvas.drawRect(new RectF(margin, margin + radius, right - radius, bottom), paint);
}
private void drawOtherBottomRightRoundRect(Canvas canvas, Paint paint, float right,
- float bottom) {
- canvas.drawRoundRect(new RectF(mMargin, mMargin, right, mMargin + mDiameter), mRadius, mRadius,
- paint);
- canvas.drawRoundRect(new RectF(mMargin, mMargin, mMargin + mDiameter, bottom), mRadius, mRadius,
- paint);
- canvas.drawRect(new RectF(mMargin + mRadius, mMargin + mRadius, right, bottom), paint);
+ 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,
+ paint);
+ canvas.drawRect(new RectF(margin + radius, margin + radius, right, bottom), paint);
}
private void drawDiagonalFromTopLeftRoundRect(Canvas canvas, Paint paint, float right,
- float bottom) {
- canvas.drawRoundRect(new RectF(mMargin, mMargin, mMargin + mDiameter, mMargin + mDiameter),
- mRadius, mRadius, paint);
- canvas.drawRoundRect(new RectF(right - mDiameter, bottom - mDiameter, right, bottom), mRadius,
- mRadius, paint);
- canvas.drawRect(new RectF(mMargin, mMargin + mRadius, right - mDiameter, bottom), paint);
- canvas.drawRect(new RectF(mMargin + mDiameter, mMargin, right, bottom - mRadius), paint);
+ 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,
+ radius, paint);
+ canvas.drawRect(new RectF(margin, margin + radius, right - radius, bottom), paint);
+ canvas.drawRect(new RectF(margin + radius, margin, right, bottom - radius), paint);
}
private void drawDiagonalFromTopRightRoundRect(Canvas canvas, Paint paint, float right,
- float bottom) {
- canvas.drawRoundRect(new RectF(right - mDiameter, mMargin, right, mMargin + mDiameter), mRadius,
- mRadius, paint);
- canvas.drawRoundRect(new RectF(mMargin, bottom - mDiameter, mMargin + mDiameter, bottom),
- mRadius, mRadius, paint);
- canvas.drawRect(new RectF(mMargin, mMargin, right - mRadius, bottom - mRadius), paint);
- canvas.drawRect(new RectF(mMargin + mRadius, mMargin + mRadius, right, bottom), paint);
- }
-
- @Override public String getId() {
- return "RoundedTransformation(radius=" + mRadius + ", margin=" + mMargin + ", diameter="
- + mDiameter + ", cornerType=" + mCornerType.name() + ")";
+ 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,
+ radius, paint);
+ canvas.drawRect(new RectF(margin, margin, right - radius, bottom - radius), paint);
+ canvas.drawRect(new RectF(margin + radius, margin + radius, right, bottom), paint);
+ }
+
+ @Override
+ public String toString() {
+ return "RoundedTransformation(radius=" + radius + ", margin=" + margin + ", diameter="
+ + diameter + ", cornerType=" + cornerType.name() + ")";
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ return o instanceof RoundedCornersTransformation &&
+ ((RoundedCornersTransformation) o).radius == radius &&
+ ((RoundedCornersTransformation) o).diameter == diameter &&
+ ((RoundedCornersTransformation) o).margin == margin &&
+ ((RoundedCornersTransformation) o).cornerType == cornerType;
+ }
+
+ @Override
+ public int hashCode() {
+ return ID.hashCode() + radius * 10000 + diameter * 1000 + margin * 100 + cornerType.ordinal() * 10;
+ }
+
+ @Override
+ public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
+ messageDigest.update((ID + radius + diameter + margin + cornerType).getBytes(CHARSET));
}
}
diff --git a/transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/BrightnessFilterTransformation.java b/transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/BrightnessFilterTransformation.java
old mode 100644
new mode 100755
index d2c7be0..8655059
--- a/transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/BrightnessFilterTransformation.java
+++ b/transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/BrightnessFilterTransformation.java
@@ -1,14 +1,14 @@
package jp.wasabeef.glide.transformations.gpu;
/**
- * Copyright (C) 2017 Wasabeef
- *
+ * Copyright (C) 2020 Wasabeef
+ *
* 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
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* 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,38 +16,52 @@
* limitations under the License.
*/
-import android.content.Context;
-import com.bumptech.glide.Glide;
-import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
-import jp.co.cyberagent.android.gpuimage.GPUImageBrightnessFilter;
+import androidx.annotation.NonNull;
+
+import java.security.MessageDigest;
+
+import jp.co.cyberagent.android.gpuimage.filter.GPUImageBrightnessFilter;
/**
* brightness value ranges from -1.0 to 1.0, with 0.0 as the normal level
*/
public class BrightnessFilterTransformation extends GPUFilterTransformation {
- private float mBrightness;
+ private static final int VERSION = 1;
+ private static final String ID =
+ "jp.wasabeef.glide.transformations.gpu.BrightnessFilterTransformation." + VERSION;
- public BrightnessFilterTransformation(Context context) {
- this(context, Glide.get(context).getBitmapPool());
+ private final float brightness;
+
+ public BrightnessFilterTransformation() {
+ this(0.0f);
}
- public BrightnessFilterTransformation(Context context, BitmapPool pool) {
- this(context, pool, 0.0f);
+ public BrightnessFilterTransformation(float brightness) {
+ super(new GPUImageBrightnessFilter());
+ this.brightness = brightness;
+ GPUImageBrightnessFilter filter = getFilter();
+ filter.setBrightness(this.brightness);
}
- public BrightnessFilterTransformation(Context context, float brightness) {
- this(context, Glide.get(context).getBitmapPool(), brightness);
+ @Override
+ public String toString() {
+ return "BrightnessFilterTransformation(brightness=" + brightness + ")";
}
- public BrightnessFilterTransformation(Context context, BitmapPool pool, float brightness) {
- super(context, pool, new GPUImageBrightnessFilter());
- mBrightness = brightness;
- GPUImageBrightnessFilter filter = getFilter();
- filter.setBrightness(mBrightness);
+ @Override
+ public boolean equals(Object o) {
+ return o instanceof BrightnessFilterTransformation &&
+ ((BrightnessFilterTransformation) o).brightness == brightness;
+ }
+
+ @Override
+ public int hashCode() {
+ return ID.hashCode() + (int) ((brightness + 1.0f) * 10);
}
- @Override public String getId() {
- return "BrightnessFilterTransformation(brightness=" + mBrightness + ")";
+ @Override
+ public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
+ messageDigest.update((ID + brightness).getBytes(CHARSET));
}
}
diff --git a/transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/ContrastFilterTransformation.java b/transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/ContrastFilterTransformation.java
old mode 100644
new mode 100755
index 99eac5b..b6af2c0
--- a/transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/ContrastFilterTransformation.java
+++ b/transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/ContrastFilterTransformation.java
@@ -1,14 +1,14 @@
package jp.wasabeef.glide.transformations.gpu;
/**
- * Copyright (C) 2017 Wasabeef
- *
+ * Copyright (C) 2020 Wasabeef
+ *
* 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
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* 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,38 +16,51 @@
* limitations under the License.
*/
-import android.content.Context;
-import com.bumptech.glide.Glide;
-import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
-import jp.co.cyberagent.android.gpuimage.GPUImageContrastFilter;
+import androidx.annotation.NonNull;
+
+import java.security.MessageDigest;
+
+import jp.co.cyberagent.android.gpuimage.filter.GPUImageContrastFilter;
/**
* contrast value ranges from 0.0 to 4.0, with 1.0 as the normal level
*/
public class ContrastFilterTransformation extends GPUFilterTransformation {
- private float mContrast;
+ private static final int VERSION = 1;
+ private static final String ID =
+ "jp.wasabeef.glide.transformations.gpu.ContrastFilterTransformation." + VERSION;
- public ContrastFilterTransformation(Context context) {
- this(context, Glide.get(context).getBitmapPool());
+ private final float contrast;
+
+ public ContrastFilterTransformation() {
+ this(1.0f);
}
- public ContrastFilterTransformation(Context context, BitmapPool pool) {
- this(context, pool, 1.0f);
+ public ContrastFilterTransformation(float contrast) {
+ super(new GPUImageContrastFilter());
+ this.contrast = contrast;
+ GPUImageContrastFilter filter = getFilter();
+ filter.setContrast(this.contrast);
}
- public ContrastFilterTransformation(Context context, float contrast) {
- this(context, Glide.get(context).getBitmapPool(), contrast);
+ @Override
+ public String toString() {
+ return "ContrastFilterTransformation(contrast=" + contrast + ")";
}
- public ContrastFilterTransformation(Context context, BitmapPool pool, float contrast) {
- super(context, pool, new GPUImageContrastFilter());
- mContrast = contrast;
- GPUImageContrastFilter filter = getFilter();
- filter.setContrast(mContrast);
+ @Override
+ public boolean equals(Object o) {
+ return o instanceof ContrastFilterTransformation;
+ }
+
+ @Override
+ public int hashCode() {
+ return ID.hashCode() + (int) (contrast * 10);
}
- @Override public String getId() {
- return "ContrastFilterTransformation(contrast=" + mContrast + ")";
+ @Override
+ public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
+ messageDigest.update((ID + contrast).getBytes(CHARSET));
}
}
diff --git a/transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/GPUFilterTransformation.java b/transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/GPUFilterTransformation.java
old mode 100644
new mode 100755
index 72898eb..91a0aec
--- a/transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/GPUFilterTransformation.java
+++ b/transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/GPUFilterTransformation.java
@@ -1,14 +1,14 @@
package jp.wasabeef.glide.transformations.gpu;
/**
- * Copyright (C) 2017 Wasabeef
- *
+ * Copyright (C) 2020 Wasabeef
+ *
* 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
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* 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.
@@ -18,48 +18,62 @@
import android.content.Context;
import android.graphics.Bitmap;
-import com.bumptech.glide.Glide;
-import com.bumptech.glide.load.Transformation;
-import com.bumptech.glide.load.engine.Resource;
+
+import androidx.annotation.NonNull;
+
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
-import com.bumptech.glide.load.resource.bitmap.BitmapResource;
+
+import java.security.MessageDigest;
+
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 implements Transformation {
+public class GPUFilterTransformation extends BitmapTransformation {
- private Context mContext;
- private BitmapPool mBitmapPool;
+ private static final int VERSION = 1;
+ private static final String ID =
+ "jp.wasabeef.glide.transformations.gpu.GPUFilterTransformation." + VERSION;
+ private static final byte[] ID_BYTES = ID.getBytes(CHARSET);
- private GPUImageFilter mFilter;
+ private final GPUImageFilter gpuImageFilter;
- public GPUFilterTransformation(Context context, GPUImageFilter filter) {
- this(context, Glide.get(context).getBitmapPool(), filter);
+ public GPUFilterTransformation(GPUImageFilter filter) {
+ this.gpuImageFilter = filter;
}
- public GPUFilterTransformation(Context context, BitmapPool pool, GPUImageFilter filter) {
- mContext = context.getApplicationContext();
- mBitmapPool = pool;
- mFilter = filter;
+ @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);
+
+ return gpuImage.getBitmapWithFilterApplied();
}
@Override
- public Resource transform(Resource resource, int outWidth, int outHeight) {
- Bitmap source = resource.get();
- GPUImage gpuImage = new GPUImage(mContext);
- gpuImage.setImage(source);
- gpuImage.setFilter(mFilter);
+ public String toString() {
+ return getClass().getSimpleName();
+ }
- Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
+ @SuppressWarnings("unchecked")
+ public T getFilter() {
+ return (T) gpuImageFilter;
+ }
- return BitmapResource.obtain(bitmap, mBitmapPool);
+ @Override
+ public boolean equals(Object o) {
+ return o instanceof GPUFilterTransformation;
}
- @Override public String getId() {
- return getClass().getSimpleName();
+ @Override
+ public int hashCode() {
+ return ID.hashCode();
}
- @SuppressWarnings("unchecked") public T getFilter() {
- return (T) mFilter;
+ @Override
+ public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
+ messageDigest.update(ID_BYTES);
}
}
diff --git a/transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/InvertFilterTransformation.java b/transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/InvertFilterTransformation.java
old mode 100644
new mode 100755
index 57734ef..7e6503e
--- a/transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/InvertFilterTransformation.java
+++ b/transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/InvertFilterTransformation.java
@@ -1,14 +1,14 @@
package jp.wasabeef.glide.transformations.gpu;
/**
- * Copyright (C) 2017 Wasabeef
- *
+ * Copyright (C) 2020 Wasabeef
+ *
* 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
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* 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,25 +16,42 @@
* limitations under the License.
*/
-import android.content.Context;
-import com.bumptech.glide.Glide;
-import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
-import jp.co.cyberagent.android.gpuimage.GPUImageColorInvertFilter;
+import androidx.annotation.NonNull;
+
+import java.security.MessageDigest;
+
+import jp.co.cyberagent.android.gpuimage.filter.GPUImageColorInvertFilter;
/**
* Invert all the colors in the image.
*/
public class InvertFilterTransformation extends GPUFilterTransformation {
- public InvertFilterTransformation(Context context) {
- this(context, Glide.get(context).getBitmapPool());
- }
+ private static final int VERSION = 1;
+ private static final String ID =
+ "jp.wasabeef.glide.transformations.gpu.InvertFilterTransformation." + VERSION;
- public InvertFilterTransformation(Context context, BitmapPool pool) {
- super(context, pool, new GPUImageColorInvertFilter());
+ public InvertFilterTransformation() {
+ super(new GPUImageColorInvertFilter());
}
- @Override public String getId() {
+ @Override
+ public String toString() {
return "InvertFilterTransformation()";
}
+
+ @Override
+ public boolean equals(Object o) {
+ return o instanceof InvertFilterTransformation;
+ }
+
+ @Override
+ public int hashCode() {
+ return ID.hashCode();
+ }
+
+ @Override
+ public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
+ messageDigest.update((ID).getBytes(CHARSET));
+ }
}
diff --git a/transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/KuwaharaFilterTransformation.java b/transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/KuwaharaFilterTransformation.java
old mode 100644
new mode 100755
index 5c39a0e..78a5b2d
--- a/transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/KuwaharaFilterTransformation.java
+++ b/transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/KuwaharaFilterTransformation.java
@@ -1,14 +1,14 @@
package jp.wasabeef.glide.transformations.gpu;
/**
- * Copyright (C) 2017 Wasabeef
- *
+ * Copyright (C) 2020 Wasabeef
+ *
* 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
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* 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,41 +16,54 @@
* limitations under the License.
*/
-import android.content.Context;
-import com.bumptech.glide.Glide;
-import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
-import jp.co.cyberagent.android.gpuimage.GPUImageKuwaharaFilter;
+import androidx.annotation.NonNull;
+
+import java.security.MessageDigest;
+
+import jp.co.cyberagent.android.gpuimage.filter.GPUImageKuwaharaFilter;
/**
* Kuwahara all the colors in the image.
- *
+ *
* The radius to sample from when creating the brush-stroke effect, with a default of 25.
* The larger the radius, the slower the filter.
*/
public class KuwaharaFilterTransformation extends GPUFilterTransformation {
- private int mRadius;
+ private static final int VERSION = 1;
+ private static final String ID =
+ "jp.wasabeef.glide.transformations.gpu.KuwaharaFilterTransformation." + VERSION;
- public KuwaharaFilterTransformation(Context context) {
- this(context, Glide.get(context).getBitmapPool());
+ private final int radius;
+
+ public KuwaharaFilterTransformation() {
+ this(25);
}
- public KuwaharaFilterTransformation(Context context, BitmapPool pool) {
- this(context, pool, 25);
+ public KuwaharaFilterTransformation(int radius) {
+ super(new GPUImageKuwaharaFilter());
+ this.radius = radius;
+ GPUImageKuwaharaFilter filter = getFilter();
+ filter.setRadius(this.radius);
}
- public KuwaharaFilterTransformation(Context context, int radius) {
- this(context, Glide.get(context).getBitmapPool(), radius);
+ @Override
+ public String toString() {
+ return "KuwaharaFilterTransformation(radius=" + radius + ")";
}
- public KuwaharaFilterTransformation(Context context, BitmapPool pool, int radius) {
- super(context, pool, new GPUImageKuwaharaFilter());
- mRadius = radius;
- GPUImageKuwaharaFilter filter = getFilter();
- filter.setRadius(mRadius);
+ @Override
+ public boolean equals(Object o) {
+ return o instanceof KuwaharaFilterTransformation;
+ }
+
+ @Override
+ public int hashCode() {
+ return ID.hashCode() + radius * 10;
}
- @Override public String getId() {
- return "KuwaharaFilterTransformation(radius=" + mRadius + ")";
+ @Override
+ public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
+ messageDigest.update((ID + radius).getBytes(CHARSET));
}
}
diff --git a/transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/PixelationFilterTransformation.java b/transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/PixelationFilterTransformation.java
old mode 100644
new mode 100755
index a91844b..1b6fd12
--- a/transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/PixelationFilterTransformation.java
+++ b/transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/PixelationFilterTransformation.java
@@ -1,14 +1,14 @@
package jp.wasabeef.glide.transformations.gpu;
/**
- * Copyright (C) 2017 Wasabeef
- *
+ * Copyright (C) 2020 Wasabeef
+ *
* 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
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* 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,40 +16,53 @@
* limitations under the License.
*/
-import android.content.Context;
-import com.bumptech.glide.Glide;
-import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
-import jp.co.cyberagent.android.gpuimage.GPUImagePixelationFilter;
+import androidx.annotation.NonNull;
+
+import java.security.MessageDigest;
+
+import jp.co.cyberagent.android.gpuimage.filter.GPUImagePixelationFilter;
/**
* Applies a Pixelation effect to the image.
- *
+ *
* The pixel with a default of 10.0.
*/
public class PixelationFilterTransformation extends GPUFilterTransformation {
- private float mPixel;
+ private static final int VERSION = 1;
+ private static final String ID =
+ "jp.wasabeef.glide.transformations.gpu.PixelationFilterTransformation." + VERSION;
- public PixelationFilterTransformation(Context context) {
- this(context, Glide.get(context).getBitmapPool());
+ private final float pixel;
+
+ public PixelationFilterTransformation() {
+ this(10f);
}
- public PixelationFilterTransformation(Context context, BitmapPool pool) {
- this(context, pool, 10f);
+ public PixelationFilterTransformation(float pixel) {
+ super(new GPUImagePixelationFilter());
+ this.pixel = pixel;
+ GPUImagePixelationFilter filter = getFilter();
+ filter.setPixel(this.pixel);
}
- public PixelationFilterTransformation(Context context, float pixel) {
- this(context, Glide.get(context).getBitmapPool(), pixel);
+ @Override
+ public String toString() {
+ return "PixelationFilterTransformation(pixel=" + pixel + ")";
}
- public PixelationFilterTransformation(Context context, BitmapPool pool, float pixel) {
- super(context, pool, new GPUImagePixelationFilter());
- mPixel = pixel;
- GPUImagePixelationFilter filter = getFilter();
- filter.setPixel(mPixel);
+ @Override
+ public boolean equals(Object o) {
+ return o instanceof PixelationFilterTransformation;
+ }
+
+ @Override
+ public int hashCode() {
+ return ID.hashCode() + (int) (pixel * 10);
}
- @Override public String getId() {
- return "PixelationFilterTransformation(pixel=" + mPixel + ")";
+ @Override
+ public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
+ messageDigest.update((ID + pixel).getBytes(CHARSET));
}
}
diff --git a/transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/SepiaFilterTransformation.java b/transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/SepiaFilterTransformation.java
old mode 100644
new mode 100755
index 18c5d98..149f009
--- a/transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/SepiaFilterTransformation.java
+++ b/transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/SepiaFilterTransformation.java
@@ -1,14 +1,14 @@
package jp.wasabeef.glide.transformations.gpu;
/**
- * Copyright (C) 2017 Wasabeef
- *
+ * Copyright (C) 2020 Wasabeef
+ *
* 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
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* 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,40 +16,53 @@
* limitations under the License.
*/
-import android.content.Context;
-import com.bumptech.glide.Glide;
-import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
-import jp.co.cyberagent.android.gpuimage.GPUImageSepiaFilter;
+import androidx.annotation.NonNull;
+
+import java.security.MessageDigest;
+
+import jp.co.cyberagent.android.gpuimage.filter.GPUImageSepiaToneFilter;
/**
* Applies a simple sepia effect.
- *
+ *
* The intensity with a default of 1.0.
*/
public class SepiaFilterTransformation extends GPUFilterTransformation {
- private float mIntensity;
+ private static final int VERSION = 1;
+ private static final String ID =
+ "jp.wasabeef.glide.transformations.gpu.SepiaFilterTransformation." + VERSION;
+
+ private final float intensity;
+
+ public SepiaFilterTransformation() {
+ this(1.0f);
+ }
- public SepiaFilterTransformation(Context context) {
- this(context, Glide.get(context).getBitmapPool());
+ public SepiaFilterTransformation(float intensity) {
+ super(new GPUImageSepiaToneFilter());
+ this.intensity = intensity;
+ GPUImageSepiaToneFilter filter = getFilter();
+ filter.setIntensity(this.intensity);
}
- public SepiaFilterTransformation(Context context, BitmapPool pool) {
- this(context, pool, 1.0f);
+ @Override
+ public String toString() {
+ return "SepiaFilterTransformation(intensity=" + intensity + ")";
}
- public SepiaFilterTransformation(Context context, float intensity) {
- this(context, Glide.get(context).getBitmapPool(), intensity);
+ @Override
+ public boolean equals(Object o) {
+ return o instanceof SepiaFilterTransformation;
}
- public SepiaFilterTransformation(Context context, BitmapPool pool, float intensity) {
- super(context, pool, new GPUImageSepiaFilter());
- mIntensity = intensity;
- GPUImageSepiaFilter filter = getFilter();
- filter.setIntensity(mIntensity);
+ @Override
+ public int hashCode() {
+ return ID.hashCode() + (int) (intensity * 10);
}
- @Override public String getId() {
- return "SepiaFilterTransformation(intensity=" + mIntensity + ")";
+ @Override
+ public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
+ messageDigest.update((ID + intensity).getBytes(CHARSET));
}
}
diff --git a/transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/SketchFilterTransformation.java b/transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/SketchFilterTransformation.java
old mode 100644
new mode 100755
index e3d9fcb..d737a29
--- a/transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/SketchFilterTransformation.java
+++ b/transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/SketchFilterTransformation.java
@@ -1,14 +1,14 @@
package jp.wasabeef.glide.transformations.gpu;
/**
- * Copyright (C) 2017 Wasabeef
- *
+ * Copyright (C) 2020 Wasabeef
+ *
* 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
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* 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,22 +16,39 @@
* limitations under the License.
*/
-import android.content.Context;
-import com.bumptech.glide.Glide;
-import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
-import jp.co.cyberagent.android.gpuimage.GPUImageSketchFilter;
+import androidx.annotation.NonNull;
+
+import java.security.MessageDigest;
+
+import jp.co.cyberagent.android.gpuimage.filter.GPUImageSketchFilter;
public class SketchFilterTransformation extends GPUFilterTransformation {
- public SketchFilterTransformation(Context context) {
- this(context, Glide.get(context).getBitmapPool());
- }
+ private static final int VERSION = 1;
+ private static final String ID =
+ "jp.wasabeef.glide.transformations.gpu.SketchFilterTransformation." + VERSION;
- public SketchFilterTransformation(Context context, BitmapPool pool) {
- super(context, pool, new GPUImageSketchFilter());
+ public SketchFilterTransformation() {
+ super(new GPUImageSketchFilter());
}
- @Override public String getId() {
+ @Override
+ public String toString() {
return "SketchFilterTransformation()";
}
+
+ @Override
+ public boolean equals(Object o) {
+ return o instanceof SketchFilterTransformation;
+ }
+
+ @Override
+ public int hashCode() {
+ return ID.hashCode();
+ }
+
+ @Override
+ public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
+ messageDigest.update((ID).getBytes(CHARSET));
+ }
}
diff --git a/transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/SwirlFilterTransformation.java b/transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/SwirlFilterTransformation.java
old mode 100644
new mode 100755
index 14ad45d..3ff0043
--- a/transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/SwirlFilterTransformation.java
+++ b/transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/SwirlFilterTransformation.java
@@ -1,14 +1,14 @@
package jp.wasabeef.glide.transformations.gpu;
/**
- * Copyright (C) 2017 Wasabeef
- *
+ * Copyright (C) 2020 Wasabeef
+ *
* 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
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* 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,52 +16,68 @@
* limitations under the License.
*/
-import android.content.Context;
import android.graphics.PointF;
-import com.bumptech.glide.Glide;
-import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
-import jp.co.cyberagent.android.gpuimage.GPUImageSwirlFilter;
+
+import androidx.annotation.NonNull;
+
+import java.security.MessageDigest;
+
+import jp.co.cyberagent.android.gpuimage.filter.GPUImageSwirlFilter;
/**
* Creates a swirl distortion on the image.
*/
public class SwirlFilterTransformation extends GPUFilterTransformation {
- private float mRadius;
- private float mAngle;
- private PointF mCenter;
+ private static final int VERSION = 1;
+ private static final String ID =
+ "jp.wasabeef.glide.transformations.gpu.SwirlFilterTransformation." + VERSION;
- public SwirlFilterTransformation(Context context) {
- this(context, Glide.get(context).getBitmapPool());
- }
-
- public SwirlFilterTransformation(Context context, BitmapPool pool) {
- this(context, pool, .5f, 1.0f, new PointF(0.5f, 0.5f));
- }
+ private final float radius;
+ private final float angle;
+ private final PointF center;
- public SwirlFilterTransformation(Context context, float radius, float angle, PointF center) {
- this(context, Glide.get(context).getBitmapPool(), radius, angle, center);
+ public SwirlFilterTransformation() {
+ this(.5f, 1.0f, new PointF(0.5f, 0.5f));
}
/**
* @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(Context context, BitmapPool pool, float radius, float angle,
- PointF center) {
- super(context, pool, new GPUImageSwirlFilter());
- mRadius = radius;
- mAngle = angle;
- mCenter = center;
+ public SwirlFilterTransformation(float radius, float angle, PointF center) {
+ super(new GPUImageSwirlFilter());
+ this.radius = radius;
+ this.angle = angle;
+ this.center = center;
GPUImageSwirlFilter filter = getFilter();
- filter.setRadius(mRadius);
- filter.setAngle(mAngle);
- filter.setCenter(mCenter);
+ filter.setRadius(this.radius);
+ filter.setAngle(this.angle);
+ filter.setCenter(this.center);
+ }
+
+ @Override
+ public String toString() {
+ return "SwirlFilterTransformation(radius=" + radius + ",angle=" + angle + ",center="
+ + center.toString() + ")";
+ }
+
+ @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() {
+ return ID.hashCode() + (int) (radius * 1000) + (int) (angle * 10) + center.hashCode();
}
- @Override public String getId() {
- return "SwirlFilterTransformation(radius=" + mRadius +
- ",angle=" + mAngle + ",center=" + mCenter.toString() + ")";
+ @Override
+ public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
+ messageDigest.update((ID + radius + angle + center.hashCode()).getBytes(CHARSET));
}
}
diff --git a/transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/ToonFilterTransformation.java b/transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/ToonFilterTransformation.java
old mode 100644
new mode 100755
index 9d6bcf7..de11c3e
--- a/transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/ToonFilterTransformation.java
+++ b/transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/ToonFilterTransformation.java
@@ -1,14 +1,14 @@
package jp.wasabeef.glide.transformations.gpu;
/**
- * Copyright (C) 2017 Wasabeef
- *
+ * Copyright (C) 2020 Wasabeef
+ *
* 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
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* 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,11 @@
* limitations under the License.
*/
-import android.content.Context;
-import com.bumptech.glide.Glide;
-import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
-import jp.co.cyberagent.android.gpuimage.GPUImageToonFilter;
+import androidx.annotation.NonNull;
+
+import java.security.MessageDigest;
+
+import jp.co.cyberagent.android.gpuimage.filter.GPUImageToonFilter;
/**
* The threshold at which to apply the edges, default of 0.2.
@@ -28,33 +29,46 @@
*/
public class ToonFilterTransformation extends GPUFilterTransformation {
- private float mThreshold;
- private float mQuantizationLevels;
+ private static final int VERSION = 1;
+ private static final String ID =
+ "jp.wasabeef.glide.transformations.gpu.ToonFilterTransformation." + VERSION;
- public ToonFilterTransformation(Context context) {
- this(context, Glide.get(context).getBitmapPool());
+ private final float threshold;
+ private final float quantizationLevels;
+
+ public ToonFilterTransformation() {
+ this(.2f, 10.0f);
}
- public ToonFilterTransformation(Context context, BitmapPool pool) {
- this(context, pool, .2f, 10.0f);
+ public ToonFilterTransformation(float threshold, float quantizationLevels) {
+ super(new GPUImageToonFilter());
+ this.threshold = threshold;
+ this.quantizationLevels = quantizationLevels;
+ GPUImageToonFilter filter = getFilter();
+ filter.setThreshold(this.threshold);
+ filter.setQuantizationLevels(this.quantizationLevels);
}
- public ToonFilterTransformation(Context context, float threshold, float quantizationLevels) {
- this(context, Glide.get(context).getBitmapPool(), threshold, quantizationLevels);
+ @Override
+ public String toString() {
+ return "ToonFilterTransformation(threshold=" + threshold + ",quantizationLevels="
+ + quantizationLevels + ")";
}
- public ToonFilterTransformation(Context context, BitmapPool pool, float threshold,
- float quantizationLevels) {
- super(context, pool, new GPUImageToonFilter());
- mThreshold = threshold;
- mQuantizationLevels = quantizationLevels;
- GPUImageToonFilter filter = getFilter();
- filter.setThreshold(mThreshold);
- filter.setQuantizationLevels(mQuantizationLevels);
+ @Override
+ public boolean equals(Object o) {
+ return o instanceof ToonFilterTransformation &&
+ ((ToonFilterTransformation) o).threshold == threshold &&
+ ((ToonFilterTransformation) o).quantizationLevels == quantizationLevels;
+ }
+
+ @Override
+ public int hashCode() {
+ return ID.hashCode() + (int) (threshold * 1000) + (int) (quantizationLevels * 10);
}
- @Override public String getId() {
- return "ToonFilterTransformation(threshold=" + mThreshold +
- ",quantizationLevels=" + mQuantizationLevels + ")";
+ @Override
+ public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
+ messageDigest.update((ID + threshold + quantizationLevels).getBytes(CHARSET));
}
}
diff --git a/transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/VignetteFilterTransformation.java b/transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/VignetteFilterTransformation.java
old mode 100644
new mode 100755
index b3eb248..22450c1
--- a/transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/VignetteFilterTransformation.java
+++ b/transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/VignetteFilterTransformation.java
@@ -1,14 +1,14 @@
package jp.wasabeef.glide.transformations.gpu;
/**
- * Copyright (C) 2017 Wasabeef
- *
+ * Copyright (C) 2020 Wasabeef
+ *
* 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
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* 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,12 +16,14 @@
* limitations under the License.
*/
-import android.content.Context;
import android.graphics.PointF;
-import com.bumptech.glide.Glide;
-import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
+
+import androidx.annotation.NonNull;
+
+import java.security.MessageDigest;
import java.util.Arrays;
-import jp.co.cyberagent.android.gpuimage.GPUImageVignetteFilter;
+
+import jp.co.cyberagent.android.gpuimage.filter.GPUImageVignetteFilter;
/**
* Performs a vignetting effect, fading out the image at the edges
@@ -30,41 +32,55 @@
*/
public class VignetteFilterTransformation extends GPUFilterTransformation {
- private PointF mCenter;
- private float[] mVignetteColor;
- private float mVignetteStart;
- private float mVignetteEnd;
+ private static final int VERSION = 1;
+ private static final String ID =
+ "jp.wasabeef.glide.transformations.gpu.VignetteFilterTransformation." + VERSION;
+
+ private final PointF center;
+ private final float[] vignetteColor;
+ private final float vignetteStart;
+ private final float vignetteEnd;
- public VignetteFilterTransformation(Context context) {
- this(context, Glide.get(context).getBitmapPool());
+ public VignetteFilterTransformation() {
+ this(new PointF(0.5f, 0.5f), new float[]{0.0f, 0.0f, 0.0f}, 0.0f, 0.75f);
}
- public VignetteFilterTransformation(Context context, BitmapPool pool) {
- this(context, pool, 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) {
+ super(new GPUImageVignetteFilter());
+ this.center = center;
+ vignetteColor = color;
+ vignetteStart = start;
+ vignetteEnd = end;
+ GPUImageVignetteFilter filter = getFilter();
+ filter.setVignetteCenter(this.center);
+ filter.setVignetteColor(vignetteColor);
+ filter.setVignetteStart(vignetteStart);
+ filter.setVignetteEnd(vignetteEnd);
}
- public VignetteFilterTransformation(Context context, PointF center, float[] color, float start,
- float end) {
- this(context, Glide.get(context).getBitmapPool(), center, color, start, end);
+ @Override
+ public String toString() {
+ return "VignetteFilterTransformation(center=" + center.toString() + ",color=" + Arrays.toString(
+ vignetteColor) + ",start=" + vignetteStart + ",end=" + vignetteEnd + ")";
}
- public VignetteFilterTransformation(Context context, BitmapPool pool, PointF center,
- float[] color, float start, float end) {
- super(context, pool, new GPUImageVignetteFilter());
- mCenter = center;
- mVignetteColor = color;
- mVignetteStart = start;
- mVignetteEnd = end;
- GPUImageVignetteFilter filter = getFilter();
- filter.setVignetteCenter(mCenter);
- filter.setVignetteColor(mVignetteColor);
- filter.setVignetteStart(mVignetteStart);
- filter.setVignetteEnd(mVignetteEnd);
+ @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;
+ }
+
+ @Override
+ public int hashCode() {
+ return ID.hashCode() + center.hashCode() + Arrays.hashCode(vignetteColor) +
+ (int) (vignetteStart * 100) + (int) (vignetteEnd * 10);
}
- @Override public String getId() {
- return "VignetteFilterTransformation(center=" + mCenter.toString() +
- ",color=" + Arrays.toString(mVignetteColor) +
- ",start=" + mVignetteStart + ",end=" + mVignetteEnd + ")";
+ @Override
+ public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
+ messageDigest.update((ID + center + Arrays.hashCode(vignetteColor) + vignetteStart + vignetteEnd).getBytes(CHARSET));
}
}
diff --git a/transformations/src/main/java/jp/wasabeef/glide/transformations/internal/FastBlur.java b/transformations/src/main/java/jp/wasabeef/glide/transformations/internal/FastBlur.java
index 3fcea0a..3275b86 100644
--- a/transformations/src/main/java/jp/wasabeef/glide/transformations/internal/FastBlur.java
+++ b/transformations/src/main/java/jp/wasabeef/glide/transformations/internal/FastBlur.java
@@ -3,14 +3,14 @@
import android.graphics.Bitmap;
/**
- * Copyright (C) 2017 Wasabeef
- *
+ * Copyright (C) 2020 Wasabeef
+ *
* 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
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* 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.
@@ -72,15 +72,15 @@ public static Bitmap blur(Bitmap sentBitmap, int radius, boolean canReuseInBitma
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, gsum, bsum, x, y, i, p, yp, yi, 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);
}
@@ -254,4 +254,4 @@ public static Bitmap blur(Bitmap sentBitmap, int radius, boolean canReuseInBitma
return (bitmap);
}
-}
\ No newline at end of file
+}
diff --git a/transformations/src/main/java/jp/wasabeef/glide/transformations/internal/RSBlur.java b/transformations/src/main/java/jp/wasabeef/glide/transformations/internal/RSBlur.java
index 62f4cba..a2827dc 100644
--- a/transformations/src/main/java/jp/wasabeef/glide/transformations/internal/RSBlur.java
+++ b/transformations/src/main/java/jp/wasabeef/glide/transformations/internal/RSBlur.java
@@ -11,14 +11,14 @@
import android.renderscript.ScriptIntrinsicBlur;
/**
- * Copyright (C) 2017 Wasabeef
- *
+ * Copyright (C) 2020 Wasabeef
+ *
* 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
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* 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.
@@ -28,7 +28,6 @@
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;
@@ -38,7 +37,7 @@ public static Bitmap blur(Context context, Bitmap bitmap, int radius) throws RSR
rs = RenderScript.create(context);
rs.setMessageHandler(new RenderScript.RSMessageHandler());
input = Allocation.createFromBitmap(rs, bitmap, Allocation.MipmapControl.MIPMAP_NONE,
- Allocation.USAGE_SCRIPT);
+ Allocation.USAGE_SCRIPT);
output = Allocation.createTyped(rs, input.getType());
blur = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
@@ -48,7 +47,11 @@ public static Bitmap blur(Context context, Bitmap bitmap, int radius) throws RSR
output.copyTo(bitmap);
} finally {
if (rs != null) {
- rs.destroy();
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
+ RenderScript.releaseAllContexts();
+ } else {
+ rs.destroy();
+ }
}
if (input != null) {
input.destroy();
diff --git a/transformations/src/main/java/jp/wasabeef/glide/transformations/internal/Utils.java b/transformations/src/main/java/jp/wasabeef/glide/transformations/internal/Utils.java
index 04f7abc..1b8ee5e 100644
--- a/transformations/src/main/java/jp/wasabeef/glide/transformations/internal/Utils.java
+++ b/transformations/src/main/java/jp/wasabeef/glide/transformations/internal/Utils.java
@@ -1,18 +1,19 @@
package jp.wasabeef.glide.transformations.internal;
import android.content.Context;
+import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Build;
/**
- * Copyright (C) 2017 Wasabeef
- *
+ * Copyright (C) 2020 Wasabeef
+ *
* 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
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* 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.
@@ -26,18 +27,7 @@ private 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;
}
}