blob: fdcd61b04ecab47a5fa93e89d46bf1d4d0fac824 [file] [log] [blame]
Jason Samsf70bb042012-09-21 16:10:49 -07001/*
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/**
Tim Murrayc11e25c2013-04-09 11:01:01 -070021 * Intrinsic kernels for blending two {@link android.renderscript.Allocation} objects.
Jason Samsf70bb042012-09-21 16:10:49 -070022 **/
23public class ScriptIntrinsicBlend extends ScriptIntrinsic {
Tim Murray460a0492013-11-19 12:45:54 -080024 ScriptIntrinsicBlend(long id, RenderScript rs) {
Jason Samsf70bb042012-09-21 16:10:49 -070025 super(id, rs);
26 }
27
28 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -070029 * Supported elements types are {@link Element#U8_4}
Jason Samsf70bb042012-09-21 16:10:49 -070030 *
Tim Murrayc11e25c2013-04-09 11:01:01 -070031 * @param rs The RenderScript context
32 * @param e Element type for inputs and outputs
Jason Samsf70bb042012-09-21 16:10:49 -070033 *
34 * @return ScriptIntrinsicBlend
35 */
36 public static ScriptIntrinsicBlend create(RenderScript rs, Element e) {
Tim Murray74478f72012-09-26 13:46:46 -070037 // 7 comes from RS_SCRIPT_INTRINSIC_ID_BLEND in rsDefines.h
Tim Murray460a0492013-11-19 12:45:54 -080038 long id = rs.nScriptIntrinsicCreate(7, e.getID(rs));
Jason Samsf70bb042012-09-21 16:10:49 -070039 return new ScriptIntrinsicBlend(id, rs);
40
41 }
42
Tim Murray6f842ac2014-01-13 11:47:53 -080043 private void blend(int id, Allocation ain, Allocation aout, Script.LaunchOptions opt) {
Tim Murray74478f72012-09-26 13:46:46 -070044 if (!ain.getElement().isCompatible(Element.U8_4(mRS))) {
45 throw new RSIllegalArgumentException("Input is not of expected format.");
Jason Samsf70bb042012-09-21 16:10:49 -070046 }
Tim Murray74478f72012-09-26 13:46:46 -070047 if (!aout.getElement().isCompatible(Element.U8_4(mRS))) {
48 throw new RSIllegalArgumentException("Output is not of expected format.");
Jason Samsf70bb042012-09-21 16:10:49 -070049 }
Tim Murray6f842ac2014-01-13 11:47:53 -080050 forEach(id, ain, aout, null, opt);
Jason Samsf70bb042012-09-21 16:10:49 -070051 }
52
53 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -070054 * Sets dst = {0, 0, 0, 0}
Jason Samsf70bb042012-09-21 16:10:49 -070055 *
56 * @param ain The source buffer
57 * @param aout The destination buffer
58 */
59 public void forEachClear(Allocation ain, Allocation aout) {
Tim Murray6f842ac2014-01-13 11:47:53 -080060 forEachClear(ain, aout, null);
61 }
62
63 /**
64 * Sets dst = {0, 0, 0, 0}
65 *
66 * @param ain The source buffer
67 * @param aout The destination buffer
68 * @param opt LaunchOptions for clipping
69 */
70 public void forEachClear(Allocation ain, Allocation aout, Script.LaunchOptions opt) {
71 blend(0, ain, aout, opt);
Jason Samsf70bb042012-09-21 16:10:49 -070072 }
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 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -070085 * Sets dst = src
Jason Samsf70bb042012-09-21 16:10:49 -070086 *
87 * @param ain The source buffer
88 * @param aout The destination buffer
89 */
90 public void forEachSrc(Allocation ain, Allocation aout) {
Tim Murray6f842ac2014-01-13 11:47:53 -080091 forEachSrc(ain, aout, null);
92 }
93
94 /**
95 * Sets dst = src
96 *
97 * @param ain The source buffer
98 * @param aout The destination buffer
99 * @param opt LaunchOptions for clipping
100 */
101 public void forEachSrc(Allocation ain, Allocation aout, Script.LaunchOptions opt) {
Tim Murray8fdcf4a2014-07-10 13:00:10 -0700102 blend(1, ain, aout, null);
Jason Samsf70bb042012-09-21 16:10:49 -0700103 }
104
105 /**
106 * Get a KernelID for the Src kernel.
107 *
108 * @return Script.KernelID The KernelID object.
109 */
110 public Script.KernelID getKernelIDSrc() {
111 return createKernelID(1, 3, null, null);
112 }
113
114 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -0700115 * Sets dst = dst
116 *
117 * This is a NOP.
Jason Samsf70bb042012-09-21 16:10:49 -0700118 *
119 * @param ain The source buffer
120 * @param aout The destination buffer
121 */
122 public void forEachDst(Allocation ain, Allocation aout) {
123 // NOP
124 }
125
126 /**
Tim Murray6f842ac2014-01-13 11:47:53 -0800127 * Sets dst = dst
128 *
129 * This is a NOP.
130 *
131 * @param ain The source buffer
132 * @param aout The destination buffer
133 * @param opt LaunchOptions for clipping
134 */
135 public void forEachDst(Allocation ain, Allocation aout, Script.LaunchOptions opt) {
136 // N, optOP
137 }
138
139 /**
Jason Samsf70bb042012-09-21 16:10:49 -0700140 * Get a KernelID for the Dst kernel.
141 *
142 * @return Script.KernelID The KernelID object.
143 */
144 public Script.KernelID getKernelIDDst() {
145 return createKernelID(2, 3, null, null);
146 }
147
148 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -0700149 * Sets dst = src + dst * (1.0 - src.a)
Jason Samsf70bb042012-09-21 16:10:49 -0700150 *
151 * @param ain The source buffer
152 * @param aout The destination buffer
153 */
154 public void forEachSrcOver(Allocation ain, Allocation aout) {
Tim Murray6f842ac2014-01-13 11:47:53 -0800155 forEachSrcOver(ain, aout, null);
156 }
157
158 /**
159 * Sets dst = src + dst * (1.0 - src.a)
160 *
161 * @param ain The source buffer
162 * @param aout The destination buffer
163 * @param opt LaunchOptions for clipping
164 */
165 public void forEachSrcOver(Allocation ain, Allocation aout, Script.LaunchOptions opt) {
166 blend(3, ain, aout, opt);
Jason Samsf70bb042012-09-21 16:10:49 -0700167 }
168
169 /**
170 * Get a KernelID for the SrcOver kernel.
171 *
172 * @return Script.KernelID The KernelID object.
173 */
174 public Script.KernelID getKernelIDSrcOver() {
175 return createKernelID(3, 3, null, null);
176 }
177
178 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -0700179 * Sets dst = dst + src * (1.0 - dst.a)
Jason Samsf70bb042012-09-21 16:10:49 -0700180 *
181 * @param ain The source buffer
182 * @param aout The destination buffer
183 */
184 public void forEachDstOver(Allocation ain, Allocation aout) {
Tim Murray6f842ac2014-01-13 11:47:53 -0800185 forEachDstOver(ain, aout, null);
186 }
187
188 /**
189 * Sets dst = dst + src * (1.0 - dst.a)
190 *
191 * @param ain The source buffer
192 * @param aout The destination buffer
193 * @param opt LaunchOptions for clipping
194 */
195 public void forEachDstOver(Allocation ain, Allocation aout, Script.LaunchOptions opt) {
196 blend(4, ain, aout, opt);
Jason Samsf70bb042012-09-21 16:10:49 -0700197 }
198
199 /**
200 * Get a KernelID for the DstOver kernel.
201 *
202 * @return Script.KernelID The KernelID object.
203 */
204 public Script.KernelID getKernelIDDstOver() {
205 return createKernelID(4, 3, null, null);
206 }
207
208 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -0700209 * Sets dst = src * dst.a
Jason Samsf70bb042012-09-21 16:10:49 -0700210 *
211 * @param ain The source buffer
212 * @param aout The destination buffer
213 */
214 public void forEachSrcIn(Allocation ain, Allocation aout) {
Tim Murray6f842ac2014-01-13 11:47:53 -0800215 forEachSrcIn(ain, aout, null);
216 }
217
218 /**
219 * Sets dst = src * dst.a
220 *
221 * @param ain The source buffer
222 * @param aout The destination buffer
223 * @param opt LaunchOptions for clipping
224 */
225 public void forEachSrcIn(Allocation ain, Allocation aout, Script.LaunchOptions opt) {
226 blend(5, ain, aout, opt);
Jason Samsf70bb042012-09-21 16:10:49 -0700227 }
228
229 /**
230 * Get a KernelID for the SrcIn kernel.
231 *
232 * @return Script.KernelID The KernelID object.
233 */
234 public Script.KernelID getKernelIDSrcIn() {
235 return createKernelID(5, 3, null, null);
236 }
237
238 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -0700239 * Sets dst = dst * src.a
Jason Samsf70bb042012-09-21 16:10:49 -0700240 *
241 * @param ain The source buffer
242 * @param aout The destination buffer
243 */
244 public void forEachDstIn(Allocation ain, Allocation aout) {
Tim Murray6f842ac2014-01-13 11:47:53 -0800245 forEachDstIn(ain, aout, null);
246 }
247
248 /**
249 * Sets dst = dst * src.a
250 *
251 * @param ain The source buffer
252 * @param aout The destination buffer
253 * @param opt LaunchOptions for clipping
254 */
255 public void forEachDstIn(Allocation ain, Allocation aout, Script.LaunchOptions opt) {
256 blend(6, ain, aout, opt);
Jason Samsf70bb042012-09-21 16:10:49 -0700257 }
258
259 /**
260 * Get a KernelID for the DstIn kernel.
261 *
262 * @return Script.KernelID The KernelID object.
263 */
264 public Script.KernelID getKernelIDDstIn() {
265 return createKernelID(6, 3, null, null);
266 }
267
268 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -0700269 * Sets dst = src * (1.0 - dst.a)
Jason Samsf70bb042012-09-21 16:10:49 -0700270 *
271 * @param ain The source buffer
272 * @param aout The destination buffer
273 */
274 public void forEachSrcOut(Allocation ain, Allocation aout) {
Tim Murray6f842ac2014-01-13 11:47:53 -0800275 forEachSrcOut(ain, aout, null);
276 }
277
278 /**
279 * Sets dst = src * (1.0 - dst.a)
280 *
281 * @param ain The source buffer
282 * @param aout The destination buffer
283 * @param opt LaunchOptions for clipping
284 */
285 public void forEachSrcOut(Allocation ain, Allocation aout, Script.LaunchOptions opt) {
286 blend(7, ain, aout, opt);
Jason Samsf70bb042012-09-21 16:10:49 -0700287 }
288
289 /**
290 * Get a KernelID for the SrcOut kernel.
291 *
292 * @return Script.KernelID The KernelID object.
293 */
294 public Script.KernelID getKernelIDSrcOut() {
295 return createKernelID(7, 3, null, null);
296 }
297
298 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -0700299 * Sets dst = dst * (1.0 - src.a)
Jason Samsf70bb042012-09-21 16:10:49 -0700300 *
301 * @param ain The source buffer
302 * @param aout The destination buffer
303 */
304 public void forEachDstOut(Allocation ain, Allocation aout) {
Tim Murray6f842ac2014-01-13 11:47:53 -0800305 forEachDstOut(ain, aout, null);
306 }
307
308 /**
309 * Sets dst = dst * (1.0 - src.a)
310 *
311 * @param ain The source buffer
312 * @param aout The destination buffer
313 * @param opt LaunchOptions for clipping
314 */
315 public void forEachDstOut(Allocation ain, Allocation aout, Script.LaunchOptions opt) {
316 blend(8, ain, aout, opt);
Jason Samsf70bb042012-09-21 16:10:49 -0700317 }
318
319 /**
320 * Get a KernelID for the DstOut kernel.
321 *
322 * @return Script.KernelID The KernelID object.
323 */
324 public Script.KernelID getKernelIDDstOut() {
325 return createKernelID(8, 3, null, null);
326 }
327
328 /**
329 * dst.rgb = src.rgb * dst.a + (1.0 - src.a) * dst.rgb
330 * dst.a = dst.a
331 *
332 * @param ain The source buffer
333 * @param aout The destination buffer
334 */
335 public void forEachSrcAtop(Allocation ain, Allocation aout) {
Tim Murray6f842ac2014-01-13 11:47:53 -0800336 forEachSrcAtop(ain, aout, null);
337 }
338
339 /**
340 * dst.rgb = src.rgb * dst.a + (1.0 - src.a) * dst.rgb
341 * dst.a = dst.a
342 *
343 * @param ain The source buffer
344 * @param aout The destination buffer
345 * @param opt LaunchOptions for clipping
346 */
347 public void forEachSrcAtop(Allocation ain, Allocation aout, Script.LaunchOptions opt) {
348 blend(9, ain, aout, opt);
Jason Samsf70bb042012-09-21 16:10:49 -0700349 }
350
351 /**
352 * Get a KernelID for the SrcAtop kernel.
353 *
354 * @return Script.KernelID The KernelID object.
355 */
356 public Script.KernelID getKernelIDSrcAtop() {
357 return createKernelID(9, 3, null, null);
358 }
359
360 /**
361 * dst = dst.rgb * src.a + (1.0 - dst.a) * src.rgb
362 * dst.a = src.a
Miao Wangffb1a9b2015-07-20 15:05:31 -0700363 * Note: Before API 23, the alpha channel was not correctly set.
364 * Please use with caution when targeting older APIs.
Jason Samsf70bb042012-09-21 16:10:49 -0700365 *
366 * @param ain The source buffer
367 * @param aout The destination buffer
368 */
369 public void forEachDstAtop(Allocation ain, Allocation aout) {
Tim Murray6f842ac2014-01-13 11:47:53 -0800370 forEachDstAtop(ain, aout, null);
371 }
372
373 /**
374 * dst = dst.rgb * src.a + (1.0 - dst.a) * src.rgb
375 * dst.a = src.a
Miao Wangffb1a9b2015-07-20 15:05:31 -0700376 * Note: Before API 23, the alpha channel was not correctly set.
377 * Please use with caution when targeting older APIs.
Tim Murray6f842ac2014-01-13 11:47:53 -0800378 *
379 * @param ain The source buffer
380 * @param aout The destination buffer
381 * @param opt LaunchOptions for clipping
382 */
383 public void forEachDstAtop(Allocation ain, Allocation aout, Script.LaunchOptions opt) {
384 blend(10, ain, aout, opt);
Jason Samsf70bb042012-09-21 16:10:49 -0700385 }
386
387 /**
388 * Get a KernelID for the DstAtop kernel.
389 *
390 * @return Script.KernelID The KernelID object.
391 */
392 public Script.KernelID getKernelIDDstAtop() {
393 return createKernelID(10, 3, null, null);
394 }
395
396 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -0700397 * Sets dst = {src.r ^ dst.r, src.g ^ dst.g, src.b ^ dst.b, src.a ^ dst.a}
Jason Samsf70bb042012-09-21 16:10:49 -0700398 *
399 * @param ain The source buffer
400 * @param aout The destination buffer
401 */
402 public void forEachXor(Allocation ain, Allocation aout) {
Tim Murray6f842ac2014-01-13 11:47:53 -0800403 forEachXor(ain, aout, null);
404 }
405
406 /**
407 * Sets dst = {src.r ^ dst.r, src.g ^ dst.g, src.b ^ dst.b, src.a ^ dst.a}
408 *
John Hoford6ba4cb72015-06-29 18:15:22 -0700409 * <b>Note:</b> this is NOT the Porter/Duff XOR mode; this is a bitwise xor.
410 *
Tim Murray6f842ac2014-01-13 11:47:53 -0800411 * @param ain The source buffer
412 * @param aout The destination buffer
413 * @param opt LaunchOptions for clipping
414 */
415 public void forEachXor(Allocation ain, Allocation aout, Script.LaunchOptions opt) {
416 blend(11, ain, aout, opt);
Jason Samsf70bb042012-09-21 16:10:49 -0700417 }
418
419 /**
420 * Get a KernelID for the Xor kernel.
421 *
422 * @return Script.KernelID The KernelID object.
423 */
424 public Script.KernelID getKernelIDXor() {
425 return createKernelID(11, 3, null, null);
426 }
427
428 ////////
429/*
430 public void forEachNormal(Allocation ain, Allocation aout) {
431 blend(12, ain, aout);
432 }
433
434 public void forEachAverage(Allocation ain, Allocation aout) {
435 blend(13, ain, aout);
436 }
437*/
438 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -0700439 * Sets dst = src * dst
Jason Samsf70bb042012-09-21 16:10:49 -0700440 *
441 * @param ain The source buffer
442 * @param aout The destination buffer
443 */
444 public void forEachMultiply(Allocation ain, Allocation aout) {
Tim Murray6f842ac2014-01-13 11:47:53 -0800445 forEachMultiply(ain, aout, null);
446 }
447
448 /**
449 * Sets dst = src * dst
450 *
451 * @param ain The source buffer
452 * @param aout The destination buffer
453 * @param opt LaunchOptions for clipping
454 */
455 public void forEachMultiply(Allocation ain, Allocation aout, Script.LaunchOptions opt) {
456 blend(14, ain, aout, opt);
Jason Samsf70bb042012-09-21 16:10:49 -0700457 }
458
459 /**
460 * Get a KernelID for the Multiply kernel.
461 *
462 * @return Script.KernelID The KernelID object.
463 */
464 public Script.KernelID getKernelIDMultiply() {
465 return createKernelID(14, 3, null, null);
466 }
467
468/*
469 public void forEachScreen(Allocation ain, Allocation aout) {
470 blend(15, ain, aout);
471 }
472
473 public void forEachDarken(Allocation ain, Allocation aout) {
474 blend(16, ain, aout);
475 }
476
477 public void forEachLighten(Allocation ain, Allocation aout) {
478 blend(17, ain, aout);
479 }
480
481 public void forEachOverlay(Allocation ain, Allocation aout) {
482 blend(18, ain, aout);
483 }
484
485 public void forEachHardlight(Allocation ain, Allocation aout) {
486 blend(19, ain, aout);
487 }
488
489 public void forEachSoftlight(Allocation ain, Allocation aout) {
490 blend(20, ain, aout);
491 }
492
493 public void forEachDifference(Allocation ain, Allocation aout) {
494 blend(21, ain, aout);
495 }
496
497 public void forEachNegation(Allocation ain, Allocation aout) {
498 blend(22, ain, aout);
499 }
500
501 public void forEachExclusion(Allocation ain, Allocation aout) {
502 blend(23, ain, aout);
503 }
504
505 public void forEachColorDodge(Allocation ain, Allocation aout) {
506 blend(24, ain, aout);
507 }
508
509 public void forEachInverseColorDodge(Allocation ain, Allocation aout) {
510 blend(25, ain, aout);
511 }
512
513 public void forEachSoftDodge(Allocation ain, Allocation aout) {
514 blend(26, ain, aout);
515 }
516
517 public void forEachColorBurn(Allocation ain, Allocation aout) {
518 blend(27, ain, aout);
519 }
520
521 public void forEachInverseColorBurn(Allocation ain, Allocation aout) {
522 blend(28, ain, aout);
523 }
524
525 public void forEachSoftBurn(Allocation ain, Allocation aout) {
526 blend(29, ain, aout);
527 }
528
529 public void forEachReflect(Allocation ain, Allocation aout) {
530 blend(30, ain, aout);
531 }
532
533 public void forEachGlow(Allocation ain, Allocation aout) {
534 blend(31, ain, aout);
535 }
536
537 public void forEachFreeze(Allocation ain, Allocation aout) {
538 blend(32, ain, aout);
539 }
540
541 public void forEachHeat(Allocation ain, Allocation aout) {
542 blend(33, ain, aout);
543 }
544*/
545 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -0700546 * Sets dst = min(src + dst, 1.0)
Jason Samsf70bb042012-09-21 16:10:49 -0700547 *
548 * @param ain The source buffer
549 * @param aout The destination buffer
550 */
551 public void forEachAdd(Allocation ain, Allocation aout) {
Tim Murray6f842ac2014-01-13 11:47:53 -0800552 forEachAdd(ain, aout, null);
553 }
554
555 /**
556 * Sets dst = min(src + dst, 1.0)
557 *
558 * @param ain The source buffer
559 * @param aout The destination buffer
560 * @param opt LaunchOptions for clipping
561 */
562 public void forEachAdd(Allocation ain, Allocation aout, Script.LaunchOptions opt) {
563 blend(34, ain, aout, opt);
Jason Samsf70bb042012-09-21 16:10:49 -0700564 }
565
566 /**
567 * Get a KernelID for the Add kernel.
568 *
569 * @return Script.KernelID The KernelID object.
570 */
571 public Script.KernelID getKernelIDAdd() {
572 return createKernelID(34, 3, null, null);
573 }
574
575 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -0700576 * Sets dst = max(dst - src, 0.0)
Jason Samsf70bb042012-09-21 16:10:49 -0700577 *
578 * @param ain The source buffer
579 * @param aout The destination buffer
580 */
581 public void forEachSubtract(Allocation ain, Allocation aout) {
Tim Murray6f842ac2014-01-13 11:47:53 -0800582 forEachSubtract(ain, aout, null);
583 }
584
585 /**
586 * Sets dst = max(dst - src, 0.0)
587 *
588 * @param ain The source buffer
589 * @param aout The destination buffer
590 * @param opt LaunchOptions for clipping
591 */
592 public void forEachSubtract(Allocation ain, Allocation aout, Script.LaunchOptions opt) {
593 blend(35, ain, aout, opt);
Jason Samsf70bb042012-09-21 16:10:49 -0700594 }
595
596 /**
597 * Get a KernelID for the Subtract kernel.
598 *
599 * @return Script.KernelID The KernelID object.
600 */
601 public Script.KernelID getKernelIDSubtract() {
602 return createKernelID(35, 3, null, null);
603 }
604
605/*
606 public void forEachStamp(Allocation ain, Allocation aout) {
607 blend(36, ain, aout);
608 }
609
610 public void forEachRed(Allocation ain, Allocation aout) {
611 blend(37, ain, aout);
612 }
613
614 public void forEachGreen(Allocation ain, Allocation aout) {
615 blend(38, ain, aout);
616 }
617
618 public void forEachBlue(Allocation ain, Allocation aout) {
619 blend(39, ain, aout);
620 }
621
622 public void forEachHue(Allocation ain, Allocation aout) {
623 blend(40, ain, aout);
624 }
625
626 public void forEachSaturation(Allocation ain, Allocation aout) {
627 blend(41, ain, aout);
628 }
629
630 public void forEachColor(Allocation ain, Allocation aout) {
631 blend(42, ain, aout);
632 }
633
634 public void forEachLuminosity(Allocation ain, Allocation aout) {
635 blend(43, ain, aout);
636 }
637*/
638}
639