mirror of
https://github.com/wasabeef/glide-transformations.git
synced 2025-06-11 01:04:04 +08:00
refactor gpu transformations
This commit is contained in:
parent
36ceccb38e
commit
4a268b6dbd
@ -17,24 +17,15 @@ package jp.wasabeef.glide.transformations.gpu;
|
||||
*/
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.Transformation;
|
||||
import com.bumptech.glide.load.engine.Resource;
|
||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImage;
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImageBrightnessFilter;
|
||||
|
||||
/**
|
||||
* brightness value ranges from -1.0 to 1.0, with 0.0 as the normal level
|
||||
*/
|
||||
public class BrightnessFilterTransformation implements Transformation<Bitmap> {
|
||||
public class BrightnessFilterTransformation extends GPUFilterTransformation {
|
||||
|
||||
private Context mContext;
|
||||
private BitmapPool mBitmapPool;
|
||||
|
||||
private GPUImageBrightnessFilter mFilter = new GPUImageBrightnessFilter();
|
||||
private float mBrightness;
|
||||
|
||||
public BrightnessFilterTransformation(Context context) {
|
||||
@ -50,24 +41,10 @@ public class BrightnessFilterTransformation implements Transformation<Bitmap> {
|
||||
}
|
||||
|
||||
public BrightnessFilterTransformation(Context context, BitmapPool pool, float brightness) {
|
||||
mContext = context;
|
||||
mBitmapPool = pool;
|
||||
super(context, pool, new GPUImageBrightnessFilter());
|
||||
mBrightness = brightness;
|
||||
mFilter.setBrightness(mBrightness);
|
||||
}
|
||||
|
||||
@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);
|
||||
GPUImageBrightnessFilter filter = getFilter();
|
||||
filter.setBrightness(mBrightness);
|
||||
}
|
||||
|
||||
@Override public String getId() {
|
||||
|
@ -17,24 +17,15 @@ package jp.wasabeef.glide.transformations.gpu;
|
||||
*/
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.Transformation;
|
||||
import com.bumptech.glide.load.engine.Resource;
|
||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImage;
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImageContrastFilter;
|
||||
|
||||
/**
|
||||
* contrast value ranges from 0.0 to 4.0, with 1.0 as the normal level
|
||||
*/
|
||||
public class ContrastFilterTransformation implements Transformation<Bitmap> {
|
||||
public class ContrastFilterTransformation extends GPUFilterTransformation {
|
||||
|
||||
private Context mContext;
|
||||
private BitmapPool mBitmapPool;
|
||||
|
||||
private GPUImageContrastFilter mFilter = new GPUImageContrastFilter();
|
||||
private float mContrast;
|
||||
|
||||
public ContrastFilterTransformation(Context context) {
|
||||
@ -50,24 +41,10 @@ public class ContrastFilterTransformation implements Transformation<Bitmap> {
|
||||
}
|
||||
|
||||
public ContrastFilterTransformation(Context context, BitmapPool pool, float contrast) {
|
||||
mContext = context;
|
||||
mBitmapPool = pool;
|
||||
super(context, pool, new GPUImageContrastFilter());
|
||||
mContrast = contrast;
|
||||
mFilter.setContrast(mContrast);
|
||||
}
|
||||
|
||||
@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);
|
||||
GPUImageContrastFilter filter = getFilter();
|
||||
filter.setContrast(mContrast);
|
||||
}
|
||||
|
||||
@Override public String getId() {
|
||||
|
@ -0,0 +1,65 @@
|
||||
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 android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.Transformation;
|
||||
import com.bumptech.glide.load.engine.Resource;
|
||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImage;
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImageFilter;
|
||||
|
||||
public class GPUFilterTransformation implements Transformation<Bitmap> {
|
||||
|
||||
private Context mContext;
|
||||
private BitmapPool mBitmapPool;
|
||||
|
||||
private GPUImageFilter mFilter;
|
||||
|
||||
public GPUFilterTransformation(Context context, GPUImageFilter filter) {
|
||||
this(context, Glide.get(context).getBitmapPool(), filter);
|
||||
}
|
||||
|
||||
public GPUFilterTransformation(Context context, BitmapPool pool, GPUImageFilter filter) {
|
||||
mContext = context.getApplicationContext();
|
||||
mBitmapPool = pool;
|
||||
mFilter = filter;
|
||||
}
|
||||
|
||||
@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();
|
||||
|
||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||
}
|
||||
|
||||
@Override public String getId() {
|
||||
return getClass().getSimpleName();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked") public <T> T getFilter() {
|
||||
return (T) mFilter;
|
||||
}
|
||||
}
|
@ -17,44 +17,21 @@ package jp.wasabeef.glide.transformations.gpu;
|
||||
*/
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.Transformation;
|
||||
import com.bumptech.glide.load.engine.Resource;
|
||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImage;
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImageColorInvertFilter;
|
||||
|
||||
/**
|
||||
* Invert all the colors in the image.
|
||||
*/
|
||||
public class InvertFilterTransformation implements Transformation<Bitmap> {
|
||||
|
||||
private Context mContext;
|
||||
private BitmapPool mBitmapPool;
|
||||
public class InvertFilterTransformation extends GPUFilterTransformation {
|
||||
|
||||
public InvertFilterTransformation(Context context) {
|
||||
this(context, Glide.get(context).getBitmapPool());
|
||||
}
|
||||
|
||||
public InvertFilterTransformation(Context context, BitmapPool pool) {
|
||||
mContext = context;
|
||||
mBitmapPool = pool;
|
||||
}
|
||||
|
||||
@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(new GPUImageColorInvertFilter());
|
||||
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
||||
|
||||
source.recycle();
|
||||
|
||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||
super(context, pool, new GPUImageColorInvertFilter());
|
||||
}
|
||||
|
||||
@Override public String getId() {
|
||||
|
@ -17,13 +17,8 @@ package jp.wasabeef.glide.transformations.gpu;
|
||||
*/
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.Transformation;
|
||||
import com.bumptech.glide.load.engine.Resource;
|
||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImage;
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImageKuwaharaFilter;
|
||||
|
||||
/**
|
||||
@ -32,12 +27,8 @@ import jp.co.cyberagent.android.gpuimage.GPUImageKuwaharaFilter;
|
||||
* The radius to sample from when creating the brush-stroke effect, with a default of 25.
|
||||
* The larger the radius, the slower the filter.
|
||||
*/
|
||||
public class KuwaharaFilterTransformation implements Transformation<Bitmap> {
|
||||
public class KuwaharaFilterTransformation extends GPUFilterTransformation {
|
||||
|
||||
private Context mContext;
|
||||
private BitmapPool mBitmapPool;
|
||||
|
||||
private GPUImageKuwaharaFilter mFilter = new GPUImageKuwaharaFilter();
|
||||
private int mRadius;
|
||||
|
||||
public KuwaharaFilterTransformation(Context context) {
|
||||
@ -53,24 +44,10 @@ public class KuwaharaFilterTransformation implements Transformation<Bitmap> {
|
||||
}
|
||||
|
||||
public KuwaharaFilterTransformation(Context context, BitmapPool pool, int radius) {
|
||||
mContext = context;
|
||||
mBitmapPool = pool;
|
||||
super(context, pool, new GPUImageKuwaharaFilter());
|
||||
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);
|
||||
GPUImageKuwaharaFilter filter = getFilter();
|
||||
filter.setRadius(mRadius);
|
||||
}
|
||||
|
||||
@Override public String getId() {
|
||||
|
@ -17,13 +17,8 @@ package jp.wasabeef.glide.transformations.gpu;
|
||||
*/
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.Transformation;
|
||||
import com.bumptech.glide.load.engine.Resource;
|
||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImage;
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImagePixelationFilter;
|
||||
|
||||
/**
|
||||
@ -31,12 +26,8 @@ import jp.co.cyberagent.android.gpuimage.GPUImagePixelationFilter;
|
||||
*
|
||||
* The pixel with a default of 10.0.
|
||||
*/
|
||||
public class PixelationFilterTransformation implements Transformation<Bitmap> {
|
||||
public class PixelationFilterTransformation extends GPUFilterTransformation {
|
||||
|
||||
private Context mContext;
|
||||
private BitmapPool mBitmapPool;
|
||||
|
||||
private GPUImagePixelationFilter mFilter = new GPUImagePixelationFilter();
|
||||
private float mPixel;
|
||||
|
||||
public PixelationFilterTransformation(Context context) {
|
||||
@ -52,24 +43,10 @@ public class PixelationFilterTransformation implements Transformation<Bitmap> {
|
||||
}
|
||||
|
||||
public PixelationFilterTransformation(Context context, BitmapPool pool, float pixel) {
|
||||
mContext = context;
|
||||
mBitmapPool = pool;
|
||||
super(context, pool, new GPUImagePixelationFilter());
|
||||
mPixel = pixel;
|
||||
mFilter.setPixel(mPixel);
|
||||
}
|
||||
|
||||
@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);
|
||||
GPUImagePixelationFilter filter = getFilter();
|
||||
filter.setPixel(mPixel);
|
||||
}
|
||||
|
||||
@Override public String getId() {
|
||||
|
@ -17,13 +17,8 @@ package jp.wasabeef.glide.transformations.gpu;
|
||||
*/
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.Transformation;
|
||||
import com.bumptech.glide.load.engine.Resource;
|
||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImage;
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImageSepiaFilter;
|
||||
|
||||
/**
|
||||
@ -31,12 +26,8 @@ import jp.co.cyberagent.android.gpuimage.GPUImageSepiaFilter;
|
||||
*
|
||||
* The intensity with a default of 1.0.
|
||||
*/
|
||||
public class SepiaFilterTransformation implements Transformation<Bitmap> {
|
||||
public class SepiaFilterTransformation extends GPUFilterTransformation {
|
||||
|
||||
private Context mContext;
|
||||
private BitmapPool mBitmapPool;
|
||||
|
||||
private GPUImageSepiaFilter mFilter = new GPUImageSepiaFilter();
|
||||
private float mIntensity;
|
||||
|
||||
public SepiaFilterTransformation(Context context) {
|
||||
@ -52,24 +43,10 @@ public class SepiaFilterTransformation implements Transformation<Bitmap> {
|
||||
}
|
||||
|
||||
public SepiaFilterTransformation(Context context, BitmapPool pool, float intensity) {
|
||||
mContext = context;
|
||||
mBitmapPool = pool;
|
||||
super(context, pool, new GPUImageSepiaFilter());
|
||||
mIntensity = intensity;
|
||||
mFilter.setIntensity(mIntensity);
|
||||
}
|
||||
|
||||
@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);
|
||||
GPUImageSepiaFilter filter = getFilter();
|
||||
filter.setIntensity(mIntensity);
|
||||
}
|
||||
|
||||
@Override public String getId() {
|
||||
|
@ -17,41 +17,18 @@ package jp.wasabeef.glide.transformations.gpu;
|
||||
*/
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.Transformation;
|
||||
import com.bumptech.glide.load.engine.Resource;
|
||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImage;
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImageSketchFilter;
|
||||
|
||||
public class SketchFilterTransformation implements Transformation<Bitmap> {
|
||||
|
||||
private Context mContext;
|
||||
private BitmapPool mBitmapPool;
|
||||
public class SketchFilterTransformation extends GPUFilterTransformation {
|
||||
|
||||
public SketchFilterTransformation(Context context) {
|
||||
this(context, Glide.get(context).getBitmapPool());
|
||||
}
|
||||
|
||||
public SketchFilterTransformation(Context context, BitmapPool pool) {
|
||||
mContext = context;
|
||||
mBitmapPool = pool;
|
||||
}
|
||||
|
||||
@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(new GPUImageSketchFilter());
|
||||
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
||||
|
||||
source.recycle();
|
||||
|
||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||
super(context, pool, new GPUImageSketchFilter());
|
||||
}
|
||||
|
||||
@Override public String getId() {
|
||||
|
@ -17,25 +17,16 @@ package jp.wasabeef.glide.transformations.gpu;
|
||||
*/
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.PointF;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.Transformation;
|
||||
import com.bumptech.glide.load.engine.Resource;
|
||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImage;
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImageSwirlFilter;
|
||||
|
||||
/**
|
||||
* Creates a swirl distortion on the image.
|
||||
*/
|
||||
public class SwirlFilterTransformation implements Transformation<Bitmap> {
|
||||
public class SwirlFilterTransformation extends GPUFilterTransformation {
|
||||
|
||||
private Context mContext;
|
||||
private BitmapPool mBitmapPool;
|
||||
|
||||
private GPUImageSwirlFilter mFilter = new GPUImageSwirlFilter();
|
||||
private float mRadius;
|
||||
private float mAngle;
|
||||
private PointF mCenter;
|
||||
@ -59,28 +50,14 @@ public class SwirlFilterTransformation implements Transformation<Bitmap> {
|
||||
*/
|
||||
public SwirlFilterTransformation(Context context, BitmapPool pool, float radius, float angle,
|
||||
PointF center) {
|
||||
mContext = context;
|
||||
mBitmapPool = pool;
|
||||
super(context, pool, new GPUImageSwirlFilter());
|
||||
mRadius = radius;
|
||||
mAngle = angle;
|
||||
mCenter = center;
|
||||
mFilter.setRadius(mRadius);
|
||||
mFilter.setAngle(mAngle);
|
||||
mFilter.setCenter(mCenter);
|
||||
}
|
||||
|
||||
@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);
|
||||
GPUImageSwirlFilter filter = getFilter();
|
||||
filter.setRadius(mRadius);
|
||||
filter.setAngle(mAngle);
|
||||
filter.setCenter(mCenter);
|
||||
}
|
||||
|
||||
@Override public String getId() {
|
||||
|
@ -17,13 +17,8 @@ package jp.wasabeef.glide.transformations.gpu;
|
||||
*/
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.Transformation;
|
||||
import com.bumptech.glide.load.engine.Resource;
|
||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImage;
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImageToonFilter;
|
||||
|
||||
/**
|
||||
@ -31,12 +26,8 @@ import jp.co.cyberagent.android.gpuimage.GPUImageToonFilter;
|
||||
* The levels of quantization for the posterization of colors within the scene,
|
||||
* with a default of 10.0.
|
||||
*/
|
||||
public class ToonFilterTransformation implements Transformation<Bitmap> {
|
||||
public class ToonFilterTransformation extends GPUFilterTransformation {
|
||||
|
||||
private Context mContext;
|
||||
private BitmapPool mBitmapPool;
|
||||
|
||||
private GPUImageToonFilter mFilter = new GPUImageToonFilter();
|
||||
private float mThreshold;
|
||||
private float mQuantizationLevels;
|
||||
|
||||
@ -54,26 +45,12 @@ public class ToonFilterTransformation implements Transformation<Bitmap> {
|
||||
|
||||
public ToonFilterTransformation(Context context, BitmapPool pool, float threshold,
|
||||
float quantizationLevels) {
|
||||
mContext = context;
|
||||
mBitmapPool = pool;
|
||||
super(context, pool, new GPUImageToonFilter());
|
||||
mThreshold = threshold;
|
||||
mQuantizationLevels = quantizationLevels;
|
||||
mFilter.setThreshold(mThreshold);
|
||||
mFilter.setQuantizationLevels(mQuantizationLevels);
|
||||
}
|
||||
|
||||
@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);
|
||||
GPUImageToonFilter filter = getFilter();
|
||||
filter.setThreshold(mThreshold);
|
||||
filter.setQuantizationLevels(mQuantizationLevels);
|
||||
}
|
||||
|
||||
@Override public String getId() {
|
||||
|
@ -17,15 +17,10 @@ package jp.wasabeef.glide.transformations.gpu;
|
||||
*/
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.PointF;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.Transformation;
|
||||
import com.bumptech.glide.load.engine.Resource;
|
||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
|
||||
import java.util.Arrays;
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImage;
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImageVignetteFilter;
|
||||
|
||||
/**
|
||||
@ -33,12 +28,8 @@ import jp.co.cyberagent.android.gpuimage.GPUImageVignetteFilter;
|
||||
* The directional intensity of the vignetting,
|
||||
* with a default of x = 0.5, y = 0.5, start = 0, end = 0.75
|
||||
*/
|
||||
public class VignetteFilterTransformation implements Transformation<Bitmap> {
|
||||
public class VignetteFilterTransformation extends GPUFilterTransformation {
|
||||
|
||||
private Context mContext;
|
||||
private BitmapPool mBitmapPool;
|
||||
|
||||
private GPUImageVignetteFilter mFilter = new GPUImageVignetteFilter();
|
||||
private PointF mCenter;
|
||||
private float[] mVignetteColor;
|
||||
private float mVignetteStart;
|
||||
@ -59,30 +50,16 @@ public class VignetteFilterTransformation implements Transformation<Bitmap> {
|
||||
|
||||
public VignetteFilterTransformation(Context context, BitmapPool pool, PointF center,
|
||||
float[] color, float start, float end) {
|
||||
mContext = context;
|
||||
mBitmapPool = pool;
|
||||
super(context, pool, new GPUImageVignetteFilter());
|
||||
mCenter = center;
|
||||
mVignetteColor = color;
|
||||
mVignetteStart = start;
|
||||
mVignetteEnd = end;
|
||||
mFilter.setVignetteCenter(mCenter);
|
||||
mFilter.setVignetteColor(mVignetteColor);
|
||||
mFilter.setVignetteStart(mVignetteStart);
|
||||
mFilter.setVignetteEnd(mVignetteEnd);
|
||||
}
|
||||
|
||||
@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);
|
||||
GPUImageVignetteFilter filter = getFilter();
|
||||
filter.setVignetteCenter(mCenter);
|
||||
filter.setVignetteColor(mVignetteColor);
|
||||
filter.setVignetteStart(mVignetteStart);
|
||||
filter.setVignetteEnd(mVignetteEnd);
|
||||
}
|
||||
|
||||
@Override public String getId() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user