mirror of
https://github.com/wasabeef/glide-transformations.git
synced 2025-10-05 18:53:20 +08:00
Compare commits
111 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
c3f09cdd0d | ||
|
ddd76d4f06 | ||
|
f9bca8887d | ||
|
592815a6a0 | ||
|
f6540b111f | ||
|
9bea464afc | ||
|
219b32bbcc | ||
|
4d7190847c | ||
|
0d7a93c264 | ||
|
e69f775ddd | ||
|
4b9cf87770 | ||
|
cafad91b0b | ||
|
933c3f7989 | ||
|
68bafb0f53 | ||
|
817b138980 | ||
|
a908abc7d4 | ||
|
3e0738de0a | ||
|
dff7328f6e | ||
|
f5cb7392d6 | ||
|
d8a12b02b8 | ||
|
a6a2b625ad | ||
|
f488f09b19 | ||
|
76b7e3b719 | ||
|
c29df80ae9 | ||
|
aef7541ea3 | ||
|
71255edcd0 | ||
|
4a268b6dbd | ||
|
eef0be6b92 | ||
|
260f91e291 | ||
|
36ceccb38e | ||
|
e3a035d5cb | ||
|
656ea50911 | ||
|
e2cf4fd7eb | ||
|
e387df2daa | ||
|
5b311f74f6 | ||
|
62f3ee6b4a | ||
|
3150b4c8d5 | ||
|
410d94b7b1 | ||
|
a559d8bea8 | ||
|
4629d5e375 | ||
|
113200de55 | ||
|
143efe2ea7 | ||
|
fe864e498b | ||
|
f2f1229c8d | ||
|
f1246ff9ee | ||
|
d063aac6fa | ||
|
cb3cd88ed2 | ||
|
57fcfce9df | ||
|
347326dafa | ||
|
b4332f8c8d | ||
|
39b9d6aa6b | ||
|
2c08c1fb5e | ||
|
abde4c694d | ||
|
d5616ec9fa | ||
|
1253147c4a | ||
|
7614f1326a | ||
|
5cf3e3d934 | ||
|
efc447d2f7 | ||
|
23b623c882 | ||
|
f9ea19aaae | ||
|
831f038d29 | ||
|
eed7b944e5 | ||
|
46d5d4d72f | ||
|
6ebfdbe581 | ||
|
2a4eb22841 | ||
|
2cc2104802 | ||
|
f83e5ef85a | ||
|
cdbd42595a | ||
|
987651f9da | ||
|
ad376134e9 | ||
|
3f695c1e9c | ||
|
58e25e613c | ||
|
c914548296 | ||
|
cfe6dc313a | ||
|
136a5512c0 | ||
|
32d0c1de82 | ||
|
e23753044e | ||
|
decd2e58d5 | ||
|
e9d2c6d209 | ||
|
79e975d490 | ||
|
a21cfb1d86 | ||
|
c0ab4282d9 | ||
|
15effa238b | ||
|
ef39ca2782 | ||
|
bdda7cdf36 | ||
|
3890c84a0f | ||
|
e3c0c8d597 | ||
|
f7d0541a19 | ||
|
900db8bc93 | ||
|
c241532a58 | ||
|
8f63c10eb9 | ||
|
6468276c50 | ||
|
e0fb7c34e0 | ||
|
4c23e38206 | ||
|
ffae37274c | ||
|
0c6f696ba7 | ||
|
3aea08abaa | ||
|
883c131ad6 | ||
|
ee1f533999 | ||
|
68a9097962 | ||
|
6269999abc | ||
|
7e93ccd9af | ||
|
07b7d24e13 | ||
|
ca648cbc7d | ||
|
67ac3e31a4 | ||
|
1534573e8f | ||
|
a5487ade83 | ||
|
62abca0b1e | ||
|
a6bbdb0694 | ||
|
2f75284dd4 | ||
|
5772f60c61 |
89
CHANGELOG.md
89
CHANGELOG.md
@@ -1,6 +1,95 @@
|
|||||||
Change Log
|
Change Log
|
||||||
==========
|
==========
|
||||||
|
|
||||||
|
Version 2.0.1 *(2016-04-21)*
|
||||||
|
----------------------------
|
||||||
|
|
||||||
|
Fix:
|
||||||
|
[#35](https://github.com/wasabeef/glide-transformations/issues/35)
|
||||||
|
RSInvalidStateException
|
||||||
|
|
||||||
|
Version 2.0.0 *(2016-03-02)*
|
||||||
|
----------------------------
|
||||||
|
|
||||||
|
Say v8.RenderScript goodbye
|
||||||
|
|
||||||
|
Version 1.4.0 *(2016-02-28)*
|
||||||
|
----------------------------
|
||||||
|
|
||||||
|
fix Issue [#29](https://github.com/wasabeef/glide-transformations/issues/29)
|
||||||
|
Use FastBlur as a fallback upon RenderScript failure.
|
||||||
|
|
||||||
|
Version 1.3.1 *(2015-11-27)*
|
||||||
|
----------------------------
|
||||||
|
|
||||||
|
Change the renderscriptTargetApi down to 20.
|
||||||
|
Warning:Renderscript support mode is not currently supported with renderscript target 21+
|
||||||
|
|
||||||
|
fix: memory leak.
|
||||||
|
|
||||||
|
Version 1.3.0 *(2015-11-10)*
|
||||||
|
----------------------------
|
||||||
|
|
||||||
|
add round corner type to RoundedCornersTransformation.
|
||||||
|
Thanks to [kaelaela](https://github.com/kaelaela)
|
||||||
|
|
||||||
|
Version 1.2.1 *(2015-09-18)*
|
||||||
|
----------------------------
|
||||||
|
|
||||||
|
Merged NinePatchMaskTransformation to MaskTransformation.
|
||||||
|
|
||||||
|
Version 1.2.0 *(2015-09-16)*
|
||||||
|
----------------------------
|
||||||
|
|
||||||
|
add new transformations MaskTransformation and NinePatchMaskTransformation.
|
||||||
|
Thanks to [start141](https://github.com/start141)
|
||||||
|
|
||||||
|
Version 1.1.0 *(2015-09-05)*
|
||||||
|
----------------------------
|
||||||
|
|
||||||
|
Adjustment of default parameters.
|
||||||
|
|
||||||
|
Version 1.0.8 *(2015-07-24)*
|
||||||
|
----------------------------
|
||||||
|
|
||||||
|
add DownSampling to BlurTransform
|
||||||
|
|
||||||
|
Version 1.0.7 *(2015-07-18)*
|
||||||
|
----------------------------
|
||||||
|
|
||||||
|
Bug fix : Blur not working.
|
||||||
|
|
||||||
|
Version 1.0.6 *(2015-04-23)*
|
||||||
|
----------------------------
|
||||||
|
|
||||||
|
add: CropType(Top, Center, Bottom) for CropTransformation.
|
||||||
|
|
||||||
|
Version 1.0.5 *(2015-03-09)*
|
||||||
|
----------------------------
|
||||||
|
|
||||||
|
Bug fix: Transparency.
|
||||||
|
|
||||||
|
Version 1.0.4 *(2015-02-13)*
|
||||||
|
----------------------------
|
||||||
|
|
||||||
|
Bug fix : remove original bitmap resource recycling.
|
||||||
|
|
||||||
|
Version 1.0.3 *(2015-02-05)*
|
||||||
|
----------------------------
|
||||||
|
|
||||||
|
Bug fix
|
||||||
|
|
||||||
|
Version 1.0.2 *(2015-02-04)*
|
||||||
|
----------------------------
|
||||||
|
|
||||||
|
Refactor: use BimapPool
|
||||||
|
|
||||||
|
Version 1.0.1 *(2015-01-21)*
|
||||||
|
----------------------------
|
||||||
|
|
||||||
|
fix: Blur Transformation now woking at Android 4.3
|
||||||
|
add: GPUImage to Gradle dependency
|
||||||
|
|
||||||
Version 1.0.0 *(2015-01-12)*
|
Version 1.0.0 *(2015-01-12)*
|
||||||
----------------------------
|
----------------------------
|
||||||
|
|
||||||
|
64
README.md
64
README.md
@@ -9,8 +9,9 @@ An Android transformation library providing a variety of image transformations f
|
|||||||
Please feel free to use this.
|
Please feel free to use this.
|
||||||
|
|
||||||
|
|
||||||
#### Are you using Picasso?
|
#### Are you using Picasso or Fresco?
|
||||||
[Picasso Transformations](https://github.com/wasabeef/picasso-transformations)
|
[Picasso Transformations](https://github.com/wasabeef/picasso-transformations)
|
||||||
|
[Fresco Processors](https://github.com/wasabeef/fresco-processors)
|
||||||
|
|
||||||
# Demo
|
# Demo
|
||||||
|
|
||||||
@@ -32,8 +33,9 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile 'jp.wasabeef:glide-transformations:1.0.1'
|
compile 'jp.wasabeef:glide-transformations:2.0.1'
|
||||||
compile 'jp.co.cyberagent.android.gpuimage:gpuimage-library:1.2.3'
|
// If you want to use the GPU Filters
|
||||||
|
compile 'jp.co.cyberagent.android.gpuimage:gpuimage-library:1.3.0'
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -43,7 +45,7 @@ Set Glide Transform.
|
|||||||
|
|
||||||
```java
|
```java
|
||||||
Glide.with(this).load(R.drawable.demo)
|
Glide.with(this).load(R.drawable.demo)
|
||||||
.bitmapTransform(new BlurTransformation(this, Glide.get(this).getBitmapPool()))
|
.bitmapTransform(new BlurTransformation(context))
|
||||||
.into((ImageView) findViewById(R.id.image));
|
.into((ImageView) findViewById(R.id.image));
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -52,31 +54,16 @@ Glide.with(this).load(R.drawable.demo)
|
|||||||
You can set a multiple transformations.
|
You can set a multiple transformations.
|
||||||
|
|
||||||
```java
|
```java
|
||||||
BitmapPool pool = Glide.get(this).getBitmapPool();
|
Glide.with(this).load(R.drawable.demo)
|
||||||
Glide.with(this).load(R.drawable.demo).bitmapTransform(
|
.bitmapTransform(new BlurTransformation(context, 25), new CropCircleTransformation(context))
|
||||||
new BlurTransformation(this, pool, 5), new CropCircleTransformation(pool))
|
|
||||||
.into((ImageView) findViewById(R.id.image));
|
.into((ImageView) findViewById(R.id.image));
|
||||||
```
|
```
|
||||||
|
|
||||||
## Step 4
|
|
||||||
|
|
||||||
If you are using `BlurTransformation`.
|
|
||||||
|
|
||||||
```groovy
|
|
||||||
android {
|
|
||||||
...
|
|
||||||
defaultConfig {
|
|
||||||
...
|
|
||||||
renderscriptTargetApi 21
|
|
||||||
renderscriptSupportModeEnabled true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Transformations
|
## Transformations
|
||||||
|
|
||||||
### Crop
|
### Crop
|
||||||
`CropTransformation`, `CropCircleTransformation`, `CropSquareTransformation`
|
`CropTransformation`, `CropCircleTransformation`, `CropSquareTransformation`,
|
||||||
|
`RoundedCornersTransformation`
|
||||||
|
|
||||||
### Color
|
### Color
|
||||||
`ColorFilterTransformation`, `GrayscaleTransformation`
|
`ColorFilterTransformation`, `GrayscaleTransformation`
|
||||||
@@ -84,13 +71,26 @@ android {
|
|||||||
### Blur
|
### Blur
|
||||||
`BlurTransformation`
|
`BlurTransformation`
|
||||||
|
|
||||||
### Filter (use [GPUImage](https://github.com/CyberAgent/android-gpuimage))
|
### Mask
|
||||||
|
`MaskTransformation`
|
||||||
|
|
||||||
|
### GPU Filter (use [GPUImage](https://github.com/CyberAgent/android-gpuimage))
|
||||||
|
**Will require add dependencies for GPUImage.**
|
||||||
|
|
||||||
`ToonFilterTransformation`, `SepiaFilterTransformation`, `ContrastFilterTransformation`
|
`ToonFilterTransformation`, `SepiaFilterTransformation`, `ContrastFilterTransformation`
|
||||||
`InvertFilterTransformation`, `PixelationFilterTransformation`, `SketchFilterTransformation`
|
`InvertFilterTransformation`, `PixelationFilterTransformation`, `SketchFilterTransformation`
|
||||||
`SwirlFilterTransformation`, `KuwaharaFilterTransformation`, `VignetteFilterTransformation`
|
`SwirlFilterTransformation`, `BrightnessFilterTransformation`, `KuwaharaFilterTransformation`
|
||||||
|
`VignetteFilterTransformation`
|
||||||
|
|
||||||
### Other
|
|
||||||
`RoundedCornersTransformation`
|
Applications using Glide Transformations
|
||||||
|
---
|
||||||
|
|
||||||
|
Please [ping](mailto:dadadada.chop@gmail.com) me or send a pull request if you would like to be added here.
|
||||||
|
|
||||||
|
Icon | Application
|
||||||
|
------------ | -------------
|
||||||
|
<img src="https://lh6.ggpht.com/6zKH_uQY1bxCwXL4DLo_uoFEOXdShi3BgmN6XRHlaJ-oA1svmq6y1PZkmO50nWQn2Lg=w300-rw" width="48" height="48" /> | [Ameba Ownd](https://play.google.com/store/apps/details?id=jp.co.cyberagent.madrid)
|
||||||
|
|
||||||
Developed By
|
Developed By
|
||||||
-------
|
-------
|
||||||
@@ -101,6 +101,16 @@ Daichi Furiya (Wasabeef) - <dadadada.chop@gmail.com>
|
|||||||
src="https://raw.githubusercontent.com/wasabeef/art/master/twitter.png" width="75"/>
|
src="https://raw.githubusercontent.com/wasabeef/art/master/twitter.png" width="75"/>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
|
Contributions
|
||||||
|
-------
|
||||||
|
|
||||||
|
Any contributions are welcome!
|
||||||
|
|
||||||
|
Contributers
|
||||||
|
-------
|
||||||
|
|
||||||
|
* [start141](https://github.com/start141)
|
||||||
|
|
||||||
Thanks
|
Thanks
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
BIN
art/demo.gif
BIN
art/demo.gif
Binary file not shown.
Before Width: | Height: | Size: 9.9 MiB After Width: | Height: | Size: 3.9 MiB |
@@ -5,11 +5,8 @@ buildscript {
|
|||||||
jcenter()
|
jcenter()
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:1.0.+'
|
classpath 'com.android.tools.build:gradle:2.0.0'
|
||||||
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
|
classpath 'com.novoda:bintray-release:0.3.4'
|
||||||
|
|
||||||
// NOTE: Do not place your application dependencies here; they belong
|
|
||||||
// in the individual module build.gradle files
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -7,10 +7,8 @@ android {
|
|||||||
defaultConfig {
|
defaultConfig {
|
||||||
minSdkVersion MIN_SDK_VERSION as int
|
minSdkVersion MIN_SDK_VERSION as int
|
||||||
targetSdkVersion TARGET_SDK_VERSION as int
|
targetSdkVersion TARGET_SDK_VERSION as int
|
||||||
versionCode VERSION_CODE as int
|
versionCode "git rev-list origin/master --count".execute().text.toInteger()
|
||||||
versionName VERSION_NAME
|
versionName VERSION_NAME
|
||||||
renderscriptTargetApi RENDERSCRIPT_TARGET_API as int
|
|
||||||
renderscriptSupportModeEnabled true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
signingConfigs {
|
signingConfigs {
|
||||||
@@ -53,9 +51,8 @@ def getKeyAliasPasswordProperty() {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile project(':transformations')
|
compile project(':transformations')
|
||||||
// compile 'jp.wasabeef:glide-transformations:1.0.1'
|
compile "com.github.bumptech.glide:glide:${GLIDE_VERSION}"
|
||||||
compile 'jp.co.cyberagent.android.gpuimage:gpuimage-library:1.2.3'
|
compile "jp.co.cyberagent.android.gpuimage:gpuimage-library:${GPUIMAGE_VERSION}"
|
||||||
compile 'com.android.support:appcompat-v7:+'
|
compile "com.android.support:appcompat-v7:${SUPPORT_PACKAGE_VERSION}"
|
||||||
compile 'com.android.support:recyclerview-v7:21.+'
|
compile "com.android.support:recyclerview-v7:${SUPPORT_PACKAGE_VERSION}"
|
||||||
compile 'com.github.bumptech.glide:glide:3.+'
|
|
||||||
}
|
}
|
||||||
|
@@ -1,19 +1,22 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="jp.wasabeef.example.glide" >
|
package="jp.wasabeef.example.glide"
|
||||||
|
>
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
android:icon="@drawable/ic_launcher"
|
android:icon="@drawable/ic_launcher"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:theme="@style/AppTheme" >
|
android:theme="@style/AppTheme"
|
||||||
|
>
|
||||||
<activity
|
<activity
|
||||||
android:name=".MainActivity"
|
android:name=".MainActivity"
|
||||||
android:label="@string/app_name" >
|
android:label="@string/app_name"
|
||||||
|
>
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN"/>
|
||||||
|
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER"/>
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
</application>
|
</application>
|
||||||
|
@@ -1,20 +1,16 @@
|
|||||||
package jp.wasabeef.example.glide;
|
package jp.wasabeef.example.glide;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v7.app.ActionBarActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.support.v7.widget.GridLayoutManager;
|
import android.support.v7.widget.GridLayoutManager;
|
||||||
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;
|
||||||
|
|
||||||
import jp.wasabeef.example.glide.MainAdapter.Type;
|
import jp.wasabeef.example.glide.MainAdapter.Type;
|
||||||
|
|
||||||
|
public class MainActivity extends AppCompatActivity {
|
||||||
|
|
||||||
public class MainActivity extends ActionBarActivity {
|
@Override protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
|
|
||||||
@@ -22,7 +18,11 @@ public class MainActivity extends ActionBarActivity {
|
|||||||
recyclerView.setLayoutManager(new GridLayoutManager(this, 2));
|
recyclerView.setLayoutManager(new GridLayoutManager(this, 2));
|
||||||
|
|
||||||
List<Type> dataSet = new ArrayList<>();
|
List<Type> dataSet = new ArrayList<>();
|
||||||
dataSet.add(Type.Crop);
|
dataSet.add(Type.Mask);
|
||||||
|
dataSet.add(Type.NinePatchMask);
|
||||||
|
dataSet.add(Type.CropTop);
|
||||||
|
dataSet.add(Type.CropCenter);
|
||||||
|
dataSet.add(Type.CropBottom);
|
||||||
dataSet.add(Type.CropSquare);
|
dataSet.add(Type.CropSquare);
|
||||||
dataSet.add(Type.CropCircle);
|
dataSet.add(Type.CropCircle);
|
||||||
dataSet.add(Type.ColorFilter);
|
dataSet.add(Type.ColorFilter);
|
||||||
|
@@ -1,11 +1,6 @@
|
|||||||
package jp.wasabeef.example.glide;
|
package jp.wasabeef.example.glide;
|
||||||
|
|
||||||
import com.bumptech.glide.Glide;
|
|
||||||
import com.bumptech.glide.load.Transformation;
|
|
||||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Bitmap;
|
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.graphics.PointF;
|
import android.graphics.PointF;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
@@ -14,15 +9,16 @@ import android.view.View;
|
|||||||
import android.view.ViewGroup;
|
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.load.resource.bitmap.CenterCrop;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import jp.wasabeef.glide.transformations.BlurTransformation;
|
import jp.wasabeef.glide.transformations.BlurTransformation;
|
||||||
import jp.wasabeef.glide.transformations.ColorFilterTransformation;
|
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.GrayscaleTransformation;
|
import jp.wasabeef.glide.transformations.GrayscaleTransformation;
|
||||||
|
import jp.wasabeef.glide.transformations.MaskTransformation;
|
||||||
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
|
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
|
||||||
import jp.wasabeef.glide.transformations.gpu.BrightnessFilterTransformation;
|
import jp.wasabeef.glide.transformations.gpu.BrightnessFilterTransformation;
|
||||||
import jp.wasabeef.glide.transformations.gpu.ContrastFilterTransformation;
|
import jp.wasabeef.glide.transformations.gpu.ContrastFilterTransformation;
|
||||||
@@ -42,10 +38,13 @@ public class MainAdapter extends RecyclerView.Adapter<MainAdapter.ViewHolder> {
|
|||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private List<Type> mDataSet;
|
private List<Type> mDataSet;
|
||||||
private BitmapPool mPool;
|
|
||||||
|
|
||||||
enum Type {
|
enum Type {
|
||||||
Crop,
|
Mask,
|
||||||
|
NinePatchMask,
|
||||||
|
CropTop,
|
||||||
|
CropCenter,
|
||||||
|
CropBottom,
|
||||||
CropSquare,
|
CropSquare,
|
||||||
CropCircle,
|
CropCircle,
|
||||||
ColorFilter,
|
ColorFilter,
|
||||||
@@ -67,82 +66,162 @@ public class MainAdapter extends RecyclerView.Adapter<MainAdapter.ViewHolder> {
|
|||||||
public MainAdapter(Context context, List<Type> dataSet) {
|
public MainAdapter(Context context, List<Type> dataSet) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mDataSet = dataSet;
|
mDataSet = dataSet;
|
||||||
mPool = Glide.get(mContext).getBitmapPool();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public MainAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||||
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(mContext)
|
|
||||||
.inflate(R.layout.layout_list_item, parent, false);
|
|
||||||
return new ViewHolder(v);
|
return new ViewHolder(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void onBindViewHolder(MainAdapter.ViewHolder holder, int position) {
|
||||||
public void onBindViewHolder(MainAdapter.ViewHolder holder, int position) {
|
|
||||||
Transformation<Bitmap> transformation = null;
|
|
||||||
switch (mDataSet.get(position)) {
|
switch (mDataSet.get(position)) {
|
||||||
case Crop:
|
case Mask: {
|
||||||
transformation = new CropTransformation(mPool, 300, 100);
|
int width = Utils.dip2px(mContext, 133.33f);
|
||||||
break;
|
int height = Utils.dip2px(mContext, 126.33f);
|
||||||
case CropSquare:
|
Glide.with(mContext)
|
||||||
transformation = new CropSquareTransformation(mPool);
|
.load(R.drawable.check)
|
||||||
break;
|
.override(width, height)
|
||||||
case CropCircle:
|
.bitmapTransform(new CenterCrop(mContext),
|
||||||
transformation = new CropCircleTransformation(mPool);
|
new MaskTransformation(mContext, R.drawable.mask_starfish))
|
||||||
break;
|
.into(holder.image);
|
||||||
case ColorFilter:
|
|
||||||
transformation = new ColorFilterTransformation(mPool, Color.argb(80, 255, 0, 0));
|
|
||||||
break;
|
|
||||||
case Grayscale:
|
|
||||||
transformation = new GrayscaleTransformation(mPool);
|
|
||||||
break;
|
|
||||||
case RoundedCorners:
|
|
||||||
transformation = new RoundedCornersTransformation(mPool, 100, 0);
|
|
||||||
break;
|
|
||||||
case Blur:
|
|
||||||
transformation = new BlurTransformation(mContext, mPool, 10);
|
|
||||||
break;
|
|
||||||
case Toon:
|
|
||||||
transformation = new ToonFilterTransformation(mContext, mPool);
|
|
||||||
break;
|
|
||||||
case Sepia:
|
|
||||||
transformation = new SepiaFilterTransformation(mContext, mPool);
|
|
||||||
break;
|
|
||||||
case Contrast:
|
|
||||||
transformation = new ContrastFilterTransformation(mContext, mPool, 2.0f);
|
|
||||||
break;
|
|
||||||
case Invert:
|
|
||||||
transformation = new InvertFilterTransformation(mContext, mPool);
|
|
||||||
break;
|
|
||||||
case Pixel:
|
|
||||||
transformation = new PixelationFilterTransformation(mContext, mPool, 20);
|
|
||||||
break;
|
|
||||||
case Sketch:
|
|
||||||
transformation = new SketchFilterTransformation(mContext, mPool);
|
|
||||||
break;
|
|
||||||
case Swirl:
|
|
||||||
transformation = new SwirlFilterTransformation(mContext, mPool,
|
|
||||||
0.5f, 1.0f, new PointF(0.5f, 0.5f));
|
|
||||||
break;
|
|
||||||
case Brightness:
|
|
||||||
transformation = new BrightnessFilterTransformation(mContext, mPool, 0.5f);
|
|
||||||
break;
|
|
||||||
case Kuawahara:
|
|
||||||
transformation = new KuwaharaFilterTransformation(mContext, mPool, 25);
|
|
||||||
break;
|
|
||||||
case Vignette:
|
|
||||||
transformation = new VignetteFilterTransformation(mContext, mPool,
|
|
||||||
new PointF(0.5f, 0.5f), new float[]{0.0f, 0.0f, 0.0f}, 0f, 0.75f);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case NinePatchMask: {
|
||||||
|
int width = Utils.dip2px(mContext, 150.0f);
|
||||||
|
int height = Utils.dip2px(mContext, 100.0f);
|
||||||
|
Glide.with(mContext)
|
||||||
|
.load(R.drawable.check)
|
||||||
|
.override(width, height)
|
||||||
|
.bitmapTransform(new CenterCrop(mContext),
|
||||||
|
new MaskTransformation(mContext, R.drawable.mask_chat_right))
|
||||||
|
.into(holder.image);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case CropTop:
|
||||||
|
Glide.with(mContext)
|
||||||
|
.load(R.drawable.demo)
|
||||||
|
.bitmapTransform(
|
||||||
|
new CropTransformation(mContext, 300, 100, CropTransformation.CropType.TOP))
|
||||||
|
.into(holder.image);
|
||||||
|
break;
|
||||||
|
case CropCenter:
|
||||||
|
Glide.with(mContext)
|
||||||
|
.load(R.drawable.demo)
|
||||||
|
.bitmapTransform(new CropTransformation(mContext, 300, 100))
|
||||||
|
.into(holder.image);
|
||||||
|
break;
|
||||||
|
case CropBottom:
|
||||||
|
Glide.with(mContext)
|
||||||
|
.load(R.drawable.demo)
|
||||||
|
.bitmapTransform(
|
||||||
|
new CropTransformation(mContext, 300, 100, CropTransformation.CropType.BOTTOM))
|
||||||
|
.into(holder.image);
|
||||||
|
|
||||||
Glide.with(mContext).load(R.drawable.demo)
|
break;
|
||||||
.bitmapTransform(transformation).into(holder.image);
|
case CropSquare:
|
||||||
|
Glide.with(mContext)
|
||||||
|
.load(R.drawable.demo)
|
||||||
|
.bitmapTransform(new CropSquareTransformation(mContext))
|
||||||
|
.into(holder.image);
|
||||||
|
break;
|
||||||
|
case CropCircle:
|
||||||
|
Glide.with(mContext)
|
||||||
|
.load(R.drawable.demo)
|
||||||
|
.bitmapTransform(new CropCircleTransformation(mContext))
|
||||||
|
.into(holder.image);
|
||||||
|
break;
|
||||||
|
case ColorFilter:
|
||||||
|
Glide.with(mContext)
|
||||||
|
.load(R.drawable.demo)
|
||||||
|
.bitmapTransform(new ColorFilterTransformation(mContext, Color.argb(80, 255, 0, 0)))
|
||||||
|
.into(holder.image);
|
||||||
|
break;
|
||||||
|
case Grayscale:
|
||||||
|
Glide.with(mContext)
|
||||||
|
.load(R.drawable.demo)
|
||||||
|
.bitmapTransform(new GrayscaleTransformation(mContext))
|
||||||
|
.into(holder.image);
|
||||||
|
break;
|
||||||
|
case RoundedCorners:
|
||||||
|
Glide.with(mContext)
|
||||||
|
.load(R.drawable.demo)
|
||||||
|
.bitmapTransform(new RoundedCornersTransformation(mContext, 30, 0,
|
||||||
|
RoundedCornersTransformation.CornerType.BOTTOM))
|
||||||
|
.into(holder.image);
|
||||||
|
break;
|
||||||
|
case Blur:
|
||||||
|
Glide.with(mContext)
|
||||||
|
.load(R.drawable.check)
|
||||||
|
.bitmapTransform(new BlurTransformation(mContext, 25))
|
||||||
|
.into(holder.image);
|
||||||
|
break;
|
||||||
|
case Toon:
|
||||||
|
Glide.with(mContext)
|
||||||
|
.load(R.drawable.demo)
|
||||||
|
.bitmapTransform(new ToonFilterTransformation(mContext))
|
||||||
|
.into(holder.image);
|
||||||
|
break;
|
||||||
|
case Sepia:
|
||||||
|
Glide.with(mContext)
|
||||||
|
.load(R.drawable.check)
|
||||||
|
.bitmapTransform(new SepiaFilterTransformation(mContext))
|
||||||
|
.into(holder.image);
|
||||||
|
break;
|
||||||
|
case Contrast:
|
||||||
|
Glide.with(mContext)
|
||||||
|
.load(R.drawable.check)
|
||||||
|
.bitmapTransform(new ContrastFilterTransformation(mContext, 2.0f))
|
||||||
|
.into(holder.image);
|
||||||
|
break;
|
||||||
|
case Invert:
|
||||||
|
Glide.with(mContext)
|
||||||
|
.load(R.drawable.check)
|
||||||
|
.bitmapTransform(new InvertFilterTransformation(mContext))
|
||||||
|
.into(holder.image);
|
||||||
|
break;
|
||||||
|
case Pixel:
|
||||||
|
Glide.with(mContext)
|
||||||
|
.load(R.drawable.check)
|
||||||
|
.bitmapTransform(new PixelationFilterTransformation(mContext, 20))
|
||||||
|
.into(holder.image);
|
||||||
|
break;
|
||||||
|
case Sketch:
|
||||||
|
Glide.with(mContext)
|
||||||
|
.load(R.drawable.check)
|
||||||
|
.bitmapTransform(new SketchFilterTransformation(mContext))
|
||||||
|
.into(holder.image);
|
||||||
|
break;
|
||||||
|
case Swirl:
|
||||||
|
Glide.with(mContext)
|
||||||
|
.load(R.drawable.check)
|
||||||
|
.bitmapTransform(
|
||||||
|
new SwirlFilterTransformation(mContext, 0.5f, 1.0f, new PointF(0.5f, 0.5f)))
|
||||||
|
.into(holder.image);
|
||||||
|
break;
|
||||||
|
case Brightness:
|
||||||
|
Glide.with(mContext)
|
||||||
|
.load(R.drawable.check)
|
||||||
|
.bitmapTransform(new BrightnessFilterTransformation(mContext, 0.5f))
|
||||||
|
.into(holder.image);
|
||||||
|
break;
|
||||||
|
case Kuawahara:
|
||||||
|
Glide.with(mContext)
|
||||||
|
.load(R.drawable.check)
|
||||||
|
.bitmapTransform(new KuwaharaFilterTransformation(mContext, 25))
|
||||||
|
.into(holder.image);
|
||||||
|
break;
|
||||||
|
case Vignette:
|
||||||
|
Glide.with(mContext)
|
||||||
|
.load(R.drawable.check)
|
||||||
|
.bitmapTransform(new VignetteFilterTransformation(mContext, new PointF(0.5f, 0.5f),
|
||||||
|
new float[] { 0.0f, 0.0f, 0.0f }, 0f, 0.75f))
|
||||||
|
.into(holder.image);
|
||||||
|
break;
|
||||||
|
}
|
||||||
holder.title.setText(mDataSet.get(position).name());
|
holder.title.setText(mDataSet.get(position).name());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public int getItemCount() {
|
||||||
public int getItemCount() {
|
|
||||||
return mDataSet.size();
|
return mDataSet.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
27
example/src/main/java/jp/wasabeef/example/glide/Utils.java
Normal file
27
example/src/main/java/jp/wasabeef/example/glide/Utils.java
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
package jp.wasabeef.example.glide;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copyright (C) 2015 Wasabeef
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
public class Utils {
|
||||||
|
|
||||||
|
public static int dip2px(Context context, float dp) {
|
||||||
|
float scale = context.getResources().getDisplayMetrics().density;
|
||||||
|
return (int) (dp * scale + 0.5f);
|
||||||
|
}
|
||||||
|
}
|
BIN
example/src/main/res/drawable-xhdpi/check.png
Normal file
BIN
example/src/main/res/drawable-xhdpi/check.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 484 KiB |
BIN
example/src/main/res/drawable-xxhdpi/mask_chat_right.9.png
Normal file
BIN
example/src/main/res/drawable-xxhdpi/mask_chat_right.9.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.9 KiB |
BIN
example/src/main/res/drawable-xxhdpi/mask_starfish.png
Normal file
BIN
example/src/main/res/drawable-xxhdpi/mask_starfish.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.6 KiB |
@@ -3,11 +3,13 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:background="#CC000000"
|
android:background="#CC000000"
|
||||||
tools:context=".MainActivity">
|
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="match_parent"
|
||||||
android:layout_height="match_parent"/>
|
android:layout_height="match_parent"
|
||||||
|
/>
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
@@ -1,16 +1,17 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="wrap_content"
|
||||||
android:padding="5dp">
|
android:padding="5dp"
|
||||||
|
>
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/image"
|
android:id="@+id/image"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_centerInParent="true"
|
android:layout_centerInParent="true"
|
||||||
android:contentDescription="@null"
|
android:contentDescription="@null"
|
||||||
android:src="@drawable/demo"/>
|
/>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/title"
|
android:id="@+id/title"
|
||||||
@@ -19,6 +20,7 @@
|
|||||||
android:layout_below="@id/image"
|
android:layout_below="@id/image"
|
||||||
android:layout_centerHorizontal="true"
|
android:layout_centerHorizontal="true"
|
||||||
android:layout_marginTop="5dp"
|
android:layout_marginTop="5dp"
|
||||||
android:textColor="@android:color/white"/>
|
android:textColor="@android:color/white"
|
||||||
|
/>
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
@@ -1,12 +1,10 @@
|
|||||||
VERSION_NAME=1.0.1
|
VERSION_NAME=2.0.1
|
||||||
VERSION_CODE=3
|
|
||||||
GROUP=jp.wasabeef
|
GROUP=jp.wasabeef
|
||||||
ARTIFACT_ID=glide-transformations
|
ARTIFACT_ID=glide-transformations
|
||||||
|
|
||||||
COMPILE_SDK_VERSION=21
|
COMPILE_SDK_VERSION=23
|
||||||
BUILD_TOOLS_VERSION=21.1.2
|
BUILD_TOOLS_VERSION=23.0.2
|
||||||
TARGET_SDK_VERSION=21
|
TARGET_SDK_VERSION=23
|
||||||
RENDERSCRIPT_TARGET_API=21
|
|
||||||
MIN_SDK_VERSION=11
|
MIN_SDK_VERSION=11
|
||||||
|
|
||||||
POM_DESCRIPTION=which provides simple Tranformations to Glide
|
POM_DESCRIPTION=which provides simple Tranformations to Glide
|
||||||
@@ -22,3 +20,7 @@ POM_DEVELOPER_NAME=Wasabeef
|
|||||||
POM_DEVELOPER_EMAIL=dadadada.chop@gmail.com
|
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.2.1
|
||||||
|
GLIDE_VERSION=3.7.0
|
||||||
|
GPUIMAGE_VERSION=1.3.0
|
3
gradle/wrapper/gradle-wrapper.properties
vendored
3
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -3,4 +3,5 @@ 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.2.1-all.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-2.12-all.zip
|
||||||
|
|
||||||
|
@@ -1,24 +0,0 @@
|
|||||||
task androidJavadocs(type: Javadoc) {
|
|
||||||
source = android.sourceSets.main.java.srcDirs
|
|
||||||
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
|
|
||||||
}
|
|
||||||
|
|
||||||
task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
|
|
||||||
classifier = 'javadoc'
|
|
||||||
from androidJavadocs.destinationDir
|
|
||||||
}
|
|
||||||
|
|
||||||
task androidSourcesJar(type: Jar) {
|
|
||||||
classifier = 'sources'
|
|
||||||
from android.sourceSets.main.java.sourceFiles
|
|
||||||
}
|
|
||||||
|
|
||||||
task androidJar(type: Jar) {
|
|
||||||
from 'build/intermediates/classes/release'
|
|
||||||
}
|
|
||||||
|
|
||||||
artifacts {
|
|
||||||
archives androidSourcesJar
|
|
||||||
archives androidJavadocsJar
|
|
||||||
archives androidJar
|
|
||||||
}
|
|
@@ -1,64 +0,0 @@
|
|||||||
apply plugin: 'maven-publish'
|
|
||||||
apply plugin: 'com.jfrog.bintray'
|
|
||||||
|
|
||||||
publishing {
|
|
||||||
publications {
|
|
||||||
mavenJava(MavenPublication) {
|
|
||||||
groupId GROUP
|
|
||||||
version VERSION_NAME
|
|
||||||
artifactId ARTIFACT_ID
|
|
||||||
// artifact androidJar
|
|
||||||
artifact "build/outputs/aar/transformations-release.aar"
|
|
||||||
artifact androidJavadocsJar
|
|
||||||
artifact androidSourcesJar
|
|
||||||
pom.withXml {
|
|
||||||
Node root = asNode()
|
|
||||||
root.appendNode('name', ARTIFACT_ID)
|
|
||||||
root.appendNode('description', POM_DESCRIPTION)
|
|
||||||
root.appendNode('url', POM_URL)
|
|
||||||
|
|
||||||
def issues = root.appendNode('issueManagement')
|
|
||||||
issues.appendNode('system', 'github')
|
|
||||||
issues.appendNode('url', ISSUE_URL)
|
|
||||||
|
|
||||||
def scm = root.appendNode('scm')
|
|
||||||
scm.appendNode('url', POM_SCM_URL)
|
|
||||||
scm.appendNode('connection', POM_SCM_CONNECTION)
|
|
||||||
scm.appendNode('developerConnection', POM_SCM_DEV_CONNECTION)
|
|
||||||
|
|
||||||
def license = root.appendNode('licenses').appendNode('license')
|
|
||||||
license.appendNode('name', POM_LICENCE_NAME)
|
|
||||||
license.appendNode('url', POM_LICENCE_URL)
|
|
||||||
license.appendNode('distribution', POM_LICENCE_DIST)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def getBintrayUserProperty() {
|
|
||||||
return hasProperty('bintrayUser') ? bintrayUser : ""
|
|
||||||
}
|
|
||||||
|
|
||||||
def getBintrayApiKeyProperty() {
|
|
||||||
return hasProperty('bintrayApiKey') ? bintrayApiKey : ""
|
|
||||||
}
|
|
||||||
|
|
||||||
bintray {
|
|
||||||
user = bintrayUserProperty
|
|
||||||
key = bintrayApiKeyProperty
|
|
||||||
publications = ['mavenJava']
|
|
||||||
|
|
||||||
dryRun = false
|
|
||||||
publish = false
|
|
||||||
pkg {
|
|
||||||
repo = 'maven'
|
|
||||||
name = ARTIFACT_ID
|
|
||||||
licenses = ['Apache-2.0']
|
|
||||||
labels = ['android']
|
|
||||||
|
|
||||||
version {
|
|
||||||
name = VERSION_NAME
|
|
||||||
vcsTag = VERSION_NAME
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,4 +1,5 @@
|
|||||||
apply plugin: 'com.android.library'
|
apply plugin: 'com.android.library'
|
||||||
|
apply plugin: 'com.novoda.bintray-release'
|
||||||
|
|
||||||
android {
|
android {
|
||||||
compileSdkVersion COMPILE_SDK_VERSION as int
|
compileSdkVersion COMPILE_SDK_VERSION as int
|
||||||
@@ -7,37 +8,43 @@ android {
|
|||||||
defaultConfig {
|
defaultConfig {
|
||||||
minSdkVersion MIN_SDK_VERSION as int
|
minSdkVersion MIN_SDK_VERSION as int
|
||||||
targetSdkVersion TARGET_SDK_VERSION as int
|
targetSdkVersion TARGET_SDK_VERSION as int
|
||||||
versionCode VERSION_CODE as int
|
versionCode "git rev-list origin/master --count".execute().text.toInteger()
|
||||||
versionName VERSION_NAME
|
versionName VERSION_NAME
|
||||||
renderscriptTargetApi RENDERSCRIPT_TARGET_API as int
|
|
||||||
renderscriptSupportModeEnabled true
|
consumerProguardFiles 'proguard-rules.txt'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile fileTree(dir: 'libs', include: ['*.jar'])
|
compile "com.github.bumptech.glide:glide:${GLIDE_VERSION}"
|
||||||
compile 'com.github.bumptech.glide:glide:3.4.0'
|
provided "jp.co.cyberagent.android.gpuimage:gpuimage-library:${GPUIMAGE_VERSION}"
|
||||||
compile 'jp.co.cyberagent.android.gpuimage:gpuimage-library:1.2.3'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
android.libraryVariants.all { variant ->
|
task androidJavadocs(type: Javadoc) {
|
||||||
if (variant.buildType.isDebuggable()) {
|
source = android.sourceSets.main.java.srcDirs
|
||||||
return; // Skip debug builds.
|
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
|
||||||
}
|
|
||||||
task("javadoc${variant.name.capitalize()}", type: Javadoc) {
|
|
||||||
description "Generates Javadoc for $variant.name."
|
|
||||||
source = variant.javaCompile.source
|
|
||||||
ext.androidJar = System.getenv("ANDROID_HOME") + "/platforms/${android.compileSdkVersion}/android.jar"
|
|
||||||
classpath = files(variant.javaCompile.classpath.files) + files(ext.androidJar)
|
|
||||||
}
|
|
||||||
|
|
||||||
task("bundleJavadoc${variant.name.capitalize()}", type: Jar) {
|
|
||||||
description "Bundles Javadoc into zip for $variant.name."
|
|
||||||
classifier = "javadoc"
|
|
||||||
from tasks["javadoc${variant.name.capitalize()}"]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
apply from: 'android-artifacts.gradle'
|
task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
|
||||||
apply from: 'central-publish.gradle'
|
classifier = 'javadoc'
|
||||||
apply from: 'bintray-publish.gradle'
|
from androidJavadocs.destinationDir
|
||||||
|
}
|
||||||
|
|
||||||
|
task androidSourcesJar(type: Jar) {
|
||||||
|
classifier = 'sources'
|
||||||
|
from android.sourceSets.main.java.srcDirs
|
||||||
|
}
|
||||||
|
|
||||||
|
artifacts {
|
||||||
|
archives androidSourcesJar
|
||||||
|
archives androidJavadocsJar
|
||||||
|
}
|
||||||
|
|
||||||
|
publish {
|
||||||
|
userOrg = POM_DEVELOPER_ID
|
||||||
|
groupId = GROUP
|
||||||
|
artifactId = ARTIFACT_ID
|
||||||
|
publishVersion = VERSION_NAME
|
||||||
|
desc = POM_DESCRIPTION
|
||||||
|
website = POM_URL
|
||||||
|
}
|
||||||
|
@@ -1,94 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2013 Chris Banes
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
apply plugin: 'maven'
|
|
||||||
apply plugin: 'signing'
|
|
||||||
|
|
||||||
def isReleaseBuild() {
|
|
||||||
return VERSION_NAME.contains("SNAPSHOT") == false
|
|
||||||
}
|
|
||||||
|
|
||||||
def getReleaseRepositoryUrl() {
|
|
||||||
return hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL
|
|
||||||
: "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
|
|
||||||
}
|
|
||||||
|
|
||||||
def getSnapshotRepositoryUrl() {
|
|
||||||
return hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL
|
|
||||||
: "https://oss.sonatype.org/content/repositories/snapshots/"
|
|
||||||
}
|
|
||||||
|
|
||||||
def getRepositoryUsername() {
|
|
||||||
return hasProperty('NEXUS_USERNAME') ? NEXUS_USERNAME : ""
|
|
||||||
}
|
|
||||||
|
|
||||||
def getRepositoryPassword() {
|
|
||||||
return hasProperty('NEXUS_PASSWORD') ? NEXUS_PASSWORD : ""
|
|
||||||
}
|
|
||||||
|
|
||||||
afterEvaluate { project ->
|
|
||||||
uploadArchives {
|
|
||||||
repositories {
|
|
||||||
mavenDeployer {
|
|
||||||
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
|
|
||||||
|
|
||||||
pom.groupId = GROUP
|
|
||||||
pom.artifactId = POM_ARTIFACT_ID
|
|
||||||
pom.version = VERSION_NAME
|
|
||||||
|
|
||||||
repository(url: getReleaseRepositoryUrl()) {
|
|
||||||
authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
|
|
||||||
}
|
|
||||||
snapshotRepository(url: getSnapshotRepositoryUrl()) {
|
|
||||||
authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
|
|
||||||
}
|
|
||||||
|
|
||||||
pom.project {
|
|
||||||
name POM_NAME
|
|
||||||
packaging POM_PACKAGING
|
|
||||||
description POM_DESCRIPTION
|
|
||||||
url POM_URL
|
|
||||||
|
|
||||||
scm {
|
|
||||||
url POM_SCM_URL
|
|
||||||
connection POM_SCM_CONNECTION
|
|
||||||
developerConnection POM_SCM_DEV_CONNECTION
|
|
||||||
}
|
|
||||||
|
|
||||||
licenses {
|
|
||||||
license {
|
|
||||||
name POM_LICENCE_NAME
|
|
||||||
url POM_LICENCE_URL
|
|
||||||
distribution POM_LICENCE_DIST
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
developers {
|
|
||||||
developer {
|
|
||||||
id POM_DEVELOPER_ID
|
|
||||||
name POM_DEVELOPER_NAME
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
signing {
|
|
||||||
required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") }
|
|
||||||
sign configurations.archives
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,3 +0,0 @@
|
|||||||
POM_NAME=which provides simple Tranformations to Glide
|
|
||||||
POM_ARTIFACT_ID=glide-transformations
|
|
||||||
POM_PACKAGING=aar
|
|
1
transformations/proguard-rules.txt
Normal file
1
transformations/proguard-rules.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
-dontwarn jp.co.cyberagent.android.gpuimage.**
|
@@ -1,3 +1 @@
|
|||||||
<manifest
|
<manifest package="jp.wasabeef.glide.transformations"></manifest>
|
||||||
package="jp.wasabeef.glide.transformations">
|
|
||||||
</manifest>
|
|
||||||
|
@@ -16,61 +16,92 @@ package jp.wasabeef.glide.transformations;
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.Canvas;
|
||||||
|
import android.graphics.Paint;
|
||||||
|
import android.os.Build;
|
||||||
|
import android.renderscript.RSRuntimeException;
|
||||||
|
import com.bumptech.glide.Glide;
|
||||||
import com.bumptech.glide.load.Transformation;
|
import com.bumptech.glide.load.Transformation;
|
||||||
import com.bumptech.glide.load.engine.Resource;
|
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.BitmapResource;
|
||||||
|
import jp.wasabeef.glide.transformations.internal.FastBlur;
|
||||||
import android.content.Context;
|
import jp.wasabeef.glide.transformations.internal.RSBlur;
|
||||||
import android.graphics.Bitmap;
|
|
||||||
import android.graphics.Canvas;
|
|
||||||
import android.support.v8.renderscript.Allocation;
|
|
||||||
import android.support.v8.renderscript.RenderScript;
|
|
||||||
import android.support.v8.renderscript.ScriptIntrinsicBlur;
|
|
||||||
|
|
||||||
public class BlurTransformation implements Transformation<Bitmap> {
|
public class BlurTransformation implements Transformation<Bitmap> {
|
||||||
|
|
||||||
private static int MAX_RADIUS = 25;
|
private static int MAX_RADIUS = 25;
|
||||||
|
private static int DEFAULT_DOWN_SAMPLING = 1;
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private BitmapPool mBitmapPool;
|
private BitmapPool mBitmapPool;
|
||||||
|
|
||||||
private int mRadius;
|
private int mRadius;
|
||||||
|
private int mSampling;
|
||||||
|
|
||||||
|
public BlurTransformation(Context context) {
|
||||||
|
this(context, Glide.get(context).getBitmapPool(), MAX_RADIUS, DEFAULT_DOWN_SAMPLING);
|
||||||
|
}
|
||||||
|
|
||||||
public BlurTransformation(Context context, BitmapPool pool) {
|
public BlurTransformation(Context context, BitmapPool pool) {
|
||||||
this(context, pool, MAX_RADIUS);
|
this(context, pool, MAX_RADIUS, DEFAULT_DOWN_SAMPLING);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BlurTransformation(Context context, BitmapPool pool, int radius) {
|
public BlurTransformation(Context context, BitmapPool pool, int radius) {
|
||||||
mContext = context;
|
this(context, pool, radius, DEFAULT_DOWN_SAMPLING);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlurTransformation(Context context, int radius) {
|
||||||
|
this(context, Glide.get(context).getBitmapPool(), radius, DEFAULT_DOWN_SAMPLING);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlurTransformation(Context context, int radius, int sampling) {
|
||||||
|
this(context, Glide.get(context).getBitmapPool(), radius, sampling);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlurTransformation(Context context, BitmapPool pool, int radius, int sampling) {
|
||||||
|
mContext = context.getApplicationContext();
|
||||||
mBitmapPool = pool;
|
mBitmapPool = pool;
|
||||||
mRadius = radius;
|
mRadius = radius;
|
||||||
|
mSampling = sampling;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
||||||
Bitmap source = resource.get();
|
Bitmap source = resource.get();
|
||||||
Bitmap outBitmap = Bitmap.createBitmap(source.getWidth(), source.getHeight(),
|
|
||||||
Bitmap.Config.ARGB_8888);
|
|
||||||
Canvas canvas = new Canvas(outBitmap);
|
|
||||||
canvas.drawBitmap(source, 0, 0, null);
|
|
||||||
|
|
||||||
RenderScript rs = RenderScript.create(mContext);
|
int width = source.getWidth();
|
||||||
Allocation overlayAlloc = Allocation.createFromBitmap(rs, outBitmap);
|
int height = source.getHeight();
|
||||||
ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(rs, overlayAlloc.getElement());
|
int scaledWidth = width / mSampling;
|
||||||
blur.setInput(overlayAlloc);
|
int scaledHeight = height / mSampling;
|
||||||
blur.setRadius(mRadius);
|
|
||||||
blur.forEach(overlayAlloc);
|
|
||||||
overlayAlloc.copyTo(outBitmap);
|
|
||||||
|
|
||||||
source.recycle();
|
Bitmap bitmap = mBitmapPool.get(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
|
||||||
rs.destroy();
|
if (bitmap == null) {
|
||||||
|
bitmap = Bitmap.createBitmap(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
|
||||||
return BitmapResource.obtain(outBitmap, mBitmapPool);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
Canvas canvas = new Canvas(bitmap);
|
||||||
public String getId() {
|
canvas.scale(1 / (float) mSampling, 1 / (float) mSampling);
|
||||||
return "BlurTransformation(radius=" + mRadius + ")";
|
Paint paint = new Paint();
|
||||||
|
paint.setFlags(Paint.FILTER_BITMAP_FLAG);
|
||||||
|
canvas.drawBitmap(source, 0, 0, paint);
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
|
||||||
|
try {
|
||||||
|
bitmap = RSBlur.blur(mContext, bitmap, mRadius);
|
||||||
|
} catch (RSRuntimeException e) {
|
||||||
|
bitmap = FastBlur.blur(bitmap, mRadius, true);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
bitmap = FastBlur.blur(bitmap, mRadius, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public String getId() {
|
||||||
|
return "BlurTransformation(radius=" + mRadius + ", sampling=" + mSampling + ")";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,16 +16,17 @@ package jp.wasabeef.glide.transformations;
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import com.bumptech.glide.load.Transformation;
|
import android.content.Context;
|
||||||
import com.bumptech.glide.load.engine.Resource;
|
|
||||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
|
||||||
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
|
|
||||||
|
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.Canvas;
|
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 com.bumptech.glide.load.Transformation;
|
||||||
|
import com.bumptech.glide.load.engine.Resource;
|
||||||
|
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||||
|
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
|
||||||
|
|
||||||
public class ColorFilterTransformation implements Transformation<Bitmap> {
|
public class ColorFilterTransformation implements Transformation<Bitmap> {
|
||||||
|
|
||||||
@@ -33,6 +34,10 @@ public class ColorFilterTransformation implements Transformation<Bitmap> {
|
|||||||
|
|
||||||
private int mColor;
|
private int mColor;
|
||||||
|
|
||||||
|
public ColorFilterTransformation(Context context, int color) {
|
||||||
|
this(Glide.get(context).getBitmapPool(), color);
|
||||||
|
}
|
||||||
|
|
||||||
public ColorFilterTransformation(BitmapPool pool, int color) {
|
public ColorFilterTransformation(BitmapPool pool, int color) {
|
||||||
mBitmapPool = pool;
|
mBitmapPool = pool;
|
||||||
mColor = color;
|
mColor = color;
|
||||||
@@ -45,20 +50,23 @@ public class ColorFilterTransformation implements Transformation<Bitmap> {
|
|||||||
int width = source.getWidth();
|
int width = source.getWidth();
|
||||||
int height = source.getHeight();
|
int height = source.getHeight();
|
||||||
|
|
||||||
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
Bitmap.Config config =
|
||||||
|
source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
|
||||||
|
Bitmap bitmap = mBitmapPool.get(width, height, config);
|
||||||
|
if (bitmap == null) {
|
||||||
|
bitmap = Bitmap.createBitmap(width, height, config);
|
||||||
|
}
|
||||||
|
|
||||||
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(mColor, PorterDuff.Mode.SRC_ATOP));
|
||||||
canvas.drawBitmap(source, 0, 0, paint);
|
canvas.drawBitmap(source, 0, 0, paint);
|
||||||
source.recycle();
|
|
||||||
|
|
||||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public String getId() {
|
||||||
public String getId() {
|
|
||||||
return "ColorFilterTransformation(color=" + mColor + ")";
|
return "ColorFilterTransformation(color=" + mColor + ")";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,20 +16,26 @@ package jp.wasabeef.glide.transformations;
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.BitmapShader;
|
||||||
|
import android.graphics.Canvas;
|
||||||
|
import android.graphics.Matrix;
|
||||||
|
import android.graphics.Paint;
|
||||||
|
import com.bumptech.glide.Glide;
|
||||||
import com.bumptech.glide.load.Transformation;
|
import com.bumptech.glide.load.Transformation;
|
||||||
import com.bumptech.glide.load.engine.Resource;
|
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.BitmapResource;
|
||||||
|
|
||||||
import android.graphics.Bitmap;
|
|
||||||
import android.graphics.BitmapShader;
|
|
||||||
import android.graphics.Canvas;
|
|
||||||
import android.graphics.Paint;
|
|
||||||
|
|
||||||
public class CropCircleTransformation implements Transformation<Bitmap> {
|
public class CropCircleTransformation implements Transformation<Bitmap> {
|
||||||
|
|
||||||
private BitmapPool mBitmapPool;
|
private BitmapPool mBitmapPool;
|
||||||
|
|
||||||
|
public CropCircleTransformation(Context context) {
|
||||||
|
this(Glide.get(context).getBitmapPool());
|
||||||
|
}
|
||||||
|
|
||||||
public CropCircleTransformation(BitmapPool pool) {
|
public CropCircleTransformation(BitmapPool pool) {
|
||||||
this.mBitmapPool = pool;
|
this.mBitmapPool = pool;
|
||||||
}
|
}
|
||||||
@@ -42,30 +48,31 @@ public class CropCircleTransformation implements Transformation<Bitmap> {
|
|||||||
int width = (source.getWidth() - size) / 2;
|
int width = (source.getWidth() - size) / 2;
|
||||||
int height = (source.getHeight() - size) / 2;
|
int height = (source.getHeight() - size) / 2;
|
||||||
|
|
||||||
Bitmap squaredBitmap = Bitmap.createBitmap(source, width, height, size, size);
|
Bitmap bitmap = mBitmapPool.get(size, size, Bitmap.Config.ARGB_8888);
|
||||||
if (squaredBitmap != source) {
|
if (bitmap == null) {
|
||||||
source.recycle();
|
bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
|
||||||
}
|
}
|
||||||
|
|
||||||
Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
|
|
||||||
|
|
||||||
Canvas canvas = new Canvas(bitmap);
|
Canvas canvas = new Canvas(bitmap);
|
||||||
Paint paint = new Paint();
|
Paint paint = new Paint();
|
||||||
BitmapShader shader = new BitmapShader(squaredBitmap, BitmapShader.TileMode.CLAMP,
|
BitmapShader shader =
|
||||||
BitmapShader.TileMode.CLAMP);
|
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.setShader(shader);
|
||||||
paint.setAntiAlias(true);
|
paint.setAntiAlias(true);
|
||||||
|
|
||||||
float r = size / 2f;
|
float r = size / 2f;
|
||||||
canvas.drawCircle(r, r, r, paint);
|
canvas.drawCircle(r, r, r, paint);
|
||||||
|
|
||||||
squaredBitmap.recycle();
|
|
||||||
|
|
||||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public String getId() {
|
||||||
public String getId() {
|
|
||||||
return "CropCircleTransformation()";
|
return "CropCircleTransformation()";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,19 +16,24 @@ package jp.wasabeef.glide.transformations;
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import com.bumptech.glide.Glide;
|
||||||
import com.bumptech.glide.load.Transformation;
|
import com.bumptech.glide.load.Transformation;
|
||||||
import com.bumptech.glide.load.engine.Resource;
|
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.BitmapResource;
|
||||||
|
|
||||||
import android.graphics.Bitmap;
|
|
||||||
|
|
||||||
public class CropSquareTransformation implements Transformation<Bitmap> {
|
public class CropSquareTransformation implements Transformation<Bitmap> {
|
||||||
|
|
||||||
private BitmapPool mBitmapPool;
|
private BitmapPool mBitmapPool;
|
||||||
private int mWidth;
|
private int mWidth;
|
||||||
private int mHeight;
|
private int mHeight;
|
||||||
|
|
||||||
|
public CropSquareTransformation(Context context) {
|
||||||
|
this(Glide.get(context).getBitmapPool());
|
||||||
|
}
|
||||||
|
|
||||||
public CropSquareTransformation(BitmapPool pool) {
|
public CropSquareTransformation(BitmapPool pool) {
|
||||||
this.mBitmapPool = pool;
|
this.mBitmapPool = pool;
|
||||||
}
|
}
|
||||||
@@ -41,16 +46,17 @@ public class CropSquareTransformation implements Transformation<Bitmap> {
|
|||||||
mWidth = (source.getWidth() - size) / 2;
|
mWidth = (source.getWidth() - size) / 2;
|
||||||
mHeight = (source.getHeight() - size) / 2;
|
mHeight = (source.getHeight() - size) / 2;
|
||||||
|
|
||||||
Bitmap bitmap = Bitmap.createBitmap(source, mWidth, mHeight, size, size);
|
Bitmap.Config config =
|
||||||
if (bitmap != source) {
|
source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
|
||||||
source.recycle();
|
Bitmap bitmap = mBitmapPool.get(mWidth, mHeight, config);
|
||||||
|
if (bitmap == null) {
|
||||||
|
bitmap = Bitmap.createBitmap(source, mWidth, mHeight, size, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public String getId() {
|
||||||
public String getId() {
|
|
||||||
return "CropSquareTransformation(width=" + mWidth + ", height=" + mHeight + ")";
|
return "CropSquareTransformation(width=" + mWidth + ", height=" + mHeight + ")";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,39 +16,68 @@ package jp.wasabeef.glide.transformations;
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.Canvas;
|
||||||
|
import android.graphics.RectF;
|
||||||
|
import com.bumptech.glide.Glide;
|
||||||
import com.bumptech.glide.load.Transformation;
|
import com.bumptech.glide.load.Transformation;
|
||||||
import com.bumptech.glide.load.engine.Resource;
|
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.BitmapResource;
|
||||||
|
|
||||||
import android.graphics.Bitmap;
|
|
||||||
import android.graphics.Canvas;
|
|
||||||
import android.graphics.RectF;
|
|
||||||
|
|
||||||
public class CropTransformation implements Transformation<Bitmap> {
|
public class CropTransformation implements Transformation<Bitmap> {
|
||||||
|
|
||||||
|
public enum CropType {
|
||||||
|
TOP,
|
||||||
|
CENTER,
|
||||||
|
BOTTOM
|
||||||
|
}
|
||||||
|
|
||||||
private BitmapPool mBitmapPool;
|
private BitmapPool mBitmapPool;
|
||||||
private int mWidth;
|
private int mWidth;
|
||||||
private int mHeight;
|
private int mHeight;
|
||||||
|
|
||||||
|
private CropType mCropType = CropType.CENTER;
|
||||||
|
|
||||||
|
public CropTransformation(Context context) {
|
||||||
|
this(Glide.get(context).getBitmapPool());
|
||||||
|
}
|
||||||
|
|
||||||
public CropTransformation(BitmapPool pool) {
|
public CropTransformation(BitmapPool pool) {
|
||||||
mBitmapPool = pool;
|
this(pool, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CropTransformation(Context context, int width, int height) {
|
||||||
|
this(Glide.get(context).getBitmapPool(), width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CropTransformation(BitmapPool pool, int width, int height) {
|
public CropTransformation(BitmapPool pool, int width, int height) {
|
||||||
|
this(pool, width, height, CropType.CENTER);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CropTransformation(Context context, int width, int height, CropType cropType) {
|
||||||
|
this(Glide.get(context).getBitmapPool(), width, height, cropType);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CropTransformation(BitmapPool pool, int width, int height, CropType cropType) {
|
||||||
mBitmapPool = pool;
|
mBitmapPool = pool;
|
||||||
mWidth = width;
|
mWidth = width;
|
||||||
mHeight = height;
|
mHeight = height;
|
||||||
|
mCropType = cropType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
||||||
Bitmap source = resource.get();
|
Bitmap source = resource.get();
|
||||||
if (mWidth == 0) {
|
mWidth = mWidth == 0 ? source.getWidth() : mWidth;
|
||||||
mWidth = source.getWidth();
|
mHeight = mHeight == 0 ? source.getHeight() : mHeight;
|
||||||
}
|
|
||||||
if (mHeight == 0) {
|
Bitmap.Config config =
|
||||||
mHeight = source.getHeight();
|
source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
|
||||||
|
Bitmap bitmap = mBitmapPool.get(mWidth, mHeight, config);
|
||||||
|
if (bitmap == null) {
|
||||||
|
bitmap = Bitmap.createBitmap(mWidth, mHeight, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
float scaleX = (float) mWidth / source.getWidth();
|
float scaleX = (float) mWidth / source.getWidth();
|
||||||
@@ -58,19 +87,30 @@ public class CropTransformation implements Transformation<Bitmap> {
|
|||||||
float scaledWidth = scale * source.getWidth();
|
float scaledWidth = scale * source.getWidth();
|
||||||
float scaledHeight = scale * source.getHeight();
|
float scaledHeight = scale * source.getHeight();
|
||||||
float left = (mWidth - scaledWidth) / 2;
|
float left = (mWidth - scaledWidth) / 2;
|
||||||
float top = (mHeight - scaledHeight) / 2;
|
float top = getTop(scaledHeight);
|
||||||
RectF targetRect = new RectF(left, top, left + scaledWidth, top + scaledHeight);
|
RectF targetRect = new RectF(left, top, left + scaledWidth, top + scaledHeight);
|
||||||
|
|
||||||
Bitmap bitmap = Bitmap.createBitmap(mWidth, mHeight, source.getConfig());
|
|
||||||
Canvas canvas = new Canvas(bitmap);
|
Canvas canvas = new Canvas(bitmap);
|
||||||
canvas.drawBitmap(source, null, targetRect, null);
|
canvas.drawBitmap(source, null, targetRect, null);
|
||||||
source.recycle();
|
|
||||||
|
|
||||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public String getId() {
|
||||||
public String getId() {
|
return "CropTransformation(width=" + mWidth + ", height=" + mHeight + ", cropType=" + mCropType
|
||||||
return "CropTransformation(width=" + mWidth + ", height=" + mHeight + ")";
|
+ ")";
|
||||||
|
}
|
||||||
|
|
||||||
|
private float getTop(float scaledHeight) {
|
||||||
|
switch (mCropType) {
|
||||||
|
case TOP:
|
||||||
|
return 0;
|
||||||
|
case CENTER:
|
||||||
|
return (mHeight - scaledHeight) / 2;
|
||||||
|
case BOTTOM:
|
||||||
|
return mHeight - scaledHeight;
|
||||||
|
default:
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,21 +16,26 @@ package jp.wasabeef.glide.transformations;
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import com.bumptech.glide.load.Transformation;
|
import android.content.Context;
|
||||||
import com.bumptech.glide.load.engine.Resource;
|
|
||||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
|
||||||
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
|
|
||||||
|
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.Canvas;
|
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 com.bumptech.glide.load.Transformation;
|
||||||
|
import com.bumptech.glide.load.engine.Resource;
|
||||||
|
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||||
|
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
|
||||||
|
|
||||||
public class GrayscaleTransformation implements Transformation<Bitmap> {
|
public class GrayscaleTransformation implements Transformation<Bitmap> {
|
||||||
|
|
||||||
private BitmapPool mBitmapPool;
|
private BitmapPool mBitmapPool;
|
||||||
|
|
||||||
|
public GrayscaleTransformation(Context context) {
|
||||||
|
this(Glide.get(context).getBitmapPool());
|
||||||
|
}
|
||||||
|
|
||||||
public GrayscaleTransformation(BitmapPool pool) {
|
public GrayscaleTransformation(BitmapPool pool) {
|
||||||
mBitmapPool = pool;
|
mBitmapPool = pool;
|
||||||
}
|
}
|
||||||
@@ -42,7 +47,12 @@ public class GrayscaleTransformation implements Transformation<Bitmap> {
|
|||||||
int width = source.getWidth();
|
int width = source.getWidth();
|
||||||
int height = source.getHeight();
|
int height = source.getHeight();
|
||||||
|
|
||||||
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
Bitmap.Config config =
|
||||||
|
source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
|
||||||
|
Bitmap bitmap = mBitmapPool.get(width, height, config);
|
||||||
|
if (bitmap == null) {
|
||||||
|
bitmap = Bitmap.createBitmap(width, height, config);
|
||||||
|
}
|
||||||
|
|
||||||
Canvas canvas = new Canvas(bitmap);
|
Canvas canvas = new Canvas(bitmap);
|
||||||
ColorMatrix saturation = new ColorMatrix();
|
ColorMatrix saturation = new ColorMatrix();
|
||||||
@@ -50,13 +60,11 @@ public class GrayscaleTransformation implements Transformation<Bitmap> {
|
|||||||
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(source, 0, 0, paint);
|
||||||
source.recycle();
|
|
||||||
|
|
||||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public String getId() {
|
||||||
public String getId() {
|
|
||||||
return "GrayscaleTransformation()";
|
return "GrayscaleTransformation()";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,85 @@
|
|||||||
|
package jp.wasabeef.glide.transformations;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copyright (C) 2015 Wasabeef
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.Canvas;
|
||||||
|
import android.graphics.Paint;
|
||||||
|
import android.graphics.PorterDuff;
|
||||||
|
import android.graphics.PorterDuffXfermode;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
|
import com.bumptech.glide.Glide;
|
||||||
|
import com.bumptech.glide.load.Transformation;
|
||||||
|
import com.bumptech.glide.load.engine.Resource;
|
||||||
|
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||||
|
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
|
||||||
|
import jp.wasabeef.glide.transformations.internal.Utils;
|
||||||
|
|
||||||
|
public class MaskTransformation implements Transformation<Bitmap> {
|
||||||
|
|
||||||
|
private static Paint sMaskingPaint = new Paint();
|
||||||
|
private Context mContext;
|
||||||
|
private BitmapPool mBitmapPool;
|
||||||
|
private int mMaskId;
|
||||||
|
|
||||||
|
static {
|
||||||
|
sMaskingPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param maskId If you change the mask file, please also rename the mask file, or Glide will get
|
||||||
|
* the cache with the old mask. Because getId() return the same values if using the
|
||||||
|
* same make file name. If you have a good idea please tell us, thanks.
|
||||||
|
*/
|
||||||
|
public MaskTransformation(Context context, int maskId) {
|
||||||
|
this(context, Glide.get(context).getBitmapPool(), maskId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MaskTransformation(Context context, BitmapPool pool, int maskId) {
|
||||||
|
mBitmapPool = pool;
|
||||||
|
mContext = context.getApplicationContext();
|
||||||
|
mMaskId = maskId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@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 result = mBitmapPool.get(width, height, Bitmap.Config.ARGB_8888);
|
||||||
|
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.draw(canvas);
|
||||||
|
canvas.drawBitmap(source, 0, 0, sMaskingPaint);
|
||||||
|
|
||||||
|
return BitmapResource.obtain(result, mBitmapPool);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public String getId() {
|
||||||
|
return "MaskTransformation(maskId=" + mContext.getResources().getResourceEntryName(mMaskId)
|
||||||
|
+ ")";
|
||||||
|
}
|
||||||
|
}
|
@@ -16,29 +16,55 @@ package jp.wasabeef.glide.transformations;
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import com.bumptech.glide.load.Transformation;
|
import android.content.Context;
|
||||||
import com.bumptech.glide.load.engine.Resource;
|
|
||||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
|
||||||
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
|
|
||||||
|
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapShader;
|
import android.graphics.BitmapShader;
|
||||||
import android.graphics.Canvas;
|
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 com.bumptech.glide.load.Transformation;
|
||||||
|
import com.bumptech.glide.load.engine.Resource;
|
||||||
|
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||||
|
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
|
||||||
|
|
||||||
public class RoundedCornersTransformation implements Transformation<Bitmap> {
|
public class RoundedCornersTransformation implements Transformation<Bitmap> {
|
||||||
|
|
||||||
private BitmapPool mBitmapPool;
|
public enum CornerType {
|
||||||
|
ALL,
|
||||||
|
TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT,
|
||||||
|
TOP, BOTTOM, LEFT, RIGHT,
|
||||||
|
OTHER_TOP_LEFT, OTHER_TOP_RIGHT, OTHER_BOTTOM_LEFT, OTHER_BOTTOM_RIGHT,
|
||||||
|
DIAGONAL_FROM_TOP_LEFT, DIAGONAL_FROM_TOP_RIGHT
|
||||||
|
}
|
||||||
|
|
||||||
private int radius;
|
private BitmapPool mBitmapPool;
|
||||||
private int margin;
|
private int mRadius;
|
||||||
|
private int mDiameter;
|
||||||
|
private int mMargin;
|
||||||
|
private CornerType mCornerType;
|
||||||
|
|
||||||
|
public RoundedCornersTransformation(Context context, int radius, int margin) {
|
||||||
|
this(context, radius, margin, CornerType.ALL);
|
||||||
|
}
|
||||||
|
|
||||||
public RoundedCornersTransformation(BitmapPool pool, int radius, int margin) {
|
public RoundedCornersTransformation(BitmapPool pool, int radius, int margin) {
|
||||||
this.radius = radius;
|
this(pool, radius, margin, CornerType.ALL);
|
||||||
this.margin = margin;
|
}
|
||||||
|
|
||||||
|
public RoundedCornersTransformation(Context context, int radius, int margin,
|
||||||
|
CornerType cornerType) {
|
||||||
|
this(Glide.get(context).getBitmapPool(), radius, margin, cornerType);
|
||||||
|
}
|
||||||
|
|
||||||
|
public RoundedCornersTransformation(BitmapPool pool, int radius, int margin,
|
||||||
|
CornerType cornerType) {
|
||||||
mBitmapPool = pool;
|
mBitmapPool = pool;
|
||||||
|
mRadius = radius;
|
||||||
|
mDiameter = mRadius * 2;
|
||||||
|
mMargin = margin;
|
||||||
|
mCornerType = cornerType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -48,21 +74,182 @@ public class RoundedCornersTransformation implements Transformation<Bitmap> {
|
|||||||
int width = source.getWidth();
|
int width = source.getWidth();
|
||||||
int height = source.getHeight();
|
int height = source.getHeight();
|
||||||
|
|
||||||
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
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(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
|
||||||
canvas.drawRoundRect(new RectF(margin, margin, width - margin, height - margin),
|
drawRoundRect(canvas, paint, width, height);
|
||||||
radius, radius, paint);
|
|
||||||
source.recycle();
|
|
||||||
|
|
||||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private void drawRoundRect(Canvas canvas, Paint paint, float width, float height) {
|
||||||
public String getId() {
|
float right = width - mMargin;
|
||||||
return "RoundedTransformation(radius=" + radius + ", margin=" + margin + ")";
|
float bottom = height - mMargin;
|
||||||
|
|
||||||
|
switch (mCornerType) {
|
||||||
|
case ALL:
|
||||||
|
canvas.drawRoundRect(new RectF(mMargin, mMargin, right, bottom), mRadius, mRadius, paint);
|
||||||
|
break;
|
||||||
|
case TOP_LEFT:
|
||||||
|
drawTopLeftRoundRect(canvas, paint, right, bottom);
|
||||||
|
break;
|
||||||
|
case TOP_RIGHT:
|
||||||
|
drawTopRightRoundRect(canvas, paint, right, bottom);
|
||||||
|
break;
|
||||||
|
case BOTTOM_LEFT:
|
||||||
|
drawBottomLeftRoundRect(canvas, paint, right, bottom);
|
||||||
|
break;
|
||||||
|
case BOTTOM_RIGHT:
|
||||||
|
drawBottomRightRoundRect(canvas, paint, right, bottom);
|
||||||
|
break;
|
||||||
|
case TOP:
|
||||||
|
drawTopRoundRect(canvas, paint, right, bottom);
|
||||||
|
break;
|
||||||
|
case BOTTOM:
|
||||||
|
drawBottomRoundRect(canvas, paint, right, bottom);
|
||||||
|
break;
|
||||||
|
case LEFT:
|
||||||
|
drawLeftRoundRect(canvas, paint, right, bottom);
|
||||||
|
break;
|
||||||
|
case RIGHT:
|
||||||
|
drawRightRoundRect(canvas, paint, right, bottom);
|
||||||
|
break;
|
||||||
|
case OTHER_TOP_LEFT:
|
||||||
|
drawOtherTopLeftRoundRect(canvas, paint, right, bottom);
|
||||||
|
break;
|
||||||
|
case OTHER_TOP_RIGHT:
|
||||||
|
drawOtherTopRightRoundRect(canvas, paint, right, bottom);
|
||||||
|
break;
|
||||||
|
case OTHER_BOTTOM_LEFT:
|
||||||
|
drawOtherBottomLeftRoundRect(canvas, paint, right, bottom);
|
||||||
|
break;
|
||||||
|
case OTHER_BOTTOM_RIGHT:
|
||||||
|
drawOtherBottomRightRoundRect(canvas, paint, right, bottom);
|
||||||
|
break;
|
||||||
|
case DIAGONAL_FROM_TOP_LEFT:
|
||||||
|
drawDiagonalFromTopLeftRoundRect(canvas, paint, right, bottom);
|
||||||
|
break;
|
||||||
|
case DIAGONAL_FROM_TOP_RIGHT:
|
||||||
|
drawDiagonalFromTopRightRoundRect(canvas, paint, right, bottom);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
canvas.drawRoundRect(new RectF(mMargin, mMargin, right, bottom), mRadius, mRadius, paint);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void drawTopLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
|
||||||
|
canvas.drawRoundRect(new RectF(mMargin, mMargin, mMargin + mDiameter, mMargin + mDiameter),
|
||||||
|
mRadius, mRadius, paint);
|
||||||
|
canvas.drawRect(new RectF(mMargin, mMargin + mRadius, mMargin + mRadius, bottom), paint);
|
||||||
|
canvas.drawRect(new RectF(mMargin + mRadius, mMargin, right, bottom), paint);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void drawTopRightRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
|
||||||
|
canvas.drawRoundRect(new RectF(right - mDiameter, mMargin, right, mMargin + mDiameter), mRadius,
|
||||||
|
mRadius, paint);
|
||||||
|
canvas.drawRect(new RectF(mMargin, mMargin, right - mRadius, bottom), paint);
|
||||||
|
canvas.drawRect(new RectF(right - mRadius, mMargin + mRadius, right, bottom), paint);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void drawBottomLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
|
||||||
|
canvas.drawRoundRect(new RectF(mMargin, bottom - mDiameter, mMargin + mDiameter, bottom),
|
||||||
|
mRadius, mRadius, paint);
|
||||||
|
canvas.drawRect(new RectF(mMargin, mMargin, mMargin + mDiameter, bottom - mRadius), paint);
|
||||||
|
canvas.drawRect(new RectF(mMargin + mRadius, mMargin, right, bottom), paint);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void drawBottomRightRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
|
||||||
|
canvas.drawRoundRect(new RectF(right - mDiameter, bottom - mDiameter, right, bottom), mRadius,
|
||||||
|
mRadius, paint);
|
||||||
|
canvas.drawRect(new RectF(mMargin, mMargin, right - mRadius, bottom), paint);
|
||||||
|
canvas.drawRect(new RectF(right - mRadius, mMargin, right, bottom - mRadius), paint);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void drawTopRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
|
||||||
|
canvas.drawRoundRect(new RectF(mMargin, mMargin, right, mMargin + mDiameter), mRadius, mRadius,
|
||||||
|
paint);
|
||||||
|
canvas.drawRect(new RectF(mMargin, mMargin + mRadius, right, bottom), paint);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void drawBottomRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
|
||||||
|
canvas.drawRoundRect(new RectF(mMargin, bottom - mDiameter, right, bottom), mRadius, mRadius,
|
||||||
|
paint);
|
||||||
|
canvas.drawRect(new RectF(mMargin, mMargin, right, bottom - mRadius), paint);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void drawLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
|
||||||
|
canvas.drawRoundRect(new RectF(mMargin, mMargin, mMargin + mDiameter, bottom), mRadius, mRadius,
|
||||||
|
paint);
|
||||||
|
canvas.drawRect(new RectF(mMargin + mRadius, mMargin, right, bottom), paint);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void drawRightRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
|
||||||
|
canvas.drawRoundRect(new RectF(right - mDiameter, mMargin, right, bottom), mRadius, mRadius,
|
||||||
|
paint);
|
||||||
|
canvas.drawRect(new RectF(mMargin, mMargin, right - mRadius, bottom), paint);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void drawOtherTopLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
|
||||||
|
canvas.drawRoundRect(new RectF(mMargin, bottom - mDiameter, right, bottom), mRadius, mRadius,
|
||||||
|
paint);
|
||||||
|
canvas.drawRoundRect(new RectF(right - mDiameter, mMargin, right, bottom), mRadius, mRadius,
|
||||||
|
paint);
|
||||||
|
canvas.drawRect(new RectF(mMargin, mMargin, right - mRadius, bottom - mRadius), paint);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void drawOtherTopRightRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
|
||||||
|
canvas.drawRoundRect(new RectF(mMargin, mMargin, mMargin + mDiameter, bottom), mRadius, mRadius,
|
||||||
|
paint);
|
||||||
|
canvas.drawRoundRect(new RectF(mMargin, bottom - mDiameter, right, bottom), mRadius, mRadius,
|
||||||
|
paint);
|
||||||
|
canvas.drawRect(new RectF(mMargin + mRadius, mMargin, right, bottom - mRadius), paint);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void drawOtherBottomLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
|
||||||
|
canvas.drawRoundRect(new RectF(mMargin, mMargin, right, mMargin + mDiameter), mRadius, mRadius,
|
||||||
|
paint);
|
||||||
|
canvas.drawRoundRect(new RectF(right - mDiameter, mMargin, right, bottom), mRadius, mRadius,
|
||||||
|
paint);
|
||||||
|
canvas.drawRect(new RectF(mMargin, mMargin + mRadius, right - mRadius, bottom), paint);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void drawOtherBottomRightRoundRect(Canvas canvas, Paint paint, float right,
|
||||||
|
float bottom) {
|
||||||
|
canvas.drawRoundRect(new RectF(mMargin, mMargin, right, mMargin + mDiameter), mRadius, mRadius,
|
||||||
|
paint);
|
||||||
|
canvas.drawRoundRect(new RectF(mMargin, mMargin, mMargin + mDiameter, bottom), mRadius, mRadius,
|
||||||
|
paint);
|
||||||
|
canvas.drawRect(new RectF(mMargin + mRadius, mMargin + mRadius, right, bottom), paint);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void drawDiagonalFromTopLeftRoundRect(Canvas canvas, Paint paint, float right,
|
||||||
|
float bottom) {
|
||||||
|
canvas.drawRoundRect(new RectF(mMargin, mMargin, mMargin + mDiameter, mMargin + mDiameter),
|
||||||
|
mRadius, mRadius, paint);
|
||||||
|
canvas.drawRoundRect(new RectF(right - mDiameter, bottom - mDiameter, right, bottom), mRadius,
|
||||||
|
mRadius, paint);
|
||||||
|
canvas.drawRect(new RectF(mMargin, mMargin + mRadius, right - mDiameter, bottom), paint);
|
||||||
|
canvas.drawRect(new RectF(mMargin + mDiameter, mMargin, right, bottom - mRadius), paint);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void drawDiagonalFromTopRightRoundRect(Canvas canvas, Paint paint, float right,
|
||||||
|
float bottom) {
|
||||||
|
canvas.drawRoundRect(new RectF(right - mDiameter, mMargin, right, mMargin + mDiameter), mRadius,
|
||||||
|
mRadius, paint);
|
||||||
|
canvas.drawRoundRect(new RectF(mMargin, bottom - mDiameter, mMargin + mDiameter, bottom),
|
||||||
|
mRadius, mRadius, paint);
|
||||||
|
canvas.drawRect(new RectF(mMargin, mMargin, right - mRadius, bottom - mRadius), paint);
|
||||||
|
canvas.drawRect(new RectF(mMargin + mRadius, mMargin + mRadius, right, bottom), paint);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public String getId() {
|
||||||
|
return "RoundedTransformation(radius=" + mRadius + ", margin=" + mMargin + ", diameter="
|
||||||
|
+ mDiameter + ", cornerType=" + mCornerType.name() + ")";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,56 +16,38 @@ package jp.wasabeef.glide.transformations.gpu;
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import com.bumptech.glide.load.Transformation;
|
|
||||||
import com.bumptech.glide.load.engine.Resource;
|
|
||||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
|
||||||
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
|
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Bitmap;
|
import com.bumptech.glide.Glide;
|
||||||
|
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||||
import jp.co.cyberagent.android.gpuimage.GPUImage;
|
|
||||||
import jp.co.cyberagent.android.gpuimage.GPUImageBrightnessFilter;
|
import jp.co.cyberagent.android.gpuimage.GPUImageBrightnessFilter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* brightness value ranges from -1.0 to 1.0, with 0.0 as the normal level
|
* brightness value ranges from -1.0 to 1.0, with 0.0 as the normal level
|
||||||
*/
|
*/
|
||||||
public class BrightnessFilterTransformation implements Transformation<Bitmap> {
|
public class BrightnessFilterTransformation extends GPUFilterTransformation {
|
||||||
|
|
||||||
private Context mContext;
|
|
||||||
private BitmapPool mBitmapPool;
|
|
||||||
|
|
||||||
private GPUImageBrightnessFilter mFilter = new GPUImageBrightnessFilter();
|
|
||||||
private float mBrightness;
|
private float mBrightness;
|
||||||
|
|
||||||
|
public BrightnessFilterTransformation(Context context) {
|
||||||
|
this(context, Glide.get(context).getBitmapPool());
|
||||||
|
}
|
||||||
|
|
||||||
public BrightnessFilterTransformation(Context context, BitmapPool pool) {
|
public BrightnessFilterTransformation(Context context, BitmapPool pool) {
|
||||||
mContext = context;
|
this(context, pool, 0.0f);
|
||||||
mBitmapPool = pool;
|
}
|
||||||
|
|
||||||
|
public BrightnessFilterTransformation(Context context, float brightness) {
|
||||||
|
this(context, Glide.get(context).getBitmapPool(), brightness);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BrightnessFilterTransformation(Context context, BitmapPool pool, float brightness) {
|
public BrightnessFilterTransformation(Context context, BitmapPool pool, float brightness) {
|
||||||
mContext = context;
|
super(context, pool, new GPUImageBrightnessFilter());
|
||||||
mBitmapPool = pool;
|
|
||||||
mBrightness = brightness;
|
mBrightness = brightness;
|
||||||
mFilter.setBrightness(mBrightness);
|
GPUImageBrightnessFilter filter = getFilter();
|
||||||
|
filter.setBrightness(mBrightness);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public String getId() {
|
||||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
|
||||||
Bitmap source = resource.get();
|
|
||||||
|
|
||||||
GPUImage gpuImage = new GPUImage(mContext);
|
|
||||||
gpuImage.setImage(source);
|
|
||||||
gpuImage.setFilter(mFilter);
|
|
||||||
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
|
||||||
|
|
||||||
source.recycle();
|
|
||||||
|
|
||||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getId() {
|
|
||||||
return "BrightnessFilterTransformation(brightness=" + mBrightness + ")";
|
return "BrightnessFilterTransformation(brightness=" + mBrightness + ")";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,56 +16,38 @@ package jp.wasabeef.glide.transformations.gpu;
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import com.bumptech.glide.load.Transformation;
|
|
||||||
import com.bumptech.glide.load.engine.Resource;
|
|
||||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
|
||||||
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
|
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Bitmap;
|
import com.bumptech.glide.Glide;
|
||||||
|
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||||
import jp.co.cyberagent.android.gpuimage.GPUImage;
|
|
||||||
import jp.co.cyberagent.android.gpuimage.GPUImageContrastFilter;
|
import jp.co.cyberagent.android.gpuimage.GPUImageContrastFilter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* contrast value ranges from 0.0 to 4.0, with 1.0 as the normal level
|
* contrast value ranges from 0.0 to 4.0, with 1.0 as the normal level
|
||||||
*/
|
*/
|
||||||
public class ContrastFilterTransformation implements Transformation<Bitmap> {
|
public class ContrastFilterTransformation extends GPUFilterTransformation {
|
||||||
|
|
||||||
private Context mContext;
|
|
||||||
private BitmapPool mBitmapPool;
|
|
||||||
|
|
||||||
private GPUImageContrastFilter mFilter = new GPUImageContrastFilter();
|
|
||||||
private float mContrast;
|
private float mContrast;
|
||||||
|
|
||||||
|
public ContrastFilterTransformation(Context context) {
|
||||||
|
this(context, Glide.get(context).getBitmapPool());
|
||||||
|
}
|
||||||
|
|
||||||
public ContrastFilterTransformation(Context context, BitmapPool pool) {
|
public ContrastFilterTransformation(Context context, BitmapPool pool) {
|
||||||
mContext = context;
|
this(context, pool, 1.0f);
|
||||||
mBitmapPool = pool;
|
}
|
||||||
|
|
||||||
|
public ContrastFilterTransformation(Context context, float contrast) {
|
||||||
|
this(context, Glide.get(context).getBitmapPool(), contrast);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ContrastFilterTransformation(Context context, BitmapPool pool, float contrast) {
|
public ContrastFilterTransformation(Context context, BitmapPool pool, float contrast) {
|
||||||
mContext = context;
|
super(context, pool, new GPUImageContrastFilter());
|
||||||
mBitmapPool = pool;
|
|
||||||
mContrast = contrast;
|
mContrast = contrast;
|
||||||
mFilter.setContrast(mContrast);
|
GPUImageContrastFilter filter = getFilter();
|
||||||
|
filter.setContrast(mContrast);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public String getId() {
|
||||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
|
||||||
Bitmap source = resource.get();
|
|
||||||
|
|
||||||
GPUImage gpuImage = new GPUImage(mContext);
|
|
||||||
gpuImage.setImage(source);
|
|
||||||
gpuImage.setFilter(mFilter);
|
|
||||||
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
|
||||||
|
|
||||||
source.recycle();
|
|
||||||
|
|
||||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getId() {
|
|
||||||
return "ContrastFilterTransformation(contrast=" + mContrast + ")";
|
return "ContrastFilterTransformation(contrast=" + mContrast + ")";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,65 @@
|
|||||||
|
package jp.wasabeef.glide.transformations.gpu;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copyright (C) 2015 Wasabeef
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import com.bumptech.glide.Glide;
|
||||||
|
import com.bumptech.glide.load.Transformation;
|
||||||
|
import com.bumptech.glide.load.engine.Resource;
|
||||||
|
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||||
|
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
|
||||||
|
import jp.co.cyberagent.android.gpuimage.GPUImage;
|
||||||
|
import jp.co.cyberagent.android.gpuimage.GPUImageFilter;
|
||||||
|
|
||||||
|
public class GPUFilterTransformation implements Transformation<Bitmap> {
|
||||||
|
|
||||||
|
private Context mContext;
|
||||||
|
private BitmapPool mBitmapPool;
|
||||||
|
|
||||||
|
private GPUImageFilter mFilter;
|
||||||
|
|
||||||
|
public GPUFilterTransformation(Context context, GPUImageFilter filter) {
|
||||||
|
this(context, Glide.get(context).getBitmapPool(), filter);
|
||||||
|
}
|
||||||
|
|
||||||
|
public GPUFilterTransformation(Context context, BitmapPool pool, GPUImageFilter filter) {
|
||||||
|
mContext = context.getApplicationContext();
|
||||||
|
mBitmapPool = pool;
|
||||||
|
mFilter = filter;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
||||||
|
Bitmap source = resource.get();
|
||||||
|
GPUImage gpuImage = new GPUImage(mContext);
|
||||||
|
gpuImage.setImage(source);
|
||||||
|
gpuImage.setFilter(mFilter);
|
||||||
|
|
||||||
|
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
||||||
|
|
||||||
|
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public String getId() {
|
||||||
|
return getClass().getSimpleName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked") public <T> T getFilter() {
|
||||||
|
return (T) mFilter;
|
||||||
|
}
|
||||||
|
}
|
@@ -16,43 +16,25 @@ package jp.wasabeef.glide.transformations.gpu;
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import com.bumptech.glide.load.Transformation;
|
|
||||||
import com.bumptech.glide.load.engine.Resource;
|
|
||||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
|
||||||
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
|
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Bitmap;
|
import com.bumptech.glide.Glide;
|
||||||
|
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||||
import jp.co.cyberagent.android.gpuimage.GPUImage;
|
|
||||||
import jp.co.cyberagent.android.gpuimage.GPUImageColorInvertFilter;
|
import jp.co.cyberagent.android.gpuimage.GPUImageColorInvertFilter;
|
||||||
|
|
||||||
public class InvertFilterTransformation implements Transformation<Bitmap> {
|
/**
|
||||||
|
* Invert all the colors in the image.
|
||||||
|
*/
|
||||||
|
public class InvertFilterTransformation extends GPUFilterTransformation {
|
||||||
|
|
||||||
private Context mContext;
|
public InvertFilterTransformation(Context context) {
|
||||||
private BitmapPool mBitmapPool;
|
this(context, Glide.get(context).getBitmapPool());
|
||||||
|
}
|
||||||
|
|
||||||
public InvertFilterTransformation(Context context, BitmapPool pool) {
|
public InvertFilterTransformation(Context context, BitmapPool pool) {
|
||||||
mContext = context;
|
super(context, pool, new GPUImageColorInvertFilter());
|
||||||
mBitmapPool = pool;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public String getId() {
|
||||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
|
||||||
Bitmap source = resource.get();
|
|
||||||
|
|
||||||
GPUImage gpuImage = new GPUImage(mContext);
|
|
||||||
gpuImage.setImage(source);
|
|
||||||
gpuImage.setFilter(new GPUImageColorInvertFilter());
|
|
||||||
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
|
||||||
|
|
||||||
source.recycle();
|
|
||||||
|
|
||||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getId() {
|
|
||||||
return "InvertFilterTransformation()";
|
return "InvertFilterTransformation()";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,57 +16,41 @@ package jp.wasabeef.glide.transformations.gpu;
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import com.bumptech.glide.load.Transformation;
|
|
||||||
import com.bumptech.glide.load.engine.Resource;
|
|
||||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
|
||||||
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
|
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Bitmap;
|
import com.bumptech.glide.Glide;
|
||||||
|
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||||
import jp.co.cyberagent.android.gpuimage.GPUImage;
|
|
||||||
import jp.co.cyberagent.android.gpuimage.GPUImageKuwaharaFilter;
|
import jp.co.cyberagent.android.gpuimage.GPUImageKuwaharaFilter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The radius to sample from when creating the brush-stroke effect, with a default of 3.
|
* Kuwahara all the colors in the image.
|
||||||
|
*
|
||||||
|
* The radius to sample from when creating the brush-stroke effect, with a default of 25.
|
||||||
* The larger the radius, the slower the filter.
|
* The larger the radius, the slower the filter.
|
||||||
*/
|
*/
|
||||||
public class KuwaharaFilterTransformation implements Transformation<Bitmap> {
|
public class KuwaharaFilterTransformation extends GPUFilterTransformation {
|
||||||
|
|
||||||
private Context mContext;
|
|
||||||
private BitmapPool mBitmapPool;
|
|
||||||
|
|
||||||
private GPUImageKuwaharaFilter mFilter = new GPUImageKuwaharaFilter();
|
|
||||||
private int mRadius;
|
private int mRadius;
|
||||||
|
|
||||||
|
public KuwaharaFilterTransformation(Context context) {
|
||||||
|
this(context, Glide.get(context).getBitmapPool());
|
||||||
|
}
|
||||||
|
|
||||||
public KuwaharaFilterTransformation(Context context, BitmapPool pool) {
|
public KuwaharaFilterTransformation(Context context, BitmapPool pool) {
|
||||||
mContext = context;
|
this(context, pool, 25);
|
||||||
mBitmapPool = pool;
|
}
|
||||||
|
|
||||||
|
public KuwaharaFilterTransformation(Context context, int radius) {
|
||||||
|
this(context, Glide.get(context).getBitmapPool(), radius);
|
||||||
}
|
}
|
||||||
|
|
||||||
public KuwaharaFilterTransformation(Context context, BitmapPool pool, int radius) {
|
public KuwaharaFilterTransformation(Context context, BitmapPool pool, int radius) {
|
||||||
mContext = context;
|
super(context, pool, new GPUImageKuwaharaFilter());
|
||||||
mBitmapPool = pool;
|
|
||||||
mRadius = radius;
|
mRadius = radius;
|
||||||
mFilter.setRadius(mRadius);
|
GPUImageKuwaharaFilter filter = getFilter();
|
||||||
|
filter.setRadius(mRadius);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public String getId() {
|
||||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
|
||||||
Bitmap source = resource.get();
|
|
||||||
|
|
||||||
GPUImage gpuImage = new GPUImage(mContext);
|
|
||||||
gpuImage.setImage(source);
|
|
||||||
gpuImage.setFilter(mFilter);
|
|
||||||
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
|
||||||
|
|
||||||
source.recycle();
|
|
||||||
|
|
||||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getId() {
|
|
||||||
return "KuwaharaFilterTransformation(radius=" + mRadius + ")";
|
return "KuwaharaFilterTransformation(radius=" + mRadius + ")";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,53 +16,40 @@ package jp.wasabeef.glide.transformations.gpu;
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import com.bumptech.glide.load.Transformation;
|
|
||||||
import com.bumptech.glide.load.engine.Resource;
|
|
||||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
|
||||||
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
|
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Bitmap;
|
import com.bumptech.glide.Glide;
|
||||||
|
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||||
import jp.co.cyberagent.android.gpuimage.GPUImage;
|
|
||||||
import jp.co.cyberagent.android.gpuimage.GPUImagePixelationFilter;
|
import jp.co.cyberagent.android.gpuimage.GPUImagePixelationFilter;
|
||||||
|
|
||||||
public class PixelationFilterTransformation implements Transformation<Bitmap> {
|
/**
|
||||||
|
* Applies a Pixelation effect to the image.
|
||||||
|
*
|
||||||
|
* The pixel with a default of 10.0.
|
||||||
|
*/
|
||||||
|
public class PixelationFilterTransformation extends GPUFilterTransformation {
|
||||||
|
|
||||||
private Context mContext;
|
|
||||||
private BitmapPool mBitmapPool;
|
|
||||||
|
|
||||||
private GPUImagePixelationFilter mFilter = new GPUImagePixelationFilter();
|
|
||||||
private float mPixel;
|
private float mPixel;
|
||||||
|
|
||||||
|
public PixelationFilterTransformation(Context context) {
|
||||||
|
this(context, Glide.get(context).getBitmapPool());
|
||||||
|
}
|
||||||
|
|
||||||
public PixelationFilterTransformation(Context context, BitmapPool pool) {
|
public PixelationFilterTransformation(Context context, BitmapPool pool) {
|
||||||
mContext = context;
|
this(context, pool, 10f);
|
||||||
mBitmapPool = pool;
|
}
|
||||||
|
|
||||||
|
public PixelationFilterTransformation(Context context, float pixel) {
|
||||||
|
this(context, Glide.get(context).getBitmapPool(), pixel);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PixelationFilterTransformation(Context context, BitmapPool pool, float pixel) {
|
public PixelationFilterTransformation(Context context, BitmapPool pool, float pixel) {
|
||||||
mContext = context;
|
super(context, pool, new GPUImagePixelationFilter());
|
||||||
mBitmapPool = pool;
|
|
||||||
mPixel = pixel;
|
mPixel = pixel;
|
||||||
mFilter.setPixel(mPixel);
|
GPUImagePixelationFilter filter = getFilter();
|
||||||
|
filter.setPixel(mPixel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public String getId() {
|
||||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
|
||||||
Bitmap source = resource.get();
|
|
||||||
|
|
||||||
GPUImage gpuImage = new GPUImage(mContext);
|
|
||||||
gpuImage.setImage(source);
|
|
||||||
gpuImage.setFilter(mFilter);
|
|
||||||
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
|
||||||
|
|
||||||
source.recycle();
|
|
||||||
|
|
||||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getId() {
|
|
||||||
return "PixelationFilterTransformation(pixel=" + mPixel + ")";
|
return "PixelationFilterTransformation(pixel=" + mPixel + ")";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,53 +16,40 @@ package jp.wasabeef.glide.transformations.gpu;
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import com.bumptech.glide.load.Transformation;
|
|
||||||
import com.bumptech.glide.load.engine.Resource;
|
|
||||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
|
||||||
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
|
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Bitmap;
|
import com.bumptech.glide.Glide;
|
||||||
|
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||||
import jp.co.cyberagent.android.gpuimage.GPUImage;
|
|
||||||
import jp.co.cyberagent.android.gpuimage.GPUImageSepiaFilter;
|
import jp.co.cyberagent.android.gpuimage.GPUImageSepiaFilter;
|
||||||
|
|
||||||
public class SepiaFilterTransformation implements Transformation<Bitmap> {
|
/**
|
||||||
|
* Applies a simple sepia effect.
|
||||||
|
*
|
||||||
|
* The intensity with a default of 1.0.
|
||||||
|
*/
|
||||||
|
public class SepiaFilterTransformation extends GPUFilterTransformation {
|
||||||
|
|
||||||
private Context mContext;
|
|
||||||
private BitmapPool mBitmapPool;
|
|
||||||
|
|
||||||
private GPUImageSepiaFilter mFilter = new GPUImageSepiaFilter();
|
|
||||||
private float mIntensity;
|
private float mIntensity;
|
||||||
|
|
||||||
|
public SepiaFilterTransformation(Context context) {
|
||||||
|
this(context, Glide.get(context).getBitmapPool());
|
||||||
|
}
|
||||||
|
|
||||||
public SepiaFilterTransformation(Context context, BitmapPool pool) {
|
public SepiaFilterTransformation(Context context, BitmapPool pool) {
|
||||||
mContext = context;
|
this(context, pool, 1.0f);
|
||||||
mBitmapPool = pool;
|
}
|
||||||
|
|
||||||
|
public SepiaFilterTransformation(Context context, float intensity) {
|
||||||
|
this(context, Glide.get(context).getBitmapPool(), intensity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SepiaFilterTransformation(Context context, BitmapPool pool, float intensity) {
|
public SepiaFilterTransformation(Context context, BitmapPool pool, float intensity) {
|
||||||
mContext = context;
|
super(context, pool, new GPUImageSepiaFilter());
|
||||||
mBitmapPool = pool;
|
|
||||||
mIntensity = intensity;
|
mIntensity = intensity;
|
||||||
mFilter.setIntensity(mIntensity);
|
GPUImageSepiaFilter filter = getFilter();
|
||||||
|
filter.setIntensity(mIntensity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public String getId() {
|
||||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
|
||||||
Bitmap source = resource.get();
|
|
||||||
|
|
||||||
GPUImage gpuImage = new GPUImage(mContext);
|
|
||||||
gpuImage.setImage(source);
|
|
||||||
gpuImage.setFilter(mFilter);
|
|
||||||
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
|
||||||
|
|
||||||
source.recycle();
|
|
||||||
|
|
||||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getId() {
|
|
||||||
return "SepiaFilterTransformation(intensity=" + mIntensity + ")";
|
return "SepiaFilterTransformation(intensity=" + mIntensity + ")";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,43 +16,22 @@ package jp.wasabeef.glide.transformations.gpu;
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import com.bumptech.glide.load.Transformation;
|
|
||||||
import com.bumptech.glide.load.engine.Resource;
|
|
||||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
|
||||||
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
|
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Bitmap;
|
import com.bumptech.glide.Glide;
|
||||||
|
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||||
import jp.co.cyberagent.android.gpuimage.GPUImage;
|
|
||||||
import jp.co.cyberagent.android.gpuimage.GPUImageSketchFilter;
|
import jp.co.cyberagent.android.gpuimage.GPUImageSketchFilter;
|
||||||
|
|
||||||
public class SketchFilterTransformation implements Transformation<Bitmap> {
|
public class SketchFilterTransformation extends GPUFilterTransformation {
|
||||||
|
|
||||||
private Context mContext;
|
public SketchFilterTransformation(Context context) {
|
||||||
private BitmapPool mBitmapPool;
|
this(context, Glide.get(context).getBitmapPool());
|
||||||
|
}
|
||||||
|
|
||||||
public SketchFilterTransformation(Context context, BitmapPool pool) {
|
public SketchFilterTransformation(Context context, BitmapPool pool) {
|
||||||
mContext = context;
|
super(context, pool, new GPUImageSketchFilter());
|
||||||
mBitmapPool = pool;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public String getId() {
|
||||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
|
||||||
Bitmap source = resource.get();
|
|
||||||
|
|
||||||
GPUImage gpuImage = new GPUImage(mContext);
|
|
||||||
gpuImage.setImage(source);
|
|
||||||
gpuImage.setFilter(new GPUImageSketchFilter());
|
|
||||||
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
|
||||||
|
|
||||||
source.recycle();
|
|
||||||
|
|
||||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getId() {
|
|
||||||
return "SketchFilterTransformation()";
|
return "SketchFilterTransformation()";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,32 +16,31 @@ package jp.wasabeef.glide.transformations.gpu;
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import com.bumptech.glide.load.Transformation;
|
|
||||||
import com.bumptech.glide.load.engine.Resource;
|
|
||||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
|
||||||
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
|
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Bitmap;
|
|
||||||
import android.graphics.PointF;
|
import android.graphics.PointF;
|
||||||
|
import com.bumptech.glide.Glide;
|
||||||
import jp.co.cyberagent.android.gpuimage.GPUImage;
|
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||||
import jp.co.cyberagent.android.gpuimage.GPUImageSwirlFilter;
|
import jp.co.cyberagent.android.gpuimage.GPUImageSwirlFilter;
|
||||||
|
|
||||||
public class SwirlFilterTransformation implements Transformation<Bitmap> {
|
/**
|
||||||
|
* Creates a swirl distortion on the image.
|
||||||
|
*/
|
||||||
|
public class SwirlFilterTransformation extends GPUFilterTransformation {
|
||||||
|
|
||||||
private Context mContext;
|
|
||||||
private BitmapPool mBitmapPool;
|
|
||||||
|
|
||||||
private GPUImageSwirlFilter mFilter = new GPUImageSwirlFilter();
|
|
||||||
private float mRadius;
|
private float mRadius;
|
||||||
private float mAngle;
|
private float mAngle;
|
||||||
private PointF mCenter;
|
private PointF mCenter;
|
||||||
|
|
||||||
|
public SwirlFilterTransformation(Context context) {
|
||||||
|
this(context, Glide.get(context).getBitmapPool());
|
||||||
|
}
|
||||||
|
|
||||||
public SwirlFilterTransformation(Context context, BitmapPool pool) {
|
public SwirlFilterTransformation(Context context, BitmapPool pool) {
|
||||||
mContext = context;
|
this(context, pool, .5f, 1.0f, new PointF(0.5f, 0.5f));
|
||||||
mBitmapPool = pool;
|
}
|
||||||
mCenter = new PointF();
|
|
||||||
|
public SwirlFilterTransformation(Context context, float radius, float angle, PointF center) {
|
||||||
|
this(context, Glide.get(context).getBitmapPool(), radius, angle, center);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -49,34 +48,19 @@ public class SwirlFilterTransformation implements Transformation<Bitmap> {
|
|||||||
* @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,
|
public SwirlFilterTransformation(Context context, BitmapPool pool, float radius, float angle,
|
||||||
float radius, float angle, PointF center) {
|
PointF center) {
|
||||||
mContext = context;
|
super(context, pool, new GPUImageSwirlFilter());
|
||||||
mBitmapPool = pool;
|
|
||||||
mRadius = radius;
|
mRadius = radius;
|
||||||
mAngle = angle;
|
mAngle = angle;
|
||||||
mCenter = center;
|
mCenter = center;
|
||||||
mFilter.setRadius(mRadius);
|
GPUImageSwirlFilter filter = getFilter();
|
||||||
mFilter.setAngle(mAngle);
|
filter.setRadius(mRadius);
|
||||||
mFilter.setCenter(mCenter);
|
filter.setAngle(mAngle);
|
||||||
|
filter.setCenter(mCenter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public String getId() {
|
||||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
|
||||||
Bitmap source = resource.get();
|
|
||||||
|
|
||||||
GPUImage gpuImage = new GPUImage(mContext);
|
|
||||||
gpuImage.setImage(source);
|
|
||||||
gpuImage.setFilter(mFilter);
|
|
||||||
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
|
||||||
|
|
||||||
source.recycle();
|
|
||||||
|
|
||||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getId() {
|
|
||||||
return "SwirlFilterTransformation(radius=" + mRadius +
|
return "SwirlFilterTransformation(radius=" + mRadius +
|
||||||
",angle=" + mAngle + ",center=" + mCenter.toString() + ")";
|
",angle=" + mAngle + ",center=" + mCenter.toString() + ")";
|
||||||
}
|
}
|
||||||
|
@@ -16,57 +16,44 @@ package jp.wasabeef.glide.transformations.gpu;
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import com.bumptech.glide.load.Transformation;
|
|
||||||
import com.bumptech.glide.load.engine.Resource;
|
|
||||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
|
||||||
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
|
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Bitmap;
|
import com.bumptech.glide.Glide;
|
||||||
|
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||||
import jp.co.cyberagent.android.gpuimage.GPUImage;
|
|
||||||
import jp.co.cyberagent.android.gpuimage.GPUImageToonFilter;
|
import jp.co.cyberagent.android.gpuimage.GPUImageToonFilter;
|
||||||
|
|
||||||
public class ToonFilterTransformation implements Transformation<Bitmap> {
|
/**
|
||||||
|
* The threshold at which to apply the edges, default of 0.2.
|
||||||
|
* The levels of quantization for the posterization of colors within the scene,
|
||||||
|
* with a default of 10.0.
|
||||||
|
*/
|
||||||
|
public class ToonFilterTransformation extends GPUFilterTransformation {
|
||||||
|
|
||||||
private Context mContext;
|
|
||||||
private BitmapPool mBitmapPool;
|
|
||||||
|
|
||||||
private GPUImageToonFilter mFilter = new GPUImageToonFilter();
|
|
||||||
private float mThreshold;
|
private float mThreshold;
|
||||||
private float mQuantizationLevels;
|
private float mQuantizationLevels;
|
||||||
|
|
||||||
public ToonFilterTransformation(Context context, BitmapPool pool) {
|
public ToonFilterTransformation(Context context) {
|
||||||
mContext = context;
|
this(context, Glide.get(context).getBitmapPool());
|
||||||
mBitmapPool = pool;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ToonFilterTransformation(Context context, BitmapPool pool,
|
public ToonFilterTransformation(Context context, BitmapPool pool) {
|
||||||
float threshold, float quantizationLevels) {
|
this(context, pool, .2f, 10.0f);
|
||||||
mContext = context;
|
}
|
||||||
mBitmapPool = pool;
|
|
||||||
|
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;
|
mThreshold = threshold;
|
||||||
mQuantizationLevels = quantizationLevels;
|
mQuantizationLevels = quantizationLevels;
|
||||||
mFilter.setThreshold(mThreshold);
|
GPUImageToonFilter filter = getFilter();
|
||||||
mFilter.setQuantizationLevels(mQuantizationLevels);
|
filter.setThreshold(mThreshold);
|
||||||
|
filter.setQuantizationLevels(mQuantizationLevels);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public String getId() {
|
||||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
|
||||||
Bitmap source = resource.get();
|
|
||||||
|
|
||||||
GPUImage gpuImage = new GPUImage(mContext);
|
|
||||||
gpuImage.setImage(source);
|
|
||||||
gpuImage.setFilter(mFilter);
|
|
||||||
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
|
||||||
|
|
||||||
source.recycle();
|
|
||||||
|
|
||||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getId() {
|
|
||||||
return "ToonFilterTransformation(threshold=" + mThreshold +
|
return "ToonFilterTransformation(threshold=" + mThreshold +
|
||||||
",quantizationLevels=" + mQuantizationLevels + ")";
|
",quantizationLevels=" + mQuantizationLevels + ")";
|
||||||
}
|
}
|
||||||
|
@@ -16,73 +16,53 @@ package jp.wasabeef.glide.transformations.gpu;
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import com.bumptech.glide.load.Transformation;
|
|
||||||
import com.bumptech.glide.load.engine.Resource;
|
|
||||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
|
||||||
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
|
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Bitmap;
|
|
||||||
import android.graphics.PointF;
|
import android.graphics.PointF;
|
||||||
|
import com.bumptech.glide.Glide;
|
||||||
|
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import jp.co.cyberagent.android.gpuimage.GPUImage;
|
|
||||||
import jp.co.cyberagent.android.gpuimage.GPUImageVignetteFilter;
|
import jp.co.cyberagent.android.gpuimage.GPUImageVignetteFilter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs a vignetting effect, fading out the image at the edges
|
* Performs a vignetting effect, fading out the image at the edges
|
||||||
* x:
|
* The directional intensity of the vignetting,
|
||||||
* y: The directional intensity of the vignetting, with a default of x = 0.75, y = 0.5
|
* with a default of x = 0.5, y = 0.5, start = 0, end = 0.75
|
||||||
*/
|
*/
|
||||||
public class VignetteFilterTransformation implements Transformation<Bitmap> {
|
public class VignetteFilterTransformation extends GPUFilterTransformation {
|
||||||
|
|
||||||
private Context mContext;
|
|
||||||
private BitmapPool mBitmapPool;
|
|
||||||
|
|
||||||
private GPUImageVignetteFilter mFilter = new GPUImageVignetteFilter();
|
|
||||||
private PointF mCenter;
|
private PointF mCenter;
|
||||||
private float[] mVignetteColor;
|
private float[] mVignetteColor;
|
||||||
private float mVignetteStart;
|
private float mVignetteStart;
|
||||||
private float mVignetteEnd;
|
private float mVignetteEnd;
|
||||||
|
|
||||||
|
public VignetteFilterTransformation(Context context) {
|
||||||
public VignetteFilterTransformation(Context context, BitmapPool pool) {
|
this(context, Glide.get(context).getBitmapPool());
|
||||||
mContext = context;
|
|
||||||
mBitmapPool = pool;
|
|
||||||
mCenter = new PointF();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public VignetteFilterTransformation(Context context, BitmapPool pool,
|
public VignetteFilterTransformation(Context context, BitmapPool pool) {
|
||||||
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);
|
||||||
mContext = context;
|
}
|
||||||
mBitmapPool = pool;
|
|
||||||
|
public VignetteFilterTransformation(Context context, PointF center, float[] color, float start,
|
||||||
|
float end) {
|
||||||
|
this(context, Glide.get(context).getBitmapPool(), center, color, start, end);
|
||||||
|
}
|
||||||
|
|
||||||
|
public VignetteFilterTransformation(Context context, BitmapPool pool, PointF center,
|
||||||
|
float[] color, float start, float end) {
|
||||||
|
super(context, pool, new GPUImageVignetteFilter());
|
||||||
mCenter = center;
|
mCenter = center;
|
||||||
mVignetteColor = color;
|
mVignetteColor = color;
|
||||||
mVignetteStart = start;
|
mVignetteStart = start;
|
||||||
mVignetteEnd = end;
|
mVignetteEnd = end;
|
||||||
mFilter.setVignetteCenter(mCenter);
|
GPUImageVignetteFilter filter = getFilter();
|
||||||
mFilter.setVignetteColor(mVignetteColor);
|
filter.setVignetteCenter(mCenter);
|
||||||
mFilter.setVignetteStart(mVignetteStart);
|
filter.setVignetteColor(mVignetteColor);
|
||||||
mFilter.setVignetteEnd(mVignetteEnd);
|
filter.setVignetteStart(mVignetteStart);
|
||||||
|
filter.setVignetteEnd(mVignetteEnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public String getId() {
|
||||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
|
||||||
Bitmap source = resource.get();
|
|
||||||
|
|
||||||
GPUImage gpuImage = new GPUImage(mContext);
|
|
||||||
gpuImage.setImage(source);
|
|
||||||
gpuImage.setFilter(mFilter);
|
|
||||||
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
|
||||||
|
|
||||||
source.recycle();
|
|
||||||
|
|
||||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getId() {
|
|
||||||
return "VignetteFilterTransformation(center=" + mCenter.toString() +
|
return "VignetteFilterTransformation(center=" + mCenter.toString() +
|
||||||
",color=" + Arrays.toString(mVignetteColor) +
|
",color=" + Arrays.toString(mVignetteColor) +
|
||||||
",start=" + mVignetteStart + ",end=" + mVignetteEnd + ")";
|
",start=" + mVignetteStart + ",end=" + mVignetteEnd + ")";
|
||||||
|
@@ -0,0 +1,257 @@
|
|||||||
|
package jp.wasabeef.glide.transformations.internal;
|
||||||
|
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copyright (C) 2015 Wasabeef
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class FastBlur {
|
||||||
|
|
||||||
|
public static Bitmap blur(Bitmap sentBitmap, int radius, boolean canReuseInBitmap) {
|
||||||
|
|
||||||
|
// Stack Blur v1.0 from
|
||||||
|
// http://www.quasimondo.com/StackBlurForCanvas/StackBlurDemo.html
|
||||||
|
//
|
||||||
|
// Java Author: Mario Klingemann <mario at quasimondo.com>
|
||||||
|
// http://incubator.quasimondo.com
|
||||||
|
// created Feburary 29, 2004
|
||||||
|
// Android port : Yahel Bouaziz <yahel at kayenko.com>
|
||||||
|
// http://www.kayenko.com
|
||||||
|
// ported april 5th, 2012
|
||||||
|
|
||||||
|
// This is a compromise between Gaussian Blur and Box blur
|
||||||
|
// It creates much better looking blurs than Box Blur, but is
|
||||||
|
// 7x faster than my Gaussian Blur implementation.
|
||||||
|
//
|
||||||
|
// I called it Stack Blur because this describes best how this
|
||||||
|
// filter works internally: it creates a kind of moving stack
|
||||||
|
// of colors whilst scanning through the image. Thereby it
|
||||||
|
// just has to add one new block of color to the right side
|
||||||
|
// of the stack and remove the leftmost color. The remaining
|
||||||
|
// colors on the topmost layer of the stack are either added on
|
||||||
|
// or reduced by one, depending on if they are on the right or
|
||||||
|
// on the left side of the stack.
|
||||||
|
//
|
||||||
|
// If you are using this algorithm in your code please add
|
||||||
|
// the following line:
|
||||||
|
//
|
||||||
|
// Stack Blur Algorithm by Mario Klingemann <mario@quasimondo.com>
|
||||||
|
|
||||||
|
Bitmap bitmap;
|
||||||
|
if (canReuseInBitmap) {
|
||||||
|
bitmap = sentBitmap;
|
||||||
|
} else {
|
||||||
|
bitmap = sentBitmap.copy(sentBitmap.getConfig(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (radius < 1) {
|
||||||
|
return (null);
|
||||||
|
}
|
||||||
|
|
||||||
|
int w = bitmap.getWidth();
|
||||||
|
int h = bitmap.getHeight();
|
||||||
|
|
||||||
|
int[] pix = new int[w * h];
|
||||||
|
bitmap.getPixels(pix, 0, w, 0, 0, w, h);
|
||||||
|
|
||||||
|
int wm = w - 1;
|
||||||
|
int hm = h - 1;
|
||||||
|
int wh = w * h;
|
||||||
|
int div = radius + radius + 1;
|
||||||
|
|
||||||
|
int r[] = new int[wh];
|
||||||
|
int g[] = new int[wh];
|
||||||
|
int b[] = new int[wh];
|
||||||
|
int rsum, gsum, bsum, x, y, i, p, yp, yi, yw;
|
||||||
|
int vmin[] = new int[Math.max(w, h)];
|
||||||
|
|
||||||
|
int divsum = (div + 1) >> 1;
|
||||||
|
divsum *= divsum;
|
||||||
|
int dv[] = new int[256 * divsum];
|
||||||
|
for (i = 0; i < 256 * divsum; i++) {
|
||||||
|
dv[i] = (i / divsum);
|
||||||
|
}
|
||||||
|
|
||||||
|
yw = yi = 0;
|
||||||
|
|
||||||
|
int[][] stack = new int[div][3];
|
||||||
|
int stackpointer;
|
||||||
|
int stackstart;
|
||||||
|
int[] sir;
|
||||||
|
int rbs;
|
||||||
|
int r1 = radius + 1;
|
||||||
|
int routsum, goutsum, boutsum;
|
||||||
|
int rinsum, ginsum, binsum;
|
||||||
|
|
||||||
|
for (y = 0; y < h; y++) {
|
||||||
|
rinsum = ginsum = binsum = routsum = goutsum = boutsum = rsum = gsum = bsum = 0;
|
||||||
|
for (i = -radius; i <= radius; i++) {
|
||||||
|
p = pix[yi + Math.min(wm, Math.max(i, 0))];
|
||||||
|
sir = stack[i + radius];
|
||||||
|
sir[0] = (p & 0xff0000) >> 16;
|
||||||
|
sir[1] = (p & 0x00ff00) >> 8;
|
||||||
|
sir[2] = (p & 0x0000ff);
|
||||||
|
rbs = r1 - Math.abs(i);
|
||||||
|
rsum += sir[0] * rbs;
|
||||||
|
gsum += sir[1] * rbs;
|
||||||
|
bsum += sir[2] * rbs;
|
||||||
|
if (i > 0) {
|
||||||
|
rinsum += sir[0];
|
||||||
|
ginsum += sir[1];
|
||||||
|
binsum += sir[2];
|
||||||
|
} else {
|
||||||
|
routsum += sir[0];
|
||||||
|
goutsum += sir[1];
|
||||||
|
boutsum += sir[2];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stackpointer = radius;
|
||||||
|
|
||||||
|
for (x = 0; x < w; x++) {
|
||||||
|
|
||||||
|
r[yi] = dv[rsum];
|
||||||
|
g[yi] = dv[gsum];
|
||||||
|
b[yi] = dv[bsum];
|
||||||
|
|
||||||
|
rsum -= routsum;
|
||||||
|
gsum -= goutsum;
|
||||||
|
bsum -= boutsum;
|
||||||
|
|
||||||
|
stackstart = stackpointer - radius + div;
|
||||||
|
sir = stack[stackstart % div];
|
||||||
|
|
||||||
|
routsum -= sir[0];
|
||||||
|
goutsum -= sir[1];
|
||||||
|
boutsum -= sir[2];
|
||||||
|
|
||||||
|
if (y == 0) {
|
||||||
|
vmin[x] = Math.min(x + radius + 1, wm);
|
||||||
|
}
|
||||||
|
p = pix[yw + vmin[x]];
|
||||||
|
|
||||||
|
sir[0] = (p & 0xff0000) >> 16;
|
||||||
|
sir[1] = (p & 0x00ff00) >> 8;
|
||||||
|
sir[2] = (p & 0x0000ff);
|
||||||
|
|
||||||
|
rinsum += sir[0];
|
||||||
|
ginsum += sir[1];
|
||||||
|
binsum += sir[2];
|
||||||
|
|
||||||
|
rsum += rinsum;
|
||||||
|
gsum += ginsum;
|
||||||
|
bsum += binsum;
|
||||||
|
|
||||||
|
stackpointer = (stackpointer + 1) % div;
|
||||||
|
sir = stack[(stackpointer) % div];
|
||||||
|
|
||||||
|
routsum += sir[0];
|
||||||
|
goutsum += sir[1];
|
||||||
|
boutsum += sir[2];
|
||||||
|
|
||||||
|
rinsum -= sir[0];
|
||||||
|
ginsum -= sir[1];
|
||||||
|
binsum -= sir[2];
|
||||||
|
|
||||||
|
yi++;
|
||||||
|
}
|
||||||
|
yw += w;
|
||||||
|
}
|
||||||
|
for (x = 0; x < w; x++) {
|
||||||
|
rinsum = ginsum = binsum = routsum = goutsum = boutsum = rsum = gsum = bsum = 0;
|
||||||
|
yp = -radius * w;
|
||||||
|
for (i = -radius; i <= radius; i++) {
|
||||||
|
yi = Math.max(0, yp) + x;
|
||||||
|
|
||||||
|
sir = stack[i + radius];
|
||||||
|
|
||||||
|
sir[0] = r[yi];
|
||||||
|
sir[1] = g[yi];
|
||||||
|
sir[2] = b[yi];
|
||||||
|
|
||||||
|
rbs = r1 - Math.abs(i);
|
||||||
|
|
||||||
|
rsum += r[yi] * rbs;
|
||||||
|
gsum += g[yi] * rbs;
|
||||||
|
bsum += b[yi] * rbs;
|
||||||
|
|
||||||
|
if (i > 0) {
|
||||||
|
rinsum += sir[0];
|
||||||
|
ginsum += sir[1];
|
||||||
|
binsum += sir[2];
|
||||||
|
} else {
|
||||||
|
routsum += sir[0];
|
||||||
|
goutsum += sir[1];
|
||||||
|
boutsum += sir[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i < hm) {
|
||||||
|
yp += w;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
yi = x;
|
||||||
|
stackpointer = radius;
|
||||||
|
for (y = 0; y < h; y++) {
|
||||||
|
// Preserve alpha channel: ( 0xff000000 & pix[yi] )
|
||||||
|
pix[yi] = (0xff000000 & pix[yi]) | (dv[rsum] << 16) | (dv[gsum] << 8) | dv[bsum];
|
||||||
|
|
||||||
|
rsum -= routsum;
|
||||||
|
gsum -= goutsum;
|
||||||
|
bsum -= boutsum;
|
||||||
|
|
||||||
|
stackstart = stackpointer - radius + div;
|
||||||
|
sir = stack[stackstart % div];
|
||||||
|
|
||||||
|
routsum -= sir[0];
|
||||||
|
goutsum -= sir[1];
|
||||||
|
boutsum -= sir[2];
|
||||||
|
|
||||||
|
if (x == 0) {
|
||||||
|
vmin[y] = Math.min(y + r1, hm) * w;
|
||||||
|
}
|
||||||
|
p = x + vmin[y];
|
||||||
|
|
||||||
|
sir[0] = r[p];
|
||||||
|
sir[1] = g[p];
|
||||||
|
sir[2] = b[p];
|
||||||
|
|
||||||
|
rinsum += sir[0];
|
||||||
|
ginsum += sir[1];
|
||||||
|
binsum += sir[2];
|
||||||
|
|
||||||
|
rsum += rinsum;
|
||||||
|
gsum += ginsum;
|
||||||
|
bsum += binsum;
|
||||||
|
|
||||||
|
stackpointer = (stackpointer + 1) % div;
|
||||||
|
sir = stack[stackpointer];
|
||||||
|
|
||||||
|
routsum += sir[0];
|
||||||
|
goutsum += sir[1];
|
||||||
|
boutsum += sir[2];
|
||||||
|
|
||||||
|
rinsum -= sir[0];
|
||||||
|
ginsum -= sir[1];
|
||||||
|
binsum -= sir[2];
|
||||||
|
|
||||||
|
yi += w;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bitmap.setPixels(pix, 0, w, 0, 0, w, h);
|
||||||
|
|
||||||
|
return (bitmap);
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,55 @@
|
|||||||
|
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) 2015 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;
|
||||||
|
try {
|
||||||
|
rs = RenderScript.create(context);
|
||||||
|
rs.setMessageHandler(new RenderScript.RSMessageHandler());
|
||||||
|
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(radius);
|
||||||
|
blur.forEach(output);
|
||||||
|
output.copyTo(bitmap);
|
||||||
|
} finally {
|
||||||
|
if (rs != null) {
|
||||||
|
rs.destroy();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return bitmap;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,43 @@
|
|||||||
|
package jp.wasabeef.glide.transformations.internal;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.os.Build;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copyright (C) 2015 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 final class Utils {
|
||||||
|
|
||||||
|
private Utils() {
|
||||||
|
// Utility class.
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Drawable getMaskDrawable(Context context, int maskId) {
|
||||||
|
Drawable drawable;
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||||
|
drawable = context.getDrawable(maskId);
|
||||||
|
} else {
|
||||||
|
drawable = context.getResources().getDrawable(maskId);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (drawable == null) {
|
||||||
|
throw new IllegalArgumentException("maskId is invalid");
|
||||||
|
}
|
||||||
|
|
||||||
|
return drawable;
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user