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


Java Allocation.copyFrom方法代码示例

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


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

示例1: renderFrame

import android.renderscript.Allocation; //导入方法依赖的package包/类
@Override
public void renderFrame(RenderScript rs, Allocation in, Allocation out) {
    if (blendScript == null) {
        blendScript = ScriptIntrinsicBlend.create(rs, in.getElement());
        setAlphaScript = new ScriptC_set_alpha(rs);
        last = RsUtil.createMatchingAlloc(rs, in);
        last.copyFrom(in);
    }
    out.copyFrom(last);

    // setting the alpha here is just to trick ScriptIntrinsicBlend to do linear
    // interpolation for us
    setAlphaScript.set_alpha_value((short) 200);
    setAlphaScript.forEach_filter(out, out);

    setAlphaScript.set_alpha_value((short) 55);
    setAlphaScript.forEach_filter(in, in);

    blendScript.forEachSrcAtop(in, out);

    last.copyFrom(out);
}
 
开发者ID:lydia-schiff,项目名称:hella-renderscript,代码行数:23,代码来源:TrailsRenderer.java

示例2: applyFilters

import android.renderscript.Allocation; //导入方法依赖的package包/类
public void applyFilters(int from, int to, Allocation in, Allocation out,
        FilterEnvironment environment) {
    if (mDoApplyFilters) {
        if (from < 0) {
            from = 0;
        }
        if (to == -1) {
            to = mFilters.size();
        }
        for (int i = from; i < to; i++) {
            FilterRepresentation representation = mFilters.elementAt(i);
            if (representation.getFilterType() == FilterRepresentation.TYPE_GEOMETRY
                    || representation.getFilterType() == FilterRepresentation.TYPE_BORDER) {
                continue;
            }
            if (i > from) {
                in.copyFrom(out);
            }
            environment.applyRepresentation(representation, in, out);
        }
    }
}
 
开发者ID:asm-products,项目名称:nexus-gallery,代码行数:23,代码来源:ImagePreset.java

示例3: run

import android.renderscript.Allocation; //导入方法依赖的package包/类
public void run() {
 	
 	RenderScript mRS = RenderScript.create(mCtx);
 	int numElements = inputData.length/2;
 	Allocation mInAllocation = Allocation.createSized(mRS, Element.F32_2(mRS), numElements);
    mInAllocation.copyFrom(inputData);
    
    Allocation  mOutAllocation = Allocation.createTyped(mRS, mInAllocation.getType());
    ScriptC_fft mScript = new ScriptC_fft(mRS, mRes, R.raw.fft);

    mScript.invoke_runRestricted(mScript, mInAllocation, mOutAllocation);
    mOutAllocation.copyTo(outputData);
    mInAllocation.copyTo(inputData);
    
    System.out.println("Debug: inBuff " + Arrays.toString(inputData));
    System.out.println("Debug: outBuff " + Arrays.toString(outputData));
}
 
开发者ID:nesl,项目名称:renderScriptFFT,代码行数:18,代码来源:FFT_Test.java

示例4: run

import android.renderscript.Allocation; //导入方法依赖的package包/类
public void run() {
 	
 	RenderScript mRS = RenderScript.create(mCtx);
 	int numElements = inputData.length/2;
 	Allocation mInAllocation = Allocation.createSized(mRS, Element.F32_2(mRS), numElements);
    mInAllocation.copyFrom(inputData);
    
    Allocation  mOutAllocation = Allocation.createTyped(mRS, mInAllocation.getType());
    ScriptC_ifft mScript = new ScriptC_ifft(mRS, mRes, R.raw.ifft);
   
    mScript.invoke_runRestricted(mScript, mInAllocation, mOutAllocation, numElements);
    mOutAllocation.copyTo(outputData);
    mInAllocation.copyTo(inputData);
    
    System.out.println("Debug: inBuff " + Arrays.toString(inputData));
    System.out.println("Debug: outBuff " + Arrays.toString(outputData));
}
 
开发者ID:nesl,项目名称:renderScriptFFT,代码行数:18,代码来源:iFFT_Test.java

示例5: allocFloat2

import android.renderscript.Allocation; //导入方法依赖的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

示例6: initializeParamsAllocation

import android.renderscript.Allocation; //导入方法依赖的package包/类
private void initializeParamsAllocation() {
    Type wInType = Type.createXY(mRs, Element.F32(mRs), hidden_units, inDim);
    Allocation wInAlloc = Allocation.createTyped(mRs, wInType);
    wInAlloc.copyFrom(convertedWIn);
    scriptC_main.set_w_in(wInAlloc);

    Allocation bInAlloc = Allocation.createSized(mRs, Element.F32(mRs), hidden_units);
    bInAlloc.copyFrom(b_in);
    scriptC_main.set_b_in(bInAlloc);

    Type wOutType = Type.createXY(mRs, Element.F32(mRs), outDim, hidden_units);
    Allocation wOutAlloc = Allocation.createTyped(mRs, wOutType);
    wOutAlloc.copyFrom(convertedWOut);
    scriptC_main.set_w_out(wOutAlloc);

    Allocation bOutAlloc = Allocation.createSized(mRs, Element.F32(mRs), outDim);
    bOutAlloc.copyFrom(b_out);
    scriptC_main.set_b_out(bOutAlloc);

    Type weightType = Type.createXYZ(mRs, Element.F32(mRs),
            hidden_units * 4, hidden_units * 2, layerSize);
    Allocation weightAlloc = Allocation.createTyped(mRs, weightType);
    weightAlloc.copyFrom(convertedWeights);
    scriptC_main.set_weights(weightAlloc);

    Type biasType = Type.createXY(mRs, Element.F32(mRs), hidden_units * 4, layerSize);
    Allocation biasAlloc = Allocation.createTyped(mRs, biasType);
    biasAlloc.copyFrom(convertedBiases);
    scriptC_main.set_biases(biasAlloc);
}
 
开发者ID:csarron,项目名称:MobiRNN-EMDL17,代码行数:31,代码来源:Model.java

示例7: applyBorder

import android.renderscript.Allocation; //导入方法依赖的package包/类
public void applyBorder(Allocation in, Allocation out,
        boolean copyOut, FilterEnvironment environment) {
    FilterRepresentation border = getFilterRepresentationForType(
            FilterRepresentation.TYPE_BORDER);
    if (border != null && mDoApplyGeometry) {
        // TODO: should keep the bitmap around
        Allocation bitmapIn = in;
        if (copyOut) {
            bitmapIn = Allocation.createTyped(
                    CachingPipeline.getRenderScriptContext(), in.getType());
            bitmapIn.copyFrom(out);
        }
        environment.applyRepresentation(border, bitmapIn, out);
    }
}
 
开发者ID:asm-products,项目名称:nexus-gallery,代码行数:16,代码来源:ImagePreset.java

示例8: toRGBA

import android.renderscript.Allocation; //导入方法依赖的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

示例9: renderFrame

import android.renderscript.Allocation; //导入方法依赖的package包/类
@Override
public void renderFrame(RenderScript rs, Allocation in, Allocation out) {
    out.copyFrom(in);
}
 
开发者ID:lydia-schiff,项目名称:hella-renderscript,代码行数:5,代码来源:DefaultRsRenderer.java

示例10: predictOnGpu

import android.renderscript.Allocation; //导入方法依赖的package包/类
private int predictOnGpu(float[][] x) {
        if (mRs == null) {
            return -1;
        }

        int timeSteps = x.length;
        float[] convertedX = alter2Dto1D(x);

        scriptC_main.set_time_steps(timeSteps);
        scriptC_main.set_in_dim(inDim);
        scriptC_main.set_hidden_unites(hidden_units);
        scriptC_main.set_layer_size(layerSize);

        // initialize input raw data allocation
        Type inRawType = Type.createXY(mRs, Element.F32(mRs), inDim, timeSteps);
        Allocation inputRawAlloc = Allocation.createTyped(mRs, inRawType);
        inputRawAlloc.copyFrom(convertedX);
        scriptC_main.set_input_raw(inputRawAlloc);

        // initialize activated input data allocation
        Type cellDataType = Type.createXY(mRs, Element.F32(mRs), hidden_units, timeSteps);
        Allocation inputsAlloc = Allocation.createTyped(mRs, cellDataType);
        scriptC_main.set_inputs(inputsAlloc);

        // initialize model parameters(weights and biases) allocation
        initializeParamsAllocation();

        allocIntermediateVariables();

        // initialize label probability output allocation
        Allocation labelProbAlloc = Allocation.createSized(mRs, Element.F32(mRs), outDim);
        scriptC_main.bind_label_prob(labelProbAlloc);
        scriptC_main.set_out_dim(outDim);

        // begin model forward pass computation
        long start = System.currentTimeMillis();
        scriptC_main.invoke_all_in_one();
////        scriptC_main.forEach_input_transform(inputsAlloc);
//        scriptC_main.invoke_input_transform_func();
//        for (int i = 0; i < layerSize; i++) {
////            scriptC_main.forEach_set_zeros(cAlloc);
////            scriptC_main.forEach_set_zeros(hAlloc);
//            scriptC_main.invoke_set_ch_zeros();
//            scriptC_main.set_current_layer(i);
//            for (int j = 0; j < timeSteps; j++) {
//                scriptC_main.set_current_step(j);
//                scriptC_main.invoke_calc_cell_one_step();
////                scriptC_main.invoke_concat_in_h();
//
////                scriptC_main.forEach_linear_map(linearResultAlloc);
////                scriptC_main.invoke_linear_map_func();
//
////                scriptC_main.forEach_pointwise_ch(cAlloc);// or pass hAlloc
////                scriptC_main.invoke_pointwise_ch_func();
//
////                scriptC_main.forEach_update_input(hAlloc);
////                scriptC_main.invoke_update_input_func();
//            }
//        }
////        scriptC_main.forEach_output_transform(labelProbAlloc);
//        scriptC_main.invoke_output_transform_func();
        mRs.finish();

        long end = System.currentTimeMillis();

        // copy result back
        float[] labelProb = new float[outDim];
        labelProbAlloc.copyTo(labelProb);
        Logger.i("invoke time: %s", (end - start));
        return DataUtil.argmax(labelProb) + 1;
    }
 
开发者ID:csarron,项目名称:MobiRNN-EMDL17,代码行数:72,代码来源:Model.java

示例11: toRGBA

import android.renderscript.Allocation; //导入方法依赖的package包/类
@Override
public byte[] toRGBA(Context context, byte[] frame, int previewWidth, int previewHeight, int rgbaSize, byte[] grey)
//-----------------------------------------------------------------------------------------------------------------
{
   ScriptIntrinsicYuvToRGB YUVToRGB = null;
   byte[] rgbaBuffer = null;
   try
   {
      Type.Builder yuvType = new Type.Builder(renderscript, Element.U8(renderscript)).setX(previewWidth).
            setY(previewHeight).setMipmaps(false);
      yuvType.setYuvFormat(ImageFormat.NV21);
      Allocation ain = Allocation.createTyped(renderscript, yuvType.create(), Allocation.USAGE_SCRIPT);

      Type.Builder rgbType = null;
      YUVToRGB = ScriptIntrinsicYuvToRGB.create(renderscript, Element.U8_4(renderscript));
      rgbType = new Type.Builder(renderscript, Element.RGBA_8888(renderscript));
      rgbaBuffer = new byte[rgbaSize];
      rgbType.setX(previewWidth).setY(previewHeight).setMipmaps(false);
      Allocation aOut = Allocation.createTyped(renderscript, rgbType.create(), Allocation.USAGE_SCRIPT);
      ain.copyFrom(frame);
      YUVToRGB.setInput(ain);
      YUVToRGB.forEach(aOut);
      aOut.copyTo(rgbaBuffer);
      if (grey != null)
      {
         Allocation allocGrayOut = null;
         ScriptC_yuv2grey rsYUVtoGrey = null;
         Type.Builder greyTypeBuilder = new Type.Builder(renderscript, Element.U8(renderscript));
         greyTypeBuilder.setX(previewWidth).setY(previewHeight);
         allocGrayOut = Allocation.createTyped(renderscript, greyTypeBuilder.create(), Allocation.USAGE_SCRIPT);
         rsYUVtoGrey = new ScriptC_yuv2grey(renderscript);
         Allocation ainbw = Allocation.createTyped(renderscript, yuvType.create(), Allocation.USAGE_SCRIPT);
         ainbw.copyFrom(frame);
         rsYUVtoGrey.set_in(ainbw);
         rsYUVtoGrey.forEach_yuv2grey(allocGrayOut);
         allocGrayOut.copyTo(grey);
      }
      return rgbaBuffer;
   }
   catch (Exception e)
   {
      Log.e(LOGTAG, "", e);
      return null;
   }
}
 
开发者ID:donaldmunro,项目名称:AARemu,代码行数:46,代码来源:LegacyPreviewCamera.java

示例12: drawToSurface

import android.renderscript.Allocation; //导入方法依赖的package包/类
public void drawToSurface(final byte[] buffer)
//--------------------------------------------
{
   int[] ARGB = new int[buffer.length/4];
   try
   {
      Type.Builder rgbaType = new Type.Builder(renderscript, Element.RGBA_8888(renderscript)).setX(width).
            setY( height).setMipmaps(false);
      Allocation aIn = Allocation.createTyped(renderscript, rgbaType.create(), Allocation.USAGE_SCRIPT);
      Type.Builder argbType = new Type.Builder(renderscript, Element.U32(renderscript)).setX(width).
            setY( height).setMipmaps(false);
      Allocation aOut = Allocation.createTyped(renderscript, argbType.create(), Allocation.USAGE_SCRIPT);
      ScriptC_rgba2argb rs = new ScriptC_rgba2argb(renderscript);
      aIn.copyFrom(buffer);
      rs.set_in(aIn);
      rs.forEach_rgba2argb(aOut);
      aOut.copyTo(ARGB);
   }
   catch (Exception e)
   {
      Log.e("PlaybackThreadFree", "drawToSurface: Renderscript RGBA to ARGB error", e);
      int i=0, j = 0;
      while (i<buffer.length)
      {
         int r = (int) buffer[i++];
         if (r < 0) r = 256 + r; // Brain-dead Java has no unsigned char
         int g = (int) buffer[i++];
         if (g < 0) g = 256 + g;
         int b = (int) buffer[i++];
         if (b < 0) b = 256 + b;
         int a = buffer[i++];
         if (a < 0) a = 256 + a;
         ARGB[j++] = Color.argb(a, r, g, b);
      }
   }

   Bitmap bmp = Bitmap.createBitmap(ARGB, width, height, Bitmap.Config.ARGB_8888);
   Canvas canvas = surface.lockCanvas(null);
   canvas.drawBitmap(bmp, 0, 0, null);
   surface.unlockCanvasAndPost(canvas);
}
 
开发者ID:donaldmunro,项目名称:AARemu,代码行数:42,代码来源:PlaybackThread360.java

示例13: drawToSurface

import android.renderscript.Allocation; //导入方法依赖的package包/类
public void drawToSurface(final byte[] buffer)
//--------------------------------------------
{
   int[] ARGB = new int[buffer.length/4];
   try
   {
      Type.Builder rgbaType = new Type.Builder(renderscript, Element.RGBA_8888(renderscript)).setX(width).
                                                            setY( height).setMipmaps(false);
      Allocation aIn = Allocation.createTyped(renderscript, rgbaType.create(), Allocation.USAGE_SCRIPT);
      Type.Builder argbType = new Type.Builder(renderscript, Element.U32(renderscript)).setX(width).
            setY( height).setMipmaps(false);
      Allocation aOut = Allocation.createTyped(renderscript, argbType.create(), Allocation.USAGE_SCRIPT);
      ScriptC_rgba2argb rs = new ScriptC_rgba2argb(renderscript);
      aIn.copyFrom(buffer);
      rs.set_in(aIn);
      rs.forEach_rgba2argb(aOut);
      aOut.copyTo(ARGB);
   }
   catch (Exception e)
   {
      Log.e("PlaybackThreadFree", "drawToSurface: Renderscript RGBA to ARGB error", e);
      int i=0, j = 0;
      while (i<buffer.length)
      {
         int r = (int) buffer[i++];
         if (r < 0) r = 256 + r; // Brain-dead Java has no unsigned char
         int g = (int) buffer[i++];
         if (g < 0) g = 256 + g;
         int b = (int) buffer[i++];
         if (b < 0) b = 256 + b;
         int a = buffer[i++];
         if (a < 0) a = 256 + a;
         ARGB[j++] = Color.argb(a, r, g, b);
      }
   }

   Bitmap bmp = Bitmap.createBitmap(ARGB, width, height, Bitmap.Config.ARGB_8888);
   Canvas canvas = surface.lockCanvas(null);
   canvas.drawBitmap(bmp, 0, 0, null);
   surface.unlockCanvasAndPost(canvas);
}
 
开发者ID:donaldmunro,项目名称:AARemu,代码行数:42,代码来源:PlaybackThreadFree.java

示例14: run

import android.renderscript.Allocation; //导入方法依赖的package包/类
public void run() {
 	
 	RenderScript mRS = RenderScript.create(mCtx);
 	Allocation mInAllocation = Allocation.createSized(mRS, Element.F32(mRS), inputData.length);
 	
  mInAllocation.copyFrom(inputData);
 
  Allocation  mOutAllocation = Allocation.createTyped(mRS, mInAllocation.getType());
  
  //ScriptC_hamming mScript = new ScriptC_hamming(mRS, mRes, R.raw.hamming);
  //mScript.set_invN(1.0f / (inputData.length - 1));
 
  //mScript.forEach_root(mInAllocation, mOutAllocation);
 	    
  mOutAllocation.copyTo(outputData);
  mInAllocation.copyTo(inputData);
 
  
  System.out.println("Debug: Verification " + Arrays.toString(verification));
  System.out.println("Debug: outBuff " + Arrays.toString(outputData));
}
 
开发者ID:nesl,项目名称:renderScriptFFT,代码行数:22,代码来源:Hamming_Test.java

示例15: run

import android.renderscript.Allocation; //导入方法依赖的package包/类
public void run() {
 	
 	RenderScript mRS = RenderScript.create(mCtx);
 	Allocation mInAllocation = Allocation.createSized(mRS, Element.F32_2(mRS), inputData.length/2);
 	
  mInAllocation.copyFrom(inputData);
 
  Allocation  mOutAllocation = Allocation.createTyped(mRS, mInAllocation.getType());
  
  ScriptC_high_pass mScript = new ScriptC_high_pass(mRS, mRes, R.raw.high_pass);
  mScript.set_gIn(mInAllocation);
  mScript.set_gOut(mOutAllocation);
  mScript.set_a(RC / (RC + dt));
 
  
  //So far rendesrcipt seems to be able to detect this is a serial-like algorithm.
  //If in your testing you start to get error change it back to the serial or linear restriction
  mScript.forEach_root(mInAllocation, mOutAllocation);
 // mScript.invoke_runRestricted(mScript, dt, RC); 
 	    
  mOutAllocation.copyTo(outputData);
  mInAllocation.copyTo(inputData);
 
  
  System.out.println("Debug: Verification " + Arrays.toString(verification));
  System.out.println("Debug: outBuff " + Arrays.toString(outputData));
}
 
开发者ID:nesl,项目名称:renderScriptFFT,代码行数:28,代码来源:HighPass_Test.java


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