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

Support Glide 4.0.0 (#83)

This commit is contained in:
Daichi Furiya 2017-09-07 00:47:27 -05:00 committed by GitHub
parent 1264e01f6e
commit f6cbe2722d
29 changed files with 495 additions and 689 deletions

View File

@ -1,6 +1,17 @@
Change Log Change Log
========== ==========
Version 3.0.0 *(2017-09-06)*
----------------------------
Update:
- Build Tools 25.0.2 -> 26.0.1
- Min SDK Version 11 -> 14
- Glide 3.7.0 -> 4.0.0
Feature:
- Supported Glide 4.0.0
Version 2.0.2 *(2017-03-17)* Version 2.0.2 *(2017-03-17)*
---------------------------- ----------------------------

View File

@ -32,7 +32,7 @@ repositories {
} }
dependencies { dependencies {
compile 'jp.wasabeef:glide-transformations:2.0.2' compile 'jp.wasabeef:glide-transformations:3.0.0'
// If you want to use the GPU Filters // If you want to use the GPU Filters
compile 'jp.co.cyberagent.android.gpuimage:gpuimage-library:1.4.1' compile 'jp.co.cyberagent.android.gpuimage:gpuimage-library:1.4.1'
} }
@ -44,7 +44,7 @@ Set Glide Transform.
```java ```java
Glide.with(this).load(R.drawable.demo) Glide.with(this).load(R.drawable.demo)
.bitmapTransform(new BlurTransformation(context)) .apply(bitmapTransform(new BlurTransformation(25)))
.into((ImageView) findViewById(R.id.image)); .into((ImageView) findViewById(R.id.image));
``` ```
@ -53,8 +53,11 @@ Glide.with(this).load(R.drawable.demo)
You can set a multiple transformations. You can set a multiple transformations.
```java ```java
MultiTransformation multi = new MultiTransformation(
new BlurTransformation(25),
new RoundedCornersTransformation(128, 0, RoundedCornersTransformation.CornerType.BOTTOM))))
Glide.with(this).load(R.drawable.demo) Glide.with(this).load(R.drawable.demo)
.bitmapTransform(new BlurTransformation(context, 25), new CropCircleTransformation(context)) .apply(bitmapTransform(multi))
.into((ImageView) findViewById(R.id.image)); .into((ImageView) findViewById(R.id.image));
``` ```

View File

@ -5,7 +5,7 @@ buildscript {
jcenter() jcenter()
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:2.3.0' classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.novoda:bintray-release:0.3.4' classpath 'com.novoda:bintray-release:0.3.4'
} }
} }

View File

@ -52,6 +52,7 @@ def getKeyAliasPasswordProperty() {
dependencies { dependencies {
compile project(':transformations') compile project(':transformations')
compile "com.github.bumptech.glide:glide:${GLIDE_VERSION}" compile "com.github.bumptech.glide:glide:${GLIDE_VERSION}"
annotationProcessor "com.github.bumptech.glide:compiler:${GLIDE_VERSION}"
compile "jp.co.cyberagent.android.gpuimage:gpuimage-library:${GPUIMAGE_VERSION}" compile "jp.co.cyberagent.android.gpuimage:gpuimage-library:${GPUIMAGE_VERSION}"
compile "com.android.support:appcompat-v7:${SUPPORT_PACKAGE_VERSION}" compile "com.android.support:appcompat-v7:${SUPPORT_PACKAGE_VERSION}"
compile "com.android.support:recyclerview-v7:${SUPPORT_PACKAGE_VERSION}" compile "com.android.support:recyclerview-v7:${SUPPORT_PACKAGE_VERSION}"

View File

@ -1,22 +1,27 @@
package jp.wasabeef.example.glide; package jp.wasabeef.example.glide;
import android.content.Context; import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.PointF; import android.graphics.PointF;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.util.DisplayMetrics;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; 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.Glide;
import com.bumptech.glide.load.MultiTransformation;
import com.bumptech.glide.load.resource.bitmap.CenterCrop; import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.request.RequestOptions;
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;
import jp.wasabeef.glide.transformations.CropSquareTransformation; import jp.wasabeef.glide.transformations.CropSquareTransformation;
import jp.wasabeef.glide.transformations.CropTransformation; import jp.wasabeef.glide.transformations.CropTransformation;
import jp.wasabeef.glide.transformations.CropTransformation.CropType;
import jp.wasabeef.glide.transformations.GrayscaleTransformation; import jp.wasabeef.glide.transformations.GrayscaleTransformation;
import jp.wasabeef.glide.transformations.MaskTransformation; import jp.wasabeef.glide.transformations.MaskTransformation;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation; import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
@ -31,13 +36,17 @@ import jp.wasabeef.glide.transformations.gpu.SwirlFilterTransformation;
import jp.wasabeef.glide.transformations.gpu.ToonFilterTransformation; import jp.wasabeef.glide.transformations.gpu.ToonFilterTransformation;
import jp.wasabeef.glide.transformations.gpu.VignetteFilterTransformation; import jp.wasabeef.glide.transformations.gpu.VignetteFilterTransformation;
import static com.bumptech.glide.request.RequestOptions.bitmapTransform;
import static com.bumptech.glide.request.RequestOptions.centerCropTransform;
import static com.bumptech.glide.request.RequestOptions.overrideOf;
/** /**
* Created by Wasabeef on 2015/01/11. * Created by Wasabeef on 2015/01/11.
*/ */
public class MainAdapter extends RecyclerView.Adapter<MainAdapter.ViewHolder> { public class MainAdapter extends RecyclerView.Adapter<MainAdapter.ViewHolder> {
private Context mContext; private Context context;
private List<Type> mDataSet; private List<Type> dataSet;
enum Type { enum Type {
Mask, Mask,
@ -64,165 +73,167 @@ public class MainAdapter extends RecyclerView.Adapter<MainAdapter.ViewHolder> {
} }
public MainAdapter(Context context, List<Type> dataSet) { public MainAdapter(Context context, List<Type> dataSet) {
mContext = context; this.context = context;
mDataSet = dataSet; this.dataSet = dataSet;
} }
@Override public MainAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { @Override public MainAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(mContext).inflate(R.layout.layout_list_item, parent, false); View v = LayoutInflater.from(context).inflate(R.layout.layout_list_item, parent, false);
return new ViewHolder(v); return new ViewHolder(v);
} }
@Override public void onBindViewHolder(MainAdapter.ViewHolder holder, int position) { @Override public void onBindViewHolder(MainAdapter.ViewHolder holder, int position) {
switch (mDataSet.get(position)) { DisplayMetrics metrics = context.getResources().getDisplayMetrics();
switch (dataSet.get(position)) {
case Mask: { case Mask: {
int width = Utils.dip2px(mContext, 133.33f); int width = Utils.dip2px(context, 133.33f);
int height = Utils.dip2px(mContext, 126.33f); int height = Utils.dip2px(context, 126.33f);
Glide.with(mContext) Glide.with(context)
.load(R.drawable.check) .load(R.drawable.check)
.override(width, height) .apply(overrideOf(width, height))
.bitmapTransform(new CenterCrop(mContext), .apply(bitmapTransform(new MultiTransformation<>(new CenterCrop(), new MaskTransformation(R.drawable.mask_starfish))))
new MaskTransformation(mContext, R.drawable.mask_starfish))
.into(holder.image); .into(holder.image);
break; break;
} }
case NinePatchMask: { case NinePatchMask: {
int width = Utils.dip2px(mContext, 150.0f); int width = Utils.dip2px(context, 150.0f);
int height = Utils.dip2px(mContext, 100.0f); int height = Utils.dip2px(context, 100.0f);
Glide.with(mContext) Glide.with(context)
.load(R.drawable.check) .load(R.drawable.check)
.override(width, height) .apply(overrideOf(width, height))
.bitmapTransform(new CenterCrop(mContext), .apply(bitmapTransform(new MultiTransformation<>(new CenterCrop(), new MaskTransformation(R.drawable.mask_chat_right))))
new MaskTransformation(mContext, R.drawable.mask_chat_right))
.into(holder.image); .into(holder.image);
break; break;
} }
case CropTop: case CropTop:
Glide.with(mContext) Glide.with(context)
.load(R.drawable.demo) .load(R.drawable.demo)
.bitmapTransform( .apply(bitmapTransform(
new CropTransformation(mContext, 300, 100, CropTransformation.CropType.TOP)) new CropTransformation(Utils.dip2px(context, 300), Utils.dip2px(context, 100),
CropType.TOP)))
.into(holder.image); .into(holder.image);
break; break;
case CropCenter: case CropCenter:
Glide.with(mContext) Glide.with(context)
.load(R.drawable.demo) .load(R.drawable.demo)
.bitmapTransform(new CropTransformation(mContext, 300, 100)) .apply(bitmapTransform(
new CropTransformation(Utils.dip2px(context, 300), Utils.dip2px(context, 100))))
.into(holder.image); .into(holder.image);
break; break;
case CropBottom: case CropBottom:
Glide.with(mContext) Glide.with(context)
.load(R.drawable.demo) .load(R.drawable.demo)
.bitmapTransform( .apply(bitmapTransform(
new CropTransformation(mContext, 300, 100, CropTransformation.CropType.BOTTOM)) new CropTransformation(Utils.dip2px(context, 300), Utils.dip2px(context, 100),
CropType.BOTTOM)))
.into(holder.image); .into(holder.image);
break; break;
case CropSquare: case CropSquare:
Glide.with(mContext) Glide.with(context)
.load(R.drawable.demo) .load(R.drawable.demo)
.bitmapTransform(new CropSquareTransformation(mContext)) .apply(bitmapTransform(new CropSquareTransformation()))
.into(holder.image); .into(holder.image);
break; break;
case CropCircle: case CropCircle:
Glide.with(mContext) Glide.with(context)
.load(R.drawable.demo) .load(R.drawable.demo)
.bitmapTransform(new CropCircleTransformation(mContext)) .apply(bitmapTransform(new CropCircleTransformation()))
.into(holder.image); .into(holder.image);
break; break;
case ColorFilter: case ColorFilter:
Glide.with(mContext) Glide.with(context)
.load(R.drawable.demo) .load(R.drawable.demo)
.bitmapTransform(new ColorFilterTransformation(mContext, Color.argb(80, 255, 0, 0))) .apply(bitmapTransform(new ColorFilterTransformation(Color.argb(80, 255, 0, 0))))
.into(holder.image); .into(holder.image);
break; break;
case Grayscale: case Grayscale:
Glide.with(mContext) Glide.with(context)
.load(R.drawable.demo) .load(R.drawable.demo)
.bitmapTransform(new GrayscaleTransformation(mContext)) .apply(bitmapTransform(new GrayscaleTransformation()))
.into(holder.image); .into(holder.image);
break; break;
case RoundedCorners: case RoundedCorners:
Glide.with(mContext) Glide.with(context)
.load(R.drawable.demo) .load(R.drawable.demo)
.bitmapTransform(new RoundedCornersTransformation(mContext, 30, 0, .apply(bitmapTransform(new RoundedCornersTransformation(45, 0,
RoundedCornersTransformation.CornerType.BOTTOM)) RoundedCornersTransformation.CornerType.BOTTOM)))
.into(holder.image); .into(holder.image);
break; break;
case Blur: case Blur:
Glide.with(mContext) Glide.with(context)
.load(R.drawable.check) .load(R.drawable.check)
.bitmapTransform(new BlurTransformation(mContext, 25)) .apply(bitmapTransform(new BlurTransformation(25)))
.into(holder.image); .into(holder.image);
break; break;
case Toon: case Toon:
Glide.with(mContext) Glide.with(context)
.load(R.drawable.demo) .load(R.drawable.demo)
.bitmapTransform(new ToonFilterTransformation(mContext)) .apply(bitmapTransform(new ToonFilterTransformation()))
.into(holder.image); .into(holder.image);
break; break;
case Sepia: case Sepia:
Glide.with(mContext) Glide.with(context)
.load(R.drawable.check) .load(R.drawable.check)
.bitmapTransform(new SepiaFilterTransformation(mContext)) .apply(bitmapTransform(new SepiaFilterTransformation()))
.into(holder.image); .into(holder.image);
break; break;
case Contrast: case Contrast:
Glide.with(mContext) Glide.with(context)
.load(R.drawable.check) .load(R.drawable.check)
.bitmapTransform(new ContrastFilterTransformation(mContext, 2.0f)) .apply(bitmapTransform(new ContrastFilterTransformation(2.0f)))
.into(holder.image); .into(holder.image);
break; break;
case Invert: case Invert:
Glide.with(mContext) Glide.with(context)
.load(R.drawable.check) .load(R.drawable.check)
.bitmapTransform(new InvertFilterTransformation(mContext)) .apply(bitmapTransform(new InvertFilterTransformation()))
.into(holder.image); .into(holder.image);
break; break;
case Pixel: case Pixel:
Glide.with(mContext) Glide.with(context)
.load(R.drawable.check) .load(R.drawable.check)
.bitmapTransform(new PixelationFilterTransformation(mContext, 20)) .apply(bitmapTransform(new PixelationFilterTransformation(20)))
.into(holder.image); .into(holder.image);
break; break;
case Sketch: case Sketch:
Glide.with(mContext) Glide.with(context)
.load(R.drawable.check) .load(R.drawable.check)
.bitmapTransform(new SketchFilterTransformation(mContext)) .apply(bitmapTransform(new SketchFilterTransformation()))
.into(holder.image); .into(holder.image);
break; break;
case Swirl: case Swirl:
Glide.with(mContext) Glide.with(context)
.load(R.drawable.check) .load(R.drawable.check)
.bitmapTransform( .apply(bitmapTransform(
new SwirlFilterTransformation(mContext, 0.5f, 1.0f, new PointF(0.5f, 0.5f))) new SwirlFilterTransformation(0.5f, 1.0f, new PointF(0.5f, 0.5f))).dontAnimate())
.into(holder.image); .into(holder.image);
break; break;
case Brightness: case Brightness:
Glide.with(mContext) Glide.with(context)
.load(R.drawable.check) .load(R.drawable.check)
.bitmapTransform(new BrightnessFilterTransformation(mContext, 0.5f)) .apply(bitmapTransform(new BrightnessFilterTransformation(0.5f)).dontAnimate())
.into(holder.image); .into(holder.image);
break; break;
case Kuawahara: case Kuawahara:
Glide.with(mContext) Glide.with(context)
.load(R.drawable.check) .load(R.drawable.check)
.bitmapTransform(new KuwaharaFilterTransformation(mContext, 25)) .apply(bitmapTransform(new KuwaharaFilterTransformation(25)).dontAnimate())
.into(holder.image); .into(holder.image);
break; break;
case Vignette: case Vignette:
Glide.with(mContext) Glide.with(context)
.load(R.drawable.check) .load(R.drawable.check)
.bitmapTransform(new VignetteFilterTransformation(mContext, new PointF(0.5f, 0.5f), .apply(bitmapTransform(new VignetteFilterTransformation(new PointF(0.5f, 0.5f),
new float[] { 0.0f, 0.0f, 0.0f }, 0f, 0.75f)) new float[] { 0.0f, 0.0f, 0.0f }, 0f, 0.75f)).dontAnimate())
.into(holder.image); .into(holder.image);
break; break;
} }
holder.title.setText(mDataSet.get(position).name()); holder.title.setText(dataSet.get(position).name());
} }
@Override public int getItemCount() { @Override public int getItemCount() {
return mDataSet.size(); return dataSet.size();
} }
static class ViewHolder extends RecyclerView.ViewHolder { static class ViewHolder extends RecyclerView.ViewHolder {

View File

@ -7,7 +7,7 @@
<ImageView <ImageView
android:id="@+id/image" android:id="@+id/image"
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_centerInParent="true"
android:contentDescription="@null" android:contentDescription="@null"

View File

@ -1,11 +1,11 @@
VERSION_NAME=2.0.2 VERSION_NAME=3.0.0
GROUP=jp.wasabeef GROUP=jp.wasabeef
ARTIFACT_ID=glide-transformations ARTIFACT_ID=glide-transformations
COMPILE_SDK_VERSION=25 COMPILE_SDK_VERSION=25
BUILD_TOOLS_VERSION=25.0.2 BUILD_TOOLS_VERSION=26.0.1
TARGET_SDK_VERSION=25 TARGET_SDK_VERSION=25
MIN_SDK_VERSION=11 MIN_SDK_VERSION=14
POM_DESCRIPTION=which provides simple Tranformations to Glide POM_DESCRIPTION=which provides simple Tranformations to Glide
POM_URL=https://github.com/wasabeef/glide-transformations POM_URL=https://github.com/wasabeef/glide-transformations
@ -21,6 +21,6 @@ POM_DEVELOPER_EMAIL=dadadada.chop@gmail.com
POM_DEVELOPER_URL=wasabeef.jp POM_DEVELOPER_URL=wasabeef.jp
ISSUE_URL=https://github.com/wasabeef/glide-transformations/issues ISSUE_URL=https://github.com/wasabeef/glide-transformations/issues
SUPPORT_PACKAGE_VERSION=25.3.0 SUPPORT_PACKAGE_VERSION=25.3.1
GLIDE_VERSION=3.7.0 GLIDE_VERSION=4.0.0
GPUIMAGE_VERSION=1.4.1 GPUIMAGE_VERSION=1.4.1

View File

@ -17,6 +17,7 @@ android {
dependencies { dependencies {
compile "com.github.bumptech.glide:glide:${GLIDE_VERSION}" compile "com.github.bumptech.glide:glide:${GLIDE_VERSION}"
annotationProcessor "com.github.bumptech.glide:compiler:${GLIDE_VERSION}"
provided "jp.co.cyberagent.android.gpuimage:gpuimage-library:${GPUIMAGE_VERSION}" provided "jp.co.cyberagent.android.gpuimage:gpuimage-library:${GPUIMAGE_VERSION}"
} }

View File

@ -1 +1,11 @@
-dontwarn jp.co.cyberagent.android.gpuimage.** -dontwarn jp.co.cyberagent.android.gpuimage.**
-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public class * extends com.bumptech.glide.AppGlideModule
-keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** {
**[] $VALUES;
public *;
}
# for DexGuard only
-keepresourcexmlelements manifest/application/meta-data@value=GlideModule

View File

@ -0,0 +1,65 @@
package jp.wasabeef.glide.transformations;
/**
* Copyright (C) 2017 Wasabeef
* Copyright 2014 Google, Inc. All rights reserved.
*
* 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 android.support.annotation.NonNull;
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 com.bumptech.glide.request.target.Target;
import com.bumptech.glide.util.Util;
import java.security.MessageDigest;
public abstract class BitmapTransformation implements Transformation<Bitmap> {
public abstract String key();
@Override
public final Resource<Bitmap> transform(Context context, Resource<Bitmap> resource, int outWidth,
int outHeight) {
if (!Util.isValidDimensions(outWidth, outHeight)) {
throw new IllegalArgumentException(
"Cannot apply transformation on width: " + outWidth + " or height: " + outHeight
+ " less than or equal to zero and not Target.SIZE_ORIGINAL");
}
BitmapPool bitmapPool = Glide.get(context).getBitmapPool();
Bitmap toTransform = resource.get();
int targetWidth = outWidth == Target.SIZE_ORIGINAL ? toTransform.getWidth() : outWidth;
int targetHeight = outHeight == Target.SIZE_ORIGINAL ? toTransform.getHeight() : outHeight;
Bitmap transformed = transform(context.getApplicationContext(), bitmapPool, toTransform, targetWidth, targetHeight);
final Resource<Bitmap> result;
if (toTransform.equals(transformed)) {
result = resource;
} else {
result = BitmapResource.obtain(transformed, bitmapPool);
}
return result;
}
protected abstract Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
@NonNull Bitmap toTransform, int outWidth, int outHeight);
@Override public void updateDiskCacheKey(MessageDigest messageDigest) {
messageDigest.update(key().getBytes());
}
}

View File

@ -22,86 +22,62 @@ import android.graphics.Canvas;
import android.graphics.Paint; import android.graphics.Paint;
import android.os.Build; import android.os.Build;
import android.renderscript.RSRuntimeException; import android.renderscript.RSRuntimeException;
import com.bumptech.glide.Glide; import android.support.annotation.NonNull;
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.wasabeef.glide.transformations.internal.FastBlur; import jp.wasabeef.glide.transformations.internal.FastBlur;
import jp.wasabeef.glide.transformations.internal.RSBlur; import jp.wasabeef.glide.transformations.internal.RSBlur;
public class BlurTransformation implements Transformation<Bitmap> { public class BlurTransformation extends BitmapTransformation {
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 int radius;
private BitmapPool mBitmapPool; private int sampling;
private int mRadius; public BlurTransformation() {
private int mSampling; this(MAX_RADIUS, DEFAULT_DOWN_SAMPLING);
public BlurTransformation(Context context) {
this(context, Glide.get(context).getBitmapPool(), MAX_RADIUS, DEFAULT_DOWN_SAMPLING);
} }
public BlurTransformation(Context context, BitmapPool pool) { public BlurTransformation(int radius) {
this(context, pool, MAX_RADIUS, DEFAULT_DOWN_SAMPLING); this(radius, DEFAULT_DOWN_SAMPLING);
} }
public BlurTransformation(Context context, BitmapPool pool, int radius) { public BlurTransformation(int radius, int sampling) {
this(context, pool, radius, DEFAULT_DOWN_SAMPLING); this.radius = radius;
this.sampling = sampling;
} }
public BlurTransformation(Context context, int radius) { @Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
this(context, Glide.get(context).getBitmapPool(), radius, DEFAULT_DOWN_SAMPLING); @NonNull Bitmap toTransform, int outWidth, int outHeight) {
}
public BlurTransformation(Context context, int radius, int sampling) { int width = toTransform.getWidth();
this(context, Glide.get(context).getBitmapPool(), radius, sampling); int height = toTransform.getHeight();
} int scaledWidth = width / sampling;
int scaledHeight = height / sampling;
public BlurTransformation(Context context, BitmapPool pool, int radius, int sampling) { Bitmap bitmap = pool.get(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
mContext = context.getApplicationContext();
mBitmapPool = pool;
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);
}
Canvas canvas = new Canvas(bitmap); Canvas canvas = new Canvas(bitmap);
canvas.scale(1 / (float) mSampling, 1 / (float) mSampling); canvas.scale(1 / (float) sampling, 1 / (float) sampling);
Paint paint = new Paint(); Paint paint = new Paint();
paint.setFlags(Paint.FILTER_BITMAP_FLAG); paint.setFlags(Paint.FILTER_BITMAP_FLAG);
canvas.drawBitmap(source, 0, 0, paint); canvas.drawBitmap(toTransform, 0, 0, paint);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
try { try {
bitmap = RSBlur.blur(mContext, bitmap, mRadius); bitmap = RSBlur.blur(context, bitmap, radius);
} catch (RSRuntimeException e) { } catch (RSRuntimeException e) {
bitmap = FastBlur.blur(bitmap, mRadius, true); bitmap = FastBlur.blur(bitmap, radius, true);
} }
} else { } else {
bitmap = FastBlur.blur(bitmap, mRadius, true); bitmap = FastBlur.blur(bitmap, radius, true);
} }
return BitmapResource.obtain(bitmap, mBitmapPool); return bitmap;
} }
@Override public String getId() { @Override public String key() {
return "BlurTransformation(radius=" + mRadius + ", sampling=" + mSampling + ")"; return "BlurTransformation(radius=" + radius + ", sampling=" + sampling + ")";
} }
} }

View File

@ -22,51 +22,36 @@ 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 android.support.annotation.NonNull;
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;
public class ColorFilterTransformation implements Transformation<Bitmap> { public class ColorFilterTransformation extends BitmapTransformation {
private BitmapPool mBitmapPool; private int color;
private int mColor; public ColorFilterTransformation(int color) {
this.color = color;
public ColorFilterTransformation(Context context, int color) {
this(Glide.get(context).getBitmapPool(), color);
} }
public ColorFilterTransformation(BitmapPool pool, int color) { @Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
mBitmapPool = pool; @NonNull Bitmap toTransform, int outWidth, int outHeight) {
mColor = color; int width = toTransform.getWidth();
} int height = toTransform.getHeight();
@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 = Bitmap.Config config =
source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888; toTransform.getConfig() != null ? toTransform.getConfig() : Bitmap.Config.ARGB_8888;
Bitmap bitmap = mBitmapPool.get(width, height, config); Bitmap bitmap = pool.get(width, height, config);
if (bitmap == null) {
bitmap = Bitmap.createBitmap(width, height, config);
}
Canvas canvas = new Canvas(bitmap); Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint(); Paint paint = new Paint();
paint.setAntiAlias(true); paint.setAntiAlias(true);
paint.setColorFilter(new PorterDuffColorFilter(mColor, PorterDuff.Mode.SRC_ATOP)); paint.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP));
canvas.drawBitmap(source, 0, 0, paint); canvas.drawBitmap(toTransform, 0, 0, paint);
return BitmapResource.obtain(bitmap, mBitmapPool); return bitmap;
} }
@Override public String getId() { @Override public String key() {
return "ColorFilterTransformation(color=" + mColor + ")"; return "ColorFilterTransformation(color=" + color + ")";
} }
} }

View File

@ -18,61 +18,23 @@ package jp.wasabeef.glide.transformations;
import android.content.Context; import android.content.Context;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapShader; import android.support.annotation.NonNull;
import android.graphics.Canvas;
import android.graphics.Matrix;
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.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapResource; import com.bumptech.glide.load.resource.bitmap.TransformationUtils;
import com.bumptech.glide.request.RequestOptions;
public class CropCircleTransformation implements Transformation<Bitmap> { /**
* @deprecated Use {@link RequestOptions#circleCrop()}.
*/
@Deprecated
public class CropCircleTransformation extends BitmapTransformation {
private BitmapPool mBitmapPool; @Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
public CropCircleTransformation(Context context) { return TransformationUtils.circleCrop(pool, toTransform, outWidth, outHeight);
this(Glide.get(context).getBitmapPool());
} }
public CropCircleTransformation(BitmapPool pool) { @Override public String key() {
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);
}
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) {
// source isn't square, move viewport to center
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()"; return "CropCircleTransformation()";
} }
} }

View File

@ -18,45 +18,21 @@ package jp.wasabeef.glide.transformations;
import android.content.Context; import android.content.Context;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import com.bumptech.glide.Glide; import android.support.annotation.NonNull;
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 com.bumptech.glide.load.resource.bitmap.TransformationUtils;
public class CropSquareTransformation implements Transformation<Bitmap> { public class CropSquareTransformation extends BitmapTransformation {
private BitmapPool mBitmapPool; private int size;
private int mWidth;
private int mHeight;
public CropSquareTransformation(Context context) { @Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
this(Glide.get(context).getBitmapPool()); @NonNull Bitmap toTransform, int outWidth, int outHeight) {
this.size = Math.max(outWidth, outHeight);
return TransformationUtils.centerCrop(pool, toTransform, size, size);
} }
public CropSquareTransformation(BitmapPool pool) { @Override public String key() {
this.mBitmapPool = pool; return "CropSquareTransformation(size=" + size + ")";
}
@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);
}
return BitmapResource.obtain(bitmap, mBitmapPool);
}
@Override public String getId() {
return "CropSquareTransformation(width=" + mWidth + ", height=" + mHeight + ")";
} }
} }

View File

@ -20,13 +20,10 @@ import android.content.Context;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.RectF; import android.graphics.RectF;
import com.bumptech.glide.Glide; import android.support.annotation.NonNull;
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;
public class CropTransformation implements Transformation<Bitmap> { public class CropTransformation extends BitmapTransformation {
public enum CropType { public enum CropType {
TOP, TOP,
@ -34,81 +31,62 @@ public class CropTransformation implements Transformation<Bitmap> {
BOTTOM BOTTOM
} }
private BitmapPool mBitmapPool; private int width;
private int mWidth; private int height;
private int mHeight;
private CropType mCropType = CropType.CENTER; private CropType cropType = CropType.CENTER;
public CropTransformation(Context context) { public CropTransformation(int width, int height) {
this(Glide.get(context).getBitmapPool()); this(width, height, CropType.CENTER);
} }
public CropTransformation(BitmapPool pool) { public CropTransformation(int width, int height, CropType cropType) {
this(pool, 0, 0); this.width = width;
this.height = height;
this.cropType = cropType;
} }
public CropTransformation(Context context, int width, int height) { @Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
this(Glide.get(context).getBitmapPool(), width, height); @NonNull Bitmap toTransform, int outWidth, int outHeight) {
}
public CropTransformation(BitmapPool pool, int width, int height) { width = width == 0 ? toTransform.getWidth() : width;
this(pool, width, height, CropType.CENTER); height = height == 0 ? toTransform.getHeight() : height;
}
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 = Bitmap.Config config =
source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888; toTransform.getConfig() != null ? toTransform.getConfig() : Bitmap.Config.ARGB_8888;
Bitmap bitmap = mBitmapPool.get(mWidth, mHeight, config); Bitmap bitmap = pool.get(width, height, config);
if (bitmap == null) {
bitmap = Bitmap.createBitmap(mWidth, mHeight, config);
}
float scaleX = (float) mWidth / source.getWidth(); bitmap.setHasAlpha(true);
float scaleY = (float) mHeight / source.getHeight();
float scaleX = (float) width / toTransform.getWidth();
float scaleY = (float) height / toTransform.getHeight();
float scale = Math.max(scaleX, scaleY); float scale = Math.max(scaleX, scaleY);
float scaledWidth = scale * source.getWidth(); float scaledWidth = scale * toTransform.getWidth();
float scaledHeight = scale * source.getHeight(); float scaledHeight = scale * toTransform.getHeight();
float left = (mWidth - scaledWidth) / 2; float left = (width - scaledWidth) / 2;
float top = getTop(scaledHeight); float top = getTop(scaledHeight);
RectF targetRect = new RectF(left, top, left + scaledWidth, top + scaledHeight); RectF targetRect = new RectF(left, top, left + scaledWidth, top + scaledHeight);
Canvas canvas = new Canvas(bitmap); Canvas canvas = new Canvas(bitmap);
canvas.drawBitmap(source, null, targetRect, null); canvas.drawBitmap(toTransform, null, targetRect, null);
return BitmapResource.obtain(bitmap, mBitmapPool); return bitmap;
} }
@Override public String getId() { @Override public String key() {
return "CropTransformation(width=" + mWidth + ", height=" + mHeight + ", cropType=" + mCropType return "CropTransformation(width=" + width + ", height=" + height + ", cropType=" + cropType
+ ")"; + ")";
} }
private float getTop(float scaledHeight) { private float getTop(float scaledHeight) {
switch (mCropType) { switch (cropType) {
case TOP: case TOP:
return 0; return 0;
case CENTER: case CENTER:
return (mHeight - scaledHeight) / 2; return (height - scaledHeight) / 2;
case BOTTOM: case BOTTOM:
return mHeight - scaledHeight; return height - scaledHeight;
default: default:
return 0; return 0;
} }

View File

@ -22,49 +22,31 @@ 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 android.support.annotation.NonNull;
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;
public class GrayscaleTransformation implements Transformation<Bitmap> { public class GrayscaleTransformation extends BitmapTransformation {
private BitmapPool mBitmapPool; @Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
public GrayscaleTransformation(Context context) { int width = toTransform.getWidth();
this(Glide.get(context).getBitmapPool()); int height = toTransform.getHeight();
}
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 = Bitmap.Config config =
source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888; toTransform.getConfig() != null ? toTransform.getConfig() : Bitmap.Config.ARGB_8888;
Bitmap bitmap = mBitmapPool.get(width, height, config); Bitmap bitmap = pool.get(width, height, config);
if (bitmap == null) {
bitmap = Bitmap.createBitmap(width, height, config);
}
Canvas canvas = new Canvas(bitmap); Canvas canvas = new Canvas(bitmap);
ColorMatrix saturation = new ColorMatrix(); ColorMatrix saturation = new ColorMatrix();
saturation.setSaturation(0f); saturation.setSaturation(0f);
Paint paint = new Paint(); Paint paint = new Paint();
paint.setColorFilter(new ColorMatrixColorFilter(saturation)); paint.setColorFilter(new ColorMatrixColorFilter(saturation));
canvas.drawBitmap(source, 0, 0, paint); canvas.drawBitmap(toTransform, 0, 0, paint);
return BitmapResource.obtain(bitmap, mBitmapPool); return bitmap;
} }
@Override public String getId() { @Override public String key() {
return "GrayscaleTransformation()"; return "GrayscaleTransformation()";
} }
} }

View File

@ -23,63 +23,47 @@ import android.graphics.Paint;
import android.graphics.PorterDuff; import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode; import android.graphics.PorterDuffXfermode;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import com.bumptech.glide.Glide; import android.support.annotation.NonNull;
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.wasabeef.glide.transformations.internal.Utils; import jp.wasabeef.glide.transformations.internal.Utils;
public class MaskTransformation implements Transformation<Bitmap> { public class MaskTransformation extends BitmapTransformation {
private static Paint sMaskingPaint = new Paint(); private static Paint paint = new Paint();
private Context mContext; private int maskId;
private BitmapPool mBitmapPool;
private int mMaskId;
static { static {
sMaskingPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
} }
/** /**
* @param maskId If you change the mask file, please also rename the mask file, or Glide will get * @param maskId If you change the mask file, please also rename the mask file, or Glide will get
* the cache with the old mask. Because getId() return the same values if using the * the cache with the old mask. Because key() return the same values if using the
* same make file name. If you have a good idea please tell us, thanks. * same make file name. If you have a good idea please tell us, thanks.
*/ */
public MaskTransformation(Context context, int maskId) { public MaskTransformation(int maskId) {
this(context, Glide.get(context).getBitmapPool(), maskId); this.maskId = maskId;
} }
public MaskTransformation(Context context, BitmapPool pool, int maskId) { @Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
mBitmapPool = pool; @NonNull Bitmap toTransform, int outWidth, int outHeight) {
mContext = context.getApplicationContext(); int width = toTransform.getWidth();
mMaskId = maskId; int height = toTransform.getHeight();
}
@Override Bitmap bitmap = pool.get(width, height, Bitmap.Config.ARGB_8888);
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) { bitmap.setHasAlpha(true);
Bitmap source = resource.get();
int width = source.getWidth(); Drawable mask = Utils.getMaskDrawable(context.getApplicationContext(), maskId);
int height = source.getHeight();
Bitmap result = mBitmapPool.get(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap);
if (result == null) {
result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
}
Drawable mask = Utils.getMaskDrawable(mContext, mMaskId);
Canvas canvas = new Canvas(result);
mask.setBounds(0, 0, width, height); mask.setBounds(0, 0, width, height);
mask.draw(canvas); mask.draw(canvas);
canvas.drawBitmap(source, 0, 0, sMaskingPaint); canvas.drawBitmap(toTransform, 0, 0, paint);
return BitmapResource.obtain(result, mBitmapPool); return bitmap;
} }
@Override public String getId() { @Override public String key() {
return "MaskTransformation(maskId=" + mContext.getResources().getResourceEntryName(mMaskId) return "MaskTransformation(maskId=" + maskId + ")";
+ ")";
} }
} }

View File

@ -23,13 +23,10 @@ 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 android.support.annotation.NonNull;
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;
public class RoundedCornersTransformation implements Transformation<Bitmap> { public class RoundedCornersTransformation extends BitmapTransformation {
public enum CornerType { public enum CornerType {
ALL, ALL,
@ -39,61 +36,45 @@ public class RoundedCornersTransformation implements Transformation<Bitmap> {
DIAGONAL_FROM_TOP_LEFT, DIAGONAL_FROM_TOP_RIGHT DIAGONAL_FROM_TOP_LEFT, DIAGONAL_FROM_TOP_RIGHT
} }
private BitmapPool mBitmapPool; private int radius;
private int mRadius; private int diameter;
private int mDiameter; private int margin;
private int mMargin; private CornerType cornerType;
private CornerType mCornerType;
public RoundedCornersTransformation(Context context, int radius, int margin) { public RoundedCornersTransformation(int radius, int margin) {
this(context, radius, margin, CornerType.ALL); this(radius, margin, CornerType.ALL);
} }
public RoundedCornersTransformation(BitmapPool pool, int radius, int margin) { public RoundedCornersTransformation(int radius, int margin, CornerType cornerType) {
this(pool, radius, margin, CornerType.ALL); this.radius = radius;
this.diameter = this.radius * 2;
this.margin = margin;
this.cornerType = cornerType;
} }
public RoundedCornersTransformation(Context context, int radius, int margin, @Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
CornerType cornerType) { @NonNull Bitmap toTransform, int outWidth, int outHeight) {
this(Glide.get(context).getBitmapPool(), radius, margin, cornerType); int width = toTransform.getWidth();
} int height = toTransform.getHeight();
public RoundedCornersTransformation(BitmapPool pool, int radius, int margin, Bitmap bitmap = pool.get(width, height, Bitmap.Config.ARGB_8888);
CornerType cornerType) { bitmap.setHasAlpha(true);
mBitmapPool = pool;
mRadius = radius;
mDiameter = mRadius * 2;
mMargin = margin;
mCornerType = cornerType;
}
@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);
}
Canvas canvas = new Canvas(bitmap); Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint(); Paint paint = new Paint();
paint.setAntiAlias(true); paint.setAntiAlias(true);
paint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP)); paint.setShader(new BitmapShader(toTransform, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
drawRoundRect(canvas, paint, width, height); drawRoundRect(canvas, paint, width, height);
return BitmapResource.obtain(bitmap, mBitmapPool); return bitmap;
} }
private void drawRoundRect(Canvas canvas, Paint paint, float width, float height) { private void drawRoundRect(Canvas canvas, Paint paint, float width, float height) {
float right = width - mMargin; float right = width - margin;
float bottom = height - mMargin; float bottom = height - margin;
switch (mCornerType) { switch (cornerType) {
case ALL: case ALL:
canvas.drawRoundRect(new RectF(mMargin, mMargin, right, bottom), mRadius, mRadius, paint); canvas.drawRoundRect(new RectF(margin, margin, right, bottom), radius, radius, paint);
break; break;
case TOP_LEFT: case TOP_LEFT:
drawTopLeftRoundRect(canvas, paint, right, bottom); drawTopLeftRoundRect(canvas, paint, right, bottom);
@ -138,118 +119,118 @@ public class RoundedCornersTransformation implements Transformation<Bitmap> {
drawDiagonalFromTopRightRoundRect(canvas, paint, right, bottom); drawDiagonalFromTopRightRoundRect(canvas, paint, right, bottom);
break; break;
default: default:
canvas.drawRoundRect(new RectF(mMargin, mMargin, right, bottom), mRadius, mRadius, paint); canvas.drawRoundRect(new RectF(margin, margin, right, bottom), radius, radius, paint);
break; break;
} }
} }
private void drawTopLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) { private void drawTopLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
canvas.drawRoundRect(new RectF(mMargin, mMargin, mMargin + mDiameter, mMargin + mDiameter), canvas.drawRoundRect(new RectF(margin, margin, margin + diameter, margin + diameter),
mRadius, mRadius, paint); radius, radius, paint);
canvas.drawRect(new RectF(mMargin, mMargin + mRadius, mMargin + mRadius, bottom), paint); canvas.drawRect(new RectF(margin, margin + radius, margin + radius, bottom), paint);
canvas.drawRect(new RectF(mMargin + mRadius, mMargin, right, bottom), paint); canvas.drawRect(new RectF(margin + radius, margin, right, bottom), paint);
} }
private void drawTopRightRoundRect(Canvas canvas, Paint paint, float right, float bottom) { private void drawTopRightRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
canvas.drawRoundRect(new RectF(right - mDiameter, mMargin, right, mMargin + mDiameter), mRadius, canvas.drawRoundRect(new RectF(right - diameter, margin, right, margin + diameter), radius,
mRadius, paint); radius, paint);
canvas.drawRect(new RectF(mMargin, mMargin, right - mRadius, bottom), paint); canvas.drawRect(new RectF(margin, margin, right - radius, bottom), paint);
canvas.drawRect(new RectF(right - mRadius, mMargin + mRadius, right, bottom), paint); canvas.drawRect(new RectF(right - radius, margin + radius, right, bottom), paint);
} }
private void drawBottomLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) { private void drawBottomLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
canvas.drawRoundRect(new RectF(mMargin, bottom - mDiameter, mMargin + mDiameter, bottom), canvas.drawRoundRect(new RectF(margin, bottom - diameter, margin + diameter, bottom),
mRadius, mRadius, paint); radius, radius, paint);
canvas.drawRect(new RectF(mMargin, mMargin, mMargin + mDiameter, bottom - mRadius), paint); canvas.drawRect(new RectF(margin, margin, margin + diameter, bottom - radius), paint);
canvas.drawRect(new RectF(mMargin + mRadius, mMargin, right, bottom), paint); canvas.drawRect(new RectF(margin + radius, margin, right, bottom), paint);
} }
private void drawBottomRightRoundRect(Canvas canvas, Paint paint, float right, float bottom) { private void drawBottomRightRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
canvas.drawRoundRect(new RectF(right - mDiameter, bottom - mDiameter, right, bottom), mRadius, canvas.drawRoundRect(new RectF(right - diameter, bottom - diameter, right, bottom), radius,
mRadius, paint); radius, paint);
canvas.drawRect(new RectF(mMargin, mMargin, right - mRadius, bottom), paint); canvas.drawRect(new RectF(margin, margin, right - radius, bottom), paint);
canvas.drawRect(new RectF(right - mRadius, mMargin, right, bottom - mRadius), paint); canvas.drawRect(new RectF(right - radius, margin, right, bottom - radius), paint);
} }
private void drawTopRoundRect(Canvas canvas, Paint paint, float right, float bottom) { private void drawTopRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
canvas.drawRoundRect(new RectF(mMargin, mMargin, right, mMargin + mDiameter), mRadius, mRadius, canvas.drawRoundRect(new RectF(margin, margin, right, margin + diameter), radius, radius,
paint); paint);
canvas.drawRect(new RectF(mMargin, mMargin + mRadius, right, bottom), paint); canvas.drawRect(new RectF(margin, margin + radius, right, bottom), paint);
} }
private void drawBottomRoundRect(Canvas canvas, Paint paint, float right, float bottom) { private void drawBottomRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
canvas.drawRoundRect(new RectF(mMargin, bottom - mDiameter, right, bottom), mRadius, mRadius, canvas.drawRoundRect(new RectF(margin, bottom - diameter, right, bottom), radius, radius,
paint); paint);
canvas.drawRect(new RectF(mMargin, mMargin, right, bottom - mRadius), paint); canvas.drawRect(new RectF(margin, margin, right, bottom - radius), paint);
} }
private void drawLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) { private void drawLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
canvas.drawRoundRect(new RectF(mMargin, mMargin, mMargin + mDiameter, bottom), mRadius, mRadius, canvas.drawRoundRect(new RectF(margin, margin, margin + diameter, bottom), radius, radius,
paint); paint);
canvas.drawRect(new RectF(mMargin + mRadius, mMargin, right, bottom), paint); canvas.drawRect(new RectF(margin + radius, margin, right, bottom), paint);
} }
private void drawRightRoundRect(Canvas canvas, Paint paint, float right, float bottom) { private void drawRightRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
canvas.drawRoundRect(new RectF(right - mDiameter, mMargin, right, bottom), mRadius, mRadius, canvas.drawRoundRect(new RectF(right - diameter, margin, right, bottom), radius, radius,
paint); paint);
canvas.drawRect(new RectF(mMargin, mMargin, right - mRadius, bottom), paint); canvas.drawRect(new RectF(margin, margin, right - radius, bottom), paint);
} }
private void drawOtherTopLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) { private void drawOtherTopLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
canvas.drawRoundRect(new RectF(mMargin, bottom - mDiameter, right, bottom), mRadius, mRadius, canvas.drawRoundRect(new RectF(margin, bottom - diameter, right, bottom), radius, radius,
paint); paint);
canvas.drawRoundRect(new RectF(right - mDiameter, mMargin, right, bottom), mRadius, mRadius, canvas.drawRoundRect(new RectF(right - diameter, margin, right, bottom), radius, radius,
paint); paint);
canvas.drawRect(new RectF(mMargin, mMargin, right - mRadius, bottom - mRadius), paint); canvas.drawRect(new RectF(margin, margin, right - radius, bottom - radius), paint);
} }
private void drawOtherTopRightRoundRect(Canvas canvas, Paint paint, float right, float bottom) { private void drawOtherTopRightRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
canvas.drawRoundRect(new RectF(mMargin, mMargin, mMargin + mDiameter, bottom), mRadius, mRadius, canvas.drawRoundRect(new RectF(margin, margin, margin + diameter, bottom), radius, radius,
paint); paint);
canvas.drawRoundRect(new RectF(mMargin, bottom - mDiameter, right, bottom), mRadius, mRadius, canvas.drawRoundRect(new RectF(margin, bottom - diameter, right, bottom), radius, radius,
paint); paint);
canvas.drawRect(new RectF(mMargin + mRadius, mMargin, right, bottom - mRadius), paint); canvas.drawRect(new RectF(margin + radius, margin, right, bottom - radius), paint);
} }
private void drawOtherBottomLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) { private void drawOtherBottomLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
canvas.drawRoundRect(new RectF(mMargin, mMargin, right, mMargin + mDiameter), mRadius, mRadius, canvas.drawRoundRect(new RectF(margin, margin, right, margin + diameter), radius, radius,
paint); paint);
canvas.drawRoundRect(new RectF(right - mDiameter, mMargin, right, bottom), mRadius, mRadius, canvas.drawRoundRect(new RectF(right - diameter, margin, right, bottom), radius, radius,
paint); paint);
canvas.drawRect(new RectF(mMargin, mMargin + mRadius, right - mRadius, bottom), paint); canvas.drawRect(new RectF(margin, margin + radius, right - radius, bottom), paint);
} }
private void drawOtherBottomRightRoundRect(Canvas canvas, Paint paint, float right, private void drawOtherBottomRightRoundRect(Canvas canvas, Paint paint, float right,
float bottom) { float bottom) {
canvas.drawRoundRect(new RectF(mMargin, mMargin, right, mMargin + mDiameter), mRadius, mRadius, canvas.drawRoundRect(new RectF(margin, margin, right, margin + diameter), radius, radius,
paint); paint);
canvas.drawRoundRect(new RectF(mMargin, mMargin, mMargin + mDiameter, bottom), mRadius, mRadius, canvas.drawRoundRect(new RectF(margin, margin, margin + diameter, bottom), radius, radius,
paint); paint);
canvas.drawRect(new RectF(mMargin + mRadius, mMargin + mRadius, right, bottom), paint); canvas.drawRect(new RectF(margin + radius, margin + radius, right, bottom), paint);
} }
private void drawDiagonalFromTopLeftRoundRect(Canvas canvas, Paint paint, float right, private void drawDiagonalFromTopLeftRoundRect(Canvas canvas, Paint paint, float right,
float bottom) { float bottom) {
canvas.drawRoundRect(new RectF(mMargin, mMargin, mMargin + mDiameter, mMargin + mDiameter), canvas.drawRoundRect(new RectF(margin, margin, margin + diameter, margin + diameter),
mRadius, mRadius, paint); radius, radius, paint);
canvas.drawRoundRect(new RectF(right - mDiameter, bottom - mDiameter, right, bottom), mRadius, canvas.drawRoundRect(new RectF(right - diameter, bottom - diameter, right, bottom), radius,
mRadius, paint); radius, paint);
canvas.drawRect(new RectF(mMargin, mMargin + mRadius, right - mDiameter, bottom), paint); canvas.drawRect(new RectF(margin, margin + radius, right - diameter, bottom), paint);
canvas.drawRect(new RectF(mMargin + mDiameter, mMargin, right, bottom - mRadius), paint); canvas.drawRect(new RectF(margin + diameter, margin, right, bottom - radius), paint);
} }
private void drawDiagonalFromTopRightRoundRect(Canvas canvas, Paint paint, float right, private void drawDiagonalFromTopRightRoundRect(Canvas canvas, Paint paint, float right,
float bottom) { float bottom) {
canvas.drawRoundRect(new RectF(right - mDiameter, mMargin, right, mMargin + mDiameter), mRadius, canvas.drawRoundRect(new RectF(right - diameter, margin, right, margin + diameter), radius,
mRadius, paint); radius, paint);
canvas.drawRoundRect(new RectF(mMargin, bottom - mDiameter, mMargin + mDiameter, bottom), canvas.drawRoundRect(new RectF(margin, bottom - diameter, margin + diameter, bottom),
mRadius, mRadius, paint); radius, radius, paint);
canvas.drawRect(new RectF(mMargin, mMargin, right - mRadius, bottom - mRadius), paint); canvas.drawRect(new RectF(margin, margin, right - radius, bottom - radius), paint);
canvas.drawRect(new RectF(mMargin + mRadius, mMargin + mRadius, right, bottom), paint); canvas.drawRect(new RectF(margin + radius, margin + radius, right, bottom), paint);
} }
@Override public String getId() { @Override public String key() {
return "RoundedTransformation(radius=" + mRadius + ", margin=" + mMargin + ", diameter=" return "RoundedTransformation(radius=" + radius + ", margin=" + margin + ", diameter="
+ mDiameter + ", cornerType=" + mCornerType.name() + ")"; + diameter + ", cornerType=" + cornerType.name() + ")";
} }
} }

View File

@ -16,9 +16,6 @@ package jp.wasabeef.glide.transformations.gpu;
* limitations under the License. * limitations under the License.
*/ */
import android.content.Context;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import jp.co.cyberagent.android.gpuimage.GPUImageBrightnessFilter; import jp.co.cyberagent.android.gpuimage.GPUImageBrightnessFilter;
/** /**
@ -26,28 +23,20 @@ import jp.co.cyberagent.android.gpuimage.GPUImageBrightnessFilter;
*/ */
public class BrightnessFilterTransformation extends GPUFilterTransformation { public class BrightnessFilterTransformation extends GPUFilterTransformation {
private float mBrightness; private float brightness;
public BrightnessFilterTransformation(Context context) { public BrightnessFilterTransformation() {
this(context, Glide.get(context).getBitmapPool()); this(0.0f);
} }
public BrightnessFilterTransformation(Context context, BitmapPool pool) { public BrightnessFilterTransformation(float brightness) {
this(context, pool, 0.0f); super(new GPUImageBrightnessFilter());
} this.brightness = brightness;
public BrightnessFilterTransformation(Context context, float brightness) {
this(context, Glide.get(context).getBitmapPool(), brightness);
}
public BrightnessFilterTransformation(Context context, BitmapPool pool, float brightness) {
super(context, pool, new GPUImageBrightnessFilter());
mBrightness = brightness;
GPUImageBrightnessFilter filter = getFilter(); GPUImageBrightnessFilter filter = getFilter();
filter.setBrightness(mBrightness); filter.setBrightness(this.brightness);
} }
@Override public String getId() { @Override public String key() {
return "BrightnessFilterTransformation(brightness=" + mBrightness + ")"; return "BrightnessFilterTransformation(brightness=" + brightness + ")";
} }
} }

View File

@ -16,9 +16,6 @@ package jp.wasabeef.glide.transformations.gpu;
* limitations under the License. * limitations under the License.
*/ */
import android.content.Context;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import jp.co.cyberagent.android.gpuimage.GPUImageContrastFilter; import jp.co.cyberagent.android.gpuimage.GPUImageContrastFilter;
/** /**
@ -26,28 +23,20 @@ import jp.co.cyberagent.android.gpuimage.GPUImageContrastFilter;
*/ */
public class ContrastFilterTransformation extends GPUFilterTransformation { public class ContrastFilterTransformation extends GPUFilterTransformation {
private float mContrast; private float contrast;
public ContrastFilterTransformation(Context context) { public ContrastFilterTransformation() {
this(context, Glide.get(context).getBitmapPool()); this(1.0f);
} }
public ContrastFilterTransformation(Context context, BitmapPool pool) { public ContrastFilterTransformation(float contrast) {
this(context, pool, 1.0f); super(new GPUImageContrastFilter());
} this.contrast = contrast;
public ContrastFilterTransformation(Context context, float contrast) {
this(context, Glide.get(context).getBitmapPool(), contrast);
}
public ContrastFilterTransformation(Context context, BitmapPool pool, float contrast) {
super(context, pool, new GPUImageContrastFilter());
mContrast = contrast;
GPUImageContrastFilter filter = getFilter(); GPUImageContrastFilter filter = getFilter();
filter.setContrast(mContrast); filter.setContrast(this.contrast);
} }
@Override public String getId() { @Override public String key() {
return "ContrastFilterTransformation(contrast=" + mContrast + ")"; return "ContrastFilterTransformation(contrast=" + contrast + ")";
} }
} }

View File

@ -18,48 +18,34 @@ package jp.wasabeef.glide.transformations.gpu;
import android.content.Context; import android.content.Context;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import com.bumptech.glide.Glide; import android.support.annotation.NonNull;
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.GPUImage;
import jp.co.cyberagent.android.gpuimage.GPUImageFilter; import jp.co.cyberagent.android.gpuimage.GPUImageFilter;
import jp.wasabeef.glide.transformations.BitmapTransformation;
public class GPUFilterTransformation implements Transformation<Bitmap> { public class GPUFilterTransformation extends BitmapTransformation {
private Context mContext; private GPUImageFilter gpuImageFilter;
private BitmapPool mBitmapPool;
private GPUImageFilter mFilter; public GPUFilterTransformation(GPUImageFilter filter) {
this.gpuImageFilter = filter;
public GPUFilterTransformation(Context context, GPUImageFilter filter) {
this(context, Glide.get(context).getBitmapPool(), filter);
} }
public GPUFilterTransformation(Context context, BitmapPool pool, GPUImageFilter filter) { @Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
mContext = context.getApplicationContext(); @NonNull Bitmap toTransform, int outWidth, int outHeight) {
mBitmapPool = pool; GPUImage gpuImage = new GPUImage(context);
mFilter = filter; gpuImage.setImage(toTransform);
gpuImage.setFilter(gpuImageFilter);
return gpuImage.getBitmapWithFilterApplied();
} }
@Override @Override public String key() {
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(); return getClass().getSimpleName();
} }
@SuppressWarnings("unchecked") public <T> T getFilter() { @SuppressWarnings("unchecked") public <T> T getFilter() {
return (T) mFilter; return (T) gpuImageFilter;
} }
} }

View File

@ -16,9 +16,6 @@ package jp.wasabeef.glide.transformations.gpu;
* limitations under the License. * limitations under the License.
*/ */
import android.content.Context;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import jp.co.cyberagent.android.gpuimage.GPUImageColorInvertFilter; import jp.co.cyberagent.android.gpuimage.GPUImageColorInvertFilter;
/** /**
@ -26,15 +23,11 @@ import jp.co.cyberagent.android.gpuimage.GPUImageColorInvertFilter;
*/ */
public class InvertFilterTransformation extends GPUFilterTransformation { public class InvertFilterTransformation extends GPUFilterTransformation {
public InvertFilterTransformation(Context context) { public InvertFilterTransformation() {
this(context, Glide.get(context).getBitmapPool()); super(new GPUImageColorInvertFilter());
} }
public InvertFilterTransformation(Context context, BitmapPool pool) { @Override public String key() {
super(context, pool, new GPUImageColorInvertFilter());
}
@Override public String getId() {
return "InvertFilterTransformation()"; return "InvertFilterTransformation()";
} }
} }

View File

@ -16,9 +16,6 @@ package jp.wasabeef.glide.transformations.gpu;
* limitations under the License. * limitations under the License.
*/ */
import android.content.Context;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import jp.co.cyberagent.android.gpuimage.GPUImageKuwaharaFilter; import jp.co.cyberagent.android.gpuimage.GPUImageKuwaharaFilter;
/** /**
@ -29,28 +26,20 @@ import jp.co.cyberagent.android.gpuimage.GPUImageKuwaharaFilter;
*/ */
public class KuwaharaFilterTransformation extends GPUFilterTransformation { public class KuwaharaFilterTransformation extends GPUFilterTransformation {
private int mRadius; private int radius;
public KuwaharaFilterTransformation(Context context) { public KuwaharaFilterTransformation() {
this(context, Glide.get(context).getBitmapPool()); this(25);
} }
public KuwaharaFilterTransformation(Context context, BitmapPool pool) { public KuwaharaFilterTransformation(int radius) {
this(context, pool, 25); super(new GPUImageKuwaharaFilter());
} this.radius = radius;
public KuwaharaFilterTransformation(Context context, int radius) {
this(context, Glide.get(context).getBitmapPool(), radius);
}
public KuwaharaFilterTransformation(Context context, BitmapPool pool, int radius) {
super(context, pool, new GPUImageKuwaharaFilter());
mRadius = radius;
GPUImageKuwaharaFilter filter = getFilter(); GPUImageKuwaharaFilter filter = getFilter();
filter.setRadius(mRadius); filter.setRadius(this.radius);
} }
@Override public String getId() { @Override public String key() {
return "KuwaharaFilterTransformation(radius=" + mRadius + ")"; return "KuwaharaFilterTransformation(radius=" + radius + ")";
} }
} }

View File

@ -16,9 +16,6 @@ package jp.wasabeef.glide.transformations.gpu;
* limitations under the License. * limitations under the License.
*/ */
import android.content.Context;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import jp.co.cyberagent.android.gpuimage.GPUImagePixelationFilter; import jp.co.cyberagent.android.gpuimage.GPUImagePixelationFilter;
/** /**
@ -28,28 +25,20 @@ import jp.co.cyberagent.android.gpuimage.GPUImagePixelationFilter;
*/ */
public class PixelationFilterTransformation extends GPUFilterTransformation { public class PixelationFilterTransformation extends GPUFilterTransformation {
private float mPixel; private float pixel;
public PixelationFilterTransformation(Context context) { public PixelationFilterTransformation() {
this(context, Glide.get(context).getBitmapPool()); this(10f);
} }
public PixelationFilterTransformation(Context context, BitmapPool pool) { public PixelationFilterTransformation(float pixel) {
this(context, pool, 10f); super(new GPUImagePixelationFilter());
} this.pixel = pixel;
public PixelationFilterTransformation(Context context, float pixel) {
this(context, Glide.get(context).getBitmapPool(), pixel);
}
public PixelationFilterTransformation(Context context, BitmapPool pool, float pixel) {
super(context, pool, new GPUImagePixelationFilter());
mPixel = pixel;
GPUImagePixelationFilter filter = getFilter(); GPUImagePixelationFilter filter = getFilter();
filter.setPixel(mPixel); filter.setPixel(this.pixel);
} }
@Override public String getId() { @Override public String key() {
return "PixelationFilterTransformation(pixel=" + mPixel + ")"; return "PixelationFilterTransformation(pixel=" + pixel + ")";
} }
} }

View File

@ -16,9 +16,6 @@ package jp.wasabeef.glide.transformations.gpu;
* limitations under the License. * limitations under the License.
*/ */
import android.content.Context;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import jp.co.cyberagent.android.gpuimage.GPUImageSepiaFilter; import jp.co.cyberagent.android.gpuimage.GPUImageSepiaFilter;
/** /**
@ -28,28 +25,20 @@ import jp.co.cyberagent.android.gpuimage.GPUImageSepiaFilter;
*/ */
public class SepiaFilterTransformation extends GPUFilterTransformation { public class SepiaFilterTransformation extends GPUFilterTransformation {
private float mIntensity; private float intensity;
public SepiaFilterTransformation(Context context) { public SepiaFilterTransformation() {
this(context, Glide.get(context).getBitmapPool()); this(1.0f);
} }
public SepiaFilterTransformation(Context context, BitmapPool pool) { public SepiaFilterTransformation(float intensity) {
this(context, pool, 1.0f); super(new GPUImageSepiaFilter());
} this.intensity = intensity;
public SepiaFilterTransformation(Context context, float intensity) {
this(context, Glide.get(context).getBitmapPool(), intensity);
}
public SepiaFilterTransformation(Context context, BitmapPool pool, float intensity) {
super(context, pool, new GPUImageSepiaFilter());
mIntensity = intensity;
GPUImageSepiaFilter filter = getFilter(); GPUImageSepiaFilter filter = getFilter();
filter.setIntensity(mIntensity); filter.setIntensity(this.intensity);
} }
@Override public String getId() { @Override public String key() {
return "SepiaFilterTransformation(intensity=" + mIntensity + ")"; return "SepiaFilterTransformation(intensity=" + intensity + ")";
} }
} }

View File

@ -16,22 +16,15 @@ package jp.wasabeef.glide.transformations.gpu;
* limitations under the License. * limitations under the License.
*/ */
import android.content.Context;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import jp.co.cyberagent.android.gpuimage.GPUImageSketchFilter; import jp.co.cyberagent.android.gpuimage.GPUImageSketchFilter;
public class SketchFilterTransformation extends GPUFilterTransformation { public class SketchFilterTransformation extends GPUFilterTransformation {
public SketchFilterTransformation(Context context) { public SketchFilterTransformation() {
this(context, Glide.get(context).getBitmapPool()); super(new GPUImageSketchFilter());
} }
public SketchFilterTransformation(Context context, BitmapPool pool) { @Override public String key() {
super(context, pool, new GPUImageSketchFilter());
}
@Override public String getId() {
return "SketchFilterTransformation()"; return "SketchFilterTransformation()";
} }
} }

View File

@ -16,10 +16,7 @@ package jp.wasabeef.glide.transformations.gpu;
* limitations under the License. * limitations under the License.
*/ */
import android.content.Context;
import android.graphics.PointF; import android.graphics.PointF;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import jp.co.cyberagent.android.gpuimage.GPUImageSwirlFilter; import jp.co.cyberagent.android.gpuimage.GPUImageSwirlFilter;
/** /**
@ -27,20 +24,12 @@ import jp.co.cyberagent.android.gpuimage.GPUImageSwirlFilter;
*/ */
public class SwirlFilterTransformation extends GPUFilterTransformation { public class SwirlFilterTransformation extends GPUFilterTransformation {
private float mRadius; private float radius;
private float mAngle; private float angle;
private PointF mCenter; private PointF center;
public SwirlFilterTransformation(Context context) { public SwirlFilterTransformation() {
this(context, Glide.get(context).getBitmapPool()); this(.5f, 1.0f, new PointF(0.5f, 0.5f));
}
public SwirlFilterTransformation(Context context, BitmapPool pool) {
this(context, pool, .5f, 1.0f, new PointF(0.5f, 0.5f));
}
public SwirlFilterTransformation(Context context, float radius, float angle, PointF center) {
this(context, Glide.get(context).getBitmapPool(), radius, angle, center);
} }
/** /**
@ -48,20 +37,19 @@ public class SwirlFilterTransformation extends GPUFilterTransformation {
* @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, float radius, float angle, public SwirlFilterTransformation(float radius, float angle, PointF center) {
PointF center) { super(new GPUImageSwirlFilter());
super(context, pool, new GPUImageSwirlFilter()); this.radius = radius;
mRadius = radius; this.angle = angle;
mAngle = angle; this.center = center;
mCenter = center;
GPUImageSwirlFilter filter = getFilter(); GPUImageSwirlFilter filter = getFilter();
filter.setRadius(mRadius); filter.setRadius(this.radius);
filter.setAngle(mAngle); filter.setAngle(this.angle);
filter.setCenter(mCenter); filter.setCenter(this.center);
} }
@Override public String getId() { @Override public String key() {
return "SwirlFilterTransformation(radius=" + mRadius + return "SwirlFilterTransformation(radius=" + radius +
",angle=" + mAngle + ",center=" + mCenter.toString() + ")"; ",angle=" + angle + ",center=" + center.toString() + ")";
} }
} }

View File

@ -16,9 +16,6 @@ package jp.wasabeef.glide.transformations.gpu;
* limitations under the License. * limitations under the License.
*/ */
import android.content.Context;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import jp.co.cyberagent.android.gpuimage.GPUImageToonFilter; import jp.co.cyberagent.android.gpuimage.GPUImageToonFilter;
/** /**
@ -28,33 +25,24 @@ import jp.co.cyberagent.android.gpuimage.GPUImageToonFilter;
*/ */
public class ToonFilterTransformation extends GPUFilterTransformation { public class ToonFilterTransformation extends GPUFilterTransformation {
private float mThreshold; private float threshold;
private float mQuantizationLevels; private float quantizationLevels;
public ToonFilterTransformation(Context context) { public ToonFilterTransformation() {
this(context, Glide.get(context).getBitmapPool()); this(.2f, 10.0f);
} }
public ToonFilterTransformation(Context context, BitmapPool pool) { public ToonFilterTransformation(float threshold, float quantizationLevels) {
this(context, pool, .2f, 10.0f); super(new GPUImageToonFilter());
} this.threshold = threshold;
this.quantizationLevels = quantizationLevels;
public ToonFilterTransformation(Context context, float threshold, float quantizationLevels) {
this(context, Glide.get(context).getBitmapPool(), threshold, quantizationLevels);
}
public ToonFilterTransformation(Context context, BitmapPool pool, float threshold,
float quantizationLevels) {
super(context, pool, new GPUImageToonFilter());
mThreshold = threshold;
mQuantizationLevels = quantizationLevels;
GPUImageToonFilter filter = getFilter(); GPUImageToonFilter filter = getFilter();
filter.setThreshold(mThreshold); filter.setThreshold(this.threshold);
filter.setQuantizationLevels(mQuantizationLevels); filter.setQuantizationLevels(this.quantizationLevels);
} }
@Override public String getId() { @Override public String key() {
return "ToonFilterTransformation(threshold=" + mThreshold + return "ToonFilterTransformation(threshold=" + threshold +
",quantizationLevels=" + mQuantizationLevels + ")"; ",quantizationLevels=" + quantizationLevels + ")";
} }
} }

View File

@ -16,10 +16,7 @@ package jp.wasabeef.glide.transformations.gpu;
* limitations under the License. * limitations under the License.
*/ */
import android.content.Context;
import android.graphics.PointF; import android.graphics.PointF;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import java.util.Arrays; import java.util.Arrays;
import jp.co.cyberagent.android.gpuimage.GPUImageVignetteFilter; import jp.co.cyberagent.android.gpuimage.GPUImageVignetteFilter;
@ -30,41 +27,31 @@ import jp.co.cyberagent.android.gpuimage.GPUImageVignetteFilter;
*/ */
public class VignetteFilterTransformation extends GPUFilterTransformation { public class VignetteFilterTransformation extends GPUFilterTransformation {
private PointF mCenter; private PointF center;
private float[] mVignetteColor; private float[] vignetteColor;
private float mVignetteStart; private float vignetteStart;
private float mVignetteEnd; private float vignetteEnd;
public VignetteFilterTransformation(Context context) { public VignetteFilterTransformation() {
this(context, Glide.get(context).getBitmapPool()); this(new PointF(0.5f, 0.5f), new float[] { 0.0f, 0.0f, 0.0f }, 0.0f, 0.75f);
} }
public VignetteFilterTransformation(Context context, BitmapPool pool) { public VignetteFilterTransformation(PointF center, float[] color, float start, float end) {
this(context, pool, new PointF(0.5f, 0.5f), new float[] { 0.0f, 0.0f, 0.0f }, 0.0f, 0.75f); super(new GPUImageVignetteFilter());
} this.center = center;
vignetteColor = color;
public VignetteFilterTransformation(Context context, PointF center, float[] color, float start, vignetteStart = start;
float end) { vignetteEnd = end;
this(context, Glide.get(context).getBitmapPool(), center, color, start, end);
}
public VignetteFilterTransformation(Context context, BitmapPool pool, PointF center,
float[] color, float start, float end) {
super(context, pool, new GPUImageVignetteFilter());
mCenter = center;
mVignetteColor = color;
mVignetteStart = start;
mVignetteEnd = end;
GPUImageVignetteFilter filter = getFilter(); GPUImageVignetteFilter filter = getFilter();
filter.setVignetteCenter(mCenter); filter.setVignetteCenter(this.center);
filter.setVignetteColor(mVignetteColor); filter.setVignetteColor(vignetteColor);
filter.setVignetteStart(mVignetteStart); filter.setVignetteStart(vignetteStart);
filter.setVignetteEnd(mVignetteEnd); filter.setVignetteEnd(vignetteEnd);
} }
@Override public String getId() { @Override public String key() {
return "VignetteFilterTransformation(center=" + mCenter.toString() + return "VignetteFilterTransformation(center=" + center.toString() +
",color=" + Arrays.toString(mVignetteColor) + ",color=" + Arrays.toString(vignetteColor) +
",start=" + mVignetteStart + ",end=" + mVignetteEnd + ")"; ",start=" + vignetteStart + ",end=" + vignetteEnd + ")";
} }
} }