android.renderscript.Element类的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(8.6k)|赞(0)|评价(0)|浏览(236)

本文整理了Java中android.renderscript.Element类的一些代码示例,展示了Element类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Element类的具体详情如下:
包路径:android.renderscript.Element
类名称:Element

Element介绍

暂无

代码示例

代码示例来源:origin: Dimezis/BlurView

  1. /**
  2. * @param context Context to create the {@link RenderScript}
  3. */
  4. @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
  5. public RenderScriptBlur(Context context) {
  6. renderScript = RenderScript.create(context);
  7. blurScript = ScriptIntrinsicBlur.create(renderScript, Element.U8_4(renderScript));
  8. }

代码示例来源:origin: gearvrf/GearVRf-Demos

  1. Type.Builder yuvTypeBuilder = new Type.Builder(rs, Element.U8_4(rs));
  2. yuvTypeBuilder.setX(width);
  3. yuvTypeBuilder.setY(height);
  4. yuvTypeBuilder.setYuvFormat(ImageFormat.YUV_420_888);
  5. Type.Builder rgbTypeBuilder = new Type.Builder(rs, Element.RGBA_8888(rs));
  6. rgbTypeBuilder.setX(width);
  7. rgbTypeBuilder.setY(height);
  8. Allocation.USAGE_SCRIPT);
  9. mScriptIntrinsic = ScriptIntrinsicYuvToRGB.create(rs, Element.U8_4(rs));
  10. } else {
  11. mInputAllocation = Allocation.createTyped(rs, rgbTypeBuilder.create(),

代码示例来源:origin: googlesamples/android-HdrViewfinder

  1. public ViewfinderProcessor(RenderScript rs, Size dimensions) {
  2. Type.Builder yuvTypeBuilder = new Type.Builder(rs, Element.YUV(rs));
  3. yuvTypeBuilder.setX(dimensions.getWidth());
  4. yuvTypeBuilder.setY(dimensions.getHeight());
  5. yuvTypeBuilder.setYuvFormat(ImageFormat.YUV_420_888);
  6. mInputHdrAllocation = Allocation.createTyped(rs, yuvTypeBuilder.create(),
  7. Allocation.USAGE_IO_INPUT | Allocation.USAGE_SCRIPT);
  8. mInputNormalAllocation = Allocation.createTyped(rs, yuvTypeBuilder.create(),
  9. Allocation.USAGE_IO_INPUT | Allocation.USAGE_SCRIPT);
  10. Type.Builder rgbTypeBuilder = new Type.Builder(rs, Element.RGBA_8888(rs));
  11. rgbTypeBuilder.setX(dimensions.getWidth());
  12. rgbTypeBuilder.setY(dimensions.getHeight());
  13. mPrevAllocation = Allocation.createTyped(rs, rgbTypeBuilder.create(),
  14. Allocation.USAGE_SCRIPT);
  15. mOutputAllocation = Allocation.createTyped(rs, rgbTypeBuilder.create(),
  16. Allocation.USAGE_IO_OUTPUT | Allocation.USAGE_SCRIPT);
  17. HandlerThread processingThread = new HandlerThread("ViewfinderProcessor");
  18. processingThread.start();
  19. mProcessingHandler = new Handler(processingThread.getLooper());
  20. mHdrMergeScript = new ScriptC_hdr_merge(rs);
  21. mHdrMergeScript.set_gPrevFrame(mPrevAllocation);
  22. mHdrTask = new ProcessingTask(mInputHdrAllocation, dimensions.getWidth()/2, true);
  23. mNormalTask = new ProcessingTask(mInputNormalAllocation, 0, false);
  24. setRenderMode(MODE_NORMAL);
  25. }

代码示例来源:origin: chuanqi305/rscnn

  1. @Override
  2. public void computeOutputShape() {
  3. outputShape = inputShape[0];
  4. if(softmaxScript!=null){
  5. int n = inputShape[0][0];
  6. int h = inputShape[0][1];
  7. int w = inputShape[0][2];
  8. int c = inputShape[0][3];
  9. Type expSumType = Type.createX(renderScript, Element.F32(renderScript), n * h * w);
  10. expSumAlloc = Allocation.createTyped(renderScript, expSumType, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_GRAPHICS_TEXTURE | Allocation.USAGE_SCRIPT);
  11. softmaxScript.set_channel(c);
  12. softmaxScript.set_expSum(expSumAlloc);
  13. }
  14. }
  15. }

代码示例来源:origin: chuanqi305/rscnn

  1. Allocation kernelAllocation;
  2. Allocation biasAllocation;
  3. kernelType = Type.createX(renderScript, Element.F32_4(renderScript), c * inh * inw * inc / 4);
  4. biasType = Type.createX(renderScript, Element.F32(renderScript), c);

代码示例来源:origin: chuanqi305/rscnn

  1. @Override
  2. public void setup(){
  3. int n = inputShape[0][0];
  4. int h = inputShape[0][1];
  5. int w = inputShape[0][2];
  6. int c = inputShape[0][3];
  7. Type expSumType = Type.createX(renderScript, Element.F32(renderScript), n * h * w);
  8. expSumAlloc = Allocation.createTyped(renderScript, expSumType, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_GRAPHICS_TEXTURE | Allocation.USAGE_SCRIPT);
  9. softmaxScript = new ScriptC_Softmax(renderScript);
  10. softmaxScript.set_channel(c);
  11. softmaxScript.set_expSum(expSumAlloc);
  12. }

代码示例来源:origin: HotBitmapGG/bilibili-android-client

  1. /**
  2. * 图片高斯模糊具体实现方法
  3. */
  4. public static Bitmap blur(Context context, Bitmap image, float radius) {
  5. // 计算图片缩小后的长宽
  6. int width = Math.round(image.getWidth() * BITMAP_SCALE);
  7. int height = Math.round(image.getHeight() * BITMAP_SCALE);
  8. // 将缩小后的图片做为预渲染的图片。
  9. Bitmap inputBitmap = Bitmap.createScaledBitmap(image, width, height, false);
  10. // 创建一张渲染后的输出图片。
  11. Bitmap outputBitmap = Bitmap.createBitmap(inputBitmap);
  12. // 创建RenderScript内核对象
  13. RenderScript rs = RenderScript.create(context);
  14. // 创建一个模糊效果的RenderScript的工具对象
  15. ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
  16. // 由于RenderScript并没有使用VM来分配内存,所以需要使用Allocation类来创建和分配内存空间。
  17. // 创建Allocation对象的时候其实内存是空的,需要使用copyTo()将数据填充进去。
  18. Allocation tmpIn = Allocation.createFromBitmap(rs, inputBitmap);
  19. Allocation tmpOut = Allocation.createFromBitmap(rs, outputBitmap);
  20. // 设置渲染的模糊程度, 25f是最大模糊度
  21. blurScript.setRadius(radius);
  22. // 设置blurScript对象的输入内存
  23. blurScript.setInput(tmpIn);
  24. // 将输出数据保存到输出内存中
  25. blurScript.forEach(tmpOut);
  26. // 将数据填充到Allocation中
  27. tmpOut.copyTo(outputBitmap);
  28. return outputBitmap;
  29. }
  30. }

代码示例来源:origin: chuanqi305/rscnn

  1. protected void allocFeatureMapNoPad()
  2. {
  3. Type.Builder outputType = new Type.Builder(renderScript, Element.F32(renderScript));
  4. outputType.setZ(outputShape[0]);
  5. outputType.setY(outputShape[1] * outputShape[2]);
  6. outputType.setX(outputShape[3]);
  7. Allocation outAllocation = Allocation.createTyped(renderScript, outputType.create());
  8. FeatureMap output = new FeatureMap();
  9. output.setFeatureMap(outAllocation);
  10. output.setN(outputShape[0]);
  11. output.setH(outputShape[1]);
  12. output.setW(outputShape[2]);
  13. output.setC(outputShape[3]);
  14. output.setPad4(false);
  15. if(this.featureMapOutput!=null){
  16. ((FeatureMap)featureMapOutput).getFeatureMap().destroy();
  17. }
  18. this.featureMapOutput = output;
  19. }

代码示例来源:origin: cymcsg/UltimateAndroid

  1. Allocation.USAGE_SCRIPT);
  2. final Allocation output = Allocation.createTyped(rs, input.getType());
  3. final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));

代码示例来源:origin: chuanqi305/rscnn

  1. Allocation biasAllocation;
  2. Type.Builder kernelType = new Type.Builder(renderScript, Element.F32(renderScript));
  3. kernelType.setX(inputChannelAligned);
  4. kernelType.setY(kernelH * kernelW);
  5. Type biasType = Type.createX(renderScript, Element.F32(renderScript), inputChannelAligned);
  6. kernelAllocation = Allocation.createTyped(renderScript, kernelType.create(), Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_GRAPHICS_TEXTURE | Allocation.USAGE_SCRIPT);
  7. biasAllocation = Allocation.createTyped(renderScript, biasType, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_GRAPHICS_TEXTURE | Allocation.USAGE_SCRIPT);

代码示例来源:origin: CameraKit/blurkit-android

  1. public Bitmap blur(Bitmap src, int radius) {
  2. final Allocation input = Allocation.createFromBitmap(rs, src);
  3. final Allocation output = Allocation.createTyped(rs, input.getType());
  4. final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
  5. script.setRadius(radius);
  6. script.setInput(input);
  7. script.forEach(output);
  8. output.copyTo(src);
  9. return src;
  10. }

代码示例来源:origin: chuanqi305/rscnn

  1. protected void allocFeatureMap()
  2. {
  3. Type.Builder outputType = new Type.Builder(renderScript, Element.F32(renderScript));
  4. outputType.setZ(outputShape[0]);
  5. outputType.setY(outputShape[1] * outputShape[2]);
  6. outputType.setX(getOutputChannelAligned());
  7. Allocation outAllocation = Allocation.createTyped(renderScript, outputType.create());
  8. FeatureMap output = new FeatureMap();
  9. output.setFeatureMap(outAllocation);
  10. output.setN(outputShape[0]);
  11. output.setH(outputShape[1]);
  12. output.setW(outputShape[2]);
  13. output.setC(outputShape[3]);
  14. output.setPad4(true);
  15. if(this.featureMapOutput!=null){
  16. ((FeatureMap)featureMapOutput).getFeatureMap().destroy();
  17. }
  18. this.featureMapOutput = output;
  19. }

代码示例来源:origin: wasabeef/glide-transformations

  1. Allocation.USAGE_SCRIPT);
  2. output = Allocation.createTyped(rs, input.getType());
  3. blur = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));

代码示例来源:origin: chuanqi305/rscnn

  1. Type outType = Type.createX(renderScript, Element.F32(renderScript), outNum * outHeight * outWidth * outChannel);

代码示例来源:origin: wasabeef/Blurry

  1. Allocation.USAGE_SCRIPT);
  2. output = Allocation.createTyped(rs, input.getType());
  3. blur = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));

代码示例来源:origin: chuanqi305/rscnn

  1. int outWidth = outputShape[2];
  2. Type.Builder kernelType = new Type.Builder(renderScript, Element.F32(renderScript));
  3. kernelType.setY(outputChannelAligned);
  4. kernelType.setX(kernelH * kernelW * inputChannelGroup);
  5. Type biasType = Type.createX(renderScript, Element.F32(renderScript), outputChannelAligned);

代码示例来源:origin: multidots/android-app-common-tasks

  1. input.getType());
  2. final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs,
  3. Element.U8_4(rs));

代码示例来源:origin: chuanqi305/rscnn

  1. Type.Builder colType = new Type.Builder(renderScript, Element.F32(renderScript));
  2. colType.setX(kernelH * kernelW * inputChannelAligned).setY(outputHeight * outputWidth);
  3. Allocation colAllocation = Allocation.createTyped(renderScript, colType.create());

代码示例来源:origin: multidots/android-app-common-tasks

  1. input.getType());
  2. final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs,
  3. Element.U8_4(rs));

代码示例来源:origin: Blizzard-liu/AndroidUtils

  1. input.getType());
  2. final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs,
  3. Element.U8_4(rs));

相关文章