本文整理汇总了Java中android.support.v8.renderscript.Element类的典型用法代码示例。如果您正苦于以下问题:Java Element类的具体用法?Java Element怎么用?Java Element使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Element类属于android.support.v8.renderscript包,在下文中一共展示了Element类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: blur
import android.support.v8.renderscript.Element; //导入依赖的package包/类
public static void blur(final Bitmap src, final int radius, final OnBlurListener onBlurListener) {
new Thread(new Runnable() {
@Override
public void run() {
final Allocation input = Allocation.createFromBitmap(renderScript, src);
final Allocation output = Allocation.createTyped(renderScript, input.getType());
final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(renderScript, Element.U8_4(renderScript));
script.setRadius(radius);
script.setInput(input);
script.forEach(output);
output.copyTo(src);
onBlurListener.onBlur(src);
}
}).start();
}
示例2: loadModel
import android.support.v8.renderscript.Element; //导入依赖的package包/类
public void loadModel(String path) throws IOException {
mInputStream = mContext.getAssets().open(path + "/W", AssetManager.ACCESS_BUFFER);
ByteBuffer bb = readInput(mInputStream);
FloatBuffer.wrap(W).put(bb.asFloatBuffer());
// padding for GPU BLAS when necessary.
int W_height_input = in_channels * ksize * ksize;
if (padded_Y_blas == W_height_input) {
// If the input width already satisfies the requirement, just copy to the Allocation.
W_alloc.copyFrom(W);
} else {
// If not, a temp allocation needs to be created.
Allocation input = Allocation.createTyped(mRS,
Type.createXY(mRS, Element.F32(mRS), W_height_input, out_channels));
input.copyFrom(W);
W_alloc.copy2DRangeFrom(0, 0, W_height_input, out_channels, input, 0, 0);
}
mInputStream = mContext.getAssets().open(path + "/b", AssetManager.ACCESS_BUFFER);
bb = readInput(mInputStream);
FloatBuffer.wrap(b).put(bb.asFloatBuffer());
b_alloc.copyFrom(b);
mInputStream.close();
Log.v(TAG, "Convolution2D loaded: " + b[0]);
}
示例3: BatchNormalization
import android.support.v8.renderscript.Element; //导入依赖的package包/类
public BatchNormalization(Context ctx, RenderScript rs, int size) {
super(ctx, rs);
this.size = size;
gamma = new float[size];
beta = new float[size];
avg_mean = new float[size];
avg_var = new float[size];
// Create RS Allocations.
gamma_alloc = Allocation.createSized(mRS, Element.F32(mRS), size);
beta_alloc = Allocation.createSized(mRS, Element.F32(mRS), size);
avg_mean_alloc = Allocation.createSized(mRS, Element.F32(mRS), size);
avg_var_alloc = Allocation.createSized(mRS, Element.F32(mRS), size);
// Initialize the BatchNormalization kernel;
rs_BN = new ScriptC_batchnormalization(mRS);
// Set the global variables for the RS kernel.
rs_BN.set_beta_alloc(beta_alloc);
rs_BN.set_gamma_alloc(gamma_alloc);
rs_BN.set_mean_alloc(avg_mean_alloc);
rs_BN.set_var_alloc(avg_var_alloc);
rs_BN.set_size(size);
}
示例4: doInBackground
import android.support.v8.renderscript.Element; //导入依赖的package包/类
@Override
protected Drawable doInBackground(Drawable... drawables) {
finalResult = ArtworkUtils.optimizeBitmap(bitmap, bitmap.getWidth());
if (finalResult != null && finalResult.getConfig() != null) {
scriptIntrinsicBlur = ScriptIntrinsicBlur.create(renderScript, Element.U8_4(renderScript));
allocationIn = Allocation.createFromBitmap(renderScript, finalResult, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT | Allocation.USAGE_SHARED);
allocationOut = Allocation.createTyped(renderScript, allocationIn.getType());
scriptIntrinsicBlur.setRadius(radius); //radius option from users
scriptIntrinsicBlur.setInput(allocationIn);
scriptIntrinsicBlur.forEach(allocationOut);
allocationOut.copyTo(finalResult);
bitmapDrawable = new BitmapDrawable(context.getResources(), finalResult);
return bitmapDrawable;
} else {
Drawable defaultDrawable = ContextCompat.getDrawable(context, R.mipmap.ic_launcher);
return defaultDrawable;
}
}
示例5: blur
import android.support.v8.renderscript.Element; //导入依赖的package包/类
public void blur(Bitmap originBitmap) {
Bitmap scaledBitmap = Bitmap.createScaledBitmap(originBitmap, originBitmap.getWidth() / scaleRatio, originBitmap.getHeight() / scaleRatio, false);
Bitmap mBitmapToBlur = scaledBitmap.copy(Bitmap.Config.ARGB_8888, true);
Bitmap mBlurredBitmap = Bitmap.createBitmap(mBitmapToBlur.getWidth(), mBitmapToBlur.getHeight(),
Bitmap.Config.ARGB_8888);
mRenderScript = RenderScript.create(getContext());
mBlurScript = ScriptIntrinsicBlur.create(mRenderScript, Element.U8_4(mRenderScript));
mBlurInput = Allocation.createFromBitmap(mRenderScript, mBitmapToBlur,
Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
mBlurOutput = Allocation.createTyped(mRenderScript, mBlurInput.getType());
mBlurInput.copyFrom(mBitmapToBlur);
mBlurScript.setRadius(blurRadius);
mBlurScript.setInput(mBlurInput);
mBlurScript.forEach(mBlurOutput);
mBlurOutput.copyTo(mBlurredBitmap);
drawableFadeDisplayer.display(mBlurredBitmap, this);
scaledBitmap.recycle();
mBitmapToBlur.recycle();
mRenderScript.destroy();
}
示例6: yuvToRgb
import android.support.v8.renderscript.Element; //导入依赖的package包/类
/**
* Converts a NV21 image to a Bitmap.
* @param nv21Image the NV21 image to convert.
*/
public static Bitmap yuvToRgb(RenderScript rs, Nv21Image nv21Image) {
long startTime = System.currentTimeMillis();
Type.Builder yuvTypeBuilder = new Type.Builder(rs, Element.U8(rs))
.setX(nv21Image.nv21ByteArray.length);
Type yuvType = yuvTypeBuilder.create();
Allocation yuvAllocation = Allocation.createTyped(rs, yuvType, Allocation.USAGE_SCRIPT);
yuvAllocation.copyFrom(nv21Image.nv21ByteArray);
Type.Builder rgbTypeBuilder = new Type.Builder(rs, Element.RGBA_8888(rs));
rgbTypeBuilder.setX(nv21Image.width);
rgbTypeBuilder.setY(nv21Image.height);
Allocation rgbAllocation = Allocation.createTyped(rs, rgbTypeBuilder.create());
ScriptIntrinsicYuvToRGB yuvToRgbScript = ScriptIntrinsicYuvToRGB.create(rs, Element.RGBA_8888(rs));
yuvToRgbScript.setInput(yuvAllocation);
yuvToRgbScript.forEach(rgbAllocation);
Bitmap bitmap = Bitmap.createBitmap(nv21Image.width, nv21Image.height, Bitmap.Config.ARGB_8888);
rgbAllocation.copyTo(bitmap);
Log.d("NV21", "Conversion to Bitmap: " + (System.currentTimeMillis() - startTime) + "ms");
return bitmap;
}
示例7: luminanceHistogram
import android.support.v8.renderscript.Element; //导入依赖的package包/类
/**
* Computes a luminance histogram of a Bitmap.
* @return a 256-length int array of integer frequencies at luminance level.
*/
public static int[] luminanceHistogram(RenderScript rs, Bitmap inputBitmap) {
RSToolboxContext bitmapRSContext = RSToolboxContext.createFromBitmap(rs, inputBitmap);
Allocation aout = Allocation.createSized(bitmapRSContext.rs, Element.I32(bitmapRSContext.rs),
COLOR_DEPTH);
ScriptIntrinsicHistogram histogramScript = ScriptIntrinsicHistogram.create(
bitmapRSContext.rs, bitmapRSContext.ain.getElement());
histogramScript.setOutput(aout);
histogramScript.forEach(bitmapRSContext.ain);
int[] histogram = new int[COLOR_DEPTH];
aout.copyTo(histogram);
return histogram;
}
示例8: rgbaHistograms
import android.support.v8.renderscript.Element; //导入依赖的package包/类
/**
* Computes a RGBA histogram of a Bitmap.
* @return a 1024-length int array of integer frequencies at each channel intensity in the
* following interleaved format [R0,G0,B0,A0,R1,G1,B1,A1...]
*/
public static int[] rgbaHistograms(RenderScript rs, Bitmap inputBitmap) {
RSToolboxContext bitmapRSContext = RSToolboxContext.createFromBitmap(rs, inputBitmap);
Allocation aout = Allocation.createSized(bitmapRSContext.rs, Element.I32_4(bitmapRSContext.rs),
COLOR_DEPTH);
ScriptIntrinsicHistogram histogramScript = ScriptIntrinsicHistogram.create(
bitmapRSContext.rs, bitmapRSContext.ain.getElement());
histogramScript.setOutput(aout);
histogramScript.forEach(bitmapRSContext.ain);
int[] histograms = new int[CHANNELS * COLOR_DEPTH];
aout.copyTo(histograms);
// RGBA interleaved: [R0,G0,B0,A0,R1,G1,B1,A1...
return histograms;
}
示例9: getExpectedHistogram
import android.support.v8.renderscript.Element; //导入依赖的package包/类
@NonNull
private int[] getExpectedHistogram(RenderScript rs, Bitmap bmpFromNv21, Op op) {
Allocation ain = Allocation.createFromBitmap(rs, bmpFromNv21);
Allocation aout;
int[] histogram;
if (op == Op.LUMINANCE) {
aout = Allocation.createSized(rs, Element.I32(rs), Histogram.COLOR_DEPTH);
histogram = new int[Histogram.COLOR_DEPTH];
}
else {
aout = Allocation.createSized(rs, Element.I32_4(rs), Histogram.COLOR_DEPTH);
histogram = new int[Histogram.COLOR_DEPTH * Histogram.CHANNELS];
}
ScriptIntrinsicHistogram histogramScript = ScriptIntrinsicHistogram.create(
rs, ain.getElement());
histogramScript.setOutput(aout);
histogramScript.forEach(ain);
aout.copyTo(histogram);
return histogram;
}
示例10: blurBitmap
import android.support.v8.renderscript.Element; //导入依赖的package包/类
public static Drawable blurBitmap(Context context, Bitmap bitmap) {
final RenderScript renderScript = RenderScript.create(context);
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = Constants.IN_SAMPLE_SIZE;
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, Constants.COMPRESS_QUALITY, stream);
byte[] imageInByte = stream.toByteArray();
ByteArrayInputStream bis = new ByteArrayInputStream(imageInByte);
Bitmap blurTemplate = BitmapFactory.decodeStream(bis, null, options);
final Allocation input = Allocation.createFromBitmap(renderScript, blurTemplate);
final Allocation output = Allocation.createTyped(renderScript, input.getType());
final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(renderScript, Element.U8_4(renderScript));
script.setRadius(Constants.BLUR_RADIUS);
script.setInput(input);
script.forEach(output);
output.copyTo(blurTemplate);
renderScript.destroy();
return new BitmapDrawable(context.getResources(), blurTemplate);
}
示例11: attachSelection
import android.support.v8.renderscript.Element; //导入依赖的package包/类
private void attachSelection(ScriptC_cm_brightness script)
{
ManipulatorSelection selection = params.getSelection();
if(selection == null) return;
byte[] selectionData = selection.getData();
Rect selectionBounds = selection.getBounds();
Allocation allocationSelection = Allocation.createSized(renderScript, Element.U8(renderScript), selectionData.length);
allocationSelection.copyFrom(selectionData);
script.bind_selectionData(allocationSelection);
script.set_selectionWidth(selectionBounds.width());
script.set_selectionLeft(selectionBounds.left);
script.set_selectionTop(selectionBounds.top);
script.set_selectionRight(selectionBounds.right);
script.set_selectionBottom(selectionBounds.bottom);
}
示例12: attachSelection
import android.support.v8.renderscript.Element; //导入依赖的package包/类
private void attachSelection(ScriptC_cm_invert script)
{
ManipulatorSelection selection = params.getSelection();
if(selection == null) return;
byte[] selectionData = selection.getData();
Rect selectionBounds = selection.getBounds();
Allocation allocationSelection = Allocation.createSized(renderScript, Element.U8(renderScript), selectionData.length);
allocationSelection.copyFrom(selectionData);
script.bind_selectionData(allocationSelection);
script.set_selectionWidth(selectionBounds.width());
script.set_selectionLeft(selectionBounds.left);
script.set_selectionTop(selectionBounds.top);
script.set_selectionRight(selectionBounds.right);
script.set_selectionBottom(selectionBounds.bottom);
}
示例13: apply
import android.support.v8.renderscript.Element; //导入依赖的package包/类
public static Bitmap apply(Context context, Bitmap sentBitmap, int radius) {
final Bitmap bitmap = sentBitmap.copy(sentBitmap.getConfig(), true);
final RenderScript rs = RenderScript.create(context);
final Allocation input = Allocation.createFromBitmap(rs, sentBitmap, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
final Allocation output = Allocation.createTyped(rs, input.getType());
final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
script.setRadius(radius);
script.setInput(input);
script.forEach(output);
output.copyTo(bitmap);
sentBitmap.recycle();
rs.destroy();
input.destroy();
output.destroy();
script.destroy();
return bitmap;
}
示例14: blur
import android.support.v8.renderscript.Element; //导入依赖的package包/类
public static Bitmap blur(Context context, Bitmap image) {
int width = Math.round(image.getWidth() * BITMAP_SCALE);
int height = Math.round(image.getHeight() * BITMAP_SCALE);
Bitmap inputBitmap = Bitmap.createScaledBitmap(image, width, height, false);
Bitmap outputBitmap = Bitmap.createBitmap(inputBitmap);
RenderScript rs = RenderScript.create(context);
ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
Allocation tmpIn = Allocation.createFromBitmap(rs, inputBitmap);
Allocation tmpOut = Allocation.createFromBitmap(rs, outputBitmap);
theIntrinsic.setRadius(BLUR_RADIUS);
theIntrinsic.setInput(tmpIn);
theIntrinsic.forEach(tmpOut);
tmpOut.copyTo(outputBitmap);
return outputBitmap;
}
示例15: transform
import android.support.v8.renderscript.Element; //导入依赖的package包/类
@Override
public Bitmap transform(Bitmap source) {
try {
final RenderScript rs = RenderScript.create(context);
final Allocation input = Allocation.createFromBitmap(rs, source, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
final Allocation output = Allocation.createTyped(rs, input.getType());
final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
script.setRadius(14.f);
script.setInput(input);
script.forEach(output);
output.copyTo(source);
} catch (Exception e) {
e.printStackTrace();
}
return source;
}