blob: 13c03af7dbe6353210f4e9b471655b17c0ce862e [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/**
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 int id = rs.nScriptIntrinsicCreate(6, e.getID(rs));
40 return new ScriptIntrinsicBlend(id, rs);
41
42 }
43
44 private void blend(int id, Allocation ain, Allocation aout) {
45 if (ain.getElement() != Element.U8_4(mRS)) {
46 throw new RSIllegalArgumentException("Input not of expected format.");
47 }
48 if (aout.getElement() != Element.U8_4(mRS)) {
49 throw new RSIllegalArgumentException("Output not of expected format.");
50 }
51 forEach(id, ain, aout, null);
52 }
53
54 /**
55 * dst = {0, 0, 0, 0}
56 *
57 * @param ain The source buffer
58 * @param aout The destination buffer
59 */
60 public void forEachClear(Allocation ain, Allocation aout) {
61 blend(0, ain, aout);
62 }
63
64 /**
65 * Get a KernelID for the Clear kernel.
66 *
67 * @return Script.KernelID The KernelID object.
68 */
69 public Script.KernelID getKernelIDClear() {
70 return createKernelID(0, 3, null, null);
71 }
72
73
74 /**
75 * dst = src
76 *
77 * @param ain The source buffer
78 * @param aout The destination buffer
79 */
80 public void forEachSrc(Allocation ain, Allocation aout) {
81 blend(1, ain, aout);
82 }
83
84 /**
85 * Get a KernelID for the Src kernel.
86 *
87 * @return Script.KernelID The KernelID object.
88 */
89 public Script.KernelID getKernelIDSrc() {
90 return createKernelID(1, 3, null, null);
91 }
92
93 /**
94 * dst = dst
95 * This is a NOP
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 /**
114 * dst = src + dst * (1.0 - src.a)
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 /**
133 * dst = dst + src * (1.0 - dst.a)
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 /**
152 * dst = src * dst.a
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 /**
171 * dst = dst * src.a
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 /**
190 * dst = src * (1.0 - dst.a)
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 /**
209 * dst = dst * (1.0 - src.a)
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 /**
268 * dst = {src.r ^ dst.r, src.g ^ dst.g, src.b ^ dst.b, src.a ^ dst.a}
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 /**
297 * dst = src * dst
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 /**
393 * dst = min(src + dst, 1.0)
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 /**
412 * dst = max(dst - src, 0.0)
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