Search in sources :

Example 71 with Allocation

use of android.renderscript.Allocation in project Signal-Android by WhisperSystems.

the class UriGlideRenderer method blur.

@NonNull
private static Bitmap blur(Bitmap bitmap, Context context, float blurRadius) {
    Point previewSize = scaleKeepingAspectRatio(new Point(bitmap.getWidth(), bitmap.getHeight()), PREVIEW_DIMENSION_LIMIT);
    Point blurSize = scaleKeepingAspectRatio(new Point(previewSize.x / 2, previewSize.y / 2), MAX_BLUR_DIMENSION);
    Bitmap small = BitmapUtil.createScaledBitmap(bitmap, blurSize.x, blurSize.y);
    Log.d(TAG, "Bitmap: " + bitmap.getWidth() + "x" + bitmap.getHeight() + ", Blur: " + blurSize.x + "x" + blurSize.y);
    RenderScript rs = RenderScript.create(context);
    Allocation input = Allocation.createFromBitmap(rs, small);
    Allocation output = Allocation.createTyped(rs, input.getType());
    ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
    script.setRadius(blurRadius);
    script.setInput(input);
    script.forEach(output);
    Bitmap blurred = Bitmap.createBitmap(small.getWidth(), small.getHeight(), small.getConfig());
    output.copyTo(blurred);
    return blurred;
}
Also used : Bitmap(android.graphics.Bitmap) RenderScript(android.renderscript.RenderScript) Allocation(android.renderscript.Allocation) ScriptIntrinsicBlur(android.renderscript.ScriptIntrinsicBlur) Point(android.graphics.Point) NonNull(androidx.annotation.NonNull)

Aggregations

Allocation (android.renderscript.Allocation)71 Bitmap (android.graphics.Bitmap)42 RenderScript (android.renderscript.RenderScript)42 ScriptIntrinsicBlur (android.renderscript.ScriptIntrinsicBlur)41 SuppressLint (android.annotation.SuppressLint)14 RequiresApi (android.support.annotation.RequiresApi)14 TargetApi (android.annotation.TargetApi)10 Type (android.renderscript.Type)6 SdkConstantType (android.annotation.SdkConstant.SdkConstantType)5 Paint (android.graphics.Paint)4 BitmapDrawable (android.graphics.drawable.BitmapDrawable)4 BitmapFactory (android.graphics.BitmapFactory)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 Canvas (android.graphics.Canvas)2 Point (android.graphics.Point)2 Element (android.renderscript.Element)2 Script (android.renderscript.Script)2 RequiresApi (androidx.annotation.RequiresApi)2 ArrayList (java.util.ArrayList)2