1
0
mirror of https://github.com/wasabeef/glide-transformations.git synced 2025-10-06 03:13:30 +08:00

34 Commits
1.4.0 ... 3.1.0

Author SHA1 Message Date
Daichi Furiya
51f7b515fa For Glide 4.5.0 (#112) 2018-01-26 17:08:27 +09:00
CrabeMan
43f38cc4b3 Implement equals() and hashCode() methods (#105)
* Implement equals() and hashCode() methods

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

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

View File

@@ -1,6 +1,60 @@
Change Log Change Log
========== ==========
Version 3.1.0 *(2018-01-26)*
----------------------------
Update:
- Compile & Target SDK Version 25 -> 27
- Build Tools 26.0.1 -> 27.0.3
- Support Library 25.3.1 -> 27.0.2
- Glide 4.0.0 -> 4.5.0
Bug Fix:
- [Implement equals() and hashCode() methods #105](https://github.com/wasabeef/glide-transformations/pull/105)
- Use RenderScript#releaseAllContexts
Version 3.0.1 *(2017-09-08)*
----------------------------
Bug Fix:
- [Deleted a setting for DexGuard #86](https://github.com/wasabeef/glide-transformations/issues/86)
Version 3.0.0 *(2017-09-06)*
----------------------------
Update:
- Build Tools 25.0.2 -> 26.0.1
- Min SDK Version 11 -> 14
- Glide 3.7.0 -> 4.0.0
Feature:
- Supported Glide 4.0.0
Version 2.0.2 *(2017-03-17)*
----------------------------
Update:
- Compile & Target SDK Version 23 -> 25
- Build Tools 23.0.2 -> 25.0.2
- Support Library 23.2.1 -> 25.3.0
- GPUImage for Android 1.3.0 -> 1.4.1
Bug Fix:
- [Additional resource cleanup in RSBlur #45](https://github.com/wasabeef/glide-transformations/pull/45)
Version 2.0.1 *(2016-04-21)*
----------------------------
Fix:
[#35](https://github.com/wasabeef/glide-transformations/issues/35)
RSInvalidStateException
Version 2.0.0 *(2016-03-02)*
----------------------------
Say v8.RenderScript goodbye
Version 1.4.0 *(2016-02-28)* Version 1.4.0 *(2016-02-28)*
---------------------------- ----------------------------

View File

@@ -29,13 +29,12 @@ Please feel free to use this.
```groovy ```groovy
repositories { repositories {
jcenter() jcenter()
mavenCentral() // GPUImage for Android
} }
dependencies { dependencies {
compile 'jp.wasabeef:glide-transformations:1.4.0' implementation 'jp.wasabeef:glide-transformations:3.1.0'
// If you want to use the GPU Filters // If you want to use the GPU Filters
compile 'jp.co.cyberagent.android.gpuimage:gpuimage-library:1.3.0' implementation 'jp.co.cyberagent.android.gpuimage:gpuimage-library:1.4.1'
} }
``` ```
@@ -45,7 +44,7 @@ Set Glide Transform.
```java ```java
Glide.with(this).load(R.drawable.demo) Glide.with(this).load(R.drawable.demo)
.bitmapTransform(new BlurTransformation(context)) .apply(bitmapTransform(new BlurTransformation(25)))
.into((ImageView) findViewById(R.id.image)); .into((ImageView) findViewById(R.id.image));
``` ```
@@ -54,26 +53,14 @@ Glide.with(this).load(R.drawable.demo)
You can set a multiple transformations. You can set a multiple transformations.
```java ```java
MultiTransformation multi = new MultiTransformation(
new BlurTransformation(25),
new RoundedCornersTransformation(128, 0, RoundedCornersTransformation.CornerType.BOTTOM))))
Glide.with(this).load(R.drawable.demo) Glide.with(this).load(R.drawable.demo)
.bitmapTransform(new BlurTransformation(context, 25, 2), new CropCircleTransformation(context)) .apply(bitmapTransform(multi))
.into((ImageView) findViewById(R.id.image)); .into((ImageView) findViewById(R.id.image));
``` ```
## Step 4
If you are using `BlurTransformation`.
```groovy
android {
...
defaultConfig {
// Warning:Renderscript support mode is not currently supported with renderscript target 21+
renderscriptTargetApi 20
renderscriptSupportModeEnabled true
}
}
```
## Transformations ## Transformations
### Crop ### Crop
@@ -106,6 +93,7 @@ Please [ping](mailto:dadadada.chop@gmail.com) me or send a pull request if you w
Icon | Application Icon | Application
------------ | ------------- ------------ | -------------
<img src="https://lh6.ggpht.com/6zKH_uQY1bxCwXL4DLo_uoFEOXdShi3BgmN6XRHlaJ-oA1svmq6y1PZkmO50nWQn2Lg=w300-rw" width="48" height="48" /> | [Ameba Ownd](https://play.google.com/store/apps/details?id=jp.co.cyberagent.madrid) <img src="https://lh6.ggpht.com/6zKH_uQY1bxCwXL4DLo_uoFEOXdShi3BgmN6XRHlaJ-oA1svmq6y1PZkmO50nWQn2Lg=w300-rw" width="48" height="48" /> | [Ameba Ownd](https://play.google.com/store/apps/details?id=jp.co.cyberagent.madrid)
<img src="https://lh3.googleusercontent.com/ZOrekp-ho-ecWG1TyvuOs0LoB5M4QYWCCLS5lFbAHhp_SklSd06544ENG3uC97zGWes=w300-rw" width="48" height="48" /> | [AbemaTV](https://play.google.com/store/apps/details?id=tv.abema)
Developed By Developed By
------- -------
@@ -134,7 +122,7 @@ Thanks
License License
------- -------
Copyright 2015 Wasabeef Copyright 2018 Wasabeef
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with 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

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

View File

@@ -9,10 +9,6 @@ android {
targetSdkVersion TARGET_SDK_VERSION as int targetSdkVersion TARGET_SDK_VERSION as int
versionCode "git rev-list origin/master --count".execute().text.toInteger() versionCode "git rev-list origin/master --count".execute().text.toInteger()
versionName VERSION_NAME versionName VERSION_NAME
// Warning:Renderscript support mode is not currently supported with renderscript target 21+
renderscriptTargetApi RENDERSCRIPT_TARGET_API as int
renderscriptSupportModeEnabled true
} }
signingConfigs { signingConfigs {
@@ -33,6 +29,8 @@ android {
debuggable false debuggable false
zipAlignEnabled true zipAlignEnabled true
signingConfig signingConfigs.release signingConfig signingConfigs.release
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
} }
} }
} }
@@ -54,9 +52,11 @@ def getKeyAliasPasswordProperty() {
} }
dependencies { dependencies {
compile project(':transformations') implementation project(':transformations')
compile "com.github.bumptech.glide:glide:${GLIDE_VERSION}" implementation "com.github.bumptech.glide:glide:${GLIDE_VERSION}"
compile "jp.co.cyberagent.android.gpuimage:gpuimage-library:${GPUIMAGE_VERSION}" annotationProcessor "com.github.bumptech.glide:compiler:${GLIDE_VERSION}"
compile "com.android.support:appcompat-v7:${SUPPORT_PACKAGE_VERSION}" implementation "jp.co.cyberagent.android.gpuimage:gpuimage-library:${GPUIMAGE_VERSION}"
compile "com.android.support:recyclerview-v7:${SUPPORT_PACKAGE_VERSION}" implementation "com.android.support:appcompat-v7:${SUPPORT_PACKAGE_VERSION}"
implementation "com.android.support:recyclerview-v7:${SUPPORT_PACKAGE_VERSION}"
implementation 'com.android.support.constraint:constraint-layout:1.1.0-beta4'
} }

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

View File

@@ -2,7 +2,7 @@ package jp.wasabeef.example.glide;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.GridLayoutManager; import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@@ -15,7 +15,7 @@ public class MainActivity extends AppCompatActivity {
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.list); RecyclerView recyclerView = (RecyclerView) findViewById(R.id.list);
recyclerView.setLayoutManager(new GridLayoutManager(this, 2)); recyclerView.setLayoutManager(new LinearLayoutManager(this));
List<Type> dataSet = new ArrayList<>(); List<Type> dataSet = new ArrayList<>();
dataSet.add(Type.Mask); dataSet.add(Type.Mask);

View File

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

View File

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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.2 KiB

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.1 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 7.5 KiB

View File

@@ -1,15 +1,23 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="#CC000000"
tools:context=".MainActivity"
> >
<android.support.v7.widget.RecyclerView <android.support.v7.widget.RecyclerView
android:id="@+id/list" android:id="@+id/list"
android:layout_width="match_parent" android:layout_width="0dp"
android:layout_height="match_parent" 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>
</RelativeLayout>

View File

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

View File

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

View File

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

View File

@@ -1,13 +1,11 @@
VERSION_NAME=1.4.0 VERSION_NAME=3.1.0
GROUP=jp.wasabeef GROUP=jp.wasabeef
ARTIFACT_ID=glide-transformations ARTIFACT_ID=glide-transformations
COMPILE_SDK_VERSION=23 COMPILE_SDK_VERSION=27
BUILD_TOOLS_VERSION=23.0.2 BUILD_TOOLS_VERSION=27.0.3
TARGET_SDK_VERSION=23 TARGET_SDK_VERSION=27
# Warning:Renderscript support mode is not currently supported with renderscript target 21+ MIN_SDK_VERSION=14
RENDERSCRIPT_TARGET_API=20
MIN_SDK_VERSION=11
POM_DESCRIPTION=which provides simple Tranformations to Glide POM_DESCRIPTION=which provides simple Tranformations to Glide
POM_URL=https://github.com/wasabeef/glide-transformations POM_URL=https://github.com/wasabeef/glide-transformations
@@ -23,6 +21,6 @@ POM_DEVELOPER_EMAIL=dadadada.chop@gmail.com
POM_DEVELOPER_URL=wasabeef.jp POM_DEVELOPER_URL=wasabeef.jp
ISSUE_URL=https://github.com/wasabeef/glide-transformations/issues ISSUE_URL=https://github.com/wasabeef/glide-transformations/issues
SUPPORT_PACKAGE_VERSION=23.1.1 SUPPORT_PACKAGE_VERSION=27.0.2
GLIDE_VERSION=3.6.1 GLIDE_VERSION=4.5.0
GPUIMAGE_VERSION=1.3.0 GPUIMAGE_VERSION=1.4.1

Binary file not shown.

View File

@@ -1,6 +1,6 @@
#Wed Apr 10 15:27:10 PDT 2013 #Thu Jan 25 11:48:25 JST 2018
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.11-all.zip distributionUrl=https\://services.gradle.org/distributions/gradle-4.3-all.zip

74
gradlew vendored
View File

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

14
gradlew.bat vendored
View File

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

View File

@@ -11,37 +11,14 @@ android {
versionCode "git rev-list origin/master --count".execute().text.toInteger() versionCode "git rev-list origin/master --count".execute().text.toInteger()
versionName VERSION_NAME versionName VERSION_NAME
// Warning:Renderscript support mode is not currently supported with renderscript target 21+
renderscriptTargetApi RENDERSCRIPT_TARGET_API as int
renderscriptSupportModeEnabled true
consumerProguardFiles 'proguard-rules.txt' consumerProguardFiles 'proguard-rules.txt'
} }
} }
dependencies { dependencies {
compile "com.github.bumptech.glide:glide:${GLIDE_VERSION}" implementation "com.github.bumptech.glide:glide:${GLIDE_VERSION}"
provided "jp.co.cyberagent.android.gpuimage:gpuimage-library:${GPUIMAGE_VERSION}" annotationProcessor "com.github.bumptech.glide:compiler:${GLIDE_VERSION}"
} compileOnly "jp.co.cyberagent.android.gpuimage:gpuimage-library:${GPUIMAGE_VERSION}"
task androidJavadocs(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}
task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
classifier = 'javadoc'
from androidJavadocs.destinationDir
}
task androidSourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.srcDirs
}
artifacts {
archives androidSourcesJar
archives androidJavadocsJar
} }
publish { publish {
@@ -51,4 +28,7 @@ publish {
publishVersion = VERSION_NAME publishVersion = VERSION_NAME
desc = POM_DESCRIPTION desc = POM_DESCRIPTION
website = POM_URL website = POM_URL
bintrayUser = BINTRAY_USER
bintrayKey = BINTRAY_API_KEY
autoPublish = false
} }

View File

@@ -1,7 +1,8 @@
-keepclasseswithmembernames class * {
native <methods>;
}
-keep class android.support.v8.renderscript.** { *; }
-dontwarn jp.co.cyberagent.android.gpuimage.** -dontwarn jp.co.cyberagent.android.gpuimage.**
-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public class * extends com.bumptech.glide.AppGlideModule
-keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** {
**[] $VALUES;
public *;
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations; package jp.wasabeef.glide.transformations;
/** /**
* Copyright (C) 2015 Wasabeef * Copyright (C) 2018 Wasabeef
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -23,63 +23,65 @@ import android.graphics.Paint;
import android.graphics.PorterDuff; import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode; import android.graphics.PorterDuffXfermode;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import com.bumptech.glide.Glide; import android.support.annotation.NonNull;
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.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapResource; import java.security.MessageDigest;
import jp.wasabeef.glide.transformations.internal.Utils; import jp.wasabeef.glide.transformations.internal.Utils;
public class MaskTransformation implements Transformation<Bitmap> { public class MaskTransformation extends BitmapTransformation {
private static Paint mMaskingPaint = new Paint(); private static final int VERSION = 1;
private Context mContext; private static final String ID =
private BitmapPool mBitmapPool; "jp.wasabeef.glide.transformations.MaskTransformation." + VERSION;
private int mMaskId; private static final byte[] ID_BYTES = ID.getBytes(CHARSET);
private static Paint paint = new Paint();
private int maskId;
static { static {
mMaskingPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
} }
/** /**
* @param maskId If you change the mask file, please also rename the mask file, or Glide will get * @param maskId If you change the mask file, please also rename the mask file, or Glide will get
* the cache with the old mask. Because getId() return the same values if using the * 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. * same make file name. If you have a good idea please tell us, thanks.
*/ */
public MaskTransformation(Context context, int maskId) { public MaskTransformation(int maskId) {
this(context, Glide.get(context).getBitmapPool(), maskId); this.maskId = maskId;
} }
public MaskTransformation(Context context, BitmapPool pool, int maskId) { @Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
mBitmapPool = pool; @NonNull Bitmap toTransform, int outWidth, int outHeight) {
mContext = context.getApplicationContext(); int width = toTransform.getWidth();
mMaskId = maskId; int height = toTransform.getHeight();
}
@Override Bitmap bitmap = pool.get(width, height, Bitmap.Config.ARGB_8888);
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) { bitmap.setHasAlpha(true);
Bitmap source = resource.get();
int width = source.getWidth(); Drawable mask = Utils.getMaskDrawable(context.getApplicationContext(), maskId);
int height = source.getHeight();
Bitmap result = mBitmapPool.get(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap);
if (result == null) {
result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
}
Drawable mask = Utils.getMaskDrawable(mContext, mMaskId);
Canvas canvas = new Canvas(result);
mask.setBounds(0, 0, width, height); mask.setBounds(0, 0, width, height);
mask.draw(canvas); mask.draw(canvas);
canvas.drawBitmap(source, 0, 0, mMaskingPaint); canvas.drawBitmap(toTransform, 0, 0, paint);
return BitmapResource.obtain(result, mBitmapPool); return bitmap;
} }
@Override public String getId() { @Override public String toString() {
return "MaskTransformation(maskId=" + mContext.getResources().getResourceEntryName(mMaskId) return "MaskTransformation(maskId=" + maskId + ")";
+ ")"; }
@Override public boolean equals(Object o) {
return o instanceof MaskTransformation;
}
@Override public int hashCode() {
return ID.hashCode();
}
@Override public void updateDiskCacheKey(MessageDigest messageDigest) {
messageDigest.update(ID_BYTES);
} }
} }

View File

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

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations.gpu; package jp.wasabeef.glide.transformations.gpu;
/** /**
* Copyright (C) 2015 Wasabeef * Copyright (C) 2018 Wasabeef
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -16,9 +16,7 @@ package jp.wasabeef.glide.transformations.gpu;
* limitations under the License. * limitations under the License.
*/ */
import android.content.Context; import java.security.MessageDigest;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import jp.co.cyberagent.android.gpuimage.GPUImageBrightnessFilter; import jp.co.cyberagent.android.gpuimage.GPUImageBrightnessFilter;
/** /**
@@ -26,28 +24,37 @@ import jp.co.cyberagent.android.gpuimage.GPUImageBrightnessFilter;
*/ */
public class BrightnessFilterTransformation extends GPUFilterTransformation { public class BrightnessFilterTransformation extends GPUFilterTransformation {
private float mBrightness; private static final int VERSION = 1;
private static final String ID =
"jp.wasabeef.glide.transformations.gpu.BrightnessFilterTransformation." + VERSION;
private static final byte[] ID_BYTES = ID.getBytes(CHARSET);
public BrightnessFilterTransformation(Context context) { private float brightness;
this(context, Glide.get(context).getBitmapPool());
public BrightnessFilterTransformation() {
this(0.0f);
} }
public BrightnessFilterTransformation(Context context, BitmapPool pool) { public BrightnessFilterTransformation(float brightness) {
this(context, pool, 0.0f); super(new GPUImageBrightnessFilter());
} this.brightness = brightness;
public BrightnessFilterTransformation(Context context, float brightness) {
this(context, Glide.get(context).getBitmapPool(), brightness);
}
public BrightnessFilterTransformation(Context context, BitmapPool pool, float brightness) {
super(context, pool, new GPUImageBrightnessFilter());
mBrightness = brightness;
GPUImageBrightnessFilter filter = getFilter(); GPUImageBrightnessFilter filter = getFilter();
filter.setBrightness(mBrightness); filter.setBrightness(this.brightness);
} }
@Override public String getId() { @Override public String toString() {
return "BrightnessFilterTransformation(brightness=" + mBrightness + ")"; return "BrightnessFilterTransformation(brightness=" + brightness + ")";
}
@Override public boolean equals(Object o) {
return o instanceof BrightnessFilterTransformation;
}
@Override public int hashCode() {
return ID.hashCode();
}
@Override public void updateDiskCacheKey(MessageDigest messageDigest) {
messageDigest.update(ID_BYTES);
} }
} }

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations.gpu; package jp.wasabeef.glide.transformations.gpu;
/** /**
* Copyright (C) 2015 Wasabeef * Copyright (C) 2018 Wasabeef
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -16,9 +16,7 @@ package jp.wasabeef.glide.transformations.gpu;
* limitations under the License. * limitations under the License.
*/ */
import android.content.Context; import java.security.MessageDigest;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import jp.co.cyberagent.android.gpuimage.GPUImageContrastFilter; import jp.co.cyberagent.android.gpuimage.GPUImageContrastFilter;
/** /**
@@ -26,28 +24,37 @@ import jp.co.cyberagent.android.gpuimage.GPUImageContrastFilter;
*/ */
public class ContrastFilterTransformation extends GPUFilterTransformation { public class ContrastFilterTransformation extends GPUFilterTransformation {
private float mContrast; private static final int VERSION = 1;
private static final String ID =
"jp.wasabeef.glide.transformations.gpu.ContrastFilterTransformation." + VERSION;
private static final byte[] ID_BYTES = ID.getBytes(CHARSET);
public ContrastFilterTransformation(Context context) { private float contrast;
this(context, Glide.get(context).getBitmapPool());
public ContrastFilterTransformation() {
this(1.0f);
} }
public ContrastFilterTransformation(Context context, BitmapPool pool) { public ContrastFilterTransformation(float contrast) {
this(context, pool, 1.0f); super(new GPUImageContrastFilter());
} this.contrast = contrast;
public ContrastFilterTransformation(Context context, float contrast) {
this(context, Glide.get(context).getBitmapPool(), contrast);
}
public ContrastFilterTransformation(Context context, BitmapPool pool, float contrast) {
super(context, pool, new GPUImageContrastFilter());
mContrast = contrast;
GPUImageContrastFilter filter = getFilter(); GPUImageContrastFilter filter = getFilter();
filter.setContrast(mContrast); filter.setContrast(this.contrast);
} }
@Override public String getId() { @Override public String toString() {
return "ContrastFilterTransformation(contrast=" + mContrast + ")"; return "ContrastFilterTransformation(contrast=" + contrast + ")";
}
@Override public boolean equals(Object o) {
return o instanceof ContrastFilterTransformation;
}
@Override public int hashCode() {
return ID.hashCode();
}
@Override public void updateDiskCacheKey(MessageDigest messageDigest) {
messageDigest.update(ID_BYTES);
} }
} }

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations.gpu; package jp.wasabeef.glide.transformations.gpu;
/** /**
* Copyright (C) 2015 Wasabeef * Copyright (C) 2018 Wasabeef
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -18,48 +18,52 @@ package jp.wasabeef.glide.transformations.gpu;
import android.content.Context; import android.content.Context;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import com.bumptech.glide.Glide; import android.support.annotation.NonNull;
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.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapResource; import java.security.MessageDigest;
import jp.co.cyberagent.android.gpuimage.GPUImage; import jp.co.cyberagent.android.gpuimage.GPUImage;
import jp.co.cyberagent.android.gpuimage.GPUImageFilter; import jp.co.cyberagent.android.gpuimage.GPUImageFilter;
import jp.wasabeef.glide.transformations.BitmapTransformation;
public class GPUFilterTransformation implements Transformation<Bitmap> { public class GPUFilterTransformation extends BitmapTransformation {
private Context mContext; private static final int VERSION = 1;
private BitmapPool mBitmapPool; private static final String ID =
"jp.wasabeef.glide.transformations.gpu.GPUFilterTransformation." + VERSION;
private static final byte[] ID_BYTES = ID.getBytes(CHARSET);
private GPUImageFilter mFilter; private GPUImageFilter gpuImageFilter;
public GPUFilterTransformation(Context context, GPUImageFilter filter) { public GPUFilterTransformation(GPUImageFilter filter) {
this(context, Glide.get(context).getBitmapPool(), filter); this.gpuImageFilter = filter;
} }
public GPUFilterTransformation(Context context, BitmapPool pool, GPUImageFilter filter) { @Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
mContext = context.getApplicationContext(); @NonNull Bitmap toTransform, int outWidth, int outHeight) {
mBitmapPool = pool; GPUImage gpuImage = new GPUImage(context);
mFilter = filter; gpuImage.setImage(toTransform);
gpuImage.setFilter(gpuImageFilter);
return gpuImage.getBitmapWithFilterApplied();
} }
@Override @Override public String toString() {
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(); return getClass().getSimpleName();
} }
@SuppressWarnings("unchecked") public <T> T getFilter() { @SuppressWarnings("unchecked") public <T> T getFilter() {
return (T) mFilter; return (T) gpuImageFilter;
}
@Override public boolean equals(Object o) {
return o instanceof GPUFilterTransformation;
}
@Override public int hashCode() {
return ID.hashCode();
}
@Override public void updateDiskCacheKey(MessageDigest messageDigest) {
messageDigest.update(ID_BYTES);
} }
} }

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations.gpu; package jp.wasabeef.glide.transformations.gpu;
/** /**
* Copyright (C) 2015 Wasabeef * Copyright (C) 2018 Wasabeef
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -16,9 +16,7 @@ package jp.wasabeef.glide.transformations.gpu;
* limitations under the License. * limitations under the License.
*/ */
import android.content.Context; import java.security.MessageDigest;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import jp.co.cyberagent.android.gpuimage.GPUImageColorInvertFilter; import jp.co.cyberagent.android.gpuimage.GPUImageColorInvertFilter;
/** /**
@@ -26,15 +24,28 @@ import jp.co.cyberagent.android.gpuimage.GPUImageColorInvertFilter;
*/ */
public class InvertFilterTransformation extends GPUFilterTransformation { public class InvertFilterTransformation extends GPUFilterTransformation {
public InvertFilterTransformation(Context context) { private static final int VERSION = 1;
this(context, Glide.get(context).getBitmapPool()); private static final String ID =
"jp.wasabeef.glide.transformations.gpu.InvertFilterTransformation." + VERSION;
private static final byte[] ID_BYTES = ID.getBytes(CHARSET);
public InvertFilterTransformation() {
super(new GPUImageColorInvertFilter());
} }
public InvertFilterTransformation(Context context, BitmapPool pool) { @Override public String toString() {
super(context, pool, new GPUImageColorInvertFilter());
}
@Override public String getId() {
return "InvertFilterTransformation()"; return "InvertFilterTransformation()";
} }
@Override public boolean equals(Object o) {
return o instanceof InvertFilterTransformation;
}
@Override public int hashCode() {
return ID.hashCode();
}
@Override public void updateDiskCacheKey(MessageDigest messageDigest) {
messageDigest.update(ID_BYTES);
}
} }

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations.gpu; package jp.wasabeef.glide.transformations.gpu;
/** /**
* Copyright (C) 2015 Wasabeef * Copyright (C) 2018 Wasabeef
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -16,9 +16,7 @@ package jp.wasabeef.glide.transformations.gpu;
* limitations under the License. * limitations under the License.
*/ */
import android.content.Context; import java.security.MessageDigest;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import jp.co.cyberagent.android.gpuimage.GPUImageKuwaharaFilter; import jp.co.cyberagent.android.gpuimage.GPUImageKuwaharaFilter;
/** /**
@@ -29,28 +27,37 @@ import jp.co.cyberagent.android.gpuimage.GPUImageKuwaharaFilter;
*/ */
public class KuwaharaFilterTransformation extends GPUFilterTransformation { public class KuwaharaFilterTransformation extends GPUFilterTransformation {
private int mRadius; private static final int VERSION = 1;
private static final String ID =
"jp.wasabeef.glide.transformations.gpu.KuwaharaFilterTransformation." + VERSION;
private static final byte[] ID_BYTES = ID.getBytes(CHARSET);
public KuwaharaFilterTransformation(Context context) { private int radius;
this(context, Glide.get(context).getBitmapPool());
public KuwaharaFilterTransformation() {
this(25);
} }
public KuwaharaFilterTransformation(Context context, BitmapPool pool) { public KuwaharaFilterTransformation(int radius) {
this(context, pool, 25); super(new GPUImageKuwaharaFilter());
} this.radius = radius;
public KuwaharaFilterTransformation(Context context, int radius) {
this(context, Glide.get(context).getBitmapPool(), radius);
}
public KuwaharaFilterTransformation(Context context, BitmapPool pool, int radius) {
super(context, pool, new GPUImageKuwaharaFilter());
mRadius = radius;
GPUImageKuwaharaFilter filter = getFilter(); GPUImageKuwaharaFilter filter = getFilter();
filter.setRadius(mRadius); filter.setRadius(this.radius);
} }
@Override public String getId() { @Override public String toString() {
return "KuwaharaFilterTransformation(radius=" + mRadius + ")"; return "KuwaharaFilterTransformation(radius=" + radius + ")";
}
@Override public boolean equals(Object o) {
return o instanceof KuwaharaFilterTransformation;
}
@Override public int hashCode() {
return ID.hashCode();
}
@Override public void updateDiskCacheKey(MessageDigest messageDigest) {
messageDigest.update(ID_BYTES);
} }
} }

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations.gpu; package jp.wasabeef.glide.transformations.gpu;
/** /**
* Copyright (C) 2015 Wasabeef * Copyright (C) 2018 Wasabeef
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -16,9 +16,7 @@ package jp.wasabeef.glide.transformations.gpu;
* limitations under the License. * limitations under the License.
*/ */
import android.content.Context; import java.security.MessageDigest;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import jp.co.cyberagent.android.gpuimage.GPUImagePixelationFilter; import jp.co.cyberagent.android.gpuimage.GPUImagePixelationFilter;
/** /**
@@ -28,28 +26,37 @@ import jp.co.cyberagent.android.gpuimage.GPUImagePixelationFilter;
*/ */
public class PixelationFilterTransformation extends GPUFilterTransformation { public class PixelationFilterTransformation extends GPUFilterTransformation {
private float mPixel; private static final int VERSION = 1;
private static final String ID =
"jp.wasabeef.glide.transformations.gpu.PixelationFilterTransformation." + VERSION;
private static final byte[] ID_BYTES = ID.getBytes(CHARSET);
public PixelationFilterTransformation(Context context) { private float pixel;
this(context, Glide.get(context).getBitmapPool());
public PixelationFilterTransformation() {
this(10f);
} }
public PixelationFilterTransformation(Context context, BitmapPool pool) { public PixelationFilterTransformation(float pixel) {
this(context, pool, 10f); super(new GPUImagePixelationFilter());
} this.pixel = pixel;
public PixelationFilterTransformation(Context context, float pixel) {
this(context, Glide.get(context).getBitmapPool(), pixel);
}
public PixelationFilterTransformation(Context context, BitmapPool pool, float pixel) {
super(context, pool, new GPUImagePixelationFilter());
mPixel = pixel;
GPUImagePixelationFilter filter = getFilter(); GPUImagePixelationFilter filter = getFilter();
filter.setPixel(mPixel); filter.setPixel(this.pixel);
} }
@Override public String getId() { @Override public String toString() {
return "PixelationFilterTransformation(pixel=" + mPixel + ")"; return "PixelationFilterTransformation(pixel=" + pixel + ")";
}
@Override public boolean equals(Object o) {
return o instanceof PixelationFilterTransformation;
}
@Override public int hashCode() {
return ID.hashCode();
}
@Override public void updateDiskCacheKey(MessageDigest messageDigest) {
messageDigest.update(ID_BYTES);
} }
} }

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations.gpu; package jp.wasabeef.glide.transformations.gpu;
/** /**
* Copyright (C) 2015 Wasabeef * Copyright (C) 2018 Wasabeef
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -16,9 +16,7 @@ package jp.wasabeef.glide.transformations.gpu;
* limitations under the License. * limitations under the License.
*/ */
import android.content.Context; import java.security.MessageDigest;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import jp.co.cyberagent.android.gpuimage.GPUImageSepiaFilter; import jp.co.cyberagent.android.gpuimage.GPUImageSepiaFilter;
/** /**
@@ -28,28 +26,37 @@ import jp.co.cyberagent.android.gpuimage.GPUImageSepiaFilter;
*/ */
public class SepiaFilterTransformation extends GPUFilterTransformation { public class SepiaFilterTransformation extends GPUFilterTransformation {
private float mIntensity; private static final int VERSION = 1;
private static final String ID =
"jp.wasabeef.glide.transformations.gpu.SepiaFilterTransformation." + VERSION;
private static final byte[] ID_BYTES = ID.getBytes(CHARSET);
public SepiaFilterTransformation(Context context) { private float intensity;
this(context, Glide.get(context).getBitmapPool());
public SepiaFilterTransformation() {
this(1.0f);
} }
public SepiaFilterTransformation(Context context, BitmapPool pool) { public SepiaFilterTransformation(float intensity) {
this(context, pool, 1.0f); super(new GPUImageSepiaFilter());
} this.intensity = intensity;
public SepiaFilterTransformation(Context context, float intensity) {
this(context, Glide.get(context).getBitmapPool(), intensity);
}
public SepiaFilterTransformation(Context context, BitmapPool pool, float intensity) {
super(context, pool, new GPUImageSepiaFilter());
mIntensity = intensity;
GPUImageSepiaFilter filter = getFilter(); GPUImageSepiaFilter filter = getFilter();
filter.setIntensity(mIntensity); filter.setIntensity(this.intensity);
} }
@Override public String getId() { @Override public String toString() {
return "SepiaFilterTransformation(intensity=" + mIntensity + ")"; return "SepiaFilterTransformation(intensity=" + intensity + ")";
}
@Override public boolean equals(Object o) {
return o instanceof SepiaFilterTransformation;
}
@Override public int hashCode() {
return ID.hashCode();
}
@Override public void updateDiskCacheKey(MessageDigest messageDigest) {
messageDigest.update(ID_BYTES);
} }
} }

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations.gpu; package jp.wasabeef.glide.transformations.gpu;
/** /**
* Copyright (C) 2015 Wasabeef * Copyright (C) 2018 Wasabeef
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -16,22 +16,33 @@ package jp.wasabeef.glide.transformations.gpu;
* limitations under the License. * limitations under the License.
*/ */
import android.content.Context; import java.security.MessageDigest;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import jp.co.cyberagent.android.gpuimage.GPUImageSketchFilter; import jp.co.cyberagent.android.gpuimage.GPUImageSketchFilter;
public class SketchFilterTransformation extends GPUFilterTransformation { public class SketchFilterTransformation extends GPUFilterTransformation {
public SketchFilterTransformation(Context context) { private static final int VERSION = 1;
this(context, Glide.get(context).getBitmapPool()); private static final String ID =
"jp.wasabeef.glide.transformations.gpu.SketchFilterTransformation." + VERSION;
private static final byte[] ID_BYTES = ID.getBytes(CHARSET);
public SketchFilterTransformation() {
super(new GPUImageSketchFilter());
} }
public SketchFilterTransformation(Context context, BitmapPool pool) { @Override public String toString() {
super(context, pool, new GPUImageSketchFilter());
}
@Override public String getId() {
return "SketchFilterTransformation()"; return "SketchFilterTransformation()";
} }
@Override public boolean equals(Object o) {
return o instanceof SketchFilterTransformation;
}
@Override public int hashCode() {
return ID.hashCode();
}
@Override public void updateDiskCacheKey(MessageDigest messageDigest) {
messageDigest.update(ID_BYTES);
}
} }

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations.gpu; package jp.wasabeef.glide.transformations.gpu;
/** /**
* Copyright (C) 2015 Wasabeef * Copyright (C) 2018 Wasabeef
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -16,10 +16,8 @@ package jp.wasabeef.glide.transformations.gpu;
* limitations under the License. * limitations under the License.
*/ */
import android.content.Context;
import android.graphics.PointF; import android.graphics.PointF;
import com.bumptech.glide.Glide; import java.security.MessageDigest;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import jp.co.cyberagent.android.gpuimage.GPUImageSwirlFilter; import jp.co.cyberagent.android.gpuimage.GPUImageSwirlFilter;
/** /**
@@ -27,20 +25,17 @@ import jp.co.cyberagent.android.gpuimage.GPUImageSwirlFilter;
*/ */
public class SwirlFilterTransformation extends GPUFilterTransformation { public class SwirlFilterTransformation extends GPUFilterTransformation {
private float mRadius; private static final int VERSION = 1;
private float mAngle; private static final String ID =
private PointF mCenter; "jp.wasabeef.glide.transformations.gpu.SwirlFilterTransformation." + VERSION;
private static final byte[] ID_BYTES = ID.getBytes(CHARSET);
public SwirlFilterTransformation(Context context) { private float radius;
this(context, Glide.get(context).getBitmapPool()); private float angle;
} private PointF center;
public SwirlFilterTransformation(Context context, BitmapPool pool) { public SwirlFilterTransformation() {
this(context, pool, .5f, 1.0f, new PointF(0.5f, 0.5f)); this(.5f, 1.0f, new PointF(0.5f, 0.5f));
}
public SwirlFilterTransformation(Context context, float radius, float angle, PointF center) {
this(context, Glide.get(context).getBitmapPool(), radius, angle, center);
} }
/** /**
@@ -48,20 +43,31 @@ public class SwirlFilterTransformation extends GPUFilterTransformation {
* @param angle minimum 0.0, default 1.0 * @param angle minimum 0.0, default 1.0
* @param center default (0.5, 0.5) * @param center default (0.5, 0.5)
*/ */
public SwirlFilterTransformation(Context context, BitmapPool pool, float radius, float angle, public SwirlFilterTransformation(float radius, float angle, PointF center) {
PointF center) { super(new GPUImageSwirlFilter());
super(context, pool, new GPUImageSwirlFilter()); this.radius = radius;
mRadius = radius; this.angle = angle;
mAngle = angle; this.center = center;
mCenter = center;
GPUImageSwirlFilter filter = getFilter(); GPUImageSwirlFilter filter = getFilter();
filter.setRadius(mRadius); filter.setRadius(this.radius);
filter.setAngle(mAngle); filter.setAngle(this.angle);
filter.setCenter(mCenter); filter.setCenter(this.center);
} }
@Override public String getId() { @Override public String toString() {
return "SwirlFilterTransformation(radius=" + mRadius + return "SwirlFilterTransformation(radius=" + radius + ",angle=" + angle + ",center="
",angle=" + mAngle + ",center=" + mCenter.toString() + ")"; + center.toString() + ")";
}
@Override public boolean equals(Object o) {
return o instanceof SwirlFilterTransformation;
}
@Override public int hashCode() {
return ID.hashCode();
}
@Override public void updateDiskCacheKey(MessageDigest messageDigest) {
messageDigest.update(ID_BYTES);
} }
} }

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations.gpu; package jp.wasabeef.glide.transformations.gpu;
/** /**
* Copyright (C) 2015 Wasabeef * Copyright (C) 2018 Wasabeef
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -16,9 +16,7 @@ package jp.wasabeef.glide.transformations.gpu;
* limitations under the License. * limitations under the License.
*/ */
import android.content.Context; import java.security.MessageDigest;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import jp.co.cyberagent.android.gpuimage.GPUImageToonFilter; import jp.co.cyberagent.android.gpuimage.GPUImageToonFilter;
/** /**
@@ -28,33 +26,41 @@ import jp.co.cyberagent.android.gpuimage.GPUImageToonFilter;
*/ */
public class ToonFilterTransformation extends GPUFilterTransformation { public class ToonFilterTransformation extends GPUFilterTransformation {
private float mThreshold; private static final int VERSION = 1;
private float mQuantizationLevels; private static final String ID =
"jp.wasabeef.glide.transformations.gpu.ToonFilterTransformation." + VERSION;
private static final byte[] ID_BYTES = ID.getBytes(CHARSET);
public ToonFilterTransformation(Context context) { private float threshold;
this(context, Glide.get(context).getBitmapPool()); private float quantizationLevels;
public ToonFilterTransformation() {
this(.2f, 10.0f);
} }
public ToonFilterTransformation(Context context, BitmapPool pool) { public ToonFilterTransformation(float threshold, float quantizationLevels) {
this(context, pool, .2f, 10.0f); super(new GPUImageToonFilter());
} this.threshold = threshold;
this.quantizationLevels = quantizationLevels;
public ToonFilterTransformation(Context context, float threshold, float quantizationLevels) {
this(context, Glide.get(context).getBitmapPool(), threshold, quantizationLevels);
}
public ToonFilterTransformation(Context context, BitmapPool pool, float threshold,
float quantizationLevels) {
super(context, pool, new GPUImageToonFilter());
mThreshold = threshold;
mQuantizationLevels = quantizationLevels;
GPUImageToonFilter filter = getFilter(); GPUImageToonFilter filter = getFilter();
filter.setThreshold(mThreshold); filter.setThreshold(this.threshold);
filter.setQuantizationLevels(mQuantizationLevels); filter.setQuantizationLevels(this.quantizationLevels);
} }
@Override public String getId() { @Override public String toString() {
return "ToonFilterTransformation(threshold=" + mThreshold + return "ToonFilterTransformation(threshold=" + threshold + ",quantizationLevels="
",quantizationLevels=" + mQuantizationLevels + ")"; + quantizationLevels + ")";
}
@Override public boolean equals(Object o) {
return o instanceof ToonFilterTransformation;
}
@Override public int hashCode() {
return ID.hashCode();
}
@Override public void updateDiskCacheKey(MessageDigest messageDigest) {
messageDigest.update(ID_BYTES);
} }
} }

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations.gpu; package jp.wasabeef.glide.transformations.gpu;
/** /**
* Copyright (C) 2015 Wasabeef * Copyright (C) 2018 Wasabeef
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -16,10 +16,8 @@ package jp.wasabeef.glide.transformations.gpu;
* limitations under the License. * limitations under the License.
*/ */
import android.content.Context;
import android.graphics.PointF; import android.graphics.PointF;
import com.bumptech.glide.Glide; import java.security.MessageDigest;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import java.util.Arrays; import java.util.Arrays;
import jp.co.cyberagent.android.gpuimage.GPUImageVignetteFilter; import jp.co.cyberagent.android.gpuimage.GPUImageVignetteFilter;
@@ -30,41 +28,47 @@ import jp.co.cyberagent.android.gpuimage.GPUImageVignetteFilter;
*/ */
public class VignetteFilterTransformation extends GPUFilterTransformation { public class VignetteFilterTransformation extends GPUFilterTransformation {
private PointF mCenter; private static final int VERSION = 1;
private float[] mVignetteColor; private static final String ID =
private float mVignetteStart; "jp.wasabeef.glide.transformations.gpu.VignetteFilterTransformation." + VERSION;
private float mVignetteEnd; private static final byte[] ID_BYTES = ID.getBytes(CHARSET);
public VignetteFilterTransformation(Context context) { private PointF center;
this(context, Glide.get(context).getBitmapPool()); private float[] vignetteColor;
private float vignetteStart;
private float vignetteEnd;
public VignetteFilterTransformation() {
this(new PointF(0.5f, 0.5f), new float[] { 0.0f, 0.0f, 0.0f }, 0.0f, 0.75f);
} }
public VignetteFilterTransformation(Context context, BitmapPool pool) { public VignetteFilterTransformation(PointF center, float[] color, float start, float end) {
this(context, pool, new PointF(0.5f, 0.5f), new float[] { 0.0f, 0.0f, 0.0f }, 0.0f, 0.75f); super(new GPUImageVignetteFilter());
} this.center = center;
vignetteColor = color;
public VignetteFilterTransformation(Context context, PointF center, float[] color, float start, vignetteStart = start;
float end) { vignetteEnd = end;
this(context, Glide.get(context).getBitmapPool(), center, color, start, end);
}
public VignetteFilterTransformation(Context context, BitmapPool pool, PointF center,
float[] color, float start, float end) {
super(context, pool, new GPUImageVignetteFilter());
mCenter = center;
mVignetteColor = color;
mVignetteStart = start;
mVignetteEnd = end;
GPUImageVignetteFilter filter = getFilter(); GPUImageVignetteFilter filter = getFilter();
filter.setVignetteCenter(mCenter); filter.setVignetteCenter(this.center);
filter.setVignetteColor(mVignetteColor); filter.setVignetteColor(vignetteColor);
filter.setVignetteStart(mVignetteStart); filter.setVignetteStart(vignetteStart);
filter.setVignetteEnd(mVignetteEnd); filter.setVignetteEnd(vignetteEnd);
} }
@Override public String getId() { @Override public String toString() {
return "VignetteFilterTransformation(center=" + mCenter.toString() + return "VignetteFilterTransformation(center=" + center.toString() + ",color=" + Arrays.toString(
",color=" + Arrays.toString(mVignetteColor) + vignetteColor) + ",start=" + vignetteStart + ",end=" + vignetteEnd + ")";
",start=" + mVignetteStart + ",end=" + mVignetteEnd + ")"; }
@Override public boolean equals(Object o) {
return o instanceof VignetteFilterTransformation;
}
@Override public int hashCode() {
return ID.hashCode();
}
@Override public void updateDiskCacheKey(MessageDigest messageDigest) {
messageDigest.update(ID_BYTES);
} }
} }

View File

@@ -3,7 +3,7 @@ package jp.wasabeef.glide.transformations.internal;
import android.graphics.Bitmap; import android.graphics.Bitmap;
/** /**
* Copyright (C) 2015 Wasabeef * Copyright (C) 2018 Wasabeef
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -20,7 +20,7 @@ import android.graphics.Bitmap;
public class FastBlur { public class FastBlur {
public static Bitmap doBlur(Bitmap sentBitmap, int radius, boolean canReuseInBitmap) { public static Bitmap blur(Bitmap sentBitmap, int radius, boolean canReuseInBitmap) {
// Stack Blur v1.0 from // Stack Blur v1.0 from
// http://www.quasimondo.com/StackBlurForCanvas/StackBlurDemo.html // http://www.quasimondo.com/StackBlurForCanvas/StackBlurDemo.html

View File

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

View File

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