mirror of
https://github.com/wasabeef/glide-transformations.git
synced 2025-06-09 16:14:09 +08:00
Refactor
This commit is contained in:
parent
f839029adb
commit
a330118112
@ -35,6 +35,7 @@ public class BrightnessFilterTransformation implements Transformation<Bitmap> {
|
|||||||
private Context mContext;
|
private Context mContext;
|
||||||
private BitmapPool mBitmapPool;
|
private BitmapPool mBitmapPool;
|
||||||
|
|
||||||
|
private GPUImageBrightnessFilter mFilter = new GPUImageBrightnessFilter();
|
||||||
private float mBrightness;
|
private float mBrightness;
|
||||||
|
|
||||||
public BrightnessFilterTransformation(Context context, BitmapPool pool) {
|
public BrightnessFilterTransformation(Context context, BitmapPool pool) {
|
||||||
@ -46,6 +47,7 @@ public class BrightnessFilterTransformation implements Transformation<Bitmap> {
|
|||||||
mContext = context;
|
mContext = context;
|
||||||
mBitmapPool = pool;
|
mBitmapPool = pool;
|
||||||
mBrightness = brightness;
|
mBrightness = brightness;
|
||||||
|
mFilter.setBrightness(mBrightness);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -54,12 +56,7 @@ public class BrightnessFilterTransformation implements Transformation<Bitmap> {
|
|||||||
|
|
||||||
GPUImage gpuImage = new GPUImage(mContext);
|
GPUImage gpuImage = new GPUImage(mContext);
|
||||||
gpuImage.setImage(source);
|
gpuImage.setImage(source);
|
||||||
GPUImageBrightnessFilter filter = new GPUImageBrightnessFilter();
|
gpuImage.setFilter(mFilter);
|
||||||
if (mBrightness != 0) {
|
|
||||||
filter.setBrightness(mBrightness);
|
|
||||||
}
|
|
||||||
|
|
||||||
gpuImage.setFilter(filter);
|
|
||||||
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
||||||
|
|
||||||
source.recycle();
|
source.recycle();
|
||||||
|
@ -35,6 +35,7 @@ public class ContrastFilterTransformation implements Transformation<Bitmap> {
|
|||||||
private Context mContext;
|
private Context mContext;
|
||||||
private BitmapPool mBitmapPool;
|
private BitmapPool mBitmapPool;
|
||||||
|
|
||||||
|
private GPUImageContrastFilter mFilter = new GPUImageContrastFilter();
|
||||||
private float mContrast;
|
private float mContrast;
|
||||||
|
|
||||||
public ContrastFilterTransformation(Context context, BitmapPool pool) {
|
public ContrastFilterTransformation(Context context, BitmapPool pool) {
|
||||||
@ -46,6 +47,7 @@ public class ContrastFilterTransformation implements Transformation<Bitmap> {
|
|||||||
mContext = context;
|
mContext = context;
|
||||||
mBitmapPool = pool;
|
mBitmapPool = pool;
|
||||||
mContrast = contrast;
|
mContrast = contrast;
|
||||||
|
mFilter.setContrast(mContrast);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -54,12 +56,7 @@ public class ContrastFilterTransformation implements Transformation<Bitmap> {
|
|||||||
|
|
||||||
GPUImage gpuImage = new GPUImage(mContext);
|
GPUImage gpuImage = new GPUImage(mContext);
|
||||||
gpuImage.setImage(source);
|
gpuImage.setImage(source);
|
||||||
GPUImageContrastFilter filter = new GPUImageContrastFilter();
|
gpuImage.setFilter(mFilter);
|
||||||
if (mContrast != 0) {
|
|
||||||
filter.setContrast(mContrast);
|
|
||||||
}
|
|
||||||
|
|
||||||
gpuImage.setFilter(filter);
|
|
||||||
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
||||||
|
|
||||||
source.recycle();
|
source.recycle();
|
||||||
|
@ -32,6 +32,7 @@ public class PixelationFilterTransformation implements Transformation<Bitmap> {
|
|||||||
private Context mContext;
|
private Context mContext;
|
||||||
private BitmapPool mBitmapPool;
|
private BitmapPool mBitmapPool;
|
||||||
|
|
||||||
|
private GPUImagePixelationFilter mFilter = new GPUImagePixelationFilter();
|
||||||
private float mPixel;
|
private float mPixel;
|
||||||
|
|
||||||
public PixelationFilterTransformation(Context context, BitmapPool pool) {
|
public PixelationFilterTransformation(Context context, BitmapPool pool) {
|
||||||
@ -43,6 +44,7 @@ public class PixelationFilterTransformation implements Transformation<Bitmap> {
|
|||||||
mContext = context;
|
mContext = context;
|
||||||
mBitmapPool = pool;
|
mBitmapPool = pool;
|
||||||
mPixel = pixel;
|
mPixel = pixel;
|
||||||
|
mFilter.setPixel(mPixel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -51,12 +53,7 @@ public class PixelationFilterTransformation implements Transformation<Bitmap> {
|
|||||||
|
|
||||||
GPUImage gpuImage = new GPUImage(mContext);
|
GPUImage gpuImage = new GPUImage(mContext);
|
||||||
gpuImage.setImage(source);
|
gpuImage.setImage(source);
|
||||||
GPUImagePixelationFilter filter = new GPUImagePixelationFilter();
|
gpuImage.setFilter(mFilter);
|
||||||
if (mPixel != 0) {
|
|
||||||
filter.setPixel(mPixel);
|
|
||||||
}
|
|
||||||
|
|
||||||
gpuImage.setFilter(filter);
|
|
||||||
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
||||||
|
|
||||||
source.recycle();
|
source.recycle();
|
||||||
|
@ -32,6 +32,7 @@ public class SepiaFilterTransformation implements Transformation<Bitmap> {
|
|||||||
private Context mContext;
|
private Context mContext;
|
||||||
private BitmapPool mBitmapPool;
|
private BitmapPool mBitmapPool;
|
||||||
|
|
||||||
|
private GPUImageSepiaFilter mFilter = new GPUImageSepiaFilter();
|
||||||
private float mIntensity;
|
private float mIntensity;
|
||||||
|
|
||||||
public SepiaFilterTransformation(Context context, BitmapPool pool) {
|
public SepiaFilterTransformation(Context context, BitmapPool pool) {
|
||||||
@ -43,6 +44,7 @@ public class SepiaFilterTransformation implements Transformation<Bitmap> {
|
|||||||
mContext = context;
|
mContext = context;
|
||||||
mBitmapPool = pool;
|
mBitmapPool = pool;
|
||||||
mIntensity = intensity;
|
mIntensity = intensity;
|
||||||
|
mFilter.setIntensity(mIntensity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -51,12 +53,7 @@ public class SepiaFilterTransformation implements Transformation<Bitmap> {
|
|||||||
|
|
||||||
GPUImage gpuImage = new GPUImage(mContext);
|
GPUImage gpuImage = new GPUImage(mContext);
|
||||||
gpuImage.setImage(source);
|
gpuImage.setImage(source);
|
||||||
GPUImageSepiaFilter filter = new GPUImageSepiaFilter();
|
gpuImage.setFilter(mFilter);
|
||||||
if (mIntensity != 0) {
|
|
||||||
filter.setIntensity(mIntensity);
|
|
||||||
}
|
|
||||||
|
|
||||||
gpuImage.setFilter(filter);
|
|
||||||
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
||||||
|
|
||||||
source.recycle();
|
source.recycle();
|
||||||
|
@ -33,6 +33,7 @@ public class SwirlFilterTransformation implements Transformation<Bitmap> {
|
|||||||
private Context mContext;
|
private Context mContext;
|
||||||
private BitmapPool mBitmapPool;
|
private BitmapPool mBitmapPool;
|
||||||
|
|
||||||
|
private GPUImageSwirlFilter mFilter = new GPUImageSwirlFilter();
|
||||||
private float mRadius;
|
private float mRadius;
|
||||||
private float mAngle;
|
private float mAngle;
|
||||||
private PointF mCenter;
|
private PointF mCenter;
|
||||||
@ -54,6 +55,9 @@ public class SwirlFilterTransformation implements Transformation<Bitmap> {
|
|||||||
mRadius = radius;
|
mRadius = radius;
|
||||||
mAngle = angle;
|
mAngle = angle;
|
||||||
mCenter = center;
|
mCenter = center;
|
||||||
|
mFilter.setRadius(mRadius);
|
||||||
|
mFilter.setAngle(mAngle);
|
||||||
|
mFilter.setCenter(mCenter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -62,18 +66,7 @@ public class SwirlFilterTransformation implements Transformation<Bitmap> {
|
|||||||
|
|
||||||
GPUImage gpuImage = new GPUImage(mContext);
|
GPUImage gpuImage = new GPUImage(mContext);
|
||||||
gpuImage.setImage(source);
|
gpuImage.setImage(source);
|
||||||
GPUImageSwirlFilter filter = new GPUImageSwirlFilter();
|
gpuImage.setFilter(mFilter);
|
||||||
if (mRadius != 0) {
|
|
||||||
filter.setRadius(mRadius);
|
|
||||||
}
|
|
||||||
if (mAngle != 0) {
|
|
||||||
filter.setAngle(mAngle);
|
|
||||||
}
|
|
||||||
if (mCenter != null) {
|
|
||||||
filter.setCenter(mCenter);
|
|
||||||
}
|
|
||||||
|
|
||||||
gpuImage.setFilter(filter);
|
|
||||||
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
||||||
|
|
||||||
source.recycle();
|
source.recycle();
|
||||||
|
@ -32,6 +32,7 @@ public class ToonFilterTransformation implements Transformation<Bitmap> {
|
|||||||
private Context mContext;
|
private Context mContext;
|
||||||
private BitmapPool mBitmapPool;
|
private BitmapPool mBitmapPool;
|
||||||
|
|
||||||
|
private GPUImageToonFilter mFilter = new GPUImageToonFilter();
|
||||||
private float mThreshold;
|
private float mThreshold;
|
||||||
private float mQuantizationLevels;
|
private float mQuantizationLevels;
|
||||||
|
|
||||||
@ -46,6 +47,8 @@ public class ToonFilterTransformation implements Transformation<Bitmap> {
|
|||||||
mBitmapPool = pool;
|
mBitmapPool = pool;
|
||||||
mThreshold = threshold;
|
mThreshold = threshold;
|
||||||
mQuantizationLevels = quantizationLevels;
|
mQuantizationLevels = quantizationLevels;
|
||||||
|
mFilter.setThreshold(mThreshold);
|
||||||
|
mFilter.setQuantizationLevels(mQuantizationLevels);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -54,15 +57,7 @@ public class ToonFilterTransformation implements Transformation<Bitmap> {
|
|||||||
|
|
||||||
GPUImage gpuImage = new GPUImage(mContext);
|
GPUImage gpuImage = new GPUImage(mContext);
|
||||||
gpuImage.setImage(source);
|
gpuImage.setImage(source);
|
||||||
GPUImageToonFilter filter = new GPUImageToonFilter();
|
gpuImage.setFilter(mFilter);
|
||||||
if (mThreshold != 0) {
|
|
||||||
filter.setThreshold(mThreshold);
|
|
||||||
}
|
|
||||||
if (mQuantizationLevels != 0) {
|
|
||||||
filter.setQuantizationLevels(mQuantizationLevels);
|
|
||||||
}
|
|
||||||
|
|
||||||
gpuImage.setFilter(filter);
|
|
||||||
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
|
||||||
|
|
||||||
source.recycle();
|
source.recycle();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user