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