Android Open Source - android-stackblur R S Blur Process






From Project

Back to project page android-stackblur.

License

The source code is released under:

Apache License

If you think the Android project android-stackblur listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.enrique.stackblur;
/* w ww  .j  a  v  a  2 s.c  om*/
import android.content.Context;
import android.graphics.Bitmap;
import android.os.Build;
import android.support.v8.renderscript.Allocation;
import android.support.v8.renderscript.Element;
import android.support.v8.renderscript.RenderScript;

/**
 * @see JavaBlurProcess
 * Blur using renderscript.
 */
class RSBlurProcess implements BlurProcess {
  private final Context context;
  private final RenderScript _rs;

  public RSBlurProcess(Context context) {
    this.context = context.getApplicationContext();
    _rs = RenderScript.create(this.context);
  }

  @Override
  public Bitmap blur(Bitmap original, float radius) {
    int width = original.getWidth();
    int height = original.getHeight();
    Bitmap blurred = original.copy(Bitmap.Config.ARGB_8888, true);

    ScriptC_blur blurScript = new ScriptC_blur(_rs, context.getResources(), R.raw.blur);

    Allocation inAllocation = Allocation.createFromBitmap(_rs, blurred, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);

    blurScript.set_gIn(inAllocation);
    blurScript.set_width(width);
    blurScript.set_height(height);
    blurScript.set_radius((int) radius);

    int[] row_indices = new int[height];
    for (int i = 0; i < height; i++) {
      row_indices[i] = i;
    }

    Allocation rows = Allocation.createSized(_rs, Element.U32(_rs), height, Allocation.USAGE_SCRIPT);
    rows.copyFrom(row_indices);

    row_indices = new int[width];
    for (int i = 0; i < width; i++) {
      row_indices[i] = i;
    }

    Allocation columns = Allocation.createSized(_rs, Element.U32(_rs), width, Allocation.USAGE_SCRIPT);
    columns.copyFrom(row_indices);

    blurScript.forEach_blur_h(rows);
    blurScript.forEach_blur_v(columns);
    inAllocation.copyTo(blurred);

    return blurred;
  }
}




Java Source Code List

com.enrique.stackblur.BlurProcess.java
com.enrique.stackblur.JavaBlurProcess.java
com.enrique.stackblur.NativeBlurProcess.java
com.enrique.stackblur.RSBlurProcess.java
com.enrique.stackblur.StackBlurManager.java
com.example.stackblurdemo.BenchmarkActivity.java
com.example.stackblurdemo.MainActivity.java