Repository: wasabeef/glide-transformations Branch: main Commit: d950f0c33f27 Files: 63 Total size: 119.8 KB Directory structure: gitextract_94bctmql/ ├── .editorconfig ├── .github/ │ ├── FUNDING.yml │ ├── ISSUE_TEMPLATE.md │ └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── .idea/ │ ├── codeStyles/ │ │ ├── Project.xml │ │ └── codeStyleConfig.xml │ ├── encodings.xml │ ├── runConfigurations.xml │ └── vcs.xml ├── CHANGELOG.md ├── LICENSE ├── README.md ├── build.gradle ├── example/ │ ├── build.gradle │ ├── proguard-rules.pro │ └── src/ │ └── main/ │ ├── AndroidManifest.xml │ ├── java/ │ │ └── jp/ │ │ └── wasabeef/ │ │ └── example/ │ │ └── glide/ │ │ ├── Ext.kt │ │ ├── MainActivity.kt │ │ └── MainAdapter.kt │ └── res/ │ ├── layout/ │ │ ├── activity_main.xml │ │ └── layout_list_item.xml │ ├── values/ │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── values-w820dp/ │ └── dimens.xml ├── gradle/ │ └── wrapper/ │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradle.properties ├── gradlew ├── gradlew.bat ├── settings.gradle ├── signingConfigs/ │ ├── debug.gradle │ └── debug.keystore └── transformations/ ├── build.gradle ├── proguard-rules.txt └── src/ ├── androidTest/ │ └── java/ │ └── jp/ │ └── wasabeef/ │ └── glide/ │ └── transformations/ │ └── ApplicationTest.java └── main/ ├── AndroidManifest.xml └── java/ └── jp/ └── wasabeef/ └── glide/ └── transformations/ ├── BitmapTransformation.java ├── BlurTransformation.java ├── ColorFilterTransformation.java ├── CropCircleTransformation.java ├── CropCircleWithBorderTransformation.java ├── CropSquareTransformation.java ├── CropTransformation.java ├── GrayscaleTransformation.java ├── MaskTransformation.java ├── RoundedCornersTransformation.java ├── gpu/ │ ├── BrightnessFilterTransformation.java │ ├── ContrastFilterTransformation.java │ ├── GPUFilterTransformation.java │ ├── InvertFilterTransformation.java │ ├── KuwaharaFilterTransformation.java │ ├── PixelationFilterTransformation.java │ ├── SepiaFilterTransformation.java │ ├── SketchFilterTransformation.java │ ├── SwirlFilterTransformation.java │ ├── ToonFilterTransformation.java │ └── VignetteFilterTransformation.java └── internal/ ├── FastBlur.java ├── RSBlur.java └── Utils.java ================================================ FILE CONTENTS ================================================ ================================================ FILE: .editorconfig ================================================ [*] indent_size = 2 max_line_length = off insert_final_newline = true [*.{kt, kts}] kotlin_imports_layout = ascii ================================================ FILE: .github/FUNDING.yml ================================================ # 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'] ================================================ FILE: .github/ISSUE_TEMPLATE.md ================================================ # 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* ================================================ FILE: .github/PULL_REQUEST_TEMPLATE.md ================================================ ## What does this change? ## What is the value of this and can you measure success? ## Screenshots ================================================ FILE: .gitignore ================================================ # Mac OS .DS_store # Built application files *.apk *.ap_ # Files for the ART/Dalvik VM *.dex # Java class files *.class # Generated files bin/ gen/ out/ # Gradle files .gradle/ build/ # Local configuration file (sdk path, etc) 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 ================================================ FILE: .idea/codeStyles/Project.xml ================================================
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
================================================ FILE: .idea/codeStyles/codeStyleConfig.xml ================================================ ================================================ FILE: .idea/encodings.xml ================================================ ================================================ FILE: .idea/runConfigurations.xml ================================================ ================================================ FILE: .idea/vcs.xml ================================================ ================================================ FILE: CHANGELOG.md ================================================ 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)* ---------------------------- Update: - Compile & Target SDK Version 23 -> 25 - Build Tools 23.0.2 -> 25.0.2 - Support Library 23.2.1 -> 25.3.0 - GPUImage for Android 1.3.0 -> 1.4.1 Bug Fix: - [Additional resource cleanup in RSBlur #45](https://github.com/wasabeef/glide-transformations/pull/45) Version 2.0.1 *(2016-04-21)* ---------------------------- Fix: [#35](https://github.com/wasabeef/glide-transformations/issues/35) RSInvalidStateException Version 2.0.0 *(2016-03-02)* ---------------------------- Say v8.RenderScript goodbye Version 1.4.0 *(2016-02-28)* ---------------------------- fix Issue [#29](https://github.com/wasabeef/glide-transformations/issues/29) Use FastBlur as a fallback upon RenderScript failure. Version 1.3.1 *(2015-11-27)* ---------------------------- Change the renderscriptTargetApi down to 20. Warning:Renderscript support mode is not currently supported with renderscript target 21+ fix: memory leak. Version 1.3.0 *(2015-11-10)* ---------------------------- add round corner type to RoundedCornersTransformation. Thanks to [kaelaela](https://github.com/kaelaela) Version 1.2.1 *(2015-09-18)* ---------------------------- Merged NinePatchMaskTransformation to MaskTransformation. Version 1.2.0 *(2015-09-16)* ---------------------------- add new transformations MaskTransformation and NinePatchMaskTransformation. Thanks to [start141](https://github.com/start141) Version 1.1.0 *(2015-09-05)* ---------------------------- Adjustment of default parameters. Version 1.0.8 *(2015-07-24)* ---------------------------- add DownSampling to BlurTransform Version 1.0.7 *(2015-07-18)* ---------------------------- Bug fix : Blur not working. Version 1.0.6 *(2015-04-23)* ---------------------------- add: CropType(Top, Center, Bottom) for CropTransformation. Version 1.0.5 *(2015-03-09)* ---------------------------- Bug fix: Transparency. Version 1.0.4 *(2015-02-13)* ---------------------------- Bug fix : remove original bitmap resource recycling. Version 1.0.3 *(2015-02-05)* ---------------------------- Bug fix Version 1.0.2 *(2015-02-04)* ---------------------------- Refactor: use BimapPool Version 1.0.1 *(2015-01-21)* ---------------------------- fix: Blur Transformation now woking at Android 4.3 add: GPUImage to Gradle dependency Version 1.0.0 *(2015-01-12)* ---------------------------- Initial release. ================================================ FILE: LICENSE ================================================ Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "{}" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright {yyyy} {name of copyright owner} 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. ================================================ FILE: README.md ================================================ 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) [![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). Please feel free to use this. #### Are you using Picasso or Fresco? [Picasso Transformations](https://github.com/wasabeef/picasso-transformations) [Fresco Processors](https://github.com/wasabeef/fresco-processors) # Demo ### Original Image ### Transformations # How do I use it? ## Step 1 #### Gradle ```groovy repositories { mavenCentral() } dependencies { 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' } ``` ## Step 2 Set Glide Transform. ```kotlin Glide.with(this).load(R.drawable.demo) .apply(RequestOptions.bitmapTransform(BlurTransformation(25, 3))) .into(imageView) ``` ## Advanced Step 3 You can set a multiple transformations. ```kotlin val multi = MultiTransformation( BlurTransformation(25), RoundedCornersTransformation(128, 0, CornerType.BOTTOM)))) Glide.with(this).load(R.drawable.demo) .apply(RequestOptions.bitmapTransform(multi)) .into(imageView)) ``` ## Transformations ### Crop - `CropTransformation` - `CropCircleTransformation` - `CropCircleWithBorderTransformation` - `CropSquareTransformation` - `RoundedCornersTransformation` ### Color - `ColorFilterTransformation` - `GrayscaleTransformation` ### Blur - `BlurTransformation` ### Mask - `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` Applications using Glide Transformations --- Please [ping](mailto:dadadada.chop@gmail.com) me or send a pull request if you would like to be added here. 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 ------- Daichi Furiya (Wasabeef) - Follow me on Twitter Contributions ------- Any contributions are welcome! Contributors ------- * [start141](https://github.com/start141) * [squeeish](https://github.com/squeeish) Thanks ------- * Inspired by `Picasso Transformations` in [TannerPerrien](https://github.com/TannerPerrien). License ------- 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. ================================================ FILE: build.gradle ================================================ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { 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 { google() mavenCentral() jcenter() } } ================================================ FILE: example/build.gradle ================================================ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-kapt' android { compileSdkVersion COMPILE_SDK_VERSION as int defaultConfig { minSdkVersion MIN_SDK_VERSION as int targetSdkVersion TARGET_SDK_VERSION as int versionCode VERSION_CODE as int versionName VERSION_NAME } // SigningConfigs apply from: '../signingConfigs/debug.gradle', to: android buildTypes { debug { debuggable true signingConfig signingConfigs.debug } release { debuggable false zipAlignEnabled true minifyEnabled true shrinkResources true } } } repositories { // maven { url = "https://oss.sonatype.org/content/repositories/snapshots"} } dependencies { // 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' } ================================================ FILE: example/proguard-rules.pro ================================================ ================================================ FILE: example/src/main/AndroidManifest.xml ================================================ ================================================ FILE: example/src/main/java/jp/wasabeef/example/glide/Ext.kt ================================================ package jp.wasabeef.example.glide /** * 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. */ import android.content.res.Resources val Float.px: Float get() = (this * Resources.getSystem().displayMetrics.density) val Int.px: Int get() = ((this * Resources.getSystem().displayMetrics.density).toInt()) ================================================ FILE: example/src/main/java/jp/wasabeef/example/glide/MainActivity.kt ================================================ 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 )) } } } ================================================ FILE: example/src/main/java/jp/wasabeef/example/glide/MainAdapter.kt ================================================ 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) } } ================================================ FILE: example/src/main/res/layout/activity_main.xml ================================================ ================================================ FILE: example/src/main/res/layout/layout_list_item.xml ================================================ ================================================ FILE: example/src/main/res/values/colors.xml ================================================ #3F51B5 #303F9F #FF4081 ================================================ FILE: example/src/main/res/values/dimens.xml ================================================ 16dp 16dp ================================================ FILE: example/src/main/res/values/strings.xml ================================================ glide-transformations Hello world! Settings ================================================ FILE: example/src/main/res/values/styles.xml ================================================ ================================================ FILE: example/src/main/res/values-w820dp/dimens.xml ================================================ 64dp ================================================ FILE: gradle/wrapper/gradle-wrapper.properties ================================================ 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 ================================================ FILE: gradle.properties ================================================ 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 VERSION_NAME=4.3.0 VERSION_CODE=421 GROUP=jp.wasabeef COMPILE_SDK_VERSION=30 TARGET_SDK_VERSION=30 MIN_SDK_VERSION=21 ================================================ FILE: gradlew ================================================ #!/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 ## ############################################################################## # Attempt to set APP_HOME # Resolve links: $0 may be a link PRG="$0" # Need this for relative symlinks. while [ -h "$PRG" ] ; do ls=`ls -ld "$PRG"` link=`expr "$ls" : '.*-> \(.*\)$'` if expr "$link" : '/.*' > /dev/null; then PRG="$link" else PRG=`dirname "$PRG"`"/$link" fi done SAVED="`pwd`" cd "`dirname \"$PRG\"`/" >/dev/null APP_HOME="`pwd -P`" cd "$SAVED" >/dev/null 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='"-Xmx64m" "-Xms64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" warn () { echo "$*" } die () { echo echo "$*" echo exit 1 } # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false nonstop=false case "`uname`" in CYGWIN* ) cygwin=true ;; Darwin* ) darwin=true ;; MINGW* ) msys=true ;; NONSTOP* ) nonstop=true ;; 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 # IBM's JDK on AIX uses strange locations for the executables JAVACMD="$JAVA_HOME/jre/sh/java" else JAVACMD="$JAVA_HOME/bin/java" fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else JAVACMD="java" which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi # Increase the maximum file descriptors if we can. if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then MAX_FD_LIMIT=`ulimit -H -n` if [ $? -eq 0 ] ; then if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then MAX_FD="$MAX_FD_LIMIT" fi ulimit -n $MAX_FD if [ $? -ne 0 ] ; then warn "Could not set maximum file descriptor limit: $MAX_FD" fi else warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" fi fi # For Darwin, add options to specify how the application appears in the dock if $darwin; then GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" fi # 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 ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` SEP="" for dir in $ROOTDIRSRAW ; do ROOTDIRS="$ROOTDIRS$SEP$dir" SEP="|" done OURCYGPATTERN="(^($ROOTDIRS))" # Add a user-defined pattern to the cygpath arguments if [ "$GRADLE_CYGPATTERN" != "" ] ; then OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" fi # Now convert the arguments - kludge to limit ourselves to /bin/sh i=0 for arg in "$@" ; do CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` else eval `echo args$i`="\"$arg\"" fi 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" ;; esac fi # Escape application args save () { for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done echo " " } 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" exec "$JAVACMD" "$@" ================================================ FILE: gradlew.bat ================================================ @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 @rem Gradle startup script for Windows @rem @rem ########################################################################## @rem Set local scope for the variables with windows NT shell if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 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="-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 execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. echo. echo Please set the JAVA_HOME variable in your environment to match the echo location of your Java installation. goto fail :findJavaFromJavaHome set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute echo. echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% echo. echo Please set the JAVA_HOME variable in your environment to match the echo location of your Java installation. goto fail :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 %* :end @rem End local scope for the variables with windows NT shell if "%ERRORLEVEL%"=="0" goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 exit /b 1 :mainEnd if "%OS%"=="Windows_NT" endlocal :omega ================================================ FILE: settings.gradle ================================================ include ':example', ':transformations' ================================================ FILE: signingConfigs/debug.gradle ================================================ 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 ================================================ FILE: transformations/build.gradle ================================================ apply plugin: 'com.android.library' android { compileSdkVersion COMPILE_SDK_VERSION as int defaultConfig { minSdkVersion MIN_SDK_VERSION as int targetSdkVersion TARGET_SDK_VERSION as int consumerProguardFiles 'proguard-rules.txt' } } dependencies { implementation "com.github.bumptech.glide:glide:$glide_version" annotationProcessor "com.github.bumptech.glide:compiler:$glide_version" compileOnly "jp.co.cyberagent.android:gpuimage:$gpuimage_version" } 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' ================================================ FILE: transformations/proguard-rules.txt ================================================ -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 *; } ================================================ FILE: transformations/src/androidTest/java/jp/wasabeef/glide/transformations/ApplicationTest.java ================================================ package jp.wasabeef.glide.transformations; import android.app.Application; import android.test.ApplicationTestCase; /** * Testing Fundamentals */ public class ApplicationTest extends ApplicationTestCase { public ApplicationTest() { super(Application.class); } } ================================================ FILE: transformations/src/main/AndroidManifest.xml ================================================ ================================================ FILE: transformations/src/main/java/jp/wasabeef/glide/transformations/BitmapTransformation.java ================================================ 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(); } ================================================ FILE: transformations/src/main/java/jp/wasabeef/glide/transformations/BlurTransformation.java ================================================ package jp.wasabeef.glide.transformations; /** * 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. */ import android.content.Context; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Paint; import android.renderscript.RSRuntimeException; import androidx.annotation.NonNull; import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; import java.security.MessageDigest; import jp.wasabeef.glide.transformations.internal.FastBlur; import jp.wasabeef.glide.transformations.internal.RSBlur; public class BlurTransformation extends BitmapTransformation { private static final int VERSION = 1; private static final String ID = "jp.wasabeef.glide.transformations.BlurTransformation." + VERSION; private static final int MAX_RADIUS = 25; private static final int DEFAULT_DOWN_SAMPLING = 1; private final int radius; private final int sampling; public BlurTransformation() { this(MAX_RADIUS, DEFAULT_DOWN_SAMPLING); } public BlurTransformation(int radius) { this(radius, DEFAULT_DOWN_SAMPLING); } public BlurTransformation(int radius, int sampling) { this.radius = radius; this.sampling = sampling; } @Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool, @NonNull Bitmap toTransform, int outWidth, int outHeight) { int width = toTransform.getWidth(); int height = toTransform.getHeight(); int scaledWidth = width / sampling; int scaledHeight = height / sampling; Bitmap bitmap = pool.get(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888); setCanvasBitmapDensity(toTransform, bitmap); Canvas canvas = new Canvas(bitmap); canvas.scale(1 / (float) sampling, 1 / (float) sampling); Paint paint = new Paint(); paint.setFlags(Paint.FILTER_BITMAP_FLAG); canvas.drawBitmap(toTransform, 0, 0, paint); try { bitmap = RSBlur.blur(context, bitmap, radius); } catch (RSRuntimeException e) { bitmap = FastBlur.blur(bitmap, radius, true); } return bitmap; } @Override public String toString() { return "BlurTransformation(radius=" + radius + ", sampling=" + sampling + ")"; } @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)); } } ================================================ FILE: transformations/src/main/java/jp/wasabeef/glide/transformations/ColorFilterTransformation.java ================================================ package jp.wasabeef.glide.transformations; /** * 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. */ import android.content.Context; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.PorterDuff; import android.graphics.PorterDuffColorFilter; import androidx.annotation.NonNull; import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; import java.security.MessageDigest; public class ColorFilterTransformation extends BitmapTransformation { private static final int VERSION = 1; private static final String ID = "jp.wasabeef.glide.transformations.ColorFilterTransformation." + VERSION; private final int color; public ColorFilterTransformation(int color) { this.color = color; } @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 = 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(color, PorterDuff.Mode.SRC_ATOP)); canvas.drawBitmap(toTransform, 0, 0, paint); return bitmap; } @Override public String toString() { return "ColorFilterTransformation(color=" + color + ")"; } @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)); } } ================================================ FILE: transformations/src/main/java/jp/wasabeef/glide/transformations/CropCircleTransformation.java ================================================ package jp.wasabeef.glide.transformations; /** * 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. */ import android.content.Context; import android.graphics.Bitmap; import androidx.annotation.NonNull; import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; import com.bumptech.glide.load.resource.bitmap.TransformationUtils; import com.bumptech.glide.request.RequestOptions; import java.security.MessageDigest; /** * @deprecated Use {@link RequestOptions#circleCrop()}. */ @Deprecated public class CropCircleTransformation extends BitmapTransformation { private static final int VERSION = 1; private static final String ID = "jp.wasabeef.glide.transformations.CropCircleTransformation." + VERSION; @Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool, @NonNull Bitmap toTransform, int outWidth, int outHeight) { return TransformationUtils.circleCrop(pool, toTransform, outWidth, outHeight); } @Override public String toString() { return "CropCircleTransformation()"; } @Override public boolean equals(Object o) { return o instanceof CropCircleTransformation; } @Override public int hashCode() { return ID.hashCode(); } @Override public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) { messageDigest.update((ID).getBytes(CHARSET)); } } ================================================ FILE: transformations/src/main/java/jp/wasabeef/glide/transformations/CropCircleWithBorderTransformation.java ================================================ 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; } } ================================================ FILE: transformations/src/main/java/jp/wasabeef/glide/transformations/CropSquareTransformation.java ================================================ package jp.wasabeef.glide.transformations; /** * 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. */ import android.content.Context; import android.graphics.Bitmap; 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; public class CropSquareTransformation extends BitmapTransformation { private static final int VERSION = 1; private static final String ID = "jp.wasabeef.glide.transformations.CropSquareTransformation." + VERSION; private int size; @Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool, @NonNull Bitmap toTransform, int outWidth, int outHeight) { this.size = Math.max(outWidth, outHeight); return TransformationUtils.centerCrop(pool, toTransform, size, size); } @Override public String toString() { return "CropSquareTransformation(size=" + size + ")"; } @Override public boolean equals(Object o) { return o instanceof CropSquareTransformation && ((CropSquareTransformation) o).size == size; } @Override public int hashCode() { return ID.hashCode() + size * 10; } @Override public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) { messageDigest.update((ID + size).getBytes(CHARSET)); } } ================================================ FILE: transformations/src/main/java/jp/wasabeef/glide/transformations/CropTransformation.java ================================================ package jp.wasabeef.glide.transformations; /** * 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. */ import android.content.Context; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.RectF; import androidx.annotation.NonNull; import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; 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, CENTER, BOTTOM } private int width; private int height; private CropType cropType = CropType.CENTER; public CropTransformation(int width, int height) { this(width, height, CropType.CENTER); } public CropTransformation(int width, int height, CropType cropType) { this.width = width; this.height = height; this.cropType = cropType; } @Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool, @NonNull Bitmap toTransform, int outWidth, int outHeight) { width = width == 0 ? toTransform.getWidth() : width; height = height == 0 ? toTransform.getHeight() : height; Bitmap.Config config = toTransform.getConfig() != null ? toTransform.getConfig() : Bitmap.Config.ARGB_8888; Bitmap bitmap = pool.get(width, height, config); bitmap.setHasAlpha(true); float scaleX = (float) width / toTransform.getWidth(); float scaleY = (float) height / toTransform.getHeight(); float scale = Math.max(scaleX, scaleY); 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); setCanvasBitmapDensity(toTransform, bitmap); Canvas canvas = new Canvas(bitmap); canvas.drawBitmap(toTransform, null, targetRect, null); return bitmap; } private float getTop(float scaledHeight) { switch (cropType) { case TOP: return 0; case CENTER: return (height - scaledHeight) / 2; case BOTTOM: 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)); } } ================================================ FILE: transformations/src/main/java/jp/wasabeef/glide/transformations/GrayscaleTransformation.java ================================================ package jp.wasabeef.glide.transformations; /** * 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. */ import android.content.Context; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.ColorMatrix; import android.graphics.ColorMatrixColorFilter; import android.graphics.Paint; import androidx.annotation.NonNull; import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; import java.security.MessageDigest; public class GrayscaleTransformation extends BitmapTransformation { private static final int VERSION = 1; private static final String ID = "jp.wasabeef.glide.transformations.GrayscaleTransformation." + VERSION; @Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool, @NonNull Bitmap toTransform, int outWidth, int outHeight) { int width = toTransform.getWidth(); int height = toTransform.getHeight(); Bitmap.Config 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(toTransform, 0, 0, paint); return bitmap; } @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)); } } ================================================ FILE: transformations/src/main/java/jp/wasabeef/glide/transformations/MaskTransformation.java ================================================ package jp.wasabeef.glide.transformations; /** * 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. */ import android.content.Context; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.PorterDuff; import android.graphics.PorterDuffXfermode; import android.graphics.drawable.Drawable; import androidx.annotation.NonNull; import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; 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 final Paint paint = new Paint(); private final int maskId; static { 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 key() return the same values if using the * same make file name. If you have a good idea please tell us, thanks. */ public MaskTransformation(int maskId) { this.maskId = maskId; } @Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool, @NonNull Bitmap toTransform, int outWidth, int outHeight) { int width = toTransform.getWidth(); int height = toTransform.getHeight(); Bitmap bitmap = pool.get(width, height, Bitmap.Config.ARGB_8888); bitmap.setHasAlpha(true); Drawable mask = context.getDrawable(maskId); setCanvasBitmapDensity(toTransform, bitmap); Canvas canvas = new Canvas(bitmap); mask.setBounds(0, 0, width, height); mask.draw(canvas); canvas.drawBitmap(toTransform, 0, 0, paint); return bitmap; } @Override public String toString() { return "MaskTransformation(maskId=" + maskId + ")"; } @Override public boolean equals(Object o) { return o instanceof MaskTransformation && ((MaskTransformation) o).maskId == maskId; } @Override public int hashCode() { return ID.hashCode() + maskId * 10; } @Override public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) { messageDigest.update((ID + maskId).getBytes(CHARSET)); } } ================================================ FILE: transformations/src/main/java/jp/wasabeef/glide/transformations/RoundedCornersTransformation.java ================================================ package jp.wasabeef.glide.transformations; /** * 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. */ import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapShader; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.RectF; import android.graphics.Shader; import androidx.annotation.NonNull; import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; 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, TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT, TOP, BOTTOM, LEFT, RIGHT, OTHER_TOP_LEFT, OTHER_TOP_RIGHT, OTHER_BOTTOM_LEFT, OTHER_BOTTOM_RIGHT, DIAGONAL_FROM_TOP_LEFT, DIAGONAL_FROM_TOP_RIGHT } private final int radius; private final int diameter; private final int margin; private final CornerType cornerType; public RoundedCornersTransformation(int radius, int margin) { this(radius, margin, CornerType.ALL); } public RoundedCornersTransformation(int radius, int margin, CornerType cornerType) { this.radius = radius; this.diameter = this.radius * 2; this.margin = margin; this.cornerType = cornerType; } @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 bitmap = pool.get(width, height, Bitmap.Config.ARGB_8888); bitmap.setHasAlpha(true); setCanvasBitmapDensity(toTransform, bitmap); Canvas canvas = new Canvas(bitmap); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setShader(new BitmapShader(toTransform, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP)); drawRoundRect(canvas, paint, width, height); return bitmap; } private void drawRoundRect(Canvas canvas, Paint paint, float width, float height) { float right = width - margin; float bottom = height - margin; switch (cornerType) { case ALL: canvas.drawRoundRect(new RectF(margin, margin, right, bottom), radius, radius, paint); break; case TOP_LEFT: drawTopLeftRoundRect(canvas, paint, right, bottom); break; case TOP_RIGHT: drawTopRightRoundRect(canvas, paint, right, bottom); break; case BOTTOM_LEFT: drawBottomLeftRoundRect(canvas, paint, right, bottom); break; case BOTTOM_RIGHT: drawBottomRightRoundRect(canvas, paint, right, bottom); break; case TOP: drawTopRoundRect(canvas, paint, right, bottom); break; case BOTTOM: drawBottomRoundRect(canvas, paint, right, bottom); break; case LEFT: drawLeftRoundRect(canvas, paint, right, bottom); break; case RIGHT: drawRightRoundRect(canvas, paint, right, bottom); break; case OTHER_TOP_LEFT: drawOtherTopLeftRoundRect(canvas, paint, right, bottom); break; case OTHER_TOP_RIGHT: drawOtherTopRightRoundRect(canvas, paint, right, bottom); break; case OTHER_BOTTOM_LEFT: drawOtherBottomLeftRoundRect(canvas, paint, right, bottom); break; case OTHER_BOTTOM_RIGHT: drawOtherBottomRightRoundRect(canvas, paint, right, bottom); break; case DIAGONAL_FROM_TOP_LEFT: drawDiagonalFromTopLeftRoundRect(canvas, paint, right, bottom); break; case DIAGONAL_FROM_TOP_RIGHT: drawDiagonalFromTopRightRoundRect(canvas, paint, right, bottom); break; default: 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(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 - 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(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 - 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(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(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(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 - 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(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(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(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(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(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 - 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)); } } ================================================ FILE: transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/BrightnessFilterTransformation.java ================================================ package jp.wasabeef.glide.transformations.gpu; /** * 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. */ 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 static final int VERSION = 1; private static final String ID = "jp.wasabeef.glide.transformations.gpu.BrightnessFilterTransformation." + VERSION; private final float brightness; public BrightnessFilterTransformation() { this(0.0f); } public BrightnessFilterTransformation(float brightness) { super(new GPUImageBrightnessFilter()); this.brightness = brightness; GPUImageBrightnessFilter filter = getFilter(); filter.setBrightness(this.brightness); } @Override public String toString() { return "BrightnessFilterTransformation(brightness=" + brightness + ")"; } @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 void updateDiskCacheKey(@NonNull MessageDigest messageDigest) { messageDigest.update((ID + brightness).getBytes(CHARSET)); } } ================================================ FILE: transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/ContrastFilterTransformation.java ================================================ package jp.wasabeef.glide.transformations.gpu; /** * 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. */ 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 static final int VERSION = 1; private static final String ID = "jp.wasabeef.glide.transformations.gpu.ContrastFilterTransformation." + VERSION; private final float contrast; public ContrastFilterTransformation() { this(1.0f); } public ContrastFilterTransformation(float contrast) { super(new GPUImageContrastFilter()); this.contrast = contrast; GPUImageContrastFilter filter = getFilter(); filter.setContrast(this.contrast); } @Override public String toString() { return "ContrastFilterTransformation(contrast=" + contrast + ")"; } @Override public boolean equals(Object o) { return o instanceof ContrastFilterTransformation; } @Override public int hashCode() { return ID.hashCode() + (int) (contrast * 10); } @Override public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) { messageDigest.update((ID + contrast).getBytes(CHARSET)); } } ================================================ FILE: transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/GPUFilterTransformation.java ================================================ package jp.wasabeef.glide.transformations.gpu; /** * 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. */ import android.content.Context; import android.graphics.Bitmap; import androidx.annotation.NonNull; import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; import java.security.MessageDigest; import jp.co.cyberagent.android.gpuimage.GPUImage; import jp.co.cyberagent.android.gpuimage.filter.GPUImageFilter; import jp.wasabeef.glide.transformations.BitmapTransformation; public class GPUFilterTransformation extends BitmapTransformation { 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 final GPUImageFilter gpuImageFilter; public GPUFilterTransformation(GPUImageFilter filter) { this.gpuImageFilter = 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 String toString() { return getClass().getSimpleName(); } @SuppressWarnings("unchecked") public T getFilter() { return (T) gpuImageFilter; } @Override public boolean equals(Object o) { return o instanceof GPUFilterTransformation; } @Override public int hashCode() { return ID.hashCode(); } @Override public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) { messageDigest.update(ID_BYTES); } } ================================================ FILE: transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/InvertFilterTransformation.java ================================================ package jp.wasabeef.glide.transformations.gpu; /** * 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. */ 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 { private static final int VERSION = 1; private static final String ID = "jp.wasabeef.glide.transformations.gpu.InvertFilterTransformation." + VERSION; public InvertFilterTransformation() { super(new GPUImageColorInvertFilter()); } @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)); } } ================================================ FILE: transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/KuwaharaFilterTransformation.java ================================================ package jp.wasabeef.glide.transformations.gpu; /** * 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. */ 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 static final int VERSION = 1; private static final String ID = "jp.wasabeef.glide.transformations.gpu.KuwaharaFilterTransformation." + VERSION; private final int radius; public KuwaharaFilterTransformation() { this(25); } public KuwaharaFilterTransformation(int radius) { super(new GPUImageKuwaharaFilter()); this.radius = radius; GPUImageKuwaharaFilter filter = getFilter(); filter.setRadius(this.radius); } @Override public String toString() { return "KuwaharaFilterTransformation(radius=" + radius + ")"; } @Override public boolean equals(Object o) { return o instanceof KuwaharaFilterTransformation; } @Override public int hashCode() { return ID.hashCode() + radius * 10; } @Override public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) { messageDigest.update((ID + radius).getBytes(CHARSET)); } } ================================================ FILE: transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/PixelationFilterTransformation.java ================================================ package jp.wasabeef.glide.transformations.gpu; /** * 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. */ 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 static final int VERSION = 1; private static final String ID = "jp.wasabeef.glide.transformations.gpu.PixelationFilterTransformation." + VERSION; private final float pixel; public PixelationFilterTransformation() { this(10f); } public PixelationFilterTransformation(float pixel) { super(new GPUImagePixelationFilter()); this.pixel = pixel; GPUImagePixelationFilter filter = getFilter(); filter.setPixel(this.pixel); } @Override public String toString() { return "PixelationFilterTransformation(pixel=" + pixel + ")"; } @Override public boolean equals(Object o) { return o instanceof PixelationFilterTransformation; } @Override public int hashCode() { return ID.hashCode() + (int) (pixel * 10); } @Override public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) { messageDigest.update((ID + pixel).getBytes(CHARSET)); } } ================================================ FILE: transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/SepiaFilterTransformation.java ================================================ package jp.wasabeef.glide.transformations.gpu; /** * 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. */ 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 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(float intensity) { super(new GPUImageSepiaToneFilter()); this.intensity = intensity; GPUImageSepiaToneFilter filter = getFilter(); filter.setIntensity(this.intensity); } @Override public String toString() { return "SepiaFilterTransformation(intensity=" + intensity + ")"; } @Override public boolean equals(Object o) { return o instanceof SepiaFilterTransformation; } @Override public int hashCode() { return ID.hashCode() + (int) (intensity * 10); } @Override public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) { messageDigest.update((ID + intensity).getBytes(CHARSET)); } } ================================================ FILE: transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/SketchFilterTransformation.java ================================================ package jp.wasabeef.glide.transformations.gpu; /** * 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. */ import androidx.annotation.NonNull; import java.security.MessageDigest; import jp.co.cyberagent.android.gpuimage.filter.GPUImageSketchFilter; public class SketchFilterTransformation extends GPUFilterTransformation { private static final int VERSION = 1; private static final String ID = "jp.wasabeef.glide.transformations.gpu.SketchFilterTransformation." + VERSION; public SketchFilterTransformation() { super(new GPUImageSketchFilter()); } @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)); } } ================================================ FILE: transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/SwirlFilterTransformation.java ================================================ package jp.wasabeef.glide.transformations.gpu; /** * 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. */ import android.graphics.PointF; 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 static final int VERSION = 1; private static final String ID = "jp.wasabeef.glide.transformations.gpu.SwirlFilterTransformation." + VERSION; private final float radius; private final float angle; private final PointF 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 center default (0.5, 0.5) */ 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(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 void updateDiskCacheKey(@NonNull MessageDigest messageDigest) { messageDigest.update((ID + radius + angle + center.hashCode()).getBytes(CHARSET)); } } ================================================ FILE: transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/ToonFilterTransformation.java ================================================ package jp.wasabeef.glide.transformations.gpu; /** * 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. */ 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. * The levels of quantization for the posterization of colors within the scene, * with a default of 10.0. */ public class ToonFilterTransformation extends GPUFilterTransformation { private static final int VERSION = 1; private static final String ID = "jp.wasabeef.glide.transformations.gpu.ToonFilterTransformation." + VERSION; private final float threshold; private final float quantizationLevels; public ToonFilterTransformation() { this(.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); } @Override public String toString() { return "ToonFilterTransformation(threshold=" + threshold + ",quantizationLevels=" + quantizationLevels + ")"; } @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 void updateDiskCacheKey(@NonNull MessageDigest messageDigest) { messageDigest.update((ID + threshold + quantizationLevels).getBytes(CHARSET)); } } ================================================ FILE: transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/VignetteFilterTransformation.java ================================================ package jp.wasabeef.glide.transformations.gpu; /** * 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. */ import android.graphics.PointF; import androidx.annotation.NonNull; import java.security.MessageDigest; import java.util.Arrays; import jp.co.cyberagent.android.gpuimage.filter.GPUImageVignetteFilter; /** * Performs a vignetting effect, fading out the image at the edges * The directional intensity of the vignetting, * with a default of x = 0.5, y = 0.5, start = 0, end = 0.75 */ public class VignetteFilterTransformation extends GPUFilterTransformation { 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() { this(new PointF(0.5f, 0.5f), new float[]{0.0f, 0.0f, 0.0f}, 0.0f, 0.75f); } public VignetteFilterTransformation(PointF center, float[] color, float start, float end) { 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); } @Override public String toString() { return "VignetteFilterTransformation(center=" + center.toString() + ",color=" + Arrays.toString( vignetteColor) + ",start=" + vignetteStart + ",end=" + vignetteEnd + ")"; } @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 void updateDiskCacheKey(@NonNull MessageDigest messageDigest) { messageDigest.update((ID + center + Arrays.hashCode(vignetteColor) + vignetteStart + vignetteEnd).getBytes(CHARSET)); } } ================================================ FILE: transformations/src/main/java/jp/wasabeef/glide/transformations/internal/FastBlur.java ================================================ package jp.wasabeef.glide.transformations.internal; import android.graphics.Bitmap; /** * 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 FastBlur { public static Bitmap blur(Bitmap sentBitmap, int radius, boolean canReuseInBitmap) { // Stack Blur v1.0 from // http://www.quasimondo.com/StackBlurForCanvas/StackBlurDemo.html // // Java Author: Mario Klingemann // http://incubator.quasimondo.com // created Feburary 29, 2004 // Android port : Yahel Bouaziz // http://www.kayenko.com // ported april 5th, 2012 // This is a compromise between Gaussian Blur and Box blur // It creates much better looking blurs than Box Blur, but is // 7x faster than my Gaussian Blur implementation. // // I called it Stack Blur because this describes best how this // filter works internally: it creates a kind of moving stack // of colors whilst scanning through the image. Thereby it // just has to add one new block of color to the right side // of the stack and remove the leftmost color. The remaining // colors on the topmost layer of the stack are either added on // or reduced by one, depending on if they are on the right or // on the left side of the stack. // // If you are using this algorithm in your code please add // the following line: // // Stack Blur Algorithm by Mario Klingemann Bitmap bitmap; if (canReuseInBitmap) { bitmap = sentBitmap; } else { bitmap = sentBitmap.copy(sentBitmap.getConfig(), true); } if (radius < 1) { return (null); } int w = bitmap.getWidth(); int h = bitmap.getHeight(); int[] pix = new int[w * h]; bitmap.getPixels(pix, 0, w, 0, 0, w, h); int wm = w - 1; int hm = h - 1; 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 rsum, gsum, bsum, x, y, i, p, yp, yi, yw; int[] vmin = new int[Math.max(w, h)]; int divsum = (div + 1) >> 1; divsum *= divsum; int[] dv = new int[256 * divsum]; for (i = 0; i < 256 * divsum; i++) { dv[i] = (i / divsum); } yw = yi = 0; int[][] stack = new int[div][3]; int stackpointer; int stackstart; int[] sir; int rbs; int r1 = radius + 1; int routsum, goutsum, boutsum; int rinsum, ginsum, binsum; for (y = 0; y < h; y++) { rinsum = ginsum = binsum = routsum = goutsum = boutsum = rsum = gsum = bsum = 0; for (i = -radius; i <= radius; i++) { p = pix[yi + Math.min(wm, Math.max(i, 0))]; sir = stack[i + radius]; sir[0] = (p & 0xff0000) >> 16; sir[1] = (p & 0x00ff00) >> 8; sir[2] = (p & 0x0000ff); rbs = r1 - Math.abs(i); rsum += sir[0] * rbs; gsum += sir[1] * rbs; bsum += sir[2] * rbs; if (i > 0) { rinsum += sir[0]; ginsum += sir[1]; binsum += sir[2]; } else { routsum += sir[0]; goutsum += sir[1]; boutsum += sir[2]; } } stackpointer = radius; for (x = 0; x < w; x++) { r[yi] = dv[rsum]; g[yi] = dv[gsum]; b[yi] = dv[bsum]; rsum -= routsum; gsum -= goutsum; bsum -= boutsum; stackstart = stackpointer - radius + div; sir = stack[stackstart % div]; routsum -= sir[0]; goutsum -= sir[1]; boutsum -= sir[2]; if (y == 0) { vmin[x] = Math.min(x + radius + 1, wm); } p = pix[yw + vmin[x]]; sir[0] = (p & 0xff0000) >> 16; sir[1] = (p & 0x00ff00) >> 8; sir[2] = (p & 0x0000ff); rinsum += sir[0]; ginsum += sir[1]; binsum += sir[2]; rsum += rinsum; gsum += ginsum; bsum += binsum; stackpointer = (stackpointer + 1) % div; sir = stack[(stackpointer) % div]; routsum += sir[0]; goutsum += sir[1]; boutsum += sir[2]; rinsum -= sir[0]; ginsum -= sir[1]; binsum -= sir[2]; yi++; } yw += w; } for (x = 0; x < w; x++) { rinsum = ginsum = binsum = routsum = goutsum = boutsum = rsum = gsum = bsum = 0; yp = -radius * w; for (i = -radius; i <= radius; i++) { yi = Math.max(0, yp) + x; sir = stack[i + radius]; sir[0] = r[yi]; sir[1] = g[yi]; sir[2] = b[yi]; rbs = r1 - Math.abs(i); rsum += r[yi] * rbs; gsum += g[yi] * rbs; bsum += b[yi] * rbs; if (i > 0) { rinsum += sir[0]; ginsum += sir[1]; binsum += sir[2]; } else { routsum += sir[0]; goutsum += sir[1]; boutsum += sir[2]; } if (i < hm) { yp += w; } } yi = x; stackpointer = radius; for (y = 0; y < h; y++) { // Preserve alpha channel: ( 0xff000000 & pix[yi] ) pix[yi] = (0xff000000 & pix[yi]) | (dv[rsum] << 16) | (dv[gsum] << 8) | dv[bsum]; rsum -= routsum; gsum -= goutsum; bsum -= boutsum; stackstart = stackpointer - radius + div; sir = stack[stackstart % div]; routsum -= sir[0]; goutsum -= sir[1]; boutsum -= sir[2]; if (x == 0) { vmin[y] = Math.min(y + r1, hm) * w; } p = x + vmin[y]; sir[0] = r[p]; sir[1] = g[p]; sir[2] = b[p]; rinsum += sir[0]; ginsum += sir[1]; binsum += sir[2]; rsum += rinsum; gsum += ginsum; bsum += binsum; stackpointer = (stackpointer + 1) % div; sir = stack[stackpointer]; routsum += sir[0]; goutsum += sir[1]; boutsum += sir[2]; rinsum -= sir[0]; ginsum -= sir[1]; binsum -= sir[2]; yi += w; } } bitmap.setPixels(pix, 0, w, 0, 0, w, h); return (bitmap); } } ================================================ FILE: transformations/src/main/java/jp/wasabeef/glide/transformations/internal/RSBlur.java ================================================ package jp.wasabeef.glide.transformations.internal; import android.annotation.TargetApi; import android.content.Context; import android.graphics.Bitmap; import android.os.Build; import android.renderscript.Allocation; import android.renderscript.Element; import android.renderscript.RSRuntimeException; import android.renderscript.RenderScript; import android.renderscript.ScriptIntrinsicBlur; /** * 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 RSBlur { public static Bitmap blur(Context context, Bitmap bitmap, int radius) throws RSRuntimeException { RenderScript rs = null; Allocation input = null; Allocation output = null; ScriptIntrinsicBlur blur = null; try { rs = RenderScript.create(context); rs.setMessageHandler(new RenderScript.RSMessageHandler()); input = Allocation.createFromBitmap(rs, bitmap, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT); output = Allocation.createTyped(rs, input.getType()); blur = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs)); blur.setInput(input); blur.setRadius(radius); blur.forEach(output); output.copyTo(bitmap); } finally { if (rs != null) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { RenderScript.releaseAllContexts(); } else { rs.destroy(); } } if (input != null) { input.destroy(); } if (output != null) { output.destroy(); } if (blur != null) { blur.destroy(); } } return bitmap; } } ================================================ FILE: transformations/src/main/java/jp/wasabeef/glide/transformations/internal/Utils.java ================================================ 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) 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 final class Utils { private Utils() { // Utility class. } public static int toDp(int px) { return px * (int) Resources.getSystem().getDisplayMetrics().density; } }