本文整理汇总了Java中android.support.v8.renderscript.Type.Builder方法的典型用法代码示例。如果您正苦于以下问题:Java Type.Builder方法的具体用法?Java Type.Builder怎么用?Java Type.Builder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v8.renderscript.Type
的用法示例。
在下文中一共展示了Type.Builder方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: yuvToRgb
import android.support.v8.renderscript.Type; //导入方法依赖的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;
}
示例2: MandelbrotRSGen
import android.support.v8.renderscript.Type; //导入方法依赖的package包/类
public MandelbrotRSGen(Context context, int width, int height, int iterations, int[] palette) {
super(context, width, height, iterations, palette);
// Create the RenderScript context used to communicate with our RS.
// Then create our actual script which will do the real work
mRSCtx = RenderScript.create(mContext);
mMandGen = new ScriptC_mand_gen(mRSCtx);
// Set the initial parameters for the generator.
// TODO: ADD SUPPORT FOR RE-CENTERING AND ZOOM
mMandGen.set_width(width);
mMandGen.set_height(height);
mMandGen.set_iter(iterations);
mMandGen.set_paletteLen(mPalette.length);
Type.Builder intArrayBuilder = new Type.Builder(mRSCtx,
Element.I32(mRSCtx));
intArrayBuilder.setX(mPalette.length);
Allocation allocPalette =
Allocation.createTyped(mRSCtx,
intArrayBuilder.create());
allocPalette.copyFrom(mPalette);
mMandGen.bind_palette(allocPalette);
}
示例3: MandelbrotRSFloatGen
import android.support.v8.renderscript.Type; //导入方法依赖的package包/类
public MandelbrotRSFloatGen(Context context, int width, int height, int iterations, int[] palette) {
super(context, width, height, iterations, palette);
// Create the RenderScript context used to communicate with our RS.
// Then create our actual script which will do the real work
mRSCtx = RenderScript.create(mContext);
mMandGen = new ScriptC_mand_float_gen(mRSCtx);
// Set the initial parameters for the generator.
// TODO: ADD SUPPORT FOR RE-CENTERING AND ZOOM
mMandGen.set_width(width);
mMandGen.set_height(height);
mMandGen.set_iter(iterations);
mMandGen.set_paletteLen(mPalette.length);
Type.Builder intArrayBuilder = new Type.Builder(mRSCtx,
Element.I32(mRSCtx));
intArrayBuilder.setX(mPalette.length);
Allocation allocPalette =
Allocation.createTyped(mRSCtx,
intArrayBuilder.create());
allocPalette.copyFrom(mPalette);
mMandGen.bind_palette(allocPalette);
}
示例4: convertYuv420ToBitmap
import android.support.v8.renderscript.Type; //导入方法依赖的package包/类
private static Bitmap convertYuv420ToBitmap(Image image) {
RenderScript rs = mRenderScript;
final int width = image.getWidth();
final int height = image.getHeight();
// prepare input Allocation for RenderScript
Type.Builder inType = new Type.Builder(rs, Element.U8(rs)).setX(width).setY(height).setYuvFormat(ImageFormat.YV12);
Allocation inAlloc = Allocation.createTyped(rs, inType.create(), Allocation.USAGE_SCRIPT);
byte[] rawBuffer = new byte[inAlloc.getBytesSize()];
int lumaSize = width * height;
int chromaSize = (width / 2) * (height / 2);
Image.Plane[] planes = image.getPlanes();
planes[0].getBuffer().get(rawBuffer, 0, lumaSize);
planes[1].getBuffer().get(rawBuffer, lumaSize, chromaSize);
planes[2].getBuffer().get(rawBuffer, lumaSize + chromaSize, chromaSize);
inAlloc.copyFromUnchecked(rawBuffer);
// prepare output Allocation for RenderScript
Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Allocation outAlloc = Allocation.createFromBitmap(rs, bmp, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT | Allocation.USAGE_SHARED);
// convert YUV to RGB colorspace
ScriptC_yuv2rgb converter = new ScriptC_yuv2rgb(rs);
converter.set_gYUV(inAlloc);
converter.forEach_convert(outAlloc);
outAlloc.copyTo(bmp);
return bmp;
}
示例5: createAllocation
import android.support.v8.renderscript.Type; //导入方法依赖的package包/类
public Allocation createAllocation(RenderScript rs) {
final int sx = xSize;
final int sy = ySize;
final int sz = zSize;
Type.Builder tb = new Type.Builder(rs, Element.U8_4(rs));
tb.setX(sx);
tb.setY(sy);
tb.setZ(sz);
Type t = tb.create();
Allocation mCube = Allocation.createTyped(rs, t);
mCube.copyFromUnchecked(getCube());
return mCube;
}
示例6: initLUT
import android.support.v8.renderscript.Type; //导入方法依赖的package包/类
public void initLUT (int setSizeX, int setSizeY, int setSizeZ) {
lutSizeX = setSizeX;
lutSizeY = setSizeY;
lutSizeZ = setSizeZ;
colorLutArray = new int[lutSizeX * lutSizeY * lutSizeZ];
rS = RenderScript.create(this);
Type.Builder tb = new Type.Builder(rS, Element.U8_4(rS));
tb.setX(lutSizeX);
tb.setY(lutSizeY);
tb.setZ(lutSizeZ);
Type t = tb.create();
allocLut = Allocation.createTyped(rS, t);
for (int x = 0; x < lutSizeX; x++) {
for (int y = 0; y < lutSizeY; y++) {
for (int z = 0; z < lutSizeZ; z++) {
colorLutArray[x * lutSizeY * lutSizeZ + y * lutSizeZ + z] = Color.argb(0xff,
(0xff * x / (lutSizeX - 1)),
(0xff * y / (lutSizeY - 1)),
(0xff * z / (lutSizeZ - 1)));
/*
Log.d(TAG, "x,y,z = " + Integer.toString(x) + ", " + Integer.toString(y) + ", " +
Integer.toString(z) + " = " + Integer.toHexString(colorLutArray[x * lutSizeY * lutSizeZ + y * lutSizeZ + z]));
*/
}
}
}
allocLut.copyFromUnchecked(colorLutArray);
sI3dLut = ScriptIntrinsic3DLUT.create(rS, Element.U8_4(rS));
sI3dLut.setLUT(allocLut);
}
示例7: CameraPreviewCallback
import android.support.v8.renderscript.Type; //导入方法依赖的package包/类
public CameraPreviewCallback()
//-----------------------------
{
if (LegacyCameraRenderer.this.camera.getFileFormat() == ARCamera.RecordFileFormat.NV21)
{
rsNv21toRGBA = RenderScript.create(activity);
YUVToRGBA = ScriptIntrinsicYuvToRGB.create(rsNv21toRGBA, Element.U8_4(rsNv21toRGBA));
Type.Builder yuvType = new Type.Builder(rsNv21toRGBA, Element.U8(rsNv21toRGBA)).setX(previewWidth).
setY(previewHeight).setMipmaps(false).setYuvFormat(ImageFormat.NV21);
Type.Builder rgbaType = new Type.Builder(rsNv21toRGBA, Element.RGBA_8888(rsNv21toRGBA)).setX(previewWidth).
setY(previewHeight).setMipmaps(false);
ain = Allocation.createTyped(rsNv21toRGBA, yuvType.create(), Allocation.USAGE_SCRIPT);
aOut = Allocation.createTyped(rsNv21toRGBA, rgbaType.create(), Allocation.USAGE_SCRIPT);
}
}
示例8: ResidualBlockChained
import android.support.v8.renderscript.Type; //导入方法依赖的package包/类
public ResidualBlockChained(Context ctx, RenderScript rs, int in_channels, int out_channels, int ksize, int stride, int pad, int numBlocks) {
super(ctx, rs);
this.in_channels = in_channels;
this.out_channels = out_channels;
this.ksize = ksize;
this.stride = stride;
this.pad = pad;
this.mNumBlocks = numBlocks;
this.b = new float[out_channels];
this.W = new float[out_channels * in_channels * ksize * ksize];
// 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 each convolution operation.
W_alloc = new Allocation[mNumBlocks * 2];
b_alloc = new Allocation[mNumBlocks * 2];
Type.Builder tb = new Type.Builder(mRS, Element.F32(mRS));
tb.setX(padded_Y_blas).setY(out_channels);
for (int i = 0; i < mNumBlocks * 2; i++) {
W_alloc[i] = Allocation.createTyped(mRS, tb.create());
}
Type.Builder tbeta = new Type.Builder(mRS, Element.F32(mRS));
tbeta.setX(out_channels);
for (int i = 0; i < mNumBlocks * 2; i++) {
b_alloc[i] = Allocation.createTyped(mRS, tbeta.create());
}
// Create Allocations for each batch normalization operation.
gamma = new float[out_channels];
beta = new float[out_channels];
avg_mean = new float[out_channels];
avg_var = new float[out_channels];
gamma_alloc = new Allocation[numBlocks * 2];
beta_alloc = new Allocation[numBlocks * 2];
avg_mean_alloc = new Allocation[numBlocks * 2];
avg_var_alloc = new Allocation[numBlocks * 2];
Type.Builder tbn = new Type.Builder(mRS, Element.F32(mRS));
tbn.setX(out_channels);
for (int i = 0; i < numBlocks * 2; i++) {
gamma_alloc[i] = Allocation.createTyped(mRS, tbn.create());
beta_alloc[i] = Allocation.createTyped(mRS, tbn.create());
avg_mean_alloc[i] = Allocation.createTyped(mRS, tbn.create());
avg_var_alloc[i] = Allocation.createTyped(mRS, tbn.create());
}
// Initialize the RS kernels;
mResidualBlock = new ScriptC_residualblock(mRS);
mActivation = new ScriptC_activation(mRS);
mConvovle = new ScriptC_convolve2d(mRS);
rs_BN = new ScriptC_batchnormalization(mRS);
// Set the global variables for the convolution 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_tile_h(TILE_Y);
}
示例9: heal
import android.support.v8.renderscript.Type; //导入方法依赖的package包/类
/**
* This function only assumes mPointsXY, mPasteOffX, mPasteOffY
*
* @param healing
* @param rs
* @param image
*/
public void heal(ScriptC_healing healing, RenderScript rs, Bitmap image, Bitmap output) {
long time = System.nanoTime();
Type.Builder floatImage = new Type.Builder(rs, Element.F32_3(rs));
floatImage.setX(mRoiBounds.width());
floatImage.setY(mRoiBounds.height());
Bitmap maskBitmap = buildMask(mRoiBounds, mPointsXY);
Allocation dest1 = Allocation.createTyped(rs, floatImage.create());
Allocation dest2 = Allocation.createTyped(rs, floatImage.create());
healing.set_dest1(dest1);
healing.set_dest2(dest2);
Bitmap destBitmap = createMutableBitmap(image, mRoiBounds.left, mRoiBounds.top,
mRoiBounds.width(), mRoiBounds.height());
Allocation dest_uc4 = Allocation.createFromBitmap(rs, destBitmap);
healing.forEach_convert_to_f(dest_uc4, dest1);
Bitmap src = createMutableBitmap(image, mCutOffsetX, mCutOffsetY,
mRoiBounds.width(), mRoiBounds.height());
Allocation src_f3 = Allocation.createTyped(rs, floatImage.create());
Allocation src_uc4 = Allocation.createFromBitmap(rs, src);
healing.forEach_convert_to_f(src_uc4, src_f3);
healing.set_src(src_f3);
Allocation mask = Allocation.createFromBitmap(rs, maskBitmap);
healing.set_mask(mask);
Allocation laplace_f3 = Allocation.createTyped(rs, floatImage.create());
healing.set_laplace(laplace_f3);
Script.LaunchOptions options = new Script.LaunchOptions();
options.setX(1, mRoiBounds.width() - 1);
options.setY(1, mRoiBounds.height() - 1);
healing.forEach_laplacian(laplace_f3, options);
healing.forEach_copyMasked(mask, dest1);
int area = calcMaskArea(mask);
int steps = (int) Math.sqrt(area);
for (int i = 0; i < steps; i++) {
healing.forEach_solve1(mask, dest2);
healing.forEach_solve2(mask, dest1);
}
healing.forEach_convert_to_uc(dest1, dest_uc4);
rs.finish();
healing.forEach_alphaMask(dest_uc4, dest_uc4);
rs.finish();
dest_uc4.copyTo(destBitmap);
rs.finish();
destBitmap.setHasAlpha(true);
rs.finish();
// build the undo
mUndoBitmap = Bitmap.createBitmap(mRoiBounds.width(), mRoiBounds.height(),
Bitmap.Config.ARGB_8888);
Canvas undoCanvas = new Canvas(mUndoBitmap);
Rect undoRect = new Rect(0, 0, mRoiBounds.width(), mRoiBounds.height());
undoCanvas.drawBitmap(output, mRoiBounds, undoRect, null);
Canvas c = new Canvas(output);
c.drawBitmap(image, 0, 0, null);
c.drawBitmap(destBitmap, mRoiBounds.left, mRoiBounds.top, null);
Log.v(TAG, " time to smart paste = " + (System.nanoTime() - time) / 1E6f + "ms");
}
示例10: findMatch
import android.support.v8.renderscript.Type; //导入方法依赖的package包/类
public Rect findMatch(ScriptC_find_region findRegion, RenderScript mRs, Bitmap image) {
long time = System.nanoTime();
Allocation border_coords;
Allocation border_values;
Type.Builder builderU32_2 = new Type.Builder(mRs, Element.U32_2(mRs));
builderU32_2.setX(mPointsXY.length / 2);
border_coords = Allocation.createTyped(mRs, builderU32_2.create());
Allocation border_coords_float;
border_coords_float = Allocation.createSized(mRs, Element.F32_2(mRs), mPointsXY.length / 2);
border_coords_float.copyFrom(mPointsXY);
findRegion.forEach_toInt(border_coords_float, border_coords);
findRegion.set_border_coords(border_coords);
findRegion.set_image(Allocation.createFromBitmap(mRs, image));
Type.Builder builderF32_3 = new Type.Builder(mRs, Element.F32_3(mRs));
builderF32_3.setX(mPointsXY.length / 2);
border_values = Allocation.createTyped(mRs, builderF32_3.create());
findRegion.set_border_values(border_values);
findRegion.forEach_extractBorder(border_coords, border_values);
Type.Builder builderF32 = new Type.Builder(mRs, Element.F32(mRs));
builderF32.setX(mSearchRange.width());
builderF32.setY(mSearchRange.height());
Allocation fit = Allocation.createTyped(mRs, builderF32.create());
findRegion.set_borderLength(mPointsXY.length / 2);
int noSearch_x = mRoiBounds.left - mSearchRange.left;
int noSearch_y = mRoiBounds.top - mSearchRange.top;
findRegion.set_imagePosX(noSearch_x);
findRegion.set_imagePosY(noSearch_y);
Script.LaunchOptions options = new Script.LaunchOptions();
options.setX(0, mSearchRange.width() - mRoiBounds.width());
options.setY(0, mSearchRange.height() - mRoiBounds.height());
findRegion.forEach_bordercorrelation(fit, options);
Log.v(TAG, "noSearch " + noSearch_x + ", " + noSearch_y);
Log.v(TAG, "noSearch " + mRoiBounds.width() + ", " + mRoiBounds.height());
Allocation fit_max = Allocation.createSized(mRs, Element.I32_2(mRs), 1);
findRegion.invoke_findMin(fit, fit_max, noSearch_x, noSearch_y,
mRoiBounds.width(), mRoiBounds.height());
int[] mina = new int[2];
fit_max.copyTo(mina);
mCutOffsetX = mina[0] + mSearchRange.left;
mCutOffsetY = mina[1] + mSearchRange.top;
Log.v(TAG, "Time to find replacement= " + (System.nanoTime() - time) / 1E6f + "ms");
return mRoiBounds;
}