本文整理汇总了Java中android.support.v8.renderscript.Allocation.createTyped方法的典型用法代码示例。如果您正苦于以下问题:Java Allocation.createTyped方法的具体用法?Java Allocation.createTyped怎么用?Java Allocation.createTyped使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v8.renderscript.Allocation
的用法示例。
在下文中一共展示了Allocation.createTyped方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadModel
import android.support.v8.renderscript.Allocation; //导入方法依赖的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]);
}
示例2: doInBackground
import android.support.v8.renderscript.Allocation; //导入方法依赖的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;
}
}
示例3: blur
import android.support.v8.renderscript.Allocation; //导入方法依赖的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();
}
示例4: yuvToRgb
import android.support.v8.renderscript.Allocation; //导入方法依赖的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;
}
示例5: resize
import android.support.v8.renderscript.Allocation; //导入方法依赖的package包/类
/**
* Resizes a Bitmap image to a target width and height.
*/
public static Bitmap resize(RenderScript rs, Bitmap inputBitmap, int targetWidth,
int targetHeight) {
RSToolboxContext bitmapRSContext = RSToolboxContext.createFromBitmap(rs, inputBitmap);
Bitmap.Config config = inputBitmap.getConfig();
Bitmap outputBitmap = Bitmap.createBitmap(targetWidth, targetHeight, config);
Type outType = Type.createXY(bitmapRSContext.rs, bitmapRSContext.ain.getElement(), targetWidth,
targetHeight);
Allocation aout = Allocation.createTyped(bitmapRSContext.rs, outType);
ScriptIntrinsicResize resizeScript = ScriptIntrinsicResize.create(bitmapRSContext.rs);
resizeScript.setInput(bitmapRSContext.ain);
resizeScript.forEach_bicubic(aout);
aout.copyTo(outputBitmap);
return outputBitmap;
}
示例6: getExpectedBitmap
import android.support.v8.renderscript.Allocation; //导入方法依赖的package包/类
@NonNull
private Bitmap getExpectedBitmap(RenderScript rs, Bitmap bmpFromNv21) {
Allocation ain = Allocation.createFromBitmap(rs, bmpFromNv21);
Allocation aout = Allocation.createTyped(rs, ain.getType());
ScriptIntrinsicLUT lutScript = ScriptIntrinsicLUT.create(rs, ain.getElement());
for (int i = 0; i < LutParams.LUT_SIZE; i++) {
LutParams.RGBALut rgbaLut = SampleParams.Lut.negative();
lutScript.setAlpha(i, rgbaLut.aLut[i]);
lutScript.setRed(i, rgbaLut.rLut[i]);
lutScript.setGreen(i, rgbaLut.gLut[i]);
lutScript.setBlue(i, rgbaLut.bLut[i]);
}
lutScript.forEach(ain, aout);
Bitmap expectedBitmap = Bitmap.createBitmap(bmpFromNv21.getWidth(), bmpFromNv21.getHeight(), bmpFromNv21.getConfig());
aout.copyTo(expectedBitmap);
return expectedBitmap;
}
示例7: blur
import android.support.v8.renderscript.Allocation; //导入方法依赖的package包/类
/**
* @param bitmap bitmap to blur
* @param blurRadius blur radius (1..25)
* @return blurred bitmap
*/
@Override
public final Bitmap blur(Bitmap bitmap, float blurRadius) {
//Allocation will use the same backing array of pixels as bitmap if created with USAGE_SHARED flag
Allocation inAllocation = Allocation.createFromBitmap(renderScript, bitmap);
if (!canReuseAllocation(bitmap)) {
if (outAllocation != null) {
outAllocation.destroy();
}
outAllocation = Allocation.createTyped(renderScript, inAllocation.getType());
lastBitmapWidth = bitmap.getWidth();
lastBitmapHeight = bitmap.getHeight();
}
blurScript.setRadius(blurRadius);
blurScript.setInput(inAllocation);
//do not use inAllocation in forEach. it will cause visual artifacts on blurred Bitmap
blurScript.forEach(outAllocation);
outAllocation.copyTo(bitmap);
inAllocation.destroy();
return bitmap;
}
示例8: blurBitmap
import android.support.v8.renderscript.Allocation; //导入方法依赖的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);
}
示例9: apply
import android.support.v8.renderscript.Allocation; //导入方法依赖的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;
}
示例10: transform
import android.support.v8.renderscript.Allocation; //导入方法依赖的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;
}
示例11: transform
import android.support.v8.renderscript.Allocation; //导入方法依赖的package包/类
@Override
public Bitmap transform(Bitmap bitmap) {
// Create another bitmap that will hold the results of the filter.
Bitmap blurredBitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);
// Allocate memory for Renderscript to work with
Allocation input = Allocation.createFromBitmap(rs, blurredBitmap, Allocation.MipmapControl.MIPMAP_FULL, Allocation.USAGE_SHARED);
Allocation output = Allocation.createTyped(rs, input.getType());
// Load up an instance of the specific script that we want to use.
ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
script.setInput(input);
// Set the blur radius
script.setRadius(10);
// Start the ScriptIntrinisicBlur
script.forEach(output);
// Copy the output to the blurred bitmap
output.copyTo(blurredBitmap);
bitmap.recycle();
return blurredBitmap;
}
示例12: blur
import android.support.v8.renderscript.Allocation; //导入方法依赖的package包/类
@Override
protected Bitmap blur(Context context, Bitmap bitmapToBlur, int radius) {
Log.i(TAG, "Current build version sdk " + Build.VERSION.SDK_INT);
Bitmap bitmap = bitmapToBlur.copy(bitmapToBlur.getConfig(), true);
final RenderScript renderScript = RenderScript.create(context, Build.VERSION.SDK_INT);
final Allocation input = Allocation.createFromBitmap(renderScript, bitmapToBlur,
Allocation.MipmapControl.MIPMAP_NONE,
Allocation.USAGE_SCRIPT);
final Allocation output = Allocation.createTyped(renderScript, input.getType());
try {
final ScriptIntrinsicBlur script = createBlurringScript(radius, renderScript, input);
script.forEach(output);
renderScript.finish();
output.copyTo(bitmap);
} finally {
input.destroy();
output.destroy();
bitmapToBlur.recycle();
renderScript.destroy();
}
return bitmap;
}
示例13: transform
import android.support.v8.renderscript.Allocation; //导入方法依赖的package包/类
@Override
protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) {
Bitmap blurredBitmap = toTransform.copy(Bitmap.Config.ARGB_8888, true);
// Allocate memory for Renderscript to work with
Allocation input = Allocation.createFromBitmap(rs, blurredBitmap, Allocation.MipmapControl.MIPMAP_FULL, Allocation.USAGE_SHARED);
Allocation output = Allocation.createTyped(rs, input.getType());
// Load up an instance of the specific script that we want to use.
ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
script.setInput(input);
// Set the blur radius
script.setRadius(10);
// Start the ScriptIntrinisicBlur
script.forEach(output);
// Copy the output to the blurred bitmap
output.copyTo(blurredBitmap);
toTransform.recycle();
return blurredBitmap;
}
示例14: transform
import android.support.v8.renderscript.Allocation; //导入方法依赖的package包/类
@Override
public Bitmap transform(Bitmap bitmap) {
// Create another bitmap that will hold the results of the filter.
Bitmap blurredBitmap = Bitmap.createBitmap(bitmap);
// Allocate memory for Renderscript to work with
Allocation input = Allocation.createFromBitmap(rs, bitmap, Allocation.MipmapControl.MIPMAP_FULL, Allocation.USAGE_SCRIPT);
Allocation output = Allocation.createTyped(rs, input.getType());
// Load up an instance of the specific script that we want to use.
ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
script.setInput(input);
// Set the blur radius
script.setRadius(RADIUS);
// Start the ScriptIntrinisicBlur
script.forEach(output);
// Copy the output to the blurred bitmap
output.copyTo(blurredBitmap);
return blurredBitmap;
}
示例15: manipulate
import android.support.v8.renderscript.Allocation; //导入方法依赖的package包/类
@Override
public Bitmap manipulate(Bitmap bitmapOriginal) {
if (brightness != 0) {
try {
Allocation input = Allocation.createFromBitmap(rs, bitmapOriginal);
final Allocation output = Allocation.createTyped(rs, input.getType());
ScriptC_brightness mScript = new ScriptC_brightness(rs);
mScript.invoke_setBright(brightness);
mScript.forEach_brightness(input, output);
output.copyTo(bitmapOriginal);
} catch (RSRuntimeException e) {
//fallback
}
}
return bitmapOriginal;
}