• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 /**
21  * Intrinsic kernels for blending two {@link android.renderscript.Allocation} objects.
22  *
23  * @deprecated Renderscript has been deprecated in API level 31. Please refer to the <a
24  * href="https://developer.android.com/guide/topics/renderscript/migration-guide">migration
25  * guide</a> for the proposed alternatives.
26  **/
27 @Deprecated
28 public class ScriptIntrinsicBlend extends ScriptIntrinsic {
ScriptIntrinsicBlend(long id, RenderScript rs)29     ScriptIntrinsicBlend(long id, RenderScript rs) {
30         super(id, rs);
31     }
32 
33     /**
34      * Supported elements types are {@link Element#U8_4}
35      *
36      * @param rs The RenderScript context
37      * @param e Element type for inputs and outputs
38      *
39      * @return ScriptIntrinsicBlend
40      */
create(RenderScript rs, Element e)41     public static ScriptIntrinsicBlend create(RenderScript rs, Element e) {
42         // 7 comes from RS_SCRIPT_INTRINSIC_ID_BLEND in rsDefines.h
43         long id = rs.nScriptIntrinsicCreate(7, e.getID(rs));
44         return new ScriptIntrinsicBlend(id, rs);
45 
46     }
47 
blend(int id, Allocation ain, Allocation aout, Script.LaunchOptions opt)48     private void blend(int id, Allocation ain, Allocation aout, Script.LaunchOptions opt) {
49         if (!ain.getElement().isCompatible(Element.U8_4(mRS))) {
50             throw new RSIllegalArgumentException("Input is not of expected format.");
51         }
52         if (!aout.getElement().isCompatible(Element.U8_4(mRS))) {
53             throw new RSIllegalArgumentException("Output is not of expected format.");
54         }
55         forEach(id, ain, aout, null, opt);
56     }
57 
58     /**
59      * Sets dst = {0, 0, 0, 0}
60      *
61      * @param ain The source buffer
62      * @param aout The destination buffer
63      */
forEachClear(Allocation ain, Allocation aout)64     public void forEachClear(Allocation ain, Allocation aout) {
65         forEachClear(ain, aout, null);
66     }
67 
68     /**
69      * Sets dst = {0, 0, 0, 0}
70      *
71      * @param ain The source buffer
72      * @param aout The destination buffer
73      * @param opt LaunchOptions for clipping
74      */
forEachClear(Allocation ain, Allocation aout, Script.LaunchOptions opt)75     public void forEachClear(Allocation ain, Allocation aout, Script.LaunchOptions opt) {
76         blend(0, ain, aout, opt);
77     }
78 
79     /**
80      * Get a KernelID for the Clear kernel.
81      *
82      * @return Script.KernelID The KernelID object.
83      */
getKernelIDClear()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      */
forEachSrc(Allocation ain, Allocation aout)95     public void forEachSrc(Allocation ain, Allocation aout) {
96         forEachSrc(ain, aout, null);
97     }
98 
99     /**
100      * Sets dst = src
101      *
102      * @param ain The source buffer
103      * @param aout The destination buffer
104      * @param opt LaunchOptions for clipping
105      */
forEachSrc(Allocation ain, Allocation aout, Script.LaunchOptions opt)106     public void forEachSrc(Allocation ain, Allocation aout, Script.LaunchOptions opt) {
107         blend(1, ain, aout, null);
108     }
109 
110     /**
111      * Get a KernelID for the Src kernel.
112      *
113      * @return Script.KernelID The KernelID object.
114      */
getKernelIDSrc()115     public Script.KernelID getKernelIDSrc() {
116         return createKernelID(1, 3, null, null);
117     }
118 
119     /**
120      * Sets dst = dst
121      *
122      * This is a NOP.
123      *
124      * @param ain The source buffer
125      * @param aout The destination buffer
126      */
forEachDst(Allocation ain, Allocation aout)127     public void forEachDst(Allocation ain, Allocation aout) {
128         // NOP
129     }
130 
131     /**
132      * Sets dst = dst
133      *
134      * This is a NOP.
135      *
136      * @param ain The source buffer
137      * @param aout The destination buffer
138      * @param opt LaunchOptions for clipping
139      */
forEachDst(Allocation ain, Allocation aout, Script.LaunchOptions opt)140     public void forEachDst(Allocation ain, Allocation aout, Script.LaunchOptions opt) {
141         // N, optOP
142     }
143 
144     /**
145      * Get a KernelID for the Dst kernel.
146      *
147      * @return Script.KernelID The KernelID object.
148      */
getKernelIDDst()149     public Script.KernelID getKernelIDDst() {
150         return createKernelID(2, 3, null, null);
151     }
152 
153     /**
154      * Sets dst = src + dst * (1.0 - src.a)
155      *
156      * @param ain The source buffer
157      * @param aout The destination buffer
158      */
forEachSrcOver(Allocation ain, Allocation aout)159     public void forEachSrcOver(Allocation ain, Allocation aout) {
160         forEachSrcOver(ain, aout, null);
161     }
162 
163     /**
164      * Sets dst = src + dst * (1.0 - src.a)
165      *
166      * @param ain The source buffer
167      * @param aout The destination buffer
168      * @param opt LaunchOptions for clipping
169      */
forEachSrcOver(Allocation ain, Allocation aout, Script.LaunchOptions opt)170     public void forEachSrcOver(Allocation ain, Allocation aout, Script.LaunchOptions opt) {
171         blend(3, ain, aout, opt);
172     }
173 
174     /**
175      * Get a KernelID for the SrcOver kernel.
176      *
177      * @return Script.KernelID The KernelID object.
178      */
getKernelIDSrcOver()179     public Script.KernelID getKernelIDSrcOver() {
180         return createKernelID(3, 3, null, null);
181     }
182 
183     /**
184      * Sets dst = dst + src * (1.0 - dst.a)
185      *
186      * @param ain The source buffer
187      * @param aout The destination buffer
188      */
forEachDstOver(Allocation ain, Allocation aout)189     public void forEachDstOver(Allocation ain, Allocation aout) {
190         forEachDstOver(ain, aout, null);
191     }
192 
193     /**
194      * Sets dst = dst + src * (1.0 - dst.a)
195      *
196      * @param ain The source buffer
197      * @param aout The destination buffer
198      * @param opt LaunchOptions for clipping
199      */
forEachDstOver(Allocation ain, Allocation aout, Script.LaunchOptions opt)200     public void forEachDstOver(Allocation ain, Allocation aout, Script.LaunchOptions opt) {
201         blend(4, ain, aout, opt);
202     }
203 
204     /**
205      * Get a KernelID for the DstOver kernel.
206      *
207      * @return Script.KernelID The KernelID object.
208      */
getKernelIDDstOver()209     public Script.KernelID getKernelIDDstOver() {
210         return createKernelID(4, 3, null, null);
211     }
212 
213     /**
214      * Sets dst = src * dst.a
215      *
216      * @param ain The source buffer
217      * @param aout The destination buffer
218      */
forEachSrcIn(Allocation ain, Allocation aout)219     public void forEachSrcIn(Allocation ain, Allocation aout) {
220         forEachSrcIn(ain, aout, null);
221     }
222 
223     /**
224      * Sets dst = src * dst.a
225      *
226      * @param ain The source buffer
227      * @param aout The destination buffer
228      * @param opt LaunchOptions for clipping
229      */
forEachSrcIn(Allocation ain, Allocation aout, Script.LaunchOptions opt)230     public void forEachSrcIn(Allocation ain, Allocation aout, Script.LaunchOptions opt) {
231         blend(5, ain, aout, opt);
232     }
233 
234     /**
235      * Get a KernelID for the SrcIn kernel.
236      *
237      * @return Script.KernelID The KernelID object.
238      */
getKernelIDSrcIn()239     public Script.KernelID getKernelIDSrcIn() {
240         return createKernelID(5, 3, null, null);
241     }
242 
243     /**
244      * Sets dst = dst * src.a
245      *
246      * @param ain The source buffer
247      * @param aout The destination buffer
248      */
forEachDstIn(Allocation ain, Allocation aout)249     public void forEachDstIn(Allocation ain, Allocation aout) {
250         forEachDstIn(ain, aout, null);
251     }
252 
253     /**
254      * Sets dst = dst * src.a
255      *
256      * @param ain The source buffer
257      * @param aout The destination buffer
258      * @param opt LaunchOptions for clipping
259      */
forEachDstIn(Allocation ain, Allocation aout, Script.LaunchOptions opt)260     public void forEachDstIn(Allocation ain, Allocation aout, Script.LaunchOptions opt) {
261         blend(6, ain, aout, opt);
262     }
263 
264     /**
265      * Get a KernelID for the DstIn kernel.
266      *
267      * @return Script.KernelID The KernelID object.
268      */
getKernelIDDstIn()269     public Script.KernelID getKernelIDDstIn() {
270         return createKernelID(6, 3, null, null);
271     }
272 
273     /**
274      * Sets dst = src * (1.0 - dst.a)
275      *
276      * @param ain The source buffer
277      * @param aout The destination buffer
278      */
forEachSrcOut(Allocation ain, Allocation aout)279     public void forEachSrcOut(Allocation ain, Allocation aout) {
280         forEachSrcOut(ain, aout, null);
281     }
282 
283     /**
284      * Sets dst = src * (1.0 - dst.a)
285      *
286      * @param ain The source buffer
287      * @param aout The destination buffer
288      * @param opt LaunchOptions for clipping
289      */
forEachSrcOut(Allocation ain, Allocation aout, Script.LaunchOptions opt)290     public void forEachSrcOut(Allocation ain, Allocation aout, Script.LaunchOptions opt) {
291         blend(7, ain, aout, opt);
292     }
293 
294     /**
295      * Get a KernelID for the SrcOut kernel.
296      *
297      * @return Script.KernelID The KernelID object.
298      */
getKernelIDSrcOut()299     public Script.KernelID getKernelIDSrcOut() {
300         return createKernelID(7, 3, null, null);
301     }
302 
303     /**
304      * Sets dst = dst * (1.0 - src.a)
305      *
306      * @param ain The source buffer
307      * @param aout The destination buffer
308      */
forEachDstOut(Allocation ain, Allocation aout)309     public void forEachDstOut(Allocation ain, Allocation aout) {
310         forEachDstOut(ain, aout, null);
311     }
312 
313     /**
314      * Sets dst = dst * (1.0 - src.a)
315      *
316      * @param ain The source buffer
317      * @param aout The destination buffer
318      * @param opt LaunchOptions for clipping
319      */
forEachDstOut(Allocation ain, Allocation aout, Script.LaunchOptions opt)320     public void forEachDstOut(Allocation ain, Allocation aout, Script.LaunchOptions opt) {
321         blend(8, ain, aout, opt);
322     }
323 
324     /**
325      * Get a KernelID for the DstOut kernel.
326      *
327      * @return Script.KernelID The KernelID object.
328      */
getKernelIDDstOut()329     public Script.KernelID getKernelIDDstOut() {
330         return createKernelID(8, 3, null, null);
331     }
332 
333     /**
334      * dst.rgb = src.rgb * dst.a + (1.0 - src.a) * dst.rgb
335      * dst.a = dst.a
336      *
337      * @param ain The source buffer
338      * @param aout The destination buffer
339      */
forEachSrcAtop(Allocation ain, Allocation aout)340     public void forEachSrcAtop(Allocation ain, Allocation aout) {
341         forEachSrcAtop(ain, aout, null);
342     }
343 
344     /**
345      * dst.rgb = src.rgb * dst.a + (1.0 - src.a) * dst.rgb
346      * dst.a = dst.a
347      *
348      * @param ain The source buffer
349      * @param aout The destination buffer
350      * @param opt LaunchOptions for clipping
351      */
forEachSrcAtop(Allocation ain, Allocation aout, Script.LaunchOptions opt)352     public void forEachSrcAtop(Allocation ain, Allocation aout, Script.LaunchOptions opt) {
353         blend(9, ain, aout, opt);
354     }
355 
356     /**
357      * Get a KernelID for the SrcAtop kernel.
358      *
359      * @return Script.KernelID The KernelID object.
360      */
getKernelIDSrcAtop()361     public Script.KernelID getKernelIDSrcAtop() {
362         return createKernelID(9, 3, null, null);
363     }
364 
365     /**
366      * dst = dst.rgb * src.a + (1.0 - dst.a) * src.rgb
367      * dst.a = src.a
368      * Note: Before API 23, the alpha channel was not correctly set.
369      *       Please use with caution when targeting older APIs.
370      *
371      * @param ain The source buffer
372      * @param aout The destination buffer
373      */
forEachDstAtop(Allocation ain, Allocation aout)374     public void forEachDstAtop(Allocation ain, Allocation aout) {
375         forEachDstAtop(ain, aout, null);
376     }
377 
378     /**
379      * dst = dst.rgb * src.a + (1.0 - dst.a) * src.rgb
380      * dst.a = src.a
381      * Note: Before API 23, the alpha channel was not correctly set.
382      *       Please use with caution when targeting older APIs.
383      *
384      * @param ain The source buffer
385      * @param aout The destination buffer
386      * @param opt LaunchOptions for clipping
387      */
forEachDstAtop(Allocation ain, Allocation aout, Script.LaunchOptions opt)388     public void forEachDstAtop(Allocation ain, Allocation aout, Script.LaunchOptions opt) {
389         blend(10, ain, aout, opt);
390     }
391 
392     /**
393      * Get a KernelID for the DstAtop kernel.
394      *
395      * @return Script.KernelID The KernelID object.
396      */
getKernelIDDstAtop()397     public Script.KernelID getKernelIDDstAtop() {
398         return createKernelID(10, 3, null, null);
399     }
400 
401     /**
402      * Sets dst = {src.r ^ dst.r, src.g ^ dst.g, src.b ^ dst.b, src.a ^ dst.a}
403      *
404      * @param ain The source buffer
405      * @param aout The destination buffer
406      */
forEachXor(Allocation ain, Allocation aout)407     public void forEachXor(Allocation ain, Allocation aout) {
408         forEachXor(ain, aout, null);
409     }
410 
411     /**
412      * Sets dst = {src.r ^ dst.r, src.g ^ dst.g, src.b ^ dst.b, src.a ^ dst.a}
413      *
414      * <b>Note:</b> this is NOT the Porter/Duff XOR mode; this is a bitwise xor.
415      *
416      * @param ain The source buffer
417      * @param aout The destination buffer
418      * @param opt LaunchOptions for clipping
419      */
forEachXor(Allocation ain, Allocation aout, Script.LaunchOptions opt)420     public void forEachXor(Allocation ain, Allocation aout, Script.LaunchOptions opt) {
421         blend(11, ain, aout, opt);
422     }
423 
424     /**
425      * Get a KernelID for the Xor kernel.
426      *
427      * @return Script.KernelID The KernelID object.
428      */
getKernelIDXor()429     public Script.KernelID getKernelIDXor() {
430         return createKernelID(11, 3, null, null);
431     }
432 
433     ////////
434 /*
435     public void forEachNormal(Allocation ain, Allocation aout) {
436         blend(12, ain, aout);
437     }
438 
439     public void forEachAverage(Allocation ain, Allocation aout) {
440         blend(13, ain, aout);
441     }
442 */
443     /**
444      * Sets dst = src * dst
445      *
446      * @param ain The source buffer
447      * @param aout The destination buffer
448      */
forEachMultiply(Allocation ain, Allocation aout)449     public void forEachMultiply(Allocation ain, Allocation aout) {
450         forEachMultiply(ain, aout, null);
451     }
452 
453     /**
454      * Sets dst = src * dst
455      *
456      * @param ain The source buffer
457      * @param aout The destination buffer
458      * @param opt LaunchOptions for clipping
459      */
forEachMultiply(Allocation ain, Allocation aout, Script.LaunchOptions opt)460     public void forEachMultiply(Allocation ain, Allocation aout, Script.LaunchOptions opt) {
461         blend(14, ain, aout, opt);
462     }
463 
464     /**
465      * Get a KernelID for the Multiply kernel.
466      *
467      * @return Script.KernelID The KernelID object.
468      */
getKernelIDMultiply()469     public Script.KernelID getKernelIDMultiply() {
470         return createKernelID(14, 3, null, null);
471     }
472 
473 /*
474     public void forEachScreen(Allocation ain, Allocation aout) {
475         blend(15, ain, aout);
476     }
477 
478     public void forEachDarken(Allocation ain, Allocation aout) {
479         blend(16, ain, aout);
480     }
481 
482     public void forEachLighten(Allocation ain, Allocation aout) {
483         blend(17, ain, aout);
484     }
485 
486     public void forEachOverlay(Allocation ain, Allocation aout) {
487         blend(18, ain, aout);
488     }
489 
490     public void forEachHardlight(Allocation ain, Allocation aout) {
491         blend(19, ain, aout);
492     }
493 
494     public void forEachSoftlight(Allocation ain, Allocation aout) {
495         blend(20, ain, aout);
496     }
497 
498     public void forEachDifference(Allocation ain, Allocation aout) {
499         blend(21, ain, aout);
500     }
501 
502     public void forEachNegation(Allocation ain, Allocation aout) {
503         blend(22, ain, aout);
504     }
505 
506     public void forEachExclusion(Allocation ain, Allocation aout) {
507         blend(23, ain, aout);
508     }
509 
510     public void forEachColorDodge(Allocation ain, Allocation aout) {
511         blend(24, ain, aout);
512     }
513 
514     public void forEachInverseColorDodge(Allocation ain, Allocation aout) {
515         blend(25, ain, aout);
516     }
517 
518     public void forEachSoftDodge(Allocation ain, Allocation aout) {
519         blend(26, ain, aout);
520     }
521 
522     public void forEachColorBurn(Allocation ain, Allocation aout) {
523         blend(27, ain, aout);
524     }
525 
526     public void forEachInverseColorBurn(Allocation ain, Allocation aout) {
527         blend(28, ain, aout);
528     }
529 
530     public void forEachSoftBurn(Allocation ain, Allocation aout) {
531         blend(29, ain, aout);
532     }
533 
534     public void forEachReflect(Allocation ain, Allocation aout) {
535         blend(30, ain, aout);
536     }
537 
538     public void forEachGlow(Allocation ain, Allocation aout) {
539         blend(31, ain, aout);
540     }
541 
542     public void forEachFreeze(Allocation ain, Allocation aout) {
543         blend(32, ain, aout);
544     }
545 
546     public void forEachHeat(Allocation ain, Allocation aout) {
547         blend(33, ain, aout);
548     }
549 */
550     /**
551      * Sets dst = min(src + dst, 1.0)
552      *
553      * @param ain The source buffer
554      * @param aout The destination buffer
555      */
forEachAdd(Allocation ain, Allocation aout)556     public void forEachAdd(Allocation ain, Allocation aout) {
557         forEachAdd(ain, aout, null);
558     }
559 
560     /**
561      * Sets dst = min(src + dst, 1.0)
562      *
563      * @param ain The source buffer
564      * @param aout The destination buffer
565      * @param opt LaunchOptions for clipping
566      */
forEachAdd(Allocation ain, Allocation aout, Script.LaunchOptions opt)567     public void forEachAdd(Allocation ain, Allocation aout, Script.LaunchOptions opt) {
568         blend(34, ain, aout, opt);
569     }
570 
571     /**
572      * Get a KernelID for the Add kernel.
573      *
574      * @return Script.KernelID The KernelID object.
575      */
getKernelIDAdd()576     public Script.KernelID getKernelIDAdd() {
577         return createKernelID(34, 3, null, null);
578     }
579 
580     /**
581      * Sets dst = max(dst - src, 0.0)
582      *
583      * @param ain The source buffer
584      * @param aout The destination buffer
585      */
forEachSubtract(Allocation ain, Allocation aout)586     public void forEachSubtract(Allocation ain, Allocation aout) {
587         forEachSubtract(ain, aout, null);
588     }
589 
590     /**
591      * Sets dst = max(dst - src, 0.0)
592      *
593      * @param ain The source buffer
594      * @param aout The destination buffer
595      * @param opt LaunchOptions for clipping
596      */
forEachSubtract(Allocation ain, Allocation aout, Script.LaunchOptions opt)597     public void forEachSubtract(Allocation ain, Allocation aout, Script.LaunchOptions opt) {
598         blend(35, ain, aout, opt);
599     }
600 
601     /**
602      * Get a KernelID for the Subtract kernel.
603      *
604      * @return Script.KernelID The KernelID object.
605      */
getKernelIDSubtract()606     public Script.KernelID getKernelIDSubtract() {
607         return createKernelID(35, 3, null, null);
608     }
609 
610 /*
611     public void forEachStamp(Allocation ain, Allocation aout) {
612         blend(36, ain, aout);
613     }
614 
615     public void forEachRed(Allocation ain, Allocation aout) {
616         blend(37, ain, aout);
617     }
618 
619     public void forEachGreen(Allocation ain, Allocation aout) {
620         blend(38, ain, aout);
621     }
622 
623     public void forEachBlue(Allocation ain, Allocation aout) {
624         blend(39, ain, aout);
625     }
626 
627     public void forEachHue(Allocation ain, Allocation aout) {
628         blend(40, ain, aout);
629     }
630 
631     public void forEachSaturation(Allocation ain, Allocation aout) {
632         blend(41, ain, aout);
633     }
634 
635     public void forEachColor(Allocation ain, Allocation aout) {
636         blend(42, ain, aout);
637     }
638 
639     public void forEachLuminosity(Allocation ain, Allocation aout) {
640         blend(43, ain, aout);
641     }
642 */
643 }
644 
645