當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。