Compare commits
167 Commits
1.0.0
...
8144929b63
Author | SHA1 | Date | |
---|---|---|---|
|
8144929b63 | ||
|
059782f6af | ||
|
09e62054e9 | ||
|
4b4f6b1ad4 | ||
|
074b6eef45 | ||
|
fa04c1b3c9 | ||
|
056adc6451 | ||
|
1c925c932e | ||
|
b08325ec70 | ||
|
e9acc52d9e | ||
|
ce14f7bdf1 | ||
|
0b9311813a | ||
|
e16eda6af1 | ||
|
783d69c579 | ||
|
ec0e655f0a | ||
|
9d4d7990d3 | ||
|
d67f715c65 | ||
|
f09f073442 | ||
|
2e2846d354 | ||
|
3aa8e53c6a | ||
|
4818373fc5 | ||
|
8c72ad64b9 | ||
|
81e72fc553 | ||
|
0361d97018 | ||
|
9b00767304 | ||
|
a5f7017f57 | ||
|
9e85b0b759 | ||
|
51f7b515fa | ||
|
43f38cc4b3 | ||
|
970afc35fe | ||
|
f6cbe2722d | ||
|
1264e01f6e | ||
|
1a474cdd8c | ||
|
311bcde37f | ||
|
945e5a8063 | ||
|
30b41fa167 | ||
|
2a720df48d | ||
|
06db3295a1 | ||
|
34cc92f7a4 | ||
|
5715d7a999 | ||
|
36c0d00ae9 | ||
|
a29346e8d2 | ||
|
c3f2ce75a4 | ||
|
4d47793f79 | ||
|
45c2e3bcfe | ||
|
a139c21d31 | ||
|
c3f09cdd0d | ||
|
ddd76d4f06 | ||
|
f9bca8887d | ||
|
592815a6a0 | ||
|
f6540b111f | ||
|
9bea464afc | ||
|
219b32bbcc | ||
|
4d7190847c | ||
|
0d7a93c264 | ||
|
e69f775ddd | ||
|
4b9cf87770 | ||
|
cafad91b0b | ||
|
933c3f7989 | ||
|
68bafb0f53 | ||
|
817b138980 | ||
|
a908abc7d4 | ||
|
3e0738de0a | ||
|
dff7328f6e | ||
|
f5cb7392d6 | ||
|
d8a12b02b8 | ||
|
a6a2b625ad | ||
|
f488f09b19 | ||
|
76b7e3b719 | ||
|
c29df80ae9 | ||
|
aef7541ea3 | ||
|
71255edcd0 | ||
|
4a268b6dbd | ||
|
eef0be6b92 | ||
|
260f91e291 | ||
|
36ceccb38e | ||
|
e3a035d5cb | ||
|
656ea50911 | ||
|
e2cf4fd7eb | ||
|
e387df2daa | ||
|
5b311f74f6 | ||
|
62f3ee6b4a | ||
|
3150b4c8d5 | ||
|
410d94b7b1 | ||
|
a559d8bea8 | ||
|
4629d5e375 | ||
|
113200de55 | ||
|
143efe2ea7 | ||
|
fe864e498b | ||
|
f2f1229c8d | ||
|
f1246ff9ee | ||
|
d063aac6fa | ||
|
cb3cd88ed2 | ||
|
57fcfce9df | ||
|
347326dafa | ||
|
b4332f8c8d | ||
|
39b9d6aa6b | ||
|
2c08c1fb5e | ||
|
abde4c694d | ||
|
d5616ec9fa | ||
|
1253147c4a | ||
|
7614f1326a | ||
|
5cf3e3d934 | ||
|
efc447d2f7 | ||
|
23b623c882 | ||
|
f9ea19aaae | ||
|
831f038d29 | ||
|
eed7b944e5 | ||
|
46d5d4d72f | ||
|
6ebfdbe581 | ||
|
2a4eb22841 | ||
|
2cc2104802 | ||
|
f83e5ef85a | ||
|
cdbd42595a | ||
|
987651f9da | ||
|
ad376134e9 | ||
|
3f695c1e9c | ||
|
58e25e613c | ||
|
c914548296 | ||
|
cfe6dc313a | ||
|
136a5512c0 | ||
|
32d0c1de82 | ||
|
e23753044e | ||
|
decd2e58d5 | ||
|
e9d2c6d209 | ||
|
79e975d490 | ||
|
a21cfb1d86 | ||
|
c0ab4282d9 | ||
|
15effa238b | ||
|
ef39ca2782 | ||
|
bdda7cdf36 | ||
|
3890c84a0f | ||
|
e3c0c8d597 | ||
|
f7d0541a19 | ||
|
900db8bc93 | ||
|
c241532a58 | ||
|
8f63c10eb9 | ||
|
6468276c50 | ||
|
e0fb7c34e0 | ||
|
4c23e38206 | ||
|
ffae37274c | ||
|
0c6f696ba7 | ||
|
3aea08abaa | ||
|
883c131ad6 | ||
|
ee1f533999 | ||
|
68a9097962 | ||
|
6269999abc | ||
|
7e93ccd9af | ||
|
07b7d24e13 | ||
|
ca648cbc7d | ||
|
67ac3e31a4 | ||
|
1534573e8f | ||
|
a5487ade83 | ||
|
62abca0b1e | ||
|
a6bbdb0694 | ||
|
2f75284dd4 | ||
|
5772f60c61 | ||
|
cf5b0bbf1d | ||
|
a0e4705452 | ||
|
d474911010 | ||
|
5775d8211c | ||
|
3c3d2c0123 | ||
|
ccf79de0f0 | ||
|
b7f1b8cd50 | ||
|
6481449de7 | ||
|
dd94a0a16a | ||
|
bf2eaadf2d |
7
.editorconfig
Normal file
@@ -0,0 +1,7 @@
|
||||
[*]
|
||||
indent_size = 2
|
||||
max_line_length = off
|
||||
insert_final_newline = true
|
||||
|
||||
[*.{kt, kts}]
|
||||
kotlin_imports_layout = ascii
|
12
.github/FUNDING.yml
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: wasabeef # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
|
||||
patreon: # Replace with a single Patreon username
|
||||
open_collective: # Replace with a single Open Collective username
|
||||
ko_fi: # Replace with a single Ko-fi username
|
||||
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
||||
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
||||
liberapay: # Replace with a single Liberapay username
|
||||
issuehunt: # Replace with a single IssueHunt username
|
||||
otechie: # Replace with a single Otechie username
|
||||
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
28
.github/ISSUE_TEMPLATE.md
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
# Future Task
|
||||
|
||||
## What is the motivation?
|
||||
|
||||
## What kind of solution can be considered?
|
||||
|
||||
## What do you want to discuss?
|
||||
|
||||
*Please add relevant labels*
|
||||
|
||||
-----
|
||||
|
||||
# Bug Reporting
|
||||
|
||||
## Steps to Reproduce
|
||||
|
||||
## Actual Results (include screenshots)
|
||||
|
||||
## Expected Results (include screenshots)
|
||||
|
||||
## URL
|
||||
|
||||
## OS details
|
||||
|
||||
- Device:
|
||||
- OS:
|
||||
|
||||
*Please add relevant labels*
|
6
.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
## What does this change?
|
||||
|
||||
## What is the value of this and can you measure success?
|
||||
|
||||
## Screenshots
|
||||
|
64
.gitignore
vendored
@@ -1,19 +1,23 @@
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
# Mac OS
|
||||
.DS_store
|
||||
|
||||
# gradle files
|
||||
.gradle
|
||||
# Built application files
|
||||
*.apk
|
||||
*.ap_
|
||||
|
||||
# Intellij project files
|
||||
.idea
|
||||
*.iml
|
||||
# Files for the ART/Dalvik VM
|
||||
*.dex
|
||||
|
||||
# generated files
|
||||
# Java class files
|
||||
*.class
|
||||
|
||||
# Generated files
|
||||
bin/
|
||||
gen/
|
||||
obj/
|
||||
apk/
|
||||
target/
|
||||
out/
|
||||
|
||||
# Gradle files
|
||||
.gradle/
|
||||
build/
|
||||
|
||||
# Local configuration file (sdk path, etc)
|
||||
@@ -21,3 +25,41 @@ local.properties
|
||||
|
||||
# Proguard folder generated by Eclipse
|
||||
proguard/
|
||||
|
||||
# Log Files
|
||||
*.log
|
||||
|
||||
# Android Studio Navigation editor temp files
|
||||
.navigation/
|
||||
|
||||
# Android Studio captures folder
|
||||
captures/
|
||||
|
||||
# IntelliJ
|
||||
*.iml
|
||||
.idea/workspace.xml
|
||||
.idea/tasks.xml
|
||||
.idea/gradle.xml
|
||||
.idea/assetWizardSettings.xml
|
||||
.idea/dictionaries
|
||||
.idea/libraries
|
||||
.idea/caches
|
||||
.idea/misc.xml
|
||||
.idea/modules.xml
|
||||
.idea/navEditor.xml
|
||||
.idea/markdown*
|
||||
.idea/jarRepositories.xml
|
||||
.idea/inspectionProfiles/Project_Default.xml
|
||||
.idea/compiler.xml
|
||||
projectFilesBackup/
|
||||
|
||||
# Keystore files
|
||||
# Uncomment the following line if you do not want to check your keystore files in.
|
||||
#*.jks
|
||||
|
||||
# External native build folder generated in Android Studio 2.2 and later
|
||||
.externalNativeBuild
|
||||
|
||||
# Google Services (e.g. APIs or Firebase)
|
||||
google-services.json
|
||||
|
||||
|
116
.idea/codeStyles/Project.xml
generated
Normal file
@@ -0,0 +1,116 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<code_scheme name="Project" version="173">
|
||||
<codeStyleSettings language="XML">
|
||||
<indentOptions>
|
||||
<option name="CONTINUATION_INDENT_SIZE" value="4" />
|
||||
</indentOptions>
|
||||
<arrangement>
|
||||
<rules>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>xmlns:android</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>xmlns:.*</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*:id</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*:name</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>name</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>style</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>ANDROID_ATTRIBUTE_ORDER</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>.*</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
</rules>
|
||||
</arrangement>
|
||||
</codeStyleSettings>
|
||||
</code_scheme>
|
||||
</component>
|
5
.idea/codeStyles/codeStyleConfig.xml
generated
Normal file
@@ -0,0 +1,5 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<state>
|
||||
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
|
||||
</state>
|
||||
</component>
|
4
.idea/encodings.xml
generated
Normal file
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding" addBOMForNewFiles="with NO BOM" />
|
||||
</project>
|
12
.idea/runConfigurations.xml
generated
Normal file
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RunConfigurationProducerService">
|
||||
<option name="ignoredProducers">
|
||||
<set>
|
||||
<option value="org.jetbrains.plugins.gradle.execution.test.runner.AllInPackageGradleConfigurationProducer" />
|
||||
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer" />
|
||||
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer" />
|
||||
</set>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
6
.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
214
CHANGELOG.md
@@ -1,6 +1,220 @@
|
||||
Change Log
|
||||
==========
|
||||
|
||||
Version 4.3.0 *(2020-09-27)*
|
||||
----------------------------
|
||||
|
||||
Feature
|
||||
- Remove support v8 renderscript (Please use BlurTransformation)
|
||||
|
||||
Update
|
||||
- minSdkVersion -> 21
|
||||
- GPUImage -> 2.1.0
|
||||
- Cleanup codes
|
||||
|
||||
Version 4.2.0 *(2020-09-15)*
|
||||
----------------------------
|
||||
|
||||
Update:
|
||||
- Compile & Target SDK Version 28 -> 30
|
||||
- GPUImage 2.0.3 -> 2.0.4
|
||||
- Glide 4.9.0 -> 4.11.0
|
||||
|
||||
Bugfix:
|
||||
- RoundedCornersTransformation with DIAGONAL_FROM_TOP_LEFT does not work [#178](https://github.com/wasabeef/glide-transformations/pull/178)
|
||||
|
||||
Version 4.1.0 *(2019-08-15)*
|
||||
----------------------------
|
||||
|
||||
Add:
|
||||
- Support to CropCircle with Border [#136](https://github.com/wasabeef/glide-transformations/pull/136)
|
||||
|
||||
Update:
|
||||
- Glide to 4.9.0
|
||||
- Android Gradle plugin to 3.6.0-alpha05
|
||||
- Kotlin to 1.3.41
|
||||
|
||||
Bug Fix:
|
||||
- Fix diffrent density [#147](https://github.com/wasabeef/glide-transformations/pull/147)
|
||||
|
||||
|
||||
Version 4.0.1 *(2018-11-20)*
|
||||
----------------------------
|
||||
|
||||
Add:
|
||||
- consumerProguardFiles setting
|
||||
|
||||
Version 4.0.0 *(2018-11-16)*
|
||||
----------------------------
|
||||
|
||||
Update:
|
||||
- Migrate to AndroidX
|
||||
- Remove novoda-bintray-plugin
|
||||
|
||||
Version 3.3.0 *(2018-04-23)*
|
||||
----------------------------
|
||||
|
||||
Update:
|
||||
- Support Library 27.1.0 -> 27.1.1
|
||||
- Glide 4.6.1 -> 4.7.1
|
||||
|
||||
Feature:
|
||||
- SupportRSBlurTransformation [#125](https://github.com/wasabeef/glide-transformations/pull/125)
|
||||
it's using RenderScript support mode but can you choose to use or not.
|
||||
Thank you [@fougere-mike](https://github.com/fougere-mike)
|
||||
|
||||
Bug Fix:
|
||||
- Set detail of Cache key [#119](https://github.com/wasabeef/glide-transformations/issues/119)
|
||||
|
||||
Version 3.2.0 *(2018-04-10)*
|
||||
----------------------------
|
||||
|
||||
Update:
|
||||
- Support Library 27.0.2 -> 27.1.0
|
||||
|
||||
Bug Fix:
|
||||
- We quit use the RenderScript [#120](https://github.com/wasabeef/glide-transformations/issues/120)
|
||||
|
||||
Version 3.1.1 *(2018-02-13)*
|
||||
----------------------------
|
||||
|
||||
Update:
|
||||
- Glide 4.5.0 -> 4.6.1
|
||||
|
||||
Bug Fix:
|
||||
- Fix settings fot proguard.
|
||||
|
||||
Version 3.1.0 *(2018-01-26)*
|
||||
----------------------------
|
||||
|
||||
Update:
|
||||
- Compile & Target SDK Version 25 -> 27
|
||||
- Build Tools 26.0.1 -> 27.0.3
|
||||
- Support Library 25.3.1 -> 27.0.2
|
||||
- Glide 4.0.0 -> 4.5.0
|
||||
|
||||
Bug Fix:
|
||||
- [Implement equals() and hashCode() methods #105](https://github.com/wasabeef/glide-transformations/pull/105)
|
||||
- Use RenderScript#releaseAllContexts
|
||||
|
||||
Version 3.0.1 *(2017-09-08)*
|
||||
----------------------------
|
||||
|
||||
Bug Fix:
|
||||
- [Deleted a setting for DexGuard #86](https://github.com/wasabeef/glide-transformations/issues/86)
|
||||
|
||||
Version 3.0.0 *(2017-09-06)*
|
||||
----------------------------
|
||||
|
||||
Update:
|
||||
- Build Tools 25.0.2 -> 26.0.1
|
||||
- Min SDK Version 11 -> 14
|
||||
- Glide 3.7.0 -> 4.0.0
|
||||
|
||||
Feature:
|
||||
- Supported Glide 4.0.0
|
||||
|
||||
Version 2.0.2 *(2017-03-17)*
|
||||
----------------------------
|
||||
|
||||
Update:
|
||||
- Compile & Target SDK Version 23 -> 25
|
||||
- Build Tools 23.0.2 -> 25.0.2
|
||||
- Support Library 23.2.1 -> 25.3.0
|
||||
- GPUImage for Android 1.3.0 -> 1.4.1
|
||||
|
||||
Bug Fix:
|
||||
- [Additional resource cleanup in RSBlur #45](https://github.com/wasabeef/glide-transformations/pull/45)
|
||||
|
||||
Version 2.0.1 *(2016-04-21)*
|
||||
----------------------------
|
||||
|
||||
Fix:
|
||||
[#35](https://github.com/wasabeef/glide-transformations/issues/35)
|
||||
RSInvalidStateException
|
||||
|
||||
Version 2.0.0 *(2016-03-02)*
|
||||
----------------------------
|
||||
|
||||
Say v8.RenderScript goodbye
|
||||
|
||||
Version 1.4.0 *(2016-02-28)*
|
||||
----------------------------
|
||||
|
||||
fix Issue [#29](https://github.com/wasabeef/glide-transformations/issues/29)
|
||||
Use FastBlur as a fallback upon RenderScript failure.
|
||||
|
||||
Version 1.3.1 *(2015-11-27)*
|
||||
----------------------------
|
||||
|
||||
Change the renderscriptTargetApi down to 20.
|
||||
Warning:Renderscript support mode is not currently supported with renderscript target 21+
|
||||
|
||||
fix: memory leak.
|
||||
|
||||
Version 1.3.0 *(2015-11-10)*
|
||||
----------------------------
|
||||
|
||||
add round corner type to RoundedCornersTransformation.
|
||||
Thanks to [kaelaela](https://github.com/kaelaela)
|
||||
|
||||
Version 1.2.1 *(2015-09-18)*
|
||||
----------------------------
|
||||
|
||||
Merged NinePatchMaskTransformation to MaskTransformation.
|
||||
|
||||
Version 1.2.0 *(2015-09-16)*
|
||||
----------------------------
|
||||
|
||||
add new transformations MaskTransformation and NinePatchMaskTransformation.
|
||||
Thanks to [start141](https://github.com/start141)
|
||||
|
||||
Version 1.1.0 *(2015-09-05)*
|
||||
----------------------------
|
||||
|
||||
Adjustment of default parameters.
|
||||
|
||||
Version 1.0.8 *(2015-07-24)*
|
||||
----------------------------
|
||||
|
||||
add DownSampling to BlurTransform
|
||||
|
||||
Version 1.0.7 *(2015-07-18)*
|
||||
----------------------------
|
||||
|
||||
Bug fix : Blur not working.
|
||||
|
||||
Version 1.0.6 *(2015-04-23)*
|
||||
----------------------------
|
||||
|
||||
add: CropType(Top, Center, Bottom) for CropTransformation.
|
||||
|
||||
Version 1.0.5 *(2015-03-09)*
|
||||
----------------------------
|
||||
|
||||
Bug fix: Transparency.
|
||||
|
||||
Version 1.0.4 *(2015-02-13)*
|
||||
----------------------------
|
||||
|
||||
Bug fix : remove original bitmap resource recycling.
|
||||
|
||||
Version 1.0.3 *(2015-02-05)*
|
||||
----------------------------
|
||||
|
||||
Bug fix
|
||||
|
||||
Version 1.0.2 *(2015-02-04)*
|
||||
----------------------------
|
||||
|
||||
Refactor: use BimapPool
|
||||
|
||||
Version 1.0.1 *(2015-01-21)*
|
||||
----------------------------
|
||||
|
||||
fix: Blur Transformation now woking at Android 4.3
|
||||
add: GPUImage to Gradle dependency
|
||||
|
||||
Version 1.0.0 *(2015-01-12)*
|
||||
----------------------------
|
||||
|
||||
|
88
README.md
@@ -8,6 +8,11 @@ An Android transformation library providing a variety of image transformations f
|
||||
|
||||
Please feel free to use this.
|
||||
|
||||
|
||||
#### Are you using Picasso or Fresco?
|
||||
[Picasso Transformations](https://github.com/wasabeef/picasso-transformations)
|
||||
[Fresco Processors](https://github.com/wasabeef/fresco-processors)
|
||||
|
||||
# Demo
|
||||
|
||||
### Original Image
|
||||
@@ -23,11 +28,13 @@ Please feel free to use this.
|
||||
#### Gradle
|
||||
```groovy
|
||||
repositories {
|
||||
jcenter()
|
||||
jcenter()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile 'jp.wasabeef:glide-transformations:1.0.0'
|
||||
implementation 'jp.wasabeef:glide-transformations:4.x.x'
|
||||
// If you want to use the GPU Filters
|
||||
implementation 'jp.co.cyberagent.android:gpuimage:2.1.0'
|
||||
}
|
||||
```
|
||||
|
||||
@@ -35,41 +42,69 @@ dependencies {
|
||||
|
||||
Set Glide Transform.
|
||||
|
||||
```java
|
||||
```kotlin
|
||||
Glide.with(this).load(R.drawable.demo)
|
||||
.bitmapTransform(new BlurTransformation(this, Glide.get(this).getBitmapPool()))
|
||||
.into((ImageView) findViewById(R.id.image));
|
||||
.apply(RequestOptions.bitmapTransform(BlurTransformation(25, 3)))
|
||||
.into(imageView)
|
||||
```
|
||||
|
||||
## Advanced Step 3
|
||||
|
||||
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))
|
||||
.into((ImageView) findViewById(R.id.image));
|
||||
```kotlin
|
||||
val multi = MultiTransformation<Bitmap>(
|
||||
BlurTransformation(25),
|
||||
RoundedCornersTransformation(128, 0, CornerType.BOTTOM))))
|
||||
Glide.with(this).load(R.drawable.demo)
|
||||
.apply(RequestOptions.bitmapTransform(multi))
|
||||
.into(imageView))
|
||||
```
|
||||
|
||||
## Transformations
|
||||
|
||||
### Crop
|
||||
`CropTransformation`, `CropCircleTransformation`, `CropSquareTransformation`
|
||||
- `CropTransformation`
|
||||
- `CropCircleTransformation`
|
||||
- `CropCircleWithBorderTransformation`
|
||||
- `CropSquareTransformation`
|
||||
- `RoundedCornersTransformation`
|
||||
|
||||
### Color
|
||||
`ColorFilterTransformation`, `GrayscaleTransformation`
|
||||
- `ColorFilterTransformation`
|
||||
- `GrayscaleTransformation`
|
||||
|
||||
### Blur
|
||||
`BlurTransformation`
|
||||
- `BlurTransformation`
|
||||
|
||||
### Filter (use [GPUImage](https://github.com/CyberAgent/android-gpuimage))
|
||||
`ToonFilterTransformation`, `SepiaFilterTransformation`, `ContrastFilterTransformation`
|
||||
`InvertFilterTransformation`, `PixelationFilterTransformation`, `SketchFilterTransformation`
|
||||
`SwirlFilterTransformation`, `KuwaharaFilterTransformation`, `VignetteFilterTransformation`
|
||||
### Mask
|
||||
- `MaskTransformation`
|
||||
|
||||
### Other
|
||||
`RoundedCornersTransformation`
|
||||
### GPU Filter (use [GPUImage](https://github.com/CyberAgent/android-gpuimage))
|
||||
**Will require add dependencies for GPUImage.**
|
||||
|
||||
- `ToonFilterTransformation`
|
||||
- `SepiaFilterTransformation`
|
||||
- `ContrastFilterTransformation`
|
||||
- `InvertFilterTransformation`
|
||||
- `PixelationFilterTransformation`
|
||||
- `SketchFilterTransformation`
|
||||
- `SwirlFilterTransformation`
|
||||
- `BrightnessFilterTransformation`
|
||||
- `KuwaharaFilterTransformation`
|
||||
- `VignetteFilterTransformation`
|
||||
|
||||
|
||||
Applications using Glide Transformations
|
||||
---
|
||||
|
||||
Please [ping](mailto:dadadada.chop@gmail.com) me or send a pull request if you would like to be added here.
|
||||
|
||||
Icon | Application
|
||||
------------ | -------------
|
||||
<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
|
||||
-------
|
||||
@@ -77,9 +112,20 @@ Daichi Furiya (Wasabeef) - <dadadada.chop@gmail.com>
|
||||
|
||||
<a href="https://twitter.com/wasabeef_jp">
|
||||
<img alt="Follow me on Twitter"
|
||||
src="https://raw.githubusercontent.com/wasabeef/wasabeef.github.io/master/art/twitter.png" width="75"/>
|
||||
src="https://raw.githubusercontent.com/wasabeef/art/master/twitter.png" width="75"/>
|
||||
</a>
|
||||
|
||||
Contributions
|
||||
-------
|
||||
|
||||
Any contributions are welcome!
|
||||
|
||||
Contributors
|
||||
-------
|
||||
|
||||
* [start141](https://github.com/start141)
|
||||
* [squeeish](https://github.com/squeeish)
|
||||
|
||||
Thanks
|
||||
-------
|
||||
|
||||
@@ -88,7 +134,7 @@ Thanks
|
||||
License
|
||||
-------
|
||||
|
||||
Copyright 2015 Wasabeef
|
||||
Copyright (C) 2020 Wasabeef
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
BIN
art/demo.gif
Before Width: | Height: | Size: 9.9 MiB After Width: | Height: | Size: 3.9 MiB |
31
build.gradle
@@ -1,20 +1,27 @@
|
||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:1.0.+'
|
||||
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
|
||||
ext {
|
||||
kotlin_version = '1.3.72'
|
||||
glide_version = '4.11.0'
|
||||
gpuimage_version = '2.1.0'
|
||||
}
|
||||
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
// in the individual module build.gradle files
|
||||
}
|
||||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:4.2.0-alpha12'
|
||||
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.5'
|
||||
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
}
|
||||
}
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
jcenter()
|
||||
}
|
||||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
}
|
||||
}
|
||||
|
@@ -1,57 +1,41 @@
|
||||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'kotlin-android'
|
||||
apply plugin: 'kotlin-kapt'
|
||||
|
||||
android {
|
||||
compileSdkVersion COMPILE_SDK_VERSION as int
|
||||
buildToolsVersion BUILD_TOOLS_VERSION
|
||||
compileSdkVersion COMPILE_SDK_VERSION as int
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion MIN_SDK_VERSION as int
|
||||
targetSdkVersion TARGET_SDK_VERSION as int
|
||||
versionCode VERSION_CODE as int
|
||||
versionName VERSION_NAME
|
||||
defaultConfig {
|
||||
minSdkVersion MIN_SDK_VERSION as int
|
||||
targetSdkVersion TARGET_SDK_VERSION as int
|
||||
versionCode VERSION_CODE as int
|
||||
versionName VERSION_NAME
|
||||
}
|
||||
|
||||
// SigningConfigs
|
||||
apply from: '../signingConfigs/debug.gradle', to: android
|
||||
|
||||
buildTypes {
|
||||
debug {
|
||||
debuggable true
|
||||
signingConfig signingConfigs.debug
|
||||
}
|
||||
|
||||
signingConfigs {
|
||||
release {
|
||||
storeFile file(keyStoreProperty)
|
||||
keyAlias keyAliasProperty
|
||||
storePassword keyStorePasswordProperty
|
||||
keyPassword keyAliasPasswordProperty
|
||||
}
|
||||
release {
|
||||
debuggable false
|
||||
zipAlignEnabled true
|
||||
minifyEnabled true
|
||||
shrinkResources true
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
debug {
|
||||
debuggable true
|
||||
zipAlignEnabled true
|
||||
}
|
||||
release {
|
||||
debuggable false
|
||||
zipAlignEnabled true
|
||||
signingConfig signingConfigs.release
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def getKeyStoreProperty() {
|
||||
return hasProperty('WASABEEF_KEYSTORE') ? WASABEEF_KEYSTORE : "debug.keystore"
|
||||
}
|
||||
|
||||
def getKeyAliasProperty() {
|
||||
return hasProperty('WASABEEF_KEYALIAS') ? WASABEEF_KEYALIAS : "android"
|
||||
}
|
||||
|
||||
def getKeyStorePasswordProperty() {
|
||||
return hasProperty('WASABEEF_KEYSTOREPASSWORD') ? WASABEEF_KEYSTOREPASSWORD : "androiddebugkey"
|
||||
}
|
||||
|
||||
def getKeyAliasPasswordProperty() {
|
||||
return hasProperty('WASABEEF_KEYALIASPASSWORD') ? WASABEEF_KEYALIASPASSWORD : "android"
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile project(':transformations')
|
||||
compile 'com.android.support:appcompat-v7:+'
|
||||
compile 'com.android.support:recyclerview-v7:21.+'
|
||||
compile 'com.github.bumptech.glide:glide:3.+'
|
||||
implementation project(':transformations')
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
||||
implementation "com.github.bumptech.glide:glide:$glide_version"
|
||||
kapt "com.github.bumptech.glide:compiler:$glide_version"
|
||||
implementation "jp.co.cyberagent.android:gpuimage:$gpuimage_version"
|
||||
implementation "androidx.appcompat:appcompat:1.3.0-alpha02"
|
||||
implementation "androidx.recyclerview:recyclerview:1.2.0-alpha05"
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
|
||||
}
|
||||
|
0
example/proguard-rules.pro
vendored
Normal file
@@ -1,21 +1,23 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="jp.wasabeef.example.glide" >
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
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"
|
||||
tools:ignore="GoogleAppIndexingWarning">
|
||||
<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>
|
||||
|
23
example/src/main/java/jp/wasabeef/example/glide/Ext.kt
Normal file
@@ -0,0 +1,23 @@
|
||||
package jp.wasabeef.example.glide
|
||||
|
||||
/**
|
||||
* Copyright (C) 2020 Wasabeef
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import android.content.res.Resources
|
||||
|
||||
val Float.px: Float get() = (this * Resources.getSystem().displayMetrics.density)
|
||||
|
||||
val Int.px: Int get() = ((this * Resources.getSystem().displayMetrics.density).toInt())
|
@@ -1,45 +0,0 @@
|
||||
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.widget.RecyclerView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import jp.wasabeef.example.glide.MainAdapter.Type;
|
||||
|
||||
|
||||
public class MainActivity extends ActionBarActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.list);
|
||||
recyclerView.setLayoutManager(new GridLayoutManager(this, 2));
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
@@ -0,0 +1,24 @@
|
||||
package jp.wasabeef.example.glide
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import jp.wasabeef.example.glide.MainAdapter.Type.*
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_main)
|
||||
|
||||
findViewById<RecyclerView>(R.id.list).apply {
|
||||
layoutManager = LinearLayoutManager(context)
|
||||
adapter = MainAdapter(context, mutableListOf(
|
||||
Mask, NinePatchMask, RoundedCorners, CropTop, CropCenter, CropBottom, CropSquare, CropCircle,
|
||||
CropCircleWithBorder, Grayscale, BlurLight, BlurDeep, Toon, Sepia, Contrast, Invert,
|
||||
Pixel, Sketch, Swirl, Brightness, Kuawahara, Vignette
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,160 +0,0 @@
|
||||
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;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
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.GrayscaleTransformation;
|
||||
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
|
||||
import jp.wasabeef.glide.transformations.gpu.BrightnessFilterTransformation;
|
||||
import jp.wasabeef.glide.transformations.gpu.ContrastFilterTransformation;
|
||||
import jp.wasabeef.glide.transformations.gpu.InvertFilterTransformation;
|
||||
import jp.wasabeef.glide.transformations.gpu.KuwaharaFilterTransformation;
|
||||
import jp.wasabeef.glide.transformations.gpu.PixelationFilterTransformation;
|
||||
import jp.wasabeef.glide.transformations.gpu.SepiaFilterTransformation;
|
||||
import jp.wasabeef.glide.transformations.gpu.SketchFilterTransformation;
|
||||
import jp.wasabeef.glide.transformations.gpu.SwirlFilterTransformation;
|
||||
import jp.wasabeef.glide.transformations.gpu.ToonFilterTransformation;
|
||||
import jp.wasabeef.glide.transformations.gpu.VignetteFilterTransformation;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
enum Type {
|
||||
Crop,
|
||||
CropSquare,
|
||||
CropCircle,
|
||||
ColorFilter,
|
||||
Grayscale,
|
||||
RoundedCorners,
|
||||
Blur,
|
||||
Toon,
|
||||
Sepia,
|
||||
Contrast,
|
||||
Invert,
|
||||
Pixel,
|
||||
Sketch,
|
||||
Swirl,
|
||||
Brightness,
|
||||
Kuawahara,
|
||||
Vignette
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
203
example/src/main/java/jp/wasabeef/example/glide/MainAdapter.kt
Normal file
@@ -0,0 +1,203 @@
|
||||
package jp.wasabeef.example.glide
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.Color
|
||||
import android.graphics.PointF
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.bumptech.glide.Glide
|
||||
import com.bumptech.glide.load.MultiTransformation
|
||||
import com.bumptech.glide.load.resource.bitmap.CenterCrop
|
||||
import com.bumptech.glide.request.RequestOptions.bitmapTransform
|
||||
import com.bumptech.glide.request.RequestOptions.overrideOf
|
||||
import jp.wasabeef.example.glide.MainAdapter.Type.*
|
||||
import jp.wasabeef.glide.transformations.*
|
||||
import jp.wasabeef.glide.transformations.CropTransformation.CropType
|
||||
import jp.wasabeef.glide.transformations.gpu.*
|
||||
import jp.wasabeef.glide.transformations.internal.Utils
|
||||
|
||||
/**
|
||||
* Created by Wasabeef on 2015/01/11.
|
||||
*/
|
||||
class MainAdapter(
|
||||
private val context: Context,
|
||||
private val dataSet: MutableList<Type>
|
||||
) : RecyclerView.Adapter<MainAdapter.ViewHolder>() {
|
||||
|
||||
enum class Type {
|
||||
Mask,
|
||||
NinePatchMask,
|
||||
CropTop,
|
||||
CropCenter,
|
||||
CropBottom,
|
||||
CropSquare,
|
||||
CropCircle,
|
||||
CropCircleWithBorder,
|
||||
ColorFilter,
|
||||
Grayscale,
|
||||
RoundedCorners,
|
||||
BlurLight,
|
||||
BlurDeep,
|
||||
Toon,
|
||||
Sepia,
|
||||
Contrast,
|
||||
Invert,
|
||||
Pixel,
|
||||
Sketch,
|
||||
Swirl,
|
||||
Brightness,
|
||||
Kuawahara,
|
||||
Vignette
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return dataSet.size
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
val v = LayoutInflater.from(context).inflate(R.layout.layout_list_item, parent, false)
|
||||
return ViewHolder(v)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
|
||||
when (dataSet[position]) {
|
||||
Mask -> {
|
||||
Glide.with(context)
|
||||
.load(R.drawable.check)
|
||||
.apply(overrideOf(266.px, 252.px))
|
||||
.apply(bitmapTransform(MultiTransformation<Bitmap>(CenterCrop(),
|
||||
MaskTransformation(R.drawable.mask_starfish))))
|
||||
.into(holder.image)
|
||||
}
|
||||
NinePatchMask -> {
|
||||
Glide.with(context)
|
||||
.load(R.drawable.check)
|
||||
.apply(overrideOf(300.px, 200.px))
|
||||
.apply(bitmapTransform(MultiTransformation<Bitmap>(CenterCrop(),
|
||||
MaskTransformation(R.drawable.mask_chat_right))))
|
||||
.into(holder.image)
|
||||
}
|
||||
|
||||
CropTop -> Glide.with(context)
|
||||
.load(R.drawable.demo)
|
||||
.apply(bitmapTransform(CropTransformation(300.px, 100.px, CropType.TOP)))
|
||||
.into(holder.image)
|
||||
|
||||
CropCenter -> Glide.with(context)
|
||||
.load(R.drawable.demo)
|
||||
.apply(bitmapTransform(CropTransformation(300.px, 100.px, CropType.CENTER)))
|
||||
.into(holder.image)
|
||||
|
||||
CropBottom -> Glide.with(context)
|
||||
.load(R.drawable.demo)
|
||||
.apply(bitmapTransform(CropTransformation(300.px, 100.px, CropType.BOTTOM)))
|
||||
.into(holder.image)
|
||||
|
||||
CropSquare -> Glide.with(context)
|
||||
.load(R.drawable.demo)
|
||||
.apply(bitmapTransform(CropSquareTransformation()))
|
||||
.into(holder.image)
|
||||
|
||||
CropCircle -> Glide.with(context)
|
||||
.load(R.drawable.demo)
|
||||
.apply(bitmapTransform(CropCircleTransformation()))
|
||||
.into(holder.image)
|
||||
|
||||
CropCircleWithBorder -> Glide.with(context)
|
||||
.load(R.drawable.demo)
|
||||
.apply(bitmapTransform(
|
||||
CropCircleWithBorderTransformation(Utils.toDp(4), Color.rgb(0, 145, 86))))
|
||||
.into(holder.image)
|
||||
|
||||
ColorFilter -> Glide.with(context)
|
||||
.load(R.drawable.demo)
|
||||
.apply(bitmapTransform(ColorFilterTransformation(Color.argb(80, 255, 0, 0))))
|
||||
.into(holder.image)
|
||||
|
||||
Grayscale -> Glide.with(context)
|
||||
.load(R.drawable.demo)
|
||||
.apply(bitmapTransform(GrayscaleTransformation()))
|
||||
.into(holder.image)
|
||||
|
||||
RoundedCorners -> Glide.with(context)
|
||||
.load(R.drawable.demo)
|
||||
.apply(bitmapTransform(RoundedCornersTransformation(120, 0,
|
||||
RoundedCornersTransformation.CornerType.DIAGONAL_FROM_TOP_LEFT)))
|
||||
.into(holder.image)
|
||||
|
||||
BlurLight -> Glide.with(context)
|
||||
.load(R.drawable.check)
|
||||
.apply(bitmapTransform(BlurTransformation(25)))
|
||||
.into(holder.image)
|
||||
|
||||
BlurDeep -> Glide.with(context)
|
||||
.load(R.drawable.check)
|
||||
.apply(bitmapTransform(BlurTransformation(25, 8)))
|
||||
.into(holder.image)
|
||||
|
||||
Toon -> Glide.with(context)
|
||||
.load(R.drawable.demo)
|
||||
.apply(bitmapTransform(ToonFilterTransformation()))
|
||||
.into(holder.image)
|
||||
|
||||
Sepia -> Glide.with(context)
|
||||
.load(R.drawable.check)
|
||||
.apply(bitmapTransform(SepiaFilterTransformation()))
|
||||
.into(holder.image)
|
||||
|
||||
Contrast -> Glide.with(context)
|
||||
.load(R.drawable.check)
|
||||
.apply(bitmapTransform(ContrastFilterTransformation(2.0f)))
|
||||
.into(holder.image)
|
||||
|
||||
Invert -> Glide.with(context)
|
||||
.load(R.drawable.check)
|
||||
.apply(bitmapTransform(InvertFilterTransformation()))
|
||||
.into(holder.image)
|
||||
|
||||
Pixel -> Glide.with(context)
|
||||
.load(R.drawable.check)
|
||||
.apply(bitmapTransform(PixelationFilterTransformation(20f)))
|
||||
.into(holder.image)
|
||||
|
||||
Sketch -> Glide.with(context)
|
||||
.load(R.drawable.check)
|
||||
.apply(bitmapTransform(SketchFilterTransformation()))
|
||||
.into(holder.image)
|
||||
|
||||
Swirl -> Glide.with(context)
|
||||
.load(R.drawable.check)
|
||||
.apply(bitmapTransform(
|
||||
SwirlFilterTransformation(0.5f, 1.0f, PointF(0.5f, 0.5f))).dontAnimate())
|
||||
.into(holder.image)
|
||||
|
||||
Brightness -> Glide.with(context)
|
||||
.load(R.drawable.check)
|
||||
.apply(bitmapTransform(BrightnessFilterTransformation(0.5f)).dontAnimate())
|
||||
.into(holder.image)
|
||||
|
||||
Kuawahara -> Glide.with(context)
|
||||
.load(R.drawable.check)
|
||||
.apply(bitmapTransform(KuwaharaFilterTransformation(25)).dontAnimate())
|
||||
.into(holder.image)
|
||||
|
||||
Vignette -> Glide.with(context)
|
||||
.load(R.drawable.check)
|
||||
.apply(bitmapTransform(VignetteFilterTransformation(PointF(0.5f, 0.5f),
|
||||
floatArrayOf(0.0f, 0.0f, 0.0f), 0f, 0.75f)).dontAnimate())
|
||||
.into(holder.image)
|
||||
}
|
||||
holder.title.text = dataSet[position].name
|
||||
}
|
||||
|
||||
class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
||||
var image: ImageView = itemView.findViewById(R.id.image)
|
||||
var title: TextView = itemView.findViewById(R.id.title)
|
||||
}
|
||||
}
|
Before Width: | Height: | Size: 9.2 KiB After Width: | Height: | Size: 3.3 KiB |
Before Width: | Height: | Size: 5.1 KiB After Width: | Height: | Size: 2.2 KiB |
BIN
example/src/main/res/drawable-xhdpi/check.png
Normal file
After Width: | Height: | Size: 484 KiB |
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 4.7 KiB |
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 7.5 KiB |
BIN
example/src/main/res/drawable-xxhdpi/mask_chat_right.9.png
Normal file
After Width: | Height: | Size: 1.9 KiB |
BIN
example/src/main/res/drawable-xxhdpi/mask_starfish.png
Normal file
After Width: | Height: | Size: 7.6 KiB |
@@ -1,13 +1,15 @@
|
||||
<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"?>
|
||||
<androidx.constraintlayout.widget.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>
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/list"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
@@ -1,24 +1,32 @@
|
||||
<?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">
|
||||
<androidx.constraintlayout.widget.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"/>
|
||||
<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_below="@id/image"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginTop="5dp"
|
||||
android:textColor="@android:color/white"/>
|
||||
|
||||
</RelativeLayout>
|
||||
<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" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
@@ -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>
|
||||
|
6
example/src/main/res/values/colors.xml
Normal 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>
|
@@ -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>
|
||||
|
@@ -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>
|
||||
|
@@ -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>
|
@@ -1,24 +1,16 @@
|
||||
VERSION_NAME=1.0.0
|
||||
VERSION_CODE=3
|
||||
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=1024m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
|
||||
org.gradle.parallel=true
|
||||
org.gradle.daemon=true
|
||||
org.gradle.configureondemand=true
|
||||
org.gradle.caching=true
|
||||
android.enableBuildCache=true
|
||||
android.useAndroidX=true
|
||||
# Use R8 instead of ProGuard for code shrinking.
|
||||
android.enableR8.fullMode=true
|
||||
|
||||
VERSION_NAME=4.3.0
|
||||
VERSION_CODE=421
|
||||
GROUP=jp.wasabeef
|
||||
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
|
||||
|
||||
POM_DESCRIPTION=which provides simple Tranformations to Glide
|
||||
POM_URL=https://github.com/wasabeef/glide-transformations
|
||||
POM_SCM_URL=scm:git@github.com:wasabeef/glide-transformations.git
|
||||
POM_SCM_CONNECTION=scm:git@github.com:wasabeef/glide-transformations.git
|
||||
POM_SCM_DEV_CONNECTION=scm:git@github.com:wasabeef/glide-transformations.git
|
||||
POM_LICENCE_NAME=The Apache Software License, Version 2.0
|
||||
POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
|
||||
POM_LICENCE_DIST=repo
|
||||
POM_DEVELOPER_ID=wasabeef
|
||||
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
|
||||
COMPILE_SDK_VERSION=30
|
||||
TARGET_SDK_VERSION=30
|
||||
MIN_SDK_VERSION=21
|
||||
|
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
3
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,6 +1,5 @@
|
||||
#Wed Apr 10 15:27:10 PDT 2013
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
|
||||
|
149
gradlew
vendored
@@ -1,4 +1,20 @@
|
||||
#!/usr/bin/env bash
|
||||
#!/usr/bin/env sh
|
||||
|
||||
#
|
||||
# Copyright 2015 the original author or authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
##
|
||||
@@ -6,47 +22,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,12 +36,53 @@ 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='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD="maximum"
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
}
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
}
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "`uname`" in
|
||||
CYGWIN* )
|
||||
cygwin=true
|
||||
;;
|
||||
Darwin* )
|
||||
darwin=true
|
||||
;;
|
||||
MINGW* )
|
||||
msys=true
|
||||
;;
|
||||
NONSTOP* )
|
||||
nonstop=true
|
||||
;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
@@ -90,7 +106,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
|
||||
@@ -110,11 +126,13 @@ if $darwin; then
|
||||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
||||
fi
|
||||
|
||||
# For Cygwin, switch paths to Windows format before running java
|
||||
if $cygwin ; then
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
|
||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||
|
||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||
|
||||
# We build the pattern for arguments to be converted via cygpath
|
||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
||||
SEP=""
|
||||
@@ -138,27 +156,30 @@ if $cygwin ; then
|
||||
else
|
||||
eval `echo args$i`="\"$arg\""
|
||||
fi
|
||||
i=$((i+1))
|
||||
i=`expr $i + 1`
|
||||
done
|
||||
case $i in
|
||||
(0) set -- ;;
|
||||
(1) set -- "$args0" ;;
|
||||
(2) set -- "$args0" "$args1" ;;
|
||||
(3) set -- "$args0" "$args1" "$args2" ;;
|
||||
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||
0) set -- ;;
|
||||
1) set -- "$args0" ;;
|
||||
2) set -- "$args0" "$args1" ;;
|
||||
3) set -- "$args0" "$args1" "$args2" ;;
|
||||
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# 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"
|
||||
|
||||
exec "$JAVACMD" "$@"
|
||||
|
53
gradlew.bat
vendored
@@ -1,3 +1,19 @@
|
||||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@@ -8,20 +24,23 @@
|
||||
@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 Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto init
|
||||
if "%ERRORLEVEL%" == "0" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
@@ -35,7 +54,7 @@ goto fail
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto init
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
@@ -45,34 +64,14 @@ echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:init
|
||||
@rem Get command-line arguments, handling Windowz 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.
|
||||
set CMD_LINE_ARGS=
|
||||
set _SKIP=2
|
||||
|
||||
:win9xME_args_slurp
|
||||
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
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
|
14
signingConfigs/debug.gradle
Normal file
@@ -0,0 +1,14 @@
|
||||
signingConfigs {
|
||||
debug {
|
||||
storeFile file("debug.keystore")
|
||||
storePassword "android"
|
||||
keyAlias "androiddebugkey"
|
||||
keyPassword "android"
|
||||
}
|
||||
}
|
||||
|
||||
// $ keytool -v -list -keystore
|
||||
// Certificate fingerprints:
|
||||
// MD5: 28:22:7C:A4:B9:2F:6E:C7:D5:58:62:48:EB:7E:82:C3
|
||||
// SHA1: 94:25:A9:50:9C:0E:AE:AA:00:37:5E:D6:71:E3:BC:ED:17:E5:0C:A3
|
||||
// SHA256: 04:92:39:09:3D:1C:B6:16:BE:55:58:A3:5F:3B:BB:CB:0B:E7:F1:DA:AA:26:C5:2D:BD:2F:44:CF:AE:47:CF:87
|
BIN
signingConfigs/debug.keystore
Normal 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
|
||||
}
|
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,42 +1,41 @@
|
||||
apply plugin: 'com.android.library'
|
||||
|
||||
android {
|
||||
compileSdkVersion COMPILE_SDK_VERSION as int
|
||||
buildToolsVersion BUILD_TOOLS_VERSION
|
||||
compileSdkVersion COMPILE_SDK_VERSION as int
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion MIN_SDK_VERSION as int
|
||||
targetSdkVersion TARGET_SDK_VERSION as int
|
||||
versionCode VERSION_CODE as int
|
||||
versionName VERSION_NAME
|
||||
renderscriptTargetApi RENDERSCRIPT_TARGET_API as int
|
||||
renderscriptSupportModeEnabled true
|
||||
}
|
||||
defaultConfig {
|
||||
minSdkVersion MIN_SDK_VERSION as int
|
||||
targetSdkVersion TARGET_SDK_VERSION as int
|
||||
|
||||
consumerProguardFiles 'proguard-rules.txt'
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile fileTree(dir: 'libs', include: ['*.jar'])
|
||||
compile 'com.github.bumptech.glide:glide:3.4.0'
|
||||
implementation "com.github.bumptech.glide:glide:$glide_version"
|
||||
annotationProcessor "com.github.bumptech.glide:compiler:$glide_version"
|
||||
compileOnly "jp.co.cyberagent.android:gpuimage:$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()}"]
|
||||
}
|
||||
ext {
|
||||
bintrayRepo = 'maven'
|
||||
bintrayName = 'glide-transformations'
|
||||
bintrayUserOrg = 'wasabeef'
|
||||
publishedGroupId = 'jp.wasabeef'
|
||||
libraryName = 'glide-transformations'
|
||||
artifact = 'glide-transformations'
|
||||
libraryDescription = 'Which provides simple Transformations to Glide'
|
||||
siteUrl = 'https://github.com/wasabeef/glide-transformations'
|
||||
gitUrl = 'https://github.com/wasabeef/glide-transformations.git'
|
||||
issueUrl = 'https://github.com/wasabeef/glide-transformations/issues'
|
||||
libraryVersion = VERSION_NAME
|
||||
developerId = 'wasabeef'
|
||||
developerName = 'Wasabeef'
|
||||
developerEmail = 'dadadada.chop@gmail.com'
|
||||
licenseName = 'The Apache Software License, Version 2.0'
|
||||
licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
|
||||
allLicenses = ["Apache-2.0"]
|
||||
}
|
||||
|
||||
apply from: 'android-artifacts.gradle'
|
||||
apply from: 'central-publish.gradle'
|
||||
apply from: 'bintray-publish.gradle'
|
||||
apply from: 'https://gist.githubusercontent.com/wasabeef/cf14805bee509baf7461974582f17d26/raw/bintray-v1.gradle'
|
||||
apply from: 'https://gist.githubusercontent.com/wasabeef/cf14805bee509baf7461974582f17d26/raw/install-v1.gradle'
|
||||
|
@@ -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
|
||||
}
|
||||
}
|
@@ -1,3 +0,0 @@
|
||||
POM_NAME=which provides simple Tranformations to Glide
|
||||
POM_ARTIFACT_ID=glide-transformations
|
||||
POM_PACKAGING=aar
|
8
transformations/proguard-rules.txt
Normal 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.ImageHeaderParser$** {
|
||||
**[] $VALUES;
|
||||
public *;
|
||||
}
|
@@ -8,7 +8,7 @@ import android.test.ApplicationTestCase;
|
||||
*/
|
||||
public class ApplicationTest extends ApplicationTestCase<Application> {
|
||||
|
||||
public ApplicationTest() {
|
||||
super(Application.class);
|
||||
}
|
||||
public ApplicationTest() {
|
||||
super(Application.class);
|
||||
}
|
||||
}
|
@@ -1,3 +1 @@
|
||||
<manifest
|
||||
package="jp.wasabeef.glide.transformations">
|
||||
</manifest>
|
||||
<manifest package="jp.wasabeef.glide.transformations" />
|
||||
|
@@ -0,0 +1,76 @@
|
||||
package jp.wasabeef.glide.transformations;
|
||||
|
||||
/**
|
||||
* Copyright (C) 2020 Wasabeef
|
||||
* Copyright 2014 Google, Inc. All rights reserved.
|
||||
* <p>
|
||||
* 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
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.Transformation;
|
||||
import com.bumptech.glide.load.engine.Resource;
|
||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
|
||||
import com.bumptech.glide.request.target.Target;
|
||||
import com.bumptech.glide.util.Util;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
|
||||
public abstract class BitmapTransformation implements Transformation<Bitmap> {
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public final Resource<Bitmap> transform(@NonNull Context context, @NonNull 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;
|
||||
}
|
||||
|
||||
void setCanvasBitmapDensity(@NonNull Bitmap toTransform, @NonNull Bitmap canvasBitmap) {
|
||||
canvasBitmap.setDensity(toTransform.getDensity());
|
||||
}
|
||||
|
||||
protected abstract Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
|
||||
@NonNull Bitmap toTransform, int outWidth, int outHeight);
|
||||
|
||||
@Override
|
||||
public abstract void updateDiskCacheKey(@NonNull MessageDigest messageDigest);
|
||||
|
||||
@Override
|
||||
public abstract boolean equals(Object o);
|
||||
|
||||
@Override
|
||||
public abstract int hashCode();
|
||||
}
|
356
transformations/src/main/java/jp/wasabeef/glide/transformations/BlurTransformation.java
Normal file → Executable file
@@ -1,14 +1,14 @@
|
||||
package jp.wasabeef.glide.transformations;
|
||||
|
||||
/**
|
||||
* Copyright (C) 2015 Wasabeef
|
||||
*
|
||||
* Copyright (C) 2020 Wasabeef
|
||||
* <p>
|
||||
* 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
|
||||
*
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* <p>
|
||||
* 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.
|
||||
@@ -16,289 +16,93 @@ 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.os.Build;
|
||||
import android.renderscript.Allocation;
|
||||
import android.renderscript.Element;
|
||||
import android.renderscript.RenderScript;
|
||||
import android.renderscript.ScriptIntrinsicBlur;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.renderscript.RSRuntimeException;
|
||||
|
||||
public class BlurTransformation implements Transformation<Bitmap> {
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
private static int MAX_RADIUS = 25;
|
||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||
|
||||
private Context mContext;
|
||||
private BitmapPool mBitmapPool;
|
||||
import java.security.MessageDigest;
|
||||
|
||||
private int mRadius;
|
||||
import jp.wasabeef.glide.transformations.internal.FastBlur;
|
||||
import jp.wasabeef.glide.transformations.internal.RSBlur;
|
||||
|
||||
public BlurTransformation(Context context, BitmapPool pool) {
|
||||
this(context, pool, MAX_RADIUS);
|
||||
public class BlurTransformation extends BitmapTransformation {
|
||||
|
||||
private static final int VERSION = 1;
|
||||
private static final String ID =
|
||||
"jp.wasabeef.glide.transformations.BlurTransformation." + VERSION;
|
||||
|
||||
private static final int MAX_RADIUS = 25;
|
||||
private static final int DEFAULT_DOWN_SAMPLING = 1;
|
||||
|
||||
private final int radius;
|
||||
private final int sampling;
|
||||
|
||||
public BlurTransformation() {
|
||||
this(MAX_RADIUS, DEFAULT_DOWN_SAMPLING);
|
||||
}
|
||||
|
||||
public BlurTransformation(int radius) {
|
||||
this(radius, DEFAULT_DOWN_SAMPLING);
|
||||
}
|
||||
|
||||
public BlurTransformation(int radius, int sampling) {
|
||||
this.radius = radius;
|
||||
this.sampling = sampling;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
|
||||
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
|
||||
|
||||
int width = toTransform.getWidth();
|
||||
int height = toTransform.getHeight();
|
||||
int scaledWidth = width / sampling;
|
||||
int scaledHeight = height / sampling;
|
||||
|
||||
Bitmap bitmap = pool.get(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
|
||||
|
||||
setCanvasBitmapDensity(toTransform, bitmap);
|
||||
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
canvas.scale(1 / (float) sampling, 1 / (float) sampling);
|
||||
Paint paint = new Paint();
|
||||
paint.setFlags(Paint.FILTER_BITMAP_FLAG);
|
||||
canvas.drawBitmap(toTransform, 0, 0, paint);
|
||||
|
||||
try {
|
||||
bitmap = RSBlur.blur(context, bitmap, radius);
|
||||
} catch (RSRuntimeException e) {
|
||||
bitmap = FastBlur.blur(bitmap, radius, true);
|
||||
}
|
||||
|
||||
public BlurTransformation(Context context, BitmapPool pool, int radius) {
|
||||
mContext = context;
|
||||
mBitmapPool = pool;
|
||||
this.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 + ")";
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT > 16) {
|
||||
Bitmap bitmap = source.copy(source.getConfig(), true);
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof BlurTransformation &&
|
||||
((BlurTransformation) o).radius == radius &&
|
||||
((BlurTransformation) o).sampling == sampling;
|
||||
}
|
||||
|
||||
final RenderScript rs = RenderScript.create(mContext);
|
||||
final Allocation input = Allocation.createFromBitmap(rs, source,
|
||||
Allocation.MipmapControl.MIPMAP_NONE,
|
||||
Allocation.USAGE_SCRIPT);
|
||||
final Allocation output = Allocation.createTyped(rs, input.getType());
|
||||
final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
|
||||
script.setRadius(mRadius /* e.g. 3.f */);
|
||||
script.setInput(input);
|
||||
script.forEach(output);
|
||||
output.copyTo(bitmap);
|
||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return ID.hashCode() + radius * 1000 + sampling * 10;
|
||||
}
|
||||
|
||||
// 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 = source.copy(source.getConfig(), true);
|
||||
|
||||
if (mRadius < 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 = mRadius + mRadius + 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 = mRadius + 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 = -mRadius; i <= mRadius; i++) {
|
||||
p = pix[yi + Math.min(wm, Math.max(i, 0))];
|
||||
sir = stack[i + mRadius];
|
||||
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 = mRadius;
|
||||
|
||||
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 - mRadius + div;
|
||||
sir = stack[stackstart % div];
|
||||
|
||||
routsum -= sir[0];
|
||||
goutsum -= sir[1];
|
||||
boutsum -= sir[2];
|
||||
|
||||
if (y == 0) {
|
||||
vmin[x] = Math.min(x + mRadius + 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 = -mRadius * w;
|
||||
for (i = -mRadius; i <= mRadius; i++) {
|
||||
yi = Math.max(0, yp) + x;
|
||||
|
||||
sir = stack[i + mRadius];
|
||||
|
||||
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 = mRadius;
|
||||
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 - mRadius + 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);
|
||||
source.recycle();
|
||||
|
||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return "BlurTransformation(radius=" + mRadius + ")";
|
||||
}
|
||||
@Override
|
||||
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
|
||||
messageDigest.update((ID + radius + sampling).getBytes(CHARSET));
|
||||
}
|
||||
}
|
||||
|
89
transformations/src/main/java/jp/wasabeef/glide/transformations/ColorFilterTransformation.java
Normal file → Executable file
@@ -1,14 +1,14 @@
|
||||
package jp.wasabeef.glide.transformations;
|
||||
|
||||
/**
|
||||
* Copyright (C) 2015 Wasabeef
|
||||
*
|
||||
* Copyright (C) 2020 Wasabeef
|
||||
* <p>
|
||||
* 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
|
||||
*
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* <p>
|
||||
* 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.
|
||||
@@ -16,49 +16,70 @@ 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;
|
||||
|
||||
public class ColorFilterTransformation implements Transformation<Bitmap> {
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
private BitmapPool mBitmapPool;
|
||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||
|
||||
private int mColor;
|
||||
import java.security.MessageDigest;
|
||||
|
||||
public ColorFilterTransformation(BitmapPool pool, int color) {
|
||||
mBitmapPool = pool;
|
||||
mColor = color;
|
||||
}
|
||||
public class ColorFilterTransformation extends BitmapTransformation {
|
||||
|
||||
@Override
|
||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
||||
Bitmap source = resource.get();
|
||||
private static final int VERSION = 1;
|
||||
private static final String ID =
|
||||
"jp.wasabeef.glide.transformations.ColorFilterTransformation." + VERSION;
|
||||
|
||||
int width = source.getWidth();
|
||||
int height = source.getHeight();
|
||||
private final int color;
|
||||
|
||||
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
||||
public ColorFilterTransformation(int color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
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);
|
||||
source.recycle();
|
||||
@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();
|
||||
|
||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||
}
|
||||
Bitmap.Config config =
|
||||
toTransform.getConfig() != null ? toTransform.getConfig() : Bitmap.Config.ARGB_8888;
|
||||
Bitmap bitmap = pool.get(width, height, config);
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return "ColorFilterTransformation(color=" + mColor + ")";
|
||||
}
|
||||
setCanvasBitmapDensity(toTransform, bitmap);
|
||||
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
Paint paint = new Paint();
|
||||
paint.setAntiAlias(true);
|
||||
paint.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP));
|
||||
canvas.drawBitmap(toTransform, 0, 0, paint);
|
||||
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ColorFilterTransformation(color=" + color + ")";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof ColorFilterTransformation &&
|
||||
((ColorFilterTransformation) o).color == color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return ID.hashCode() + color * 10;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
|
||||
messageDigest.update((ID + color).getBytes(CHARSET));
|
||||
}
|
||||
}
|
||||
|
84
transformations/src/main/java/jp/wasabeef/glide/transformations/CropCircleTransformation.java
Normal file → Executable file
@@ -1,14 +1,14 @@
|
||||
package jp.wasabeef.glide.transformations;
|
||||
|
||||
/**
|
||||
* Copyright (C) 2015 Wasabeef
|
||||
*
|
||||
* Copyright (C) 2020 Wasabeef
|
||||
* <p>
|
||||
* 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
|
||||
*
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* <p>
|
||||
* 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.
|
||||
@@ -16,56 +16,50 @@ 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;
|
||||
|
||||
public class CropCircleTransformation implements Transformation<Bitmap> {
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
private BitmapPool mBitmapPool;
|
||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||
import com.bumptech.glide.load.resource.bitmap.TransformationUtils;
|
||||
import com.bumptech.glide.request.RequestOptions;
|
||||
|
||||
public CropCircleTransformation(BitmapPool pool) {
|
||||
this.mBitmapPool = pool;
|
||||
}
|
||||
import java.security.MessageDigest;
|
||||
|
||||
@Override
|
||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
||||
Bitmap source = resource.get();
|
||||
int size = Math.min(source.getWidth(), source.getHeight());
|
||||
/**
|
||||
* @deprecated Use {@link RequestOptions#circleCrop()}.
|
||||
*/
|
||||
@Deprecated
|
||||
public class CropCircleTransformation extends BitmapTransformation {
|
||||
|
||||
int width = (source.getWidth() - size) / 2;
|
||||
int height = (source.getHeight() - size) / 2;
|
||||
private static final int VERSION = 1;
|
||||
private static final String ID =
|
||||
"jp.wasabeef.glide.transformations.CropCircleTransformation." + VERSION;
|
||||
|
||||
Bitmap squaredBitmap = Bitmap.createBitmap(source, width, height, size, size);
|
||||
if (squaredBitmap != source) {
|
||||
source.recycle();
|
||||
}
|
||||
@Override
|
||||
protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
|
||||
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
|
||||
return TransformationUtils.circleCrop(pool, toTransform, outWidth, outHeight);
|
||||
}
|
||||
|
||||
Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CropCircleTransformation()";
|
||||
}
|
||||
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
Paint paint = new Paint();
|
||||
BitmapShader shader = new BitmapShader(squaredBitmap, BitmapShader.TileMode.CLAMP,
|
||||
BitmapShader.TileMode.CLAMP);
|
||||
paint.setShader(shader);
|
||||
paint.setAntiAlias(true);
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof CropCircleTransformation;
|
||||
}
|
||||
|
||||
float r = size / 2f;
|
||||
canvas.drawCircle(r, r, r, paint);
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return ID.hashCode();
|
||||
}
|
||||
|
||||
squaredBitmap.recycle();
|
||||
|
||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return "CropCircleTransformation()";
|
||||
}
|
||||
@Override
|
||||
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
|
||||
messageDigest.update((ID).getBytes(CHARSET));
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,96 @@
|
||||
package jp.wasabeef.glide.transformations;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
|
||||
import androidx.annotation.ColorInt;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||
import com.bumptech.glide.load.resource.bitmap.TransformationUtils;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
|
||||
import jp.wasabeef.glide.transformations.internal.Utils;
|
||||
|
||||
/**
|
||||
* Copyright (C) 2020 Wasabeef
|
||||
* <p>
|
||||
* 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
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
public class CropCircleWithBorderTransformation extends BitmapTransformation {
|
||||
|
||||
|
||||
private static final int VERSION = 1;
|
||||
private static final String ID = "jp.wasabeef.glide.transformations.CropCircleWithBorderTransformation." + VERSION;
|
||||
|
||||
private final int borderSize;
|
||||
private final int borderColor;
|
||||
|
||||
|
||||
public CropCircleWithBorderTransformation() {
|
||||
this.borderSize = Utils.toDp(4);
|
||||
this.borderColor = Color.BLACK;
|
||||
}
|
||||
|
||||
public CropCircleWithBorderTransformation(int borderSize, @ColorInt int borderColor) {
|
||||
this.borderSize = borderSize;
|
||||
this.borderColor = borderColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
|
||||
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
|
||||
|
||||
Bitmap bitmap = TransformationUtils.circleCrop(pool, toTransform, outWidth, outHeight);
|
||||
|
||||
setCanvasBitmapDensity(toTransform, bitmap);
|
||||
|
||||
Paint paint = new Paint();
|
||||
paint.setColor(borderColor);
|
||||
paint.setStyle(Paint.Style.STROKE);
|
||||
paint.setStrokeWidth(borderSize);
|
||||
paint.setAntiAlias(true);
|
||||
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
canvas.drawCircle(
|
||||
outWidth / 2f,
|
||||
outHeight / 2f,
|
||||
Math.max(outWidth, outHeight) / 2f - borderSize / 2f,
|
||||
paint
|
||||
);
|
||||
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
|
||||
messageDigest.update((ID + borderSize + borderColor).getBytes(CHARSET));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof CropCircleWithBorderTransformation &&
|
||||
((CropCircleWithBorderTransformation) o).borderSize == borderSize &&
|
||||
((CropCircleWithBorderTransformation) o).borderColor == borderColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return ID.hashCode() + borderSize * 100 + borderColor + 10;
|
||||
}
|
||||
}
|
75
transformations/src/main/java/jp/wasabeef/glide/transformations/CropSquareTransformation.java
Normal file → Executable file
@@ -1,14 +1,14 @@
|
||||
package jp.wasabeef.glide.transformations;
|
||||
|
||||
/**
|
||||
* Copyright (C) 2015 Wasabeef
|
||||
*
|
||||
* Copyright (C) 2020 Wasabeef
|
||||
* <p>
|
||||
* 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
|
||||
*
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* <p>
|
||||
* 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.
|
||||
@@ -16,47 +16,48 @@ 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;
|
||||
|
||||
public class CropSquareTransformation implements Transformation<Bitmap> {
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
private BitmapPool mBitmapPool;
|
||||
private int mWidth;
|
||||
private int mHeight;
|
||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||
import com.bumptech.glide.load.resource.bitmap.TransformationUtils;
|
||||
|
||||
public CropSquareTransformation(BitmapPool pool) {
|
||||
this.mBitmapPool = pool;
|
||||
}
|
||||
import java.security.MessageDigest;
|
||||
|
||||
public CropSquareTransformation(BitmapPool pool, int width, int height) {
|
||||
mBitmapPool = pool;
|
||||
mWidth = width;
|
||||
mHeight = height;
|
||||
}
|
||||
public class CropSquareTransformation extends BitmapTransformation {
|
||||
|
||||
@Override
|
||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
||||
Bitmap source = resource.get();
|
||||
int size = Math.min(source.getWidth(), source.getHeight());
|
||||
private static final int VERSION = 1;
|
||||
private static final String ID =
|
||||
"jp.wasabeef.glide.transformations.CropSquareTransformation." + VERSION;
|
||||
|
||||
int width = (source.getWidth() - size) / 2;
|
||||
int height = (source.getHeight() - size) / 2;
|
||||
private int size;
|
||||
|
||||
Bitmap bitmap = Bitmap.createBitmap(source, width, height, size, size);
|
||||
if (bitmap != source) {
|
||||
source.recycle();
|
||||
}
|
||||
@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);
|
||||
}
|
||||
|
||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CropSquareTransformation(size=" + size + ")";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return "CropSquareTransformation(width=" + mWidth + ", height=" + mHeight + ")";
|
||||
}
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof CropSquareTransformation && ((CropSquareTransformation) o).size == size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return ID.hashCode() + size * 10;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
|
||||
messageDigest.update((ID + size).getBytes(CHARSET));
|
||||
}
|
||||
}
|
||||
|
146
transformations/src/main/java/jp/wasabeef/glide/transformations/CropTransformation.java
Normal file → Executable file
@@ -1,14 +1,14 @@
|
||||
package jp.wasabeef.glide.transformations;
|
||||
|
||||
/**
|
||||
* Copyright (C) 2015 Wasabeef
|
||||
*
|
||||
* Copyright (C) 2020 Wasabeef
|
||||
* <p>
|
||||
* 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
|
||||
*
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* <p>
|
||||
* 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.
|
||||
@@ -16,61 +16,107 @@ 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;
|
||||
|
||||
public class CropTransformation implements Transformation<Bitmap> {
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
private BitmapPool mBitmapPool;
|
||||
private int mWidth;
|
||||
private int mHeight;
|
||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||
|
||||
public CropTransformation(BitmapPool pool) {
|
||||
mBitmapPool = pool;
|
||||
import java.security.MessageDigest;
|
||||
|
||||
public class CropTransformation extends BitmapTransformation {
|
||||
|
||||
private static final int VERSION = 1;
|
||||
private static final String ID = "jp.wasabeef.glide.transformations.CropTransformation." + VERSION;
|
||||
|
||||
public enum CropType {
|
||||
TOP,
|
||||
CENTER,
|
||||
BOTTOM
|
||||
}
|
||||
|
||||
private int width;
|
||||
private int height;
|
||||
|
||||
private CropType cropType = CropType.CENTER;
|
||||
|
||||
public CropTransformation(int width, int height) {
|
||||
this(width, height, CropType.CENTER);
|
||||
}
|
||||
|
||||
public CropTransformation(int width, int height, CropType cropType) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.cropType = cropType;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
|
||||
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
|
||||
|
||||
width = width == 0 ? toTransform.getWidth() : width;
|
||||
height = height == 0 ? toTransform.getHeight() : height;
|
||||
|
||||
Bitmap.Config config =
|
||||
toTransform.getConfig() != null ? toTransform.getConfig() : Bitmap.Config.ARGB_8888;
|
||||
Bitmap bitmap = pool.get(width, height, config);
|
||||
|
||||
bitmap.setHasAlpha(true);
|
||||
|
||||
float scaleX = (float) width / toTransform.getWidth();
|
||||
float scaleY = (float) height / toTransform.getHeight();
|
||||
float scale = Math.max(scaleX, scaleY);
|
||||
|
||||
float scaledWidth = scale * toTransform.getWidth();
|
||||
float scaledHeight = scale * toTransform.getHeight();
|
||||
float left = (width - scaledWidth) / 2;
|
||||
float top = getTop(scaledHeight);
|
||||
RectF targetRect = new RectF(left, top, left + scaledWidth, top + scaledHeight);
|
||||
|
||||
setCanvasBitmapDensity(toTransform, bitmap);
|
||||
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
canvas.drawBitmap(toTransform, null, targetRect, null);
|
||||
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
private float getTop(float scaledHeight) {
|
||||
switch (cropType) {
|
||||
case TOP:
|
||||
return 0;
|
||||
case CENTER:
|
||||
return (height - scaledHeight) / 2;
|
||||
case BOTTOM:
|
||||
return height - scaledHeight;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public CropTransformation(BitmapPool pool, int width, int height) {
|
||||
mBitmapPool = pool;
|
||||
mWidth = width;
|
||||
mHeight = height;
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CropTransformation(width=" + width + ", height=" + height + ", cropType=" + cropType + ")";
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof CropTransformation &&
|
||||
((CropTransformation) o).width == width &&
|
||||
((CropTransformation) o).height == height &&
|
||||
((CropTransformation) o).cropType == cropType;
|
||||
}
|
||||
|
||||
float scaleX = (float) mWidth / source.getWidth();
|
||||
float scaleY = (float) mHeight / source.getHeight();
|
||||
float scale = Math.max(scaleX, scaleY);
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return ID.hashCode() + width * 100000 + height * 1000 + cropType.ordinal() * 10;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
Bitmap bitmap = Bitmap.createBitmap(mWidth, mHeight, source.getConfig());
|
||||
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 + ")";
|
||||
}
|
||||
@Override
|
||||
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
|
||||
messageDigest.update((ID + width + height + cropType).getBytes(CHARSET));
|
||||
}
|
||||
}
|
||||
|
83
transformations/src/main/java/jp/wasabeef/glide/transformations/GrayscaleTransformation.java
Normal file → Executable file
@@ -1,14 +1,14 @@
|
||||
package jp.wasabeef.glide.transformations;
|
||||
|
||||
/**
|
||||
* Copyright (C) 2015 Wasabeef
|
||||
*
|
||||
* Copyright (C) 2020 Wasabeef
|
||||
* <p>
|
||||
* 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
|
||||
*
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* <p>
|
||||
* 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.
|
||||
@@ -16,47 +16,64 @@ 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;
|
||||
|
||||
public class GrayscaleTransformation implements Transformation<Bitmap> {
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
private BitmapPool mBitmapPool;
|
||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||
|
||||
public GrayscaleTransformation(BitmapPool pool) {
|
||||
mBitmapPool = pool;
|
||||
}
|
||||
import java.security.MessageDigest;
|
||||
|
||||
@Override
|
||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
||||
Bitmap source = resource.get();
|
||||
public class GrayscaleTransformation extends BitmapTransformation {
|
||||
|
||||
int width = source.getWidth();
|
||||
int height = source.getHeight();
|
||||
private static final int VERSION = 1;
|
||||
private static final String ID =
|
||||
"jp.wasabeef.glide.transformations.GrayscaleTransformation." + VERSION;
|
||||
|
||||
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
||||
@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();
|
||||
|
||||
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);
|
||||
source.recycle();
|
||||
Bitmap.Config config =
|
||||
toTransform.getConfig() != null ? toTransform.getConfig() : Bitmap.Config.ARGB_8888;
|
||||
Bitmap bitmap = pool.get(width, height, config);
|
||||
|
||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||
}
|
||||
setCanvasBitmapDensity(toTransform, bitmap);
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return "GrayscaleTransformation()";
|
||||
}
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
ColorMatrix saturation = new ColorMatrix();
|
||||
saturation.setSaturation(0f);
|
||||
Paint paint = new Paint();
|
||||
paint.setColorFilter(new ColorMatrixColorFilter(saturation));
|
||||
canvas.drawBitmap(toTransform, 0, 0, paint);
|
||||
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "GrayscaleTransformation()";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof GrayscaleTransformation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return ID.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
|
||||
messageDigest.update((ID).getBytes(CHARSET));
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,96 @@
|
||||
package jp.wasabeef.glide.transformations;
|
||||
|
||||
/**
|
||||
* Copyright (C) 2020 Wasabeef
|
||||
* <p>
|
||||
* 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
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.PorterDuffXfermode;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
|
||||
public class MaskTransformation extends BitmapTransformation {
|
||||
|
||||
private static final int VERSION = 1;
|
||||
private static final String ID =
|
||||
"jp.wasabeef.glide.transformations.MaskTransformation." + VERSION;
|
||||
|
||||
private static final Paint paint = new Paint();
|
||||
private final int maskId;
|
||||
|
||||
static {
|
||||
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param maskId If you change the mask file, please also rename the mask file, or Glide will get
|
||||
* the cache with the old mask. Because key() return the same values if using the
|
||||
* same make file name. If you have a good idea please tell us, thanks.
|
||||
*/
|
||||
public MaskTransformation(int maskId) {
|
||||
this.maskId = maskId;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
|
||||
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
|
||||
int width = toTransform.getWidth();
|
||||
int height = toTransform.getHeight();
|
||||
|
||||
Bitmap bitmap = pool.get(width, height, Bitmap.Config.ARGB_8888);
|
||||
bitmap.setHasAlpha(true);
|
||||
|
||||
Drawable mask = context.getDrawable(maskId);
|
||||
|
||||
setCanvasBitmapDensity(toTransform, bitmap);
|
||||
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
mask.setBounds(0, 0, width, height);
|
||||
mask.draw(canvas);
|
||||
canvas.drawBitmap(toTransform, 0, 0, paint);
|
||||
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "MaskTransformation(maskId=" + maskId + ")";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof MaskTransformation &&
|
||||
((MaskTransformation) o).maskId == maskId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return ID.hashCode() + maskId * 10;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
|
||||
messageDigest.update((ID + maskId).getBytes(CHARSET));
|
||||
}
|
||||
}
|
267
transformations/src/main/java/jp/wasabeef/glide/transformations/RoundedCornersTransformation.java
Normal file → Executable file
@@ -1,14 +1,14 @@
|
||||
package jp.wasabeef.glide.transformations;
|
||||
|
||||
/**
|
||||
* Copyright (C) 2015 Wasabeef
|
||||
*
|
||||
* Copyright (C) 2020 Wasabeef
|
||||
* <p>
|
||||
* 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
|
||||
*
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* <p>
|
||||
* 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.
|
||||
@@ -16,11 +16,7 @@ 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;
|
||||
@@ -28,41 +24,240 @@ import android.graphics.Paint;
|
||||
import android.graphics.RectF;
|
||||
import android.graphics.Shader;
|
||||
|
||||
public class RoundedCornersTransformation implements Transformation<Bitmap> {
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
private BitmapPool mBitmapPool;
|
||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||
|
||||
private int radius;
|
||||
private int margin;
|
||||
import java.security.MessageDigest;
|
||||
|
||||
public RoundedCornersTransformation(BitmapPool pool, int radius, int margin) {
|
||||
this.radius = radius;
|
||||
this.margin = margin;
|
||||
mBitmapPool = pool;
|
||||
public class RoundedCornersTransformation extends BitmapTransformation {
|
||||
|
||||
private static final int VERSION = 1;
|
||||
private static final String ID = "jp.wasabeef.glide.transformations.RoundedCornersTransformation." + VERSION;
|
||||
|
||||
public enum CornerType {
|
||||
ALL,
|
||||
TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT,
|
||||
TOP, BOTTOM, LEFT, RIGHT,
|
||||
OTHER_TOP_LEFT, OTHER_TOP_RIGHT, OTHER_BOTTOM_LEFT, OTHER_BOTTOM_RIGHT,
|
||||
DIAGONAL_FROM_TOP_LEFT, DIAGONAL_FROM_TOP_RIGHT
|
||||
}
|
||||
|
||||
private final int radius;
|
||||
private final int diameter;
|
||||
private final int margin;
|
||||
private final CornerType cornerType;
|
||||
|
||||
public RoundedCornersTransformation(int radius, int margin) {
|
||||
this(radius, margin, CornerType.ALL);
|
||||
}
|
||||
|
||||
public RoundedCornersTransformation(int radius, int margin, CornerType cornerType) {
|
||||
this.radius = radius;
|
||||
this.diameter = this.radius * 2;
|
||||
this.margin = margin;
|
||||
this.cornerType = cornerType;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
|
||||
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
|
||||
int width = toTransform.getWidth();
|
||||
int height = toTransform.getHeight();
|
||||
|
||||
Bitmap bitmap = pool.get(width, height, Bitmap.Config.ARGB_8888);
|
||||
bitmap.setHasAlpha(true);
|
||||
|
||||
setCanvasBitmapDensity(toTransform, bitmap);
|
||||
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
Paint paint = new Paint();
|
||||
paint.setAntiAlias(true);
|
||||
paint.setShader(new BitmapShader(toTransform, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
|
||||
drawRoundRect(canvas, paint, width, height);
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
private void drawRoundRect(Canvas canvas, Paint paint, float width, float height) {
|
||||
float right = width - margin;
|
||||
float bottom = height - margin;
|
||||
|
||||
switch (cornerType) {
|
||||
case ALL:
|
||||
canvas.drawRoundRect(new RectF(margin, margin, right, bottom), radius, radius, paint);
|
||||
break;
|
||||
case TOP_LEFT:
|
||||
drawTopLeftRoundRect(canvas, paint, right, bottom);
|
||||
break;
|
||||
case TOP_RIGHT:
|
||||
drawTopRightRoundRect(canvas, paint, right, bottom);
|
||||
break;
|
||||
case BOTTOM_LEFT:
|
||||
drawBottomLeftRoundRect(canvas, paint, right, bottom);
|
||||
break;
|
||||
case BOTTOM_RIGHT:
|
||||
drawBottomRightRoundRect(canvas, paint, right, bottom);
|
||||
break;
|
||||
case TOP:
|
||||
drawTopRoundRect(canvas, paint, right, bottom);
|
||||
break;
|
||||
case BOTTOM:
|
||||
drawBottomRoundRect(canvas, paint, right, bottom);
|
||||
break;
|
||||
case LEFT:
|
||||
drawLeftRoundRect(canvas, paint, right, bottom);
|
||||
break;
|
||||
case RIGHT:
|
||||
drawRightRoundRect(canvas, paint, right, bottom);
|
||||
break;
|
||||
case OTHER_TOP_LEFT:
|
||||
drawOtherTopLeftRoundRect(canvas, paint, right, bottom);
|
||||
break;
|
||||
case OTHER_TOP_RIGHT:
|
||||
drawOtherTopRightRoundRect(canvas, paint, right, bottom);
|
||||
break;
|
||||
case OTHER_BOTTOM_LEFT:
|
||||
drawOtherBottomLeftRoundRect(canvas, paint, right, bottom);
|
||||
break;
|
||||
case OTHER_BOTTOM_RIGHT:
|
||||
drawOtherBottomRightRoundRect(canvas, paint, right, bottom);
|
||||
break;
|
||||
case DIAGONAL_FROM_TOP_LEFT:
|
||||
drawDiagonalFromTopLeftRoundRect(canvas, paint, right, bottom);
|
||||
break;
|
||||
case DIAGONAL_FROM_TOP_RIGHT:
|
||||
drawDiagonalFromTopRightRoundRect(canvas, paint, right, bottom);
|
||||
break;
|
||||
default:
|
||||
canvas.drawRoundRect(new RectF(margin, margin, right, bottom), radius, radius, paint);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@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 = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
||||
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);
|
||||
source.recycle();
|
||||
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);
|
||||
}
|
||||
|
||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return "RoundedTransformation(radius=" + radius + ", margin=" + margin + ")";
|
||||
}
|
||||
private void drawBottomRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
|
||||
canvas.drawRoundRect(new RectF(margin, bottom - diameter, right, bottom), radius, radius,
|
||||
paint);
|
||||
canvas.drawRect(new RectF(margin, margin, right, bottom - radius), paint);
|
||||
}
|
||||
|
||||
private void drawLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
|
||||
canvas.drawRoundRect(new RectF(margin, margin, margin + diameter, bottom), radius, radius,
|
||||
paint);
|
||||
canvas.drawRect(new RectF(margin + radius, margin, right, bottom), paint);
|
||||
}
|
||||
|
||||
private void drawRightRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
|
||||
canvas.drawRoundRect(new RectF(right - diameter, margin, right, bottom), radius, radius, paint);
|
||||
canvas.drawRect(new RectF(margin, margin, right - radius, bottom), paint);
|
||||
}
|
||||
|
||||
private void drawOtherTopLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
|
||||
canvas.drawRoundRect(new RectF(margin, bottom - diameter, right, bottom), radius, radius,
|
||||
paint);
|
||||
canvas.drawRoundRect(new RectF(right - diameter, margin, right, bottom), radius, radius, paint);
|
||||
canvas.drawRect(new RectF(margin, margin, right - radius, bottom - radius), paint);
|
||||
}
|
||||
|
||||
private void drawOtherTopRightRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
|
||||
canvas.drawRoundRect(new RectF(margin, margin, margin + diameter, bottom), radius, radius,
|
||||
paint);
|
||||
canvas.drawRoundRect(new RectF(margin, bottom - diameter, right, bottom), radius, radius,
|
||||
paint);
|
||||
canvas.drawRect(new RectF(margin + radius, margin, right, bottom - radius), paint);
|
||||
}
|
||||
|
||||
private void drawOtherBottomLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
|
||||
canvas.drawRoundRect(new RectF(margin, margin, right, margin + diameter), radius, radius,
|
||||
paint);
|
||||
canvas.drawRoundRect(new RectF(right - diameter, margin, right, bottom), radius, radius, paint);
|
||||
canvas.drawRect(new RectF(margin, margin + radius, right - radius, bottom), paint);
|
||||
}
|
||||
|
||||
private void drawOtherBottomRightRoundRect(Canvas canvas, Paint paint, float right,
|
||||
float bottom) {
|
||||
canvas.drawRoundRect(new RectF(margin, margin, right, margin + diameter), radius, radius,
|
||||
paint);
|
||||
canvas.drawRoundRect(new RectF(margin, margin, margin + diameter, bottom), radius, radius,
|
||||
paint);
|
||||
canvas.drawRect(new RectF(margin + radius, margin + radius, right, bottom), paint);
|
||||
}
|
||||
|
||||
private void drawDiagonalFromTopLeftRoundRect(Canvas canvas, Paint paint, float right,
|
||||
float bottom) {
|
||||
canvas.drawRoundRect(new RectF(margin, margin, margin + diameter, margin + diameter), radius,
|
||||
radius, paint);
|
||||
canvas.drawRoundRect(new RectF(right - diameter, bottom - diameter, right, bottom), radius,
|
||||
radius, paint);
|
||||
canvas.drawRect(new RectF(margin, margin + radius, right - radius, bottom), paint);
|
||||
canvas.drawRect(new RectF(margin + radius, margin, right, bottom - radius), paint);
|
||||
}
|
||||
|
||||
private void drawDiagonalFromTopRightRoundRect(Canvas canvas, Paint paint, float right,
|
||||
float bottom) {
|
||||
canvas.drawRoundRect(new RectF(right - diameter, margin, right, margin + diameter), radius,
|
||||
radius, paint);
|
||||
canvas.drawRoundRect(new RectF(margin, bottom - diameter, margin + diameter, bottom), radius,
|
||||
radius, paint);
|
||||
canvas.drawRect(new RectF(margin, margin, right - radius, bottom - radius), paint);
|
||||
canvas.drawRect(new RectF(margin + radius, margin + radius, right, bottom), paint);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "RoundedTransformation(radius=" + radius + ", margin=" + margin + ", diameter="
|
||||
+ diameter + ", cornerType=" + cornerType.name() + ")";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof RoundedCornersTransformation &&
|
||||
((RoundedCornersTransformation) o).radius == radius &&
|
||||
((RoundedCornersTransformation) o).diameter == diameter &&
|
||||
((RoundedCornersTransformation) o).margin == margin &&
|
||||
((RoundedCornersTransformation) o).cornerType == cornerType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return ID.hashCode() + radius * 10000 + diameter * 1000 + margin * 100 + cornerType.ordinal() * 10;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
|
||||
messageDigest.update((ID + radius + diameter + margin + cornerType).getBytes(CHARSET));
|
||||
}
|
||||
}
|
||||
|
80
transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/BrightnessFilterTransformation.java
Normal file → Executable file
@@ -1,14 +1,14 @@
|
||||
package jp.wasabeef.glide.transformations.gpu;
|
||||
|
||||
/**
|
||||
* Copyright (C) 2015 Wasabeef
|
||||
*
|
||||
* Copyright (C) 2020 Wasabeef
|
||||
* <p>
|
||||
* 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
|
||||
*
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* <p>
|
||||
* 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.
|
||||
@@ -16,56 +16,52 @@ 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 androidx.annotation.NonNull;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import java.security.MessageDigest;
|
||||
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImage;
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImageBrightnessFilter;
|
||||
import jp.co.cyberagent.android.gpuimage.filter.GPUImageBrightnessFilter;
|
||||
|
||||
/**
|
||||
* brightness value ranges from -1.0 to 1.0, with 0.0 as the normal level
|
||||
*/
|
||||
public class BrightnessFilterTransformation 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 GPUImageBrightnessFilter mFilter = new GPUImageBrightnessFilter();
|
||||
private float mBrightness;
|
||||
private final 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 &&
|
||||
((BrightnessFilterTransformation) o).brightness == brightness;
|
||||
}
|
||||
|
||||
source.recycle();
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return ID.hashCode() + (int) ((brightness + 1.0f) * 10);
|
||||
}
|
||||
|
||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return "BrightnessFilterTransformation(brightness=" + mBrightness + ")";
|
||||
}
|
||||
@Override
|
||||
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
|
||||
messageDigest.update((ID + brightness).getBytes(CHARSET));
|
||||
}
|
||||
}
|
||||
|
79
transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/ContrastFilterTransformation.java
Normal file → Executable file
@@ -1,14 +1,14 @@
|
||||
package jp.wasabeef.glide.transformations.gpu;
|
||||
|
||||
/**
|
||||
* Copyright (C) 2015 Wasabeef
|
||||
*
|
||||
* Copyright (C) 2020 Wasabeef
|
||||
* <p>
|
||||
* 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
|
||||
*
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* <p>
|
||||
* 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.
|
||||
@@ -16,56 +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 androidx.annotation.NonNull;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import java.security.MessageDigest;
|
||||
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImage;
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImageContrastFilter;
|
||||
import jp.co.cyberagent.android.gpuimage.filter.GPUImageContrastFilter;
|
||||
|
||||
/**
|
||||
* contrast value ranges from 0.0 to 4.0, with 1.0 as the normal level
|
||||
*/
|
||||
public class ContrastFilterTransformation 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 GPUImageContrastFilter mFilter = new GPUImageContrastFilter();
|
||||
private float mContrast;
|
||||
private final 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() + (int) (contrast * 10);
|
||||
}
|
||||
|
||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return "ContrastFilterTransformation(contrast=" + mContrast + ")";
|
||||
}
|
||||
@Override
|
||||
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
|
||||
messageDigest.update((ID + contrast).getBytes(CHARSET));
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,79 @@
|
||||
package jp.wasabeef.glide.transformations.gpu;
|
||||
|
||||
/**
|
||||
* Copyright (C) 2020 Wasabeef
|
||||
* <p>
|
||||
* 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
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImage;
|
||||
import jp.co.cyberagent.android.gpuimage.filter.GPUImageFilter;
|
||||
import jp.wasabeef.glide.transformations.BitmapTransformation;
|
||||
|
||||
public class GPUFilterTransformation extends BitmapTransformation {
|
||||
|
||||
private static final int VERSION = 1;
|
||||
private static final String ID =
|
||||
"jp.wasabeef.glide.transformations.gpu.GPUFilterTransformation." + VERSION;
|
||||
private static final byte[] ID_BYTES = ID.getBytes(CHARSET);
|
||||
|
||||
private final GPUImageFilter gpuImageFilter;
|
||||
|
||||
public GPUFilterTransformation(GPUImageFilter filter) {
|
||||
this.gpuImageFilter = filter;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
|
||||
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
|
||||
GPUImage gpuImage = new GPUImage(context);
|
||||
gpuImage.setImage(toTransform);
|
||||
gpuImage.setFilter(gpuImageFilter);
|
||||
|
||||
return gpuImage.getBitmapWithFilterApplied();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getClass().getSimpleName();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T getFilter() {
|
||||
return (T) gpuImageFilter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof GPUFilterTransformation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return ID.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
|
||||
messageDigest.update(ID_BYTES);
|
||||
}
|
||||
}
|
67
transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/InvertFilterTransformation.java
Normal file → Executable file
@@ -1,14 +1,14 @@
|
||||
package jp.wasabeef.glide.transformations.gpu;
|
||||
|
||||
/**
|
||||
* Copyright (C) 2015 Wasabeef
|
||||
*
|
||||
* Copyright (C) 2020 Wasabeef
|
||||
* <p>
|
||||
* 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
|
||||
*
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* <p>
|
||||
* 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.
|
||||
@@ -16,43 +16,42 @@ 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 androidx.annotation.NonNull;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import java.security.MessageDigest;
|
||||
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImage;
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImageColorInvertFilter;
|
||||
import jp.co.cyberagent.android.gpuimage.filter.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;
|
||||
|
||||
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(@NonNull MessageDigest messageDigest) {
|
||||
messageDigest.update((ID).getBytes(CHARSET));
|
||||
}
|
||||
}
|
||||
|
83
transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/KuwaharaFilterTransformation.java
Normal file → Executable file
@@ -1,14 +1,14 @@
|
||||
package jp.wasabeef.glide.transformations.gpu;
|
||||
|
||||
/**
|
||||
* Copyright (C) 2015 Wasabeef
|
||||
*
|
||||
* Copyright (C) 2020 Wasabeef
|
||||
* <p>
|
||||
* 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
|
||||
*
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* <p>
|
||||
* 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.
|
||||
@@ -16,57 +16,54 @@ 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 androidx.annotation.NonNull;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import java.security.MessageDigest;
|
||||
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImage;
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImageKuwaharaFilter;
|
||||
import jp.co.cyberagent.android.gpuimage.filter.GPUImageKuwaharaFilter;
|
||||
|
||||
/**
|
||||
* The radius to sample from when creating the brush-stroke effect, with a default of 3.
|
||||
* Kuwahara all the colors in the image.
|
||||
* <p>
|
||||
* 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 GPUImageKuwaharaFilter mFilter = new GPUImageKuwaharaFilter();
|
||||
private int mRadius;
|
||||
private final 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() + radius * 10;
|
||||
}
|
||||
|
||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return "KuwaharaFilterTransformation(radius=" + mRadius + ")";
|
||||
}
|
||||
@Override
|
||||
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
|
||||
messageDigest.update((ID + radius).getBytes(CHARSET));
|
||||
}
|
||||
}
|
||||
|
84
transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/PixelationFilterTransformation.java
Normal file → Executable file
@@ -1,14 +1,14 @@
|
||||
package jp.wasabeef.glide.transformations.gpu;
|
||||
|
||||
/**
|
||||
* Copyright (C) 2015 Wasabeef
|
||||
*
|
||||
* Copyright (C) 2020 Wasabeef
|
||||
* <p>
|
||||
* 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
|
||||
*
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* <p>
|
||||
* 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.
|
||||
@@ -16,53 +16,53 @@ 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 androidx.annotation.NonNull;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import java.security.MessageDigest;
|
||||
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImage;
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImagePixelationFilter;
|
||||
import jp.co.cyberagent.android.gpuimage.filter.GPUImagePixelationFilter;
|
||||
|
||||
public class PixelationFilterTransformation implements Transformation<Bitmap> {
|
||||
/**
|
||||
* Applies a Pixelation effect to the image.
|
||||
* <p>
|
||||
* 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 GPUImagePixelationFilter mFilter = new GPUImagePixelationFilter();
|
||||
private float mPixel;
|
||||
private final 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() + (int) (pixel * 10);
|
||||
}
|
||||
|
||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return "PixelationFilterTransformation(pixel=" + mPixel + ")";
|
||||
}
|
||||
@Override
|
||||
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
|
||||
messageDigest.update((ID + pixel).getBytes(CHARSET));
|
||||
}
|
||||
}
|
||||
|
84
transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/SepiaFilterTransformation.java
Normal file → Executable file
@@ -1,14 +1,14 @@
|
||||
package jp.wasabeef.glide.transformations.gpu;
|
||||
|
||||
/**
|
||||
* Copyright (C) 2015 Wasabeef
|
||||
*
|
||||
* Copyright (C) 2020 Wasabeef
|
||||
* <p>
|
||||
* 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
|
||||
*
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* <p>
|
||||
* 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.
|
||||
@@ -16,53 +16,53 @@ 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 androidx.annotation.NonNull;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import java.security.MessageDigest;
|
||||
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImage;
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImageSepiaFilter;
|
||||
import jp.co.cyberagent.android.gpuimage.filter.GPUImageSepiaToneFilter;
|
||||
|
||||
public class SepiaFilterTransformation implements Transformation<Bitmap> {
|
||||
/**
|
||||
* Applies a simple sepia effect.
|
||||
* <p>
|
||||
* 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 GPUImageSepiaFilter mFilter = new GPUImageSepiaFilter();
|
||||
private float mIntensity;
|
||||
private final 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 GPUImageSepiaToneFilter());
|
||||
this.intensity = intensity;
|
||||
GPUImageSepiaToneFilter 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() + (int) (intensity * 10);
|
||||
}
|
||||
|
||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return "SepiaFilterTransformation(intensity=" + mIntensity + ")";
|
||||
}
|
||||
@Override
|
||||
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
|
||||
messageDigest.update((ID + intensity).getBytes(CHARSET));
|
||||
}
|
||||
}
|
||||
|
64
transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/SketchFilterTransformation.java
Normal file → Executable file
@@ -1,14 +1,14 @@
|
||||
package jp.wasabeef.glide.transformations.gpu;
|
||||
|
||||
/**
|
||||
* Copyright (C) 2015 Wasabeef
|
||||
*
|
||||
* Copyright (C) 2020 Wasabeef
|
||||
* <p>
|
||||
* 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
|
||||
*
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* <p>
|
||||
* 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.
|
||||
@@ -16,43 +16,39 @@ 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 androidx.annotation.NonNull;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import java.security.MessageDigest;
|
||||
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImage;
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImageSketchFilter;
|
||||
import jp.co.cyberagent.android.gpuimage.filter.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;
|
||||
|
||||
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(@NonNull MessageDigest messageDigest) {
|
||||
messageDigest.update((ID).getBytes(CHARSET));
|
||||
}
|
||||
}
|
||||
|
112
transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/SwirlFilterTransformation.java
Normal file → Executable file
@@ -1,14 +1,14 @@
|
||||
package jp.wasabeef.glide.transformations.gpu;
|
||||
|
||||
/**
|
||||
* Copyright (C) 2015 Wasabeef
|
||||
*
|
||||
* Copyright (C) 2020 Wasabeef
|
||||
* <p>
|
||||
* 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
|
||||
*
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* <p>
|
||||
* 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.
|
||||
@@ -16,68 +16,68 @@ 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 jp.co.cyberagent.android.gpuimage.GPUImageSwirlFilter;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
public class SwirlFilterTransformation implements Transformation<Bitmap> {
|
||||
import java.security.MessageDigest;
|
||||
|
||||
private Context mContext;
|
||||
private BitmapPool mBitmapPool;
|
||||
import jp.co.cyberagent.android.gpuimage.filter.GPUImageSwirlFilter;
|
||||
|
||||
private GPUImageSwirlFilter mFilter = new GPUImageSwirlFilter();
|
||||
private float mRadius;
|
||||
private float mAngle;
|
||||
private PointF mCenter;
|
||||
/**
|
||||
* Creates a swirl distortion on the image.
|
||||
*/
|
||||
public class SwirlFilterTransformation extends GPUFilterTransformation {
|
||||
|
||||
public SwirlFilterTransformation(Context context, BitmapPool pool) {
|
||||
mContext = context;
|
||||
mBitmapPool = pool;
|
||||
mCenter = new PointF();
|
||||
}
|
||||
private static final int VERSION = 1;
|
||||
private static final String ID =
|
||||
"jp.wasabeef.glide.transformations.gpu.SwirlFilterTransformation." + VERSION;
|
||||
|
||||
/**
|
||||
* @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);
|
||||
}
|
||||
private final float radius;
|
||||
private final float angle;
|
||||
private final PointF center;
|
||||
|
||||
@Override
|
||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
||||
Bitmap source = resource.get();
|
||||
public SwirlFilterTransformation() {
|
||||
this(.5f, 1.0f, new PointF(0.5f, 0.5f));
|
||||
}
|
||||
|
||||
GPUImage gpuImage = new GPUImage(mContext);
|
||||
gpuImage.setImage(source);
|
||||
gpuImage.setFilter(mFilter);
|
||||
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
||||
/**
|
||||
* @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);
|
||||
}
|
||||
|
||||
source.recycle();
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SwirlFilterTransformation(radius=" + radius + ",angle=" + angle + ",center="
|
||||
+ center.toString() + ")";
|
||||
}
|
||||
|
||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||
}
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof SwirlFilterTransformation &&
|
||||
((SwirlFilterTransformation) o).radius == radius &&
|
||||
((SwirlFilterTransformation) o).angle == radius &&
|
||||
((SwirlFilterTransformation) o).center.equals(center.x, center.y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return "SwirlFilterTransformation(radius=" + mRadius +
|
||||
",angle=" + mAngle + ",center=" + mCenter.toString() + ")";
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return ID.hashCode() + (int) (radius * 1000) + (int) (angle * 10) + center.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
|
||||
messageDigest.update((ID + radius + angle + center.hashCode()).getBytes(CHARSET));
|
||||
}
|
||||
}
|
||||
|
95
transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/ToonFilterTransformation.java
Normal file → Executable file
@@ -1,14 +1,14 @@
|
||||
package jp.wasabeef.glide.transformations.gpu;
|
||||
|
||||
/**
|
||||
* Copyright (C) 2015 Wasabeef
|
||||
*
|
||||
* Copyright (C) 2020 Wasabeef
|
||||
* <p>
|
||||
* 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
|
||||
*
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* <p>
|
||||
* 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.
|
||||
@@ -16,58 +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 androidx.annotation.NonNull;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import java.security.MessageDigest;
|
||||
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImage;
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImageToonFilter;
|
||||
import jp.co.cyberagent.android.gpuimage.filter.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 GPUImageToonFilter mFilter = new GPUImageToonFilter();
|
||||
private float mThreshold;
|
||||
private float mQuantizationLevels;
|
||||
private final float threshold;
|
||||
private final 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 &&
|
||||
((ToonFilterTransformation) o).threshold == threshold &&
|
||||
((ToonFilterTransformation) o).quantizationLevels == quantizationLevels;
|
||||
}
|
||||
|
||||
source.recycle();
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return ID.hashCode() + (int) (threshold * 1000) + (int) (quantizationLevels * 10);
|
||||
}
|
||||
|
||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return "ToonFilterTransformation(threshold=" + mThreshold +
|
||||
",quantizationLevels=" + mQuantizationLevels + ")";
|
||||
}
|
||||
@Override
|
||||
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
|
||||
messageDigest.update((ID + threshold + quantizationLevels).getBytes(CHARSET));
|
||||
}
|
||||
}
|
||||
|
114
transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/VignetteFilterTransformation.java
Normal file → Executable file
@@ -1,14 +1,14 @@
|
||||
package jp.wasabeef.glide.transformations.gpu;
|
||||
|
||||
/**
|
||||
* Copyright (C) 2015 Wasabeef
|
||||
*
|
||||
* Copyright (C) 2020 Wasabeef
|
||||
* <p>
|
||||
* 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
|
||||
*
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* <p>
|
||||
* 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.
|
||||
@@ -16,75 +16,71 @@ 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 androidx.annotation.NonNull;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import java.util.Arrays;
|
||||
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImage;
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImageVignetteFilter;
|
||||
import jp.co.cyberagent.android.gpuimage.filter.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 GPUImageVignetteFilter mFilter = new GPUImageVignetteFilter();
|
||||
private PointF mCenter;
|
||||
private float[] mVignetteColor;
|
||||
private float mVignetteStart;
|
||||
private float mVignetteEnd;
|
||||
private final PointF center;
|
||||
private final float[] vignetteColor;
|
||||
private final float vignetteStart;
|
||||
private final float vignetteEnd;
|
||||
|
||||
public VignetteFilterTransformation() {
|
||||
this(new PointF(0.5f, 0.5f), new float[]{0.0f, 0.0f, 0.0f}, 0.0f, 0.75f);
|
||||
}
|
||||
|
||||
public VignetteFilterTransformation(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 &&
|
||||
((VignetteFilterTransformation) o).center.equals(center.x, center.y) &&
|
||||
Arrays.equals(((VignetteFilterTransformation) o).vignetteColor, vignetteColor) &&
|
||||
((VignetteFilterTransformation) o).vignetteStart == vignetteStart &&
|
||||
((VignetteFilterTransformation) o).vignetteEnd == vignetteEnd;
|
||||
}
|
||||
|
||||
GPUImage gpuImage = new GPUImage(mContext);
|
||||
gpuImage.setImage(source);
|
||||
gpuImage.setFilter(mFilter);
|
||||
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return ID.hashCode() + center.hashCode() + Arrays.hashCode(vignetteColor) +
|
||||
(int) (vignetteStart * 100) + (int) (vignetteEnd * 10);
|
||||
}
|
||||
|
||||
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(@NonNull MessageDigest messageDigest) {
|
||||
messageDigest.update((ID + center + Arrays.hashCode(vignetteColor) + vignetteStart + vignetteEnd).getBytes(CHARSET));
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,257 @@
|
||||
package jp.wasabeef.glide.transformations.internal;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
|
||||
/**
|
||||
* Copyright (C) 2020 Wasabeef
|
||||
* <p>
|
||||
* 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
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* 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);
|
||||
}
|
||||
}
|
@@ -0,0 +1,69 @@
|
||||
package jp.wasabeef.glide.transformations.internal;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Build;
|
||||
import android.renderscript.Allocation;
|
||||
import android.renderscript.Element;
|
||||
import android.renderscript.RSRuntimeException;
|
||||
import android.renderscript.RenderScript;
|
||||
import android.renderscript.ScriptIntrinsicBlur;
|
||||
|
||||
/**
|
||||
* Copyright (C) 2020 Wasabeef
|
||||
* <p>
|
||||
* 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
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
public class RSBlur {
|
||||
|
||||
public static Bitmap blur(Context context, Bitmap bitmap, int radius) throws RSRuntimeException {
|
||||
RenderScript rs = null;
|
||||
Allocation input = null;
|
||||
Allocation output = null;
|
||||
ScriptIntrinsicBlur blur = null;
|
||||
try {
|
||||
rs = RenderScript.create(context);
|
||||
rs.setMessageHandler(new RenderScript.RSMessageHandler());
|
||||
input = Allocation.createFromBitmap(rs, bitmap, Allocation.MipmapControl.MIPMAP_NONE,
|
||||
Allocation.USAGE_SCRIPT);
|
||||
output = Allocation.createTyped(rs, input.getType());
|
||||
blur = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
|
||||
|
||||
blur.setInput(input);
|
||||
blur.setRadius(radius);
|
||||
blur.forEach(output);
|
||||
output.copyTo(bitmap);
|
||||
} finally {
|
||||
if (rs != null) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
RenderScript.releaseAllContexts();
|
||||
} else {
|
||||
rs.destroy();
|
||||
}
|
||||
}
|
||||
if (input != null) {
|
||||
input.destroy();
|
||||
}
|
||||
if (output != null) {
|
||||
output.destroy();
|
||||
}
|
||||
if (blur != null) {
|
||||
blur.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
return bitmap;
|
||||
}
|
||||
}
|
@@ -0,0 +1,33 @@
|
||||
package jp.wasabeef.glide.transformations.internal;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
|
||||
/**
|
||||
* Copyright (C) 2020 Wasabeef
|
||||
* <p>
|
||||
* 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
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
public final class Utils {
|
||||
|
||||
private Utils() {
|
||||
// Utility class.
|
||||
}
|
||||
|
||||
public static int toDp(int px) {
|
||||
return px * (int) Resources.getSystem().getDisplayMetrics().density;
|
||||
}
|
||||
}
|