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

55 Commits
1.0.2 ... 1.2.0

Author SHA1 Message Date
Daichi Furiya
39b9d6aa6b Update README.md 2015-09-16 23:59:48 +09:00
wasabeef
2c08c1fb5e Merge branch 'master' of github.com:wasabeef/glide-transformations 2015-09-16 23:56:07 +09:00
wasabeef
abde4c694d update documents 2015-09-16 23:52:37 +09:00
wasabeef
d5616ec9fa refactor samples 2015-09-16 23:46:49 +09:00
wasabeef
1253147c4a bump up 2015-09-16 22:49:01 +09:00
wasabeef
7614f1326a update demo 2015-09-16 22:38:28 +09:00
wasabeef
5cf3e3d934 Refactor 2015-09-16 22:38:16 +09:00
Daichi Furiya
efc447d2f7 Update README.md 2015-09-15 15:12:11 +09:00
Daichi Furiya
23b623c882 Merge pull request #19 from satorufujiwara/feature/provided_gpuimage
Change gpuimage's scope to provided.
2015-09-15 15:09:24 +09:00
Daichi Furiya
f9ea19aaae Merge pull request #18 from start141/master
Add Transformation
2015-09-15 15:09:13 +09:00
start141
831f038d29 Put the mask bitmap to the BitmapPool
put the mask bitmap to the BitmapPool when the mask is get from the
BitmapPool.
2015-09-14 19:56:51 +08:00
fujiwara-satoru
eed7b944e5 Change gpuimage's scope to provided. 2015-09-14 20:54:40 +09:00
start141
46d5d4d72f Add Transformation
Add MaskTransformation and NinePatchMaskTransformation.
2015-09-14 16:49:58 +08:00
wasabeef
6ebfdbe581 modify changelog 2015-09-06 17:34:47 +09:00
wasabeef
2a4eb22841 modify comment 2015-09-06 17:19:27 +09:00
wasabeef
2cc2104802 bump up 2015-09-06 01:29:00 +09:00
wasabeef
f83e5ef85a change the codestyle 2015-09-06 01:24:12 +09:00
wasabeef
cdbd42595a Adjustment of default parameters. 2015-09-06 01:18:40 +09:00
Daichi Furiya
987651f9da Update README.md 2015-08-12 19:26:57 +09:00
Daichi Furiya
ad376134e9 Update README.md 2015-07-25 15:36:18 +09:00
Daichi Furiya
3f695c1e9c Update CHANGELOG.md 2015-07-24 18:28:35 +09:00
wasabeef
58e25e613c update parent activity 2015-07-24 18:17:36 +09:00
wasabeef
c914548296 update readme 2015-07-24 18:17:22 +09:00
wasabeef
cfe6dc313a Added the DownSampling to BlurTransformation 2015-07-24 18:00:07 +09:00
wasabeef
136a5512c0 update changelog 2015-07-18 01:53:24 +09:00
wasabeef
32d0c1de82 fix blur not working 2015-07-18 01:47:43 +09:00
wasabeef
e23753044e format 2015-07-18 01:47:25 +09:00
wasabeef
decd2e58d5 refactor 2015-07-18 01:47:17 +09:00
wasabeef
e9d2c6d209 bump up 2015-07-18 00:18:08 +09:00
wasabeef
79e975d490 bump up 2015-04-23 12:56:01 +09:00
wasabeef
a21cfb1d86 Merge branch 'master' of github.com:wasabeef/glide-transformations 2015-04-23 12:40:25 +09:00
wasabeef
c0ab4282d9 add CropType(Top, Center, Bottom) for CropTransformation 2015-04-23 12:40:15 +09:00
Daichi Furiya
15effa238b Update README.md 2015-04-14 17:44:54 +09:00
Daichi Furiya
ef39ca2782 Merge pull request #9 from bitdeli-chef/master
Add a Bitdeli Badge to README
2015-04-14 17:40:59 +09:00
Bitdeli Chef
bdda7cdf36 Add a Bitdeli badge to README 2015-04-14 08:50:37 +00:00
Daichi Furiya
3890c84a0f Update README.md 2015-04-06 11:34:41 +09:00
wasabeef
e3c0c8d597 update gradle 2015-04-02 14:52:41 +09:00
Daichi Furiya
f7d0541a19 Update README.md 2015-04-01 23:29:37 +09:00
wasabeef
900db8bc93 Merge branch 'master' of github.com:wasabeef/glide-transformations 2015-04-01 16:05:44 +09:00
wasabeef
c241532a58 Update keystore name 2015-04-01 16:05:33 +09:00
Daichi Furiya
8f63c10eb9 Merge pull request #7 from Arkar-Aung/master
Fixed missing @ in gradle script
2015-03-27 00:19:52 +09:00
Arkar Aung
6468276c50 Fixed missing @ in gradle script 2015-03-26 15:11:33 +06:30
Daichi Furiya
e0fb7c34e0 Update README.md 2015-03-09 00:24:01 +09:00
wasabeef
4c23e38206 fix Transparency 2015-03-09 00:08:53 +09:00
Daichi Furiya
ffae37274c Update CHANGELOG.md 2015-02-13 16:11:43 +09:00
Daichi Furiya
0c6f696ba7 Update README.md 2015-02-13 16:07:45 +09:00
wasabeef
3aea08abaa bump up 2015-02-13 15:52:42 +09:00
Daichi Furiya
883c131ad6 Merge pull request #3 from yqritc/fix/bitmap-recycling
remove original bitmap resource recycling
2015-02-13 15:26:28 +09:00
ikeda_yoshihito
ee1f533999 remove original bitmap resource recycling 2015-02-13 12:31:30 +09:00
wasabeef
68a9097962 refactor: Bitmap.Config 2015-02-05 20:51:12 +09:00
wasabeef
6269999abc bump up 2015-02-04 01:00:50 +09:00
wasabeef
7e93ccd9af Merge branch 'master' of github.com:wasabeef/glide-transformations 2015-02-04 00:55:18 +09:00
wasabeef
07b7d24e13 bug fix 2015-02-04 00:54:22 +09:00
Daichi Furiya
ca648cbc7d bump up 2015-02-04 00:40:08 +09:00
Daichi Furiya
67ac3e31a4 Update CHANGELOG.md 2015-02-04 00:39:19 +09:00
42 changed files with 1345 additions and 857 deletions

View File

@@ -1,5 +1,50 @@
Change Log Change Log
========== ==========
Version 1.2.0 *(2015-09-16)*
----------------------------
add new transformations MaskTransformation and NinePatchMaskTransformation.
Thank you @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)* Version 1.0.1 *(2015-01-21)*
---------------------------- ----------------------------

View File

@@ -32,8 +32,9 @@ repositories {
} }
dependencies { dependencies {
compile 'jp.wasabeef:glide-transformations:1.0.1@aar' compile 'jp.wasabeef:glide-transformations:1.1.0'
compile 'jp.co.cyberagent.android.gpuimage:gpuimage-library:1.2.3@aar' // If you want to use the GPU Filters
compile 'jp.co.cyberagent.android.gpuimage:gpuimage-library:1.3.0'
} }
``` ```
@@ -43,7 +44,7 @@ Set Glide Transform.
```java ```java
Glide.with(this).load(R.drawable.demo) Glide.with(this).load(R.drawable.demo)
.bitmapTransform(new BlurTransformation(this, Glide.get(this).getBitmapPool())) .bitmapTransform(new BlurTransformation(context))
.into((ImageView) findViewById(R.id.image)); .into((ImageView) findViewById(R.id.image));
``` ```
@@ -52,9 +53,8 @@ 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, 2), new CropCircleTransformation(context))
new BlurTransformation(this, pool, 5), new CropCircleTransformation(pool))
.into((ImageView) findViewById(R.id.image)); .into((ImageView) findViewById(R.id.image));
``` ```
@@ -67,7 +67,7 @@ android {
... ...
defaultConfig { defaultConfig {
... ...
renderscriptTargetApi 21 renderscriptTargetApi 23
renderscriptSupportModeEnabled true renderscriptSupportModeEnabled true
} }
} }
@@ -76,7 +76,8 @@ android {
## Transformations ## Transformations
### Crop ### Crop
`CropTransformation`, `CropCircleTransformation`, `CropSquareTransformation` `CropTransformation`, `CropCircleTransformation`, `CropSquareTransformation`,
`RoundedCornersTransformation`
### Color ### Color
`ColorFilterTransformation`, `GrayscaleTransformation` `ColorFilterTransformation`, `GrayscaleTransformation`
@@ -84,13 +85,24 @@ android {
### Blur ### Blur
`BlurTransformation` `BlurTransformation`
### Filter (use [GPUImage](https://github.com/CyberAgent/android-gpuimage)) ### Mask
`MaskTransformation`, `NinePatchMaskTransformation`
### 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`, `KuwaharaFilterTransformation`, `VignetteFilterTransformation`
### Other Applications using Glide Transformations
`RoundedCornersTransformation` ---
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
------- -------

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.9 MiB

After

Width:  |  Height:  |  Size: 6.9 MiB

View File

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

View File

@@ -53,9 +53,8 @@ def getKeyAliasPasswordProperty() {
dependencies { dependencies {
compile project(':transformations') compile project(':transformations')
// compile 'jp.wasabeef:glide-transformations:1.0.2' 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:21.+' 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.5.1'
} }

View File

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

View File

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

View File

@@ -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,17 @@ 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.NinePatchMaskTransformation;
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 +39,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 +67,156 @@ 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); Glide.with(mContext)
.load(R.drawable.demo)
.override(210, 210)
.bitmapTransform(new CenterCrop(mContext),
new MaskTransformation(mContext, R.drawable.mask210))
.into(holder.image);
break;
case NinePatchMask:
Glide.with(mContext)
.load(R.drawable.demo)
.override(300, 300)
.bitmapTransform(new CenterCrop(mContext),
new NinePatchMaskTransformation(mContext, R.drawable.chat_me_mask))
.into(holder.image);
break;
case CropTop:
Glide.with(mContext)
.load(R.drawable.demo)
.bitmapTransform(
new CropTransformation(mContext, 300, 100, CropTransformation.CropType.TOP))
.into(holder.image);
break;
case CropCenter:
Glide.with(mContext)
.load(R.drawable.demo)
.bitmapTransform(new CropTransformation(mContext, 300, 100))
.into(holder.image);
break;
case CropBottom:
Glide.with(mContext)
.load(R.drawable.demo)
.bitmapTransform(
new CropTransformation(mContext, 300, 100, CropTransformation.CropType.BOTTOM))
.into(holder.image);
break; break;
case CropSquare: case CropSquare:
transformation = new CropSquareTransformation(mPool); Glide.with(mContext)
.load(R.drawable.demo)
.bitmapTransform(new CropSquareTransformation(mContext))
.into(holder.image);
break; break;
case CropCircle: case CropCircle:
transformation = new CropCircleTransformation(mPool); Glide.with(mContext)
.load(R.drawable.demo)
.bitmapTransform(new CropCircleTransformation(mContext))
.into(holder.image);
break; break;
case ColorFilter: case ColorFilter:
transformation = new ColorFilterTransformation(mPool, Color.argb(80, 255, 0, 0)); Glide.with(mContext)
.load(R.drawable.demo)
.bitmapTransform(new ColorFilterTransformation(mContext, Color.argb(80, 255, 0, 0)))
.into(holder.image);
break; break;
case Grayscale: case Grayscale:
transformation = new GrayscaleTransformation(mPool); Glide.with(mContext)
.load(R.drawable.demo)
.bitmapTransform(new GrayscaleTransformation(mContext))
.into(holder.image);
break; break;
case RoundedCorners: case RoundedCorners:
transformation = new RoundedCornersTransformation(mPool, 100, 0); Glide.with(mContext)
.load(R.drawable.demo)
.bitmapTransform(new RoundedCornersTransformation(mContext, 100, 0))
.into(holder.image);
break; break;
case Blur: case Blur:
transformation = new BlurTransformation(mContext, mPool, 10); Glide.with(mContext)
.load(R.drawable.check)
.bitmapTransform(new BlurTransformation(mContext, 25, 1))
.into(holder.image);
break; break;
case Toon: case Toon:
transformation = new ToonFilterTransformation(mContext, mPool); Glide.with(mContext)
.load(R.drawable.demo)
.bitmapTransform(new ToonFilterTransformation(mContext))
.into(holder.image);
break; break;
case Sepia: case Sepia:
transformation = new SepiaFilterTransformation(mContext, mPool); Glide.with(mContext)
.load(R.drawable.check)
.bitmapTransform(new SepiaFilterTransformation(mContext))
.into(holder.image);
break; break;
case Contrast: case Contrast:
transformation = new ContrastFilterTransformation(mContext, mPool, 2.0f); Glide.with(mContext)
.load(R.drawable.check)
.bitmapTransform(new ContrastFilterTransformation(mContext, 2.0f))
.into(holder.image);
break; break;
case Invert: case Invert:
transformation = new InvertFilterTransformation(mContext, mPool); Glide.with(mContext)
.load(R.drawable.check)
.bitmapTransform(new InvertFilterTransformation(mContext))
.into(holder.image);
break; break;
case Pixel: case Pixel:
transformation = new PixelationFilterTransformation(mContext, mPool, 20); Glide.with(mContext)
.load(R.drawable.check)
.bitmapTransform(new PixelationFilterTransformation(mContext, 20))
.into(holder.image);
break; break;
case Sketch: case Sketch:
transformation = new SketchFilterTransformation(mContext, mPool); Glide.with(mContext)
.load(R.drawable.check)
.bitmapTransform(new SketchFilterTransformation(mContext))
.into(holder.image);
break; break;
case Swirl: case Swirl:
transformation = new SwirlFilterTransformation(mContext, mPool, Glide.with(mContext)
0.5f, 1.0f, new PointF(0.5f, 0.5f)); .load(R.drawable.check)
.bitmapTransform(
new SwirlFilterTransformation(mContext, 0.5f, 1.0f, new PointF(0.5f, 0.5f)))
.into(holder.image);
break; break;
case Brightness: case Brightness:
transformation = new BrightnessFilterTransformation(mContext, mPool, 0.5f); Glide.with(mContext)
.load(R.drawable.check)
.bitmapTransform(new BrightnessFilterTransformation(mContext, 0.5f))
.into(holder.image);
break; break;
case Kuawahara: case Kuawahara:
transformation = new KuwaharaFilterTransformation(mContext, mPool, 25); Glide.with(mContext)
.load(R.drawable.check)
.bitmapTransform(new KuwaharaFilterTransformation(mContext, 25))
.into(holder.image);
break; break;
case Vignette: case Vignette:
transformation = new VignetteFilterTransformation(mContext, mPool, Glide.with(mContext)
new PointF(0.5f, 0.5f), new float[]{0.0f, 0.0f, 0.0f}, 0f, 0.75f); .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; break;
} }
Glide.with(mContext).load(R.drawable.demo)
.bitmapTransform(transformation).into(holder.image);
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();
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 484 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

View File

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

View File

@@ -2,15 +2,16 @@
<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="match_parent"
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>

View File

@@ -1,12 +1,12 @@
VERSION_NAME=1.0.2 VERSION_NAME=1.2.0
VERSION_CODE=3 VERSION_CODE=10
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.1
TARGET_SDK_VERSION=21 TARGET_SDK_VERSION=23
RENDERSCRIPT_TARGET_API=21 RENDERSCRIPT_TARGET_API=23
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 +22,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.0.1
GLIDE_VERSION=3.6.1
GPUIMAGE_VERSION=1.3.0

View File

@@ -3,4 +3,4 @@ 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.4-all.zip

View File

@@ -1,6 +1,7 @@
task androidJavadocs(type: Javadoc) { task androidJavadocs(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) ext.androidJar = "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar"
classpath += files(ext.androidJar)
} }
task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) { task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {

View File

@@ -15,9 +15,8 @@ android {
} }
dependencies { dependencies {
compile fileTree(dir: 'libs', include: ['*.jar']) compile "com.github.bumptech.glide:glide:${GLIDE_VERSION}"
compile 'com.github.bumptech.glide:glide:3.5.1' 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 -> android.libraryVariants.all { variant ->

View File

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

View File

@@ -16,35 +16,59 @@ 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.support.v8.renderscript.Allocation;
import android.support.v8.renderscript.Element;
import android.support.v8.renderscript.RenderScript;
import android.support.v8.renderscript.ScriptIntrinsicBlur;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.Transformation; import com.bumptech.glide.load.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.content.Context;
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) {
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, BitmapPool pool, int radius, int sampling) {
mContext = context; mContext = context;
mBitmapPool = pool; mBitmapPool = pool;
mRadius = radius; mRadius = radius;
mSampling = sampling;
}
public BlurTransformation(Context context, int radius, int sampling) {
mContext = context;
mBitmapPool = Glide.get(context).getBitmapPool();
mRadius = radius;
mSampling = sampling;
} }
@Override @Override
@@ -53,31 +77,37 @@ public class BlurTransformation implements Transformation<Bitmap> {
int width = source.getWidth(); int width = source.getWidth();
int height = source.getHeight(); int height = source.getHeight();
int scaledWidth = width / mSampling;
int scaledHeight = height / mSampling;
Bitmap bitmap = mBitmapPool.get(width, height, source.getConfig()); Bitmap bitmap = mBitmapPool.get(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
if (bitmap == null) { if (bitmap == null) {
bitmap = Bitmap.createBitmap(width, height, source.getConfig()); bitmap = Bitmap.createBitmap(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
} }
Canvas canvas = new Canvas(bitmap); Canvas canvas = new Canvas(bitmap);
canvas.drawBitmap(source, 0, 0, null); canvas.scale(1 / (float) mSampling, 1 / (float) mSampling);
Paint paint = new Paint();
paint.setFlags(Paint.FILTER_BITMAP_FLAG);
canvas.drawBitmap(source, 0, 0, paint);
RenderScript rs = RenderScript.create(mContext); RenderScript rs = RenderScript.create(mContext);
Allocation overlayAlloc = Allocation.createFromBitmap(rs, bitmap); Allocation input = Allocation.createFromBitmap(rs, bitmap, Allocation.MipmapControl.MIPMAP_NONE,
ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(rs, overlayAlloc.getElement()); Allocation.USAGE_SCRIPT);
blur.setInput(overlayAlloc); Allocation output = Allocation.createTyped(rs, input.getType());
blur.setRadius(mRadius); ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
blur.forEach(overlayAlloc);
overlayAlloc.copyTo(bitmap); blur.setInput(input);
blur.setRadius(mRadius);
blur.forEach(output);
output.copyTo(bitmap);
source.recycle();
rs.destroy(); rs.destroy();
return BitmapResource.obtain(bitmap, mBitmapPool); return BitmapResource.obtain(bitmap, mBitmapPool);
} }
@Override @Override public String getId() {
public String getId() { return "BlurTransformation(radius=" + mRadius + ", sampling=" + mSampling + ")";
return "BlurTransformation(radius=" + mRadius + ")";
} }
} }

View File

@@ -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,9 +50,11 @@ public class ColorFilterTransformation implements Transformation<Bitmap> {
int width = source.getWidth(); int width = source.getWidth();
int height = source.getHeight(); int height = source.getHeight();
Bitmap bitmap = mBitmapPool.get(width, height, source.getConfig()); Bitmap.Config config =
source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
Bitmap bitmap = mBitmapPool.get(width, height, config);
if (bitmap == null) { if (bitmap == null) {
bitmap = Bitmap.createBitmap(width, height, source.getConfig()); bitmap = Bitmap.createBitmap(width, height, config);
} }
Canvas canvas = new Canvas(bitmap); Canvas canvas = new Canvas(bitmap);
@@ -56,13 +63,10 @@ public class ColorFilterTransformation implements Transformation<Bitmap> {
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 + ")";
} }
} }

View File

@@ -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.BitmapShader; import android.graphics.BitmapShader;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Matrix; import android.graphics.Matrix;
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 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;
} }
@@ -43,31 +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 bitmap = mBitmapPool.get(width, height, source.getConfig()); Bitmap bitmap = mBitmapPool.get(size, size, Bitmap.Config.ARGB_8888);
if (bitmap == null) { if (bitmap == null) {
bitmap = Bitmap.createBitmap(width, height, source.getConfig()); 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(source, 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 matrix = new Matrix();
matrix.setTranslate(-width, -height); matrix.setTranslate(-width, -height);
shader.setLocalMatrix(matrix); 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);
source.recycle();
return BitmapResource.obtain(bitmap, mBitmapPool); return BitmapResource.obtain(bitmap, mBitmapPool);
} }
@Override @Override public String getId() {
public String getId() {
return "CropCircleTransformation()"; return "CropCircleTransformation()";
} }
} }

View File

@@ -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,20 +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 = mBitmapPool.get(mWidth, mHeight, source.getConfig()); Bitmap.Config config =
source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
Bitmap bitmap = mBitmapPool.get(mWidth, mHeight, config);
if (bitmap == null) { if (bitmap == null) {
bitmap = Bitmap.createBitmap(source, mWidth, mHeight, size, size); bitmap = Bitmap.createBitmap(source, mWidth, mHeight, size, size);
} }
if (bitmap != source) {
source.recycle();
}
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 + ")";
} }
} }

View File

@@ -16,44 +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) {
mHeight = source.getHeight();
}
Bitmap bitmap = mBitmapPool.get(mWidth, mHeight, source.getConfig()); Bitmap.Config config =
source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
Bitmap bitmap = mBitmapPool.get(mWidth, mHeight, config);
if (bitmap == null) { if (bitmap == null) {
bitmap = Bitmap.createBitmap(mWidth, mHeight, source.getConfig()); bitmap = Bitmap.createBitmap(mWidth, mHeight, config);
} }
float scaleX = (float) mWidth / source.getWidth(); float scaleX = (float) mWidth / source.getWidth();
@@ -63,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);
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;
}
} }
} }

View File

@@ -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,9 +47,11 @@ public class GrayscaleTransformation implements Transformation<Bitmap> {
int width = source.getWidth(); int width = source.getWidth();
int height = source.getHeight(); int height = source.getHeight();
Bitmap bitmap = mBitmapPool.get(width, height, source.getConfig()); Bitmap.Config config =
source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
Bitmap bitmap = mBitmapPool.get(width, height, config);
if (bitmap == null) { if (bitmap == null) {
bitmap = Bitmap.createBitmap(width, height, source.getConfig()); bitmap = Bitmap.createBitmap(width, height, config);
} }
Canvas canvas = new Canvas(bitmap); Canvas canvas = new Canvas(bitmap);
@@ -54,13 +61,10 @@ public class GrayscaleTransformation implements Transformation<Bitmap> {
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()";
} }
} }

View File

@@ -0,0 +1,78 @@
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.Rect;
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.Util;
public class MaskTransformation implements Transformation<Bitmap> {
private Context mContext;
private BitmapPool mBitmapPool;
private int mMaskId;
public MaskTransformation(Context context, int maskId) {
mBitmapPool = Glide.get(context).getBitmapPool();
mContext = context;
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 mask = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Drawable drawable = Util.getMaskDrawable(mContext, mMaskId);
drawable.setBounds(0, 0, width, height);
Canvas canvas = new Canvas(mask);
drawable.draw(canvas);
Bitmap bitmap = mBitmapPool.get(width, height, Bitmap.Config.ARGB_8888);
if (bitmap == null) {
bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
}
Paint paint = new Paint();
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
canvas = new Canvas(bitmap);
canvas.drawBitmap(mask, new Rect(0, 0, width, height), new Rect(0, 0, width, height), null);
canvas.drawBitmap(source, 0, 0, paint);
return BitmapResource.obtain(bitmap, mBitmapPool);
}
@Override public String getId() {
return "MaskTransformation(maskId=" + mMaskId + ")";
}
}

View File

@@ -0,0 +1,82 @@
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.Rect;
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 com.bumptech.glide.request.target.Target;
import jp.wasabeef.glide.transformations.internal.Util;
public class NinePatchMaskTransformation implements Transformation<Bitmap> {
private Context mContext;
private BitmapPool mBitmapPool;
private int mMaskId;
public NinePatchMaskTransformation(Context context, int maskId) {
mBitmapPool = Glide.get(context).getBitmapPool();
mContext = context;
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();
int maskWidth = outWidth == Target.SIZE_ORIGINAL ? width : outWidth;
int maskHeight = outHeight == Target.SIZE_ORIGINAL ? height : outHeight;
Bitmap mask = Bitmap.createBitmap(maskWidth, maskHeight, Bitmap.Config.ARGB_8888);
Drawable drawable = Util.getMaskDrawable(mContext, mMaskId);
drawable.setBounds(0, 0, maskWidth, maskHeight);
Canvas canvas = new Canvas(mask);
drawable.draw(canvas);
Bitmap bitmap = mBitmapPool.get(width, height, Bitmap.Config.ARGB_8888);
if (bitmap == null) {
bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
}
Paint paint = new Paint();
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
canvas = new Canvas(bitmap);
canvas.drawBitmap(mask, new Rect(0, 0, maskWidth, maskHeight), new Rect(0, 0, width, height),
null);
canvas.drawBitmap(source, 0, 0, paint);
return BitmapResource.obtain(bitmap, mBitmapPool);
}
@Override public String getId() {
return "NinePatchMaskTransformation(mMaskId=" + mMaskId + ")";
}
}

View File

@@ -16,17 +16,18 @@ 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> {
@@ -35,10 +36,14 @@ public class RoundedCornersTransformation implements Transformation<Bitmap> {
private int radius; private int radius;
private int margin; private int margin;
public RoundedCornersTransformation(Context context, int radius, int margin) {
this(Glide.get(context).getBitmapPool(), radius, margin);
}
public RoundedCornersTransformation(BitmapPool pool, int radius, int margin) { public RoundedCornersTransformation(BitmapPool pool, int radius, int margin) {
mBitmapPool = pool;
this.radius = radius; this.radius = radius;
this.margin = margin; this.margin = margin;
mBitmapPool = pool;
} }
@Override @Override
@@ -48,25 +53,22 @@ public class RoundedCornersTransformation implements Transformation<Bitmap> {
int width = source.getWidth(); int width = source.getWidth();
int height = source.getHeight(); int height = source.getHeight();
Bitmap bitmap = mBitmapPool.get(width, height, source.getConfig()); Bitmap bitmap = mBitmapPool.get(width, height, Bitmap.Config.ARGB_8888);
if (bitmap == null) { if (bitmap == null) {
bitmap = Bitmap.createBitmap(width, height, source.getConfig()); 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), canvas.drawRoundRect(new RectF(margin, margin, width - margin, height - margin), radius, radius,
radius, radius, paint); paint);
source.recycle();
return BitmapResource.obtain(bitmap, mBitmapPool); return BitmapResource.obtain(bitmap, mBitmapPool);
} }
@Override @Override public String getId() {
public String getId() {
return "RoundedTransformation(radius=" + radius + ", margin=" + margin + ")"; return "RoundedTransformation(radius=" + radius + ", margin=" + margin + ")";
} }
} }

View File

@@ -16,14 +16,13 @@ package jp.wasabeef.glide.transformations.gpu;
* 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.content.Context;
import android.graphics.Bitmap;
import jp.co.cyberagent.android.gpuimage.GPUImage; import jp.co.cyberagent.android.gpuimage.GPUImage;
import jp.co.cyberagent.android.gpuimage.GPUImageBrightnessFilter; import jp.co.cyberagent.android.gpuimage.GPUImageBrightnessFilter;
@@ -38,9 +37,16 @@ public class BrightnessFilterTransformation implements Transformation<Bitmap> {
private GPUImageBrightnessFilter mFilter = new GPUImageBrightnessFilter(); 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) {
@@ -64,8 +70,7 @@ public class BrightnessFilterTransformation implements Transformation<Bitmap> {
return BitmapResource.obtain(bitmap, mBitmapPool); return BitmapResource.obtain(bitmap, mBitmapPool);
} }
@Override @Override public String getId() {
public String getId() {
return "BrightnessFilterTransformation(brightness=" + mBrightness + ")"; return "BrightnessFilterTransformation(brightness=" + mBrightness + ")";
} }
} }

View File

@@ -16,14 +16,13 @@ package jp.wasabeef.glide.transformations.gpu;
* 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.content.Context;
import android.graphics.Bitmap;
import jp.co.cyberagent.android.gpuimage.GPUImage; import jp.co.cyberagent.android.gpuimage.GPUImage;
import jp.co.cyberagent.android.gpuimage.GPUImageContrastFilter; import jp.co.cyberagent.android.gpuimage.GPUImageContrastFilter;
@@ -38,9 +37,16 @@ public class ContrastFilterTransformation implements Transformation<Bitmap> {
private GPUImageContrastFilter mFilter = new GPUImageContrastFilter(); 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) {
@@ -64,8 +70,7 @@ public class ContrastFilterTransformation implements Transformation<Bitmap> {
return BitmapResource.obtain(bitmap, mBitmapPool); return BitmapResource.obtain(bitmap, mBitmapPool);
} }
@Override @Override public String getId() {
public String getId() {
return "ContrastFilterTransformation(contrast=" + mContrast + ")"; return "ContrastFilterTransformation(contrast=" + mContrast + ")";
} }
} }

View File

@@ -16,22 +16,28 @@ package jp.wasabeef.glide.transformations.gpu;
* 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.content.Context;
import android.graphics.Bitmap;
import jp.co.cyberagent.android.gpuimage.GPUImage; import jp.co.cyberagent.android.gpuimage.GPUImage;
import jp.co.cyberagent.android.gpuimage.GPUImageColorInvertFilter; import jp.co.cyberagent.android.gpuimage.GPUImageColorInvertFilter;
/**
* Invert all the colors in the image.
*/
public class InvertFilterTransformation implements Transformation<Bitmap> { public class InvertFilterTransformation implements Transformation<Bitmap> {
private Context mContext; private Context mContext;
private BitmapPool mBitmapPool; private BitmapPool mBitmapPool;
public InvertFilterTransformation(Context context) {
this(context, Glide.get(context).getBitmapPool());
}
public InvertFilterTransformation(Context context, BitmapPool pool) { public InvertFilterTransformation(Context context, BitmapPool pool) {
mContext = context; mContext = context;
mBitmapPool = pool; mBitmapPool = pool;
@@ -51,8 +57,7 @@ public class InvertFilterTransformation implements Transformation<Bitmap> {
return BitmapResource.obtain(bitmap, mBitmapPool); return BitmapResource.obtain(bitmap, mBitmapPool);
} }
@Override @Override public String getId() {
public String getId() {
return "InvertFilterTransformation()"; return "InvertFilterTransformation()";
} }
} }

View File

@@ -16,19 +16,20 @@ package jp.wasabeef.glide.transformations.gpu;
* 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.content.Context;
import android.graphics.Bitmap;
import jp.co.cyberagent.android.gpuimage.GPUImage; 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 implements Transformation<Bitmap> {
@@ -39,9 +40,16 @@ public class KuwaharaFilterTransformation implements Transformation<Bitmap> {
private GPUImageKuwaharaFilter mFilter = new GPUImageKuwaharaFilter(); 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) {
@@ -65,8 +73,7 @@ public class KuwaharaFilterTransformation implements Transformation<Bitmap> {
return BitmapResource.obtain(bitmap, mBitmapPool); return BitmapResource.obtain(bitmap, mBitmapPool);
} }
@Override @Override public String getId() {
public String getId() {
return "KuwaharaFilterTransformation(radius=" + mRadius + ")"; return "KuwaharaFilterTransformation(radius=" + mRadius + ")";
} }
} }

View File

@@ -16,17 +16,21 @@ package jp.wasabeef.glide.transformations.gpu;
* 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.content.Context;
import android.graphics.Bitmap;
import jp.co.cyberagent.android.gpuimage.GPUImage; import jp.co.cyberagent.android.gpuimage.GPUImage;
import jp.co.cyberagent.android.gpuimage.GPUImagePixelationFilter; import jp.co.cyberagent.android.gpuimage.GPUImagePixelationFilter;
/**
* Applies a Pixelation effect to the image.
*
* The pixel with a default of 10.0.
*/
public class PixelationFilterTransformation implements Transformation<Bitmap> { public class PixelationFilterTransformation implements Transformation<Bitmap> {
private Context mContext; private Context mContext;
@@ -35,9 +39,16 @@ public class PixelationFilterTransformation implements Transformation<Bitmap> {
private GPUImagePixelationFilter mFilter = new GPUImagePixelationFilter(); 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) {
@@ -61,8 +72,7 @@ public class PixelationFilterTransformation implements Transformation<Bitmap> {
return BitmapResource.obtain(bitmap, mBitmapPool); return BitmapResource.obtain(bitmap, mBitmapPool);
} }
@Override @Override public String getId() {
public String getId() {
return "PixelationFilterTransformation(pixel=" + mPixel + ")"; return "PixelationFilterTransformation(pixel=" + mPixel + ")";
} }
} }

View File

@@ -16,17 +16,21 @@ package jp.wasabeef.glide.transformations.gpu;
* 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.content.Context;
import android.graphics.Bitmap;
import jp.co.cyberagent.android.gpuimage.GPUImage; import jp.co.cyberagent.android.gpuimage.GPUImage;
import jp.co.cyberagent.android.gpuimage.GPUImageSepiaFilter; import jp.co.cyberagent.android.gpuimage.GPUImageSepiaFilter;
/**
* Applies a simple sepia effect.
*
* The intensity with a default of 1.0.
*/
public class SepiaFilterTransformation implements Transformation<Bitmap> { public class SepiaFilterTransformation implements Transformation<Bitmap> {
private Context mContext; private Context mContext;
@@ -35,9 +39,16 @@ public class SepiaFilterTransformation implements Transformation<Bitmap> {
private GPUImageSepiaFilter mFilter = new GPUImageSepiaFilter(); 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) {
@@ -61,8 +72,7 @@ public class SepiaFilterTransformation implements Transformation<Bitmap> {
return BitmapResource.obtain(bitmap, mBitmapPool); return BitmapResource.obtain(bitmap, mBitmapPool);
} }
@Override @Override public String getId() {
public String getId() {
return "SepiaFilterTransformation(intensity=" + mIntensity + ")"; return "SepiaFilterTransformation(intensity=" + mIntensity + ")";
} }
} }

View File

@@ -16,14 +16,13 @@ package jp.wasabeef.glide.transformations.gpu;
* 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.content.Context;
import android.graphics.Bitmap;
import jp.co.cyberagent.android.gpuimage.GPUImage; import jp.co.cyberagent.android.gpuimage.GPUImage;
import jp.co.cyberagent.android.gpuimage.GPUImageSketchFilter; import jp.co.cyberagent.android.gpuimage.GPUImageSketchFilter;
@@ -32,6 +31,10 @@ public class SketchFilterTransformation implements Transformation<Bitmap> {
private Context mContext; private Context mContext;
private BitmapPool mBitmapPool; private BitmapPool mBitmapPool;
public SketchFilterTransformation(Context context) {
this(context, Glide.get(context).getBitmapPool());
}
public SketchFilterTransformation(Context context, BitmapPool pool) { public SketchFilterTransformation(Context context, BitmapPool pool) {
mContext = context; mContext = context;
mBitmapPool = pool; mBitmapPool = pool;
@@ -51,8 +54,7 @@ public class SketchFilterTransformation implements Transformation<Bitmap> {
return BitmapResource.obtain(bitmap, mBitmapPool); return BitmapResource.obtain(bitmap, mBitmapPool);
} }
@Override @Override public String getId() {
public String getId() {
return "SketchFilterTransformation()"; return "SketchFilterTransformation()";
} }
} }

View File

@@ -16,18 +16,20 @@ package jp.wasabeef.glide.transformations.gpu;
* limitations under the License. * limitations under the License.
*/ */
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.PointF;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.Transformation; import com.bumptech.glide.load.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.content.Context;
import android.graphics.Bitmap;
import android.graphics.PointF;
import jp.co.cyberagent.android.gpuimage.GPUImage; import jp.co.cyberagent.android.gpuimage.GPUImage;
import jp.co.cyberagent.android.gpuimage.GPUImageSwirlFilter; import jp.co.cyberagent.android.gpuimage.GPUImageSwirlFilter;
/**
* Creates a swirl distortion on the image.
*/
public class SwirlFilterTransformation implements Transformation<Bitmap> { public class SwirlFilterTransformation implements Transformation<Bitmap> {
private Context mContext; private Context mContext;
@@ -38,10 +40,16 @@ public class SwirlFilterTransformation implements Transformation<Bitmap> {
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,8 +57,8 @@ 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; mContext = context;
mBitmapPool = pool; mBitmapPool = pool;
mRadius = radius; mRadius = radius;
@@ -75,8 +83,7 @@ public class SwirlFilterTransformation implements Transformation<Bitmap> {
return BitmapResource.obtain(bitmap, mBitmapPool); return BitmapResource.obtain(bitmap, mBitmapPool);
} }
@Override @Override public String getId() {
public String getId() {
return "SwirlFilterTransformation(radius=" + mRadius + return "SwirlFilterTransformation(radius=" + mRadius +
",angle=" + mAngle + ",center=" + mCenter.toString() + ")"; ",angle=" + mAngle + ",center=" + mCenter.toString() + ")";
} }

View File

@@ -16,17 +16,21 @@ package jp.wasabeef.glide.transformations.gpu;
* 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.content.Context;
import android.graphics.Bitmap;
import jp.co.cyberagent.android.gpuimage.GPUImage; import jp.co.cyberagent.android.gpuimage.GPUImage;
import jp.co.cyberagent.android.gpuimage.GPUImageToonFilter; import jp.co.cyberagent.android.gpuimage.GPUImageToonFilter;
/**
* 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 implements Transformation<Bitmap> { public class ToonFilterTransformation implements Transformation<Bitmap> {
private Context mContext; private Context mContext;
@@ -36,13 +40,20 @@ public class ToonFilterTransformation implements Transformation<Bitmap> {
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);
}
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) {
mContext = context; mContext = context;
mBitmapPool = pool; mBitmapPool = pool;
mThreshold = threshold; mThreshold = threshold;
@@ -65,8 +76,7 @@ public class ToonFilterTransformation implements Transformation<Bitmap> {
return BitmapResource.obtain(bitmap, mBitmapPool); return BitmapResource.obtain(bitmap, mBitmapPool);
} }
@Override @Override public String getId() {
public String getId() {
return "ToonFilterTransformation(threshold=" + mThreshold + return "ToonFilterTransformation(threshold=" + mThreshold +
",quantizationLevels=" + mQuantizationLevels + ")"; ",quantizationLevels=" + mQuantizationLevels + ")";
} }

View File

@@ -16,24 +16,22 @@ package jp.wasabeef.glide.transformations.gpu;
* limitations under the License. * limitations under the License.
*/ */
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.PointF;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.Transformation; import com.bumptech.glide.load.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.content.Context;
import android.graphics.Bitmap;
import android.graphics.PointF;
import java.util.Arrays; import java.util.Arrays;
import jp.co.cyberagent.android.gpuimage.GPUImage; 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 implements Transformation<Bitmap> {
@@ -46,15 +44,21 @@ public class VignetteFilterTransformation implements Transformation<Bitmap> {
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);
}
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) {
mContext = context; mContext = context;
mBitmapPool = pool; mBitmapPool = pool;
mCenter = center; mCenter = center;
@@ -81,8 +85,7 @@ public class VignetteFilterTransformation implements Transformation<Bitmap> {
return BitmapResource.obtain(bitmap, mBitmapPool); return BitmapResource.obtain(bitmap, mBitmapPool);
} }
@Override @Override public String getId() {
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 + ")";

View File

@@ -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 Util {
private Util() {
// 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;
}
}