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