├── .gitignore
├── CHANGELOG.md
├── LICENSE
├── README.md
├── art
├── demo-org.jpg
└── demo.gif
├── build.gradle
├── example
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── jp
│ │ └── wasabeef
│ │ └── example
│ │ └── picasso
│ │ └── ApplicationTest.java
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── jp
│ │ └── wasabeef
│ │ └── example
│ │ └── picasso
│ │ ├── 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
│ ├── chat_me_mask.9.png
│ ├── ic_launcher.png
│ └── mask_starfish.png
│ ├── layout
│ ├── activity_main.xml
│ └── layout_list_item.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
└── main
├── AndroidManifest.xml
└── java
└── jp
└── wasabeef
└── picasso
└── 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.1.0 *(2016-03-28)*
5 | ----------------------------
6 |
7 | Extended the CropTransformation by [@molexx](https://github.com/molexx)
8 | - Horizontal gravity
9 | - Crop to aspect ratio
10 | - Crop to width/height as a ratio of original image's width/height
11 | - Crop to exact area (specify left and top)
12 |
13 | Version 2.0.0 *(2016-03-02)*
14 | ----------------------------
15 |
16 | Say v8.RenderScript goodbye
17 |
18 | Version 1.4.0 *(2016-02-28)*
19 | ----------------------------
20 |
21 | Use FastBlur as a fallback upon RenderScript failure.
22 |
23 | Version 1.3.1 *(2015-11-27)*
24 | ----------------------------
25 |
26 | Change the renderscriptTargetApi down to 20.
27 | Warning:Renderscript support mode is not currently supported with renderscript target 21+
28 |
29 | fix: memory leak.
30 |
31 | Version 1.3.0 *(2015-11-10)*
32 | ----------------------------
33 |
34 | add round corner type to RoundedCornersTransformation.
35 | Thanks to [kaelaela](https://github.com/kaelaela)
36 |
37 | Version 1.2.1 *(2015-09-16)*
38 | ----------------------------
39 |
40 | Optimization.
41 |
42 | Version 1.2.0 *(2015-09-16)*
43 | ----------------------------
44 |
45 | add new transformations MaskTransformation.
46 | Thanks to [start141](https://github.com/start141)
47 |
48 | Version 1.1.0 *(2015-09-06)*
49 | ----------------------------
50 |
51 | Adjustment of default parameters.
52 |
53 | Version 1.0.5 *(2015-07-24)*
54 | ----------------------------
55 |
56 | add DownSampling to BlurTransform
57 |
58 | Version 1.0.4 *(2015-04-28)*
59 | ----------------------------
60 |
61 | update support-library
62 |
63 | Version 1.0.3 *(2015-04-23)*
64 | ----------------------------
65 |
66 | add: CropType(Top, Center, Bottom) for CropTransformation
67 |
68 | Version 1.0.2 *(2015-03-09)*
69 | ----------------------------
70 |
71 | fix: source isn't square, move viewport to center
72 |
73 | Version 1.0.1 *(2015-01-21)*
74 | ----------------------------
75 |
76 | fix: Blur Transformation now woking at Android 4.3
77 | add: GPUImage to Gradle dependency
78 |
79 | Version 1.0.0 *(2015-01-14)*
80 | ----------------------------
81 |
82 | Initial release.
83 |
--------------------------------------------------------------------------------
/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 | # 结合Picasso实现很炫的图片效果框架
2 | 开源项目地址:[https://github.com/open-android/Picasso-transformations](https://github.com/open-android/Picasso-transformations)
3 |
4 | PS:如果觉得文章太长,你也可观看该课程的[视频](https://www.boxuegu.com/web/html/video.html?courseId=172§ionId=8a2c9bed5a3a4c7e015a3bbffc6107ed&chapterId=8a2c9bed5a3a4c7e015a3afea6140464&vId=8a2c9bed5a3a4c7e015a3b0482c10627&videoId=A9996ED78AAC2B7B9C33DC5901307461),亲,里面还有高清,无码的福利喔
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:Picasso-transformations:0.1.0'
27 | ### 3. 使用Picasso加载图片时添加显示效果
28 |
29 | Picasso.with(context)
30 | .load(url)
31 | .transform(new CropCircleTransformation())//图片最终会展示出圆形区域
32 | .into(view);
33 | Picasso-transformations 是通过Picasso加载图片中通过上面的transform可以设置图片展示的效果 CropCircleTransformation是圆形效果,还有很多其他的效果
34 |
35 | 模糊效果
36 | Picasso.with(this)
37 | .load(R.mipmap.ic_image_sample)
38 | .bitmapTransform(new BlurTransformation(this))
39 | .into(mResultIv);
40 |
41 | 圆角效果
42 | Picasso.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 | Picasso.with(this).load(R.mipmap.ic_image_sample)
49 | .bitmapTransform(new MaskTransformation(this, R.mipmap.ic_launcher))
50 | .into(mResultIv);
51 |
52 | 灰度效果
53 | Picasso.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/Picasso-transformations/a5c92a9b63360f695fb7a8d9d3845d29730f9731/art/demo-org.jpg
--------------------------------------------------------------------------------
/art/demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/Picasso-transformations/a5c92a9b63360f695fb7a8d9d3845d29730f9731/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 | // NOTE: Do not place your application dependencies here; they belong
12 | // in the individual module build.gradle files
13 | }
14 | }
15 |
16 | allprojects {
17 | repositories {
18 | jcenter()
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/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.squareup.picasso:picasso:${PICASSO_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 | }
--------------------------------------------------------------------------------
/example/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Applications/android-sdk-macosx/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/example/src/androidTest/java/jp/wasabeef/example/picasso/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package jp.wasabeef.example.picasso;
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 | }
--------------------------------------------------------------------------------
/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/picasso/MainActivity.java:
--------------------------------------------------------------------------------
1 | package jp.wasabeef.example.picasso;
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.picasso.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.CropCenterTop);
24 | dataSet.add(Type.CropCenterCenter);
25 | dataSet.add(Type.CropCenterBottom);
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 | dataSet.add(Type.CropLeftTop);
44 | dataSet.add(Type.CropLeftCenter);
45 | dataSet.add(Type.CropLeftBottom);
46 | dataSet.add(Type.CropRightTop);
47 | dataSet.add(Type.CropRightCenter);
48 | dataSet.add(Type.CropRightBottom);
49 | dataSet.add(Type.Crop169CenterCenter);
50 | dataSet.add(Type.Crop43CenterCenter);
51 | dataSet.add(Type.Crop31CenterCenter);
52 | dataSet.add(Type.Crop31CenterTop);
53 | dataSet.add(Type.CropSquareCenterCenter);
54 | dataSet.add(Type.CropQuarterCenterCenter);
55 | dataSet.add(Type.CropQuarterCenterTop);
56 | dataSet.add(Type.CropQuarterBottomRight);
57 | dataSet.add(Type.CropHalfWidth43CenterCenter);
58 |
59 | recyclerView.setAdapter(new MainAdapter(this, dataSet));
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/example/src/main/java/jp/wasabeef/example/picasso/MainAdapter.java:
--------------------------------------------------------------------------------
1 | package jp.wasabeef.example.picasso;
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.squareup.picasso.Picasso;
13 | import java.util.List;
14 | import jp.wasabeef.picasso.transformations.BlurTransformation;
15 | import jp.wasabeef.picasso.transformations.ColorFilterTransformation;
16 | import jp.wasabeef.picasso.transformations.CropCircleTransformation;
17 | import jp.wasabeef.picasso.transformations.CropSquareTransformation;
18 | import jp.wasabeef.picasso.transformations.CropTransformation;
19 | import jp.wasabeef.picasso.transformations.GrayscaleTransformation;
20 | import jp.wasabeef.picasso.transformations.MaskTransformation;
21 | import jp.wasabeef.picasso.transformations.RoundedCornersTransformation;
22 | import jp.wasabeef.picasso.transformations.gpu.BrightnessFilterTransformation;
23 | import jp.wasabeef.picasso.transformations.gpu.ContrastFilterTransformation;
24 | import jp.wasabeef.picasso.transformations.gpu.InvertFilterTransformation;
25 | import jp.wasabeef.picasso.transformations.gpu.KuwaharaFilterTransformation;
26 | import jp.wasabeef.picasso.transformations.gpu.PixelationFilterTransformation;
27 | import jp.wasabeef.picasso.transformations.gpu.SepiaFilterTransformation;
28 | import jp.wasabeef.picasso.transformations.gpu.SketchFilterTransformation;
29 | import jp.wasabeef.picasso.transformations.gpu.SwirlFilterTransformation;
30 | import jp.wasabeef.picasso.transformations.gpu.ToonFilterTransformation;
31 | import jp.wasabeef.picasso.transformations.gpu.VignetteFilterTransformation;
32 |
33 | /**
34 | * Created by Wasabeef on 2015/01/11.
35 | */
36 | public class MainAdapter extends RecyclerView.Adapter {
37 |
38 | private Context mContext;
39 | private List mDataSet;
40 |
41 | enum Type {
42 | Mask,
43 | NinePatchMask,
44 | CropLeftTop,
45 | CropLeftCenter,
46 | CropLeftBottom,
47 | CropCenterTop,
48 | CropCenterCenter,
49 | CropCenterBottom,
50 | CropRightTop,
51 | CropRightCenter,
52 | CropRightBottom,
53 | CropSquareCenterCenter,
54 | Crop169CenterCenter,
55 | Crop43CenterCenter,
56 | Crop31CenterCenter,
57 | Crop31CenterTop,
58 | CropQuarterCenterCenter,
59 | CropQuarterCenterTop,
60 | CropQuarterBottomRight,
61 | CropHalfWidth43CenterCenter,
62 | CropSquare,
63 | CropCircle,
64 | ColorFilter,
65 | Grayscale,
66 | RoundedCorners,
67 | Blur,
68 | Toon,
69 | Sepia,
70 | Contrast,
71 | Invert,
72 | Pixel,
73 | Sketch,
74 | Swirl,
75 | Brightness,
76 | Kuawahara,
77 | Vignette
78 | }
79 |
80 | public MainAdapter(Context context, List dataSet) {
81 | mContext = context;
82 | mDataSet = dataSet;
83 | }
84 |
85 | @Override public MainAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
86 | View v = LayoutInflater.from(mContext).inflate(R.layout.layout_list_item, parent, false);
87 | return new ViewHolder(v);
88 | }
89 |
90 | @Override public void onBindViewHolder(MainAdapter.ViewHolder holder, int position) {
91 | switch (mDataSet.get(position)) {
92 | case Mask: {
93 | int width = Utils.dip2px(mContext, 133.33f);
94 | int height = Utils.dip2px(mContext, 126.33f);
95 | Picasso.with(mContext)
96 | .load(R.drawable.check)
97 | .resize(width, height)
98 | .centerCrop()
99 | .transform((new MaskTransformation(mContext, R.drawable.mask_starfish)))
100 | .into(holder.image);
101 | break;
102 | }
103 | case NinePatchMask: {
104 | int width = Utils.dip2px(mContext, 150.0f);
105 | int height = Utils.dip2px(mContext, 100.0f);
106 | Picasso.with(mContext)
107 | .load(R.drawable.check)
108 | .resize(width, height)
109 | .centerCrop()
110 | .transform(new MaskTransformation(mContext, R.drawable.chat_me_mask))
111 | .into(holder.image);
112 | break;
113 | }
114 | case CropLeftTop:
115 | Picasso.with(mContext)
116 | .load(R.drawable.demo)
117 | .transform(new CropTransformation(300, 100, CropTransformation.GravityHorizontal.LEFT,
118 | CropTransformation.GravityVertical.TOP))
119 | .into(holder.image);
120 | break;
121 | case CropLeftCenter:
122 | Picasso.with(mContext).load(R.drawable.demo)
123 | // 300, 100, CropTransformation.GravityHorizontal.LEFT, CropTransformation.GravityVertical.CENTER))
124 | .transform(new CropTransformation(300, 100)).into(holder.image);
125 | break;
126 | case CropLeftBottom:
127 | Picasso.with(mContext)
128 | .load(R.drawable.demo)
129 | .transform(new CropTransformation(300, 100, CropTransformation.GravityHorizontal.LEFT,
130 | CropTransformation.GravityVertical.BOTTOM))
131 | .into(holder.image);
132 | break;
133 | case CropCenterTop:
134 | Picasso.with(mContext)
135 | .load(R.drawable.demo)
136 | .transform(new CropTransformation(300, 100, CropTransformation.GravityHorizontal.CENTER,
137 | CropTransformation.GravityVertical.TOP))
138 | .into(holder.image);
139 | break;
140 | case CropCenterCenter:
141 | Picasso.with(mContext)
142 | .load(R.drawable.demo)
143 | .transform(new CropTransformation(300, 100))
144 | .into(holder.image);
145 | break;
146 | case CropCenterBottom:
147 | Picasso.with(mContext)
148 | .load(R.drawable.demo)
149 | .transform(new CropTransformation(300, 100, CropTransformation.GravityHorizontal.CENTER,
150 | CropTransformation.GravityVertical.BOTTOM))
151 | .into(holder.image);
152 | break;
153 | case CropRightTop:
154 | Picasso.with(mContext)
155 | .load(R.drawable.demo)
156 | .transform(new CropTransformation(300, 100, CropTransformation.GravityHorizontal.RIGHT,
157 | CropTransformation.GravityVertical.TOP))
158 | .into(holder.image);
159 | break;
160 | case CropRightCenter:
161 | Picasso.with(mContext)
162 | .load(R.drawable.demo)
163 | .transform(new CropTransformation(300, 100, CropTransformation.GravityHorizontal.RIGHT,
164 | CropTransformation.GravityVertical.CENTER))
165 | .into(holder.image);
166 | break;
167 | case CropRightBottom:
168 | Picasso.with(mContext)
169 | .load(R.drawable.demo)
170 | .transform(new CropTransformation(300, 100, CropTransformation.GravityHorizontal.RIGHT,
171 | CropTransformation.GravityVertical.BOTTOM))
172 | .into(holder.image);
173 | break;
174 | case Crop169CenterCenter:
175 | Picasso.with(mContext)
176 | .load(R.drawable.demo)
177 | .transform(new CropTransformation((float) 16 / (float) 9,
178 | CropTransformation.GravityHorizontal.CENTER,
179 | CropTransformation.GravityVertical.CENTER))
180 | .into(holder.image);
181 | break;
182 | case Crop43CenterCenter:
183 | Picasso.with(mContext)
184 | .load(R.drawable.demo)
185 | .transform(new CropTransformation((float) 4 / (float) 3,
186 | CropTransformation.GravityHorizontal.CENTER,
187 | CropTransformation.GravityVertical.CENTER))
188 | .into(holder.image);
189 | break;
190 | case Crop31CenterCenter:
191 | Picasso.with(mContext)
192 | .load(R.drawable.demo)
193 | .transform(new CropTransformation(3, CropTransformation.GravityHorizontal.CENTER,
194 | CropTransformation.GravityVertical.CENTER))
195 | .into(holder.image);
196 | break;
197 | case Crop31CenterTop:
198 | Picasso.with(mContext)
199 | .load(R.drawable.demo)
200 | .transform(new CropTransformation(3, CropTransformation.GravityHorizontal.CENTER,
201 | CropTransformation.GravityVertical.TOP))
202 | .into(holder.image);
203 | break;
204 | case CropSquareCenterCenter:
205 | Picasso.with(mContext)
206 | .load(R.drawable.demo)
207 | .transform(new CropTransformation(1, CropTransformation.GravityHorizontal.CENTER,
208 | CropTransformation.GravityVertical.CENTER))
209 | .into(holder.image);
210 | break;
211 | case CropQuarterCenterCenter:
212 | Picasso.with(mContext)
213 | .load(R.drawable.demo)
214 | .transform(new CropTransformation((float) 0.5, (float) 0.5,
215 | CropTransformation.GravityHorizontal.CENTER,
216 | CropTransformation.GravityVertical.CENTER))
217 | .into(holder.image);
218 | break;
219 | case CropQuarterCenterTop:
220 | Picasso.with(mContext)
221 | .load(R.drawable.demo)
222 | .transform(new CropTransformation((float) 0.5, (float) 0.5,
223 | CropTransformation.GravityHorizontal.CENTER,
224 | CropTransformation.GravityVertical.TOP))
225 | .into(holder.image);
226 | break;
227 | case CropQuarterBottomRight:
228 | Picasso.with(mContext)
229 | .load(R.drawable.demo)
230 | .transform(new CropTransformation((float) 0.5, (float) 0.5,
231 | CropTransformation.GravityHorizontal.RIGHT,
232 | CropTransformation.GravityVertical.BOTTOM))
233 | .into(holder.image);
234 | break;
235 | case CropHalfWidth43CenterCenter:
236 | Picasso.with(mContext)
237 | .load(R.drawable.demo)
238 | .transform(new CropTransformation((float) 0.5, 0, (float) 4 / (float) 3,
239 | CropTransformation.GravityHorizontal.CENTER,
240 | CropTransformation.GravityVertical.CENTER))
241 | .into(holder.image);
242 | break;
243 | case CropSquare:
244 | Picasso.with(mContext)
245 | .load(R.drawable.demo)
246 | .transform(new CropSquareTransformation())
247 | .into(holder.image);
248 | break;
249 | case CropCircle:
250 | Picasso.with(mContext)
251 | .load(R.drawable.demo)
252 | .transform(new CropCircleTransformation())
253 | .into(holder.image);
254 | break;
255 | case ColorFilter:
256 | Picasso.with(mContext)
257 | .load(R.drawable.demo)
258 | .transform(new ColorFilterTransformation(Color.argb(80, 255, 0, 0)))
259 | .into(holder.image);
260 | break;
261 | case Grayscale:
262 | Picasso.with(mContext)
263 | .load(R.drawable.demo)
264 | .transform(new GrayscaleTransformation())
265 | .into(holder.image);
266 | break;
267 | case RoundedCorners:
268 | Picasso.with(mContext)
269 | .load(R.drawable.demo)
270 | .transform(new RoundedCornersTransformation(30, 0,
271 | RoundedCornersTransformation.CornerType.BOTTOM_LEFT))
272 | .into(holder.image);
273 | break;
274 | case Blur:
275 | Picasso.with(mContext)
276 | .load(R.drawable.check)
277 | .transform(new BlurTransformation(mContext, 25, 1))
278 | .into(holder.image);
279 | break;
280 | case Toon:
281 | Picasso.with(mContext)
282 | .load(R.drawable.demo)
283 | .transform(new ToonFilterTransformation(mContext))
284 | .into(holder.image);
285 | break;
286 | case Sepia:
287 | Picasso.with(mContext)
288 | .load(R.drawable.check)
289 | .transform(new SepiaFilterTransformation(mContext))
290 | .into(holder.image);
291 | break;
292 | case Contrast:
293 | Picasso.with(mContext)
294 | .load(R.drawable.check)
295 | .transform(new ContrastFilterTransformation(mContext, 2.0f))
296 | .into(holder.image);
297 | break;
298 | case Invert:
299 | Picasso.with(mContext)
300 | .load(R.drawable.check)
301 | .transform(new InvertFilterTransformation(mContext))
302 | .into(holder.image);
303 | break;
304 | case Pixel:
305 | Picasso.with(mContext)
306 | .load(R.drawable.check)
307 | .transform(new PixelationFilterTransformation(mContext, 20))
308 | .into(holder.image);
309 | break;
310 | case Sketch:
311 | Picasso.with(mContext)
312 | .load(R.drawable.check)
313 | .transform(new SketchFilterTransformation(mContext))
314 | .into(holder.image);
315 | break;
316 | case Swirl:
317 | Picasso.with(mContext)
318 | .load(R.drawable.check)
319 | .transform(new SwirlFilterTransformation(mContext, 0.5f, 1.0f, new PointF(0.5f, 0.5f)))
320 | .into(holder.image);
321 |
322 | break;
323 | case Brightness:
324 | Picasso.with(mContext)
325 | .load(R.drawable.check)
326 | .transform(new BrightnessFilterTransformation(mContext, 0.5f))
327 | .into(holder.image);
328 | break;
329 | case Kuawahara:
330 | Picasso.with(mContext)
331 | .load(R.drawable.check)
332 | .transform(new KuwaharaFilterTransformation(mContext, 25))
333 | .into(holder.image);
334 | break;
335 | case Vignette:
336 | Picasso.with(mContext)
337 | .load(R.drawable.check)
338 | .transform(new VignetteFilterTransformation(mContext, new PointF(0.5f, 0.5f),
339 | new float[] { 0.0f, 0.0f, 0.0f }, 0f, 0.75f))
340 | .into(holder.image);
341 | break;
342 | }
343 | holder.title.setText(mDataSet.get(position).name());
344 | }
345 |
346 | @Override public int getItemCount() {
347 | return mDataSet.size();
348 | }
349 |
350 | static class ViewHolder extends RecyclerView.ViewHolder {
351 |
352 | public ImageView image;
353 | public TextView title;
354 |
355 | ViewHolder(View itemView) {
356 | super(itemView);
357 | image = (ImageView) itemView.findViewById(R.id.image);
358 | title = (TextView) itemView.findViewById(R.id.title);
359 | }
360 | }
361 | }
362 |
--------------------------------------------------------------------------------
/example/src/main/java/jp/wasabeef/example/picasso/Utils.java:
--------------------------------------------------------------------------------
1 | package jp.wasabeef.example.picasso;
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/Picasso-transformations/a5c92a9b63360f695fb7a8d9d3845d29730f9731/example/src/main/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/src/main/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/Picasso-transformations/a5c92a9b63360f695fb7a8d9d3845d29730f9731/example/src/main/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/src/main/res/drawable-xhdpi/check.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/Picasso-transformations/a5c92a9b63360f695fb7a8d9d3845d29730f9731/example/src/main/res/drawable-xhdpi/check.png
--------------------------------------------------------------------------------
/example/src/main/res/drawable-xhdpi/demo.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/Picasso-transformations/a5c92a9b63360f695fb7a8d9d3845d29730f9731/example/src/main/res/drawable-xhdpi/demo.jpg
--------------------------------------------------------------------------------
/example/src/main/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/Picasso-transformations/a5c92a9b63360f695fb7a8d9d3845d29730f9731/example/src/main/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/src/main/res/drawable-xxhdpi/chat_me_mask.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/Picasso-transformations/a5c92a9b63360f695fb7a8d9d3845d29730f9731/example/src/main/res/drawable-xxhdpi/chat_me_mask.9.png
--------------------------------------------------------------------------------
/example/src/main/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/Picasso-transformations/a5c92a9b63360f695fb7a8d9d3845d29730f9731/example/src/main/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/src/main/res/drawable-xxhdpi/mask_starfish.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/Picasso-transformations/a5c92a9b63360f695fb7a8d9d3845d29730f9731/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 |
24 |
25 |
--------------------------------------------------------------------------------
/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 | picasso-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.1.0
2 | GROUP=jp.wasabeef
3 | ARTIFACT_ID=picasso-transformations
4 |
5 | COMPILE_SDK_VERSION=23
6 | BUILD_TOOLS_VERSION=23.0.2
7 | TARGET_SDK_VERSION=23
8 | MIN_SDK_VERSION=11
9 |
10 | POM_DESCRIPTION=which provides simple Tranformations to Picasso
11 | POM_URL=https://github.com/wasabeef/picasso-transformations
12 | POM_SCM_URL=scm:git@github.com:wasabeef/picasso-transformations.git
13 | POM_SCM_CONNECTION=scm:git@github.com:wasabeef/picasso-transformations.git
14 | POM_SCM_DEV_CONNECTION=scm:git@github.com:wasabeef/picasso-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/picasso-transformations/issues
23 |
24 | SUPPORT_PACKAGE_VERSION=23.1.1
25 | PICASSO_VERSION=2.5.2
26 | GPUIMAGE_VERSION=1.4.1
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/Picasso-transformations/a5c92a9b63360f695fb7a8d9d3845d29730f9731/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 |
--------------------------------------------------------------------------------
/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.squareup.picasso:picasso:${PICASSO_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 | -keepclasseswithmembernames class * {
2 | native ;
3 | }
4 |
5 | -keep class android.support.v8.renderscript.** { *; }
6 |
7 | -dontwarn jp.co.cyberagent.android.gpuimage.**
--------------------------------------------------------------------------------
/transformations/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
--------------------------------------------------------------------------------
/transformations/src/main/java/jp/wasabeef/picasso/transformations/BlurTransformation.java:
--------------------------------------------------------------------------------
1 | package jp.wasabeef.picasso.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.squareup.picasso.Transformation;
26 | import jp.wasabeef.picasso.transformations.internal.FastBlur;
27 | import jp.wasabeef.picasso.transformations.internal.RSBlur;
28 |
29 | public class BlurTransformation implements Transformation {
30 |
31 | private static int MAX_RADIUS = 25;
32 | private static int DEFAULT_DOWN_SAMPLING = 1;
33 |
34 | private Context mContext;
35 |
36 | private int mRadius;
37 | private int mSampling;
38 |
39 | public BlurTransformation(Context context) {
40 | this(context, MAX_RADIUS, DEFAULT_DOWN_SAMPLING);
41 | }
42 |
43 | public BlurTransformation(Context context, int radius) {
44 | this(context, radius, DEFAULT_DOWN_SAMPLING);
45 | }
46 |
47 | public BlurTransformation(Context context, int radius, int sampling) {
48 | mContext = context.getApplicationContext();
49 | mRadius = radius;
50 | mSampling = sampling;
51 | }
52 |
53 | @Override public Bitmap transform(Bitmap source) {
54 |
55 | int scaledWidth = source.getWidth() / mSampling;
56 | int scaledHeight = source.getHeight() / mSampling;
57 |
58 | Bitmap bitmap = Bitmap.createBitmap(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
59 |
60 | Canvas canvas = new Canvas(bitmap);
61 | canvas.scale(1 / (float) mSampling, 1 / (float) mSampling);
62 | Paint paint = new Paint();
63 | paint.setFlags(Paint.FILTER_BITMAP_FLAG);
64 | canvas.drawBitmap(source, 0, 0, paint);
65 |
66 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
67 | try {
68 | bitmap = RSBlur.blur(mContext, bitmap, mRadius);
69 | } catch (RSRuntimeException e) {
70 | bitmap = FastBlur.blur(bitmap, mRadius, true);
71 | }
72 | } else {
73 | bitmap = FastBlur.blur(bitmap, mRadius, true);
74 | }
75 |
76 | source.recycle();
77 |
78 | return bitmap;
79 | }
80 |
81 | @Override public String key() {
82 | return "BlurTransformation(radius=" + mRadius + ", sampling=" + mSampling + ")";
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/transformations/src/main/java/jp/wasabeef/picasso/transformations/ColorFilterTransformation.java:
--------------------------------------------------------------------------------
1 | package jp.wasabeef.picasso.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.graphics.Bitmap;
20 | import android.graphics.Canvas;
21 | import android.graphics.Paint;
22 | import android.graphics.PorterDuff;
23 | import android.graphics.PorterDuffColorFilter;
24 | import com.squareup.picasso.Transformation;
25 |
26 | public class ColorFilterTransformation implements Transformation {
27 |
28 | private int mColor;
29 |
30 | public ColorFilterTransformation(int color) {
31 | mColor = color;
32 | }
33 |
34 | @Override public Bitmap transform(Bitmap source) {
35 |
36 | int width = source.getWidth();
37 | int height = source.getHeight();
38 |
39 | Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
40 |
41 | Canvas canvas = new Canvas(bitmap);
42 | Paint paint = new Paint();
43 | paint.setAntiAlias(true);
44 | paint.setColorFilter(new PorterDuffColorFilter(mColor, PorterDuff.Mode.SRC_ATOP));
45 | canvas.drawBitmap(source, 0, 0, paint);
46 | source.recycle();
47 |
48 | return bitmap;
49 | }
50 |
51 | @Override public String key() {
52 | return "ColorFilterTransformation(color=" + mColor + ")";
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/transformations/src/main/java/jp/wasabeef/picasso/transformations/CropCircleTransformation.java:
--------------------------------------------------------------------------------
1 | package jp.wasabeef.picasso.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.graphics.Bitmap;
20 | import android.graphics.BitmapShader;
21 | import android.graphics.Canvas;
22 | import android.graphics.Matrix;
23 | import android.graphics.Paint;
24 | import com.squareup.picasso.Transformation;
25 |
26 | public class CropCircleTransformation implements Transformation {
27 |
28 | @Override public Bitmap transform(Bitmap source) {
29 | int size = Math.min(source.getWidth(), source.getHeight());
30 |
31 | int width = (source.getWidth() - size) / 2;
32 | int height = (source.getHeight() - size) / 2;
33 |
34 | Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
35 |
36 | Canvas canvas = new Canvas(bitmap);
37 | Paint paint = new Paint();
38 | BitmapShader shader =
39 | new BitmapShader(source, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP);
40 | if (width != 0 || height != 0) {
41 | // source isn't square, move viewport to center
42 | Matrix matrix = new Matrix();
43 | matrix.setTranslate(-width, -height);
44 | shader.setLocalMatrix(matrix);
45 | }
46 | paint.setShader(shader);
47 | paint.setAntiAlias(true);
48 |
49 | float r = size / 2f;
50 | canvas.drawCircle(r, r, r, paint);
51 |
52 | source.recycle();
53 |
54 | return bitmap;
55 | }
56 |
57 | @Override public String key() {
58 | return "CropCircleTransformation()";
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/transformations/src/main/java/jp/wasabeef/picasso/transformations/CropSquareTransformation.java:
--------------------------------------------------------------------------------
1 | package jp.wasabeef.picasso.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.graphics.Bitmap;
20 | import com.squareup.picasso.Transformation;
21 |
22 | public class CropSquareTransformation implements Transformation {
23 |
24 | private int mWidth;
25 | private int mHeight;
26 |
27 | @Override public Bitmap transform(Bitmap source) {
28 | int size = Math.min(source.getWidth(), source.getHeight());
29 |
30 | mWidth = (source.getWidth() - size) / 2;
31 | mHeight = (source.getHeight() - size) / 2;
32 |
33 | Bitmap bitmap = Bitmap.createBitmap(source, mWidth, mHeight, size, size);
34 | if (bitmap != source) {
35 | source.recycle();
36 | }
37 |
38 | return bitmap;
39 | }
40 |
41 | @Override public String key() {
42 | return "CropSquareTransformation(width=" + mWidth + ", height=" + mHeight + ")";
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/transformations/src/main/java/jp/wasabeef/picasso/transformations/CropTransformation.java:
--------------------------------------------------------------------------------
1 | package jp.wasabeef.picasso.transformations;
2 |
3 | /**
4 | * Copyright (C) 2015 Wasabeef, molexx
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | import android.graphics.Bitmap;
20 | import android.graphics.Canvas;
21 | import android.graphics.Rect;
22 | import android.util.Log;
23 | import com.squareup.picasso.Transformation;
24 |
25 | /**
26 | * Crops a rectangle, allowing its dimensions and positioning to be specified by a combination of:
27 | * width/height in pixels
28 | * width/height as a ratio of the source image
29 | * aspect ratio
30 | * offset from left/top in pixels
31 | * horizontal and vertical gravity
32 | *
33 | * If aspect ratio is provided then both width and height should not be provided or the ratio wil
34 | * be
35 | * ignored.
36 | * If neither width or height are provided then the aspect ratio is used to crop the largest
37 | * possible image.
38 | *
39 | * Constructors accepting width and height expect pixels if the values are ints and ratio of source
40 | * image if the
41 | * values are floats.
42 | */
43 | public class CropTransformation implements Transformation {
44 | private static final String TAG = "PicassoTransformation";
45 |
46 | public enum GravityHorizontal {
47 | LEFT,
48 | CENTER,
49 | RIGHT
50 | }
51 |
52 | public enum GravityVertical {
53 | TOP,
54 | CENTER,
55 | BOTTOM
56 | }
57 |
58 | private float mAspectRatio;
59 | private int mLeft;
60 | private int mTop;
61 | private int mWidth;
62 | private int mHeight;
63 | private float mWidthRatio;
64 | private float mHeightRatio;
65 | private GravityHorizontal mGravityHorizontal = GravityHorizontal.CENTER;
66 | private GravityVertical mGravityVertical = GravityVertical.CENTER;
67 |
68 | /**
69 | * Crops to the given size and offset in pixels.
70 | * If either width or height is zero then the original image's dimension is used.
71 | *
72 | * @param left offset in pixels from the left edge of the source image
73 | * @param top offset in pixels from the top of the source image
74 | * @param width in pixels
75 | * @param height in pixels
76 | */
77 | public CropTransformation(int left, int top, int width, int height) {
78 | mLeft = left;
79 | mTop = top;
80 | mWidth = width;
81 | mHeight = height;
82 | }
83 |
84 | /**
85 | * Crops to the given width and height (in pixels) using the given gravity.
86 | * If either width or height is zero then the original image's dimension is used.
87 | *
88 | * @param width in pixels
89 | * @param height in pixels
90 | * @param gravityHorizontal position of the cropped area within the larger source image
91 | * @param gravityVertical position of the cropped area within the larger source image
92 | */
93 | public CropTransformation(int width, int height, GravityHorizontal gravityHorizontal,
94 | GravityVertical gravityVertical) {
95 | mWidth = width;
96 | mHeight = height;
97 | mGravityHorizontal = gravityHorizontal;
98 | mGravityVertical = gravityVertical;
99 | }
100 |
101 | /**
102 | * Crops to the given width and height (in pixels), defaulting gravity to CENTER/CENTER.
103 | * If either width or height is zero then the original image's dimension is used.
104 | *
105 | * @param width in pixels
106 | * @param height in pixels
107 | */
108 | public CropTransformation(int width, int height) {
109 | this(width, height, GravityHorizontal.CENTER, GravityVertical.CENTER);
110 | }
111 |
112 | /**
113 | * Crops to a ratio of the source image's width/height.
114 | *
115 | * e.g. (0.5, 0.5, LEFT, TOP) will crop a quarter-sized box from the top left of the original.
116 | *
117 | * If widthRatio or heightRatio are zero then 100% of the original image's dimension will be
118 | * used.
119 | *
120 | * @param widthRatio width of the target image relative to the width of the source image; 1 =
121 | * 100%
122 | * @param heightRatio height of the target image relative to the height of the source image; 1 =
123 | * 100%
124 | * @param gravityHorizontal position of the cropped area within the larger source image
125 | * @param gravityVertical position of the cropped area within the larger source image
126 | */
127 | public CropTransformation(float widthRatio, float heightRatio,
128 | GravityHorizontal gravityHorizontal, GravityVertical gravityVertical) {
129 | mWidthRatio = widthRatio;
130 | mHeightRatio = heightRatio;
131 | mGravityHorizontal = gravityHorizontal;
132 | mGravityVertical = gravityVertical;
133 | }
134 |
135 | /**
136 | * Crops to a ratio of the source image's width/height, defaulting to CENTER/CENTER gravity.
137 | *
138 | * e.g. (0.5, 0.5) will crop a quarter-sized box from the middle of the original.
139 | *
140 | * If widthRatio or heightRatio are zero then 100% of the original image's dimension will be
141 | * used.
142 | *
143 | * @param widthRatio width of the target image relative to the width of the source image; 1 =
144 | * 100%
145 | * @param heightRatio height of the target image relative to the height of the source image; 1 =
146 | * 100%
147 | */
148 | public CropTransformation(float widthRatio, float heightRatio) {
149 | this(widthRatio, heightRatio, GravityHorizontal.CENTER, GravityVertical.CENTER);
150 | }
151 |
152 | /**
153 | * Crops to the desired aspectRatio driven by either width OR height in pixels.
154 | * If one of width/height is greater than zero the other is calculated
155 | * If width and height are both zero then the largest area matching the aspectRatio is returned
156 | * If both width and height are specified then the aspectRatio is ignored
157 | *
158 | * If aspectRatio is 0 then the result will be the same as calling the version without
159 | * aspectRatio.
160 | *
161 | * @param width in pixels, one of width/height should be zero
162 | * @param height in pixels, one of width/height should be zero
163 | * @param aspectRatio width/height: greater than 1 is landscape, less than 1 is portrait, 1 is
164 | * square
165 | * @param gravityHorizontal position of the cropped area within the larger source image
166 | * @param gravityVertical position of the cropped area within the larger source image
167 | */
168 | public CropTransformation(int width, int height, float aspectRatio,
169 | GravityHorizontal gravityHorizontal, GravityVertical gravityVertical) {
170 | mWidth = width;
171 | mHeight = height;
172 | mAspectRatio = aspectRatio;
173 | mGravityHorizontal = gravityHorizontal;
174 | mGravityVertical = gravityVertical;
175 | }
176 |
177 | /**
178 | * Crops to the desired aspectRatio driven by either width OR height as a ratio to the original
179 | * image's dimension.
180 | * If one of width/height is greater than zero the other is calculated
181 | * If width and height are both zero then the largest area matching the aspectRatio is returned
182 | * If both width and height are specified then the aspectRatio is ignored
183 | *
184 | * If aspectRatio is 0 then the result will be the same as calling the version without
185 | * aspectRatio.
186 | *
187 | * e.g. to get an image with a width of 50% of the source image's width and cropped to 16:9 from
188 | * the center/center:
189 | * CropTransformation(0.5, (float)0, (float)16/9, CENTER, CENTER);
190 | *
191 | * @param widthRatio width of the target image relative to the width of the source image; 1 =
192 | * 100%
193 | * @param heightRatio height of the target image relative to the height of the source image; 1 =
194 | * 100%
195 | * @param aspectRatio width/height: greater than 1 is landscape, less than 1 is portrait, 1 is
196 | * square
197 | * @param gravityHorizontal position of the cropped area within the larger source image
198 | * @param gravityVertical position of the cropped area within the larger source image
199 | */
200 | public CropTransformation(float widthRatio, float heightRatio, float aspectRatio,
201 | GravityHorizontal gravityHorizontal, GravityVertical gravityVertical) {
202 | mWidthRatio = widthRatio;
203 | mHeightRatio = heightRatio;
204 | mAspectRatio = aspectRatio;
205 | mGravityHorizontal = gravityHorizontal;
206 | mGravityVertical = gravityVertical;
207 | }
208 |
209 | /**
210 | * Crops to the largest image that will fit the given aspectRatio.
211 | * This will effectively chop off either the top/bottom or left/right of the source image.
212 | *
213 | * @param aspectRatio width/height: greater than 1 is landscape, less than 1 is portrait, 1 is
214 | * square
215 | * @param gravityHorizontal position of the cropped area within the larger source image
216 | * @param gravityVertical position of the cropped area within the larger source image
217 | */
218 | public CropTransformation(float aspectRatio, GravityHorizontal gravityHorizontal,
219 | GravityVertical gravityVertical) {
220 | mAspectRatio = aspectRatio;
221 | mGravityHorizontal = gravityHorizontal;
222 | mGravityVertical = gravityVertical;
223 | }
224 |
225 | @Override public Bitmap transform(Bitmap source) {
226 | if (Log.isLoggable(TAG, Log.VERBOSE)) Log.v(TAG, "transform(): called, " + key());
227 |
228 | if (mWidth == 0 && mWidthRatio != 0) {
229 | mWidth = (int) ((float) source.getWidth() * mWidthRatio);
230 | }
231 | if (mHeight == 0 && mHeightRatio != 0) {
232 | mHeight = (int) ((float) source.getHeight() * mHeightRatio);
233 | }
234 |
235 | if (mAspectRatio != 0) {
236 | if (mWidth == 0 && mHeight == 0) {
237 | float sourceRatio = (float) source.getWidth() / (float) source.getHeight();
238 |
239 | if (Log.isLoggable(TAG, Log.VERBOSE)) {
240 | Log.v(TAG,
241 | "transform(): mAspectRatio: " + mAspectRatio + ", sourceRatio: " + sourceRatio);
242 | }
243 |
244 | if (sourceRatio > mAspectRatio) {
245 | // source is wider than we want, restrict by height
246 | mHeight = source.getHeight();
247 | } else {
248 | // source is taller than we want, restrict by width
249 | mWidth = source.getWidth();
250 | }
251 | }
252 |
253 | if (Log.isLoggable(TAG, Log.VERBOSE)) {
254 | Log.v(TAG, "transform(): before setting other of h/w: mAspectRatio: " + mAspectRatio
255 | + ", set one of width: " + mWidth + ", height: " + mHeight);
256 | }
257 |
258 | if (mWidth != 0) {
259 | mHeight = (int) ((float) mWidth / mAspectRatio);
260 | } else {
261 | if (mHeight != 0) {
262 | mWidth = (int) ((float) mHeight * mAspectRatio);
263 | }
264 | }
265 |
266 | if (Log.isLoggable(TAG, Log.VERBOSE)) {
267 | Log.v(TAG,
268 | "transform(): mAspectRatio: " + mAspectRatio + ", set width: " + mWidth + ", height: "
269 | + mHeight);
270 | }
271 | }
272 |
273 | if (mWidth == 0) {
274 | mWidth = source.getWidth();
275 | }
276 |
277 | if (mHeight == 0) {
278 | mHeight = source.getHeight();
279 | }
280 |
281 | if (mGravityHorizontal != null) {
282 | mLeft = getLeft(source);
283 | }
284 | if (mGravityVertical != null) {
285 | mTop = getTop(source);
286 | }
287 |
288 | Rect sourceRect = new Rect(mLeft, mTop, (mLeft + mWidth), (mTop + mHeight));
289 | Rect targetRect = new Rect(0, 0, mWidth, mHeight);
290 |
291 | if (Log.isLoggable(TAG, Log.VERBOSE)) {
292 | Log.v(TAG,
293 | "transform(): created sourceRect with mLeft: " + mLeft + ", mTop: " + mTop + ", right: "
294 | + (mLeft + mWidth) + ", bottom: " + (mTop + mHeight));
295 | }
296 | if (Log.isLoggable(TAG, Log.VERBOSE)) {
297 | Log.v(TAG, "transform(): created targetRect with width: " + mWidth + ", height: " + mHeight);
298 | }
299 |
300 | Bitmap bitmap = Bitmap.createBitmap(mWidth, mHeight, Bitmap.Config.ARGB_8888);
301 | Canvas canvas = new Canvas(bitmap);
302 | if (Log.isLoggable(TAG, Log.VERBOSE)) {
303 | Log.v(TAG, "transform(): copying from source with width: " + source.getWidth() + ", height: "
304 | + source.getHeight());
305 | }
306 | canvas.drawBitmap(source, sourceRect, targetRect, null);
307 |
308 | source.recycle();
309 |
310 | if (Log.isLoggable(TAG, Log.VERBOSE)) {
311 | Log.v(TAG, "transform(): returning bitmap with width: " + bitmap.getWidth() + ", height: "
312 | + bitmap.getHeight());
313 | }
314 |
315 | return bitmap;
316 | }
317 |
318 | @Override public String key() {
319 | return "CropTransformation(width=" + mWidth + ", height=" + mHeight + ", mWidthRatio="
320 | + mWidthRatio + ", mHeightRatio=" + mHeightRatio + ", mAspectRatio=" + mAspectRatio
321 | + ", gravityHorizontal=" + mGravityHorizontal + ", mGravityVertical=" + mGravityVertical
322 | + ")";
323 | }
324 |
325 | private int getTop(Bitmap source) {
326 | switch (mGravityVertical) {
327 | case TOP:
328 | return 0;
329 | case CENTER:
330 | return (source.getHeight() - mHeight) / 2;
331 | case BOTTOM:
332 | return source.getHeight() - mHeight;
333 | default:
334 | return 0;
335 | }
336 | }
337 |
338 | private int getLeft(Bitmap source) {
339 | switch (mGravityHorizontal) {
340 | case LEFT:
341 | return 0;
342 | case CENTER:
343 | return (source.getWidth() - mWidth) / 2;
344 | case RIGHT:
345 | return source.getWidth() - mWidth;
346 | default:
347 | return 0;
348 | }
349 | }
350 | }
351 |
--------------------------------------------------------------------------------
/transformations/src/main/java/jp/wasabeef/picasso/transformations/GrayscaleTransformation.java:
--------------------------------------------------------------------------------
1 | package jp.wasabeef.picasso.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.graphics.Bitmap;
20 | import android.graphics.Canvas;
21 | import android.graphics.ColorMatrix;
22 | import android.graphics.ColorMatrixColorFilter;
23 | import android.graphics.Paint;
24 | import com.squareup.picasso.Transformation;
25 |
26 | public class GrayscaleTransformation implements Transformation {
27 |
28 | @Override public Bitmap transform(Bitmap source) {
29 |
30 | int width = source.getWidth();
31 | int height = source.getHeight();
32 |
33 | Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
34 |
35 | Canvas canvas = new Canvas(bitmap);
36 | ColorMatrix saturation = new ColorMatrix();
37 | saturation.setSaturation(0f);
38 | Paint paint = new Paint();
39 | paint.setColorFilter(new ColorMatrixColorFilter(saturation));
40 | canvas.drawBitmap(source, 0, 0, paint);
41 | source.recycle();
42 |
43 | return bitmap;
44 | }
45 |
46 | @Override public String key() {
47 | return "GrayscaleTransformation()";
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/transformations/src/main/java/jp/wasabeef/picasso/transformations/MaskTransformation.java:
--------------------------------------------------------------------------------
1 | package jp.wasabeef.picasso.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.squareup.picasso.Transformation;
27 | import jp.wasabeef.picasso.transformations.internal.Utils;
28 |
29 | public class MaskTransformation implements Transformation {
30 |
31 | private static Paint mMaskingPaint = new Paint();
32 | private Context mContext;
33 | private int mMaskId;
34 |
35 | static {
36 | mMaskingPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
37 | }
38 |
39 | /**
40 | * @param maskId If you change the mask file, please also rename the mask file, or Glide will get
41 | * the cache with the old mask. Because getId() return the same values if using the
42 | * same make file name. If you have a good idea please tell us, thanks.
43 | */
44 | public MaskTransformation(Context context, int maskId) {
45 | mContext = context.getApplicationContext();
46 | mMaskId = maskId;
47 | }
48 |
49 | @Override public Bitmap transform(Bitmap source) {
50 | int width = source.getWidth();
51 | int height = source.getHeight();
52 |
53 | Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
54 |
55 | Drawable mask = Utils.getMaskDrawable(mContext, mMaskId);
56 |
57 | Canvas canvas = new Canvas(result);
58 | mask.setBounds(0, 0, width, height);
59 | mask.draw(canvas);
60 | canvas.drawBitmap(source, 0, 0, mMaskingPaint);
61 |
62 | source.recycle();
63 |
64 | return result;
65 | }
66 |
67 | @Override public String key() {
68 | return "MaskTransformation(maskId=" + mContext.getResources().getResourceEntryName(mMaskId)
69 | + ")";
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/transformations/src/main/java/jp/wasabeef/picasso/transformations/RoundedCornersTransformation.java:
--------------------------------------------------------------------------------
1 | package jp.wasabeef.picasso.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.graphics.Bitmap;
20 | import android.graphics.BitmapShader;
21 | import android.graphics.Canvas;
22 | import android.graphics.Paint;
23 | import android.graphics.RectF;
24 | import android.graphics.Shader;
25 | import com.squareup.picasso.Transformation;
26 |
27 | public class RoundedCornersTransformation implements Transformation {
28 |
29 | public enum CornerType {
30 | ALL,
31 | TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT,
32 | TOP, BOTTOM, LEFT, RIGHT,
33 | OTHER_TOP_LEFT, OTHER_TOP_RIGHT, OTHER_BOTTOM_LEFT, OTHER_BOTTOM_RIGHT,
34 | DIAGONAL_FROM_TOP_LEFT, DIAGONAL_FROM_TOP_RIGHT
35 | }
36 |
37 | private int mRadius;
38 | private int mDiameter;
39 | private int mMargin;
40 | private CornerType mCornerType;
41 |
42 | public RoundedCornersTransformation(int radius, int margin) {
43 | this(radius, margin, CornerType.ALL);
44 | }
45 |
46 | public RoundedCornersTransformation(int radius, int margin, CornerType cornerType) {
47 | mRadius = radius;
48 | mDiameter = radius * 2;
49 | mMargin = margin;
50 | mCornerType = cornerType;
51 | }
52 |
53 | @Override public Bitmap transform(Bitmap source) {
54 |
55 | int width = source.getWidth();
56 | int height = source.getHeight();
57 |
58 | Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
59 |
60 | Canvas canvas = new Canvas(bitmap);
61 | Paint paint = new Paint();
62 | paint.setAntiAlias(true);
63 | paint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
64 | drawRoundRect(canvas, paint, width, height);
65 | source.recycle();
66 |
67 | return bitmap;
68 | }
69 |
70 | private void drawRoundRect(Canvas canvas, Paint paint, float width, float height) {
71 | float right = width - mMargin;
72 | float bottom = height - mMargin;
73 |
74 | switch (mCornerType) {
75 | case ALL:
76 | canvas.drawRoundRect(new RectF(mMargin, mMargin, right, bottom), mRadius, mRadius, paint);
77 | break;
78 | case TOP_LEFT:
79 | drawTopLeftRoundRect(canvas, paint, right, bottom);
80 | break;
81 | case TOP_RIGHT:
82 | drawTopRightRoundRect(canvas, paint, right, bottom);
83 | break;
84 | case BOTTOM_LEFT:
85 | drawBottomLeftRoundRect(canvas, paint, right, bottom);
86 | break;
87 | case BOTTOM_RIGHT:
88 | drawBottomRightRoundRect(canvas, paint, right, bottom);
89 | break;
90 | case TOP:
91 | drawTopRoundRect(canvas, paint, right, bottom);
92 | break;
93 | case BOTTOM:
94 | drawBottomRoundRect(canvas, paint, right, bottom);
95 | break;
96 | case LEFT:
97 | drawLeftRoundRect(canvas, paint, right, bottom);
98 | break;
99 | case RIGHT:
100 | drawRightRoundRect(canvas, paint, right, bottom);
101 | break;
102 | case OTHER_TOP_LEFT:
103 | drawOtherTopLeftRoundRect(canvas, paint, right, bottom);
104 | break;
105 | case OTHER_TOP_RIGHT:
106 | drawOtherTopRightRoundRect(canvas, paint, right, bottom);
107 | break;
108 | case OTHER_BOTTOM_LEFT:
109 | drawOtherBottomLeftRoundRect(canvas, paint, right, bottom);
110 | break;
111 | case OTHER_BOTTOM_RIGHT:
112 | drawOtherBottomRightRoundRect(canvas, paint, right, bottom);
113 | break;
114 | case DIAGONAL_FROM_TOP_LEFT:
115 | drawDiagonalFromTopLeftRoundRect(canvas, paint, right, bottom);
116 | break;
117 | case DIAGONAL_FROM_TOP_RIGHT:
118 | drawDiagonalFromTopRightRoundRect(canvas, paint, right, bottom);
119 | break;
120 | default:
121 | canvas.drawRoundRect(new RectF(mMargin, mMargin, right, bottom), mRadius, mRadius, paint);
122 | break;
123 | }
124 | }
125 |
126 | private void drawTopLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
127 | canvas.drawRoundRect(new RectF(mMargin, mMargin, mMargin + mDiameter, mMargin + mDiameter),
128 | mRadius, mRadius, paint);
129 | canvas.drawRect(new RectF(mMargin, mMargin + mRadius, mMargin + mRadius, bottom), paint);
130 | canvas.drawRect(new RectF(mMargin + mRadius, mMargin, right, bottom), paint);
131 | }
132 |
133 | private void drawTopRightRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
134 | canvas.drawRoundRect(new RectF(right - mDiameter, mMargin, right, mMargin + mDiameter), mRadius,
135 | mRadius, paint);
136 | canvas.drawRect(new RectF(mMargin, mMargin, right - mRadius, bottom), paint);
137 | canvas.drawRect(new RectF(right - mRadius, mMargin + mRadius, right, bottom), paint);
138 | }
139 |
140 | private void drawBottomLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
141 | canvas.drawRoundRect(new RectF(mMargin, bottom - mDiameter, mMargin + mDiameter, bottom),
142 | mRadius, mRadius, paint);
143 | canvas.drawRect(new RectF(mMargin, mMargin, mMargin + mDiameter, bottom - mRadius), paint);
144 | canvas.drawRect(new RectF(mMargin + mRadius, mMargin, right, bottom), paint);
145 | }
146 |
147 | private void drawBottomRightRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
148 | canvas.drawRoundRect(new RectF(right - mDiameter, bottom - mDiameter, right, bottom), mRadius,
149 | mRadius, paint);
150 | canvas.drawRect(new RectF(mMargin, mMargin, right - mRadius, bottom), paint);
151 | canvas.drawRect(new RectF(right - mRadius, mMargin, right, bottom - mRadius), paint);
152 | }
153 |
154 | private void drawTopRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
155 | canvas.drawRoundRect(new RectF(mMargin, mMargin, right, mMargin + mDiameter), mRadius, mRadius,
156 | paint);
157 | canvas.drawRect(new RectF(mMargin, mMargin + mRadius, right, bottom), paint);
158 | }
159 |
160 | private void drawBottomRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
161 | canvas.drawRoundRect(new RectF(mMargin, bottom - mDiameter, right, bottom), mRadius, mRadius,
162 | paint);
163 | canvas.drawRect(new RectF(mMargin, mMargin, right, bottom - mRadius), paint);
164 | }
165 |
166 | private void drawLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
167 | canvas.drawRoundRect(new RectF(mMargin, mMargin, mMargin + mDiameter, bottom), mRadius, mRadius,
168 | paint);
169 | canvas.drawRect(new RectF(mMargin + mRadius, mMargin, right, bottom), paint);
170 | }
171 |
172 | private void drawRightRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
173 | canvas.drawRoundRect(new RectF(right - mDiameter, mMargin, right, bottom), mRadius, mRadius,
174 | paint);
175 | canvas.drawRect(new RectF(mMargin, mMargin, right - mRadius, bottom), paint);
176 | }
177 |
178 | private void drawOtherTopLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
179 | canvas.drawRoundRect(new RectF(mMargin, bottom - mDiameter, right, bottom), mRadius, mRadius,
180 | paint);
181 | canvas.drawRoundRect(new RectF(right - mDiameter, mMargin, right, bottom), mRadius, mRadius,
182 | paint);
183 | canvas.drawRect(new RectF(mMargin, mMargin, right - mRadius, bottom - mRadius), paint);
184 | }
185 |
186 | private void drawOtherTopRightRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
187 | canvas.drawRoundRect(new RectF(mMargin, mMargin, mMargin + mDiameter, bottom), mRadius, mRadius,
188 | paint);
189 | canvas.drawRoundRect(new RectF(mMargin, bottom - mDiameter, right, bottom), mRadius, mRadius,
190 | paint);
191 | canvas.drawRect(new RectF(mMargin + mRadius, mMargin, right, bottom - mRadius), paint);
192 | }
193 |
194 | private void drawOtherBottomLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
195 | canvas.drawRoundRect(new RectF(mMargin, mMargin, right, mMargin + mDiameter), mRadius, mRadius,
196 | paint);
197 | canvas.drawRoundRect(new RectF(right - mDiameter, mMargin, right, bottom), mRadius, mRadius,
198 | paint);
199 | canvas.drawRect(new RectF(mMargin, mMargin + mRadius, right - mRadius, bottom), paint);
200 | }
201 |
202 | private void drawOtherBottomRightRoundRect(Canvas canvas, Paint paint, float right,
203 | float bottom) {
204 | canvas.drawRoundRect(new RectF(mMargin, mMargin, right, mMargin + mDiameter), mRadius, mRadius,
205 | paint);
206 | canvas.drawRoundRect(new RectF(mMargin, mMargin, mMargin + mDiameter, bottom), mRadius, mRadius,
207 | paint);
208 | canvas.drawRect(new RectF(mMargin + mRadius, mMargin + mRadius, right, bottom), paint);
209 | }
210 |
211 | private void drawDiagonalFromTopLeftRoundRect(Canvas canvas, Paint paint, float right,
212 | float bottom) {
213 | canvas.drawRoundRect(new RectF(mMargin, mMargin, mMargin + mDiameter, mMargin + mDiameter),
214 | mRadius, mRadius, paint);
215 | canvas.drawRoundRect(new RectF(right - mDiameter, bottom - mDiameter, right, bottom), mRadius,
216 | mRadius, paint);
217 | canvas.drawRect(new RectF(mMargin, mMargin + mRadius, right - mDiameter, bottom), paint);
218 | canvas.drawRect(new RectF(mMargin + mDiameter, mMargin, right, bottom - mRadius), paint);
219 | }
220 |
221 | private void drawDiagonalFromTopRightRoundRect(Canvas canvas, Paint paint, float right,
222 | float bottom) {
223 | canvas.drawRoundRect(new RectF(right - mDiameter, mMargin, right, mMargin + mDiameter), mRadius,
224 | mRadius, paint);
225 | canvas.drawRoundRect(new RectF(mMargin, bottom - mDiameter, mMargin + mDiameter, bottom),
226 | mRadius, mRadius, paint);
227 | canvas.drawRect(new RectF(mMargin, mMargin, right - mRadius, bottom - mRadius), paint);
228 | canvas.drawRect(new RectF(mMargin + mRadius, mMargin + mRadius, right, bottom), paint);
229 | }
230 |
231 | @Override public String key() {
232 | return "RoundedTransformation(radius=" + mRadius + ", margin=" + mMargin + ", diameter="
233 | + mDiameter + ", cornerType=" + mCornerType.name() + ")";
234 | }
235 | }
236 |
--------------------------------------------------------------------------------
/transformations/src/main/java/jp/wasabeef/picasso/transformations/gpu/BrightnessFilterTransformation.java:
--------------------------------------------------------------------------------
1 | package jp.wasabeef.picasso.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 jp.co.cyberagent.android.gpuimage.GPUImageBrightnessFilter;
21 |
22 | /**
23 | * brightness value ranges from -1.0 to 1.0, with 0.0 as the normal level
24 | */
25 | public class BrightnessFilterTransformation extends GPUFilterTransformation {
26 |
27 | private float mBrightness;
28 |
29 | public BrightnessFilterTransformation(Context context) {
30 | this(context, 0.0f);
31 | }
32 |
33 | public BrightnessFilterTransformation(Context context, float brightness) {
34 | super(context, new GPUImageBrightnessFilter());
35 | mBrightness = brightness;
36 | GPUImageBrightnessFilter filter = getFilter();
37 | filter.setBrightness(mBrightness);
38 | }
39 |
40 | @Override public String key() {
41 | return "BrightnessFilterTransformation(brightness=" + mBrightness + ")";
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/transformations/src/main/java/jp/wasabeef/picasso/transformations/gpu/ContrastFilterTransformation.java:
--------------------------------------------------------------------------------
1 | package jp.wasabeef.picasso.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 jp.co.cyberagent.android.gpuimage.GPUImageContrastFilter;
21 |
22 | /**
23 | * contrast value ranges from 0.0 to 4.0, with 1.0 as the normal level
24 | */
25 | public class ContrastFilterTransformation extends GPUFilterTransformation {
26 |
27 | private float mContrast;
28 |
29 | public ContrastFilterTransformation(Context context) {
30 | this(context, 1.0f);
31 | }
32 |
33 | public ContrastFilterTransformation(Context context, float contrast) {
34 | super(context, new GPUImageContrastFilter());
35 | mContrast = contrast;
36 | GPUImageContrastFilter filter = getFilter();
37 | filter.setContrast(mContrast);
38 | }
39 |
40 | @Override public String key() {
41 | return "ContrastFilterTransformation(contrast=" + mContrast + ")";
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/transformations/src/main/java/jp/wasabeef/picasso/transformations/gpu/GPUFilterTransformation.java:
--------------------------------------------------------------------------------
1 | package jp.wasabeef.picasso.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.squareup.picasso.Transformation;
22 | import jp.co.cyberagent.android.gpuimage.GPUImage;
23 | import jp.co.cyberagent.android.gpuimage.GPUImageFilter;
24 |
25 | public class GPUFilterTransformation implements Transformation {
26 |
27 | private Context mContext;
28 | private GPUImageFilter mFilter;
29 |
30 | public GPUFilterTransformation(Context context, GPUImageFilter filter) {
31 | mContext = context.getApplicationContext();
32 | mFilter = filter;
33 | }
34 |
35 | @Override public Bitmap transform(Bitmap source) {
36 | GPUImage gpuImage = new GPUImage(mContext);
37 | gpuImage.setImage(source);
38 | gpuImage.setFilter(mFilter);
39 |
40 | Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
41 | source.recycle();
42 |
43 | return bitmap;
44 | }
45 |
46 | @Override public String key() {
47 | return getClass().getSimpleName();
48 | }
49 |
50 | @SuppressWarnings("unchecked") public T getFilter() {
51 | return (T) mFilter;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/transformations/src/main/java/jp/wasabeef/picasso/transformations/gpu/InvertFilterTransformation.java:
--------------------------------------------------------------------------------
1 | package jp.wasabeef.picasso.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 jp.co.cyberagent.android.gpuimage.GPUImageColorInvertFilter;
21 |
22 | /**
23 | * Invert all the colors in the image.
24 | */
25 | public class InvertFilterTransformation extends GPUFilterTransformation {
26 |
27 | public InvertFilterTransformation(Context context) {
28 | super(context, new GPUImageColorInvertFilter());
29 | }
30 |
31 | @Override public String key() {
32 | return "InvertFilterTransformation()";
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/transformations/src/main/java/jp/wasabeef/picasso/transformations/gpu/KuwaharaFilterTransformation.java:
--------------------------------------------------------------------------------
1 | package jp.wasabeef.picasso.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 jp.co.cyberagent.android.gpuimage.GPUImageKuwaharaFilter;
21 |
22 | /**
23 | * Kuwahara all the colors in the image.
24 | *
25 | * The radius to sample from when creating the brush-stroke effect, with a default of 25.
26 | * The larger the radius, the slower the filter.
27 | */
28 | public class KuwaharaFilterTransformation extends GPUFilterTransformation {
29 |
30 | private int mRadius;
31 |
32 | public KuwaharaFilterTransformation(Context context) {
33 | this(context, 25);
34 | }
35 |
36 | public KuwaharaFilterTransformation(Context context, int radius) {
37 | super(context, new GPUImageKuwaharaFilter());
38 | mRadius = radius;
39 | GPUImageKuwaharaFilter filter = getFilter();
40 | filter.setRadius(mRadius);
41 | }
42 |
43 | @Override public String key() {
44 | return "KuwaharaFilterTransformation(radius=" + mRadius + ")";
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/transformations/src/main/java/jp/wasabeef/picasso/transformations/gpu/PixelationFilterTransformation.java:
--------------------------------------------------------------------------------
1 | package jp.wasabeef.picasso.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 jp.co.cyberagent.android.gpuimage.GPUImagePixelationFilter;
21 |
22 | /**
23 | * Applies a Pixelation effect to the image.
24 | *
25 | * The pixel with a default of 10.0.
26 | */
27 | public class PixelationFilterTransformation extends GPUFilterTransformation {
28 |
29 | private float mPixel;
30 |
31 | public PixelationFilterTransformation(Context context) {
32 | this(context, 10f);
33 | }
34 |
35 | public PixelationFilterTransformation(Context context, float pixel) {
36 | super(context, new GPUImagePixelationFilter());
37 | mPixel = pixel;
38 | GPUImagePixelationFilter filter = getFilter();
39 | filter.setPixel(mPixel);
40 | }
41 |
42 | @Override public String key() {
43 | return "PixelationFilterTransformation(pixel=" + mPixel + ")";
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/transformations/src/main/java/jp/wasabeef/picasso/transformations/gpu/SepiaFilterTransformation.java:
--------------------------------------------------------------------------------
1 | package jp.wasabeef.picasso.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 jp.co.cyberagent.android.gpuimage.GPUImageSepiaFilter;
21 |
22 | /**
23 | * Applies a simple sepia effect.
24 | *
25 | * The intensity with a default of 1.0.
26 | */
27 | public class SepiaFilterTransformation extends GPUFilterTransformation {
28 |
29 | private float mIntensity;
30 |
31 | public SepiaFilterTransformation(Context context) {
32 | this(context, 1.0f);
33 | }
34 |
35 | public SepiaFilterTransformation(Context context, float intensity) {
36 | super(context, new GPUImageSepiaFilter());
37 | mIntensity = intensity;
38 | GPUImageSepiaFilter filter = getFilter();
39 | filter.setIntensity(mIntensity);
40 | }
41 |
42 | @Override public String key() {
43 | return "SepiaFilterTransformation(intensity=" + mIntensity + ")";
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/transformations/src/main/java/jp/wasabeef/picasso/transformations/gpu/SketchFilterTransformation.java:
--------------------------------------------------------------------------------
1 | package jp.wasabeef.picasso.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 jp.co.cyberagent.android.gpuimage.GPUImageSketchFilter;
21 |
22 | public class SketchFilterTransformation extends GPUFilterTransformation {
23 |
24 | public SketchFilterTransformation(Context context) {
25 | super(context, new GPUImageSketchFilter());
26 | }
27 |
28 | @Override public String key() {
29 | return "SketchFilterTransformation()";
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/transformations/src/main/java/jp/wasabeef/picasso/transformations/gpu/SwirlFilterTransformation.java:
--------------------------------------------------------------------------------
1 | package jp.wasabeef.picasso.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 jp.co.cyberagent.android.gpuimage.GPUImageSwirlFilter;
22 |
23 | /**
24 | * Creates a swirl distortion on the image.
25 | */
26 | public class SwirlFilterTransformation extends GPUFilterTransformation {
27 |
28 | private float mRadius;
29 | private float mAngle;
30 | private PointF mCenter;
31 |
32 | public SwirlFilterTransformation(Context context) {
33 | this(context, .5f, 1.0f, new PointF(.5f, .5f));
34 | }
35 |
36 | /**
37 | * @param radius from 0.0 to 1.0, default 0.5
38 | * @param angle minimum 0.0, default 1.0
39 | * @param center default (0.5, 0.5)
40 | */
41 | public SwirlFilterTransformation(Context context, float radius, float angle, PointF center) {
42 | super(context, new GPUImageSwirlFilter());
43 | mRadius = radius;
44 | mAngle = angle;
45 | mCenter = center;
46 | GPUImageSwirlFilter filter = getFilter();
47 | filter.setRadius(mRadius);
48 | filter.setAngle(mAngle);
49 | filter.setCenter(mCenter);
50 | }
51 |
52 | @Override public String key() {
53 | return "SwirlFilterTransformation(radius=" + mRadius +
54 | ",angle=" + mAngle + ",center=" + mCenter.toString() + ")";
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/transformations/src/main/java/jp/wasabeef/picasso/transformations/gpu/ToonFilterTransformation.java:
--------------------------------------------------------------------------------
1 | package jp.wasabeef.picasso.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 jp.co.cyberagent.android.gpuimage.GPUImageToonFilter;
21 |
22 | /**
23 | * The threshold at which to apply the edges, default of 0.2.
24 | * The levels of quantization for the posterization of colors within the scene,
25 | * with a default of 10.0.
26 | */
27 | public class ToonFilterTransformation extends GPUFilterTransformation {
28 |
29 | private float mThreshold;
30 | private float mQuantizationLevels;
31 |
32 | public ToonFilterTransformation(Context context) {
33 | this(context, .2f, 10.0f);
34 | }
35 |
36 | public ToonFilterTransformation(Context context, float threshold, float quantizationLevels) {
37 | super(context, new GPUImageToonFilter());
38 | mThreshold = threshold;
39 | mQuantizationLevels = quantizationLevels;
40 | GPUImageToonFilter filter = getFilter();
41 | filter.setThreshold(mThreshold);
42 | filter.setQuantizationLevels(mQuantizationLevels);
43 | }
44 |
45 | @Override public String key() {
46 | return "ToonFilterTransformation(threshold=" + mThreshold +
47 | ",quantizationLevels=" + mQuantizationLevels + ")";
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/transformations/src/main/java/jp/wasabeef/picasso/transformations/gpu/VignetteFilterTransformation.java:
--------------------------------------------------------------------------------
1 | package jp.wasabeef.picasso.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 java.util.Arrays;
22 | import jp.co.cyberagent.android.gpuimage.GPUImageVignetteFilter;
23 |
24 | /**
25 | * Performs a vignetting effect, fading out the image at the edges
26 | * The directional intensity of the vignetting,
27 | * with a default of x = 0.5, y = 0.5, start = 0, end = 0.75
28 | */
29 | public class VignetteFilterTransformation extends GPUFilterTransformation {
30 |
31 | private PointF mCenter;
32 | private float[] mVignetteColor;
33 | private float mVignetteStart;
34 | private float mVignetteEnd;
35 |
36 | public VignetteFilterTransformation(Context context) {
37 | this(context, new PointF(0.5f, 0.5f), new float[] { 0.0f, 0.0f, 0.0f }, 0.0f, 0.75f);
38 | }
39 |
40 | public VignetteFilterTransformation(Context context, PointF center, float[] color, float start,
41 | float end) {
42 | super(context, new GPUImageVignetteFilter());
43 | mCenter = center;
44 | mVignetteColor = color;
45 | mVignetteStart = start;
46 | mVignetteEnd = end;
47 | GPUImageVignetteFilter filter = getFilter();
48 | filter.setVignetteCenter(mCenter);
49 | filter.setVignetteColor(mVignetteColor);
50 | filter.setVignetteStart(mVignetteStart);
51 | filter.setVignetteEnd(mVignetteEnd);
52 | }
53 |
54 | @Override public String key() {
55 | return "VignetteFilterTransformation(center=" + mCenter.toString() +
56 | ",color=" + Arrays.toString(mVignetteColor) +
57 | ",start=" + mVignetteStart + ",end=" + mVignetteEnd + ")";
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/transformations/src/main/java/jp/wasabeef/picasso/transformations/internal/FastBlur.java:
--------------------------------------------------------------------------------
1 | package jp.wasabeef.picasso.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/picasso/transformations/internal/RSBlur.java:
--------------------------------------------------------------------------------
1 | package jp.wasabeef.picasso.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_MR1)
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 | Allocation input =
37 | Allocation.createFromBitmap(rs, bitmap, Allocation.MipmapControl.MIPMAP_NONE,
38 | Allocation.USAGE_SCRIPT);
39 | Allocation output = Allocation.createTyped(rs, input.getType());
40 | ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
41 |
42 | blur.setInput(input);
43 | blur.setRadius(radius);
44 | blur.forEach(output);
45 | output.copyTo(bitmap);
46 | } finally {
47 | if (rs != null) {
48 | rs.destroy();
49 | }
50 | }
51 |
52 | return bitmap;
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/transformations/src/main/java/jp/wasabeef/picasso/transformations/internal/Utils.java:
--------------------------------------------------------------------------------
1 | package jp.wasabeef.picasso.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 |
--------------------------------------------------------------------------------