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