blob: cc37120f80308052a3cf213b99db22edecd3b3e8 [file] [log] [blame]
Jason Sams464af412014-04-16 17:13:09 -07001/*
2 * Copyright (C) 2014 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
19/**
20 * Intrinsic for performing a resize of a 2D allocation.
21 * @hide
22 */
23public final class ScriptIntrinsicResize extends ScriptIntrinsic {
24 private Allocation mInput;
25
26 private ScriptIntrinsicResize(long id, RenderScript rs) {
27 super(id, rs);
28 }
29
30 /**
31 * Supported elements types are {@link Element#U8}, {@link
32 * Element#U8_2}, {@link Element#U8_3}, {@link Element#U8_4}
33 *
34 * @param rs The RenderScript context
35 *
36 * @return ScriptIntrinsicResize
37 */
38 public static ScriptIntrinsicResize create(RenderScript rs) {
39 long id = rs.nScriptIntrinsicCreate(12, 0);
40 ScriptIntrinsicResize si = new ScriptIntrinsicResize(id, rs);
41 return si;
42
43 }
44
45 /**
46 * Set the input of the resize.
47 * Must match the element type supplied during create.
48 *
49 * @param ain The input allocation.
50 */
51 public void setInput(Allocation ain) {
52 Element e = ain.getElement();
53 if (!e.isCompatible(Element.U8(mRS)) &&
54 !e.isCompatible(Element.U8_2(mRS)) &&
55 !e.isCompatible(Element.U8_3(mRS)) &&
56 !e.isCompatible(Element.U8_4(mRS))) {
57 throw new RSIllegalArgumentException("Unsuported element type.");
58 }
59
60 mInput = ain;
61 setVar(0, ain);
62 }
63
64 /**
65 * Get a FieldID for the input field of this intrinsic.
66 *
67 * @return Script.FieldID The FieldID object.
68 */
69 public Script.FieldID getFieldID_Input() {
70 return createFieldID(0, null);
71 }
72
73
74 /**
75 * Resize copy the input allocation to the output specified. The
76 * Allocation is rescaled if necessary using bi-cubic
77 * interpolation.
78 *
79 * @param aout Output allocation. Element type must match
80 * current input. Must not be same as input.
81 */
82 public void forEach_bicubic(Allocation aout) {
83 if (aout == mInput) {
84 throw new RSIllegalArgumentException("Output cannot be same as Input.");
85 }
86 forEach_bicubic(aout, null);
87 }
88
89 /**
90 * Resize copy the input allocation to the output specified. The
91 * Allocation is rescaled if necessary using bi-cubic
92 * interpolation.
93 *
94 * @param aout Output allocation. Element type must match
95 * current input.
96 * @param opt LaunchOptions for clipping
97 */
98 public void forEach_bicubic(Allocation aout, Script.LaunchOptions opt) {
99 forEach(0, null, aout, null, opt);
100 }
101
102 /**
103 * Get a KernelID for this intrinsic kernel.
104 *
105 * @return Script.KernelID The KernelID object.
106 */
107 public Script.KernelID getKernelID_bicubic() {
108 return createKernelID(0, 2, null, null);
109 }
110
111
112}
113