├── .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 ├── art ├── demo-org.jpg └── demo.gif ├── build.gradle ├── example ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── jp │ │ └── wasabeef │ │ └── example │ │ └── glide │ │ ├── Ext.kt │ │ ├── MainActivity.kt │ │ └── MainAdapter.kt │ └── res │ ├── drawable-hdpi │ └── ic_launcher.png │ ├── drawable-mdpi │ └── ic_launcher.png │ ├── drawable-xhdpi │ ├── check.png │ ├── demo.jpg │ └── ic_launcher.png │ ├── drawable-xxhdpi │ ├── ic_launcher.png │ ├── mask_chat_right.9.png │ └── mask_starfish.png │ ├── layout │ ├── activity_main.xml │ └── layout_list_item.xml │ ├── values-w820dp │ └── dimens.xml │ └── values │ ├── colors.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.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 /.editorconfig: -------------------------------------------------------------------------------- 1 | [*] 2 | indent_size = 2 3 | max_line_length = off 4 | insert_final_newline = true 5 | 6 | [*.{kt, kts}] 7 | kotlin_imports_layout = ascii 8 | 9 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: wasabeef # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 13 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | # Future Task 2 | 3 | ## What is the motivation? 4 | 5 | ## What kind of solution can be considered? 6 | 7 | ## What do you want to discuss? 8 | 9 | *Please add relevant labels* 10 | 11 | ----- 12 | 13 | # Bug Reporting 14 | 15 | ## Steps to Reproduce 16 | 17 | ## Actual Results (include screenshots) 18 | 19 | ## Expected Results (include screenshots) 20 | 21 | ## URL 22 | 23 | ## OS details 24 | 25 | - Device: 26 | - OS: 27 | 28 | *Please add relevant labels* 29 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## What does this change? 2 | 3 | ## What is the value of this and can you measure success? 4 | 5 | ## Screenshots 6 | 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Mac OS 2 | .DS_store 3 | 4 | # Built application files 5 | *.apk 6 | *.ap_ 7 | 8 | # Files for the ART/Dalvik VM 9 | *.dex 10 | 11 | # Java class files 12 | *.class 13 | 14 | # Generated files 15 | bin/ 16 | gen/ 17 | out/ 18 | 19 | # Gradle files 20 | .gradle/ 21 | build/ 22 | 23 | # Local configuration file (sdk path, etc) 24 | local.properties 25 | 26 | # Proguard folder generated by Eclipse 27 | proguard/ 28 | 29 | # Log Files 30 | *.log 31 | 32 | # Android Studio Navigation editor temp files 33 | .navigation/ 34 | 35 | # Android Studio captures folder 36 | captures/ 37 | 38 | # IntelliJ 39 | *.iml 40 | .idea/workspace.xml 41 | .idea/tasks.xml 42 | .idea/gradle.xml 43 | .idea/assetWizardSettings.xml 44 | .idea/dictionaries 45 | .idea/libraries 46 | .idea/caches 47 | .idea/misc.xml 48 | .idea/modules.xml 49 | .idea/navEditor.xml 50 | .idea/markdown* 51 | .idea/jarRepositories.xml 52 | .idea/inspectionProfiles/Project_Default.xml 53 | .idea/compiler.xml 54 | projectFilesBackup/ 55 | 56 | # Keystore files 57 | # Uncomment the following line if you do not want to check your keystore files in. 58 | #*.jks 59 | 60 | # External native build folder generated in Android Studio 2.2 and later 61 | .externalNativeBuild 62 | 63 | # Google Services (e.g. APIs or Firebase) 64 | google-services.json 65 | 66 | -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | xmlns:android 14 | 15 | ^$ 16 | 17 | 18 | 19 |
20 |
21 | 22 | 23 | 24 | xmlns:.* 25 | 26 | ^$ 27 | 28 | 29 | BY_NAME 30 | 31 |
32 |
33 | 34 | 35 | 36 | .*:id 37 | 38 | http://schemas.android.com/apk/res/android 39 | 40 | 41 | 42 |
43 |
44 | 45 | 46 | 47 | .*:name 48 | 49 | http://schemas.android.com/apk/res/android 50 | 51 | 52 | 53 |
54 |
55 | 56 | 57 | 58 | name 59 | 60 | ^$ 61 | 62 | 63 | 64 |
65 |
66 | 67 | 68 | 69 | style 70 | 71 | ^$ 72 | 73 | 74 | 75 |
76 |
77 | 78 | 79 | 80 | .* 81 | 82 | ^$ 83 | 84 | 85 | BY_NAME 86 | 87 |
88 |
89 | 90 | 91 | 92 | .* 93 | 94 | http://schemas.android.com/apk/res/android 95 | 96 | 97 | ANDROID_ATTRIBUTE_ORDER 98 | 99 |
100 |
101 | 102 | 103 | 104 | .* 105 | 106 | .* 107 | 108 | 109 | BY_NAME 110 | 111 |
112 |
113 |
114 |
115 |
116 |
-------------------------------------------------------------------------------- /.idea/codeStyles/codeStyleConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | Change Log 2 | ========== 3 | 4 | Version 4.3.0 *(2020-09-27)* 5 | ---------------------------- 6 | 7 | Feature 8 | - Remove support v8 renderscript (Please use BlurTransformation) 9 | 10 | Update 11 | - minSdkVersion -> 21 12 | - GPUImage -> 2.1.0 13 | - Cleanup codes 14 | 15 | Version 4.2.0 *(2020-09-15)* 16 | ---------------------------- 17 | 18 | Update: 19 | - Compile & Target SDK Version 28 -> 30 20 | - GPUImage 2.0.3 -> 2.0.4 21 | - Glide 4.9.0 -> 4.11.0 22 | 23 | Bugfix: 24 | - RoundedCornersTransformation with DIAGONAL_FROM_TOP_LEFT does not work [#178](https://github.com/wasabeef/glide-transformations/pull/178) 25 | 26 | Version 4.1.0 *(2019-08-15)* 27 | ---------------------------- 28 | 29 | Add: 30 | - Support to CropCircle with Border [#136](https://github.com/wasabeef/glide-transformations/pull/136) 31 | 32 | Update: 33 | - Glide to 4.9.0 34 | - Android Gradle plugin to 3.6.0-alpha05 35 | - Kotlin to 1.3.41 36 | 37 | Bug Fix: 38 | - Fix diffrent density [#147](https://github.com/wasabeef/glide-transformations/pull/147) 39 | 40 | 41 | Version 4.0.1 *(2018-11-20)* 42 | ---------------------------- 43 | 44 | Add: 45 | - consumerProguardFiles setting 46 | 47 | Version 4.0.0 *(2018-11-16)* 48 | ---------------------------- 49 | 50 | Update: 51 | - Migrate to AndroidX 52 | - Remove novoda-bintray-plugin 53 | 54 | Version 3.3.0 *(2018-04-23)* 55 | ---------------------------- 56 | 57 | Update: 58 | - Support Library 27.1.0 -> 27.1.1 59 | - Glide 4.6.1 -> 4.7.1 60 | 61 | Feature: 62 | - SupportRSBlurTransformation [#125](https://github.com/wasabeef/glide-transformations/pull/125) 63 | it's using RenderScript support mode but can you choose to use or not. 64 | Thank you [@fougere-mike](https://github.com/fougere-mike) 65 | 66 | Bug Fix: 67 | - Set detail of Cache key [#119](https://github.com/wasabeef/glide-transformations/issues/119) 68 | 69 | Version 3.2.0 *(2018-04-10)* 70 | ---------------------------- 71 | 72 | Update: 73 | - Support Library 27.0.2 -> 27.1.0 74 | 75 | Bug Fix: 76 | - We quit use the RenderScript [#120](https://github.com/wasabeef/glide-transformations/issues/120) 77 | 78 | Version 3.1.1 *(2018-02-13)* 79 | ---------------------------- 80 | 81 | Update: 82 | - Glide 4.5.0 -> 4.6.1 83 | 84 | Bug Fix: 85 | - Fix settings fot proguard. 86 | 87 | Version 3.1.0 *(2018-01-26)* 88 | ---------------------------- 89 | 90 | Update: 91 | - Compile & Target SDK Version 25 -> 27 92 | - Build Tools 26.0.1 -> 27.0.3 93 | - Support Library 25.3.1 -> 27.0.2 94 | - Glide 4.0.0 -> 4.5.0 95 | 96 | Bug Fix: 97 | - [Implement equals() and hashCode() methods #105](https://github.com/wasabeef/glide-transformations/pull/105) 98 | - Use RenderScript#releaseAllContexts 99 | 100 | Version 3.0.1 *(2017-09-08)* 101 | ---------------------------- 102 | 103 | Bug Fix: 104 | - [Deleted a setting for DexGuard #86](https://github.com/wasabeef/glide-transformations/issues/86) 105 | 106 | Version 3.0.0 *(2017-09-06)* 107 | ---------------------------- 108 | 109 | Update: 110 | - Build Tools 25.0.2 -> 26.0.1 111 | - Min SDK Version 11 -> 14 112 | - Glide 3.7.0 -> 4.0.0 113 | 114 | Feature: 115 | - Supported Glide 4.0.0 116 | 117 | Version 2.0.2 *(2017-03-17)* 118 | ---------------------------- 119 | 120 | Update: 121 | - Compile & Target SDK Version 23 -> 25 122 | - Build Tools 23.0.2 -> 25.0.2 123 | - Support Library 23.2.1 -> 25.3.0 124 | - GPUImage for Android 1.3.0 -> 1.4.1 125 | 126 | Bug Fix: 127 | - [Additional resource cleanup in RSBlur #45](https://github.com/wasabeef/glide-transformations/pull/45) 128 | 129 | Version 2.0.1 *(2016-04-21)* 130 | ---------------------------- 131 | 132 | Fix: 133 | [#35](https://github.com/wasabeef/glide-transformations/issues/35) 134 | RSInvalidStateException 135 | 136 | Version 2.0.0 *(2016-03-02)* 137 | ---------------------------- 138 | 139 | Say v8.RenderScript goodbye 140 | 141 | Version 1.4.0 *(2016-02-28)* 142 | ---------------------------- 143 | 144 | fix Issue [#29](https://github.com/wasabeef/glide-transformations/issues/29) 145 | Use FastBlur as a fallback upon RenderScript failure. 146 | 147 | Version 1.3.1 *(2015-11-27)* 148 | ---------------------------- 149 | 150 | Change the renderscriptTargetApi down to 20. 151 | Warning:Renderscript support mode is not currently supported with renderscript target 21+ 152 | 153 | fix: memory leak. 154 | 155 | Version 1.3.0 *(2015-11-10)* 156 | ---------------------------- 157 | 158 | add round corner type to RoundedCornersTransformation. 159 | Thanks to [kaelaela](https://github.com/kaelaela) 160 | 161 | Version 1.2.1 *(2015-09-18)* 162 | ---------------------------- 163 | 164 | Merged NinePatchMaskTransformation to MaskTransformation. 165 | 166 | Version 1.2.0 *(2015-09-16)* 167 | ---------------------------- 168 | 169 | add new transformations MaskTransformation and NinePatchMaskTransformation. 170 | Thanks to [start141](https://github.com/start141) 171 | 172 | Version 1.1.0 *(2015-09-05)* 173 | ---------------------------- 174 | 175 | Adjustment of default parameters. 176 | 177 | Version 1.0.8 *(2015-07-24)* 178 | ---------------------------- 179 | 180 | add DownSampling to BlurTransform 181 | 182 | Version 1.0.7 *(2015-07-18)* 183 | ---------------------------- 184 | 185 | Bug fix : Blur not working. 186 | 187 | Version 1.0.6 *(2015-04-23)* 188 | ---------------------------- 189 | 190 | add: CropType(Top, Center, Bottom) for CropTransformation. 191 | 192 | Version 1.0.5 *(2015-03-09)* 193 | ---------------------------- 194 | 195 | Bug fix: Transparency. 196 | 197 | Version 1.0.4 *(2015-02-13)* 198 | ---------------------------- 199 | 200 | Bug fix : remove original bitmap resource recycling. 201 | 202 | Version 1.0.3 *(2015-02-05)* 203 | ---------------------------- 204 | 205 | Bug fix 206 | 207 | Version 1.0.2 *(2015-02-04)* 208 | ---------------------------- 209 | 210 | Refactor: use BimapPool 211 | 212 | Version 1.0.1 *(2015-01-21)* 213 | ---------------------------- 214 | 215 | fix: Blur Transformation now woking at Android 4.3 216 | add: GPUImage to Gradle dependency 217 | 218 | Version 1.0.0 *(2015-01-12)* 219 | ---------------------------- 220 | 221 | Initial release. 222 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Glide Transformations 2 | ====================== 3 | [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-glide--transformations-brightgreen.svg?style=flat)](https://android-arsenal.com/details/1/1363) 4 | [![License](https://img.shields.io/badge/license-Apache%202-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0) 5 | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/jp.wasabeef/glide-transformations/badge.svg)](https://search.maven.org/artifact/jp.wasabeef/glide-transformations) 6 | 7 | An Android transformation library providing a variety of image transformations for [Glide](https://github.com/bumptech/glide). 8 | 9 | Please feel free to use this. 10 | 11 | 12 | #### Are you using Picasso or Fresco? 13 | [Picasso Transformations](https://github.com/wasabeef/picasso-transformations) 14 | [Fresco Processors](https://github.com/wasabeef/fresco-processors) 15 | 16 | # Demo 17 | 18 | ### Original Image 19 | 20 | 21 | ### Transformations 22 | 23 | 24 | # How do I use it? 25 | 26 | ## Step 1 27 | 28 | #### Gradle 29 | ```groovy 30 | repositories { 31 | mavenCentral() 32 | } 33 | 34 | dependencies { 35 | implementation 'jp.wasabeef:glide-transformations:4.3.0' 36 | // If you want to use the GPU Filters 37 | implementation 'jp.co.cyberagent.android:gpuimage:2.1.0' 38 | } 39 | ``` 40 | 41 | ## Step 2 42 | 43 | Set Glide Transform. 44 | 45 | ```kotlin 46 | Glide.with(this).load(R.drawable.demo) 47 | .apply(RequestOptions.bitmapTransform(BlurTransformation(25, 3))) 48 | .into(imageView) 49 | ``` 50 | 51 | ## Advanced Step 3 52 | 53 | You can set a multiple transformations. 54 | 55 | ```kotlin 56 | val multi = MultiTransformation( 57 | BlurTransformation(25), 58 | RoundedCornersTransformation(128, 0, CornerType.BOTTOM)))) 59 | Glide.with(this).load(R.drawable.demo) 60 | .apply(RequestOptions.bitmapTransform(multi)) 61 | .into(imageView)) 62 | ``` 63 | 64 | ## Transformations 65 | 66 | ### Crop 67 | - `CropTransformation` 68 | - `CropCircleTransformation` 69 | - `CropCircleWithBorderTransformation` 70 | - `CropSquareTransformation` 71 | - `RoundedCornersTransformation` 72 | 73 | ### Color 74 | - `ColorFilterTransformation` 75 | - `GrayscaleTransformation` 76 | 77 | ### Blur 78 | - `BlurTransformation` 79 | 80 | ### Mask 81 | - `MaskTransformation` 82 | 83 | ### GPU Filter (use [GPUImage](https://github.com/CyberAgent/android-gpuimage)) 84 | **Will require add dependencies for GPUImage.** 85 | 86 | - `ToonFilterTransformation` 87 | - `SepiaFilterTransformation` 88 | - `ContrastFilterTransformation` 89 | - `InvertFilterTransformation` 90 | - `PixelationFilterTransformation` 91 | - `SketchFilterTransformation` 92 | - `SwirlFilterTransformation` 93 | - `BrightnessFilterTransformation` 94 | - `KuwaharaFilterTransformation` 95 | - `VignetteFilterTransformation` 96 | 97 | 98 | Applications using Glide Transformations 99 | --- 100 | 101 | Please [ping](mailto:dadadada.chop@gmail.com) me or send a pull request if you would like to be added here. 102 | 103 | Icon | Application 104 | ------------ | ------------- 105 | | [Ameba Ownd](https://play.google.com/store/apps/details?id=jp.co.cyberagent.madrid) 106 | | [AbemaTV](https://play.google.com/store/apps/details?id=tv.abema) 107 | | [TV Time](https://play.google.com/store/apps/details?id=com.tozelabs.tvshowtime) 108 | | [Christmas Radio](https://play.google.com/store/apps/details?id=nl.netwaves.christmasradio) 109 | 110 | 111 | 112 | Developed By 113 | ------- 114 | Daichi Furiya (Wasabeef) - 115 | 116 | 117 | Follow me on Twitter 119 | 120 | 121 | Contributions 122 | ------- 123 | 124 | Any contributions are welcome! 125 | 126 | Contributors 127 | ------- 128 | 129 | * [start141](https://github.com/start141) 130 | * [squeeish](https://github.com/squeeish) 131 | 132 | Thanks 133 | ------- 134 | 135 | * Inspired by `Picasso Transformations` in [TannerPerrien](https://github.com/TannerPerrien). 136 | 137 | License 138 | ------- 139 | 140 | Copyright (C) 2020 Wasabeef 141 | 142 | Licensed under the Apache License, Version 2.0 (the "License"); 143 | you may not use this file except in compliance with the License. 144 | You may obtain a copy of the License at 145 | 146 | http://www.apache.org/licenses/LICENSE-2.0 147 | 148 | Unless required by applicable law or agreed to in writing, software 149 | distributed under the License is distributed on an "AS IS" BASIS, 150 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 151 | See the License for the specific language governing permissions and 152 | limitations under the License. 153 | -------------------------------------------------------------------------------- /art/demo-org.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wasabeef/glide-transformations/d950f0c33f27f864e4ab4b26fce66c27079911c1/art/demo-org.jpg -------------------------------------------------------------------------------- /art/demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wasabeef/glide-transformations/d950f0c33f27f864e4ab4b26fce66c27079911c1/art/demo.gif -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | ext { 5 | kotlin_version = '1.3.72' 6 | glide_version = '4.11.0' 7 | gpuimage_version = '2.1.0' 8 | } 9 | 10 | repositories { 11 | google() 12 | jcenter() 13 | } 14 | dependencies { 15 | classpath 'com.android.tools.build:gradle:4.2.0-beta04' 16 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 17 | 18 | // TODO: Close JCenter on May 1st https://jfrog.com/blog/into-the-sunset-bintray-jcenter-gocenter-and-chartcenter/ 19 | // classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.5' 20 | // classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' 21 | } 22 | } 23 | 24 | allprojects { 25 | repositories { 26 | google() 27 | mavenCentral() 28 | jcenter() 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /example/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'kotlin-android' 3 | apply plugin: 'kotlin-kapt' 4 | 5 | android { 6 | compileSdkVersion COMPILE_SDK_VERSION as int 7 | 8 | defaultConfig { 9 | minSdkVersion MIN_SDK_VERSION as int 10 | targetSdkVersion TARGET_SDK_VERSION as int 11 | versionCode VERSION_CODE as int 12 | versionName VERSION_NAME 13 | } 14 | 15 | // SigningConfigs 16 | apply from: '../signingConfigs/debug.gradle', to: android 17 | 18 | buildTypes { 19 | debug { 20 | debuggable true 21 | signingConfig signingConfigs.debug 22 | } 23 | release { 24 | debuggable false 25 | zipAlignEnabled true 26 | minifyEnabled true 27 | shrinkResources true 28 | } 29 | } 30 | } 31 | 32 | repositories { 33 | // maven { url = "https://oss.sonatype.org/content/repositories/snapshots"} 34 | } 35 | 36 | dependencies { 37 | // implementation project(':transformations') 38 | implementation 'jp.wasabeef:glide-transformations:4.3.0' 39 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 40 | implementation "com.github.bumptech.glide:glide:$glide_version" 41 | kapt "com.github.bumptech.glide:compiler:$glide_version" 42 | implementation "jp.co.cyberagent.android:gpuimage:$gpuimage_version" 43 | implementation "androidx.appcompat:appcompat:1.3.0-beta01" 44 | implementation "androidx.recyclerview:recyclerview:1.2.0-beta01" 45 | implementation 'androidx.constraintlayout:constraintlayout:2.0.4' 46 | } 47 | -------------------------------------------------------------------------------- /example/proguard-rules.pro: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wasabeef/glide-transformations/d950f0c33f27f864e4ab4b26fce66c27079911c1/example/proguard-rules.pro -------------------------------------------------------------------------------- /example/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 12 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /example/src/main/java/jp/wasabeef/example/glide/Ext.kt: -------------------------------------------------------------------------------- 1 | package jp.wasabeef.example.glide 2 | 3 | /** 4 | * Copyright (C) 2020 Wasabeef 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import android.content.res.Resources 20 | 21 | val Float.px: Float get() = (this * Resources.getSystem().displayMetrics.density) 22 | 23 | val Int.px: Int get() = ((this * Resources.getSystem().displayMetrics.density).toInt()) 24 | -------------------------------------------------------------------------------- /example/src/main/java/jp/wasabeef/example/glide/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package jp.wasabeef.example.glide 2 | 3 | import android.os.Bundle 4 | import androidx.appcompat.app.AppCompatActivity 5 | import androidx.recyclerview.widget.LinearLayoutManager 6 | import androidx.recyclerview.widget.RecyclerView 7 | import jp.wasabeef.example.glide.MainAdapter.Type.* 8 | 9 | class MainActivity : AppCompatActivity() { 10 | 11 | override fun onCreate(savedInstanceState: Bundle?) { 12 | super.onCreate(savedInstanceState) 13 | setContentView(R.layout.activity_main) 14 | 15 | findViewById(R.id.list).apply { 16 | layoutManager = LinearLayoutManager(context) 17 | adapter = MainAdapter(context, mutableListOf( 18 | Mask, NinePatchMask, RoundedCorners, CropTop, CropCenter, CropBottom, CropSquare, CropCircle, 19 | CropCircleWithBorder, Grayscale, BlurLight, BlurDeep, Toon, Sepia, Contrast, Invert, 20 | Pixel, Sketch, Swirl, Brightness, Kuawahara, Vignette 21 | )) 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /example/src/main/java/jp/wasabeef/example/glide/MainAdapter.kt: -------------------------------------------------------------------------------- 1 | package jp.wasabeef.example.glide 2 | 3 | import android.content.Context 4 | import android.graphics.Bitmap 5 | import android.graphics.Color 6 | import android.graphics.PointF 7 | import android.view.LayoutInflater 8 | import android.view.View 9 | import android.view.ViewGroup 10 | import android.widget.ImageView 11 | import android.widget.TextView 12 | import androidx.recyclerview.widget.RecyclerView 13 | import com.bumptech.glide.Glide 14 | import com.bumptech.glide.load.MultiTransformation 15 | import com.bumptech.glide.load.resource.bitmap.CenterCrop 16 | import com.bumptech.glide.request.RequestOptions.bitmapTransform 17 | import com.bumptech.glide.request.RequestOptions.overrideOf 18 | import jp.wasabeef.example.glide.MainAdapter.Type.* 19 | import jp.wasabeef.glide.transformations.* 20 | import jp.wasabeef.glide.transformations.CropTransformation.CropType 21 | import jp.wasabeef.glide.transformations.gpu.* 22 | import jp.wasabeef.glide.transformations.internal.Utils 23 | 24 | /** 25 | * Created by Wasabeef on 2015/01/11. 26 | */ 27 | class MainAdapter( 28 | private val context: Context, 29 | private val dataSet: MutableList 30 | ) : RecyclerView.Adapter() { 31 | 32 | enum class Type { 33 | Mask, 34 | NinePatchMask, 35 | CropTop, 36 | CropCenter, 37 | CropBottom, 38 | CropSquare, 39 | CropCircle, 40 | CropCircleWithBorder, 41 | ColorFilter, 42 | Grayscale, 43 | RoundedCorners, 44 | BlurLight, 45 | BlurDeep, 46 | Toon, 47 | Sepia, 48 | Contrast, 49 | Invert, 50 | Pixel, 51 | Sketch, 52 | Swirl, 53 | Brightness, 54 | Kuawahara, 55 | Vignette 56 | } 57 | 58 | override fun getItemCount(): Int { 59 | return dataSet.size 60 | } 61 | 62 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { 63 | val v = LayoutInflater.from(context).inflate(R.layout.layout_list_item, parent, false) 64 | return ViewHolder(v) 65 | } 66 | 67 | override fun onBindViewHolder(holder: ViewHolder, position: Int) { 68 | 69 | when (dataSet[position]) { 70 | Mask -> { 71 | Glide.with(context) 72 | .load(R.drawable.check) 73 | .apply(overrideOf(266.px, 252.px)) 74 | .apply(bitmapTransform(MultiTransformation(CenterCrop(), 75 | MaskTransformation(R.drawable.mask_starfish)))) 76 | .into(holder.image) 77 | } 78 | NinePatchMask -> { 79 | Glide.with(context) 80 | .load(R.drawable.check) 81 | .apply(overrideOf(300.px, 200.px)) 82 | .apply(bitmapTransform(MultiTransformation(CenterCrop(), 83 | MaskTransformation(R.drawable.mask_chat_right)))) 84 | .into(holder.image) 85 | } 86 | 87 | CropTop -> Glide.with(context) 88 | .load(R.drawable.demo) 89 | .apply(bitmapTransform(CropTransformation(300.px, 100.px, CropType.TOP))) 90 | .into(holder.image) 91 | 92 | CropCenter -> Glide.with(context) 93 | .load(R.drawable.demo) 94 | .apply(bitmapTransform(CropTransformation(300.px, 100.px, CropType.CENTER))) 95 | .into(holder.image) 96 | 97 | CropBottom -> Glide.with(context) 98 | .load(R.drawable.demo) 99 | .apply(bitmapTransform(CropTransformation(300.px, 100.px, CropType.BOTTOM))) 100 | .into(holder.image) 101 | 102 | CropSquare -> Glide.with(context) 103 | .load(R.drawable.demo) 104 | .apply(bitmapTransform(CropSquareTransformation())) 105 | .into(holder.image) 106 | 107 | CropCircle -> Glide.with(context) 108 | .load(R.drawable.demo) 109 | .apply(bitmapTransform(CropCircleTransformation())) 110 | .into(holder.image) 111 | 112 | CropCircleWithBorder -> Glide.with(context) 113 | .load(R.drawable.demo) 114 | .apply(bitmapTransform( 115 | CropCircleWithBorderTransformation(Utils.toDp(4), Color.rgb(0, 145, 86)))) 116 | .into(holder.image) 117 | 118 | ColorFilter -> Glide.with(context) 119 | .load(R.drawable.demo) 120 | .apply(bitmapTransform(ColorFilterTransformation(Color.argb(80, 255, 0, 0)))) 121 | .into(holder.image) 122 | 123 | Grayscale -> Glide.with(context) 124 | .load(R.drawable.demo) 125 | .apply(bitmapTransform(GrayscaleTransformation())) 126 | .into(holder.image) 127 | 128 | RoundedCorners -> Glide.with(context) 129 | .load(R.drawable.demo) 130 | .apply(bitmapTransform(RoundedCornersTransformation(120, 0, 131 | RoundedCornersTransformation.CornerType.DIAGONAL_FROM_TOP_LEFT))) 132 | .into(holder.image) 133 | 134 | BlurLight -> Glide.with(context) 135 | .load(R.drawable.check) 136 | .apply(bitmapTransform(BlurTransformation(25))) 137 | .into(holder.image) 138 | 139 | BlurDeep -> Glide.with(context) 140 | .load(R.drawable.check) 141 | .apply(bitmapTransform(BlurTransformation(25, 8))) 142 | .into(holder.image) 143 | 144 | Toon -> Glide.with(context) 145 | .load(R.drawable.demo) 146 | .apply(bitmapTransform(ToonFilterTransformation())) 147 | .into(holder.image) 148 | 149 | Sepia -> Glide.with(context) 150 | .load(R.drawable.check) 151 | .apply(bitmapTransform(SepiaFilterTransformation())) 152 | .into(holder.image) 153 | 154 | Contrast -> Glide.with(context) 155 | .load(R.drawable.check) 156 | .apply(bitmapTransform(ContrastFilterTransformation(2.0f))) 157 | .into(holder.image) 158 | 159 | Invert -> Glide.with(context) 160 | .load(R.drawable.check) 161 | .apply(bitmapTransform(InvertFilterTransformation())) 162 | .into(holder.image) 163 | 164 | Pixel -> Glide.with(context) 165 | .load(R.drawable.check) 166 | .apply(bitmapTransform(PixelationFilterTransformation(20f))) 167 | .into(holder.image) 168 | 169 | Sketch -> Glide.with(context) 170 | .load(R.drawable.check) 171 | .apply(bitmapTransform(SketchFilterTransformation())) 172 | .into(holder.image) 173 | 174 | Swirl -> Glide.with(context) 175 | .load(R.drawable.check) 176 | .apply(bitmapTransform( 177 | SwirlFilterTransformation(0.5f, 1.0f, PointF(0.5f, 0.5f))).dontAnimate()) 178 | .into(holder.image) 179 | 180 | Brightness -> Glide.with(context) 181 | .load(R.drawable.check) 182 | .apply(bitmapTransform(BrightnessFilterTransformation(0.5f)).dontAnimate()) 183 | .into(holder.image) 184 | 185 | Kuawahara -> Glide.with(context) 186 | .load(R.drawable.check) 187 | .apply(bitmapTransform(KuwaharaFilterTransformation(25)).dontAnimate()) 188 | .into(holder.image) 189 | 190 | Vignette -> Glide.with(context) 191 | .load(R.drawable.check) 192 | .apply(bitmapTransform(VignetteFilterTransformation(PointF(0.5f, 0.5f), 193 | floatArrayOf(0.0f, 0.0f, 0.0f), 0f, 0.75f)).dontAnimate()) 194 | .into(holder.image) 195 | } 196 | holder.title.text = dataSet[position].name 197 | } 198 | 199 | class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { 200 | var image: ImageView = itemView.findViewById(R.id.image) 201 | var title: TextView = itemView.findViewById(R.id.title) 202 | } 203 | } 204 | -------------------------------------------------------------------------------- /example/src/main/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wasabeef/glide-transformations/d950f0c33f27f864e4ab4b26fce66c27079911c1/example/src/main/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/src/main/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wasabeef/glide-transformations/d950f0c33f27f864e4ab4b26fce66c27079911c1/example/src/main/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/src/main/res/drawable-xhdpi/check.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wasabeef/glide-transformations/d950f0c33f27f864e4ab4b26fce66c27079911c1/example/src/main/res/drawable-xhdpi/check.png -------------------------------------------------------------------------------- /example/src/main/res/drawable-xhdpi/demo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wasabeef/glide-transformations/d950f0c33f27f864e4ab4b26fce66c27079911c1/example/src/main/res/drawable-xhdpi/demo.jpg -------------------------------------------------------------------------------- /example/src/main/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wasabeef/glide-transformations/d950f0c33f27f864e4ab4b26fce66c27079911c1/example/src/main/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/src/main/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wasabeef/glide-transformations/d950f0c33f27f864e4ab4b26fce66c27079911c1/example/src/main/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/src/main/res/drawable-xxhdpi/mask_chat_right.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wasabeef/glide-transformations/d950f0c33f27f864e4ab4b26fce66c27079911c1/example/src/main/res/drawable-xxhdpi/mask_chat_right.9.png -------------------------------------------------------------------------------- /example/src/main/res/drawable-xxhdpi/mask_starfish.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wasabeef/glide-transformations/d950f0c33f27f864e4ab4b26fce66c27079911c1/example/src/main/res/drawable-xxhdpi/mask_starfish.png -------------------------------------------------------------------------------- /example/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 15 | 16 | -------------------------------------------------------------------------------- /example/src/main/res/layout/layout_list_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 21 | 22 | 32 | 33 | -------------------------------------------------------------------------------- /example/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /example/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /example/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /example/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | glide-transformations 5 | Hello world! 6 | Settings 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=1024m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 2 | org.gradle.parallel=true 3 | org.gradle.daemon=true 4 | org.gradle.configureondemand=true 5 | org.gradle.caching=true 6 | android.enableBuildCache=true 7 | android.useAndroidX=true 8 | # Use R8 instead of ProGuard for code shrinking. 9 | android.enableR8.fullMode=true 10 | 11 | VERSION_NAME=4.3.0 12 | VERSION_CODE=421 13 | GROUP=jp.wasabeef 14 | COMPILE_SDK_VERSION=30 15 | TARGET_SDK_VERSION=30 16 | MIN_SDK_VERSION=21 17 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wasabeef/glide-transformations/d950f0c33f27f864e4ab4b26fce66c27079911c1/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https://services.gradle.org/distributions/gradle-6.7.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | 86 | # Determine the Java command to use to start the JVM. 87 | if [ -n "$JAVA_HOME" ] ; then 88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 89 | # IBM's JDK on AIX uses strange locations for the executables 90 | JAVACMD="$JAVA_HOME/jre/sh/java" 91 | else 92 | JAVACMD="$JAVA_HOME/bin/java" 93 | fi 94 | if [ ! -x "$JAVACMD" ] ; then 95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 96 | 97 | Please set the JAVA_HOME variable in your environment to match the 98 | location of your Java installation." 99 | fi 100 | else 101 | JAVACMD="java" 102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 103 | 104 | Please set the JAVA_HOME variable in your environment to match the 105 | location of your Java installation." 106 | fi 107 | 108 | # Increase the maximum file descriptors if we can. 109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 110 | MAX_FD_LIMIT=`ulimit -H -n` 111 | if [ $? -eq 0 ] ; then 112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 113 | MAX_FD="$MAX_FD_LIMIT" 114 | fi 115 | ulimit -n $MAX_FD 116 | if [ $? -ne 0 ] ; then 117 | warn "Could not set maximum file descriptor limit: $MAX_FD" 118 | fi 119 | else 120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 121 | fi 122 | fi 123 | 124 | # For Darwin, add options to specify how the application appears in the dock 125 | if $darwin; then 126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 127 | fi 128 | 129 | # For Cygwin or MSYS, switch paths to Windows format before running java 130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 133 | 134 | JAVACMD=`cygpath --unix "$JAVACMD"` 135 | 136 | # We build the pattern for arguments to be converted via cygpath 137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 138 | SEP="" 139 | for dir in $ROOTDIRSRAW ; do 140 | ROOTDIRS="$ROOTDIRS$SEP$dir" 141 | SEP="|" 142 | done 143 | OURCYGPATTERN="(^($ROOTDIRS))" 144 | # Add a user-defined pattern to the cygpath arguments 145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 147 | fi 148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 149 | i=0 150 | for arg in "$@" ; do 151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 153 | 154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 156 | else 157 | eval `echo args$i`="\"$arg\"" 158 | fi 159 | i=`expr $i + 1` 160 | done 161 | case $i in 162 | 0) set -- ;; 163 | 1) set -- "$args0" ;; 164 | 2) set -- "$args0" "$args1" ;; 165 | 3) set -- "$args0" "$args1" "$args2" ;; 166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 172 | esac 173 | fi 174 | 175 | # Escape application args 176 | save () { 177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 178 | echo " " 179 | } 180 | APP_ARGS=`save "$@"` 181 | 182 | # Collect all arguments for the java command, following the shell quoting and substitution rules 183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 184 | 185 | exec "$JAVACMD" "$@" 186 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':example', ':transformations' 2 | -------------------------------------------------------------------------------- /signingConfigs/debug.gradle: -------------------------------------------------------------------------------- 1 | signingConfigs { 2 | debug { 3 | storeFile file("debug.keystore") 4 | storePassword "android" 5 | keyAlias "androiddebugkey" 6 | keyPassword "android" 7 | } 8 | } 9 | 10 | // $ keytool -v -list -keystore 11 | // Certificate fingerprints: 12 | // MD5: 28:22:7C:A4:B9:2F:6E:C7:D5:58:62:48:EB:7E:82:C3 13 | // SHA1: 94:25:A9:50:9C:0E:AE:AA:00:37:5E:D6:71:E3:BC:ED:17:E5:0C:A3 14 | // 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 15 | -------------------------------------------------------------------------------- /signingConfigs/debug.keystore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wasabeef/glide-transformations/d950f0c33f27f864e4ab4b26fce66c27079911c1/signingConfigs/debug.keystore -------------------------------------------------------------------------------- /transformations/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion COMPILE_SDK_VERSION as int 5 | 6 | defaultConfig { 7 | minSdkVersion MIN_SDK_VERSION as int 8 | targetSdkVersion TARGET_SDK_VERSION as int 9 | 10 | consumerProguardFiles 'proguard-rules.txt' 11 | } 12 | } 13 | 14 | dependencies { 15 | implementation "com.github.bumptech.glide:glide:$glide_version" 16 | annotationProcessor "com.github.bumptech.glide:compiler:$glide_version" 17 | compileOnly "jp.co.cyberagent.android:gpuimage:$gpuimage_version" 18 | } 19 | 20 | ext { 21 | bintrayRepo = 'maven' 22 | bintrayName = 'glide-transformations' 23 | bintrayUserOrg = 'wasabeef' 24 | publishedGroupId = 'jp.wasabeef' 25 | libraryName = 'glide-transformations' 26 | artifact = 'glide-transformations' 27 | libraryDescription = 'Which provides simple Transformations to Glide' 28 | siteUrl = 'https://github.com/wasabeef/glide-transformations' 29 | gitUrl = 'https://github.com/wasabeef/glide-transformations.git' 30 | issueUrl = 'https://github.com/wasabeef/glide-transformations/issues' 31 | libraryVersion = VERSION_NAME 32 | developerId = 'wasabeef' 33 | developerName = 'Wasabeef' 34 | developerEmail = 'dadadada.chop@gmail.com' 35 | licenseName = 'The Apache Software License, Version 2.0' 36 | licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt' 37 | allLicenses = ["Apache-2.0"] 38 | } 39 | 40 | // TODO: Close JCenter on May 1st https://jfrog.com/blog/into-the-sunset-bintray-jcenter-gocenter-and-chartcenter/ 41 | // apply from: 'https://gist.githubusercontent.com/wasabeef/cf14805bee509baf7461974582f17d26/raw/bintray-v1.gradle' 42 | // apply from: 'https://gist.githubusercontent.com/wasabeef/cf14805bee509baf7461974582f17d26/raw/install-v1.gradle' 43 | 44 | apply from: 'https://gist.githubusercontent.com/wasabeef/2f2ae8d97b429e7d967128125dc47854/raw/maven-central-v1.gradle' 45 | -------------------------------------------------------------------------------- /transformations/proguard-rules.txt: -------------------------------------------------------------------------------- 1 | -dontwarn jp.co.cyberagent.android.gpuimage.** 2 | 3 | -keep public class * implements com.bumptech.glide.module.GlideModule 4 | -keep public class * extends com.bumptech.glide.module.AppGlideModule 5 | -keep public enum com.bumptech.glide.load.ImageHeaderParser$** { 6 | **[] $VALUES; 7 | public *; 8 | } 9 | -------------------------------------------------------------------------------- /transformations/src/androidTest/java/jp/wasabeef/glide/transformations/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package jp.wasabeef.glide.transformations; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | 11 | public ApplicationTest() { 12 | super(Application.class); 13 | } 14 | } -------------------------------------------------------------------------------- /transformations/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /transformations/src/main/java/jp/wasabeef/glide/transformations/BitmapTransformation.java: -------------------------------------------------------------------------------- 1 | package jp.wasabeef.glide.transformations; 2 | 3 | /** 4 | * Copyright (C) 2020 Wasabeef 5 | * Copyright 2014 Google, Inc. All rights reserved. 6 | *

7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | *

11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | *

13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | 20 | import android.content.Context; 21 | import android.graphics.Bitmap; 22 | 23 | import androidx.annotation.NonNull; 24 | 25 | import com.bumptech.glide.Glide; 26 | import com.bumptech.glide.load.Transformation; 27 | import com.bumptech.glide.load.engine.Resource; 28 | import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; 29 | import com.bumptech.glide.load.resource.bitmap.BitmapResource; 30 | import com.bumptech.glide.request.target.Target; 31 | import com.bumptech.glide.util.Util; 32 | 33 | import java.security.MessageDigest; 34 | 35 | public abstract class BitmapTransformation implements Transformation { 36 | 37 | @NonNull 38 | @Override 39 | public final Resource transform(@NonNull Context context, @NonNull Resource resource, 40 | int outWidth, int outHeight) { 41 | if (!Util.isValidDimensions(outWidth, outHeight)) { 42 | throw new IllegalArgumentException( 43 | "Cannot apply transformation on width: " + outWidth + " or height: " + outHeight 44 | + " less than or equal to zero and not Target.SIZE_ORIGINAL"); 45 | } 46 | BitmapPool bitmapPool = Glide.get(context).getBitmapPool(); 47 | Bitmap toTransform = resource.get(); 48 | int targetWidth = outWidth == Target.SIZE_ORIGINAL ? toTransform.getWidth() : outWidth; 49 | int targetHeight = outHeight == Target.SIZE_ORIGINAL ? toTransform.getHeight() : outHeight; 50 | Bitmap transformed = transform(context.getApplicationContext(), bitmapPool, toTransform, targetWidth, targetHeight); 51 | 52 | final Resource result; 53 | if (toTransform.equals(transformed)) { 54 | result = resource; 55 | } else { 56 | result = BitmapResource.obtain(transformed, bitmapPool); 57 | } 58 | return result; 59 | } 60 | 61 | void setCanvasBitmapDensity(@NonNull Bitmap toTransform, @NonNull Bitmap canvasBitmap) { 62 | canvasBitmap.setDensity(toTransform.getDensity()); 63 | } 64 | 65 | protected abstract Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool, 66 | @NonNull Bitmap toTransform, int outWidth, int outHeight); 67 | 68 | @Override 69 | public abstract void updateDiskCacheKey(@NonNull MessageDigest messageDigest); 70 | 71 | @Override 72 | public abstract boolean equals(Object o); 73 | 74 | @Override 75 | public abstract int hashCode(); 76 | } 77 | -------------------------------------------------------------------------------- /transformations/src/main/java/jp/wasabeef/glide/transformations/BlurTransformation.java: -------------------------------------------------------------------------------- 1 | package jp.wasabeef.glide.transformations; 2 | 3 | /** 4 | * Copyright (C) 2020 Wasabeef 5 | *

6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *

10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *

12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import android.content.Context; 20 | import android.graphics.Bitmap; 21 | import android.graphics.Canvas; 22 | import android.graphics.Paint; 23 | import android.renderscript.RSRuntimeException; 24 | 25 | import androidx.annotation.NonNull; 26 | 27 | import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; 28 | 29 | import java.security.MessageDigest; 30 | 31 | import jp.wasabeef.glide.transformations.internal.FastBlur; 32 | import jp.wasabeef.glide.transformations.internal.RSBlur; 33 | 34 | public class BlurTransformation extends BitmapTransformation { 35 | 36 | private static final int VERSION = 1; 37 | private static final String ID = 38 | "jp.wasabeef.glide.transformations.BlurTransformation." + VERSION; 39 | 40 | private static final int MAX_RADIUS = 25; 41 | private static final int DEFAULT_DOWN_SAMPLING = 1; 42 | 43 | private final int radius; 44 | private final int sampling; 45 | 46 | public BlurTransformation() { 47 | this(MAX_RADIUS, DEFAULT_DOWN_SAMPLING); 48 | } 49 | 50 | public BlurTransformation(int radius) { 51 | this(radius, DEFAULT_DOWN_SAMPLING); 52 | } 53 | 54 | public BlurTransformation(int radius, int sampling) { 55 | this.radius = radius; 56 | this.sampling = sampling; 57 | } 58 | 59 | @Override 60 | protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool, 61 | @NonNull Bitmap toTransform, int outWidth, int outHeight) { 62 | 63 | int width = toTransform.getWidth(); 64 | int height = toTransform.getHeight(); 65 | int scaledWidth = width / sampling; 66 | int scaledHeight = height / sampling; 67 | 68 | Bitmap bitmap = pool.get(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888); 69 | 70 | setCanvasBitmapDensity(toTransform, bitmap); 71 | 72 | Canvas canvas = new Canvas(bitmap); 73 | canvas.scale(1 / (float) sampling, 1 / (float) sampling); 74 | Paint paint = new Paint(); 75 | paint.setFlags(Paint.FILTER_BITMAP_FLAG); 76 | canvas.drawBitmap(toTransform, 0, 0, paint); 77 | 78 | try { 79 | bitmap = RSBlur.blur(context, bitmap, radius); 80 | } catch (RSRuntimeException e) { 81 | bitmap = FastBlur.blur(bitmap, radius, true); 82 | } 83 | 84 | return bitmap; 85 | } 86 | 87 | @Override 88 | public String toString() { 89 | return "BlurTransformation(radius=" + radius + ", sampling=" + sampling + ")"; 90 | } 91 | 92 | @Override 93 | public boolean equals(Object o) { 94 | return o instanceof BlurTransformation && 95 | ((BlurTransformation) o).radius == radius && 96 | ((BlurTransformation) o).sampling == sampling; 97 | } 98 | 99 | @Override 100 | public int hashCode() { 101 | return ID.hashCode() + radius * 1000 + sampling * 10; 102 | } 103 | 104 | @Override 105 | public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) { 106 | messageDigest.update((ID + radius + sampling).getBytes(CHARSET)); 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /transformations/src/main/java/jp/wasabeef/glide/transformations/ColorFilterTransformation.java: -------------------------------------------------------------------------------- 1 | package jp.wasabeef.glide.transformations; 2 | 3 | /** 4 | * Copyright (C) 2020 Wasabeef 5 | *

6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *

10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *

12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import android.content.Context; 20 | import android.graphics.Bitmap; 21 | import android.graphics.Canvas; 22 | import android.graphics.Paint; 23 | import android.graphics.PorterDuff; 24 | import android.graphics.PorterDuffColorFilter; 25 | 26 | import androidx.annotation.NonNull; 27 | 28 | import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; 29 | 30 | import java.security.MessageDigest; 31 | 32 | public class ColorFilterTransformation extends BitmapTransformation { 33 | 34 | private static final int VERSION = 1; 35 | private static final String ID = 36 | "jp.wasabeef.glide.transformations.ColorFilterTransformation." + VERSION; 37 | 38 | private final int color; 39 | 40 | public ColorFilterTransformation(int color) { 41 | this.color = color; 42 | } 43 | 44 | @Override 45 | protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool, 46 | @NonNull Bitmap toTransform, int outWidth, int outHeight) { 47 | int width = toTransform.getWidth(); 48 | int height = toTransform.getHeight(); 49 | 50 | Bitmap.Config config = 51 | toTransform.getConfig() != null ? toTransform.getConfig() : Bitmap.Config.ARGB_8888; 52 | Bitmap bitmap = pool.get(width, height, config); 53 | 54 | setCanvasBitmapDensity(toTransform, bitmap); 55 | 56 | Canvas canvas = new Canvas(bitmap); 57 | Paint paint = new Paint(); 58 | paint.setAntiAlias(true); 59 | paint.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP)); 60 | canvas.drawBitmap(toTransform, 0, 0, paint); 61 | 62 | return bitmap; 63 | } 64 | 65 | @Override 66 | public String toString() { 67 | return "ColorFilterTransformation(color=" + color + ")"; 68 | } 69 | 70 | @Override 71 | public boolean equals(Object o) { 72 | return o instanceof ColorFilterTransformation && 73 | ((ColorFilterTransformation) o).color == color; 74 | } 75 | 76 | @Override 77 | public int hashCode() { 78 | return ID.hashCode() + color * 10; 79 | } 80 | 81 | @Override 82 | public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) { 83 | messageDigest.update((ID + color).getBytes(CHARSET)); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /transformations/src/main/java/jp/wasabeef/glide/transformations/CropCircleTransformation.java: -------------------------------------------------------------------------------- 1 | package jp.wasabeef.glide.transformations; 2 | 3 | /** 4 | * Copyright (C) 2020 Wasabeef 5 | *

6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *

10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *

12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import android.content.Context; 20 | import android.graphics.Bitmap; 21 | 22 | import androidx.annotation.NonNull; 23 | 24 | import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; 25 | import com.bumptech.glide.load.resource.bitmap.TransformationUtils; 26 | import com.bumptech.glide.request.RequestOptions; 27 | 28 | import java.security.MessageDigest; 29 | 30 | /** 31 | * @deprecated Use {@link RequestOptions#circleCrop()}. 32 | */ 33 | @Deprecated 34 | public class CropCircleTransformation extends BitmapTransformation { 35 | 36 | private static final int VERSION = 1; 37 | private static final String ID = 38 | "jp.wasabeef.glide.transformations.CropCircleTransformation." + VERSION; 39 | 40 | @Override 41 | protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool, 42 | @NonNull Bitmap toTransform, int outWidth, int outHeight) { 43 | return TransformationUtils.circleCrop(pool, toTransform, outWidth, outHeight); 44 | } 45 | 46 | @Override 47 | public String toString() { 48 | return "CropCircleTransformation()"; 49 | } 50 | 51 | @Override 52 | public boolean equals(Object o) { 53 | return o instanceof CropCircleTransformation; 54 | } 55 | 56 | @Override 57 | public int hashCode() { 58 | return ID.hashCode(); 59 | } 60 | 61 | @Override 62 | public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) { 63 | messageDigest.update((ID).getBytes(CHARSET)); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /transformations/src/main/java/jp/wasabeef/glide/transformations/CropCircleWithBorderTransformation.java: -------------------------------------------------------------------------------- 1 | package jp.wasabeef.glide.transformations; 2 | 3 | import android.content.Context; 4 | import android.graphics.Bitmap; 5 | import android.graphics.Canvas; 6 | import android.graphics.Color; 7 | import android.graphics.Paint; 8 | 9 | import androidx.annotation.ColorInt; 10 | import androidx.annotation.NonNull; 11 | 12 | import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; 13 | import com.bumptech.glide.load.resource.bitmap.TransformationUtils; 14 | 15 | import java.security.MessageDigest; 16 | 17 | import jp.wasabeef.glide.transformations.internal.Utils; 18 | 19 | /** 20 | * Copyright (C) 2020 Wasabeef 21 | *

22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | *

26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | *

28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | public class CropCircleWithBorderTransformation extends BitmapTransformation { 36 | 37 | 38 | private static final int VERSION = 1; 39 | private static final String ID = "jp.wasabeef.glide.transformations.CropCircleWithBorderTransformation." + VERSION; 40 | 41 | private final int borderSize; 42 | private final int borderColor; 43 | 44 | 45 | public CropCircleWithBorderTransformation() { 46 | this.borderSize = Utils.toDp(4); 47 | this.borderColor = Color.BLACK; 48 | } 49 | 50 | public CropCircleWithBorderTransformation(int borderSize, @ColorInt int borderColor) { 51 | this.borderSize = borderSize; 52 | this.borderColor = borderColor; 53 | } 54 | 55 | @Override 56 | protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool, 57 | @NonNull Bitmap toTransform, int outWidth, int outHeight) { 58 | 59 | Bitmap bitmap = TransformationUtils.circleCrop(pool, toTransform, outWidth, outHeight); 60 | 61 | setCanvasBitmapDensity(toTransform, bitmap); 62 | 63 | Paint paint = new Paint(); 64 | paint.setColor(borderColor); 65 | paint.setStyle(Paint.Style.STROKE); 66 | paint.setStrokeWidth(borderSize); 67 | paint.setAntiAlias(true); 68 | 69 | Canvas canvas = new Canvas(bitmap); 70 | canvas.drawCircle( 71 | outWidth / 2f, 72 | outHeight / 2f, 73 | Math.max(outWidth, outHeight) / 2f - borderSize / 2f, 74 | paint 75 | ); 76 | 77 | return bitmap; 78 | } 79 | 80 | @Override 81 | public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) { 82 | messageDigest.update((ID + borderSize + borderColor).getBytes(CHARSET)); 83 | } 84 | 85 | @Override 86 | public boolean equals(Object o) { 87 | return o instanceof CropCircleWithBorderTransformation && 88 | ((CropCircleWithBorderTransformation) o).borderSize == borderSize && 89 | ((CropCircleWithBorderTransformation) o).borderColor == borderColor; 90 | } 91 | 92 | @Override 93 | public int hashCode() { 94 | return ID.hashCode() + borderSize * 100 + borderColor + 10; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /transformations/src/main/java/jp/wasabeef/glide/transformations/CropSquareTransformation.java: -------------------------------------------------------------------------------- 1 | package jp.wasabeef.glide.transformations; 2 | 3 | /** 4 | * Copyright (C) 2020 Wasabeef 5 | *

6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *

10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *

12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import android.content.Context; 20 | import android.graphics.Bitmap; 21 | 22 | import androidx.annotation.NonNull; 23 | 24 | import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; 25 | import com.bumptech.glide.load.resource.bitmap.TransformationUtils; 26 | 27 | import java.security.MessageDigest; 28 | 29 | public class CropSquareTransformation extends BitmapTransformation { 30 | 31 | private static final int VERSION = 1; 32 | private static final String ID = 33 | "jp.wasabeef.glide.transformations.CropSquareTransformation." + VERSION; 34 | 35 | private int size; 36 | 37 | @Override 38 | protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool, 39 | @NonNull Bitmap toTransform, int outWidth, int outHeight) { 40 | this.size = Math.max(outWidth, outHeight); 41 | return TransformationUtils.centerCrop(pool, toTransform, size, size); 42 | } 43 | 44 | @Override 45 | public String toString() { 46 | return "CropSquareTransformation(size=" + size + ")"; 47 | } 48 | 49 | @Override 50 | public boolean equals(Object o) { 51 | return o instanceof CropSquareTransformation && ((CropSquareTransformation) o).size == size; 52 | } 53 | 54 | @Override 55 | public int hashCode() { 56 | return ID.hashCode() + size * 10; 57 | } 58 | 59 | @Override 60 | public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) { 61 | messageDigest.update((ID + size).getBytes(CHARSET)); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /transformations/src/main/java/jp/wasabeef/glide/transformations/CropTransformation.java: -------------------------------------------------------------------------------- 1 | package jp.wasabeef.glide.transformations; 2 | 3 | /** 4 | * Copyright (C) 2020 Wasabeef 5 | *

6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *

10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *

12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import android.content.Context; 20 | import android.graphics.Bitmap; 21 | import android.graphics.Canvas; 22 | import android.graphics.RectF; 23 | 24 | import androidx.annotation.NonNull; 25 | 26 | import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; 27 | 28 | import java.security.MessageDigest; 29 | 30 | public class CropTransformation extends BitmapTransformation { 31 | 32 | private static final int VERSION = 1; 33 | private static final String ID = "jp.wasabeef.glide.transformations.CropTransformation." + VERSION; 34 | 35 | public enum CropType { 36 | TOP, 37 | CENTER, 38 | BOTTOM 39 | } 40 | 41 | private int width; 42 | private int height; 43 | 44 | private CropType cropType = CropType.CENTER; 45 | 46 | public CropTransformation(int width, int height) { 47 | this(width, height, CropType.CENTER); 48 | } 49 | 50 | public CropTransformation(int width, int height, CropType cropType) { 51 | this.width = width; 52 | this.height = height; 53 | this.cropType = cropType; 54 | } 55 | 56 | @Override 57 | protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool, 58 | @NonNull Bitmap toTransform, int outWidth, int outHeight) { 59 | 60 | width = width == 0 ? toTransform.getWidth() : width; 61 | height = height == 0 ? toTransform.getHeight() : height; 62 | 63 | Bitmap.Config config = 64 | toTransform.getConfig() != null ? toTransform.getConfig() : Bitmap.Config.ARGB_8888; 65 | Bitmap bitmap = pool.get(width, height, config); 66 | 67 | bitmap.setHasAlpha(true); 68 | 69 | float scaleX = (float) width / toTransform.getWidth(); 70 | float scaleY = (float) height / toTransform.getHeight(); 71 | float scale = Math.max(scaleX, scaleY); 72 | 73 | float scaledWidth = scale * toTransform.getWidth(); 74 | float scaledHeight = scale * toTransform.getHeight(); 75 | float left = (width - scaledWidth) / 2; 76 | float top = getTop(scaledHeight); 77 | RectF targetRect = new RectF(left, top, left + scaledWidth, top + scaledHeight); 78 | 79 | setCanvasBitmapDensity(toTransform, bitmap); 80 | 81 | Canvas canvas = new Canvas(bitmap); 82 | canvas.drawBitmap(toTransform, null, targetRect, null); 83 | 84 | return bitmap; 85 | } 86 | 87 | private float getTop(float scaledHeight) { 88 | switch (cropType) { 89 | case TOP: 90 | return 0; 91 | case CENTER: 92 | return (height - scaledHeight) / 2; 93 | case BOTTOM: 94 | return height - scaledHeight; 95 | default: 96 | return 0; 97 | } 98 | } 99 | 100 | @Override 101 | public String toString() { 102 | return "CropTransformation(width=" + width + ", height=" + height + ", cropType=" + cropType + ")"; 103 | } 104 | 105 | @Override 106 | public boolean equals(Object o) { 107 | return o instanceof CropTransformation && 108 | ((CropTransformation) o).width == width && 109 | ((CropTransformation) o).height == height && 110 | ((CropTransformation) o).cropType == cropType; 111 | } 112 | 113 | @Override 114 | public int hashCode() { 115 | return ID.hashCode() + width * 100000 + height * 1000 + cropType.ordinal() * 10; 116 | } 117 | 118 | @Override 119 | public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) { 120 | messageDigest.update((ID + width + height + cropType).getBytes(CHARSET)); 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /transformations/src/main/java/jp/wasabeef/glide/transformations/GrayscaleTransformation.java: -------------------------------------------------------------------------------- 1 | package jp.wasabeef.glide.transformations; 2 | 3 | /** 4 | * Copyright (C) 2020 Wasabeef 5 | *

6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *

10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *

12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import android.content.Context; 20 | import android.graphics.Bitmap; 21 | import android.graphics.Canvas; 22 | import android.graphics.ColorMatrix; 23 | import android.graphics.ColorMatrixColorFilter; 24 | import android.graphics.Paint; 25 | 26 | import androidx.annotation.NonNull; 27 | 28 | import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; 29 | 30 | import java.security.MessageDigest; 31 | 32 | public class GrayscaleTransformation extends BitmapTransformation { 33 | 34 | private static final int VERSION = 1; 35 | private static final String ID = 36 | "jp.wasabeef.glide.transformations.GrayscaleTransformation." + VERSION; 37 | 38 | @Override 39 | protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool, 40 | @NonNull Bitmap toTransform, int outWidth, int outHeight) { 41 | int width = toTransform.getWidth(); 42 | int height = toTransform.getHeight(); 43 | 44 | Bitmap.Config config = 45 | toTransform.getConfig() != null ? toTransform.getConfig() : Bitmap.Config.ARGB_8888; 46 | Bitmap bitmap = pool.get(width, height, config); 47 | 48 | setCanvasBitmapDensity(toTransform, bitmap); 49 | 50 | Canvas canvas = new Canvas(bitmap); 51 | ColorMatrix saturation = new ColorMatrix(); 52 | saturation.setSaturation(0f); 53 | Paint paint = new Paint(); 54 | paint.setColorFilter(new ColorMatrixColorFilter(saturation)); 55 | canvas.drawBitmap(toTransform, 0, 0, paint); 56 | 57 | return bitmap; 58 | } 59 | 60 | @Override 61 | public String toString() { 62 | return "GrayscaleTransformation()"; 63 | } 64 | 65 | @Override 66 | public boolean equals(Object o) { 67 | return o instanceof GrayscaleTransformation; 68 | } 69 | 70 | @Override 71 | public int hashCode() { 72 | return ID.hashCode(); 73 | } 74 | 75 | @Override 76 | public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) { 77 | messageDigest.update((ID).getBytes(CHARSET)); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /transformations/src/main/java/jp/wasabeef/glide/transformations/MaskTransformation.java: -------------------------------------------------------------------------------- 1 | package jp.wasabeef.glide.transformations; 2 | 3 | /** 4 | * Copyright (C) 2020 Wasabeef 5 | *

6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *

10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *

12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import android.content.Context; 20 | import android.graphics.Bitmap; 21 | import android.graphics.Canvas; 22 | import android.graphics.Paint; 23 | import android.graphics.PorterDuff; 24 | import android.graphics.PorterDuffXfermode; 25 | import android.graphics.drawable.Drawable; 26 | 27 | import androidx.annotation.NonNull; 28 | 29 | import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; 30 | 31 | import java.security.MessageDigest; 32 | 33 | public class MaskTransformation extends BitmapTransformation { 34 | 35 | private static final int VERSION = 1; 36 | private static final String ID = 37 | "jp.wasabeef.glide.transformations.MaskTransformation." + VERSION; 38 | 39 | private static final Paint paint = new Paint(); 40 | private final int maskId; 41 | 42 | static { 43 | paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); 44 | } 45 | 46 | /** 47 | * @param maskId If you change the mask file, please also rename the mask file, or Glide will get 48 | * the cache with the old mask. Because key() return the same values if using the 49 | * same make file name. If you have a good idea please tell us, thanks. 50 | */ 51 | public MaskTransformation(int maskId) { 52 | this.maskId = maskId; 53 | } 54 | 55 | @Override 56 | protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool, 57 | @NonNull Bitmap toTransform, int outWidth, int outHeight) { 58 | int width = toTransform.getWidth(); 59 | int height = toTransform.getHeight(); 60 | 61 | Bitmap bitmap = pool.get(width, height, Bitmap.Config.ARGB_8888); 62 | bitmap.setHasAlpha(true); 63 | 64 | Drawable mask = context.getDrawable(maskId); 65 | 66 | setCanvasBitmapDensity(toTransform, bitmap); 67 | 68 | Canvas canvas = new Canvas(bitmap); 69 | mask.setBounds(0, 0, width, height); 70 | mask.draw(canvas); 71 | canvas.drawBitmap(toTransform, 0, 0, paint); 72 | 73 | return bitmap; 74 | } 75 | 76 | @Override 77 | public String toString() { 78 | return "MaskTransformation(maskId=" + maskId + ")"; 79 | } 80 | 81 | @Override 82 | public boolean equals(Object o) { 83 | return o instanceof MaskTransformation && 84 | ((MaskTransformation) o).maskId == maskId; 85 | } 86 | 87 | @Override 88 | public int hashCode() { 89 | return ID.hashCode() + maskId * 10; 90 | } 91 | 92 | @Override 93 | public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) { 94 | messageDigest.update((ID + maskId).getBytes(CHARSET)); 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /transformations/src/main/java/jp/wasabeef/glide/transformations/RoundedCornersTransformation.java: -------------------------------------------------------------------------------- 1 | package jp.wasabeef.glide.transformations; 2 | 3 | /** 4 | * Copyright (C) 2020 Wasabeef 5 | *

6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *

10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *

12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import android.content.Context; 20 | import android.graphics.Bitmap; 21 | import android.graphics.BitmapShader; 22 | import android.graphics.Canvas; 23 | import android.graphics.Paint; 24 | import android.graphics.RectF; 25 | import android.graphics.Shader; 26 | 27 | import androidx.annotation.NonNull; 28 | 29 | import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; 30 | 31 | import java.security.MessageDigest; 32 | 33 | public class RoundedCornersTransformation extends BitmapTransformation { 34 | 35 | private static final int VERSION = 1; 36 | private static final String ID = "jp.wasabeef.glide.transformations.RoundedCornersTransformation." + VERSION; 37 | 38 | public enum CornerType { 39 | ALL, 40 | TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT, 41 | TOP, BOTTOM, LEFT, RIGHT, 42 | OTHER_TOP_LEFT, OTHER_TOP_RIGHT, OTHER_BOTTOM_LEFT, OTHER_BOTTOM_RIGHT, 43 | DIAGONAL_FROM_TOP_LEFT, DIAGONAL_FROM_TOP_RIGHT 44 | } 45 | 46 | private final int radius; 47 | private final int diameter; 48 | private final int margin; 49 | private final CornerType cornerType; 50 | 51 | public RoundedCornersTransformation(int radius, int margin) { 52 | this(radius, margin, CornerType.ALL); 53 | } 54 | 55 | public RoundedCornersTransformation(int radius, int margin, CornerType cornerType) { 56 | this.radius = radius; 57 | this.diameter = this.radius * 2; 58 | this.margin = margin; 59 | this.cornerType = cornerType; 60 | } 61 | 62 | @Override 63 | protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool, 64 | @NonNull Bitmap toTransform, int outWidth, int outHeight) { 65 | int width = toTransform.getWidth(); 66 | int height = toTransform.getHeight(); 67 | 68 | Bitmap bitmap = pool.get(width, height, Bitmap.Config.ARGB_8888); 69 | bitmap.setHasAlpha(true); 70 | 71 | setCanvasBitmapDensity(toTransform, bitmap); 72 | 73 | Canvas canvas = new Canvas(bitmap); 74 | Paint paint = new Paint(); 75 | paint.setAntiAlias(true); 76 | paint.setShader(new BitmapShader(toTransform, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP)); 77 | drawRoundRect(canvas, paint, width, height); 78 | return bitmap; 79 | } 80 | 81 | private void drawRoundRect(Canvas canvas, Paint paint, float width, float height) { 82 | float right = width - margin; 83 | float bottom = height - margin; 84 | 85 | switch (cornerType) { 86 | case ALL: 87 | canvas.drawRoundRect(new RectF(margin, margin, right, bottom), radius, radius, paint); 88 | break; 89 | case TOP_LEFT: 90 | drawTopLeftRoundRect(canvas, paint, right, bottom); 91 | break; 92 | case TOP_RIGHT: 93 | drawTopRightRoundRect(canvas, paint, right, bottom); 94 | break; 95 | case BOTTOM_LEFT: 96 | drawBottomLeftRoundRect(canvas, paint, right, bottom); 97 | break; 98 | case BOTTOM_RIGHT: 99 | drawBottomRightRoundRect(canvas, paint, right, bottom); 100 | break; 101 | case TOP: 102 | drawTopRoundRect(canvas, paint, right, bottom); 103 | break; 104 | case BOTTOM: 105 | drawBottomRoundRect(canvas, paint, right, bottom); 106 | break; 107 | case LEFT: 108 | drawLeftRoundRect(canvas, paint, right, bottom); 109 | break; 110 | case RIGHT: 111 | drawRightRoundRect(canvas, paint, right, bottom); 112 | break; 113 | case OTHER_TOP_LEFT: 114 | drawOtherTopLeftRoundRect(canvas, paint, right, bottom); 115 | break; 116 | case OTHER_TOP_RIGHT: 117 | drawOtherTopRightRoundRect(canvas, paint, right, bottom); 118 | break; 119 | case OTHER_BOTTOM_LEFT: 120 | drawOtherBottomLeftRoundRect(canvas, paint, right, bottom); 121 | break; 122 | case OTHER_BOTTOM_RIGHT: 123 | drawOtherBottomRightRoundRect(canvas, paint, right, bottom); 124 | break; 125 | case DIAGONAL_FROM_TOP_LEFT: 126 | drawDiagonalFromTopLeftRoundRect(canvas, paint, right, bottom); 127 | break; 128 | case DIAGONAL_FROM_TOP_RIGHT: 129 | drawDiagonalFromTopRightRoundRect(canvas, paint, right, bottom); 130 | break; 131 | default: 132 | canvas.drawRoundRect(new RectF(margin, margin, right, bottom), radius, radius, paint); 133 | break; 134 | } 135 | } 136 | 137 | private void drawTopLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) { 138 | canvas.drawRoundRect(new RectF(margin, margin, margin + diameter, margin + diameter), radius, 139 | radius, paint); 140 | canvas.drawRect(new RectF(margin, margin + radius, margin + radius, bottom), paint); 141 | canvas.drawRect(new RectF(margin + radius, margin, right, bottom), paint); 142 | } 143 | 144 | private void drawTopRightRoundRect(Canvas canvas, Paint paint, float right, float bottom) { 145 | canvas.drawRoundRect(new RectF(right - diameter, margin, right, margin + diameter), radius, 146 | radius, paint); 147 | canvas.drawRect(new RectF(margin, margin, right - radius, bottom), paint); 148 | canvas.drawRect(new RectF(right - radius, margin + radius, right, bottom), paint); 149 | } 150 | 151 | private void drawBottomLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) { 152 | canvas.drawRoundRect(new RectF(margin, bottom - diameter, margin + diameter, bottom), radius, 153 | radius, paint); 154 | canvas.drawRect(new RectF(margin, margin, margin + diameter, bottom - radius), paint); 155 | canvas.drawRect(new RectF(margin + radius, margin, right, bottom), paint); 156 | } 157 | 158 | private void drawBottomRightRoundRect(Canvas canvas, Paint paint, float right, float bottom) { 159 | canvas.drawRoundRect(new RectF(right - diameter, bottom - diameter, right, bottom), radius, 160 | radius, paint); 161 | canvas.drawRect(new RectF(margin, margin, right - radius, bottom), paint); 162 | canvas.drawRect(new RectF(right - radius, margin, right, bottom - radius), paint); 163 | } 164 | 165 | private void drawTopRoundRect(Canvas canvas, Paint paint, float right, float bottom) { 166 | canvas.drawRoundRect(new RectF(margin, margin, right, margin + diameter), radius, radius, 167 | paint); 168 | canvas.drawRect(new RectF(margin, margin + radius, right, bottom), paint); 169 | } 170 | 171 | private void drawBottomRoundRect(Canvas canvas, Paint paint, float right, float bottom) { 172 | canvas.drawRoundRect(new RectF(margin, bottom - diameter, right, bottom), radius, radius, 173 | paint); 174 | canvas.drawRect(new RectF(margin, margin, right, bottom - radius), paint); 175 | } 176 | 177 | private void drawLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) { 178 | canvas.drawRoundRect(new RectF(margin, margin, margin + diameter, bottom), radius, radius, 179 | paint); 180 | canvas.drawRect(new RectF(margin + radius, margin, right, bottom), paint); 181 | } 182 | 183 | private void drawRightRoundRect(Canvas canvas, Paint paint, float right, float bottom) { 184 | canvas.drawRoundRect(new RectF(right - diameter, margin, right, bottom), radius, radius, paint); 185 | canvas.drawRect(new RectF(margin, margin, right - radius, bottom), paint); 186 | } 187 | 188 | private void drawOtherTopLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) { 189 | canvas.drawRoundRect(new RectF(margin, bottom - diameter, right, bottom), radius, radius, 190 | paint); 191 | canvas.drawRoundRect(new RectF(right - diameter, margin, right, bottom), radius, radius, paint); 192 | canvas.drawRect(new RectF(margin, margin, right - radius, bottom - radius), paint); 193 | } 194 | 195 | private void drawOtherTopRightRoundRect(Canvas canvas, Paint paint, float right, float bottom) { 196 | canvas.drawRoundRect(new RectF(margin, margin, margin + diameter, bottom), radius, radius, 197 | paint); 198 | canvas.drawRoundRect(new RectF(margin, bottom - diameter, right, bottom), radius, radius, 199 | paint); 200 | canvas.drawRect(new RectF(margin + radius, margin, right, bottom - radius), paint); 201 | } 202 | 203 | private void drawOtherBottomLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) { 204 | canvas.drawRoundRect(new RectF(margin, margin, right, margin + diameter), radius, radius, 205 | paint); 206 | canvas.drawRoundRect(new RectF(right - diameter, margin, right, bottom), radius, radius, paint); 207 | canvas.drawRect(new RectF(margin, margin + radius, right - radius, bottom), paint); 208 | } 209 | 210 | private void drawOtherBottomRightRoundRect(Canvas canvas, Paint paint, float right, 211 | float bottom) { 212 | canvas.drawRoundRect(new RectF(margin, margin, right, margin + diameter), radius, radius, 213 | paint); 214 | canvas.drawRoundRect(new RectF(margin, margin, margin + diameter, bottom), radius, radius, 215 | paint); 216 | canvas.drawRect(new RectF(margin + radius, margin + radius, right, bottom), paint); 217 | } 218 | 219 | private void drawDiagonalFromTopLeftRoundRect(Canvas canvas, Paint paint, float right, 220 | float bottom) { 221 | canvas.drawRoundRect(new RectF(margin, margin, margin + diameter, margin + diameter), radius, 222 | radius, paint); 223 | canvas.drawRoundRect(new RectF(right - diameter, bottom - diameter, right, bottom), radius, 224 | radius, paint); 225 | canvas.drawRect(new RectF(margin, margin + radius, right - radius, bottom), paint); 226 | canvas.drawRect(new RectF(margin + radius, margin, right, bottom - radius), paint); 227 | } 228 | 229 | private void drawDiagonalFromTopRightRoundRect(Canvas canvas, Paint paint, float right, 230 | float bottom) { 231 | canvas.drawRoundRect(new RectF(right - diameter, margin, right, margin + diameter), radius, 232 | radius, paint); 233 | canvas.drawRoundRect(new RectF(margin, bottom - diameter, margin + diameter, bottom), radius, 234 | radius, paint); 235 | canvas.drawRect(new RectF(margin, margin, right - radius, bottom - radius), paint); 236 | canvas.drawRect(new RectF(margin + radius, margin + radius, right, bottom), paint); 237 | } 238 | 239 | @Override 240 | public String toString() { 241 | return "RoundedTransformation(radius=" + radius + ", margin=" + margin + ", diameter=" 242 | + diameter + ", cornerType=" + cornerType.name() + ")"; 243 | } 244 | 245 | @Override 246 | public boolean equals(Object o) { 247 | return o instanceof RoundedCornersTransformation && 248 | ((RoundedCornersTransformation) o).radius == radius && 249 | ((RoundedCornersTransformation) o).diameter == diameter && 250 | ((RoundedCornersTransformation) o).margin == margin && 251 | ((RoundedCornersTransformation) o).cornerType == cornerType; 252 | } 253 | 254 | @Override 255 | public int hashCode() { 256 | return ID.hashCode() + radius * 10000 + diameter * 1000 + margin * 100 + cornerType.ordinal() * 10; 257 | } 258 | 259 | @Override 260 | public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) { 261 | messageDigest.update((ID + radius + diameter + margin + cornerType).getBytes(CHARSET)); 262 | } 263 | } 264 | -------------------------------------------------------------------------------- /transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/BrightnessFilterTransformation.java: -------------------------------------------------------------------------------- 1 | package jp.wasabeef.glide.transformations.gpu; 2 | 3 | /** 4 | * Copyright (C) 2020 Wasabeef 5 | *

6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *

10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *

12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import androidx.annotation.NonNull; 20 | 21 | import java.security.MessageDigest; 22 | 23 | import jp.co.cyberagent.android.gpuimage.filter.GPUImageBrightnessFilter; 24 | 25 | /** 26 | * brightness value ranges from -1.0 to 1.0, with 0.0 as the normal level 27 | */ 28 | public class BrightnessFilterTransformation extends GPUFilterTransformation { 29 | 30 | private static final int VERSION = 1; 31 | private static final String ID = 32 | "jp.wasabeef.glide.transformations.gpu.BrightnessFilterTransformation." + VERSION; 33 | 34 | private final float brightness; 35 | 36 | public BrightnessFilterTransformation() { 37 | this(0.0f); 38 | } 39 | 40 | public BrightnessFilterTransformation(float brightness) { 41 | super(new GPUImageBrightnessFilter()); 42 | this.brightness = brightness; 43 | GPUImageBrightnessFilter filter = getFilter(); 44 | filter.setBrightness(this.brightness); 45 | } 46 | 47 | @Override 48 | public String toString() { 49 | return "BrightnessFilterTransformation(brightness=" + brightness + ")"; 50 | } 51 | 52 | @Override 53 | public boolean equals(Object o) { 54 | return o instanceof BrightnessFilterTransformation && 55 | ((BrightnessFilterTransformation) o).brightness == brightness; 56 | } 57 | 58 | @Override 59 | public int hashCode() { 60 | return ID.hashCode() + (int) ((brightness + 1.0f) * 10); 61 | } 62 | 63 | @Override 64 | public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) { 65 | messageDigest.update((ID + brightness).getBytes(CHARSET)); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/ContrastFilterTransformation.java: -------------------------------------------------------------------------------- 1 | package jp.wasabeef.glide.transformations.gpu; 2 | 3 | /** 4 | * Copyright (C) 2020 Wasabeef 5 | *

6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *

10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *

12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import androidx.annotation.NonNull; 20 | 21 | import java.security.MessageDigest; 22 | 23 | import jp.co.cyberagent.android.gpuimage.filter.GPUImageContrastFilter; 24 | 25 | /** 26 | * contrast value ranges from 0.0 to 4.0, with 1.0 as the normal level 27 | */ 28 | public class ContrastFilterTransformation extends GPUFilterTransformation { 29 | 30 | private static final int VERSION = 1; 31 | private static final String ID = 32 | "jp.wasabeef.glide.transformations.gpu.ContrastFilterTransformation." + VERSION; 33 | 34 | private final float contrast; 35 | 36 | public ContrastFilterTransformation() { 37 | this(1.0f); 38 | } 39 | 40 | public ContrastFilterTransformation(float contrast) { 41 | super(new GPUImageContrastFilter()); 42 | this.contrast = contrast; 43 | GPUImageContrastFilter filter = getFilter(); 44 | filter.setContrast(this.contrast); 45 | } 46 | 47 | @Override 48 | public String toString() { 49 | return "ContrastFilterTransformation(contrast=" + contrast + ")"; 50 | } 51 | 52 | @Override 53 | public boolean equals(Object o) { 54 | return o instanceof ContrastFilterTransformation; 55 | } 56 | 57 | @Override 58 | public int hashCode() { 59 | return ID.hashCode() + (int) (contrast * 10); 60 | } 61 | 62 | @Override 63 | public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) { 64 | messageDigest.update((ID + contrast).getBytes(CHARSET)); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/GPUFilterTransformation.java: -------------------------------------------------------------------------------- 1 | package jp.wasabeef.glide.transformations.gpu; 2 | 3 | /** 4 | * Copyright (C) 2020 Wasabeef 5 | *

6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *

10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *

12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import android.content.Context; 20 | import android.graphics.Bitmap; 21 | 22 | import androidx.annotation.NonNull; 23 | 24 | import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; 25 | 26 | import java.security.MessageDigest; 27 | 28 | import jp.co.cyberagent.android.gpuimage.GPUImage; 29 | import jp.co.cyberagent.android.gpuimage.filter.GPUImageFilter; 30 | import jp.wasabeef.glide.transformations.BitmapTransformation; 31 | 32 | public class GPUFilterTransformation extends BitmapTransformation { 33 | 34 | private static final int VERSION = 1; 35 | private static final String ID = 36 | "jp.wasabeef.glide.transformations.gpu.GPUFilterTransformation." + VERSION; 37 | private static final byte[] ID_BYTES = ID.getBytes(CHARSET); 38 | 39 | private final GPUImageFilter gpuImageFilter; 40 | 41 | public GPUFilterTransformation(GPUImageFilter filter) { 42 | this.gpuImageFilter = filter; 43 | } 44 | 45 | @Override 46 | protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool, 47 | @NonNull Bitmap toTransform, int outWidth, int outHeight) { 48 | GPUImage gpuImage = new GPUImage(context); 49 | gpuImage.setImage(toTransform); 50 | gpuImage.setFilter(gpuImageFilter); 51 | 52 | return gpuImage.getBitmapWithFilterApplied(); 53 | } 54 | 55 | @Override 56 | public String toString() { 57 | return getClass().getSimpleName(); 58 | } 59 | 60 | @SuppressWarnings("unchecked") 61 | public T getFilter() { 62 | return (T) gpuImageFilter; 63 | } 64 | 65 | @Override 66 | public boolean equals(Object o) { 67 | return o instanceof GPUFilterTransformation; 68 | } 69 | 70 | @Override 71 | public int hashCode() { 72 | return ID.hashCode(); 73 | } 74 | 75 | @Override 76 | public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) { 77 | messageDigest.update(ID_BYTES); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/InvertFilterTransformation.java: -------------------------------------------------------------------------------- 1 | package jp.wasabeef.glide.transformations.gpu; 2 | 3 | /** 4 | * Copyright (C) 2020 Wasabeef 5 | *

6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *

10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *

12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import androidx.annotation.NonNull; 20 | 21 | import java.security.MessageDigest; 22 | 23 | import jp.co.cyberagent.android.gpuimage.filter.GPUImageColorInvertFilter; 24 | 25 | /** 26 | * Invert all the colors in the image. 27 | */ 28 | public class InvertFilterTransformation extends GPUFilterTransformation { 29 | 30 | private static final int VERSION = 1; 31 | private static final String ID = 32 | "jp.wasabeef.glide.transformations.gpu.InvertFilterTransformation." + VERSION; 33 | 34 | public InvertFilterTransformation() { 35 | super(new GPUImageColorInvertFilter()); 36 | } 37 | 38 | @Override 39 | public String toString() { 40 | return "InvertFilterTransformation()"; 41 | } 42 | 43 | @Override 44 | public boolean equals(Object o) { 45 | return o instanceof InvertFilterTransformation; 46 | } 47 | 48 | @Override 49 | public int hashCode() { 50 | return ID.hashCode(); 51 | } 52 | 53 | @Override 54 | public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) { 55 | messageDigest.update((ID).getBytes(CHARSET)); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/KuwaharaFilterTransformation.java: -------------------------------------------------------------------------------- 1 | package jp.wasabeef.glide.transformations.gpu; 2 | 3 | /** 4 | * Copyright (C) 2020 Wasabeef 5 | *

6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *

10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *

12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import androidx.annotation.NonNull; 20 | 21 | import java.security.MessageDigest; 22 | 23 | import jp.co.cyberagent.android.gpuimage.filter.GPUImageKuwaharaFilter; 24 | 25 | /** 26 | * Kuwahara all the colors in the image. 27 | *

28 | * The radius to sample from when creating the brush-stroke effect, with a default of 25. 29 | * The larger the radius, the slower the filter. 30 | */ 31 | public class KuwaharaFilterTransformation extends GPUFilterTransformation { 32 | 33 | private static final int VERSION = 1; 34 | private static final String ID = 35 | "jp.wasabeef.glide.transformations.gpu.KuwaharaFilterTransformation." + VERSION; 36 | 37 | private final int radius; 38 | 39 | public KuwaharaFilterTransformation() { 40 | this(25); 41 | } 42 | 43 | public KuwaharaFilterTransformation(int radius) { 44 | super(new GPUImageKuwaharaFilter()); 45 | this.radius = radius; 46 | GPUImageKuwaharaFilter filter = getFilter(); 47 | filter.setRadius(this.radius); 48 | } 49 | 50 | @Override 51 | public String toString() { 52 | return "KuwaharaFilterTransformation(radius=" + radius + ")"; 53 | } 54 | 55 | @Override 56 | public boolean equals(Object o) { 57 | return o instanceof KuwaharaFilterTransformation; 58 | } 59 | 60 | @Override 61 | public int hashCode() { 62 | return ID.hashCode() + radius * 10; 63 | } 64 | 65 | @Override 66 | public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) { 67 | messageDigest.update((ID + radius).getBytes(CHARSET)); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/PixelationFilterTransformation.java: -------------------------------------------------------------------------------- 1 | package jp.wasabeef.glide.transformations.gpu; 2 | 3 | /** 4 | * Copyright (C) 2020 Wasabeef 5 | *

6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *

10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *

12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import androidx.annotation.NonNull; 20 | 21 | import java.security.MessageDigest; 22 | 23 | import jp.co.cyberagent.android.gpuimage.filter.GPUImagePixelationFilter; 24 | 25 | /** 26 | * Applies a Pixelation effect to the image. 27 | *

28 | * The pixel with a default of 10.0. 29 | */ 30 | public class PixelationFilterTransformation extends GPUFilterTransformation { 31 | 32 | private static final int VERSION = 1; 33 | private static final String ID = 34 | "jp.wasabeef.glide.transformations.gpu.PixelationFilterTransformation." + VERSION; 35 | 36 | private final float pixel; 37 | 38 | public PixelationFilterTransformation() { 39 | this(10f); 40 | } 41 | 42 | public PixelationFilterTransformation(float pixel) { 43 | super(new GPUImagePixelationFilter()); 44 | this.pixel = pixel; 45 | GPUImagePixelationFilter filter = getFilter(); 46 | filter.setPixel(this.pixel); 47 | } 48 | 49 | @Override 50 | public String toString() { 51 | return "PixelationFilterTransformation(pixel=" + pixel + ")"; 52 | } 53 | 54 | @Override 55 | public boolean equals(Object o) { 56 | return o instanceof PixelationFilterTransformation; 57 | } 58 | 59 | @Override 60 | public int hashCode() { 61 | return ID.hashCode() + (int) (pixel * 10); 62 | } 63 | 64 | @Override 65 | public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) { 66 | messageDigest.update((ID + pixel).getBytes(CHARSET)); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/SepiaFilterTransformation.java: -------------------------------------------------------------------------------- 1 | package jp.wasabeef.glide.transformations.gpu; 2 | 3 | /** 4 | * Copyright (C) 2020 Wasabeef 5 | *

6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *

10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *

12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import androidx.annotation.NonNull; 20 | 21 | import java.security.MessageDigest; 22 | 23 | import jp.co.cyberagent.android.gpuimage.filter.GPUImageSepiaToneFilter; 24 | 25 | /** 26 | * Applies a simple sepia effect. 27 | *

28 | * The intensity with a default of 1.0. 29 | */ 30 | public class SepiaFilterTransformation extends GPUFilterTransformation { 31 | 32 | private static final int VERSION = 1; 33 | private static final String ID = 34 | "jp.wasabeef.glide.transformations.gpu.SepiaFilterTransformation." + VERSION; 35 | 36 | private final float intensity; 37 | 38 | public SepiaFilterTransformation() { 39 | this(1.0f); 40 | } 41 | 42 | public SepiaFilterTransformation(float intensity) { 43 | super(new GPUImageSepiaToneFilter()); 44 | this.intensity = intensity; 45 | GPUImageSepiaToneFilter filter = getFilter(); 46 | filter.setIntensity(this.intensity); 47 | } 48 | 49 | @Override 50 | public String toString() { 51 | return "SepiaFilterTransformation(intensity=" + intensity + ")"; 52 | } 53 | 54 | @Override 55 | public boolean equals(Object o) { 56 | return o instanceof SepiaFilterTransformation; 57 | } 58 | 59 | @Override 60 | public int hashCode() { 61 | return ID.hashCode() + (int) (intensity * 10); 62 | } 63 | 64 | @Override 65 | public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) { 66 | messageDigest.update((ID + intensity).getBytes(CHARSET)); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/SketchFilterTransformation.java: -------------------------------------------------------------------------------- 1 | package jp.wasabeef.glide.transformations.gpu; 2 | 3 | /** 4 | * Copyright (C) 2020 Wasabeef 5 | *

6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *

10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *

12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import androidx.annotation.NonNull; 20 | 21 | import java.security.MessageDigest; 22 | 23 | import jp.co.cyberagent.android.gpuimage.filter.GPUImageSketchFilter; 24 | 25 | public class SketchFilterTransformation extends GPUFilterTransformation { 26 | 27 | private static final int VERSION = 1; 28 | private static final String ID = 29 | "jp.wasabeef.glide.transformations.gpu.SketchFilterTransformation." + VERSION; 30 | 31 | public SketchFilterTransformation() { 32 | super(new GPUImageSketchFilter()); 33 | } 34 | 35 | @Override 36 | public String toString() { 37 | return "SketchFilterTransformation()"; 38 | } 39 | 40 | @Override 41 | public boolean equals(Object o) { 42 | return o instanceof SketchFilterTransformation; 43 | } 44 | 45 | @Override 46 | public int hashCode() { 47 | return ID.hashCode(); 48 | } 49 | 50 | @Override 51 | public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) { 52 | messageDigest.update((ID).getBytes(CHARSET)); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/SwirlFilterTransformation.java: -------------------------------------------------------------------------------- 1 | package jp.wasabeef.glide.transformations.gpu; 2 | 3 | /** 4 | * Copyright (C) 2020 Wasabeef 5 | *

6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *

10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *

12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import android.graphics.PointF; 20 | 21 | import androidx.annotation.NonNull; 22 | 23 | import java.security.MessageDigest; 24 | 25 | import jp.co.cyberagent.android.gpuimage.filter.GPUImageSwirlFilter; 26 | 27 | /** 28 | * Creates a swirl distortion on the image. 29 | */ 30 | public class SwirlFilterTransformation extends GPUFilterTransformation { 31 | 32 | private static final int VERSION = 1; 33 | private static final String ID = 34 | "jp.wasabeef.glide.transformations.gpu.SwirlFilterTransformation." + VERSION; 35 | 36 | private final float radius; 37 | private final float angle; 38 | private final PointF center; 39 | 40 | public SwirlFilterTransformation() { 41 | this(.5f, 1.0f, new PointF(0.5f, 0.5f)); 42 | } 43 | 44 | /** 45 | * @param radius from 0.0 to 1.0, default 0.5 46 | * @param angle minimum 0.0, default 1.0 47 | * @param center default (0.5, 0.5) 48 | */ 49 | public SwirlFilterTransformation(float radius, float angle, PointF center) { 50 | super(new GPUImageSwirlFilter()); 51 | this.radius = radius; 52 | this.angle = angle; 53 | this.center = center; 54 | GPUImageSwirlFilter filter = getFilter(); 55 | filter.setRadius(this.radius); 56 | filter.setAngle(this.angle); 57 | filter.setCenter(this.center); 58 | } 59 | 60 | @Override 61 | public String toString() { 62 | return "SwirlFilterTransformation(radius=" + radius + ",angle=" + angle + ",center=" 63 | + center.toString() + ")"; 64 | } 65 | 66 | @Override 67 | public boolean equals(Object o) { 68 | return o instanceof SwirlFilterTransformation && 69 | ((SwirlFilterTransformation) o).radius == radius && 70 | ((SwirlFilterTransformation) o).angle == radius && 71 | ((SwirlFilterTransformation) o).center.equals(center.x, center.y); 72 | } 73 | 74 | @Override 75 | public int hashCode() { 76 | return ID.hashCode() + (int) (radius * 1000) + (int) (angle * 10) + center.hashCode(); 77 | } 78 | 79 | @Override 80 | public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) { 81 | messageDigest.update((ID + radius + angle + center.hashCode()).getBytes(CHARSET)); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/ToonFilterTransformation.java: -------------------------------------------------------------------------------- 1 | package jp.wasabeef.glide.transformations.gpu; 2 | 3 | /** 4 | * Copyright (C) 2020 Wasabeef 5 | *

6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *

10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *

12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import androidx.annotation.NonNull; 20 | 21 | import java.security.MessageDigest; 22 | 23 | import jp.co.cyberagent.android.gpuimage.filter.GPUImageToonFilter; 24 | 25 | /** 26 | * The threshold at which to apply the edges, default of 0.2. 27 | * The levels of quantization for the posterization of colors within the scene, 28 | * with a default of 10.0. 29 | */ 30 | public class ToonFilterTransformation extends GPUFilterTransformation { 31 | 32 | private static final int VERSION = 1; 33 | private static final String ID = 34 | "jp.wasabeef.glide.transformations.gpu.ToonFilterTransformation." + VERSION; 35 | 36 | private final float threshold; 37 | private final float quantizationLevels; 38 | 39 | public ToonFilterTransformation() { 40 | this(.2f, 10.0f); 41 | } 42 | 43 | public ToonFilterTransformation(float threshold, float quantizationLevels) { 44 | super(new GPUImageToonFilter()); 45 | this.threshold = threshold; 46 | this.quantizationLevels = quantizationLevels; 47 | GPUImageToonFilter filter = getFilter(); 48 | filter.setThreshold(this.threshold); 49 | filter.setQuantizationLevels(this.quantizationLevels); 50 | } 51 | 52 | @Override 53 | public String toString() { 54 | return "ToonFilterTransformation(threshold=" + threshold + ",quantizationLevels=" 55 | + quantizationLevels + ")"; 56 | } 57 | 58 | @Override 59 | public boolean equals(Object o) { 60 | return o instanceof ToonFilterTransformation && 61 | ((ToonFilterTransformation) o).threshold == threshold && 62 | ((ToonFilterTransformation) o).quantizationLevels == quantizationLevels; 63 | } 64 | 65 | @Override 66 | public int hashCode() { 67 | return ID.hashCode() + (int) (threshold * 1000) + (int) (quantizationLevels * 10); 68 | } 69 | 70 | @Override 71 | public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) { 72 | messageDigest.update((ID + threshold + quantizationLevels).getBytes(CHARSET)); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/VignetteFilterTransformation.java: -------------------------------------------------------------------------------- 1 | package jp.wasabeef.glide.transformations.gpu; 2 | 3 | /** 4 | * Copyright (C) 2020 Wasabeef 5 | *

6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *

10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *

12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import android.graphics.PointF; 20 | 21 | import androidx.annotation.NonNull; 22 | 23 | import java.security.MessageDigest; 24 | import java.util.Arrays; 25 | 26 | import jp.co.cyberagent.android.gpuimage.filter.GPUImageVignetteFilter; 27 | 28 | /** 29 | * Performs a vignetting effect, fading out the image at the edges 30 | * The directional intensity of the vignetting, 31 | * with a default of x = 0.5, y = 0.5, start = 0, end = 0.75 32 | */ 33 | public class VignetteFilterTransformation extends GPUFilterTransformation { 34 | 35 | private static final int VERSION = 1; 36 | private static final String ID = 37 | "jp.wasabeef.glide.transformations.gpu.VignetteFilterTransformation." + VERSION; 38 | 39 | private final PointF center; 40 | private final float[] vignetteColor; 41 | private final float vignetteStart; 42 | private final float vignetteEnd; 43 | 44 | public VignetteFilterTransformation() { 45 | this(new PointF(0.5f, 0.5f), new float[]{0.0f, 0.0f, 0.0f}, 0.0f, 0.75f); 46 | } 47 | 48 | public VignetteFilterTransformation(PointF center, float[] color, float start, float end) { 49 | super(new GPUImageVignetteFilter()); 50 | this.center = center; 51 | vignetteColor = color; 52 | vignetteStart = start; 53 | vignetteEnd = end; 54 | GPUImageVignetteFilter filter = getFilter(); 55 | filter.setVignetteCenter(this.center); 56 | filter.setVignetteColor(vignetteColor); 57 | filter.setVignetteStart(vignetteStart); 58 | filter.setVignetteEnd(vignetteEnd); 59 | } 60 | 61 | @Override 62 | public String toString() { 63 | return "VignetteFilterTransformation(center=" + center.toString() + ",color=" + Arrays.toString( 64 | vignetteColor) + ",start=" + vignetteStart + ",end=" + vignetteEnd + ")"; 65 | } 66 | 67 | @Override 68 | public boolean equals(Object o) { 69 | return o instanceof VignetteFilterTransformation && 70 | ((VignetteFilterTransformation) o).center.equals(center.x, center.y) && 71 | Arrays.equals(((VignetteFilterTransformation) o).vignetteColor, vignetteColor) && 72 | ((VignetteFilterTransformation) o).vignetteStart == vignetteStart && 73 | ((VignetteFilterTransformation) o).vignetteEnd == vignetteEnd; 74 | } 75 | 76 | @Override 77 | public int hashCode() { 78 | return ID.hashCode() + center.hashCode() + Arrays.hashCode(vignetteColor) + 79 | (int) (vignetteStart * 100) + (int) (vignetteEnd * 10); 80 | } 81 | 82 | @Override 83 | public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) { 84 | messageDigest.update((ID + center + Arrays.hashCode(vignetteColor) + vignetteStart + vignetteEnd).getBytes(CHARSET)); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /transformations/src/main/java/jp/wasabeef/glide/transformations/internal/FastBlur.java: -------------------------------------------------------------------------------- 1 | package jp.wasabeef.glide.transformations.internal; 2 | 3 | import android.graphics.Bitmap; 4 | 5 | /** 6 | * Copyright (C) 2020 Wasabeef 7 | *

8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | *

12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | *

14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | 21 | public class FastBlur { 22 | 23 | public static Bitmap blur(Bitmap sentBitmap, int radius, boolean canReuseInBitmap) { 24 | 25 | // Stack Blur v1.0 from 26 | // http://www.quasimondo.com/StackBlurForCanvas/StackBlurDemo.html 27 | // 28 | // Java Author: Mario Klingemann 29 | // http://incubator.quasimondo.com 30 | // created Feburary 29, 2004 31 | // Android port : Yahel Bouaziz 32 | // http://www.kayenko.com 33 | // ported april 5th, 2012 34 | 35 | // This is a compromise between Gaussian Blur and Box blur 36 | // It creates much better looking blurs than Box Blur, but is 37 | // 7x faster than my Gaussian Blur implementation. 38 | // 39 | // I called it Stack Blur because this describes best how this 40 | // filter works internally: it creates a kind of moving stack 41 | // of colors whilst scanning through the image. Thereby it 42 | // just has to add one new block of color to the right side 43 | // of the stack and remove the leftmost color. The remaining 44 | // colors on the topmost layer of the stack are either added on 45 | // or reduced by one, depending on if they are on the right or 46 | // on the left side of the stack. 47 | // 48 | // If you are using this algorithm in your code please add 49 | // the following line: 50 | // 51 | // Stack Blur Algorithm by Mario Klingemann 52 | 53 | Bitmap bitmap; 54 | if (canReuseInBitmap) { 55 | bitmap = sentBitmap; 56 | } else { 57 | bitmap = sentBitmap.copy(sentBitmap.getConfig(), true); 58 | } 59 | 60 | if (radius < 1) { 61 | return (null); 62 | } 63 | 64 | int w = bitmap.getWidth(); 65 | int h = bitmap.getHeight(); 66 | 67 | int[] pix = new int[w * h]; 68 | bitmap.getPixels(pix, 0, w, 0, 0, w, h); 69 | 70 | int wm = w - 1; 71 | int hm = h - 1; 72 | int wh = w * h; 73 | int div = radius + radius + 1; 74 | 75 | int[] r = new int[wh]; 76 | int[] g = new int[wh]; 77 | int[] b = new int[wh]; 78 | int rsum, gsum, bsum, x, y, i, p, yp, yi, yw; 79 | int[] vmin = new int[Math.max(w, h)]; 80 | 81 | int divsum = (div + 1) >> 1; 82 | divsum *= divsum; 83 | int[] dv = new int[256 * divsum]; 84 | for (i = 0; i < 256 * divsum; i++) { 85 | dv[i] = (i / divsum); 86 | } 87 | 88 | yw = yi = 0; 89 | 90 | int[][] stack = new int[div][3]; 91 | int stackpointer; 92 | int stackstart; 93 | int[] sir; 94 | int rbs; 95 | int r1 = radius + 1; 96 | int routsum, goutsum, boutsum; 97 | int rinsum, ginsum, binsum; 98 | 99 | for (y = 0; y < h; y++) { 100 | rinsum = ginsum = binsum = routsum = goutsum = boutsum = rsum = gsum = bsum = 0; 101 | for (i = -radius; i <= radius; i++) { 102 | p = pix[yi + Math.min(wm, Math.max(i, 0))]; 103 | sir = stack[i + radius]; 104 | sir[0] = (p & 0xff0000) >> 16; 105 | sir[1] = (p & 0x00ff00) >> 8; 106 | sir[2] = (p & 0x0000ff); 107 | rbs = r1 - Math.abs(i); 108 | rsum += sir[0] * rbs; 109 | gsum += sir[1] * rbs; 110 | bsum += sir[2] * rbs; 111 | if (i > 0) { 112 | rinsum += sir[0]; 113 | ginsum += sir[1]; 114 | binsum += sir[2]; 115 | } else { 116 | routsum += sir[0]; 117 | goutsum += sir[1]; 118 | boutsum += sir[2]; 119 | } 120 | } 121 | stackpointer = radius; 122 | 123 | for (x = 0; x < w; x++) { 124 | 125 | r[yi] = dv[rsum]; 126 | g[yi] = dv[gsum]; 127 | b[yi] = dv[bsum]; 128 | 129 | rsum -= routsum; 130 | gsum -= goutsum; 131 | bsum -= boutsum; 132 | 133 | stackstart = stackpointer - radius + div; 134 | sir = stack[stackstart % div]; 135 | 136 | routsum -= sir[0]; 137 | goutsum -= sir[1]; 138 | boutsum -= sir[2]; 139 | 140 | if (y == 0) { 141 | vmin[x] = Math.min(x + radius + 1, wm); 142 | } 143 | p = pix[yw + vmin[x]]; 144 | 145 | sir[0] = (p & 0xff0000) >> 16; 146 | sir[1] = (p & 0x00ff00) >> 8; 147 | sir[2] = (p & 0x0000ff); 148 | 149 | rinsum += sir[0]; 150 | ginsum += sir[1]; 151 | binsum += sir[2]; 152 | 153 | rsum += rinsum; 154 | gsum += ginsum; 155 | bsum += binsum; 156 | 157 | stackpointer = (stackpointer + 1) % div; 158 | sir = stack[(stackpointer) % div]; 159 | 160 | routsum += sir[0]; 161 | goutsum += sir[1]; 162 | boutsum += sir[2]; 163 | 164 | rinsum -= sir[0]; 165 | ginsum -= sir[1]; 166 | binsum -= sir[2]; 167 | 168 | yi++; 169 | } 170 | yw += w; 171 | } 172 | for (x = 0; x < w; x++) { 173 | rinsum = ginsum = binsum = routsum = goutsum = boutsum = rsum = gsum = bsum = 0; 174 | yp = -radius * w; 175 | for (i = -radius; i <= radius; i++) { 176 | yi = Math.max(0, yp) + x; 177 | 178 | sir = stack[i + radius]; 179 | 180 | sir[0] = r[yi]; 181 | sir[1] = g[yi]; 182 | sir[2] = b[yi]; 183 | 184 | rbs = r1 - Math.abs(i); 185 | 186 | rsum += r[yi] * rbs; 187 | gsum += g[yi] * rbs; 188 | bsum += b[yi] * rbs; 189 | 190 | if (i > 0) { 191 | rinsum += sir[0]; 192 | ginsum += sir[1]; 193 | binsum += sir[2]; 194 | } else { 195 | routsum += sir[0]; 196 | goutsum += sir[1]; 197 | boutsum += sir[2]; 198 | } 199 | 200 | if (i < hm) { 201 | yp += w; 202 | } 203 | } 204 | yi = x; 205 | stackpointer = radius; 206 | for (y = 0; y < h; y++) { 207 | // Preserve alpha channel: ( 0xff000000 & pix[yi] ) 208 | pix[yi] = (0xff000000 & pix[yi]) | (dv[rsum] << 16) | (dv[gsum] << 8) | dv[bsum]; 209 | 210 | rsum -= routsum; 211 | gsum -= goutsum; 212 | bsum -= boutsum; 213 | 214 | stackstart = stackpointer - radius + div; 215 | sir = stack[stackstart % div]; 216 | 217 | routsum -= sir[0]; 218 | goutsum -= sir[1]; 219 | boutsum -= sir[2]; 220 | 221 | if (x == 0) { 222 | vmin[y] = Math.min(y + r1, hm) * w; 223 | } 224 | p = x + vmin[y]; 225 | 226 | sir[0] = r[p]; 227 | sir[1] = g[p]; 228 | sir[2] = b[p]; 229 | 230 | rinsum += sir[0]; 231 | ginsum += sir[1]; 232 | binsum += sir[2]; 233 | 234 | rsum += rinsum; 235 | gsum += ginsum; 236 | bsum += binsum; 237 | 238 | stackpointer = (stackpointer + 1) % div; 239 | sir = stack[stackpointer]; 240 | 241 | routsum += sir[0]; 242 | goutsum += sir[1]; 243 | boutsum += sir[2]; 244 | 245 | rinsum -= sir[0]; 246 | ginsum -= sir[1]; 247 | binsum -= sir[2]; 248 | 249 | yi += w; 250 | } 251 | } 252 | 253 | bitmap.setPixels(pix, 0, w, 0, 0, w, h); 254 | 255 | return (bitmap); 256 | } 257 | } 258 | -------------------------------------------------------------------------------- /transformations/src/main/java/jp/wasabeef/glide/transformations/internal/RSBlur.java: -------------------------------------------------------------------------------- 1 | package jp.wasabeef.glide.transformations.internal; 2 | 3 | import android.annotation.TargetApi; 4 | import android.content.Context; 5 | import android.graphics.Bitmap; 6 | import android.os.Build; 7 | import android.renderscript.Allocation; 8 | import android.renderscript.Element; 9 | import android.renderscript.RSRuntimeException; 10 | import android.renderscript.RenderScript; 11 | import android.renderscript.ScriptIntrinsicBlur; 12 | 13 | /** 14 | * Copyright (C) 2020 Wasabeef 15 | *

16 | * Licensed under the Apache License, Version 2.0 (the "License"); 17 | * you may not use this file except in compliance with the License. 18 | * You may obtain a copy of the License at 19 | *

20 | * http://www.apache.org/licenses/LICENSE-2.0 21 | *

22 | * Unless required by applicable law or agreed to in writing, software 23 | * distributed under the License is distributed on an "AS IS" BASIS, 24 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 25 | * See the License for the specific language governing permissions and 26 | * limitations under the License. 27 | */ 28 | 29 | public class RSBlur { 30 | 31 | public static Bitmap blur(Context context, Bitmap bitmap, int radius) throws RSRuntimeException { 32 | RenderScript rs = null; 33 | Allocation input = null; 34 | Allocation output = null; 35 | ScriptIntrinsicBlur blur = null; 36 | try { 37 | rs = RenderScript.create(context); 38 | rs.setMessageHandler(new RenderScript.RSMessageHandler()); 39 | input = Allocation.createFromBitmap(rs, bitmap, Allocation.MipmapControl.MIPMAP_NONE, 40 | Allocation.USAGE_SCRIPT); 41 | output = Allocation.createTyped(rs, input.getType()); 42 | blur = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs)); 43 | 44 | blur.setInput(input); 45 | blur.setRadius(radius); 46 | blur.forEach(output); 47 | output.copyTo(bitmap); 48 | } finally { 49 | if (rs != null) { 50 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 51 | RenderScript.releaseAllContexts(); 52 | } else { 53 | rs.destroy(); 54 | } 55 | } 56 | if (input != null) { 57 | input.destroy(); 58 | } 59 | if (output != null) { 60 | output.destroy(); 61 | } 62 | if (blur != null) { 63 | blur.destroy(); 64 | } 65 | } 66 | 67 | return bitmap; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /transformations/src/main/java/jp/wasabeef/glide/transformations/internal/Utils.java: -------------------------------------------------------------------------------- 1 | package jp.wasabeef.glide.transformations.internal; 2 | 3 | import android.content.Context; 4 | import android.content.res.Resources; 5 | import android.graphics.drawable.Drawable; 6 | import android.os.Build; 7 | 8 | /** 9 | * Copyright (C) 2020 Wasabeef 10 | *

11 | * Licensed under the Apache License, Version 2.0 (the "License"); 12 | * you may not use this file except in compliance with the License. 13 | * You may obtain a copy of the License at 14 | *

15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | *

17 | * Unless required by applicable law or agreed to in writing, software 18 | * distributed under the License is distributed on an "AS IS" BASIS, 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 | * See the License for the specific language governing permissions and 21 | * limitations under the License. 22 | */ 23 | 24 | public final class Utils { 25 | 26 | private Utils() { 27 | // Utility class. 28 | } 29 | 30 | public static int toDp(int px) { 31 | return px * (int) Resources.getSystem().getDisplayMetrics().density; 32 | } 33 | } 34 | --------------------------------------------------------------------------------