2 * Copyright (C) 2012 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package android.renderscript;
19 import android.content.Context;
20 import android.content.res.Resources;
21 import android.util.Log;
24 * Intrinsic Gausian blur filter. Applies a gaussian blur of the
25 * specified radius to all elements of an allocation.
29 public final class ScriptIntrinsicBlur extends ScriptIntrinsic {
30 private final float[] mValues = new float[9];
31 private Allocation mInput;
33 private ScriptIntrinsicBlur(int id, RenderScript rs) {
38 * Create an intrinsic for applying a blur to an allocation. The
39 * default radius is 5.0.
41 * Supported elements types are {@link Element#U8_4}
43 * @param rs The RenderScript context
44 * @param e Element type for inputs and outputs
46 * @return ScriptIntrinsicBlur
48 public static ScriptIntrinsicBlur create(RenderScript rs, Element e) {
49 if ((!e.isCompatible(Element.U8_4(rs))) && (!e.isCompatible(Element.U8(rs)))) {
50 throw new RSIllegalArgumentException("Unsuported element type.");
52 int id = rs.nScriptIntrinsicCreate(5, e.getID(rs));
53 ScriptIntrinsicBlur sib = new ScriptIntrinsicBlur(id, rs);
59 * Set the input of the blur.
60 * Must match the element type supplied during create.
62 * @param ain The input allocation
64 public void setInput(Allocation ain) {
70 * Set the radius of the Blur.
72 * Supported range 0 < radius <= 25
74 * @param radius The radius of the blur
76 public void setRadius(float radius) {
77 if (radius <= 0 || radius > 25) {
78 throw new RSIllegalArgumentException("Radius out of range (0 < r <= 25).");
84 * Apply the filter to the input and save to the specified
87 * @param aout Output allocation. Must match creation element
90 public void forEach(Allocation aout) {
91 forEach(0, null, aout, null);
95 * Get a KernelID for this intrinsic kernel.
97 * @return Script.KernelID The KernelID object.
99 public Script.KernelID getKernelID() {
100 return createKernelID(0, 2, null, null);
104 * Get a FieldID for the input field of this intrinsic.
106 * @return Script.FieldID The FieldID object.
108 public Script.FieldID getFieldID_Input() {
109 return createFieldID(1, null);