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 17package android.support.v8.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 */ 27public class ScriptIntrinsicYuvToRGB extends ScriptIntrinsic { 28 private Allocation mInput; 29 30 ScriptIntrinsicYuvToRGB(int id, RenderScript rs) { 31 super(id, rs); 32 } 33 34 /** 35 * Create an intrinsic for converting YUV to RGB. 36 * 37 * Supported elements types are {@link Element#U8_4} 38 * 39 * @param rs The RenderScript context 40 * @param e Element type for output 41 * 42 * @return ScriptIntrinsicYuvToRGB 43 */ 44 public static ScriptIntrinsicYuvToRGB create(RenderScript rs, Element e) { 45 if (rs.isNative) { 46 RenderScriptThunker rst = (RenderScriptThunker) rs; 47 return ScriptIntrinsicYuvToRGBThunker.create(rs, e); 48 } 49 50 // 6 comes from RS_SCRIPT_INTRINSIC_YUV_TO_RGB in rsDefines.h 51 int id = rs.nScriptIntrinsicCreate(6, e.getID(rs)); 52 ScriptIntrinsicYuvToRGB si = new ScriptIntrinsicYuvToRGB(id, rs); 53 return si; 54 } 55 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; 64 setVar(0, ain); 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) { 74 forEach(0, null, aout, null); 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 } 94} 95