public ViewfinderProcessor(RenderScript rs, Size dimensions) { Type.Builder yuvTypeBuilder = new Type.Builder(rs, Element.YUV(rs)); yuvTypeBuilder.SetX(dimensions.Width); yuvTypeBuilder.SetY(dimensions.Height); yuvTypeBuilder.SetYuvFormat((int)ImageFormatType.Yuv420888); mInputHdrAllocation = Allocation.CreateTyped(rs, yuvTypeBuilder.Create(), AllocationUsage.IoInput | AllocationUsage.Script); Type.Builder rgbTypeBuilder = new Type.Builder(rs, Element.RGBA_8888(rs)); rgbTypeBuilder.SetX(dimensions.Width); rgbTypeBuilder.SetY(dimensions.Height); mPrevAllocation = Allocation.CreateTyped(rs, rgbTypeBuilder.Create(), AllocationUsage.Script); mOutputAllocation = Allocation.CreateTyped(rs, rgbTypeBuilder.Create(), AllocationUsage.IoOutput | AllocationUsage.Script); mHdrYuvToRGBScript = ScriptIntrinsicYuvToRGB.Create(rs, Element.RGBA_8888(rs)); mHdrColorMatrixScript = ScriptIntrinsicColorMatrix.Create(rs); mHdrColorMatrixScript.SetColorMatrix(new Matrix4f(new float[] { 0.5f, 0, 0, 0, 0, 0.5f, 0, 0, 0, 0, 0.5f, 0, 0, 0, 0, 0.5f })); mHdrBlendScript = ScriptIntrinsicBlend.Create(rs, Element.RGBA_8888(rs)); mDimensions = dimensions; mFrameCounter = 0; SetRenderMode(ModeNormal); }
public Bitmap blur(Bitmap bitmap, float radius, int repeat) { if (!IS_BLUR_SUPPORTED) { return(null); } if (radius > MAX_RADIUS) { radius = MAX_RADIUS; } int width = bitmap.Width; int height = bitmap.Height; // Create allocation type Type bitmapType = new Type.Builder(rs, Element.RGBA_8888(rs)) .SetX(width) .SetY(height) .SetMipmaps(false) // We are using MipmapControl.MIPMAP_NONE .Create(); // Create allocation Allocation allocation = Allocation.CreateTyped(rs, bitmapType); // Create blur script ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.Create(rs, Element.U8_4(rs)); blurScript.SetRadius(radius); // Copy data to allocation allocation.CopyFrom(bitmap); // set blur script input blurScript.SetInput(allocation); // invoke the script to blur blurScript.ForEach(allocation); // Repeat the blur for extra effect for (int i = 0; i < repeat; i++) { blurScript.ForEach(allocation); } // copy data back to the bitmap allocation.CopyTo(bitmap); // release memory allocation.Destroy(); blurScript.Destroy(); allocation = null; blurScript = null; return(bitmap); }