compositor: Add support for I420/I422 high bitdepth formats
[platform/upstream/gstreamer.git] / subprojects / gst-plugins-base / gst / compositor / compositororc.orc
1 .function compositor_orc_splat_u32
2 .dest 4 d1 guint32
3 .param 4 p1 guint32
4
5 copyl d1, p1
6
7 .function compositor_orc_memcpy_u32
8 .dest 4 d1 guint32
9 .source 4 s1 guint32
10
11 copyl d1, s1
12
13 .function compositor_orc_memset_u16_2d
14 .flags 2d
15 .dest 2 d1 guint8
16 .param 2 p1
17
18 storew d1, p1
19
20 .function compositor_orc_blend_u8
21 .flags 2d
22 .dest 1 d1 guint8
23 .source 1 s1 guint8
24 .param 2 p1
25 .temp 2 t1
26 .temp 2 t2
27 .const 1 c1 8
28
29 convubw t1, d1
30 convubw t2, s1
31 subw t2, t2, t1
32 mullw t2, t2, p1
33 shlw t1, t1, c1
34 addw t2, t1, t2
35 shruw t2, t2, c1
36 convsuswb d1, t2
37
38 .function compositor_orc_blend_u10
39 .flags 2d
40 .dest 2 d1 guint8
41 .source 2 s1 guint8
42 .param 2 p1
43 .temp 4 t1
44 .temp 4 t2
45 .const 1 c1 10
46
47 convuwl t1, d1
48 convuwl t2, s1
49 subl t2, t2, t1
50 mulll t2, t2, p1
51 shll t1, t1, c1
52 addl t2, t1, t2
53 shrul t2, t2, c1
54 convsuslw d1, t2
55
56 .function compositor_orc_blend_u12
57 .flags 2d
58 .dest 2 d1 guint8
59 .source 2 s1 guint8
60 .param 2 p1
61 .temp 4 t1
62 .temp 4 t2
63 .const 1 c1 12
64
65 convuwl t1, d1
66 convuwl t2, s1
67 subl t2, t2, t1
68 mulll t2, t2, p1
69 shll t1, t1, c1
70 addl t2, t1, t2
71 shrul t2, t2, c1
72 convsuslw d1, t2
73
74 .function compositor_orc_blend_u16
75 .flags 2d
76 .dest 2 d1 guint8
77 .source 2 s1 guint8
78 .param 2 p1
79 .temp 4 t1
80 .temp 4 t2
81 .const 1 c1 16
82
83 convuwl t1, d1
84 convuwl t2, s1
85 subl t2, t2, t1
86 mulll t2, t2, p1
87 shll t1, t1, c1
88 addl t2, t1, t2
89 shrul t2, t2, c1
90 convsuslw d1, t2
91
92 .function compositor_orc_blend_u10_swap
93 .flags 2d
94 .dest 2 d1 guint8
95 .source 2 s1 guint8
96 .param 2 p1
97 .temp 4 t1
98 .temp 4 t2
99 .temp 2 t3
100 .const 1 c1 10
101
102 swapw t3 d1
103 convuwl t1, t3
104 swapw t3 s1
105 convuwl t2, t3
106 subl t2, t2, t1
107 mulll t2, t2, p1
108 shll t1, t1, c1
109 addl t2, t1, t2
110 shrul t2, t2, c1
111 convsuslw t3, t2
112 swapw d1 t3
113
114 .function compositor_orc_blend_u12_swap
115 .flags 2d
116 .dest 2 d1 guint8
117 .source 2 s1 guint8
118 .param 2 p1
119 .temp 4 t1
120 .temp 4 t2
121 .temp 2 t3
122 .const 1 c1 12
123
124 swapw t3 d1
125 convuwl t1, t3
126 swapw t3 s1
127 convuwl t2, t3
128 subl t2, t2, t1
129 mulll t2, t2, p1
130 shll t1, t1, c1
131 addl t2, t1, t2
132 shrul t2, t2, c1
133 convsuslw t3, t2
134 swapw d1 t3
135
136 .function compositor_orc_blend_u16_swap
137 .flags 2d
138 .dest 2 d1 guint8
139 .source 2 s1 guint8
140 .param 2 p1
141 .temp 4 t1
142 .temp 4 t2
143 .temp 2 t3
144 .const 1 c1 16
145
146 swapw t3 d1
147 convuwl t1, t3
148 swapw t3 s1
149 convuwl t2, t3
150 subl t2, t2, t1
151 mulll t2, t2, p1
152 shll t1, t1, c1
153 addl t2, t1, t2
154 shrul t2, t2, c1
155 convsuslw t3, t2
156 swapw d1 t3
157
158 .function compositor_orc_blend_argb
159 .flags 2d
160 .dest 4 d guint8
161 .source 4 s guint8
162 .param 2 alpha
163 .temp 4 t
164 .temp 2 tw
165 .temp 1 tb
166 .temp 4 a
167 .temp 8 d_wide
168 .temp 8 s_wide
169 .temp 8 a_wide
170 .const 4 a_alpha 0x000000ff
171
172 loadl t, s
173 convlw tw, t
174 convwb tb, tw
175 splatbl a, tb
176 x4 convubw a_wide, a
177 x4 mullw a_wide, a_wide, alpha
178 x4 div255w a_wide, a_wide
179
180 x4 convubw s_wide, t
181 x4 mullw s_wide, s_wide, a_wide
182
183 # calc 255-alpha
184 x4 subw a_wide, 0xff, a_wide
185
186 loadl t, d
187 x4 convubw d_wide, t
188 x4 mullw d_wide, d_wide, a_wide
189
190 x4 addw d_wide, d_wide, s_wide
191 x4 div255w d_wide, d_wide
192 x4 convwb t, d_wide
193 orl t, t, a_alpha
194 storel d, t
195
196 .function compositor_orc_source_argb
197 .flags 2d
198 .dest 4 d guint8
199 .source 4 s guint8
200 .param 2 alpha
201 .temp 4 t
202 .temp 4 t2
203 .temp 2 tw
204 .temp 1 tb
205 .temp 4 a
206 .temp 8 a_wide
207 .const 4 a_alpha 0x000000ff
208 .const 4 a_not_alpha 0xffffff00
209
210 loadl t, s
211 convlw tw, t
212 convwb tb, tw
213 splatbl a, tb
214 x4 convubw a_wide, a
215 x4 mullw a_wide, a_wide, alpha
216 x4 div255w a_wide, a_wide
217
218 andl t, t, a_not_alpha
219 x4 convwb t2, a_wide
220 andl t2, t2, a_alpha
221 orl t, t, t2
222
223 storel d, t
224
225 .function compositor_orc_blend_bgra
226 .flags 2d
227 .dest 4 d guint8
228 .source 4 s guint8
229 .param 2 alpha
230 .temp 4 t
231 .temp 4 t2
232 .temp 2 tw
233 .temp 1 tb
234 .temp 4 a
235 .temp 8 d_wide
236 .temp 8 s_wide
237 .temp 8 a_wide
238 .const 4 a_alpha 0xff000000
239
240 loadl t, s
241 shrul t2, t, 24
242 convlw tw, t2
243 convwb tb, tw
244 splatbl a, tb
245 x4 convubw a_wide, a
246 x4 mullw a_wide, a_wide, alpha
247 x4 div255w a_wide, a_wide
248
249 x4 convubw s_wide, t
250 x4 mullw s_wide, s_wide, a_wide
251
252 # calc 255-alpha
253 x4 subw a_wide, 0xff, a_wide
254
255 loadl t, d
256 x4 convubw d_wide, t
257 x4 mullw d_wide, d_wide, a_wide
258
259 x4 addw d_wide, d_wide, s_wide
260 x4 div255w d_wide, d_wide
261
262 x4 convwb t, d_wide
263 orl t, t, a_alpha
264 storel d, t
265
266 .function compositor_orc_source_bgra
267 .flags 2d
268 .dest 4 d guint8
269 .source 4 s guint8
270 .param 2 alpha
271 .temp 4 t
272 .temp 4 t2
273 .temp 2 tw
274 .temp 1 tb
275 .temp 4 a
276 .temp 8 a_wide
277 .const 4 a_alpha 0xff000000
278 .const 4 a_not_alpha 0x00ffffff
279
280 loadl t, s
281 convhlw tw, t
282 convhwb tb, tw
283 splatbl a, tb
284 x4 convubw a_wide, a
285 x4 mullw a_wide, a_wide, alpha
286 x4 div255w a_wide, a_wide
287
288 andl t, t, a_not_alpha
289 x4 convwb t2, a_wide
290 andl t2, t2, a_alpha
291 orl t, t, t2
292
293 storel d, t
294
295 .function compositor_orc_overlay_argb
296 .flags 2d
297 .dest 4 d guint8
298 .source 4 s guint8
299 .param 2 alpha
300 .temp 4 t
301 .temp 2 tw
302 .temp 1 tb
303 .temp 8 alpha_s
304 .temp 8 alpha_s_inv
305 .temp 8 alpha_d
306 .temp 4 a
307 .temp 8 d_wide
308 .temp 8 s_wide
309 .const 4 xfs 0xffffffff
310 .const 4 a_alpha 0x000000ff
311 .const 4 a_alpha_inv 0xffffff00
312
313 # calc source alpha as alpha_s = alpha_s * alpha / 255
314 loadl t, s
315 convlw tw, t
316 convwb tb, tw
317 splatbl a, tb
318 x4 convubw alpha_s, a
319 x4 mullw alpha_s, alpha_s, alpha
320 x4 div255w alpha_s, alpha_s
321 x4 convubw s_wide, t
322 x4 mullw s_wide, s_wide, alpha_s
323
324 # calc destination alpha as alpha_d = (255-alpha_s) * alpha_d / 255
325 loadpl a, xfs
326 x4 convubw alpha_s_inv, a
327 x4 subw alpha_s_inv, alpha_s_inv, alpha_s
328 loadl t, d
329 convlw tw, t
330 convwb tb, tw
331 splatbl a, tb
332 x4 convubw alpha_d, a
333 x4 mullw alpha_d, alpha_d, alpha_s_inv
334 x4 div255w alpha_d, alpha_d
335 x4 convubw d_wide, t
336 x4 mullw d_wide, d_wide, alpha_d
337
338 # calc final pixel as pix_d = pix_s*alpha_s + pix_d*alpha_d*(255-alpha_s)/255
339 x4 addw d_wide, d_wide, s_wide
340
341 # calc the final destination alpha_d = alpha_s + alpha_d * (255-alpha_s)/255
342 x4 addw alpha_d, alpha_d, alpha_s
343
344 # now normalize the pix_d by the final alpha to make it associative
345 x4 divluw, d_wide, d_wide, alpha_d
346
347 # pack the new alpha into the correct spot
348 x4 convwb t, d_wide
349 andl t, t, a_alpha_inv
350 x4 convwb a, alpha_d
351 andl a, a, a_alpha
352 orl  t, t, a
353 storel d, t
354
355
356 .function compositor_orc_overlay_argb_addition
357 .flags 2d
358 .dest 4 d guint8
359 .source 4 s guint8
360 .param 2 alpha
361 .temp 4 t
362 .temp 2 tw
363 .temp 1 tb
364 .temp 8 alpha_s
365 .temp 8 alpha_s_inv
366 .temp 8 alpha_factor
367 .temp 8 alpha_d
368 .temp 4 a
369 .temp 8 d_wide
370 .temp 8 s_wide
371 .const 4 xfs 0xffffffff
372 .const 4 a_alpha 0x000000ff
373 .const 4 a_alpha_inv 0xffffff00
374
375 # calc source alpha as alpha_s = alpha_s * alpha / 255
376 loadl t, s
377 convlw tw, t
378 convwb tb, tw
379 splatbl a, tb
380 x4 convubw alpha_s, a
381 x4 mullw alpha_s, alpha_s, alpha
382 x4 div255w alpha_s, alpha_s
383 x4 convubw s_wide, t
384 x4 mullw s_wide, s_wide, alpha_s
385
386 # calc destination alpha as alpha_factor = (255-alpha_s) * alpha_factor / factor
387 loadpl a, xfs
388 x4 convubw alpha_s_inv, a
389 x4 subw alpha_s_inv, alpha_s_inv, alpha_s
390 loadl t, d
391 convlw tw, t
392 convwb tb, tw
393 splatbl a, tb
394 x4 convubw alpha_factor, a
395 x4 mullw alpha_factor, alpha_factor, alpha_s_inv
396 x4 div255w alpha_factor, alpha_factor
397 x4 convubw d_wide, t
398 x4 mullw d_wide, d_wide, alpha_factor
399
400 # calc final pixel as pix_d = pix_s*alpha_s + pix_d*alpha_factor*(255-alpha_s)/255
401 x4 addw d_wide, d_wide, s_wide
402
403 # calc the alpha factor alpha_factor = alpha_s + alpha_factor * (255-alpha_s)/255
404 x4 addw alpha_factor, alpha_factor, alpha_s
405
406 # now normalize the pix_d by the final alpha to make it associative
407 x4 divluw, d_wide, d_wide, alpha_factor
408
409 # calc the final global alpha_d = alpha_d + (alpha_s * (alpha / 255))
410 loadl t, d
411 convlw tw, t
412 convwb tb, tw
413 splatbl a, tb
414 x4 convubw alpha_d, a
415 x4 addw alpha_d, alpha_d, alpha_s
416
417 # pack the new alpha into the correct spot
418 x4 convwb t, d_wide
419 andl t, t, a_alpha_inv
420 x4 convwb a, alpha_d
421 andl a, a, a_alpha
422 orl  t, t, a
423 storel d, t
424
425 .function compositor_orc_overlay_bgra
426 .flags 2d
427 .dest 4 d guint8
428 .source 4 s guint8
429 .param 2 alpha
430 .temp 4 t
431 .temp 4 t2
432 .temp 2 tw
433 .temp 1 tb
434 .temp 8 alpha_s
435 .temp 8 alpha_s_inv
436 .temp 8 alpha_d
437 .temp 4 a
438 .temp 8 d_wide
439 .temp 8 s_wide
440 .const 4 xfs 0xffffffff
441 .const 4 a_alpha 0xff000000
442 .const 4 a_alpha_inv 0x00ffffff
443
444 # calc source alpha as alpha_s = alpha_s * alpha / 255
445 loadl t, s
446 shrul t2, t, 24
447 convlw tw, t2
448 convwb tb, tw
449 splatbl a, tb
450 x4 convubw alpha_s, a
451 x4 mullw alpha_s, alpha_s, alpha
452 x4 div255w alpha_s, alpha_s
453 x4 convubw s_wide, t
454 x4 mullw s_wide, s_wide, alpha_s
455
456 # calc destination alpha as alpha_d = (255-alpha_s) * alpha_d / 255
457 loadpl a, xfs
458 x4 convubw alpha_s_inv, a
459 x4 subw alpha_s_inv, alpha_s_inv, alpha_s
460 loadl t, d
461 shrul t2, t, 24
462 convlw tw, t2
463 convwb tb, tw
464 splatbl a, tb
465 x4 convubw alpha_d, a
466 x4 mullw alpha_d, alpha_d, alpha_s_inv
467 x4 div255w alpha_d, alpha_d
468 x4 convubw d_wide, t
469 x4 mullw d_wide, d_wide, alpha_d
470
471 # calc final pixel as pix_d = pix_s*alpha_s + pix_d*alpha_d*(255-alpha_s)/255
472 x4 addw d_wide, d_wide, s_wide
473
474 # calc the final destination alpha_d = alpha_s + alpha_d * (255-alpha_s)/255
475 x4 addw alpha_d, alpha_d, alpha_s
476
477 # now normalize the pix_d by the final alpha to make it associative
478 x4 divluw, d_wide, d_wide, alpha_d
479
480 # pack the new alpha into the correct spot
481 x4 convwb t, d_wide
482 andl t, t, a_alpha_inv
483 x4 convwb a, alpha_d
484 andl a, a, a_alpha
485 orl  t, t, a
486 storel d, t
487
488 .function compositor_orc_overlay_bgra_addition
489 .flags 2d
490 .dest 4 d guint8
491 .source 4 s guint8
492 .param 2 alpha
493 .temp 4 t
494 .temp 4 t2
495 .temp 2 tw
496 .temp 1 tb
497 .temp 8 alpha_s
498 .temp 8 alpha_s_inv
499 .temp 8 alpha_factor
500 .temp 8 alpha_d
501 .temp 4 a
502 .temp 8 d_wide
503 .temp 8 s_wide
504 .const 4 xfs 0xffffffff
505 .const 4 a_alpha 0xff000000
506 .const 4 a_alpha_inv 0x00ffffff
507
508 # calc source alpha as alpha_s = alpha_s * alpha / 255
509 loadl t, s
510 shrul t2, t, 24
511 convlw tw, t2
512 convwb tb, tw
513 splatbl a, tb
514 x4 convubw alpha_s, a
515 x4 mullw alpha_s, alpha_s, alpha
516 x4 div255w alpha_s, alpha_s
517 x4 convubw s_wide, t
518 x4 mullw s_wide, s_wide, alpha_s
519
520 # calc destination alpha as alpha_factor = (255-alpha_s) * alpha_factor / 255
521 loadpl a, xfs
522 x4 convubw alpha_s_inv, a
523 x4 subw alpha_s_inv, alpha_s_inv, alpha_s
524 loadl t, d
525 shrul t2, t, 24
526 convlw tw, t2
527 convwb tb, tw
528 splatbl a, tb
529 x4 convubw alpha_factor, a
530 x4 mullw alpha_factor, alpha_factor, alpha_s_inv
531 x4 div255w alpha_factor, alpha_factor
532 x4 convubw d_wide, t
533 x4 mullw d_wide, d_wide, alpha_factor
534
535 # calc final pixel as pix_d = pix_s*alpha_s + pix_d*alpha_factor*(255-alpha_s)/255
536 x4 addw d_wide, d_wide, s_wide
537
538 # calc the final destination alpha_factor = alpha_s + alpha_factor * (255-alpha_s)/255
539 x4 addw alpha_factor, alpha_factor, alpha_s
540
541 # now normalize the pix_d by the final alpha to make it associative
542 x4 divluw, d_wide, d_wide, alpha_factor
543
544 # calc the final global alpha_d = alpha_d + (alpha_s * (alpha / 255))
545 loadl t, d
546 shrul t2, t, 24
547 convlw tw, t2
548 convwb tb, tw
549 splatbl a, tb
550 x4 convubw alpha_d, a
551 x4 addw alpha_d, alpha_d, alpha_s
552
553 # pack the new alpha into the correct spot
554 x4 convwb t, d_wide
555 andl t, t, a_alpha_inv
556 x4 convwb a, alpha_d
557 andl a, a, a_alpha
558 orl  t, t, a
559 storel d, t