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

49 Commits
1.2.1 ... 2.0.2

Author SHA1 Message Date
Daichi Furiya
2a720df48d Update README.md 2017-03-17 17:47:58 -07:00
wasabeef
06db3295a1 updated art 2017-03-17 17:45:28 -07:00
Daichi Furiya
34cc92f7a4 Merge pull request #66 from wasabeef/dev
2.0.2
2017-03-17 17:41:49 -07:00
wasabeef
5715d7a999 bump up 2.0.2 2017-03-17 17:35:48 -07:00
wasabeef
36c0d00ae9 updated libs 2017-03-17 17:35:29 -07:00
wasabeef
a29346e8d2 updated sdks 2017-03-17 17:20:28 -07:00
wasabeef
c3f2ce75a4 updated gradle 2017-03-17 17:19:53 -07:00
wasabeef
4d47793f79 updated copyright 2017-03-17 17:17:37 -07:00
Daichi Furiya
45c2e3bcfe Merge pull request #45 from timusus/master
Additional resource cleanup in RSBlur
2017-03-17 15:27:20 -07:00
Tim Malseed
a139c21d31 Additional resource cleanup in RSBlur
When the blur is finished, the input, output, and blur are all destroyed, along with the renderscript instance.

This resolves a strictmode 'resource acquired but never released' violation.
2016-06-12 23:55:52 +10:00
Daichi Furiya
c3f09cdd0d Merge pull request #38 from wasabeef/v2.0.1
V2.0.1
2016-04-21 15:29:01 +09:00
wasabeef
ddd76d4f06 fix layout 2016-04-21 15:27:26 +09:00
wasabeef
f9bca8887d fix bugs issue #35 2016-04-21 15:23:22 +09:00
wasabeef
592815a6a0 update gradle 2016-04-21 15:22:58 +09:00
wasabeef
f6540b111f bump up 2.0.1 2016-04-21 15:22:46 +09:00
wasabeef
9bea464afc format 2016-04-21 15:22:21 +09:00
wasabeef
219b32bbcc format 2016-04-21 15:18:48 +09:00
Daichi Furiya
4d7190847c Merge pull request #36 from elevenfive/patch-1
Use correct field prefix
2016-04-19 13:05:36 +09:00
Matthew Zavislak
0d7a93c264 Use correct field prefix 2016-04-15 20:19:29 -07:00
Daichi Furiya
e69f775ddd Update build.gradle 2016-03-02 23:12:39 +09:00
Daichi Furiya
4b9cf87770 Update gradle-wrapper.properties 2016-03-02 23:11:59 +09:00
Daichi Furiya
cafad91b0b Update gradle-wrapper.properties 2016-03-02 23:11:43 +09:00
Daichi Furiya
933c3f7989 Merge pull request #31 from wasabeef/goodbye-v8rs
Goodbye v8.RenderScript
2016-03-02 23:11:05 +09:00
wasabeef
68bafb0f53 bump up 2.0.0 2016-03-02 23:09:31 +09:00
wasabeef
817b138980 Say v8.RenderScript goodbye 2016-03-02 22:53:34 +09:00
wasabeef
a908abc7d4 bump up 1.4.0 2016-02-28 04:58:55 +09:00
Daichi Furiya
3e0738de0a Update README.md 2016-01-31 02:57:09 +09:00
Daichi Furiya
dff7328f6e Update README.md 2015-12-11 17:50:07 +09:00
Daichi Furiya
f5cb7392d6 Update CHANGELOG.md 2015-11-27 17:56:25 +09:00
wasabeef
d8a12b02b8 bump up 1.3.1 2015-11-27 17:50:00 +09:00
wasabeef
a6a2b625ad fix leak code 2015-11-27 17:44:35 +09:00
wasabeef
f488f09b19 Merge branch 'master' of github.com:wasabeef/glide-transformations 2015-11-27 17:42:30 +09:00
Daichi Furiya
76b7e3b719 Merge pull request #25 from AAkira/fix/leak-context
Fix memory leak at BlurTransformation.
2015-11-27 17:41:57 +09:00
A.Akira
c29df80ae9 Use application context. 2015-11-27 17:38:06 +09:00
wasabeef
aef7541ea3 fix leak code and constractor 2015-11-27 17:11:58 +09:00
wasabeef
71255edcd0 Change the renderscriptTargetApi down to 20 2015-11-27 17:03:55 +09:00
wasabeef
4a268b6dbd refactor gpu transformations 2015-11-27 17:00:01 +09:00
A.Akira
eef0be6b92 Add null checking the context. 2015-11-26 10:22:18 +09:00
A.Akira
260f91e291 Use WeakReference. 2015-11-25 17:09:05 +09:00
Daichi Furiya
36ceccb38e Update README.md 2015-11-10 15:17:55 +09:00
Daichi Furiya
e3a035d5cb Update CHANGELOG.md 2015-11-10 15:17:42 +09:00
wasabeef
656ea50911 bump up 1.3.0 2015-11-10 15:10:18 +09:00
wasabeef
e2cf4fd7eb update sample 2015-11-10 15:03:58 +09:00
wasabeef
e387df2daa format 2015-11-10 15:03:49 +09:00
wasabeef
5b311f74f6 update gradle 2015-11-10 12:42:46 +09:00
Daichi Furiya
62f3ee6b4a Merge pull request #23 from kaelaela/feature/upgrade_rounded_transformation
Add round corner type
2015-11-10 12:40:38 +09:00
kaelaela
3150b4c8d5 Add round corner type 2015-10-04 15:57:46 +09:00
Daichi Furiya
410d94b7b1 Update README.md 2015-09-20 01:47:23 +09:00
Daichi Furiya
a559d8bea8 Update README.md 2015-09-20 00:53:23 +09:00
39 changed files with 798 additions and 630 deletions

View File

@@ -1,6 +1,50 @@
Change Log
==========
Version 2.0.2 *(2017-03-17)*
----------------------------
Update:
- Compile & Target SDK Version 23 -> 25
- Build Tools 23.0.2 -> 25.0.2
- Support Library 23.2.1 -> 25.3.0
- GPUImage for Android 1.3.0 -> 1.4.1
Bug Fix:
- [Additional resource cleanup in RSBlur #45](https://github.com/wasabeef/glide-transformations/pull/45)
Version 2.0.1 *(2016-04-21)*
----------------------------
Fix:
[#35](https://github.com/wasabeef/glide-transformations/issues/35)
RSInvalidStateException
Version 2.0.0 *(2016-03-02)*
----------------------------
Say v8.RenderScript goodbye
Version 1.4.0 *(2016-02-28)*
----------------------------
fix Issue [#29](https://github.com/wasabeef/glide-transformations/issues/29)
Use FastBlur as a fallback upon RenderScript failure.
Version 1.3.1 *(2015-11-27)*
----------------------------
Change the renderscriptTargetApi down to 20.
Warning:Renderscript support mode is not currently supported with renderscript target 21+
fix: memory leak.
Version 1.3.0 *(2015-11-10)*
----------------------------
add round corner type to RoundedCornersTransformation.
Thanks to [kaelaela](https://github.com/kaelaela)
Version 1.2.1 *(2015-09-18)*
----------------------------

View File

@@ -9,8 +9,9 @@ An Android transformation library providing a variety of image transformations f
Please feel free to use this.
#### Are you using Picasso?
[Picasso Transformations](https://github.com/wasabeef/picasso-transformations)
#### Are you using Picasso or Fresco?
[Picasso Transformations](https://github.com/wasabeef/picasso-transformations)
[Fresco Processors](https://github.com/wasabeef/fresco-processors)
# Demo
@@ -28,13 +29,12 @@ Please feel free to use this.
```groovy
repositories {
jcenter()
mavenCentral() // GPUImage for Android
}
dependencies {
compile 'jp.wasabeef:glide-transformations:1.2.1'
compile 'jp.wasabeef:glide-transformations:2.0.2'
// If you want to use the GPU Filters
compile 'jp.co.cyberagent.android.gpuimage:gpuimage-library:1.3.0'
compile 'jp.co.cyberagent.android.gpuimage:gpuimage-library:1.4.1'
}
```
@@ -54,25 +54,10 @@ You can set a multiple transformations.
```java
Glide.with(this).load(R.drawable.demo)
.bitmapTransform(new BlurTransformation(context, 25, 2), new CropCircleTransformation(context))
.bitmapTransform(new BlurTransformation(context, 25), new CropCircleTransformation(context))
.into((ImageView) findViewById(R.id.image));
```
## Step 4
If you are using `BlurTransformation`.
```groovy
android {
...
defaultConfig {
...
renderscriptTargetApi 23
renderscriptSupportModeEnabled true
}
}
```
## Transformations
### Crop
@@ -93,7 +78,9 @@ android {
`ToonFilterTransformation`, `SepiaFilterTransformation`, `ContrastFilterTransformation`
`InvertFilterTransformation`, `PixelationFilterTransformation`, `SketchFilterTransformation`
`SwirlFilterTransformation`, `KuwaharaFilterTransformation`, `VignetteFilterTransformation`
`SwirlFilterTransformation`, `BrightnessFilterTransformation`, `KuwaharaFilterTransformation`
`VignetteFilterTransformation`
Applications using Glide Transformations
---
@@ -131,7 +118,7 @@ Thanks
License
-------
Copyright 2015 Wasabeef
Copyright 2017 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

@@ -5,11 +5,8 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.1'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.3.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.android.tools.build:gradle:2.3.0'
classpath 'com.novoda:bintray-release:0.3.4'
}
}

View File

@@ -1,60 +1,58 @@
apply plugin: 'com.android.application'
android {
compileSdkVersion COMPILE_SDK_VERSION as int
buildToolsVersion BUILD_TOOLS_VERSION
compileSdkVersion COMPILE_SDK_VERSION as int
buildToolsVersion BUILD_TOOLS_VERSION
defaultConfig {
minSdkVersion MIN_SDK_VERSION as int
targetSdkVersion TARGET_SDK_VERSION as int
versionCode VERSION_CODE as int
versionName VERSION_NAME
renderscriptTargetApi RENDERSCRIPT_TARGET_API as int
renderscriptSupportModeEnabled true
}
defaultConfig {
minSdkVersion MIN_SDK_VERSION as int
targetSdkVersion TARGET_SDK_VERSION as int
versionCode "git rev-list origin/master --count".execute().text.toInteger()
versionName VERSION_NAME
}
signingConfigs {
release {
storeFile file(keyStoreProperty)
keyAlias keyAliasProperty
storePassword keyStorePasswordProperty
keyPassword keyAliasPasswordProperty
}
signingConfigs {
release {
storeFile file(keyStoreProperty)
keyAlias keyAliasProperty
storePassword keyStorePasswordProperty
keyPassword keyAliasPasswordProperty
}
}
buildTypes {
debug {
debuggable true
zipAlignEnabled true
}
release {
debuggable false
zipAlignEnabled true
signingConfig signingConfigs.release
}
buildTypes {
debug {
debuggable true
zipAlignEnabled true
}
release {
debuggable false
zipAlignEnabled true
signingConfig signingConfigs.release
}
}
}
def getKeyStoreProperty() {
return hasProperty('WASABEEF_KEYSTORE') ? WASABEEF_KEYSTORE : "debug.keystore"
return hasProperty('WASABEEF_KEYSTORE') ? WASABEEF_KEYSTORE : "debug.keystore"
}
def getKeyAliasProperty() {
return hasProperty('WASABEEF_KEYALIAS') ? WASABEEF_KEYALIAS : "android"
return hasProperty('WASABEEF_KEYALIAS') ? WASABEEF_KEYALIAS : "android"
}
def getKeyStorePasswordProperty() {
return hasProperty('WASABEEF_KEYSTOREPASSWORD') ? WASABEEF_KEYSTOREPASSWORD : "androiddebugkey"
return hasProperty('WASABEEF_KEYSTOREPASSWORD') ? WASABEEF_KEYSTOREPASSWORD : "androiddebugkey"
}
def getKeyAliasPasswordProperty() {
return hasProperty('WASABEEF_KEYALIASPASSWORD') ? WASABEEF_KEYALIASPASSWORD : "android"
return hasProperty('WASABEEF_KEYALIASPASSWORD') ? WASABEEF_KEYALIASPASSWORD : "android"
}
dependencies {
compile project(':transformations')
compile "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}"
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}"
}

View File

@@ -145,13 +145,14 @@ public class MainAdapter extends RecyclerView.Adapter<MainAdapter.ViewHolder> {
case RoundedCorners:
Glide.with(mContext)
.load(R.drawable.demo)
.bitmapTransform(new RoundedCornersTransformation(mContext, 100, 0))
.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))
.bitmapTransform(new BlurTransformation(mContext, 25))
.into(holder.image);
break;
case Toon:

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.example.glide;
/**
* Copyright (C) 2015 Wasabeef
* Copyright (C) 2017 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
>

View File

@@ -1,12 +1,10 @@
VERSION_NAME=1.2.1
VERSION_CODE=11
VERSION_NAME=2.0.2
GROUP=jp.wasabeef
ARTIFACT_ID=glide-transformations
COMPILE_SDK_VERSION=23
BUILD_TOOLS_VERSION=23.0.1
TARGET_SDK_VERSION=23
RENDERSCRIPT_TARGET_API=23
COMPILE_SDK_VERSION=25
BUILD_TOOLS_VERSION=25.0.2
TARGET_SDK_VERSION=25
MIN_SDK_VERSION=11
POM_DESCRIPTION=which provides simple Tranformations to Glide
@@ -23,6 +21,6 @@ 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.0.1
GLIDE_VERSION=3.6.1
GPUIMAGE_VERSION=1.3.0
SUPPORT_PACKAGE_VERSION=25.3.0
GLIDE_VERSION=3.7.0
GPUIMAGE_VERSION=1.4.1

View File

@@ -1,6 +1,6 @@
#Wed Apr 10 15:27:10 PDT 2013
#Fri Mar 17 06:53:45 JST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip

View File

@@ -1,25 +0,0 @@
task androidJavadocs(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
ext.androidJar = "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar"
classpath += files(ext.androidJar)
}
task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
classifier = 'javadoc'
from androidJavadocs.destinationDir
}
task androidSourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.sourceFiles
}
task androidJar(type: Jar) {
from 'build/intermediates/classes/release'
}
artifacts {
archives androidSourcesJar
archives androidJavadocsJar
archives androidJar
}

View File

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

View File

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

View File

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

View File

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

View File

@@ -0,0 +1 @@
-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,7 +1,7 @@
package jp.wasabeef.glide.transformations;
/**
* Copyright (C) 2015 Wasabeef
* Copyright (C) 2017 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,15 +20,15 @@ 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.RenderScript;
import android.support.v8.renderscript.ScriptIntrinsicBlur;
import android.os.Build;
import android.renderscript.RSRuntimeException;
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 jp.wasabeef.glide.transformations.internal.FastBlur;
import jp.wasabeef.glide.transformations.internal.RSBlur;
public class BlurTransformation implements Transformation<Bitmap> {
@@ -57,16 +57,13 @@ public class BlurTransformation implements Transformation<Bitmap> {
this(context, Glide.get(context).getBitmapPool(), radius, DEFAULT_DOWN_SAMPLING);
}
public BlurTransformation(Context context, BitmapPool pool, int radius, int sampling) {
mContext = context;
mBitmapPool = pool;
mRadius = radius;
mSampling = sampling;
public BlurTransformation(Context context, int radius, int sampling) {
this(context, Glide.get(context).getBitmapPool(), radius, sampling);
}
public BlurTransformation(Context context, int radius, int sampling) {
mContext = context;
mBitmapPool = Glide.get(context).getBitmapPool();
public BlurTransformation(Context context, BitmapPool pool, int radius, int sampling) {
mContext = context.getApplicationContext();
mBitmapPool = pool;
mRadius = radius;
mSampling = sampling;
}
@@ -91,18 +88,15 @@ public class BlurTransformation implements Transformation<Bitmap> {
paint.setFlags(Paint.FILTER_BITMAP_FLAG);
canvas.drawBitmap(source, 0, 0, paint);
RenderScript 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);
rs.destroy();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
try {
bitmap = RSBlur.blur(mContext, bitmap, mRadius);
} catch (RSRuntimeException e) {
bitmap = FastBlur.blur(bitmap, mRadius, true);
}
} else {
bitmap = FastBlur.blur(bitmap, mRadius, true);
}
return BitmapResource.obtain(bitmap, mBitmapPool);
}

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations;
/**
* Copyright (C) 2015 Wasabeef
* Copyright (C) 2017 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations;
/**
* Copyright (C) 2015 Wasabeef
* Copyright (C) 2017 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations;
/**
* Copyright (C) 2015 Wasabeef
* Copyright (C) 2017 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations;
/**
* Copyright (C) 2015 Wasabeef
* Copyright (C) 2017 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations;
/**
* Copyright (C) 2015 Wasabeef
* Copyright (C) 2017 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations;
/**
* Copyright (C) 2015 Wasabeef
* Copyright (C) 2017 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -32,13 +32,13 @@ import jp.wasabeef.glide.transformations.internal.Utils;
public class MaskTransformation implements Transformation<Bitmap> {
private static Paint mMaskingPaint = new Paint();
private static Paint sMaskingPaint = new Paint();
private Context mContext;
private BitmapPool mBitmapPool;
private int mMaskId;
static {
mMaskingPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
sMaskingPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
}
/**
@@ -47,8 +47,12 @@ public class MaskTransformation implements Transformation<Bitmap> {
* same make file name. If you have a good idea please tell us, thanks.
*/
public MaskTransformation(Context context, int maskId) {
mBitmapPool = Glide.get(context).getBitmapPool();
mContext = context;
this(context, Glide.get(context).getBitmapPool(), maskId);
}
public MaskTransformation(Context context, BitmapPool pool, int maskId) {
mBitmapPool = pool;
mContext = context.getApplicationContext();
mMaskId = maskId;
}
@@ -69,7 +73,7 @@ public class MaskTransformation implements Transformation<Bitmap> {
Canvas canvas = new Canvas(result);
mask.setBounds(0, 0, width, height);
mask.draw(canvas);
canvas.drawBitmap(source, 0, 0, mMaskingPaint);
canvas.drawBitmap(source, 0, 0, sMaskingPaint);
return BitmapResource.obtain(result, mBitmapPool);
}

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations;
/**
* Copyright (C) 2015 Wasabeef
* Copyright (C) 2017 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,19 +31,40 @@ import com.bumptech.glide.load.resource.bitmap.BitmapResource;
public class RoundedCornersTransformation implements Transformation<Bitmap> {
private BitmapPool mBitmapPool;
public enum CornerType {
ALL,
TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT,
TOP, BOTTOM, LEFT, RIGHT,
OTHER_TOP_LEFT, OTHER_TOP_RIGHT, OTHER_BOTTOM_LEFT, OTHER_BOTTOM_RIGHT,
DIAGONAL_FROM_TOP_LEFT, DIAGONAL_FROM_TOP_RIGHT
}
private int radius;
private int margin;
private BitmapPool mBitmapPool;
private int mRadius;
private int mDiameter;
private int mMargin;
private CornerType mCornerType;
public RoundedCornersTransformation(Context context, int radius, int margin) {
this(Glide.get(context).getBitmapPool(), radius, margin);
this(context, 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;
this.radius = radius;
this.margin = margin;
mRadius = radius;
mDiameter = mRadius * 2;
mMargin = margin;
mCornerType = cornerType;
}
@Override
@@ -62,13 +83,173 @@ public class RoundedCornersTransformation implements Transformation<Bitmap> {
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
canvas.drawRoundRect(new RectF(margin, margin, width - margin, height - margin), radius, radius,
paint);
drawRoundRect(canvas, paint, width, height);
return BitmapResource.obtain(bitmap, mBitmapPool);
}
private void drawRoundRect(Canvas canvas, Paint paint, float width, float height) {
float right = width - mMargin;
float bottom = height - mMargin;
switch (mCornerType) {
case ALL:
canvas.drawRoundRect(new RectF(mMargin, mMargin, right, bottom), mRadius, mRadius, paint);
break;
case TOP_LEFT:
drawTopLeftRoundRect(canvas, paint, right, bottom);
break;
case TOP_RIGHT:
drawTopRightRoundRect(canvas, paint, right, bottom);
break;
case BOTTOM_LEFT:
drawBottomLeftRoundRect(canvas, paint, right, bottom);
break;
case BOTTOM_RIGHT:
drawBottomRightRoundRect(canvas, paint, right, bottom);
break;
case TOP:
drawTopRoundRect(canvas, paint, right, bottom);
break;
case BOTTOM:
drawBottomRoundRect(canvas, paint, right, bottom);
break;
case LEFT:
drawLeftRoundRect(canvas, paint, right, bottom);
break;
case RIGHT:
drawRightRoundRect(canvas, paint, right, bottom);
break;
case OTHER_TOP_LEFT:
drawOtherTopLeftRoundRect(canvas, paint, right, bottom);
break;
case OTHER_TOP_RIGHT:
drawOtherTopRightRoundRect(canvas, paint, right, bottom);
break;
case OTHER_BOTTOM_LEFT:
drawOtherBottomLeftRoundRect(canvas, paint, right, bottom);
break;
case OTHER_BOTTOM_RIGHT:
drawOtherBottomRightRoundRect(canvas, paint, right, bottom);
break;
case DIAGONAL_FROM_TOP_LEFT:
drawDiagonalFromTopLeftRoundRect(canvas, paint, right, bottom);
break;
case DIAGONAL_FROM_TOP_RIGHT:
drawDiagonalFromTopRightRoundRect(canvas, paint, right, bottom);
break;
default:
canvas.drawRoundRect(new RectF(mMargin, mMargin, right, bottom), mRadius, mRadius, 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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
@Override public String getId() {
return "RoundedTransformation(radius=" + radius + ", margin=" + margin + ")";
return "RoundedTransformation(radius=" + mRadius + ", margin=" + mMargin + ", diameter="
+ mDiameter + ", cornerType=" + mCornerType.name() + ")";
}
}

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations.gpu;
/**
* Copyright (C) 2015 Wasabeef
* Copyright (C) 2017 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,24 +17,15 @@ 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 com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
import jp.co.cyberagent.android.gpuimage.GPUImage;
import jp.co.cyberagent.android.gpuimage.GPUImageBrightnessFilter;
/**
* brightness value ranges from -1.0 to 1.0, with 0.0 as the normal level
*/
public class BrightnessFilterTransformation implements Transformation<Bitmap> {
public class BrightnessFilterTransformation extends GPUFilterTransformation {
private Context mContext;
private BitmapPool mBitmapPool;
private GPUImageBrightnessFilter mFilter = new GPUImageBrightnessFilter();
private float mBrightness;
public BrightnessFilterTransformation(Context context) {
@@ -50,24 +41,10 @@ public class BrightnessFilterTransformation implements Transformation<Bitmap> {
}
public BrightnessFilterTransformation(Context context, BitmapPool pool, float brightness) {
mContext = context;
mBitmapPool = pool;
super(context, pool, new GPUImageBrightnessFilter());
mBrightness = brightness;
mFilter.setBrightness(mBrightness);
}
@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);
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
source.recycle();
return BitmapResource.obtain(bitmap, mBitmapPool);
GPUImageBrightnessFilter filter = getFilter();
filter.setBrightness(mBrightness);
}
@Override public String getId() {

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations.gpu;
/**
* Copyright (C) 2015 Wasabeef
* Copyright (C) 2017 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,24 +17,15 @@ 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 com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
import jp.co.cyberagent.android.gpuimage.GPUImage;
import jp.co.cyberagent.android.gpuimage.GPUImageContrastFilter;
/**
* contrast value ranges from 0.0 to 4.0, with 1.0 as the normal level
*/
public class ContrastFilterTransformation implements Transformation<Bitmap> {
public class ContrastFilterTransformation extends GPUFilterTransformation {
private Context mContext;
private BitmapPool mBitmapPool;
private GPUImageContrastFilter mFilter = new GPUImageContrastFilter();
private float mContrast;
public ContrastFilterTransformation(Context context) {
@@ -50,24 +41,10 @@ public class ContrastFilterTransformation implements Transformation<Bitmap> {
}
public ContrastFilterTransformation(Context context, BitmapPool pool, float contrast) {
mContext = context;
mBitmapPool = pool;
super(context, pool, new GPUImageContrastFilter());
mContrast = contrast;
mFilter.setContrast(mContrast);
}
@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);
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
source.recycle();
return BitmapResource.obtain(bitmap, mBitmapPool);
GPUImageContrastFilter filter = getFilter();
filter.setContrast(mContrast);
}
@Override public String getId() {

View File

@@ -0,0 +1,65 @@
package jp.wasabeef.glide.transformations.gpu;
/**
* Copyright (C) 2017 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import android.content.Context;
import android.graphics.Bitmap;
import 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 jp.co.cyberagent.android.gpuimage.GPUImage;
import jp.co.cyberagent.android.gpuimage.GPUImageFilter;
public class GPUFilterTransformation implements Transformation<Bitmap> {
private Context mContext;
private BitmapPool mBitmapPool;
private GPUImageFilter mFilter;
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;
}
@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);
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
return BitmapResource.obtain(bitmap, mBitmapPool);
}
@Override public String getId() {
return getClass().getSimpleName();
}
@SuppressWarnings("unchecked") public <T> T getFilter() {
return (T) mFilter;
}
}

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations.gpu;
/**
* Copyright (C) 2015 Wasabeef
* Copyright (C) 2017 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,44 +17,21 @@ 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 com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
import jp.co.cyberagent.android.gpuimage.GPUImage;
import jp.co.cyberagent.android.gpuimage.GPUImageColorInvertFilter;
/**
* Invert all the colors in the image.
*/
public class InvertFilterTransformation implements Transformation<Bitmap> {
private Context mContext;
private BitmapPool mBitmapPool;
public class InvertFilterTransformation extends GPUFilterTransformation {
public InvertFilterTransformation(Context context) {
this(context, Glide.get(context).getBitmapPool());
}
public InvertFilterTransformation(Context context, BitmapPool pool) {
mContext = context;
mBitmapPool = pool;
}
@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(new GPUImageColorInvertFilter());
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
source.recycle();
return BitmapResource.obtain(bitmap, mBitmapPool);
super(context, pool, new GPUImageColorInvertFilter());
}
@Override public String getId() {

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations.gpu;
/**
* Copyright (C) 2015 Wasabeef
* Copyright (C) 2017 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,13 +17,8 @@ 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 com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
import jp.co.cyberagent.android.gpuimage.GPUImage;
import jp.co.cyberagent.android.gpuimage.GPUImageKuwaharaFilter;
/**
@@ -32,12 +27,8 @@ import jp.co.cyberagent.android.gpuimage.GPUImageKuwaharaFilter;
* The radius to sample from when creating the brush-stroke effect, with a default of 25.
* The larger the radius, the slower the filter.
*/
public class KuwaharaFilterTransformation implements Transformation<Bitmap> {
public class KuwaharaFilterTransformation extends GPUFilterTransformation {
private Context mContext;
private BitmapPool mBitmapPool;
private GPUImageKuwaharaFilter mFilter = new GPUImageKuwaharaFilter();
private int mRadius;
public KuwaharaFilterTransformation(Context context) {
@@ -53,24 +44,10 @@ public class KuwaharaFilterTransformation implements Transformation<Bitmap> {
}
public KuwaharaFilterTransformation(Context context, BitmapPool pool, int radius) {
mContext = context;
mBitmapPool = pool;
super(context, pool, new GPUImageKuwaharaFilter());
mRadius = radius;
mFilter.setRadius(mRadius);
}
@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);
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
source.recycle();
return BitmapResource.obtain(bitmap, mBitmapPool);
GPUImageKuwaharaFilter filter = getFilter();
filter.setRadius(mRadius);
}
@Override public String getId() {

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations.gpu;
/**
* Copyright (C) 2015 Wasabeef
* Copyright (C) 2017 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,13 +17,8 @@ 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 com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
import jp.co.cyberagent.android.gpuimage.GPUImage;
import jp.co.cyberagent.android.gpuimage.GPUImagePixelationFilter;
/**
@@ -31,12 +26,8 @@ import jp.co.cyberagent.android.gpuimage.GPUImagePixelationFilter;
*
* The pixel with a default of 10.0.
*/
public class PixelationFilterTransformation implements Transformation<Bitmap> {
public class PixelationFilterTransformation extends GPUFilterTransformation {
private Context mContext;
private BitmapPool mBitmapPool;
private GPUImagePixelationFilter mFilter = new GPUImagePixelationFilter();
private float mPixel;
public PixelationFilterTransformation(Context context) {
@@ -52,24 +43,10 @@ public class PixelationFilterTransformation implements Transformation<Bitmap> {
}
public PixelationFilterTransformation(Context context, BitmapPool pool, float pixel) {
mContext = context;
mBitmapPool = pool;
super(context, pool, new GPUImagePixelationFilter());
mPixel = pixel;
mFilter.setPixel(mPixel);
}
@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);
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
source.recycle();
return BitmapResource.obtain(bitmap, mBitmapPool);
GPUImagePixelationFilter filter = getFilter();
filter.setPixel(mPixel);
}
@Override public String getId() {

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations.gpu;
/**
* Copyright (C) 2015 Wasabeef
* Copyright (C) 2017 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,13 +17,8 @@ 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 com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
import jp.co.cyberagent.android.gpuimage.GPUImage;
import jp.co.cyberagent.android.gpuimage.GPUImageSepiaFilter;
/**
@@ -31,12 +26,8 @@ import jp.co.cyberagent.android.gpuimage.GPUImageSepiaFilter;
*
* The intensity with a default of 1.0.
*/
public class SepiaFilterTransformation implements Transformation<Bitmap> {
public class SepiaFilterTransformation extends GPUFilterTransformation {
private Context mContext;
private BitmapPool mBitmapPool;
private GPUImageSepiaFilter mFilter = new GPUImageSepiaFilter();
private float mIntensity;
public SepiaFilterTransformation(Context context) {
@@ -52,24 +43,10 @@ public class SepiaFilterTransformation implements Transformation<Bitmap> {
}
public SepiaFilterTransformation(Context context, BitmapPool pool, float intensity) {
mContext = context;
mBitmapPool = pool;
super(context, pool, new GPUImageSepiaFilter());
mIntensity = intensity;
mFilter.setIntensity(mIntensity);
}
@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);
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
source.recycle();
return BitmapResource.obtain(bitmap, mBitmapPool);
GPUImageSepiaFilter filter = getFilter();
filter.setIntensity(mIntensity);
}
@Override public String getId() {

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations.gpu;
/**
* Copyright (C) 2015 Wasabeef
* Copyright (C) 2017 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,41 +17,18 @@ 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 com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
import jp.co.cyberagent.android.gpuimage.GPUImage;
import jp.co.cyberagent.android.gpuimage.GPUImageSketchFilter;
public class SketchFilterTransformation implements Transformation<Bitmap> {
private Context mContext;
private BitmapPool mBitmapPool;
public class SketchFilterTransformation extends GPUFilterTransformation {
public SketchFilterTransformation(Context context) {
this(context, Glide.get(context).getBitmapPool());
}
public SketchFilterTransformation(Context context, BitmapPool pool) {
mContext = context;
mBitmapPool = pool;
}
@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(new GPUImageSketchFilter());
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
source.recycle();
return BitmapResource.obtain(bitmap, mBitmapPool);
super(context, pool, new GPUImageSketchFilter());
}
@Override public String getId() {

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations.gpu;
/**
* Copyright (C) 2015 Wasabeef
* Copyright (C) 2017 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,25 +17,16 @@ package jp.wasabeef.glide.transformations.gpu;
*/
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.PointF;
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 jp.co.cyberagent.android.gpuimage.GPUImage;
import jp.co.cyberagent.android.gpuimage.GPUImageSwirlFilter;
/**
* Creates a swirl distortion on the image.
*/
public class SwirlFilterTransformation implements Transformation<Bitmap> {
public class SwirlFilterTransformation extends GPUFilterTransformation {
private Context mContext;
private BitmapPool mBitmapPool;
private GPUImageSwirlFilter mFilter = new GPUImageSwirlFilter();
private float mRadius;
private float mAngle;
private PointF mCenter;
@@ -59,28 +50,14 @@ public class SwirlFilterTransformation implements Transformation<Bitmap> {
*/
public SwirlFilterTransformation(Context context, BitmapPool pool, float radius, float angle,
PointF center) {
mContext = context;
mBitmapPool = pool;
super(context, pool, new GPUImageSwirlFilter());
mRadius = radius;
mAngle = angle;
mCenter = center;
mFilter.setRadius(mRadius);
mFilter.setAngle(mAngle);
mFilter.setCenter(mCenter);
}
@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);
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
source.recycle();
return BitmapResource.obtain(bitmap, mBitmapPool);
GPUImageSwirlFilter filter = getFilter();
filter.setRadius(mRadius);
filter.setAngle(mAngle);
filter.setCenter(mCenter);
}
@Override public String getId() {

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations.gpu;
/**
* Copyright (C) 2015 Wasabeef
* Copyright (C) 2017 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,13 +17,8 @@ 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 com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
import jp.co.cyberagent.android.gpuimage.GPUImage;
import jp.co.cyberagent.android.gpuimage.GPUImageToonFilter;
/**
@@ -31,12 +26,8 @@ import jp.co.cyberagent.android.gpuimage.GPUImageToonFilter;
* The levels of quantization for the posterization of colors within the scene,
* with a default of 10.0.
*/
public class ToonFilterTransformation implements Transformation<Bitmap> {
public class ToonFilterTransformation extends GPUFilterTransformation {
private Context mContext;
private BitmapPool mBitmapPool;
private GPUImageToonFilter mFilter = new GPUImageToonFilter();
private float mThreshold;
private float mQuantizationLevels;
@@ -54,26 +45,12 @@ public class ToonFilterTransformation implements Transformation<Bitmap> {
public ToonFilterTransformation(Context context, BitmapPool pool, float threshold,
float quantizationLevels) {
mContext = context;
mBitmapPool = pool;
super(context, pool, new GPUImageToonFilter());
mThreshold = threshold;
mQuantizationLevels = quantizationLevels;
mFilter.setThreshold(mThreshold);
mFilter.setQuantizationLevels(mQuantizationLevels);
}
@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);
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
source.recycle();
return BitmapResource.obtain(bitmap, mBitmapPool);
GPUImageToonFilter filter = getFilter();
filter.setThreshold(mThreshold);
filter.setQuantizationLevels(mQuantizationLevels);
}
@Override public String getId() {

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations.gpu;
/**
* Copyright (C) 2015 Wasabeef
* Copyright (C) 2017 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,15 +17,10 @@ package jp.wasabeef.glide.transformations.gpu;
*/
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.PointF;
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 java.util.Arrays;
import jp.co.cyberagent.android.gpuimage.GPUImage;
import jp.co.cyberagent.android.gpuimage.GPUImageVignetteFilter;
/**
@@ -33,12 +28,8 @@ import jp.co.cyberagent.android.gpuimage.GPUImageVignetteFilter;
* The directional intensity of the vignetting,
* with a default of x = 0.5, y = 0.5, start = 0, end = 0.75
*/
public class VignetteFilterTransformation implements Transformation<Bitmap> {
public class VignetteFilterTransformation extends GPUFilterTransformation {
private Context mContext;
private BitmapPool mBitmapPool;
private GPUImageVignetteFilter mFilter = new GPUImageVignetteFilter();
private PointF mCenter;
private float[] mVignetteColor;
private float mVignetteStart;
@@ -59,30 +50,16 @@ public class VignetteFilterTransformation implements Transformation<Bitmap> {
public VignetteFilterTransformation(Context context, BitmapPool pool, PointF center,
float[] color, float start, float end) {
mContext = context;
mBitmapPool = pool;
super(context, pool, new GPUImageVignetteFilter());
mCenter = center;
mVignetteColor = color;
mVignetteStart = start;
mVignetteEnd = end;
mFilter.setVignetteCenter(mCenter);
mFilter.setVignetteColor(mVignetteColor);
mFilter.setVignetteStart(mVignetteStart);
mFilter.setVignetteEnd(mVignetteEnd);
}
@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);
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
source.recycle();
return BitmapResource.obtain(bitmap, mBitmapPool);
GPUImageVignetteFilter filter = getFilter();
filter.setVignetteCenter(mCenter);
filter.setVignetteColor(mVignetteColor);
filter.setVignetteStart(mVignetteStart);
filter.setVignetteEnd(mVignetteEnd);
}
@Override public String getId() {

View File

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

View File

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

View File

@@ -5,7 +5,7 @@ import android.graphics.drawable.Drawable;
import android.os.Build;
/**
* Copyright (C) 2015 Wasabeef
* Copyright (C) 2017 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.