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

59 Commits
1.4.0 ... 4.3.0

Author SHA1 Message Date
Daichi Furiya
09e62054e9 Release 4.3.0 (#184)
* refactor: clean code

* update: gpuimage

* update: min sdk to 21

* refactor: remove support rs

* update: gradle plugin

* style: fix xml format

* update: update gradle properties

* release 4.2.1

* update: samples

* update: sample

* update:changelog

* remove comments

* change release version
2020-09-27 07:37:31 +09:00
Daichi Furiya
4b4f6b1ad4 Update build.gradle 2020-09-24 18:49:48 +09:00
Daichi Furiya
074b6eef45 Release 4.2.0 (#183)
* format

* update copyright

* remove -android.namespacedRClass

* update compile&target sdk version to 30

* update dependencies

* update gitignore

* update samples dependencies

* update signinconfig

* bump up to 4.2.0

* bump up to 4.2.0
2020-09-15 03:51:31 +09:00
bigeye-wg
fa04c1b3c9 fixed drawDiagonalFromTopLeftRoundRect (#178) 2020-09-15 02:45:35 +09:00
Daichi Furiya
056adc6451 Create FUNDING.yml 2020-07-28 23:24:40 +09:00
Jason Cooke
1c925c932e docs: fix typo (#166) 2020-01-30 15:52:25 +09:00
Daichi Furiya
b08325ec70 Update README.md 2019-08-15 17:07:31 +09:00
wasabeef
e9acc52d9e add RoundedCourners to sample 2019-08-15 16:24:26 +09:00
wasabeef
ce14f7bdf1 update androidx libraries 2019-08-15 15:10:55 +09:00
Daichi Furiya
0b9311813a 4.1.0 (#163)
* update gradle wrapper

* update Copyright

* update kotlin version

* update glide

* update Copyright

* refactor to be simply

* add CircleCropWithBorder to sample

* code cleanup

* add px to dp convert

* update gradle

* update idea settings

* bump up to 4.1.0

* update readme
2019-08-15 13:47:18 +09:00
VeCharm
e16eda6af1 setCanvasBitmapDensity (#147) 2019-08-15 12:05:57 +09:00
Terence
783d69c579 Add crop circle with border transformation (#136) 2019-08-15 12:04:05 +09:00
Devansh Maurya
ec0e655f0a Update Readme.md (#162)
Added RequestOptions as a prefix to bitmapTransform() function call as it is difficult for many newcomers to understand from where to get bitmapTransform() function
2019-08-15 12:01:32 +09:00
wasabeef
9d4d7990d3 bump up to 4.0.1 2018-11-20 10:54:25 +09:00
wasabeef
d67f715c65 add consumerProguardFiles 2018-11-20 10:52:45 +09:00
wasabeef
f09f073442 update gradle plugin 2018-11-20 10:52:26 +09:00
Daichi Furiya
2e2846d354 refactor support rs (#142) 2018-11-16 18:01:01 +09:00
Daichi Furiya
3aa8e53c6a [WIP] Migrate to AndroidX (#141)
Migrate to AndroidX
2018-11-16 16:19:42 +09:00
Daichi Furiya
4818373fc5 v3.3.0 (#127)
* fixed #119

* update gradle files

* rename

* add sample of SupportRSBlur

* update libs

* bump up 3.3.0
2018-04-23 05:08:05 +09:00
Mike Fougere
8c72ad64b9 Add SupportBlurTransformation which uses RenderScript support library. (#125)
* 	Add SupportBlurTransformation which uses RenderScript support library.

* 	Whoops -- forgot to change the imports.

* 	Fix type.
2018-04-23 02:09:21 +09:00
Daichi Furiya
81e72fc553 Deprecated RSBlur (#124) 2018-04-10 03:05:28 +09:00
Daichi Furiya
0361d97018 Update build.gradle 2018-04-10 01:01:17 +09:00
Daichi Furiya
9b00767304 3.1.1 (#116)
* update gradle wrapeer

* fix proguard settings

* update glide

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

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

This resolves a strictmode 'resource acquired but never released' violation.
2016-06-12 23:55:52 +10:00
Daichi Furiya
c3f09cdd0d Merge pull request #38 from wasabeef/v2.0.1
V2.0.1
2016-04-21 15:29:01 +09:00
wasabeef
ddd76d4f06 fix layout 2016-04-21 15:27:26 +09:00
wasabeef
f9bca8887d fix bugs issue #35 2016-04-21 15:23:22 +09:00
wasabeef
592815a6a0 update gradle 2016-04-21 15:22:58 +09:00
wasabeef
f6540b111f bump up 2.0.1 2016-04-21 15:22:46 +09:00
wasabeef
9bea464afc format 2016-04-21 15:22:21 +09:00
wasabeef
219b32bbcc format 2016-04-21 15:18:48 +09:00
Daichi Furiya
4d7190847c Merge pull request #36 from elevenfive/patch-1
Use correct field prefix
2016-04-19 13:05:36 +09:00
Matthew Zavislak
0d7a93c264 Use correct field prefix 2016-04-15 20:19:29 -07:00
Daichi Furiya
e69f775ddd Update build.gradle 2016-03-02 23:12:39 +09:00
Daichi Furiya
4b9cf87770 Update gradle-wrapper.properties 2016-03-02 23:11:59 +09:00
Daichi Furiya
cafad91b0b Update gradle-wrapper.properties 2016-03-02 23:11:43 +09:00
Daichi Furiya
933c3f7989 Merge pull request #31 from wasabeef/goodbye-v8rs
Goodbye v8.RenderScript
2016-03-02 23:11:05 +09:00
wasabeef
68bafb0f53 bump up 2.0.0 2016-03-02 23:09:31 +09:00
wasabeef
817b138980 Say v8.RenderScript goodbye 2016-03-02 22:53:34 +09:00
65 changed files with 2108 additions and 1357 deletions

7
.editorconfig Normal file
View 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
View 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
View 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
View File

@@ -0,0 +1,6 @@
## What does this change?
## What is the value of this and can you measure success?
## Screenshots

64
.gitignore vendored
View File

@@ -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
View 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
View 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
View 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
View 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
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

View File

@@ -1,6 +1,143 @@
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)*
----------------------------

View File

@@ -28,14 +28,13 @@ Please feel free to use this.
#### Gradle
```groovy
repositories {
jcenter()
mavenCentral() // GPUImage for Android
jcenter()
}
dependencies {
compile 'jp.wasabeef:glide-transformations:1.4.0'
// If you want to use the GPU Filters
compile 'jp.co.cyberagent.android.gpuimage:gpuimage-library:1.3.0'
implementation 'jp.wasabeef:glide-transformations:4.x.x'
// If you want to use the GPU Filters
implementation 'jp.co.cyberagent.android:gpuimage:2.x.x'
}
```
@@ -43,59 +42,72 @@ dependencies {
Set Glide Transform.
```java
```kotlin
Glide.with(this).load(R.drawable.demo)
.bitmapTransform(new BlurTransformation(context))
.into((ImageView) findViewById(R.id.image));
.apply(RequestOptions.bitmapTransform(BlurTransformation(25, 3)))
.into(imageView)
```
## Advanced Step 3
You can set a multiple transformations.
```java
```kotlin
val multi = MultiTransformation<Bitmap>(
BlurTransformation(25),
RoundedCornersTransformation(128, 0, CornerType.BOTTOM))))
Glide.with(this).load(R.drawable.demo)
.bitmapTransform(new BlurTransformation(context, 25, 2), new CropCircleTransformation(context))
.into((ImageView) findViewById(R.id.image));
.apply(RequestOptions.bitmapTransform(multi))
.into(imageView))
```
## Step 4
# Step 4
If you are using `BlurTransformation`.
If you are using `SupportRSBlurTransformation`.
```groovy
android {
...
defaultConfig {
// Warning:Renderscript support mode is not currently supported with renderscript target 21+
renderscriptTargetApi 20
renderscriptSupportModeEnabled true
}
//...
defaultConfig {
//...
renderscriptTargetApi YOUR_TARGET_SDK_VERSION as int
renderscriptSupportModeEnabled true
}
}
```
## Transformations
### Crop
`CropTransformation`, `CropCircleTransformation`, `CropSquareTransformation`,
`RoundedCornersTransformation`
- `CropTransformation`
- `CropCircleTransformation`
- `CropCircleWithBorderTransformation`
- `CropSquareTransformation`
- `RoundedCornersTransformation`
### Color
`ColorFilterTransformation`, `GrayscaleTransformation`
- `ColorFilterTransformation`
- `GrayscaleTransformation`
### Blur
`BlurTransformation`
- `BlurTransformation`
### Mask
`MaskTransformation`
- `MaskTransformation`
### 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`
- `ToonFilterTransformation`
- `SepiaFilterTransformation`
- `ContrastFilterTransformation`
- `InvertFilterTransformation`
- `PixelationFilterTransformation`
- `SketchFilterTransformation`
- `SwirlFilterTransformation`
- `BrightnessFilterTransformation`
- `KuwaharaFilterTransformation`
- `VignetteFilterTransformation`
Applications using Glide Transformations
@@ -106,6 +118,8 @@ Please [ping](mailto:dadadada.chop@gmail.com) me or send a pull request if you w
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
-------
@@ -121,10 +135,11 @@ Contributions
Any contributions are welcome!
Contributers
Contributors
-------
* [start141](https://github.com/start141)
* [squeeish](https://github.com/squeeish)
Thanks
-------
@@ -134,7 +149,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.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.9 MiB

After

Width:  |  Height:  |  Size: 3.9 MiB

View File

@@ -1,21 +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:2.0.0-beta6'
classpath 'com.novoda:bintray-release:0.3.4'
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()
mavenCentral()
}
repositories {
google()
jcenter()
}
}

View File

@@ -1,62 +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 "git rev-list origin/master --count".execute().text.toInteger()
versionName VERSION_NAME
defaultConfig {
minSdkVersion MIN_SDK_VERSION as int
targetSdkVersion TARGET_SDK_VERSION as int
versionCode VERSION_CODE as int
versionName VERSION_NAME
}
// Warning:Renderscript support mode is not currently supported with renderscript target 21+
renderscriptTargetApi RENDERSCRIPT_TARGET_API as int
renderscriptSupportModeEnabled true
// 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.github.bumptech.glide:glide:${GLIDE_VERSION}"
compile "jp.co.cyberagent.android.gpuimage:gpuimage-library:${GPUIMAGE_VERSION}"
compile "com.android.support:appcompat-v7:${SUPPORT_PACKAGE_VERSION}"
compile "com.android.support:recyclerview-v7:${SUPPORT_PACKAGE_VERSION}"
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
View File

View File

@@ -1,22 +1,21 @@
<?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"
>
tools:ignore="GoogleAppIndexingWarning">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
>
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"/>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.example.glide;
package jp.wasabeef.example.glide
/**
* Copyright (C) 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.
@@ -16,12 +16,8 @@ package jp.wasabeef.example.glide;
* limitations under the License.
*/
import android.content.Context;
import android.content.res.Resources
public class Utils {
val Float.px: Float get() = (this * Resources.getSystem().displayMetrics.density)
public static int dip2px(Context context, float dp) {
float scale = context.getResources().getDisplayMetrics().density;
return (int) (dp * scale + 0.5f);
}
}
val Int.px: Int get() = ((this * Resources.getSystem().displayMetrics.density).toInt())

View File

@@ -1,45 +0,0 @@
package jp.wasabeef.example.glide;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
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 AppCompatActivity {
@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.Mask);
dataSet.add(Type.NinePatchMask);
dataSet.add(Type.CropTop);
dataSet.add(Type.CropCenter);
dataSet.add(Type.CropBottom);
dataSet.add(Type.CropSquare);
dataSet.add(Type.CropCircle);
dataSet.add(Type.ColorFilter);
dataSet.add(Type.Grayscale);
dataSet.add(Type.RoundedCorners);
dataSet.add(Type.Blur);
dataSet.add(Type.Toon);
dataSet.add(Type.Sepia);
dataSet.add(Type.Contrast);
dataSet.add(Type.Invert);
dataSet.add(Type.Pixel);
dataSet.add(Type.Sketch);
dataSet.add(Type.Swirl);
dataSet.add(Type.Brightness);
dataSet.add(Type.Kuawahara);
dataSet.add(Type.Vignette);
recyclerView.setAdapter(new MainAdapter(this, dataSet));
}
}

View File

@@ -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
))
}
}
}

View File

@@ -1,239 +0,0 @@
package jp.wasabeef.example.glide;
import android.content.Context;
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 com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import java.util.List;
import jp.wasabeef.glide.transformations.BlurTransformation;
import jp.wasabeef.glide.transformations.ColorFilterTransformation;
import jp.wasabeef.glide.transformations.CropCircleTransformation;
import jp.wasabeef.glide.transformations.CropSquareTransformation;
import jp.wasabeef.glide.transformations.CropTransformation;
import jp.wasabeef.glide.transformations.GrayscaleTransformation;
import jp.wasabeef.glide.transformations.MaskTransformation;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
import jp.wasabeef.glide.transformations.gpu.BrightnessFilterTransformation;
import jp.wasabeef.glide.transformations.gpu.ContrastFilterTransformation;
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;
enum Type {
Mask,
NinePatchMask,
CropTop,
CropCenter,
CropBottom,
CropSquare,
CropCircle,
ColorFilter,
Grayscale,
RoundedCorners,
Blur,
Toon,
Sepia,
Contrast,
Invert,
Pixel,
Sketch,
Swirl,
Brightness,
Kuawahara,
Vignette
}
public MainAdapter(Context context, List<Type> dataSet) {
mContext = context;
mDataSet = dataSet;
}
@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) {
switch (mDataSet.get(position)) {
case Mask: {
int width = Utils.dip2px(mContext, 133.33f);
int height = Utils.dip2px(mContext, 126.33f);
Glide.with(mContext)
.load(R.drawable.check)
.override(width, height)
.bitmapTransform(new CenterCrop(mContext),
new MaskTransformation(mContext, R.drawable.mask_starfish))
.into(holder.image);
break;
}
case NinePatchMask: {
int width = Utils.dip2px(mContext, 150.0f);
int height = Utils.dip2px(mContext, 100.0f);
Glide.with(mContext)
.load(R.drawable.check)
.override(width, height)
.bitmapTransform(new CenterCrop(mContext),
new MaskTransformation(mContext, R.drawable.mask_chat_right))
.into(holder.image);
break;
}
case CropTop:
Glide.with(mContext)
.load(R.drawable.demo)
.bitmapTransform(
new CropTransformation(mContext, 300, 100, CropTransformation.CropType.TOP))
.into(holder.image);
break;
case CropCenter:
Glide.with(mContext)
.load(R.drawable.demo)
.bitmapTransform(new CropTransformation(mContext, 300, 100))
.into(holder.image);
break;
case CropBottom:
Glide.with(mContext)
.load(R.drawable.demo)
.bitmapTransform(
new CropTransformation(mContext, 300, 100, CropTransformation.CropType.BOTTOM))
.into(holder.image);
break;
case CropSquare:
Glide.with(mContext)
.load(R.drawable.demo)
.bitmapTransform(new CropSquareTransformation(mContext))
.into(holder.image);
break;
case CropCircle:
Glide.with(mContext)
.load(R.drawable.demo)
.bitmapTransform(new CropCircleTransformation(mContext))
.into(holder.image);
break;
case ColorFilter:
Glide.with(mContext)
.load(R.drawable.demo)
.bitmapTransform(new ColorFilterTransformation(mContext, Color.argb(80, 255, 0, 0)))
.into(holder.image);
break;
case Grayscale:
Glide.with(mContext)
.load(R.drawable.demo)
.bitmapTransform(new GrayscaleTransformation(mContext))
.into(holder.image);
break;
case RoundedCorners:
Glide.with(mContext)
.load(R.drawable.demo)
.bitmapTransform(new RoundedCornersTransformation(mContext, 30, 0,
RoundedCornersTransformation.CornerType.BOTTOM))
.into(holder.image);
break;
case Blur:
Glide.with(mContext)
.load(R.drawable.check)
.bitmapTransform(new BlurTransformation(mContext, 25, 1))
.into(holder.image);
break;
case Toon:
Glide.with(mContext)
.load(R.drawable.demo)
.bitmapTransform(new ToonFilterTransformation(mContext))
.into(holder.image);
break;
case Sepia:
Glide.with(mContext)
.load(R.drawable.check)
.bitmapTransform(new SepiaFilterTransformation(mContext))
.into(holder.image);
break;
case Contrast:
Glide.with(mContext)
.load(R.drawable.check)
.bitmapTransform(new ContrastFilterTransformation(mContext, 2.0f))
.into(holder.image);
break;
case Invert:
Glide.with(mContext)
.load(R.drawable.check)
.bitmapTransform(new InvertFilterTransformation(mContext))
.into(holder.image);
break;
case Pixel:
Glide.with(mContext)
.load(R.drawable.check)
.bitmapTransform(new PixelationFilterTransformation(mContext, 20))
.into(holder.image);
break;
case Sketch:
Glide.with(mContext)
.load(R.drawable.check)
.bitmapTransform(new SketchFilterTransformation(mContext))
.into(holder.image);
break;
case Swirl:
Glide.with(mContext)
.load(R.drawable.check)
.bitmapTransform(
new SwirlFilterTransformation(mContext, 0.5f, 1.0f, new PointF(0.5f, 0.5f)))
.into(holder.image);
break;
case Brightness:
Glide.with(mContext)
.load(R.drawable.check)
.bitmapTransform(new BrightnessFilterTransformation(mContext, 0.5f))
.into(holder.image);
break;
case Kuawahara:
Glide.with(mContext)
.load(R.drawable.check)
.bitmapTransform(new KuwaharaFilterTransformation(mContext, 25))
.into(holder.image);
break;
case Vignette:
Glide.with(mContext)
.load(R.drawable.check)
.bitmapTransform(new VignetteFilterTransformation(mContext, new PointF(0.5f, 0.5f),
new float[] { 0.0f, 0.0f, 0.0f }, 0f, 0.75f))
.into(holder.image);
break;
}
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);
}
}
}

View 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)
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.2 KiB

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.1 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 7.5 KiB

View File

@@ -1,15 +1,15 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
<?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:background="#CC000000"
tools:context=".MainActivity"
>
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</RelativeLayout>
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>

View File

@@ -1,26 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<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:padding="5dp"
>
android:layout_height="wrap_content">
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:contentDescription="@null"
/>
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>
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>

View File

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

View File

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

View File

@@ -1,28 +1,16 @@
VERSION_NAME=1.4.0
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=23
BUILD_TOOLS_VERSION=23.0.2
TARGET_SDK_VERSION=23
# Warning:Renderscript support mode is not currently supported with renderscript target 21+
RENDERSCRIPT_TARGET_API=20
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
SUPPORT_PACKAGE_VERSION=23.1.1
GLIDE_VERSION=3.6.1
GPUIMAGE_VERSION=1.3.0
COMPILE_SDK_VERSION=30
TARGET_SDK_VERSION=30
MIN_SDK_VERSION=21

Binary file not shown.

View File

@@ -1,6 +1,5 @@
#Wed Apr 10 15:27:10 PDT 2013
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
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.11-all.zip

149
gradlew vendored
View File

@@ -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
View File

@@ -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

View 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

Binary file not shown.

View File

@@ -1,54 +1,41 @@
apply plugin: 'com.android.library'
apply plugin: 'com.novoda.bintray-release'
android {
compileSdkVersion COMPILE_SDK_VERSION as int
buildToolsVersion BUILD_TOOLS_VERSION
compileSdkVersion COMPILE_SDK_VERSION as int
defaultConfig {
minSdkVersion MIN_SDK_VERSION as int
targetSdkVersion TARGET_SDK_VERSION as int
versionCode "git rev-list origin/master --count".execute().text.toInteger()
versionName VERSION_NAME
defaultConfig {
minSdkVersion MIN_SDK_VERSION as int
targetSdkVersion TARGET_SDK_VERSION as int
// Warning:Renderscript support mode is not currently supported with renderscript target 21+
renderscriptTargetApi RENDERSCRIPT_TARGET_API as int
renderscriptSupportModeEnabled true
consumerProguardFiles 'proguard-rules.txt'
}
consumerProguardFiles 'proguard-rules.txt'
}
}
dependencies {
compile "com.github.bumptech.glide:glide:${GLIDE_VERSION}"
provided "jp.co.cyberagent.android.gpuimage:gpuimage-library:${GPUIMAGE_VERSION}"
implementation "com.github.bumptech.glide:glide:$glide_version"
annotationProcessor "com.github.bumptech.glide:compiler:$glide_version"
compileOnly "jp.co.cyberagent.android:gpuimage:$gpuimage_version"
}
task androidJavadocs(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
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"]
}
task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
classifier = 'javadoc'
from androidJavadocs.destinationDir
}
task androidSourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.srcDirs
}
artifacts {
archives androidSourcesJar
archives androidJavadocsJar
}
publish {
userOrg = POM_DEVELOPER_ID
groupId = GROUP
artifactId = ARTIFACT_ID
publishVersion = VERSION_NAME
desc = POM_DESCRIPTION
website = POM_URL
}
apply from: 'https://gist.githubusercontent.com/wasabeef/cf14805bee509baf7461974582f17d26/raw/bintray-v1.gradle'
apply from: 'https://gist.githubusercontent.com/wasabeef/cf14805bee509baf7461974582f17d26/raw/install-v1.gradle'

View File

@@ -1,7 +1,8 @@
-keepclasseswithmembernames class * {
native <methods>;
-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 *;
}
-keep class android.support.v8.renderscript.** { *; }
-dontwarn jp.co.cyberagent.android.gpuimage.**

View File

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

View File

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

View File

@@ -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();
}

View 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.
@@ -20,101 +20,89 @@ import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.support.v8.renderscript.Allocation;
import android.support.v8.renderscript.Element;
import android.support.v8.renderscript.RSRuntimeException;
import android.support.v8.renderscript.RenderScript;
import android.support.v8.renderscript.ScriptIntrinsicBlur;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.Transformation;
import com.bumptech.glide.load.engine.Resource;
import android.renderscript.RSRuntimeException;
import androidx.annotation.NonNull;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
import java.security.MessageDigest;
import jp.wasabeef.glide.transformations.internal.FastBlur;
import jp.wasabeef.glide.transformations.internal.RSBlur;
public class BlurTransformation implements Transformation<Bitmap> {
public class BlurTransformation extends BitmapTransformation {
private static int MAX_RADIUS = 25;
private static int DEFAULT_DOWN_SAMPLING = 1;
private static final int VERSION = 1;
private static final String ID =
"jp.wasabeef.glide.transformations.BlurTransformation." + VERSION;
private Context mContext;
private BitmapPool mBitmapPool;
private static final int MAX_RADIUS = 25;
private static final int DEFAULT_DOWN_SAMPLING = 1;
private int mRadius;
private int mSampling;
private final int radius;
private final int sampling;
public BlurTransformation(Context context) {
this(context, Glide.get(context).getBitmapPool(), MAX_RADIUS, DEFAULT_DOWN_SAMPLING);
public BlurTransformation() {
this(MAX_RADIUS, DEFAULT_DOWN_SAMPLING);
}
public BlurTransformation(Context context, BitmapPool pool) {
this(context, pool, MAX_RADIUS, DEFAULT_DOWN_SAMPLING);
public BlurTransformation(int radius) {
this(radius, DEFAULT_DOWN_SAMPLING);
}
public BlurTransformation(Context context, BitmapPool pool, int radius) {
this(context, pool, radius, DEFAULT_DOWN_SAMPLING);
}
public BlurTransformation(Context context, int radius) {
this(context, Glide.get(context).getBitmapPool(), radius, DEFAULT_DOWN_SAMPLING);
}
public BlurTransformation(Context context, int radius, int sampling) {
this(context, Glide.get(context).getBitmapPool(), radius, sampling);
}
public BlurTransformation(Context context, BitmapPool pool, int radius, int sampling) {
mContext = context.getApplicationContext();
mBitmapPool = pool;
mRadius = radius;
mSampling = sampling;
public BlurTransformation(int radius, int sampling) {
this.radius = radius;
this.sampling = sampling;
}
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
Bitmap source = resource.get();
protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
int width = source.getWidth();
int height = source.getHeight();
int scaledWidth = width / mSampling;
int scaledHeight = height / mSampling;
int width = toTransform.getWidth();
int height = toTransform.getHeight();
int scaledWidth = width / sampling;
int scaledHeight = height / sampling;
Bitmap bitmap = mBitmapPool.get(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
if (bitmap == null) {
bitmap = Bitmap.createBitmap(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
}
Bitmap bitmap = pool.get(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
setCanvasBitmapDensity(toTransform, bitmap);
Canvas canvas = new Canvas(bitmap);
canvas.scale(1 / (float) mSampling, 1 / (float) mSampling);
canvas.scale(1 / (float) sampling, 1 / (float) sampling);
Paint paint = new Paint();
paint.setFlags(Paint.FILTER_BITMAP_FLAG);
canvas.drawBitmap(source, 0, 0, paint);
canvas.drawBitmap(toTransform, 0, 0, paint);
RenderScript rs = null;
try {
rs = RenderScript.create(mContext);
Allocation input =
Allocation.createFromBitmap(rs, bitmap, Allocation.MipmapControl.MIPMAP_NONE,
Allocation.USAGE_SCRIPT);
Allocation output = Allocation.createTyped(rs, input.getType());
ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
blur.setInput(input);
blur.setRadius(mRadius);
blur.forEach(output);
output.copyTo(bitmap);
bitmap = RSBlur.blur(context, bitmap, radius);
} catch (RSRuntimeException e) {
bitmap = FastBlur.doBlur(bitmap, mRadius, true);
} finally {
if (rs != null) {
rs.destroy();
}
bitmap = FastBlur.blur(bitmap, radius, true);
}
return BitmapResource.obtain(bitmap, mBitmapPool);
return bitmap;
}
@Override public String getId() {
return "BlurTransformation(radius=" + mRadius + ", sampling=" + mSampling + ")";
@Override
public String toString() {
return "BlurTransformation(radius=" + radius + ", sampling=" + sampling + ")";
}
@Override
public boolean equals(Object o) {
return o instanceof BlurTransformation &&
((BlurTransformation) o).radius == radius &&
((BlurTransformation) o).sampling == sampling;
}
@Override
public int hashCode() {
return ID.hashCode() + radius * 1000 + sampling * 10;
}
@Override
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
messageDigest.update((ID + radius + sampling).getBytes(CHARSET));
}
}

View 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.
@@ -22,51 +22,64 @@ import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.Transformation;
import com.bumptech.glide.load.engine.Resource;
import androidx.annotation.NonNull;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
public class ColorFilterTransformation implements Transformation<Bitmap> {
import java.security.MessageDigest;
private BitmapPool mBitmapPool;
public class ColorFilterTransformation extends BitmapTransformation {
private int mColor;
private static final int VERSION = 1;
private static final String ID =
"jp.wasabeef.glide.transformations.ColorFilterTransformation." + VERSION;
public ColorFilterTransformation(Context context, int color) {
this(Glide.get(context).getBitmapPool(), color);
}
private final int color;
public ColorFilterTransformation(BitmapPool pool, int color) {
mBitmapPool = pool;
mColor = color;
public ColorFilterTransformation(int color) {
this.color = color;
}
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
Bitmap source = resource.get();
int width = source.getWidth();
int height = source.getHeight();
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.Config config =
source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
Bitmap bitmap = mBitmapPool.get(width, height, config);
if (bitmap == null) {
bitmap = Bitmap.createBitmap(width, height, config);
}
toTransform.getConfig() != null ? toTransform.getConfig() : Bitmap.Config.ARGB_8888;
Bitmap bitmap = pool.get(width, height, config);
setCanvasBitmapDensity(toTransform, bitmap);
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);
paint.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP));
canvas.drawBitmap(toTransform, 0, 0, paint);
return BitmapResource.obtain(bitmap, mBitmapPool);
return bitmap;
}
@Override public String getId() {
return "ColorFilterTransformation(color=" + mColor + ")";
@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));
}
}

View 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.
@@ -18,61 +18,48 @@ package jp.wasabeef.glide.transformations;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.Transformation;
import com.bumptech.glide.load.engine.Resource;
import androidx.annotation.NonNull;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
import com.bumptech.glide.load.resource.bitmap.TransformationUtils;
import com.bumptech.glide.request.RequestOptions;
public class CropCircleTransformation implements Transformation<Bitmap> {
import java.security.MessageDigest;
private BitmapPool mBitmapPool;
/**
* @deprecated Use {@link RequestOptions#circleCrop()}.
*/
@Deprecated
public class CropCircleTransformation extends BitmapTransformation {
public CropCircleTransformation(Context context) {
this(Glide.get(context).getBitmapPool());
}
private static final int VERSION = 1;
private static final String ID =
"jp.wasabeef.glide.transformations.CropCircleTransformation." + VERSION;
public CropCircleTransformation(BitmapPool pool) {
this.mBitmapPool = pool;
@Override
protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
return TransformationUtils.circleCrop(pool, toTransform, outWidth, outHeight);
}
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
Bitmap source = resource.get();
int size = Math.min(source.getWidth(), source.getHeight());
int width = (source.getWidth() - size) / 2;
int height = (source.getHeight() - size) / 2;
Bitmap bitmap = mBitmapPool.get(size, size, Bitmap.Config.ARGB_8888);
if (bitmap == null) {
bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
}
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint();
BitmapShader shader =
new BitmapShader(source, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP);
if (width != 0 || height != 0) {
// source isn't square, move viewport to center
Matrix matrix = new Matrix();
matrix.setTranslate(-width, -height);
shader.setLocalMatrix(matrix);
}
paint.setShader(shader);
paint.setAntiAlias(true);
float r = size / 2f;
canvas.drawCircle(r, r, r, paint);
return BitmapResource.obtain(bitmap, mBitmapPool);
}
@Override public String getId() {
public String toString() {
return "CropCircleTransformation()";
}
@Override
public boolean equals(Object o) {
return o instanceof CropCircleTransformation;
}
@Override
public int hashCode() {
return ID.hashCode();
}
@Override
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
messageDigest.update((ID).getBytes(CHARSET));
}
}

View File

@@ -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;
}
}

View 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.
@@ -18,45 +18,46 @@ package jp.wasabeef.glide.transformations;
import android.content.Context;
import android.graphics.Bitmap;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.Transformation;
import com.bumptech.glide.load.engine.Resource;
import androidx.annotation.NonNull;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
import com.bumptech.glide.load.resource.bitmap.TransformationUtils;
public class CropSquareTransformation implements Transformation<Bitmap> {
import java.security.MessageDigest;
private BitmapPool mBitmapPool;
private int mWidth;
private int mHeight;
public class CropSquareTransformation extends BitmapTransformation {
public CropSquareTransformation(Context context) {
this(Glide.get(context).getBitmapPool());
}
private static final int VERSION = 1;
private static final String ID =
"jp.wasabeef.glide.transformations.CropSquareTransformation." + VERSION;
public CropSquareTransformation(BitmapPool pool) {
this.mBitmapPool = pool;
private int size;
@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);
}
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
Bitmap source = resource.get();
int size = Math.min(source.getWidth(), source.getHeight());
mWidth = (source.getWidth() - size) / 2;
mHeight = (source.getHeight() - size) / 2;
Bitmap.Config config =
source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
Bitmap bitmap = mBitmapPool.get(mWidth, mHeight, config);
if (bitmap == null) {
bitmap = Bitmap.createBitmap(source, mWidth, mHeight, size, size);
}
return BitmapResource.obtain(bitmap, mBitmapPool);
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));
}
}

View 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.
@@ -20,13 +20,17 @@ import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.RectF;
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;
public class CropTransformation implements Transformation<Bitmap> {
import androidx.annotation.NonNull;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
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,
@@ -34,83 +38,85 @@ public class CropTransformation implements Transformation<Bitmap> {
BOTTOM
}
private BitmapPool mBitmapPool;
private int mWidth;
private int mHeight;
private int width;
private int height;
private CropType mCropType = CropType.CENTER;
private CropType cropType = CropType.CENTER;
public CropTransformation(Context context) {
this(Glide.get(context).getBitmapPool());
public CropTransformation(int width, int height) {
this(width, height, CropType.CENTER);
}
public CropTransformation(BitmapPool pool) {
this(pool, 0, 0);
}
public CropTransformation(Context context, int width, int height) {
this(Glide.get(context).getBitmapPool(), width, height);
}
public CropTransformation(BitmapPool pool, int width, int height) {
this(pool, width, height, CropType.CENTER);
}
public CropTransformation(Context context, int width, int height, CropType cropType) {
this(Glide.get(context).getBitmapPool(), width, height, cropType);
}
public CropTransformation(BitmapPool pool, int width, int height, CropType cropType) {
mBitmapPool = pool;
mWidth = width;
mHeight = height;
mCropType = cropType;
public CropTransformation(int width, int height, CropType cropType) {
this.width = width;
this.height = height;
this.cropType = cropType;
}
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
Bitmap source = resource.get();
mWidth = mWidth == 0 ? source.getWidth() : mWidth;
mHeight = mHeight == 0 ? source.getHeight() : mHeight;
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 =
source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
Bitmap bitmap = mBitmapPool.get(mWidth, mHeight, config);
if (bitmap == null) {
bitmap = Bitmap.createBitmap(mWidth, mHeight, config);
}
toTransform.getConfig() != null ? toTransform.getConfig() : Bitmap.Config.ARGB_8888;
Bitmap bitmap = pool.get(width, height, config);
float scaleX = (float) mWidth / source.getWidth();
float scaleY = (float) mHeight / source.getHeight();
bitmap.setHasAlpha(true);
float scaleX = (float) width / toTransform.getWidth();
float scaleY = (float) height / toTransform.getHeight();
float scale = Math.max(scaleX, scaleY);
float scaledWidth = scale * source.getWidth();
float scaledHeight = scale * source.getHeight();
float left = (mWidth - scaledWidth) / 2;
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(source, null, targetRect, null);
canvas.drawBitmap(toTransform, null, targetRect, null);
return BitmapResource.obtain(bitmap, mBitmapPool);
}
@Override public String getId() {
return "CropTransformation(width=" + mWidth + ", height=" + mHeight + ", cropType=" + mCropType
+ ")";
return bitmap;
}
private float getTop(float scaledHeight) {
switch (mCropType) {
switch (cropType) {
case TOP:
return 0;
case CENTER:
return (mHeight - scaledHeight) / 2;
return (height - scaledHeight) / 2;
case BOTTOM:
return mHeight - scaledHeight;
return height - scaledHeight;
default:
return 0;
}
}
@Override
public String toString() {
return "CropTransformation(width=" + width + ", height=" + height + ", cropType=" + cropType + ")";
}
@Override
public boolean equals(Object o) {
return o instanceof CropTransformation &&
((CropTransformation) o).width == width &&
((CropTransformation) o).height == height &&
((CropTransformation) o).cropType == cropType;
}
@Override
public int hashCode() {
return ID.hashCode() + width * 100000 + height * 1000 + cropType.ordinal() * 10;
}
@Override
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
messageDigest.update((ID + width + height + cropType).getBytes(CHARSET));
}
}

View 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.
@@ -22,49 +22,58 @@ import android.graphics.Canvas;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.Paint;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.Transformation;
import com.bumptech.glide.load.engine.Resource;
import androidx.annotation.NonNull;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
public class GrayscaleTransformation implements Transformation<Bitmap> {
import java.security.MessageDigest;
private BitmapPool mBitmapPool;
public class GrayscaleTransformation extends BitmapTransformation {
public GrayscaleTransformation(Context context) {
this(Glide.get(context).getBitmapPool());
}
public GrayscaleTransformation(BitmapPool pool) {
mBitmapPool = pool;
}
private static final int VERSION = 1;
private static final String ID =
"jp.wasabeef.glide.transformations.GrayscaleTransformation." + VERSION;
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
Bitmap source = resource.get();
int width = source.getWidth();
int height = source.getHeight();
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.Config config =
source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
Bitmap bitmap = mBitmapPool.get(width, height, config);
if (bitmap == null) {
bitmap = Bitmap.createBitmap(width, height, config);
}
toTransform.getConfig() != null ? toTransform.getConfig() : Bitmap.Config.ARGB_8888;
Bitmap bitmap = pool.get(width, height, config);
setCanvasBitmapDensity(toTransform, bitmap);
Canvas canvas = new Canvas(bitmap);
ColorMatrix saturation = new ColorMatrix();
saturation.setSaturation(0f);
Paint paint = new Paint();
paint.setColorFilter(new ColorMatrixColorFilter(saturation));
canvas.drawBitmap(source, 0, 0, paint);
canvas.drawBitmap(toTransform, 0, 0, paint);
return BitmapResource.obtain(bitmap, mBitmapPool);
return bitmap;
}
@Override public String getId() {
@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));
}
}

View 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.
@@ -23,63 +23,74 @@ import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.drawable.Drawable;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.Transformation;
import com.bumptech.glide.load.engine.Resource;
import androidx.annotation.NonNull;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
import jp.wasabeef.glide.transformations.internal.Utils;
public class MaskTransformation implements Transformation<Bitmap> {
import java.security.MessageDigest;
private static Paint mMaskingPaint = new Paint();
private Context mContext;
private BitmapPool mBitmapPool;
private int mMaskId;
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 {
mMaskingPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
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 getId() return the same values if using the
* same make file name. If you have a good idea please tell us, thanks.
* 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(Context context, int maskId) {
this(context, Glide.get(context).getBitmapPool(), maskId);
}
public MaskTransformation(Context context, BitmapPool pool, int maskId) {
mBitmapPool = pool;
mContext = context.getApplicationContext();
mMaskId = maskId;
public MaskTransformation(int maskId) {
this.maskId = maskId;
}
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
Bitmap source = resource.get();
protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
int width = toTransform.getWidth();
int height = toTransform.getHeight();
int width = source.getWidth();
int height = source.getHeight();
Bitmap bitmap = pool.get(width, height, Bitmap.Config.ARGB_8888);
bitmap.setHasAlpha(true);
Bitmap result = mBitmapPool.get(width, height, Bitmap.Config.ARGB_8888);
if (result == null) {
result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
}
Drawable mask = context.getDrawable(maskId);
Drawable mask = Utils.getMaskDrawable(mContext, mMaskId);
setCanvasBitmapDensity(toTransform, bitmap);
Canvas canvas = new Canvas(result);
Canvas canvas = new Canvas(bitmap);
mask.setBounds(0, 0, width, height);
mask.draw(canvas);
canvas.drawBitmap(source, 0, 0, mMaskingPaint);
canvas.drawBitmap(toTransform, 0, 0, paint);
return BitmapResource.obtain(result, mBitmapPool);
return bitmap;
}
@Override public String getId() {
return "MaskTransformation(maskId=" + mContext.getResources().getResourceEntryName(mMaskId)
+ ")";
@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));
}
}

View 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.
@@ -23,13 +23,17 @@ import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.Shader;
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;
public class RoundedCornersTransformation implements Transformation<Bitmap> {
import androidx.annotation.NonNull;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import java.security.MessageDigest;
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,
@@ -39,61 +43,48 @@ public class RoundedCornersTransformation implements Transformation<Bitmap> {
DIAGONAL_FROM_TOP_LEFT, DIAGONAL_FROM_TOP_RIGHT
}
private BitmapPool mBitmapPool;
private int mRadius;
private int mDiameter;
private int mMargin;
private CornerType mCornerType;
private final int radius;
private final int diameter;
private final int margin;
private final CornerType cornerType;
public RoundedCornersTransformation(Context context, int radius, int margin) {
this(context, radius, margin, CornerType.ALL);
public RoundedCornersTransformation(int radius, int margin) {
this(radius, margin, CornerType.ALL);
}
public RoundedCornersTransformation(BitmapPool pool, int radius, int margin) {
this(pool, radius, margin, CornerType.ALL);
}
public RoundedCornersTransformation(Context context, int radius, int margin,
CornerType cornerType) {
this(Glide.get(context).getBitmapPool(), radius, margin, cornerType);
}
public RoundedCornersTransformation(BitmapPool pool, int radius, int margin,
CornerType cornerType) {
mBitmapPool = pool;
mRadius = radius;
mDiameter = mRadius * 2;
mMargin = margin;
mCornerType = cornerType;
public RoundedCornersTransformation(int radius, int margin, CornerType cornerType) {
this.radius = radius;
this.diameter = this.radius * 2;
this.margin = margin;
this.cornerType = cornerType;
}
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
Bitmap source = resource.get();
protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
int width = toTransform.getWidth();
int height = toTransform.getHeight();
int width = source.getWidth();
int height = source.getHeight();
Bitmap bitmap = pool.get(width, height, Bitmap.Config.ARGB_8888);
bitmap.setHasAlpha(true);
Bitmap bitmap = mBitmapPool.get(width, height, Bitmap.Config.ARGB_8888);
if (bitmap == null) {
bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
}
setCanvasBitmapDensity(toTransform, bitmap);
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
paint.setShader(new BitmapShader(toTransform, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
drawRoundRect(canvas, paint, width, height);
return BitmapResource.obtain(bitmap, mBitmapPool);
return bitmap;
}
private void drawRoundRect(Canvas canvas, Paint paint, float width, float height) {
float right = width - mMargin;
float bottom = height - mMargin;
float right = width - margin;
float bottom = height - margin;
switch (mCornerType) {
switch (cornerType) {
case ALL:
canvas.drawRoundRect(new RectF(mMargin, mMargin, right, bottom), mRadius, mRadius, paint);
canvas.drawRoundRect(new RectF(margin, margin, right, bottom), radius, radius, paint);
break;
case TOP_LEFT:
drawTopLeftRoundRect(canvas, paint, right, bottom);
@@ -138,118 +129,135 @@ public class RoundedCornersTransformation implements Transformation<Bitmap> {
drawDiagonalFromTopRightRoundRect(canvas, paint, right, bottom);
break;
default:
canvas.drawRoundRect(new RectF(mMargin, mMargin, right, bottom), mRadius, mRadius, paint);
canvas.drawRoundRect(new RectF(margin, margin, right, bottom), radius, radius, paint);
break;
}
}
private void drawTopLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
canvas.drawRoundRect(new RectF(mMargin, mMargin, mMargin + mDiameter, mMargin + mDiameter),
mRadius, mRadius, paint);
canvas.drawRect(new RectF(mMargin, mMargin + mRadius, mMargin + mRadius, bottom), paint);
canvas.drawRect(new RectF(mMargin + mRadius, mMargin, right, bottom), paint);
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);
}
private void drawTopRightRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
canvas.drawRoundRect(new RectF(right - mDiameter, mMargin, right, mMargin + mDiameter), mRadius,
mRadius, paint);
canvas.drawRect(new RectF(mMargin, mMargin, right - mRadius, bottom), paint);
canvas.drawRect(new RectF(right - mRadius, mMargin + mRadius, right, bottom), paint);
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);
}
private void drawBottomLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
canvas.drawRoundRect(new RectF(mMargin, bottom - mDiameter, mMargin + mDiameter, bottom),
mRadius, mRadius, paint);
canvas.drawRect(new RectF(mMargin, mMargin, mMargin + mDiameter, bottom - mRadius), paint);
canvas.drawRect(new RectF(mMargin + mRadius, mMargin, right, bottom), paint);
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);
}
private void drawBottomRightRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
canvas.drawRoundRect(new RectF(right - mDiameter, bottom - mDiameter, right, bottom), mRadius,
mRadius, paint);
canvas.drawRect(new RectF(mMargin, mMargin, right - mRadius, bottom), paint);
canvas.drawRect(new RectF(right - mRadius, mMargin, right, bottom - mRadius), paint);
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);
}
private void drawTopRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
canvas.drawRoundRect(new RectF(mMargin, mMargin, right, mMargin + mDiameter), mRadius, mRadius,
paint);
canvas.drawRect(new RectF(mMargin, mMargin + mRadius, right, bottom), paint);
canvas.drawRoundRect(new RectF(margin, margin, right, margin + diameter), radius, radius,
paint);
canvas.drawRect(new RectF(margin, margin + radius, right, bottom), paint);
}
private void drawBottomRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
canvas.drawRoundRect(new RectF(mMargin, bottom - mDiameter, right, bottom), mRadius, mRadius,
paint);
canvas.drawRect(new RectF(mMargin, mMargin, right, bottom - mRadius), paint);
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(mMargin, mMargin, mMargin + mDiameter, bottom), mRadius, mRadius,
paint);
canvas.drawRect(new RectF(mMargin + mRadius, mMargin, right, bottom), paint);
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 - mDiameter, mMargin, right, bottom), mRadius, mRadius,
paint);
canvas.drawRect(new RectF(mMargin, mMargin, right - mRadius, bottom), paint);
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(mMargin, bottom - mDiameter, right, bottom), mRadius, mRadius,
paint);
canvas.drawRoundRect(new RectF(right - mDiameter, mMargin, right, bottom), mRadius, mRadius,
paint);
canvas.drawRect(new RectF(mMargin, mMargin, right - mRadius, bottom - mRadius), paint);
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(mMargin, mMargin, mMargin + mDiameter, bottom), mRadius, mRadius,
paint);
canvas.drawRoundRect(new RectF(mMargin, bottom - mDiameter, right, bottom), mRadius, mRadius,
paint);
canvas.drawRect(new RectF(mMargin + mRadius, mMargin, right, bottom - mRadius), paint);
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(mMargin, mMargin, right, mMargin + mDiameter), mRadius, mRadius,
paint);
canvas.drawRoundRect(new RectF(right - mDiameter, mMargin, right, bottom), mRadius, mRadius,
paint);
canvas.drawRect(new RectF(mMargin, mMargin + mRadius, right - mRadius, bottom), paint);
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(mMargin, mMargin, right, mMargin + mDiameter), mRadius, mRadius,
paint);
canvas.drawRoundRect(new RectF(mMargin, mMargin, mMargin + mDiameter, bottom), mRadius, mRadius,
paint);
canvas.drawRect(new RectF(mMargin + mRadius, mMargin + mRadius, right, bottom), paint);
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(mMargin, mMargin, mMargin + mDiameter, mMargin + mDiameter),
mRadius, mRadius, paint);
canvas.drawRoundRect(new RectF(right - mDiameter, bottom - mDiameter, right, bottom), mRadius,
mRadius, paint);
canvas.drawRect(new RectF(mMargin, mMargin + mRadius, right - mDiameter, bottom), paint);
canvas.drawRect(new RectF(mMargin + mDiameter, mMargin, right, bottom - mRadius), paint);
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 - mDiameter, mMargin, right, mMargin + mDiameter), mRadius,
mRadius, paint);
canvas.drawRoundRect(new RectF(mMargin, bottom - mDiameter, mMargin + mDiameter, bottom),
mRadius, mRadius, paint);
canvas.drawRect(new RectF(mMargin, mMargin, right - mRadius, bottom - mRadius), paint);
canvas.drawRect(new RectF(mMargin + mRadius, mMargin + mRadius, right, bottom), paint);
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 getId() {
return "RoundedTransformation(radius=" + mRadius + ", margin=" + mMargin + ", diameter="
+ mDiameter + ", cornerType=" + mCornerType.name() + ")";
@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));
}
}

View 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,38 +16,52 @@ package jp.wasabeef.glide.transformations.gpu;
* limitations under the License.
*/
import android.content.Context;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import jp.co.cyberagent.android.gpuimage.GPUImageBrightnessFilter;
import androidx.annotation.NonNull;
import java.security.MessageDigest;
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 extends GPUFilterTransformation {
private float mBrightness;
private static final int VERSION = 1;
private static final String ID =
"jp.wasabeef.glide.transformations.gpu.BrightnessFilterTransformation." + VERSION;
public BrightnessFilterTransformation(Context context) {
this(context, Glide.get(context).getBitmapPool());
private final float brightness;
public BrightnessFilterTransformation() {
this(0.0f);
}
public BrightnessFilterTransformation(Context context, BitmapPool pool) {
this(context, pool, 0.0f);
}
public BrightnessFilterTransformation(Context context, float brightness) {
this(context, Glide.get(context).getBitmapPool(), brightness);
}
public BrightnessFilterTransformation(Context context, BitmapPool pool, float brightness) {
super(context, pool, new GPUImageBrightnessFilter());
mBrightness = brightness;
public BrightnessFilterTransformation(float brightness) {
super(new GPUImageBrightnessFilter());
this.brightness = brightness;
GPUImageBrightnessFilter filter = getFilter();
filter.setBrightness(mBrightness);
filter.setBrightness(this.brightness);
}
@Override public String getId() {
return "BrightnessFilterTransformation(brightness=" + mBrightness + ")";
@Override
public String toString() {
return "BrightnessFilterTransformation(brightness=" + brightness + ")";
}
@Override
public boolean equals(Object o) {
return o instanceof BrightnessFilterTransformation &&
((BrightnessFilterTransformation) o).brightness == brightness;
}
@Override
public int hashCode() {
return ID.hashCode() + (int) ((brightness + 1.0f) * 10);
}
@Override
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
messageDigest.update((ID + brightness).getBytes(CHARSET));
}
}

View 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,38 +16,51 @@ package jp.wasabeef.glide.transformations.gpu;
* limitations under the License.
*/
import android.content.Context;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import jp.co.cyberagent.android.gpuimage.GPUImageContrastFilter;
import androidx.annotation.NonNull;
import java.security.MessageDigest;
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 extends GPUFilterTransformation {
private float mContrast;
private static final int VERSION = 1;
private static final String ID =
"jp.wasabeef.glide.transformations.gpu.ContrastFilterTransformation." + VERSION;
public ContrastFilterTransformation(Context context) {
this(context, Glide.get(context).getBitmapPool());
private final float contrast;
public ContrastFilterTransformation() {
this(1.0f);
}
public ContrastFilterTransformation(Context context, BitmapPool pool) {
this(context, pool, 1.0f);
}
public ContrastFilterTransformation(Context context, float contrast) {
this(context, Glide.get(context).getBitmapPool(), contrast);
}
public ContrastFilterTransformation(Context context, BitmapPool pool, float contrast) {
super(context, pool, new GPUImageContrastFilter());
mContrast = contrast;
public ContrastFilterTransformation(float contrast) {
super(new GPUImageContrastFilter());
this.contrast = contrast;
GPUImageContrastFilter filter = getFilter();
filter.setContrast(mContrast);
filter.setContrast(this.contrast);
}
@Override public String getId() {
return "ContrastFilterTransformation(contrast=" + mContrast + ")";
@Override
public String toString() {
return "ContrastFilterTransformation(contrast=" + contrast + ")";
}
@Override
public boolean equals(Object o) {
return o instanceof ContrastFilterTransformation;
}
@Override
public int hashCode() {
return ID.hashCode() + (int) (contrast * 10);
}
@Override
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
messageDigest.update((ID + contrast).getBytes(CHARSET));
}
}

View 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.
@@ -18,48 +18,62 @@ package jp.wasabeef.glide.transformations.gpu;
import android.content.Context;
import android.graphics.Bitmap;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.Transformation;
import com.bumptech.glide.load.engine.Resource;
import androidx.annotation.NonNull;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
import java.security.MessageDigest;
import jp.co.cyberagent.android.gpuimage.GPUImage;
import jp.co.cyberagent.android.gpuimage.GPUImageFilter;
import jp.co.cyberagent.android.gpuimage.filter.GPUImageFilter;
import jp.wasabeef.glide.transformations.BitmapTransformation;
public class GPUFilterTransformation implements Transformation<Bitmap> {
public class GPUFilterTransformation extends BitmapTransformation {
private Context mContext;
private BitmapPool mBitmapPool;
private static final int VERSION = 1;
private static final String ID =
"jp.wasabeef.glide.transformations.gpu.GPUFilterTransformation." + VERSION;
private static final byte[] ID_BYTES = ID.getBytes(CHARSET);
private GPUImageFilter mFilter;
private final GPUImageFilter gpuImageFilter;
public GPUFilterTransformation(Context context, GPUImageFilter filter) {
this(context, Glide.get(context).getBitmapPool(), filter);
}
public GPUFilterTransformation(Context context, BitmapPool pool, GPUImageFilter filter) {
mContext = context.getApplicationContext();
mBitmapPool = pool;
mFilter = filter;
public GPUFilterTransformation(GPUImageFilter filter) {
this.gpuImageFilter = filter;
}
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
Bitmap source = resource.get();
GPUImage gpuImage = new GPUImage(mContext);
gpuImage.setImage(source);
gpuImage.setFilter(mFilter);
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);
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
return BitmapResource.obtain(bitmap, mBitmapPool);
return gpuImage.getBitmapWithFilterApplied();
}
@Override public String getId() {
@Override
public String toString() {
return getClass().getSimpleName();
}
@SuppressWarnings("unchecked") public <T> T getFilter() {
return (T) mFilter;
@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);
}
}

View 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,25 +16,42 @@ package jp.wasabeef.glide.transformations.gpu;
* limitations under the License.
*/
import android.content.Context;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import jp.co.cyberagent.android.gpuimage.GPUImageColorInvertFilter;
import androidx.annotation.NonNull;
import java.security.MessageDigest;
import jp.co.cyberagent.android.gpuimage.filter.GPUImageColorInvertFilter;
/**
* Invert all the colors in the image.
*/
public class InvertFilterTransformation extends GPUFilterTransformation {
public InvertFilterTransformation(Context context) {
this(context, Glide.get(context).getBitmapPool());
private static final int VERSION = 1;
private static final String ID =
"jp.wasabeef.glide.transformations.gpu.InvertFilterTransformation." + VERSION;
public InvertFilterTransformation() {
super(new GPUImageColorInvertFilter());
}
public InvertFilterTransformation(Context context, BitmapPool pool) {
super(context, pool, new GPUImageColorInvertFilter());
}
@Override public String getId() {
@Override
public String toString() {
return "InvertFilterTransformation()";
}
@Override
public boolean equals(Object o) {
return o instanceof InvertFilterTransformation;
}
@Override
public int hashCode() {
return ID.hashCode();
}
@Override
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
messageDigest.update((ID).getBytes(CHARSET));
}
}

View 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,41 +16,54 @@ package jp.wasabeef.glide.transformations.gpu;
* limitations under the License.
*/
import android.content.Context;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import jp.co.cyberagent.android.gpuimage.GPUImageKuwaharaFilter;
import androidx.annotation.NonNull;
import java.security.MessageDigest;
import jp.co.cyberagent.android.gpuimage.filter.GPUImageKuwaharaFilter;
/**
* 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 extends GPUFilterTransformation {
private int mRadius;
private static final int VERSION = 1;
private static final String ID =
"jp.wasabeef.glide.transformations.gpu.KuwaharaFilterTransformation." + VERSION;
public KuwaharaFilterTransformation(Context context) {
this(context, Glide.get(context).getBitmapPool());
private final int radius;
public KuwaharaFilterTransformation() {
this(25);
}
public KuwaharaFilterTransformation(Context context, BitmapPool pool) {
this(context, pool, 25);
}
public KuwaharaFilterTransformation(Context context, int radius) {
this(context, Glide.get(context).getBitmapPool(), radius);
}
public KuwaharaFilterTransformation(Context context, BitmapPool pool, int radius) {
super(context, pool, new GPUImageKuwaharaFilter());
mRadius = radius;
public KuwaharaFilterTransformation(int radius) {
super(new GPUImageKuwaharaFilter());
this.radius = radius;
GPUImageKuwaharaFilter filter = getFilter();
filter.setRadius(mRadius);
filter.setRadius(this.radius);
}
@Override public String getId() {
return "KuwaharaFilterTransformation(radius=" + mRadius + ")";
@Override
public String toString() {
return "KuwaharaFilterTransformation(radius=" + radius + ")";
}
@Override
public boolean equals(Object o) {
return o instanceof KuwaharaFilterTransformation;
}
@Override
public int hashCode() {
return ID.hashCode() + radius * 10;
}
@Override
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
messageDigest.update((ID + radius).getBytes(CHARSET));
}
}

View 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,40 +16,53 @@ package jp.wasabeef.glide.transformations.gpu;
* limitations under the License.
*/
import android.content.Context;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import jp.co.cyberagent.android.gpuimage.GPUImagePixelationFilter;
import androidx.annotation.NonNull;
import java.security.MessageDigest;
import jp.co.cyberagent.android.gpuimage.filter.GPUImagePixelationFilter;
/**
* Applies a Pixelation effect to the image.
*
* <p>
* The pixel with a default of 10.0.
*/
public class PixelationFilterTransformation extends GPUFilterTransformation {
private float mPixel;
private static final int VERSION = 1;
private static final String ID =
"jp.wasabeef.glide.transformations.gpu.PixelationFilterTransformation." + VERSION;
public PixelationFilterTransformation(Context context) {
this(context, Glide.get(context).getBitmapPool());
private final float pixel;
public PixelationFilterTransformation() {
this(10f);
}
public PixelationFilterTransformation(Context context, BitmapPool pool) {
this(context, pool, 10f);
}
public PixelationFilterTransformation(Context context, float pixel) {
this(context, Glide.get(context).getBitmapPool(), pixel);
}
public PixelationFilterTransformation(Context context, BitmapPool pool, float pixel) {
super(context, pool, new GPUImagePixelationFilter());
mPixel = pixel;
public PixelationFilterTransformation(float pixel) {
super(new GPUImagePixelationFilter());
this.pixel = pixel;
GPUImagePixelationFilter filter = getFilter();
filter.setPixel(mPixel);
filter.setPixel(this.pixel);
}
@Override public String getId() {
return "PixelationFilterTransformation(pixel=" + mPixel + ")";
@Override
public String toString() {
return "PixelationFilterTransformation(pixel=" + pixel + ")";
}
@Override
public boolean equals(Object o) {
return o instanceof PixelationFilterTransformation;
}
@Override
public int hashCode() {
return ID.hashCode() + (int) (pixel * 10);
}
@Override
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
messageDigest.update((ID + pixel).getBytes(CHARSET));
}
}

View 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,40 +16,53 @@ package jp.wasabeef.glide.transformations.gpu;
* limitations under the License.
*/
import android.content.Context;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import jp.co.cyberagent.android.gpuimage.GPUImageSepiaFilter;
import androidx.annotation.NonNull;
import java.security.MessageDigest;
import jp.co.cyberagent.android.gpuimage.filter.GPUImageSepiaToneFilter;
/**
* Applies a simple sepia effect.
*
* <p>
* The intensity with a default of 1.0.
*/
public class SepiaFilterTransformation extends GPUFilterTransformation {
private float mIntensity;
private static final int VERSION = 1;
private static final String ID =
"jp.wasabeef.glide.transformations.gpu.SepiaFilterTransformation." + VERSION;
public SepiaFilterTransformation(Context context) {
this(context, Glide.get(context).getBitmapPool());
private final float intensity;
public SepiaFilterTransformation() {
this(1.0f);
}
public SepiaFilterTransformation(Context context, BitmapPool pool) {
this(context, pool, 1.0f);
public SepiaFilterTransformation(float intensity) {
super(new GPUImageSepiaToneFilter());
this.intensity = intensity;
GPUImageSepiaToneFilter filter = getFilter();
filter.setIntensity(this.intensity);
}
public SepiaFilterTransformation(Context context, float intensity) {
this(context, Glide.get(context).getBitmapPool(), intensity);
@Override
public String toString() {
return "SepiaFilterTransformation(intensity=" + intensity + ")";
}
public SepiaFilterTransformation(Context context, BitmapPool pool, float intensity) {
super(context, pool, new GPUImageSepiaFilter());
mIntensity = intensity;
GPUImageSepiaFilter filter = getFilter();
filter.setIntensity(mIntensity);
@Override
public boolean equals(Object o) {
return o instanceof SepiaFilterTransformation;
}
@Override public String getId() {
return "SepiaFilterTransformation(intensity=" + mIntensity + ")";
@Override
public int hashCode() {
return ID.hashCode() + (int) (intensity * 10);
}
@Override
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
messageDigest.update((ID + intensity).getBytes(CHARSET));
}
}

View 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,22 +16,39 @@ package jp.wasabeef.glide.transformations.gpu;
* limitations under the License.
*/
import android.content.Context;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import jp.co.cyberagent.android.gpuimage.GPUImageSketchFilter;
import androidx.annotation.NonNull;
import java.security.MessageDigest;
import jp.co.cyberagent.android.gpuimage.filter.GPUImageSketchFilter;
public class SketchFilterTransformation extends GPUFilterTransformation {
public SketchFilterTransformation(Context context) {
this(context, Glide.get(context).getBitmapPool());
private static final int VERSION = 1;
private static final String ID =
"jp.wasabeef.glide.transformations.gpu.SketchFilterTransformation." + VERSION;
public SketchFilterTransformation() {
super(new GPUImageSketchFilter());
}
public SketchFilterTransformation(Context context, BitmapPool pool) {
super(context, pool, new GPUImageSketchFilter());
}
@Override public String getId() {
@Override
public String toString() {
return "SketchFilterTransformation()";
}
@Override
public boolean equals(Object o) {
return o instanceof SketchFilterTransformation;
}
@Override
public int hashCode() {
return ID.hashCode();
}
@Override
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
messageDigest.update((ID).getBytes(CHARSET));
}
}

View 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,52 +16,68 @@ package jp.wasabeef.glide.transformations.gpu;
* limitations under the License.
*/
import android.content.Context;
import android.graphics.PointF;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import jp.co.cyberagent.android.gpuimage.GPUImageSwirlFilter;
import androidx.annotation.NonNull;
import java.security.MessageDigest;
import jp.co.cyberagent.android.gpuimage.filter.GPUImageSwirlFilter;
/**
* Creates a swirl distortion on the image.
*/
public class SwirlFilterTransformation extends GPUFilterTransformation {
private float mRadius;
private float mAngle;
private PointF mCenter;
private static final int VERSION = 1;
private static final String ID =
"jp.wasabeef.glide.transformations.gpu.SwirlFilterTransformation." + VERSION;
public SwirlFilterTransformation(Context context) {
this(context, Glide.get(context).getBitmapPool());
}
private final float radius;
private final float angle;
private final PointF center;
public SwirlFilterTransformation(Context context, BitmapPool pool) {
this(context, pool, .5f, 1.0f, new PointF(0.5f, 0.5f));
}
public SwirlFilterTransformation(Context context, float radius, float angle, PointF center) {
this(context, Glide.get(context).getBitmapPool(), radius, angle, center);
public SwirlFilterTransformation() {
this(.5f, 1.0f, new PointF(0.5f, 0.5f));
}
/**
* @param radius from 0.0 to 1.0, default 0.5
* @param angle minimum 0.0, default 1.0
* @param 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) {
super(context, pool, new GPUImageSwirlFilter());
mRadius = radius;
mAngle = angle;
mCenter = center;
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(mRadius);
filter.setAngle(mAngle);
filter.setCenter(mCenter);
filter.setRadius(this.radius);
filter.setAngle(this.angle);
filter.setCenter(this.center);
}
@Override public String getId() {
return "SwirlFilterTransformation(radius=" + mRadius +
",angle=" + mAngle + ",center=" + mCenter.toString() + ")";
@Override
public String toString() {
return "SwirlFilterTransformation(radius=" + radius + ",angle=" + angle + ",center="
+ center.toString() + ")";
}
@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 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));
}
}

View 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,10 +16,11 @@ package jp.wasabeef.glide.transformations.gpu;
* limitations under the License.
*/
import android.content.Context;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import jp.co.cyberagent.android.gpuimage.GPUImageToonFilter;
import androidx.annotation.NonNull;
import java.security.MessageDigest;
import jp.co.cyberagent.android.gpuimage.filter.GPUImageToonFilter;
/**
* The threshold at which to apply the edges, default of 0.2.
@@ -28,33 +29,46 @@ import jp.co.cyberagent.android.gpuimage.GPUImageToonFilter;
*/
public class ToonFilterTransformation extends GPUFilterTransformation {
private float mThreshold;
private float mQuantizationLevels;
private static final int VERSION = 1;
private static final String ID =
"jp.wasabeef.glide.transformations.gpu.ToonFilterTransformation." + VERSION;
public ToonFilterTransformation(Context context) {
this(context, Glide.get(context).getBitmapPool());
private final float threshold;
private final float quantizationLevels;
public ToonFilterTransformation() {
this(.2f, 10.0f);
}
public ToonFilterTransformation(Context context, BitmapPool pool) {
this(context, pool, .2f, 10.0f);
}
public ToonFilterTransformation(Context context, float threshold, float quantizationLevels) {
this(context, Glide.get(context).getBitmapPool(), threshold, quantizationLevels);
}
public ToonFilterTransformation(Context context, BitmapPool pool, float threshold,
float quantizationLevels) {
super(context, pool, new GPUImageToonFilter());
mThreshold = threshold;
mQuantizationLevels = quantizationLevels;
public ToonFilterTransformation(float threshold, float quantizationLevels) {
super(new GPUImageToonFilter());
this.threshold = threshold;
this.quantizationLevels = quantizationLevels;
GPUImageToonFilter filter = getFilter();
filter.setThreshold(mThreshold);
filter.setQuantizationLevels(mQuantizationLevels);
filter.setThreshold(this.threshold);
filter.setQuantizationLevels(this.quantizationLevels);
}
@Override public String getId() {
return "ToonFilterTransformation(threshold=" + mThreshold +
",quantizationLevels=" + mQuantizationLevels + ")";
@Override
public String toString() {
return "ToonFilterTransformation(threshold=" + threshold + ",quantizationLevels="
+ quantizationLevels + ")";
}
@Override
public boolean equals(Object o) {
return o instanceof ToonFilterTransformation &&
((ToonFilterTransformation) o).threshold == threshold &&
((ToonFilterTransformation) o).quantizationLevels == quantizationLevels;
}
@Override
public int hashCode() {
return ID.hashCode() + (int) (threshold * 1000) + (int) (quantizationLevels * 10);
}
@Override
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
messageDigest.update((ID + threshold + quantizationLevels).getBytes(CHARSET));
}
}

View 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,12 +16,14 @@ package jp.wasabeef.glide.transformations.gpu;
* limitations under the License.
*/
import android.content.Context;
import android.graphics.PointF;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import androidx.annotation.NonNull;
import java.security.MessageDigest;
import java.util.Arrays;
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
@@ -30,41 +32,55 @@ import jp.co.cyberagent.android.gpuimage.GPUImageVignetteFilter;
*/
public class VignetteFilterTransformation extends GPUFilterTransformation {
private PointF mCenter;
private float[] mVignetteColor;
private float mVignetteStart;
private float mVignetteEnd;
private static final int VERSION = 1;
private static final String ID =
"jp.wasabeef.glide.transformations.gpu.VignetteFilterTransformation." + VERSION;
public VignetteFilterTransformation(Context context) {
this(context, Glide.get(context).getBitmapPool());
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) {
this(context, pool, new PointF(0.5f, 0.5f), new float[] { 0.0f, 0.0f, 0.0f }, 0.0f, 0.75f);
}
public VignetteFilterTransformation(Context context, PointF center, float[] color, float start,
float end) {
this(context, Glide.get(context).getBitmapPool(), center, color, start, end);
}
public VignetteFilterTransformation(Context context, BitmapPool pool, PointF center,
float[] color, float start, float end) {
super(context, pool, new GPUImageVignetteFilter());
mCenter = center;
mVignetteColor = color;
mVignetteStart = start;
mVignetteEnd = end;
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(mCenter);
filter.setVignetteColor(mVignetteColor);
filter.setVignetteStart(mVignetteStart);
filter.setVignetteEnd(mVignetteEnd);
filter.setVignetteCenter(this.center);
filter.setVignetteColor(vignetteColor);
filter.setVignetteStart(vignetteStart);
filter.setVignetteEnd(vignetteEnd);
}
@Override public String getId() {
return "VignetteFilterTransformation(center=" + mCenter.toString() +
",color=" + Arrays.toString(mVignetteColor) +
",start=" + mVignetteStart + ",end=" + mVignetteEnd + ")";
@Override
public String toString() {
return "VignetteFilterTransformation(center=" + center.toString() + ",color=" + Arrays.toString(
vignetteColor) + ",start=" + vignetteStart + ",end=" + vignetteEnd + ")";
}
@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;
}
@Override
public int hashCode() {
return ID.hashCode() + center.hashCode() + Arrays.hashCode(vignetteColor) +
(int) (vignetteStart * 100) + (int) (vignetteEnd * 10);
}
@Override
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
messageDigest.update((ID + center + Arrays.hashCode(vignetteColor) + vignetteStart + vignetteEnd).getBytes(CHARSET));
}
}

View File

@@ -3,14 +3,14 @@ package jp.wasabeef.glide.transformations.internal;
import android.graphics.Bitmap;
/**
* 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.
@@ -20,7 +20,7 @@ import android.graphics.Bitmap;
public class FastBlur {
public static Bitmap doBlur(Bitmap sentBitmap, int radius, boolean canReuseInBitmap) {
public static Bitmap blur(Bitmap sentBitmap, int radius, boolean canReuseInBitmap) {
// Stack Blur v1.0 from
// http://www.quasimondo.com/StackBlurForCanvas/StackBlurDemo.html
@@ -72,15 +72,15 @@ public class FastBlur {
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[] 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[] vmin = new int[Math.max(w, h)];
int divsum = (div + 1) >> 1;
divsum *= divsum;
int dv[] = new int[256 * divsum];
int[] dv = new int[256 * divsum];
for (i = 0; i < 256 * divsum; i++) {
dv[i] = (i / divsum);
}
@@ -254,4 +254,4 @@ public class FastBlur {
return (bitmap);
}
}
}

View File

@@ -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;
}
}

View File

@@ -1,18 +1,19 @@
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) 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.
@@ -26,18 +27,7 @@ public final class Utils {
// Utility class.
}
public static Drawable getMaskDrawable(Context context, int maskId) {
Drawable drawable;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
drawable = context.getDrawable(maskId);
} else {
drawable = context.getResources().getDrawable(maskId);
}
if (drawable == null) {
throw new IllegalArgumentException("maskId is invalid");
}
return drawable;
public static int toDp(int px) {
return px * (int) Resources.getSystem().getDisplayMetrics().density;
}
}