mirror of
https://github.com/wasabeef/glide-transformations.git
synced 2025-06-10 16:54:26 +08:00
change the codestyle
This commit is contained in:
parent
cdbd42595a
commit
f83e5ef85a
@ -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,40 @@ 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.CropTop);
|
||||||
dataSet.add(Type.CropCenter);
|
dataSet.add(Type.CropCenter);
|
||||||
dataSet.add(Type.CropBottom);
|
dataSet.add(Type.CropBottom);
|
||||||
dataSet.add(Type.CropSquare);
|
dataSet.add(Type.CropSquare);
|
||||||
dataSet.add(Type.CropCircle);
|
dataSet.add(Type.CropCircle);
|
||||||
dataSet.add(Type.ColorFilter);
|
dataSet.add(Type.ColorFilter);
|
||||||
dataSet.add(Type.Grayscale);
|
dataSet.add(Type.Grayscale);
|
||||||
dataSet.add(Type.RoundedCorners);
|
dataSet.add(Type.RoundedCorners);
|
||||||
dataSet.add(Type.Blur);
|
dataSet.add(Type.Blur);
|
||||||
dataSet.add(Type.Toon);
|
dataSet.add(Type.Toon);
|
||||||
dataSet.add(Type.Sepia);
|
dataSet.add(Type.Sepia);
|
||||||
dataSet.add(Type.Contrast);
|
dataSet.add(Type.Contrast);
|
||||||
dataSet.add(Type.Invert);
|
dataSet.add(Type.Invert);
|
||||||
dataSet.add(Type.Pixel);
|
dataSet.add(Type.Pixel);
|
||||||
dataSet.add(Type.Sketch);
|
dataSet.add(Type.Sketch);
|
||||||
dataSet.add(Type.Swirl);
|
dataSet.add(Type.Swirl);
|
||||||
dataSet.add(Type.Brightness);
|
dataSet.add(Type.Brightness);
|
||||||
dataSet.add(Type.Kuawahara);
|
dataSet.add(Type.Kuawahara);
|
||||||
dataSet.add(Type.Vignette);
|
dataSet.add(Type.Vignette);
|
||||||
|
|
||||||
recyclerView.setAdapter(new MainAdapter(this, dataSet));
|
recyclerView.setAdapter(new MainAdapter(this, dataSet));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
package jp.wasabeef.example.glide;
|
package jp.wasabeef.example.glide;
|
||||||
|
|
||||||
import com.bumptech.glide.Glide;
|
|
||||||
import com.bumptech.glide.load.Transformation;
|
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.graphics.PointF;
|
import android.graphics.PointF;
|
||||||
@ -12,9 +9,9 @@ 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.Transformation;
|
||||||
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;
|
||||||
@ -38,130 +35,124 @@ 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;
|
||||||
|
|
||||||
enum Type {
|
enum Type {
|
||||||
CropTop,
|
CropTop,
|
||||||
CropCenter,
|
CropCenter,
|
||||||
CropBottom,
|
CropBottom,
|
||||||
CropSquare,
|
CropSquare,
|
||||||
CropCircle,
|
CropCircle,
|
||||||
ColorFilter,
|
ColorFilter,
|
||||||
Grayscale,
|
Grayscale,
|
||||||
RoundedCorners,
|
RoundedCorners,
|
||||||
Blur,
|
Blur,
|
||||||
Toon,
|
Toon,
|
||||||
Sepia,
|
Sepia,
|
||||||
Contrast,
|
Contrast,
|
||||||
Invert,
|
Invert,
|
||||||
Pixel,
|
Pixel,
|
||||||
Sketch,
|
Sketch,
|
||||||
Swirl,
|
Swirl,
|
||||||
Brightness,
|
Brightness,
|
||||||
Kuawahara,
|
Kuawahara,
|
||||||
Vignette
|
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) {
|
Glide.with(mContext).load(R.drawable.demo).bitmapTransform(transformation).into(holder.image);
|
||||||
mContext = context;
|
holder.title.setText(mDataSet.get(position).name());
|
||||||
mDataSet = dataSet;
|
}
|
||||||
}
|
|
||||||
|
@Override public int getItemCount() {
|
||||||
@Override
|
return mDataSet.size();
|
||||||
public MainAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
}
|
||||||
View v = LayoutInflater.from(mContext)
|
|
||||||
.inflate(R.layout.layout_list_item, parent, false);
|
static class ViewHolder extends RecyclerView.ViewHolder {
|
||||||
return new ViewHolder(v);
|
|
||||||
}
|
public ImageView image;
|
||||||
|
public TextView title;
|
||||||
@Override
|
|
||||||
public void onBindViewHolder(MainAdapter.ViewHolder holder, int position) {
|
ViewHolder(View itemView) {
|
||||||
Transformation transformation = null;
|
super(itemView);
|
||||||
switch (mDataSet.get(position)) {
|
image = (ImageView) itemView.findViewById(R.id.image);
|
||||||
case CropTop:
|
title = (TextView) itemView.findViewById(R.id.title);
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
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"
|
<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>
|
||||||
|
@ -16,12 +16,6 @@ package jp.wasabeef.glide.transformations;
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
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.content.Context;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
@ -30,86 +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) {
|
public BlurTransformation(Context context) {
|
||||||
this(context, Glide.get(context).getBitmapPool(), 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) {
|
Canvas canvas = new Canvas(bitmap);
|
||||||
this(context, pool, MAX_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) {
|
RenderScript rs = RenderScript.create(mContext);
|
||||||
this(context, pool, radius, DEFAULT_DOWN_SAMPLING);
|
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));
|
||||||
|
|
||||||
public BlurTransformation(Context context, int radius) {
|
blur.setInput(input);
|
||||||
this(context, Glide.get(context).getBitmapPool(), radius, DEFAULT_DOWN_SAMPLING);
|
blur.setRadius(mRadius);
|
||||||
}
|
blur.forEach(output);
|
||||||
|
output.copyTo(bitmap);
|
||||||
|
|
||||||
public BlurTransformation(Context context, BitmapPool pool, int radius, int sampling) {
|
rs.destroy();
|
||||||
mContext = context;
|
|
||||||
mBitmapPool = pool;
|
|
||||||
mRadius = radius;
|
|
||||||
mSampling = sampling;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BlurTransformation(Context context, int radius, int sampling) {
|
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||||
mContext = context;
|
}
|
||||||
mBitmapPool = Glide.get(context).getBitmapPool();
|
|
||||||
mRadius = radius;
|
|
||||||
mSampling = sampling;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override public String getId() {
|
||||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
return "BlurTransformation(radius=" + mRadius + ", sampling=" + mSampling + ")";
|
||||||
Bitmap source = resource.get();
|
}
|
||||||
|
|
||||||
int width = source.getWidth();
|
|
||||||
int height = source.getHeight();
|
|
||||||
int scaledWidth = width / mSampling;
|
|
||||||
int scaledHeight = height / mSampling;
|
|
||||||
|
|
||||||
Bitmap bitmap = mBitmapPool.get(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
|
|
||||||
if (bitmap == null) {
|
|
||||||
bitmap = Bitmap.createBitmap(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
|
|
||||||
}
|
|
||||||
|
|
||||||
Canvas canvas = new Canvas(bitmap);
|
|
||||||
canvas.scale(1 / (float) mSampling, 1 / (float) mSampling);
|
|
||||||
Paint paint = new Paint();
|
|
||||||
paint.setFlags(Paint.FILTER_BITMAP_FLAG);
|
|
||||||
canvas.drawBitmap(source, 0, 0, paint);
|
|
||||||
|
|
||||||
RenderScript rs = RenderScript.create(mContext);
|
|
||||||
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,59 +16,57 @@ package jp.wasabeef.glide.transformations;
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
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.content.Context;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
import android.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(Context context, int color) {
|
public ColorFilterTransformation(Context context, int color) {
|
||||||
this(Glide.get(context).getBitmapPool(), 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ColorFilterTransformation(BitmapPool pool, int color) {
|
Canvas canvas = new Canvas(bitmap);
|
||||||
mBitmapPool = pool;
|
Paint paint = new Paint();
|
||||||
mColor = color;
|
paint.setAntiAlias(true);
|
||||||
}
|
paint.setColorFilter(new PorterDuffColorFilter(mColor, PorterDuff.Mode.SRC_ATOP));
|
||||||
|
canvas.drawBitmap(source, 0, 0, paint);
|
||||||
|
|
||||||
@Override
|
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
}
|
||||||
Bitmap source = resource.get();
|
|
||||||
|
|
||||||
int width = source.getWidth();
|
@Override public String getId() {
|
||||||
int height = source.getHeight();
|
return "ColorFilterTransformation(color=" + mColor + ")";
|
||||||
|
}
|
||||||
Bitmap.Config config =
|
|
||||||
source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
|
|
||||||
Bitmap bitmap = mBitmapPool.get(width, height, config);
|
|
||||||
if (bitmap == null) {
|
|
||||||
bitmap = Bitmap.createBitmap(width, height, config);
|
|
||||||
}
|
|
||||||
|
|
||||||
Canvas canvas = new Canvas(bitmap);
|
|
||||||
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,64 +16,62 @@ package jp.wasabeef.glide.transformations;
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
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.content.Context;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapShader;
|
import android.graphics.BitmapShader;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Matrix;
|
import android.graphics.Matrix;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
|
import com.bumptech.glide.Glide;
|
||||||
|
import com.bumptech.glide.load.Transformation;
|
||||||
|
import com.bumptech.glide.load.engine.Resource;
|
||||||
|
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||||
|
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
|
||||||
|
|
||||||
public class CropCircleTransformation implements Transformation<Bitmap> {
|
public class CropCircleTransformation implements Transformation<Bitmap> {
|
||||||
|
|
||||||
private BitmapPool mBitmapPool;
|
private BitmapPool mBitmapPool;
|
||||||
|
|
||||||
public CropCircleTransformation(Context context) {
|
public CropCircleTransformation(Context context) {
|
||||||
this(Glide.get(context).getBitmapPool());
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CropCircleTransformation(BitmapPool pool) {
|
Canvas canvas = new Canvas(bitmap);
|
||||||
this.mBitmapPool = pool;
|
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
|
float r = size / 2f;
|
||||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
canvas.drawCircle(r, r, r, paint);
|
||||||
Bitmap source = resource.get();
|
|
||||||
int size = Math.min(source.getWidth(), source.getHeight());
|
|
||||||
|
|
||||||
int width = (source.getWidth() - size) / 2;
|
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||||
int height = (source.getHeight() - size) / 2;
|
}
|
||||||
|
|
||||||
Bitmap bitmap = mBitmapPool.get(size, size, Bitmap.Config.ARGB_8888);
|
@Override public String getId() {
|
||||||
if (bitmap == null) {
|
return "CropCircleTransformation()";
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getId() {
|
|
||||||
return "CropCircleTransformation()";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -16,49 +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.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;
|
|
||||||
|
|
||||||
public class CropSquareTransformation implements Transformation<Bitmap> {
|
public class CropSquareTransformation implements Transformation<Bitmap> {
|
||||||
|
|
||||||
private BitmapPool mBitmapPool;
|
private BitmapPool mBitmapPool;
|
||||||
private int mWidth;
|
private int mWidth;
|
||||||
private int mHeight;
|
private int mHeight;
|
||||||
|
|
||||||
public CropSquareTransformation(Context context) {
|
public CropSquareTransformation(Context context) {
|
||||||
this(Glide.get(context).getBitmapPool());
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CropSquareTransformation(BitmapPool pool) {
|
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||||
this.mBitmapPool = pool;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override public String getId() {
|
||||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
return "CropSquareTransformation(width=" + mWidth + ", height=" + mHeight + ")";
|
||||||
Bitmap source = resource.get();
|
}
|
||||||
int size = Math.min(source.getWidth(), source.getHeight());
|
|
||||||
|
|
||||||
mWidth = (source.getWidth() - size) / 2;
|
|
||||||
mHeight = (source.getHeight() - size) / 2;
|
|
||||||
|
|
||||||
Bitmap.Config config =
|
|
||||||
source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
|
|
||||||
Bitmap bitmap = mBitmapPool.get(mWidth, mHeight, config);
|
|
||||||
if (bitmap == null) {
|
|
||||||
bitmap = Bitmap.createBitmap(source, mWidth, mHeight, size, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getId() {
|
|
||||||
return "CropSquareTransformation(width=" + mWidth + ", height=" + mHeight + ")";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -16,103 +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.Glide;
|
||||||
import com.bumptech.glide.load.Transformation;
|
import com.bumptech.glide.load.Transformation;
|
||||||
import com.bumptech.glide.load.engine.Resource;
|
import com.bumptech.glide.load.engine.Resource;
|
||||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||||
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
|
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.graphics.Bitmap;
|
|
||||||
import android.graphics.Canvas;
|
|
||||||
import android.graphics.RectF;
|
|
||||||
|
|
||||||
public class CropTransformation implements Transformation<Bitmap> {
|
public class CropTransformation implements Transformation<Bitmap> {
|
||||||
|
|
||||||
public enum CropType {
|
public enum CropType {
|
||||||
TOP,
|
TOP,
|
||||||
CENTER,
|
CENTER,
|
||||||
BOTTOM
|
BOTTOM
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
private BitmapPool mBitmapPool;
|
float scaleX = (float) mWidth / source.getWidth();
|
||||||
private int mWidth;
|
float scaleY = (float) mHeight / source.getHeight();
|
||||||
private int mHeight;
|
float scale = Math.max(scaleX, scaleY);
|
||||||
|
|
||||||
private CropType mCropType = CropType.CENTER;
|
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);
|
||||||
|
|
||||||
public CropTransformation(Context context) {
|
Canvas canvas = new Canvas(bitmap);
|
||||||
this(Glide.get(context).getBitmapPool());
|
canvas.drawBitmap(source, null, targetRect, null);
|
||||||
}
|
|
||||||
|
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||||
public CropTransformation(BitmapPool pool) {
|
}
|
||||||
this(pool, 0, 0);
|
|
||||||
}
|
@Override public String getId() {
|
||||||
|
return "CropTransformation(width=" + mWidth + ", height=" + mHeight + ", cropType=" + mCropType
|
||||||
public CropTransformation(Context context, int width, int height) {
|
+ ")";
|
||||||
this(Glide.get(context).getBitmapPool(), width, height);
|
}
|
||||||
}
|
|
||||||
|
private float getTop(float scaledHeight) {
|
||||||
public CropTransformation(BitmapPool pool, int width, int height) {
|
switch (mCropType) {
|
||||||
this(pool, width, height, CropType.CENTER);
|
case TOP:
|
||||||
}
|
return 0;
|
||||||
|
case CENTER:
|
||||||
public CropTransformation(Context context, int width, int height, CropType cropType) {
|
return (mHeight - scaledHeight) / 2;
|
||||||
this(Glide.get(context).getBitmapPool(), width, height, cropType);
|
case BOTTOM:
|
||||||
}
|
return mHeight - scaledHeight;
|
||||||
|
default:
|
||||||
public CropTransformation(BitmapPool pool, int width, int height, CropType cropType) {
|
return 0;
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
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,57 +16,55 @@ package jp.wasabeef.glide.transformations;
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
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.content.Context;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.ColorMatrix;
|
import android.graphics.ColorMatrix;
|
||||||
import android.graphics.ColorMatrixColorFilter;
|
import android.graphics.ColorMatrixColorFilter;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
|
import com.bumptech.glide.Glide;
|
||||||
|
import com.bumptech.glide.load.Transformation;
|
||||||
|
import com.bumptech.glide.load.engine.Resource;
|
||||||
|
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||||
|
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
|
||||||
|
|
||||||
public class GrayscaleTransformation implements Transformation<Bitmap> {
|
public class GrayscaleTransformation implements Transformation<Bitmap> {
|
||||||
|
|
||||||
private BitmapPool mBitmapPool;
|
private BitmapPool mBitmapPool;
|
||||||
|
|
||||||
public GrayscaleTransformation(Context context) {
|
public GrayscaleTransformation(Context context) {
|
||||||
this(Glide.get(context).getBitmapPool());
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GrayscaleTransformation(BitmapPool pool) {
|
Canvas canvas = new Canvas(bitmap);
|
||||||
mBitmapPool = pool;
|
ColorMatrix saturation = new ColorMatrix();
|
||||||
}
|
saturation.setSaturation(0f);
|
||||||
|
Paint paint = new Paint();
|
||||||
|
paint.setColorFilter(new ColorMatrixColorFilter(saturation));
|
||||||
|
canvas.drawBitmap(source, 0, 0, paint);
|
||||||
|
|
||||||
@Override
|
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
}
|
||||||
Bitmap source = resource.get();
|
|
||||||
|
|
||||||
int width = source.getWidth();
|
@Override public String getId() {
|
||||||
int height = source.getHeight();
|
return "GrayscaleTransformation()";
|
||||||
|
}
|
||||||
Bitmap.Config config =
|
|
||||||
source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
|
|
||||||
Bitmap bitmap = mBitmapPool.get(width, height, config);
|
|
||||||
if (bitmap == null) {
|
|
||||||
bitmap = Bitmap.createBitmap(width, height, config);
|
|
||||||
}
|
|
||||||
|
|
||||||
Canvas canvas = new Canvas(bitmap);
|
|
||||||
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()";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -16,12 +16,6 @@ package jp.wasabeef.glide.transformations;
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
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.content.Context;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapShader;
|
import android.graphics.BitmapShader;
|
||||||
@ -29,48 +23,52 @@ 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(Context context, int radius, int margin) {
|
public RoundedCornersTransformation(Context context, int radius, int margin) {
|
||||||
this(Glide.get(context).getBitmapPool(), radius, 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
public RoundedCornersTransformation(BitmapPool pool, int radius, int margin) {
|
Canvas canvas = new Canvas(bitmap);
|
||||||
mBitmapPool = pool;
|
Paint paint = new Paint();
|
||||||
this.radius = radius;
|
paint.setAntiAlias(true);
|
||||||
this.margin = margin;
|
paint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
|
||||||
}
|
canvas.drawRoundRect(new RectF(margin, margin, width - margin, height - margin), radius, radius,
|
||||||
|
paint);
|
||||||
|
|
||||||
@Override
|
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
}
|
||||||
Bitmap source = resource.get();
|
|
||||||
|
|
||||||
int width = source.getWidth();
|
@Override public String getId() {
|
||||||
int height = source.getHeight();
|
return "RoundedTransformation(radius=" + radius + ", margin=" + margin + ")";
|
||||||
|
}
|
||||||
Bitmap bitmap = mBitmapPool.get(width, height, Bitmap.Config.ARGB_8888);
|
|
||||||
if (bitmap == null) {
|
|
||||||
bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
|
||||||
}
|
|
||||||
|
|
||||||
Canvas canvas = new Canvas(bitmap);
|
|
||||||
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,15 +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.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;
|
||||||
|
|
||||||
@ -33,47 +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) {
|
public BrightnessFilterTransformation(Context context) {
|
||||||
this(context, Glide.get(context).getBitmapPool());
|
this(context, Glide.get(context).getBitmapPool());
|
||||||
}
|
}
|
||||||
|
|
||||||
public BrightnessFilterTransformation(Context context, BitmapPool pool) {
|
public BrightnessFilterTransformation(Context context, BitmapPool pool) {
|
||||||
this(context, pool, 0.0f);
|
this(context, pool, 0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BrightnessFilterTransformation(Context context, float brightness) {
|
public BrightnessFilterTransformation(Context context, float brightness) {
|
||||||
this(context, Glide.get(context).getBitmapPool(), brightness);
|
this(context, Glide.get(context).getBitmapPool(), brightness);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BrightnessFilterTransformation(Context context, BitmapPool pool, float brightness) {
|
public BrightnessFilterTransformation(Context context, BitmapPool pool, float brightness) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mBitmapPool = pool;
|
mBitmapPool = pool;
|
||||||
mBrightness = brightness;
|
mBrightness = brightness;
|
||||||
mFilter.setBrightness(mBrightness);
|
mFilter.setBrightness(mBrightness);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
||||||
Bitmap source = resource.get();
|
Bitmap source = resource.get();
|
||||||
|
|
||||||
GPUImage gpuImage = new GPUImage(mContext);
|
GPUImage gpuImage = new GPUImage(mContext);
|
||||||
gpuImage.setImage(source);
|
gpuImage.setImage(source);
|
||||||
gpuImage.setFilter(mFilter);
|
gpuImage.setFilter(mFilter);
|
||||||
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
||||||
|
|
||||||
source.recycle();
|
source.recycle();
|
||||||
|
|
||||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public String getId() {
|
||||||
public String getId() {
|
return "BrightnessFilterTransformation(brightness=" + mBrightness + ")";
|
||||||
return "BrightnessFilterTransformation(brightness=" + mBrightness + ")";
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -16,15 +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.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;
|
||||||
|
|
||||||
@ -33,47 +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) {
|
public ContrastFilterTransformation(Context context) {
|
||||||
this(context, Glide.get(context).getBitmapPool());
|
this(context, Glide.get(context).getBitmapPool());
|
||||||
}
|
}
|
||||||
|
|
||||||
public ContrastFilterTransformation(Context context, BitmapPool pool) {
|
public ContrastFilterTransformation(Context context, BitmapPool pool) {
|
||||||
this(context, pool, 1.0f);
|
this(context, pool, 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ContrastFilterTransformation(Context context, float contrast) {
|
public ContrastFilterTransformation(Context context, float contrast) {
|
||||||
this(context, Glide.get(context).getBitmapPool(), contrast);
|
this(context, Glide.get(context).getBitmapPool(), contrast);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ContrastFilterTransformation(Context context, BitmapPool pool, float contrast) {
|
public ContrastFilterTransformation(Context context, BitmapPool pool, float contrast) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mBitmapPool = pool;
|
mBitmapPool = pool;
|
||||||
mContrast = contrast;
|
mContrast = contrast;
|
||||||
mFilter.setContrast(mContrast);
|
mFilter.setContrast(mContrast);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
||||||
Bitmap source = resource.get();
|
Bitmap source = resource.get();
|
||||||
|
|
||||||
GPUImage gpuImage = new GPUImage(mContext);
|
GPUImage gpuImage = new GPUImage(mContext);
|
||||||
gpuImage.setImage(source);
|
gpuImage.setImage(source);
|
||||||
gpuImage.setFilter(mFilter);
|
gpuImage.setFilter(mFilter);
|
||||||
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
||||||
|
|
||||||
source.recycle();
|
source.recycle();
|
||||||
|
|
||||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public String getId() {
|
||||||
public String getId() {
|
return "ContrastFilterTransformation(contrast=" + mContrast + ")";
|
||||||
return "ContrastFilterTransformation(contrast=" + mContrast + ")";
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -16,15 +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.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;
|
||||||
|
|
||||||
@ -33,34 +31,33 @@ import jp.co.cyberagent.android.gpuimage.GPUImageColorInvertFilter;
|
|||||||
*/
|
*/
|
||||||
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) {
|
public InvertFilterTransformation(Context context) {
|
||||||
this(context, Glide.get(context).getBitmapPool());
|
this(context, Glide.get(context).getBitmapPool());
|
||||||
}
|
}
|
||||||
|
|
||||||
public InvertFilterTransformation(Context context, BitmapPool pool) {
|
public InvertFilterTransformation(Context context, BitmapPool pool) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mBitmapPool = pool;
|
mBitmapPool = pool;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
||||||
Bitmap source = resource.get();
|
Bitmap source = resource.get();
|
||||||
|
|
||||||
GPUImage gpuImage = new GPUImage(mContext);
|
GPUImage gpuImage = new GPUImage(mContext);
|
||||||
gpuImage.setImage(source);
|
gpuImage.setImage(source);
|
||||||
gpuImage.setFilter(new GPUImageColorInvertFilter());
|
gpuImage.setFilter(new GPUImageColorInvertFilter());
|
||||||
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
||||||
|
|
||||||
source.recycle();
|
source.recycle();
|
||||||
|
|
||||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public String getId() {
|
||||||
public String getId() {
|
return "InvertFilterTransformation()";
|
||||||
return "InvertFilterTransformation()";
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -16,15 +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.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;
|
||||||
|
|
||||||
@ -32,7 +30,8 @@ import jp.co.cyberagent.android.gpuimage.GPUImageKuwaharaFilter;
|
|||||||
* Kuwahara image abstraction, drawn from the work of Kyprianidis, et. al. in their publication
|
* 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
|
* "Anisotropic Kuwahara Filtering on the GPU" within the GPU Pro collection. This produces an
|
||||||
* oil-painting-like
|
* oil-painting-like
|
||||||
* image, but it is extremely computationally expensive, so it can take seconds to render a frame on
|
* image, but it is extremely computationally expensive, so it can take seconds to render a frame
|
||||||
|
* on
|
||||||
* an iPad 2.
|
* an iPad 2.
|
||||||
* This might be best used for still images.
|
* This might be best used for still images.
|
||||||
*
|
*
|
||||||
@ -41,47 +40,46 @@ import jp.co.cyberagent.android.gpuimage.GPUImageKuwaharaFilter;
|
|||||||
*/
|
*/
|
||||||
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) {
|
public KuwaharaFilterTransformation(Context context) {
|
||||||
this(context, Glide.get(context).getBitmapPool());
|
this(context, Glide.get(context).getBitmapPool());
|
||||||
}
|
}
|
||||||
|
|
||||||
public KuwaharaFilterTransformation(Context context, BitmapPool pool) {
|
public KuwaharaFilterTransformation(Context context, BitmapPool pool) {
|
||||||
this(context, pool, 25);
|
this(context, pool, 25);
|
||||||
}
|
}
|
||||||
|
|
||||||
public KuwaharaFilterTransformation(Context context, int radius) {
|
public KuwaharaFilterTransformation(Context context, int radius) {
|
||||||
this(context, Glide.get(context).getBitmapPool(), radius);
|
this(context, Glide.get(context).getBitmapPool(), radius);
|
||||||
}
|
}
|
||||||
|
|
||||||
public KuwaharaFilterTransformation(Context context, BitmapPool pool, int radius) {
|
public KuwaharaFilterTransformation(Context context, BitmapPool pool, int radius) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mBitmapPool = pool;
|
mBitmapPool = pool;
|
||||||
mRadius = radius;
|
mRadius = radius;
|
||||||
mFilter.setRadius(mRadius);
|
mFilter.setRadius(mRadius);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
||||||
Bitmap source = resource.get();
|
Bitmap source = resource.get();
|
||||||
|
|
||||||
GPUImage gpuImage = new GPUImage(mContext);
|
GPUImage gpuImage = new GPUImage(mContext);
|
||||||
gpuImage.setImage(source);
|
gpuImage.setImage(source);
|
||||||
gpuImage.setFilter(mFilter);
|
gpuImage.setFilter(mFilter);
|
||||||
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
||||||
|
|
||||||
source.recycle();
|
source.recycle();
|
||||||
|
|
||||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public String getId() {
|
||||||
public String getId() {
|
return "KuwaharaFilterTransformation(radius=" + mRadius + ")";
|
||||||
return "KuwaharaFilterTransformation(radius=" + mRadius + ")";
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -16,15 +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.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;
|
||||||
|
|
||||||
@ -35,47 +33,46 @@ import jp.co.cyberagent.android.gpuimage.GPUImagePixelationFilter;
|
|||||||
*/
|
*/
|
||||||
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) {
|
public PixelationFilterTransformation(Context context) {
|
||||||
this(context, Glide.get(context).getBitmapPool());
|
this(context, Glide.get(context).getBitmapPool());
|
||||||
}
|
}
|
||||||
|
|
||||||
public PixelationFilterTransformation(Context context, BitmapPool pool) {
|
public PixelationFilterTransformation(Context context, BitmapPool pool) {
|
||||||
this(context, pool, 10f);
|
this(context, pool, 10f);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PixelationFilterTransformation(Context context, float pixel) {
|
public PixelationFilterTransformation(Context context, float pixel) {
|
||||||
this(context, Glide.get(context).getBitmapPool(), pixel);
|
this(context, Glide.get(context).getBitmapPool(), pixel);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PixelationFilterTransformation(Context context, BitmapPool pool, float pixel) {
|
public PixelationFilterTransformation(Context context, BitmapPool pool, float pixel) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mBitmapPool = pool;
|
mBitmapPool = pool;
|
||||||
mPixel = pixel;
|
mPixel = pixel;
|
||||||
mFilter.setPixel(mPixel);
|
mFilter.setPixel(mPixel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
||||||
Bitmap source = resource.get();
|
Bitmap source = resource.get();
|
||||||
|
|
||||||
GPUImage gpuImage = new GPUImage(mContext);
|
GPUImage gpuImage = new GPUImage(mContext);
|
||||||
gpuImage.setImage(source);
|
gpuImage.setImage(source);
|
||||||
gpuImage.setFilter(mFilter);
|
gpuImage.setFilter(mFilter);
|
||||||
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
||||||
|
|
||||||
source.recycle();
|
source.recycle();
|
||||||
|
|
||||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public String getId() {
|
||||||
public String getId() {
|
return "PixelationFilterTransformation(pixel=" + mPixel + ")";
|
||||||
return "PixelationFilterTransformation(pixel=" + mPixel + ")";
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -16,15 +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.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;
|
||||||
|
|
||||||
@ -35,47 +33,46 @@ import jp.co.cyberagent.android.gpuimage.GPUImageSepiaFilter;
|
|||||||
*/
|
*/
|
||||||
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) {
|
public SepiaFilterTransformation(Context context) {
|
||||||
this(context, Glide.get(context).getBitmapPool());
|
this(context, Glide.get(context).getBitmapPool());
|
||||||
}
|
}
|
||||||
|
|
||||||
public SepiaFilterTransformation(Context context, BitmapPool pool) {
|
public SepiaFilterTransformation(Context context, BitmapPool pool) {
|
||||||
this(context, pool, 1.0f);
|
this(context, pool, 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SepiaFilterTransformation(Context context, float intensity) {
|
public SepiaFilterTransformation(Context context, float intensity) {
|
||||||
this(context, Glide.get(context).getBitmapPool(), intensity);
|
this(context, Glide.get(context).getBitmapPool(), intensity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SepiaFilterTransformation(Context context, BitmapPool pool, float intensity) {
|
public SepiaFilterTransformation(Context context, BitmapPool pool, float intensity) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mBitmapPool = pool;
|
mBitmapPool = pool;
|
||||||
mIntensity = intensity;
|
mIntensity = intensity;
|
||||||
mFilter.setIntensity(mIntensity);
|
mFilter.setIntensity(mIntensity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
||||||
Bitmap source = resource.get();
|
Bitmap source = resource.get();
|
||||||
|
|
||||||
GPUImage gpuImage = new GPUImage(mContext);
|
GPUImage gpuImage = new GPUImage(mContext);
|
||||||
gpuImage.setImage(source);
|
gpuImage.setImage(source);
|
||||||
gpuImage.setFilter(mFilter);
|
gpuImage.setFilter(mFilter);
|
||||||
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
||||||
|
|
||||||
source.recycle();
|
source.recycle();
|
||||||
|
|
||||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public String getId() {
|
||||||
public String getId() {
|
return "SepiaFilterTransformation(intensity=" + mIntensity + ")";
|
||||||
return "SepiaFilterTransformation(intensity=" + mIntensity + ")";
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -16,48 +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.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) {
|
public SketchFilterTransformation(Context context) {
|
||||||
this(context, Glide.get(context).getBitmapPool());
|
this(context, Glide.get(context).getBitmapPool());
|
||||||
}
|
}
|
||||||
|
|
||||||
public SketchFilterTransformation(Context context, BitmapPool pool) {
|
public SketchFilterTransformation(Context context, BitmapPool pool) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mBitmapPool = pool;
|
mBitmapPool = pool;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
||||||
Bitmap source = resource.get();
|
Bitmap source = resource.get();
|
||||||
|
|
||||||
GPUImage gpuImage = new GPUImage(mContext);
|
GPUImage gpuImage = new GPUImage(mContext);
|
||||||
gpuImage.setImage(source);
|
gpuImage.setImage(source);
|
||||||
gpuImage.setFilter(new GPUImageSketchFilter());
|
gpuImage.setFilter(new GPUImageSketchFilter());
|
||||||
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
||||||
|
|
||||||
source.recycle();
|
source.recycle();
|
||||||
|
|
||||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public String getId() {
|
||||||
public String getId() {
|
return "SketchFilterTransformation()";
|
||||||
return "SketchFilterTransformation()";
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -16,16 +16,14 @@ 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.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;
|
||||||
|
|
||||||
@ -34,61 +32,59 @@ import jp.co.cyberagent.android.gpuimage.GPUImageSwirlFilter;
|
|||||||
*/
|
*/
|
||||||
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) {
|
public SwirlFilterTransformation(Context context) {
|
||||||
this(context, Glide.get(context).getBitmapPool());
|
this(context, Glide.get(context).getBitmapPool());
|
||||||
}
|
}
|
||||||
|
|
||||||
public SwirlFilterTransformation(Context context, BitmapPool pool) {
|
public SwirlFilterTransformation(Context context, BitmapPool pool) {
|
||||||
this(context, pool, .5f, 1.0f, new PointF(0.5f, 0.5f));
|
this(context, pool, .5f, 1.0f, new PointF(0.5f, 0.5f));
|
||||||
}
|
}
|
||||||
|
|
||||||
public SwirlFilterTransformation(Context context,
|
public SwirlFilterTransformation(Context context, float radius, float angle, PointF center) {
|
||||||
float radius, float angle, PointF center) {
|
this(context, Glide.get(context).getBitmapPool(), radius, angle, center);
|
||||||
this(context, Glide.get(context).getBitmapPool(), radius, angle, center);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param radius from 0.0 to 1.0, default 0.5
|
* @param radius from 0.0 to 1.0, default 0.5
|
||||||
* @param angle minimum 0.0, default 1.0
|
* @param angle minimum 0.0, default 1.0
|
||||||
* @param center default (0.5, 0.5)
|
* @param center default (0.5, 0.5)
|
||||||
*/
|
*/
|
||||||
public SwirlFilterTransformation(Context context, BitmapPool pool,
|
public SwirlFilterTransformation(Context context, BitmapPool pool, float radius, float angle,
|
||||||
float radius, float angle, PointF center) {
|
PointF center) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mBitmapPool = pool;
|
mBitmapPool = pool;
|
||||||
mRadius = radius;
|
mRadius = radius;
|
||||||
mAngle = angle;
|
mAngle = angle;
|
||||||
mCenter = center;
|
mCenter = center;
|
||||||
mFilter.setRadius(mRadius);
|
mFilter.setRadius(mRadius);
|
||||||
mFilter.setAngle(mAngle);
|
mFilter.setAngle(mAngle);
|
||||||
mFilter.setCenter(mCenter);
|
mFilter.setCenter(mCenter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
||||||
Bitmap source = resource.get();
|
Bitmap source = resource.get();
|
||||||
|
|
||||||
GPUImage gpuImage = new GPUImage(mContext);
|
GPUImage gpuImage = new GPUImage(mContext);
|
||||||
gpuImage.setImage(source);
|
gpuImage.setImage(source);
|
||||||
gpuImage.setFilter(mFilter);
|
gpuImage.setFilter(mFilter);
|
||||||
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
||||||
|
|
||||||
source.recycle();
|
source.recycle();
|
||||||
|
|
||||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public String getId() {
|
||||||
public String getId() {
|
return "SwirlFilterTransformation(radius=" + mRadius +
|
||||||
return "SwirlFilterTransformation(radius=" + mRadius +
|
",angle=" + mAngle + ",center=" + mCenter.toString() + ")";
|
||||||
",angle=" + mAngle + ",center=" + mCenter.toString() + ")";
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -16,15 +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.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;
|
||||||
|
|
||||||
@ -35,52 +33,51 @@ import jp.co.cyberagent.android.gpuimage.GPUImageToonFilter;
|
|||||||
*/
|
*/
|
||||||
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) {
|
public ToonFilterTransformation(Context context) {
|
||||||
this(context, Glide.get(context).getBitmapPool());
|
this(context, Glide.get(context).getBitmapPool());
|
||||||
}
|
}
|
||||||
|
|
||||||
public ToonFilterTransformation(Context context, BitmapPool pool) {
|
public ToonFilterTransformation(Context context, BitmapPool pool) {
|
||||||
this(context, pool, .2f, 10.0f);
|
this(context, pool, .2f, 10.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ToonFilterTransformation(Context context, float threshold, float quantizationLevels) {
|
public ToonFilterTransformation(Context context, float threshold, float quantizationLevels) {
|
||||||
this(context, Glide.get(context).getBitmapPool(), threshold, quantizationLevels);
|
this(context, Glide.get(context).getBitmapPool(), threshold, quantizationLevels);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ToonFilterTransformation(Context context, BitmapPool pool,
|
public ToonFilterTransformation(Context context, BitmapPool pool, float threshold,
|
||||||
float threshold, float quantizationLevels) {
|
float quantizationLevels) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mBitmapPool = pool;
|
mBitmapPool = pool;
|
||||||
mThreshold = threshold;
|
mThreshold = threshold;
|
||||||
mQuantizationLevels = quantizationLevels;
|
mQuantizationLevels = quantizationLevels;
|
||||||
mFilter.setThreshold(mThreshold);
|
mFilter.setThreshold(mThreshold);
|
||||||
mFilter.setQuantizationLevels(mQuantizationLevels);
|
mFilter.setQuantizationLevels(mQuantizationLevels);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
||||||
Bitmap source = resource.get();
|
Bitmap source = resource.get();
|
||||||
|
|
||||||
GPUImage gpuImage = new GPUImage(mContext);
|
GPUImage gpuImage = new GPUImage(mContext);
|
||||||
gpuImage.setImage(source);
|
gpuImage.setImage(source);
|
||||||
gpuImage.setFilter(mFilter);
|
gpuImage.setFilter(mFilter);
|
||||||
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
||||||
|
|
||||||
source.recycle();
|
source.recycle();
|
||||||
|
|
||||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public String getId() {
|
||||||
public String getId() {
|
return "ToonFilterTransformation(threshold=" + mThreshold +
|
||||||
return "ToonFilterTransformation(threshold=" + mThreshold +
|
",quantizationLevels=" + mQuantizationLevels + ")";
|
||||||
",quantizationLevels=" + mQuantizationLevels + ")";
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -16,18 +16,15 @@ 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.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;
|
||||||
|
|
||||||
@ -38,60 +35,59 @@ import jp.co.cyberagent.android.gpuimage.GPUImageVignetteFilter;
|
|||||||
*/
|
*/
|
||||||
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) {
|
public VignetteFilterTransformation(Context context) {
|
||||||
this(context, Glide.get(context).getBitmapPool());
|
this(context, Glide.get(context).getBitmapPool());
|
||||||
}
|
}
|
||||||
|
|
||||||
public VignetteFilterTransformation(Context context, BitmapPool pool) {
|
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);
|
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,
|
public VignetteFilterTransformation(Context context, PointF center, float[] color, float start,
|
||||||
PointF center, float[] color, float start, float end) {
|
float end) {
|
||||||
this(context, Glide.get(context).getBitmapPool(), center, color, start, end);
|
this(context, Glide.get(context).getBitmapPool(), center, color, start, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
public VignetteFilterTransformation(Context context, BitmapPool pool,
|
public VignetteFilterTransformation(Context context, BitmapPool pool, PointF center,
|
||||||
PointF center, float[] color, float start, float end) {
|
float[] color, float start, float end) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mBitmapPool = pool;
|
mBitmapPool = pool;
|
||||||
mCenter = center;
|
mCenter = center;
|
||||||
mVignetteColor = color;
|
mVignetteColor = color;
|
||||||
mVignetteStart = start;
|
mVignetteStart = start;
|
||||||
mVignetteEnd = end;
|
mVignetteEnd = end;
|
||||||
mFilter.setVignetteCenter(mCenter);
|
mFilter.setVignetteCenter(mCenter);
|
||||||
mFilter.setVignetteColor(mVignetteColor);
|
mFilter.setVignetteColor(mVignetteColor);
|
||||||
mFilter.setVignetteStart(mVignetteStart);
|
mFilter.setVignetteStart(mVignetteStart);
|
||||||
mFilter.setVignetteEnd(mVignetteEnd);
|
mFilter.setVignetteEnd(mVignetteEnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
||||||
Bitmap source = resource.get();
|
Bitmap source = resource.get();
|
||||||
|
|
||||||
GPUImage gpuImage = new GPUImage(mContext);
|
GPUImage gpuImage = new GPUImage(mContext);
|
||||||
gpuImage.setImage(source);
|
gpuImage.setImage(source);
|
||||||
gpuImage.setFilter(mFilter);
|
gpuImage.setFilter(mFilter);
|
||||||
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
||||||
|
|
||||||
source.recycle();
|
source.recycle();
|
||||||
|
|
||||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public String getId() {
|
||||||
public String getId() {
|
return "VignetteFilterTransformation(center=" + mCenter.toString() +
|
||||||
return "VignetteFilterTransformation(center=" + mCenter.toString() +
|
",color=" + Arrays.toString(mVignetteColor) +
|
||||||
",color=" + Arrays.toString(mVignetteColor) +
|
",start=" + mVignetteStart + ",end=" + mVignetteEnd + ")";
|
||||||
",start=" + mVignetteStart + ",end=" + mVignetteEnd + ")";
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user