blob: f942982583bfaf5899a749b9ad6dd561b66d6cb1 [file] [log] [blame]
Jason Sams6ab97682012-08-10 12:09:43 -07001/*
Jason Sams8fd58532012-09-05 15:30:18 -07002 * Copyright (C) 2012 The Android Open Source Project
Jason Sams6ab97682012-08-10 12:09:43 -07003 *
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
Jason Sams6ab97682012-08-10 12:09:43 -070019
20/**
Jason Samse69e9e62012-09-18 18:23:15 -070021 * Intrinsic for converting an Android YUV buffer to RGB.
22 *
Tim Murray932e78e2013-09-03 11:42:26 -070023 * 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.
Jason Samse69e9e62012-09-18 18:23:15 -070026 */
27public final class ScriptIntrinsicYuvToRGB extends ScriptIntrinsic {
28 private Allocation mInput;
29
Tim Murray7a629fa2013-11-19 12:45:54 -080030 ScriptIntrinsicYuvToRGB(long id, RenderScript rs) {
Jason Sams6ab97682012-08-10 12:09:43 -070031 super(id, rs);
32 }
33
Jason Samse69e9e62012-09-18 18:23:15 -070034 /**
35 * Create an intrinsic for converting YUV to RGB.
36 *
37 * Supported elements types are {@link Element#U8_4}
38 *
Tim Murrayc11e25c2013-04-09 11:01:01 -070039 * @param rs The RenderScript context
Jason Samse69e9e62012-09-18 18:23:15 -070040 * @param e Element type for output
41 *
42 * @return ScriptIntrinsicYuvToRGB
43 */
44 public static ScriptIntrinsicYuvToRGB create(RenderScript rs, Element e) {
45 // 6 comes from RS_SCRIPT_INTRINSIC_YUV_TO_RGB in rsDefines.h
Tim Murray7a629fa2013-11-19 12:45:54 -080046 long id = rs.nScriptIntrinsicCreate(6, e.getID(rs));
Jason Samse69e9e62012-09-18 18:23:15 -070047 ScriptIntrinsicYuvToRGB si = new ScriptIntrinsicYuvToRGB(id, rs);
48 return si;
Jason Sams6ab97682012-08-10 12:09:43 -070049 }
50
Jason Samse69e9e62012-09-18 18:23:15 -070051
52 /**
53 * Set the input yuv allocation, must be {@link Element#U8}.
54 *
55 * @param ain The input allocation.
56 */
57 public void setInput(Allocation ain) {
58 mInput = ain;
Jason Samse6a78862012-10-15 15:45:12 -070059 setVar(0, ain);
Jason Samse69e9e62012-09-18 18:23:15 -070060 }
61
62 /**
63 * Convert the image to RGB.
64 *
65 * @param aout Output allocation. Must match creation element
66 * type.
67 */
68 public void forEach(Allocation aout) {
69 forEach(0, null, aout, null);
70 }
71
72 /**
73 * Get a KernelID for this intrinsic kernel.
74 *
75 * @return Script.KernelID The KernelID object.
76 */
77 public Script.KernelID getKernelID() {
78 return createKernelID(0, 2, null, null);
79 }
80
81 /**
82 * Get a FieldID for the input field of this intrinsic.
83 *
84 * @return Script.FieldID The FieldID object.
85 */
86 public Script.FieldID getFieldID_Input() {
87 return createFieldID(0, null);
88 }
Jason Sams6ab97682012-08-10 12:09:43 -070089}