• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2012 The Android Open Source Project
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 
17 package androidx.renderscript;
18 
19 import android.content.Context;
20 import android.content.res.Resources;
21 import android.util.Log;
22 
23 /**
24  * Intrinsic Gausian blur filter. Applies a gaussian blur of the
25  * specified radius to all elements of an allocation.
26  *
27  * @deprecated Renderscript has been deprecated in API level 31. Please refer to the <a
28  * href="https://developer.android.com/guide/topics/renderscript/migration-guide">migration
29  * guide</a> for the proposed alternatives.
30  **/
31 @Deprecated
32 public class ScriptIntrinsicBlur extends ScriptIntrinsic {
33     private final float[] mValues = new float[9];
34     private Allocation mInput;
35     // API level for the intrinsic
36     private static final int INTRINSIC_API_LEVEL = 19;
37 
ScriptIntrinsicBlur(long id, RenderScript rs)38     protected ScriptIntrinsicBlur(long id, RenderScript rs) {
39         super(id, rs);
40     }
41 
42     /**
43      * Create an intrinsic for applying a blur to an allocation. The
44      * default radius is 5.0.
45      *
46      * Supported elements types are {@link Element#U8},
47      * {@link Element#U8_4}.
48      *
49      * @param rs The RenderScript context
50      * @param e Element type for inputs and outputs
51      *
52      * @return ScriptIntrinsicBlur
53      */
create(RenderScript rs, Element e)54     public static ScriptIntrinsicBlur create(RenderScript rs, Element e) {
55         if ((!e.isCompatible(Element.U8_4(rs))) && (!e.isCompatible(Element.U8(rs)))) {
56             throw new RSIllegalArgumentException("Unsupported element type.");
57         }
58         long id;
59         boolean mUseIncSupp = rs.isUseNative() &&
60                               android.os.Build.VERSION.SDK_INT < INTRINSIC_API_LEVEL;
61 
62         id = rs.nScriptIntrinsicCreate(5, e.getID(rs), mUseIncSupp);
63 
64         ScriptIntrinsicBlur si = new ScriptIntrinsicBlur(id, rs);
65         si.setIncSupp(mUseIncSupp);
66         si.setRadius(5.f);
67 
68         return si;
69     }
70 
71     /**
72      * Set the input of the blur.
73      * Must match the element type supplied during create.
74      *
75      * @param ain The input allocation
76      */
77     public void setInput(Allocation ain) {
78         if (ain.getType().getY() == 0) {
79             throw new RSIllegalArgumentException("Input set to a 1D Allocation");
80         }
81         mInput = ain;
82         setVar(1, ain);
83     }
84 
85     /**
86      * Set the radius of the Blur.
87      *
88      * Supported range 0 < radius <= 25
89      *
90      * @param radius The radius of the blur
91      */
92     public void setRadius(float radius) {
93         if (radius <= 0 || radius > 25) {
94             throw new RSIllegalArgumentException("Radius out of range (0 < r <= 25).");
95         }
96         setVar(0, radius);
97     }
98 
99     /**
100      * Apply the filter to the input and save to the specified
101      * allocation.
102      *
103      * @param aout Output allocation. Must match creation element
104      *             type.
105      */
106     public void forEach(Allocation aout) {
107         if (aout.getType().getY() == 0) {
108             throw new RSIllegalArgumentException("Output is a 1D Allocation");
109         }
110         forEach(0, (Allocation) null, aout, null);
111     }
112 
113     /**
114      * Get a KernelID for this intrinsic kernel.
115      *
116      * @return Script.KernelID The KernelID object.
117      */
118     public Script.KernelID getKernelID() {
119         return createKernelID(0, 2, null, null);
120     }
121 
122     /**
123      * Get a FieldID for the input field of this intrinsic.
124      *
125      * @return Script.FieldID The FieldID object.
126      */
127     public Script.FieldID getFieldID_Input() {
128         return createFieldID(1, null);
129     }
130 }
131 
132