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