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


Java Allocation类代码示例

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


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

示例1: blur

import android.support.v8.renderscript.Allocation; //导入依赖的package包/类
public static void blur(final Bitmap src, final int radius, final OnBlurListener onBlurListener) {
    new Thread(new Runnable() {
        @Override
        public void run() {
            final Allocation input = Allocation.createFromBitmap(renderScript, src);
            final Allocation output = Allocation.createTyped(renderScript, input.getType());
            final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(renderScript, Element.U8_4(renderScript));

            script.setRadius(radius);
            script.setInput(input);
            script.forEach(output);
            output.copyTo(src);

            onBlurListener.onBlur(src);
        }
    }).start();
}
 
开发者ID:wonderkiln,项目名称:ShadowKit-Android,代码行数:18,代码来源:ShadowKit.java

示例2: 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

示例3: BatchNormalization

import android.support.v8.renderscript.Allocation; //导入依赖的package包/类
public BatchNormalization(Context ctx, RenderScript rs, int size) {
    super(ctx, rs);

    this.size = size;
    gamma = new float[size];
    beta = new float[size];
    avg_mean = new float[size];
    avg_var = new float[size];

    // Create RS Allocations.
    gamma_alloc = Allocation.createSized(mRS, Element.F32(mRS), size);
    beta_alloc = Allocation.createSized(mRS, Element.F32(mRS), size);
    avg_mean_alloc = Allocation.createSized(mRS, Element.F32(mRS), size);
    avg_var_alloc = Allocation.createSized(mRS, Element.F32(mRS), size);

    // Initialize the BatchNormalization kernel;
    rs_BN = new ScriptC_batchnormalization(mRS);

    // Set the global variables for the RS kernel.
    rs_BN.set_beta_alloc(beta_alloc);
    rs_BN.set_gamma_alloc(gamma_alloc);
    rs_BN.set_mean_alloc(avg_mean_alloc);
    rs_BN.set_var_alloc(avg_var_alloc);
    rs_BN.set_size(size);
}
 
开发者ID:googlecodelabs,项目名称:style-transfer,代码行数:26,代码来源:BatchNormalization.java

示例4: process

import android.support.v8.renderscript.Allocation; //导入依赖的package包/类
public Allocation process(Allocation input, int height, int width) {
    // 1st convolution.
    Allocation output = c1.process(input, height, width);
    // 1st batch normalization.
    b1.process(output);
    // Use RELU for the activation function.
    mActivation.forEach_relu(output, output);
    // 2nd convolution.
    output = c2.process(output, c1.outH, c1.outW);
    // 2nd batch normalization.
    b2.process(output);

    // Add the residual back to the input image.
    mResidualBlock.set_img_alloc(input);
    mResidualBlock.forEach_add(output, output);

    // Update the output dimensions.
    outH = c2.outH;
    outW = c2.outW;
    return output;
}
 
开发者ID:googlecodelabs,项目名称:style-transfer,代码行数:22,代码来源:ResidualBlock.java

示例5: doInBackground

import android.support.v8.renderscript.Allocation; //导入依赖的package包/类
@Override
protected Drawable doInBackground(Drawable... drawables) {
    finalResult = ArtworkUtils.optimizeBitmap(bitmap, bitmap.getWidth());
    if (finalResult != null && finalResult.getConfig() != null) {
        scriptIntrinsicBlur = ScriptIntrinsicBlur.create(renderScript, Element.U8_4(renderScript));
        allocationIn = Allocation.createFromBitmap(renderScript, finalResult, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT | Allocation.USAGE_SHARED);
        allocationOut = Allocation.createTyped(renderScript, allocationIn.getType());
        scriptIntrinsicBlur.setRadius(radius); //radius option from users
        scriptIntrinsicBlur.setInput(allocationIn);
        scriptIntrinsicBlur.forEach(allocationOut);
        allocationOut.copyTo(finalResult);
        bitmapDrawable = new BitmapDrawable(context.getResources(), finalResult);
        return bitmapDrawable;
    } else {
        Drawable defaultDrawable = ContextCompat.getDrawable(context, R.mipmap.ic_launcher);
        return defaultDrawable;
    }
}
 
开发者ID:RajneeshSingh007,项目名称:MusicX-music-player,代码行数:19,代码来源:BlurArtwork.java

示例6: blur

import android.support.v8.renderscript.Allocation; //导入依赖的package包/类
public void blur(Bitmap originBitmap) {
    Bitmap scaledBitmap = Bitmap.createScaledBitmap(originBitmap, originBitmap.getWidth() / scaleRatio, originBitmap.getHeight() / scaleRatio, false);
    Bitmap mBitmapToBlur = scaledBitmap.copy(Bitmap.Config.ARGB_8888, true);
    Bitmap mBlurredBitmap = Bitmap.createBitmap(mBitmapToBlur.getWidth(), mBitmapToBlur.getHeight(),
            Bitmap.Config.ARGB_8888);

    mRenderScript = RenderScript.create(getContext());
    mBlurScript = ScriptIntrinsicBlur.create(mRenderScript, Element.U8_4(mRenderScript));

    mBlurInput = Allocation.createFromBitmap(mRenderScript, mBitmapToBlur,
            Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
    mBlurOutput = Allocation.createTyped(mRenderScript, mBlurInput.getType());

    mBlurInput.copyFrom(mBitmapToBlur);
    mBlurScript.setRadius(blurRadius);
    mBlurScript.setInput(mBlurInput);
    mBlurScript.forEach(mBlurOutput);
    mBlurOutput.copyTo(mBlurredBitmap);

    drawableFadeDisplayer.display(mBlurredBitmap, this);
    scaledBitmap.recycle();
    mBitmapToBlur.recycle();
    mRenderScript.destroy();
}
 
开发者ID:J1aDong,项目名称:Gank-Meizi,代码行数:25,代码来源:BlurImageView.java

示例7: 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

示例8: resize

import android.support.v8.renderscript.Allocation; //导入依赖的package包/类
/**
 * Resizes a Bitmap image to a target width and height.
 */
public static Bitmap resize(RenderScript rs, Bitmap inputBitmap, int targetWidth,
                            int targetHeight) {
    RSToolboxContext bitmapRSContext = RSToolboxContext.createFromBitmap(rs, inputBitmap);
    Bitmap.Config config = inputBitmap.getConfig();
    Bitmap outputBitmap = Bitmap.createBitmap(targetWidth, targetHeight, config);
    Type outType = Type.createXY(bitmapRSContext.rs, bitmapRSContext.ain.getElement(), targetWidth,
            targetHeight);
    Allocation aout = Allocation.createTyped(bitmapRSContext.rs, outType);

    ScriptIntrinsicResize resizeScript = ScriptIntrinsicResize.create(bitmapRSContext.rs);
    resizeScript.setInput(bitmapRSContext.ain);
    resizeScript.forEach_bicubic(aout);

    aout.copyTo(outputBitmap);
    return outputBitmap;
}
 
开发者ID:silvaren,项目名称:easyrs,代码行数:20,代码来源:Resize.java

示例9: luminanceHistogram

import android.support.v8.renderscript.Allocation; //导入依赖的package包/类
/**
 * Computes a luminance histogram of a Bitmap.
 * @return a 256-length int array of integer frequencies at luminance level.
 */
public static int[] luminanceHistogram(RenderScript rs, Bitmap inputBitmap) {
    RSToolboxContext bitmapRSContext = RSToolboxContext.createFromBitmap(rs, inputBitmap);
    Allocation aout = Allocation.createSized(bitmapRSContext.rs, Element.I32(bitmapRSContext.rs),
            COLOR_DEPTH);

    ScriptIntrinsicHistogram histogramScript = ScriptIntrinsicHistogram.create(
            bitmapRSContext.rs, bitmapRSContext.ain.getElement());
    histogramScript.setOutput(aout);
    histogramScript.forEach(bitmapRSContext.ain);

    int[] histogram = new int[COLOR_DEPTH];
    aout.copyTo(histogram);

    return histogram;
}
 
开发者ID:silvaren,项目名称:easyrs,代码行数:20,代码来源:Histogram.java

示例10: rgbaHistograms

import android.support.v8.renderscript.Allocation; //导入依赖的package包/类
/**
 * Computes a RGBA histogram of a Bitmap.
 * @return a 1024-length int array of integer frequencies at each channel intensity in the
 * following interleaved format [R0,G0,B0,A0,R1,G1,B1,A1...]
 */
public static int[] rgbaHistograms(RenderScript rs, Bitmap inputBitmap) {
    RSToolboxContext bitmapRSContext = RSToolboxContext.createFromBitmap(rs, inputBitmap);
    Allocation aout = Allocation.createSized(bitmapRSContext.rs, Element.I32_4(bitmapRSContext.rs),
            COLOR_DEPTH);

    ScriptIntrinsicHistogram histogramScript = ScriptIntrinsicHistogram.create(
            bitmapRSContext.rs, bitmapRSContext.ain.getElement());
    histogramScript.setOutput(aout);
    histogramScript.forEach(bitmapRSContext.ain);

    int[] histograms = new int[CHANNELS * COLOR_DEPTH];
    aout.copyTo(histograms);

    // RGBA interleaved: [R0,G0,B0,A0,R1,G1,B1,A1...
    return histograms;
}
 
开发者ID:silvaren,项目名称:easyrs,代码行数:22,代码来源:Histogram.java

示例11: getExpectedHistogram

import android.support.v8.renderscript.Allocation; //导入依赖的package包/类
@NonNull
private int[] getExpectedHistogram(RenderScript rs, Bitmap bmpFromNv21, Op op) {
    Allocation ain = Allocation.createFromBitmap(rs, bmpFromNv21);
    Allocation aout;
    int[] histogram;
    if (op == Op.LUMINANCE) {
        aout = Allocation.createSized(rs, Element.I32(rs), Histogram.COLOR_DEPTH);
        histogram = new int[Histogram.COLOR_DEPTH];
    }
    else {
        aout = Allocation.createSized(rs, Element.I32_4(rs), Histogram.COLOR_DEPTH);
        histogram = new int[Histogram.COLOR_DEPTH * Histogram.CHANNELS];
    }

    ScriptIntrinsicHistogram histogramScript = ScriptIntrinsicHistogram.create(
            rs, ain.getElement());
    histogramScript.setOutput(aout);
    histogramScript.forEach(ain);

    aout.copyTo(histogram);
    return histogram;
}
 
开发者ID:silvaren,项目名称:easyrs,代码行数:23,代码来源:HistogramTest.java

示例12: getExpectedBitmap

import android.support.v8.renderscript.Allocation; //导入依赖的package包/类
@NonNull
private Bitmap getExpectedBitmap(RenderScript rs, Bitmap bmpFromNv21) {
    Allocation ain = Allocation.createFromBitmap(rs, bmpFromNv21);
    Allocation aout = Allocation.createTyped(rs, ain.getType());

    ScriptIntrinsicLUT lutScript = ScriptIntrinsicLUT.create(rs, ain.getElement());
    for (int i = 0; i < LutParams.LUT_SIZE; i++) {
        LutParams.RGBALut rgbaLut = SampleParams.Lut.negative();
        lutScript.setAlpha(i, rgbaLut.aLut[i]);
        lutScript.setRed(i, rgbaLut.rLut[i]);
        lutScript.setGreen(i, rgbaLut.gLut[i]);
        lutScript.setBlue(i, rgbaLut.bLut[i]);
    }
    lutScript.forEach(ain, aout);

    Bitmap expectedBitmap = Bitmap.createBitmap(bmpFromNv21.getWidth(), bmpFromNv21.getHeight(), bmpFromNv21.getConfig());
    aout.copyTo(expectedBitmap);
    return expectedBitmap;
}
 
开发者ID:silvaren,项目名称:easyrs,代码行数:20,代码来源:LutTest.java

示例13: blurBitmap

import android.support.v8.renderscript.Allocation; //导入依赖的package包/类
public static Drawable blurBitmap(Context context, Bitmap bitmap) {
    final RenderScript renderScript = RenderScript.create(context);
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inSampleSize = Constants.IN_SAMPLE_SIZE;
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.JPEG, Constants.COMPRESS_QUALITY, stream);
    byte[] imageInByte = stream.toByteArray();
    ByteArrayInputStream bis = new ByteArrayInputStream(imageInByte);
    Bitmap blurTemplate = BitmapFactory.decodeStream(bis, null, options);
    final Allocation input = Allocation.createFromBitmap(renderScript, blurTemplate);
    final Allocation output = Allocation.createTyped(renderScript, input.getType());
    final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(renderScript, Element.U8_4(renderScript));
    script.setRadius(Constants.BLUR_RADIUS);
    script.setInput(input);
    script.forEach(output);
    output.copyTo(blurTemplate);
    renderScript.destroy();
    return new BitmapDrawable(context.getResources(), blurTemplate);
}
 
开发者ID:komamj,项目名称:FileManager,代码行数:20,代码来源:BlurUtils.java

示例14: run

import android.support.v8.renderscript.Allocation; //导入依赖的package包/类
@Override
public Bitmap run(Bitmap in, BrightnessParams params)
{
	this.params = params;
	
	Bitmap out = Bitmap.createBitmap(in.getWidth(), in.getHeight(), Bitmap.Config.ARGB_8888);
	
	Allocation allocationIn = Allocation.createFromBitmap(renderScript, in);
	Allocation allocationOut = Allocation.createFromBitmap(renderScript, out);
	
	ScriptC_cm_brightness script = new ScriptC_cm_brightness(renderScript);
	attachSelection(script);
	script.set_brightness(params.getBrightness());
	script.set_contrast(params.getContrast());
	script.forEach_invert(allocationIn, allocationOut);
	allocationOut.copyTo(out);
	
	return out;
}
 
开发者ID:karol-202,项目名称:PaintPlusPlus,代码行数:20,代码来源:ColorsBrightness.java

示例15: 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


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