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


Java Type类代码示例

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


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

示例1: loadModel

import android.support.v8.renderscript.Type; //导入依赖的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.Type; //导入依赖的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: resize

import android.support.v8.renderscript.Type; //导入依赖的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

示例4: MandelbrotRSGen

import android.support.v8.renderscript.Type; //导入依赖的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

示例5: MandelbrotRSFloatGen

import android.support.v8.renderscript.Type; //导入依赖的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

示例6: convertYuv420ToBitmap

import android.support.v8.renderscript.Type; //导入依赖的package包/类
private static Bitmap convertYuv420ToBitmap(Image image) {
    RenderScript rs = mRenderScript;
    final int width = image.getWidth();
    final int height = image.getHeight();

    // prepare input Allocation for RenderScript
    Type.Builder inType = new Type.Builder(rs, Element.U8(rs)).setX(width).setY(height).setYuvFormat(ImageFormat.YV12);
    Allocation inAlloc = Allocation.createTyped(rs, inType.create(), Allocation.USAGE_SCRIPT);
    byte[] rawBuffer = new byte[inAlloc.getBytesSize()];
    int lumaSize = width * height;
    int chromaSize = (width / 2) * (height / 2);
    Image.Plane[] planes = image.getPlanes();
    planes[0].getBuffer().get(rawBuffer, 0, lumaSize);
    planes[1].getBuffer().get(rawBuffer, lumaSize, chromaSize);
    planes[2].getBuffer().get(rawBuffer, lumaSize + chromaSize, chromaSize);
    inAlloc.copyFromUnchecked(rawBuffer);

    // prepare output Allocation for RenderScript
    Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Allocation outAlloc = Allocation.createFromBitmap(rs, bmp, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT | Allocation.USAGE_SHARED);

    // convert YUV to RGB colorspace
    ScriptC_yuv2rgb converter = new ScriptC_yuv2rgb(rs);
    converter.set_gYUV(inAlloc);
    converter.forEach_convert(outAlloc);
    outAlloc.copyTo(bmp);
    return bmp;
}
 
开发者ID:yohhoy,项目名称:heifreader,代码行数:29,代码来源:HeifReader.java

示例7: Convolution2D

import android.support.v8.renderscript.Type; //导入依赖的package包/类
public Convolution2D(Context ctx, RenderScript rs, int in_channels, int out_channels, int ksize, int stride, int pad) {
    super(ctx, rs);

    this.in_channels = in_channels;
    this.out_channels = out_channels;
    this.ksize = ksize;
    this.stride = stride;
    this.pad = pad;
    // X dimension for W: in_channels * ksize * ksize
    // Y dimension for W: out_channels
    this.W = new float[out_channels * in_channels * ksize * ksize];
    this.b = new float[out_channels];

    // Pad the width of W to be multiple of 8.
    padded_Y_blas = in_channels * ksize * ksize;
    if (padded_Y_blas % 8 > 0) {
        padded_Y_blas = (padded_Y_blas / 8 + 1) * 8;
    }

    // Create Allocations for W and b.
    W_alloc = Allocation.createTyped(mRS,
            Type.createXY(mRS, Element.F32(mRS), padded_Y_blas, out_channels));
    b_alloc = Allocation.createSized(mRS, Element.F32(mRS), out_channels);

    // Initialize the 2D convolution kernel;
    mConvovle = new ScriptC_convolve2d(mRS);

    // Set the global variables for the RS kernel.
    mConvovle.set_kernel_h(ksize);
    mConvovle.set_kernel_w(ksize);
    mConvovle.set_step_x(stride);
    mConvovle.set_step_y(stride);
    mConvovle.set_pad_h(pad);
    mConvovle.set_pad_w(pad);

    mConvovle.set_beta_alloc(b_alloc);
    mConvovle.set_img_channel(in_channels);
}
 
开发者ID:googlecodelabs,项目名称:style-transfer,代码行数:39,代码来源:Convolution2D.java

示例8: process

import android.support.v8.renderscript.Type; //导入依赖的package包/类
public Allocation process(Allocation input, int img_h, int img_w) {
    // Set the input variables to the convolve kernel.
    mConvovle.set_img_h(img_h);
    mConvovle.set_img_w(img_w);
    mConvovle.set_img_alloc(input);

    // Calculate the dimensions of the image after padding.
    int padded_h = img_h + 2 * pad;
    int padded_w = img_w + 2 * pad;

    // Create Allocation to hold the padded image.
    Allocation img_padded = Allocation.createTyped(mRS,
            Type.createXY(mRS, Element.F32(mRS), padded_h * padded_w, in_channels));
    // Initialize the padded Allocation to zero.
    mConvovle.forEach_zero(img_padded, img_padded);
    mConvovle.set_padded_alloc(img_padded);

    // Invoked the padding kernel.
    mConvovle.invoke_padd();

    // TODO Step2: Use convolve2DGEMM instead.
    Allocation out_alloc = convolve2D(img_padded, img_h, img_w);

    // Destroy the intermediate Allocations.
    img_padded.destroy();

    return out_alloc;
}
 
开发者ID:googlecodelabs,项目名称:style-transfer,代码行数:29,代码来源:Convolution2D.java

示例9: convolve2D

import android.support.v8.renderscript.Type; //导入依赖的package包/类
private Allocation convolve2D(Allocation img_padded, int img_h, int img_w) {
    // Calculate the dimensions of image after convolution.
    int out_h = ConvolveUtil.get_conv_outsize(img_h, ksize, stride, pad);
    int out_w = ConvolveUtil.get_conv_outsize(img_w, ksize, stride, pad);
    Log.v(TAG, "convolve size: " + out_h + " " + out_w);

    mConvovle.set_outW(out_w);
    mConvovle.set_outH(out_h);
    mConvovle.set_W_alloc(W_alloc);
    mConvovle.set_input_padded(img_padded);

    // Create the output Allocation for 2D convolution operation.
    Allocation out_alloc = Allocation.createTyped(mRS,
            Type.createXY(mRS, Element.F32(mRS), out_h * out_w, out_channels));

    long time = System.currentTimeMillis();
    mConvovle.forEach_convolve2D(out_alloc);
    if (LOG_TIME) {
        mRS.finish();
        time = System.currentTimeMillis() - time;
        conv2dTime += time;
        Log.v(TAG, "Convolution2D, channels: " + in_channels + ", " + out_channels + " size: " + img_h + ", " + img_w + " conv2D process time: " + time);
    }

    time = System.currentTimeMillis();
    mConvovle.forEach_addBeta(out_alloc, out_alloc);
    if (LOG_TIME) {
        mRS.finish();
        time = System.currentTimeMillis() - time;
        betaTime += time;
        Log.v(TAG, "Convolution2D, channels: " + in_channels + ", " + out_channels + " size: " + img_h + ", " + img_w + " initBeta process time: " + time);
    }
    // Update the output dimensions.
    outH = out_h;
    outW = out_w;

    return out_alloc;
}
 
开发者ID:googlecodelabs,项目名称:style-transfer,代码行数:39,代码来源:Convolution2D.java

示例10: Convolution2DTiled

import android.support.v8.renderscript.Type; //导入依赖的package包/类
public Convolution2DTiled(Context ctx, RenderScript rs, int in_channels, int out_channels, int ksize, int stride, int pad) {
    super(ctx, rs);

    this.in_channels = in_channels;
    this.out_channels = out_channels;
    this.ksize = ksize;
    this.stride = stride;
    this.pad = pad;
    // X dimension for W: in_channels * ksize * ksize
    // Y dimension for W: out_channels
    this.W = new float[out_channels * in_channels * ksize * ksize];
    this.b = new float[out_channels];

    // Pad the width of W to be multiple of 8.
    padded_Y_blas = in_channels * ksize * ksize;
    if (padded_Y_blas % 8 > 0) {
        padded_Y_blas = (padded_Y_blas / 8 + 1) * 8;
    }

    // Create Allocations for W and b.
    W_alloc = Allocation.createTyped(mRS,
            Type.createXY(mRS, Element.F32(mRS), padded_Y_blas, out_channels));
    b_alloc = Allocation.createSized(mRS, Element.F32(mRS), out_channels);

    // Initialize the 2D convolution kernel;
    mConvovle = new ScriptC_convolve2d(mRS);

    // Set the global variables for the RS kernel.
    mConvovle.set_kernel_h(ksize);
    mConvovle.set_kernel_w(ksize);
    mConvovle.set_step_x(stride);
    mConvovle.set_step_y(stride);
    mConvovle.set_pad_h(pad);
    mConvovle.set_pad_w(pad);

    mConvovle.set_beta_alloc(b_alloc);
    mConvovle.set_img_channel(in_channels);
    mConvovle.set_tile_h(TILE_Y);
}
 
开发者ID:googlecodelabs,项目名称:style-transfer,代码行数:40,代码来源:Convolution2DTiled.java

示例11: Deconvolution2DTiled

import android.support.v8.renderscript.Type; //导入依赖的package包/类
public Deconvolution2DTiled(Context ctx, RenderScript rs, int in_channels, int out_channels, int ksize, int stride, int pad) {
    super(ctx, rs);

    this.in_channels = in_channels;
    this.out_channels = out_channels;
    this.ksize = ksize;
    this.stride = stride;
    this.pad = pad;
    // X dimension for W: in_channels * ksize * ksize
    // Y dimension for W: out_channels
    this.W = new float[out_channels * ksize * ksize * in_channels];
    this.b = new float[out_channels];

    // Pad the width of W to be multiple of 8.
    padded_Y_blas = out_channels * ksize * ksize;
    if (padded_Y_blas % 8 > 0) {
        padded_Y_blas = (padded_Y_blas / 8 + 1) * 8;
    }

    // Create Allocations for W and b.
    W_alloc = Allocation.createTyped(mRS,
            Type.createXY(mRS, Element.F32(mRS), in_channels, padded_Y_blas));
    b_alloc = Allocation.createSized(mRS, Element.F32(mRS), out_channels);

    // Initialize the 2D deconvolution kernel;
    mConvovle = new ScriptC_deconvolve2d(mRS);

    // Set the global variables for the RS kernel.
    mConvovle.set_tile_h(TILE_Y);
    mConvovle.set_col_h(TILE_Y);

    mConvovle.set_kernel_h(ksize);
    mConvovle.set_kernel_w(ksize);
    mConvovle.set_step_x(stride);
    mConvovle.set_step_y(stride);
    mConvovle.set_pad_h(pad);
    mConvovle.set_pad_w(pad);
    mConvovle.set_beta_alloc(b_alloc);
}
 
开发者ID:googlecodelabs,项目名称:style-transfer,代码行数:40,代码来源:Deconvolution2DTiled.java

示例12: Deconvolution2D

import android.support.v8.renderscript.Type; //导入依赖的package包/类
public Deconvolution2D(Context ctx, RenderScript rs, int in_channels, int out_channels, int ksize, int stride, int pad) {
    super(ctx, rs);

    this.in_channels = in_channels;
    this.out_channels = out_channels;
    this.ksize = ksize;
    this.stride = stride;
    this.pad = pad;
    // Y dimension for W: out_channels * ksize * ksize
    // X dimension for W: in_channels
    this.W = new float[out_channels * ksize * ksize * in_channels];
    this.b = new float[out_channels];

    // Pad the width of W to be multiple of 8.
    padded_Y_blas = out_channels * ksize * ksize;
    if (padded_Y_blas % 8 > 0) {
        padded_Y_blas = (padded_Y_blas / 8 + 1) * 8;
    }

    // Create Allocations for W and b.
    W_alloc = Allocation.createTyped(mRS,
            Type.createXY(mRS, Element.F32(mRS), in_channels, padded_Y_blas));
    b_alloc = Allocation.createSized(mRS, Element.F32(mRS), out_channels);

    // Initialize the 2D deconvolution kernel;
    mConvovle = new ScriptC_deconvolve2d(mRS);

    // Set the global variables for the RS kernel.
    mConvovle.set_kernel_h(ksize);
    mConvovle.set_kernel_w(ksize);
    mConvovle.set_step_x(stride);
    mConvovle.set_step_y(stride);
    mConvovle.set_pad_h(pad);
    mConvovle.set_pad_w(pad);

    mConvovle.set_beta_alloc(b_alloc);

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

示例13: createAllocation

import android.support.v8.renderscript.Type; //导入依赖的package包/类
public Allocation createAllocation(RenderScript rs) {
    final int sx = xSize;
    final int sy = ySize;
    final int sz = zSize;
    Type.Builder tb = new Type.Builder(rs, Element.U8_4(rs));
    tb.setX(sx);
    tb.setY(sy);
    tb.setZ(sz);
    Type t = tb.create();
    Allocation mCube = Allocation.createTyped(rs, t);
    mCube.copyFromUnchecked(getCube());

    return mCube;
}
 
开发者ID:silvaren,项目名称:easyrs,代码行数:15,代码来源:Lut3DParams.java

示例14: getExpectedBitmap

import android.support.v8.renderscript.Type; //导入依赖的package包/类
@NonNull
private Bitmap getExpectedBitmap(RenderScript rs, Bitmap bmpFromNv21) {
    Allocation ain = Allocation.createFromBitmap(rs, bmpFromNv21);
    Bitmap expectedBitmap = Bitmap.createBitmap(TARGET_WIDTH, TARGET_HEIGHT, bmpFromNv21.getConfig());
    Type outType = Type.createXY(rs, ain.getElement(), TARGET_WIDTH, TARGET_HEIGHT);
    Allocation aout = Allocation.createTyped(rs, outType);

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

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

示例15: initLUT

import android.support.v8.renderscript.Type; //导入依赖的package包/类
public void initLUT (int setSizeX, int setSizeY, int setSizeZ) {

        lutSizeX = setSizeX;
        lutSizeY = setSizeY;
        lutSizeZ = setSizeZ;
        colorLutArray = new int[lutSizeX * lutSizeY * lutSizeZ];

        rS = RenderScript.create(this);

        Type.Builder tb = new Type.Builder(rS, Element.U8_4(rS));
        tb.setX(lutSizeX);
        tb.setY(lutSizeY);
        tb.setZ(lutSizeZ);
        Type t = tb.create();


        allocLut = Allocation.createTyped(rS, t);


        for (int x = 0; x < lutSizeX; x++) {
            for (int y = 0; y < lutSizeY; y++) {
                for (int z = 0; z < lutSizeZ; z++) {


                    colorLutArray[x * lutSizeY * lutSizeZ + y * lutSizeZ + z] = Color.argb(0xff,
                            (0xff * x / (lutSizeX - 1)),
                            (0xff * y / (lutSizeY - 1)),
                            (0xff * z / (lutSizeZ - 1)));
                    /*
                    Log.d(TAG, "x,y,z = " + Integer.toString(x) + ", " + Integer.toString(y) + ", " +
                            Integer.toString(z) + " = " + Integer.toHexString(colorLutArray[x * lutSizeY * lutSizeZ + y * lutSizeZ + z]));
                    */

                }
            }
        }
        allocLut.copyFromUnchecked(colorLutArray);
        sI3dLut = ScriptIntrinsic3DLUT.create(rS, Element.U8_4(rS));
        sI3dLut.setLUT(allocLut);
    }
 
开发者ID:colorchief,项目名称:colorchief,代码行数:41,代码来源:ColorLUT.java


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