Search in sources :

Example 36 with RenderScript

use of android.renderscript.RenderScript in project Audient by komamj.

the class ImageUtils method createBlurredImageFromBitmap.

public static Drawable createBlurredImageFromBitmap(Bitmap bitmap, Context context, int inSampleSize) {
    RenderScript rs = RenderScript.create(context);
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inSampleSize = inSampleSize;
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
    byte[] imageInByte = stream.toByteArray();
    ByteArrayInputStream bis = new ByteArrayInputStream(imageInByte);
    Bitmap blurTemplate = BitmapFactory.decodeStream(bis, null, options);
    final Allocation input = Allocation.createFromBitmap(rs, blurTemplate);
    final Allocation output = Allocation.createTyped(rs, input.getType());
    final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
    script.setRadius(8f);
    script.setInput(input);
    script.forEach(output);
    output.copyTo(blurTemplate);
    return new BitmapDrawable(context.getResources(), blurTemplate);
}
Also used : RenderScript(android.renderscript.RenderScript) Bitmap(android.graphics.Bitmap) Allocation(android.renderscript.Allocation) ScriptIntrinsicBlur(android.renderscript.ScriptIntrinsicBlur) ByteArrayInputStream(java.io.ByteArrayInputStream) BitmapFactory(android.graphics.BitmapFactory) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BitmapDrawable(android.graphics.drawable.BitmapDrawable)

Example 37 with RenderScript

use of android.renderscript.RenderScript in project android_packages_apps_Gallery2 by LineageOS.

the class CachingPipeline method prepareRenderscriptAllocations.

public boolean prepareRenderscriptAllocations(Bitmap bitmap) {
    RenderScript RS = getRenderScriptContext();
    boolean needsUpdate = false;
    if (mOutPixelsAllocation == null || mInPixelsAllocation == null || bitmap.getWidth() != mWidth || bitmap.getHeight() != mHeight) {
        destroyPixelAllocations();
        Bitmap bitmapBuffer = bitmap;
        if (bitmap.getConfig() == null || bitmap.getConfig() != BITMAP_CONFIG) {
            bitmapBuffer = bitmap.copy(BITMAP_CONFIG, true);
        }
        mOutPixelsAllocation = Allocation.createFromBitmap(RS, bitmapBuffer, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
        mInPixelsAllocation = Allocation.createTyped(RS, mOutPixelsAllocation.getType());
        needsUpdate = true;
    }
    if (RS != null) {
        mInPixelsAllocation.copyFrom(bitmap);
    }
    if (bitmap.getWidth() != mWidth || bitmap.getHeight() != mHeight) {
        mWidth = bitmap.getWidth();
        mHeight = bitmap.getHeight();
        needsUpdate = true;
    }
    if (DEBUG) {
        Log.v(LOGTAG, "prepareRenderscriptAllocations: " + needsUpdate + " in " + getName());
    }
    return needsUpdate;
}
Also used : RenderScript(android.renderscript.RenderScript) Bitmap(android.graphics.Bitmap)

Example 38 with RenderScript

use of android.renderscript.RenderScript in project android_packages_apps_Gallery2 by LineageOS.

the class ImageFilterVignette method createFilter.

@Override
protected void createFilter(Resources res, float scaleFactor, int quality) {
    RenderScript rsCtx = getRenderScriptContext();
    mScript = new ScriptC_vignette(rsCtx);
}
Also used : RenderScript(android.renderscript.RenderScript)

Example 39 with RenderScript

use of android.renderscript.RenderScript in project android_packages_apps_Gallery2 by LineageOS.

the class ImageFilterGrad method checkStop.

private boolean checkStop() {
    RenderScript rsCtx = getRenderScriptContext();
    rsCtx.finish();
    if (getEnvironment().needsStop()) {
        return true;
    }
    return false;
}
Also used : RenderScript(android.renderscript.RenderScript)

Example 40 with RenderScript

use of android.renderscript.RenderScript in project android_packages_apps_Gallery2 by LineageOS.

the class ImageFilterGrad method createFilter.

@Override
protected void createFilter(android.content.res.Resources res, float scaleFactor, int quality, Allocation in) {
    RenderScript rsCtx = getRenderScriptContext();
    Type.Builder tb_float = new Type.Builder(rsCtx, Element.F32_4(rsCtx));
    tb_float.setX(in.getType().getX());
    tb_float.setY(in.getType().getY());
    mScript = new ScriptC_grad(rsCtx);
}
Also used : RenderScript(android.renderscript.RenderScript) Type(android.renderscript.Type)

Aggregations

RenderScript (android.renderscript.RenderScript)51 Allocation (android.renderscript.Allocation)44 ScriptIntrinsicBlur (android.renderscript.ScriptIntrinsicBlur)41 Bitmap (android.graphics.Bitmap)37 SuppressLint (android.annotation.SuppressLint)12 TargetApi (android.annotation.TargetApi)10 BitmapDrawable (android.graphics.drawable.BitmapDrawable)4 Type (android.renderscript.Type)4 BitmapFactory (android.graphics.BitmapFactory)3 Paint (android.graphics.Paint)3 RequiresApi (android.support.annotation.RequiresApi)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 Canvas (android.graphics.Canvas)2 ScriptIntrinsicYuvToRGB (android.renderscript.ScriptIntrinsicYuvToRGB)2 Point (android.graphics.Point)1 RSRuntimeException (android.renderscript.RSRuntimeException)1 Script (android.renderscript.Script)1 NonNull (androidx.annotation.NonNull)1 RequiresApi (androidx.annotation.RequiresApi)1