Search in sources :

Example 26 with Allocation

use of android.renderscript.Allocation in project PolarrCameraAndroidSDK by Polarrco.

the class MainActivity method renderScriptNV21ToRGBA888.

public Allocation renderScriptNV21ToRGBA888(Context context, int width, int height, byte[] nv21) {
    RenderScript rs = RenderScript.create(context);
    ScriptIntrinsicYuvToRGB yuvToRgbIntrinsic = ScriptIntrinsicYuvToRGB.create(rs, Element.U8_4(rs));
    Type.Builder yuvType = new Type.Builder(rs, Element.U8(rs)).setX(nv21.length);
    Allocation in = Allocation.createTyped(rs, yuvType.create(), Allocation.USAGE_SCRIPT);
    Type.Builder rgbaType = new Type.Builder(rs, Element.RGBA_8888(rs)).setX(width).setY(height);
    Allocation out = Allocation.createTyped(rs, rgbaType.create(), Allocation.USAGE_SCRIPT);
    in.copyFrom(nv21);
    yuvToRgbIntrinsic.setInput(in);
    yuvToRgbIntrinsic.forEach(out);
    return out;
}
Also used : ScriptIntrinsicYuvToRGB(android.renderscript.ScriptIntrinsicYuvToRGB) RenderScript(android.renderscript.RenderScript) Type(android.renderscript.Type) Allocation(android.renderscript.Allocation)

Example 27 with Allocation

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

the class ImagePreset method applyBorder.

public void applyBorder(Allocation in, Allocation out, boolean copyOut, FilterEnvironment environment) {
    FilterRepresentation border = getFilterRepresentationForType(FilterRepresentation.TYPE_BORDER);
    if (border != null && mDoApplyGeometry) {
        // TODO: should keep the bitmap around
        Allocation bitmapIn = in;
        if (copyOut) {
            bitmapIn = Allocation.createTyped(CachingPipeline.getRenderScriptContext(), in.getType());
            bitmapIn.copyFrom(out);
        }
        environment.applyRepresentation(border, bitmapIn, out);
    }
}
Also used : Allocation(android.renderscript.Allocation) FilterRepresentation(com.android.gallery3d.filtershow.filters.FilterRepresentation)

Example 28 with Allocation

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

the class CachingPipeline method updateOriginalAllocation.

private synchronized boolean updateOriginalAllocation(ImagePreset preset) {
    if (preset == null) {
        return false;
    }
    Bitmap originalBitmap = mOriginalBitmap;
    if (originalBitmap == null) {
        return false;
    }
    RenderScript RS = getRenderScriptContext();
    Allocation filtersOnlyOriginalAllocation = mFiltersOnlyOriginalAllocation;
    mFiltersOnlyOriginalAllocation = Allocation.createFromBitmap(RS, originalBitmap, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
    if (filtersOnlyOriginalAllocation != null) {
        filtersOnlyOriginalAllocation.destroy();
    }
    Allocation originalAllocation = mOriginalAllocation;
    mResizedOriginalBitmap = preset.applyGeometry(originalBitmap, mEnvironment);
    mOriginalAllocation = Allocation.createFromBitmap(RS, mResizedOriginalBitmap, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
    if (originalAllocation != null) {
        originalAllocation.destroy();
    }
    return true;
}
Also used : Bitmap(android.graphics.Bitmap) RenderScript(android.renderscript.RenderScript) Allocation(android.renderscript.Allocation)

Example 29 with Allocation

use of android.renderscript.Allocation in project CodenameOne by codenameone.

the class AndroidImplementation method gaussianBlurImage.

public Image gaussianBlurImage(Image image, float radius) {
    try {
        Bitmap outputBitmap = Bitmap.createBitmap((Bitmap) image.getImage());
        RenderScript rs = RenderScript.create(getContext());
        ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
        Allocation tmpIn = Allocation.createFromBitmap(rs, (Bitmap) image.getImage());
        Allocation tmpOut = Allocation.createFromBitmap(rs, outputBitmap);
        theIntrinsic.setRadius(radius);
        theIntrinsic.setInput(tmpIn);
        theIntrinsic.forEach(tmpOut);
        tmpOut.copyTo(outputBitmap);
        return new NativeImage(outputBitmap);
    } catch (Throwable t) {
        brokenGaussian = true;
        return image;
    }
}
Also used : Bitmap(android.graphics.Bitmap) RenderScript(android.renderscript.RenderScript) ScriptIntrinsicBlur(android.renderscript.ScriptIntrinsicBlur) Allocation(android.renderscript.Allocation)

Example 30 with Allocation

use of android.renderscript.Allocation in project MusicLake by caiyonglong.

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)

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