From 817b1389806f3af1ed53ca461c5bff7919d525bf Mon Sep 17 00:00:00 2001 From: wasabeef Date: Wed, 2 Mar 2016 22:51:54 +0900 Subject: [PATCH 1/2] Say v8.RenderScript goodbye --- example/build.gradle | 4 -- .../wasabeef/example/glide/MainAdapter.java | 2 +- gradle.properties | 4 +- transformations/build.gradle | 4 -- transformations/proguard-rules.txt | 6 --- .../transformations/BlurTransformation.java | 33 ++++-------- .../transformations/internal/FastBlur.java | 2 +- .../transformations/internal/RSBlur.java | 54 +++++++++++++++++++ 8 files changed, 67 insertions(+), 42 deletions(-) create mode 100644 transformations/src/main/java/jp/wasabeef/glide/transformations/internal/RSBlur.java diff --git a/example/build.gradle b/example/build.gradle index baeeb35..ce030c0 100644 --- a/example/build.gradle +++ b/example/build.gradle @@ -9,10 +9,6 @@ android { targetSdkVersion TARGET_SDK_VERSION as int versionCode "git rev-list origin/master --count".execute().text.toInteger() versionName VERSION_NAME - - // Warning:Renderscript support mode is not currently supported with renderscript target 21+ - renderscriptTargetApi RENDERSCRIPT_TARGET_API as int - renderscriptSupportModeEnabled true } signingConfigs { diff --git a/example/src/main/java/jp/wasabeef/example/glide/MainAdapter.java b/example/src/main/java/jp/wasabeef/example/glide/MainAdapter.java index df5743e..cf626db 100644 --- a/example/src/main/java/jp/wasabeef/example/glide/MainAdapter.java +++ b/example/src/main/java/jp/wasabeef/example/glide/MainAdapter.java @@ -152,7 +152,7 @@ public class MainAdapter extends RecyclerView.Adapter { case Blur: Glide.with(mContext) .load(R.drawable.check) - .bitmapTransform(new BlurTransformation(mContext, 25, 1)) + .bitmapTransform(new BlurTransformation(mContext, 25)) .into(holder.image); break; case Toon: diff --git a/gradle.properties b/gradle.properties index b0550a2..deb4c55 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,12 +1,10 @@ -VERSION_NAME=1.4.0 +VERSION_NAME=2.0.0 GROUP=jp.wasabeef ARTIFACT_ID=glide-transformations COMPILE_SDK_VERSION=23 BUILD_TOOLS_VERSION=23.0.2 TARGET_SDK_VERSION=23 -# Warning:Renderscript support mode is not currently supported with renderscript target 21+ -RENDERSCRIPT_TARGET_API=20 MIN_SDK_VERSION=11 POM_DESCRIPTION=which provides simple Tranformations to Glide diff --git a/transformations/build.gradle b/transformations/build.gradle index 8955d0a..7c90c62 100644 --- a/transformations/build.gradle +++ b/transformations/build.gradle @@ -11,10 +11,6 @@ android { versionCode "git rev-list origin/master --count".execute().text.toInteger() 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' } } diff --git a/transformations/proguard-rules.txt b/transformations/proguard-rules.txt index 3fbf1d4..32ba203 100644 --- a/transformations/proguard-rules.txt +++ b/transformations/proguard-rules.txt @@ -1,7 +1 @@ --keepclasseswithmembernames class * { - native ; -} - --keep class android.support.v8.renderscript.** { *; } - -dontwarn jp.co.cyberagent.android.gpuimage.** \ No newline at end of file diff --git a/transformations/src/main/java/jp/wasabeef/glide/transformations/BlurTransformation.java b/transformations/src/main/java/jp/wasabeef/glide/transformations/BlurTransformation.java index 0690bbe..3e96989 100644 --- a/transformations/src/main/java/jp/wasabeef/glide/transformations/BlurTransformation.java +++ b/transformations/src/main/java/jp/wasabeef/glide/transformations/BlurTransformation.java @@ -20,17 +20,15 @@ import android.content.Context; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Paint; -import android.support.v8.renderscript.Allocation; -import android.support.v8.renderscript.Element; -import android.support.v8.renderscript.RSRuntimeException; -import android.support.v8.renderscript.RenderScript; -import android.support.v8.renderscript.ScriptIntrinsicBlur; +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 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 { @@ -90,25 +88,14 @@ public class BlurTransformation implements Transformation { paint.setFlags(Paint.FILTER_BITMAP_FLAG); canvas.drawBitmap(source, 0, 0, paint); - RenderScript rs = null; - try { - rs = RenderScript.create(mContext); - 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(mRadius); - blur.forEach(output); - output.copyTo(bitmap); - } catch (RSRuntimeException e) { - bitmap = FastBlur.doBlur(bitmap, mRadius, true); - } finally { - if (rs != null) { - rs.destroy(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { + try { + bitmap = RSBlur.blur(mContext, bitmap, mRadius); + } catch (RSRuntimeException e) { + bitmap = FastBlur.blur(bitmap, mRadius, true); } + } else { + bitmap = FastBlur.blur(bitmap, mRadius, true); } return BitmapResource.obtain(bitmap, mBitmapPool); diff --git a/transformations/src/main/java/jp/wasabeef/glide/transformations/internal/FastBlur.java b/transformations/src/main/java/jp/wasabeef/glide/transformations/internal/FastBlur.java index f8abca9..b9543f1 100644 --- a/transformations/src/main/java/jp/wasabeef/glide/transformations/internal/FastBlur.java +++ b/transformations/src/main/java/jp/wasabeef/glide/transformations/internal/FastBlur.java @@ -20,7 +20,7 @@ import android.graphics.Bitmap; 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 // http://www.quasimondo.com/StackBlurForCanvas/StackBlurDemo.html diff --git a/transformations/src/main/java/jp/wasabeef/glide/transformations/internal/RSBlur.java b/transformations/src/main/java/jp/wasabeef/glide/transformations/internal/RSBlur.java new file mode 100644 index 0000000..f8617b0 --- /dev/null +++ b/transformations/src/main/java/jp/wasabeef/glide/transformations/internal/RSBlur.java @@ -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; + } +} From 68bafb0f53f0bcff6d28ec1daed16481a858864c Mon Sep 17 00:00:00 2001 From: wasabeef Date: Wed, 2 Mar 2016 23:09:31 +0900 Subject: [PATCH 2/2] bump up 2.0.0 --- CHANGELOG.md | 5 +++++ README.md | 19 ++----------------- gradle.properties | 2 +- 3 files changed, 8 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index adb19a5..bb49272 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ Change Log ========== +Version 2.0.0 *(2016-03-02)* +---------------------------- + +Say v8.RenderScript goodbye + Version 1.4.0 *(2016-02-28)* ---------------------------- diff --git a/README.md b/README.md index 2140339..8e65c8e 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ repositories { } dependencies { - compile 'jp.wasabeef:glide-transformations:1.4.0' + compile 'jp.wasabeef:glide-transformations:2.0.0' // If you want to use the GPU Filters compile 'jp.co.cyberagent.android.gpuimage:gpuimage-library:1.3.0' } @@ -55,25 +55,10 @@ You can set a multiple transformations. ```java Glide.with(this).load(R.drawable.demo) - .bitmapTransform(new BlurTransformation(context, 25, 2), new CropCircleTransformation(context)) + .bitmapTransform(new BlurTransformation(context, 25), new CropCircleTransformation(context)) .into((ImageView) findViewById(R.id.image)); ``` -## Step 4 - -If you are using `BlurTransformation`. - -```groovy -android { - ... - defaultConfig { - // Warning:Renderscript support mode is not currently supported with renderscript target 21+ - renderscriptTargetApi 20 - renderscriptSupportModeEnabled true - } -} -``` - ## Transformations ### Crop diff --git a/gradle.properties b/gradle.properties index deb4c55..523c37c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -22,5 +22,5 @@ POM_DEVELOPER_URL=wasabeef.jp ISSUE_URL=https://github.com/wasabeef/glide-transformations/issues SUPPORT_PACKAGE_VERSION=23.1.1 -GLIDE_VERSION=3.6.1 +GLIDE_VERSION=3.7.0 GPUIMAGE_VERSION=1.3.0 \ No newline at end of file