8000 Say v8.RenderScript goodbye · coder0728/glide-transformations@817b138 · GitHub
[go: up one dir, main page]

Skip to content

Commit 817b138

Browse files
committed
Say v8.RenderScript goodbye
1 parent a908abc commit 817b138

File tree

8 files changed

+67
-42
lines changed

8 files changed

+67
-42
lines changed

example/build.gradle

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ android {
99
targetSdkVersion TARGET_SDK_VERSION as int
1010
versionCode "git rev-list origin/master --count".execute().text.toInteger()
1111
versionName VERSION_NAME
12-
13-
// Warning:Renderscript support mode is not currently supported with renderscript target 21+
14-
renderscriptTargetApi RENDERSCRIPT_TARGET_API as int
15-
renderscriptSupportModeEnabled true
1612
}
1713

1814
signingConfigs {

example/src/main/java/jp/wasabeef/example/glide/MainAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public MainAdapter(Context context, List<Type> dataSet) {
152152
case Blur:
153153
Glide.with(mContext)
154154
.load(R.drawable.check)
155-
.bitmapTransform(new BlurTransformation(mContext, 25, 1))
155+
.bitmapTransform(new BlurTransformation(mContext, 25))
156156
.into(holder.image);
157157
break;
158158
case Toon:

gradle.properties

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
VERSION_NAME=1.4.0
1+
VERSION_NAME=2.0.0
22
GROUP=jp.wasabeef
33
ARTIFACT_ID=glide-transformations
44

55
COMPILE_SDK_VERSION=23
66
BUILD_TOOLS_VERSION=23.0.2
77
TARGET_SDK_VERSION=23
8-
# Warning:Renderscript support mode is not currently supported with renderscript target 21+
9-
RENDERSCRIPT_TARGET_API=20
108
MIN_SDK_VERSION=11
119

1210
POM_DESCRIPTION=which provides simple Tranformations to Glide

transformations/build.gradle

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ android {
1111
versionCode "git rev-list origin/master --count".execute().text.toInteger()
1212
versionName VERSION_NAME
1313

14-
// Warning:Renderscript support mode is not currently supported with renderscript target 21+
15-
renderscriptTargetApi RENDERSCRIPT_TARGET_API as int
16-
renderscriptSupportModeEnabled true
17-
1814
consumerProguardFiles 'proguard-rules.txt'
1915
}
2016
}

transformations/proguard-rules.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1 @@
1-
-keepclasseswithmembernames class * {
2-
native <methods>;
3-
}
4-
5-
-keep class android.support.v8.renderscript.** { *; }
6-
71
-dontwarn jp.co.cyberagent.android.gpuimage.**

transformations/src/main/java/jp/wasabeef/glide/transformations/BlurTransformation.java

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,15 @@
2020
import android.graphics.Bitmap;
2121
import android.graphics.Canvas;
2222
import android.graphics.Paint;
23-
import android.support.v8.renderscript.Allocation;
24-
import android.support.v8.renderscript.Element;
25-
import android.support.v8.renderscript.RSRuntimeException;
26-
import android.support.v8.renderscript.RenderScript;
27-
import android.support.v8.renderscript.ScriptIntrinsicBlur;
23+
import android.os.Build;
24+
import android.renderscript.RSRuntimeException;
2825
import com.bumptech.glide.Glide;
2926
import com.bumptech.glide.load.Transformation;
3027
import com.bumptech.glide.load.engine.Resource;
3128
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
3229
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
3330
import jp.wasabeef.glide.transformations.internal.FastBlur;
31+
import jp.wasabeef.glide.transformations.internal.RSBlur;
3432

3533
public class BlurTransformation implements Transformation<Bitmap> {
3634

@@ -90,25 +88,14 @@ public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int o
9088
paint.setFlags(Paint.FILTER_BITMAP_FLAG);
9189
canvas.drawBitmap(source, 0, 0, paint);
9290

93-
RenderScript rs = null;
94-
try {
95-
rs = RenderScript.create(mContext);
96-
Allocation input =
97 9E88 -
Allocation.createFromBitmap(rs, bitmap, Allocation.MipmapControl.MIPMAP_NONE,
98-
Allocation.USAGE_SCRIPT);
99-
Allocation output = Allocation.createTyped(rs, input.getType());
100-
ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
101-
102-
blur.setInput(input);
103-
blur.setRadius(mRadius);
104-
blur.forEach(output);
105-
output.copyTo(bitmap);
106-
} catch (RSRuntimeException e) {
107-
bitmap = FastBlur.doBlur(bitmap, mRadius, true);
108-
} finally {
109-
if (rs != null) {
110-
rs.destroy();
91+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
92+
try {
93+
bitmap = RSBlur.blur(mContext, bitmap, mRadius);
94+
} catch (RSRuntimeException e) {
95+
bitmap = FastBlur.blur(bitmap, mRadius, true);
11196
}
97+
} else {
98+
bitmap = FastBlur.blur(bitmap, mRadius, true);
11299
}
113100

114101
return BitmapResource.obtain(bitmap, mBitmapPool);

transformations/src/main/java/jp/wasabeef/glide/transformations/internal/FastBlur.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
public class FastBlur {
2222

23-
public static Bitmap doBlur(Bitmap sentBitmap, int radius, boolean canReuseInBitmap) {
23+
public static Bitmap blur(Bitmap sentBitmap, int radius, boolean canReuseInBitmap) {
2424

2525
// Stack Blur v1.0 from
2626
// http://www.quasimondo.com/StackBlurForCanvas/StackBlurDemo.html
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package jp.wasabeef.glide.transformations.internal;
2+
3+
import android.annotation.TargetApi;
4+
import android.content.Context;
5+
import android.graphics.Bitmap;
6+
import android.os.Build;
7+
import android.renderscript.Allocation;
8+
import android.renderscript.Element;
9+
import android.renderscript.RSRuntimeException;
10+
import android.renderscript.RenderScript;
11+
import android.renderscript.ScriptIntrinsicBlur;
12+
13+
/**
14+
* Copyright (C) 2015 Wasabeef
15+
*
16+
* Licensed under the Apache License, Version 2.0 (the "License");
17+
* you may not use this file except in compliance with the License.
18+
* You may obtain a copy of the License at
19+
*
20+
* http://www.apache.org/licenses/LICENSE-2.0
21+
*
22+
* Unless required by applicable law or agreed to in writing, software
23+
* distributed under the License is distributed on an "AS IS" BASIS,
24+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25+
* See the License for the specific language governing permissions and
26+
* limitations under the License.
27+
*/
28+
29+
public class RSBlur {
30+
31+
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
32+
public static Bitmap blur(Context context, Bitmap bitmap, int radius) throws RSRuntimeException {
33+
RenderScript rs = null;
34+
try {
35+
rs = RenderScript.create(context);
36+
Allocation input =
37+
Allocation.createFromBitmap(rs, bitmap, Allocation.MipmapControl.MIPMAP_NONE,
38+
Allocation.USAGE_SCRIPT);
39+
Allocation output = Allocation.createTyped(rs, input.getType());
40+
ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
41+
42+
blur.setInput(input);
43+
blur.setRadius(radius);
44+
blur.forEach(output);
45+
output.copyTo(bitmap);
46+
} finally {
47+
if (rs != null) {
48+
rs.destroy();
49+
}
50+
}
51+
52+
return bitmap;
53+
}
54+
}

0 commit comments

Comments
 (0)
0