| Jason Sams | 6ab9768 | 2012-08-10 12:09:43 -0700 | [diff] [blame] | 1 | /* | 
| Jason Sams | 8fd5853 | 2012-09-05 15:30:18 -0700 | [diff] [blame] | 2 |  * Copyright (C) 2012 The Android Open Source Project | 
| Jason Sams | 6ab9768 | 2012-08-10 12:09:43 -0700 | [diff] [blame] | 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.renderscript; | 
 | 18 |  | 
| Jason Sams | 6ab9768 | 2012-08-10 12:09:43 -0700 | [diff] [blame] | 19 |  | 
 | 20 | /** | 
| Jason Sams | e69e9e6 | 2012-09-18 18:23:15 -0700 | [diff] [blame] | 21 |  * Intrinsic for converting an Android YUV buffer to RGB. | 
 | 22 |  * | 
| Tim Murray | 932e78e | 2013-09-03 11:42:26 -0700 | [diff] [blame] | 23 |  * The input allocation should be supplied in a supported YUV format | 
 | 24 |  * as a YUV element Allocation. The output is RGBA; the alpha channel | 
 | 25 |  * will be set to 255. | 
| Xusong Wang | 1f8dc65 | 2021-01-05 10:09:52 -0800 | [diff] [blame] | 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. | 
| Jason Sams | e69e9e6 | 2012-09-18 18:23:15 -0700 | [diff] [blame] | 30 |  */ | 
| Xusong Wang | 1f8dc65 | 2021-01-05 10:09:52 -0800 | [diff] [blame] | 31 | @Deprecated | 
| Jason Sams | e69e9e6 | 2012-09-18 18:23:15 -0700 | [diff] [blame] | 32 | public final class ScriptIntrinsicYuvToRGB extends ScriptIntrinsic { | 
 | 33 |     private Allocation mInput; | 
 | 34 |  | 
| Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 35 |     ScriptIntrinsicYuvToRGB(long id, RenderScript rs) { | 
| Jason Sams | 6ab9768 | 2012-08-10 12:09:43 -0700 | [diff] [blame] | 36 |         super(id, rs); | 
 | 37 |     } | 
 | 38 |  | 
| Jason Sams | e69e9e6 | 2012-09-18 18:23:15 -0700 | [diff] [blame] | 39 |     /** | 
 | 40 |      * Create an intrinsic for converting YUV to RGB. | 
 | 41 |      * | 
 | 42 |      * Supported elements types are {@link Element#U8_4} | 
 | 43 |      * | 
| Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 44 |      * @param rs The RenderScript context | 
| Jason Sams | e69e9e6 | 2012-09-18 18:23:15 -0700 | [diff] [blame] | 45 |      * @param e Element type for output | 
 | 46 |      * | 
 | 47 |      * @return ScriptIntrinsicYuvToRGB | 
 | 48 |      */ | 
 | 49 |     public static ScriptIntrinsicYuvToRGB create(RenderScript rs, Element e) { | 
 | 50 |         // 6 comes from RS_SCRIPT_INTRINSIC_YUV_TO_RGB in rsDefines.h | 
| Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 51 |         long id = rs.nScriptIntrinsicCreate(6, e.getID(rs)); | 
| Jason Sams | e69e9e6 | 2012-09-18 18:23:15 -0700 | [diff] [blame] | 52 |         ScriptIntrinsicYuvToRGB si = new ScriptIntrinsicYuvToRGB(id, rs); | 
 | 53 |         return si; | 
| Jason Sams | 6ab9768 | 2012-08-10 12:09:43 -0700 | [diff] [blame] | 54 |     } | 
 | 55 |  | 
| Jason Sams | e69e9e6 | 2012-09-18 18:23:15 -0700 | [diff] [blame] | 56 |  | 
 | 57 |     /** | 
 | 58 |      * Set the input yuv allocation, must be {@link Element#U8}. | 
 | 59 |      * | 
 | 60 |      * @param ain The input allocation. | 
 | 61 |      */ | 
 | 62 |     public void setInput(Allocation ain) { | 
 | 63 |         mInput = ain; | 
| Jason Sams | e6a7886 | 2012-10-15 15:45:12 -0700 | [diff] [blame] | 64 |         setVar(0, ain); | 
| Jason Sams | e69e9e6 | 2012-09-18 18:23:15 -0700 | [diff] [blame] | 65 |     } | 
 | 66 |  | 
 | 67 |     /** | 
 | 68 |      * Convert the image to RGB. | 
 | 69 |      * | 
 | 70 |      * @param aout Output allocation. Must match creation element | 
 | 71 |      *             type. | 
 | 72 |      */ | 
 | 73 |     public void forEach(Allocation aout) { | 
| Chris Wailes | 9496106 | 2014-06-11 12:01:28 -0700 | [diff] [blame] | 74 |         forEach(0, (Allocation) null, aout, null); | 
| Jason Sams | e69e9e6 | 2012-09-18 18:23:15 -0700 | [diff] [blame] | 75 |     } | 
 | 76 |  | 
 | 77 |     /** | 
 | 78 |      * Get a KernelID for this intrinsic kernel. | 
 | 79 |      * | 
 | 80 |      * @return Script.KernelID The KernelID object. | 
 | 81 |      */ | 
 | 82 |     public Script.KernelID getKernelID() { | 
 | 83 |         return createKernelID(0, 2, null, null); | 
 | 84 |     } | 
 | 85 |  | 
 | 86 |     /** | 
 | 87 |      * Get a FieldID for the input field of this intrinsic. | 
 | 88 |      * | 
 | 89 |      * @return Script.FieldID The FieldID object. | 
 | 90 |      */ | 
 | 91 |     public Script.FieldID getFieldID_Input() { | 
 | 92 |         return createFieldID(0, null); | 
 | 93 |     } | 
| Jason Sams | 6ab9768 | 2012-08-10 12:09:43 -0700 | [diff] [blame] | 94 | } |