blob: 3e58b8726ec7445f69b5e9fd6c07d415616f5b4f [file] [log] [blame]
Jason Sams40f1fa62013-01-08 11:52:32 -08001/*
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.renderscript;
18
19import android.util.Log;
20
21/**
22 *
23 * @hide
24 **/
25public final class ScriptIntrinsic3DLUT extends ScriptIntrinsic {
26 private Allocation mLUT;
27 private Element mElement;
28
29 private ScriptIntrinsic3DLUT(int id, RenderScript rs, Element e) {
30 super(id, rs);
31 mElement = e;
32 }
33
34 /**
35 * Supported elements types are {@link Element#U8_4}
36 *
37 * The defaults tables are identity.
38 *
39 * @param rs The Renderscript context
40 * @param e Element type for intputs and outputs
41 *
42 * @return ScriptIntrinsic3DLUT
43 */
44 public static ScriptIntrinsic3DLUT create(RenderScript rs, Element e) {
45 int id = rs.nScriptIntrinsicCreate(8, e.getID(rs));
46
47 if (!e.isCompatible(Element.U8_4(rs))) {
Jason Sams1e645d22013-03-08 14:32:43 -080048 throw new RSIllegalArgumentException("Element must be compatible with uchar4.");
Jason Sams40f1fa62013-01-08 11:52:32 -080049 }
50
51 return new ScriptIntrinsic3DLUT(id, rs, e);
52 }
53
54 public void setLUT(Allocation lut) {
55 final Type t = lut.getType();
56
57 if (t.getZ() == 0) {
58 throw new RSIllegalArgumentException("LUT must be 3d.");
59 }
60
61 if (!t.getElement().isCompatible(mElement)) {
62 throw new RSIllegalArgumentException("LUT element type must match.");
63 }
64
65 mLUT = lut;
66 setVar(0, mLUT);
67 }
68
69
70 /**
71 * Invoke the kernel and apply the lookup to each cell of ain
72 * and copy to aout.
73 *
74 * @param ain Input allocation
75 * @param aout Output allocation
76 */
77 public void forEach(Allocation ain, Allocation aout) {
78 forEach(0, ain, aout, null);
79 }
80
81 /**
82 * Get a KernelID for this intrinsic kernel.
83 *
84 * @return Script.KernelID The KernelID object.
85 */
86 public Script.KernelID getKernelID() {
87 return createKernelID(0, 3, null, null);
88 }
89}
90