1
0
mirror of https://github.com/wasabeef/glide-transformations.git synced 2025-06-13 02:54:05 +08:00

[WIP] Migrate to AndroidX (#141)

Migrate to AndroidX
This commit is contained in:
Daichi Furiya 2018-11-16 16:19:42 +09:00 committed by GitHub
parent 4818373fc5
commit 3aa8e53c6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
46 changed files with 831 additions and 671 deletions

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

61
.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,38 @@ 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*
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

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,13 @@
Change Log
==========
Version 4.0.0 *(2018-11-16)*
----------------------------
Update:
- Migrate to AndroidX
- Remove novoda-bintray-plugin
Version 3.3.0 *(2018-04-23)*
----------------------------

View File

@ -28,13 +28,13 @@ Please feel free to use this.
#### Gradle
```groovy
repositories {
jcenter()
jcenter()
}
dependencies {
implementation 'jp.wasabeef:glide-transformations:3.3.0'
// If you want to use the GPU Filters
implementation 'jp.co.cyberagent.android.gpuimage:gpuimage-library:1.4.1'
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'
}
```
@ -42,23 +42,23 @@ dependencies {
Set Glide Transform.
```java
```kotlin
Glide.with(this).load(R.drawable.demo)
.apply(bitmapTransform(new BlurTransformation(25, 3)))
.into((ImageView) findViewById(R.id.image));
.apply(bitmapTransform(BlurTransformation(25, 3)))
.into(imageView)
```
## Advanced Step 3
You can set a multiple transformations.
```java
MultiTransformation multi = new MultiTransformation(
new BlurTransformation(25),
new RoundedCornersTransformation(128, 0, RoundedCornersTransformation.CornerType.BOTTOM))))
```kotlin
val multi = MultiTransformation<Bitmap>(
BlurTransformation(25),
RoundedCornersTransformation(128, 0, CornerType.BOTTOM))))
Glide.with(this).load(R.drawable.demo)
.apply(bitmapTransform(multi))
.into((ImageView) findViewById(R.id.image));
.into(imageView))
```
# Step 4
@ -67,12 +67,12 @@ If you are using `SupportRSBlurTransformation`.
```groovy
android {
...
defaultConfig {
...
renderscriptTargetApi YOUR_TARGET_SDK_VERSION as int
renderscriptSupportModeEnabled true
}
//...
defaultConfig {
//...
renderscriptTargetApi YOUR_TARGET_SDK_VERSION as int
renderscriptSupportModeEnabled true
}
}
```

View File

@ -1,13 +1,21 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
kotlin_version = '1.3.0'
glide_version = '4.8.0'
gpuimage_version = '2.0.3'
}
repositories {
jcenter()
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.1'
classpath 'com.novoda:bintray-release:0.8.1'
classpath 'com.android.tools.build:gradle:3.4.0-alpha03'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
@ -15,6 +23,5 @@ allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}

View File

@ -1,8 +1,9 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion COMPILE_SDK_VERSION as int
buildToolsVersion BUILD_TOOLS_VERSION
defaultConfig {
minSdkVersion MIN_SDK_VERSION as int
@ -57,10 +58,11 @@ def getKeyAliasPasswordProperty() {
dependencies {
implementation project(':transformations')
implementation "com.github.bumptech.glide:glide:${GLIDE_VERSION}"
annotationProcessor "com.github.bumptech.glide:compiler:${GLIDE_VERSION}"
implementation "jp.co.cyberagent.android.gpuimage:gpuimage-library:${GPUIMAGE_VERSION}"
implementation "com.android.support:appcompat-v7:${SUPPORT_PACKAGE_VERSION}"
implementation "com.android.support:recyclerview-v7:${SUPPORT_PACKAGE_VERSION}"
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
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.0.2"
implementation "androidx.recyclerview:recyclerview:1.0.0"
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
}

View File

@ -1,6 +1,7 @@
<?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
@ -8,7 +9,7 @@
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"

View File

@ -1,4 +1,4 @@
package jp.wasabeef.example.glide;
package jp.wasabeef.example.glide
/**
* Copyright (C) 2018 Wasabeef
@ -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,46 +0,0 @@
package jp.wasabeef.example.glide;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import java.util.ArrayList;
import java.util.List;
import jp.wasabeef.example.glide.MainAdapter.Type;
public class MainActivity extends AppCompatActivity {
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.list);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
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.SupportRSBlur);
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, CropTop, CropCenter, CropBottom, CropSquare, CropCircle, Grayscale,
Blur, SupportRSBlur, Toon, Sepia, Contrast, Invert, Pixel, Sketch, Swirl, Brightness,
Kuawahara, Vignette
))
}
}
}

View File

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

View File

@ -0,0 +1,195 @@
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.*
/**
* 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,
ColorFilter,
Grayscale,
RoundedCorners,
Blur,
SupportRSBlur,
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]) {
MainAdapter.Type.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)
}
MainAdapter.Type.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)
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(45, 0,
RoundedCornersTransformation.CornerType.BOTTOM)))
.into(holder.image)
Blur -> Glide.with(context)
.load(R.drawable.check)
.apply(bitmapTransform(BlurTransformation(25)))
.into(holder.image)
SupportRSBlur -> Glide.with(context)
.load(R.drawable.check)
.apply(bitmapTransform(SupportRSBlurTransformation(25, 10)))
.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)
}
}

View File

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

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
<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"
@ -32,4 +32,4 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
/>
</android.support.constraint.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -1,26 +1,35 @@
VERSION_NAME=3.3.0
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=1024m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
org.gradle.parallel=true
org.gradle.daemon=true
org.gradle.configureondemand=true
org.gradle.caching=true
android.enableBuildCache=true
android.useAndroidX=true
android.enableJetifier=true
# Use R8 instead of ProGuard for code shrinking.
android.enableR8=true
android.enableR8.fullMode=true
# Enable rudimentary R class namespacing where each library only contains
# references to the resources it declares instead of declarations plus all
# transitive dependency references.
android.namespacedRClass=true
VERSION_NAME=4.0.0
GROUP=jp.wasabeef
ARTIFACT_ID=glide-transformations
COMPILE_SDK_VERSION=27
BUILD_TOOLS_VERSION=27.0.3
TARGET_SDK_VERSION=27
MIN_SDK_VERSION=14
POM_DESCRIPTION=which provides simple Tranformations to Glide
POM_URL=https://github.com/wasabeef/glide-transformations
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=27.1.1
GLIDE_VERSION=4.7.1
GPUIMAGE_VERSION=1.4.1
COMPILE_SDK_VERSION=28
TARGET_SDK_VERSION=28
MIN_SDK_VERSION=14

Binary file not shown.

View File

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.0-milestone-1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-bin.zip

View File

@ -1,37 +1,39 @@
apply plugin: 'com.android.library'
apply plugin: 'com.novoda.bintray-release'
android {
compileSdkVersion COMPILE_SDK_VERSION as int
buildToolsVersion BUILD_TOOLS_VERSION
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
renderscriptTargetApi TARGET_SDK_VERSION as int
renderscriptSupportModeEnabled true
consumerProguardFiles 'proguard-rules.txt'
}
}
dependencies {
implementation "com.github.bumptech.glide:glide:${GLIDE_VERSION}"
annotationProcessor "com.github.bumptech.glide:compiler:${GLIDE_VERSION}"
compileOnly "jp.co.cyberagent.android.gpuimage:gpuimage-library:${GPUIMAGE_VERSION}"
implementation "com.github.bumptech.glide:glide:$glide_version"
annotationProcessor "com.github.bumptech.glide:compiler:$glide_version"
compileOnly "jp.co.cyberagent.android:gpuimage:$gpuimage_version"
}
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
ext {
bintrayRepo = 'maven'
bintrayName = 'glide-transformations'
bintrayUserOrg = 'wasabeef'
publishedGroupId = 'jp.wasabeef'
libraryName = 'glide-transformations'
artifact = 'glide-transformations'
libraryDescription = 'Which provides simple Tranformations to Glide'
siteUrl = 'https://github.com/wasabeef/glide-transformations'
gitUrl = 'https://github.com/wasabeef/glide-transformations.git'
issueUrl = 'https://github.com/wasabeef/glide-transformations/issues'
libraryVersion = VERSION_NAME
developerId = 'wasabeef'
developerName = 'Wasabeef'
developerEmail = 'dadadada.chop@gmail.com'
licenseName = 'The Apache Software License, Version 2.0'
licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
allLicenses = ["Apache-2.0"]
}
apply from: 'https://gist.githubusercontent.com/wasabeef/cf14805bee509baf7461974582f17d26/raw/bintray-v1.gradle'
apply from: 'https://gist.githubusercontent.com/wasabeef/cf14805bee509baf7461974582f17d26/raw/install-v1.gradle'

View File

@ -2,7 +2,7 @@
-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public class * extends com.bumptech.glide.module.AppGlideModule
-keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** {
-keep public enum com.bumptech.glide.load.ImageHeaderParser$** {
**[] $VALUES;
public *;
}

View File

@ -19,7 +19,7 @@ package jp.wasabeef.glide.transformations;
import android.content.Context;
import android.graphics.Bitmap;
import android.support.annotation.NonNull;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.Transformation;
import com.bumptech.glide.load.engine.Resource;
@ -27,8 +27,11 @@ 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;
import androidx.annotation.NonNull;
public abstract class BitmapTransformation implements Transformation<Bitmap> {
@NonNull
@ -56,11 +59,14 @@ public abstract class BitmapTransformation implements Transformation<Bitmap> {
}
protected abstract Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
@NonNull Bitmap toTransform, int outWidth, int outHeight);
@NonNull Bitmap toTransform, int outWidth, int outHeight);
@Override public abstract void updateDiskCacheKey(@NonNull MessageDigest messageDigest);
@Override
public abstract void updateDiskCacheKey(@NonNull MessageDigest messageDigest);
@Override public abstract boolean equals(Object o);
@Override
public abstract boolean equals(Object o);
@Override public abstract int hashCode();
@Override
public abstract int hashCode();
}

View File

@ -20,13 +20,13 @@ import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.os.Build;
import android.renderscript.RSRuntimeException;
import android.support.annotation.NonNull;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import java.security.MessageDigest;
import androidx.annotation.NonNull;
import jp.wasabeef.glide.transformations.internal.FastBlur;
import jp.wasabeef.glide.transformations.internal.RSBlur;
public class BlurTransformation extends BitmapTransformation {
@ -53,8 +53,9 @@ public class BlurTransformation extends BitmapTransformation {
this.sampling = sampling;
}
@Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
@Override
protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
int width = toTransform.getWidth();
int height = toTransform.getHeight();
@ -74,21 +75,25 @@ public class BlurTransformation extends BitmapTransformation {
return bitmap;
}
@Override public String toString() {
@Override
public String toString() {
return "BlurTransformation(radius=" + radius + ", sampling=" + sampling + ")";
}
@Override public boolean equals(Object o) {
@Override
public boolean equals(Object o) {
return o instanceof BlurTransformation &&
((BlurTransformation) o).radius == radius &&
((BlurTransformation) o).sampling == sampling;
}
@Override public int hashCode() {
@Override
public int hashCode() {
return ID.hashCode() + radius * 1000 + sampling * 10;
}
@Override public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
@Override
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
messageDigest.update((ID + radius + sampling).getBytes(CHARSET));
}
}

View File

@ -22,10 +22,13 @@ import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.support.annotation.NonNull;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import java.security.MessageDigest;
import androidx.annotation.NonNull;
public class ColorFilterTransformation extends BitmapTransformation {
private static final int VERSION = 1;
@ -38,8 +41,9 @@ public class ColorFilterTransformation extends BitmapTransformation {
this.color = color;
}
@Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
@Override
protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
int width = toTransform.getWidth();
int height = toTransform.getHeight();
@ -56,20 +60,24 @@ public class ColorFilterTransformation extends BitmapTransformation {
return bitmap;
}
@Override public String toString() {
@Override
public String toString() {
return "ColorFilterTransformation(color=" + color + ")";
}
@Override public boolean equals(Object o) {
@Override
public boolean equals(Object o) {
return o instanceof ColorFilterTransformation &&
((ColorFilterTransformation) o).color == color;
}
@Override public int hashCode() {
@Override
public int hashCode() {
return ID.hashCode() + color * 10;
}
@Override public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
@Override
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
messageDigest.update((ID + color).getBytes(CHARSET));
}
}

View File

@ -18,12 +18,15 @@ package jp.wasabeef.glide.transformations;
import android.content.Context;
import android.graphics.Bitmap;
import android.support.annotation.NonNull;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.TransformationUtils;
import com.bumptech.glide.request.RequestOptions;
import java.security.MessageDigest;
import androidx.annotation.NonNull;
/**
* @deprecated Use {@link RequestOptions#circleCrop()}.
*/
@ -34,24 +37,29 @@ public class CropCircleTransformation extends BitmapTransformation {
private static final String ID =
"jp.wasabeef.glide.transformations.CropCircleTransformation." + VERSION;
@Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
@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 String toString() {
@Override
public String toString() {
return "CropCircleTransformation()";
}
@Override public boolean equals(Object o) {
@Override
public boolean equals(Object o) {
return o instanceof CropCircleTransformation;
}
@Override public int hashCode() {
@Override
public int hashCode() {
return ID.hashCode();
}
@Override public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
@Override
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
messageDigest.update((ID).getBytes(CHARSET));
}
}

View File

@ -18,11 +18,14 @@ package jp.wasabeef.glide.transformations;
import android.content.Context;
import android.graphics.Bitmap;
import android.support.annotation.NonNull;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.TransformationUtils;
import java.security.MessageDigest;
import androidx.annotation.NonNull;
public class CropSquareTransformation extends BitmapTransformation {
private static final int VERSION = 1;
@ -31,25 +34,30 @@ public class CropSquareTransformation extends BitmapTransformation {
private int size;
@Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
@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 String toString() {
@Override
public String toString() {
return "CropSquareTransformation(size=" + size + ")";
}
@Override public boolean equals(Object o) {
@Override
public boolean equals(Object o) {
return o instanceof CropSquareTransformation && ((CropSquareTransformation) o).size == size;
}
@Override public int hashCode() {
@Override
public int hashCode() {
return ID.hashCode() + size * 10;
}
@Override public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
@Override
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
messageDigest.update((ID + size).getBytes(CHARSET));
}
}

View File

@ -20,10 +20,13 @@ import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.RectF;
import android.support.annotation.NonNull;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import java.security.MessageDigest;
import androidx.annotation.NonNull;
public class CropTransformation extends BitmapTransformation {
private static final int VERSION = 1;
@ -50,8 +53,9 @@ public class CropTransformation extends BitmapTransformation {
this.cropType = cropType;
}
@Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
@Override
protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
width = width == 0 ? toTransform.getWidth() : width;
height = height == 0 ? toTransform.getHeight() : height;
@ -91,22 +95,26 @@ public class CropTransformation extends BitmapTransformation {
}
}
@Override public String toString() {
@Override
public String toString() {
return "CropTransformation(width=" + width + ", height=" + height + ", cropType=" + cropType + ")";
}
@Override public boolean equals(Object o) {
@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() {
@Override
public int hashCode() {
return ID.hashCode() + width * 100000 + height * 1000 + cropType.ordinal() * 10;
}
@Override public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
@Override
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
messageDigest.update((ID + width + height + cropType).getBytes(CHARSET));
}
}

View File

@ -22,18 +22,22 @@ import android.graphics.Canvas;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.Paint;
import android.support.annotation.NonNull;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import java.security.MessageDigest;
import androidx.annotation.NonNull;
public class GrayscaleTransformation extends BitmapTransformation {
private static final int VERSION = 1;
private static final String ID =
"jp.wasabeef.glide.transformations.GrayscaleTransformation." + VERSION;
@Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
@Override
protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
int width = toTransform.getWidth();
int height = toTransform.getHeight();
@ -51,19 +55,23 @@ public class GrayscaleTransformation extends BitmapTransformation {
return bitmap;
}
@Override public String toString() {
@Override
public String toString() {
return "GrayscaleTransformation()";
}
@Override public boolean equals(Object o) {
@Override
public boolean equals(Object o) {
return o instanceof GrayscaleTransformation;
}
@Override public int hashCode() {
@Override
public int hashCode() {
return ID.hashCode();
}
@Override public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
@Override
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
messageDigest.update((ID).getBytes(CHARSET));
}
}

View File

@ -23,9 +23,12 @@ import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import java.security.MessageDigest;
import androidx.annotation.NonNull;
import jp.wasabeef.glide.transformations.internal.Utils;
public class MaskTransformation extends BitmapTransformation {
@ -43,15 +46,16 @@ public class MaskTransformation extends BitmapTransformation {
/**
* @param maskId If you change the mask file, please also rename the mask file, or Glide will get
* the cache with the old mask. Because key() return the same values if using the
* same make file name. If you have a good idea please tell us, thanks.
* the cache with the old mask. Because key() return the same values if using the
* same make file name. If you have a good idea please tell us, thanks.
*/
public MaskTransformation(int maskId) {
this.maskId = maskId;
}
@Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
@Override
protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
int width = toTransform.getWidth();
int height = toTransform.getHeight();
@ -68,20 +72,24 @@ public class MaskTransformation extends BitmapTransformation {
return bitmap;
}
@Override public String toString() {
@Override
public String toString() {
return "MaskTransformation(maskId=" + maskId + ")";
}
@Override public boolean equals(Object o) {
@Override
public boolean equals(Object o) {
return o instanceof MaskTransformation &&
((MaskTransformation) o).maskId == maskId;
}
@Override public int hashCode() {
@Override
public int hashCode() {
return ID.hashCode() + maskId * 10;
}
@Override public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
@Override
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
messageDigest.update((ID + maskId).getBytes(CHARSET));
}
}

View File

@ -23,11 +23,13 @@ import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.Shader;
import android.support.annotation.NonNull;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import java.security.MessageDigest;
import androidx.annotation.NonNull;
public class RoundedCornersTransformation extends BitmapTransformation {
private static final int VERSION = 1;
@ -57,8 +59,9 @@ public class RoundedCornersTransformation extends BitmapTransformation {
this.cornerType = cornerType;
}
@Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
@Override
protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
int width = toTransform.getWidth();
int height = toTransform.getHeight();
@ -203,7 +206,7 @@ public class RoundedCornersTransformation extends BitmapTransformation {
}
private void drawOtherBottomRightRoundRect(Canvas canvas, Paint paint, float right,
float bottom) {
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,
@ -212,7 +215,7 @@ public class RoundedCornersTransformation extends BitmapTransformation {
}
private void drawDiagonalFromTopLeftRoundRect(Canvas canvas, Paint paint, float right,
float bottom) {
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,
@ -222,7 +225,7 @@ public class RoundedCornersTransformation extends BitmapTransformation {
}
private void drawDiagonalFromTopRightRoundRect(Canvas canvas, Paint paint, float right,
float bottom) {
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,
@ -231,12 +234,14 @@ public class RoundedCornersTransformation extends BitmapTransformation {
canvas.drawRect(new RectF(margin + radius, margin + radius, right, bottom), paint);
}
@Override public String toString() {
@Override
public String toString() {
return "RoundedTransformation(radius=" + radius + ", margin=" + margin + ", diameter="
+ diameter + ", cornerType=" + cornerType.name() + ")";
}
@Override public boolean equals(Object o) {
@Override
public boolean equals(Object o) {
return o instanceof RoundedCornersTransformation &&
((RoundedCornersTransformation) o).radius == radius &&
((RoundedCornersTransformation) o).diameter == diameter &&
@ -244,11 +249,13 @@ public class RoundedCornersTransformation extends BitmapTransformation {
((RoundedCornersTransformation) o).cornerType == cornerType;
}
@Override public int hashCode() {
@Override
public int hashCode() {
return ID.hashCode() + radius * 10000 + diameter * 1000 + margin * 100 + cornerType.ordinal() * 10;
}
@Override public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
@Override
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
messageDigest.update((ID + radius + diameter + margin + cornerType).getBytes(CHARSET));
}
}

View File

@ -21,82 +21,90 @@ import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.os.Build;
import android.support.v8.renderscript.RSRuntimeException;
import android.support.annotation.NonNull;
import android.renderscript.RSRuntimeException;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import java.security.MessageDigest;
import androidx.annotation.NonNull;
import jp.wasabeef.glide.transformations.internal.FastBlur;
import jp.wasabeef.glide.transformations.internal.SupportRSBlur;
public class SupportRSBlurTransformation extends BitmapTransformation {
private static final int VERSION = 1;
private static final String ID =
"jp.wasabeef.glide.transformations.SupportRSBlurTransformation." + VERSION;
private static final int VERSION = 1;
private static final String ID =
"jp.wasabeef.glide.transformations.SupportRSBlurTransformation." + VERSION;
private static int MAX_RADIUS = 25;
private static int DEFAULT_DOWN_SAMPLING = 1;
private static int MAX_RADIUS = 25;
private static int DEFAULT_DOWN_SAMPLING = 1;
private int radius;
private int sampling;
private int radius;
private int sampling;
public SupportRSBlurTransformation() {
this(MAX_RADIUS, DEFAULT_DOWN_SAMPLING);
public SupportRSBlurTransformation() {
this(MAX_RADIUS, DEFAULT_DOWN_SAMPLING);
}
public SupportRSBlurTransformation(int radius) {
this(radius, DEFAULT_DOWN_SAMPLING);
}
public SupportRSBlurTransformation(int radius, int sampling) {
this.radius = radius;
this.sampling = sampling;
}
@Override
protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
int width = toTransform.getWidth();
int height = toTransform.getHeight();
int scaledWidth = width / sampling;
int scaledHeight = height / sampling;
Bitmap bitmap = pool.get(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
canvas.scale(1 / (float) sampling, 1 / (float) sampling);
Paint paint = new Paint();
paint.setFlags(Paint.FILTER_BITMAP_FLAG);
canvas.drawBitmap(toTransform, 0, 0, paint);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
try {
bitmap = SupportRSBlur.blur(context, bitmap, radius);
} catch (RSRuntimeException e) {
bitmap = FastBlur.blur(bitmap, radius, true);
}
} else {
bitmap = FastBlur.blur(bitmap, radius, true);
}
public SupportRSBlurTransformation(int radius) {
this(radius, DEFAULT_DOWN_SAMPLING);
}
return bitmap;
}
public SupportRSBlurTransformation(int radius, int sampling) {
this.radius = radius;
this.sampling = sampling;
}
@Override
public String toString() {
return "SupportRSBlurTransformation(radius=" + radius + ", sampling=" + sampling + ")";
}
@Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
@Override
public boolean equals(Object o) {
return o instanceof SupportRSBlurTransformation &&
((SupportRSBlurTransformation) o).radius == radius &&
((SupportRSBlurTransformation) o).sampling == sampling;
}
int width = toTransform.getWidth();
int height = toTransform.getHeight();
int scaledWidth = width / sampling;
int scaledHeight = height / sampling;
@Override
public int hashCode() {
return ID.hashCode() + radius * 1000 + sampling * 10;
}
Bitmap bitmap = pool.get(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
canvas.scale(1 / (float) sampling, 1 / (float) sampling);
Paint paint = new Paint();
paint.setFlags(Paint.FILTER_BITMAP_FLAG);
canvas.drawBitmap(toTransform, 0, 0, paint);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
try {
bitmap = SupportRSBlur.blur(context, bitmap, radius);
} catch (RSRuntimeException e) {
bitmap = FastBlur.blur(bitmap, radius, true);
}
} else {
bitmap = FastBlur.blur(bitmap, radius, true);
}
return bitmap;
}
@Override public String toString() {
return "SupportRSBlurTransformation(radius=" + radius + ", sampling=" + sampling + ")";
}
@Override public boolean equals(Object o) {
return o instanceof SupportRSBlurTransformation &&
((SupportRSBlurTransformation) o).radius == radius &&
((SupportRSBlurTransformation) 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));
}
@Override
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
messageDigest.update((ID + radius + sampling).getBytes(CHARSET));
}
}

View File

@ -16,10 +16,10 @@ package jp.wasabeef.glide.transformations.gpu;
* limitations under the License.
*/
import android.support.annotation.NonNull;
import java.security.MessageDigest;
import jp.co.cyberagent.android.gpuimage.GPUImageBrightnessFilter;
import androidx.annotation.NonNull;
import jp.co.cyberagent.android.gpuimage.filter.GPUImageBrightnessFilter;
/**
* brightness value ranges from -1.0 to 1.0, with 0.0 as the normal level
@ -43,20 +43,24 @@ public class BrightnessFilterTransformation extends GPUFilterTransformation {
filter.setBrightness(this.brightness);
}
@Override public String toString() {
@Override
public String toString() {
return "BrightnessFilterTransformation(brightness=" + brightness + ")";
}
@Override public boolean equals(Object o) {
@Override
public boolean equals(Object o) {
return o instanceof BrightnessFilterTransformation &&
((BrightnessFilterTransformation) o).brightness == brightness;
}
@Override public int hashCode() {
@Override
public int hashCode() {
return ID.hashCode() + (int) ((brightness + 1.0f) * 10);
}
@Override public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
@Override
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
messageDigest.update((ID + brightness).getBytes(CHARSET));
}
}

View File

@ -16,10 +16,10 @@ package jp.wasabeef.glide.transformations.gpu;
* limitations under the License.
*/
import android.support.annotation.NonNull;
import java.security.MessageDigest;
import jp.co.cyberagent.android.gpuimage.GPUImageContrastFilter;
import androidx.annotation.NonNull;
import jp.co.cyberagent.android.gpuimage.filter.GPUImageContrastFilter;
/**
* contrast value ranges from 0.0 to 4.0, with 1.0 as the normal level
@ -43,19 +43,23 @@ public class ContrastFilterTransformation extends GPUFilterTransformation {
filter.setContrast(this.contrast);
}
@Override public String toString() {
@Override
public String toString() {
return "ContrastFilterTransformation(contrast=" + contrast + ")";
}
@Override public boolean equals(Object o) {
@Override
public boolean equals(Object o) {
return o instanceof ContrastFilterTransformation;
}
@Override public int hashCode() {
@Override
public int hashCode() {
return ID.hashCode() + (int) (contrast * 10);
}
@Override public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
@Override
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
messageDigest.update((ID + contrast).getBytes(CHARSET));
}
}

View File

@ -18,11 +18,14 @@ package jp.wasabeef.glide.transformations.gpu;
import android.content.Context;
import android.graphics.Bitmap;
import android.support.annotation.NonNull;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import java.security.MessageDigest;
import androidx.annotation.NonNull;
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 extends BitmapTransformation {
@ -38,8 +41,9 @@ public class GPUFilterTransformation extends BitmapTransformation {
this.gpuImageFilter = filter;
}
@Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
@Override
protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
GPUImage gpuImage = new GPUImage(context);
gpuImage.setImage(toTransform);
gpuImage.setFilter(gpuImageFilter);
@ -47,23 +51,28 @@ public class GPUFilterTransformation extends BitmapTransformation {
return gpuImage.getBitmapWithFilterApplied();
}
@Override public String toString() {
@Override
public String toString() {
return getClass().getSimpleName();
}
@SuppressWarnings("unchecked") public <T> T getFilter() {
@SuppressWarnings("unchecked")
public <T> T getFilter() {
return (T) gpuImageFilter;
}
@Override public boolean equals(Object o) {
@Override
public boolean equals(Object o) {
return o instanceof GPUFilterTransformation;
}
@Override public int hashCode() {
@Override
public int hashCode() {
return ID.hashCode();
}
@Override public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
@Override
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
messageDigest.update(ID_BYTES);
}
}

View File

@ -16,10 +16,10 @@ package jp.wasabeef.glide.transformations.gpu;
* limitations under the License.
*/
import android.support.annotation.NonNull;
import java.security.MessageDigest;
import jp.co.cyberagent.android.gpuimage.GPUImageColorInvertFilter;
import androidx.annotation.NonNull;
import jp.co.cyberagent.android.gpuimage.filter.GPUImageColorInvertFilter;
/**
* Invert all the colors in the image.
@ -34,19 +34,23 @@ public class InvertFilterTransformation extends GPUFilterTransformation {
super(new GPUImageColorInvertFilter());
}
@Override public String toString() {
@Override
public String toString() {
return "InvertFilterTransformation()";
}
@Override public boolean equals(Object o) {
@Override
public boolean equals(Object o) {
return o instanceof InvertFilterTransformation;
}
@Override public int hashCode() {
@Override
public int hashCode() {
return ID.hashCode();
}
@Override public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
@Override
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
messageDigest.update((ID).getBytes(CHARSET));
}
}

View File

@ -16,10 +16,10 @@ package jp.wasabeef.glide.transformations.gpu;
* limitations under the License.
*/
import android.support.annotation.NonNull;
import java.security.MessageDigest;
import jp.co.cyberagent.android.gpuimage.GPUImageKuwaharaFilter;
import androidx.annotation.NonNull;
import jp.co.cyberagent.android.gpuimage.filter.GPUImageKuwaharaFilter;
/**
* Kuwahara all the colors in the image.
@ -46,19 +46,23 @@ public class KuwaharaFilterTransformation extends GPUFilterTransformation {
filter.setRadius(this.radius);
}
@Override public String toString() {
@Override
public String toString() {
return "KuwaharaFilterTransformation(radius=" + radius + ")";
}
@Override public boolean equals(Object o) {
@Override
public boolean equals(Object o) {
return o instanceof KuwaharaFilterTransformation;
}
@Override public int hashCode() {
@Override
public int hashCode() {
return ID.hashCode() + radius * 10;
}
@Override public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
@Override
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
messageDigest.update((ID + radius).getBytes(CHARSET));
}
}

View File

@ -16,10 +16,10 @@ package jp.wasabeef.glide.transformations.gpu;
* limitations under the License.
*/
import android.support.annotation.NonNull;
import java.security.MessageDigest;
import jp.co.cyberagent.android.gpuimage.GPUImagePixelationFilter;
import androidx.annotation.NonNull;
import jp.co.cyberagent.android.gpuimage.filter.GPUImagePixelationFilter;
/**
* Applies a Pixelation effect to the image.
@ -45,19 +45,23 @@ public class PixelationFilterTransformation extends GPUFilterTransformation {
filter.setPixel(this.pixel);
}
@Override public String toString() {
@Override
public String toString() {
return "PixelationFilterTransformation(pixel=" + pixel + ")";
}
@Override public boolean equals(Object o) {
@Override
public boolean equals(Object o) {
return o instanceof PixelationFilterTransformation;
}
@Override public int hashCode() {
@Override
public int hashCode() {
return ID.hashCode() + (int) (pixel * 10);
}
@Override public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
@Override
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
messageDigest.update((ID + pixel).getBytes(CHARSET));
}
}

View File

@ -2,13 +2,13 @@ package jp.wasabeef.glide.transformations.gpu;
/**
* Copyright (C) 2018 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,10 @@ package jp.wasabeef.glide.transformations.gpu;
* limitations under the License.
*/
import android.support.annotation.NonNull;
import java.security.MessageDigest;
import jp.co.cyberagent.android.gpuimage.GPUImageSepiaFilter;
import androidx.annotation.NonNull;
import jp.co.cyberagent.android.gpuimage.filter.GPUImageSepiaToneFilter;
/**
* Applies a simple sepia effect.
@ -39,25 +39,29 @@ public class SepiaFilterTransformation extends GPUFilterTransformation {
}
public SepiaFilterTransformation(float intensity) {
super(new GPUImageSepiaFilter());
super(new GPUImageSepiaToneFilter());
this.intensity = intensity;
GPUImageSepiaFilter filter = getFilter();
GPUImageSepiaToneFilter filter = getFilter();
filter.setIntensity(this.intensity);
}
@Override public String toString() {
@Override
public String toString() {
return "SepiaFilterTransformation(intensity=" + intensity + ")";
}
@Override public boolean equals(Object o) {
@Override
public boolean equals(Object o) {
return o instanceof SepiaFilterTransformation;
}
@Override public int hashCode() {
@Override
public int hashCode() {
return ID.hashCode() + (int) (intensity * 10);
}
@Override public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
@Override
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
messageDigest.update((ID + intensity).getBytes(CHARSET));
}
}

View File

@ -16,10 +16,10 @@ package jp.wasabeef.glide.transformations.gpu;
* limitations under the License.
*/
import android.support.annotation.NonNull;
import java.security.MessageDigest;
import jp.co.cyberagent.android.gpuimage.GPUImageSketchFilter;
import androidx.annotation.NonNull;
import jp.co.cyberagent.android.gpuimage.filter.GPUImageSketchFilter;
public class SketchFilterTransformation extends GPUFilterTransformation {
@ -31,19 +31,23 @@ public class SketchFilterTransformation extends GPUFilterTransformation {
super(new GPUImageSketchFilter());
}
@Override public String toString() {
@Override
public String toString() {
return "SketchFilterTransformation()";
}
@Override public boolean equals(Object o) {
@Override
public boolean equals(Object o) {
return o instanceof SketchFilterTransformation;
}
@Override public int hashCode() {
@Override
public int hashCode() {
return ID.hashCode();
}
@Override public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
@Override
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
messageDigest.update((ID).getBytes(CHARSET));
}
}

View File

@ -17,10 +17,11 @@ package jp.wasabeef.glide.transformations.gpu;
*/
import android.graphics.PointF;
import android.support.annotation.NonNull;
import java.security.MessageDigest;
import jp.co.cyberagent.android.gpuimage.GPUImageSwirlFilter;
import androidx.annotation.NonNull;
import jp.co.cyberagent.android.gpuimage.filter.GPUImageSwirlFilter;
/**
* Creates a swirl distortion on the image.
@ -41,7 +42,7 @@ public class SwirlFilterTransformation extends GPUFilterTransformation {
/**
* @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(float radius, float angle, PointF center) {
@ -55,23 +56,27 @@ public class SwirlFilterTransformation extends GPUFilterTransformation {
filter.setCenter(this.center);
}
@Override public String toString() {
@Override
public String toString() {
return "SwirlFilterTransformation(radius=" + radius + ",angle=" + angle + ",center="
+ center.toString() + ")";
}
@Override public boolean equals(Object o) {
@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() {
@Override
public int hashCode() {
return ID.hashCode() + (int) (radius * 1000) + (int) (angle * 10) + center.hashCode();
}
@Override public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
@Override
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
messageDigest.update((ID + radius + angle + center.hashCode()).getBytes(CHARSET));
}
}

View File

@ -16,10 +16,10 @@ package jp.wasabeef.glide.transformations.gpu;
* limitations under the License.
*/
import android.support.annotation.NonNull;
import java.security.MessageDigest;
import jp.co.cyberagent.android.gpuimage.GPUImageToonFilter;
import androidx.annotation.NonNull;
import jp.co.cyberagent.android.gpuimage.filter.GPUImageToonFilter;
/**
* The threshold at which to apply the edges, default of 0.2.
@ -48,22 +48,26 @@ public class ToonFilterTransformation extends GPUFilterTransformation {
filter.setQuantizationLevels(this.quantizationLevels);
}
@Override public String toString() {
@Override
public String toString() {
return "ToonFilterTransformation(threshold=" + threshold + ",quantizationLevels="
+ quantizationLevels + ")";
}
@Override public boolean equals(Object o) {
@Override
public boolean equals(Object o) {
return o instanceof ToonFilterTransformation &&
((ToonFilterTransformation) o).threshold == threshold &&
((ToonFilterTransformation) o).quantizationLevels == quantizationLevels;
}
@Override public int hashCode() {
@Override
public int hashCode() {
return ID.hashCode() + (int) (threshold * 1000) + (int) (quantizationLevels * 10);
}
@Override public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
@Override
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
messageDigest.update((ID + threshold + quantizationLevels).getBytes(CHARSET));
}
}

View File

@ -17,11 +17,12 @@ package jp.wasabeef.glide.transformations.gpu;
*/
import android.graphics.PointF;
import android.support.annotation.NonNull;
import java.security.MessageDigest;
import java.util.Arrays;
import jp.co.cyberagent.android.gpuimage.GPUImageVignetteFilter;
import androidx.annotation.NonNull;
import jp.co.cyberagent.android.gpuimage.filter.GPUImageVignetteFilter;
/**
* Performs a vignetting effect, fading out the image at the edges
@ -40,7 +41,7 @@ public class VignetteFilterTransformation extends GPUFilterTransformation {
private float vignetteEnd;
public VignetteFilterTransformation() {
this(new PointF(0.5f, 0.5f), new float[] { 0.0f, 0.0f, 0.0f }, 0.0f, 0.75f);
this(new PointF(0.5f, 0.5f), new float[]{0.0f, 0.0f, 0.0f}, 0.0f, 0.75f);
}
public VignetteFilterTransformation(PointF center, float[] color, float start, float end) {
@ -56,25 +57,29 @@ public class VignetteFilterTransformation extends GPUFilterTransformation {
filter.setVignetteEnd(vignetteEnd);
}
@Override public String toString() {
@Override
public String toString() {
return "VignetteFilterTransformation(center=" + center.toString() + ",color=" + Arrays.toString(
vignetteColor) + ",start=" + vignetteStart + ",end=" + vignetteEnd + ")";
}
@Override public boolean equals(Object o) {
@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;
((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() {
@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) {
@Override
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
messageDigest.update((ID + center + Arrays.hashCode(vignetteColor) + vignetteStart + vignetteEnd).getBytes(CHARSET));
}
}

View File

@ -4,11 +4,11 @@ import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Bitmap;
import android.os.Build;
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 android.renderscript.Allocation;
import android.renderscript.Element;
import android.renderscript.RSRuntimeException;
import android.renderscript.RenderScript;
import android.renderscript.ScriptIntrinsicBlur;
/**
* Copyright (C) 2018 Wasabeef
@ -28,43 +28,43 @@ import android.support.v8.renderscript.ScriptIntrinsicBlur;
public class SupportRSBlur {
@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));
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
public static Bitmap blur(Context context, Bitmap bitmap, int radius) throws RSRuntimeException {
RenderScript rs = null;
Allocation input = null;
Allocation output = null;
ScriptIntrinsicBlur blur = null;
try {
rs = RenderScript.create(context);
rs.setMessageHandler(new RenderScript.RSMessageHandler());
input = Allocation.createFromBitmap(rs, bitmap, Allocation.MipmapControl.MIPMAP_NONE,
Allocation.USAGE_SCRIPT);
output = Allocation.createTyped(rs, input.getType());
blur = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
blur.setInput(input);
blur.setRadius(radius);
blur.forEach(output);
output.copyTo(bitmap);
} finally {
if (rs != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
RenderScript.releaseAllContexts();
} else {
rs.destroy();
}
}
if (input != null) {
input.destroy();
}
if (output != null) {
output.destroy();
}
if (blur != null) {
blur.destroy();
}
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();
}
return bitmap;
}
if (input != null) {
input.destroy();
}
if (output != null) {
output.destroy();
}
if (blur != null) {
blur.destroy();
}
}
return bitmap;
}
}