mirror of
https://github.com/wasabeef/glide-transformations.git
synced 2025-06-08 23:44:04 +08:00
Say v8.RenderScript goodbye
This commit is contained in:
parent
a908abc7d4
commit
817b138980
@ -9,10 +9,6 @@ android {
|
|||||||
targetSdkVersion TARGET_SDK_VERSION as int
|
targetSdkVersion TARGET_SDK_VERSION as int
|
||||||
versionCode "git rev-list origin/master --count".execute().text.toInteger()
|
versionCode "git rev-list origin/master --count".execute().text.toInteger()
|
||||||
versionName VERSION_NAME
|
versionName VERSION_NAME
|
||||||
|
|
||||||
// Warning:Renderscript support mode is not currently supported with renderscript target 21+
|
|
||||||
renderscriptTargetApi RENDERSCRIPT_TARGET_API as int
|
|
||||||
renderscriptSupportModeEnabled true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
signingConfigs {
|
signingConfigs {
|
||||||
|
@ -152,7 +152,7 @@ public class MainAdapter extends RecyclerView.Adapter<MainAdapter.ViewHolder> {
|
|||||||
case Blur:
|
case Blur:
|
||||||
Glide.with(mContext)
|
Glide.with(mContext)
|
||||||
.load(R.drawable.check)
|
.load(R.drawable.check)
|
||||||
.bitmapTransform(new BlurTransformation(mContext, 25, 1))
|
.bitmapTransform(new BlurTransformation(mContext, 25))
|
||||||
.into(holder.image);
|
.into(holder.image);
|
||||||
break;
|
break;
|
||||||
case Toon:
|
case Toon:
|
||||||
|
@ -1,12 +1,10 @@
|
|||||||
VERSION_NAME=1.4.0
|
VERSION_NAME=2.0.0
|
||||||
GROUP=jp.wasabeef
|
GROUP=jp.wasabeef
|
||||||
ARTIFACT_ID=glide-transformations
|
ARTIFACT_ID=glide-transformations
|
||||||
|
|
||||||
COMPILE_SDK_VERSION=23
|
COMPILE_SDK_VERSION=23
|
||||||
BUILD_TOOLS_VERSION=23.0.2
|
BUILD_TOOLS_VERSION=23.0.2
|
||||||
TARGET_SDK_VERSION=23
|
TARGET_SDK_VERSION=23
|
||||||
# Warning:Renderscript support mode is not currently supported with renderscript target 21+
|
|
||||||
RENDERSCRIPT_TARGET_API=20
|
|
||||||
MIN_SDK_VERSION=11
|
MIN_SDK_VERSION=11
|
||||||
|
|
||||||
POM_DESCRIPTION=which provides simple Tranformations to Glide
|
POM_DESCRIPTION=which provides simple Tranformations to Glide
|
||||||
|
@ -11,10 +11,6 @@ android {
|
|||||||
versionCode "git rev-list origin/master --count".execute().text.toInteger()
|
versionCode "git rev-list origin/master --count".execute().text.toInteger()
|
||||||
versionName VERSION_NAME
|
versionName VERSION_NAME
|
||||||
|
|
||||||
// Warning:Renderscript support mode is not currently supported with renderscript target 21+
|
|
||||||
renderscriptTargetApi RENDERSCRIPT_TARGET_API as int
|
|
||||||
renderscriptSupportModeEnabled true
|
|
||||||
|
|
||||||
consumerProguardFiles 'proguard-rules.txt'
|
consumerProguardFiles 'proguard-rules.txt'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1 @@
|
|||||||
-keepclasseswithmembernames class * {
|
|
||||||
native <methods>;
|
|
||||||
}
|
|
||||||
|
|
||||||
-keep class android.support.v8.renderscript.** { *; }
|
|
||||||
|
|
||||||
-dontwarn jp.co.cyberagent.android.gpuimage.**
|
-dontwarn jp.co.cyberagent.android.gpuimage.**
|
@ -20,17 +20,15 @@ import android.content.Context;
|
|||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
import android.support.v8.renderscript.Allocation;
|
import android.os.Build;
|
||||||
import android.support.v8.renderscript.Element;
|
import android.renderscript.RSRuntimeException;
|
||||||
import android.support.v8.renderscript.RSRuntimeException;
|
|
||||||
import android.support.v8.renderscript.RenderScript;
|
|
||||||
import android.support.v8.renderscript.ScriptIntrinsicBlur;
|
|
||||||
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.Glide;
|
||||||
import com.bumptech.glide.load.Transformation;
|
import com.bumptech.glide.load.Transformation;
|
||||||
import com.bumptech.glide.load.engine.Resource;
|
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.BitmapResource;
|
||||||
import jp.wasabeef.glide.transformations.internal.FastBlur;
|
import jp.wasabeef.glide.transformations.internal.FastBlur;
|
||||||
|
import jp.wasabeef.glide.transformations.internal.RSBlur;
|
||||||
|
|
||||||
public class BlurTransformation implements Transformation<Bitmap> {
|
public class BlurTransformation implements Transformation<Bitmap> {
|
||||||
|
|
||||||
@ -90,25 +88,14 @@ public class BlurTransformation implements Transformation<Bitmap> {
|
|||||||
paint.setFlags(Paint.FILTER_BITMAP_FLAG);
|
paint.setFlags(Paint.FILTER_BITMAP_FLAG);
|
||||||
canvas.drawBitmap(source, 0, 0, paint);
|
canvas.drawBitmap(source, 0, 0, paint);
|
||||||
|
|
||||||
RenderScript rs = null;
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
|
||||||
try {
|
try {
|
||||||
rs = RenderScript.create(mContext);
|
bitmap = RSBlur.blur(mContext, bitmap, mRadius);
|
||||||
Allocation input =
|
} catch (RSRuntimeException e) {
|
||||||
Allocation.createFromBitmap(rs, bitmap, Allocation.MipmapControl.MIPMAP_NONE,
|
bitmap = FastBlur.blur(bitmap, mRadius, true);
|
||||||
Allocation.USAGE_SCRIPT);
|
|
||||||
Allocation output = Allocation.createTyped(rs, input.getType());
|
|
||||||
ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
|
|
||||||
|
|
||||||
blur.setInput(input);
|
|
||||||
blur.setRadius(mRadius);
|
|
||||||
blur.forEach(output);
|
|
||||||
output.copyTo(bitmap);
|
|
||||||
} catch (RSRuntimeException e) {
|
|
||||||
bitmap = FastBlur.doBlur(bitmap, mRadius, true);
|
|
||||||
} finally {
|
|
||||||
if (rs != null) {
|
|
||||||
rs.destroy();
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
bitmap = FastBlur.blur(bitmap, mRadius, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||||
|
@ -20,7 +20,7 @@ import android.graphics.Bitmap;
|
|||||||
|
|
||||||
public class FastBlur {
|
public class FastBlur {
|
||||||
|
|
||||||
public static Bitmap doBlur(Bitmap sentBitmap, int radius, boolean canReuseInBitmap) {
|
public static Bitmap blur(Bitmap sentBitmap, int radius, boolean canReuseInBitmap) {
|
||||||
|
|
||||||
// Stack Blur v1.0 from
|
// Stack Blur v1.0 from
|
||||||
// http://www.quasimondo.com/StackBlurForCanvas/StackBlurDemo.html
|
// http://www.quasimondo.com/StackBlurForCanvas/StackBlurDemo.html
|
||||||
|
@ -0,0 +1,54 @@
|
|||||||
|
package jp.wasabeef.glide.transformations.internal;
|
||||||
|
|
||||||
|
import android.annotation.TargetApi;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.os.Build;
|
||||||
|
import android.renderscript.Allocation;
|
||||||
|
import android.renderscript.Element;
|
||||||
|
import android.renderscript.RSRuntimeException;
|
||||||
|
import android.renderscript.RenderScript;
|
||||||
|
import android.renderscript.ScriptIntrinsicBlur;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copyright (C) 2015 Wasabeef
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class RSBlur {
|
||||||
|
|
||||||
|
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
|
||||||
|
public static Bitmap blur(Context context, Bitmap bitmap, int radius) throws RSRuntimeException {
|
||||||
|
RenderScript rs = null;
|
||||||
|
try {
|
||||||
|
rs = RenderScript.create(context);
|
||||||
|
Allocation input =
|
||||||
|
Allocation.createFromBitmap(rs, bitmap, Allocation.MipmapControl.MIPMAP_NONE,
|
||||||
|
Allocation.USAGE_SCRIPT);
|
||||||
|
Allocation output = Allocation.createTyped(rs, input.getType());
|
||||||
|
ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
|
||||||
|
|
||||||
|
blur.setInput(input);
|
||||||
|
blur.setRadius(radius);
|
||||||
|
blur.forEach(output);
|
||||||
|
output.copyTo(bitmap);
|
||||||
|
} finally {
|
||||||
|
if (rs != null) {
|
||||||
|
rs.destroy();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return bitmap;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user