本文整理匯總了Java中android.support.v8.renderscript.Allocation.destroy方法的典型用法代碼示例。如果您正苦於以下問題:Java Allocation.destroy方法的具體用法?Java Allocation.destroy怎麽用?Java Allocation.destroy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.support.v8.renderscript.Allocation
的用法示例。
在下文中一共展示了Allocation.destroy方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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;
}
示例4: compressTexture
import android.support.v8.renderscript.Allocation; //導入方法依賴的package包/類
/**
* Helper function that compresses an image into an ETC1Texture.
* @param input a native order direct buffer containing the image data
* @param width the width of the image in pixels
* @param height the height of the image in pixels
* @param pixelSize the size of a pixel in bytes (2 or 3)
* @param stride the width of a line of the image in bytes
* @return the ETC1 texture.
*/
public static ETC1Texture compressTexture(RenderScript rs, ScriptC_etc1compressor script, Buffer input, int width, int height, int pixelSize, int stride){
int encodedImageSize = RsETC1.getEncodedDataSize(width, height);
System.out.println("encodedImageSize : "+encodedImageSize);
ByteBuffer compressedImage = ByteBuffer.allocateDirect(encodedImageSize).
order(ByteOrder.nativeOrder());
Allocation p00 = Allocation.createSized(rs, Element.U8(rs), width * height * pixelSize);
p00.copyFrom(((ByteBuffer)input).array());
// TODO : there is a bug in the android sdk :
// ETC1.encodeImage((ByteBuffer) input, width, height, 3, stride, compressedImage); should be
RsETC1.encodeImage(rs, script, p00, width, height, pixelSize, stride, compressedImage, null, false, false);
p00.destroy();
compressedImage.rewind();
return new ETC1Texture(width, height, compressedImage);
}
示例5: getBlurBitmap
import android.support.v8.renderscript.Allocation; //導入方法依賴的package包/類
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
@WorkerThread
private Bitmap getBlurBitmap(Context context, Bitmap inBitmap, float radius) {
if (context == null || inBitmap == null) {
throw new IllegalArgumentException("have not called setParams() before call execute()");
}
int width = Math.round(inBitmap.getWidth() * SCALE);
int height = Math.round(inBitmap.getHeight() * SCALE);
Bitmap in = Bitmap.createScaledBitmap(inBitmap, width, height, false);
Bitmap out = Bitmap.createBitmap(in);
RenderScript rs = RenderScript.create(context);
ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
Allocation allocationIn = Allocation.createFromBitmap(rs, in);
Allocation allocationOut = Allocation.createFromBitmap(rs, out);
blurScript.setRadius(radius);
blurScript.setInput(allocationIn);
blurScript.forEach(allocationOut);
allocationOut.copyTo(out);
allocationIn.destroy();
allocationOut.destroy();
blurScript.destroy();
rs.destroy();
return out;
}
示例6: process
import android.support.v8.renderscript.Allocation; //導入方法依賴的package包/類
public Allocation process(Allocation input, int img_h, int img_w) {
// Set the input variables to the convolve kernel.
mConvovle.set_img_h(img_h);
mConvovle.set_img_w(img_w);
mConvovle.set_img_alloc(input);
// Calculate the dimensions of the image after padding.
int padded_h = img_h + 2 * pad;
int padded_w = img_w + 2 * pad;
// Create Allocation to hold the padded image.
Allocation img_padded = Allocation.createTyped(mRS,
Type.createXY(mRS, Element.F32(mRS), padded_h * padded_w, in_channels));
// Initialize the padded Allocation to zero.
mConvovle.forEach_zero(img_padded, img_padded);
mConvovle.set_padded_alloc(img_padded);
// Invoked the padding kernel.
mConvovle.invoke_padd();
// TODO Step2: Use convolve2DGEMM instead.
Allocation out_alloc = convolve2D(img_padded, img_h, img_w);
// Destroy the intermediate Allocations.
img_padded.destroy();
return out_alloc;
}
示例7: dispatchDraw
import android.support.v8.renderscript.Allocation; //導入方法依賴的package包/類
@Override
protected void dispatchDraw(Canvas canvas) {
super.dispatchDraw(canvas);
long time = System.currentTimeMillis();
if (time - mLastUpdate >= 16) {
mLastUpdate = time;
Bitmap original = createBitmapOfViews();
if (original != null) {
Allocation input = Allocation.createFromBitmap(mRenderScript, original);
Allocation output = Allocation.createTyped(mRenderScript, input.getType());
mIntrinsicBlur.setRadius(25f);
mIntrinsicBlur.setInput(input);
mIntrinsicBlur.forEach(output);
output.copyTo(original);
input.destroy();
output.destroy();
BitmapDrawable drawable = new BitmapDrawable(getContext().getResources(), original);
drawable.setAlpha(63);
drawable.setColorFilter(BRIGHTNESS_FILTER);
this.setBackground(drawable);
mCurrent.recycle();
mCurrent = original;
}
}
quadTo(canvas);
}
示例8: 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);
Bitmap outputBitmap;
if (canModifyBitmap) {
outputBitmap = bitmap;
} else {
outputBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig());
}
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(outputBitmap);
inAllocation.destroy();
return outputBitmap;
}
示例9: getBlurBitmap
import android.support.v8.renderscript.Allocation; //導入方法依賴的package包/類
@WorkerThread
private Bitmap getBlurBitmap(Context context, Bitmap inBitmap, float radius) {
if (context == null || inBitmap == null) {
throw new IllegalArgumentException("have not called setParams() before call execute()");
}
int width = Math.round(inBitmap.getWidth() * SCALE);
int height = Math.round(inBitmap.getHeight() * SCALE);
Bitmap in = Bitmap.createScaledBitmap(inBitmap, width, height, false);
Bitmap out = Bitmap.createBitmap(in);
RenderScript rs = RenderScript.create(context);
ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
Allocation allocationIn = Allocation.createFromBitmap(rs, in);
Allocation allocationOut = Allocation.createFromBitmap(rs, out);
blurScript.setRadius(radius);
blurScript.setInput(allocationIn);
blurScript.forEach(allocationOut);
allocationOut.copyTo(out);
allocationIn.destroy();
allocationOut.destroy();
blurScript.destroy();
rs.destroy();
return out;
}
示例10: testRsETC1ImageCompressor
import android.support.v8.renderscript.Allocation; //導入方法依賴的package包/類
public static ETC1Texture testRsETC1ImageCompressor(RenderScript rs,
ScriptC_etc1compressor script) {
Allocation alloc = Allocation.createFromBitmap(rs, bitmapARGB, MipmapControl.MIPMAP_NONE, Allocation.USAGE_SHARED);
// RGB_565 is 2 bytes per pixel
RsETC1.encodeImage(rs, script, alloc, bitmapARGB.getWidth(), bitmapARGB.getHeight(), 4,
4 * bitmapARGB.getWidth(), compressedImage, null, false, false);
ETC1Texture texture = new ETC1Texture(bitmapARGB.getWidth(),
bitmapARGB.getHeight(), compressedImage);
alloc.destroy();
// if (texture != null) {
// int estimatedMemorySize = ETC1.ETC_PKM_HEADER_SIZE
// + texture.getHeight() * texture.getWidth() / 2;
// File f = new
// File(Environment.getExternalStorageDirectory(),"bmngpkm.pkm");
// f.delete();
// f.createNewFile();
// ETC1Util.writeTexture(texture, new FileOutputStream(f));
// System.out.println("Texture PKM created ");
// }
// System.out.println("Texture PKM creation failed ");
return texture;
}
示例11: testRsETC1ImageCompressorWithAlpha
import android.support.v8.renderscript.Allocation; //導入方法依賴的package包/類
public static ETC1Texture testRsETC1ImageCompressorWithAlpha(RenderScript rs,
ScriptC_etc1compressor script) {
Allocation alloc = Allocation.createFromBitmap(rs, bitmapARGB, MipmapControl.MIPMAP_NONE, Allocation.USAGE_SHARED);
// RGB_565 is 2 bytes per pixel
RsETC1.encodeImage(rs, script, alloc, bitmapARGB.getWidth(), bitmapARGB.getHeight(), 4,
4 * bitmapARGB.getWidth(), compressedImage, compressedImageAlpha, false, true);
ETC1Texture texture = new ETC1Texture(bitmapARGB.getWidth(),
bitmapARGB.getHeight(), compressedImage);
alloc.destroy();
// if (texture != null) {
// int estimatedMemorySize = ETC1.ETC_PKM_HEADER_SIZE
// + texture.getHeight() * texture.getWidth() / 2;
// File f = new
// File(Environment.getExternalStorageDirectory(),"bmngpkm.pkm");
// f.delete();
// f.createNewFile();
// ETC1Util.writeTexture(texture, new FileOutputStream(f));
// System.out.println("Texture PKM created ");
// }
// System.out.println("Texture PKM creation failed ");
return texture;
}
示例12: convolve2DGEMM
import android.support.v8.renderscript.Allocation; //導入方法依賴的package包/類
private Allocation convolve2DGEMM(Allocation img_padded, int img_h, int img_w) {
// Calculate the dimensions of image after convolution.
int out_h = ConvolveUtil.get_conv_outsize(img_h, ksize, stride, pad);
int out_w = ConvolveUtil.get_conv_outsize(img_w, ksize, stride, pad);
Log.v(TAG, "convolve size: " + out_h + " " + out_w);
// Create the column Allocation.
Allocation col_alloc = Allocation.createTyped(mRS,
Type.createXY(mRS, Element.F32(mRS), out_h * out_w, padded_Y_blas));
long time = System.currentTimeMillis();
// Invoke im2col kernel, to transform padded image to column image:
mConvovle.set_outW(out_w);
mConvovle.set_outH(out_h);
mConvovle.forEach_im2col(col_alloc);
if (LOG_TIME) {
mRS.finish();
time = System.currentTimeMillis() - time;
im2colTime += time;
Log.v(TAG, "Convolution2D, channels: " + in_channels + ", " + out_channels + " size: " + img_h + ", " + img_w + " im2col process time: " + time);
}
// Create the output Allocation for SGEMM operation.
Allocation out_alloc = Allocation.createTyped(mRS,
Type.createXY(mRS, Element.F32(mRS), out_h * out_w, out_channels));
time = System.currentTimeMillis();
// Conduct the convolution by matrix multiplication, using SGEMM (BLAS API).
mBlas.SGEMM(ScriptIntrinsicBLAS.NO_TRANSPOSE, ScriptIntrinsicBLAS.NO_TRANSPOSE,
1.0f, W_alloc, col_alloc, 0.0f, out_alloc);
if (LOG_TIME) {
mRS.finish();
time = System.currentTimeMillis() - time;
sgemmTime += time;
Log.v(TAG, "Convolution2D, channels: " + in_channels + ", " + out_channels + " size: " + img_h + ", " + img_w + " SGEMM process time: " + time);
}
time = System.currentTimeMillis();
// Add beta to the results for each channel.
mConvovle.forEach_addBeta(out_alloc, out_alloc);
if (LOG_TIME) {
mRS.finish();
time = System.currentTimeMillis() - time;
betaTime += time;
Log.v(TAG, "Convolution2D, channels: " + in_channels + ", " + out_channels + " size: " + img_h + ", " + img_w + " initBeta process time: " + time);
}
// Destroy the intermediate Allocations.
col_alloc.destroy();
// Update the output dimensions.
outH = out_h;
outW = out_w;
return out_alloc;
}
示例13: process
import android.support.v8.renderscript.Allocation; //導入方法依賴的package包/類
public Allocation process(Allocation input, int col_h, int col_w) {
// Create the output Allocation for SGEMM operation.
Allocation out_alloc = Allocation.createTyped(mRS,
Type.createXY(mRS, Element.F32(mRS), input.getType().getX(), W_alloc.getType().getY()));
long time = System.currentTimeMillis();
Log.v(TAG, "Deconvolution2D: " + input.getType().getX() + " " + input.getType().getY() + " " + W_alloc.getType().getX() + " " + W_alloc.getType().getY());
// Conduct the deconvolution by matrix multiplication, using SGEMM (BLAS API).
mBlas.SGEMM(ScriptIntrinsicBLAS.NO_TRANSPOSE, ScriptIntrinsicBLAS.NO_TRANSPOSE,
1.0f, W_alloc, input, 0.0f, out_alloc);
if (LOG_TIME) {
mRS.finish();
time = System.currentTimeMillis() - time;
sgemmTime += time;
Log.v(TAG, "Deconvolution2D, channels: " + in_channels + ", " + out_channels + " size: " + col_h + ", " + col_w + " SGEMM process time: " + time);
}
Log.v(TAG, "Deconvolution2D: SGEMM");
// Calculate the dimensions of image after deconvolution.
int img_h = ConvolveUtil.get_deconv_outsize(col_h, ksize, stride, pad);
int img_w = ConvolveUtil.get_deconv_outsize(col_w, ksize, stride, pad);
// Set the global input variables for the RS kernel.
mConvovle.set_col_h(col_h);
mConvovle.set_col_w(col_w);
mConvovle.set_col_channel(out_channels);
mConvovle.set_img_channel(out_channels);
mConvovle.set_img_h(img_h);
mConvovle.set_img_w(img_w);
mConvovle.set_col_alloc(out_alloc);
// Calculate the dimensions of the padded image.
int padded_h = img_h + 2 * pad;
int padded_w = img_w + 2 * pad;
// Create Allocation to hold the padded image.
Allocation img_padded = Allocation.createTyped(mRS,
Type.createXY(mRS, Element.F32(mRS), padded_h * padded_w, out_channels));
// Initialize the padded Allocation to zero.
mConvovle.forEach_zero(img_padded, img_padded);
mConvovle.set_padded_alloc(img_padded);
// Create output image Allocation.
Allocation img_alloc = Allocation.createTyped(mRS,
Type.createXY(mRS, Element.F32(mRS), img_h * img_w, out_channels));
mConvovle.set_img_alloc(img_alloc);
time = System.currentTimeMillis();
// Invoke col2im kernel, to transform column image to padded image:
mConvovle.invoke_col2im();
// mConvovle.set_tile_h(col_h);
// mConvovle.forEach_col2imPar(img_padded, img_padded);
// Invoked the unpadding kernel.
mConvovle.invoke_unpadd();
if (LOG_TIME) {
mRS.finish();
time = System.currentTimeMillis() - time;
col2imTime += time;
Log.v(TAG, "Deconvolution2D, channels: " + in_channels + ", " + out_channels + " size: " + col_h + ", " + col_w + " col2im process time: " + time);
}
time = System.currentTimeMillis();
// Add beta to the results for each channel.
mConvovle.forEach_addBeta(img_alloc, img_alloc);
if (LOG_TIME) {
mRS.finish();
time = System.currentTimeMillis() - time;
betaTime += time;
Log.v(TAG, "Deconvolution2D, channels: " + in_channels + ", " + out_channels + " size: " + col_h + ", " + col_w + " addBeta process time: " + time);
}
// Destroy the intermediate Allocations.
out_alloc.destroy();
img_padded.destroy();
// Update the output dimensions.
outH = img_h;
outW = img_w;
return img_alloc;
}
示例14: encodeImage
import android.support.v8.renderscript.Allocation; //導入方法依賴的package包/類
/**
* Encode an entire image. pIn - pointer to the image data. Formatted such
* that the Red component of pixel (x,y) is at pIn + pixelSize * x + stride
* * y + redOffset; pOut - pointer to encoded data. Must be large enough to
* store entire encoded image.
* @param script
* @param containMipmaps
*/
public static int encodeImage(RenderScript rs, ScriptC_etc1compressor script, Allocation aIn, int width, int height,
int pixelSize, int stride, ByteBuffer compressedImage, ByteBuffer compressedAlphaImage, boolean containMipmaps, boolean hasAlpha) {
long tInitArray = java.lang.System.currentTimeMillis();
script.set_height(height);
script.set_width(width);
script.set_containMipmaps(containMipmaps);
script.set_pixelSize(pixelSize);
script.set_hasAlpha(hasAlpha);
if (pixelSize < 2 || pixelSize > 4) {
return -1;
}
// int iOut = 0;
int size = Math.max(aIn.getBytesSize() / ((DECODED_BLOCK_SIZE/3)*pixelSize), 1);
Allocation aout = Allocation.createSized(rs, Element.U16_4(rs), size);
Allocation aoutAlpha = Allocation.createSized(rs, Element.U8(rs), 8*size);
tInitArray = java.lang.System.currentTimeMillis() - tInitArray;
//System.out.println("tInitArray : "+tInitArray+" ms");
long tFillAlloc = java.lang.System.currentTimeMillis();
script.bind_pInA(aIn);
script.bind_outAlpha(aoutAlpha);
tFillAlloc = java.lang.System.currentTimeMillis() - tFillAlloc;
//System.out.println("tFillAlloc : "+tFillAlloc+" ms");
long tExec = java.lang.System.currentTimeMillis();
script.forEach_root(aout);
tExec = java.lang.System.currentTimeMillis() - tExec;
//System.out.println("tExec : "+tExec+" ms");
long tFillOut = java.lang.System.currentTimeMillis();
short[] arrayOut3Temp = new short[4*size];
aout.copyTo(arrayOut3Temp);
aout.destroy();
Allocation aout2 = Allocation.createSized(rs, Element.U8(rs), 8*size);
aout2.copyFromUnchecked(arrayOut3Temp);
aout2.copyTo(compressedImage.array());
aout2.destroy();
if(hasAlpha) {
aoutAlpha.copyTo(compressedAlphaImage.array());
}
aoutAlpha.destroy();
tFillOut = java.lang.System.currentTimeMillis() - tFillOut;
compressedImage.rewind();
//System.out.println("tFillOut : "+tFillOut+" ms");
return 0;
}