packages/apps/Eleven
Revision | d378526526f5ae93a99a89176ee0a2afc452a356 (tree) |
---|---|
Time | 2018-05-31 18:26:24 |
Author | Matthias Yzusqui <myzb.dev@gmai...> |
Commiter | Simon Shields |
Eleven: Catch unsupported bitmap exception
Android's renderscript allocation class only supports creating
elements from ALPHA_8, ARGB_4444, ARGB_8888 and RGB_565 bitmaps.
Change-Id: Ib3e40755e7eacd9725b97ae9ab4bde34c6eec70d
@@ -23,6 +23,7 @@ import android.support.v8.renderscript.Allocation; | ||
23 | 23 | import android.support.v8.renderscript.Element; |
24 | 24 | import android.support.v8.renderscript.RenderScript; |
25 | 25 | import android.support.v8.renderscript.ScriptIntrinsicBlur; |
26 | +import android.util.Log; | |
26 | 27 | import android.widget.ImageView; |
27 | 28 | |
28 | 29 | import org.lineageos.eleven.cache.ImageWorker.ImageType; |
@@ -35,6 +36,9 @@ import java.lang.ref.WeakReference; | ||
35 | 36 | * BlurScrimImage |
36 | 37 | */ |
37 | 38 | public class BlurBitmapWorkerTask extends BitmapWorkerTask<String, Void, BlurBitmapWorkerTask.ResultContainer> { |
39 | + | |
40 | + private static final String TAG = BlurBitmapWorkerTask.class.getSimpleName(); | |
41 | + | |
38 | 42 | // if the image is too small, the blur will look bad post scale up so we use the min size |
39 | 43 | // to scale up before bluring |
40 | 44 | private static final int MIN_BITMAP_SIZE = 500; |
@@ -114,19 +118,24 @@ public class BlurBitmapWorkerTask extends BitmapWorkerTask<String, Void, BlurBit | ||
114 | 118 | |
115 | 119 | // run the blur multiple times |
116 | 120 | for (int i = 0; i < NUM_BLUR_RUNS; i++) { |
117 | - final Allocation inputAlloc = Allocation.createFromBitmap(mRenderScript, input); | |
118 | - final Allocation outputAlloc = Allocation.createTyped(mRenderScript, | |
119 | - inputAlloc.getType()); | |
120 | - final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(mRenderScript, | |
121 | - Element.U8_4(mRenderScript)); | |
122 | - | |
123 | - script.setRadius(BLUR_RADIUS); | |
124 | - script.setInput(inputAlloc); | |
125 | - script.forEach(outputAlloc); | |
126 | - outputAlloc.copyTo(output); | |
127 | - | |
128 | - // if we run more than 1 blur, the new input should be the old output | |
129 | - input = output; | |
121 | + try { | |
122 | + final Allocation inputAlloc = Allocation.createFromBitmap(mRenderScript, input); | |
123 | + final Allocation outputAlloc = Allocation.createTyped(mRenderScript, | |
124 | + inputAlloc.getType()); | |
125 | + final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(mRenderScript, | |
126 | + Element.U8_4(mRenderScript)); | |
127 | + | |
128 | + script.setRadius(BLUR_RADIUS); | |
129 | + script.setInput(inputAlloc); | |
130 | + script.forEach(outputAlloc); | |
131 | + outputAlloc.copyTo(output); | |
132 | + | |
133 | + // if we run more than 1 blur, the new input should be the old output | |
134 | + input = output; | |
135 | + } catch (RuntimeException e) { | |
136 | + Log.w(TAG, "Cannot blur image. " + e.getMessage()); | |
137 | + break; | |
138 | + } | |
130 | 139 | } |
131 | 140 | |
132 | 141 | // Set the scrim color to be 50% gray |