├── .gitignore
├── CHANGELOG.md
├── LICENSE
├── README.md
├── art
├── demo-org.jpg
└── demo.gif
├── build.gradle
├── example
├── build.gradle
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── jp
│ │ └── wasabeef
│ │ └── example
│ │ └── glide
│ │ ├── MainActivity.java
│ │ ├── MainAdapter.java
│ │ └── Utils.java
│ └── 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
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── settings.gradle
└── transformations
├── build.gradle
├── proguard-rules.txt
└── src
├── androidTest
└── java
│ └── jp
│ └── wasabeef
│ └── glide
│ └── transformations
│ └── ApplicationTest.java
└── main
├── AndroidManifest.xml
└── java
└── jp
└── wasabeef
└── glide
└── transformations
├── BlurTransformation.java
├── ColorFilterTransformation.java
├── CropCircleTransformation.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
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | Thumbs.db
3 |
4 | # gradle files
5 | .gradle
6 |
7 | # Intellij project files
8 | .idea
9 | *.iml
10 |
11 | # generated files
12 | bin/
13 | gen/
14 | obj/
15 | apk/
16 | target/
17 | build/
18 |
19 | # Local configuration file (sdk path, etc)
20 | local.properties
21 |
22 | # Proguard folder generated by Eclipse
23 | proguard/
24 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | Change Log
2 | ==========
3 |
4 | Version 2.0.1 *(2016-04-21)*
5 | ----------------------------
6 |
7 | Fix:
8 | [#35](https://github.com/wasabeef/glide-transformations/issues/35)
9 | RSInvalidStateException
10 |
11 | Version 2.0.0 *(2016-03-02)*
12 | ----------------------------
13 |
14 | Say v8.RenderScript goodbye
15 |
16 | Version 1.4.0 *(2016-02-28)*
17 | ----------------------------
18 |
19 | fix Issue [#29](https://github.com/wasabeef/glide-transformations/issues/29)
20 | Use FastBlur as a fallback upon RenderScript failure.
21 |
22 | Version 1.3.1 *(2015-11-27)*
23 | ----------------------------
24 |
25 | Change the renderscriptTargetApi down to 20.
26 | Warning:Renderscript support mode is not currently supported with renderscript target 21+
27 |
28 | fix: memory leak.
29 |
30 | Version 1.3.0 *(2015-11-10)*
31 | ----------------------------
32 |
33 | add round corner type to RoundedCornersTransformation.
34 | Thanks to [kaelaela](https://github.com/kaelaela)
35 |
36 | Version 1.2.1 *(2015-09-18)*
37 | ----------------------------
38 |
39 | Merged NinePatchMaskTransformation to MaskTransformation.
40 |
41 | Version 1.2.0 *(2015-09-16)*
42 | ----------------------------
43 |
44 | add new transformations MaskTransformation and NinePatchMaskTransformation.
45 | Thanks to [start141](https://github.com/start141)
46 |
47 | Version 1.1.0 *(2015-09-05)*
48 | ----------------------------
49 |
50 | Adjustment of default parameters.
51 |
52 | Version 1.0.8 *(2015-07-24)*
53 | ----------------------------
54 |
55 | add DownSampling to BlurTransform
56 |
57 | Version 1.0.7 *(2015-07-18)*
58 | ----------------------------
59 |
60 | Bug fix : Blur not working.
61 |
62 | Version 1.0.6 *(2015-04-23)*
63 | ----------------------------
64 |
65 | add: CropType(Top, Center, Bottom) for CropTransformation.
66 |
67 | Version 1.0.5 *(2015-03-09)*
68 | ----------------------------
69 |
70 | Bug fix: Transparency.
71 |
72 | Version 1.0.4 *(2015-02-13)*
73 | ----------------------------
74 |
75 | Bug fix : remove original bitmap resource recycling.
76 |
77 | Version 1.0.3 *(2015-02-05)*
78 | ----------------------------
79 |
80 | Bug fix
81 |
82 | Version 1.0.2 *(2015-02-04)*
83 | ----------------------------
84 |
85 | Refactor: use BimapPool
86 |
87 | Version 1.0.1 *(2015-01-21)*
88 | ----------------------------
89 |
90 | fix: Blur Transformation now woking at Android 4.3
91 | add: GPUImage to Gradle dependency
92 |
93 | Version 1.0.0 *(2015-01-12)*
94 | ----------------------------
95 |
96 | Initial release.
97 |
--------------------------------------------------------------------------------
/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实现很炫的图片效果框架
2 | 开源项目地址:[https://github.com/open-android/Glide-transformations](https://github.com/open-android/Glide-transformations)
3 |
4 | PS:如果觉得文章太长,你也可观看该课程的[视频](https://www.boxuegu.com/web/html/video.html?courseId=172§ionId=8a2c9bed5a3a4c7e015a3bbffc6107ed&chapterId=8a2c9bed5a3a4c7e015a3b0c9441077a&vId=8a2c9bed5a3a4c7e015a3b03f3bd04da&videoId=13CAE14707B5911C9C33DC5901307461),亲,里面还有高清,无码的福利喔
5 |
6 | # 运行效果
7 |
8 |
9 | * 爱生活,爱学习,更爱做代码的搬运工,分类查找更方便请下载黑马助手app
10 |
11 |
12 | 
13 |
14 | ## 使用步骤
15 | ### 1. 在project的build.gradle添加如下代码(如下图)
16 |
17 | allprojects {
18 | repositories {
19 | ...
20 | maven { url "https://jitpack.io" }
21 | }
22 | }
23 |
24 | ### 2. 在Module的build.gradle添加依赖
25 |
26 | compile 'com.github.open-android:Glide-transformations:0.1.0'
27 | ### 3. 使用Picasso加载图片时添加显示效果
28 |
29 | Glide.with(context)
30 | .load(url)
31 | .transform(new CropCircleTransformation())//图片最终会展示出圆形区域
32 | .into(view);
33 | Glide-transformations 是通过Glide加载图片中通过上面的transform可以设置图片展示的效果 CropCircleTransformation是圆形效果,还有很多其他的效果
34 |
35 | 模糊效果
36 | Glide.with(this)
37 | .load(R.mipmap.ic_image_sample)
38 | .bitmapTransform(new BlurTransformation(this))
39 | .into(mResultIv);
40 |
41 | 圆角效果
42 | Glide.with(this).load(R.mipmap.ic_image_sample)
43 | .bitmapTransform(new RoundedCornersTransformation(this, 24, 0,
44 | RoundedCornersTransformation.CornerType.ALL))
45 | .into(mResultIv);
46 |
47 | 遮盖效果
48 | Glide.with(this).load(R.mipmap.ic_image_sample)
49 | .bitmapTransform(new MaskTransformation(this, R.mipmap.ic_launcher))
50 | .into(mResultIv);
51 |
52 | 灰度效果
53 | Glide.with(this).load(R.mipmap.ic_image_sample)
54 | .bitmapTransform(new GrayscaleTransformation(this))
55 | .into(mResultIv);
56 |
57 | 其他效果
58 | ToonFilterTransformation
59 | SepiaFilterTransformation
60 | ContrastFilterTransformation
61 | InvertFilterTransformation
62 | PixelationFilterTransformation
63 | SketchFilterTransformation
64 | SwirlFilterTransformation
65 | BrightnessFilterTransformation
66 | KuwaharaFilterTransformation
67 | VignetteFilterTransformation
68 |
69 |
70 | * 详细的使用方法在DEMO里面都演示啦,如果你觉得这个库还不错,请赏我一颗star吧~~~
71 |
72 | * 欢迎关注微信公众号
73 |
74 | 
75 |
--------------------------------------------------------------------------------
/art/demo-org.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/Glide-transformations/ae653b1eac81823bcde0f4f345c29e4253d336fc/art/demo-org.jpg
--------------------------------------------------------------------------------
/art/demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/Glide-transformations/ae653b1eac81823bcde0f4f345c29e4253d336fc/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 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.2.3'
9 | classpath 'com.novoda:bintray-release:0.3.4'
10 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' // Add this line
11 | }
12 | }
13 |
14 | allprojects {
15 | repositories {
16 | jcenter()
17 | mavenCentral()
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/example/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 24
5 | buildToolsVersion "25.0.2"
6 |
7 | defaultConfig {
8 | minSdkVersion 15
9 | targetSdkVersion 24
10 | versionCode 1
11 | versionName VERSION_NAME
12 | }
13 |
14 | signingConfigs {
15 | release {
16 | storeFile file(keyStoreProperty)
17 | keyAlias keyAliasProperty
18 | storePassword keyStorePasswordProperty
19 | keyPassword keyAliasPasswordProperty
20 | }
21 | }
22 |
23 | buildTypes {
24 | debug {
25 | debuggable true
26 | zipAlignEnabled true
27 | }
28 | release {
29 | debuggable false
30 | zipAlignEnabled true
31 | signingConfig signingConfigs.release
32 | }
33 | }
34 | }
35 |
36 | def getKeyStoreProperty() {
37 | return hasProperty('WASABEEF_KEYSTORE') ? WASABEEF_KEYSTORE : "debug.keystore"
38 | }
39 |
40 | def getKeyAliasProperty() {
41 | return hasProperty('WASABEEF_KEYALIAS') ? WASABEEF_KEYALIAS : "android"
42 | }
43 |
44 | def getKeyStorePasswordProperty() {
45 | return hasProperty('WASABEEF_KEYSTOREPASSWORD') ? WASABEEF_KEYSTOREPASSWORD : "androiddebugkey"
46 | }
47 |
48 | def getKeyAliasPasswordProperty() {
49 | return hasProperty('WASABEEF_KEYALIASPASSWORD') ? WASABEEF_KEYALIASPASSWORD : "android"
50 | }
51 |
52 | dependencies {
53 | compile project(':transformations')
54 | compile "com.github.bumptech.glide:glide:${GLIDE_VERSION}"
55 | compile "jp.co.cyberagent.android.gpuimage:gpuimage-library:${GPUIMAGE_VERSION}"
56 | compile "com.android.support:appcompat-v7:${SUPPORT_PACKAGE_VERSION}"
57 | compile "com.android.support:recyclerview-v7:${SUPPORT_PACKAGE_VERSION}"
58 | }
59 |
--------------------------------------------------------------------------------
/example/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
12 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/example/src/main/java/jp/wasabeef/example/glide/MainActivity.java:
--------------------------------------------------------------------------------
1 | package jp.wasabeef.example.glide;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.support.v7.widget.GridLayoutManager;
6 | import android.support.v7.widget.RecyclerView;
7 | import java.util.ArrayList;
8 | import java.util.List;
9 | import jp.wasabeef.example.glide.MainAdapter.Type;
10 |
11 | public class MainActivity extends AppCompatActivity {
12 |
13 | @Override protected void onCreate(Bundle savedInstanceState) {
14 | super.onCreate(savedInstanceState);
15 | setContentView(R.layout.activity_main);
16 |
17 | RecyclerView recyclerView = (RecyclerView) findViewById(R.id.list);
18 | recyclerView.setLayoutManager(new GridLayoutManager(this, 2));
19 |
20 | List dataSet = new ArrayList<>();
21 | dataSet.add(Type.Mask);
22 | dataSet.add(Type.NinePatchMask);
23 | dataSet.add(Type.CropTop);
24 | dataSet.add(Type.CropCenter);
25 | dataSet.add(Type.CropBottom);
26 | dataSet.add(Type.CropSquare);
27 | dataSet.add(Type.CropCircle);
28 | dataSet.add(Type.ColorFilter);
29 | dataSet.add(Type.Grayscale);
30 | dataSet.add(Type.RoundedCorners);
31 | dataSet.add(Type.Blur);
32 | dataSet.add(Type.Toon);
33 | dataSet.add(Type.Sepia);
34 | dataSet.add(Type.Contrast);
35 | dataSet.add(Type.Invert);
36 | dataSet.add(Type.Pixel);
37 | dataSet.add(Type.Sketch);
38 | dataSet.add(Type.Swirl);
39 | dataSet.add(Type.Brightness);
40 | dataSet.add(Type.Kuawahara);
41 | dataSet.add(Type.Vignette);
42 |
43 | recyclerView.setAdapter(new MainAdapter(this, dataSet));
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/example/src/main/java/jp/wasabeef/example/glide/MainAdapter.java:
--------------------------------------------------------------------------------
1 | package jp.wasabeef.example.glide;
2 |
3 | import android.content.Context;
4 | import android.graphics.Color;
5 | import android.graphics.PointF;
6 | import android.support.v7.widget.RecyclerView;
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 com.bumptech.glide.Glide;
13 | import com.bumptech.glide.load.resource.bitmap.CenterCrop;
14 | import java.util.List;
15 | import jp.wasabeef.glide.transformations.BlurTransformation;
16 | import jp.wasabeef.glide.transformations.ColorFilterTransformation;
17 | import jp.wasabeef.glide.transformations.CropCircleTransformation;
18 | import jp.wasabeef.glide.transformations.CropSquareTransformation;
19 | import jp.wasabeef.glide.transformations.CropTransformation;
20 | import jp.wasabeef.glide.transformations.GrayscaleTransformation;
21 | import jp.wasabeef.glide.transformations.MaskTransformation;
22 | import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
23 | import jp.wasabeef.glide.transformations.gpu.BrightnessFilterTransformation;
24 | import jp.wasabeef.glide.transformations.gpu.ContrastFilterTransformation;
25 | import jp.wasabeef.glide.transformations.gpu.InvertFilterTransformation;
26 | import jp.wasabeef.glide.transformations.gpu.KuwaharaFilterTransformation;
27 | import jp.wasabeef.glide.transformations.gpu.PixelationFilterTransformation;
28 | import jp.wasabeef.glide.transformations.gpu.SepiaFilterTransformation;
29 | import jp.wasabeef.glide.transformations.gpu.SketchFilterTransformation;
30 | import jp.wasabeef.glide.transformations.gpu.SwirlFilterTransformation;
31 | import jp.wasabeef.glide.transformations.gpu.ToonFilterTransformation;
32 | import jp.wasabeef.glide.transformations.gpu.VignetteFilterTransformation;
33 |
34 | /**
35 | * Created by Wasabeef on 2015/01/11.
36 | */
37 | public class MainAdapter extends RecyclerView.Adapter {
38 |
39 | private Context mContext;
40 | private List mDataSet;
41 |
42 | enum Type {
43 | Mask,
44 | NinePatchMask,
45 | CropTop,
46 | CropCenter,
47 | CropBottom,
48 | CropSquare,
49 | CropCircle,
50 | ColorFilter,
51 | Grayscale,
52 | RoundedCorners,
53 | Blur,
54 | Toon,
55 | Sepia,
56 | Contrast,
57 | Invert,
58 | Pixel,
59 | Sketch,
60 | Swirl,
61 | Brightness,
62 | Kuawahara,
63 | Vignette
64 | }
65 |
66 | public MainAdapter(Context context, List dataSet) {
67 | mContext = context;
68 | mDataSet = dataSet;
69 | }
70 |
71 | @Override public MainAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
72 | View v = LayoutInflater.from(mContext).inflate(R.layout.layout_list_item, parent, false);
73 | return new ViewHolder(v);
74 | }
75 |
76 | @Override public void onBindViewHolder(MainAdapter.ViewHolder holder, int position) {
77 | switch (mDataSet.get(position)) {
78 | case Mask: {
79 | int width = Utils.dip2px(mContext, 133.33f);
80 | int height = Utils.dip2px(mContext, 126.33f);
81 | Glide.with(mContext)
82 | .load(R.drawable.check)
83 | .override(width, height)
84 | .bitmapTransform(new CenterCrop(mContext),
85 | new MaskTransformation(mContext, R.drawable.mask_starfish))
86 | .into(holder.image);
87 | break;
88 | }
89 | case NinePatchMask: {
90 | int width = Utils.dip2px(mContext, 150.0f);
91 | int height = Utils.dip2px(mContext, 100.0f);
92 | Glide.with(mContext)
93 | .load(R.drawable.check)
94 | .override(width, height)
95 | .bitmapTransform(new CenterCrop(mContext),
96 | new MaskTransformation(mContext, R.drawable.mask_chat_right))
97 | .into(holder.image);
98 | break;
99 | }
100 | case CropTop:
101 | Glide.with(mContext)
102 | .load(R.drawable.demo)
103 | .bitmapTransform(
104 | new CropTransformation(mContext, 300, 100, CropTransformation.CropType.TOP))
105 | .into(holder.image);
106 | break;
107 | case CropCenter:
108 | Glide.with(mContext)
109 | .load(R.drawable.demo)
110 | .bitmapTransform(new CropTransformation(mContext, 300, 100))
111 | .into(holder.image);
112 | break;
113 | case CropBottom:
114 | Glide.with(mContext)
115 | .load(R.drawable.demo)
116 | .bitmapTransform(
117 | new CropTransformation(mContext, 300, 100, CropTransformation.CropType.BOTTOM))
118 | .into(holder.image);
119 |
120 | break;
121 | case CropSquare:
122 | Glide.with(mContext)
123 | .load(R.drawable.demo)
124 | .bitmapTransform(new CropSquareTransformation(mContext))
125 | .into(holder.image);
126 | break;
127 | case CropCircle:
128 | Glide.with(mContext)
129 | .load(R.drawable.demo)
130 | .bitmapTransform(new CropCircleTransformation(mContext))
131 | .into(holder.image);
132 | break;
133 | case ColorFilter:
134 | Glide.with(mContext)
135 | .load(R.drawable.demo)
136 | .bitmapTransform(new ColorFilterTransformation(mContext, Color.argb(80, 255, 0, 0)))
137 | .into(holder.image);
138 | break;
139 | case Grayscale:
140 | Glide.with(mContext)
141 | .load(R.drawable.demo)
142 | .bitmapTransform(new GrayscaleTransformation(mContext))
143 | .into(holder.image);
144 | break;
145 | case RoundedCorners:
146 | Glide.with(mContext)
147 | .load(R.drawable.demo)
148 | .bitmapTransform(new RoundedCornersTransformation(mContext, 30, 0,
149 | RoundedCornersTransformation.CornerType.BOTTOM))
150 | .into(holder.image);
151 | break;
152 | case Blur:
153 | Glide.with(mContext)
154 | .load(R.drawable.check)
155 | .bitmapTransform(new BlurTransformation(mContext, 25))
156 | .into(holder.image);
157 | break;
158 | case Toon:
159 | Glide.with(mContext)
160 | .load(R.drawable.demo)
161 | .bitmapTransform(new ToonFilterTransformation(mContext))
162 | .into(holder.image);
163 | break;
164 | case Sepia:
165 | Glide.with(mContext)
166 | .load(R.drawable.check)
167 | .bitmapTransform(new SepiaFilterTransformation(mContext))
168 | .into(holder.image);
169 | break;
170 | case Contrast:
171 | Glide.with(mContext)
172 | .load(R.drawable.check)
173 | .bitmapTransform(new ContrastFilterTransformation(mContext, 2.0f))
174 | .into(holder.image);
175 | break;
176 | case Invert:
177 | Glide.with(mContext)
178 | .load(R.drawable.check)
179 | .bitmapTransform(new InvertFilterTransformation(mContext))
180 | .into(holder.image);
181 | break;
182 | case Pixel:
183 | Glide.with(mContext)
184 | .load(R.drawable.check)
185 | .bitmapTransform(new PixelationFilterTransformation(mContext, 20))
186 | .into(holder.image);
187 | break;
188 | case Sketch:
189 | Glide.with(mContext)
190 | .load(R.drawable.check)
191 | .bitmapTransform(new SketchFilterTransformation(mContext))
192 | .into(holder.image);
193 | break;
194 | case Swirl:
195 | Glide.with(mContext)
196 | .load(R.drawable.check)
197 | .bitmapTransform(
198 | new SwirlFilterTransformation(mContext, 0.5f, 1.0f, new PointF(0.5f, 0.5f)))
199 | .into(holder.image);
200 | break;
201 | case Brightness:
202 | Glide.with(mContext)
203 | .load(R.drawable.check)
204 | .bitmapTransform(new BrightnessFilterTransformation(mContext, 0.5f))
205 | .into(holder.image);
206 | break;
207 | case Kuawahara:
208 | Glide.with(mContext)
209 | .load(R.drawable.check)
210 | .bitmapTransform(new KuwaharaFilterTransformation(mContext, 25))
211 | .into(holder.image);
212 | break;
213 | case Vignette:
214 | Glide.with(mContext)
215 | .load(R.drawable.check)
216 | .bitmapTransform(new VignetteFilterTransformation(mContext, new PointF(0.5f, 0.5f),
217 | new float[] { 0.0f, 0.0f, 0.0f }, 0f, 0.75f))
218 | .into(holder.image);
219 | break;
220 | }
221 | holder.title.setText(mDataSet.get(position).name());
222 | }
223 |
224 | @Override public int getItemCount() {
225 | return mDataSet.size();
226 | }
227 |
228 | static class ViewHolder extends RecyclerView.ViewHolder {
229 |
230 | public ImageView image;
231 | public TextView title;
232 |
233 | ViewHolder(View itemView) {
234 | super(itemView);
235 | image = (ImageView) itemView.findViewById(R.id.image);
236 | title = (TextView) itemView.findViewById(R.id.title);
237 | }
238 | }
239 | }
240 |
--------------------------------------------------------------------------------
/example/src/main/java/jp/wasabeef/example/glide/Utils.java:
--------------------------------------------------------------------------------
1 | package jp.wasabeef.example.glide;
2 |
3 | /**
4 | * Copyright (C) 2015 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 |
21 | public class Utils {
22 |
23 | public static int dip2px(Context context, float dp) {
24 | float scale = context.getResources().getDisplayMetrics().density;
25 | return (int) (dp * scale + 0.5f);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/example/src/main/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/Glide-transformations/ae653b1eac81823bcde0f4f345c29e4253d336fc/example/src/main/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/src/main/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/Glide-transformations/ae653b1eac81823bcde0f4f345c29e4253d336fc/example/src/main/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/src/main/res/drawable-xhdpi/check.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/Glide-transformations/ae653b1eac81823bcde0f4f345c29e4253d336fc/example/src/main/res/drawable-xhdpi/check.png
--------------------------------------------------------------------------------
/example/src/main/res/drawable-xhdpi/demo.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/Glide-transformations/ae653b1eac81823bcde0f4f345c29e4253d336fc/example/src/main/res/drawable-xhdpi/demo.jpg
--------------------------------------------------------------------------------
/example/src/main/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/Glide-transformations/ae653b1eac81823bcde0f4f345c29e4253d336fc/example/src/main/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/src/main/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/Glide-transformations/ae653b1eac81823bcde0f4f345c29e4253d336fc/example/src/main/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/src/main/res/drawable-xxhdpi/mask_chat_right.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/Glide-transformations/ae653b1eac81823bcde0f4f345c29e4253d336fc/example/src/main/res/drawable-xxhdpi/mask_chat_right.9.png
--------------------------------------------------------------------------------
/example/src/main/res/drawable-xxhdpi/mask_starfish.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/Glide-transformations/ae653b1eac81823bcde0f4f345c29e4253d336fc/example/src/main/res/drawable-xxhdpi/mask_starfish.png
--------------------------------------------------------------------------------
/example/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/example/src/main/res/layout/layout_list_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
15 |
16 |
25 |
26 |
--------------------------------------------------------------------------------
/example/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
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 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | VERSION_NAME=2.0.1
2 | GROUP=jp.wasabeef
3 | ARTIFACT_ID=glide-transformations
4 |
5 | COMPILE_SDK_VERSION=24
6 | BUILD_TOOLS_VERSION=25.0.2
7 | TARGET_SDK_VERSION=24
8 | MIN_SDK_VERSION=15
9 |
10 | POM_DESCRIPTION=which provides simple Tranformations to Glide
11 | POM_URL=https://github.com/wasabeef/glide-transformations
12 | POM_SCM_URL=scm:git@github.com:wasabeef/glide-transformations.git
13 | POM_SCM_CONNECTION=scm:git@github.com:wasabeef/glide-transformations.git
14 | POM_SCM_DEV_CONNECTION=scm:git@github.com:wasabeef/glide-transformations.git
15 | POM_LICENCE_NAME=The Apache Software License, Version 2.0
16 | POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
17 | POM_LICENCE_DIST=repo
18 | POM_DEVELOPER_ID=wasabeef
19 | POM_DEVELOPER_NAME=Wasabeef
20 | POM_DEVELOPER_EMAIL=dadadada.chop@gmail.com
21 | POM_DEVELOPER_URL=wasabeef.jp
22 | ISSUE_URL=https://github.com/wasabeef/glide-transformations/issues
23 |
24 | SUPPORT_PACKAGE_VERSION=23.2.1
25 | GLIDE_VERSION=3.7.0
26 | GPUIMAGE_VERSION=1.3.0
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/Glide-transformations/ae653b1eac81823bcde0f4f345c29e4253d336fc/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Apr 10 15:27:10 PDT 2013
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
7 |
8 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':example', ':transformations'
2 |
--------------------------------------------------------------------------------
/transformations/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.novoda.bintray-release'
3 | apply plugin: 'com.github.dcendents.android-maven'//固定不变
4 | group='com.github.open-android'//itcastsh:github账号
5 | android {
6 | compileSdkVersion 24
7 | buildToolsVersion "25.0.2"
8 |
9 | defaultConfig {
10 | minSdkVersion 15
11 | targetSdkVersion 24
12 | versionCode 1
13 | versionName VERSION_NAME
14 |
15 | consumerProguardFiles 'proguard-rules.txt'
16 | }
17 | }
18 |
19 | dependencies {
20 | compile "com.github.bumptech.glide:glide:${GLIDE_VERSION}"
21 | provided "jp.co.cyberagent.android.gpuimage:gpuimage-library:${GPUIMAGE_VERSION}"
22 | }
23 |
24 | task androidJavadocs(type: Javadoc) {
25 | source = android.sourceSets.main.java.srcDirs
26 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
27 | }
28 |
29 | task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
30 | classifier = 'javadoc'
31 | from androidJavadocs.destinationDir
32 | }
33 |
34 | task androidSourcesJar(type: Jar) {
35 | classifier = 'sources'
36 | from android.sourceSets.main.java.srcDirs
37 | }
38 |
39 | artifacts {
40 | archives androidSourcesJar
41 | archives androidJavadocsJar
42 | }
43 |
44 | publish {
45 | userOrg = POM_DEVELOPER_ID
46 | groupId = GROUP
47 | artifactId = ARTIFACT_ID
48 | publishVersion = VERSION_NAME
49 | desc = POM_DESCRIPTION
50 | website = POM_URL
51 | }
52 |
--------------------------------------------------------------------------------
/transformations/proguard-rules.txt:
--------------------------------------------------------------------------------
1 | -dontwarn jp.co.cyberagent.android.gpuimage.**
--------------------------------------------------------------------------------
/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/BlurTransformation.java:
--------------------------------------------------------------------------------
1 | package jp.wasabeef.glide.transformations;
2 |
3 | /**
4 | * Copyright (C) 2015 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.os.Build;
24 | import android.renderscript.RSRuntimeException;
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 jp.wasabeef.glide.transformations.internal.FastBlur;
31 | import jp.wasabeef.glide.transformations.internal.RSBlur;
32 |
33 | public class BlurTransformation implements Transformation {
34 |
35 | private static int MAX_RADIUS = 25;
36 | private static int DEFAULT_DOWN_SAMPLING = 1;
37 |
38 | private Context mContext;
39 | private BitmapPool mBitmapPool;
40 |
41 | private int mRadius;
42 | private int mSampling;
43 |
44 | public BlurTransformation(Context context) {
45 | this(context, Glide.get(context).getBitmapPool(), MAX_RADIUS, DEFAULT_DOWN_SAMPLING);
46 | }
47 |
48 | public BlurTransformation(Context context, BitmapPool pool) {
49 | this(context, pool, MAX_RADIUS, DEFAULT_DOWN_SAMPLING);
50 | }
51 |
52 | public BlurTransformation(Context context, BitmapPool pool, int radius) {
53 | this(context, pool, radius, DEFAULT_DOWN_SAMPLING);
54 | }
55 |
56 | public BlurTransformation(Context context, int radius) {
57 | this(context, Glide.get(context).getBitmapPool(), radius, DEFAULT_DOWN_SAMPLING);
58 | }
59 |
60 | public BlurTransformation(Context context, int radius, int sampling) {
61 | this(context, Glide.get(context).getBitmapPool(), radius, sampling);
62 | }
63 |
64 | public BlurTransformation(Context context, BitmapPool pool, int radius, int sampling) {
65 | mContext = context.getApplicationContext();
66 | mBitmapPool = pool;
67 | mRadius = radius;
68 | mSampling = sampling;
69 | }
70 |
71 | @Override
72 | public Resource transform(Resource resource, int outWidth, int outHeight) {
73 | Bitmap source = resource.get();
74 |
75 | int width = source.getWidth();
76 | int height = source.getHeight();
77 | int scaledWidth = width / mSampling;
78 | int scaledHeight = height / mSampling;
79 |
80 | Bitmap bitmap = mBitmapPool.get(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
81 | if (bitmap == null) {
82 | bitmap = Bitmap.createBitmap(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
83 | }
84 |
85 | Canvas canvas = new Canvas(bitmap);
86 | canvas.scale(1 / (float) mSampling, 1 / (float) mSampling);
87 | Paint paint = new Paint();
88 | paint.setFlags(Paint.FILTER_BITMAP_FLAG);
89 | canvas.drawBitmap(source, 0, 0, paint);
90 |
91 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
92 | try {
93 | bitmap = RSBlur.blur(mContext, bitmap, mRadius);
94 | } catch (RSRuntimeException e) {
95 | bitmap = FastBlur.blur(bitmap, mRadius, true);
96 | }
97 | } else {
98 | bitmap = FastBlur.blur(bitmap, mRadius, true);
99 | }
100 |
101 | return BitmapResource.obtain(bitmap, mBitmapPool);
102 | }
103 |
104 | @Override public String getId() {
105 | return "BlurTransformation(radius=" + mRadius + ", sampling=" + mSampling + ")";
106 | }
107 | }
108 |
--------------------------------------------------------------------------------
/transformations/src/main/java/jp/wasabeef/glide/transformations/ColorFilterTransformation.java:
--------------------------------------------------------------------------------
1 | package jp.wasabeef.glide.transformations;
2 |
3 | /**
4 | * Copyright (C) 2015 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 | 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 |
31 | public class ColorFilterTransformation implements Transformation {
32 |
33 | private BitmapPool mBitmapPool;
34 |
35 | private int mColor;
36 |
37 | public ColorFilterTransformation(Context context, int color) {
38 | this(Glide.get(context).getBitmapPool(), color);
39 | }
40 |
41 | public ColorFilterTransformation(BitmapPool pool, int color) {
42 | mBitmapPool = pool;
43 | mColor = color;
44 | }
45 |
46 | @Override
47 | public Resource transform(Resource resource, int outWidth, int outHeight) {
48 | Bitmap source = resource.get();
49 |
50 | int width = source.getWidth();
51 | int height = source.getHeight();
52 |
53 | Bitmap.Config config =
54 | source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
55 | Bitmap bitmap = mBitmapPool.get(width, height, config);
56 | if (bitmap == null) {
57 | bitmap = Bitmap.createBitmap(width, height, config);
58 | }
59 |
60 | Canvas canvas = new Canvas(bitmap);
61 | Paint paint = new Paint();
62 | paint.setAntiAlias(true);
63 | paint.setColorFilter(new PorterDuffColorFilter(mColor, PorterDuff.Mode.SRC_ATOP));
64 | canvas.drawBitmap(source, 0, 0, paint);
65 |
66 | return BitmapResource.obtain(bitmap, mBitmapPool);
67 | }
68 |
69 | @Override public String getId() {
70 | return "ColorFilterTransformation(color=" + mColor + ")";
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/transformations/src/main/java/jp/wasabeef/glide/transformations/CropCircleTransformation.java:
--------------------------------------------------------------------------------
1 | package jp.wasabeef.glide.transformations;
2 |
3 | /**
4 | * Copyright (C) 2015 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.Matrix;
24 | import android.graphics.Paint;
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 |
31 | public class CropCircleTransformation implements Transformation {
32 |
33 | private BitmapPool mBitmapPool;
34 |
35 | public CropCircleTransformation(Context context) {
36 | this(Glide.get(context).getBitmapPool());
37 | }
38 |
39 | public CropCircleTransformation(BitmapPool pool) {
40 | this.mBitmapPool = pool;
41 | }
42 |
43 | @Override
44 | public Resource transform(Resource resource, int outWidth, int outHeight) {
45 | Bitmap source = resource.get();
46 | int size = Math.min(source.getWidth(), source.getHeight());
47 |
48 | int width = (source.getWidth() - size) / 2;
49 | int height = (source.getHeight() - size) / 2;
50 |
51 | Bitmap bitmap = mBitmapPool.get(size, size, Bitmap.Config.ARGB_8888);
52 | if (bitmap == null) {
53 | bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
54 | }
55 |
56 | Canvas canvas = new Canvas(bitmap);
57 | Paint paint = new Paint();
58 | BitmapShader shader =
59 | new BitmapShader(source, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP);
60 | if (width != 0 || height != 0) {
61 | // source isn't square, move viewport to center
62 | Matrix matrix = new Matrix();
63 | matrix.setTranslate(-width, -height);
64 | shader.setLocalMatrix(matrix);
65 | }
66 | paint.setShader(shader);
67 | paint.setAntiAlias(true);
68 |
69 | float r = size / 2f;
70 | canvas.drawCircle(r, r, r, paint);
71 |
72 | return BitmapResource.obtain(bitmap, mBitmapPool);
73 | }
74 |
75 | @Override public String getId() {
76 | return "CropCircleTransformation()";
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/transformations/src/main/java/jp/wasabeef/glide/transformations/CropSquareTransformation.java:
--------------------------------------------------------------------------------
1 | package jp.wasabeef.glide.transformations;
2 |
3 | /**
4 | * Copyright (C) 2015 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 com.bumptech.glide.Glide;
22 | import com.bumptech.glide.load.Transformation;
23 | import com.bumptech.glide.load.engine.Resource;
24 | import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
25 | import com.bumptech.glide.load.resource.bitmap.BitmapResource;
26 |
27 | public class CropSquareTransformation implements Transformation {
28 |
29 | private BitmapPool mBitmapPool;
30 | private int mWidth;
31 | private int mHeight;
32 |
33 | public CropSquareTransformation(Context context) {
34 | this(Glide.get(context).getBitmapPool());
35 | }
36 |
37 | public CropSquareTransformation(BitmapPool pool) {
38 | this.mBitmapPool = pool;
39 | }
40 |
41 | @Override
42 | public Resource transform(Resource resource, int outWidth, int outHeight) {
43 | Bitmap source = resource.get();
44 | int size = Math.min(source.getWidth(), source.getHeight());
45 |
46 | mWidth = (source.getWidth() - size) / 2;
47 | mHeight = (source.getHeight() - size) / 2;
48 |
49 | Bitmap.Config config =
50 | source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
51 | Bitmap bitmap = mBitmapPool.get(mWidth, mHeight, config);
52 | if (bitmap == null) {
53 | bitmap = Bitmap.createBitmap(source, mWidth, mHeight, size, size);
54 | }
55 |
56 | return BitmapResource.obtain(bitmap, mBitmapPool);
57 | }
58 |
59 | @Override public String getId() {
60 | return "CropSquareTransformation(width=" + mWidth + ", height=" + mHeight + ")";
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/transformations/src/main/java/jp/wasabeef/glide/transformations/CropTransformation.java:
--------------------------------------------------------------------------------
1 | package jp.wasabeef.glide.transformations;
2 |
3 | /**
4 | * Copyright (C) 2015 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 | import com.bumptech.glide.Glide;
24 | import com.bumptech.glide.load.Transformation;
25 | import com.bumptech.glide.load.engine.Resource;
26 | import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
27 | import com.bumptech.glide.load.resource.bitmap.BitmapResource;
28 |
29 | public class CropTransformation implements Transformation {
30 |
31 | public enum CropType {
32 | TOP,
33 | CENTER,
34 | BOTTOM
35 | }
36 |
37 | private BitmapPool mBitmapPool;
38 | private int mWidth;
39 | private int mHeight;
40 |
41 | private CropType mCropType = CropType.CENTER;
42 |
43 | public CropTransformation(Context context) {
44 | this(Glide.get(context).getBitmapPool());
45 | }
46 |
47 | public CropTransformation(BitmapPool pool) {
48 | this(pool, 0, 0);
49 | }
50 |
51 | public CropTransformation(Context context, int width, int height) {
52 | this(Glide.get(context).getBitmapPool(), width, height);
53 | }
54 |
55 | public CropTransformation(BitmapPool pool, int width, int height) {
56 | this(pool, width, height, CropType.CENTER);
57 | }
58 |
59 | public CropTransformation(Context context, int width, int height, CropType cropType) {
60 | this(Glide.get(context).getBitmapPool(), width, height, cropType);
61 | }
62 |
63 | public CropTransformation(BitmapPool pool, int width, int height, CropType cropType) {
64 | mBitmapPool = pool;
65 | mWidth = width;
66 | mHeight = height;
67 | mCropType = cropType;
68 | }
69 |
70 | @Override
71 | public Resource transform(Resource resource, int outWidth, int outHeight) {
72 | Bitmap source = resource.get();
73 | mWidth = mWidth == 0 ? source.getWidth() : mWidth;
74 | mHeight = mHeight == 0 ? source.getHeight() : mHeight;
75 |
76 | Bitmap.Config config =
77 | source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
78 | Bitmap bitmap = mBitmapPool.get(mWidth, mHeight, config);
79 | if (bitmap == null) {
80 | bitmap = Bitmap.createBitmap(mWidth, mHeight, config);
81 | }
82 |
83 | float scaleX = (float) mWidth / source.getWidth();
84 | float scaleY = (float) mHeight / source.getHeight();
85 | float scale = Math.max(scaleX, scaleY);
86 |
87 | float scaledWidth = scale * source.getWidth();
88 | float scaledHeight = scale * source.getHeight();
89 | float left = (mWidth - scaledWidth) / 2;
90 | float top = getTop(scaledHeight);
91 | RectF targetRect = new RectF(left, top, left + scaledWidth, top + scaledHeight);
92 |
93 | Canvas canvas = new Canvas(bitmap);
94 | canvas.drawBitmap(source, null, targetRect, null);
95 |
96 | return BitmapResource.obtain(bitmap, mBitmapPool);
97 | }
98 |
99 | @Override public String getId() {
100 | return "CropTransformation(width=" + mWidth + ", height=" + mHeight + ", cropType=" + mCropType
101 | + ")";
102 | }
103 |
104 | private float getTop(float scaledHeight) {
105 | switch (mCropType) {
106 | case TOP:
107 | return 0;
108 | case CENTER:
109 | return (mHeight - scaledHeight) / 2;
110 | case BOTTOM:
111 | return mHeight - scaledHeight;
112 | default:
113 | return 0;
114 | }
115 | }
116 | }
117 |
--------------------------------------------------------------------------------
/transformations/src/main/java/jp/wasabeef/glide/transformations/GrayscaleTransformation.java:
--------------------------------------------------------------------------------
1 | package jp.wasabeef.glide.transformations;
2 |
3 | /**
4 | * Copyright (C) 2015 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 | 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 |
31 | public class GrayscaleTransformation implements Transformation {
32 |
33 | private BitmapPool mBitmapPool;
34 |
35 | public GrayscaleTransformation(Context context) {
36 | this(Glide.get(context).getBitmapPool());
37 | }
38 |
39 | public GrayscaleTransformation(BitmapPool pool) {
40 | mBitmapPool = pool;
41 | }
42 |
43 | @Override
44 | public Resource transform(Resource resource, int outWidth, int outHeight) {
45 | Bitmap source = resource.get();
46 |
47 | int width = source.getWidth();
48 | int height = source.getHeight();
49 |
50 | Bitmap.Config config =
51 | source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
52 | Bitmap bitmap = mBitmapPool.get(width, height, config);
53 | if (bitmap == null) {
54 | bitmap = Bitmap.createBitmap(width, height, config);
55 | }
56 |
57 | Canvas canvas = new Canvas(bitmap);
58 | ColorMatrix saturation = new ColorMatrix();
59 | saturation.setSaturation(0f);
60 | Paint paint = new Paint();
61 | paint.setColorFilter(new ColorMatrixColorFilter(saturation));
62 | canvas.drawBitmap(source, 0, 0, paint);
63 |
64 | return BitmapResource.obtain(bitmap, mBitmapPool);
65 | }
66 |
67 | @Override public String getId() {
68 | return "GrayscaleTransformation()";
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/transformations/src/main/java/jp/wasabeef/glide/transformations/MaskTransformation.java:
--------------------------------------------------------------------------------
1 | package jp.wasabeef.glide.transformations;
2 |
3 | /**
4 | * Copyright (C) 2015 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 | import com.bumptech.glide.Glide;
27 | import com.bumptech.glide.load.Transformation;
28 | import com.bumptech.glide.load.engine.Resource;
29 | import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
30 | import com.bumptech.glide.load.resource.bitmap.BitmapResource;
31 | import jp.wasabeef.glide.transformations.internal.Utils;
32 |
33 | public class MaskTransformation implements Transformation {
34 |
35 | private static Paint sMaskingPaint = new Paint();
36 | private Context mContext;
37 | private BitmapPool mBitmapPool;
38 | private int mMaskId;
39 |
40 | static {
41 | sMaskingPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
42 | }
43 |
44 | /**
45 | * @param maskId If you change the mask file, please also rename the mask file, or Glide will get
46 | * the cache with the old mask. Because getId() return the same values if using the
47 | * same make file name. If you have a good idea please tell us, thanks.
48 | */
49 | public MaskTransformation(Context context, int maskId) {
50 | this(context, Glide.get(context).getBitmapPool(), maskId);
51 | }
52 |
53 | public MaskTransformation(Context context, BitmapPool pool, int maskId) {
54 | mBitmapPool = pool;
55 | mContext = context.getApplicationContext();
56 | mMaskId = maskId;
57 | }
58 |
59 | @Override
60 | public Resource transform(Resource resource, int outWidth, int outHeight) {
61 | Bitmap source = resource.get();
62 |
63 | int width = source.getWidth();
64 | int height = source.getHeight();
65 |
66 | Bitmap result = mBitmapPool.get(width, height, Bitmap.Config.ARGB_8888);
67 | if (result == null) {
68 | result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
69 | }
70 |
71 | Drawable mask = Utils.getMaskDrawable(mContext, mMaskId);
72 |
73 | Canvas canvas = new Canvas(result);
74 | mask.setBounds(0, 0, width, height);
75 | mask.draw(canvas);
76 | canvas.drawBitmap(source, 0, 0, sMaskingPaint);
77 |
78 | return BitmapResource.obtain(result, mBitmapPool);
79 | }
80 |
81 | @Override public String getId() {
82 | return "MaskTransformation(maskId=" + mContext.getResources().getResourceEntryName(mMaskId)
83 | + ")";
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/transformations/src/main/java/jp/wasabeef/glide/transformations/RoundedCornersTransformation.java:
--------------------------------------------------------------------------------
1 | package jp.wasabeef.glide.transformations;
2 |
3 | /**
4 | * Copyright (C) 2015 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 | import com.bumptech.glide.Glide;
27 | import com.bumptech.glide.load.Transformation;
28 | import com.bumptech.glide.load.engine.Resource;
29 | import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
30 | import com.bumptech.glide.load.resource.bitmap.BitmapResource;
31 |
32 | public class RoundedCornersTransformation implements Transformation {
33 |
34 | public enum CornerType {
35 | ALL,
36 | TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT,
37 | TOP, BOTTOM, LEFT, RIGHT,
38 | OTHER_TOP_LEFT, OTHER_TOP_RIGHT, OTHER_BOTTOM_LEFT, OTHER_BOTTOM_RIGHT,
39 | DIAGONAL_FROM_TOP_LEFT, DIAGONAL_FROM_TOP_RIGHT
40 | }
41 |
42 | private BitmapPool mBitmapPool;
43 | private int mRadius;
44 | private int mDiameter;
45 | private int mMargin;
46 | private CornerType mCornerType;
47 |
48 | public RoundedCornersTransformation(Context context, int radius, int margin) {
49 | this(context, radius, margin, CornerType.ALL);
50 | }
51 |
52 | public RoundedCornersTransformation(BitmapPool pool, int radius, int margin) {
53 | this(pool, radius, margin, CornerType.ALL);
54 | }
55 |
56 | public RoundedCornersTransformation(Context context, int radius, int margin,
57 | CornerType cornerType) {
58 | this(Glide.get(context).getBitmapPool(), radius, margin, cornerType);
59 | }
60 |
61 | public RoundedCornersTransformation(BitmapPool pool, int radius, int margin,
62 | CornerType cornerType) {
63 | mBitmapPool = pool;
64 | mRadius = radius;
65 | mDiameter = mRadius * 2;
66 | mMargin = margin;
67 | mCornerType = cornerType;
68 | }
69 |
70 | @Override
71 | public Resource transform(Resource resource, int outWidth, int outHeight) {
72 | Bitmap source = resource.get();
73 |
74 | int width = source.getWidth();
75 | int height = source.getHeight();
76 |
77 | Bitmap bitmap = mBitmapPool.get(width, height, Bitmap.Config.ARGB_8888);
78 | if (bitmap == null) {
79 | bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
80 | }
81 |
82 | Canvas canvas = new Canvas(bitmap);
83 | Paint paint = new Paint();
84 | paint.setAntiAlias(true);
85 | paint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
86 | drawRoundRect(canvas, paint, width, height);
87 | return BitmapResource.obtain(bitmap, mBitmapPool);
88 | }
89 |
90 | private void drawRoundRect(Canvas canvas, Paint paint, float width, float height) {
91 | float right = width - mMargin;
92 | float bottom = height - mMargin;
93 |
94 | switch (mCornerType) {
95 | case ALL:
96 | canvas.drawRoundRect(new RectF(mMargin, mMargin, right, bottom), mRadius, mRadius, paint);
97 | break;
98 | case TOP_LEFT:
99 | drawTopLeftRoundRect(canvas, paint, right, bottom);
100 | break;
101 | case TOP_RIGHT:
102 | drawTopRightRoundRect(canvas, paint, right, bottom);
103 | break;
104 | case BOTTOM_LEFT:
105 | drawBottomLeftRoundRect(canvas, paint, right, bottom);
106 | break;
107 | case BOTTOM_RIGHT:
108 | drawBottomRightRoundRect(canvas, paint, right, bottom);
109 | break;
110 | case TOP:
111 | drawTopRoundRect(canvas, paint, right, bottom);
112 | break;
113 | case BOTTOM:
114 | drawBottomRoundRect(canvas, paint, right, bottom);
115 | break;
116 | case LEFT:
117 | drawLeftRoundRect(canvas, paint, right, bottom);
118 | break;
119 | case RIGHT:
120 | drawRightRoundRect(canvas, paint, right, bottom);
121 | break;
122 | case OTHER_TOP_LEFT:
123 | drawOtherTopLeftRoundRect(canvas, paint, right, bottom);
124 | break;
125 | case OTHER_TOP_RIGHT:
126 | drawOtherTopRightRoundRect(canvas, paint, right, bottom);
127 | break;
128 | case OTHER_BOTTOM_LEFT:
129 | drawOtherBottomLeftRoundRect(canvas, paint, right, bottom);
130 | break;
131 | case OTHER_BOTTOM_RIGHT:
132 | drawOtherBottomRightRoundRect(canvas, paint, right, bottom);
133 | break;
134 | case DIAGONAL_FROM_TOP_LEFT:
135 | drawDiagonalFromTopLeftRoundRect(canvas, paint, right, bottom);
136 | break;
137 | case DIAGONAL_FROM_TOP_RIGHT:
138 | drawDiagonalFromTopRightRoundRect(canvas, paint, right, bottom);
139 | break;
140 | default:
141 | canvas.drawRoundRect(new RectF(mMargin, mMargin, right, bottom), mRadius, mRadius, paint);
142 | break;
143 | }
144 | }
145 |
146 | private void drawTopLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
147 | canvas.drawRoundRect(new RectF(mMargin, mMargin, mMargin + mDiameter, mMargin + mDiameter),
148 | mRadius, mRadius, paint);
149 | canvas.drawRect(new RectF(mMargin, mMargin + mRadius, mMargin + mRadius, bottom), paint);
150 | canvas.drawRect(new RectF(mMargin + mRadius, mMargin, right, bottom), paint);
151 | }
152 |
153 | private void drawTopRightRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
154 | canvas.drawRoundRect(new RectF(right - mDiameter, mMargin, right, mMargin + mDiameter), mRadius,
155 | mRadius, paint);
156 | canvas.drawRect(new RectF(mMargin, mMargin, right - mRadius, bottom), paint);
157 | canvas.drawRect(new RectF(right - mRadius, mMargin + mRadius, right, bottom), paint);
158 | }
159 |
160 | private void drawBottomLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
161 | canvas.drawRoundRect(new RectF(mMargin, bottom - mDiameter, mMargin + mDiameter, bottom),
162 | mRadius, mRadius, paint);
163 | canvas.drawRect(new RectF(mMargin, mMargin, mMargin + mDiameter, bottom - mRadius), paint);
164 | canvas.drawRect(new RectF(mMargin + mRadius, mMargin, right, bottom), paint);
165 | }
166 |
167 | private void drawBottomRightRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
168 | canvas.drawRoundRect(new RectF(right - mDiameter, bottom - mDiameter, right, bottom), mRadius,
169 | mRadius, paint);
170 | canvas.drawRect(new RectF(mMargin, mMargin, right - mRadius, bottom), paint);
171 | canvas.drawRect(new RectF(right - mRadius, mMargin, right, bottom - mRadius), paint);
172 | }
173 |
174 | private void drawTopRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
175 | canvas.drawRoundRect(new RectF(mMargin, mMargin, right, mMargin + mDiameter), mRadius, mRadius,
176 | paint);
177 | canvas.drawRect(new RectF(mMargin, mMargin + mRadius, right, bottom), paint);
178 | }
179 |
180 | private void drawBottomRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
181 | canvas.drawRoundRect(new RectF(mMargin, bottom - mDiameter, right, bottom), mRadius, mRadius,
182 | paint);
183 | canvas.drawRect(new RectF(mMargin, mMargin, right, bottom - mRadius), paint);
184 | }
185 |
186 | private void drawLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
187 | canvas.drawRoundRect(new RectF(mMargin, mMargin, mMargin + mDiameter, bottom), mRadius, mRadius,
188 | paint);
189 | canvas.drawRect(new RectF(mMargin + mRadius, mMargin, right, bottom), paint);
190 | }
191 |
192 | private void drawRightRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
193 | canvas.drawRoundRect(new RectF(right - mDiameter, mMargin, right, bottom), mRadius, mRadius,
194 | paint);
195 | canvas.drawRect(new RectF(mMargin, mMargin, right - mRadius, bottom), paint);
196 | }
197 |
198 | private void drawOtherTopLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
199 | canvas.drawRoundRect(new RectF(mMargin, bottom - mDiameter, right, bottom), mRadius, mRadius,
200 | paint);
201 | canvas.drawRoundRect(new RectF(right - mDiameter, mMargin, right, bottom), mRadius, mRadius,
202 | paint);
203 | canvas.drawRect(new RectF(mMargin, mMargin, right - mRadius, bottom - mRadius), paint);
204 | }
205 |
206 | private void drawOtherTopRightRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
207 | canvas.drawRoundRect(new RectF(mMargin, mMargin, mMargin + mDiameter, bottom), mRadius, mRadius,
208 | paint);
209 | canvas.drawRoundRect(new RectF(mMargin, bottom - mDiameter, right, bottom), mRadius, mRadius,
210 | paint);
211 | canvas.drawRect(new RectF(mMargin + mRadius, mMargin, right, bottom - mRadius), paint);
212 | }
213 |
214 | private void drawOtherBottomLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
215 | canvas.drawRoundRect(new RectF(mMargin, mMargin, right, mMargin + mDiameter), mRadius, mRadius,
216 | paint);
217 | canvas.drawRoundRect(new RectF(right - mDiameter, mMargin, right, bottom), mRadius, mRadius,
218 | paint);
219 | canvas.drawRect(new RectF(mMargin, mMargin + mRadius, right - mRadius, bottom), paint);
220 | }
221 |
222 | private void drawOtherBottomRightRoundRect(Canvas canvas, Paint paint, float right,
223 | float bottom) {
224 | canvas.drawRoundRect(new RectF(mMargin, mMargin, right, mMargin + mDiameter), mRadius, mRadius,
225 | paint);
226 | canvas.drawRoundRect(new RectF(mMargin, mMargin, mMargin + mDiameter, bottom), mRadius, mRadius,
227 | paint);
228 | canvas.drawRect(new RectF(mMargin + mRadius, mMargin + mRadius, right, bottom), paint);
229 | }
230 |
231 | private void drawDiagonalFromTopLeftRoundRect(Canvas canvas, Paint paint, float right,
232 | float bottom) {
233 | canvas.drawRoundRect(new RectF(mMargin, mMargin, mMargin + mDiameter, mMargin + mDiameter),
234 | mRadius, mRadius, paint);
235 | canvas.drawRoundRect(new RectF(right - mDiameter, bottom - mDiameter, right, bottom), mRadius,
236 | mRadius, paint);
237 | canvas.drawRect(new RectF(mMargin, mMargin + mRadius, right - mDiameter, bottom), paint);
238 | canvas.drawRect(new RectF(mMargin + mDiameter, mMargin, right, bottom - mRadius), paint);
239 | }
240 |
241 | private void drawDiagonalFromTopRightRoundRect(Canvas canvas, Paint paint, float right,
242 | float bottom) {
243 | canvas.drawRoundRect(new RectF(right - mDiameter, mMargin, right, mMargin + mDiameter), mRadius,
244 | mRadius, paint);
245 | canvas.drawRoundRect(new RectF(mMargin, bottom - mDiameter, mMargin + mDiameter, bottom),
246 | mRadius, mRadius, paint);
247 | canvas.drawRect(new RectF(mMargin, mMargin, right - mRadius, bottom - mRadius), paint);
248 | canvas.drawRect(new RectF(mMargin + mRadius, mMargin + mRadius, right, bottom), paint);
249 | }
250 |
251 | @Override public String getId() {
252 | return "RoundedTransformation(radius=" + mRadius + ", margin=" + mMargin + ", diameter="
253 | + mDiameter + ", cornerType=" + mCornerType.name() + ")";
254 | }
255 | }
256 |
--------------------------------------------------------------------------------
/transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/BrightnessFilterTransformation.java:
--------------------------------------------------------------------------------
1 | package jp.wasabeef.glide.transformations.gpu;
2 |
3 | /**
4 | * Copyright (C) 2015 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 com.bumptech.glide.Glide;
21 | import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
22 | import jp.co.cyberagent.android.gpuimage.GPUImageBrightnessFilter;
23 |
24 | /**
25 | * brightness value ranges from -1.0 to 1.0, with 0.0 as the normal level
26 | */
27 | public class BrightnessFilterTransformation extends GPUFilterTransformation {
28 |
29 | private float mBrightness;
30 |
31 | public BrightnessFilterTransformation(Context context) {
32 | this(context, Glide.get(context).getBitmapPool());
33 | }
34 |
35 | public BrightnessFilterTransformation(Context context, BitmapPool pool) {
36 | this(context, pool, 0.0f);
37 | }
38 |
39 | public BrightnessFilterTransformation(Context context, float brightness) {
40 | this(context, Glide.get(context).getBitmapPool(), brightness);
41 | }
42 |
43 | public BrightnessFilterTransformation(Context context, BitmapPool pool, float brightness) {
44 | super(context, pool, new GPUImageBrightnessFilter());
45 | mBrightness = brightness;
46 | GPUImageBrightnessFilter filter = getFilter();
47 | filter.setBrightness(mBrightness);
48 | }
49 |
50 | @Override public String getId() {
51 | return "BrightnessFilterTransformation(brightness=" + mBrightness + ")";
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/ContrastFilterTransformation.java:
--------------------------------------------------------------------------------
1 | package jp.wasabeef.glide.transformations.gpu;
2 |
3 | /**
4 | * Copyright (C) 2015 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 com.bumptech.glide.Glide;
21 | import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
22 | import jp.co.cyberagent.android.gpuimage.GPUImageContrastFilter;
23 |
24 | /**
25 | * contrast value ranges from 0.0 to 4.0, with 1.0 as the normal level
26 | */
27 | public class ContrastFilterTransformation extends GPUFilterTransformation {
28 |
29 | private float mContrast;
30 |
31 | public ContrastFilterTransformation(Context context) {
32 | this(context, Glide.get(context).getBitmapPool());
33 | }
34 |
35 | public ContrastFilterTransformation(Context context, BitmapPool pool) {
36 | this(context, pool, 1.0f);
37 | }
38 |
39 | public ContrastFilterTransformation(Context context, float contrast) {
40 | this(context, Glide.get(context).getBitmapPool(), contrast);
41 | }
42 |
43 | public ContrastFilterTransformation(Context context, BitmapPool pool, float contrast) {
44 | super(context, pool, new GPUImageContrastFilter());
45 | mContrast = contrast;
46 | GPUImageContrastFilter filter = getFilter();
47 | filter.setContrast(mContrast);
48 | }
49 |
50 | @Override public String getId() {
51 | return "ContrastFilterTransformation(contrast=" + mContrast + ")";
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/GPUFilterTransformation.java:
--------------------------------------------------------------------------------
1 | package jp.wasabeef.glide.transformations.gpu;
2 |
3 | /**
4 | * Copyright (C) 2015 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 com.bumptech.glide.Glide;
22 | import com.bumptech.glide.load.Transformation;
23 | import com.bumptech.glide.load.engine.Resource;
24 | import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
25 | import com.bumptech.glide.load.resource.bitmap.BitmapResource;
26 | import jp.co.cyberagent.android.gpuimage.GPUImage;
27 | import jp.co.cyberagent.android.gpuimage.GPUImageFilter;
28 |
29 | public class GPUFilterTransformation implements Transformation {
30 |
31 | private Context mContext;
32 | private BitmapPool mBitmapPool;
33 |
34 | private GPUImageFilter mFilter;
35 |
36 | public GPUFilterTransformation(Context context, GPUImageFilter filter) {
37 | this(context, Glide.get(context).getBitmapPool(), filter);
38 | }
39 |
40 | public GPUFilterTransformation(Context context, BitmapPool pool, GPUImageFilter filter) {
41 | mContext = context.getApplicationContext();
42 | mBitmapPool = pool;
43 | mFilter = filter;
44 | }
45 |
46 | @Override
47 | public Resource transform(Resource resource, int outWidth, int outHeight) {
48 | Bitmap source = resource.get();
49 | GPUImage gpuImage = new GPUImage(mContext);
50 | gpuImage.setImage(source);
51 | gpuImage.setFilter(mFilter);
52 |
53 | Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
54 |
55 | return BitmapResource.obtain(bitmap, mBitmapPool);
56 | }
57 |
58 | @Override public String getId() {
59 | return getClass().getSimpleName();
60 | }
61 |
62 | @SuppressWarnings("unchecked") public T getFilter() {
63 | return (T) mFilter;
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/InvertFilterTransformation.java:
--------------------------------------------------------------------------------
1 | package jp.wasabeef.glide.transformations.gpu;
2 |
3 | /**
4 | * Copyright (C) 2015 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 com.bumptech.glide.Glide;
21 | import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
22 | import jp.co.cyberagent.android.gpuimage.GPUImageColorInvertFilter;
23 |
24 | /**
25 | * Invert all the colors in the image.
26 | */
27 | public class InvertFilterTransformation extends GPUFilterTransformation {
28 |
29 | public InvertFilterTransformation(Context context) {
30 | this(context, Glide.get(context).getBitmapPool());
31 | }
32 |
33 | public InvertFilterTransformation(Context context, BitmapPool pool) {
34 | super(context, pool, new GPUImageColorInvertFilter());
35 | }
36 |
37 | @Override public String getId() {
38 | return "InvertFilterTransformation()";
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/KuwaharaFilterTransformation.java:
--------------------------------------------------------------------------------
1 | package jp.wasabeef.glide.transformations.gpu;
2 |
3 | /**
4 | * Copyright (C) 2015 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 com.bumptech.glide.Glide;
21 | import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
22 | import jp.co.cyberagent.android.gpuimage.GPUImageKuwaharaFilter;
23 |
24 | /**
25 | * Kuwahara all the colors in the image.
26 | *
27 | * The radius to sample from when creating the brush-stroke effect, with a default of 25.
28 | * The larger the radius, the slower the filter.
29 | */
30 | public class KuwaharaFilterTransformation extends GPUFilterTransformation {
31 |
32 | private int mRadius;
33 |
34 | public KuwaharaFilterTransformation(Context context) {
35 | this(context, Glide.get(context).getBitmapPool());
36 | }
37 |
38 | public KuwaharaFilterTransformation(Context context, BitmapPool pool) {
39 | this(context, pool, 25);
40 | }
41 |
42 | public KuwaharaFilterTransformation(Context context, int radius) {
43 | this(context, Glide.get(context).getBitmapPool(), radius);
44 | }
45 |
46 | public KuwaharaFilterTransformation(Context context, BitmapPool pool, int radius) {
47 | super(context, pool, new GPUImageKuwaharaFilter());
48 | mRadius = radius;
49 | GPUImageKuwaharaFilter filter = getFilter();
50 | filter.setRadius(mRadius);
51 | }
52 |
53 | @Override public String getId() {
54 | return "KuwaharaFilterTransformation(radius=" + mRadius + ")";
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/PixelationFilterTransformation.java:
--------------------------------------------------------------------------------
1 | package jp.wasabeef.glide.transformations.gpu;
2 |
3 | /**
4 | * Copyright (C) 2015 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 com.bumptech.glide.Glide;
21 | import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
22 | import jp.co.cyberagent.android.gpuimage.GPUImagePixelationFilter;
23 |
24 | /**
25 | * Applies a Pixelation effect to the image.
26 | *
27 | * The pixel with a default of 10.0.
28 | */
29 | public class PixelationFilterTransformation extends GPUFilterTransformation {
30 |
31 | private float mPixel;
32 |
33 | public PixelationFilterTransformation(Context context) {
34 | this(context, Glide.get(context).getBitmapPool());
35 | }
36 |
37 | public PixelationFilterTransformation(Context context, BitmapPool pool) {
38 | this(context, pool, 10f);
39 | }
40 |
41 | public PixelationFilterTransformation(Context context, float pixel) {
42 | this(context, Glide.get(context).getBitmapPool(), pixel);
43 | }
44 |
45 | public PixelationFilterTransformation(Context context, BitmapPool pool, float pixel) {
46 | super(context, pool, new GPUImagePixelationFilter());
47 | mPixel = pixel;
48 | GPUImagePixelationFilter filter = getFilter();
49 | filter.setPixel(mPixel);
50 | }
51 |
52 | @Override public String getId() {
53 | return "PixelationFilterTransformation(pixel=" + mPixel + ")";
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/SepiaFilterTransformation.java:
--------------------------------------------------------------------------------
1 | package jp.wasabeef.glide.transformations.gpu;
2 |
3 | /**
4 | * Copyright (C) 2015 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 com.bumptech.glide.Glide;
21 | import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
22 | import jp.co.cyberagent.android.gpuimage.GPUImageSepiaFilter;
23 |
24 | /**
25 | * Applies a simple sepia effect.
26 | *
27 | * The intensity with a default of 1.0.
28 | */
29 | public class SepiaFilterTransformation extends GPUFilterTransformation {
30 |
31 | private float mIntensity;
32 |
33 | public SepiaFilterTransformation(Context context) {
34 | this(context, Glide.get(context).getBitmapPool());
35 | }
36 |
37 | public SepiaFilterTransformation(Context context, BitmapPool pool) {
38 | this(context, pool, 1.0f);
39 | }
40 |
41 | public SepiaFilterTransformation(Context context, float intensity) {
42 | this(context, Glide.get(context).getBitmapPool(), intensity);
43 | }
44 |
45 | public SepiaFilterTransformation(Context context, BitmapPool pool, float intensity) {
46 | super(context, pool, new GPUImageSepiaFilter());
47 | mIntensity = intensity;
48 | GPUImageSepiaFilter filter = getFilter();
49 | filter.setIntensity(mIntensity);
50 | }
51 |
52 | @Override public String getId() {
53 | return "SepiaFilterTransformation(intensity=" + mIntensity + ")";
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/SketchFilterTransformation.java:
--------------------------------------------------------------------------------
1 | package jp.wasabeef.glide.transformations.gpu;
2 |
3 | /**
4 | * Copyright (C) 2015 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 com.bumptech.glide.Glide;
21 | import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
22 | import jp.co.cyberagent.android.gpuimage.GPUImageSketchFilter;
23 |
24 | public class SketchFilterTransformation extends GPUFilterTransformation {
25 |
26 | public SketchFilterTransformation(Context context) {
27 | this(context, Glide.get(context).getBitmapPool());
28 | }
29 |
30 | public SketchFilterTransformation(Context context, BitmapPool pool) {
31 | super(context, pool, new GPUImageSketchFilter());
32 | }
33 |
34 | @Override public String getId() {
35 | return "SketchFilterTransformation()";
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/SwirlFilterTransformation.java:
--------------------------------------------------------------------------------
1 | package jp.wasabeef.glide.transformations.gpu;
2 |
3 | /**
4 | * Copyright (C) 2015 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.PointF;
21 | import com.bumptech.glide.Glide;
22 | import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
23 | import jp.co.cyberagent.android.gpuimage.GPUImageSwirlFilter;
24 |
25 | /**
26 | * Creates a swirl distortion on the image.
27 | */
28 | public class SwirlFilterTransformation extends GPUFilterTransformation {
29 |
30 | private float mRadius;
31 | private float mAngle;
32 | private PointF mCenter;
33 |
34 | public SwirlFilterTransformation(Context context) {
35 | this(context, Glide.get(context).getBitmapPool());
36 | }
37 |
38 | public SwirlFilterTransformation(Context context, BitmapPool pool) {
39 | this(context, pool, .5f, 1.0f, new PointF(0.5f, 0.5f));
40 | }
41 |
42 | public SwirlFilterTransformation(Context context, float radius, float angle, PointF center) {
43 | this(context, Glide.get(context).getBitmapPool(), radius, angle, center);
44 | }
45 |
46 | /**
47 | * @param radius from 0.0 to 1.0, default 0.5
48 | * @param angle minimum 0.0, default 1.0
49 | * @param center default (0.5, 0.5)
50 | */
51 | public SwirlFilterTransformation(Context context, BitmapPool pool, float radius, float angle,
52 | PointF center) {
53 | super(context, pool, new GPUImageSwirlFilter());
54 | mRadius = radius;
55 | mAngle = angle;
56 | mCenter = center;
57 | GPUImageSwirlFilter filter = getFilter();
58 | filter.setRadius(mRadius);
59 | filter.setAngle(mAngle);
60 | filter.setCenter(mCenter);
61 | }
62 |
63 | @Override public String getId() {
64 | return "SwirlFilterTransformation(radius=" + mRadius +
65 | ",angle=" + mAngle + ",center=" + mCenter.toString() + ")";
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/ToonFilterTransformation.java:
--------------------------------------------------------------------------------
1 | package jp.wasabeef.glide.transformations.gpu;
2 |
3 | /**
4 | * Copyright (C) 2015 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 com.bumptech.glide.Glide;
21 | import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
22 | import jp.co.cyberagent.android.gpuimage.GPUImageToonFilter;
23 |
24 | /**
25 | * The threshold at which to apply the edges, default of 0.2.
26 | * The levels of quantization for the posterization of colors within the scene,
27 | * with a default of 10.0.
28 | */
29 | public class ToonFilterTransformation extends GPUFilterTransformation {
30 |
31 | private float mThreshold;
32 | private float mQuantizationLevels;
33 |
34 | public ToonFilterTransformation(Context context) {
35 | this(context, Glide.get(context).getBitmapPool());
36 | }
37 |
38 | public ToonFilterTransformation(Context context, BitmapPool pool) {
39 | this(context, pool, .2f, 10.0f);
40 | }
41 |
42 | public ToonFilterTransformation(Context context, float threshold, float quantizationLevels) {
43 | this(context, Glide.get(context).getBitmapPool(), threshold, quantizationLevels);
44 | }
45 |
46 | public ToonFilterTransformation(Context context, BitmapPool pool, float threshold,
47 | float quantizationLevels) {
48 | super(context, pool, new GPUImageToonFilter());
49 | mThreshold = threshold;
50 | mQuantizationLevels = quantizationLevels;
51 | GPUImageToonFilter filter = getFilter();
52 | filter.setThreshold(mThreshold);
53 | filter.setQuantizationLevels(mQuantizationLevels);
54 | }
55 |
56 | @Override public String getId() {
57 | return "ToonFilterTransformation(threshold=" + mThreshold +
58 | ",quantizationLevels=" + mQuantizationLevels + ")";
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/VignetteFilterTransformation.java:
--------------------------------------------------------------------------------
1 | package jp.wasabeef.glide.transformations.gpu;
2 |
3 | /**
4 | * Copyright (C) 2015 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.PointF;
21 | import com.bumptech.glide.Glide;
22 | import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
23 | import java.util.Arrays;
24 | import jp.co.cyberagent.android.gpuimage.GPUImageVignetteFilter;
25 |
26 | /**
27 | * Performs a vignetting effect, fading out the image at the edges
28 | * The directional intensity of the vignetting,
29 | * with a default of x = 0.5, y = 0.5, start = 0, end = 0.75
30 | */
31 | public class VignetteFilterTransformation extends GPUFilterTransformation {
32 |
33 | private PointF mCenter;
34 | private float[] mVignetteColor;
35 | private float mVignetteStart;
36 | private float mVignetteEnd;
37 |
38 | public VignetteFilterTransformation(Context context) {
39 | this(context, Glide.get(context).getBitmapPool());
40 | }
41 |
42 | public VignetteFilterTransformation(Context context, BitmapPool pool) {
43 | this(context, pool, new PointF(0.5f, 0.5f), new float[] { 0.0f, 0.0f, 0.0f }, 0.0f, 0.75f);
44 | }
45 |
46 | public VignetteFilterTransformation(Context context, PointF center, float[] color, float start,
47 | float end) {
48 | this(context, Glide.get(context).getBitmapPool(), center, color, start, end);
49 | }
50 |
51 | public VignetteFilterTransformation(Context context, BitmapPool pool, PointF center,
52 | float[] color, float start, float end) {
53 | super(context, pool, new GPUImageVignetteFilter());
54 | mCenter = center;
55 | mVignetteColor = color;
56 | mVignetteStart = start;
57 | mVignetteEnd = end;
58 | GPUImageVignetteFilter filter = getFilter();
59 | filter.setVignetteCenter(mCenter);
60 | filter.setVignetteColor(mVignetteColor);
61 | filter.setVignetteStart(mVignetteStart);
62 | filter.setVignetteEnd(mVignetteEnd);
63 | }
64 |
65 | @Override public String getId() {
66 | return "VignetteFilterTransformation(center=" + mCenter.toString() +
67 | ",color=" + Arrays.toString(mVignetteColor) +
68 | ",start=" + mVignetteStart + ",end=" + mVignetteEnd + ")";
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/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) 2015 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 | }
--------------------------------------------------------------------------------
/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) 2015 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 | @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
32 | public static Bitmap blur(Context context, Bitmap bitmap, int radius) throws RSRuntimeException {
33 | RenderScript rs = null;
34 | try {
35 | rs = RenderScript.create(context);
36 | rs.setMessageHandler(new RenderScript.RSMessageHandler());
37 | Allocation input =
38 | Allocation.createFromBitmap(rs, bitmap, Allocation.MipmapControl.MIPMAP_NONE,
39 | Allocation.USAGE_SCRIPT);
40 | Allocation output = Allocation.createTyped(rs, input.getType());
41 | ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
42 |
43 | blur.setInput(input);
44 | blur.setRadius(radius);
45 | blur.forEach(output);
46 | output.copyTo(bitmap);
47 | } finally {
48 | if (rs != null) {
49 | rs.destroy();
50 | }
51 | }
52 |
53 | return bitmap;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/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.graphics.drawable.Drawable;
5 | import android.os.Build;
6 |
7 | /**
8 | * Copyright (C) 2015 Wasabeef
9 | *
10 | * Licensed under the Apache License, Version 2.0 (the "License");
11 | * you may not use this file except in compliance with the License.
12 | * You may obtain a copy of the License at
13 | *
14 | * http://www.apache.org/licenses/LICENSE-2.0
15 | *
16 | * Unless required by applicable law or agreed to in writing, software
17 | * distributed under the License is distributed on an "AS IS" BASIS,
18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 | * See the License for the specific language governing permissions and
20 | * limitations under the License.
21 | */
22 |
23 | public final class Utils {
24 |
25 | private Utils() {
26 | // Utility class.
27 | }
28 |
29 | public static Drawable getMaskDrawable(Context context, int maskId) {
30 | Drawable drawable;
31 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
32 | drawable = context.getDrawable(maskId);
33 | } else {
34 | drawable = context.getResources().getDrawable(maskId);
35 | }
36 |
37 | if (drawable == null) {
38 | throw new IllegalArgumentException("maskId is invalid");
39 | }
40 |
41 | return drawable;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------