| 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 |
@Deprecated |
| 27 |
public final class ScriptIntrinsicHistogram extends ScriptIntrinsic { |
| 28 |
private Allocation mOut; |
| 29 |
|
| 30 |
private ScriptIntrinsicHistogram(long id, RenderScript rs) { |
| 31 |
super(id, rs); |
| 32 |
} |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
public static ScriptIntrinsicHistogram create(RenderScript rs, Element e) { |
| 48 |
if ((!e.isCompatible(Element.U8_4(rs))) && |
| 49 |
(!e.isCompatible(Element.U8_3(rs))) && |
| 50 |
(!e.isCompatible(Element.U8_2(rs))) && |
| 51 |
(!e.isCompatible(Element.U8(rs)))) { |
| 52 |
throw new RSIllegalArgumentException("Unsupported element type."); |
| 53 |
} |
| 54 |
long id = rs.nScriptIntrinsicCreate(9, e.getID(rs)); |
| 55 |
ScriptIntrinsicHistogram sib = new ScriptIntrinsicHistogram(id, rs); |
| 56 |
return sib; |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
public void forEach(Allocation ain) { |
| 73 |
forEach(ain, null); |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
public void forEach(Allocation ain, Script.LaunchOptions opt) { |
| 91 |
if (ain.getType().getElement().getVectorSize() < |
| 92 |
mOut.getType().getElement().getVectorSize()) { |
| 93 |
|
| 94 |
throw new RSIllegalArgumentException( |
| 95 |
"Input vector size must be >= output vector size."); |
| 96 |
} |
| 97 |
if (!ain.getType().getElement().isCompatible(Element.U8(mRS)) && |
| 98 |
!ain.getType().getElement().isCompatible(Element.U8_2(mRS)) && |
| 99 |
!ain.getType().getElement().isCompatible(Element.U8_3(mRS)) && |
| 100 |
!ain.getType().getElement().isCompatible(Element.U8_4(mRS))) { |
| 101 |
throw new RSIllegalArgumentException("Input type must be U8, U8_1, U8_2 or U8_4."); |
| 102 |
} |
| 103 |
|
| 104 |
forEach(0, ain, null, null, opt); |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
public void setDotCoefficients(float r, float g, float b, float a) { |
| 121 |
if ((r < 0.f) || (g < 0.f) || (b < 0.f) || (a < 0.f)) { |
| 122 |
throw new RSIllegalArgumentException("Coefficient may not be negative."); |
| 123 |
} |
| 124 |
if ((r + g + b + a) > 1.f) { |
| 125 |
throw new RSIllegalArgumentException("Sum of coefficients must be 1.0 or less."); |
| 126 |
} |
| 127 |
|
| 128 |
FieldPacker fp = new FieldPacker(16); |
| 129 |
fp.addF32(r); |
| 130 |
fp.addF32(g); |
| 131 |
fp.addF32(b); |
| 132 |
fp.addF32(a); |
| 133 |
setVar(0, fp); |
| 134 |
} |
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
public void setOutput(Allocation aout) { |
| 143 |
mOut = aout; |
| 144 |
if (mOut.getType().getElement() != Element.U32(mRS) && |
| 145 |
mOut.getType().getElement() != Element.U32_2(mRS) && |
| 146 |
mOut.getType().getElement() != Element.U32_3(mRS) && |
| 147 |
mOut.getType().getElement() != Element.U32_4(mRS) && |
| 148 |
mOut.getType().getElement() != Element.I32(mRS) && |
| 149 |
mOut.getType().getElement() != Element.I32_2(mRS) && |
| 150 |
mOut.getType().getElement() != Element.I32_3(mRS) && |
| 151 |
mOut.getType().getElement() != Element.I32_4(mRS)) { |
| 152 |
|
| 153 |
throw new RSIllegalArgumentException("Output type must be U32 or I32."); |
| 154 |
} |
| 155 |
if ((mOut.getType().getX() != 256) || |
| 156 |
(mOut.getType().getY() != 0) || |
| 157 |
mOut.getType().hasMipmaps() || |
| 158 |
(mOut.getType().getYuv() != 0)) { |
| 159 |
|
| 160 |
throw new RSIllegalArgumentException("Output must be 1D, 256 elements."); |
| 161 |
} |
| 162 |
setVar(1, aout); |
| 163 |
} |
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
public void forEach_Dot(Allocation ain) { |
| 177 |
forEach_Dot(ain, null); |
| 178 |
} |
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
public void forEach_Dot(Allocation ain, Script.LaunchOptions opt) { |
| 192 |
if (mOut.getType().getElement().getVectorSize() != 1) { |
| 193 |
throw new RSIllegalArgumentException("Output vector size must be one."); |
| 194 |
} |
| 195 |
if (!ain.getType().getElement().isCompatible(Element.U8(mRS)) && |
| 196 |
!ain.getType().getElement().isCompatible(Element.U8_2(mRS)) && |
| 197 |
!ain.getType().getElement().isCompatible(Element.U8_3(mRS)) && |
| 198 |
!ain.getType().getElement().isCompatible(Element.U8_4(mRS))) { |
| 199 |
throw new RSIllegalArgumentException("Input type must be U8, U8_1, U8_2 or U8_4."); |
| 200 |
} |
| 201 |
|
| 202 |
forEach(1, ain, null, null, opt); |
| 203 |
} |
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
public Script.KernelID getKernelID_Separate() { |
| 213 |
return createKernelID(0, 3, null, null); |
| 214 |
} |
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
public Script.FieldID getFieldID_Input() { |
| 222 |
return createFieldID(1, null); |
| 223 |
} |
| 224 |
} |
| 225 |
|