| Jason Sams | 40f1fa6 | 2013-01-08 11:52:32 -0800 | [diff] [blame] | 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 android.renderscript; | 
|  | 18 |  | 
| Jason Sams | 40f1fa6 | 2013-01-08 11:52:32 -0800 | [diff] [blame] | 19 | /** | 
|  | 20 | * | 
| Jason Sams | 02d56d9 | 2013-04-12 16:40:50 -0700 | [diff] [blame] | 21 | * Intrinsic for converting RGB to RGBA by using a 3D lookup table.  The | 
|  | 22 | * incoming r,g,b values are use as normalized x,y,z coordinates into a 3D | 
|  | 23 | * allocation.  The 8 nearest values are sampled and linearly interpolated.  The | 
|  | 24 | * result is placed in the output. | 
|  | 25 | * | 
| Xusong Wang | 1f8dc65 | 2021-01-05 10:09:52 -0800 | [diff] [blame] | 26 | * @deprecated Renderscript has been deprecated in API level 31. Please refer to the <a | 
|  | 27 | * href="https://developer.android.com/guide/topics/renderscript/migration-guide">migration | 
|  | 28 | * guide</a> for the proposed alternatives. | 
| Jason Sams | 40f1fa6 | 2013-01-08 11:52:32 -0800 | [diff] [blame] | 29 | **/ | 
| Xusong Wang | 1f8dc65 | 2021-01-05 10:09:52 -0800 | [diff] [blame] | 30 | @Deprecated | 
| Jason Sams | 40f1fa6 | 2013-01-08 11:52:32 -0800 | [diff] [blame] | 31 | public final class ScriptIntrinsic3DLUT extends ScriptIntrinsic { | 
|  | 32 | private Allocation mLUT; | 
|  | 33 | private Element mElement; | 
|  | 34 |  | 
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 35 | private ScriptIntrinsic3DLUT(long id, RenderScript rs, Element e) { | 
| Jason Sams | 40f1fa6 | 2013-01-08 11:52:32 -0800 | [diff] [blame] | 36 | super(id, rs); | 
|  | 37 | mElement = e; | 
|  | 38 | } | 
|  | 39 |  | 
|  | 40 | /** | 
|  | 41 | * Supported elements types are {@link Element#U8_4} | 
|  | 42 | * | 
|  | 43 | * The defaults tables are identity. | 
|  | 44 | * | 
| Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 45 | * @param rs The RenderScript context | 
| Jason Sams | 40f1fa6 | 2013-01-08 11:52:32 -0800 | [diff] [blame] | 46 | * @param e Element type for intputs and outputs | 
|  | 47 | * | 
|  | 48 | * @return ScriptIntrinsic3DLUT | 
|  | 49 | */ | 
|  | 50 | public static ScriptIntrinsic3DLUT create(RenderScript rs, Element e) { | 
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 51 | long id = rs.nScriptIntrinsicCreate(8, e.getID(rs)); | 
| Jason Sams | 40f1fa6 | 2013-01-08 11:52:32 -0800 | [diff] [blame] | 52 |  | 
|  | 53 | if (!e.isCompatible(Element.U8_4(rs))) { | 
| Jason Sams | 1e645d2 | 2013-03-08 14:32:43 -0800 | [diff] [blame] | 54 | throw new RSIllegalArgumentException("Element must be compatible with uchar4."); | 
| Jason Sams | 40f1fa6 | 2013-01-08 11:52:32 -0800 | [diff] [blame] | 55 | } | 
|  | 56 |  | 
|  | 57 | return new ScriptIntrinsic3DLUT(id, rs, e); | 
|  | 58 | } | 
|  | 59 |  | 
| Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 60 | /** | 
|  | 61 | * Sets the {@link android.renderscript.Allocation} to be used as the lookup table. | 
|  | 62 | * | 
|  | 63 | * The lookup table must use the same {@link android.renderscript.Element} as the intrinsic. | 
|  | 64 | * | 
|  | 65 | */ | 
|  | 66 |  | 
| Jason Sams | 40f1fa6 | 2013-01-08 11:52:32 -0800 | [diff] [blame] | 67 | public void setLUT(Allocation lut) { | 
|  | 68 | final Type t = lut.getType(); | 
|  | 69 |  | 
|  | 70 | if (t.getZ() == 0) { | 
|  | 71 | throw new RSIllegalArgumentException("LUT must be 3d."); | 
|  | 72 | } | 
|  | 73 |  | 
|  | 74 | if (!t.getElement().isCompatible(mElement)) { | 
|  | 75 | throw new RSIllegalArgumentException("LUT element type must match."); | 
|  | 76 | } | 
|  | 77 |  | 
|  | 78 | mLUT = lut; | 
|  | 79 | setVar(0, mLUT); | 
|  | 80 | } | 
|  | 81 |  | 
|  | 82 |  | 
|  | 83 | /** | 
|  | 84 | * Invoke the kernel and apply the lookup to each cell of ain | 
|  | 85 | * and copy to aout. | 
|  | 86 | * | 
|  | 87 | * @param ain Input allocation | 
|  | 88 | * @param aout Output allocation | 
|  | 89 | */ | 
|  | 90 | public void forEach(Allocation ain, Allocation aout) { | 
| Tim Murray | 6f842ac | 2014-01-13 11:47:53 -0800 | [diff] [blame] | 91 | forEach(ain, aout, null); | 
| Jason Sams | 40f1fa6 | 2013-01-08 11:52:32 -0800 | [diff] [blame] | 92 | } | 
|  | 93 |  | 
|  | 94 | /** | 
| Tim Murray | 6f842ac | 2014-01-13 11:47:53 -0800 | [diff] [blame] | 95 | * Invoke the kernel and apply the lookup to each cell of ain | 
|  | 96 | * and copy to aout. | 
|  | 97 | * | 
|  | 98 | * @param ain Input allocation | 
|  | 99 | * @param aout Output allocation | 
|  | 100 | * @param opt Launch options for kernel | 
|  | 101 | */ | 
|  | 102 | public void forEach(Allocation ain, Allocation aout, Script.LaunchOptions opt) { | 
|  | 103 | forEach(0, ain, aout, null, opt); | 
|  | 104 | } | 
|  | 105 |  | 
|  | 106 |  | 
|  | 107 | /** | 
| Jason Sams | 40f1fa6 | 2013-01-08 11:52:32 -0800 | [diff] [blame] | 108 | * Get a KernelID for this intrinsic kernel. | 
|  | 109 | * | 
|  | 110 | * @return Script.KernelID The KernelID object. | 
|  | 111 | */ | 
|  | 112 | public Script.KernelID getKernelID() { | 
|  | 113 | return createKernelID(0, 3, null, null); | 
|  | 114 | } | 
|  | 115 | } | 
|  | 116 |  |