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