当前位置: 首页>>代码示例>>Java>>正文


Java Type.Builder方法代码示例

本文整理汇总了Java中android.renderscript.Type.Builder方法的典型用法代码示例。如果您正苦于以下问题:Java Type.Builder方法的具体用法?Java Type.Builder怎么用?Java Type.Builder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.renderscript.Type的用法示例。


在下文中一共展示了Type.Builder方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: heal

import android.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 mask_bitmap = buildMask(mRoiBounds, mPointsXY);
    Bitmap dest_bitmap = createMutableBitmap(image, mRoiBounds.left, mRoiBounds.top,
            mRoiBounds.width(), mRoiBounds.height());
    Allocation dest_alloc = Allocation.createFromBitmap(rs, dest_bitmap);
    Bitmap src_bitmap = createMutableBitmap(image, mCutOffsetX, mCutOffsetY,
            mRoiBounds.width(), mRoiBounds.height());
    Allocation src_alloc = Allocation.createFromBitmap(rs, src_bitmap);
    Allocation mask_alloc = Allocation.createFromBitmap(rs, mask_bitmap);

    healing.invoke_heal(mask_alloc, src_alloc, dest_alloc);

    dest_alloc.copyTo(dest_bitmap);

    dest_bitmap.setHasAlpha(true);

    // 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(dest_bitmap, mRoiBounds.left, mRoiBounds.top, null);
    Log.v(TAG, " time ss to smart paste = " + (System.nanoTime() - time) / 1E6f + "ms");
    heal_orig(healing, rs, image, output);

}
 
开发者ID:googlecodelabs,项目名称:style-transfer,代码行数:45,代码来源:Healing.java

示例2: allocFloat2

import android.renderscript.Type; //导入方法依赖的package包/类
Allocation allocFloat2(float[] p, RenderScript rs) {
    Type.Builder builderF32_2 = new Type.Builder(rs, Element.F32_2(rs));
    builderF32_2.setX(p.length / 2);
    Allocation ret = Allocation.createTyped(rs, builderF32_2.create());
    ret.copyFrom(p);
    return ret;
}
 
开发者ID:googlecodelabs,项目名称:style-transfer,代码行数:8,代码来源:FindRegion.java

示例3: config

import android.renderscript.Type; //导入方法依赖的package包/类
protected void config(){

        opt.setX(0,height);

        Type.Builder builder = new Type.Builder(rs, Element.F32(rs));
        builder.setX(height);
        out = Allocation.createTyped(rs,builder.create());

        rsSum.set_g_x_start(0);
        rsSum.set_g_x_end(width);
        rsSum.set_g_src(parameter.allocIn);
    }
 
开发者ID:machao-github,项目名称:Camore,代码行数:13,代码来源:RsSumMatFloat.java

示例4: createAllocOutEstimateErr

import android.renderscript.Type; //导入方法依赖的package包/类
private void createAllocOutEstimateErr(){
    Type.Builder builder = new Type.Builder(rs, Element.F32(rs));
    builder.setX(curRect.width() + 1);
    builder.setY(curRect.height()+1);
    Type type = builder.create();
    outErr = Allocation.createTyped(rs,type);
}
 
开发者ID:machao-github,项目名称:Camore,代码行数:8,代码来源:RsMotionErr.java

示例5: allocGray

import android.renderscript.Type; //导入方法依赖的package包/类
static  private void allocGray(){
    Type.Builder builder = new Type.Builder(rs,Element.I32(rs));
    builder.setX(data.getOriWidth());
    builder.setY(data.getOriHeight());

    allocGrayBase = Allocation.createTyped(rs,builder.create());
    allocGrayCur = Allocation.createTyped(rs,builder.create());
}
 
开发者ID:machao-github,项目名称:Camore,代码行数:9,代码来源:RsInvokorBase.java

示例6: allocPartial

import android.renderscript.Type; //导入方法依赖的package包/类
static  private void  allocPartial(){
    Type.Builder builder = new Type.Builder(rs,Element.I32(rs));
    builder.setX(data.getOriWidth());
    builder.setY(data.getOriHeight());
    allocBasePartialX = Allocation.createTyped(rs,builder.create());
    allocBasePartialY = Allocation.createTyped(rs,builder.create());
}
 
开发者ID:machao-github,项目名称:Camore,代码行数:8,代码来源:RsInvokorBase.java

示例7: allocSecPartial

import android.renderscript.Type; //导入方法依赖的package包/类
static  private void allocSecPartial(){
    Type.Builder builder = new Type.Builder(rs,Element.F32(rs));
    builder.setX(data.getOriWidth());
    builder.setY(data.getOriHeight());
    allocBaseSecPartialX = Allocation.createTyped(rs,builder.create());
    allocBaseSecPartialY = Allocation.createTyped(rs,builder.create());
}
 
开发者ID:machao-github,项目名称:Camore,代码行数:8,代码来源:RsInvokorBase.java

示例8: createFilter

import android.renderscript.Type; //导入方法依赖的package包/类
@Override
protected void createFilter(android.content.res.Resources res, float scaleFactor,
                            int quality, Allocation in) {
    RenderScript rsCtx = getRenderScriptContext();

    Type.Builder tb_float = new Type.Builder(rsCtx, Element.F32_4(rsCtx));
    tb_float.setX(in.getType().getX());
    tb_float.setY(in.getType().getY());
    mScript = new ScriptC_saturation(rsCtx, res, R.raw.saturation);
}
 
开发者ID:asm-products,项目名称:nexus-gallery,代码行数:11,代码来源:ImageFilterChanSat.java

示例9: createFilter

import android.renderscript.Type; //导入方法依赖的package包/类
@Override
protected void createFilter(android.content.res.Resources res, float scaleFactor,
                            int quality, Allocation in) {
    RenderScript rsCtx = getRenderScriptContext();

    Type.Builder tb_float = new Type.Builder(rsCtx, Element.F32_4(rsCtx));
    tb_float.setX(in.getType().getX());
    tb_float.setY(in.getType().getY());
    mScript = new ScriptC_grad(rsCtx, res, R.raw.grad);
}
 
开发者ID:asm-products,项目名称:nexus-gallery,代码行数:11,代码来源:ImageFilterGrad.java

示例10: Camera2Callback

import android.renderscript.Type; //导入方法依赖的package包/类
public Camera2Callback()
//----------------------
{
   rs = RenderScript.create(activity);
   switch (fileFormat)
   {
      case YUV_420:
         YUVToRGBA = ScriptIntrinsicYuvToRGB.create(rs, Element.RGBA_8888(rs));
         Type.Builder yuvTypeBuilder = new Type.Builder(rs, Element.YUV(rs));
         yuvTypeBuilder.setX(previewWidth).setY(previewHeight).setYuvFormat(ImageFormat.YUV_420_888);
         ain = Allocation.createTyped(rs, yuvTypeBuilder.create(), Allocation.USAGE_SCRIPT);

         Type.Builder rgbTypeBuilder = new Type.Builder(rs, Element.RGBA_8888(rs));
         rgbTypeBuilder.setX(previewWidth).setY(previewHeight);
         aOut = Allocation.createTyped(rs, rgbTypeBuilder.create(), Allocation.USAGE_SCRIPT);
         break;
      case NV21:
         YUVToRGBA = ScriptIntrinsicYuvToRGB.create(rs, Element.U8_4(rs));
         Type.Builder yuvType = new Type.Builder(rs, Element.U8(rs)).setX(previewWidth).
               setY(previewHeight).setMipmaps(false).setYuvFormat(ImageFormat.NV21);
         Type.Builder rgbaType = new Type.Builder(rs, Element.RGBA_8888(rs)).setX(previewWidth).
               setY(previewHeight).setMipmaps(false);
         ain = Allocation.createTyped(rs, yuvType.create(), Allocation.USAGE_SCRIPT);
         aOut = Allocation.createTyped(rs, rgbaType.create(), Allocation.USAGE_SCRIPT);
         break;
   }
}
 
开发者ID:donaldmunro,项目名称:AARemu,代码行数:28,代码来源:Camera2CameraRenderer.java

示例11: toRGBA

import android.renderscript.Type; //导入方法依赖的package包/类
public byte[] toRGBA(Context context, byte[] frame, int previewWidth, int previewHeight, int rgbaSize, byte[] grey)
//----------------------------------------------------------------------------------------------------------------
{
   try
   {
      final int inputFormat = ImageFormat.YUV_420_888;
      Type.Builder yuvTypeBuilder = new Type.Builder(renderscript, Element.YUV(renderscript));
      yuvTypeBuilder.setX(previewWidth).setY(previewHeight).setYuvFormat(inputFormat);
      Allocation allocYUVIn = Allocation.createTyped(renderscript, yuvTypeBuilder.create(), Allocation.USAGE_SCRIPT);

      Type.Builder rgbTypeBuilder = new Type.Builder(renderscript, Element.RGBA_8888(renderscript));
      rgbTypeBuilder.setX(previewWidth).setY(previewHeight);
      Allocation allocRGBAOut = Allocation.createTyped(renderscript, rgbTypeBuilder.create(), Allocation.USAGE_SCRIPT);

      ScriptIntrinsicYuvToRGB YUVToRGB = ScriptIntrinsicYuvToRGB.create(renderscript, Element.RGBA_8888(renderscript));
      allocYUVIn.copyFrom(frame);
      YUVToRGB.setInput(allocYUVIn);
      YUVToRGB.forEach(allocRGBAOut);
      byte[] rgbaBuffer = new byte[rgbaSize];
      allocRGBAOut.copyTo(rgbaBuffer);
      if (grey != null)
      {
         Type.Builder greyTypeBuilder = new Type.Builder(renderscript, Element.U8(renderscript));
         greyTypeBuilder.setX(cameraWidth).setY(cameraHeight);
         Allocation allocGrayOut = Allocation.createTyped(renderscript, greyTypeBuilder.create(), Allocation.USAGE_SCRIPT);
         ScriptC_yuv2grey rsYUVtoGrey = new ScriptC_yuv2grey(renderscript);
         allocYUVIn.copyFrom(frame);
         rsYUVtoGrey.set_in(allocYUVIn);
         rsYUVtoGrey.forEach_yuv2grey(allocGrayOut);
         allocGrayOut.copyTo(grey);
      }
      return rgbaBuffer;
   }
   catch (Exception e)
   {
      Log.e(LOGTAG, "", e);
      return null;
   }
}
 
开发者ID:donaldmunro,项目名称:AARemu,代码行数:40,代码来源:PreviewCamera.java

示例12: createPreviewAllocation

import android.renderscript.Type; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
public Allocation createPreviewAllocation(RenderScript rs, int usage) throws RSIllegalArgumentException
//------------------------------------------------------------------------------------------------------
{
   Type.Builder yuvBuilder = new Type.Builder(rs, Element.createPixel(rs, Element.DataType.UNSIGNED_8,
                                                                      Element.DataKind.PIXEL_YUV)
   );
   yuvBuilder.setYuvFormat(ImageFormat.YV12);
   yuvBuilder.setX(previewWidth);
   yuvBuilder.setY(previewHeight);
   Allocation a = Allocation.createTyped(rs, yuvBuilder.create(), usage | Allocation.USAGE_IO_INPUT);
   return a;
}
 
开发者ID:donaldmunro,项目名称:AARemu,代码行数:14,代码来源:ARCamera.java

示例13: NV21ToRGBABitmap

import android.renderscript.Type; //导入方法依赖的package包/类
@SuppressLint("NewApi")
public static Bitmap NV21ToRGBABitmap(byte []nv21, int width, int height, Context context) {
	
	TimingLogger timings = new TimingLogger(TIMING_LOG_TAG, "NV21ToRGBABitmap");
	
	Rect rect = new Rect(0, 0, width, height);
	
	try {
		Class.forName("android.renderscript.Element$DataKind").getField("PIXEL_YUV");
		Class.forName("android.renderscript.ScriptIntrinsicYuvToRGB");
    	byte[] imageData = nv21;
    	if (mRS == null) {
    		mRS = RenderScript.create(context);
    		mYuvToRgb = ScriptIntrinsicYuvToRGB.create(mRS, Element.U8_4(mRS));
    		Type.Builder tb = new Type.Builder(mRS, Element.createPixel(mRS, Element.DataType.UNSIGNED_8, Element.DataKind.PIXEL_YUV));
    		tb.setX(width);
    		tb.setY(height);
    		tb.setMipmaps(false);
    		tb.setYuvFormat(ImageFormat.NV21);
    		ain = Allocation.createTyped(mRS, tb.create(), Allocation.USAGE_SCRIPT);
    		timings.addSplit("Prepare for ain");
    		Type.Builder tb2 = new Type.Builder(mRS, Element.RGBA_8888(mRS));
    		tb2.setX(width);
    		tb2.setY(height);
    		tb2.setMipmaps(false);
    		aOut = Allocation.createTyped(mRS, tb2.create(), Allocation.USAGE_SCRIPT & Allocation.USAGE_SHARED);
    		timings.addSplit("Prepare for aOut");
    		bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    		timings.addSplit("Create Bitmap");
		}
    	ain.copyFrom(imageData);
		timings.addSplit("ain copyFrom");
		mYuvToRgb.setInput(ain);
		timings.addSplit("setInput ain");
		mYuvToRgb.forEach(aOut);
		timings.addSplit("NV21 to ARGB forEach");
		aOut.copyTo(bitmap);
		timings.addSplit("Allocation to Bitmap");
	} catch (Exception e) {
		YuvImage yuvImage = new YuvImage(nv21, ImageFormat.NV21, width, height, null);
		timings.addSplit("NV21 bytes to YuvImage");
		
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
        yuvImage.compressToJpeg(rect, 90, baos);
        byte[] cur = baos.toByteArray();
        timings.addSplit("YuvImage crop and compress to Jpeg Bytes");
        
        bitmap = BitmapFactory.decodeByteArray(cur, 0, cur.length);
        timings.addSplit("Jpeg Bytes to Bitmap");
	}
	
   	timings.dumpToLog();
   	return bitmap;
}
 
开发者ID:zhangyaqiang,项目名称:Fatigue-Detection,代码行数:55,代码来源:STUtils.java

示例14: heal_orig

import android.renderscript.Type; //导入方法依赖的package包/类
/**
 * This function only assumes mPointsXY, mPasteOffX, mPasteOffY
 *
 * @param healing
 * @param rs
 * @param image
 */
public void heal_orig(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 steps = (int) Math.hypot(mRoiBounds.width(), mRoiBounds.height()); // match RS Single source
    Log.v(TAG, "Healing_orig  :steps = " + steps);
    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");
}
 
开发者ID:googlecodelabs,项目名称:style-transfer,代码行数:74,代码来源:Healing.java

示例15: example

import android.renderscript.Type; //导入方法依赖的package包/类
private void example() {

        RenderScript mRS = RenderScript.create(this);

        // Loads input image
        Bitmap inputImage = BitmapFactory.decodeResource(getResources(), R.drawable.houseimage);

        // Defines all allocations
        Allocation inputAllocation = Allocation.createFromBitmap(mRS, inputImage);
        Allocation convolvedAllocation = Allocation.createTyped(mRS, inputAllocation.getType());

        // This are the bounds of execution for the allocation (specifically for this example,
        // the area is where the house is in the image).

        // This is the start position of the convolution
        int outIndexX = 253;
        int outIndexY = 81;
        // This is the extension of the convolution [x, x+width) -> [outIndexX, outIndexX + outSizeX)
        int outSizeX = 59;
        int outSizeY = 56;

        Type.Builder tb = new Type.Builder(mRS, Element.RGBA_8888(mRS));
        tb.setX(outSizeX);
        tb.setY(outSizeY);
        Allocation outputAllocation = Allocation.createTyped(mRS, tb.create());

        // --- Pre fill output allocation with black color for debug purposes
        ScriptC_main scriptC_main = new ScriptC_main(mRS);
        scriptC_main.forEach_fillWithBlack(convolvedAllocation);
        scriptC_main.forEach_fillWithBlack(outputAllocation);

        // --- Convolution section

        // Defines the execution limits
        Script.LaunchOptions launchOptions = new Script.LaunchOptions();
        launchOptions.setX(outIndexX, outIndexX + outSizeX);
        launchOptions.setY(outIndexY, outIndexY + outSizeY);

        // Define the convolution
        ScriptIntrinsicConvolve3x3 convolve3x3 = ScriptIntrinsicConvolve3x3.create(mRS, Element.RGBA_8888(mRS));

        // Some coefficients
        float[] coefficients = {
                0.7f, 0, 0.5f,
                0, 1.0f, 0,
                0.5f, 0, 1.0f
        };
        convolve3x3.setCoefficients(coefficients);

        // Execute the allocation with limits
        convolve3x3.setInput(inputAllocation);
        convolve3x3.forEach(convolvedAllocation, launchOptions);

        // --- Output section, copies the convolution result to outputAllocation
        scriptC_main.set_inputAllocation(convolvedAllocation);
        scriptC_main.set_inputOffsetX(outIndexX);
        scriptC_main.set_inputOffsetY(outIndexY);

        scriptC_main.forEach_copyAllocation(outputAllocation);

        // --- Display all stages
        Bitmap intermediateImage = Bitmap.createBitmap(inputImage.getWidth(), inputImage.getHeight(), Bitmap.Config.ARGB_8888);
        Bitmap outputImage = Bitmap.createBitmap(outSizeX, outSizeY, Bitmap.Config.ARGB_8888);

        convolvedAllocation.copyTo(intermediateImage);
        outputAllocation.copyTo(outputImage);

        ((ImageView) findViewById(R.id.imageView)).setImageBitmap(inputImage);
        ((ImageView) findViewById(R.id.imageView2)).setImageBitmap(intermediateImage);
        ((ImageView) findViewById(R.id.imageView3)).setImageBitmap(outputImage);

    }
 
开发者ID:csarron,项目名称:renderscript_examples,代码行数:73,代码来源:MainActivity.java


注:本文中的android.renderscript.Type.Builder方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。