1
0
mirror of https://github.com/wasabeef/glide-transformations.git synced 2025-06-08 15:34:04 +08:00

add Kuwahara

This commit is contained in:
wasabeef 2015-01-12 21:36:55 +09:00
parent d9b3fa890c
commit 5c8051acff
4 changed files with 80 additions and 2 deletions

View File

@ -65,7 +65,7 @@ Glide.with(this).load(R.drawable.demo).bitmapTransform(
### Filter (use GPUImage) ### Filter (use GPUImage)
`ToonFilterTransformation`, `SepiaFilterTransformation`, `ContrastFilterTransformation` `ToonFilterTransformation`, `SepiaFilterTransformation`, `ContrastFilterTransformation`
`InvertFilterTransformation`, `PixelationFilterTransformation`, `SketchFilterTransformation` `InvertFilterTransformation`, `PixelationFilterTransformation`, `SketchFilterTransformation`
`SwirlFilterTransformation` `SwirlFilterTransformation`, `KuwaharaFilterTransformation`
### Other ### Other
`RoundedCornersTransformation` `RoundedCornersTransformation`

View File

@ -37,6 +37,7 @@ public class MainActivity extends ActionBarActivity {
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);
recyclerView.setAdapter(new MainAdapter(this, dataSet)); recyclerView.setAdapter(new MainAdapter(this, dataSet));
} }

View File

@ -27,6 +27,7 @@ import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
import jp.wasabeef.glide.transformations.gpu.BrightnessFilterTransformation; import jp.wasabeef.glide.transformations.gpu.BrightnessFilterTransformation;
import jp.wasabeef.glide.transformations.gpu.ContrastFilterTransformation; import jp.wasabeef.glide.transformations.gpu.ContrastFilterTransformation;
import jp.wasabeef.glide.transformations.gpu.InvertFilterTransformation; import jp.wasabeef.glide.transformations.gpu.InvertFilterTransformation;
import jp.wasabeef.glide.transformations.gpu.KuwaharaFilterTransformation;
import jp.wasabeef.glide.transformations.gpu.PixelationFilterTransformation; import jp.wasabeef.glide.transformations.gpu.PixelationFilterTransformation;
import jp.wasabeef.glide.transformations.gpu.SepiaFilterTransformation; import jp.wasabeef.glide.transformations.gpu.SepiaFilterTransformation;
import jp.wasabeef.glide.transformations.gpu.SketchFilterTransformation; import jp.wasabeef.glide.transformations.gpu.SketchFilterTransformation;
@ -57,7 +58,8 @@ public class MainAdapter extends RecyclerView.Adapter<MainAdapter.ViewHolder> {
Pixel, Pixel,
Sketch, Sketch,
Swirl, Swirl,
Brightness Brightness,
Kuawahara
} }
public MainAdapter(Context context, List<Type> dataSet) { public MainAdapter(Context context, List<Type> dataSet) {
@ -123,6 +125,9 @@ public class MainAdapter extends RecyclerView.Adapter<MainAdapter.ViewHolder> {
case Brightness: case Brightness:
transformation = new BrightnessFilterTransformation(mContext, mPool, 0.5f); transformation = new BrightnessFilterTransformation(mContext, mPool, 0.5f);
break; break;
case Kuawahara:
transformation = new KuwaharaFilterTransformation(mContext, mPool, 25);
break;
} }
Glide.with(mContext).load(R.drawable.demo) Glide.with(mContext).load(R.drawable.demo)

View File

@ -0,0 +1,72 @@
package jp.wasabeef.glide.transformations.gpu;
/**
* Copyright (C) 2015 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import com.bumptech.glide.load.Transformation;
import com.bumptech.glide.load.engine.Resource;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
import android.content.Context;
import android.graphics.Bitmap;
import jp.co.cyberagent.android.gpuimage.GPUImage;
import jp.co.cyberagent.android.gpuimage.GPUImageKuwaharaFilter;
/**
* The radius to sample from when creating the brush-stroke effect, with a default of 3.
* The larger the radius, the slower the filter.
*/
public class KuwaharaFilterTransformation implements Transformation<Bitmap> {
private Context mContext;
private BitmapPool mBitmapPool;
private GPUImageKuwaharaFilter mFilter = new GPUImageKuwaharaFilter();
private int mRadius;
public KuwaharaFilterTransformation(Context context, BitmapPool pool) {
mContext = context;
mBitmapPool = pool;
}
public KuwaharaFilterTransformation(Context context, BitmapPool pool, int radius) {
mContext = context;
mBitmapPool = pool;
mRadius = radius;
mFilter.setRadius(mRadius);
}
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
Bitmap source = resource.get();
GPUImage gpuImage = new GPUImage(mContext);
gpuImage.setImage(source);
gpuImage.setFilter(mFilter);
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
source.recycle();
return BitmapResource.obtain(bitmap, mBitmapPool);
}
@Override
public String getId() {
return "KuwaharaFilterTransformation(radius=" + mRadius + ")";
}
}