Commit d3785265 authored by Matthias Yzusqui's avatar Matthias Yzusqui Committed by 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
parent 156ca6df
......@@ -23,6 +23,7 @@ import android.support.v8.renderscript.Allocation;
import android.support.v8.renderscript.Element;
import android.support.v8.renderscript.RenderScript;
import android.support.v8.renderscript.ScriptIntrinsicBlur;
import android.util.Log;
import android.widget.ImageView;
import org.lineageos.eleven.cache.ImageWorker.ImageType;
......@@ -35,6 +36,9 @@ import java.lang.ref.WeakReference;
* BlurScrimImage
*/
public class BlurBitmapWorkerTask extends BitmapWorkerTask<String, Void, BlurBitmapWorkerTask.ResultContainer> {
private static final String TAG = BlurBitmapWorkerTask.class.getSimpleName();
// if the image is too small, the blur will look bad post scale up so we use the min size
// to scale up before bluring
private static final int MIN_BITMAP_SIZE = 500;
......@@ -114,19 +118,24 @@ public class BlurBitmapWorkerTask extends BitmapWorkerTask<String, Void, BlurBit
// run the blur multiple times
for (int i = 0; i < NUM_BLUR_RUNS; i++) {
final Allocation inputAlloc = Allocation.createFromBitmap(mRenderScript, input);
final Allocation outputAlloc = Allocation.createTyped(mRenderScript,
inputAlloc.getType());
final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(mRenderScript,
Element.U8_4(mRenderScript));
script.setRadius(BLUR_RADIUS);
script.setInput(inputAlloc);
script.forEach(outputAlloc);
outputAlloc.copyTo(output);
// if we run more than 1 blur, the new input should be the old output
input = output;
try {
final Allocation inputAlloc = Allocation.createFromBitmap(mRenderScript, input);
final Allocation outputAlloc = Allocation.createTyped(mRenderScript,
inputAlloc.getType());
final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(mRenderScript,
Element.U8_4(mRenderScript));
script.setRadius(BLUR_RADIUS);
script.setInput(inputAlloc);
script.forEach(outputAlloc);
outputAlloc.copyTo(output);
// if we run more than 1 blur, the new input should be the old output
input = output;
} catch (RuntimeException e) {
Log.w(TAG, "Cannot blur image. " + e.getMessage());
break;
}
}
// Set the scrim color to be 50% gray
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment