| 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 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
@Deprecated |
| 45 |
public final class ScriptIntrinsicColorMatrix extends ScriptIntrinsic { |
| 46 |
private final Matrix4f mMatrix = new Matrix4f(); |
| 47 |
private final Float4 mAdd = new Float4(); |
| 48 |
|
| 49 |
private ScriptIntrinsicColorMatrix(long id, RenderScript rs) { |
| 50 |
super(id, rs); |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
@Deprecated |
| 68 |
public static ScriptIntrinsicColorMatrix create(RenderScript rs, Element e) { |
| 69 |
return create(rs); |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
public static ScriptIntrinsicColorMatrix create(RenderScript rs) { |
| 81 |
long id = rs.nScriptIntrinsicCreate(2, 0); |
| 82 |
return new ScriptIntrinsicColorMatrix(id, rs); |
| 83 |
|
| 84 |
} |
| 85 |
|
| 86 |
private void setMatrix() { |
| 87 |
FieldPacker fp = new FieldPacker(16*4); |
| 88 |
fp.addMatrix(mMatrix); |
| 89 |
setVar(0, fp); |
| 90 |
} |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
public void setColorMatrix(Matrix4f m) { |
| 99 |
mMatrix.load(m); |
| 100 |
setMatrix(); |
| 101 |
} |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
public void setColorMatrix(Matrix3f m) { |
| 110 |
mMatrix.load(m); |
| 111 |
setMatrix(); |
| 112 |
} |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
public void setAdd(Float4 f) { |
| 121 |
mAdd.x = f.x; |
| 122 |
mAdd.y = f.y; |
| 123 |
mAdd.z = f.z; |
| 124 |
mAdd.w = f.w; |
| 125 |
|
| 126 |
FieldPacker fp = new FieldPacker(4*4); |
| 127 |
fp.addF32(f.x); |
| 128 |
fp.addF32(f.y); |
| 129 |
fp.addF32(f.z); |
| 130 |
fp.addF32(f.w); |
| 131 |
setVar(1, fp); |
| 132 |
} |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
public void setAdd(float r, float g, float b, float a) { |
| 144 |
mAdd.x = r; |
| 145 |
mAdd.y = g; |
| 146 |
mAdd.z = b; |
| 147 |
mAdd.w = a; |
| 148 |
|
| 149 |
FieldPacker fp = new FieldPacker(4*4); |
| 150 |
fp.addF32(mAdd.x); |
| 151 |
fp.addF32(mAdd.y); |
| 152 |
fp.addF32(mAdd.z); |
| 153 |
fp.addF32(mAdd.w); |
| 154 |
setVar(1, fp); |
| 155 |
} |
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
public void setGreyscale() { |
| 163 |
mMatrix.loadIdentity(); |
| 164 |
mMatrix.set(0, 0, 0.299f); |
| 165 |
mMatrix.set(1, 0, 0.587f); |
| 166 |
mMatrix.set(2, 0, 0.114f); |
| 167 |
mMatrix.set(0, 1, 0.299f); |
| 168 |
mMatrix.set(1, 1, 0.587f); |
| 169 |
mMatrix.set(2, 1, 0.114f); |
| 170 |
mMatrix.set(0, 2, 0.299f); |
| 171 |
mMatrix.set(1, 2, 0.587f); |
| 172 |
mMatrix.set(2, 2, 0.114f); |
| 173 |
setMatrix(); |
| 174 |
} |
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
public void setYUVtoRGB() { |
| 182 |
mMatrix.loadIdentity(); |
| 183 |
mMatrix.set(0, 0, 1.f); |
| 184 |
mMatrix.set(1, 0, 0.f); |
| 185 |
mMatrix.set(2, 0, 1.13983f); |
| 186 |
mMatrix.set(0, 1, 1.f); |
| 187 |
mMatrix.set(1, 1, -0.39465f); |
| 188 |
mMatrix.set(2, 1, -0.5806f); |
| 189 |
mMatrix.set(0, 2, 1.f); |
| 190 |
mMatrix.set(1, 2, 2.03211f); |
| 191 |
mMatrix.set(2, 2, 0.f); |
| 192 |
setMatrix(); |
| 193 |
} |
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
public void setRGBtoYUV() { |
| 201 |
mMatrix.loadIdentity(); |
| 202 |
mMatrix.set(0, 0, 0.299f); |
| 203 |
mMatrix.set(1, 0, 0.587f); |
| 204 |
mMatrix.set(2, 0, 0.114f); |
| 205 |
mMatrix.set(0, 1, -0.14713f); |
| 206 |
mMatrix.set(1, 1, -0.28886f); |
| 207 |
mMatrix.set(2, 1, 0.436f); |
| 208 |
mMatrix.set(0, 2, 0.615f); |
| 209 |
mMatrix.set(1, 2, -0.51499f); |
| 210 |
mMatrix.set(2, 2, -0.10001f); |
| 211 |
setMatrix(); |
| 212 |
} |
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
public void forEach(Allocation ain, Allocation aout) { |
| 230 |
forEach(ain, aout, null); |
| 231 |
} |
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
public void forEach(Allocation ain, Allocation aout, Script.LaunchOptions opt) { |
| 250 |
if (!ain.getElement().isCompatible(Element.U8(mRS)) && |
| 251 |
!ain.getElement().isCompatible(Element.U8_2(mRS)) && |
| 252 |
!ain.getElement().isCompatible(Element.U8_3(mRS)) && |
| 253 |
!ain.getElement().isCompatible(Element.U8_4(mRS)) && |
| 254 |
!ain.getElement().isCompatible(Element.F32(mRS)) && |
| 255 |
!ain.getElement().isCompatible(Element.F32_2(mRS)) && |
| 256 |
!ain.getElement().isCompatible(Element.F32_3(mRS)) && |
| 257 |
!ain.getElement().isCompatible(Element.F32_4(mRS))) { |
| 258 |
|
| 259 |
throw new RSIllegalArgumentException("Unsupported element type."); |
| 260 |
} |
| 261 |
|
| 262 |
if (!aout.getElement().isCompatible(Element.U8(mRS)) && |
| 263 |
!aout.getElement().isCompatible(Element.U8_2(mRS)) && |
| 264 |
!aout.getElement().isCompatible(Element.U8_3(mRS)) && |
| 265 |
!aout.getElement().isCompatible(Element.U8_4(mRS)) && |
| 266 |
!aout.getElement().isCompatible(Element.F32(mRS)) && |
| 267 |
!aout.getElement().isCompatible(Element.F32_2(mRS)) && |
| 268 |
!aout.getElement().isCompatible(Element.F32_3(mRS)) && |
| 269 |
!aout.getElement().isCompatible(Element.F32_4(mRS))) { |
| 270 |
|
| 271 |
throw new RSIllegalArgumentException("Unsupported element type."); |
| 272 |
} |
| 273 |
|
| 274 |
forEach(0, ain, aout, null, opt); |
| 275 |
} |
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
public Script.KernelID getKernelID() { |
| 283 |
return createKernelID(0, 3, null, null); |
| 284 |
} |
| 285 |
|
| 286 |
} |
| 287 |
|