| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.renderscript; |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
@Deprecated |
| 30 |
public final class ScriptIntrinsicLUT extends ScriptIntrinsic { |
| 31 |
private final Matrix4f mMatrix = new Matrix4f(); |
| 32 |
private Allocation mTables; |
| 33 |
private final byte mCache[] = new byte[1024]; |
| 34 |
private boolean mDirty = true; |
| 35 |
|
| 36 |
private ScriptIntrinsicLUT(long id, RenderScript rs) { |
| 37 |
super(id, rs); |
| 38 |
mTables = Allocation.createSized(rs, Element.U8(rs), 1024); |
| 39 |
for (int ct=0; ct < 256; ct++) { |
| 40 |
mCache[ct] = (byte)ct; |
| 41 |
mCache[ct + 256] = (byte)ct; |
| 42 |
mCache[ct + 512] = (byte)ct; |
| 43 |
mCache[ct + 768] = (byte)ct; |
| 44 |
} |
| 45 |
setVar(0, mTables); |
| 46 |
} |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
public static ScriptIntrinsicLUT create(RenderScript rs, Element e) { |
| 59 |
long id = rs.nScriptIntrinsicCreate(3, e.getID(rs)); |
| 60 |
return new ScriptIntrinsicLUT(id, rs); |
| 61 |
|
| 62 |
} |
| 63 |
|
| 64 |
public void destroy() { |
| 65 |
mTables.destroy(); |
| 66 |
super.destroy(); |
| 67 |
} |
| 68 |
|
| 69 |
private void validate(int index, int value) { |
| 70 |
if (index < 0 || index > 255) { |
| 71 |
throw new RSIllegalArgumentException("Index out of range (0-255)."); |
| 72 |
} |
| 73 |
if (value < 0 || value > 255) { |
| 74 |
throw new RSIllegalArgumentException("Value out of range (0-255)."); |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
public void setRed(int index, int value) { |
| 85 |
validate(index, value); |
| 86 |
mCache[index] = (byte)value; |
| 87 |
mDirty = true; |
| 88 |
} |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
public void setGreen(int index, int value) { |
| 97 |
validate(index, value); |
| 98 |
mCache[index+256] = (byte)value; |
| 99 |
mDirty = true; |
| 100 |
} |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
public void setBlue(int index, int value) { |
| 109 |
validate(index, value); |
| 110 |
mCache[index+512] = (byte)value; |
| 111 |
mDirty = true; |
| 112 |
} |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
public void setAlpha(int index, int value) { |
| 121 |
validate(index, value); |
| 122 |
mCache[index+768] = (byte)value; |
| 123 |
mDirty = true; |
| 124 |
} |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
public void forEach(Allocation ain, Allocation aout) { |
| 134 |
forEach(ain, aout, null); |
| 135 |
} |
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
public void forEach(Allocation ain, Allocation aout, Script.LaunchOptions opt) { |
| 146 |
if (mDirty) { |
| 147 |
mDirty = false; |
| 148 |
mTables.copyFromUnchecked(mCache); |
| 149 |
} |
| 150 |
forEach(0, ain, aout, null, opt); |
| 151 |
} |
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
public Script.KernelID getKernelID() { |
| 159 |
return createKernelID(0, 3, null, null); |
| 160 |
} |
| 161 |
} |
| 162 |
|