private static void copyToAllocation(float[][] input, Allocation allocation) { int n = input.length; int c = input[0].length; float[] output = new float[n * c]; int count = 0; for(int i=0;i<n;i++){ for(int j=0;j<c;j++){ output[count++] = input[i][j]; } } allocation.copyFrom(output); }
private static void copyToAllocation(float[][][][] input, Allocation allocation) { int n = input.length; int h = input[0].length; int w = input[0][0].length; int c = input[0][0][0].length; float[] output = new float[n * h * w * c]; int count = 0; for(int i=0;i<n;i++){ for(int j=0;j<h;j++){ for(int k=0;k<w;k++){ for(int l=0;l<c;l++){ output[count++] = input[i][j][k][l]; } } } } allocation.copyFrom(output); }
private static void copyToAllocationVector4(float[][][][] input, Allocation allocation) { int n = input.length; int h = input[0].length; int w = input[0][0].length; int c = input[0][0][0].length; int channelAlign = c; int skip = 0; if(channelAlign % 4 !=0) { channelAlign = c + 4 - c % 4; skip = 4 - c % 4; } float[] output = new float[n * h * w * channelAlign]; int count = 0; for(int i=0;i<n;i++){ for(int j=0;j<h;j++){ for(int k=0;k<w;k++){ for(int l=0;l<c;l++){ output[count++] = input[i][j][k][l]; } count += skip; } } } allocation.copyFrom(output); }
@Override public void computeFeatureMap(){ float[] bmp = (float[])featureMapInput[0]; FeatureMap featureMap = (FeatureMap) featureMapOutput; featureMap.getFeatureMap().copyFrom(bmp); }
protected void blur(Bitmap bitmapToBlur, Bitmap blurredBitmap) { mBlurInput.copyFrom(bitmapToBlur); mBlurScript.setInput(mBlurInput); mBlurScript.forEach(mBlurOutput); mBlurOutput.copyTo(blurredBitmap); }
mScript = new ScriptC_Square(mRS, getResources(), R.raw.square); mInAllocation.copyFrom(input);
@Override public void setup() { int channel = outputShape[3]; int channelAlign = channel; if(channel % 4 != 0){ channelAlign = channel + 4 - channel % 4; } scriptScale = new ScriptC_Scale(renderScript); float[] scaleArray = new float[channelAlign]; float[] biasArray = new float[channelAlign]; for(int i=0;i<channel;i++){ scaleArray[i] = scale[i]; biasArray[i] = bias[i]; } Allocation scaleAllocation; Allocation biasAllocation; Type scaleType = Type.createX(renderScript, Element.F32_4(renderScript), channelAlign / 4); Type biasType = Type.createX(renderScript, Element.F32_4(renderScript), channelAlign / 4); scaleAllocation = Allocation.createTyped(renderScript, scaleType, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_GRAPHICS_TEXTURE | Allocation.USAGE_SCRIPT); scaleAllocation.copyFrom(scaleArray); biasAllocation = Allocation.createTyped(renderScript, biasType, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_GRAPHICS_TEXTURE | Allocation.USAGE_SCRIPT); biasAllocation.copyFrom(biasArray); scriptScale.set_scale(scaleAllocation); scriptScale.set_bias(biasAllocation); }