diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..abde953 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,8 @@ +[*] +indent_size = 2 +max_line_length = off +insert_final_newline = true + +[*.{kt, kts}] +kotlin_imports_layout = ascii + diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..38f87b6 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,12 @@ +# These are supported funding model platforms + +github: wasabeef # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] +patreon: # Replace with a single Patreon username +open_collective: # Replace with a single Open Collective username +ko_fi: # Replace with a single Ko-fi username +tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel +community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry +liberapay: # Replace with a single Liberapay username +issuehunt: # Replace with a single IssueHunt username +otechie: # Replace with a single Otechie username +custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md new file mode 100644 index 0000000..9ddc912 --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,28 @@ +# Future Task + +## What is the motivation? + +## What kind of solution can be considered? + +## What do you want to discuss? + +*Please add relevant labels* + +----- + +# Bug Reporting + +## Steps to Reproduce + +## Actual Results (include screenshots) + +## Expected Results (include screenshots) + +## URL + +## OS details + +- Device: +- OS: + +*Please add relevant labels* diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..9a97254 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,6 @@ +## What does this change? + +## What is the value of this and can you measure success? + +## Screenshots + diff --git a/.gitignore b/.gitignore index f99652d..9ef0bff 100644 --- a/.gitignore +++ b/.gitignore @@ -1,19 +1,23 @@ -.DS_Store -Thumbs.db +# Mac OS +.DS_store -# gradle files -.gradle +# Built application files +*.apk +*.ap_ -# Intellij project files -.idea -*.iml +# Files for the ART/Dalvik VM +*.dex + +# Java class files +*.class -# generated files +# Generated files bin/ gen/ -obj/ -apk/ -target/ +out/ + +# Gradle files +.gradle/ build/ # Local configuration file (sdk path, etc) @@ -21,3 +25,41 @@ local.properties # Proguard folder generated by Eclipse proguard/ + +# Log Files +*.log + +# Android Studio Navigation editor temp files +.navigation/ + +# Android Studio captures folder +captures/ + +# IntelliJ +*.iml +.idea/workspace.xml +.idea/tasks.xml +.idea/gradle.xml +.idea/assetWizardSettings.xml +.idea/dictionaries +.idea/libraries +.idea/caches +.idea/misc.xml +.idea/modules.xml +.idea/navEditor.xml +.idea/markdown* +.idea/jarRepositories.xml +.idea/inspectionProfiles/Project_Default.xml +.idea/compiler.xml +projectFilesBackup/ + +# Keystore files +# Uncomment the following line if you do not want to check your keystore files in. +#*.jks + +# External native build folder generated in Android Studio 2.2 and later +.externalNativeBuild + +# Google Services (e.g. APIs or Firebase) +google-services.json + diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..681f41a --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,116 @@ + + + + + + + +
+ + + + xmlns:android + + ^$ + + + +
+
+ + + + xmlns:.* + + ^$ + + + BY_NAME + +
+
+ + + + .*:id + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + .*:name + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + name + + ^$ + + + +
+
+ + + + style + + ^$ + + + +
+
+ + + + .* + + ^$ + + + BY_NAME + +
+
+ + + + .* + + http://schemas.android.com/apk/res/android + + + ANDROID_ATTRIBUTE_ORDER + +
+
+ + + + .* + + .* + + + BY_NAME + +
+
+
+
+
+
\ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..a55e7a1 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..15a15b2 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..e497da9 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,13 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index e6f4606..b61609d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,119 @@ Change Log ========== +Version 4.3.0 *(2020-09-27)* +---------------------------- + +Feature +- Remove support v8 renderscript (Please use BlurTransformation) + +Update +- minSdkVersion -> 21 +- GPUImage -> 2.1.0 +- Cleanup codes + +Version 4.2.0 *(2020-09-15)* +---------------------------- + +Update: +- Compile & Target SDK Version 28 -> 30 +- GPUImage 2.0.3 -> 2.0.4 +- Glide 4.9.0 -> 4.11.0 + +Bugfix: +- RoundedCornersTransformation with DIAGONAL_FROM_TOP_LEFT does not work [#178](https://github.com/wasabeef/glide-transformations/pull/178) + +Version 4.1.0 *(2019-08-15)* +---------------------------- + +Add: +- Support to CropCircle with Border [#136](https://github.com/wasabeef/glide-transformations/pull/136) + +Update: +- Glide to 4.9.0 +- Android Gradle plugin to 3.6.0-alpha05 +- Kotlin to 1.3.41 + +Bug Fix: +- Fix diffrent density [#147](https://github.com/wasabeef/glide-transformations/pull/147) + + +Version 4.0.1 *(2018-11-20)* +---------------------------- + +Add: +- consumerProguardFiles setting + +Version 4.0.0 *(2018-11-16)* +---------------------------- + +Update: +- Migrate to AndroidX +- Remove novoda-bintray-plugin + +Version 3.3.0 *(2018-04-23)* +---------------------------- + +Update: +- Support Library 27.1.0 -> 27.1.1 +- Glide 4.6.1 -> 4.7.1 + +Feature: +- SupportRSBlurTransformation [#125](https://github.com/wasabeef/glide-transformations/pull/125) + it's using RenderScript support mode but can you choose to use or not. + Thank you [@fougere-mike](https://github.com/fougere-mike) + +Bug Fix: +- Set detail of Cache key [#119](https://github.com/wasabeef/glide-transformations/issues/119) + +Version 3.2.0 *(2018-04-10)* +---------------------------- + +Update: +- Support Library 27.0.2 -> 27.1.0 + +Bug Fix: +- We quit use the RenderScript [#120](https://github.com/wasabeef/glide-transformations/issues/120) + +Version 3.1.1 *(2018-02-13)* +---------------------------- + +Update: +- Glide 4.5.0 -> 4.6.1 + +Bug Fix: +- Fix settings fot proguard. + +Version 3.1.0 *(2018-01-26)* +---------------------------- + +Update: +- Compile & Target SDK Version 25 -> 27 +- Build Tools 26.0.1 -> 27.0.3 +- Support Library 25.3.1 -> 27.0.2 +- Glide 4.0.0 -> 4.5.0 + +Bug Fix: +- [Implement equals() and hashCode() methods #105](https://github.com/wasabeef/glide-transformations/pull/105) +- Use RenderScript#releaseAllContexts + +Version 3.0.1 *(2017-09-08)* +---------------------------- + +Bug Fix: +- [Deleted a setting for DexGuard #86](https://github.com/wasabeef/glide-transformations/issues/86) + +Version 3.0.0 *(2017-09-06)* +---------------------------- + +Update: +- Build Tools 25.0.2 -> 26.0.1 +- Min SDK Version 11 -> 14 +- Glide 3.7.0 -> 4.0.0 + +Feature: +- Supported Glide 4.0.0 + Version 2.0.2 *(2017-03-17)* ---------------------------- diff --git a/README.md b/README.md index bff6911..edf22c2 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Glide Transformations ====================== [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-glide--transformations-brightgreen.svg?style=flat)](https://android-arsenal.com/details/1/1363) [![License](https://img.shields.io/badge/license-Apache%202-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0) -[![Download](https://api.bintray.com/packages/wasabeef/maven/glide-transformations/images/download.svg)](https://bintray.com/wasabeef/maven/glide-transformations/_latestVersion) +[![Maven Central](https://maven-badges.herokuapp.com/maven-central/jp.wasabeef/glide-transformations/badge.svg)](https://search.maven.org/artifact/jp.wasabeef/glide-transformations) An Android transformation library providing a variety of image transformations for [Glide](https://github.com/bumptech/glide). @@ -28,13 +28,13 @@ Please feel free to use this. #### Gradle ```groovy repositories { - jcenter() + mavenCentral() } dependencies { - compile 'jp.wasabeef:glide-transformations:2.0.2' - // If you want to use the GPU Filters - compile 'jp.co.cyberagent.android.gpuimage:gpuimage-library:1.4.1' + implementation 'jp.wasabeef:glide-transformations:4.3.0' + // If you want to use the GPU Filters + implementation 'jp.co.cyberagent.android:gpuimage:2.1.0' } ``` @@ -42,44 +42,57 @@ dependencies { Set Glide Transform. -```java +```kotlin Glide.with(this).load(R.drawable.demo) - .bitmapTransform(new BlurTransformation(context)) - .into((ImageView) findViewById(R.id.image)); + .apply(RequestOptions.bitmapTransform(BlurTransformation(25, 3))) + .into(imageView) ``` ## Advanced Step 3 You can set a multiple transformations. -```java +```kotlin +val multi = MultiTransformation( + BlurTransformation(25), + RoundedCornersTransformation(128, 0, CornerType.BOTTOM)))) Glide.with(this).load(R.drawable.demo) - .bitmapTransform(new BlurTransformation(context, 25), new CropCircleTransformation(context)) - .into((ImageView) findViewById(R.id.image)); + .apply(RequestOptions.bitmapTransform(multi)) + .into(imageView)) ``` ## Transformations ### Crop -`CropTransformation`, `CropCircleTransformation`, `CropSquareTransformation`, -`RoundedCornersTransformation` +- `CropTransformation` +- `CropCircleTransformation` +- `CropCircleWithBorderTransformation` +- `CropSquareTransformation` +- `RoundedCornersTransformation` ### Color -`ColorFilterTransformation`, `GrayscaleTransformation` +- `ColorFilterTransformation` +- `GrayscaleTransformation` ### Blur -`BlurTransformation` +- `BlurTransformation` ### Mask -`MaskTransformation` +- `MaskTransformation` ### GPU Filter (use [GPUImage](https://github.com/CyberAgent/android-gpuimage)) **Will require add dependencies for GPUImage.** -`ToonFilterTransformation`, `SepiaFilterTransformation`, `ContrastFilterTransformation` -`InvertFilterTransformation`, `PixelationFilterTransformation`, `SketchFilterTransformation` -`SwirlFilterTransformation`, `BrightnessFilterTransformation`, `KuwaharaFilterTransformation` -`VignetteFilterTransformation` +- `ToonFilterTransformation` +- `SepiaFilterTransformation` +- `ContrastFilterTransformation` +- `InvertFilterTransformation` +- `PixelationFilterTransformation` +- `SketchFilterTransformation` +- `SwirlFilterTransformation` +- `BrightnessFilterTransformation` +- `KuwaharaFilterTransformation` +- `VignetteFilterTransformation` Applications using Glide Transformations @@ -91,6 +104,10 @@ Icon | Application ------------ | ------------- | [Ameba Ownd](https://play.google.com/store/apps/details?id=jp.co.cyberagent.madrid) | [AbemaTV](https://play.google.com/store/apps/details?id=tv.abema) + | [TV Time](https://play.google.com/store/apps/details?id=com.tozelabs.tvshowtime) + | [Christmas Radio](https://play.google.com/store/apps/details?id=nl.netwaves.christmasradio) + + Developed By ------- @@ -106,10 +123,11 @@ Contributions Any contributions are welcome! -Contributers +Contributors ------- * [start141](https://github.com/start141) +* [squeeish](https://github.com/squeeish) Thanks ------- @@ -119,7 +137,7 @@ Thanks License ------- - Copyright 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. diff --git a/build.gradle b/build.gradle index 8a67314..9d4a8c1 100644 --- a/build.gradle +++ b/build.gradle @@ -1,18 +1,30 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - repositories { - jcenter() - } - dependencies { - classpath 'com.android.tools.build:gradle:2.3.0' - classpath 'com.novoda:bintray-release:0.3.4' - } + ext { + kotlin_version = '1.3.72' + glide_version = '4.11.0' + gpuimage_version = '2.1.0' + } + + repositories { + google() + jcenter() + } + dependencies { + classpath 'com.android.tools.build:gradle:4.2.0-beta04' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + + // TODO: Close JCenter on May 1st https://jfrog.com/blog/into-the-sunset-bintray-jcenter-gocenter-and-chartcenter/ +// classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.5' +// classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' + } } allprojects { - repositories { - jcenter() - mavenCentral() - } + repositories { + google() + mavenCentral() + jcenter() + } } diff --git a/example/build.gradle b/example/build.gradle index 95d1cc5..1679ca8 100644 --- a/example/build.gradle +++ b/example/build.gradle @@ -1,58 +1,46 @@ apply plugin: 'com.android.application' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-kapt' 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() + versionCode VERSION_CODE as int versionName VERSION_NAME } - signingConfigs { - release { - storeFile file(keyStoreProperty) - keyAlias keyAliasProperty - storePassword keyStorePasswordProperty - keyPassword keyAliasPasswordProperty - } - } + // SigningConfigs + apply from: '../signingConfigs/debug.gradle', to: android buildTypes { debug { debuggable true - zipAlignEnabled true + signingConfig signingConfigs.debug } release { debuggable false zipAlignEnabled true - signingConfig signingConfigs.release + minifyEnabled true + shrinkResources true } } } -def getKeyStoreProperty() { - return hasProperty('WASABEEF_KEYSTORE') ? WASABEEF_KEYSTORE : "debug.keystore" -} - -def getKeyAliasProperty() { - return hasProperty('WASABEEF_KEYALIAS') ? WASABEEF_KEYALIAS : "android" -} - -def getKeyStorePasswordProperty() { - return hasProperty('WASABEEF_KEYSTOREPASSWORD') ? WASABEEF_KEYSTOREPASSWORD : "androiddebugkey" -} - -def getKeyAliasPasswordProperty() { - return hasProperty('WASABEEF_KEYALIASPASSWORD') ? WASABEEF_KEYALIASPASSWORD : "android" +repositories { +// maven { url = "https://oss.sonatype.org/content/repositories/snapshots"} } dependencies { - compile project(':transformations') - compile "com.github.bumptech.glide:glide:${GLIDE_VERSION}" - compile "jp.co.cyberagent.android.gpuimage:gpuimage-library:${GPUIMAGE_VERSION}" - compile "com.android.support:appcompat-v7:${SUPPORT_PACKAGE_VERSION}" - compile "com.android.support:recyclerview-v7:${SUPPORT_PACKAGE_VERSION}" +// implementation project(':transformations') + implementation 'jp.wasabeef:glide-transformations:4.3.0' + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation "com.github.bumptech.glide:glide:$glide_version" + kapt "com.github.bumptech.glide:compiler:$glide_version" + implementation "jp.co.cyberagent.android:gpuimage:$gpuimage_version" + implementation "androidx.appcompat:appcompat:1.3.0-beta01" + implementation "androidx.recyclerview:recyclerview:1.2.0-beta01" + implementation 'androidx.constraintlayout:constraintlayout:2.0.4' } diff --git a/example/proguard-rules.pro b/example/proguard-rules.pro new file mode 100644 index 0000000..e69de29 diff --git a/example/src/main/AndroidManifest.xml b/example/src/main/AndroidManifest.xml index 2e838d2..2c18882 100644 --- a/example/src/main/AndroidManifest.xml +++ b/example/src/main/AndroidManifest.xml @@ -1,22 +1,21 @@ + xmlns:tools="http://schemas.android.com/tools" + package="jp.wasabeef.example.glide"> + tools:ignore="GoogleAppIndexingWarning"> + android:label="@string/app_name"> - + - + diff --git a/example/src/main/java/jp/wasabeef/example/glide/Utils.java b/example/src/main/java/jp/wasabeef/example/glide/Ext.kt similarity index 66% rename from example/src/main/java/jp/wasabeef/example/glide/Utils.java rename to example/src/main/java/jp/wasabeef/example/glide/Ext.kt index 4c2da8e..850935e 100644 --- a/example/src/main/java/jp/wasabeef/example/glide/Utils.java +++ b/example/src/main/java/jp/wasabeef/example/glide/Ext.kt @@ -1,7 +1,7 @@ -package jp.wasabeef.example.glide; +package jp.wasabeef.example.glide /** - * 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. @@ -16,12 +16,8 @@ * limitations under the License. */ -import android.content.Context; +import android.content.res.Resources -public class Utils { +val Float.px: Float get() = (this * Resources.getSystem().displayMetrics.density) - public static int dip2px(Context context, float dp) { - float scale = context.getResources().getDisplayMetrics().density; - return (int) (dp * scale + 0.5f); - } -} +val Int.px: Int get() = ((this * Resources.getSystem().displayMetrics.density).toInt()) diff --git a/example/src/main/java/jp/wasabeef/example/glide/MainActivity.java b/example/src/main/java/jp/wasabeef/example/glide/MainActivity.java deleted file mode 100644 index 7819568..0000000 --- a/example/src/main/java/jp/wasabeef/example/glide/MainActivity.java +++ /dev/null @@ -1,45 +0,0 @@ -package jp.wasabeef.example.glide; - -import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.GridLayoutManager; -import android.support.v7.widget.RecyclerView; -import java.util.ArrayList; -import java.util.List; -import jp.wasabeef.example.glide.MainAdapter.Type; - -public class MainActivity extends AppCompatActivity { - - @Override protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); - - RecyclerView recyclerView = (RecyclerView) findViewById(R.id.list); - recyclerView.setLayoutManager(new GridLayoutManager(this, 2)); - - List dataSet = new ArrayList<>(); - dataSet.add(Type.Mask); - dataSet.add(Type.NinePatchMask); - dataSet.add(Type.CropTop); - dataSet.add(Type.CropCenter); - dataSet.add(Type.CropBottom); - dataSet.add(Type.CropSquare); - dataSet.add(Type.CropCircle); - dataSet.add(Type.ColorFilter); - dataSet.add(Type.Grayscale); - dataSet.add(Type.RoundedCorners); - dataSet.add(Type.Blur); - dataSet.add(Type.Toon); - dataSet.add(Type.Sepia); - dataSet.add(Type.Contrast); - dataSet.add(Type.Invert); - dataSet.add(Type.Pixel); - dataSet.add(Type.Sketch); - dataSet.add(Type.Swirl); - dataSet.add(Type.Brightness); - dataSet.add(Type.Kuawahara); - dataSet.add(Type.Vignette); - - recyclerView.setAdapter(new MainAdapter(this, dataSet)); - } -} diff --git a/example/src/main/java/jp/wasabeef/example/glide/MainActivity.kt b/example/src/main/java/jp/wasabeef/example/glide/MainActivity.kt new file mode 100644 index 0000000..c2939ba --- /dev/null +++ b/example/src/main/java/jp/wasabeef/example/glide/MainActivity.kt @@ -0,0 +1,24 @@ +package jp.wasabeef.example.glide + +import android.os.Bundle +import androidx.appcompat.app.AppCompatActivity +import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView +import jp.wasabeef.example.glide.MainAdapter.Type.* + +class MainActivity : AppCompatActivity() { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main) + + findViewById(R.id.list).apply { + layoutManager = LinearLayoutManager(context) + adapter = MainAdapter(context, mutableListOf( + Mask, NinePatchMask, RoundedCorners, CropTop, CropCenter, CropBottom, CropSquare, CropCircle, + CropCircleWithBorder, Grayscale, BlurLight, BlurDeep, Toon, Sepia, Contrast, Invert, + Pixel, Sketch, Swirl, Brightness, Kuawahara, Vignette + )) + } + } +} diff --git a/example/src/main/java/jp/wasabeef/example/glide/MainAdapter.java b/example/src/main/java/jp/wasabeef/example/glide/MainAdapter.java deleted file mode 100644 index cf626db..0000000 --- a/example/src/main/java/jp/wasabeef/example/glide/MainAdapter.java +++ /dev/null @@ -1,239 +0,0 @@ -package jp.wasabeef.example.glide; - -import android.content.Context; -import android.graphics.Color; -import android.graphics.PointF; -import android.support.v7.widget.RecyclerView; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ImageView; -import android.widget.TextView; -import com.bumptech.glide.Glide; -import com.bumptech.glide.load.resource.bitmap.CenterCrop; -import java.util.List; -import jp.wasabeef.glide.transformations.BlurTransformation; -import jp.wasabeef.glide.transformations.ColorFilterTransformation; -import jp.wasabeef.glide.transformations.CropCircleTransformation; -import jp.wasabeef.glide.transformations.CropSquareTransformation; -import jp.wasabeef.glide.transformations.CropTransformation; -import jp.wasabeef.glide.transformations.GrayscaleTransformation; -import jp.wasabeef.glide.transformations.MaskTransformation; -import jp.wasabeef.glide.transformations.RoundedCornersTransformation; -import jp.wasabeef.glide.transformations.gpu.BrightnessFilterTransformation; -import jp.wasabeef.glide.transformations.gpu.ContrastFilterTransformation; -import jp.wasabeef.glide.transformations.gpu.InvertFilterTransformation; -import jp.wasabeef.glide.transformations.gpu.KuwaharaFilterTransformation; -import jp.wasabeef.glide.transformations.gpu.PixelationFilterTransformation; -import jp.wasabeef.glide.transformations.gpu.SepiaFilterTransformation; -import jp.wasabeef.glide.transformations.gpu.SketchFilterTransformation; -import jp.wasabeef.glide.transformations.gpu.SwirlFilterTransformation; -import jp.wasabeef.glide.transformations.gpu.ToonFilterTransformation; -import jp.wasabeef.glide.transformations.gpu.VignetteFilterTransformation; - -/** - * Created by Wasabeef on 2015/01/11. - */ -public class MainAdapter extends RecyclerView.Adapter { - - private Context mContext; - private List mDataSet; - - enum Type { - Mask, - NinePatchMask, - CropTop, - CropCenter, - CropBottom, - CropSquare, - CropCircle, - ColorFilter, - Grayscale, - RoundedCorners, - Blur, - Toon, - Sepia, - Contrast, - Invert, - Pixel, - Sketch, - Swirl, - Brightness, - Kuawahara, - Vignette - } - - public MainAdapter(Context context, List dataSet) { - mContext = context; - mDataSet = dataSet; - } - - @Override public MainAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { - View v = LayoutInflater.from(mContext).inflate(R.layout.layout_list_item, parent, false); - return new ViewHolder(v); - } - - @Override public void onBindViewHolder(MainAdapter.ViewHolder holder, int position) { - switch (mDataSet.get(position)) { - case Mask: { - int width = Utils.dip2px(mContext, 133.33f); - int height = Utils.dip2px(mContext, 126.33f); - Glide.with(mContext) - .load(R.drawable.check) - .override(width, height) - .bitmapTransform(new CenterCrop(mContext), - new MaskTransformation(mContext, R.drawable.mask_starfish)) - .into(holder.image); - break; - } - case NinePatchMask: { - int width = Utils.dip2px(mContext, 150.0f); - int height = Utils.dip2px(mContext, 100.0f); - Glide.with(mContext) - .load(R.drawable.check) - .override(width, height) - .bitmapTransform(new CenterCrop(mContext), - new MaskTransformation(mContext, R.drawable.mask_chat_right)) - .into(holder.image); - break; - } - case CropTop: - Glide.with(mContext) - .load(R.drawable.demo) - .bitmapTransform( - new CropTransformation(mContext, 300, 100, CropTransformation.CropType.TOP)) - .into(holder.image); - break; - case CropCenter: - Glide.with(mContext) - .load(R.drawable.demo) - .bitmapTransform(new CropTransformation(mContext, 300, 100)) - .into(holder.image); - break; - case CropBottom: - Glide.with(mContext) - .load(R.drawable.demo) - .bitmapTransform( - new CropTransformation(mContext, 300, 100, CropTransformation.CropType.BOTTOM)) - .into(holder.image); - - break; - case CropSquare: - Glide.with(mContext) - .load(R.drawable.demo) - .bitmapTransform(new CropSquareTransformation(mContext)) - .into(holder.image); - break; - case CropCircle: - Glide.with(mContext) - .load(R.drawable.demo) - .bitmapTransform(new CropCircleTransformation(mContext)) - .into(holder.image); - break; - case ColorFilter: - Glide.with(mContext) - .load(R.drawable.demo) - .bitmapTransform(new ColorFilterTransformation(mContext, Color.argb(80, 255, 0, 0))) - .into(holder.image); - break; - case Grayscale: - Glide.with(mContext) - .load(R.drawable.demo) - .bitmapTransform(new GrayscaleTransformation(mContext)) - .into(holder.image); - break; - case RoundedCorners: - Glide.with(mContext) - .load(R.drawable.demo) - .bitmapTransform(new RoundedCornersTransformation(mContext, 30, 0, - RoundedCornersTransformation.CornerType.BOTTOM)) - .into(holder.image); - break; - case Blur: - Glide.with(mContext) - .load(R.drawable.check) - .bitmapTransform(new BlurTransformation(mContext, 25)) - .into(holder.image); - break; - case Toon: - Glide.with(mContext) - .load(R.drawable.demo) - .bitmapTransform(new ToonFilterTransformation(mContext)) - .into(holder.image); - break; - case Sepia: - Glide.with(mContext) - .load(R.drawable.check) - .bitmapTransform(new SepiaFilterTransformation(mContext)) - .into(holder.image); - break; - case Contrast: - Glide.with(mContext) - .load(R.drawable.check) - .bitmapTransform(new ContrastFilterTransformation(mContext, 2.0f)) - .into(holder.image); - break; - case Invert: - Glide.with(mContext) - .load(R.drawable.check) - .bitmapTransform(new InvertFilterTransformation(mContext)) - .into(holder.image); - break; - case Pixel: - Glide.with(mContext) - .load(R.drawable.check) - .bitmapTransform(new PixelationFilterTransformation(mContext, 20)) - .into(holder.image); - break; - case Sketch: - Glide.with(mContext) - .load(R.drawable.check) - .bitmapTransform(new SketchFilterTransformation(mContext)) - .into(holder.image); - break; - case Swirl: - Glide.with(mContext) - .load(R.drawable.check) - .bitmapTransform( - new SwirlFilterTransformation(mContext, 0.5f, 1.0f, new PointF(0.5f, 0.5f))) - .into(holder.image); - break; - case Brightness: - Glide.with(mContext) - .load(R.drawable.check) - .bitmapTransform(new BrightnessFilterTransformation(mContext, 0.5f)) - .into(holder.image); - break; - case Kuawahara: - Glide.with(mContext) - .load(R.drawable.check) - .bitmapTransform(new KuwaharaFilterTransformation(mContext, 25)) - .into(holder.image); - break; - case Vignette: - Glide.with(mContext) - .load(R.drawable.check) - .bitmapTransform(new VignetteFilterTransformation(mContext, new PointF(0.5f, 0.5f), - new float[] { 0.0f, 0.0f, 0.0f }, 0f, 0.75f)) - .into(holder.image); - break; - } - holder.title.setText(mDataSet.get(position).name()); - } - - @Override public int getItemCount() { - return mDataSet.size(); - } - - static class ViewHolder extends RecyclerView.ViewHolder { - - public ImageView image; - public TextView title; - - ViewHolder(View itemView) { - super(itemView); - image = (ImageView) itemView.findViewById(R.id.image); - title = (TextView) itemView.findViewById(R.id.title); - } - } -} diff --git a/example/src/main/java/jp/wasabeef/example/glide/MainAdapter.kt b/example/src/main/java/jp/wasabeef/example/glide/MainAdapter.kt new file mode 100644 index 0000000..dc5badb --- /dev/null +++ b/example/src/main/java/jp/wasabeef/example/glide/MainAdapter.kt @@ -0,0 +1,203 @@ +package jp.wasabeef.example.glide + +import android.content.Context +import android.graphics.Bitmap +import android.graphics.Color +import android.graphics.PointF +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.bumptech.glide.Glide +import com.bumptech.glide.load.MultiTransformation +import com.bumptech.glide.load.resource.bitmap.CenterCrop +import com.bumptech.glide.request.RequestOptions.bitmapTransform +import com.bumptech.glide.request.RequestOptions.overrideOf +import jp.wasabeef.example.glide.MainAdapter.Type.* +import jp.wasabeef.glide.transformations.* +import jp.wasabeef.glide.transformations.CropTransformation.CropType +import jp.wasabeef.glide.transformations.gpu.* +import jp.wasabeef.glide.transformations.internal.Utils + +/** + * Created by Wasabeef on 2015/01/11. + */ +class MainAdapter( + private val context: Context, + private val dataSet: MutableList +) : RecyclerView.Adapter() { + + enum class Type { + Mask, + NinePatchMask, + CropTop, + CropCenter, + CropBottom, + CropSquare, + CropCircle, + CropCircleWithBorder, + ColorFilter, + Grayscale, + RoundedCorners, + BlurLight, + BlurDeep, + Toon, + Sepia, + Contrast, + Invert, + Pixel, + Sketch, + Swirl, + Brightness, + Kuawahara, + Vignette + } + + override fun getItemCount(): Int { + return dataSet.size + } + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { + val v = LayoutInflater.from(context).inflate(R.layout.layout_list_item, parent, false) + return ViewHolder(v) + } + + override fun onBindViewHolder(holder: ViewHolder, position: Int) { + + when (dataSet[position]) { + Mask -> { + Glide.with(context) + .load(R.drawable.check) + .apply(overrideOf(266.px, 252.px)) + .apply(bitmapTransform(MultiTransformation(CenterCrop(), + MaskTransformation(R.drawable.mask_starfish)))) + .into(holder.image) + } + NinePatchMask -> { + Glide.with(context) + .load(R.drawable.check) + .apply(overrideOf(300.px, 200.px)) + .apply(bitmapTransform(MultiTransformation(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; } }