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;
}
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);
}
}
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;
}
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;
}
}
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);
}
Aggregations