Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d3785265 authored by Matthias Yzusqui's avatar Matthias Yzusqui Committed by Simon Shields
Browse files

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
Loading
Loading
Loading
Loading
+22 −13
Original line number Diff line number Diff line
@@ -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,6 +118,7 @@ public class BlurBitmapWorkerTask extends BitmapWorkerTask<String, Void, BlurBit

            // run the blur multiple times
            for (int i = 0; i < NUM_BLUR_RUNS; i++) {
                try {
                    final Allocation inputAlloc = Allocation.createFromBitmap(mRenderScript, input);
                    final Allocation outputAlloc = Allocation.createTyped(mRenderScript,
                            inputAlloc.getType());
@@ -127,6 +132,10 @@ public class BlurBitmapWorkerTask extends BitmapWorkerTask<String, Void, BlurBit

                    // 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