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


Java Allocation.copyFrom方法代码示例

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


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

示例1: loadModel

import android.support.v8.renderscript.Allocation; //导入方法依赖的package包/类
public void loadModel(String path) throws IOException {
    mInputStream = mContext.getAssets().open(path + "/W", AssetManager.ACCESS_BUFFER);
    ByteBuffer bb = readInput(mInputStream);
    FloatBuffer.wrap(W).put(bb.asFloatBuffer());

    // padding for GPU BLAS when necessary.
    int W_height_input = in_channels * ksize * ksize;
    if (padded_Y_blas == W_height_input) {
        // If the input width already satisfies the requirement, just copy to the Allocation.
        W_alloc.copyFrom(W);
    } else {
        // If not, a temp allocation needs to be created.
        Allocation input = Allocation.createTyped(mRS,
                Type.createXY(mRS, Element.F32(mRS), W_height_input, out_channels));
        input.copyFrom(W);
        W_alloc.copy2DRangeFrom(0, 0, W_height_input, out_channels, input, 0, 0);
    }

    mInputStream = mContext.getAssets().open(path + "/b", AssetManager.ACCESS_BUFFER);
    bb = readInput(mInputStream);
    FloatBuffer.wrap(b).put(bb.asFloatBuffer());
    b_alloc.copyFrom(b);

    mInputStream.close();
    Log.v(TAG, "Convolution2D loaded: " + b[0]);
}
 
开发者ID:googlecodelabs,项目名称:style-transfer,代码行数:27,代码来源:Convolution2D.java

示例2: yuvToRgb

import android.support.v8.renderscript.Allocation; //导入方法依赖的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;
}
 
开发者ID:silvaren,项目名称:easyrs,代码行数:29,代码来源:YuvToRgb.java

示例3: 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);
}
 
开发者ID:karol-202,项目名称:PaintPlusPlus,代码行数:18,代码来源:ColorsBrightness.java

示例4: 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);
}
 
开发者ID:karol-202,项目名称:PaintPlusPlus,代码行数:18,代码来源:ColorsInvert.java

示例5: 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);
}
 
开发者ID:mtbii,项目名称:imij,代码行数:18,代码来源:Imij.java

示例6: 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);
  }
 
开发者ID:nicastel,项目名称:renderscript_texture_compressor,代码行数:26,代码来源:RsETC1Util.java

示例7: MandelbrotRSGen

import android.support.v8.renderscript.Allocation; //导入方法依赖的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);
}
 
开发者ID:hiq-larryschiefer,项目名称:SimpleFractal,代码行数:24,代码来源:MandelbrotRSGen.java

示例8: MandelbrotRSFloatGen

import android.support.v8.renderscript.Allocation; //导入方法依赖的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);
}
 
开发者ID:hiq-larryschiefer,项目名称:SimpleFractal,代码行数:24,代码来源:MandelbrotRSFloatGen.java

示例9: 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;
}
 
开发者ID:vipulyaara,项目名称:betterHotels,代码行数:38,代码来源:RSBlurProcess.java

示例10: attachCurvesRGB

import android.support.v8.renderscript.Allocation; //导入方法依赖的package包/类
private void attachCurvesRGB(ScriptC_cm_curves_rgb script, CurveManipulatorParams params)
{
	for(int i = 0; i < params.getCurvesAmount(); i++)
	{
		ChannelInOutSet channels = params.getChannel(i);
		ColorCurve curve = params.getCurve(i);
		byte[] curveMap = curve.createByteColorsMap();
		Allocation allocation = Allocation.createSized(renderScript, Element.U8(renderScript), curveMap.length);
		allocation.copyFrom(curveMap);
		
		if(channels.getIn() == ColorChannel.RED && channels.getOut() == ColorChannel.RED)
			script.bind_curve_rtr(allocation);
		else if(channels.getIn() == ColorChannel.RED && channels.getOut() == ColorChannel.GREEN)
			script.bind_curve_rtg(allocation);
		else if(channels.getIn() == ColorChannel.RED && channels.getOut() == ColorChannel.BLUE)
			script.bind_curve_rtb(allocation);
		else if(channels.getIn() == ColorChannel.GREEN && channels.getOut() == ColorChannel.RED)
			script.bind_curve_gtr(allocation);
		else if(channels.getIn() == ColorChannel.GREEN && channels.getOut() == ColorChannel.GREEN)
			script.bind_curve_gtg(allocation);
		else if(channels.getIn() == ColorChannel.GREEN && channels.getOut() == ColorChannel.BLUE)
			script.bind_curve_gtb(allocation);
		else if(channels.getIn() == ColorChannel.BLUE && channels.getOut() == ColorChannel.RED)
			script.bind_curve_btr(allocation);
		else if(channels.getIn() == ColorChannel.BLUE && channels.getOut() == ColorChannel.GREEN)
			script.bind_curve_btg(allocation);
		else if(channels.getIn() == ColorChannel.BLUE && channels.getOut() == ColorChannel.BLUE)
			script.bind_curve_btb(allocation);
	}
}
 
开发者ID:karol-202,项目名称:PaintPlusPlus,代码行数:31,代码来源:ColorsCurveManipulator.java

示例11: attachCurvesHSV

import android.support.v8.renderscript.Allocation; //导入方法依赖的package包/类
private void attachCurvesHSV(ScriptC_cm_curves_hsv script, CurveManipulatorParams params)
{
	for(int i = 0; i < params.getCurvesAmount(); i++)
	{
		ChannelInOutSet channels = params.getChannel(i);
		ColorCurve curve = params.getCurve(i);
		short[] curveMap = curve.createShortColorsMap();
		Allocation allocation = Allocation.createSized(renderScript, Element.U16(renderScript), curveMap.length);
		allocation.copyFrom(curveMap);
		
		if(channels.getIn() == ColorChannel.HUE && channels.getOut() == ColorChannel.HUE)
			script.bind_curve_hth(allocation);
		else if(channels.getIn() == ColorChannel.HUE && channels.getOut() == ColorChannel.SATURATION)
			script.bind_curve_hts(allocation);
		else if(channels.getIn() == ColorChannel.HUE && channels.getOut() == ColorChannel.VALUE)
			script.bind_curve_htv(allocation);
		else if(channels.getIn() == ColorChannel.SATURATION && channels.getOut() == ColorChannel.HUE)
			script.bind_curve_sth(allocation);
		else if(channels.getIn() == ColorChannel.SATURATION && channels.getOut() == ColorChannel.SATURATION)
			script.bind_curve_sts(allocation);
		else if(channels.getIn() == ColorChannel.SATURATION && channels.getOut() == ColorChannel.VALUE)
			script.bind_curve_stv(allocation);
		else if(channels.getIn() == ColorChannel.VALUE && channels.getOut() == ColorChannel.HUE)
			script.bind_curve_vth(allocation);
		else if(channels.getIn() == ColorChannel.VALUE && channels.getOut() == ColorChannel.SATURATION)
			script.bind_curve_vts(allocation);
		else if(channels.getIn() == ColorChannel.VALUE && channels.getOut() == ColorChannel.VALUE)
			script.bind_curve_vtv(allocation);
	}
}
 
开发者ID:karol-202,项目名称:PaintPlusPlus,代码行数:31,代码来源:ColorsCurveManipulator.java

示例12: 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;
}
 
开发者ID:Cangol,项目名称:AndroidStackBlur,代码行数:38,代码来源:RSBlurProcess.java

示例13: blur

import android.support.v8.renderscript.Allocation; //导入方法依赖的package包/类
@Override
public Bitmap blur(int radius, Bitmap blurred) {
    int width = blurred.getWidth();
    int height = blurred.getHeight();

    ScriptC_stackblur blurScript = new ScriptC_stackblur(_rs);
    Allocation inAllocation = Allocation.createFromBitmap(_rs, blurred);

    blurScript.set_gIn(inAllocation);
    blurScript.set_width(width);
    blurScript.set_height(height);
    blurScript.set_radius(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;
}
 
开发者ID:patrickfav,项目名称:BlurTestAndroid,代码行数:36,代码来源:RenderScriptStackBlur.java

示例14: blur

import android.support.v8.renderscript.Allocation; //导入方法依赖的package包/类
@Override
public Bitmap blur(int radius, Bitmap blurred) {
    int width = blurred.getWidth();
    int height = blurred.getHeight();

    ScriptC_stackblur blurScript = new ScriptC_stackblur(_rs);
    Allocation inAllocation = Allocation.createFromBitmap(_rs, blurred);

    blurScript.set_gIn(inAllocation);
    blurScript.set_width(width);
    blurScript.set_height(height);
    blurScript.set_radius(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;

}
 
开发者ID:patrickfav,项目名称:Dali,代码行数:37,代码来源:RenderScriptStackBlur.java

示例15: loadModel

import android.support.v8.renderscript.Allocation; //导入方法依赖的package包/类
public void loadModel(String path) throws IOException {
    for (int i = 0; i < mNumBlocks; i++) {
        for (int j = 0; j < 2; j++) {
            // Read all convolution blocks.
            mInputStream = mContext.getAssets().open(path + "/r" + (i + 1) + "/c" + (j + 1) + "/W", AssetManager.ACCESS_BUFFER);
            ByteBuffer bb = readInput(mInputStream);
            FloatBuffer.wrap(W).put(bb.asFloatBuffer());

            // padding for GPU BLAS
            int W_height_input = in_channels * ksize * ksize;
            if (padded_Y_blas == W_height_input) {
                // If the input width already satisfies the requirement, just copy to the Allocation.
                W_alloc[i * 2 + j].copyFrom(W);
            } else {
                // If not, a temp allocation needs to be created.
                Allocation input = Allocation.createTyped(mRS,
                        Type.createXY(mRS, Element.F32(mRS), W_height_input, out_channels));
                input.copyFrom(W);
                W_alloc[i * 2 + j].copy2DRangeFrom(0, 0, W_height_input, out_channels, input, 0, 0);
            }

            mInputStream = mContext.getAssets().open(path + "/r" + (i + 1) + "/c" + (j + 1) + "/b", AssetManager.ACCESS_BUFFER);
            bb = readInput(mInputStream);
            FloatBuffer.wrap(b).put(bb.asFloatBuffer());
            b_alloc[i * 2 + j].copyFrom(b);

            // Read all batch normalization blocks;
            mInputStream = mContext.getAssets().open(path + "/r" + (i + 1) + "/b" + (j + 1) + "/gamma", AssetManager.ACCESS_BUFFER);
            bb = readInput(mInputStream);
            FloatBuffer.wrap(gamma).put(bb.asFloatBuffer());
            gamma_alloc[i * 2 + j].copyFrom(gamma);

            mInputStream = mContext.getAssets().open(path + "/r" + (i + 1) + "/b" + (j + 1) + "/beta", AssetManager.ACCESS_BUFFER);
            bb = readInput(mInputStream);
            FloatBuffer.wrap(beta).put(bb.asFloatBuffer());
            beta_alloc[i * 2 + j].copyFrom(beta);

            mInputStream = mContext.getAssets().open(path + "/r" + (i + 1) + "/b" + (j + 1) + "/avg_mean", AssetManager.ACCESS_BUFFER);
            bb = readInput(mInputStream);
            FloatBuffer.wrap(avg_mean).put(bb.asFloatBuffer());
            avg_mean_alloc[i * 2 + j].copyFrom(avg_mean);

            mInputStream = mContext.getAssets().open(path + "/r" + (i + 1) + "/b" + (j + 1) + "/avg_var", AssetManager.ACCESS_BUFFER);
            bb = readInput(mInputStream);
            FloatBuffer.wrap(avg_var).put(bb.asFloatBuffer());
            avg_var_alloc[i * 2 + j].copyFrom(avg_var);

        }

    }
    mInputStream.close();
    Log.v(TAG, "ResidualBlockChained loaded: " + b[0]);
}
 
开发者ID:googlecodelabs,项目名称:style-transfer,代码行数:54,代码来源:ResidualBlockChained.java


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