• 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 
20 /**
21  * Intrinsic for converting an Android YUV buffer to RGB.
22  *
23  * The input allocation is supplied in NV21 format as a U8
24  * element type. The output is RGBA, the alpha channel will be
25  * set to 255.
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 ScriptIntrinsicYuvToRGB extends ScriptIntrinsic {
33     private Allocation mInput;
34     // API level for the intrinsic
35     private static final int INTRINSIC_API_LEVEL = 19;
36 
ScriptIntrinsicYuvToRGB(long id, RenderScript rs)37     ScriptIntrinsicYuvToRGB(long id, RenderScript rs) {
38         super(id, rs);
39     }
40 
41     /**
42      * Create an intrinsic for converting YUV to RGB.
43      *
44      * Supported elements types are {@link Element#U8_4}
45      *
46      * @param rs The RenderScript context
47      * @param e Element type for output
48      *
49      * @return ScriptIntrinsicYuvToRGB
50      */
create(RenderScript rs, Element e)51     public static ScriptIntrinsicYuvToRGB create(RenderScript rs, Element e) {
52         // 6 comes from RS_SCRIPT_INTRINSIC_YUV_TO_RGB in rsDefines.h
53         long id;
54         boolean mUseIncSupp = rs.isUseNative() &&
55                               android.os.Build.VERSION.SDK_INT < INTRINSIC_API_LEVEL;
56 
57         id = rs.nScriptIntrinsicCreate(6, e.getID(rs), mUseIncSupp);
58 
59         ScriptIntrinsicYuvToRGB si = new ScriptIntrinsicYuvToRGB(id, rs);
60         si.setIncSupp(mUseIncSupp);
61         return si;
62     }
63 
64 
65     /**
66      * Set the input yuv allocation, must be {@link Element#U8}.
67      *
68      * @param ain The input allocation.
69      */
70     public void setInput(Allocation ain) {
71         mInput = ain;
72         setVar(0, ain);
73     }
74 
75     /**
76      * Convert the image to RGB.
77      *
78      * @param aout Output allocation. Must match creation element
79      *             type.
80      */
81     public void forEach(Allocation aout) {
82         forEach(0, (Allocation) null, aout, null);
83     }
84 
85     /**
86      * Get a KernelID for this intrinsic kernel.
87      *
88      * @return Script.KernelID The KernelID object.
89      */
90     public Script.KernelID getKernelID() {
91         return createKernelID(0, 2, null, null);
92     }
93 
94     /**
95      * Get a FieldID for the input field of this intrinsic.
96      *
97      * @return Script.FieldID The FieldID object.
98      */
99     public Script.FieldID getFieldID_Input() {
100         return createFieldID(0, null);
101     }
102 }
103