mirror of
https://github.com/wasabeef/glide-transformations.git
synced 2025-10-05 02:13:22 +08:00
Compare commits
40 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
2cc2104802 | ||
|
f83e5ef85a | ||
|
cdbd42595a | ||
|
987651f9da | ||
|
ad376134e9 | ||
|
3f695c1e9c | ||
|
58e25e613c | ||
|
c914548296 | ||
|
cfe6dc313a | ||
|
136a5512c0 | ||
|
32d0c1de82 | ||
|
e23753044e | ||
|
decd2e58d5 | ||
|
e9d2c6d209 | ||
|
79e975d490 | ||
|
a21cfb1d86 | ||
|
c0ab4282d9 | ||
|
15effa238b | ||
|
ef39ca2782 | ||
|
bdda7cdf36 | ||
|
3890c84a0f | ||
|
e3c0c8d597 | ||
|
f7d0541a19 | ||
|
900db8bc93 | ||
|
c241532a58 | ||
|
8f63c10eb9 | ||
|
6468276c50 | ||
|
e0fb7c34e0 | ||
|
4c23e38206 | ||
|
ffae37274c | ||
|
0c6f696ba7 | ||
|
3aea08abaa | ||
|
883c131ad6 | ||
|
ee1f533999 | ||
|
68a9097962 | ||
|
6269999abc | ||
|
7e93ccd9af | ||
|
07b7d24e13 | ||
|
ca648cbc7d | ||
|
67ac3e31a4 |
40
CHANGELOG.md
40
CHANGELOG.md
@@ -1,6 +1,46 @@
|
||||
Change Log
|
||||
==========
|
||||
|
||||
Version 1.1.0 *(2015-07-24)*
|
||||
----------------------------
|
||||
|
||||
Adjustment of default parameters.
|
||||
|
||||
Version 1.0.8 *(2015-07-24)*
|
||||
----------------------------
|
||||
|
||||
add DownSampling to BlurTransform
|
||||
|
||||
Version 1.0.7 *(2015-07-18)*
|
||||
----------------------------
|
||||
|
||||
Bug fix : Blur not working.
|
||||
|
||||
Version 1.0.6 *(2015-04-23)*
|
||||
----------------------------
|
||||
|
||||
add: CropType(Top, Center, Bottom) for CropTransformation.
|
||||
|
||||
Version 1.0.5 *(2015-03-09)*
|
||||
----------------------------
|
||||
|
||||
Bug fix: Transparency.
|
||||
|
||||
Version 1.0.4 *(2015-02-13)*
|
||||
----------------------------
|
||||
|
||||
Bug fix : remove original bitmap resource recycling.
|
||||
|
||||
Version 1.0.3 *(2015-02-05)*
|
||||
----------------------------
|
||||
|
||||
Bug fix
|
||||
|
||||
Version 1.0.2 *(2015-02-04)*
|
||||
----------------------------
|
||||
|
||||
Refactor: use BimapPool
|
||||
|
||||
Version 1.0.1 *(2015-01-21)*
|
||||
----------------------------
|
||||
|
||||
|
23
README.md
23
README.md
@@ -32,8 +32,9 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile 'jp.wasabeef:glide-transformations:1.0.1@aar'
|
||||
compile 'jp.co.cyberagent.android.gpuimage:gpuimage-library:1.2.3@aar'
|
||||
compile 'jp.wasabeef:glide-transformations:1.1.0'
|
||||
// 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
|
||||
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));
|
||||
```
|
||||
|
||||
@@ -52,9 +53,8 @@ Glide.with(this).load(R.drawable.demo)
|
||||
You can set a multiple transformations.
|
||||
|
||||
```java
|
||||
BitmapPool pool = Glide.get(this).getBitmapPool();
|
||||
Glide.with(this).load(R.drawable.demo).bitmapTransform(
|
||||
new BlurTransformation(this, pool, 5), new CropCircleTransformation(pool))
|
||||
Glide.with(this).load(R.drawable.demo)
|
||||
.bitmapTransform(new BlurTransformation(context, 25, 2), new CropCircleTransformation(pool))
|
||||
.into((ImageView) findViewById(R.id.image));
|
||||
```
|
||||
|
||||
@@ -67,7 +67,7 @@ android {
|
||||
...
|
||||
defaultConfig {
|
||||
...
|
||||
renderscriptTargetApi 21
|
||||
renderscriptTargetApi 23
|
||||
renderscriptSupportModeEnabled true
|
||||
}
|
||||
}
|
||||
@@ -92,6 +92,15 @@ android {
|
||||
### Other
|
||||
`RoundedCornersTransformation`
|
||||
|
||||
Applications using Glide Transformations
|
||||
---
|
||||
|
||||
Please [ping](mailto:dadadada.chop@gmail.com) me or send a pull request if you would like to be added here.
|
||||
|
||||
Icon | Application
|
||||
------------ | -------------
|
||||
<img src="https://lh6.ggpht.com/6zKH_uQY1bxCwXL4DLo_uoFEOXdShi3BgmN6XRHlaJ-oA1svmq6y1PZkmO50nWQn2Lg=w300-rw" width="48" height="48" /> | [Ameba Ownd](https://play.google.com/store/apps/details?id=jp.co.cyberagent.madrid)
|
||||
|
||||
Developed By
|
||||
-------
|
||||
Daichi Furiya (Wasabeef) - <dadadada.chop@gmail.com>
|
||||
|
@@ -5,8 +5,8 @@ buildscript {
|
||||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:1.0.+'
|
||||
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
|
||||
classpath 'com.android.tools.build:gradle:1.3.1'
|
||||
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.2'
|
||||
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
// in the individual module build.gradle files
|
||||
|
@@ -53,9 +53,8 @@ def getKeyAliasPasswordProperty() {
|
||||
|
||||
dependencies {
|
||||
compile project(':transformations')
|
||||
// compile 'jp.wasabeef:glide-transformations:1.0.2'
|
||||
compile 'jp.co.cyberagent.android.gpuimage:gpuimage-library:1.2.3'
|
||||
compile 'com.android.support:appcompat-v7:21.+'
|
||||
compile 'com.android.support:recyclerview-v7:21.+'
|
||||
compile 'com.github.bumptech.glide:glide:3.5.1'
|
||||
compile "com.github.bumptech.glide:glide:${GLIDE_VERSION}"
|
||||
compile "jp.co.cyberagent.android.gpuimage:gpuimage-library:${GPUIMAGE_VERSION}"
|
||||
compile "com.android.support:appcompat-v7:${SUPPORT_PACKAGE_VERSION}"
|
||||
compile "com.android.support:recyclerview-v7:${SUPPORT_PACKAGE_VERSION}"
|
||||
}
|
||||
|
@@ -1,21 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="jp.wasabeef.example.glide" >
|
||||
package="jp.wasabeef.example.glide"
|
||||
>
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/AppTheme" >
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:label="@string/app_name" >
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/AppTheme"
|
||||
>
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:label="@string/app_name"
|
||||
>
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
@@ -1,45 +1,43 @@
|
||||
package jp.wasabeef.example.glide;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.GridLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import jp.wasabeef.example.glide.MainAdapter.Type;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
public class MainActivity extends ActionBarActivity {
|
||||
@Override protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.list);
|
||||
recyclerView.setLayoutManager(new GridLayoutManager(this, 2));
|
||||
|
||||
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.list);
|
||||
recyclerView.setLayoutManager(new GridLayoutManager(this, 2));
|
||||
List<Type> dataSet = new ArrayList<>();
|
||||
dataSet.add(Type.CropTop);
|
||||
dataSet.add(Type.CropCenter);
|
||||
dataSet.add(Type.CropBottom);
|
||||
dataSet.add(Type.CropSquare);
|
||||
dataSet.add(Type.CropCircle);
|
||||
dataSet.add(Type.ColorFilter);
|
||||
dataSet.add(Type.Grayscale);
|
||||
dataSet.add(Type.RoundedCorners);
|
||||
dataSet.add(Type.Blur);
|
||||
dataSet.add(Type.Toon);
|
||||
dataSet.add(Type.Sepia);
|
||||
dataSet.add(Type.Contrast);
|
||||
dataSet.add(Type.Invert);
|
||||
dataSet.add(Type.Pixel);
|
||||
dataSet.add(Type.Sketch);
|
||||
dataSet.add(Type.Swirl);
|
||||
dataSet.add(Type.Brightness);
|
||||
dataSet.add(Type.Kuawahara);
|
||||
dataSet.add(Type.Vignette);
|
||||
|
||||
List<Type> dataSet = new ArrayList<>();
|
||||
dataSet.add(Type.Crop);
|
||||
dataSet.add(Type.CropSquare);
|
||||
dataSet.add(Type.CropCircle);
|
||||
dataSet.add(Type.ColorFilter);
|
||||
dataSet.add(Type.Grayscale);
|
||||
dataSet.add(Type.RoundedCorners);
|
||||
dataSet.add(Type.Blur);
|
||||
dataSet.add(Type.Toon);
|
||||
dataSet.add(Type.Sepia);
|
||||
dataSet.add(Type.Contrast);
|
||||
dataSet.add(Type.Invert);
|
||||
dataSet.add(Type.Pixel);
|
||||
dataSet.add(Type.Sketch);
|
||||
dataSet.add(Type.Swirl);
|
||||
dataSet.add(Type.Brightness);
|
||||
dataSet.add(Type.Kuawahara);
|
||||
dataSet.add(Type.Vignette);
|
||||
|
||||
recyclerView.setAdapter(new MainAdapter(this, dataSet));
|
||||
}
|
||||
recyclerView.setAdapter(new MainAdapter(this, dataSet));
|
||||
}
|
||||
}
|
||||
|
@@ -1,11 +1,6 @@
|
||||
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.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.PointF;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
@@ -14,9 +9,9 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.Transformation;
|
||||
import java.util.List;
|
||||
|
||||
import jp.wasabeef.glide.transformations.BlurTransformation;
|
||||
import jp.wasabeef.glide.transformations.ColorFilterTransformation;
|
||||
import jp.wasabeef.glide.transformations.CropCircleTransformation;
|
||||
@@ -40,121 +35,124 @@ import jp.wasabeef.glide.transformations.gpu.VignetteFilterTransformation;
|
||||
*/
|
||||
public class MainAdapter extends RecyclerView.Adapter<MainAdapter.ViewHolder> {
|
||||
|
||||
private Context mContext;
|
||||
private List<Type> mDataSet;
|
||||
private BitmapPool mPool;
|
||||
private Context mContext;
|
||||
private List<Type> mDataSet;
|
||||
|
||||
enum Type {
|
||||
Crop,
|
||||
CropSquare,
|
||||
CropCircle,
|
||||
ColorFilter,
|
||||
Grayscale,
|
||||
RoundedCorners,
|
||||
Blur,
|
||||
Toon,
|
||||
Sepia,
|
||||
Contrast,
|
||||
Invert,
|
||||
Pixel,
|
||||
Sketch,
|
||||
Swirl,
|
||||
Brightness,
|
||||
Kuawahara,
|
||||
Vignette
|
||||
enum Type {
|
||||
CropTop,
|
||||
CropCenter,
|
||||
CropBottom,
|
||||
CropSquare,
|
||||
CropCircle,
|
||||
ColorFilter,
|
||||
Grayscale,
|
||||
RoundedCorners,
|
||||
Blur,
|
||||
Toon,
|
||||
Sepia,
|
||||
Contrast,
|
||||
Invert,
|
||||
Pixel,
|
||||
Sketch,
|
||||
Swirl,
|
||||
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) {
|
||||
Transformation transformation = null;
|
||||
switch (mDataSet.get(position)) {
|
||||
case CropTop:
|
||||
transformation =
|
||||
new CropTransformation(mContext, 300, 100, CropTransformation.CropType.TOP);
|
||||
break;
|
||||
case CropCenter:
|
||||
transformation = new CropTransformation(mContext, 300, 100);
|
||||
break;
|
||||
case CropBottom:
|
||||
transformation =
|
||||
new CropTransformation(mContext, 300, 100, CropTransformation.CropType.BOTTOM);
|
||||
break;
|
||||
case CropSquare:
|
||||
transformation = new CropSquareTransformation(mContext);
|
||||
break;
|
||||
case CropCircle:
|
||||
transformation = new CropCircleTransformation(mContext);
|
||||
break;
|
||||
case ColorFilter:
|
||||
transformation = new ColorFilterTransformation(mContext, Color.argb(80, 255, 0, 0));
|
||||
break;
|
||||
case Grayscale:
|
||||
transformation = new GrayscaleTransformation(mContext);
|
||||
break;
|
||||
case RoundedCorners:
|
||||
transformation = new RoundedCornersTransformation(mContext, 100, 0);
|
||||
break;
|
||||
case Blur:
|
||||
transformation = new BlurTransformation(mContext, 25, 1);
|
||||
break;
|
||||
case Toon:
|
||||
transformation = new ToonFilterTransformation(mContext);
|
||||
break;
|
||||
case Sepia:
|
||||
transformation = new SepiaFilterTransformation(mContext);
|
||||
break;
|
||||
case Contrast:
|
||||
transformation = new ContrastFilterTransformation(mContext, 2.0f);
|
||||
break;
|
||||
case Invert:
|
||||
transformation = new InvertFilterTransformation(mContext);
|
||||
break;
|
||||
case Pixel:
|
||||
transformation = new PixelationFilterTransformation(mContext, 20);
|
||||
break;
|
||||
case Sketch:
|
||||
transformation = new SketchFilterTransformation(mContext);
|
||||
break;
|
||||
case Swirl:
|
||||
transformation =
|
||||
new SwirlFilterTransformation(mContext, 0.5f, 1.0f, new PointF(0.5f, 0.5f));
|
||||
break;
|
||||
case Brightness:
|
||||
transformation = new BrightnessFilterTransformation(mContext, 0.5f);
|
||||
break;
|
||||
case Kuawahara:
|
||||
transformation = new KuwaharaFilterTransformation(mContext, 25);
|
||||
break;
|
||||
case Vignette:
|
||||
transformation = new VignetteFilterTransformation(mContext, new PointF(0.5f, 0.5f),
|
||||
new float[] { 0.0f, 0.0f, 0.0f }, 0f, 0.75f);
|
||||
break;
|
||||
}
|
||||
|
||||
public MainAdapter(Context context, List<Type> dataSet) {
|
||||
mContext = context;
|
||||
mDataSet = dataSet;
|
||||
mPool = Glide.get(mContext).getBitmapPool();
|
||||
}
|
||||
|
||||
@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) {
|
||||
Transformation<Bitmap> transformation = null;
|
||||
switch (mDataSet.get(position)) {
|
||||
case Crop:
|
||||
transformation = new CropTransformation(mPool, 300, 100);
|
||||
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, 10);
|
||||
break;
|
||||
case Toon:
|
||||
transformation = new ToonFilterTransformation(mContext, mPool);
|
||||
break;
|
||||
case Sepia:
|
||||
transformation = new SepiaFilterTransformation(mContext, mPool);
|
||||
break;
|
||||
case Contrast:
|
||||
transformation = new ContrastFilterTransformation(mContext, mPool, 2.0f);
|
||||
break;
|
||||
case Invert:
|
||||
transformation = new InvertFilterTransformation(mContext, mPool);
|
||||
break;
|
||||
case Pixel:
|
||||
transformation = new PixelationFilterTransformation(mContext, mPool, 20);
|
||||
break;
|
||||
case Sketch:
|
||||
transformation = new SketchFilterTransformation(mContext, mPool);
|
||||
break;
|
||||
case Swirl:
|
||||
transformation = new SwirlFilterTransformation(mContext, mPool,
|
||||
0.5f, 1.0f, new PointF(0.5f, 0.5f));
|
||||
break;
|
||||
case Brightness:
|
||||
transformation = new BrightnessFilterTransformation(mContext, mPool, 0.5f);
|
||||
break;
|
||||
case Kuawahara:
|
||||
transformation = new KuwaharaFilterTransformation(mContext, mPool, 25);
|
||||
break;
|
||||
case Vignette:
|
||||
transformation = new VignetteFilterTransformation(mContext, mPool,
|
||||
new PointF(0.5f, 0.5f), new float[]{0.0f, 0.0f, 0.0f}, 0f, 0.75f);
|
||||
break;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,13 +1,15 @@
|
||||
<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_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>
|
||||
|
@@ -1,24 +1,26 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<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_height="match_parent"
|
||||
android:padding="5dp">
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:contentDescription="@null"
|
||||
/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/image"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:contentDescription="@null"
|
||||
android:src="@drawable/demo"/>
|
||||
|
||||
<TextView
|
||||
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"/>
|
||||
<TextView
|
||||
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>
|
@@ -1,6 +1,6 @@
|
||||
<resources>
|
||||
<!-- 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
|
||||
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
|
||||
<dimen name="activity_horizontal_margin">64dp</dimen>
|
||||
<!-- 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
|
||||
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
|
||||
<dimen name="activity_horizontal_margin">64dp</dimen>
|
||||
</resources>
|
||||
|
@@ -1,5 +1,5 @@
|
||||
<resources>
|
||||
<!-- Default screen margins, per the Android Design guidelines. -->
|
||||
<dimen name="activity_horizontal_margin">16dp</dimen>
|
||||
<dimen name="activity_vertical_margin">16dp</dimen>
|
||||
<!-- Default screen margins, per the Android Design guidelines. -->
|
||||
<dimen name="activity_horizontal_margin">16dp</dimen>
|
||||
<dimen name="activity_vertical_margin">16dp</dimen>
|
||||
</resources>
|
||||
|
@@ -1,8 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<string name="app_name">glide-transformations</string>
|
||||
<string name="hello_world">Hello world!</string>
|
||||
<string name="action_settings">Settings</string>
|
||||
<string name="app_name">glide-transformations</string>
|
||||
<string name="hello_world">Hello world!</string>
|
||||
<string name="action_settings">Settings</string>
|
||||
|
||||
</resources>
|
||||
|
@@ -1,8 +1,8 @@
|
||||
<resources>
|
||||
|
||||
<!-- Base application theme. -->
|
||||
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
|
||||
<!-- Customize your theme here. -->
|
||||
</style>
|
||||
<!-- Base application theme. -->
|
||||
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
|
||||
<!-- Customize your theme here. -->
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
|
@@ -1,12 +1,12 @@
|
||||
VERSION_NAME=1.0.2
|
||||
VERSION_CODE=3
|
||||
VERSION_NAME=1.1.0
|
||||
VERSION_CODE=9
|
||||
GROUP=jp.wasabeef
|
||||
ARTIFACT_ID=glide-transformations
|
||||
|
||||
COMPILE_SDK_VERSION=21
|
||||
BUILD_TOOLS_VERSION=21.1.2
|
||||
TARGET_SDK_VERSION=21
|
||||
RENDERSCRIPT_TARGET_API=21
|
||||
COMPILE_SDK_VERSION=23
|
||||
BUILD_TOOLS_VERSION=23.0.1
|
||||
TARGET_SDK_VERSION=23
|
||||
RENDERSCRIPT_TARGET_API=23
|
||||
MIN_SDK_VERSION=11
|
||||
|
||||
POM_DESCRIPTION=which provides simple Tranformations to Glide
|
||||
@@ -22,3 +22,7 @@ POM_DEVELOPER_NAME=Wasabeef
|
||||
POM_DEVELOPER_EMAIL=dadadada.chop@gmail.com
|
||||
POM_DEVELOPER_URL=wasabeef.jp
|
||||
ISSUE_URL=https://github.com/wasabeef/glide-transformations/issues
|
||||
|
||||
SUPPORT_PACKAGE_VERSION=23.0.1
|
||||
GLIDE_VERSION=3.6.1
|
||||
GPUIMAGE_VERSION=1.3.0
|
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
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
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
|
||||
|
@@ -1,6 +1,7 @@
|
||||
task androidJavadocs(type: Javadoc) {
|
||||
source = android.sourceSets.main.java.srcDirs
|
||||
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
|
||||
ext.androidJar = "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar"
|
||||
classpath += files(ext.androidJar)
|
||||
}
|
||||
|
||||
task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
|
||||
|
@@ -15,9 +15,8 @@ android {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile fileTree(dir: 'libs', include: ['*.jar'])
|
||||
compile 'com.github.bumptech.glide:glide:3.5.1'
|
||||
compile 'jp.co.cyberagent.android.gpuimage:gpuimage-library:1.2.3'
|
||||
compile "com.github.bumptech.glide:glide:${GLIDE_VERSION}"
|
||||
compile "jp.co.cyberagent.android.gpuimage:gpuimage-library:${GPUIMAGE_VERSION}"
|
||||
}
|
||||
|
||||
android.libraryVariants.all { variant ->
|
||||
|
@@ -1,3 +1 @@
|
||||
<manifest
|
||||
package="jp.wasabeef.glide.transformations">
|
||||
</manifest>
|
||||
<manifest package="jp.wasabeef.glide.transformations"></manifest>
|
||||
|
@@ -16,68 +16,98 @@ package jp.wasabeef.glide.transformations;
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.support.v8.renderscript.Allocation;
|
||||
import android.support.v8.renderscript.Element;
|
||||
import android.support.v8.renderscript.RenderScript;
|
||||
import android.support.v8.renderscript.ScriptIntrinsicBlur;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.Transformation;
|
||||
import com.bumptech.glide.load.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.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.support.v8.renderscript.Allocation;
|
||||
import android.support.v8.renderscript.RenderScript;
|
||||
import android.support.v8.renderscript.ScriptIntrinsicBlur;
|
||||
|
||||
public class BlurTransformation implements Transformation<Bitmap> {
|
||||
|
||||
private static int MAX_RADIUS = 25;
|
||||
private static int MAX_RADIUS = 25;
|
||||
private static int DEFAULT_DOWN_SAMPLING = 1;
|
||||
|
||||
private Context mContext;
|
||||
private BitmapPool mBitmapPool;
|
||||
private Context mContext;
|
||||
private BitmapPool mBitmapPool;
|
||||
|
||||
private int mRadius;
|
||||
private int mRadius;
|
||||
private int mSampling;
|
||||
|
||||
public BlurTransformation(Context context, BitmapPool pool) {
|
||||
this(context, pool, MAX_RADIUS);
|
||||
public BlurTransformation(Context context) {
|
||||
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) {
|
||||
mContext = context;
|
||||
mBitmapPool = pool;
|
||||
mRadius = radius;
|
||||
}
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
canvas.scale(1 / (float) mSampling, 1 / (float) mSampling);
|
||||
Paint paint = new Paint();
|
||||
paint.setFlags(Paint.FILTER_BITMAP_FLAG);
|
||||
canvas.drawBitmap(source, 0, 0, paint);
|
||||
|
||||
@Override
|
||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
||||
Bitmap source = resource.get();
|
||||
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));
|
||||
|
||||
int width = source.getWidth();
|
||||
int height = source.getHeight();
|
||||
blur.setInput(input);
|
||||
blur.setRadius(mRadius);
|
||||
blur.forEach(output);
|
||||
output.copyTo(bitmap);
|
||||
|
||||
Bitmap bitmap = mBitmapPool.get(width, height, source.getConfig());
|
||||
if (bitmap == null) {
|
||||
bitmap = Bitmap.createBitmap(width, height, source.getConfig());
|
||||
}
|
||||
rs.destroy();
|
||||
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
canvas.drawBitmap(source, 0, 0, null);
|
||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||
}
|
||||
|
||||
RenderScript rs = RenderScript.create(mContext);
|
||||
Allocation overlayAlloc = Allocation.createFromBitmap(rs, bitmap);
|
||||
ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(rs, overlayAlloc.getElement());
|
||||
blur.setInput(overlayAlloc);
|
||||
blur.setRadius(mRadius);
|
||||
blur.forEach(overlayAlloc);
|
||||
overlayAlloc.copyTo(bitmap);
|
||||
|
||||
source.recycle();
|
||||
rs.destroy();
|
||||
|
||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return "BlurTransformation(radius=" + mRadius + ")";
|
||||
}
|
||||
@Override public String getId() {
|
||||
return "BlurTransformation(radius=" + mRadius + ", sampling=" + mSampling + ")";
|
||||
}
|
||||
}
|
||||
|
@@ -16,53 +16,57 @@ package jp.wasabeef.glide.transformations;
|
||||
* 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.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.PorterDuff;
|
||||
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> {
|
||||
|
||||
private BitmapPool mBitmapPool;
|
||||
private BitmapPool mBitmapPool;
|
||||
|
||||
private int mColor;
|
||||
private int mColor;
|
||||
|
||||
public ColorFilterTransformation(BitmapPool pool, int color) {
|
||||
mBitmapPool = pool;
|
||||
mColor = color;
|
||||
public ColorFilterTransformation(Context context, int color) {
|
||||
this(Glide.get(context).getBitmapPool(), 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
|
||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
||||
Bitmap source = resource.get();
|
||||
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);
|
||||
|
||||
int width = source.getWidth();
|
||||
int height = source.getHeight();
|
||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||
}
|
||||
|
||||
Bitmap bitmap = mBitmapPool.get(width, height, source.getConfig());
|
||||
if (bitmap == null) {
|
||||
bitmap = Bitmap.createBitmap(width, height, source.getConfig());
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
source.recycle();
|
||||
|
||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return "ColorFilterTransformation(color=" + mColor + ")";
|
||||
}
|
||||
@Override public String getId() {
|
||||
return "ColorFilterTransformation(color=" + mColor + ")";
|
||||
}
|
||||
}
|
||||
|
@@ -16,58 +16,62 @@ package jp.wasabeef.glide.transformations;
|
||||
* 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.graphics.Bitmap;
|
||||
import android.graphics.BitmapShader;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.Paint;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.Transformation;
|
||||
import com.bumptech.glide.load.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> {
|
||||
|
||||
private BitmapPool mBitmapPool;
|
||||
private BitmapPool mBitmapPool;
|
||||
|
||||
public CropCircleTransformation(BitmapPool pool) {
|
||||
this.mBitmapPool = pool;
|
||||
public CropCircleTransformation(Context context) {
|
||||
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
|
||||
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(width, height, source.getConfig());
|
||||
if (bitmap == null) {
|
||||
bitmap = Bitmap.createBitmap(width, height, source.getConfig());
|
||||
}
|
||||
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
Paint paint = new Paint();
|
||||
BitmapShader shader = new BitmapShader(source, BitmapShader.TileMode.CLAMP,
|
||||
BitmapShader.TileMode.CLAMP);
|
||||
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);
|
||||
|
||||
source.recycle();
|
||||
|
||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||
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);
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return "CropCircleTransformation()";
|
||||
}
|
||||
float r = size / 2f;
|
||||
canvas.drawCircle(r, r, r, paint);
|
||||
|
||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||
}
|
||||
|
||||
@Override public String getId() {
|
||||
return "CropCircleTransformation()";
|
||||
}
|
||||
}
|
||||
|
@@ -16,45 +16,47 @@ package jp.wasabeef.glide.transformations;
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.Transformation;
|
||||
import com.bumptech.glide.load.engine.Resource;
|
||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
|
||||
public class CropSquareTransformation implements Transformation<Bitmap> {
|
||||
|
||||
private BitmapPool mBitmapPool;
|
||||
private int mWidth;
|
||||
private int mHeight;
|
||||
private BitmapPool mBitmapPool;
|
||||
private int mWidth;
|
||||
private int mHeight;
|
||||
|
||||
public CropSquareTransformation(BitmapPool pool) {
|
||||
this.mBitmapPool = pool;
|
||||
public CropSquareTransformation(Context context) {
|
||||
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
|
||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
||||
Bitmap source = resource.get();
|
||||
int size = Math.min(source.getWidth(), source.getHeight());
|
||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||
}
|
||||
|
||||
mWidth = (source.getWidth() - size) / 2;
|
||||
mHeight = (source.getHeight() - size) / 2;
|
||||
|
||||
Bitmap bitmap = mBitmapPool.get(mWidth, mHeight, source.getConfig());
|
||||
if (bitmap == null) {
|
||||
bitmap = Bitmap.createBitmap(source, mWidth, mHeight, size, size);
|
||||
}
|
||||
|
||||
if (bitmap != source) {
|
||||
source.recycle();
|
||||
}
|
||||
|
||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return "CropSquareTransformation(width=" + mWidth + ", height=" + mHeight + ")";
|
||||
}
|
||||
@Override public String getId() {
|
||||
return "CropSquareTransformation(width=" + mWidth + ", height=" + mHeight + ")";
|
||||
}
|
||||
}
|
||||
|
@@ -16,66 +16,101 @@ package jp.wasabeef.glide.transformations;
|
||||
* 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.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.Canvas;
|
||||
import android.graphics.RectF;
|
||||
|
||||
public class CropTransformation implements Transformation<Bitmap> {
|
||||
|
||||
private BitmapPool mBitmapPool;
|
||||
private int mWidth;
|
||||
private int mHeight;
|
||||
public enum CropType {
|
||||
TOP,
|
||||
CENTER,
|
||||
BOTTOM
|
||||
}
|
||||
|
||||
public CropTransformation(BitmapPool pool) {
|
||||
mBitmapPool = pool;
|
||||
private BitmapPool mBitmapPool;
|
||||
private int mWidth;
|
||||
private int mHeight;
|
||||
|
||||
private CropType mCropType = CropType.CENTER;
|
||||
|
||||
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) {
|
||||
mBitmapPool = pool;
|
||||
mWidth = width;
|
||||
mHeight = height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
||||
Bitmap source = resource.get();
|
||||
if (mWidth == 0) {
|
||||
mWidth = source.getWidth();
|
||||
}
|
||||
if (mHeight == 0) {
|
||||
mHeight = source.getHeight();
|
||||
}
|
||||
|
||||
Bitmap bitmap = mBitmapPool.get(mWidth, mHeight, source.getConfig());
|
||||
if (bitmap == null) {
|
||||
bitmap = Bitmap.createBitmap(mWidth, mHeight, source.getConfig());
|
||||
}
|
||||
|
||||
float scaleX = (float) mWidth / source.getWidth();
|
||||
float scaleY = (float) mHeight / source.getHeight();
|
||||
float scale = Math.max(scaleX, scaleY);
|
||||
|
||||
float scaledWidth = scale * source.getWidth();
|
||||
float scaledHeight = scale * source.getHeight();
|
||||
float left = (mWidth - scaledWidth) / 2;
|
||||
float top = (mHeight - scaledHeight) / 2;
|
||||
RectF targetRect = new RectF(left, top, left + scaledWidth, top + scaledHeight);
|
||||
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
canvas.drawBitmap(source, null, targetRect, null);
|
||||
|
||||
source.recycle();
|
||||
|
||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return "CropTransformation(width=" + mWidth + ", height=" + mHeight + ")";
|
||||
float scaleX = (float) mWidth / source.getWidth();
|
||||
float scaleY = (float) mHeight / source.getHeight();
|
||||
float scale = Math.max(scaleX, scaleY);
|
||||
|
||||
float scaledWidth = scale * source.getWidth();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -16,51 +16,55 @@ package jp.wasabeef.glide.transformations;
|
||||
* 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.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.ColorMatrix;
|
||||
import android.graphics.ColorMatrixColorFilter;
|
||||
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> {
|
||||
|
||||
private BitmapPool mBitmapPool;
|
||||
private BitmapPool mBitmapPool;
|
||||
|
||||
public GrayscaleTransformation(BitmapPool pool) {
|
||||
mBitmapPool = pool;
|
||||
public GrayscaleTransformation(Context context) {
|
||||
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
|
||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
||||
Bitmap source = resource.get();
|
||||
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);
|
||||
|
||||
int width = source.getWidth();
|
||||
int height = source.getHeight();
|
||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||
}
|
||||
|
||||
Bitmap bitmap = mBitmapPool.get(width, height, source.getConfig());
|
||||
if (bitmap == null) {
|
||||
bitmap = Bitmap.createBitmap(width, height, source.getConfig());
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
source.recycle();
|
||||
|
||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return "GrayscaleTransformation()";
|
||||
}
|
||||
@Override public String getId() {
|
||||
return "GrayscaleTransformation()";
|
||||
}
|
||||
}
|
||||
|
@@ -16,57 +16,59 @@ package jp.wasabeef.glide.transformations;
|
||||
* 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.graphics.Bitmap;
|
||||
import android.graphics.BitmapShader;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.RectF;
|
||||
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> {
|
||||
|
||||
private BitmapPool mBitmapPool;
|
||||
private BitmapPool mBitmapPool;
|
||||
|
||||
private int radius;
|
||||
private int margin;
|
||||
private int radius;
|
||||
private int margin;
|
||||
|
||||
public RoundedCornersTransformation(BitmapPool pool, int radius, int margin) {
|
||||
this.radius = radius;
|
||||
this.margin = margin;
|
||||
mBitmapPool = pool;
|
||||
public RoundedCornersTransformation(Context context, int radius, int margin) {
|
||||
this(Glide.get(context).getBitmapPool(), radius, margin);
|
||||
}
|
||||
|
||||
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
|
||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
||||
Bitmap source = resource.get();
|
||||
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);
|
||||
|
||||
int width = source.getWidth();
|
||||
int height = source.getHeight();
|
||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||
}
|
||||
|
||||
Bitmap bitmap = mBitmapPool.get(width, height, source.getConfig());
|
||||
if (bitmap == null) {
|
||||
bitmap = Bitmap.createBitmap(width, height, source.getConfig());
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
source.recycle();
|
||||
|
||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return "RoundedTransformation(radius=" + radius + ", margin=" + margin + ")";
|
||||
}
|
||||
@Override public String getId() {
|
||||
return "RoundedTransformation(radius=" + radius + ", margin=" + margin + ")";
|
||||
}
|
||||
}
|
||||
|
@@ -16,14 +16,13 @@ package jp.wasabeef.glide.transformations.gpu;
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.Transformation;
|
||||
import com.bumptech.glide.load.engine.Resource;
|
||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImage;
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImageBrightnessFilter;
|
||||
|
||||
@@ -32,40 +31,46 @@ import jp.co.cyberagent.android.gpuimage.GPUImageBrightnessFilter;
|
||||
*/
|
||||
public class BrightnessFilterTransformation implements Transformation<Bitmap> {
|
||||
|
||||
private Context mContext;
|
||||
private BitmapPool mBitmapPool;
|
||||
private Context mContext;
|
||||
private BitmapPool mBitmapPool;
|
||||
|
||||
private GPUImageBrightnessFilter mFilter = new GPUImageBrightnessFilter();
|
||||
private float mBrightness;
|
||||
private GPUImageBrightnessFilter mFilter = new GPUImageBrightnessFilter();
|
||||
private float mBrightness;
|
||||
|
||||
public BrightnessFilterTransformation(Context context, BitmapPool pool) {
|
||||
mContext = context;
|
||||
mBitmapPool = pool;
|
||||
}
|
||||
public BrightnessFilterTransformation(Context context) {
|
||||
this(context, Glide.get(context).getBitmapPool());
|
||||
}
|
||||
|
||||
public BrightnessFilterTransformation(Context context, BitmapPool pool, float brightness) {
|
||||
mContext = context;
|
||||
mBitmapPool = pool;
|
||||
mBrightness = brightness;
|
||||
mFilter.setBrightness(mBrightness);
|
||||
}
|
||||
public BrightnessFilterTransformation(Context context, BitmapPool pool) {
|
||||
this(context, pool, 0.0f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
||||
Bitmap source = resource.get();
|
||||
public BrightnessFilterTransformation(Context context, float brightness) {
|
||||
this(context, Glide.get(context).getBitmapPool(), brightness);
|
||||
}
|
||||
|
||||
GPUImage gpuImage = new GPUImage(mContext);
|
||||
gpuImage.setImage(source);
|
||||
gpuImage.setFilter(mFilter);
|
||||
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
||||
public BrightnessFilterTransformation(Context context, BitmapPool pool, float brightness) {
|
||||
mContext = context;
|
||||
mBitmapPool = pool;
|
||||
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
|
||||
public String getId() {
|
||||
return "BrightnessFilterTransformation(brightness=" + mBrightness + ")";
|
||||
}
|
||||
source.recycle();
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.Transformation;
|
||||
import com.bumptech.glide.load.engine.Resource;
|
||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImage;
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImageContrastFilter;
|
||||
|
||||
@@ -32,40 +31,46 @@ import jp.co.cyberagent.android.gpuimage.GPUImageContrastFilter;
|
||||
*/
|
||||
public class ContrastFilterTransformation implements Transformation<Bitmap> {
|
||||
|
||||
private Context mContext;
|
||||
private BitmapPool mBitmapPool;
|
||||
private Context mContext;
|
||||
private BitmapPool mBitmapPool;
|
||||
|
||||
private GPUImageContrastFilter mFilter = new GPUImageContrastFilter();
|
||||
private float mContrast;
|
||||
private GPUImageContrastFilter mFilter = new GPUImageContrastFilter();
|
||||
private float mContrast;
|
||||
|
||||
public ContrastFilterTransformation(Context context, BitmapPool pool) {
|
||||
mContext = context;
|
||||
mBitmapPool = pool;
|
||||
}
|
||||
public ContrastFilterTransformation(Context context) {
|
||||
this(context, Glide.get(context).getBitmapPool());
|
||||
}
|
||||
|
||||
public ContrastFilterTransformation(Context context, BitmapPool pool, float contrast) {
|
||||
mContext = context;
|
||||
mBitmapPool = pool;
|
||||
mContrast = contrast;
|
||||
mFilter.setContrast(mContrast);
|
||||
}
|
||||
public ContrastFilterTransformation(Context context, BitmapPool pool) {
|
||||
this(context, pool, 1.0f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
||||
Bitmap source = resource.get();
|
||||
public ContrastFilterTransformation(Context context, float contrast) {
|
||||
this(context, Glide.get(context).getBitmapPool(), contrast);
|
||||
}
|
||||
|
||||
GPUImage gpuImage = new GPUImage(mContext);
|
||||
gpuImage.setImage(source);
|
||||
gpuImage.setFilter(mFilter);
|
||||
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
||||
public ContrastFilterTransformation(Context context, BitmapPool pool, float contrast) {
|
||||
mContext = context;
|
||||
mBitmapPool = pool;
|
||||
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
|
||||
public String getId() {
|
||||
return "ContrastFilterTransformation(contrast=" + mContrast + ")";
|
||||
}
|
||||
source.recycle();
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.Transformation;
|
||||
import com.bumptech.glide.load.engine.Resource;
|
||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImage;
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImageColorInvertFilter;
|
||||
|
||||
/**
|
||||
* Invert all the colors in the image.
|
||||
*/
|
||||
public class InvertFilterTransformation implements Transformation<Bitmap> {
|
||||
|
||||
private Context mContext;
|
||||
private BitmapPool mBitmapPool;
|
||||
private Context mContext;
|
||||
private BitmapPool mBitmapPool;
|
||||
|
||||
public InvertFilterTransformation(Context context, BitmapPool pool) {
|
||||
mContext = context;
|
||||
mBitmapPool = pool;
|
||||
}
|
||||
public InvertFilterTransformation(Context context) {
|
||||
this(context, Glide.get(context).getBitmapPool());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
||||
Bitmap source = resource.get();
|
||||
public InvertFilterTransformation(Context context, BitmapPool pool) {
|
||||
mContext = context;
|
||||
mBitmapPool = pool;
|
||||
}
|
||||
|
||||
GPUImage gpuImage = new GPUImage(mContext);
|
||||
gpuImage.setImage(source);
|
||||
gpuImage.setFilter(new GPUImageColorInvertFilter());
|
||||
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
||||
@Override
|
||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
||||
Bitmap source = resource.get();
|
||||
|
||||
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
|
||||
public String getId() {
|
||||
return "InvertFilterTransformation()";
|
||||
}
|
||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||
}
|
||||
|
||||
@Override public String getId() {
|
||||
return "InvertFilterTransformation()";
|
||||
}
|
||||
}
|
||||
|
@@ -16,57 +16,70 @@ package jp.wasabeef.glide.transformations.gpu;
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.Transformation;
|
||||
import com.bumptech.glide.load.engine.Resource;
|
||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImage;
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImageKuwaharaFilter;
|
||||
|
||||
/**
|
||||
* The radius to sample from when creating the brush-stroke effect, with a default of 3.
|
||||
* Kuwahara image abstraction, drawn from the work of Kyprianidis, et. al. in their publication
|
||||
* "Anisotropic Kuwahara Filtering on the GPU" within the GPU Pro collection. This produces an
|
||||
* oil-painting-like
|
||||
* image, but it is extremely computationally expensive, so it can take seconds to render a frame
|
||||
* on
|
||||
* an iPad 2.
|
||||
* This might be best used for still images.
|
||||
*
|
||||
* The radius to sample from when creating the brush-stroke effect, with a default of 25.
|
||||
* The larger the radius, the slower the filter.
|
||||
*/
|
||||
public class KuwaharaFilterTransformation implements Transformation<Bitmap> {
|
||||
|
||||
private Context mContext;
|
||||
private BitmapPool mBitmapPool;
|
||||
private Context mContext;
|
||||
private BitmapPool mBitmapPool;
|
||||
|
||||
private GPUImageKuwaharaFilter mFilter = new GPUImageKuwaharaFilter();
|
||||
private int mRadius;
|
||||
private GPUImageKuwaharaFilter mFilter = new GPUImageKuwaharaFilter();
|
||||
private int mRadius;
|
||||
|
||||
public KuwaharaFilterTransformation(Context context, BitmapPool pool) {
|
||||
mContext = context;
|
||||
mBitmapPool = pool;
|
||||
}
|
||||
public KuwaharaFilterTransformation(Context context) {
|
||||
this(context, Glide.get(context).getBitmapPool());
|
||||
}
|
||||
|
||||
public KuwaharaFilterTransformation(Context context, BitmapPool pool, int radius) {
|
||||
mContext = context;
|
||||
mBitmapPool = pool;
|
||||
mRadius = radius;
|
||||
mFilter.setRadius(mRadius);
|
||||
}
|
||||
public KuwaharaFilterTransformation(Context context, BitmapPool pool) {
|
||||
this(context, pool, 25);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
||||
Bitmap source = resource.get();
|
||||
public KuwaharaFilterTransformation(Context context, int radius) {
|
||||
this(context, Glide.get(context).getBitmapPool(), radius);
|
||||
}
|
||||
|
||||
GPUImage gpuImage = new GPUImage(mContext);
|
||||
gpuImage.setImage(source);
|
||||
gpuImage.setFilter(mFilter);
|
||||
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
||||
public KuwaharaFilterTransformation(Context context, BitmapPool pool, int radius) {
|
||||
mContext = context;
|
||||
mBitmapPool = pool;
|
||||
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
|
||||
public String getId() {
|
||||
return "KuwaharaFilterTransformation(radius=" + mRadius + ")";
|
||||
}
|
||||
source.recycle();
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.Transformation;
|
||||
import com.bumptech.glide.load.engine.Resource;
|
||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImage;
|
||||
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> {
|
||||
|
||||
private Context mContext;
|
||||
private BitmapPool mBitmapPool;
|
||||
private Context mContext;
|
||||
private BitmapPool mBitmapPool;
|
||||
|
||||
private GPUImagePixelationFilter mFilter = new GPUImagePixelationFilter();
|
||||
private float mPixel;
|
||||
private GPUImagePixelationFilter mFilter = new GPUImagePixelationFilter();
|
||||
private float mPixel;
|
||||
|
||||
public PixelationFilterTransformation(Context context, BitmapPool pool) {
|
||||
mContext = context;
|
||||
mBitmapPool = pool;
|
||||
}
|
||||
public PixelationFilterTransformation(Context context) {
|
||||
this(context, Glide.get(context).getBitmapPool());
|
||||
}
|
||||
|
||||
public PixelationFilterTransformation(Context context, BitmapPool pool, float pixel) {
|
||||
mContext = context;
|
||||
mBitmapPool = pool;
|
||||
mPixel = pixel;
|
||||
mFilter.setPixel(mPixel);
|
||||
}
|
||||
public PixelationFilterTransformation(Context context, BitmapPool pool) {
|
||||
this(context, pool, 10f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
||||
Bitmap source = resource.get();
|
||||
public PixelationFilterTransformation(Context context, float pixel) {
|
||||
this(context, Glide.get(context).getBitmapPool(), pixel);
|
||||
}
|
||||
|
||||
GPUImage gpuImage = new GPUImage(mContext);
|
||||
gpuImage.setImage(source);
|
||||
gpuImage.setFilter(mFilter);
|
||||
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
||||
public PixelationFilterTransformation(Context context, BitmapPool pool, float pixel) {
|
||||
mContext = context;
|
||||
mBitmapPool = pool;
|
||||
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
|
||||
public String getId() {
|
||||
return "PixelationFilterTransformation(pixel=" + mPixel + ")";
|
||||
}
|
||||
source.recycle();
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.Transformation;
|
||||
import com.bumptech.glide.load.engine.Resource;
|
||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImage;
|
||||
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> {
|
||||
|
||||
private Context mContext;
|
||||
private BitmapPool mBitmapPool;
|
||||
private Context mContext;
|
||||
private BitmapPool mBitmapPool;
|
||||
|
||||
private GPUImageSepiaFilter mFilter = new GPUImageSepiaFilter();
|
||||
private float mIntensity;
|
||||
private GPUImageSepiaFilter mFilter = new GPUImageSepiaFilter();
|
||||
private float mIntensity;
|
||||
|
||||
public SepiaFilterTransformation(Context context, BitmapPool pool) {
|
||||
mContext = context;
|
||||
mBitmapPool = pool;
|
||||
}
|
||||
public SepiaFilterTransformation(Context context) {
|
||||
this(context, Glide.get(context).getBitmapPool());
|
||||
}
|
||||
|
||||
public SepiaFilterTransformation(Context context, BitmapPool pool, float intensity) {
|
||||
mContext = context;
|
||||
mBitmapPool = pool;
|
||||
mIntensity = intensity;
|
||||
mFilter.setIntensity(mIntensity);
|
||||
}
|
||||
public SepiaFilterTransformation(Context context, BitmapPool pool) {
|
||||
this(context, pool, 1.0f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
||||
Bitmap source = resource.get();
|
||||
public SepiaFilterTransformation(Context context, float intensity) {
|
||||
this(context, Glide.get(context).getBitmapPool(), intensity);
|
||||
}
|
||||
|
||||
GPUImage gpuImage = new GPUImage(mContext);
|
||||
gpuImage.setImage(source);
|
||||
gpuImage.setFilter(mFilter);
|
||||
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
||||
public SepiaFilterTransformation(Context context, BitmapPool pool, float intensity) {
|
||||
mContext = context;
|
||||
mBitmapPool = pool;
|
||||
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
|
||||
public String getId() {
|
||||
return "SepiaFilterTransformation(intensity=" + mIntensity + ")";
|
||||
}
|
||||
source.recycle();
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.Transformation;
|
||||
import com.bumptech.glide.load.engine.Resource;
|
||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImage;
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImageSketchFilter;
|
||||
|
||||
public class SketchFilterTransformation implements Transformation<Bitmap> {
|
||||
|
||||
private Context mContext;
|
||||
private BitmapPool mBitmapPool;
|
||||
private Context mContext;
|
||||
private BitmapPool mBitmapPool;
|
||||
|
||||
public SketchFilterTransformation(Context context, BitmapPool pool) {
|
||||
mContext = context;
|
||||
mBitmapPool = pool;
|
||||
}
|
||||
public SketchFilterTransformation(Context context) {
|
||||
this(context, Glide.get(context).getBitmapPool());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
||||
Bitmap source = resource.get();
|
||||
public SketchFilterTransformation(Context context, BitmapPool pool) {
|
||||
mContext = context;
|
||||
mBitmapPool = pool;
|
||||
}
|
||||
|
||||
GPUImage gpuImage = new GPUImage(mContext);
|
||||
gpuImage.setImage(source);
|
||||
gpuImage.setFilter(new GPUImageSketchFilter());
|
||||
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
||||
@Override
|
||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
||||
Bitmap source = resource.get();
|
||||
|
||||
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
|
||||
public String getId() {
|
||||
return "SketchFilterTransformation()";
|
||||
}
|
||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||
}
|
||||
|
||||
@Override public String getId() {
|
||||
return "SketchFilterTransformation()";
|
||||
}
|
||||
}
|
||||
|
@@ -16,68 +16,75 @@ package jp.wasabeef.glide.transformations.gpu;
|
||||
* 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.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.graphics.Bitmap;
|
||||
import android.graphics.PointF;
|
||||
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImage;
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImageSwirlFilter;
|
||||
|
||||
/**
|
||||
* Creates a swirl distortion on the image.
|
||||
*/
|
||||
public class SwirlFilterTransformation implements Transformation<Bitmap> {
|
||||
|
||||
private Context mContext;
|
||||
private BitmapPool mBitmapPool;
|
||||
private Context mContext;
|
||||
private BitmapPool mBitmapPool;
|
||||
|
||||
private GPUImageSwirlFilter mFilter = new GPUImageSwirlFilter();
|
||||
private float mRadius;
|
||||
private float mAngle;
|
||||
private PointF mCenter;
|
||||
private GPUImageSwirlFilter mFilter = new GPUImageSwirlFilter();
|
||||
private float mRadius;
|
||||
private float mAngle;
|
||||
private PointF mCenter;
|
||||
|
||||
public SwirlFilterTransformation(Context context, BitmapPool pool) {
|
||||
mContext = context;
|
||||
mBitmapPool = pool;
|
||||
mCenter = new PointF();
|
||||
}
|
||||
public SwirlFilterTransformation(Context context) {
|
||||
this(context, Glide.get(context).getBitmapPool());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param radius from 0.0 to 1.0, default 0.5
|
||||
* @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);
|
||||
}
|
||||
public SwirlFilterTransformation(Context context, BitmapPool pool) {
|
||||
this(context, pool, .5f, 1.0f, new PointF(0.5f, 0.5f));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
||||
Bitmap source = resource.get();
|
||||
public SwirlFilterTransformation(Context context, float radius, float angle, PointF center) {
|
||||
this(context, Glide.get(context).getBitmapPool(), radius, angle, center);
|
||||
}
|
||||
|
||||
GPUImage gpuImage = new GPUImage(mContext);
|
||||
gpuImage.setImage(source);
|
||||
gpuImage.setFilter(mFilter);
|
||||
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
||||
/**
|
||||
* @param radius from 0.0 to 1.0, default 0.5
|
||||
* @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);
|
||||
}
|
||||
|
||||
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
|
||||
public String getId() {
|
||||
return "SwirlFilterTransformation(radius=" + mRadius +
|
||||
",angle=" + mAngle + ",center=" + mCenter.toString() + ")";
|
||||
}
|
||||
source.recycle();
|
||||
|
||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||
}
|
||||
|
||||
@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.
|
||||
*/
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.Transformation;
|
||||
import com.bumptech.glide.load.engine.Resource;
|
||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImage;
|
||||
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> {
|
||||
|
||||
private Context mContext;
|
||||
private BitmapPool mBitmapPool;
|
||||
private Context mContext;
|
||||
private BitmapPool mBitmapPool;
|
||||
|
||||
private GPUImageToonFilter mFilter = new GPUImageToonFilter();
|
||||
private float mThreshold;
|
||||
private float mQuantizationLevels;
|
||||
private GPUImageToonFilter mFilter = new GPUImageToonFilter();
|
||||
private float mThreshold;
|
||||
private float mQuantizationLevels;
|
||||
|
||||
public ToonFilterTransformation(Context context, BitmapPool pool) {
|
||||
mContext = context;
|
||||
mBitmapPool = pool;
|
||||
}
|
||||
public ToonFilterTransformation(Context context) {
|
||||
this(context, Glide.get(context).getBitmapPool());
|
||||
}
|
||||
|
||||
public ToonFilterTransformation(Context context, BitmapPool pool,
|
||||
float threshold, float quantizationLevels) {
|
||||
mContext = context;
|
||||
mBitmapPool = pool;
|
||||
mThreshold = threshold;
|
||||
mQuantizationLevels = quantizationLevels;
|
||||
mFilter.setThreshold(mThreshold);
|
||||
mFilter.setQuantizationLevels(mQuantizationLevels);
|
||||
}
|
||||
public ToonFilterTransformation(Context context, BitmapPool pool) {
|
||||
this(context, pool, .2f, 10.0f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
||||
Bitmap source = resource.get();
|
||||
public ToonFilterTransformation(Context context, float threshold, float quantizationLevels) {
|
||||
this(context, Glide.get(context).getBitmapPool(), threshold, quantizationLevels);
|
||||
}
|
||||
|
||||
GPUImage gpuImage = new GPUImage(mContext);
|
||||
gpuImage.setImage(source);
|
||||
gpuImage.setFilter(mFilter);
|
||||
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
||||
public ToonFilterTransformation(Context context, BitmapPool pool, float threshold,
|
||||
float quantizationLevels) {
|
||||
mContext = context;
|
||||
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
|
||||
public String getId() {
|
||||
return "ToonFilterTransformation(threshold=" + mThreshold +
|
||||
",quantizationLevels=" + mQuantizationLevels + ")";
|
||||
}
|
||||
source.recycle();
|
||||
|
||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||
}
|
||||
|
||||
@Override public String getId() {
|
||||
return "ToonFilterTransformation(threshold=" + mThreshold +
|
||||
",quantizationLevels=" + mQuantizationLevels + ")";
|
||||
}
|
||||
}
|
||||
|
@@ -16,75 +16,78 @@ package jp.wasabeef.glide.transformations.gpu;
|
||||
* 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.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.graphics.Bitmap;
|
||||
import android.graphics.PointF;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImage;
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImageVignetteFilter;
|
||||
|
||||
/**
|
||||
* Performs a vignetting effect, fading out the image at the edges
|
||||
* x:
|
||||
* y: The directional intensity of the vignetting, with a default of x = 0.75, y = 0.5
|
||||
* The directional intensity of the vignetting,
|
||||
* with a default of x = 0.5, y = 0.5, start = 0, end = 0.75
|
||||
*/
|
||||
public class VignetteFilterTransformation implements Transformation<Bitmap> {
|
||||
|
||||
private Context mContext;
|
||||
private BitmapPool mBitmapPool;
|
||||
private Context mContext;
|
||||
private BitmapPool mBitmapPool;
|
||||
|
||||
private GPUImageVignetteFilter mFilter = new GPUImageVignetteFilter();
|
||||
private PointF mCenter;
|
||||
private float[] mVignetteColor;
|
||||
private float mVignetteStart;
|
||||
private float mVignetteEnd;
|
||||
private GPUImageVignetteFilter mFilter = new GPUImageVignetteFilter();
|
||||
private PointF mCenter;
|
||||
private float[] mVignetteColor;
|
||||
private float mVignetteStart;
|
||||
private float mVignetteEnd;
|
||||
|
||||
public VignetteFilterTransformation(Context context) {
|
||||
this(context, Glide.get(context).getBitmapPool());
|
||||
}
|
||||
|
||||
public VignetteFilterTransformation(Context context, BitmapPool pool) {
|
||||
mContext = context;
|
||||
mBitmapPool = pool;
|
||||
mCenter = new PointF();
|
||||
}
|
||||
public VignetteFilterTransformation(Context context, BitmapPool pool) {
|
||||
this(context, pool, new PointF(0.5f, 0.5f), new float[] { 0.0f, 0.0f, 0.0f }, 0.0f, 0.75f);
|
||||
}
|
||||
|
||||
public VignetteFilterTransformation(Context context, BitmapPool pool,
|
||||
PointF center, float[] color, float start, float end) {
|
||||
mContext = context;
|
||||
mBitmapPool = pool;
|
||||
mCenter = center;
|
||||
mVignetteColor = color;
|
||||
mVignetteStart = start;
|
||||
mVignetteEnd = end;
|
||||
mFilter.setVignetteCenter(mCenter);
|
||||
mFilter.setVignetteColor(mVignetteColor);
|
||||
mFilter.setVignetteStart(mVignetteStart);
|
||||
mFilter.setVignetteEnd(mVignetteEnd);
|
||||
}
|
||||
public VignetteFilterTransformation(Context context, PointF center, float[] color, float start,
|
||||
float end) {
|
||||
this(context, Glide.get(context).getBitmapPool(), center, color, start, end);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
||||
Bitmap source = resource.get();
|
||||
public VignetteFilterTransformation(Context context, BitmapPool pool, PointF center,
|
||||
float[] color, float start, float end) {
|
||||
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);
|
||||
gpuImage.setImage(source);
|
||||
gpuImage.setFilter(mFilter);
|
||||
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
||||
@Override
|
||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
||||
Bitmap source = resource.get();
|
||||
|
||||
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
|
||||
public String getId() {
|
||||
return "VignetteFilterTransformation(center=" + mCenter.toString() +
|
||||
",color=" + Arrays.toString(mVignetteColor) +
|
||||
",start=" + mVignetteStart + ",end=" + mVignetteEnd + ")";
|
||||
}
|
||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||
}
|
||||
|
||||
@Override public String getId() {
|
||||
return "VignetteFilterTransformation(center=" + mCenter.toString() +
|
||||
",color=" + Arrays.toString(mVignetteColor) +
|
||||
",start=" + mVignetteStart + ",end=" + mVignetteEnd + ")";
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user