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 17package android.support.v8.renderscript; 18 19 20/** 21 * Intrinsic kernels for blending two 22 * {@link android.support.v8.renderscript.Allocation} objects. 23 **/ 24public class ScriptIntrinsicBlend extends ScriptIntrinsic { 25 ScriptIntrinsicBlend(int id, RenderScript rs) { 26 super(id, rs); 27 } 28 29 /** 30 * Supported elements types are {@link Element#U8_4} 31 * 32 * @param rs The RenderScript context 33 * @param e Element type for inputs and outputs 34 * 35 * @return ScriptIntrinsicBlend 36 */ 37 public static ScriptIntrinsicBlend create(RenderScript rs, Element e) { 38 if (rs.isNative) { 39 RenderScriptThunker rst = (RenderScriptThunker) rs; 40 return ScriptIntrinsicBlendThunker.create(rs, e); 41 } 42 // 7 comes from RS_SCRIPT_INTRINSIC_ID_BLEND in rsDefines.h 43 int id = rs.nScriptIntrinsicCreate(7, e.getID(rs)); 44 return new ScriptIntrinsicBlend(id, rs); 45 46 } 47 48 private void blend(int id, Allocation ain, Allocation aout) { 49 if (!ain.getElement().isCompatible(Element.U8_4(mRS))) { 50 throw new RSIllegalArgumentException("Input is not of expected format."); 51 } 52 if (!aout.getElement().isCompatible(Element.U8_4(mRS))) { 53 throw new RSIllegalArgumentException("Output is not of expected format."); 54 } 55 forEach(id, ain, aout, null); 56 } 57 58 /** 59 * Sets dst = {0, 0, 0, 0} 60 * 61 * @param ain The source buffer 62 * @param aout The destination buffer 63 */ 64 public void forEachClear(Allocation ain, Allocation aout) { 65 blend(0, ain, aout); 66 } 67 68 /** 69 * Get a KernelID for the Clear kernel. 70 * 71 * @return Script.KernelID The KernelID object. 72 */ 73 public Script.KernelID getKernelIDClear() { 74 return createKernelID(0, 3, null, null); 75 } 76 77 78 /** 79 * Sets dst = src 80 * 81 * @param ain The source buffer 82 * @param aout The destination buffer 83 */ 84 public void forEachSrc(Allocation ain, Allocation aout) { 85 blend(1, ain, aout); 86 } 87 88 /** 89 * Get a KernelID for the Src kernel. 90 * 91 * @return Script.KernelID The KernelID object. 92 */ 93 public Script.KernelID getKernelIDSrc() { 94 return createKernelID(1, 3, null, null); 95 } 96 97 /** 98 * Sets dst = dst 99 * 100 * This is a NOP. 101 * 102 * @param ain The source buffer 103 * @param aout The destination buffer 104 */ 105 public void forEachDst(Allocation ain, Allocation aout) { 106 // NOP 107 } 108 109 /** 110 * Get a KernelID for the Dst kernel. 111 * 112 * @return Script.KernelID The KernelID object. 113 */ 114 public Script.KernelID getKernelIDDst() { 115 return createKernelID(2, 3, null, null); 116 } 117 118 /** 119 * Sets dst = src + dst * (1.0 - src.a) 120 * 121 * @param ain The source buffer 122 * @param aout The destination buffer 123 */ 124 public void forEachSrcOver(Allocation ain, Allocation aout) { 125 blend(3, ain, aout); 126 } 127 128 /** 129 * Get a KernelID for the SrcOver kernel. 130 * 131 * @return Script.KernelID The KernelID object. 132 */ 133 public Script.KernelID getKernelIDSrcOver() { 134 return createKernelID(3, 3, null, null); 135 } 136 137 /** 138 * Sets dst = dst + src * (1.0 - dst.a) 139 * 140 * @param ain The source buffer 141 * @param aout The destination buffer 142 */ 143 public void forEachDstOver(Allocation ain, Allocation aout) { 144 blend(4, ain, aout); 145 } 146 147 /** 148 * Get a KernelID for the DstOver kernel. 149 * 150 * @return Script.KernelID The KernelID object. 151 */ 152 public Script.KernelID getKernelIDDstOver() { 153 return createKernelID(4, 3, null, null); 154 } 155 156 /** 157 * Sets dst = src * dst.a 158 * 159 * @param ain The source buffer 160 * @param aout The destination buffer 161 */ 162 public void forEachSrcIn(Allocation ain, Allocation aout) { 163 blend(5, ain, aout); 164 } 165 166 /** 167 * Get a KernelID for the SrcIn kernel. 168 * 169 * @return Script.KernelID The KernelID object. 170 */ 171 public Script.KernelID getKernelIDSrcIn() { 172 return createKernelID(5, 3, null, null); 173 } 174 175 /** 176 * Sets dst = dst * src.a 177 * 178 * @param ain The source buffer 179 * @param aout The destination buffer 180 */ 181 public void forEachDstIn(Allocation ain, Allocation aout) { 182 blend(6, ain, aout); 183 } 184 185 /** 186 * Get a KernelID for the DstIn kernel. 187 * 188 * @return Script.KernelID The KernelID object. 189 */ 190 public Script.KernelID getKernelIDDstIn() { 191 return createKernelID(6, 3, null, null); 192 } 193 194 /** 195 * Sets dst = src * (1.0 - dst.a) 196 * 197 * @param ain The source buffer 198 * @param aout The destination buffer 199 */ 200 public void forEachSrcOut(Allocation ain, Allocation aout) { 201 blend(7, ain, aout); 202 } 203 204 /** 205 * Get a KernelID for the SrcOut kernel. 206 * 207 * @return Script.KernelID The KernelID object. 208 */ 209 public Script.KernelID getKernelIDSrcOut() { 210 return createKernelID(7, 3, null, null); 211 } 212 213 /** 214 * Sets dst = dst * (1.0 - src.a) 215 * 216 * @param ain The source buffer 217 * @param aout The destination buffer 218 */ 219 public void forEachDstOut(Allocation ain, Allocation aout) { 220 blend(8, ain, aout); 221 } 222 223 /** 224 * Get a KernelID for the DstOut kernel. 225 * 226 * @return Script.KernelID The KernelID object. 227 */ 228 public Script.KernelID getKernelIDDstOut() { 229 return createKernelID(8, 3, null, null); 230 } 231 232 /** 233 * dst.rgb = src.rgb * dst.a + (1.0 - src.a) * dst.rgb 234 * dst.a = dst.a 235 * 236 * @param ain The source buffer 237 * @param aout The destination buffer 238 */ 239 public void forEachSrcAtop(Allocation ain, Allocation aout) { 240 blend(9, ain, aout); 241 } 242 243 /** 244 * Get a KernelID for the SrcAtop kernel. 245 * 246 * @return Script.KernelID The KernelID object. 247 */ 248 public Script.KernelID getKernelIDSrcAtop() { 249 return createKernelID(9, 3, null, null); 250 } 251 252 /** 253 * dst = dst.rgb * src.a + (1.0 - dst.a) * src.rgb 254 * dst.a = src.a 255 * 256 * @param ain The source buffer 257 * @param aout The destination buffer 258 */ 259 public void forEachDstAtop(Allocation ain, Allocation aout) { 260 blend(10, ain, aout); 261 } 262 263 /** 264 * Get a KernelID for the DstAtop kernel. 265 * 266 * @return Script.KernelID The KernelID object. 267 */ 268 public Script.KernelID getKernelIDDstAtop() { 269 return createKernelID(10, 3, null, null); 270 } 271 272 /** 273 * Sets dst = {src.r ^ dst.r, src.g ^ dst.g, src.b ^ dst.b, src.a ^ dst.a} 274 * 275 * @param ain The source buffer 276 * @param aout The destination buffer 277 */ 278 public void forEachXor(Allocation ain, Allocation aout) { 279 blend(11, ain, aout); 280 } 281 282 /** 283 * Get a KernelID for the Xor kernel. 284 * 285 * @return Script.KernelID The KernelID object. 286 */ 287 public Script.KernelID getKernelIDXor() { 288 return createKernelID(11, 3, null, null); 289 } 290 291 //////// 292/* 293 public void forEachNormal(Allocation ain, Allocation aout) { 294 blend(12, ain, aout); 295 } 296 297 public void forEachAverage(Allocation ain, Allocation aout) { 298 blend(13, ain, aout); 299 } 300*/ 301 /** 302 * Sets dst = src * dst 303 * 304 * @param ain The source buffer 305 * @param aout The destination buffer 306 */ 307 public void forEachMultiply(Allocation ain, Allocation aout) { 308 blend(14, ain, aout); 309 } 310 311 /** 312 * Get a KernelID for the Multiply kernel. 313 * 314 * @return Script.KernelID The KernelID object. 315 */ 316 public Script.KernelID getKernelIDMultiply() { 317 return createKernelID(14, 3, null, null); 318 } 319 320/* 321 public void forEachScreen(Allocation ain, Allocation aout) { 322 blend(15, ain, aout); 323 } 324 325 public void forEachDarken(Allocation ain, Allocation aout) { 326 blend(16, ain, aout); 327 } 328 329 public void forEachLighten(Allocation ain, Allocation aout) { 330 blend(17, ain, aout); 331 } 332 333 public void forEachOverlay(Allocation ain, Allocation aout) { 334 blend(18, ain, aout); 335 } 336 337 public void forEachHardlight(Allocation ain, Allocation aout) { 338 blend(19, ain, aout); 339 } 340 341 public void forEachSoftlight(Allocation ain, Allocation aout) { 342 blend(20, ain, aout); 343 } 344 345 public void forEachDifference(Allocation ain, Allocation aout) { 346 blend(21, ain, aout); 347 } 348 349 public void forEachNegation(Allocation ain, Allocation aout) { 350 blend(22, ain, aout); 351 } 352 353 public void forEachExclusion(Allocation ain, Allocation aout) { 354 blend(23, ain, aout); 355 } 356 357 public void forEachColorDodge(Allocation ain, Allocation aout) { 358 blend(24, ain, aout); 359 } 360 361 public void forEachInverseColorDodge(Allocation ain, Allocation aout) { 362 blend(25, ain, aout); 363 } 364 365 public void forEachSoftDodge(Allocation ain, Allocation aout) { 366 blend(26, ain, aout); 367 } 368 369 public void forEachColorBurn(Allocation ain, Allocation aout) { 370 blend(27, ain, aout); 371 } 372 373 public void forEachInverseColorBurn(Allocation ain, Allocation aout) { 374 blend(28, ain, aout); 375 } 376 377 public void forEachSoftBurn(Allocation ain, Allocation aout) { 378 blend(29, ain, aout); 379 } 380 381 public void forEachReflect(Allocation ain, Allocation aout) { 382 blend(30, ain, aout); 383 } 384 385 public void forEachGlow(Allocation ain, Allocation aout) { 386 blend(31, ain, aout); 387 } 388 389 public void forEachFreeze(Allocation ain, Allocation aout) { 390 blend(32, ain, aout); 391 } 392 393 public void forEachHeat(Allocation ain, Allocation aout) { 394 blend(33, ain, aout); 395 } 396*/ 397 /** 398 * Sets dst = min(src + dst, 1.0) 399 * 400 * @param ain The source buffer 401 * @param aout The destination buffer 402 */ 403 public void forEachAdd(Allocation ain, Allocation aout) { 404 blend(34, ain, aout); 405 } 406 407 /** 408 * Get a KernelID for the Add kernel. 409 * 410 * @return Script.KernelID The KernelID object. 411 */ 412 public Script.KernelID getKernelIDAdd() { 413 return createKernelID(34, 3, null, null); 414 } 415 416 /** 417 * Sets dst = max(dst - src, 0.0) 418 * 419 * @param ain The source buffer 420 * @param aout The destination buffer 421 */ 422 public void forEachSubtract(Allocation ain, Allocation aout) { 423 blend(35, ain, aout); 424 } 425 426 /** 427 * Get a KernelID for the Subtract kernel. 428 * 429 * @return Script.KernelID The KernelID object. 430 */ 431 public Script.KernelID getKernelIDSubtract() { 432 return createKernelID(35, 3, null, null); 433 } 434 435/* 436 public void forEachStamp(Allocation ain, Allocation aout) { 437 blend(36, ain, aout); 438 } 439 440 public void forEachRed(Allocation ain, Allocation aout) { 441 blend(37, ain, aout); 442 } 443 444 public void forEachGreen(Allocation ain, Allocation aout) { 445 blend(38, ain, aout); 446 } 447 448 public void forEachBlue(Allocation ain, Allocation aout) { 449 blend(39, ain, aout); 450 } 451 452 public void forEachHue(Allocation ain, Allocation aout) { 453 blend(40, ain, aout); 454 } 455 456 public void forEachSaturation(Allocation ain, Allocation aout) { 457 blend(41, ain, aout); 458 } 459 460 public void forEachColor(Allocation ain, Allocation aout) { 461 blend(42, ain, aout); 462 } 463 464 public void forEachLuminosity(Allocation ain, Allocation aout) { 465 blend(43, ain, aout); 466 } 467*/ 468} 469 470