mirror of
https://github.com/wasabeef/glide-transformations.git
synced 2025-06-29 21:02:47 +08:00
Support Glide 4.0.0 (#83)
This commit is contained in:
parent
1264e01f6e
commit
f6cbe2722d
11
CHANGELOG.md
11
CHANGELOG.md
@ -1,6 +1,17 @@
|
||||
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)*
|
||||
----------------------------
|
||||
|
||||
|
11
README.md
11
README.md
@ -32,7 +32,7 @@ repositories {
|
||||
}
|
||||
|
||||
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
|
||||
compile 'jp.co.cyberagent.android.gpuimage:gpuimage-library:1.4.1'
|
||||
}
|
||||
@ -44,8 +44,8 @@ Set Glide Transform.
|
||||
|
||||
```java
|
||||
Glide.with(this).load(R.drawable.demo)
|
||||
.bitmapTransform(new BlurTransformation(context))
|
||||
.into((ImageView) findViewById(R.id.image));
|
||||
.apply(bitmapTransform(new BlurTransformation(25)))
|
||||
.into((ImageView) findViewById(R.id.image));
|
||||
```
|
||||
|
||||
## Advanced Step 3
|
||||
@ -53,8 +53,11 @@ Glide.with(this).load(R.drawable.demo)
|
||||
You can set a multiple transformations.
|
||||
|
||||
```java
|
||||
MultiTransformation multi = new MultiTransformation(
|
||||
new BlurTransformation(25),
|
||||
new RoundedCornersTransformation(128, 0, RoundedCornersTransformation.CornerType.BOTTOM))))
|
||||
Glide.with(this).load(R.drawable.demo)
|
||||
.bitmapTransform(new BlurTransformation(context, 25), new CropCircleTransformation(context))
|
||||
.apply(bitmapTransform(multi))
|
||||
.into((ImageView) findViewById(R.id.image));
|
||||
```
|
||||
|
||||
|
@ -5,7 +5,7 @@ buildscript {
|
||||
jcenter()
|
||||
}
|
||||
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'
|
||||
}
|
||||
}
|
||||
|
@ -52,6 +52,7 @@ def getKeyAliasPasswordProperty() {
|
||||
dependencies {
|
||||
compile project(':transformations')
|
||||
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 "com.android.support:appcompat-v7:${SUPPORT_PACKAGE_VERSION}"
|
||||
compile "com.android.support:recyclerview-v7:${SUPPORT_PACKAGE_VERSION}"
|
||||
|
@ -1,22 +1,27 @@
|
||||
package jp.wasabeef.example.glide;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.PointF;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.MultiTransformation;
|
||||
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
|
||||
import com.bumptech.glide.request.RequestOptions;
|
||||
import java.util.List;
|
||||
import jp.wasabeef.glide.transformations.BlurTransformation;
|
||||
import jp.wasabeef.glide.transformations.ColorFilterTransformation;
|
||||
import jp.wasabeef.glide.transformations.CropCircleTransformation;
|
||||
import jp.wasabeef.glide.transformations.CropSquareTransformation;
|
||||
import jp.wasabeef.glide.transformations.CropTransformation;
|
||||
import jp.wasabeef.glide.transformations.CropTransformation.CropType;
|
||||
import jp.wasabeef.glide.transformations.GrayscaleTransformation;
|
||||
import jp.wasabeef.glide.transformations.MaskTransformation;
|
||||
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.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.
|
||||
*/
|
||||
public class MainAdapter extends RecyclerView.Adapter<MainAdapter.ViewHolder> {
|
||||
|
||||
private Context mContext;
|
||||
private List<Type> mDataSet;
|
||||
private Context context;
|
||||
private List<Type> dataSet;
|
||||
|
||||
enum Type {
|
||||
Mask,
|
||||
@ -64,165 +73,167 @@ public class MainAdapter extends RecyclerView.Adapter<MainAdapter.ViewHolder> {
|
||||
}
|
||||
|
||||
public MainAdapter(Context context, List<Type> dataSet) {
|
||||
mContext = context;
|
||||
mDataSet = dataSet;
|
||||
this.context = context;
|
||||
this.dataSet = dataSet;
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
@Override public void onBindViewHolder(MainAdapter.ViewHolder holder, int position) {
|
||||
switch (mDataSet.get(position)) {
|
||||
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
|
||||
switch (dataSet.get(position)) {
|
||||
case Mask: {
|
||||
int width = Utils.dip2px(mContext, 133.33f);
|
||||
int height = Utils.dip2px(mContext, 126.33f);
|
||||
Glide.with(mContext)
|
||||
int width = Utils.dip2px(context, 133.33f);
|
||||
int height = Utils.dip2px(context, 126.33f);
|
||||
Glide.with(context)
|
||||
.load(R.drawable.check)
|
||||
.override(width, height)
|
||||
.bitmapTransform(new CenterCrop(mContext),
|
||||
new MaskTransformation(mContext, R.drawable.mask_starfish))
|
||||
.apply(overrideOf(width, height))
|
||||
.apply(bitmapTransform(new MultiTransformation<>(new CenterCrop(), new MaskTransformation(R.drawable.mask_starfish))))
|
||||
.into(holder.image);
|
||||
break;
|
||||
}
|
||||
case NinePatchMask: {
|
||||
int width = Utils.dip2px(mContext, 150.0f);
|
||||
int height = Utils.dip2px(mContext, 100.0f);
|
||||
Glide.with(mContext)
|
||||
int width = Utils.dip2px(context, 150.0f);
|
||||
int height = Utils.dip2px(context, 100.0f);
|
||||
Glide.with(context)
|
||||
.load(R.drawable.check)
|
||||
.override(width, height)
|
||||
.bitmapTransform(new CenterCrop(mContext),
|
||||
new MaskTransformation(mContext, R.drawable.mask_chat_right))
|
||||
.apply(overrideOf(width, height))
|
||||
.apply(bitmapTransform(new MultiTransformation<>(new CenterCrop(), new MaskTransformation(R.drawable.mask_chat_right))))
|
||||
.into(holder.image);
|
||||
break;
|
||||
}
|
||||
case CropTop:
|
||||
Glide.with(mContext)
|
||||
Glide.with(context)
|
||||
.load(R.drawable.demo)
|
||||
.bitmapTransform(
|
||||
new CropTransformation(mContext, 300, 100, CropTransformation.CropType.TOP))
|
||||
.apply(bitmapTransform(
|
||||
new CropTransformation(Utils.dip2px(context, 300), Utils.dip2px(context, 100),
|
||||
CropType.TOP)))
|
||||
.into(holder.image);
|
||||
break;
|
||||
case CropCenter:
|
||||
Glide.with(mContext)
|
||||
Glide.with(context)
|
||||
.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);
|
||||
break;
|
||||
case CropBottom:
|
||||
Glide.with(mContext)
|
||||
Glide.with(context)
|
||||
.load(R.drawable.demo)
|
||||
.bitmapTransform(
|
||||
new CropTransformation(mContext, 300, 100, CropTransformation.CropType.BOTTOM))
|
||||
.apply(bitmapTransform(
|
||||
new CropTransformation(Utils.dip2px(context, 300), Utils.dip2px(context, 100),
|
||||
CropType.BOTTOM)))
|
||||
.into(holder.image);
|
||||
|
||||
break;
|
||||
case CropSquare:
|
||||
Glide.with(mContext)
|
||||
Glide.with(context)
|
||||
.load(R.drawable.demo)
|
||||
.bitmapTransform(new CropSquareTransformation(mContext))
|
||||
.apply(bitmapTransform(new CropSquareTransformation()))
|
||||
.into(holder.image);
|
||||
break;
|
||||
case CropCircle:
|
||||
Glide.with(mContext)
|
||||
Glide.with(context)
|
||||
.load(R.drawable.demo)
|
||||
.bitmapTransform(new CropCircleTransformation(mContext))
|
||||
.apply(bitmapTransform(new CropCircleTransformation()))
|
||||
.into(holder.image);
|
||||
break;
|
||||
case ColorFilter:
|
||||
Glide.with(mContext)
|
||||
Glide.with(context)
|
||||
.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);
|
||||
break;
|
||||
case Grayscale:
|
||||
Glide.with(mContext)
|
||||
Glide.with(context)
|
||||
.load(R.drawable.demo)
|
||||
.bitmapTransform(new GrayscaleTransformation(mContext))
|
||||
.apply(bitmapTransform(new GrayscaleTransformation()))
|
||||
.into(holder.image);
|
||||
break;
|
||||
case RoundedCorners:
|
||||
Glide.with(mContext)
|
||||
Glide.with(context)
|
||||
.load(R.drawable.demo)
|
||||
.bitmapTransform(new RoundedCornersTransformation(mContext, 30, 0,
|
||||
RoundedCornersTransformation.CornerType.BOTTOM))
|
||||
.apply(bitmapTransform(new RoundedCornersTransformation(45, 0,
|
||||
RoundedCornersTransformation.CornerType.BOTTOM)))
|
||||
.into(holder.image);
|
||||
break;
|
||||
case Blur:
|
||||
Glide.with(mContext)
|
||||
Glide.with(context)
|
||||
.load(R.drawable.check)
|
||||
.bitmapTransform(new BlurTransformation(mContext, 25))
|
||||
.apply(bitmapTransform(new BlurTransformation(25)))
|
||||
.into(holder.image);
|
||||
break;
|
||||
case Toon:
|
||||
Glide.with(mContext)
|
||||
Glide.with(context)
|
||||
.load(R.drawable.demo)
|
||||
.bitmapTransform(new ToonFilterTransformation(mContext))
|
||||
.apply(bitmapTransform(new ToonFilterTransformation()))
|
||||
.into(holder.image);
|
||||
break;
|
||||
case Sepia:
|
||||
Glide.with(mContext)
|
||||
Glide.with(context)
|
||||
.load(R.drawable.check)
|
||||
.bitmapTransform(new SepiaFilterTransformation(mContext))
|
||||
.apply(bitmapTransform(new SepiaFilterTransformation()))
|
||||
.into(holder.image);
|
||||
break;
|
||||
case Contrast:
|
||||
Glide.with(mContext)
|
||||
Glide.with(context)
|
||||
.load(R.drawable.check)
|
||||
.bitmapTransform(new ContrastFilterTransformation(mContext, 2.0f))
|
||||
.apply(bitmapTransform(new ContrastFilterTransformation(2.0f)))
|
||||
.into(holder.image);
|
||||
break;
|
||||
case Invert:
|
||||
Glide.with(mContext)
|
||||
Glide.with(context)
|
||||
.load(R.drawable.check)
|
||||
.bitmapTransform(new InvertFilterTransformation(mContext))
|
||||
.apply(bitmapTransform(new InvertFilterTransformation()))
|
||||
.into(holder.image);
|
||||
break;
|
||||
case Pixel:
|
||||
Glide.with(mContext)
|
||||
Glide.with(context)
|
||||
.load(R.drawable.check)
|
||||
.bitmapTransform(new PixelationFilterTransformation(mContext, 20))
|
||||
.apply(bitmapTransform(new PixelationFilterTransformation(20)))
|
||||
.into(holder.image);
|
||||
break;
|
||||
case Sketch:
|
||||
Glide.with(mContext)
|
||||
Glide.with(context)
|
||||
.load(R.drawable.check)
|
||||
.bitmapTransform(new SketchFilterTransformation(mContext))
|
||||
.apply(bitmapTransform(new SketchFilterTransformation()))
|
||||
.into(holder.image);
|
||||
break;
|
||||
case Swirl:
|
||||
Glide.with(mContext)
|
||||
Glide.with(context)
|
||||
.load(R.drawable.check)
|
||||
.bitmapTransform(
|
||||
new SwirlFilterTransformation(mContext, 0.5f, 1.0f, new PointF(0.5f, 0.5f)))
|
||||
.apply(bitmapTransform(
|
||||
new SwirlFilterTransformation(0.5f, 1.0f, new PointF(0.5f, 0.5f))).dontAnimate())
|
||||
.into(holder.image);
|
||||
break;
|
||||
case Brightness:
|
||||
Glide.with(mContext)
|
||||
Glide.with(context)
|
||||
.load(R.drawable.check)
|
||||
.bitmapTransform(new BrightnessFilterTransformation(mContext, 0.5f))
|
||||
.apply(bitmapTransform(new BrightnessFilterTransformation(0.5f)).dontAnimate())
|
||||
.into(holder.image);
|
||||
break;
|
||||
case Kuawahara:
|
||||
Glide.with(mContext)
|
||||
Glide.with(context)
|
||||
.load(R.drawable.check)
|
||||
.bitmapTransform(new KuwaharaFilterTransformation(mContext, 25))
|
||||
.apply(bitmapTransform(new KuwaharaFilterTransformation(25)).dontAnimate())
|
||||
.into(holder.image);
|
||||
break;
|
||||
case Vignette:
|
||||
Glide.with(mContext)
|
||||
Glide.with(context)
|
||||
.load(R.drawable.check)
|
||||
.bitmapTransform(new VignetteFilterTransformation(mContext, new PointF(0.5f, 0.5f),
|
||||
new float[] { 0.0f, 0.0f, 0.0f }, 0f, 0.75f))
|
||||
.apply(bitmapTransform(new VignetteFilterTransformation(new PointF(0.5f, 0.5f),
|
||||
new float[] { 0.0f, 0.0f, 0.0f }, 0f, 0.75f)).dontAnimate())
|
||||
.into(holder.image);
|
||||
break;
|
||||
}
|
||||
holder.title.setText(mDataSet.get(position).name());
|
||||
holder.title.setText(dataSet.get(position).name());
|
||||
}
|
||||
|
||||
@Override public int getItemCount() {
|
||||
return mDataSet.size();
|
||||
return dataSet.size();
|
||||
}
|
||||
|
||||
static class ViewHolder extends RecyclerView.ViewHolder {
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/image"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:contentDescription="@null"
|
||||
|
@ -1,11 +1,11 @@
|
||||
VERSION_NAME=2.0.2
|
||||
VERSION_NAME=3.0.0
|
||||
GROUP=jp.wasabeef
|
||||
ARTIFACT_ID=glide-transformations
|
||||
|
||||
COMPILE_SDK_VERSION=25
|
||||
BUILD_TOOLS_VERSION=25.0.2
|
||||
BUILD_TOOLS_VERSION=26.0.1
|
||||
TARGET_SDK_VERSION=25
|
||||
MIN_SDK_VERSION=11
|
||||
MIN_SDK_VERSION=14
|
||||
|
||||
POM_DESCRIPTION=which provides simple Tranformations to Glide
|
||||
POM_URL=https://github.com/wasabeef/glide-transformations
|
||||
@ -21,6 +21,6 @@ POM_DEVELOPER_EMAIL=dadadada.chop@gmail.com
|
||||
POM_DEVELOPER_URL=wasabeef.jp
|
||||
ISSUE_URL=https://github.com/wasabeef/glide-transformations/issues
|
||||
|
||||
SUPPORT_PACKAGE_VERSION=25.3.0
|
||||
GLIDE_VERSION=3.7.0
|
||||
SUPPORT_PACKAGE_VERSION=25.3.1
|
||||
GLIDE_VERSION=4.0.0
|
||||
GPUIMAGE_VERSION=1.4.1
|
@ -17,6 +17,7 @@ android {
|
||||
|
||||
dependencies {
|
||||
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}"
|
||||
}
|
||||
|
||||
|
@ -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
|
@ -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());
|
||||
}
|
||||
}
|
@ -22,86 +22,62 @@ import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.os.Build;
|
||||
import android.renderscript.RSRuntimeException;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.Transformation;
|
||||
import com.bumptech.glide.load.engine.Resource;
|
||||
import android.support.annotation.NonNull;
|
||||
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.RSBlur;
|
||||
|
||||
public class BlurTransformation implements Transformation<Bitmap> {
|
||||
public class BlurTransformation extends BitmapTransformation {
|
||||
|
||||
private static int MAX_RADIUS = 25;
|
||||
private static int DEFAULT_DOWN_SAMPLING = 1;
|
||||
|
||||
private Context mContext;
|
||||
private BitmapPool mBitmapPool;
|
||||
private int radius;
|
||||
private int sampling;
|
||||
|
||||
private int mRadius;
|
||||
private int mSampling;
|
||||
|
||||
public BlurTransformation(Context context) {
|
||||
this(context, Glide.get(context).getBitmapPool(), MAX_RADIUS, DEFAULT_DOWN_SAMPLING);
|
||||
public BlurTransformation() {
|
||||
this(MAX_RADIUS, DEFAULT_DOWN_SAMPLING);
|
||||
}
|
||||
|
||||
public BlurTransformation(Context context, BitmapPool pool) {
|
||||
this(context, pool, MAX_RADIUS, DEFAULT_DOWN_SAMPLING);
|
||||
public BlurTransformation(int radius) {
|
||||
this(radius, DEFAULT_DOWN_SAMPLING);
|
||||
}
|
||||
|
||||
public BlurTransformation(Context context, BitmapPool pool, int radius) {
|
||||
this(context, pool, radius, DEFAULT_DOWN_SAMPLING);
|
||||
public BlurTransformation(int radius, int sampling) {
|
||||
this.radius = radius;
|
||||
this.sampling = sampling;
|
||||
}
|
||||
|
||||
public BlurTransformation(Context context, int radius) {
|
||||
this(context, Glide.get(context).getBitmapPool(), radius, DEFAULT_DOWN_SAMPLING);
|
||||
}
|
||||
@Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
|
||||
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
|
||||
|
||||
public BlurTransformation(Context context, int radius, int sampling) {
|
||||
this(context, Glide.get(context).getBitmapPool(), radius, sampling);
|
||||
}
|
||||
int width = toTransform.getWidth();
|
||||
int height = toTransform.getHeight();
|
||||
int scaledWidth = width / sampling;
|
||||
int scaledHeight = height / sampling;
|
||||
|
||||
public BlurTransformation(Context context, BitmapPool pool, int radius, int sampling) {
|
||||
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);
|
||||
}
|
||||
Bitmap bitmap = pool.get(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
|
||||
|
||||
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.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) {
|
||||
try {
|
||||
bitmap = RSBlur.blur(mContext, bitmap, mRadius);
|
||||
bitmap = RSBlur.blur(context, bitmap, radius);
|
||||
} catch (RSRuntimeException e) {
|
||||
bitmap = FastBlur.blur(bitmap, mRadius, true);
|
||||
bitmap = FastBlur.blur(bitmap, radius, true);
|
||||
}
|
||||
} else {
|
||||
bitmap = FastBlur.blur(bitmap, mRadius, true);
|
||||
bitmap = FastBlur.blur(bitmap, radius, true);
|
||||
}
|
||||
|
||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
@Override public String getId() {
|
||||
return "BlurTransformation(radius=" + mRadius + ", sampling=" + mSampling + ")";
|
||||
@Override public String key() {
|
||||
return "BlurTransformation(radius=" + radius + ", sampling=" + sampling + ")";
|
||||
}
|
||||
}
|
||||
|
@ -22,51 +22,36 @@ import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.PorterDuffColorFilter;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.Transformation;
|
||||
import com.bumptech.glide.load.engine.Resource;
|
||||
import android.support.annotation.NonNull;
|
||||
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(Context context, int color) {
|
||||
this(Glide.get(context).getBitmapPool(), color);
|
||||
public ColorFilterTransformation(int color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public ColorFilterTransformation(BitmapPool pool, int color) {
|
||||
mBitmapPool = pool;
|
||||
mColor = color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
||||
Bitmap source = resource.get();
|
||||
|
||||
int width = source.getWidth();
|
||||
int height = source.getHeight();
|
||||
@Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
|
||||
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
|
||||
int width = toTransform.getWidth();
|
||||
int height = toTransform.getHeight();
|
||||
|
||||
Bitmap.Config config =
|
||||
source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
|
||||
Bitmap bitmap = mBitmapPool.get(width, height, config);
|
||||
if (bitmap == null) {
|
||||
bitmap = Bitmap.createBitmap(width, height, config);
|
||||
}
|
||||
toTransform.getConfig() != null ? toTransform.getConfig() : Bitmap.Config.ARGB_8888;
|
||||
Bitmap bitmap = pool.get(width, height, config);
|
||||
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
Paint paint = new Paint();
|
||||
paint.setAntiAlias(true);
|
||||
paint.setColorFilter(new PorterDuffColorFilter(mColor, PorterDuff.Mode.SRC_ATOP));
|
||||
canvas.drawBitmap(source, 0, 0, paint);
|
||||
paint.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP));
|
||||
canvas.drawBitmap(toTransform, 0, 0, paint);
|
||||
|
||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
@Override public String getId() {
|
||||
return "ColorFilterTransformation(color=" + mColor + ")";
|
||||
@Override public String key() {
|
||||
return "ColorFilterTransformation(color=" + color + ")";
|
||||
}
|
||||
}
|
||||
|
@ -18,61 +18,23 @@ package jp.wasabeef.glide.transformations;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapShader;
|
||||
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 android.support.annotation.NonNull;
|
||||
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;
|
||||
|
||||
public CropCircleTransformation(Context context) {
|
||||
this(Glide.get(context).getBitmapPool());
|
||||
@Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
|
||||
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
|
||||
return TransformationUtils.circleCrop(pool, toTransform, outWidth, outHeight);
|
||||
}
|
||||
|
||||
public CropCircleTransformation(BitmapPool pool) {
|
||||
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() {
|
||||
@Override public String key() {
|
||||
return "CropCircleTransformation()";
|
||||
}
|
||||
}
|
||||
|
@ -18,45 +18,21 @@ package jp.wasabeef.glide.transformations;
|
||||
|
||||
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 android.support.annotation.NonNull;
|
||||
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 mWidth;
|
||||
private int mHeight;
|
||||
private int size;
|
||||
|
||||
public CropSquareTransformation(Context context) {
|
||||
this(Glide.get(context).getBitmapPool());
|
||||
@Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
|
||||
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
|
||||
this.size = Math.max(outWidth, outHeight);
|
||||
return TransformationUtils.centerCrop(pool, toTransform, size, size);
|
||||
}
|
||||
|
||||
public CropSquareTransformation(BitmapPool pool) {
|
||||
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());
|
||||
|
||||
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 + ")";
|
||||
@Override public String key() {
|
||||
return "CropSquareTransformation(size=" + size + ")";
|
||||
}
|
||||
}
|
||||
|
@ -20,13 +20,10 @@ import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.RectF;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.Transformation;
|
||||
import com.bumptech.glide.load.engine.Resource;
|
||||
import android.support.annotation.NonNull;
|
||||
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 {
|
||||
TOP,
|
||||
@ -34,81 +31,62 @@ public class CropTransformation implements Transformation<Bitmap> {
|
||||
BOTTOM
|
||||
}
|
||||
|
||||
private BitmapPool mBitmapPool;
|
||||
private int mWidth;
|
||||
private int mHeight;
|
||||
private int width;
|
||||
private int height;
|
||||
|
||||
private CropType mCropType = CropType.CENTER;
|
||||
private CropType cropType = CropType.CENTER;
|
||||
|
||||
public CropTransformation(Context context) {
|
||||
this(Glide.get(context).getBitmapPool());
|
||||
public CropTransformation(int width, int height) {
|
||||
this(width, height, CropType.CENTER);
|
||||
}
|
||||
|
||||
public CropTransformation(BitmapPool pool) {
|
||||
this(pool, 0, 0);
|
||||
public CropTransformation(int width, int height, CropType cropType) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.cropType = cropType;
|
||||
}
|
||||
|
||||
public CropTransformation(Context context, int width, int height) {
|
||||
this(Glide.get(context).getBitmapPool(), width, height);
|
||||
}
|
||||
@Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
|
||||
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
|
||||
|
||||
public CropTransformation(BitmapPool pool, int width, int height) {
|
||||
this(pool, width, height, CropType.CENTER);
|
||||
}
|
||||
|
||||
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;
|
||||
width = width == 0 ? toTransform.getWidth() : width;
|
||||
height = height == 0 ? toTransform.getHeight() : height;
|
||||
|
||||
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(mWidth, mHeight, config);
|
||||
}
|
||||
toTransform.getConfig() != null ? toTransform.getConfig() : Bitmap.Config.ARGB_8888;
|
||||
Bitmap bitmap = pool.get(width, height, config);
|
||||
|
||||
float scaleX = (float) mWidth / source.getWidth();
|
||||
float scaleY = (float) mHeight / source.getHeight();
|
||||
bitmap.setHasAlpha(true);
|
||||
|
||||
float scaleX = (float) width / toTransform.getWidth();
|
||||
float scaleY = (float) height / toTransform.getHeight();
|
||||
float scale = Math.max(scaleX, scaleY);
|
||||
|
||||
float scaledWidth = scale * source.getWidth();
|
||||
float scaledHeight = scale * source.getHeight();
|
||||
float left = (mWidth - scaledWidth) / 2;
|
||||
float scaledWidth = scale * toTransform.getWidth();
|
||||
float scaledHeight = scale * toTransform.getHeight();
|
||||
float left = (width - scaledWidth) / 2;
|
||||
float top = getTop(scaledHeight);
|
||||
RectF targetRect = new RectF(left, top, left + scaledWidth, top + scaledHeight);
|
||||
|
||||
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() {
|
||||
return "CropTransformation(width=" + mWidth + ", height=" + mHeight + ", cropType=" + mCropType
|
||||
@Override public String key() {
|
||||
return "CropTransformation(width=" + width + ", height=" + height + ", cropType=" + cropType
|
||||
+ ")";
|
||||
}
|
||||
|
||||
private float getTop(float scaledHeight) {
|
||||
switch (mCropType) {
|
||||
switch (cropType) {
|
||||
case TOP:
|
||||
return 0;
|
||||
case CENTER:
|
||||
return (mHeight - scaledHeight) / 2;
|
||||
return (height - scaledHeight) / 2;
|
||||
case BOTTOM:
|
||||
return mHeight - scaledHeight;
|
||||
return height - scaledHeight;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
@ -22,49 +22,31 @@ import android.graphics.Canvas;
|
||||
import android.graphics.ColorMatrix;
|
||||
import android.graphics.ColorMatrixColorFilter;
|
||||
import android.graphics.Paint;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.Transformation;
|
||||
import com.bumptech.glide.load.engine.Resource;
|
||||
import android.support.annotation.NonNull;
|
||||
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;
|
||||
|
||||
public GrayscaleTransformation(Context context) {
|
||||
this(Glide.get(context).getBitmapPool());
|
||||
}
|
||||
|
||||
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();
|
||||
@Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
|
||||
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
|
||||
int width = toTransform.getWidth();
|
||||
int height = toTransform.getHeight();
|
||||
|
||||
Bitmap.Config config =
|
||||
source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
|
||||
Bitmap bitmap = mBitmapPool.get(width, height, config);
|
||||
if (bitmap == null) {
|
||||
bitmap = Bitmap.createBitmap(width, height, config);
|
||||
}
|
||||
toTransform.getConfig() != null ? toTransform.getConfig() : Bitmap.Config.ARGB_8888;
|
||||
Bitmap bitmap = pool.get(width, height, config);
|
||||
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
ColorMatrix saturation = new ColorMatrix();
|
||||
saturation.setSaturation(0f);
|
||||
Paint paint = new Paint();
|
||||
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()";
|
||||
}
|
||||
}
|
||||
|
@ -23,63 +23,47 @@ import android.graphics.Paint;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.PorterDuffXfermode;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.Transformation;
|
||||
import com.bumptech.glide.load.engine.Resource;
|
||||
import android.support.annotation.NonNull;
|
||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
|
||||
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 Context mContext;
|
||||
private BitmapPool mBitmapPool;
|
||||
private int mMaskId;
|
||||
private static Paint paint = new Paint();
|
||||
private int maskId;
|
||||
|
||||
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
|
||||
* 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.
|
||||
*/
|
||||
public MaskTransformation(Context context, int maskId) {
|
||||
this(context, Glide.get(context).getBitmapPool(), maskId);
|
||||
public MaskTransformation(int maskId) {
|
||||
this.maskId = maskId;
|
||||
}
|
||||
|
||||
public MaskTransformation(Context context, BitmapPool pool, int maskId) {
|
||||
mBitmapPool = pool;
|
||||
mContext = context.getApplicationContext();
|
||||
mMaskId = maskId;
|
||||
}
|
||||
@Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
|
||||
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
|
||||
int width = toTransform.getWidth();
|
||||
int height = toTransform.getHeight();
|
||||
|
||||
@Override
|
||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
||||
Bitmap source = resource.get();
|
||||
Bitmap bitmap = pool.get(width, height, Bitmap.Config.ARGB_8888);
|
||||
bitmap.setHasAlpha(true);
|
||||
|
||||
int width = source.getWidth();
|
||||
int height = source.getHeight();
|
||||
Drawable mask = Utils.getMaskDrawable(context.getApplicationContext(), maskId);
|
||||
|
||||
Bitmap result = mBitmapPool.get(width, height, Bitmap.Config.ARGB_8888);
|
||||
if (result == null) {
|
||||
result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
||||
}
|
||||
|
||||
Drawable mask = Utils.getMaskDrawable(mContext, mMaskId);
|
||||
|
||||
Canvas canvas = new Canvas(result);
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
mask.setBounds(0, 0, width, height);
|
||||
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() {
|
||||
return "MaskTransformation(maskId=" + mContext.getResources().getResourceEntryName(mMaskId)
|
||||
+ ")";
|
||||
@Override public String key() {
|
||||
return "MaskTransformation(maskId=" + maskId + ")";
|
||||
}
|
||||
}
|
||||
|
@ -23,13 +23,10 @@ import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.RectF;
|
||||
import android.graphics.Shader;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.Transformation;
|
||||
import com.bumptech.glide.load.engine.Resource;
|
||||
import android.support.annotation.NonNull;
|
||||
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 {
|
||||
ALL,
|
||||
@ -39,61 +36,45 @@ public class RoundedCornersTransformation implements Transformation<Bitmap> {
|
||||
DIAGONAL_FROM_TOP_LEFT, DIAGONAL_FROM_TOP_RIGHT
|
||||
}
|
||||
|
||||
private BitmapPool mBitmapPool;
|
||||
private int mRadius;
|
||||
private int mDiameter;
|
||||
private int mMargin;
|
||||
private CornerType mCornerType;
|
||||
private int radius;
|
||||
private int diameter;
|
||||
private int margin;
|
||||
private CornerType cornerType;
|
||||
|
||||
public RoundedCornersTransformation(Context context, int radius, int margin) {
|
||||
this(context, radius, margin, CornerType.ALL);
|
||||
public RoundedCornersTransformation(int radius, int margin) {
|
||||
this(radius, margin, CornerType.ALL);
|
||||
}
|
||||
|
||||
public RoundedCornersTransformation(BitmapPool pool, int radius, int margin) {
|
||||
this(pool, radius, margin, CornerType.ALL);
|
||||
public RoundedCornersTransformation(int radius, int margin, CornerType cornerType) {
|
||||
this.radius = radius;
|
||||
this.diameter = this.radius * 2;
|
||||
this.margin = margin;
|
||||
this.cornerType = cornerType;
|
||||
}
|
||||
|
||||
public RoundedCornersTransformation(Context context, int radius, int margin,
|
||||
CornerType cornerType) {
|
||||
this(Glide.get(context).getBitmapPool(), radius, margin, cornerType);
|
||||
}
|
||||
@Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
|
||||
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
|
||||
int width = toTransform.getWidth();
|
||||
int height = toTransform.getHeight();
|
||||
|
||||
public RoundedCornersTransformation(BitmapPool pool, int radius, int margin,
|
||||
CornerType cornerType) {
|
||||
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);
|
||||
}
|
||||
Bitmap bitmap = pool.get(width, height, Bitmap.Config.ARGB_8888);
|
||||
bitmap.setHasAlpha(true);
|
||||
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
Paint paint = new Paint();
|
||||
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);
|
||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
private void drawRoundRect(Canvas canvas, Paint paint, float width, float height) {
|
||||
float right = width - mMargin;
|
||||
float bottom = height - mMargin;
|
||||
float right = width - margin;
|
||||
float bottom = height - margin;
|
||||
|
||||
switch (mCornerType) {
|
||||
switch (cornerType) {
|
||||
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;
|
||||
case TOP_LEFT:
|
||||
drawTopLeftRoundRect(canvas, paint, right, bottom);
|
||||
@ -138,118 +119,118 @@ public class RoundedCornersTransformation implements Transformation<Bitmap> {
|
||||
drawDiagonalFromTopRightRoundRect(canvas, paint, right, bottom);
|
||||
break;
|
||||
default:
|
||||
canvas.drawRoundRect(new RectF(mMargin, mMargin, right, bottom), mRadius, mRadius, paint);
|
||||
canvas.drawRoundRect(new RectF(margin, margin, right, bottom), radius, radius, paint);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void drawTopLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
|
||||
canvas.drawRoundRect(new RectF(mMargin, mMargin, mMargin + mDiameter, mMargin + mDiameter),
|
||||
mRadius, mRadius, paint);
|
||||
canvas.drawRect(new RectF(mMargin, mMargin + mRadius, mMargin + mRadius, bottom), paint);
|
||||
canvas.drawRect(new RectF(mMargin + mRadius, mMargin, right, bottom), paint);
|
||||
canvas.drawRoundRect(new RectF(margin, margin, margin + diameter, margin + diameter),
|
||||
radius, radius, paint);
|
||||
canvas.drawRect(new RectF(margin, margin + radius, margin + radius, bottom), paint);
|
||||
canvas.drawRect(new RectF(margin + radius, margin, right, bottom), paint);
|
||||
}
|
||||
|
||||
private void drawTopRightRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
|
||||
canvas.drawRoundRect(new RectF(right - mDiameter, mMargin, right, mMargin + mDiameter), mRadius,
|
||||
mRadius, paint);
|
||||
canvas.drawRect(new RectF(mMargin, mMargin, right - mRadius, bottom), paint);
|
||||
canvas.drawRect(new RectF(right - mRadius, mMargin + mRadius, right, bottom), paint);
|
||||
canvas.drawRoundRect(new RectF(right - diameter, margin, right, margin + diameter), radius,
|
||||
radius, paint);
|
||||
canvas.drawRect(new RectF(margin, margin, right - radius, bottom), paint);
|
||||
canvas.drawRect(new RectF(right - radius, margin + radius, right, bottom), paint);
|
||||
}
|
||||
|
||||
private void drawBottomLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
|
||||
canvas.drawRoundRect(new RectF(mMargin, bottom - mDiameter, mMargin + mDiameter, bottom),
|
||||
mRadius, mRadius, paint);
|
||||
canvas.drawRect(new RectF(mMargin, mMargin, mMargin + mDiameter, bottom - mRadius), paint);
|
||||
canvas.drawRect(new RectF(mMargin + mRadius, mMargin, right, bottom), paint);
|
||||
canvas.drawRoundRect(new RectF(margin, bottom - diameter, margin + diameter, bottom),
|
||||
radius, radius, paint);
|
||||
canvas.drawRect(new RectF(margin, margin, margin + diameter, bottom - radius), paint);
|
||||
canvas.drawRect(new RectF(margin + radius, margin, right, bottom), paint);
|
||||
}
|
||||
|
||||
private void drawBottomRightRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
|
||||
canvas.drawRoundRect(new RectF(right - mDiameter, bottom - mDiameter, right, bottom), mRadius,
|
||||
mRadius, paint);
|
||||
canvas.drawRect(new RectF(mMargin, mMargin, right - mRadius, bottom), paint);
|
||||
canvas.drawRect(new RectF(right - mRadius, mMargin, right, bottom - mRadius), paint);
|
||||
canvas.drawRoundRect(new RectF(right - diameter, bottom - diameter, right, bottom), radius,
|
||||
radius, paint);
|
||||
canvas.drawRect(new RectF(margin, margin, right - radius, bottom), paint);
|
||||
canvas.drawRect(new RectF(right - radius, margin, right, bottom - radius), paint);
|
||||
}
|
||||
|
||||
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);
|
||||
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) {
|
||||
canvas.drawRoundRect(new RectF(mMargin, bottom - mDiameter, right, bottom), mRadius, mRadius,
|
||||
canvas.drawRoundRect(new RectF(margin, bottom - diameter, right, bottom), radius, radius,
|
||||
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) {
|
||||
canvas.drawRoundRect(new RectF(mMargin, mMargin, mMargin + mDiameter, bottom), mRadius, mRadius,
|
||||
canvas.drawRoundRect(new RectF(margin, margin, margin + diameter, bottom), radius, radius,
|
||||
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) {
|
||||
canvas.drawRoundRect(new RectF(right - mDiameter, mMargin, right, bottom), mRadius, mRadius,
|
||||
canvas.drawRoundRect(new RectF(right - diameter, margin, right, bottom), radius, radius,
|
||||
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) {
|
||||
canvas.drawRoundRect(new RectF(mMargin, bottom - mDiameter, right, bottom), mRadius, mRadius,
|
||||
canvas.drawRoundRect(new RectF(margin, bottom - diameter, right, bottom), radius, radius,
|
||||
paint);
|
||||
canvas.drawRoundRect(new RectF(right - mDiameter, mMargin, right, bottom), mRadius, mRadius,
|
||||
canvas.drawRoundRect(new RectF(right - diameter, margin, right, bottom), 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);
|
||||
}
|
||||
|
||||
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);
|
||||
canvas.drawRoundRect(new RectF(mMargin, bottom - mDiameter, right, bottom), mRadius, mRadius,
|
||||
canvas.drawRoundRect(new RectF(margin, bottom - diameter, right, bottom), radius, radius,
|
||||
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) {
|
||||
canvas.drawRoundRect(new RectF(mMargin, mMargin, right, mMargin + mDiameter), mRadius, mRadius,
|
||||
canvas.drawRoundRect(new RectF(margin, margin, right, margin + diameter), radius, radius,
|
||||
paint);
|
||||
canvas.drawRoundRect(new RectF(right - mDiameter, mMargin, right, bottom), mRadius, mRadius,
|
||||
canvas.drawRoundRect(new RectF(right - diameter, margin, right, bottom), radius, radius,
|
||||
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,
|
||||
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);
|
||||
canvas.drawRoundRect(new RectF(mMargin, mMargin, mMargin + mDiameter, bottom), mRadius, mRadius,
|
||||
canvas.drawRoundRect(new RectF(margin, margin, margin + diameter, bottom), radius, radius,
|
||||
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,
|
||||
float bottom) {
|
||||
canvas.drawRoundRect(new RectF(mMargin, mMargin, mMargin + mDiameter, mMargin + mDiameter),
|
||||
mRadius, mRadius, paint);
|
||||
canvas.drawRoundRect(new RectF(right - mDiameter, bottom - mDiameter, right, bottom), mRadius,
|
||||
mRadius, paint);
|
||||
canvas.drawRect(new RectF(mMargin, mMargin + mRadius, right - mDiameter, bottom), paint);
|
||||
canvas.drawRect(new RectF(mMargin + mDiameter, mMargin, right, bottom - mRadius), paint);
|
||||
canvas.drawRoundRect(new RectF(margin, margin, margin + diameter, margin + diameter),
|
||||
radius, radius, paint);
|
||||
canvas.drawRoundRect(new RectF(right - diameter, bottom - diameter, right, bottom), radius,
|
||||
radius, paint);
|
||||
canvas.drawRect(new RectF(margin, margin + radius, right - diameter, bottom), paint);
|
||||
canvas.drawRect(new RectF(margin + diameter, margin, right, bottom - radius), paint);
|
||||
}
|
||||
|
||||
private void drawDiagonalFromTopRightRoundRect(Canvas canvas, Paint paint, float right,
|
||||
float bottom) {
|
||||
canvas.drawRoundRect(new RectF(right - mDiameter, mMargin, right, mMargin + mDiameter), mRadius,
|
||||
mRadius, paint);
|
||||
canvas.drawRoundRect(new RectF(mMargin, bottom - mDiameter, mMargin + mDiameter, bottom),
|
||||
mRadius, mRadius, paint);
|
||||
canvas.drawRect(new RectF(mMargin, mMargin, right - mRadius, bottom - mRadius), paint);
|
||||
canvas.drawRect(new RectF(mMargin + mRadius, mMargin + mRadius, right, bottom), paint);
|
||||
canvas.drawRoundRect(new RectF(right - diameter, margin, right, margin + diameter), radius,
|
||||
radius, paint);
|
||||
canvas.drawRoundRect(new RectF(margin, bottom - diameter, margin + diameter, bottom),
|
||||
radius, radius, paint);
|
||||
canvas.drawRect(new RectF(margin, margin, right - radius, bottom - radius), paint);
|
||||
canvas.drawRect(new RectF(margin + radius, margin + radius, right, bottom), paint);
|
||||
}
|
||||
|
||||
@Override public String getId() {
|
||||
return "RoundedTransformation(radius=" + mRadius + ", margin=" + mMargin + ", diameter="
|
||||
+ mDiameter + ", cornerType=" + mCornerType.name() + ")";
|
||||
@Override public String key() {
|
||||
return "RoundedTransformation(radius=" + radius + ", margin=" + margin + ", diameter="
|
||||
+ diameter + ", cornerType=" + cornerType.name() + ")";
|
||||
}
|
||||
}
|
||||
|
@ -16,9 +16,6 @@ package jp.wasabeef.glide.transformations.gpu;
|
||||
* 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;
|
||||
|
||||
/**
|
||||
@ -26,28 +23,20 @@ import jp.co.cyberagent.android.gpuimage.GPUImageBrightnessFilter;
|
||||
*/
|
||||
public class BrightnessFilterTransformation extends GPUFilterTransformation {
|
||||
|
||||
private float mBrightness;
|
||||
private float brightness;
|
||||
|
||||
public BrightnessFilterTransformation(Context context) {
|
||||
this(context, Glide.get(context).getBitmapPool());
|
||||
public BrightnessFilterTransformation() {
|
||||
this(0.0f);
|
||||
}
|
||||
|
||||
public BrightnessFilterTransformation(Context context, BitmapPool pool) {
|
||||
this(context, pool, 0.0f);
|
||||
}
|
||||
|
||||
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;
|
||||
public BrightnessFilterTransformation(float brightness) {
|
||||
super(new GPUImageBrightnessFilter());
|
||||
this.brightness = brightness;
|
||||
GPUImageBrightnessFilter filter = getFilter();
|
||||
filter.setBrightness(mBrightness);
|
||||
filter.setBrightness(this.brightness);
|
||||
}
|
||||
|
||||
@Override public String getId() {
|
||||
return "BrightnessFilterTransformation(brightness=" + mBrightness + ")";
|
||||
@Override public String key() {
|
||||
return "BrightnessFilterTransformation(brightness=" + brightness + ")";
|
||||
}
|
||||
}
|
||||
|
@ -16,9 +16,6 @@ package jp.wasabeef.glide.transformations.gpu;
|
||||
* 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;
|
||||
|
||||
/**
|
||||
@ -26,28 +23,20 @@ import jp.co.cyberagent.android.gpuimage.GPUImageContrastFilter;
|
||||
*/
|
||||
public class ContrastFilterTransformation extends GPUFilterTransformation {
|
||||
|
||||
private float mContrast;
|
||||
private float contrast;
|
||||
|
||||
public ContrastFilterTransformation(Context context) {
|
||||
this(context, Glide.get(context).getBitmapPool());
|
||||
public ContrastFilterTransformation() {
|
||||
this(1.0f);
|
||||
}
|
||||
|
||||
public ContrastFilterTransformation(Context context, BitmapPool pool) {
|
||||
this(context, pool, 1.0f);
|
||||
}
|
||||
|
||||
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;
|
||||
public ContrastFilterTransformation(float contrast) {
|
||||
super(new GPUImageContrastFilter());
|
||||
this.contrast = contrast;
|
||||
GPUImageContrastFilter filter = getFilter();
|
||||
filter.setContrast(mContrast);
|
||||
filter.setContrast(this.contrast);
|
||||
}
|
||||
|
||||
@Override public String getId() {
|
||||
return "ContrastFilterTransformation(contrast=" + mContrast + ")";
|
||||
@Override public String key() {
|
||||
return "ContrastFilterTransformation(contrast=" + contrast + ")";
|
||||
}
|
||||
}
|
||||
|
@ -18,48 +18,34 @@ package jp.wasabeef.glide.transformations.gpu;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.Transformation;
|
||||
import com.bumptech.glide.load.engine.Resource;
|
||||
import android.support.annotation.NonNull;
|
||||
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;
|
||||
import jp.wasabeef.glide.transformations.BitmapTransformation;
|
||||
|
||||
public class GPUFilterTransformation implements Transformation<Bitmap> {
|
||||
public class GPUFilterTransformation extends BitmapTransformation {
|
||||
|
||||
private Context mContext;
|
||||
private BitmapPool mBitmapPool;
|
||||
private GPUImageFilter gpuImageFilter;
|
||||
|
||||
private GPUImageFilter mFilter;
|
||||
|
||||
public GPUFilterTransformation(Context context, GPUImageFilter filter) {
|
||||
this(context, Glide.get(context).getBitmapPool(), filter);
|
||||
public GPUFilterTransformation(GPUImageFilter filter) {
|
||||
this.gpuImageFilter = filter;
|
||||
}
|
||||
|
||||
public GPUFilterTransformation(Context context, BitmapPool pool, GPUImageFilter filter) {
|
||||
mContext = context.getApplicationContext();
|
||||
mBitmapPool = pool;
|
||||
mFilter = filter;
|
||||
@Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
|
||||
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
|
||||
GPUImage gpuImage = new GPUImage(context);
|
||||
gpuImage.setImage(toTransform);
|
||||
gpuImage.setFilter(gpuImageFilter);
|
||||
|
||||
return gpuImage.getBitmapWithFilterApplied();
|
||||
}
|
||||
|
||||
@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() {
|
||||
@Override public String key() {
|
||||
return getClass().getSimpleName();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked") public <T> T getFilter() {
|
||||
return (T) mFilter;
|
||||
return (T) gpuImageFilter;
|
||||
}
|
||||
}
|
||||
|
@ -16,9 +16,6 @@ package jp.wasabeef.glide.transformations.gpu;
|
||||
* 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;
|
||||
|
||||
/**
|
||||
@ -26,15 +23,11 @@ import jp.co.cyberagent.android.gpuimage.GPUImageColorInvertFilter;
|
||||
*/
|
||||
public class InvertFilterTransformation extends GPUFilterTransformation {
|
||||
|
||||
public InvertFilterTransformation(Context context) {
|
||||
this(context, Glide.get(context).getBitmapPool());
|
||||
public InvertFilterTransformation() {
|
||||
super(new GPUImageColorInvertFilter());
|
||||
}
|
||||
|
||||
public InvertFilterTransformation(Context context, BitmapPool pool) {
|
||||
super(context, pool, new GPUImageColorInvertFilter());
|
||||
}
|
||||
|
||||
@Override public String getId() {
|
||||
@Override public String key() {
|
||||
return "InvertFilterTransformation()";
|
||||
}
|
||||
}
|
||||
|
@ -16,9 +16,6 @@ package jp.wasabeef.glide.transformations.gpu;
|
||||
* 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;
|
||||
|
||||
/**
|
||||
@ -29,28 +26,20 @@ import jp.co.cyberagent.android.gpuimage.GPUImageKuwaharaFilter;
|
||||
*/
|
||||
public class KuwaharaFilterTransformation extends GPUFilterTransformation {
|
||||
|
||||
private int mRadius;
|
||||
private int radius;
|
||||
|
||||
public KuwaharaFilterTransformation(Context context) {
|
||||
this(context, Glide.get(context).getBitmapPool());
|
||||
public KuwaharaFilterTransformation() {
|
||||
this(25);
|
||||
}
|
||||
|
||||
public KuwaharaFilterTransformation(Context context, BitmapPool pool) {
|
||||
this(context, pool, 25);
|
||||
}
|
||||
|
||||
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;
|
||||
public KuwaharaFilterTransformation(int radius) {
|
||||
super(new GPUImageKuwaharaFilter());
|
||||
this.radius = radius;
|
||||
GPUImageKuwaharaFilter filter = getFilter();
|
||||
filter.setRadius(mRadius);
|
||||
filter.setRadius(this.radius);
|
||||
}
|
||||
|
||||
@Override public String getId() {
|
||||
return "KuwaharaFilterTransformation(radius=" + mRadius + ")";
|
||||
@Override public String key() {
|
||||
return "KuwaharaFilterTransformation(radius=" + radius + ")";
|
||||
}
|
||||
}
|
||||
|
@ -16,9 +16,6 @@ package jp.wasabeef.glide.transformations.gpu;
|
||||
* 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;
|
||||
|
||||
/**
|
||||
@ -28,28 +25,20 @@ import jp.co.cyberagent.android.gpuimage.GPUImagePixelationFilter;
|
||||
*/
|
||||
public class PixelationFilterTransformation extends GPUFilterTransformation {
|
||||
|
||||
private float mPixel;
|
||||
private float pixel;
|
||||
|
||||
public PixelationFilterTransformation(Context context) {
|
||||
this(context, Glide.get(context).getBitmapPool());
|
||||
public PixelationFilterTransformation() {
|
||||
this(10f);
|
||||
}
|
||||
|
||||
public PixelationFilterTransformation(Context context, BitmapPool pool) {
|
||||
this(context, pool, 10f);
|
||||
}
|
||||
|
||||
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;
|
||||
public PixelationFilterTransformation(float pixel) {
|
||||
super(new GPUImagePixelationFilter());
|
||||
this.pixel = pixel;
|
||||
GPUImagePixelationFilter filter = getFilter();
|
||||
filter.setPixel(mPixel);
|
||||
filter.setPixel(this.pixel);
|
||||
}
|
||||
|
||||
@Override public String getId() {
|
||||
return "PixelationFilterTransformation(pixel=" + mPixel + ")";
|
||||
@Override public String key() {
|
||||
return "PixelationFilterTransformation(pixel=" + pixel + ")";
|
||||
}
|
||||
}
|
||||
|
@ -16,9 +16,6 @@ package jp.wasabeef.glide.transformations.gpu;
|
||||
* 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;
|
||||
|
||||
/**
|
||||
@ -28,28 +25,20 @@ import jp.co.cyberagent.android.gpuimage.GPUImageSepiaFilter;
|
||||
*/
|
||||
public class SepiaFilterTransformation extends GPUFilterTransformation {
|
||||
|
||||
private float mIntensity;
|
||||
private float intensity;
|
||||
|
||||
public SepiaFilterTransformation(Context context) {
|
||||
this(context, Glide.get(context).getBitmapPool());
|
||||
public SepiaFilterTransformation() {
|
||||
this(1.0f);
|
||||
}
|
||||
|
||||
public SepiaFilterTransformation(Context context, BitmapPool pool) {
|
||||
this(context, pool, 1.0f);
|
||||
}
|
||||
|
||||
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;
|
||||
public SepiaFilterTransformation(float intensity) {
|
||||
super(new GPUImageSepiaFilter());
|
||||
this.intensity = intensity;
|
||||
GPUImageSepiaFilter filter = getFilter();
|
||||
filter.setIntensity(mIntensity);
|
||||
filter.setIntensity(this.intensity);
|
||||
}
|
||||
|
||||
@Override public String getId() {
|
||||
return "SepiaFilterTransformation(intensity=" + mIntensity + ")";
|
||||
@Override public String key() {
|
||||
return "SepiaFilterTransformation(intensity=" + intensity + ")";
|
||||
}
|
||||
}
|
||||
|
@ -16,22 +16,15 @@ package jp.wasabeef.glide.transformations.gpu;
|
||||
* 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;
|
||||
|
||||
public class SketchFilterTransformation extends GPUFilterTransformation {
|
||||
|
||||
public SketchFilterTransformation(Context context) {
|
||||
this(context, Glide.get(context).getBitmapPool());
|
||||
public SketchFilterTransformation() {
|
||||
super(new GPUImageSketchFilter());
|
||||
}
|
||||
|
||||
public SketchFilterTransformation(Context context, BitmapPool pool) {
|
||||
super(context, pool, new GPUImageSketchFilter());
|
||||
}
|
||||
|
||||
@Override public String getId() {
|
||||
@Override public String key() {
|
||||
return "SketchFilterTransformation()";
|
||||
}
|
||||
}
|
||||
|
@ -16,10 +16,7 @@ package jp.wasabeef.glide.transformations.gpu;
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import android.content.Context;
|
||||
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;
|
||||
|
||||
/**
|
||||
@ -27,20 +24,12 @@ import jp.co.cyberagent.android.gpuimage.GPUImageSwirlFilter;
|
||||
*/
|
||||
public class SwirlFilterTransformation extends GPUFilterTransformation {
|
||||
|
||||
private float mRadius;
|
||||
private float mAngle;
|
||||
private PointF mCenter;
|
||||
private float radius;
|
||||
private float angle;
|
||||
private PointF center;
|
||||
|
||||
public SwirlFilterTransformation(Context context) {
|
||||
this(context, Glide.get(context).getBitmapPool());
|
||||
}
|
||||
|
||||
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);
|
||||
public SwirlFilterTransformation() {
|
||||
this(.5f, 1.0f, new PointF(0.5f, 0.5f));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -48,20 +37,19 @@ public class SwirlFilterTransformation extends GPUFilterTransformation {
|
||||
* @param angle minimum 0.0, default 1.0
|
||||
* @param center default (0.5, 0.5)
|
||||
*/
|
||||
public SwirlFilterTransformation(Context context, BitmapPool pool, float radius, float angle,
|
||||
PointF center) {
|
||||
super(context, pool, new GPUImageSwirlFilter());
|
||||
mRadius = radius;
|
||||
mAngle = angle;
|
||||
mCenter = center;
|
||||
public SwirlFilterTransformation(float radius, float angle, PointF center) {
|
||||
super(new GPUImageSwirlFilter());
|
||||
this.radius = radius;
|
||||
this.angle = angle;
|
||||
this.center = center;
|
||||
GPUImageSwirlFilter filter = getFilter();
|
||||
filter.setRadius(mRadius);
|
||||
filter.setAngle(mAngle);
|
||||
filter.setCenter(mCenter);
|
||||
filter.setRadius(this.radius);
|
||||
filter.setAngle(this.angle);
|
||||
filter.setCenter(this.center);
|
||||
}
|
||||
|
||||
@Override public String getId() {
|
||||
return "SwirlFilterTransformation(radius=" + mRadius +
|
||||
",angle=" + mAngle + ",center=" + mCenter.toString() + ")";
|
||||
@Override public String key() {
|
||||
return "SwirlFilterTransformation(radius=" + radius +
|
||||
",angle=" + angle + ",center=" + center.toString() + ")";
|
||||
}
|
||||
}
|
||||
|
@ -16,9 +16,6 @@ package jp.wasabeef.glide.transformations.gpu;
|
||||
* 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;
|
||||
|
||||
/**
|
||||
@ -28,33 +25,24 @@ import jp.co.cyberagent.android.gpuimage.GPUImageToonFilter;
|
||||
*/
|
||||
public class ToonFilterTransformation extends GPUFilterTransformation {
|
||||
|
||||
private float mThreshold;
|
||||
private float mQuantizationLevels;
|
||||
private float threshold;
|
||||
private float quantizationLevels;
|
||||
|
||||
public ToonFilterTransformation(Context context) {
|
||||
this(context, Glide.get(context).getBitmapPool());
|
||||
public ToonFilterTransformation() {
|
||||
this(.2f, 10.0f);
|
||||
}
|
||||
|
||||
public ToonFilterTransformation(Context context, BitmapPool pool) {
|
||||
this(context, pool, .2f, 10.0f);
|
||||
}
|
||||
|
||||
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;
|
||||
public ToonFilterTransformation(float threshold, float quantizationLevels) {
|
||||
super(new GPUImageToonFilter());
|
||||
this.threshold = threshold;
|
||||
this.quantizationLevels = quantizationLevels;
|
||||
GPUImageToonFilter filter = getFilter();
|
||||
filter.setThreshold(mThreshold);
|
||||
filter.setQuantizationLevels(mQuantizationLevels);
|
||||
filter.setThreshold(this.threshold);
|
||||
filter.setQuantizationLevels(this.quantizationLevels);
|
||||
}
|
||||
|
||||
@Override public String getId() {
|
||||
return "ToonFilterTransformation(threshold=" + mThreshold +
|
||||
",quantizationLevels=" + mQuantizationLevels + ")";
|
||||
@Override public String key() {
|
||||
return "ToonFilterTransformation(threshold=" + threshold +
|
||||
",quantizationLevels=" + quantizationLevels + ")";
|
||||
}
|
||||
}
|
||||
|
@ -16,10 +16,7 @@ package jp.wasabeef.glide.transformations.gpu;
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.PointF;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||
import java.util.Arrays;
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImageVignetteFilter;
|
||||
|
||||
@ -30,41 +27,31 @@ import jp.co.cyberagent.android.gpuimage.GPUImageVignetteFilter;
|
||||
*/
|
||||
public class VignetteFilterTransformation extends GPUFilterTransformation {
|
||||
|
||||
private PointF mCenter;
|
||||
private float[] mVignetteColor;
|
||||
private float mVignetteStart;
|
||||
private float mVignetteEnd;
|
||||
private PointF center;
|
||||
private float[] vignetteColor;
|
||||
private float vignetteStart;
|
||||
private float vignetteEnd;
|
||||
|
||||
public VignetteFilterTransformation(Context context) {
|
||||
this(context, Glide.get(context).getBitmapPool());
|
||||
public VignetteFilterTransformation() {
|
||||
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) {
|
||||
this(context, pool, new PointF(0.5f, 0.5f), new float[] { 0.0f, 0.0f, 0.0f }, 0.0f, 0.75f);
|
||||
}
|
||||
|
||||
public VignetteFilterTransformation(Context context, PointF center, float[] color, float start,
|
||||
float 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;
|
||||
public VignetteFilterTransformation(PointF center, float[] color, float start, float end) {
|
||||
super(new GPUImageVignetteFilter());
|
||||
this.center = center;
|
||||
vignetteColor = color;
|
||||
vignetteStart = start;
|
||||
vignetteEnd = end;
|
||||
GPUImageVignetteFilter filter = getFilter();
|
||||
filter.setVignetteCenter(mCenter);
|
||||
filter.setVignetteColor(mVignetteColor);
|
||||
filter.setVignetteStart(mVignetteStart);
|
||||
filter.setVignetteEnd(mVignetteEnd);
|
||||
filter.setVignetteCenter(this.center);
|
||||
filter.setVignetteColor(vignetteColor);
|
||||
filter.setVignetteStart(vignetteStart);
|
||||
filter.setVignetteEnd(vignetteEnd);
|
||||
}
|
||||
|
||||
@Override public String getId() {
|
||||
return "VignetteFilterTransformation(center=" + mCenter.toString() +
|
||||
",color=" + Arrays.toString(mVignetteColor) +
|
||||
",start=" + mVignetteStart + ",end=" + mVignetteEnd + ")";
|
||||
@Override public String key() {
|
||||
return "VignetteFilterTransformation(center=" + center.toString() +
|
||||
",color=" + Arrays.toString(vignetteColor) +
|
||||
",start=" + vignetteStart + ",end=" + vignetteEnd + ")";
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user