blob: 98499b5dbab20c9ccf3073b20296ec07e3c9b7af [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 *
23 *
Jason Sams3a5b8012012-09-08 22:16:14 -070024 **/
Jason Sams80d81902012-09-13 17:00:48 -070025public final class ScriptIntrinsicBlur extends ScriptIntrinsic {
26 private final float[] mValues = new float[9];
Jason Sams3a5b8012012-09-08 22:16:14 -070027 private Allocation mInput;
28
Tim Murray460a0492013-11-19 12:45:54 -080029 private ScriptIntrinsicBlur(long id, RenderScript rs) {
Jason Sams3a5b8012012-09-08 22:16:14 -070030 super(id, rs);
31 }
32
33 /**
Jason Sams80d81902012-09-13 17:00:48 -070034 * Create an intrinsic for applying a blur to an allocation. The
35 * default radius is 5.0.
Jason Sams3a5b8012012-09-08 22:16:14 -070036 *
Jason Sams37192dc2015-04-02 14:10:53 -070037 * Supported elements types are {@link Element#U8_4 Element#U8}
Jason Sams3a5b8012012-09-08 22:16:14 -070038 *
Tim Murrayc11e25c2013-04-09 11:01:01 -070039 * @param rs The RenderScript context
Jason Sams80d81902012-09-13 17:00:48 -070040 * @param e Element type for inputs and outputs
Jason Sams3a5b8012012-09-08 22:16:14 -070041 *
Jason Sams80d81902012-09-13 17:00:48 -070042 * @return ScriptIntrinsicBlur
Jason Sams3a5b8012012-09-08 22:16:14 -070043 */
44 public static ScriptIntrinsicBlur create(RenderScript rs, Element e) {
Tim Murraybddc7ff2013-04-01 11:35:35 -070045 if ((!e.isCompatible(Element.U8_4(rs))) && (!e.isCompatible(Element.U8(rs)))) {
Stephen Hinesad57e332016-04-11 13:05:55 -070046 throw new RSIllegalArgumentException("Unsupported element type.");
Jason Sams80d81902012-09-13 17:00:48 -070047 }
Tim Murray460a0492013-11-19 12:45:54 -080048 long id = rs.nScriptIntrinsicCreate(5, e.getID(rs));
Jason Sams80d81902012-09-13 17:00:48 -070049 ScriptIntrinsicBlur sib = new ScriptIntrinsicBlur(id, rs);
50 sib.setRadius(5.f);
51 return sib;
Jason Sams3a5b8012012-09-08 22:16:14 -070052 }
53
Jason Sams80d81902012-09-13 17:00:48 -070054 /**
55 * Set the input of the blur.
56 * Must match the element type supplied during create.
57 *
58 * @param ain The input allocation
59 */
Jason Sams3a5b8012012-09-08 22:16:14 -070060 public void setInput(Allocation ain) {
61 mInput = ain;
Jason Samse6a78862012-10-15 15:45:12 -070062 setVar(1, ain);
Jason Sams3a5b8012012-09-08 22:16:14 -070063 }
64
Jason Sams80d81902012-09-13 17:00:48 -070065 /**
66 * Set the radius of the Blur.
67 *
Jason Sams31864d72012-10-02 15:21:11 -070068 * Supported range 0 < radius <= 25
Jason Sams80d81902012-09-13 17:00:48 -070069 *
70 * @param radius The radius of the blur
71 */
72 public void setRadius(float radius) {
Jason Sams31864d72012-10-02 15:21:11 -070073 if (radius <= 0 || radius > 25) {
74 throw new RSIllegalArgumentException("Radius out of range (0 < r <= 25).");
Jason Sams3a5b8012012-09-08 22:16:14 -070075 }
Jason Sams80d81902012-09-13 17:00:48 -070076 setVar(0, radius);
Jason Sams3a5b8012012-09-08 22:16:14 -070077 }
78
Jason Sams80d81902012-09-13 17:00:48 -070079 /**
80 * Apply the filter to the input and save to the specified
81 * allocation.
82 *
83 * @param aout Output allocation. Must match creation element
84 * type.
85 */
Jason Sams3a5b8012012-09-08 22:16:14 -070086 public void forEach(Allocation aout) {
Chris Wailes94961062014-06-11 12:01:28 -070087 forEach(0, (Allocation) null, aout, null);
Jason Sams3a5b8012012-09-08 22:16:14 -070088 }
89
Jason Sams08a81582012-09-18 12:32:10 -070090 /**
Tim Murray6f842ac2014-01-13 11:47:53 -080091 * 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 * @param opt LaunchOptions for clipping
97 */
98 public void forEach(Allocation aout, Script.LaunchOptions opt) {
Stephen Hines48ba5062014-07-09 07:39:38 -070099 forEach(0, (Allocation) null, aout, null, opt);
Tim Murray6f842ac2014-01-13 11:47:53 -0800100 }
101
102
103 /**
Jason Sams08a81582012-09-18 12:32:10 -0700104 * Get a KernelID for this intrinsic kernel.
105 *
106 * @return Script.KernelID The KernelID object.
107 */
108 public Script.KernelID getKernelID() {
109 return createKernelID(0, 2, null, null);
110 }
111
112 /**
113 * Get a FieldID for the input field of this intrinsic.
114 *
115 * @return Script.FieldID The FieldID object.
116 */
117 public Script.FieldID getFieldID_Input() {
118 return createFieldID(1, null);
119 }
Jason Sams3a5b8012012-09-08 22:16:14 -0700120}