// Path: dali/src/main/java/at/favre/lib/dali/blur/BlurKernels.java
// public final class BlurKernels {
//     private BlurKernels() {
//     }
// 
//     public static final float[] GAUSSIAN_5x5 = new float[]{
//             0.0030f, 0.0133f, 0.0219f, 0.0133f, 0.0030f,
//             0.0133f, 0.0596f, 0.0983f, 0.0596f, 0.0133f,
//             0.0219f, 0.0983f, 0.1621f, 0.0983f, 0.0219f,
//             0.0133f, 0.0596f, 0.0983f, 0.0596f, 0.0133f,
//             0.0030f, 0.0133f, 0.0219f, 0.0133f, 0.0030f
//     };
// 
//     public static final float[] BOX_5x5 = new float[]{
//             0.04f, 0.04f, 0.04f, 0.04f, 0.04f,
//             0.04f, 0.04f, 0.04f, 0.04f, 0.04f,
//             0.04f, 0.0425f, 0.05f, 0.0425f, 0.04f,
//             0.04f, 0.04f, 0.04f, 0.04f, 0.04f,
//             0.04f, 0.04f, 0.04f, 0.04f, 0.04f
//     };
// 
//     public static final float[] BOX_3x3 = new float[]{
//             0.111111111111111111111111112f, 0.111111111111111111111111112f, 0.111111111111111111111111112f,
//             0.111111111111111111111111112f, 0.13f, 0.111111111111111111111111112f,
//             0.111111111111111111111111112f, 0.111111111111111111111111112f, 0.111111111111111111111111112f
//     };
// }
// 
// Path: dali/src/main/java/at/favre/lib/dali/blur/IBlur.java
// public interface IBlur {
//     //threshold for live blurring
//     int MS_THRESHOLD_FOR_SMOOTH = 16;
// 
//     /**
//      * Takes a bitmap and blurs it with the given blur radius. This will NOT copy the original
//      * but reuses it, so if this instance will be used somewhere else, manual copying is needed.
//      *
//      * @param radius   blurradius, keep in mind some algorithms don't take all values (e.g. ScriptIntrinsicBlur will only take 1-25)
//      * @param original
//      * @return blurred original bitmap
//      */
//     Bitmap blur(int radius, Bitmap original);
// }


import android.graphics.Bitmap;
import androidx.renderscript.Allocation;
import androidx.renderscript.Element;
import androidx.renderscript.RenderScript;
import androidx.renderscript.ScriptIntrinsicConvolve5x5;
import at.favre.lib.dali.blur.BlurKernels;
import at.favre.lib.dali.blur.IBlur;
package at.favre.lib.dali.blur.algorithms;




/**
 * This is a convolve matrix based blur algorithms powered by Renderscript's ScriptIntrinsicConvolve class. This uses a box kernel.
 * Instead of radius it uses passes, so a radius parameter of 16 makes the convolve algorithm applied 16 times onto the image.
 */
public class RenderScriptBox5x5Blur implements IBlur {
    private RenderScript rs;

    public RenderScriptBox5x5Blur(RenderScript rs) {
        this.rs = rs;
    }

    @Override
    public Bitmap blur(int radius, Bitmap bitmapOriginal) {
        Allocation input = Allocation.createFromBitmap(rs, bitmapOriginal);
        final Allocation output = Allocation.createTyped(rs, input.getType());
        final ScriptIntrinsicConvolve5x5 script = ScriptIntrinsicConvolve5x5.create(rs, Element.U8_4(rs));
// Path: dali/src/main/java/at/favre/lib/dali/blur/BlurKernels.java
// public final class BlurKernels {
//     private BlurKernels() {
//     }
// 
//     public static final float[] GAUSSIAN_5x5 = new float[]{
//             0.0030f, 0.0133f, 0.0219f, 0.0133f, 0.0030f,
//             0.0133f, 0.0596f, 0.0983f, 0.0596f, 0.0133f,
//             0.0219f, 0.0983f, 0.1621f, 0.0983f, 0.0219f,
//             0.0133f, 0.0596f, 0.0983f, 0.0596f, 0.0133f,
//             0.0030f, 0.0133f, 0.0219f, 0.0133f, 0.0030f
//     };
// 
//     public static final float[] BOX_5x5 = new float[]{
//             0.04f, 0.04f, 0.04f, 0.04f, 0.04f,
//             0.04f, 0.04f, 0.04f, 0.04f, 0.04f,
//             0.04f, 0.0425f, 0.05f, 0.0425f, 0.04f,
//             0.04f, 0.04f, 0.04f, 0.04f, 0.04f,
//             0.04f, 0.04f, 0.04f, 0.04f, 0.04f
//     };
// 
//     public static final float[] BOX_3x3 = new float[]{
//             0.111111111111111111111111112f, 0.111111111111111111111111112f, 0.111111111111111111111111112f,
//             0.111111111111111111111111112f, 0.13f, 0.111111111111111111111111112f,
//             0.111111111111111111111111112f, 0.111111111111111111111111112f, 0.111111111111111111111111112f
//     };
// }
// 
// Path: dali/src/main/java/at/favre/lib/dali/blur/IBlur.java
// public interface IBlur {
//     //threshold for live blurring
//     int MS_THRESHOLD_FOR_SMOOTH = 16;
// 
//     /**
//      * Takes a bitmap and blurs it with the given blur radius. This will NOT copy the original
//      * but reuses it, so if this instance will be used somewhere else, manual copying is needed.
//      *
//      * @param radius   blurradius, keep in mind some algorithms don't take all values (e.g. ScriptIntrinsicBlur will only take 1-25)
//      * @param original
//      * @return blurred original bitmap
//      */
//     Bitmap blur(int radius, Bitmap original);
// }


// Path: dali/src/main/java/at/favre/lib/dali/blur/algorithms/RenderScriptBox5x5Blur.java
import android.graphics.Bitmap;
import androidx.renderscript.Allocation;
import androidx.renderscript.Element;
import androidx.renderscript.RenderScript;
import androidx.renderscript.ScriptIntrinsicConvolve5x5;
import at.favre.lib.dali.blur.BlurKernels;
import at.favre.lib.dali.blur.IBlur;

package at.favre.lib.dali.blur.algorithms;




/**
 * This is a convolve matrix based blur algorithms powered by Renderscript's ScriptIntrinsicConvolve class. This uses a box kernel.
 * Instead of radius it uses passes, so a radius parameter of 16 makes the convolve algorithm applied 16 times onto the image.
 */
public class RenderScriptBox5x5Blur implements IBlur {
    private RenderScript rs;

    public RenderScriptBox5x5Blur(RenderScript rs) {
        this.rs = rs;
    }

    @Override
    public Bitmap blur(int radius, Bitmap bitmapOriginal) {
        Allocation input = Allocation.createFromBitmap(rs, bitmapOriginal);
        final Allocation output = Allocation.createTyped(rs, input.getType());
        final ScriptIntrinsicConvolve5x5 script = ScriptIntrinsicConvolve5x5.create(rs, Element.U8_4(rs));
        script.setCoefficients(BlurKernels.BOX_5x5);