1
0
mirror of https://github.com/wasabeef/glide-transformations.git synced 2025-10-04 09:53:21 +08:00

127 Commits
1.0.2 ... 3.1.1

Author SHA1 Message Date
Daichi Furiya
9b00767304 3.1.1 (#116)
* update gradle wrapeer

* fix proguard settings

* update glide

* bump up 3.1.1
2018-02-13 16:32:10 +09:00
Frederic Ye
a5f7017f57 Added TV Time as application (#114) 2018-02-13 15:26:41 +09:00
wasabeef
9e85b0b759 update sample codes 2018-02-01 16:48:27 +09:00
Daichi Furiya
51f7b515fa For Glide 4.5.0 (#112) 2018-01-26 17:08:27 +09:00
CrabeMan
43f38cc4b3 Implement equals() and hashCode() methods (#105)
* Implement equals() and hashCode() methods

* Oops: Replace by static final to prevent String class name generation for every call on hashCodes() & updateDiskCacheKey() methods
2018-01-25 17:15:27 +09:00
Daichi Furiya
970afc35fe Fixed Proguard settings (#88)
* Issue #86 - Deleted a setting for DexGuard
2017-09-08 17:18:50 -07:00
Daichi Furiya
f6cbe2722d Support Glide 4.0.0 (#83) 2017-09-07 00:47:27 -05:00
wasabeef
1264e01f6e fix format 2017-03-21 11:55:30 -07:00
wasabeef
1a474cdd8c update gradle wrapper 2017-03-21 11:53:41 -07:00
wasabeef
311bcde37f Merge branch 'master' of github.com:wasabeef/glide-transformations 2017-03-17 18:35:44 -07:00
wasabeef
945e5a8063 updated icon 2017-03-17 18:35:05 -07:00
Daichi Furiya
30b41fa167 Update README.md 2017-03-17 18:29:47 -07:00
Daichi Furiya
2a720df48d Update README.md 2017-03-17 17:47:58 -07:00
wasabeef
06db3295a1 updated art 2017-03-17 17:45:28 -07:00
Daichi Furiya
34cc92f7a4 Merge pull request #66 from wasabeef/dev
2.0.2
2017-03-17 17:41:49 -07:00
wasabeef
5715d7a999 bump up 2.0.2 2017-03-17 17:35:48 -07:00
wasabeef
36c0d00ae9 updated libs 2017-03-17 17:35:29 -07:00
wasabeef
a29346e8d2 updated sdks 2017-03-17 17:20:28 -07:00
wasabeef
c3f2ce75a4 updated gradle 2017-03-17 17:19:53 -07:00
wasabeef
4d47793f79 updated copyright 2017-03-17 17:17:37 -07:00
Daichi Furiya
45c2e3bcfe Merge pull request #45 from timusus/master
Additional resource cleanup in RSBlur
2017-03-17 15:27:20 -07:00
Tim Malseed
a139c21d31 Additional resource cleanup in RSBlur
When the blur is finished, the input, output, and blur are all destroyed, along with the renderscript instance.

This resolves a strictmode 'resource acquired but never released' violation.
2016-06-12 23:55:52 +10:00
Daichi Furiya
c3f09cdd0d Merge pull request #38 from wasabeef/v2.0.1
V2.0.1
2016-04-21 15:29:01 +09:00
wasabeef
ddd76d4f06 fix layout 2016-04-21 15:27:26 +09:00
wasabeef
f9bca8887d fix bugs issue #35 2016-04-21 15:23:22 +09:00
wasabeef
592815a6a0 update gradle 2016-04-21 15:22:58 +09:00
wasabeef
f6540b111f bump up 2.0.1 2016-04-21 15:22:46 +09:00
wasabeef
9bea464afc format 2016-04-21 15:22:21 +09:00
wasabeef
219b32bbcc format 2016-04-21 15:18:48 +09:00
Daichi Furiya
4d7190847c Merge pull request #36 from elevenfive/patch-1
Use correct field prefix
2016-04-19 13:05:36 +09:00
Matthew Zavislak
0d7a93c264 Use correct field prefix 2016-04-15 20:19:29 -07:00
Daichi Furiya
e69f775ddd Update build.gradle 2016-03-02 23:12:39 +09:00
Daichi Furiya
4b9cf87770 Update gradle-wrapper.properties 2016-03-02 23:11:59 +09:00
Daichi Furiya
cafad91b0b Update gradle-wrapper.properties 2016-03-02 23:11:43 +09:00
Daichi Furiya
933c3f7989 Merge pull request #31 from wasabeef/goodbye-v8rs
Goodbye v8.RenderScript
2016-03-02 23:11:05 +09:00
wasabeef
68bafb0f53 bump up 2.0.0 2016-03-02 23:09:31 +09:00
wasabeef
817b138980 Say v8.RenderScript goodbye 2016-03-02 22:53:34 +09:00
wasabeef
a908abc7d4 bump up 1.4.0 2016-02-28 04:58:55 +09:00
Daichi Furiya
3e0738de0a Update README.md 2016-01-31 02:57:09 +09:00
Daichi Furiya
dff7328f6e Update README.md 2015-12-11 17:50:07 +09:00
Daichi Furiya
f5cb7392d6 Update CHANGELOG.md 2015-11-27 17:56:25 +09:00
wasabeef
d8a12b02b8 bump up 1.3.1 2015-11-27 17:50:00 +09:00
wasabeef
a6a2b625ad fix leak code 2015-11-27 17:44:35 +09:00
wasabeef
f488f09b19 Merge branch 'master' of github.com:wasabeef/glide-transformations 2015-11-27 17:42:30 +09:00
Daichi Furiya
76b7e3b719 Merge pull request #25 from AAkira/fix/leak-context
Fix memory leak at BlurTransformation.
2015-11-27 17:41:57 +09:00
A.Akira
c29df80ae9 Use application context. 2015-11-27 17:38:06 +09:00
wasabeef
aef7541ea3 fix leak code and constractor 2015-11-27 17:11:58 +09:00
wasabeef
71255edcd0 Change the renderscriptTargetApi down to 20 2015-11-27 17:03:55 +09:00
wasabeef
4a268b6dbd refactor gpu transformations 2015-11-27 17:00:01 +09:00
A.Akira
eef0be6b92 Add null checking the context. 2015-11-26 10:22:18 +09:00
A.Akira
260f91e291 Use WeakReference. 2015-11-25 17:09:05 +09:00
Daichi Furiya
36ceccb38e Update README.md 2015-11-10 15:17:55 +09:00
Daichi Furiya
e3a035d5cb Update CHANGELOG.md 2015-11-10 15:17:42 +09:00
wasabeef
656ea50911 bump up 1.3.0 2015-11-10 15:10:18 +09:00
wasabeef
e2cf4fd7eb update sample 2015-11-10 15:03:58 +09:00
wasabeef
e387df2daa format 2015-11-10 15:03:49 +09:00
wasabeef
5b311f74f6 update gradle 2015-11-10 12:42:46 +09:00
Daichi Furiya
62f3ee6b4a Merge pull request #23 from kaelaela/feature/upgrade_rounded_transformation
Add round corner type
2015-11-10 12:40:38 +09:00
kaelaela
3150b4c8d5 Add round corner type 2015-10-04 15:57:46 +09:00
Daichi Furiya
410d94b7b1 Update README.md 2015-09-20 01:47:23 +09:00
Daichi Furiya
a559d8bea8 Update README.md 2015-09-20 00:53:23 +09:00
wasabeef
4629d5e375 bump up 1.2.1 2015-09-18 15:32:51 +09:00
Daichi Furiya
113200de55 Merge pull request #22 from start141/master
Replaced the mask_starfish.png
2015-09-18 15:22:49 +09:00
wasabeef
143efe2ea7 bump up 1.2.1 2015-09-18 15:14:36 +09:00
start141
fe864e498b replace mask_starfish.png 2015-09-18 14:14:09 +08:00
wasabeef
f2f1229c8d format 2015-09-18 15:09:03 +09:00
Daichi Furiya
f1246ff9ee Merge pull request #21 from start141/master
Merged NinePatchMaskTransformation to MaskTransformation
2015-09-18 15:03:32 +09:00
start141
d063aac6fa Merged NinePatchMaskTransformation to MaskTransformation
1.merged the NinePatchMaskTransformation to the maskTransformation.
2.replace mask resource.
2015-09-18 12:07:54 +08:00
start141
cb3cd88ed2 Optimize the code
1. Not to create the mask bitmap.
2. Adjust MaskTransformation’s getId()’s return.
2015-09-17 20:27:30 +08:00
start141
57fcfce9df Merge pull request #1 from wasabeef/master
Update to 1.2.0
2015-09-17 18:25:55 +08:00
Daichi Furiya
347326dafa Update README.md 2015-09-17 00:09:12 +09:00
Daichi Furiya
b4332f8c8d Update CHANGELOG.md 2015-09-17 00:08:47 +09:00
Daichi Furiya
39b9d6aa6b Update README.md 2015-09-16 23:59:48 +09:00
wasabeef
2c08c1fb5e Merge branch 'master' of github.com:wasabeef/glide-transformations 2015-09-16 23:56:07 +09:00
wasabeef
abde4c694d update documents 2015-09-16 23:52:37 +09:00
wasabeef
d5616ec9fa refactor samples 2015-09-16 23:46:49 +09:00
wasabeef
1253147c4a bump up 2015-09-16 22:49:01 +09:00
wasabeef
7614f1326a update demo 2015-09-16 22:38:28 +09:00
wasabeef
5cf3e3d934 Refactor 2015-09-16 22:38:16 +09:00
Daichi Furiya
efc447d2f7 Update README.md 2015-09-15 15:12:11 +09:00
Daichi Furiya
23b623c882 Merge pull request #19 from satorufujiwara/feature/provided_gpuimage
Change gpuimage's scope to provided.
2015-09-15 15:09:24 +09:00
Daichi Furiya
f9ea19aaae Merge pull request #18 from start141/master
Add Transformation
2015-09-15 15:09:13 +09:00
start141
831f038d29 Put the mask bitmap to the BitmapPool
put the mask bitmap to the BitmapPool when the mask is get from the
BitmapPool.
2015-09-14 19:56:51 +08:00
fujiwara-satoru
eed7b944e5 Change gpuimage's scope to provided. 2015-09-14 20:54:40 +09:00
start141
46d5d4d72f Add Transformation
Add MaskTransformation and NinePatchMaskTransformation.
2015-09-14 16:49:58 +08:00
wasabeef
6ebfdbe581 modify changelog 2015-09-06 17:34:47 +09:00
wasabeef
2a4eb22841 modify comment 2015-09-06 17:19:27 +09:00
wasabeef
2cc2104802 bump up 2015-09-06 01:29:00 +09:00
wasabeef
f83e5ef85a change the codestyle 2015-09-06 01:24:12 +09:00
wasabeef
cdbd42595a Adjustment of default parameters. 2015-09-06 01:18:40 +09:00
Daichi Furiya
987651f9da Update README.md 2015-08-12 19:26:57 +09:00
Daichi Furiya
ad376134e9 Update README.md 2015-07-25 15:36:18 +09:00
Daichi Furiya
3f695c1e9c Update CHANGELOG.md 2015-07-24 18:28:35 +09:00
wasabeef
58e25e613c update parent activity 2015-07-24 18:17:36 +09:00
wasabeef
c914548296 update readme 2015-07-24 18:17:22 +09:00
wasabeef
cfe6dc313a Added the DownSampling to BlurTransformation 2015-07-24 18:00:07 +09:00
wasabeef
136a5512c0 update changelog 2015-07-18 01:53:24 +09:00
wasabeef
32d0c1de82 fix blur not working 2015-07-18 01:47:43 +09:00
wasabeef
e23753044e format 2015-07-18 01:47:25 +09:00
wasabeef
decd2e58d5 refactor 2015-07-18 01:47:17 +09:00
wasabeef
e9d2c6d209 bump up 2015-07-18 00:18:08 +09:00
wasabeef
79e975d490 bump up 2015-04-23 12:56:01 +09:00
wasabeef
a21cfb1d86 Merge branch 'master' of github.com:wasabeef/glide-transformations 2015-04-23 12:40:25 +09:00
wasabeef
c0ab4282d9 add CropType(Top, Center, Bottom) for CropTransformation 2015-04-23 12:40:15 +09:00
Daichi Furiya
15effa238b Update README.md 2015-04-14 17:44:54 +09:00
Daichi Furiya
ef39ca2782 Merge pull request #9 from bitdeli-chef/master
Add a Bitdeli Badge to README
2015-04-14 17:40:59 +09:00
Bitdeli Chef
bdda7cdf36 Add a Bitdeli badge to README 2015-04-14 08:50:37 +00:00
Daichi Furiya
3890c84a0f Update README.md 2015-04-06 11:34:41 +09:00
wasabeef
e3c0c8d597 update gradle 2015-04-02 14:52:41 +09:00
Daichi Furiya
f7d0541a19 Update README.md 2015-04-01 23:29:37 +09:00
wasabeef
900db8bc93 Merge branch 'master' of github.com:wasabeef/glide-transformations 2015-04-01 16:05:44 +09:00
wasabeef
c241532a58 Update keystore name 2015-04-01 16:05:33 +09:00
Daichi Furiya
8f63c10eb9 Merge pull request #7 from Arkar-Aung/master
Fixed missing @ in gradle script
2015-03-27 00:19:52 +09:00
Arkar Aung
6468276c50 Fixed missing @ in gradle script 2015-03-26 15:11:33 +06:30
Daichi Furiya
e0fb7c34e0 Update README.md 2015-03-09 00:24:01 +09:00
wasabeef
4c23e38206 fix Transparency 2015-03-09 00:08:53 +09:00
Daichi Furiya
ffae37274c Update CHANGELOG.md 2015-02-13 16:11:43 +09:00
Daichi Furiya
0c6f696ba7 Update README.md 2015-02-13 16:07:45 +09:00
wasabeef
3aea08abaa bump up 2015-02-13 15:52:42 +09:00
Daichi Furiya
883c131ad6 Merge pull request #3 from yqritc/fix/bitmap-recycling
remove original bitmap resource recycling
2015-02-13 15:26:28 +09:00
ikeda_yoshihito
ee1f533999 remove original bitmap resource recycling 2015-02-13 12:31:30 +09:00
wasabeef
68a9097962 refactor: Bitmap.Config 2015-02-05 20:51:12 +09:00
wasabeef
6269999abc bump up 2015-02-04 01:00:50 +09:00
wasabeef
7e93ccd9af Merge branch 'master' of github.com:wasabeef/glide-transformations 2015-02-04 00:55:18 +09:00
wasabeef
07b7d24e13 bug fix 2015-02-04 00:54:22 +09:00
Daichi Furiya
ca648cbc7d bump up 2015-02-04 00:40:08 +09:00
Daichi Furiya
67ac3e31a4 Update CHANGELOG.md 2015-02-04 00:39:19 +09:00
60 changed files with 2121 additions and 1294 deletions

View File

@@ -1,6 +1,140 @@
Change Log
==========
Version 3.1.1 *(2018-02-13)*
----------------------------
Update:
- Glide 4.5.0 -> 4.6.1
Bug Fix:
- Fix settings fot proguard.
Version 3.1.0 *(2018-01-26)*
----------------------------
Update:
- Compile & Target SDK Version 25 -> 27
- Build Tools 26.0.1 -> 27.0.3
- Support Library 25.3.1 -> 27.0.2
- Glide 4.0.0 -> 4.5.0
Bug Fix:
- [Implement equals() and hashCode() methods #105](https://github.com/wasabeef/glide-transformations/pull/105)
- Use RenderScript#releaseAllContexts
Version 3.0.1 *(2017-09-08)*
----------------------------
Bug Fix:
- [Deleted a setting for DexGuard #86](https://github.com/wasabeef/glide-transformations/issues/86)
Version 3.0.0 *(2017-09-06)*
----------------------------
Update:
- Build Tools 25.0.2 -> 26.0.1
- Min SDK Version 11 -> 14
- Glide 3.7.0 -> 4.0.0
Feature:
- Supported Glide 4.0.0
Version 2.0.2 *(2017-03-17)*
----------------------------
Update:
- Compile & Target SDK Version 23 -> 25
- Build Tools 23.0.2 -> 25.0.2
- Support Library 23.2.1 -> 25.3.0
- GPUImage for Android 1.3.0 -> 1.4.1
Bug Fix:
- [Additional resource cleanup in RSBlur #45](https://github.com/wasabeef/glide-transformations/pull/45)
Version 2.0.1 *(2016-04-21)*
----------------------------
Fix:
[#35](https://github.com/wasabeef/glide-transformations/issues/35)
RSInvalidStateException
Version 2.0.0 *(2016-03-02)*
----------------------------
Say v8.RenderScript goodbye
Version 1.4.0 *(2016-02-28)*
----------------------------
fix Issue [#29](https://github.com/wasabeef/glide-transformations/issues/29)
Use FastBlur as a fallback upon RenderScript failure.
Version 1.3.1 *(2015-11-27)*
----------------------------
Change the renderscriptTargetApi down to 20.
Warning:Renderscript support mode is not currently supported with renderscript target 21+
fix: memory leak.
Version 1.3.0 *(2015-11-10)*
----------------------------
add round corner type to RoundedCornersTransformation.
Thanks to [kaelaela](https://github.com/kaelaela)
Version 1.2.1 *(2015-09-18)*
----------------------------
Merged NinePatchMaskTransformation to MaskTransformation.
Version 1.2.0 *(2015-09-16)*
----------------------------
add new transformations MaskTransformation and NinePatchMaskTransformation.
Thanks to [start141](https://github.com/start141)
Version 1.1.0 *(2015-09-05)*
----------------------------
Adjustment of default parameters.
Version 1.0.8 *(2015-07-24)*
----------------------------
add DownSampling to BlurTransform
Version 1.0.7 *(2015-07-18)*
----------------------------
Bug fix : Blur not working.
Version 1.0.6 *(2015-04-23)*
----------------------------
add: CropType(Top, Center, Bottom) for CropTransformation.
Version 1.0.5 *(2015-03-09)*
----------------------------
Bug fix: Transparency.
Version 1.0.4 *(2015-02-13)*
----------------------------
Bug fix : remove original bitmap resource recycling.
Version 1.0.3 *(2015-02-05)*
----------------------------
Bug fix
Version 1.0.2 *(2015-02-04)*
----------------------------
Refactor: use BimapPool
Version 1.0.1 *(2015-01-21)*
----------------------------

View File

@@ -9,8 +9,9 @@ An Android transformation library providing a variety of image transformations f
Please feel free to use this.
#### Are you using Picasso?
[Picasso Transformations](https://github.com/wasabeef/picasso-transformations)
#### Are you using Picasso or Fresco?
[Picasso Transformations](https://github.com/wasabeef/picasso-transformations)
[Fresco Processors](https://github.com/wasabeef/fresco-processors)
# Demo
@@ -28,12 +29,12 @@ Please feel free to use this.
```groovy
repositories {
jcenter()
mavenCentral() // GPUImage for Android
}
dependencies {
compile 'jp.wasabeef:glide-transformations:1.0.1@aar'
compile 'jp.co.cyberagent.android.gpuimage:gpuimage-library:1.2.3@aar'
implementation 'jp.wasabeef:glide-transformations:3.1.1'
// If you want to use the GPU Filters
implementation 'jp.co.cyberagent.android.gpuimage:gpuimage-library:1.4.1'
}
```
@@ -43,8 +44,8 @@ Set Glide Transform.
```java
Glide.with(this).load(R.drawable.demo)
.bitmapTransform(new BlurTransformation(this, Glide.get(this).getBitmapPool()))
.into((ImageView) findViewById(R.id.image));
.apply(bitmapTransform(new BlurTransformation(25)))
.into((ImageView) findViewById(R.id.image));
```
## Advanced Step 3
@@ -52,31 +53,19 @@ Glide.with(this).load(R.drawable.demo)
You can set a multiple transformations.
```java
BitmapPool pool = Glide.get(this).getBitmapPool();
Glide.with(this).load(R.drawable.demo).bitmapTransform(
new BlurTransformation(this, pool, 5), new CropCircleTransformation(pool))
MultiTransformation multi = new MultiTransformation(
new BlurTransformation(25),
new RoundedCornersTransformation(128, 0, RoundedCornersTransformation.CornerType.BOTTOM))))
Glide.with(this).load(R.drawable.demo)
.apply(bitmapTransform(multi))
.into((ImageView) findViewById(R.id.image));
```
## Step 4
If you are using `BlurTransformation`.
```groovy
android {
...
defaultConfig {
...
renderscriptTargetApi 21
renderscriptSupportModeEnabled true
}
}
```
## Transformations
### Crop
`CropTransformation`, `CropCircleTransformation`, `CropSquareTransformation`
`CropTransformation`, `CropCircleTransformation`, `CropSquareTransformation`,
`RoundedCornersTransformation`
### Color
`ColorFilterTransformation`, `GrayscaleTransformation`
@@ -84,13 +73,28 @@ android {
### Blur
`BlurTransformation`
### Filter (use [GPUImage](https://github.com/CyberAgent/android-gpuimage))
### Mask
`MaskTransformation`
### GPU Filter (use [GPUImage](https://github.com/CyberAgent/android-gpuimage))
**Will require add dependencies for GPUImage.**
`ToonFilterTransformation`, `SepiaFilterTransformation`, `ContrastFilterTransformation`
`InvertFilterTransformation`, `PixelationFilterTransformation`, `SketchFilterTransformation`
`SwirlFilterTransformation`, `KuwaharaFilterTransformation`, `VignetteFilterTransformation`
`SwirlFilterTransformation`, `BrightnessFilterTransformation`, `KuwaharaFilterTransformation`
`VignetteFilterTransformation`
### Other
`RoundedCornersTransformation`
Applications using Glide Transformations
---
Please [ping](mailto:dadadada.chop@gmail.com) me or send a pull request if you would like to be added here.
Icon | Application
------------ | -------------
<img src="https://lh6.ggpht.com/6zKH_uQY1bxCwXL4DLo_uoFEOXdShi3BgmN6XRHlaJ-oA1svmq6y1PZkmO50nWQn2Lg=w300-rw" width="48" height="48" /> | [Ameba Ownd](https://play.google.com/store/apps/details?id=jp.co.cyberagent.madrid)
<img src="https://lh3.googleusercontent.com/ZOrekp-ho-ecWG1TyvuOs0LoB5M4QYWCCLS5lFbAHhp_SklSd06544ENG3uC97zGWes=w300-rw" width="48" height="48" /> | [AbemaTV](https://play.google.com/store/apps/details?id=tv.abema)
<img src="https://lh3.googleusercontent.com/eikxMAKKMU2O-rV-oUg04dGp-O4Aoje91kffDlnCB_3DCIPDzzADxdBOdPCW18Lmqw=w300-rw" width="48" height="48" /> | [TV Time](https://play.google.com/store/apps/details?id=com.tozelabs.tvshowtime)
Developed By
-------
@@ -101,6 +105,16 @@ Daichi Furiya (Wasabeef) - <dadadada.chop@gmail.com>
src="https://raw.githubusercontent.com/wasabeef/art/master/twitter.png" width="75"/>
</a>
Contributions
-------
Any contributions are welcome!
Contributers
-------
* [start141](https://github.com/start141)
Thanks
-------
@@ -109,7 +123,7 @@ Thanks
License
-------
Copyright 2015 Wasabeef
Copyright 2018 Wasabeef
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.9 MiB

After

Width:  |  Height:  |  Size: 3.9 MiB

View File

@@ -3,18 +3,17 @@
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.+'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.novoda:bintray-release:0.8.0'
}
}
allprojects {
repositories {
google()
jcenter()
mavenCentral()
}

View File

@@ -1,61 +1,63 @@
apply plugin: 'com.android.application'
android {
compileSdkVersion COMPILE_SDK_VERSION as int
buildToolsVersion BUILD_TOOLS_VERSION
compileSdkVersion COMPILE_SDK_VERSION as int
buildToolsVersion BUILD_TOOLS_VERSION
defaultConfig {
minSdkVersion MIN_SDK_VERSION as int
targetSdkVersion TARGET_SDK_VERSION as int
versionCode VERSION_CODE as int
versionName VERSION_NAME
renderscriptTargetApi RENDERSCRIPT_TARGET_API as int
renderscriptSupportModeEnabled true
}
defaultConfig {
minSdkVersion MIN_SDK_VERSION as int
targetSdkVersion TARGET_SDK_VERSION as int
versionCode "git rev-list origin/master --count".execute().text.toInteger()
versionName VERSION_NAME
}
signingConfigs {
release {
storeFile file(keyStoreProperty)
keyAlias keyAliasProperty
storePassword keyStorePasswordProperty
keyPassword keyAliasPasswordProperty
}
signingConfigs {
release {
storeFile file(keyStoreProperty)
keyAlias keyAliasProperty
storePassword keyStorePasswordProperty
keyPassword keyAliasPasswordProperty
}
}
buildTypes {
debug {
debuggable true
zipAlignEnabled true
}
release {
debuggable false
zipAlignEnabled true
signingConfig signingConfigs.release
}
buildTypes {
debug {
debuggable true
zipAlignEnabled true
}
release {
debuggable false
zipAlignEnabled true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
shrinkResources true
signingConfig signingConfigs.release
}
}
}
def getKeyStoreProperty() {
return hasProperty('WASABEEF_KEYSTORE') ? WASABEEF_KEYSTORE : "debug.keystore"
return hasProperty('WASABEEF_KEYSTORE') ? WASABEEF_KEYSTORE : "debug.keystore"
}
def getKeyAliasProperty() {
return hasProperty('WASABEEF_KEYALIAS') ? WASABEEF_KEYALIAS : "android"
return hasProperty('WASABEEF_KEYALIAS') ? WASABEEF_KEYALIAS : "android"
}
def getKeyStorePasswordProperty() {
return hasProperty('WASABEEF_KEYSTOREPASSWORD') ? WASABEEF_KEYSTOREPASSWORD : "androiddebugkey"
return hasProperty('WASABEEF_KEYSTOREPASSWORD') ? WASABEEF_KEYSTOREPASSWORD : "androiddebugkey"
}
def getKeyAliasPasswordProperty() {
return hasProperty('WASABEEF_KEYALIASPASSWORD') ? WASABEEF_KEYALIASPASSWORD : "android"
return hasProperty('WASABEEF_KEYALIASPASSWORD') ? WASABEEF_KEYALIASPASSWORD : "android"
}
dependencies {
compile project(':transformations')
// compile 'jp.wasabeef:glide-transformations:1.0.2'
compile 'jp.co.cyberagent.android.gpuimage:gpuimage-library:1.2.3'
compile 'com.android.support:appcompat-v7:21.+'
compile 'com.android.support:recyclerview-v7:21.+'
compile 'com.github.bumptech.glide:glide:3.5.1'
implementation project(':transformations')
implementation "com.github.bumptech.glide:glide:${GLIDE_VERSION}"
annotationProcessor "com.github.bumptech.glide:compiler:${GLIDE_VERSION}"
implementation "jp.co.cyberagent.android.gpuimage:gpuimage-library:${GPUIMAGE_VERSION}"
implementation "com.android.support:appcompat-v7:${SUPPORT_PACKAGE_VERSION}"
implementation "com.android.support:recyclerview-v7:${SUPPORT_PACKAGE_VERSION}"
implementation 'com.android.support.constraint:constraint-layout:1.1.0-beta4'
}

0
example/proguard-rules.pro vendored Normal file
View File

View File

@@ -1,21 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="jp.wasabeef.example.glide" >
package="jp.wasabeef.example.glide"
>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
>
<activity
android:name=".MainActivity"
android:label="@string/app_name"
>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>

View File

@@ -1,45 +1,45 @@
package jp.wasabeef.example.glide;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import java.util.ArrayList;
import java.util.List;
import jp.wasabeef.example.glide.MainAdapter.Type;
public class MainActivity extends AppCompatActivity {
public class MainActivity extends ActionBarActivity {
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.list);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.list);
recyclerView.setLayoutManager(new GridLayoutManager(this, 2));
List<Type> dataSet = new ArrayList<>();
dataSet.add(Type.Mask);
dataSet.add(Type.NinePatchMask);
dataSet.add(Type.CropTop);
dataSet.add(Type.CropCenter);
dataSet.add(Type.CropBottom);
dataSet.add(Type.CropSquare);
dataSet.add(Type.CropCircle);
dataSet.add(Type.ColorFilter);
dataSet.add(Type.Grayscale);
dataSet.add(Type.RoundedCorners);
dataSet.add(Type.Blur);
dataSet.add(Type.Toon);
dataSet.add(Type.Sepia);
dataSet.add(Type.Contrast);
dataSet.add(Type.Invert);
dataSet.add(Type.Pixel);
dataSet.add(Type.Sketch);
dataSet.add(Type.Swirl);
dataSet.add(Type.Brightness);
dataSet.add(Type.Kuawahara);
dataSet.add(Type.Vignette);
List<Type> dataSet = new ArrayList<>();
dataSet.add(Type.Crop);
dataSet.add(Type.CropSquare);
dataSet.add(Type.CropCircle);
dataSet.add(Type.ColorFilter);
dataSet.add(Type.Grayscale);
dataSet.add(Type.RoundedCorners);
dataSet.add(Type.Blur);
dataSet.add(Type.Toon);
dataSet.add(Type.Sepia);
dataSet.add(Type.Contrast);
dataSet.add(Type.Invert);
dataSet.add(Type.Pixel);
dataSet.add(Type.Sketch);
dataSet.add(Type.Swirl);
dataSet.add(Type.Brightness);
dataSet.add(Type.Kuawahara);
dataSet.add(Type.Vignette);
recyclerView.setAdapter(new MainAdapter(this, dataSet));
}
recyclerView.setAdapter(new MainAdapter(this, dataSet));
}
}

View File

@@ -1,11 +1,6 @@
package jp.wasabeef.example.glide;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.Transformation;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.PointF;
import android.support.v7.widget.RecyclerView;
@@ -14,15 +9,18 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.MultiTransformation;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import java.util.List;
import jp.wasabeef.glide.transformations.BlurTransformation;
import jp.wasabeef.glide.transformations.ColorFilterTransformation;
import jp.wasabeef.glide.transformations.CropCircleTransformation;
import jp.wasabeef.glide.transformations.CropSquareTransformation;
import jp.wasabeef.glide.transformations.CropTransformation;
import jp.wasabeef.glide.transformations.CropTransformation.CropType;
import jp.wasabeef.glide.transformations.GrayscaleTransformation;
import jp.wasabeef.glide.transformations.MaskTransformation;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
import jp.wasabeef.glide.transformations.gpu.BrightnessFilterTransformation;
import jp.wasabeef.glide.transformations.gpu.ContrastFilterTransformation;
@@ -35,126 +33,215 @@ import jp.wasabeef.glide.transformations.gpu.SwirlFilterTransformation;
import jp.wasabeef.glide.transformations.gpu.ToonFilterTransformation;
import jp.wasabeef.glide.transformations.gpu.VignetteFilterTransformation;
import static com.bumptech.glide.request.RequestOptions.bitmapTransform;
import static com.bumptech.glide.request.RequestOptions.overrideOf;
/**
* Created by Wasabeef on 2015/01/11.
*/
public class MainAdapter extends RecyclerView.Adapter<MainAdapter.ViewHolder> {
private Context mContext;
private List<Type> mDataSet;
private BitmapPool mPool;
private Context context;
private List<Type> dataSet;
enum Type {
Crop,
CropSquare,
CropCircle,
ColorFilter,
Grayscale,
RoundedCorners,
Blur,
Toon,
Sepia,
Contrast,
Invert,
Pixel,
Sketch,
Swirl,
Brightness,
Kuawahara,
Vignette
enum Type {
Mask,
NinePatchMask,
CropTop,
CropCenter,
CropBottom,
CropSquare,
CropCircle,
ColorFilter,
Grayscale,
RoundedCorners,
Blur,
Toon,
Sepia,
Contrast,
Invert,
Pixel,
Sketch,
Swirl,
Brightness,
Kuawahara,
Vignette
}
public MainAdapter(Context context, List<Type> dataSet) {
this.context = context;
this.dataSet = dataSet;
}
@Override public MainAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(context).inflate(R.layout.layout_list_item, parent, false);
return new ViewHolder(v);
}
@Override public void onBindViewHolder(MainAdapter.ViewHolder holder, int position) {
switch (dataSet.get(position)) {
case Mask: {
int width = Utils.dip2px(context, 266.66f);
int height = Utils.dip2px(context, 252.66f);
Glide.with(context)
.load(R.drawable.check)
.apply(overrideOf(width, height))
.apply(bitmapTransform(new MultiTransformation<>(new CenterCrop(),
new MaskTransformation(R.drawable.mask_starfish))))
.into(holder.image);
break;
}
case NinePatchMask: {
int width = Utils.dip2px(context, 300.0f);
int height = Utils.dip2px(context, 200.0f);
Glide.with(context)
.load(R.drawable.check)
.apply(overrideOf(width, height))
.apply(bitmapTransform(new MultiTransformation<>(new CenterCrop(),
new MaskTransformation(R.drawable.mask_chat_right))))
.into(holder.image);
break;
}
case CropTop:
Glide.with(context)
.load(R.drawable.demo)
.apply(bitmapTransform(
new CropTransformation(Utils.dip2px(context, 300), Utils.dip2px(context, 100),
CropType.TOP)))
.into(holder.image);
break;
case CropCenter:
Glide.with(context)
.load(R.drawable.demo)
.apply(bitmapTransform(
new CropTransformation(Utils.dip2px(context, 300), Utils.dip2px(context, 100), CropType.CENTER)))
.into(holder.image);
break;
case CropBottom:
Glide.with(context)
.load(R.drawable.demo)
.apply(bitmapTransform(
new CropTransformation(Utils.dip2px(context, 300), Utils.dip2px(context, 100),
CropType.BOTTOM)))
.into(holder.image);
break;
case CropSquare:
Glide.with(context)
.load(R.drawable.demo)
.apply(bitmapTransform(new CropSquareTransformation()))
.into(holder.image);
break;
case CropCircle:
Glide.with(context)
.load(R.drawable.demo)
.apply(bitmapTransform(new CropCircleTransformation()))
.into(holder.image);
break;
case ColorFilter:
Glide.with(context)
.load(R.drawable.demo)
.apply(bitmapTransform(new ColorFilterTransformation(Color.argb(80, 255, 0, 0))))
.into(holder.image);
break;
case Grayscale:
Glide.with(context)
.load(R.drawable.demo)
.apply(bitmapTransform(new GrayscaleTransformation()))
.into(holder.image);
break;
case RoundedCorners:
Glide.with(context)
.load(R.drawable.demo)
.apply(bitmapTransform(new RoundedCornersTransformation(45, 0,
RoundedCornersTransformation.CornerType.BOTTOM)))
.into(holder.image);
break;
case Blur:
Glide.with(context)
.load(R.drawable.check)
.apply(bitmapTransform(new BlurTransformation(25)))
.into(holder.image);
break;
case Toon:
Glide.with(context)
.load(R.drawable.demo)
.apply(bitmapTransform(new ToonFilterTransformation()))
.into(holder.image);
break;
case Sepia:
Glide.with(context)
.load(R.drawable.check)
.apply(bitmapTransform(new SepiaFilterTransformation()))
.into(holder.image);
break;
case Contrast:
Glide.with(context)
.load(R.drawable.check)
.apply(bitmapTransform(new ContrastFilterTransformation(2.0f)))
.into(holder.image);
break;
case Invert:
Glide.with(context)
.load(R.drawable.check)
.apply(bitmapTransform(new InvertFilterTransformation()))
.into(holder.image);
break;
case Pixel:
Glide.with(context)
.load(R.drawable.check)
.apply(bitmapTransform(new PixelationFilterTransformation(20)))
.into(holder.image);
break;
case Sketch:
Glide.with(context)
.load(R.drawable.check)
.apply(bitmapTransform(new SketchFilterTransformation()))
.into(holder.image);
break;
case Swirl:
Glide.with(context)
.load(R.drawable.check)
.apply(bitmapTransform(
new SwirlFilterTransformation(0.5f, 1.0f, new PointF(0.5f, 0.5f))).dontAnimate())
.into(holder.image);
break;
case Brightness:
Glide.with(context)
.load(R.drawable.check)
.apply(bitmapTransform(new BrightnessFilterTransformation(0.5f)).dontAnimate())
.into(holder.image);
break;
case Kuawahara:
Glide.with(context)
.load(R.drawable.check)
.apply(bitmapTransform(new KuwaharaFilterTransformation(25)).dontAnimate())
.into(holder.image);
break;
case Vignette:
Glide.with(context)
.load(R.drawable.check)
.apply(bitmapTransform(new VignetteFilterTransformation(new PointF(0.5f, 0.5f),
new float[] { 0.0f, 0.0f, 0.0f }, 0f, 0.75f)).dontAnimate())
.into(holder.image);
break;
}
holder.title.setText(dataSet.get(position).name());
}
public MainAdapter(Context context, List<Type> dataSet) {
mContext = context;
mDataSet = dataSet;
mPool = Glide.get(mContext).getBitmapPool();
}
@Override
public MainAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(mContext)
.inflate(R.layout.layout_list_item, parent, false);
return new ViewHolder(v);
}
@Override
public void onBindViewHolder(MainAdapter.ViewHolder holder, int position) {
Transformation<Bitmap> transformation = null;
switch (mDataSet.get(position)) {
case Crop:
transformation = new CropTransformation(mPool, 300, 100);
break;
case CropSquare:
transformation = new CropSquareTransformation(mPool);
break;
case CropCircle:
transformation = new CropCircleTransformation(mPool);
break;
case ColorFilter:
transformation = new ColorFilterTransformation(mPool, Color.argb(80, 255, 0, 0));
break;
case Grayscale:
transformation = new GrayscaleTransformation(mPool);
break;
case RoundedCorners:
transformation = new RoundedCornersTransformation(mPool, 100, 0);
break;
case Blur:
transformation = new BlurTransformation(mContext, mPool, 10);
break;
case Toon:
transformation = new ToonFilterTransformation(mContext, mPool);
break;
case Sepia:
transformation = new SepiaFilterTransformation(mContext, mPool);
break;
case Contrast:
transformation = new ContrastFilterTransformation(mContext, mPool, 2.0f);
break;
case Invert:
transformation = new InvertFilterTransformation(mContext, mPool);
break;
case Pixel:
transformation = new PixelationFilterTransformation(mContext, mPool, 20);
break;
case Sketch:
transformation = new SketchFilterTransformation(mContext, mPool);
break;
case Swirl:
transformation = new SwirlFilterTransformation(mContext, mPool,
0.5f, 1.0f, new PointF(0.5f, 0.5f));
break;
case Brightness:
transformation = new BrightnessFilterTransformation(mContext, mPool, 0.5f);
break;
case Kuawahara:
transformation = new KuwaharaFilterTransformation(mContext, mPool, 25);
break;
case Vignette:
transformation = new VignetteFilterTransformation(mContext, mPool,
new PointF(0.5f, 0.5f), new float[]{0.0f, 0.0f, 0.0f}, 0f, 0.75f);
break;
}
Glide.with(mContext).load(R.drawable.demo)
.bitmapTransform(transformation).into(holder.image);
holder.title.setText(mDataSet.get(position).name());
}
@Override
public int getItemCount() {
return mDataSet.size();
}
static class ViewHolder extends RecyclerView.ViewHolder {
public ImageView image;
public TextView title;
ViewHolder(View itemView) {
super(itemView);
image = (ImageView) itemView.findViewById(R.id.image);
title = (TextView) itemView.findViewById(R.id.title);
}
@Override public int getItemCount() {
return dataSet.size();
}
static class ViewHolder extends RecyclerView.ViewHolder {
public ImageView image;
public TextView title;
ViewHolder(View itemView) {
super(itemView);
image = (ImageView) itemView.findViewById(R.id.image);
title = (TextView) itemView.findViewById(R.id.title);
}
}
}

View File

@@ -0,0 +1,27 @@
package jp.wasabeef.example.glide;
/**
* Copyright (C) 2018 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import android.content.Context;
public class Utils {
public static int dip2px(Context context, float dp) {
float scale = context.getResources().getDisplayMetrics().density;
return (int) (dp * scale + 0.5f);
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.2 KiB

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.1 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 484 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

View File

@@ -1,13 +1,22 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#CC000000"
tools:context=".MainActivity">
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<android.support.v7.widget.RecyclerView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/list"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
</android.support.constraint.ConstraintLayout>

View File

@@ -1,24 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp">
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:contentDescription="@null"
android:src="@drawable/demo"/>
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/image"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:textColor="@android:color/white"/>
</RelativeLayout>
<ImageView
android:id="@+id/image"
android:layout_width="250dp"
android:layout_height="250dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:cropToPadding="false"
android:scaleType="fitCenter"
app:layout_constraintBottom_toTopOf="@+id/title"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
/>
</android.support.constraint.ConstraintLayout>

View File

@@ -1,6 +1,6 @@
<resources>
<!-- Example customization of dimensions originally defined in res/values/dimens.xml
(such as screen margins) for screens with more than 820dp of available width. This
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
<dimen name="activity_horizontal_margin">64dp</dimen>
<!-- Example customization of dimensions originally defined in res/values/dimens.xml
(such as screen margins) for screens with more than 820dp of available width. This
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
<dimen name="activity_horizontal_margin">64dp</dimen>
</resources>

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
</resources>

View File

@@ -1,5 +1,5 @@
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
</resources>

View File

@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">glide-transformations</string>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>
<string name="app_name">glide-transformations</string>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>
</resources>

View File

@@ -1,8 +1,11 @@
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>
</resources>

View File

@@ -1,13 +1,11 @@
VERSION_NAME=1.0.2
VERSION_CODE=3
VERSION_NAME=3.1.1
GROUP=jp.wasabeef
ARTIFACT_ID=glide-transformations
COMPILE_SDK_VERSION=21
BUILD_TOOLS_VERSION=21.1.2
TARGET_SDK_VERSION=21
RENDERSCRIPT_TARGET_API=21
MIN_SDK_VERSION=11
COMPILE_SDK_VERSION=27
BUILD_TOOLS_VERSION=27.0.3
TARGET_SDK_VERSION=27
MIN_SDK_VERSION=14
POM_DESCRIPTION=which provides simple Tranformations to Glide
POM_URL=https://github.com/wasabeef/glide-transformations
@@ -22,3 +20,7 @@ POM_DEVELOPER_NAME=Wasabeef
POM_DEVELOPER_EMAIL=dadadada.chop@gmail.com
POM_DEVELOPER_URL=wasabeef.jp
ISSUE_URL=https://github.com/wasabeef/glide-transformations/issues
SUPPORT_PACKAGE_VERSION=27.0.2
GLIDE_VERSION=4.6.1
GPUIMAGE_VERSION=1.4.1

Binary file not shown.

View File

@@ -1,6 +1,5 @@
#Wed Apr 10 15:27:10 PDT 2013
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.3-bin.zip

110
gradlew vendored
View File

@@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/usr/bin/env sh
##############################################################################
##
@@ -6,47 +6,6 @@
##
##############################################################################
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn ( ) {
echo "$*"
}
die ( ) {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
esac
# For Cygwin, ensure paths are in UNIX format before anything is touched.
if $cygwin ; then
[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
fi
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
@@ -61,9 +20,49 @@ while [ -h "$PRG" ] ; do
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >&-
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >&-
cd "$SAVED" >/dev/null
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn () {
echo "$*"
}
die () {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
@@ -90,7 +89,7 @@ location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
@@ -114,6 +113,7 @@ fi
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
@@ -154,11 +154,19 @@ if $cygwin ; then
esac
fi
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
function splitJvmOpts() {
JVM_OPTS=("$@")
# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
APP_ARGS=$(save "$@")
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi
exec "$JAVACMD" "$@"

14
gradlew.bat vendored
View File

@@ -8,14 +8,14 @@
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
@@ -46,10 +46,9 @@ echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windowz variants
@rem Get command-line arguments, handling Windows variants
if not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_args
:win9xME_args
@rem Slurp the command line arguments.
@@ -60,11 +59,6 @@ set _SKIP=2
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
goto execute
:4NT_args
@rem Get arguments from the 4NT Shell from JP Software
set CMD_LINE_ARGS=%$
:execute
@rem Setup the command line

View File

@@ -1,24 +0,0 @@
task androidJavadocs(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}
task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
classifier = 'javadoc'
from androidJavadocs.destinationDir
}
task androidSourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.sourceFiles
}
task androidJar(type: Jar) {
from 'build/intermediates/classes/release'
}
artifacts {
archives androidSourcesJar
archives androidJavadocsJar
archives androidJar
}

View File

@@ -1,64 +0,0 @@
apply plugin: 'maven-publish'
apply plugin: 'com.jfrog.bintray'
publishing {
publications {
mavenJava(MavenPublication) {
groupId GROUP
version VERSION_NAME
artifactId ARTIFACT_ID
// artifact androidJar
artifact "build/outputs/aar/transformations-release.aar"
artifact androidJavadocsJar
artifact androidSourcesJar
pom.withXml {
Node root = asNode()
root.appendNode('name', ARTIFACT_ID)
root.appendNode('description', POM_DESCRIPTION)
root.appendNode('url', POM_URL)
def issues = root.appendNode('issueManagement')
issues.appendNode('system', 'github')
issues.appendNode('url', ISSUE_URL)
def scm = root.appendNode('scm')
scm.appendNode('url', POM_SCM_URL)
scm.appendNode('connection', POM_SCM_CONNECTION)
scm.appendNode('developerConnection', POM_SCM_DEV_CONNECTION)
def license = root.appendNode('licenses').appendNode('license')
license.appendNode('name', POM_LICENCE_NAME)
license.appendNode('url', POM_LICENCE_URL)
license.appendNode('distribution', POM_LICENCE_DIST)
}
}
}
}
def getBintrayUserProperty() {
return hasProperty('bintrayUser') ? bintrayUser : ""
}
def getBintrayApiKeyProperty() {
return hasProperty('bintrayApiKey') ? bintrayApiKey : ""
}
bintray {
user = bintrayUserProperty
key = bintrayApiKeyProperty
publications = ['mavenJava']
dryRun = false
publish = false
pkg {
repo = 'maven'
name = ARTIFACT_ID
licenses = ['Apache-2.0']
labels = ['android']
version {
name = VERSION_NAME
vcsTag = VERSION_NAME
}
}
}

View File

@@ -1,43 +1,34 @@
apply plugin: 'com.android.library'
apply plugin: 'com.novoda.bintray-release'
android {
compileSdkVersion COMPILE_SDK_VERSION as int
buildToolsVersion BUILD_TOOLS_VERSION
compileSdkVersion COMPILE_SDK_VERSION as int
buildToolsVersion BUILD_TOOLS_VERSION
defaultConfig {
minSdkVersion MIN_SDK_VERSION as int
targetSdkVersion TARGET_SDK_VERSION as int
versionCode VERSION_CODE as int
versionName VERSION_NAME
renderscriptTargetApi RENDERSCRIPT_TARGET_API as int
renderscriptSupportModeEnabled true
}
defaultConfig {
minSdkVersion MIN_SDK_VERSION as int
targetSdkVersion TARGET_SDK_VERSION as int
versionCode "git rev-list origin/master --count".execute().text.toInteger()
versionName VERSION_NAME
consumerProguardFiles 'proguard-rules.txt'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.github.bumptech.glide:glide:3.5.1'
compile 'jp.co.cyberagent.android.gpuimage:gpuimage-library:1.2.3'
implementation "com.github.bumptech.glide:glide:${GLIDE_VERSION}"
annotationProcessor "com.github.bumptech.glide:compiler:${GLIDE_VERSION}"
compileOnly "jp.co.cyberagent.android.gpuimage:gpuimage-library:${GPUIMAGE_VERSION}"
}
android.libraryVariants.all { variant ->
if (variant.buildType.isDebuggable()) {
return; // Skip debug builds.
}
task("javadoc${variant.name.capitalize()}", type: Javadoc) {
description "Generates Javadoc for $variant.name."
source = variant.javaCompile.source
ext.androidJar = System.getenv("ANDROID_HOME") + "/platforms/${android.compileSdkVersion}/android.jar"
classpath = files(variant.javaCompile.classpath.files) + files(ext.androidJar)
}
task("bundleJavadoc${variant.name.capitalize()}", type: Jar) {
description "Bundles Javadoc into zip for $variant.name."
classifier = "javadoc"
from tasks["javadoc${variant.name.capitalize()}"]
}
publish {
userOrg = POM_DEVELOPER_ID
groupId = GROUP
artifactId = ARTIFACT_ID
publishVersion = VERSION_NAME
desc = POM_DESCRIPTION
website = POM_URL
bintrayUser = BINTRAY_USER
bintrayKey = BINTRAY_API_KEY
autoPublish = false
}
apply from: 'android-artifacts.gradle'
apply from: 'central-publish.gradle'
apply from: 'bintray-publish.gradle'

View File

@@ -1,94 +0,0 @@
/*
* Copyright 2013 Chris Banes
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
apply plugin: 'maven'
apply plugin: 'signing'
def isReleaseBuild() {
return VERSION_NAME.contains("SNAPSHOT") == false
}
def getReleaseRepositoryUrl() {
return hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL
: "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
}
def getSnapshotRepositoryUrl() {
return hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL
: "https://oss.sonatype.org/content/repositories/snapshots/"
}
def getRepositoryUsername() {
return hasProperty('NEXUS_USERNAME') ? NEXUS_USERNAME : ""
}
def getRepositoryPassword() {
return hasProperty('NEXUS_PASSWORD') ? NEXUS_PASSWORD : ""
}
afterEvaluate { project ->
uploadArchives {
repositories {
mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
pom.groupId = GROUP
pom.artifactId = POM_ARTIFACT_ID
pom.version = VERSION_NAME
repository(url: getReleaseRepositoryUrl()) {
authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
}
snapshotRepository(url: getSnapshotRepositoryUrl()) {
authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
}
pom.project {
name POM_NAME
packaging POM_PACKAGING
description POM_DESCRIPTION
url POM_URL
scm {
url POM_SCM_URL
connection POM_SCM_CONNECTION
developerConnection POM_SCM_DEV_CONNECTION
}
licenses {
license {
name POM_LICENCE_NAME
url POM_LICENCE_URL
distribution POM_LICENCE_DIST
}
}
developers {
developer {
id POM_DEVELOPER_ID
name POM_DEVELOPER_NAME
}
}
}
}
}
}
signing {
required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") }
sign configurations.archives
}
}

View File

@@ -1,3 +0,0 @@
POM_NAME=which provides simple Tranformations to Glide
POM_ARTIFACT_ID=glide-transformations
POM_PACKAGING=aar

View File

@@ -0,0 +1,8 @@
-dontwarn jp.co.cyberagent.android.gpuimage.**
-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public class * extends com.bumptech.glide.module.AppGlideModule
-keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** {
**[] $VALUES;
public *;
}

View File

@@ -8,7 +8,7 @@ import android.test.ApplicationTestCase;
*/
public class ApplicationTest extends ApplicationTestCase<Application> {
public ApplicationTest() {
super(Application.class);
}
public ApplicationTest() {
super(Application.class);
}
}

View File

@@ -1,3 +1 @@
<manifest
package="jp.wasabeef.glide.transformations">
</manifest>
<manifest package="jp.wasabeef.glide.transformations"></manifest>

View File

@@ -0,0 +1,65 @@
package jp.wasabeef.glide.transformations;
/**
* Copyright (C) 2018 Wasabeef
* Copyright 2014 Google, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import android.content.Context;
import android.graphics.Bitmap;
import android.support.annotation.NonNull;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.Transformation;
import com.bumptech.glide.load.engine.Resource;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
import com.bumptech.glide.request.target.Target;
import com.bumptech.glide.util.Util;
import java.security.MessageDigest;
public abstract class BitmapTransformation implements Transformation<Bitmap> {
@Override
public final Resource<Bitmap> transform(Context context, Resource<Bitmap> resource, int outWidth,
int outHeight) {
if (!Util.isValidDimensions(outWidth, outHeight)) {
throw new IllegalArgumentException(
"Cannot apply transformation on width: " + outWidth + " or height: " + outHeight
+ " less than or equal to zero and not Target.SIZE_ORIGINAL");
}
BitmapPool bitmapPool = Glide.get(context).getBitmapPool();
Bitmap toTransform = resource.get();
int targetWidth = outWidth == Target.SIZE_ORIGINAL ? toTransform.getWidth() : outWidth;
int targetHeight = outHeight == Target.SIZE_ORIGINAL ? toTransform.getHeight() : outHeight;
Bitmap transformed = transform(context.getApplicationContext(), bitmapPool, toTransform, targetWidth, targetHeight);
final Resource<Bitmap> result;
if (toTransform.equals(transformed)) {
result = resource;
} else {
result = BitmapResource.obtain(transformed, bitmapPool);
}
return result;
}
protected abstract Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
@NonNull Bitmap toTransform, int outWidth, int outHeight);
@Override public abstract void updateDiskCacheKey(MessageDigest messageDigest);
@Override public abstract boolean equals(Object o);
@Override public abstract int hashCode();
}

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations;
/**
* Copyright (C) 2015 Wasabeef
* Copyright (C) 2018 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,68 +16,86 @@ package jp.wasabeef.glide.transformations;
* limitations under the License.
*/
import com.bumptech.glide.load.Transformation;
import com.bumptech.glide.load.engine.Resource;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.support.v8.renderscript.Allocation;
import android.support.v8.renderscript.RenderScript;
import android.support.v8.renderscript.ScriptIntrinsicBlur;
import android.graphics.Paint;
import android.os.Build;
import android.renderscript.RSRuntimeException;
import android.support.annotation.NonNull;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import java.security.MessageDigest;
import jp.wasabeef.glide.transformations.internal.FastBlur;
import jp.wasabeef.glide.transformations.internal.RSBlur;
public class BlurTransformation implements Transformation<Bitmap> {
public class BlurTransformation extends BitmapTransformation {
private static int MAX_RADIUS = 25;
private static final int VERSION = 1;
private static final String ID =
"jp.wasabeef.glide.transformations.BlurTransformation." + VERSION;
private static final byte[] ID_BYTES = ID.getBytes(CHARSET);
private Context mContext;
private BitmapPool mBitmapPool;
private static int MAX_RADIUS = 25;
private static int DEFAULT_DOWN_SAMPLING = 1;
private int mRadius;
private int radius;
private int sampling;
public BlurTransformation(Context context, BitmapPool pool) {
this(context, pool, MAX_RADIUS);
public BlurTransformation() {
this(MAX_RADIUS, DEFAULT_DOWN_SAMPLING);
}
public BlurTransformation(int radius) {
this(radius, DEFAULT_DOWN_SAMPLING);
}
public BlurTransformation(int radius, int sampling) {
this.radius = radius;
this.sampling = sampling;
}
@Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
int width = toTransform.getWidth();
int height = toTransform.getHeight();
int scaledWidth = width / sampling;
int scaledHeight = height / sampling;
Bitmap bitmap = pool.get(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
canvas.scale(1 / (float) sampling, 1 / (float) sampling);
Paint paint = new Paint();
paint.setFlags(Paint.FILTER_BITMAP_FLAG);
canvas.drawBitmap(toTransform, 0, 0, paint);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
try {
bitmap = RSBlur.blur(context, bitmap, radius);
} catch (RSRuntimeException e) {
bitmap = FastBlur.blur(bitmap, radius, true);
}
} else {
bitmap = FastBlur.blur(bitmap, radius, true);
}
public BlurTransformation(Context context, BitmapPool pool, int radius) {
mContext = context;
mBitmapPool = pool;
mRadius = radius;
}
return bitmap;
}
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
Bitmap source = resource.get();
@Override public String toString() {
return "BlurTransformation(radius=" + radius + ", sampling=" + sampling + ")";
}
int width = source.getWidth();
int height = source.getHeight();
@Override public boolean equals(Object o) {
return o instanceof BlurTransformation;
}
Bitmap bitmap = mBitmapPool.get(width, height, source.getConfig());
if (bitmap == null) {
bitmap = Bitmap.createBitmap(width, height, source.getConfig());
}
@Override public int hashCode() {
return ID.hashCode();
}
Canvas canvas = new Canvas(bitmap);
canvas.drawBitmap(source, 0, 0, null);
RenderScript rs = RenderScript.create(mContext);
Allocation overlayAlloc = Allocation.createFromBitmap(rs, bitmap);
ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(rs, overlayAlloc.getElement());
blur.setInput(overlayAlloc);
blur.setRadius(mRadius);
blur.forEach(overlayAlloc);
overlayAlloc.copyTo(bitmap);
source.recycle();
rs.destroy();
return BitmapResource.obtain(bitmap, mBitmapPool);
}
@Override
public String getId() {
return "BlurTransformation(radius=" + mRadius + ")";
}
@Override public void updateDiskCacheKey(MessageDigest messageDigest) {
messageDigest.update(ID_BYTES);
}
}

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations;
/**
* Copyright (C) 2015 Wasabeef
* Copyright (C) 2018 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,53 +16,60 @@ package jp.wasabeef.glide.transformations;
* limitations under the License.
*/
import com.bumptech.glide.load.Transformation;
import com.bumptech.glide.load.engine.Resource;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.support.annotation.NonNull;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import java.security.MessageDigest;
public class ColorFilterTransformation implements Transformation<Bitmap> {
public class ColorFilterTransformation extends BitmapTransformation {
private BitmapPool mBitmapPool;
private static final int VERSION = 1;
private static final String ID =
"jp.wasabeef.glide.transformations.ColorFilterTransformation." + VERSION;
private static final byte[] ID_BYTES = ID.getBytes(CHARSET);
private int mColor;
private int color;
public ColorFilterTransformation(BitmapPool pool, int color) {
mBitmapPool = pool;
mColor = color;
}
public ColorFilterTransformation(int color) {
this.color = color;
}
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
Bitmap source = resource.get();
@Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
int width = toTransform.getWidth();
int height = toTransform.getHeight();
int width = source.getWidth();
int height = source.getHeight();
Bitmap.Config config =
toTransform.getConfig() != null ? toTransform.getConfig() : Bitmap.Config.ARGB_8888;
Bitmap bitmap = pool.get(width, height, config);
Bitmap bitmap = mBitmapPool.get(width, height, source.getConfig());
if (bitmap == null) {
bitmap = Bitmap.createBitmap(width, height, source.getConfig());
}
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP));
canvas.drawBitmap(toTransform, 0, 0, paint);
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setColorFilter(new PorterDuffColorFilter(mColor, PorterDuff.Mode.SRC_ATOP));
canvas.drawBitmap(source, 0, 0, paint);
return bitmap;
}
source.recycle();
@Override public String toString() {
return "ColorFilterTransformation(color=" + color + ")";
}
return BitmapResource.obtain(bitmap, mBitmapPool);
}
@Override public boolean equals(Object o) {
return o instanceof ColorFilterTransformation;
}
@Override
public String getId() {
return "ColorFilterTransformation(color=" + mColor + ")";
}
@Override public int hashCode() {
return ID.hashCode();
}
@Override public void updateDiskCacheKey(MessageDigest messageDigest) {
messageDigest.update(ID_BYTES);
}
}

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations;
/**
* Copyright (C) 2015 Wasabeef
* Copyright (C) 2018 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,58 +16,43 @@ package jp.wasabeef.glide.transformations;
* limitations under the License.
*/
import com.bumptech.glide.load.Transformation;
import com.bumptech.glide.load.engine.Resource;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.support.annotation.NonNull;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.TransformationUtils;
import com.bumptech.glide.request.RequestOptions;
import java.security.MessageDigest;
public class CropCircleTransformation implements Transformation<Bitmap> {
/**
* @deprecated Use {@link RequestOptions#circleCrop()}.
*/
@Deprecated
public class CropCircleTransformation extends BitmapTransformation {
private BitmapPool mBitmapPool;
private static final int VERSION = 1;
private static final String ID =
"jp.wasabeef.glide.transformations.CropCircleTransformation." + VERSION;
private static final byte[] ID_BYTES = ID.getBytes(CHARSET);
public CropCircleTransformation(BitmapPool pool) {
this.mBitmapPool = pool;
}
@Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
return TransformationUtils.circleCrop(pool, toTransform, outWidth, outHeight);
}
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
Bitmap source = resource.get();
int size = Math.min(source.getWidth(), source.getHeight());
@Override public String toString() {
return "CropCircleTransformation()";
}
int width = (source.getWidth() - size) / 2;
int height = (source.getHeight() - size) / 2;
@Override public boolean equals(Object o) {
return o instanceof CropCircleTransformation;
}
Bitmap bitmap = mBitmapPool.get(width, height, source.getConfig());
if (bitmap == null) {
bitmap = Bitmap.createBitmap(width, height, source.getConfig());
}
@Override public int hashCode() {
return ID.hashCode();
}
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint();
BitmapShader shader = new BitmapShader(source, BitmapShader.TileMode.CLAMP,
BitmapShader.TileMode.CLAMP);
Matrix matrix = new Matrix();
matrix.setTranslate(-width, -height);
shader.setLocalMatrix(matrix);
paint.setShader(shader);
paint.setAntiAlias(true);
float r = size / 2f;
canvas.drawCircle(r, r, r, paint);
source.recycle();
return BitmapResource.obtain(bitmap, mBitmapPool);
}
@Override
public String getId() {
return "CropCircleTransformation()";
}
@Override public void updateDiskCacheKey(MessageDigest messageDigest) {
messageDigest.update(ID_BYTES);
}
}

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations;
/**
* Copyright (C) 2015 Wasabeef
* Copyright (C) 2018 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,45 +16,41 @@ package jp.wasabeef.glide.transformations;
* limitations under the License.
*/
import com.bumptech.glide.load.Transformation;
import com.bumptech.glide.load.engine.Resource;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
import android.content.Context;
import android.graphics.Bitmap;
import android.support.annotation.NonNull;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.TransformationUtils;
import java.security.MessageDigest;
public class CropSquareTransformation implements Transformation<Bitmap> {
public class CropSquareTransformation extends BitmapTransformation {
private BitmapPool mBitmapPool;
private int mWidth;
private int mHeight;
private static final int VERSION = 1;
private static final String ID =
"jp.wasabeef.glide.transformations.CropSquareTransformation." + VERSION;
private static final byte[] ID_BYTES = ID.getBytes(CHARSET);
public CropSquareTransformation(BitmapPool pool) {
this.mBitmapPool = pool;
}
private int size;
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
Bitmap source = resource.get();
int size = Math.min(source.getWidth(), source.getHeight());
@Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
this.size = Math.max(outWidth, outHeight);
return TransformationUtils.centerCrop(pool, toTransform, size, size);
}
mWidth = (source.getWidth() - size) / 2;
mHeight = (source.getHeight() - size) / 2;
@Override public String toString() {
return "CropSquareTransformation(size=" + size + ")";
}
Bitmap bitmap = mBitmapPool.get(mWidth, mHeight, source.getConfig());
if (bitmap == null) {
bitmap = Bitmap.createBitmap(source, mWidth, mHeight, size, size);
}
@Override public boolean equals(Object o) {
return o instanceof CropSquareTransformation;
}
if (bitmap != source) {
source.recycle();
}
@Override public int hashCode() {
return ID.hashCode();
}
return BitmapResource.obtain(bitmap, mBitmapPool);
}
@Override
public String getId() {
return "CropSquareTransformation(width=" + mWidth + ", height=" + mHeight + ")";
}
@Override public void updateDiskCacheKey(MessageDigest messageDigest) {
messageDigest.update(ID_BYTES);
}
}

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations;
/**
* Copyright (C) 2015 Wasabeef
* Copyright (C) 2018 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,66 +16,96 @@ package jp.wasabeef.glide.transformations;
* limitations under the License.
*/
import com.bumptech.glide.load.Transformation;
import com.bumptech.glide.load.engine.Resource;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.RectF;
import android.support.annotation.NonNull;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import java.security.MessageDigest;
public class CropTransformation implements Transformation<Bitmap> {
public class CropTransformation extends BitmapTransformation {
private BitmapPool mBitmapPool;
private int mWidth;
private int mHeight;
private static final int VERSION = 1;
private static final String ID = "jp.wasabeef.glide.transformations.CropTransformation." + VERSION;
private static final byte[] ID_BYTES = ID.getBytes(CHARSET);
public CropTransformation(BitmapPool pool) {
mBitmapPool = pool;
}
public CropTransformation(BitmapPool pool, int width, int height) {
mBitmapPool = pool;
mWidth = width;
mHeight = height;
}
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
Bitmap source = resource.get();
if (mWidth == 0) {
mWidth = source.getWidth();
}
if (mHeight == 0) {
mHeight = source.getHeight();
}
Bitmap bitmap = mBitmapPool.get(mWidth, mHeight, source.getConfig());
if (bitmap == null) {
bitmap = Bitmap.createBitmap(mWidth, mHeight, source.getConfig());
}
float scaleX = (float) mWidth / source.getWidth();
float scaleY = (float) mHeight / source.getHeight();
float scale = Math.max(scaleX, scaleY);
float scaledWidth = scale * source.getWidth();
float scaledHeight = scale * source.getHeight();
float left = (mWidth - scaledWidth) / 2;
float top = (mHeight - scaledHeight) / 2;
RectF targetRect = new RectF(left, top, left + scaledWidth, top + scaledHeight);
Canvas canvas = new Canvas(bitmap);
canvas.drawBitmap(source, null, targetRect, null);
source.recycle();
return BitmapResource.obtain(bitmap, mBitmapPool);
}
@Override
public String getId() {
return "CropTransformation(width=" + mWidth + ", height=" + mHeight + ")";
public enum CropType {
TOP,
CENTER,
BOTTOM
}
private int width;
private int height;
private CropType cropType = CropType.CENTER;
public CropTransformation(int width, int height) {
this(width, height, CropType.CENTER);
}
public CropTransformation(int width, int height, CropType cropType) {
this.width = width;
this.height = height;
this.cropType = cropType;
}
@Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
width = width == 0 ? toTransform.getWidth() : width;
height = height == 0 ? toTransform.getHeight() : height;
Bitmap.Config config =
toTransform.getConfig() != null ? toTransform.getConfig() : Bitmap.Config.ARGB_8888;
Bitmap bitmap = pool.get(width, height, config);
bitmap.setHasAlpha(true);
float scaleX = (float) width / toTransform.getWidth();
float scaleY = (float) height / toTransform.getHeight();
float scale = Math.max(scaleX, scaleY);
float scaledWidth = scale * toTransform.getWidth();
float scaledHeight = scale * toTransform.getHeight();
float left = (width - scaledWidth) / 2;
float top = getTop(scaledHeight);
RectF targetRect = new RectF(left, top, left + scaledWidth, top + scaledHeight);
Canvas canvas = new Canvas(bitmap);
canvas.drawBitmap(toTransform, null, targetRect, null);
return bitmap;
}
@Override public String toString() {
return "CropTransformation(width=" + width + ", height=" + height + ", cropType=" + cropType
+ ")";
}
@Override public boolean equals(Object o) {
return o instanceof CropTransformation;
}
@Override public int hashCode() {
return ID.hashCode();
}
@Override public void updateDiskCacheKey(MessageDigest messageDigest) {
messageDigest.update(ID_BYTES);
}
private float getTop(float scaledHeight) {
switch (cropType) {
case TOP:
return 0;
case CENTER:
return (height - scaledHeight) / 2;
case BOTTOM:
return height - scaledHeight;
default:
return 0;
}
}
}

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations;
/**
* Copyright (C) 2015 Wasabeef
* Copyright (C) 2018 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,51 +16,55 @@ package jp.wasabeef.glide.transformations;
* limitations under the License.
*/
import com.bumptech.glide.load.Transformation;
import com.bumptech.glide.load.engine.Resource;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.Paint;
import android.support.annotation.NonNull;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import java.security.MessageDigest;
public class GrayscaleTransformation implements Transformation<Bitmap> {
public class GrayscaleTransformation extends BitmapTransformation {
private BitmapPool mBitmapPool;
private static final int VERSION = 1;
private static final String ID =
"jp.wasabeef.glide.transformations.GrayscaleTransformation." + VERSION;
private static final byte[] ID_BYTES = ID.getBytes(CHARSET);
public GrayscaleTransformation(BitmapPool pool) {
mBitmapPool = pool;
}
@Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
int width = toTransform.getWidth();
int height = toTransform.getHeight();
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
Bitmap source = resource.get();
Bitmap.Config config =
toTransform.getConfig() != null ? toTransform.getConfig() : Bitmap.Config.ARGB_8888;
Bitmap bitmap = pool.get(width, height, config);
int width = source.getWidth();
int height = source.getHeight();
Canvas canvas = new Canvas(bitmap);
ColorMatrix saturation = new ColorMatrix();
saturation.setSaturation(0f);
Paint paint = new Paint();
paint.setColorFilter(new ColorMatrixColorFilter(saturation));
canvas.drawBitmap(toTransform, 0, 0, paint);
Bitmap bitmap = mBitmapPool.get(width, height, source.getConfig());
if (bitmap == null) {
bitmap = Bitmap.createBitmap(width, height, source.getConfig());
}
return bitmap;
}
Canvas canvas = new Canvas(bitmap);
ColorMatrix saturation = new ColorMatrix();
saturation.setSaturation(0f);
Paint paint = new Paint();
paint.setColorFilter(new ColorMatrixColorFilter(saturation));
canvas.drawBitmap(source, 0, 0, paint);
@Override public String toString() {
return "GrayscaleTransformation()";
}
source.recycle();
@Override public boolean equals(Object o) {
return o instanceof GrayscaleTransformation;
}
return BitmapResource.obtain(bitmap, mBitmapPool);
}
@Override public int hashCode() {
return ID.hashCode();
}
@Override
public String getId() {
return "GrayscaleTransformation()";
}
@Override public void updateDiskCacheKey(MessageDigest messageDigest) {
messageDigest.update(ID_BYTES);
}
}

View File

@@ -0,0 +1,87 @@
package jp.wasabeef.glide.transformations;
/**
* Copyright (C) 2018 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import java.security.MessageDigest;
import jp.wasabeef.glide.transformations.internal.Utils;
public class MaskTransformation extends BitmapTransformation {
private static final int VERSION = 1;
private static final String ID =
"jp.wasabeef.glide.transformations.MaskTransformation." + VERSION;
private static final byte[] ID_BYTES = ID.getBytes(CHARSET);
private static Paint paint = new Paint();
private int maskId;
static {
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
}
/**
* @param maskId If you change the mask file, please also rename the mask file, or Glide will get
* the cache with the old mask. Because key() return the same values if using the
* same make file name. If you have a good idea please tell us, thanks.
*/
public MaskTransformation(int maskId) {
this.maskId = maskId;
}
@Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
int width = toTransform.getWidth();
int height = toTransform.getHeight();
Bitmap bitmap = pool.get(width, height, Bitmap.Config.ARGB_8888);
bitmap.setHasAlpha(true);
Drawable mask = Utils.getMaskDrawable(context.getApplicationContext(), maskId);
Canvas canvas = new Canvas(bitmap);
mask.setBounds(0, 0, width, height);
mask.draw(canvas);
canvas.drawBitmap(toTransform, 0, 0, paint);
return bitmap;
}
@Override public String toString() {
return "MaskTransformation(maskId=" + maskId + ")";
}
@Override public boolean equals(Object o) {
return o instanceof MaskTransformation;
}
@Override public int hashCode() {
return ID.hashCode();
}
@Override public void updateDiskCacheKey(MessageDigest messageDigest) {
messageDigest.update(ID_BYTES);
}
}

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations;
/**
* Copyright (C) 2015 Wasabeef
* Copyright (C) 2018 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,57 +16,236 @@ package jp.wasabeef.glide.transformations;
* limitations under the License.
*/
import com.bumptech.glide.load.Transformation;
import com.bumptech.glide.load.engine.Resource;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.Shader;
import android.support.annotation.NonNull;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
public class RoundedCornersTransformation implements Transformation<Bitmap> {
import java.security.MessageDigest;
private BitmapPool mBitmapPool;
public class RoundedCornersTransformation extends BitmapTransformation {
private int radius;
private int margin;
private static final int VERSION = 1;
private static final String ID = "jp.wasabeef.glide.transformations.RoundedCornersTransformation." + VERSION;
private static final byte[] ID_BYTES = ID.getBytes(CHARSET);
public RoundedCornersTransformation(BitmapPool pool, int radius, int margin) {
this.radius = radius;
this.margin = margin;
mBitmapPool = pool;
public enum CornerType {
ALL,
TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT,
TOP, BOTTOM, LEFT, RIGHT,
OTHER_TOP_LEFT, OTHER_TOP_RIGHT, OTHER_BOTTOM_LEFT, OTHER_BOTTOM_RIGHT,
DIAGONAL_FROM_TOP_LEFT, DIAGONAL_FROM_TOP_RIGHT
}
private int radius;
private int diameter;
private int margin;
private CornerType cornerType;
public RoundedCornersTransformation(int radius, int margin) {
this(radius, margin, CornerType.ALL);
}
public RoundedCornersTransformation(int radius, int margin, CornerType cornerType) {
this.radius = radius;
this.diameter = this.radius * 2;
this.margin = margin;
this.cornerType = cornerType;
}
@Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
int width = toTransform.getWidth();
int height = toTransform.getHeight();
Bitmap bitmap = pool.get(width, height, Bitmap.Config.ARGB_8888);
bitmap.setHasAlpha(true);
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setShader(new BitmapShader(toTransform, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
drawRoundRect(canvas, paint, width, height);
return bitmap;
}
private void drawRoundRect(Canvas canvas, Paint paint, float width, float height) {
float right = width - margin;
float bottom = height - margin;
switch (cornerType) {
case ALL:
canvas.drawRoundRect(new RectF(margin, margin, right, bottom), radius, radius, paint);
break;
case TOP_LEFT:
drawTopLeftRoundRect(canvas, paint, right, bottom);
break;
case TOP_RIGHT:
drawTopRightRoundRect(canvas, paint, right, bottom);
break;
case BOTTOM_LEFT:
drawBottomLeftRoundRect(canvas, paint, right, bottom);
break;
case BOTTOM_RIGHT:
drawBottomRightRoundRect(canvas, paint, right, bottom);
break;
case TOP:
drawTopRoundRect(canvas, paint, right, bottom);
break;
case BOTTOM:
drawBottomRoundRect(canvas, paint, right, bottom);
break;
case LEFT:
drawLeftRoundRect(canvas, paint, right, bottom);
break;
case RIGHT:
drawRightRoundRect(canvas, paint, right, bottom);
break;
case OTHER_TOP_LEFT:
drawOtherTopLeftRoundRect(canvas, paint, right, bottom);
break;
case OTHER_TOP_RIGHT:
drawOtherTopRightRoundRect(canvas, paint, right, bottom);
break;
case OTHER_BOTTOM_LEFT:
drawOtherBottomLeftRoundRect(canvas, paint, right, bottom);
break;
case OTHER_BOTTOM_RIGHT:
drawOtherBottomRightRoundRect(canvas, paint, right, bottom);
break;
case DIAGONAL_FROM_TOP_LEFT:
drawDiagonalFromTopLeftRoundRect(canvas, paint, right, bottom);
break;
case DIAGONAL_FROM_TOP_RIGHT:
drawDiagonalFromTopRightRoundRect(canvas, paint, right, bottom);
break;
default:
canvas.drawRoundRect(new RectF(margin, margin, right, bottom), radius, radius, paint);
break;
}
}
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
Bitmap source = resource.get();
private void drawTopLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
canvas.drawRoundRect(new RectF(margin, margin, margin + diameter, margin + diameter), radius,
radius, paint);
canvas.drawRect(new RectF(margin, margin + radius, margin + radius, bottom), paint);
canvas.drawRect(new RectF(margin + radius, margin, right, bottom), paint);
}
int width = source.getWidth();
int height = source.getHeight();
private void drawTopRightRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
canvas.drawRoundRect(new RectF(right - diameter, margin, right, margin + diameter), radius,
radius, paint);
canvas.drawRect(new RectF(margin, margin, right - radius, bottom), paint);
canvas.drawRect(new RectF(right - radius, margin + radius, right, bottom), paint);
}
Bitmap bitmap = mBitmapPool.get(width, height, source.getConfig());
if (bitmap == null) {
bitmap = Bitmap.createBitmap(width, height, source.getConfig());
}
private void drawBottomLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
canvas.drawRoundRect(new RectF(margin, bottom - diameter, margin + diameter, bottom), radius,
radius, paint);
canvas.drawRect(new RectF(margin, margin, margin + diameter, bottom - radius), paint);
canvas.drawRect(new RectF(margin + radius, margin, right, bottom), paint);
}
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
canvas.drawRoundRect(new RectF(margin, margin, width - margin, height - margin),
radius, radius, paint);
private void drawBottomRightRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
canvas.drawRoundRect(new RectF(right - diameter, bottom - diameter, right, bottom), radius,
radius, paint);
canvas.drawRect(new RectF(margin, margin, right - radius, bottom), paint);
canvas.drawRect(new RectF(right - radius, margin, right, bottom - radius), paint);
}
source.recycle();
private void drawTopRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
canvas.drawRoundRect(new RectF(margin, margin, right, margin + diameter), radius, radius,
paint);
canvas.drawRect(new RectF(margin, margin + radius, right, bottom), paint);
}
return BitmapResource.obtain(bitmap, mBitmapPool);
}
private void drawBottomRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
canvas.drawRoundRect(new RectF(margin, bottom - diameter, right, bottom), radius, radius,
paint);
canvas.drawRect(new RectF(margin, margin, right, bottom - radius), paint);
}
@Override
public String getId() {
return "RoundedTransformation(radius=" + radius + ", margin=" + margin + ")";
}
private void drawLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
canvas.drawRoundRect(new RectF(margin, margin, margin + diameter, bottom), radius, radius,
paint);
canvas.drawRect(new RectF(margin + radius, margin, right, bottom), paint);
}
private void drawRightRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
canvas.drawRoundRect(new RectF(right - diameter, margin, right, bottom), radius, radius, paint);
canvas.drawRect(new RectF(margin, margin, right - radius, bottom), paint);
}
private void drawOtherTopLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
canvas.drawRoundRect(new RectF(margin, bottom - diameter, right, bottom), radius, radius,
paint);
canvas.drawRoundRect(new RectF(right - diameter, margin, right, bottom), radius, radius, paint);
canvas.drawRect(new RectF(margin, margin, right - radius, bottom - radius), paint);
}
private void drawOtherTopRightRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
canvas.drawRoundRect(new RectF(margin, margin, margin + diameter, bottom), radius, radius,
paint);
canvas.drawRoundRect(new RectF(margin, bottom - diameter, right, bottom), radius, radius,
paint);
canvas.drawRect(new RectF(margin + radius, margin, right, bottom - radius), paint);
}
private void drawOtherBottomLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
canvas.drawRoundRect(new RectF(margin, margin, right, margin + diameter), radius, radius,
paint);
canvas.drawRoundRect(new RectF(right - diameter, margin, right, bottom), radius, radius, paint);
canvas.drawRect(new RectF(margin, margin + radius, right - radius, bottom), paint);
}
private void drawOtherBottomRightRoundRect(Canvas canvas, Paint paint, float right,
float bottom) {
canvas.drawRoundRect(new RectF(margin, margin, right, margin + diameter), radius, radius,
paint);
canvas.drawRoundRect(new RectF(margin, margin, margin + diameter, bottom), radius, radius,
paint);
canvas.drawRect(new RectF(margin + radius, margin + radius, right, bottom), paint);
}
private void drawDiagonalFromTopLeftRoundRect(Canvas canvas, Paint paint, float right,
float bottom) {
canvas.drawRoundRect(new RectF(margin, margin, margin + diameter, margin + diameter), radius,
radius, paint);
canvas.drawRoundRect(new RectF(right - diameter, bottom - diameter, right, bottom), radius,
radius, paint);
canvas.drawRect(new RectF(margin, margin + radius, right - diameter, bottom), paint);
canvas.drawRect(new RectF(margin + diameter, margin, right, bottom - radius), paint);
}
private void drawDiagonalFromTopRightRoundRect(Canvas canvas, Paint paint, float right,
float bottom) {
canvas.drawRoundRect(new RectF(right - diameter, margin, right, margin + diameter), radius,
radius, paint);
canvas.drawRoundRect(new RectF(margin, bottom - diameter, margin + diameter, bottom), radius,
radius, paint);
canvas.drawRect(new RectF(margin, margin, right - radius, bottom - radius), paint);
canvas.drawRect(new RectF(margin + radius, margin + radius, right, bottom), paint);
}
@Override public String toString() {
return "RoundedTransformation(radius=" + radius + ", margin=" + margin + ", diameter="
+ diameter + ", cornerType=" + cornerType.name() + ")";
}
@Override public boolean equals(Object o) {
return o instanceof RoundedCornersTransformation;
}
@Override public int hashCode() {
return ID.hashCode();
}
@Override public void updateDiskCacheKey(MessageDigest messageDigest) {
messageDigest.update(ID_BYTES);
}
}

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations.gpu;
/**
* Copyright (C) 2015 Wasabeef
* Copyright (C) 2018 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,56 +16,45 @@ package jp.wasabeef.glide.transformations.gpu;
* limitations under the License.
*/
import com.bumptech.glide.load.Transformation;
import com.bumptech.glide.load.engine.Resource;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
import android.content.Context;
import android.graphics.Bitmap;
import jp.co.cyberagent.android.gpuimage.GPUImage;
import java.security.MessageDigest;
import jp.co.cyberagent.android.gpuimage.GPUImageBrightnessFilter;
/**
* brightness value ranges from -1.0 to 1.0, with 0.0 as the normal level
*/
public class BrightnessFilterTransformation implements Transformation<Bitmap> {
public class BrightnessFilterTransformation extends GPUFilterTransformation {
private Context mContext;
private BitmapPool mBitmapPool;
private static final int VERSION = 1;
private static final String ID =
"jp.wasabeef.glide.transformations.gpu.BrightnessFilterTransformation." + VERSION;
private static final byte[] ID_BYTES = ID.getBytes(CHARSET);
private GPUImageBrightnessFilter mFilter = new GPUImageBrightnessFilter();
private float mBrightness;
private float brightness;
public BrightnessFilterTransformation(Context context, BitmapPool pool) {
mContext = context;
mBitmapPool = pool;
}
public BrightnessFilterTransformation() {
this(0.0f);
}
public BrightnessFilterTransformation(Context context, BitmapPool pool, float brightness) {
mContext = context;
mBitmapPool = pool;
mBrightness = brightness;
mFilter.setBrightness(mBrightness);
}
public BrightnessFilterTransformation(float brightness) {
super(new GPUImageBrightnessFilter());
this.brightness = brightness;
GPUImageBrightnessFilter filter = getFilter();
filter.setBrightness(this.brightness);
}
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
Bitmap source = resource.get();
@Override public String toString() {
return "BrightnessFilterTransformation(brightness=" + brightness + ")";
}
GPUImage gpuImage = new GPUImage(mContext);
gpuImage.setImage(source);
gpuImage.setFilter(mFilter);
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
@Override public boolean equals(Object o) {
return o instanceof BrightnessFilterTransformation;
}
source.recycle();
@Override public int hashCode() {
return ID.hashCode();
}
return BitmapResource.obtain(bitmap, mBitmapPool);
}
@Override
public String getId() {
return "BrightnessFilterTransformation(brightness=" + mBrightness + ")";
}
@Override public void updateDiskCacheKey(MessageDigest messageDigest) {
messageDigest.update(ID_BYTES);
}
}

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations.gpu;
/**
* Copyright (C) 2015 Wasabeef
* Copyright (C) 2018 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,56 +16,45 @@ package jp.wasabeef.glide.transformations.gpu;
* limitations under the License.
*/
import com.bumptech.glide.load.Transformation;
import com.bumptech.glide.load.engine.Resource;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
import android.content.Context;
import android.graphics.Bitmap;
import jp.co.cyberagent.android.gpuimage.GPUImage;
import java.security.MessageDigest;
import jp.co.cyberagent.android.gpuimage.GPUImageContrastFilter;
/**
* contrast value ranges from 0.0 to 4.0, with 1.0 as the normal level
*/
public class ContrastFilterTransformation implements Transformation<Bitmap> {
public class ContrastFilterTransformation extends GPUFilterTransformation {
private Context mContext;
private BitmapPool mBitmapPool;
private static final int VERSION = 1;
private static final String ID =
"jp.wasabeef.glide.transformations.gpu.ContrastFilterTransformation." + VERSION;
private static final byte[] ID_BYTES = ID.getBytes(CHARSET);
private GPUImageContrastFilter mFilter = new GPUImageContrastFilter();
private float mContrast;
private float contrast;
public ContrastFilterTransformation(Context context, BitmapPool pool) {
mContext = context;
mBitmapPool = pool;
}
public ContrastFilterTransformation() {
this(1.0f);
}
public ContrastFilterTransformation(Context context, BitmapPool pool, float contrast) {
mContext = context;
mBitmapPool = pool;
mContrast = contrast;
mFilter.setContrast(mContrast);
}
public ContrastFilterTransformation(float contrast) {
super(new GPUImageContrastFilter());
this.contrast = contrast;
GPUImageContrastFilter filter = getFilter();
filter.setContrast(this.contrast);
}
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
Bitmap source = resource.get();
@Override public String toString() {
return "ContrastFilterTransformation(contrast=" + contrast + ")";
}
GPUImage gpuImage = new GPUImage(mContext);
gpuImage.setImage(source);
gpuImage.setFilter(mFilter);
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
@Override public boolean equals(Object o) {
return o instanceof ContrastFilterTransformation;
}
source.recycle();
@Override public int hashCode() {
return ID.hashCode();
}
return BitmapResource.obtain(bitmap, mBitmapPool);
}
@Override
public String getId() {
return "ContrastFilterTransformation(contrast=" + mContrast + ")";
}
@Override public void updateDiskCacheKey(MessageDigest messageDigest) {
messageDigest.update(ID_BYTES);
}
}

View File

@@ -0,0 +1,69 @@
package jp.wasabeef.glide.transformations.gpu;
/**
* Copyright (C) 2018 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import android.content.Context;
import android.graphics.Bitmap;
import android.support.annotation.NonNull;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import java.security.MessageDigest;
import jp.co.cyberagent.android.gpuimage.GPUImage;
import jp.co.cyberagent.android.gpuimage.GPUImageFilter;
import jp.wasabeef.glide.transformations.BitmapTransformation;
public class GPUFilterTransformation extends BitmapTransformation {
private static final int VERSION = 1;
private static final String ID =
"jp.wasabeef.glide.transformations.gpu.GPUFilterTransformation." + VERSION;
private static final byte[] ID_BYTES = ID.getBytes(CHARSET);
private GPUImageFilter gpuImageFilter;
public GPUFilterTransformation(GPUImageFilter filter) {
this.gpuImageFilter = filter;
}
@Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
GPUImage gpuImage = new GPUImage(context);
gpuImage.setImage(toTransform);
gpuImage.setFilter(gpuImageFilter);
return gpuImage.getBitmapWithFilterApplied();
}
@Override public String toString() {
return getClass().getSimpleName();
}
@SuppressWarnings("unchecked") public <T> T getFilter() {
return (T) gpuImageFilter;
}
@Override public boolean equals(Object o) {
return o instanceof GPUFilterTransformation;
}
@Override public int hashCode() {
return ID.hashCode();
}
@Override public void updateDiskCacheKey(MessageDigest messageDigest) {
messageDigest.update(ID_BYTES);
}
}

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations.gpu;
/**
* Copyright (C) 2015 Wasabeef
* Copyright (C) 2018 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,43 +16,36 @@ package jp.wasabeef.glide.transformations.gpu;
* limitations under the License.
*/
import com.bumptech.glide.load.Transformation;
import com.bumptech.glide.load.engine.Resource;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
import android.content.Context;
import android.graphics.Bitmap;
import jp.co.cyberagent.android.gpuimage.GPUImage;
import java.security.MessageDigest;
import jp.co.cyberagent.android.gpuimage.GPUImageColorInvertFilter;
public class InvertFilterTransformation implements Transformation<Bitmap> {
/**
* Invert all the colors in the image.
*/
public class InvertFilterTransformation extends GPUFilterTransformation {
private Context mContext;
private BitmapPool mBitmapPool;
private static final int VERSION = 1;
private static final String ID =
"jp.wasabeef.glide.transformations.gpu.InvertFilterTransformation." + VERSION;
private static final byte[] ID_BYTES = ID.getBytes(CHARSET);
public InvertFilterTransformation(Context context, BitmapPool pool) {
mContext = context;
mBitmapPool = pool;
}
public InvertFilterTransformation() {
super(new GPUImageColorInvertFilter());
}
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
Bitmap source = resource.get();
@Override public String toString() {
return "InvertFilterTransformation()";
}
GPUImage gpuImage = new GPUImage(mContext);
gpuImage.setImage(source);
gpuImage.setFilter(new GPUImageColorInvertFilter());
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
@Override public boolean equals(Object o) {
return o instanceof InvertFilterTransformation;
}
source.recycle();
@Override public int hashCode() {
return ID.hashCode();
}
return BitmapResource.obtain(bitmap, mBitmapPool);
}
@Override
public String getId() {
return "InvertFilterTransformation()";
}
@Override public void updateDiskCacheKey(MessageDigest messageDigest) {
messageDigest.update(ID_BYTES);
}
}

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations.gpu;
/**
* Copyright (C) 2015 Wasabeef
* Copyright (C) 2018 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,57 +16,48 @@ package jp.wasabeef.glide.transformations.gpu;
* limitations under the License.
*/
import com.bumptech.glide.load.Transformation;
import com.bumptech.glide.load.engine.Resource;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
import android.content.Context;
import android.graphics.Bitmap;
import jp.co.cyberagent.android.gpuimage.GPUImage;
import java.security.MessageDigest;
import jp.co.cyberagent.android.gpuimage.GPUImageKuwaharaFilter;
/**
* The radius to sample from when creating the brush-stroke effect, with a default of 3.
* Kuwahara all the colors in the image.
*
* The radius to sample from when creating the brush-stroke effect, with a default of 25.
* The larger the radius, the slower the filter.
*/
public class KuwaharaFilterTransformation implements Transformation<Bitmap> {
public class KuwaharaFilterTransformation extends GPUFilterTransformation {
private Context mContext;
private BitmapPool mBitmapPool;
private static final int VERSION = 1;
private static final String ID =
"jp.wasabeef.glide.transformations.gpu.KuwaharaFilterTransformation." + VERSION;
private static final byte[] ID_BYTES = ID.getBytes(CHARSET);
private GPUImageKuwaharaFilter mFilter = new GPUImageKuwaharaFilter();
private int mRadius;
private int radius;
public KuwaharaFilterTransformation(Context context, BitmapPool pool) {
mContext = context;
mBitmapPool = pool;
}
public KuwaharaFilterTransformation() {
this(25);
}
public KuwaharaFilterTransformation(Context context, BitmapPool pool, int radius) {
mContext = context;
mBitmapPool = pool;
mRadius = radius;
mFilter.setRadius(mRadius);
}
public KuwaharaFilterTransformation(int radius) {
super(new GPUImageKuwaharaFilter());
this.radius = radius;
GPUImageKuwaharaFilter filter = getFilter();
filter.setRadius(this.radius);
}
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
Bitmap source = resource.get();
@Override public String toString() {
return "KuwaharaFilterTransformation(radius=" + radius + ")";
}
GPUImage gpuImage = new GPUImage(mContext);
gpuImage.setImage(source);
gpuImage.setFilter(mFilter);
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
@Override public boolean equals(Object o) {
return o instanceof KuwaharaFilterTransformation;
}
source.recycle();
@Override public int hashCode() {
return ID.hashCode();
}
return BitmapResource.obtain(bitmap, mBitmapPool);
}
@Override
public String getId() {
return "KuwaharaFilterTransformation(radius=" + mRadius + ")";
}
@Override public void updateDiskCacheKey(MessageDigest messageDigest) {
messageDigest.update(ID_BYTES);
}
}

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations.gpu;
/**
* Copyright (C) 2015 Wasabeef
* Copyright (C) 2018 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,53 +16,47 @@ package jp.wasabeef.glide.transformations.gpu;
* limitations under the License.
*/
import com.bumptech.glide.load.Transformation;
import com.bumptech.glide.load.engine.Resource;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
import android.content.Context;
import android.graphics.Bitmap;
import jp.co.cyberagent.android.gpuimage.GPUImage;
import java.security.MessageDigest;
import jp.co.cyberagent.android.gpuimage.GPUImagePixelationFilter;
public class PixelationFilterTransformation implements Transformation<Bitmap> {
/**
* Applies a Pixelation effect to the image.
*
* The pixel with a default of 10.0.
*/
public class PixelationFilterTransformation extends GPUFilterTransformation {
private Context mContext;
private BitmapPool mBitmapPool;
private static final int VERSION = 1;
private static final String ID =
"jp.wasabeef.glide.transformations.gpu.PixelationFilterTransformation." + VERSION;
private static final byte[] ID_BYTES = ID.getBytes(CHARSET);
private GPUImagePixelationFilter mFilter = new GPUImagePixelationFilter();
private float mPixel;
private float pixel;
public PixelationFilterTransformation(Context context, BitmapPool pool) {
mContext = context;
mBitmapPool = pool;
}
public PixelationFilterTransformation() {
this(10f);
}
public PixelationFilterTransformation(Context context, BitmapPool pool, float pixel) {
mContext = context;
mBitmapPool = pool;
mPixel = pixel;
mFilter.setPixel(mPixel);
}
public PixelationFilterTransformation(float pixel) {
super(new GPUImagePixelationFilter());
this.pixel = pixel;
GPUImagePixelationFilter filter = getFilter();
filter.setPixel(this.pixel);
}
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
Bitmap source = resource.get();
@Override public String toString() {
return "PixelationFilterTransformation(pixel=" + pixel + ")";
}
GPUImage gpuImage = new GPUImage(mContext);
gpuImage.setImage(source);
gpuImage.setFilter(mFilter);
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
@Override public boolean equals(Object o) {
return o instanceof PixelationFilterTransformation;
}
source.recycle();
@Override public int hashCode() {
return ID.hashCode();
}
return BitmapResource.obtain(bitmap, mBitmapPool);
}
@Override
public String getId() {
return "PixelationFilterTransformation(pixel=" + mPixel + ")";
}
@Override public void updateDiskCacheKey(MessageDigest messageDigest) {
messageDigest.update(ID_BYTES);
}
}

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations.gpu;
/**
* Copyright (C) 2015 Wasabeef
* Copyright (C) 2018 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,53 +16,47 @@ package jp.wasabeef.glide.transformations.gpu;
* limitations under the License.
*/
import com.bumptech.glide.load.Transformation;
import com.bumptech.glide.load.engine.Resource;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
import android.content.Context;
import android.graphics.Bitmap;
import jp.co.cyberagent.android.gpuimage.GPUImage;
import java.security.MessageDigest;
import jp.co.cyberagent.android.gpuimage.GPUImageSepiaFilter;
public class SepiaFilterTransformation implements Transformation<Bitmap> {
/**
* Applies a simple sepia effect.
*
* The intensity with a default of 1.0.
*/
public class SepiaFilterTransformation extends GPUFilterTransformation {
private Context mContext;
private BitmapPool mBitmapPool;
private static final int VERSION = 1;
private static final String ID =
"jp.wasabeef.glide.transformations.gpu.SepiaFilterTransformation." + VERSION;
private static final byte[] ID_BYTES = ID.getBytes(CHARSET);
private GPUImageSepiaFilter mFilter = new GPUImageSepiaFilter();
private float mIntensity;
private float intensity;
public SepiaFilterTransformation(Context context, BitmapPool pool) {
mContext = context;
mBitmapPool = pool;
}
public SepiaFilterTransformation() {
this(1.0f);
}
public SepiaFilterTransformation(Context context, BitmapPool pool, float intensity) {
mContext = context;
mBitmapPool = pool;
mIntensity = intensity;
mFilter.setIntensity(mIntensity);
}
public SepiaFilterTransformation(float intensity) {
super(new GPUImageSepiaFilter());
this.intensity = intensity;
GPUImageSepiaFilter filter = getFilter();
filter.setIntensity(this.intensity);
}
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
Bitmap source = resource.get();
@Override public String toString() {
return "SepiaFilterTransformation(intensity=" + intensity + ")";
}
GPUImage gpuImage = new GPUImage(mContext);
gpuImage.setImage(source);
gpuImage.setFilter(mFilter);
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
@Override public boolean equals(Object o) {
return o instanceof SepiaFilterTransformation;
}
source.recycle();
@Override public int hashCode() {
return ID.hashCode();
}
return BitmapResource.obtain(bitmap, mBitmapPool);
}
@Override
public String getId() {
return "SepiaFilterTransformation(intensity=" + mIntensity + ")";
}
@Override public void updateDiskCacheKey(MessageDigest messageDigest) {
messageDigest.update(ID_BYTES);
}
}

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations.gpu;
/**
* Copyright (C) 2015 Wasabeef
* Copyright (C) 2018 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,43 +16,33 @@ package jp.wasabeef.glide.transformations.gpu;
* limitations under the License.
*/
import com.bumptech.glide.load.Transformation;
import com.bumptech.glide.load.engine.Resource;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
import android.content.Context;
import android.graphics.Bitmap;
import jp.co.cyberagent.android.gpuimage.GPUImage;
import java.security.MessageDigest;
import jp.co.cyberagent.android.gpuimage.GPUImageSketchFilter;
public class SketchFilterTransformation implements Transformation<Bitmap> {
public class SketchFilterTransformation extends GPUFilterTransformation {
private Context mContext;
private BitmapPool mBitmapPool;
private static final int VERSION = 1;
private static final String ID =
"jp.wasabeef.glide.transformations.gpu.SketchFilterTransformation." + VERSION;
private static final byte[] ID_BYTES = ID.getBytes(CHARSET);
public SketchFilterTransformation(Context context, BitmapPool pool) {
mContext = context;
mBitmapPool = pool;
}
public SketchFilterTransformation() {
super(new GPUImageSketchFilter());
}
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
Bitmap source = resource.get();
@Override public String toString() {
return "SketchFilterTransformation()";
}
GPUImage gpuImage = new GPUImage(mContext);
gpuImage.setImage(source);
gpuImage.setFilter(new GPUImageSketchFilter());
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
@Override public boolean equals(Object o) {
return o instanceof SketchFilterTransformation;
}
source.recycle();
@Override public int hashCode() {
return ID.hashCode();
}
return BitmapResource.obtain(bitmap, mBitmapPool);
}
@Override
public String getId() {
return "SketchFilterTransformation()";
}
@Override public void updateDiskCacheKey(MessageDigest messageDigest) {
messageDigest.update(ID_BYTES);
}
}

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations.gpu;
/**
* Copyright (C) 2015 Wasabeef
* Copyright (C) 2018 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,68 +16,58 @@ package jp.wasabeef.glide.transformations.gpu;
* limitations under the License.
*/
import com.bumptech.glide.load.Transformation;
import com.bumptech.glide.load.engine.Resource;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.PointF;
import jp.co.cyberagent.android.gpuimage.GPUImage;
import java.security.MessageDigest;
import jp.co.cyberagent.android.gpuimage.GPUImageSwirlFilter;
public class SwirlFilterTransformation implements Transformation<Bitmap> {
/**
* Creates a swirl distortion on the image.
*/
public class SwirlFilterTransformation extends GPUFilterTransformation {
private Context mContext;
private BitmapPool mBitmapPool;
private static final int VERSION = 1;
private static final String ID =
"jp.wasabeef.glide.transformations.gpu.SwirlFilterTransformation." + VERSION;
private static final byte[] ID_BYTES = ID.getBytes(CHARSET);
private GPUImageSwirlFilter mFilter = new GPUImageSwirlFilter();
private float mRadius;
private float mAngle;
private PointF mCenter;
private float radius;
private float angle;
private PointF center;
public SwirlFilterTransformation(Context context, BitmapPool pool) {
mContext = context;
mBitmapPool = pool;
mCenter = new PointF();
}
public SwirlFilterTransformation() {
this(.5f, 1.0f, new PointF(0.5f, 0.5f));
}
/**
* @param radius from 0.0 to 1.0, default 0.5
* @param angle minimum 0.0, default 1.0
* @param center default (0.5, 0.5)
*/
public SwirlFilterTransformation(Context context, BitmapPool pool,
float radius, float angle, PointF center) {
mContext = context;
mBitmapPool = pool;
mRadius = radius;
mAngle = angle;
mCenter = center;
mFilter.setRadius(mRadius);
mFilter.setAngle(mAngle);
mFilter.setCenter(mCenter);
}
/**
* @param radius from 0.0 to 1.0, default 0.5
* @param angle minimum 0.0, default 1.0
* @param center default (0.5, 0.5)
*/
public SwirlFilterTransformation(float radius, float angle, PointF center) {
super(new GPUImageSwirlFilter());
this.radius = radius;
this.angle = angle;
this.center = center;
GPUImageSwirlFilter filter = getFilter();
filter.setRadius(this.radius);
filter.setAngle(this.angle);
filter.setCenter(this.center);
}
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
Bitmap source = resource.get();
@Override public String toString() {
return "SwirlFilterTransformation(radius=" + radius + ",angle=" + angle + ",center="
+ center.toString() + ")";
}
GPUImage gpuImage = new GPUImage(mContext);
gpuImage.setImage(source);
gpuImage.setFilter(mFilter);
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
@Override public boolean equals(Object o) {
return o instanceof SwirlFilterTransformation;
}
source.recycle();
@Override public int hashCode() {
return ID.hashCode();
}
return BitmapResource.obtain(bitmap, mBitmapPool);
}
@Override
public String getId() {
return "SwirlFilterTransformation(radius=" + mRadius +
",angle=" + mAngle + ",center=" + mCenter.toString() + ")";
}
@Override public void updateDiskCacheKey(MessageDigest messageDigest) {
messageDigest.update(ID_BYTES);
}
}

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations.gpu;
/**
* Copyright (C) 2015 Wasabeef
* Copyright (C) 2018 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,58 +16,51 @@ package jp.wasabeef.glide.transformations.gpu;
* limitations under the License.
*/
import com.bumptech.glide.load.Transformation;
import com.bumptech.glide.load.engine.Resource;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
import android.content.Context;
import android.graphics.Bitmap;
import jp.co.cyberagent.android.gpuimage.GPUImage;
import java.security.MessageDigest;
import jp.co.cyberagent.android.gpuimage.GPUImageToonFilter;
public class ToonFilterTransformation implements Transformation<Bitmap> {
/**
* The threshold at which to apply the edges, default of 0.2.
* The levels of quantization for the posterization of colors within the scene,
* with a default of 10.0.
*/
public class ToonFilterTransformation extends GPUFilterTransformation {
private Context mContext;
private BitmapPool mBitmapPool;
private static final int VERSION = 1;
private static final String ID =
"jp.wasabeef.glide.transformations.gpu.ToonFilterTransformation." + VERSION;
private static final byte[] ID_BYTES = ID.getBytes(CHARSET);
private GPUImageToonFilter mFilter = new GPUImageToonFilter();
private float mThreshold;
private float mQuantizationLevels;
private float threshold;
private float quantizationLevels;
public ToonFilterTransformation(Context context, BitmapPool pool) {
mContext = context;
mBitmapPool = pool;
}
public ToonFilterTransformation() {
this(.2f, 10.0f);
}
public ToonFilterTransformation(Context context, BitmapPool pool,
float threshold, float quantizationLevels) {
mContext = context;
mBitmapPool = pool;
mThreshold = threshold;
mQuantizationLevels = quantizationLevels;
mFilter.setThreshold(mThreshold);
mFilter.setQuantizationLevels(mQuantizationLevels);
}
public ToonFilterTransformation(float threshold, float quantizationLevels) {
super(new GPUImageToonFilter());
this.threshold = threshold;
this.quantizationLevels = quantizationLevels;
GPUImageToonFilter filter = getFilter();
filter.setThreshold(this.threshold);
filter.setQuantizationLevels(this.quantizationLevels);
}
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
Bitmap source = resource.get();
@Override public String toString() {
return "ToonFilterTransformation(threshold=" + threshold + ",quantizationLevels="
+ quantizationLevels + ")";
}
GPUImage gpuImage = new GPUImage(mContext);
gpuImage.setImage(source);
gpuImage.setFilter(mFilter);
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
@Override public boolean equals(Object o) {
return o instanceof ToonFilterTransformation;
}
source.recycle();
@Override public int hashCode() {
return ID.hashCode();
}
return BitmapResource.obtain(bitmap, mBitmapPool);
}
@Override
public String getId() {
return "ToonFilterTransformation(threshold=" + mThreshold +
",quantizationLevels=" + mQuantizationLevels + ")";
}
@Override public void updateDiskCacheKey(MessageDigest messageDigest) {
messageDigest.update(ID_BYTES);
}
}

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations.gpu;
/**
* Copyright (C) 2015 Wasabeef
* Copyright (C) 2018 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,75 +16,59 @@ package jp.wasabeef.glide.transformations.gpu;
* limitations under the License.
*/
import com.bumptech.glide.load.Transformation;
import com.bumptech.glide.load.engine.Resource;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.PointF;
import java.security.MessageDigest;
import java.util.Arrays;
import jp.co.cyberagent.android.gpuimage.GPUImage;
import jp.co.cyberagent.android.gpuimage.GPUImageVignetteFilter;
/**
* Performs a vignetting effect, fading out the image at the edges
* x:
* y: The directional intensity of the vignetting, with a default of x = 0.75, y = 0.5
* The directional intensity of the vignetting,
* with a default of x = 0.5, y = 0.5, start = 0, end = 0.75
*/
public class VignetteFilterTransformation implements Transformation<Bitmap> {
public class VignetteFilterTransformation extends GPUFilterTransformation {
private Context mContext;
private BitmapPool mBitmapPool;
private static final int VERSION = 1;
private static final String ID =
"jp.wasabeef.glide.transformations.gpu.VignetteFilterTransformation." + VERSION;
private static final byte[] ID_BYTES = ID.getBytes(CHARSET);
private GPUImageVignetteFilter mFilter = new GPUImageVignetteFilter();
private PointF mCenter;
private float[] mVignetteColor;
private float mVignetteStart;
private float mVignetteEnd;
private PointF center;
private float[] vignetteColor;
private float vignetteStart;
private float vignetteEnd;
public VignetteFilterTransformation() {
this(new PointF(0.5f, 0.5f), new float[] { 0.0f, 0.0f, 0.0f }, 0.0f, 0.75f);
}
public VignetteFilterTransformation(Context context, BitmapPool pool) {
mContext = context;
mBitmapPool = pool;
mCenter = new PointF();
}
public VignetteFilterTransformation(PointF center, float[] color, float start, float end) {
super(new GPUImageVignetteFilter());
this.center = center;
vignetteColor = color;
vignetteStart = start;
vignetteEnd = end;
GPUImageVignetteFilter filter = getFilter();
filter.setVignetteCenter(this.center);
filter.setVignetteColor(vignetteColor);
filter.setVignetteStart(vignetteStart);
filter.setVignetteEnd(vignetteEnd);
}
public VignetteFilterTransformation(Context context, BitmapPool pool,
PointF center, float[] color, float start, float end) {
mContext = context;
mBitmapPool = pool;
mCenter = center;
mVignetteColor = color;
mVignetteStart = start;
mVignetteEnd = end;
mFilter.setVignetteCenter(mCenter);
mFilter.setVignetteColor(mVignetteColor);
mFilter.setVignetteStart(mVignetteStart);
mFilter.setVignetteEnd(mVignetteEnd);
}
@Override public String toString() {
return "VignetteFilterTransformation(center=" + center.toString() + ",color=" + Arrays.toString(
vignetteColor) + ",start=" + vignetteStart + ",end=" + vignetteEnd + ")";
}
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
Bitmap source = resource.get();
@Override public boolean equals(Object o) {
return o instanceof VignetteFilterTransformation;
}
GPUImage gpuImage = new GPUImage(mContext);
gpuImage.setImage(source);
gpuImage.setFilter(mFilter);
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
@Override public int hashCode() {
return ID.hashCode();
}
source.recycle();
return BitmapResource.obtain(bitmap, mBitmapPool);
}
@Override
public String getId() {
return "VignetteFilterTransformation(center=" + mCenter.toString() +
",color=" + Arrays.toString(mVignetteColor) +
",start=" + mVignetteStart + ",end=" + mVignetteEnd + ")";
}
@Override public void updateDiskCacheKey(MessageDigest messageDigest) {
messageDigest.update(ID_BYTES);
}
}

View File

@@ -0,0 +1,257 @@
package jp.wasabeef.glide.transformations.internal;
import android.graphics.Bitmap;
/**
* Copyright (C) 2018 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
public class FastBlur {
public static Bitmap blur(Bitmap sentBitmap, int radius, boolean canReuseInBitmap) {
// Stack Blur v1.0 from
// http://www.quasimondo.com/StackBlurForCanvas/StackBlurDemo.html
//
// Java Author: Mario Klingemann <mario at quasimondo.com>
// http://incubator.quasimondo.com
// created Feburary 29, 2004
// Android port : Yahel Bouaziz <yahel at kayenko.com>
// http://www.kayenko.com
// ported april 5th, 2012
// This is a compromise between Gaussian Blur and Box blur
// It creates much better looking blurs than Box Blur, but is
// 7x faster than my Gaussian Blur implementation.
//
// I called it Stack Blur because this describes best how this
// filter works internally: it creates a kind of moving stack
// of colors whilst scanning through the image. Thereby it
// just has to add one new block of color to the right side
// of the stack and remove the leftmost color. The remaining
// colors on the topmost layer of the stack are either added on
// or reduced by one, depending on if they are on the right or
// on the left side of the stack.
//
// If you are using this algorithm in your code please add
// the following line:
//
// Stack Blur Algorithm by Mario Klingemann <mario@quasimondo.com>
Bitmap bitmap;
if (canReuseInBitmap) {
bitmap = sentBitmap;
} else {
bitmap = sentBitmap.copy(sentBitmap.getConfig(), true);
}
if (radius < 1) {
return (null);
}
int w = bitmap.getWidth();
int h = bitmap.getHeight();
int[] pix = new int[w * h];
bitmap.getPixels(pix, 0, w, 0, 0, w, h);
int wm = w - 1;
int hm = h - 1;
int wh = w * h;
int div = radius + radius + 1;
int r[] = new int[wh];
int g[] = new int[wh];
int b[] = new int[wh];
int rsum, gsum, bsum, x, y, i, p, yp, yi, yw;
int vmin[] = new int[Math.max(w, h)];
int divsum = (div + 1) >> 1;
divsum *= divsum;
int dv[] = new int[256 * divsum];
for (i = 0; i < 256 * divsum; i++) {
dv[i] = (i / divsum);
}
yw = yi = 0;
int[][] stack = new int[div][3];
int stackpointer;
int stackstart;
int[] sir;
int rbs;
int r1 = radius + 1;
int routsum, goutsum, boutsum;
int rinsum, ginsum, binsum;
for (y = 0; y < h; y++) {
rinsum = ginsum = binsum = routsum = goutsum = boutsum = rsum = gsum = bsum = 0;
for (i = -radius; i <= radius; i++) {
p = pix[yi + Math.min(wm, Math.max(i, 0))];
sir = stack[i + radius];
sir[0] = (p & 0xff0000) >> 16;
sir[1] = (p & 0x00ff00) >> 8;
sir[2] = (p & 0x0000ff);
rbs = r1 - Math.abs(i);
rsum += sir[0] * rbs;
gsum += sir[1] * rbs;
bsum += sir[2] * rbs;
if (i > 0) {
rinsum += sir[0];
ginsum += sir[1];
binsum += sir[2];
} else {
routsum += sir[0];
goutsum += sir[1];
boutsum += sir[2];
}
}
stackpointer = radius;
for (x = 0; x < w; x++) {
r[yi] = dv[rsum];
g[yi] = dv[gsum];
b[yi] = dv[bsum];
rsum -= routsum;
gsum -= goutsum;
bsum -= boutsum;
stackstart = stackpointer - radius + div;
sir = stack[stackstart % div];
routsum -= sir[0];
goutsum -= sir[1];
boutsum -= sir[2];
if (y == 0) {
vmin[x] = Math.min(x + radius + 1, wm);
}
p = pix[yw + vmin[x]];
sir[0] = (p & 0xff0000) >> 16;
sir[1] = (p & 0x00ff00) >> 8;
sir[2] = (p & 0x0000ff);
rinsum += sir[0];
ginsum += sir[1];
binsum += sir[2];
rsum += rinsum;
gsum += ginsum;
bsum += binsum;
stackpointer = (stackpointer + 1) % div;
sir = stack[(stackpointer) % div];
routsum += sir[0];
goutsum += sir[1];
boutsum += sir[2];
rinsum -= sir[0];
ginsum -= sir[1];
binsum -= sir[2];
yi++;
}
yw += w;
}
for (x = 0; x < w; x++) {
rinsum = ginsum = binsum = routsum = goutsum = boutsum = rsum = gsum = bsum = 0;
yp = -radius * w;
for (i = -radius; i <= radius; i++) {
yi = Math.max(0, yp) + x;
sir = stack[i + radius];
sir[0] = r[yi];
sir[1] = g[yi];
sir[2] = b[yi];
rbs = r1 - Math.abs(i);
rsum += r[yi] * rbs;
gsum += g[yi] * rbs;
bsum += b[yi] * rbs;
if (i > 0) {
rinsum += sir[0];
ginsum += sir[1];
binsum += sir[2];
} else {
routsum += sir[0];
goutsum += sir[1];
boutsum += sir[2];
}
if (i < hm) {
yp += w;
}
}
yi = x;
stackpointer = radius;
for (y = 0; y < h; y++) {
// Preserve alpha channel: ( 0xff000000 & pix[yi] )
pix[yi] = (0xff000000 & pix[yi]) | (dv[rsum] << 16) | (dv[gsum] << 8) | dv[bsum];
rsum -= routsum;
gsum -= goutsum;
bsum -= boutsum;
stackstart = stackpointer - radius + div;
sir = stack[stackstart % div];
routsum -= sir[0];
goutsum -= sir[1];
boutsum -= sir[2];
if (x == 0) {
vmin[y] = Math.min(y + r1, hm) * w;
}
p = x + vmin[y];
sir[0] = r[p];
sir[1] = g[p];
sir[2] = b[p];
rinsum += sir[0];
ginsum += sir[1];
binsum += sir[2];
rsum += rinsum;
gsum += ginsum;
bsum += binsum;
stackpointer = (stackpointer + 1) % div;
sir = stack[stackpointer];
routsum += sir[0];
goutsum += sir[1];
boutsum += sir[2];
rinsum -= sir[0];
ginsum -= sir[1];
binsum -= sir[2];
yi += w;
}
}
bitmap.setPixels(pix, 0, w, 0, 0, w, h);
return (bitmap);
}
}

View File

@@ -0,0 +1,70 @@
package jp.wasabeef.glide.transformations.internal;
import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Bitmap;
import android.os.Build;
import android.renderscript.Allocation;
import android.renderscript.Element;
import android.renderscript.RSRuntimeException;
import android.renderscript.RenderScript;
import android.renderscript.ScriptIntrinsicBlur;
/**
* Copyright (C) 2018 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
public class RSBlur {
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
public static Bitmap blur(Context context, Bitmap bitmap, int radius) throws RSRuntimeException {
RenderScript rs = null;
Allocation input = null;
Allocation output = null;
ScriptIntrinsicBlur blur = null;
try {
rs = RenderScript.create(context);
rs.setMessageHandler(new RenderScript.RSMessageHandler());
input = Allocation.createFromBitmap(rs, bitmap, Allocation.MipmapControl.MIPMAP_NONE,
Allocation.USAGE_SCRIPT);
output = Allocation.createTyped(rs, input.getType());
blur = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
blur.setInput(input);
blur.setRadius(radius);
blur.forEach(output);
output.copyTo(bitmap);
} finally {
if (rs != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
RenderScript.releaseAllContexts();
} else {
rs.destroy();
}
}
if (input != null) {
input.destroy();
}
if (output != null) {
output.destroy();
}
if (blur != null) {
blur.destroy();
}
}
return bitmap;
}
}

View File

@@ -0,0 +1,43 @@
package jp.wasabeef.glide.transformations.internal;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Build;
/**
* Copyright (C) 2018 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
public final class Utils {
private Utils() {
// Utility class.
}
public static Drawable getMaskDrawable(Context context, int maskId) {
Drawable drawable;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
drawable = context.getDrawable(maskId);
} else {
drawable = context.getResources().getDrawable(maskId);
}
if (drawable == null) {
throw new IllegalArgumentException("maskId is invalid");
}
return drawable;
}
}