public ViewfinderProcessor(RenderScript rs, Size dimensions) { Type.Builder yuvTypeBuilder = new Type.Builder(rs, Element.YUV(rs)); yuvTypeBuilder.setX(dimensions.getWidth()); yuvTypeBuilder.setY(dimensions.getHeight()); yuvTypeBuilder.setYuvFormat(ImageFormat.YUV_420_888); mInputHdrAllocation = Allocation.createTyped(rs, yuvTypeBuilder.create(), Allocation.USAGE_IO_INPUT | Allocation.USAGE_SCRIPT); mInputNormalAllocation = Allocation.createTyped(rs, yuvTypeBuilder.create(), Allocation.USAGE_IO_INPUT | Allocation.USAGE_SCRIPT); Type.Builder rgbTypeBuilder = new Type.Builder(rs, Element.RGBA_8888(rs)); rgbTypeBuilder.setX(dimensions.getWidth()); rgbTypeBuilder.setY(dimensions.getHeight()); mPrevAllocation = Allocation.createTyped(rs, rgbTypeBuilder.create(), Allocation.USAGE_SCRIPT); mOutputAllocation = Allocation.createTyped(rs, rgbTypeBuilder.create(), Allocation.USAGE_IO_OUTPUT | Allocation.USAGE_SCRIPT); HandlerThread processingThread = new HandlerThread("ViewfinderProcessor"); processingThread.start(); mProcessingHandler = new Handler(processingThread.getLooper()); mHdrMergeScript = new ScriptC_hdr_merge(rs); mHdrMergeScript.set_gPrevFrame(mPrevAllocation); mHdrTask = new ProcessingTask(mInputHdrAllocation, dimensions.getWidth()/2, true); mNormalTask = new ProcessingTask(mInputNormalAllocation, 0, false); setRenderMode(MODE_NORMAL); }
kernelType.setY(outputChannelAligned); kernelType.setX(kernelH * kernelW * inputChannelGroup); Type biasType = Type.createX(renderScript, Element.F32(renderScript), outputChannelAligned);
colType.setX(kernelH * kernelW * inputChannelAligned).setY(outputHeight * outputWidth); Allocation colAllocation = Allocation.createTyped(renderScript, colType.create()); scriptConvolution.set_ColData(colAllocation);
kernelType.setY(kernelH * kernelW); Type biasType = Type.createX(renderScript, Element.F32(renderScript), inputChannelAligned); kernelAllocation = Allocation.createTyped(renderScript, kernelType.create(), Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_GRAPHICS_TEXTURE | Allocation.USAGE_SCRIPT);
protected void allocFeatureMap() { Type.Builder outputType = new Type.Builder(renderScript, Element.F32(renderScript)); outputType.setZ(outputShape[0]); outputType.setY(outputShape[1] * outputShape[2]); outputType.setX(getOutputChannelAligned()); Allocation outAllocation = Allocation.createTyped(renderScript, outputType.create()); FeatureMap output = new FeatureMap(); output.setFeatureMap(outAllocation); output.setN(outputShape[0]); output.setH(outputShape[1]); output.setW(outputShape[2]); output.setC(outputShape[3]); output.setPad4(true); if(this.featureMapOutput!=null){ ((FeatureMap)featureMapOutput).getFeatureMap().destroy(); } this.featureMapOutput = output; }
protected void allocFeatureMapNoPad() { Type.Builder outputType = new Type.Builder(renderScript, Element.F32(renderScript)); outputType.setZ(outputShape[0]); outputType.setY(outputShape[1] * outputShape[2]); outputType.setX(outputShape[3]); Allocation outAllocation = Allocation.createTyped(renderScript, outputType.create()); FeatureMap output = new FeatureMap(); output.setFeatureMap(outAllocation); output.setN(outputShape[0]); output.setH(outputShape[1]); output.setW(outputShape[2]); output.setC(outputShape[3]); output.setPad4(false); if(this.featureMapOutput!=null){ ((FeatureMap)featureMapOutput).getFeatureMap().destroy(); } this.featureMapOutput = output; }