本文整理汇总了Java中android.support.v8.renderscript.Allocation.createSized方法的典型用法代码示例。如果您正苦于以下问题:Java Allocation.createSized方法的具体用法?Java Allocation.createSized怎么用?Java Allocation.createSized使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v8.renderscript.Allocation
的用法示例。
在下文中一共展示了Allocation.createSized方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: BatchNormalization
import android.support.v8.renderscript.Allocation; //导入方法依赖的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);
}
示例2: luminanceHistogram
import android.support.v8.renderscript.Allocation; //导入方法依赖的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;
}
示例3: rgbaHistograms
import android.support.v8.renderscript.Allocation; //导入方法依赖的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;
}
示例4: getExpectedHistogram
import android.support.v8.renderscript.Allocation; //导入方法依赖的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;
}
示例5: attachSelection
import android.support.v8.renderscript.Allocation; //导入方法依赖的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);
}
示例6: attachSelection
import android.support.v8.renderscript.Allocation; //导入方法依赖的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);
}
示例7: convolve
import android.support.v8.renderscript.Allocation; //导入方法依赖的package包/类
public void convolve(Bitmap bmp, Bitmap bmpOut, float[] kernel, int blockSize) {
if (bmp.getConfig() != Bitmap.Config.ARGB_8888 || bmpOut.getConfig() != Bitmap.Config.ARGB_8888) {
throw new IllegalArgumentException("Input and output bitmaps must be 1 channel, 8-bit configuration");
}
alloc(bmp, bmpOut);
Allocation kernelAlloc = Allocation.createSized(mRS, Element.F32(mRS), blockSize * blockSize);
kernelAlloc.copyFrom(kernel);
imijScript.set_imgIn(mInAllocation);
imijScript.set_width(bmp.getWidth());
imijScript.set_height(bmp.getHeight());
imijScript.forEach_convolve(mOutAllocation);
copy(bmpOut);
}
示例8: 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);
}
示例9: SamplePacket
import android.support.v8.renderscript.Allocation; //导入方法依赖的package包/类
/**
* Constructor. This constructor wraps existing arrays and allows to set the
* number of samples in this packet to something smaller than the array length
*
* @param re array of real parts of the sample values
* @param im array of imaginary parts of the sample values
* @param frequency center frequency
* @param sampleRate sample rate
* @param size number of samples in this packet ( <= arrays.length )
*/
public SamplePacket(float[] re, float im[], long frequency, int sampleRate, int size) {
if(re.length != im.length)
throw new IllegalArgumentException("Arrays must be of the same length");
if(size > re.length)
throw new IllegalArgumentException("Size must be of the smaller or equal the array length");
this.capacity = re.length;
this.reAlloc = Allocation.createSized(AndroidDSPLib.getRenderScript(), Element.F32(AndroidDSPLib.getRenderScript()), capacity);
this.imAlloc = Allocation.createSized(AndroidDSPLib.getRenderScript(), Element.F32(AndroidDSPLib.getRenderScript()), capacity);
this.reAlloc.copyFrom(re);
this.imAlloc.copyFrom(im);
this.frequency = frequency;
this.sampleRate = sampleRate;
this.size = size;
}
示例10: blur
import android.support.v8.renderscript.Allocation; //导入方法依赖的package包/类
@Override
public Bitmap blur(Bitmap original, float radius) {
int width = original.getWidth();
int height = original.getHeight();
Bitmap blurred = original.copy(Bitmap.Config.ARGB_8888, true);
ScriptC_blur blurScript = new ScriptC_blur(_rs, context.getResources(), R.raw.blur);
Allocation inAllocation = Allocation.createFromBitmap(_rs, blurred, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
blurScript.set_gIn(inAllocation);
blurScript.set_width(width);
blurScript.set_height(height);
blurScript.set_radius((int) radius);
int[] row_indices = new int[height];
for (int i = 0; i < height; i++) {
row_indices[i] = i;
}
Allocation rows = Allocation.createSized(_rs, Element.U32(_rs), height, Allocation.USAGE_SCRIPT);
rows.copyFrom(row_indices);
row_indices = new int[width];
for (int i = 0; i < width; i++) {
row_indices[i] = i;
}
Allocation columns = Allocation.createSized(_rs, Element.U32(_rs), width, Allocation.USAGE_SCRIPT);
columns.copyFrom(row_indices);
blurScript.forEach_blur_h(rows);
blurScript.forEach_blur_v(columns);
inAllocation.copyTo(blurred);
return blurred;
}
示例11: Convolution2D
import android.support.v8.renderscript.Allocation; //导入方法依赖的package包/类
public Convolution2D(Context ctx, RenderScript rs, int in_channels, int out_channels, int ksize, int stride, int pad) {
super(ctx, rs);
this.in_channels = in_channels;
this.out_channels = out_channels;
this.ksize = ksize;
this.stride = stride;
this.pad = pad;
// X dimension for W: in_channels * ksize * ksize
// Y dimension for W: out_channels
this.W = new float[out_channels * in_channels * ksize * ksize];
this.b = new float[out_channels];
// Pad the width of W to be multiple of 8.
padded_Y_blas = in_channels * ksize * ksize;
if (padded_Y_blas % 8 > 0) {
padded_Y_blas = (padded_Y_blas / 8 + 1) * 8;
}
// Create Allocations for W and b.
W_alloc = Allocation.createTyped(mRS,
Type.createXY(mRS, Element.F32(mRS), padded_Y_blas, out_channels));
b_alloc = Allocation.createSized(mRS, Element.F32(mRS), out_channels);
// Initialize the 2D convolution kernel;
mConvovle = new ScriptC_convolve2d(mRS);
// Set the global variables for the RS kernel.
mConvovle.set_kernel_h(ksize);
mConvovle.set_kernel_w(ksize);
mConvovle.set_step_x(stride);
mConvovle.set_step_y(stride);
mConvovle.set_pad_h(pad);
mConvovle.set_pad_w(pad);
mConvovle.set_beta_alloc(b_alloc);
mConvovle.set_img_channel(in_channels);
}
示例12: Convolution2DTiled
import android.support.v8.renderscript.Allocation; //导入方法依赖的package包/类
public Convolution2DTiled(Context ctx, RenderScript rs, int in_channels, int out_channels, int ksize, int stride, int pad) {
super(ctx, rs);
this.in_channels = in_channels;
this.out_channels = out_channels;
this.ksize = ksize;
this.stride = stride;
this.pad = pad;
// X dimension for W: in_channels * ksize * ksize
// Y dimension for W: out_channels
this.W = new float[out_channels * in_channels * ksize * ksize];
this.b = new float[out_channels];
// Pad the width of W to be multiple of 8.
padded_Y_blas = in_channels * ksize * ksize;
if (padded_Y_blas % 8 > 0) {
padded_Y_blas = (padded_Y_blas / 8 + 1) * 8;
}
// Create Allocations for W and b.
W_alloc = Allocation.createTyped(mRS,
Type.createXY(mRS, Element.F32(mRS), padded_Y_blas, out_channels));
b_alloc = Allocation.createSized(mRS, Element.F32(mRS), out_channels);
// Initialize the 2D convolution kernel;
mConvovle = new ScriptC_convolve2d(mRS);
// Set the global variables for the RS kernel.
mConvovle.set_kernel_h(ksize);
mConvovle.set_kernel_w(ksize);
mConvovle.set_step_x(stride);
mConvovle.set_step_y(stride);
mConvovle.set_pad_h(pad);
mConvovle.set_pad_w(pad);
mConvovle.set_beta_alloc(b_alloc);
mConvovle.set_img_channel(in_channels);
mConvovle.set_tile_h(TILE_Y);
}
示例13: Deconvolution2DTiled
import android.support.v8.renderscript.Allocation; //导入方法依赖的package包/类
public Deconvolution2DTiled(Context ctx, RenderScript rs, int in_channels, int out_channels, int ksize, int stride, int pad) {
super(ctx, rs);
this.in_channels = in_channels;
this.out_channels = out_channels;
this.ksize = ksize;
this.stride = stride;
this.pad = pad;
// X dimension for W: in_channels * ksize * ksize
// Y dimension for W: out_channels
this.W = new float[out_channels * ksize * ksize * in_channels];
this.b = new float[out_channels];
// Pad the width of W to be multiple of 8.
padded_Y_blas = out_channels * ksize * ksize;
if (padded_Y_blas % 8 > 0) {
padded_Y_blas = (padded_Y_blas / 8 + 1) * 8;
}
// Create Allocations for W and b.
W_alloc = Allocation.createTyped(mRS,
Type.createXY(mRS, Element.F32(mRS), in_channels, padded_Y_blas));
b_alloc = Allocation.createSized(mRS, Element.F32(mRS), out_channels);
// Initialize the 2D deconvolution kernel;
mConvovle = new ScriptC_deconvolve2d(mRS);
// Set the global variables for the RS kernel.
mConvovle.set_tile_h(TILE_Y);
mConvovle.set_col_h(TILE_Y);
mConvovle.set_kernel_h(ksize);
mConvovle.set_kernel_w(ksize);
mConvovle.set_step_x(stride);
mConvovle.set_step_y(stride);
mConvovle.set_pad_h(pad);
mConvovle.set_pad_w(pad);
mConvovle.set_beta_alloc(b_alloc);
}
示例14: Deconvolution2D
import android.support.v8.renderscript.Allocation; //导入方法依赖的package包/类
public Deconvolution2D(Context ctx, RenderScript rs, int in_channels, int out_channels, int ksize, int stride, int pad) {
super(ctx, rs);
this.in_channels = in_channels;
this.out_channels = out_channels;
this.ksize = ksize;
this.stride = stride;
this.pad = pad;
// Y dimension for W: out_channels * ksize * ksize
// X dimension for W: in_channels
this.W = new float[out_channels * ksize * ksize * in_channels];
this.b = new float[out_channels];
// Pad the width of W to be multiple of 8.
padded_Y_blas = out_channels * ksize * ksize;
if (padded_Y_blas % 8 > 0) {
padded_Y_blas = (padded_Y_blas / 8 + 1) * 8;
}
// Create Allocations for W and b.
W_alloc = Allocation.createTyped(mRS,
Type.createXY(mRS, Element.F32(mRS), in_channels, padded_Y_blas));
b_alloc = Allocation.createSized(mRS, Element.F32(mRS), out_channels);
// Initialize the 2D deconvolution kernel;
mConvovle = new ScriptC_deconvolve2d(mRS);
// Set the global variables for the RS kernel.
mConvovle.set_kernel_h(ksize);
mConvovle.set_kernel_w(ksize);
mConvovle.set_step_x(stride);
mConvovle.set_step_y(stride);
mConvovle.set_pad_h(pad);
mConvovle.set_pad_w(pad);
mConvovle.set_beta_alloc(b_alloc);
}
示例15: prepareSelection
import android.support.v8.renderscript.Allocation; //导入方法依赖的package包/类
private void prepareSelection()
{
ManipulatorSelection selection = params.getSelection();
if(selection == null) return;
byte[] selectionData = selection.getData();
selectionBounds = selection.getBounds();
allocationSelection = Allocation.createSized(renderScript, Element.U8(renderScript), selectionData.length);
allocationSelection.copyFrom(selectionData);
}