blob: 68cbc3f3eaadf90d19be68081336b8da46250254 [file] [log] [blame]
Jason Sams3a5b8012012-09-08 22:16:14 -07001/*
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
17package android.renderscript;
18
Jason Sams3a5b8012012-09-08 22:16:14 -070019/**
Jason Sams80d81902012-09-13 17:00:48 -070020 * Intrinsic Gausian blur filter. Applies a gaussian blur of the
21 * specified radius to all elements of an allocation.
22 *
Xusong Wang8b4548c2021-01-05 10:09:52 -080023 * @deprecated Renderscript has been deprecated in API level 31. Please refer to the <a
24 * href="https://developer.android.com/guide/topics/renderscript/migration-guide">migration
25 * guide</a> for the proposed alternatives.
Jason Sams3a5b8012012-09-08 22:16:14 -070026 **/
Xusong Wang8b4548c2021-01-05 10:09:52 -080027@Deprecated
Jason Sams80d81902012-09-13 17:00:48 -070028public final class ScriptIntrinsicBlur extends ScriptIntrinsic {
29 private final float[] mValues = new float[9];
Jason Sams3a5b8012012-09-08 22:16:14 -070030 private Allocation mInput;
31
Tim Murray460a0492013-11-19 12:45:54 -080032 private ScriptIntrinsicBlur(long id, RenderScript rs) {
Jason Sams3a5b8012012-09-08 22:16:14 -070033 super(id, rs);
34 }
35
36 /**
Jason Sams80d81902012-09-13 17:00:48 -070037 * Create an intrinsic for applying a blur to an allocation. The
38 * default radius is 5.0.
Jason Sams3a5b8012012-09-08 22:16:14 -070039 *
Miao Wangc242fa62016-04-13 16:43:10 -070040 * Supported elements types are {@link Element#U8},
41 * {@link Element#U8_4}.
Jason Sams3a5b8012012-09-08 22:16:14 -070042 *
Tim Murrayc11e25c2013-04-09 11:01:01 -070043 * @param rs The RenderScript context
Jason Sams80d81902012-09-13 17:00:48 -070044 * @param e Element type for inputs and outputs
Jason Sams3a5b8012012-09-08 22:16:14 -070045 *
Jason Sams80d81902012-09-13 17:00:48 -070046 * @return ScriptIntrinsicBlur
Jason Sams3a5b8012012-09-08 22:16:14 -070047 */
48 public static ScriptIntrinsicBlur create(RenderScript rs, Element e) {
Tim Murraybddc7ff2013-04-01 11:35:35 -070049 if ((!e.isCompatible(Element.U8_4(rs))) && (!e.isCompatible(Element.U8(rs)))) {
Stephen Hinesad57e332016-04-11 13:05:55 -070050 throw new RSIllegalArgumentException("Unsupported element type.");
Jason Sams80d81902012-09-13 17:00:48 -070051 }
Tim Murray460a0492013-11-19 12:45:54 -080052 long id = rs.nScriptIntrinsicCreate(5, e.getID(rs));
Jason Sams80d81902012-09-13 17:00:48 -070053 ScriptIntrinsicBlur sib = new ScriptIntrinsicBlur(id, rs);
54 sib.setRadius(5.f);
55 return sib;
Jason Sams3a5b8012012-09-08 22:16:14 -070056 }
57
Jason Sams80d81902012-09-13 17:00:48 -070058 /**
59 * Set the input of the blur.
60 * Must match the element type supplied during create.
61 *
62 * @param ain The input allocation
63 */
Jason Sams3a5b8012012-09-08 22:16:14 -070064 public void setInput(Allocation ain) {
Yang Nibb671372017-04-18 14:04:55 -070065 if (ain.getType().getY() == 0) {
66 throw new RSIllegalArgumentException("Input set to a 1D Allocation");
67 }
Miao Wang08d7d032019-03-06 12:33:51 -080068 Element e = ain.getElement();
69 if ((!e.isCompatible(Element.U8_4(mRS))) && (!e.isCompatible(Element.U8(mRS)))) {
70 throw new RSIllegalArgumentException("Unsupported element type.");
71 }
Jason Sams3a5b8012012-09-08 22:16:14 -070072 mInput = ain;
Jason Samse6a78862012-10-15 15:45:12 -070073 setVar(1, ain);
Jason Sams3a5b8012012-09-08 22:16:14 -070074 }
75
Jason Sams80d81902012-09-13 17:00:48 -070076 /**
77 * Set the radius of the Blur.
78 *
Jason Sams31864d72012-10-02 15:21:11 -070079 * Supported range 0 < radius <= 25
Jason Sams80d81902012-09-13 17:00:48 -070080 *
81 * @param radius The radius of the blur
82 */
83 public void setRadius(float radius) {
Jason Sams31864d72012-10-02 15:21:11 -070084 if (radius <= 0 || radius > 25) {
85 throw new RSIllegalArgumentException("Radius out of range (0 < r <= 25).");
Jason Sams3a5b8012012-09-08 22:16:14 -070086 }
Jason Sams80d81902012-09-13 17:00:48 -070087 setVar(0, radius);
Jason Sams3a5b8012012-09-08 22:16:14 -070088 }
89
Jason Sams80d81902012-09-13 17:00:48 -070090 /**
91 * Apply the filter to the input and save to the specified
92 * allocation.
93 *
94 * @param aout Output allocation. Must match creation element
95 * type.
96 */
Jason Sams3a5b8012012-09-08 22:16:14 -070097 public void forEach(Allocation aout) {
Yang Nibb671372017-04-18 14:04:55 -070098 if (aout.getType().getY() == 0) {
99 throw new RSIllegalArgumentException("Output is a 1D Allocation");
100 }
Chris Wailes94961062014-06-11 12:01:28 -0700101 forEach(0, (Allocation) null, aout, null);
Jason Sams3a5b8012012-09-08 22:16:14 -0700102 }
103
Jason Sams08a81582012-09-18 12:32:10 -0700104 /**
Tim Murray6f842ac2014-01-13 11:47:53 -0800105 * Apply the filter to the input and save to the specified
106 * allocation.
107 *
108 * @param aout Output allocation. Must match creation element
109 * type.
110 * @param opt LaunchOptions for clipping
111 */
112 public void forEach(Allocation aout, Script.LaunchOptions opt) {
Yang Nibb671372017-04-18 14:04:55 -0700113 if (aout.getType().getY() == 0) {
114 throw new RSIllegalArgumentException("Output is a 1D Allocation");
115 }
Stephen Hines48ba5062014-07-09 07:39:38 -0700116 forEach(0, (Allocation) null, aout, null, opt);
Tim Murray6f842ac2014-01-13 11:47:53 -0800117 }
118
119
120 /**
Jason Sams08a81582012-09-18 12:32:10 -0700121 * Get a KernelID for this intrinsic kernel.
122 *
123 * @return Script.KernelID The KernelID object.
124 */
125 public Script.KernelID getKernelID() {
126 return createKernelID(0, 2, null, null);
127 }
128
129 /**
130 * Get a FieldID for the input field of this intrinsic.
131 *
132 * @return Script.FieldID The FieldID object.
133 */
134 public Script.FieldID getFieldID_Input() {
135 return createFieldID(1, null);
136 }
Jason Sams3a5b8012012-09-08 22:16:14 -0700137}