• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 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 android.support.v8.renderscript;
18 
19 import android.util.Log;
20 
21 /**
22  * Intrinsic for performing a resize of a 2D allocation.
23  */
24 public class ScriptIntrinsicResize extends ScriptIntrinsic {
25     private Allocation mInput;
26     // API level for the intrinsic
27     private static final int INTRINSIC_API_LEVEL = 21;
28 
ScriptIntrinsicResize(long id, RenderScript rs)29     protected ScriptIntrinsicResize(long id, RenderScript rs) {
30         super(id, rs);
31     }
32 
33     /**
34      * Supported elements types are {@link Element#U8}, {@link
35      * Element#U8_2}, {@link Element#U8_3}, {@link Element#U8_4}
36      * {@link Element#F32}, {@link Element#F32_2}, {@link
37      * Element#F32_3}, {@link Element#F32_4}
38      *
39      * @param rs The RenderScript context
40      *
41      * @return ScriptIntrinsicResize
42      */
create(RenderScript rs)43     public static ScriptIntrinsicResize create(RenderScript rs) {
44         long id;
45         boolean mUseIncSupp = rs.isUseNative() &&
46                               android.os.Build.VERSION.SDK_INT < INTRINSIC_API_LEVEL;
47 
48         id = rs.nScriptIntrinsicCreate(12, 0, mUseIncSupp);
49 
50         ScriptIntrinsicResize si = new ScriptIntrinsicResize(id, rs);
51         si.setIncSupp(mUseIncSupp);
52         return si;
53 
54     }
55 
56     /**
57      * Set the input of the resize.
58      * Must match the element type supplied during create.
59      *
60      * @param ain The input allocation.
61      */
62     public void setInput(Allocation ain) {
63         Element e = ain.getElement();
64         if (!e.isCompatible(Element.U8(mRS)) &&
65             !e.isCompatible(Element.U8_2(mRS)) &&
66             !e.isCompatible(Element.U8_3(mRS)) &&
67             !e.isCompatible(Element.U8_4(mRS)) &&
68             !e.isCompatible(Element.F32(mRS)) &&
69             !e.isCompatible(Element.F32_2(mRS)) &&
70             !e.isCompatible(Element.F32_3(mRS)) &&
71             !e.isCompatible(Element.F32_4(mRS))) {
72             throw new RSIllegalArgumentException("Unsuported element type.");
73         }
74 
75         mInput = ain;
76         setVar(0, ain);
77     }
78 
79     /**
80      * Get a FieldID for the input field of this intrinsic.
81      *
82      * @return Script.FieldID The FieldID object.
83      */
84     public Script.FieldID getFieldID_Input() {
85         return createFieldID(0, null);
86     }
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.  Must not be same as input.
96      */
97     public void forEach_bicubic(Allocation aout) {
98         if (aout == mInput) {
99             throw new RSIllegalArgumentException("Output cannot be same as Input.");
100         }
101         forEach_bicubic(aout, null);
102     }
103 
104     /**
105      * Resize copy the input allocation to the output specified. The
106      * Allocation is rescaled if necessary using bi-cubic
107      * interpolation.
108      *
109      * @param aout Output allocation. Element type must match
110      *             current input.
111      * @param opt LaunchOptions for clipping
112      */
113     public void forEach_bicubic(Allocation aout, Script.LaunchOptions opt) {
114         forEach(0, (Allocation) null, aout, null, opt);
115     }
116 
117     /**
118      * Get a KernelID for this intrinsic kernel.
119      *
120      * @return Script.KernelID The KernelID object.
121      */
122     public Script.KernelID getKernelID_bicubic() {
123         return createKernelID(0, 2, null, null);
124     }
125 
126 
127 }
128