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