mirror of
https://github.com/wasabeef/glide-transformations.git
synced 2025-10-05 18:53:20 +08:00
Compare commits
32 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
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 |
21
CHANGELOG.md
21
CHANGELOG.md
@@ -1,6 +1,27 @@
|
|||||||
Change Log
|
Change Log
|
||||||
==========
|
==========
|
||||||
|
|
||||||
|
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)*
|
Version 1.0.7 *(2015-07-18)*
|
||||||
----------------------------
|
----------------------------
|
||||||
|
|
||||||
|
37
README.md
37
README.md
@@ -32,8 +32,9 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile 'jp.wasabeef:glide-transformations:1.0.8@aar'
|
compile 'jp.wasabeef:glide-transformations:1.2.1'
|
||||||
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, 25, 2), new CropCircleTransformation(pool))
|
|
||||||
.into((ImageView) findViewById(R.id.image));
|
.into((ImageView) findViewById(R.id.image));
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -67,7 +67,7 @@ android {
|
|||||||
...
|
...
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
...
|
...
|
||||||
renderscriptTargetApi 22
|
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,14 +85,16 @@ 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`, `KuwaharaFilterTransformation`, `VignetteFilterTransformation`
|
||||||
|
|
||||||
### Other
|
|
||||||
`RoundedCornersTransformation`
|
|
||||||
|
|
||||||
Applications using Glide Transformations
|
Applications using Glide Transformations
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -110,6 +113,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,8 +5,8 @@ buildscript {
|
|||||||
jcenter()
|
jcenter()
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:1.3.0-beta4'
|
classpath 'com.android.tools.build:gradle:1.3.1'
|
||||||
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.2'
|
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.3.1'
|
||||||
|
|
||||||
// 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
|
||||||
|
@@ -1,21 +1,24 @@
|
|||||||
<?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
|
>
|
||||||
android:name=".MainActivity"
|
<activity
|
||||||
android:label="@string/app_name" >
|
android:name=".MainActivity"
|
||||||
<intent-filter>
|
android:label="@string/app_name"
|
||||||
<action android:name="android.intent.action.MAIN" />
|
>
|
||||||
|
<intent-filter>
|
||||||
|
<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>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
|
@@ -4,44 +4,42 @@ import android.os.Bundle;
|
|||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.support.v7.widget.GridLayoutManager;
|
import android.support.v7.widget.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 AppCompatActivity {
|
||||||
|
|
||||||
@Override
|
@Override protected void onCreate(Bundle savedInstanceState) {
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
super.onCreate(savedInstanceState);
|
||||||
super.onCreate(savedInstanceState);
|
setContentView(R.layout.activity_main);
|
||||||
setContentView(R.layout.activity_main);
|
|
||||||
|
|
||||||
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.list);
|
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.list);
|
||||||
recyclerView.setLayoutManager(new GridLayoutManager(this, 2));
|
recyclerView.setLayoutManager(new GridLayoutManager(this, 2));
|
||||||
|
|
||||||
List<Type> dataSet = new ArrayList<>();
|
List<Type> dataSet = new ArrayList<>();
|
||||||
dataSet.add(Type.CropTop);
|
dataSet.add(Type.Mask);
|
||||||
dataSet.add(Type.CropCenter);
|
dataSet.add(Type.NinePatchMask);
|
||||||
dataSet.add(Type.CropBottom);
|
dataSet.add(Type.CropTop);
|
||||||
dataSet.add(Type.CropSquare);
|
dataSet.add(Type.CropCenter);
|
||||||
dataSet.add(Type.CropCircle);
|
dataSet.add(Type.CropBottom);
|
||||||
dataSet.add(Type.ColorFilter);
|
dataSet.add(Type.CropSquare);
|
||||||
dataSet.add(Type.Grayscale);
|
dataSet.add(Type.CropCircle);
|
||||||
dataSet.add(Type.RoundedCorners);
|
dataSet.add(Type.ColorFilter);
|
||||||
dataSet.add(Type.Blur);
|
dataSet.add(Type.Grayscale);
|
||||||
dataSet.add(Type.Toon);
|
dataSet.add(Type.RoundedCorners);
|
||||||
dataSet.add(Type.Sepia);
|
dataSet.add(Type.Blur);
|
||||||
dataSet.add(Type.Contrast);
|
dataSet.add(Type.Toon);
|
||||||
dataSet.add(Type.Invert);
|
dataSet.add(Type.Sepia);
|
||||||
dataSet.add(Type.Pixel);
|
dataSet.add(Type.Contrast);
|
||||||
dataSet.add(Type.Sketch);
|
dataSet.add(Type.Invert);
|
||||||
dataSet.add(Type.Swirl);
|
dataSet.add(Type.Pixel);
|
||||||
dataSet.add(Type.Brightness);
|
dataSet.add(Type.Sketch);
|
||||||
dataSet.add(Type.Kuawahara);
|
dataSet.add(Type.Swirl);
|
||||||
dataSet.add(Type.Vignette);
|
dataSet.add(Type.Brightness);
|
||||||
|
dataSet.add(Type.Kuawahara);
|
||||||
|
dataSet.add(Type.Vignette);
|
||||||
|
|
||||||
recyclerView.setAdapter(new MainAdapter(this, dataSet));
|
recyclerView.setAdapter(new MainAdapter(this, dataSet));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -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;
|
||||||
@@ -40,131 +36,203 @@ import jp.wasabeef.glide.transformations.gpu.VignetteFilterTransformation;
|
|||||||
*/
|
*/
|
||||||
public class MainAdapter extends RecyclerView.Adapter<MainAdapter.ViewHolder> {
|
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 {
|
||||||
CropTop,
|
Mask,
|
||||||
CropCenter,
|
NinePatchMask,
|
||||||
CropBottom,
|
CropTop,
|
||||||
CropSquare,
|
CropCenter,
|
||||||
CropCircle,
|
CropBottom,
|
||||||
ColorFilter,
|
CropSquare,
|
||||||
Grayscale,
|
CropCircle,
|
||||||
RoundedCorners,
|
ColorFilter,
|
||||||
Blur,
|
Grayscale,
|
||||||
Toon,
|
RoundedCorners,
|
||||||
Sepia,
|
Blur,
|
||||||
Contrast,
|
Toon,
|
||||||
Invert,
|
Sepia,
|
||||||
Pixel,
|
Contrast,
|
||||||
Sketch,
|
Invert,
|
||||||
Swirl,
|
Pixel,
|
||||||
Brightness,
|
Sketch,
|
||||||
Kuawahara,
|
Swirl,
|
||||||
Vignette
|
Brightness,
|
||||||
|
Kuawahara,
|
||||||
|
Vignette
|
||||||
|
}
|
||||||
|
|
||||||
|
public MainAdapter(Context context, List<Type> dataSet) {
|
||||||
|
mContext = context;
|
||||||
|
mDataSet = dataSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public MainAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||||
|
View v = LayoutInflater.from(mContext).inflate(R.layout.layout_list_item, parent, false);
|
||||||
|
return new ViewHolder(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void onBindViewHolder(MainAdapter.ViewHolder holder, int position) {
|
||||||
|
switch (mDataSet.get(position)) {
|
||||||
|
case Mask: {
|
||||||
|
int width = Utils.dip2px(mContext, 133.33f);
|
||||||
|
int height = Utils.dip2px(mContext, 126.33f);
|
||||||
|
Glide.with(mContext)
|
||||||
|
.load(R.drawable.check)
|
||||||
|
.override(width, height)
|
||||||
|
.bitmapTransform(new CenterCrop(mContext),
|
||||||
|
new MaskTransformation(mContext, R.drawable.mask_starfish))
|
||||||
|
.into(holder.image);
|
||||||
|
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);
|
||||||
|
|
||||||
|
break;
|
||||||
|
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, 100, 0))
|
||||||
|
.into(holder.image);
|
||||||
|
break;
|
||||||
|
case Blur:
|
||||||
|
Glide.with(mContext)
|
||||||
|
.load(R.drawable.check)
|
||||||
|
.bitmapTransform(new BlurTransformation(mContext, 25, 1))
|
||||||
|
.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());
|
||||||
|
}
|
||||||
|
|
||||||
public MainAdapter(Context context, List<Type> dataSet) {
|
@Override public int getItemCount() {
|
||||||
mContext = context;
|
return mDataSet.size();
|
||||||
mDataSet = dataSet;
|
}
|
||||||
mPool = Glide.get(mContext).getBitmapPool();
|
|
||||||
}
|
static class ViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
|
||||||
@Override
|
public ImageView image;
|
||||||
public MainAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
public TextView title;
|
||||||
View v = LayoutInflater.from(mContext)
|
|
||||||
.inflate(R.layout.layout_list_item, parent, false);
|
ViewHolder(View itemView) {
|
||||||
return new ViewHolder(v);
|
super(itemView);
|
||||||
}
|
image = (ImageView) itemView.findViewById(R.id.image);
|
||||||
|
title = (TextView) itemView.findViewById(R.id.title);
|
||||||
@Override
|
|
||||||
public void onBindViewHolder(MainAdapter.ViewHolder holder, int position) {
|
|
||||||
Transformation transformation = null;
|
|
||||||
switch (mDataSet.get(position)) {
|
|
||||||
case CropTop:
|
|
||||||
transformation =
|
|
||||||
new CropTransformation(mPool, 300, 100, CropTransformation.CropType.TOP);
|
|
||||||
break;
|
|
||||||
case CropCenter:
|
|
||||||
transformation = new CropTransformation(mPool, 300, 100);
|
|
||||||
break;
|
|
||||||
case CropBottom:
|
|
||||||
transformation =
|
|
||||||
new CropTransformation(mPool, 300, 100, CropTransformation.CropType.BOTTOM);
|
|
||||||
break;
|
|
||||||
case CropSquare:
|
|
||||||
transformation = new CropSquareTransformation(mPool);
|
|
||||||
break;
|
|
||||||
case CropCircle:
|
|
||||||
transformation = new CropCircleTransformation(mPool);
|
|
||||||
break;
|
|
||||||
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, 25, 1);
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
Glide.with(mContext).load(R.drawable.demo)
|
|
||||||
.bitmapTransform(transformation).into(holder.image);
|
|
||||||
holder.title.setText(mDataSet.get(position).name());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getItemCount() {
|
|
||||||
return mDataSet.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
static class ViewHolder extends RecyclerView.ViewHolder {
|
|
||||||
|
|
||||||
public ImageView image;
|
|
||||||
public TextView title;
|
|
||||||
|
|
||||||
ViewHolder(View itemView) {
|
|
||||||
super(itemView);
|
|
||||||
image = (ImageView) itemView.findViewById(R.id.image);
|
|
||||||
title = (TextView) itemView.findViewById(R.id.title);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
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 |
@@ -1,13 +1,15 @@
|
|||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:background="#CC000000"
|
||||||
|
tools:context=".MainActivity"
|
||||||
|
>
|
||||||
|
|
||||||
|
<android.support.v7.widget.RecyclerView
|
||||||
|
android:id="@+id/list"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:background="#CC000000"
|
/>
|
||||||
tools:context=".MainActivity">
|
|
||||||
|
|
||||||
<android.support.v7.widget.RecyclerView
|
|
||||||
android:id="@+id/list"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"/>
|
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
@@ -1,23 +1,26 @@
|
|||||||
<?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_height="match_parent"
|
||||||
|
android:padding="5dp"
|
||||||
|
>
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/image"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="wrap_content"
|
||||||
android:padding="5dp">
|
android:layout_centerInParent="true"
|
||||||
|
android:contentDescription="@null"
|
||||||
|
/>
|
||||||
|
|
||||||
<ImageView
|
<TextView
|
||||||
android:id="@+id/image"
|
android:id="@+id/title"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_centerInParent="true"
|
android:layout_below="@id/image"
|
||||||
android:contentDescription="@null"/>
|
android:layout_centerHorizontal="true"
|
||||||
|
android:layout_marginTop="5dp"
|
||||||
<TextView
|
android:textColor="@android:color/white"
|
||||||
android:id="@+id/title"
|
/>
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_below="@id/image"
|
|
||||||
android:layout_centerHorizontal="true"
|
|
||||||
android:layout_marginTop="5dp"
|
|
||||||
android:textColor="@android:color/white"/>
|
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
@@ -1,6 +1,6 @@
|
|||||||
<resources>
|
<resources>
|
||||||
<!-- Example customization of dimensions originally defined in res/values/dimens.xml
|
<!-- Example customization of dimensions originally defined in res/values/dimens.xml
|
||||||
(such as screen margins) for screens with more than 820dp of available width. This
|
(such as screen margins) for screens with more than 820dp of available width. This
|
||||||
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
|
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
|
||||||
<dimen name="activity_horizontal_margin">64dp</dimen>
|
<dimen name="activity_horizontal_margin">64dp</dimen>
|
||||||
</resources>
|
</resources>
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
<resources>
|
<resources>
|
||||||
<!-- Default screen margins, per the Android Design guidelines. -->
|
<!-- Default screen margins, per the Android Design guidelines. -->
|
||||||
<dimen name="activity_horizontal_margin">16dp</dimen>
|
<dimen name="activity_horizontal_margin">16dp</dimen>
|
||||||
<dimen name="activity_vertical_margin">16dp</dimen>
|
<dimen name="activity_vertical_margin">16dp</dimen>
|
||||||
</resources>
|
</resources>
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
|
|
||||||
<string name="app_name">glide-transformations</string>
|
<string name="app_name">glide-transformations</string>
|
||||||
<string name="hello_world">Hello world!</string>
|
<string name="hello_world">Hello world!</string>
|
||||||
<string name="action_settings">Settings</string>
|
<string name="action_settings">Settings</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
<resources>
|
<resources>
|
||||||
|
|
||||||
<!-- Base application theme. -->
|
<!-- Base application theme. -->
|
||||||
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
|
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
|
||||||
<!-- Customize your theme here. -->
|
<!-- Customize your theme here. -->
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
@@ -1,12 +1,12 @@
|
|||||||
VERSION_NAME=1.0.8
|
VERSION_NAME=1.2.1
|
||||||
VERSION_CODE=8
|
VERSION_CODE=11
|
||||||
GROUP=jp.wasabeef
|
GROUP=jp.wasabeef
|
||||||
ARTIFACT_ID=glide-transformations
|
ARTIFACT_ID=glide-transformations
|
||||||
|
|
||||||
COMPILE_SDK_VERSION=22
|
COMPILE_SDK_VERSION=23
|
||||||
BUILD_TOOLS_VERSION=22.0.1
|
BUILD_TOOLS_VERSION=23.0.1
|
||||||
TARGET_SDK_VERSION=22
|
TARGET_SDK_VERSION=23
|
||||||
RENDERSCRIPT_TARGET_API=22
|
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
|
||||||
@@ -23,6 +23,6 @@ POM_DEVELOPER_EMAIL=dadadada.chop@gmail.com
|
|||||||
POM_DEVELOPER_URL=wasabeef.jp
|
POM_DEVELOPER_URL=wasabeef.jp
|
||||||
ISSUE_URL=https://github.com/wasabeef/glide-transformations/issues
|
ISSUE_URL=https://github.com/wasabeef/glide-transformations/issues
|
||||||
|
|
||||||
SUPPORT_PACKAGE_VERSION=22.2.1
|
SUPPORT_PACKAGE_VERSION=23.0.1
|
||||||
GLIDE_VERSION=3.6.1
|
GLIDE_VERSION=3.6.1
|
||||||
GPUIMAGE_VERSION=1.2.3
|
GPUIMAGE_VERSION=1.3.0
|
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -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
|
||||||
|
@@ -16,7 +16,7 @@ android {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile "com.github.bumptech.glide:glide:${GLIDE_VERSION}"
|
compile "com.github.bumptech.glide:glide:${GLIDE_VERSION}"
|
||||||
compile "jp.co.cyberagent.android.gpuimage:gpuimage-library:${GPUIMAGE_VERSION}"
|
provided "jp.co.cyberagent.android.gpuimage:gpuimage-library:${GPUIMAGE_VERSION}"
|
||||||
}
|
}
|
||||||
|
|
||||||
android.libraryVariants.all { variant ->
|
android.libraryVariants.all { variant ->
|
||||||
@@ -39,4 +39,4 @@ android.libraryVariants.all { variant ->
|
|||||||
|
|
||||||
apply from: 'android-artifacts.gradle'
|
apply from: 'android-artifacts.gradle'
|
||||||
apply from: 'central-publish.gradle'
|
apply from: 'central-publish.gradle'
|
||||||
apply from: 'bintray-publish.gradle'
|
apply from: 'bintray-publish.gradle'
|
||||||
|
@@ -16,11 +16,6 @@ package jp.wasabeef.glide.transformations;
|
|||||||
* 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.Bitmap;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
@@ -29,71 +24,90 @@ import android.support.v8.renderscript.Allocation;
|
|||||||
import android.support.v8.renderscript.Element;
|
import android.support.v8.renderscript.Element;
|
||||||
import android.support.v8.renderscript.RenderScript;
|
import android.support.v8.renderscript.RenderScript;
|
||||||
import android.support.v8.renderscript.ScriptIntrinsicBlur;
|
import android.support.v8.renderscript.ScriptIntrinsicBlur;
|
||||||
|
import com.bumptech.glide.Glide;
|
||||||
|
import com.bumptech.glide.load.Transformation;
|
||||||
|
import com.bumptech.glide.load.engine.Resource;
|
||||||
|
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||||
|
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
|
||||||
|
|
||||||
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 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;
|
private int mSampling;
|
||||||
|
|
||||||
public BlurTransformation(Context context, BitmapPool pool) {
|
public BlurTransformation(Context context) {
|
||||||
this(context, pool, MAX_RADIUS, DEFAULT_DOWN_SAMPLING);
|
this(context, Glide.get(context).getBitmapPool(), MAX_RADIUS, DEFAULT_DOWN_SAMPLING);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlurTransformation(Context context, BitmapPool pool) {
|
||||||
|
this(context, pool, MAX_RADIUS, DEFAULT_DOWN_SAMPLING);
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
mBitmapPool = pool;
|
||||||
|
mRadius = radius;
|
||||||
|
mSampling = sampling;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlurTransformation(Context context, int radius, int sampling) {
|
||||||
|
mContext = context;
|
||||||
|
mBitmapPool = Glide.get(context).getBitmapPool();
|
||||||
|
mRadius = radius;
|
||||||
|
mSampling = sampling;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
||||||
|
Bitmap source = resource.get();
|
||||||
|
|
||||||
|
int width = source.getWidth();
|
||||||
|
int height = source.getHeight();
|
||||||
|
int scaledWidth = width / mSampling;
|
||||||
|
int scaledHeight = height / mSampling;
|
||||||
|
|
||||||
|
Bitmap bitmap = mBitmapPool.get(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
|
||||||
|
if (bitmap == null) {
|
||||||
|
bitmap = Bitmap.createBitmap(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BlurTransformation(Context context, BitmapPool pool, int radius) {
|
Canvas canvas = new Canvas(bitmap);
|
||||||
this(context, pool, radius, DEFAULT_DOWN_SAMPLING);
|
canvas.scale(1 / (float) mSampling, 1 / (float) mSampling);
|
||||||
}
|
Paint paint = new Paint();
|
||||||
|
paint.setFlags(Paint.FILTER_BITMAP_FLAG);
|
||||||
|
canvas.drawBitmap(source, 0, 0, paint);
|
||||||
|
|
||||||
public BlurTransformation(Context context, BitmapPool pool, int radius, int sampling) {
|
RenderScript rs = RenderScript.create(mContext);
|
||||||
mContext = context;
|
Allocation input = Allocation.createFromBitmap(rs, bitmap, Allocation.MipmapControl.MIPMAP_NONE,
|
||||||
mBitmapPool = pool;
|
Allocation.USAGE_SCRIPT);
|
||||||
mRadius = radius;
|
Allocation output = Allocation.createTyped(rs, input.getType());
|
||||||
mSampling = sampling;
|
ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
blur.setInput(input);
|
||||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
blur.setRadius(mRadius);
|
||||||
Bitmap source = resource.get();
|
blur.forEach(output);
|
||||||
|
output.copyTo(bitmap);
|
||||||
|
|
||||||
int width = source.getWidth();
|
rs.destroy();
|
||||||
int height = source.getHeight();
|
|
||||||
int scaledWidth = width / mSampling;
|
|
||||||
int scaledHeight = height / mSampling;
|
|
||||||
|
|
||||||
Bitmap bitmap = mBitmapPool.get(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
|
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||||
if (bitmap == null) {
|
}
|
||||||
bitmap = Bitmap.createBitmap(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
|
|
||||||
}
|
|
||||||
|
|
||||||
Canvas canvas = new Canvas(bitmap);
|
@Override public String getId() {
|
||||||
canvas.scale(1 / (float) mSampling, 1 / (float) mSampling);
|
return "BlurTransformation(radius=" + mRadius + ", sampling=" + mSampling + ")";
|
||||||
Paint paint = new Paint();
|
}
|
||||||
paint.setFlags(Paint.FILTER_BITMAP_FLAG);
|
|
||||||
canvas.drawBitmap(source, 0, 0, paint);
|
|
||||||
|
|
||||||
RenderScript rs = RenderScript.create(mContext);
|
|
||||||
Allocation input = Allocation.createFromBitmap(rs, bitmap,
|
|
||||||
Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
|
|
||||||
Allocation output = Allocation.createTyped(rs, input.getType());
|
|
||||||
ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
|
|
||||||
|
|
||||||
blur.setInput(input);
|
|
||||||
blur.setRadius(mRadius);
|
|
||||||
blur.forEach(output);
|
|
||||||
output.copyTo(bitmap);
|
|
||||||
|
|
||||||
rs.destroy();
|
|
||||||
|
|
||||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getId() {
|
|
||||||
return "BlurTransformation(radius=" + mRadius + ", sampling=" + mSampling + ")";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -16,53 +16,57 @@ 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> {
|
||||||
|
|
||||||
private BitmapPool mBitmapPool;
|
private BitmapPool mBitmapPool;
|
||||||
|
|
||||||
private int mColor;
|
private int mColor;
|
||||||
|
|
||||||
public ColorFilterTransformation(BitmapPool pool, int color) {
|
public ColorFilterTransformation(Context context, int color) {
|
||||||
mBitmapPool = pool;
|
this(Glide.get(context).getBitmapPool(), color);
|
||||||
mColor = color;
|
}
|
||||||
|
|
||||||
|
public ColorFilterTransformation(BitmapPool pool, int color) {
|
||||||
|
mBitmapPool = pool;
|
||||||
|
mColor = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
||||||
|
Bitmap source = resource.get();
|
||||||
|
|
||||||
|
int width = source.getWidth();
|
||||||
|
int height = source.getHeight();
|
||||||
|
|
||||||
|
Bitmap.Config config =
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
Canvas canvas = new Canvas(bitmap);
|
||||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
Paint paint = new Paint();
|
||||||
Bitmap source = resource.get();
|
paint.setAntiAlias(true);
|
||||||
|
paint.setColorFilter(new PorterDuffColorFilter(mColor, PorterDuff.Mode.SRC_ATOP));
|
||||||
|
canvas.drawBitmap(source, 0, 0, paint);
|
||||||
|
|
||||||
int width = source.getWidth();
|
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||||
int height = source.getHeight();
|
}
|
||||||
|
|
||||||
Bitmap.Config config =
|
@Override public String getId() {
|
||||||
source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
|
return "ColorFilterTransformation(color=" + mColor + ")";
|
||||||
Bitmap bitmap = mBitmapPool.get(width, height, config);
|
}
|
||||||
if (bitmap == null) {
|
|
||||||
bitmap = Bitmap.createBitmap(width, height, config);
|
|
||||||
}
|
|
||||||
|
|
||||||
Canvas canvas = new Canvas(bitmap);
|
|
||||||
Paint paint = new Paint();
|
|
||||||
paint.setAntiAlias(true);
|
|
||||||
paint.setColorFilter(new PorterDuffColorFilter(mColor, PorterDuff.Mode.SRC_ATOP));
|
|
||||||
canvas.drawBitmap(source, 0, 0, paint);
|
|
||||||
|
|
||||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getId() {
|
|
||||||
return "ColorFilterTransformation(color=" + mColor + ")";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -16,58 +16,63 @@ 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(BitmapPool pool) {
|
public CropCircleTransformation(Context context) {
|
||||||
this.mBitmapPool = pool;
|
this(Glide.get(context).getBitmapPool());
|
||||||
|
}
|
||||||
|
|
||||||
|
public CropCircleTransformation(BitmapPool pool) {
|
||||||
|
this.mBitmapPool = pool;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
||||||
|
Bitmap source = resource.get();
|
||||||
|
int size = Math.min(source.getWidth(), source.getHeight());
|
||||||
|
|
||||||
|
int width = (source.getWidth() - size) / 2;
|
||||||
|
int height = (source.getHeight() - size) / 2;
|
||||||
|
|
||||||
|
Bitmap bitmap = mBitmapPool.get(size, size, Bitmap.Config.ARGB_8888);
|
||||||
|
if (bitmap == null) {
|
||||||
|
bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
Canvas canvas = new Canvas(bitmap);
|
||||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
Paint paint = new Paint();
|
||||||
Bitmap source = resource.get();
|
BitmapShader shader =
|
||||||
int size = Math.min(source.getWidth(), source.getHeight());
|
new BitmapShader(source, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP);
|
||||||
|
if (width != 0 || height != 0) {
|
||||||
int width = (source.getWidth() - size) / 2;
|
// source isn't square, move viewport to center
|
||||||
int height = (source.getHeight() - size) / 2;
|
Matrix matrix = new Matrix();
|
||||||
|
matrix.setTranslate(-width, -height);
|
||||||
Bitmap bitmap = mBitmapPool.get(size, size, Bitmap.Config.ARGB_8888);
|
shader.setLocalMatrix(matrix);
|
||||||
if (bitmap == null) {
|
|
||||||
bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
|
|
||||||
}
|
|
||||||
|
|
||||||
Canvas canvas = new Canvas(bitmap);
|
|
||||||
Paint paint = new Paint();
|
|
||||||
BitmapShader shader = new BitmapShader(source, BitmapShader.TileMode.CLAMP,
|
|
||||||
BitmapShader.TileMode.CLAMP);
|
|
||||||
if (width != 0 || height != 0) {
|
|
||||||
Matrix matrix = new Matrix();
|
|
||||||
matrix.setTranslate(-width, -height);
|
|
||||||
shader.setLocalMatrix(matrix);
|
|
||||||
}
|
|
||||||
paint.setShader(shader);
|
|
||||||
paint.setAntiAlias(true);
|
|
||||||
|
|
||||||
float r = size / 2f;
|
|
||||||
canvas.drawCircle(r, r, r, paint);
|
|
||||||
|
|
||||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
|
||||||
}
|
}
|
||||||
|
paint.setShader(shader);
|
||||||
|
paint.setAntiAlias(true);
|
||||||
|
|
||||||
@Override
|
float r = size / 2f;
|
||||||
public String getId() {
|
canvas.drawCircle(r, r, r, paint);
|
||||||
return "CropCircleTransformation()";
|
|
||||||
}
|
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public String getId() {
|
||||||
|
return "CropCircleTransformation()";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,43 +16,47 @@ 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(BitmapPool pool) {
|
public CropSquareTransformation(Context context) {
|
||||||
this.mBitmapPool = pool;
|
this(Glide.get(context).getBitmapPool());
|
||||||
|
}
|
||||||
|
|
||||||
|
public CropSquareTransformation(BitmapPool pool) {
|
||||||
|
this.mBitmapPool = pool;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
||||||
|
Bitmap source = resource.get();
|
||||||
|
int size = Math.min(source.getWidth(), source.getHeight());
|
||||||
|
|
||||||
|
mWidth = (source.getWidth() - size) / 2;
|
||||||
|
mHeight = (source.getHeight() - size) / 2;
|
||||||
|
|
||||||
|
Bitmap.Config config =
|
||||||
|
source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
|
||||||
|
Bitmap bitmap = mBitmapPool.get(mWidth, mHeight, config);
|
||||||
|
if (bitmap == null) {
|
||||||
|
bitmap = Bitmap.createBitmap(source, mWidth, mHeight, size, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
}
|
||||||
Bitmap source = resource.get();
|
|
||||||
int size = Math.min(source.getWidth(), source.getHeight());
|
|
||||||
|
|
||||||
mWidth = (source.getWidth() - size) / 2;
|
@Override public String getId() {
|
||||||
mHeight = (source.getHeight() - size) / 2;
|
return "CropSquareTransformation(width=" + mWidth + ", height=" + mHeight + ")";
|
||||||
|
}
|
||||||
Bitmap.Config config =
|
|
||||||
source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
|
|
||||||
Bitmap bitmap = mBitmapPool.get(mWidth, mHeight, config);
|
|
||||||
if (bitmap == null) {
|
|
||||||
bitmap = Bitmap.createBitmap(source, mWidth, mHeight, size, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getId() {
|
|
||||||
return "CropSquareTransformation(width=" + mWidth + ", height=" + mHeight + ")";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -16,91 +16,101 @@ 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> {
|
||||||
|
|
||||||
private BitmapPool mBitmapPool;
|
public enum CropType {
|
||||||
private int mWidth;
|
TOP,
|
||||||
private int mHeight;
|
CENTER,
|
||||||
|
BOTTOM
|
||||||
|
}
|
||||||
|
|
||||||
private CropType mCropType = CropType.CENTER;
|
private BitmapPool mBitmapPool;
|
||||||
|
private int mWidth;
|
||||||
|
private int mHeight;
|
||||||
|
|
||||||
public CropTransformation(BitmapPool pool) {
|
private CropType mCropType = CropType.CENTER;
|
||||||
mBitmapPool = pool;
|
|
||||||
|
public CropTransformation(Context context) {
|
||||||
|
this(Glide.get(context).getBitmapPool());
|
||||||
|
}
|
||||||
|
|
||||||
|
public CropTransformation(BitmapPool 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) {
|
||||||
|
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;
|
||||||
|
mWidth = width;
|
||||||
|
mHeight = height;
|
||||||
|
mCropType = cropType;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
||||||
|
Bitmap source = resource.get();
|
||||||
|
mWidth = mWidth == 0 ? source.getWidth() : mWidth;
|
||||||
|
mHeight = mHeight == 0 ? source.getHeight() : mHeight;
|
||||||
|
|
||||||
|
Bitmap.Config config =
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CropTransformation(BitmapPool pool, int width, int height) {
|
float scaleX = (float) mWidth / source.getWidth();
|
||||||
mBitmapPool = pool;
|
float scaleY = (float) mHeight / source.getHeight();
|
||||||
mWidth = width;
|
float scale = Math.max(scaleX, scaleY);
|
||||||
mHeight = height;
|
|
||||||
}
|
float scaledWidth = scale * source.getWidth();
|
||||||
|
float scaledHeight = scale * source.getHeight();
|
||||||
public CropTransformation(BitmapPool pool, int width, int height, CropType cropType) {
|
float left = (mWidth - scaledWidth) / 2;
|
||||||
mBitmapPool = pool;
|
float top = getTop(scaledHeight);
|
||||||
mWidth = width;
|
RectF targetRect = new RectF(left, top, left + scaledWidth, top + scaledHeight);
|
||||||
mHeight = height;
|
|
||||||
mCropType = cropType;
|
Canvas canvas = new Canvas(bitmap);
|
||||||
}
|
canvas.drawBitmap(source, null, targetRect, null);
|
||||||
|
|
||||||
@Override
|
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
}
|
||||||
Bitmap source = resource.get();
|
|
||||||
mWidth = mWidth == 0 ? source.getWidth() : mWidth;
|
@Override public String getId() {
|
||||||
mHeight = mHeight == 0 ? source.getHeight() : mHeight;
|
return "CropTransformation(width=" + mWidth + ", height=" + mHeight + ", cropType=" + mCropType
|
||||||
|
+ ")";
|
||||||
Bitmap.Config config =
|
}
|
||||||
source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
|
|
||||||
Bitmap bitmap = mBitmapPool.get(mWidth, mHeight, config);
|
private float getTop(float scaledHeight) {
|
||||||
if (bitmap == null) {
|
switch (mCropType) {
|
||||||
bitmap = Bitmap.createBitmap(mWidth, mHeight, config);
|
case TOP:
|
||||||
}
|
return 0;
|
||||||
|
case CENTER:
|
||||||
float scaleX = (float) mWidth / source.getWidth();
|
return (mHeight - scaledHeight) / 2;
|
||||||
float scaleY = (float) mHeight / source.getHeight();
|
case BOTTOM:
|
||||||
float scale = Math.max(scaleX, scaleY);
|
return mHeight - scaledHeight;
|
||||||
|
default:
|
||||||
float scaledWidth = scale * source.getWidth();
|
return 0;
|
||||||
float scaledHeight = scale * source.getHeight();
|
|
||||||
float left = (mWidth - scaledWidth) / 2;
|
|
||||||
float top = getTop(scaledHeight);
|
|
||||||
RectF targetRect = new RectF(left, top, left + scaledWidth, top + scaledHeight);
|
|
||||||
|
|
||||||
Canvas canvas = new Canvas(bitmap);
|
|
||||||
canvas.drawBitmap(source, null, targetRect, null);
|
|
||||||
|
|
||||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getId() {
|
|
||||||
return "CropTransformation(width=" + mWidth + ", height=" + mHeight + ", cropType="
|
|
||||||
+ mCropType + ")";
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum CropType {
|
|
||||||
TOP,
|
|
||||||
CENTER,
|
|
||||||
BOTTOM
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,51 +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.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(BitmapPool pool) {
|
public GrayscaleTransformation(Context context) {
|
||||||
mBitmapPool = pool;
|
this(Glide.get(context).getBitmapPool());
|
||||||
|
}
|
||||||
|
|
||||||
|
public GrayscaleTransformation(BitmapPool pool) {
|
||||||
|
mBitmapPool = pool;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
||||||
|
Bitmap source = resource.get();
|
||||||
|
|
||||||
|
int width = source.getWidth();
|
||||||
|
int height = source.getHeight();
|
||||||
|
|
||||||
|
Bitmap.Config config =
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
Canvas canvas = new Canvas(bitmap);
|
||||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
ColorMatrix saturation = new ColorMatrix();
|
||||||
Bitmap source = resource.get();
|
saturation.setSaturation(0f);
|
||||||
|
Paint paint = new Paint();
|
||||||
|
paint.setColorFilter(new ColorMatrixColorFilter(saturation));
|
||||||
|
canvas.drawBitmap(source, 0, 0, paint);
|
||||||
|
|
||||||
int width = source.getWidth();
|
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||||
int height = source.getHeight();
|
}
|
||||||
|
|
||||||
Bitmap.Config config =
|
@Override public String getId() {
|
||||||
source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
|
return "GrayscaleTransformation()";
|
||||||
Bitmap bitmap = mBitmapPool.get(width, height, config);
|
}
|
||||||
if (bitmap == null) {
|
|
||||||
bitmap = Bitmap.createBitmap(width, height, config);
|
|
||||||
}
|
|
||||||
|
|
||||||
Canvas canvas = new Canvas(bitmap);
|
|
||||||
ColorMatrix saturation = new ColorMatrix();
|
|
||||||
saturation.setSaturation(0f);
|
|
||||||
Paint paint = new Paint();
|
|
||||||
paint.setColorFilter(new ColorMatrixColorFilter(saturation));
|
|
||||||
canvas.drawBitmap(source, 0, 0, paint);
|
|
||||||
|
|
||||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getId() {
|
|
||||||
return "GrayscaleTransformation()";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,81 @@
|
|||||||
|
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 mMaskingPaint = new Paint();
|
||||||
|
private Context mContext;
|
||||||
|
private BitmapPool mBitmapPool;
|
||||||
|
private int mMaskId;
|
||||||
|
|
||||||
|
static {
|
||||||
|
mMaskingPaint.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) {
|
||||||
|
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 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, mMaskingPaint);
|
||||||
|
|
||||||
|
return BitmapResource.obtain(result, mBitmapPool);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public String getId() {
|
||||||
|
return "MaskTransformation(maskId=" + mContext.getResources().getResourceEntryName(mMaskId)
|
||||||
|
+ ")";
|
||||||
|
}
|
||||||
|
}
|
@@ -16,55 +16,59 @@ 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;
|
private BitmapPool mBitmapPool;
|
||||||
|
|
||||||
private int radius;
|
private int radius;
|
||||||
private int margin;
|
private int margin;
|
||||||
|
|
||||||
public RoundedCornersTransformation(BitmapPool pool, int radius, int margin) {
|
public RoundedCornersTransformation(Context context, int radius, int margin) {
|
||||||
this.radius = radius;
|
this(Glide.get(context).getBitmapPool(), radius, margin);
|
||||||
this.margin = margin;
|
}
|
||||||
mBitmapPool = pool;
|
|
||||||
|
public RoundedCornersTransformation(BitmapPool pool, int radius, int margin) {
|
||||||
|
mBitmapPool = pool;
|
||||||
|
this.radius = radius;
|
||||||
|
this.margin = margin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
||||||
|
Bitmap source = resource.get();
|
||||||
|
|
||||||
|
int width = source.getWidth();
|
||||||
|
int height = source.getHeight();
|
||||||
|
|
||||||
|
Bitmap bitmap = mBitmapPool.get(width, height, Bitmap.Config.ARGB_8888);
|
||||||
|
if (bitmap == null) {
|
||||||
|
bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
Canvas canvas = new Canvas(bitmap);
|
||||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
Paint paint = new Paint();
|
||||||
Bitmap source = resource.get();
|
paint.setAntiAlias(true);
|
||||||
|
paint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
|
||||||
|
canvas.drawRoundRect(new RectF(margin, margin, width - margin, height - margin), radius, radius,
|
||||||
|
paint);
|
||||||
|
|
||||||
int width = source.getWidth();
|
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||||
int height = source.getHeight();
|
}
|
||||||
|
|
||||||
Bitmap bitmap = mBitmapPool.get(width, height, Bitmap.Config.ARGB_8888);
|
@Override public String getId() {
|
||||||
if (bitmap == null) {
|
return "RoundedTransformation(radius=" + radius + ", margin=" + margin + ")";
|
||||||
bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Canvas canvas = new Canvas(bitmap);
|
|
||||||
Paint paint = new Paint();
|
|
||||||
paint.setAntiAlias(true);
|
|
||||||
paint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
|
|
||||||
canvas.drawRoundRect(new RectF(margin, margin, width - margin, height - margin),
|
|
||||||
radius, radius, paint);
|
|
||||||
|
|
||||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getId() {
|
|
||||||
return "RoundedTransformation(radius=" + radius + ", margin=" + margin + ")";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -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;
|
||||||
|
|
||||||
@@ -32,40 +31,46 @@ import jp.co.cyberagent.android.gpuimage.GPUImageBrightnessFilter;
|
|||||||
*/
|
*/
|
||||||
public class BrightnessFilterTransformation implements Transformation<Bitmap> {
|
public class BrightnessFilterTransformation implements Transformation<Bitmap> {
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private BitmapPool mBitmapPool;
|
private BitmapPool mBitmapPool;
|
||||||
|
|
||||||
private GPUImageBrightnessFilter mFilter = new GPUImageBrightnessFilter();
|
private GPUImageBrightnessFilter mFilter = new GPUImageBrightnessFilter();
|
||||||
private float mBrightness;
|
private float mBrightness;
|
||||||
|
|
||||||
public BrightnessFilterTransformation(Context context, BitmapPool pool) {
|
public BrightnessFilterTransformation(Context context) {
|
||||||
mContext = context;
|
this(context, Glide.get(context).getBitmapPool());
|
||||||
mBitmapPool = pool;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public BrightnessFilterTransformation(Context context, BitmapPool pool, float brightness) {
|
public BrightnessFilterTransformation(Context context, BitmapPool pool) {
|
||||||
mContext = context;
|
this(context, pool, 0.0f);
|
||||||
mBitmapPool = pool;
|
}
|
||||||
mBrightness = brightness;
|
|
||||||
mFilter.setBrightness(mBrightness);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
public BrightnessFilterTransformation(Context context, float brightness) {
|
||||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
this(context, Glide.get(context).getBitmapPool(), brightness);
|
||||||
Bitmap source = resource.get();
|
}
|
||||||
|
|
||||||
GPUImage gpuImage = new GPUImage(mContext);
|
public BrightnessFilterTransformation(Context context, BitmapPool pool, float brightness) {
|
||||||
gpuImage.setImage(source);
|
mContext = context;
|
||||||
gpuImage.setFilter(mFilter);
|
mBitmapPool = pool;
|
||||||
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
mBrightness = brightness;
|
||||||
|
mFilter.setBrightness(mBrightness);
|
||||||
|
}
|
||||||
|
|
||||||
source.recycle();
|
@Override
|
||||||
|
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
||||||
|
Bitmap source = resource.get();
|
||||||
|
|
||||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
GPUImage gpuImage = new GPUImage(mContext);
|
||||||
}
|
gpuImage.setImage(source);
|
||||||
|
gpuImage.setFilter(mFilter);
|
||||||
|
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
||||||
|
|
||||||
@Override
|
source.recycle();
|
||||||
public String getId() {
|
|
||||||
return "BrightnessFilterTransformation(brightness=" + mBrightness + ")";
|
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override public String getId() {
|
||||||
|
return "BrightnessFilterTransformation(brightness=" + mBrightness + ")";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -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;
|
||||||
|
|
||||||
@@ -32,40 +31,46 @@ import jp.co.cyberagent.android.gpuimage.GPUImageContrastFilter;
|
|||||||
*/
|
*/
|
||||||
public class ContrastFilterTransformation implements Transformation<Bitmap> {
|
public class ContrastFilterTransformation implements Transformation<Bitmap> {
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private BitmapPool mBitmapPool;
|
private BitmapPool mBitmapPool;
|
||||||
|
|
||||||
private GPUImageContrastFilter mFilter = new GPUImageContrastFilter();
|
private GPUImageContrastFilter mFilter = new GPUImageContrastFilter();
|
||||||
private float mContrast;
|
private float mContrast;
|
||||||
|
|
||||||
public ContrastFilterTransformation(Context context, BitmapPool pool) {
|
public ContrastFilterTransformation(Context context) {
|
||||||
mContext = context;
|
this(context, Glide.get(context).getBitmapPool());
|
||||||
mBitmapPool = pool;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public ContrastFilterTransformation(Context context, BitmapPool pool, float contrast) {
|
public ContrastFilterTransformation(Context context, BitmapPool pool) {
|
||||||
mContext = context;
|
this(context, pool, 1.0f);
|
||||||
mBitmapPool = pool;
|
}
|
||||||
mContrast = contrast;
|
|
||||||
mFilter.setContrast(mContrast);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
public ContrastFilterTransformation(Context context, float contrast) {
|
||||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
this(context, Glide.get(context).getBitmapPool(), contrast);
|
||||||
Bitmap source = resource.get();
|
}
|
||||||
|
|
||||||
GPUImage gpuImage = new GPUImage(mContext);
|
public ContrastFilterTransformation(Context context, BitmapPool pool, float contrast) {
|
||||||
gpuImage.setImage(source);
|
mContext = context;
|
||||||
gpuImage.setFilter(mFilter);
|
mBitmapPool = pool;
|
||||||
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
mContrast = contrast;
|
||||||
|
mFilter.setContrast(mContrast);
|
||||||
|
}
|
||||||
|
|
||||||
source.recycle();
|
@Override
|
||||||
|
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
||||||
|
Bitmap source = resource.get();
|
||||||
|
|
||||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
GPUImage gpuImage = new GPUImage(mContext);
|
||||||
}
|
gpuImage.setImage(source);
|
||||||
|
gpuImage.setFilter(mFilter);
|
||||||
|
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
||||||
|
|
||||||
@Override
|
source.recycle();
|
||||||
public String getId() {
|
|
||||||
return "ContrastFilterTransformation(contrast=" + mContrast + ")";
|
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override public String getId() {
|
||||||
|
return "ContrastFilterTransformation(contrast=" + mContrast + ")";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,43 +16,48 @@ 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, BitmapPool pool) {
|
public InvertFilterTransformation(Context context) {
|
||||||
mContext = context;
|
this(context, Glide.get(context).getBitmapPool());
|
||||||
mBitmapPool = pool;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
public InvertFilterTransformation(Context context, BitmapPool pool) {
|
||||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
mContext = context;
|
||||||
Bitmap source = resource.get();
|
mBitmapPool = pool;
|
||||||
|
}
|
||||||
|
|
||||||
GPUImage gpuImage = new GPUImage(mContext);
|
@Override
|
||||||
gpuImage.setImage(source);
|
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
||||||
gpuImage.setFilter(new GPUImageColorInvertFilter());
|
Bitmap source = resource.get();
|
||||||
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
|
||||||
|
|
||||||
source.recycle();
|
GPUImage gpuImage = new GPUImage(mContext);
|
||||||
|
gpuImage.setImage(source);
|
||||||
|
gpuImage.setFilter(new GPUImageColorInvertFilter());
|
||||||
|
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
||||||
|
|
||||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
source.recycle();
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||||
public String getId() {
|
}
|
||||||
return "InvertFilterTransformation()";
|
|
||||||
}
|
@Override public String getId() {
|
||||||
|
return "InvertFilterTransformation()";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,57 +16,64 @@ 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> {
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private BitmapPool mBitmapPool;
|
private BitmapPool mBitmapPool;
|
||||||
|
|
||||||
private GPUImageKuwaharaFilter mFilter = new GPUImageKuwaharaFilter();
|
private GPUImageKuwaharaFilter mFilter = new GPUImageKuwaharaFilter();
|
||||||
private int mRadius;
|
private int mRadius;
|
||||||
|
|
||||||
public KuwaharaFilterTransformation(Context context, BitmapPool pool) {
|
public KuwaharaFilterTransformation(Context context) {
|
||||||
mContext = context;
|
this(context, Glide.get(context).getBitmapPool());
|
||||||
mBitmapPool = pool;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public KuwaharaFilterTransformation(Context context, BitmapPool pool, int radius) {
|
public KuwaharaFilterTransformation(Context context, BitmapPool pool) {
|
||||||
mContext = context;
|
this(context, pool, 25);
|
||||||
mBitmapPool = pool;
|
}
|
||||||
mRadius = radius;
|
|
||||||
mFilter.setRadius(mRadius);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
public KuwaharaFilterTransformation(Context context, int radius) {
|
||||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
this(context, Glide.get(context).getBitmapPool(), radius);
|
||||||
Bitmap source = resource.get();
|
}
|
||||||
|
|
||||||
GPUImage gpuImage = new GPUImage(mContext);
|
public KuwaharaFilterTransformation(Context context, BitmapPool pool, int radius) {
|
||||||
gpuImage.setImage(source);
|
mContext = context;
|
||||||
gpuImage.setFilter(mFilter);
|
mBitmapPool = pool;
|
||||||
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
mRadius = radius;
|
||||||
|
mFilter.setRadius(mRadius);
|
||||||
|
}
|
||||||
|
|
||||||
source.recycle();
|
@Override
|
||||||
|
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
||||||
|
Bitmap source = resource.get();
|
||||||
|
|
||||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
GPUImage gpuImage = new GPUImage(mContext);
|
||||||
}
|
gpuImage.setImage(source);
|
||||||
|
gpuImage.setFilter(mFilter);
|
||||||
|
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
||||||
|
|
||||||
@Override
|
source.recycle();
|
||||||
public String getId() {
|
|
||||||
return "KuwaharaFilterTransformation(radius=" + mRadius + ")";
|
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override public String getId() {
|
||||||
|
return "KuwaharaFilterTransformation(radius=" + mRadius + ")";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,53 +16,63 @@ 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;
|
||||||
private BitmapPool mBitmapPool;
|
private BitmapPool mBitmapPool;
|
||||||
|
|
||||||
private GPUImagePixelationFilter mFilter = new GPUImagePixelationFilter();
|
private GPUImagePixelationFilter mFilter = new GPUImagePixelationFilter();
|
||||||
private float mPixel;
|
private float mPixel;
|
||||||
|
|
||||||
public PixelationFilterTransformation(Context context, BitmapPool pool) {
|
public PixelationFilterTransformation(Context context) {
|
||||||
mContext = context;
|
this(context, Glide.get(context).getBitmapPool());
|
||||||
mBitmapPool = pool;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public PixelationFilterTransformation(Context context, BitmapPool pool, float pixel) {
|
public PixelationFilterTransformation(Context context, BitmapPool pool) {
|
||||||
mContext = context;
|
this(context, pool, 10f);
|
||||||
mBitmapPool = pool;
|
}
|
||||||
mPixel = pixel;
|
|
||||||
mFilter.setPixel(mPixel);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
public PixelationFilterTransformation(Context context, float pixel) {
|
||||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
this(context, Glide.get(context).getBitmapPool(), pixel);
|
||||||
Bitmap source = resource.get();
|
}
|
||||||
|
|
||||||
GPUImage gpuImage = new GPUImage(mContext);
|
public PixelationFilterTransformation(Context context, BitmapPool pool, float pixel) {
|
||||||
gpuImage.setImage(source);
|
mContext = context;
|
||||||
gpuImage.setFilter(mFilter);
|
mBitmapPool = pool;
|
||||||
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
mPixel = pixel;
|
||||||
|
mFilter.setPixel(mPixel);
|
||||||
|
}
|
||||||
|
|
||||||
source.recycle();
|
@Override
|
||||||
|
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
||||||
|
Bitmap source = resource.get();
|
||||||
|
|
||||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
GPUImage gpuImage = new GPUImage(mContext);
|
||||||
}
|
gpuImage.setImage(source);
|
||||||
|
gpuImage.setFilter(mFilter);
|
||||||
|
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
||||||
|
|
||||||
@Override
|
source.recycle();
|
||||||
public String getId() {
|
|
||||||
return "PixelationFilterTransformation(pixel=" + mPixel + ")";
|
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override public String getId() {
|
||||||
|
return "PixelationFilterTransformation(pixel=" + mPixel + ")";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,53 +16,63 @@ 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;
|
||||||
private BitmapPool mBitmapPool;
|
private BitmapPool mBitmapPool;
|
||||||
|
|
||||||
private GPUImageSepiaFilter mFilter = new GPUImageSepiaFilter();
|
private GPUImageSepiaFilter mFilter = new GPUImageSepiaFilter();
|
||||||
private float mIntensity;
|
private float mIntensity;
|
||||||
|
|
||||||
public SepiaFilterTransformation(Context context, BitmapPool pool) {
|
public SepiaFilterTransformation(Context context) {
|
||||||
mContext = context;
|
this(context, Glide.get(context).getBitmapPool());
|
||||||
mBitmapPool = pool;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public SepiaFilterTransformation(Context context, BitmapPool pool, float intensity) {
|
public SepiaFilterTransformation(Context context, BitmapPool pool) {
|
||||||
mContext = context;
|
this(context, pool, 1.0f);
|
||||||
mBitmapPool = pool;
|
}
|
||||||
mIntensity = intensity;
|
|
||||||
mFilter.setIntensity(mIntensity);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
public SepiaFilterTransformation(Context context, float intensity) {
|
||||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
this(context, Glide.get(context).getBitmapPool(), intensity);
|
||||||
Bitmap source = resource.get();
|
}
|
||||||
|
|
||||||
GPUImage gpuImage = new GPUImage(mContext);
|
public SepiaFilterTransformation(Context context, BitmapPool pool, float intensity) {
|
||||||
gpuImage.setImage(source);
|
mContext = context;
|
||||||
gpuImage.setFilter(mFilter);
|
mBitmapPool = pool;
|
||||||
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
mIntensity = intensity;
|
||||||
|
mFilter.setIntensity(mIntensity);
|
||||||
|
}
|
||||||
|
|
||||||
source.recycle();
|
@Override
|
||||||
|
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
||||||
|
Bitmap source = resource.get();
|
||||||
|
|
||||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
GPUImage gpuImage = new GPUImage(mContext);
|
||||||
}
|
gpuImage.setImage(source);
|
||||||
|
gpuImage.setFilter(mFilter);
|
||||||
|
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
||||||
|
|
||||||
@Override
|
source.recycle();
|
||||||
public String getId() {
|
|
||||||
return "SepiaFilterTransformation(intensity=" + mIntensity + ")";
|
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override public String getId() {
|
||||||
|
return "SepiaFilterTransformation(intensity=" + mIntensity + ")";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,43 +16,45 @@ 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;
|
||||||
|
|
||||||
public class SketchFilterTransformation implements Transformation<Bitmap> {
|
public class SketchFilterTransformation implements Transformation<Bitmap> {
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private BitmapPool mBitmapPool;
|
private BitmapPool mBitmapPool;
|
||||||
|
|
||||||
public SketchFilterTransformation(Context context, BitmapPool pool) {
|
public SketchFilterTransformation(Context context) {
|
||||||
mContext = context;
|
this(context, Glide.get(context).getBitmapPool());
|
||||||
mBitmapPool = pool;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
public SketchFilterTransformation(Context context, BitmapPool pool) {
|
||||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
mContext = context;
|
||||||
Bitmap source = resource.get();
|
mBitmapPool = pool;
|
||||||
|
}
|
||||||
|
|
||||||
GPUImage gpuImage = new GPUImage(mContext);
|
@Override
|
||||||
gpuImage.setImage(source);
|
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
||||||
gpuImage.setFilter(new GPUImageSketchFilter());
|
Bitmap source = resource.get();
|
||||||
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
|
||||||
|
|
||||||
source.recycle();
|
GPUImage gpuImage = new GPUImage(mContext);
|
||||||
|
gpuImage.setImage(source);
|
||||||
|
gpuImage.setFilter(new GPUImageSketchFilter());
|
||||||
|
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
||||||
|
|
||||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
source.recycle();
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||||
public String getId() {
|
}
|
||||||
return "SketchFilterTransformation()";
|
|
||||||
}
|
@Override public String getId() {
|
||||||
|
return "SketchFilterTransformation()";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,68 +16,75 @@ 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;
|
||||||
private BitmapPool mBitmapPool;
|
private BitmapPool mBitmapPool;
|
||||||
|
|
||||||
private GPUImageSwirlFilter mFilter = new GPUImageSwirlFilter();
|
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, BitmapPool pool) {
|
public SwirlFilterTransformation(Context context) {
|
||||||
mContext = context;
|
this(context, Glide.get(context).getBitmapPool());
|
||||||
mBitmapPool = pool;
|
}
|
||||||
mCenter = new PointF();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
public SwirlFilterTransformation(Context context, BitmapPool pool) {
|
||||||
* @param radius from 0.0 to 1.0, default 0.5
|
this(context, pool, .5f, 1.0f, new PointF(0.5f, 0.5f));
|
||||||
* @param angle minimum 0.0, default 1.0
|
}
|
||||||
* @param center default (0.5, 0.5)
|
|
||||||
*/
|
|
||||||
public SwirlFilterTransformation(Context context, BitmapPool pool,
|
|
||||||
float radius, float angle, PointF center) {
|
|
||||||
mContext = context;
|
|
||||||
mBitmapPool = pool;
|
|
||||||
mRadius = radius;
|
|
||||||
mAngle = angle;
|
|
||||||
mCenter = center;
|
|
||||||
mFilter.setRadius(mRadius);
|
|
||||||
mFilter.setAngle(mAngle);
|
|
||||||
mFilter.setCenter(mCenter);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
public SwirlFilterTransformation(Context context, float radius, float angle, PointF center) {
|
||||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
this(context, Glide.get(context).getBitmapPool(), radius, angle, center);
|
||||||
Bitmap source = resource.get();
|
}
|
||||||
|
|
||||||
GPUImage gpuImage = new GPUImage(mContext);
|
/**
|
||||||
gpuImage.setImage(source);
|
* @param radius from 0.0 to 1.0, default 0.5
|
||||||
gpuImage.setFilter(mFilter);
|
* @param angle minimum 0.0, default 1.0
|
||||||
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
* @param center default (0.5, 0.5)
|
||||||
|
*/
|
||||||
|
public SwirlFilterTransformation(Context context, BitmapPool pool, float radius, float angle,
|
||||||
|
PointF center) {
|
||||||
|
mContext = context;
|
||||||
|
mBitmapPool = pool;
|
||||||
|
mRadius = radius;
|
||||||
|
mAngle = angle;
|
||||||
|
mCenter = center;
|
||||||
|
mFilter.setRadius(mRadius);
|
||||||
|
mFilter.setAngle(mAngle);
|
||||||
|
mFilter.setCenter(mCenter);
|
||||||
|
}
|
||||||
|
|
||||||
source.recycle();
|
@Override
|
||||||
|
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
||||||
|
Bitmap source = resource.get();
|
||||||
|
|
||||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
GPUImage gpuImage = new GPUImage(mContext);
|
||||||
}
|
gpuImage.setImage(source);
|
||||||
|
gpuImage.setFilter(mFilter);
|
||||||
|
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
||||||
|
|
||||||
@Override
|
source.recycle();
|
||||||
public String getId() {
|
|
||||||
return "SwirlFilterTransformation(radius=" + mRadius +
|
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||||
",angle=" + mAngle + ",center=" + mCenter.toString() + ")";
|
}
|
||||||
}
|
|
||||||
|
@Override public String getId() {
|
||||||
|
return "SwirlFilterTransformation(radius=" + mRadius +
|
||||||
|
",angle=" + mAngle + ",center=" + mCenter.toString() + ")";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,58 +16,68 @@ 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;
|
||||||
private BitmapPool mBitmapPool;
|
private BitmapPool mBitmapPool;
|
||||||
|
|
||||||
private GPUImageToonFilter mFilter = new GPUImageToonFilter();
|
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;
|
|
||||||
mThreshold = threshold;
|
|
||||||
mQuantizationLevels = quantizationLevels;
|
|
||||||
mFilter.setThreshold(mThreshold);
|
|
||||||
mFilter.setQuantizationLevels(mQuantizationLevels);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
public ToonFilterTransformation(Context context, float threshold, float quantizationLevels) {
|
||||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
this(context, Glide.get(context).getBitmapPool(), threshold, quantizationLevels);
|
||||||
Bitmap source = resource.get();
|
}
|
||||||
|
|
||||||
GPUImage gpuImage = new GPUImage(mContext);
|
public ToonFilterTransformation(Context context, BitmapPool pool, float threshold,
|
||||||
gpuImage.setImage(source);
|
float quantizationLevels) {
|
||||||
gpuImage.setFilter(mFilter);
|
mContext = context;
|
||||||
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
mBitmapPool = pool;
|
||||||
|
mThreshold = threshold;
|
||||||
|
mQuantizationLevels = quantizationLevels;
|
||||||
|
mFilter.setThreshold(mThreshold);
|
||||||
|
mFilter.setQuantizationLevels(mQuantizationLevels);
|
||||||
|
}
|
||||||
|
|
||||||
source.recycle();
|
@Override
|
||||||
|
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
||||||
|
Bitmap source = resource.get();
|
||||||
|
|
||||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
GPUImage gpuImage = new GPUImage(mContext);
|
||||||
}
|
gpuImage.setImage(source);
|
||||||
|
gpuImage.setFilter(mFilter);
|
||||||
|
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
||||||
|
|
||||||
@Override
|
source.recycle();
|
||||||
public String getId() {
|
|
||||||
return "ToonFilterTransformation(threshold=" + mThreshold +
|
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||||
",quantizationLevels=" + mQuantizationLevels + ")";
|
}
|
||||||
}
|
|
||||||
|
@Override public String getId() {
|
||||||
|
return "ToonFilterTransformation(threshold=" + mThreshold +
|
||||||
|
",quantizationLevels=" + mQuantizationLevels + ")";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,75 +16,78 @@ 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> {
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private BitmapPool mBitmapPool;
|
private BitmapPool mBitmapPool;
|
||||||
|
|
||||||
private GPUImageVignetteFilter mFilter = new GPUImageVignetteFilter();
|
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) {
|
||||||
|
this(context, Glide.get(context).getBitmapPool());
|
||||||
|
}
|
||||||
|
|
||||||
public VignetteFilterTransformation(Context context, BitmapPool pool) {
|
public VignetteFilterTransformation(Context context, BitmapPool pool) {
|
||||||
mContext = context;
|
this(context, pool, new PointF(0.5f, 0.5f), new float[] { 0.0f, 0.0f, 0.0f }, 0.0f, 0.75f);
|
||||||
mBitmapPool = pool;
|
}
|
||||||
mCenter = new PointF();
|
|
||||||
}
|
|
||||||
|
|
||||||
public VignetteFilterTransformation(Context context, BitmapPool pool,
|
public VignetteFilterTransformation(Context context, PointF center, float[] color, float start,
|
||||||
PointF center, float[] color, float start, float end) {
|
float end) {
|
||||||
mContext = context;
|
this(context, Glide.get(context).getBitmapPool(), center, color, start, end);
|
||||||
mBitmapPool = pool;
|
}
|
||||||
mCenter = center;
|
|
||||||
mVignetteColor = color;
|
|
||||||
mVignetteStart = start;
|
|
||||||
mVignetteEnd = end;
|
|
||||||
mFilter.setVignetteCenter(mCenter);
|
|
||||||
mFilter.setVignetteColor(mVignetteColor);
|
|
||||||
mFilter.setVignetteStart(mVignetteStart);
|
|
||||||
mFilter.setVignetteEnd(mVignetteEnd);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
public VignetteFilterTransformation(Context context, BitmapPool pool, PointF center,
|
||||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
float[] color, float start, float end) {
|
||||||
Bitmap source = resource.get();
|
mContext = context;
|
||||||
|
mBitmapPool = pool;
|
||||||
|
mCenter = center;
|
||||||
|
mVignetteColor = color;
|
||||||
|
mVignetteStart = start;
|
||||||
|
mVignetteEnd = end;
|
||||||
|
mFilter.setVignetteCenter(mCenter);
|
||||||
|
mFilter.setVignetteColor(mVignetteColor);
|
||||||
|
mFilter.setVignetteStart(mVignetteStart);
|
||||||
|
mFilter.setVignetteEnd(mVignetteEnd);
|
||||||
|
}
|
||||||
|
|
||||||
GPUImage gpuImage = new GPUImage(mContext);
|
@Override
|
||||||
gpuImage.setImage(source);
|
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
||||||
gpuImage.setFilter(mFilter);
|
Bitmap source = resource.get();
|
||||||
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
|
||||||
|
|
||||||
source.recycle();
|
GPUImage gpuImage = new GPUImage(mContext);
|
||||||
|
gpuImage.setImage(source);
|
||||||
|
gpuImage.setFilter(mFilter);
|
||||||
|
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
||||||
|
|
||||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
source.recycle();
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||||
public String getId() {
|
}
|
||||||
return "VignetteFilterTransformation(center=" + mCenter.toString() +
|
|
||||||
",color=" + Arrays.toString(mVignetteColor) +
|
@Override public String getId() {
|
||||||
",start=" + mVignetteStart + ",end=" + mVignetteEnd + ")";
|
return "VignetteFilterTransformation(center=" + mCenter.toString() +
|
||||||
}
|
",color=" + Arrays.toString(mVignetteColor) +
|
||||||
|
",start=" + mVignetteStart + ",end=" + mVignetteEnd + ")";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -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