r609: Make it compile with xorg
[cinelerra_cv/mob.git] / quicktime / cmodel_permutation.h
blobe752e2cfd35cee8d02317b3387b1581df6e43e1f
1 /*
2 * This library is free software; you can redistribute it and/or modify it
3 * under the terms of the GNU Lesser General Public License as published
4 * by the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This library is distributed in the hope that it will be useful, but
8 * WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * Lesser General Public License for more details.
12 * You should have received a copy of the GNU Lesser General Public
13 * License along with this library; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
15 * USA
17 #include "colormodels.h"
18 #include <stdint.h>
20 // All variables are unsigned
21 // y -> 24 bits u, v, -> 8 bits r, g, b -> 8 bits
22 #define YUV_TO_RGB(y, u, v, r, g, b) \
23 { \
24 (r) = ((y + yuv_table->vtor_tab[v]) >> 16); \
25 (g) = ((y + yuv_table->utog_tab[u] + yuv_table->vtog_tab[v]) >> 16); \
26 (b) = ((y + yuv_table->utob_tab[u]) >> 16); \
27 CLAMP(r, 0, 0xff); \
28 CLAMP(g, 0, 0xff); \
29 CLAMP(b, 0, 0xff); \
32 // y -> 0 - 1 float
33 // u, v, -> 8 bits
34 // r, g, b -> float
35 #define YUV_TO_FLOAT(y, u, v, r, g, b) \
36 { \
37 (r) = y + yuv_table->vtor_float_tab[v]; \
38 (g) = y + yuv_table->utog_float_tab[u] + yuv_table->vtog_float_tab[v]; \
39 (b) = y + yuv_table->utob_float_tab[u]; \
42 // y -> 0 - 1 float
43 // u, v, -> 16 bits
44 // r, g, b -> float
45 #define YUV16_TO_RGB_FLOAT(y, u, v, r, g, b) \
46 { \
47 (r) = y + yuv_table->v16tor_float_tab[v]; \
48 (g) = y + yuv_table->u16tog_float_tab[u] + yuv_table->v16tog_float_tab[v]; \
49 (b) = y + yuv_table->u16tob_float_tab[u]; \
52 // y -> 24 bits u, v-> 16 bits
53 #define YUV_TO_RGB16(y, u, v, r, g, b) \
54 { \
55 (r) = ((y + yuv_table->vtor_tab16[v]) >> 8); \
56 (g) = ((y + yuv_table->utog_tab16[u] + yuv_table->vtog_tab16[v]) >> 8); \
57 (b) = ((y + yuv_table->utob_tab16[u]) >> 8); \
58 CLAMP(r, 0, 0xffff); \
59 CLAMP(g, 0, 0xffff); \
60 CLAMP(b, 0, 0xffff); \
66 #define RGB_TO_YUV(y, u, v, r, g, b) \
67 { \
68 y = ((yuv_table->rtoy_tab[r] + yuv_table->gtoy_tab[g] + yuv_table->btoy_tab[b]) >> 16); \
69 u = ((yuv_table->rtou_tab[r] + yuv_table->gtou_tab[g] + yuv_table->btou_tab[b]) >> 16); \
70 v = ((yuv_table->rtov_tab[r] + yuv_table->gtov_tab[g] + yuv_table->btov_tab[b]) >> 16); \
71 CLAMP(y, 0, 0xff); \
72 CLAMP(u, 0, 0xff); \
73 CLAMP(v, 0, 0xff); \
76 // r, g, b -> 16 bits
77 #define RGB_TO_YUV16(y, u, v, r, g, b) \
78 { \
79 y = ((yuv_table->rtoy_tab16[r] + yuv_table->gtoy_tab16[g] + yuv_table->btoy_tab16[b]) >> 8); \
80 u = ((yuv_table->rtou_tab16[r] + yuv_table->gtou_tab16[g] + yuv_table->btou_tab16[b]) >> 8); \
81 v = ((yuv_table->rtov_tab16[r] + yuv_table->gtov_tab16[g] + yuv_table->btov_tab16[b]) >> 8); \
82 CLAMP(y, 0, 0xffff); \
83 CLAMP(u, 0, 0xffff); \
84 CLAMP(v, 0, 0xffff); \
87 #define WRITE_YUV101010(y, u, v) \
88 { \
89 uint32_t output_i = ((y & 0xffc0) << 16) | \
90 ((u & 0xffc0) << 6) | \
91 ((v & 0xffc0) >> 4); \
92 *(*output)++ = (output_i & 0xff); \
93 *(*output)++ = (output_i & 0xff00) >> 8; \
94 *(*output)++ = (output_i & 0xff0000) >> 16; \
95 *(*output)++ = (output_i & 0xff000000) >> 24; \
100 // ****************************** Pixel transfers *****************************
107 // ****************************** ARGB8888 -> *********************************
109 static inline void transfer_ARGB8888_to_ARGB8888(unsigned char *(*output), unsigned char *input)
111 (*output)[0] = input[0];
112 (*output)[1] = input[1];
113 (*output)[2] = input[2];
114 (*output)[3] = input[3];
115 (*output) += 4;
118 static inline void transfer_ARGB8888_to_RGBA8888(unsigned char *(*output), unsigned char *input)
120 (*output)[0] = input[1];
121 (*output)[1] = input[2];
122 (*output)[2] = input[3];
123 (*output)[3] = input[0];
124 (*output) += 4;
128 static inline void transfer_ARGB8888_to_RGB888(unsigned char *(*output), unsigned char *input)
130 int a = input[0];
131 (*output)[0] = input[1] * a / 0xff;
132 (*output)[1] = input[2] * a / 0xff;
133 (*output)[2] = input[3] * a / 0xff;
134 (*output) += 3;
137 static inline void transfer_ARGB8888_to_BGR8888(unsigned char *(*output), unsigned char *input)
139 int a = input[0];
140 (*output)[0] = input[3] * a / 0xff;
141 (*output)[1] = input[2] * a / 0xff;
142 (*output)[2] = input[1] * a / 0xff;
143 (*output) += 3;
160 // ******************************** RGB888 -> *********************************
162 static inline void transfer_RGB888_to_RGB8(unsigned char *(*output), unsigned char *input)
164 *(*output) = (unsigned char)((input[0] & 0xc0) +
165 ((input[1] & 0xe0) >> 2) +
166 ((input[2] & 0xe0) >> 5));
167 (*output)++;
170 static inline void transfer_RGB888_to_BGR565(unsigned char *(*output), unsigned char *input)
172 uint16_t r, g, b;
173 uint16_t r_s, g_s, b_s;
174 r = *input++;
175 g = *input++;
176 b = *input;
178 r_s = (r & 0x01) << 7;
179 r_s |= (r & 0x02) << 5;
180 r_s |= (r & 0x04) << 3;
181 r_s |= (r & 0x08) << 1;
182 r_s |= (r & 0x10) >> 1;
183 r_s |= (r & 0x20) >> 3;
184 r_s |= (r & 0x40) >> 5;
185 r_s |= (r & 0x80) >> 7;
187 g_s = (g & 0x01) << 7;
188 g_s |= (g & 0x02) << 5;
189 g_s |= (g & 0x04) << 3;
190 g_s |= (g & 0x08) << 1;
191 g_s |= (g & 0x10) >> 1;
192 g_s |= (g & 0x20) >> 3;
193 g_s |= (g & 0x40) >> 5;
194 g_s |= (g & 0x80) >> 7;
196 b_s = (b & 0x01) << 7;
197 b_s |= (b & 0x02) << 5;
198 b_s |= (b & 0x04) << 3;
199 b_s |= (b & 0x08) << 1;
200 b_s |= (b & 0x10) >> 1;
201 b_s |= (b & 0x20) >> 3;
202 b_s |= (b & 0x40) >> 5;
203 b_s |= (b & 0x80) >> 7;
205 *(uint16_t*)(*output) = ((b_s & 0xf8) << 8)
206 + ((g_s & 0xfc) << 3)
207 + ((r_s & 0xf8) >> 3);
208 (*output) += 2;
211 static inline void transfer_RGB888_to_RGB565(unsigned char *(*output), unsigned char *input)
213 uint16_t r, g, b;
214 r = *input++;
215 g = *input++;
216 b = *input;
217 *(uint16_t*)(*output) = ((r & 0xf8) << 8)
218 + ((g & 0xfc) << 3)
219 + ((b & 0xf8) >> 3);
220 (*output) += 2;
223 static inline void transfer_RGB888_to_BGR888(unsigned char *(*output), unsigned char *input)
225 *(*output)++ = input[2];
226 *(*output)++ = input[1];
227 *(*output)++ = input[0];
230 static inline void transfer_RGB888_to_RGB888(unsigned char *(*output), unsigned char *input)
232 *(*output)++ = *input++;
233 *(*output)++ = *input++;
234 *(*output)++ = *input;
237 static inline void transfer_RGB888_to_RGBA8888(unsigned char *(*output), unsigned char *input)
239 *(*output)++ = *input++;
240 *(*output)++ = *input++;
241 *(*output)++ = *input;
242 *(*output)++ = 0xff;
245 static inline void transfer_RGB888_to_ARGB8888(unsigned char *(*output), unsigned char *input)
247 *(*output)++ = 0xff;
248 *(*output)++ = *input++;
249 *(*output)++ = *input++;
250 *(*output)++ = *input;
253 static inline void transfer_RGB888_to_RGB161616(uint16_t *(*output), unsigned char *input)
255 (*output)[0] = (input[0] << 8) | input[0];
256 (*output)[1] = (input[1] << 8) | input[1];
257 (*output)[2] = (input[2] << 8) | input[2];
258 (*output) += 3;
261 static inline void transfer_RGB888_to_RGBA16161616(uint16_t *(*output), unsigned char *input)
263 (*output)[0] = (input[0] << 8) | input[0];
264 (*output)[1] = (input[1] << 8) | input[1];
265 (*output)[2] = (input[2] << 8) | input[2];
266 (*output)[3] = 0xffff;
267 (*output) += 4;
270 static inline void transfer_RGB888_to_RGB_FLOAT(float *(*output), unsigned char *input)
272 *(*output)++ = (float)*input++ / 0xff;
273 *(*output)++ = (float)*input++ / 0xff;
274 *(*output)++ = (float)*input / 0xff;
277 static inline void transfer_RGB888_to_RGBA_FLOAT(float *(*output), unsigned char *input)
279 *(*output)++ = (float)*input++ / 0xff;
280 *(*output)++ = (float)*input++ / 0xff;
281 *(*output)++ = (float)*input / 0xff;
282 *(*output)++ = 1.0;
285 static inline void transfer_RGB888_to_ABGR8888(unsigned char *(*output), unsigned char *input)
287 *(*output)++ = 0xff;
288 *(*output)++ = input[2];
289 *(*output)++ = input[1];
290 *(*output)++ = input[0];
293 static inline void transfer_RGB888_to_BGR8888(unsigned char *(*output), unsigned char *input)
295 *(*output)++ = input[2];
296 *(*output)++ = input[1];
297 *(*output)++ = input[0];
298 (*output)++;
301 static inline void transfer_RGB888_to_YUV888(unsigned char *(*output), unsigned char *input)
303 int y, u, v;
305 RGB_TO_YUV(y, u, v, input[0], input[1], input[2]);
307 *(*output)++ = y;
308 *(*output)++ = u;
309 *(*output)++ = v;
313 static inline void transfer_RGB888_to_YUV101010(unsigned char *(*output), unsigned char *input)
315 int r, g, b;
316 int y, u, v;
318 r = ((uint16_t)input[0]) << 8;
319 g = ((uint16_t)input[1]) << 8;
320 b = ((uint16_t)input[2]) << 8;
321 RGB_TO_YUV16(y, u, v, r, g, b);
322 WRITE_YUV101010(y, u, v);
325 static inline void transfer_RGB888_to_VYU888(unsigned char *(*output), unsigned char *input)
327 int y, u, v;
329 RGB_TO_YUV(y, u, v, input[0], input[1], input[2]);
331 *(*output)++ = v;
332 *(*output)++ = y;
333 *(*output)++ = u;
336 static inline void transfer_RGB888_to_UYVA8888(unsigned char *(*output), unsigned char *input)
338 int y, u, v;
340 RGB_TO_YUV(y, u, v, input[0], input[1], input[2]);
342 *(*output)++ = u;
343 *(*output)++ = y;
344 *(*output)++ = v;
345 *(*output)++ = 0xff;
350 static inline void transfer_RGB888_to_YUVA8888(unsigned char *(*output), unsigned char *input)
352 int y, u, v;
354 RGB_TO_YUV(y, u, v, input[0], input[1], input[2]);
356 *(*output)++ = y;
357 *(*output)++ = u;
358 *(*output)++ = v;
359 *(*output)++ = 255;
362 static inline void transfer_RGB888_to_YUV161616(uint16_t *(*output), unsigned char *input)
364 int y, u, v, opacity, r, g, b;
366 r = ((int)input[0] << 8) | input[0];
367 g = ((int)input[1] << 8) | input[1];
368 b = ((int)input[2] << 8) | input[2];
370 RGB_TO_YUV16(y, u, v, r, g, b);
372 *(*output)++ = y;
373 *(*output)++ = u;
374 *(*output)++ = v;
377 static inline void transfer_RGB888_to_YUVA16161616(uint16_t *(*output), unsigned char *input)
379 int y, u, v, r, g, b;
381 r = (((int)input[0]) << 8) | input[0];
382 g = (((int)input[1]) << 8) | input[1];
383 b = (((int)input[2]) << 8) | input[2];
384 RGB_TO_YUV16(y, u, v, r, g, b);
386 *(*output)++ = y;
387 *(*output)++ = u;
388 *(*output)++ = v;
389 *(*output)++ = 0xffff;
392 static inline void transfer_RGB888_to_YUV420P_YUV422P(unsigned char *output_y,
393 unsigned char *output_u,
394 unsigned char *output_v,
395 unsigned char *input,
396 int output_column)
398 int y, u, v;
400 RGB_TO_YUV(y, u, v, input[0], input[1], input[2]);
402 output_y[output_column] = y;
403 output_u[output_column / 2] = u;
404 output_v[output_column / 2] = v;
407 static inline void transfer_RGB888_to_YUV444P(unsigned char *output_y,
408 unsigned char *output_u,
409 unsigned char *output_v,
410 unsigned char *input,
411 int output_column)
413 int y, u, v;
415 RGB_TO_YUV(y, u, v, input[0], input[1], input[2]);
417 output_y[output_column] = y;
418 output_u[output_column] = u;
419 output_v[output_column] = v;
422 static inline void transfer_RGB888_to_YUV422(unsigned char *(*output),
423 unsigned char *input,
424 int j)
426 int y, u, v;
428 RGB_TO_YUV(y, u, v, input[0], input[1], input[2]);
430 if(!(j & 1))
432 // Store U and V for even pixels only
433 (*output)[1] = u;
434 (*output)[3] = v;
435 (*output)[0] = y;
437 else
439 // Store Y and advance output for odd pixels only
440 (*output)[2] = y;
441 (*output) += 4;
452 // *************************** RGBA8888 -> ************************************
454 static inline void transfer_RGBA8888_to_TRANSPARENCY(unsigned char *(*output), unsigned char *input, int (*bit_counter))
456 if((*bit_counter) == 7) *(*output) = 0;
458 if(input[3] < 127)
460 *(*output) |= (unsigned char)1 << (7 - (*bit_counter));
463 if((*bit_counter) == 0)
465 (*output)++;
466 (*bit_counter) = 7;
468 else
469 (*bit_counter)--;
472 // These routines blend in a background color since they should be
473 // exclusively used for widgets.
475 static inline void transfer_RGBA8888_to_RGB8bg(unsigned char *(*output), unsigned char *input, int bg_r, int bg_g, int bg_b)
477 unsigned int r, g, b, a, anti_a;
478 a = input[3];
479 anti_a = 255 - a;
480 r = ((unsigned int)input[0] * a + bg_r * anti_a) / 0xff;
481 g = ((unsigned int)input[1] * a + bg_g * anti_a) / 0xff;
482 b = ((unsigned int)input[2] * a + bg_b * anti_a) / 0xff;
483 *(*output) = (unsigned char)((r & 0xc0) +
484 ((g & 0xe0) >> 2) +
485 ((b & 0xe0) >> 5));
486 (*output)++;
489 static inline void transfer_RGBA8888_to_BGR565bg(unsigned char *(*output), unsigned char *input, int bg_r, int bg_g, int bg_b)
491 unsigned int r, g, b, a, anti_a;
492 a = input[3];
493 anti_a = 255 - a;
494 r = ((unsigned int)input[0] * a + bg_r * anti_a) / 0xff;
495 g = ((unsigned int)input[1] * a + bg_g * anti_a) / 0xff;
496 b = ((unsigned int)input[2] * a + bg_b * anti_a) / 0xff;
497 *(uint16_t*)(*output) = (uint16_t)(((b & 0xf8) << 8) +
498 ((g & 0xfc) << 3) +
499 ((r & 0xf8) >> 3));
500 (*output) += 2;
503 static inline void transfer_RGBA8888_to_RGB565bg(unsigned char *(*output), unsigned char *input, int bg_r, int bg_g, int bg_b)
505 unsigned int r, g, b, a, anti_a;
506 a = input[3];
507 anti_a = 255 - a;
508 r = ((unsigned int)input[0] * a + bg_r * anti_a) / 0xff;
509 g = ((unsigned int)input[1] * a + bg_g * anti_a) / 0xff;
510 b = ((unsigned int)input[2] * a + bg_b * anti_a) / 0xff;
511 *(uint16_t*)(*output) = (uint16_t)(((r & 0xf8) << 8)+
512 ((g & 0xfc) << 3) +
513 ((b & 0xf8) >> 3));
514 (*output) += 2;
517 static inline void transfer_RGBA8888_to_BGR888bg(unsigned char *(*output), unsigned char *input, int bg_r, int bg_g, int bg_b)
519 unsigned int r, g, b, a, anti_a;
520 a = input[3];
521 anti_a = 255 - a;
522 r = ((unsigned int)input[0] * a + bg_r * anti_a) / 0xff;
523 g = ((unsigned int)input[1] * a + bg_g * anti_a) / 0xff;
524 b = ((unsigned int)input[2] * a + bg_b * anti_a) / 0xff;
525 *(*output)++ = b;
526 *(*output)++ = g;
527 *(*output)++ = r;
530 static inline void transfer_RGBA8888_to_RGB888bg(unsigned char *(*output), unsigned char *input, int bg_r, int bg_g, int bg_b)
532 unsigned int r, g, b, a, anti_a;
533 a = input[3];
534 anti_a = 255 - a;
535 r = ((unsigned int)input[0] * a + bg_r * anti_a) / 0xff;
536 g = ((unsigned int)input[1] * a + bg_g * anti_a) / 0xff;
537 b = ((unsigned int)input[2] * a + bg_b * anti_a) / 0xff;
538 *(*output)++ = r;
539 *(*output)++ = g;
540 *(*output)++ = b;
543 static inline void transfer_RGBA8888_to_BGR8888bg(unsigned char *(*output), unsigned char *input, int bg_r, int bg_g, int bg_b)
545 unsigned int r, g, b, a, anti_a;
546 a = input[3];
547 anti_a = 255 - a;
549 r = ((unsigned int)input[0] * a + bg_r * anti_a) / 0xff;
550 g = ((unsigned int)input[1] * a + bg_g * anti_a) / 0xff;
551 b = ((unsigned int)input[2] * a + bg_b * anti_a) / 0xff;
553 *(*output)++ = b;
554 *(*output)++ = g;
555 *(*output)++ = r;
556 (*output)++;
565 // These routines blend in a black background
567 static inline void transfer_RGBA8888_to_RGB8(unsigned char *(*output), unsigned char *input)
569 unsigned int r, g, b, a;
570 a = input[3];
571 r = (unsigned int)input[0] * a;
572 g = (unsigned int)input[1] * a;
573 b = (unsigned int)input[2] * a;
574 *(*output) = (unsigned char)(((r & 0xc000) >> 8) +
575 ((g & 0xe000) >> 10) +
576 ((b & 0xe000) >> 13));
577 (*output)++;
580 static inline void transfer_RGBA8888_to_BGR565(unsigned char *(*output), unsigned char *input)
582 unsigned int r, g, b, a;
583 a = input[3];
584 r = ((unsigned int)input[0] * a) / 0xff;
585 g = ((unsigned int)input[1] * a) / 0xff;
586 b = ((unsigned int)input[2] * a) / 0xff;
587 *(uint16_t*)(*output) = (uint16_t)(((b & 0xf8) << 8) +
588 ((g & 0xfc) << 3) +
589 ((r & 0xf8) >> 3));
590 (*output) += 2;
593 static inline void transfer_RGBA8888_to_RGB565(unsigned char *(*output), unsigned char *input)
595 unsigned int r, g, b, a;
596 a = input[3];
597 r = ((unsigned int)input[0] * a) / 0xff;
598 g = ((unsigned int)input[1] * a) / 0xff;
599 b = ((unsigned int)input[2] * a) / 0xff;
602 *(uint16_t*)(*output) = (uint16_t)(((r & 0xf8) << 8) +
603 ((g & 0xfc) << 3) +
604 ((b & 0xf8) >> 3));
605 (*output) += 2;
608 static inline void transfer_RGBA8888_to_BGR888(unsigned char *(*output), unsigned char *input)
610 unsigned int r, g, b, a;
611 a = input[3];
612 r = ((unsigned int)input[0] * a) / 0xff;
613 g = ((unsigned int)input[1] * a) / 0xff;
614 b = ((unsigned int)input[2] * a) / 0xff;
615 *(*output)++ = b;
616 *(*output)++ = g;
617 *(*output)++ = r;
620 static inline void transfer_RGBA8888_to_RGB888(unsigned char *(*output), unsigned char *input)
622 unsigned int r, g, b, a;
623 a = input[3];
624 r = ((unsigned int)input[0] * a) / 0xff;
625 g = ((unsigned int)input[1] * a) / 0xff;
626 b = ((unsigned int)input[2] * a) / 0xff;
627 *(*output)++ = r;
628 *(*output)++ = g;
629 *(*output)++ = b;
632 static inline void transfer_RGBA8888_to_RGBA8888(unsigned char *(*output), unsigned char *input)
634 (*output)[0] = input[0];
635 (*output)[1] = input[1];
636 (*output)[2] = input[2];
637 (*output)[3] = input[3];
638 (*output) += 4;
641 static inline void transfer_RGBA8888_to_ARGB8888(unsigned char *(*output), unsigned char *input)
643 (*output)[0] = input[3];
644 (*output)[1] = input[0];
645 (*output)[2] = input[1];
646 (*output)[3] = input[2];
647 (*output) += 4;
650 static inline void transfer_RGBA8888_to_RGB161616(uint16_t *(*output), unsigned char *input)
652 int y, u, v, opacity, r, g, b;
654 opacity = input[3];
655 (*output)[0] = (((int)input[0] << 8) | input[0]) * opacity / 0xff;
656 (*output)[1] = (((int)input[1] << 8) | input[1]) * opacity / 0xff;
657 (*output)[2] = (((int)input[2] << 8) | input[2]) * opacity / 0xff;
658 (*output) += 3;
661 static inline void transfer_RGBA8888_to_RGBA16161616(uint16_t *(*output), unsigned char *input)
663 int y, u, v, r, g, b;
665 (*output)[0] = (((int)input[0]) << 8) | input[0];
666 (*output)[1] = (((int)input[1]) << 8) | input[1];
667 (*output)[2] = (((int)input[2]) << 8) | input[2];
668 (*output)[3] = (((int)input[3]) << 8) | input[3];
669 (*output) += 4;
672 static inline void transfer_RGBA8888_to_RGB_FLOAT(float *(*output), unsigned char *input)
674 float opacity = (float)input[3];
675 *(*output)++ = (float)*input++ * opacity / 0xff / 0xff;
676 *(*output)++ = (float)*input++ * opacity / 0xff / 0xff;
677 *(*output)++ = (float)*input * opacity / 0xff / 0xff;
680 static inline void transfer_RGBA8888_to_RGBA_FLOAT(float *(*output), unsigned char *input)
682 *(*output)++ = (float)*input++ / 0xff;
683 *(*output)++ = (float)*input++ / 0xff;
684 *(*output)++ = (float)*input++ / 0xff;
685 *(*output)++ = (float)*input / 0xff;
688 static inline void transfer_RGBA8888_to_BGR8888(unsigned char *(*output), unsigned char *input)
690 unsigned int r, g, b, a;
691 a = input[3];
692 r = ((unsigned int)input[0] * a) / 0xff;
693 g = ((unsigned int)input[1] * a) / 0xff;
694 b = ((unsigned int)input[2] * a) / 0xff;
695 *(*output)++ = b;
696 *(*output)++ = g;
697 *(*output)++ = r;
698 (*output)++;
701 static inline void transfer_RGBA8888_to_YUV888(unsigned char *(*output), unsigned char *input)
703 int y, u, v, a, r, g, b;
705 a = input[3];
706 r = (input[0] * a) / 0xff;
707 g = (input[1] * a) / 0xff;
708 b = (input[2] * a) / 0xff;
710 RGB_TO_YUV(y, u, v, input[0], input[1], input[2]);
712 *(*output)++ = y;
713 *(*output)++ = u;
714 *(*output)++ = v;
717 static inline void transfer_RGBA8888_to_YUVA8888(unsigned char *(*output), unsigned char *input)
719 int y, u, v;
721 RGB_TO_YUV(y, u, v, input[0], input[1], input[2]);
723 *(*output)++ = y;
724 *(*output)++ = u;
725 *(*output)++ = v;
726 *(*output)++ = input[3];
729 static inline void transfer_RGBA8888_to_YUV161616(uint16_t *(*output), unsigned char *input)
731 int y, u, v, opacity, r, g, b;
733 opacity = input[3];
734 r = (((int)input[0] << 8) | input[0]) * opacity / 0xff;
735 g = (((int)input[1] << 8) | input[1]) * opacity / 0xff;
736 b = (((int)input[2] << 8) | input[2]) * opacity / 0xff;
738 RGB_TO_YUV16(y, u, v, r, g, b);
740 *(*output)++ = y;
741 *(*output)++ = u;
742 *(*output)++ = v;
745 static inline void transfer_RGBA8888_to_YUVA16161616(uint16_t *(*output), unsigned char *input)
747 int y, u, v, r, g, b;
749 r = (((int)input[0]) << 8) | input[0];
750 g = (((int)input[1]) << 8) | input[1];
751 b = (((int)input[2]) << 8) | input[2];
752 RGB_TO_YUV16(y, u, v, r, g, b);
754 *(*output)++ = y;
755 *(*output)++ = u;
756 *(*output)++ = v;
757 *(*output)++ = (((int)input[3]) << 8) | input[3];
760 static inline void transfer_RGBA8888_to_YUV101010(unsigned char *(*output), unsigned char *input)
762 int r, g, b;
763 int y, u, v;
765 r = ((uint16_t)input[0] * input[3]) + 0x1fe;
766 g = ((uint16_t)input[1] * input[3]) + 0x1fe;
767 b = ((uint16_t)input[2] * input[3]) + 0x1fe;
768 RGB_TO_YUV16(y, u, v, r, g, b);
769 WRITE_YUV101010(y, u, v);
772 static inline void transfer_RGBA8888_to_VYU888(unsigned char *(*output), unsigned char *input)
774 int y, u, v, a, r, g, b;
776 a = input[3];
777 r = ((input[0] * a) >> 8) + 1;
778 g = ((input[1] * a) >> 8) + 1;
779 b = ((input[2] * a) >> 8) + 1;
781 RGB_TO_YUV(y, u, v, input[0], input[1], input[2]);
783 *(*output)++ = v;
784 *(*output)++ = y;
785 *(*output)++ = u;
788 static inline void transfer_RGBA8888_to_UYVA8888(unsigned char *(*output), unsigned char *input)
790 int y, u, v;
792 RGB_TO_YUV(y, u, v, input[0], input[1], input[2]);
794 *(*output)++ = u;
795 *(*output)++ = y;
796 *(*output)++ = v;
797 *(*output)++ = input[3];
800 static inline void transfer_RGBA888_to_YUV420P_YUV422P(unsigned char *output_y,
801 unsigned char *output_u,
802 unsigned char *output_v,
803 unsigned char *input,
804 int output_column)
806 int y, u, v, a, r, g, b;
808 a = input[3];
809 r = (input[0] * a) / 0xff;
810 g = (input[1] * a) / 0xff;
811 b = (input[2] * a) / 0xff;
813 RGB_TO_YUV(y, u, v, r, g, b);
815 output_y[output_column] = y;
816 output_u[output_column / 2] = u;
817 output_v[output_column / 2] = v;
820 static inline void transfer_RGBA888_to_YUV444P(unsigned char *output_y,
821 unsigned char *output_u,
822 unsigned char *output_v,
823 unsigned char *input,
824 int output_column)
826 int y, u, v, a, r, g, b;
828 a = input[3];
829 r = (input[0] * a) / 0xff;
830 g = (input[1] * a) / 0xff;
831 b = (input[2] * a) / 0xff;
833 RGB_TO_YUV(y, u, v, r, g, b);
835 output_y[output_column] = y;
836 output_u[output_column] = u;
837 output_v[output_column] = v;
840 static inline void transfer_RGBA888_to_YUV422(unsigned char *(*output),
841 unsigned char *input,
842 int j)
844 int y, u, v, a, r, g, b;
846 a = input[3];
847 r = (input[0] * a) / 0xff;
848 g = (input[1] * a) / 0xff;
849 b = (input[2] * a) / 0xff;
851 RGB_TO_YUV(y, u, v, r, g, b);
853 if(!(j & 1))
855 // Store U and V for even pixels only
856 (*output)[1] = u;
857 (*output)[3] = v;
858 (*output)[0] = y;
860 else
862 // Store Y and advance output for odd pixels only
863 (*output)[2] = y;
864 (*output) += 4;
881 // ******************************** RGB161616 -> *********************************
883 static inline void transfer_RGB161616_to_RGB8(unsigned char *(*output), uint16_t *input)
885 *(*output) = (unsigned char)(((input[0] & 0xc000) >> 8) +
886 ((input[1] & 0xe000) >> 10) +
887 ((input[2] & 0xe000) >> 13));
888 (*output)++;
891 static inline void transfer_RGB161616_to_BGR565(unsigned char *(*output), uint16_t *input)
893 uint16_t r, g, b;
894 r = *input++;
895 g = *input++;
896 b = *input;
897 *(uint16_t*)(*output) = (b & 0xf800) |
898 ((g & 0xfc00) >> 5) |
899 ((r & 0xf800) >> 11);
900 (*output) += 2;
903 static inline void transfer_RGB161616_to_RGB565(unsigned char *(*output), uint16_t *input)
905 uint16_t r, g, b;
906 r = *input++;
907 g = *input++;
908 b = *input;
909 *(uint16_t*)(*output) = (r & 0xf800) |
910 ((g & 0xfc00) >> 5) |
911 ((b & 0xf800) >> 11);
912 (*output) += 2;
915 static inline void transfer_RGB161616_to_BGR888(unsigned char *(*output), uint16_t *input)
917 (*output)[0] = input[2] >> 8;
918 (*output)[1] = input[1] >> 8;
919 (*output)[2] = input[0] >> 8;
920 (*output) += 3;
923 static inline void transfer_RGB161616_to_RGB888(unsigned char *(*output), uint16_t *input)
925 (*output)[0] = input[0] >> 8;
926 (*output)[1] = input[1] >> 8;
927 (*output)[2] = input[2] >> 8;
928 (*output) += 3;
931 static inline void transfer_RGB161616_to_RGBA8888(unsigned char *(*output), uint16_t *input)
933 (*output)[0] = input[0] >> 8;
934 (*output)[1] = input[1] >> 8;
935 (*output)[2] = input[2] >> 8;
936 (*output)[3] = 0xff;
937 (*output) += 4;
940 static inline void transfer_RGB161616_to_BGR8888(unsigned char *(*output), uint16_t *input)
942 (*output)[0] = input[2] >> 8;
943 (*output)[1] = input[1] >> 8;
944 (*output)[2] = input[0] >> 8;
945 (*output) += 4;
948 static inline void transfer_RGB161616_to_RGB_FLOAT(float *(*output), uint16_t *input)
950 *(*output)++ = (float)*input++ / 0xffff;
951 *(*output)++ = (float)*input++ / 0xffff;
952 *(*output)++ = (float)*input / 0xffff;
955 static inline void transfer_RGB161616_to_RGBA_FLOAT(float *(*output), uint16_t *input)
957 *(*output)++ = (float)*input++ / 0xffff;
958 *(*output)++ = (float)*input++ / 0xffff;
959 *(*output)++ = (float)*input / 0xffff;
960 *(*output)++ = 1.0;
963 static inline void transfer_RGB161616_to_YUV888(unsigned char *(*output), uint16_t *input)
965 int y, u, v, r, g, b;
966 r = input[0] >> 8;
967 g = input[1] >> 8;
968 b = input[2] >> 8;
970 RGB_TO_YUV(y, u, v, r, g, b);
972 (*output)[0] = y;
973 (*output)[1] = u;
974 (*output)[2] = v;
975 (*output) += 3;
978 static inline void transfer_RGB161616_to_YUVA8888(unsigned char *(*output), uint16_t *input)
980 int y, u, v, r, g, b;
982 r = input[0] >> 8;
983 g = input[1] >> 8;
984 b = input[2] >> 8;
986 RGB_TO_YUV(y, u, v, r, g, b);
988 (*output)[0] = y;
989 (*output)[1] = u;
990 (*output)[2] = v;
991 (*output)[3] = 255;
992 (*output) += 4;
995 static inline void transfer_RGB161616_to_YUV161616(uint16_t *(*output), uint16_t *input)
997 uint32_t y, u, v, r, g, b, a;
999 r = (uint32_t)input[0];
1000 g = (uint32_t)input[1];
1001 b = (uint32_t)input[2];
1003 RGB_TO_YUV16(y, u, v, r, g, b);
1005 (*output)[0] = y;
1006 (*output)[1] = u;
1007 (*output)[2] = v;
1008 (*output) += 3;
1011 static inline void transfer_RGB161616_to_YUVA16161616(uint16_t *(*output), uint16_t *input)
1013 uint32_t y, u, v, r, g, b;
1015 r = (uint32_t)input[0];
1016 g = (uint32_t)input[1];
1017 b = (uint32_t)input[2];
1019 RGB_TO_YUV16(y, u, v, r, g, b);
1021 (*output)[0] = y;
1022 (*output)[1] = u;
1023 (*output)[2] = v;
1024 (*output)[3] = 0xffff;
1025 (*output) += 4;
1028 static inline void transfer_RGB161616_to_YUV101010(unsigned char *(*output), uint16_t *input)
1030 int r, g, b;
1031 int y, u, v;
1033 r = input[0];
1034 g = input[1];
1035 b = input[2];
1036 RGB_TO_YUV16(y, u, v, r, g, b);
1037 WRITE_YUV101010(y, u, v);
1040 static inline void transfer_RGB161616_to_VYU888(unsigned char *(*output), uint16_t *input)
1042 int y, u, v, r, g, b;
1043 r = input[0] >> 8;
1044 g = input[1] >> 8;
1045 b = input[2] >> 8;
1047 RGB_TO_YUV(y, u, v, r, g, b);
1049 (*output)[0] = v;
1050 (*output)[1] = y;
1051 (*output)[2] = u;
1052 (*output) += 3;
1055 static inline void transfer_RGB161616_to_UYVA8888(unsigned char *(*output), uint16_t *input)
1057 int y, u, v, r, g, b;
1059 r = input[0] >> 8;
1060 g = input[1] >> 8;
1061 b = input[2] >> 8;
1063 RGB_TO_YUV(y, u, v, r, g, b);
1065 (*output)[0] = u;
1066 (*output)[1] = y;
1067 (*output)[2] = v;
1068 (*output)[3] = 0xff;
1069 (*output) += 4;
1073 static inline void transfer_RGB161616_to_YUV420P_YUV422P(unsigned char *output_y,
1074 unsigned char *output_u,
1075 unsigned char *output_v,
1076 uint16_t *input,
1077 int output_column)
1079 int y, u, v, r, g, b;
1080 r = input[0] >> 8;
1081 g = input[1] >> 8;
1082 b = input[2] >> 8;
1084 RGB_TO_YUV(y, u, v, r, g, b);
1086 output_y[output_column] = y;
1087 output_u[output_column / 2] = u;
1088 output_v[output_column / 2] = v;
1091 static inline void transfer_RGB161616_to_YUV444P(unsigned char *output_y,
1092 unsigned char *output_u,
1093 unsigned char *output_v,
1094 uint16_t *input,
1095 int output_column)
1097 int y, u, v, r, g, b;
1098 r = input[0] >> 8;
1099 g = input[1] >> 8;
1100 b = input[2] >> 8;
1102 RGB_TO_YUV(y, u, v, r, g, b);
1104 output_y[output_column] = y;
1105 output_u[output_column] = u;
1106 output_v[output_column] = v;
1110 // ****************************** RGBA16161616 -> *****************************
1112 static inline void transfer_RGBA16161616_to_RGB8(unsigned char *(*output), uint16_t *input)
1114 unsigned int r, g, b, a;
1115 a = (input)[3] >> 8;
1116 r = (unsigned int)(input)[0] * a;
1117 g = (unsigned int)(input)[1] * a;
1118 b = (unsigned int)(input)[2] * a;
1120 *(*output) = (unsigned char)(((r & 0xc00000) >> 16) +
1121 ((g & 0xe00000) >> 18) +
1122 ((b & 0xe00000) >> 21));
1123 (*output)++;
1126 static inline void transfer_RGBA16161616_to_BGR565(unsigned char *(*output), uint16_t *input)
1128 unsigned int r, g, b, a;
1129 a = (input)[3] >> 8;
1130 r = (unsigned int)(input)[0] * a;
1131 g = (unsigned int)(input)[1] * a;
1132 b = (unsigned int)(input)[2] * a;
1134 *(uint16_t*)(*output) = (uint16_t)(((b & 0xf80000) >> 8) +
1135 ((g & 0xfc0000) >> 13) +
1136 ((r & 0xf80000) >> 19));
1137 (*output) += 2;
1140 static inline void transfer_RGBA16161616_to_RGB565(unsigned char *(*output), uint16_t *input)
1142 unsigned int r, g, b, a;
1143 a = (input)[3] >> 8;
1144 r = (unsigned int)(input)[0] * a;
1145 g = (unsigned int)(input)[1] * a;
1146 b = (unsigned int)(input)[2] * a;
1148 *(uint16_t*)(*output) = (uint16_t)(((r & 0xf80000) >> 8) +
1149 ((g & 0xfc0000) >> 13) +
1150 ((b & 0xf80000) >> 19));
1151 (*output) += 2;
1154 static inline void transfer_RGBA16161616_to_BGR888(unsigned char *(*output), uint16_t *input)
1156 uint32_t r, g, b, a;
1157 a = input[3];
1158 r = (uint32_t)(input)[0] * a;
1159 g = (uint32_t)(input)[1] * a;
1160 b = (uint32_t)(input)[2] * a;
1162 // For display only
1163 (*output)[0] = (unsigned char)(b >> 24);
1164 (*output)[1] = (unsigned char)(g >> 24);
1165 (*output)[2] = (unsigned char)(r >> 24);
1166 (*output) += 3;
1169 static inline void transfer_RGBA16161616_to_RGB888(unsigned char *(*output), uint16_t *input)
1171 uint32_t r, g, b, a;
1172 a = input[3];
1173 r = (unsigned int)(input)[0] * a;
1174 g = (unsigned int)(input)[1] * a;
1175 b = (unsigned int)(input)[2] * a;
1177 (*output)[0] = (unsigned char)(r / 0xffffff);
1178 (*output)[1] = (unsigned char)(g / 0xffffff);
1179 (*output)[2] = (unsigned char)(b / 0xffffff);
1180 (*output) += 3;
1184 static inline void transfer_RGBA16161616_to_RGBA8888(unsigned char *(*output), uint16_t *input)
1186 (*output)[0] = input[0] >> 8;
1187 (*output)[1] = input[1] >> 8;
1188 (*output)[2] = input[2] >> 8;
1189 (*output)[3] = input[3] >> 8;
1190 (*output) += 4;
1194 static inline void transfer_RGBA16161616_to_BGR8888(unsigned char *(*output), uint16_t *input)
1196 uint32_t r, g, b, a;
1197 a = input[3];
1198 r = (input)[0] * a;
1199 g = (input)[1] * a;
1200 b = (input)[2] * a;
1202 // For display only
1203 (*output)[0] = (unsigned char)(b >> 24);
1204 (*output)[1] = (unsigned char)(g >> 24);
1205 (*output)[2] = (unsigned char)(r >> 24);
1206 (*output) += 4;
1209 static inline void transfer_RGBA16161616_to_RGB_FLOAT(float *(*output), uint16_t *input)
1211 float opacity = (float)input[3];
1212 *(*output)++ = (float)*input++ * opacity / 0xffff / 0xffff;
1213 *(*output)++ = (float)*input++ * opacity / 0xffff / 0xffff;
1214 *(*output)++ = (float)*input * opacity / 0xffff / 0xffff;
1217 static inline void transfer_RGBA16161616_to_RGBA_FLOAT(float *(*output), uint16_t *input)
1219 *(*output)++ = (float)*input++ / 0xffff;
1220 *(*output)++ = (float)*input++ / 0xffff;
1221 *(*output)++ = (float)*input++ / 0xffff;
1222 *(*output)++ = (float)*input / 0xffff;
1225 static inline void transfer_RGBA16161616_to_YUV888(unsigned char *(*output), uint16_t *input)
1227 uint32_t y, u, v, r, g, b, a;
1229 a = input[3];
1230 r = (uint32_t)input[0] * a / 0xffffff;
1231 g = (uint32_t)input[1] * a / 0xffffff;
1232 b = (uint32_t)input[2] * a / 0xffffff;
1234 RGB_TO_YUV(y, u, v, r, g, b);
1236 (*output)[0] = y;
1237 (*output)[1] = u;
1238 (*output)[2] = v;
1239 (*output) += 3;
1242 static inline void transfer_RGBA16161616_to_YUVA8888(unsigned char *(*output), uint16_t *input)
1244 int y, u, v, r, g, b;
1246 r = input[0] >> 8;
1247 g = input[1] >> 8;
1248 b = input[2] >> 8;
1250 RGB_TO_YUV(y, u, v, r, g, b);
1252 (*output)[0] = y;
1253 (*output)[1] = u;
1254 (*output)[2] = v;
1255 (*output)[3] = input[3] >> 8;
1256 (*output) += 4;
1259 static inline void transfer_RGBA16161616_to_YUV161616(uint16_t *(*output), uint16_t *input)
1261 uint32_t y, u, v, r, g, b, a;
1263 a = input[3];
1264 r = (uint32_t)input[0] * a / 0xffff;
1265 g = (uint32_t)input[1] * a / 0xffff;
1266 b = (uint32_t)input[2] * a / 0xffff;
1268 RGB_TO_YUV16(y, u, v, r, g, b);
1270 (*output)[0] = y;
1271 (*output)[1] = u;
1272 (*output)[2] = v;
1273 (*output) += 3;
1276 static inline void transfer_RGBA16161616_to_YUVA16161616(uint16_t *(*output), uint16_t *input)
1278 uint32_t y, u, v, r, g, b;
1280 r = (uint32_t)input[0];
1281 g = (uint32_t)input[1];
1282 b = (uint32_t)input[2];
1284 RGB_TO_YUV16(y, u, v, r, g, b);
1286 (*output)[0] = y;
1287 (*output)[1] = u;
1288 (*output)[2] = v;
1289 (*output)[3] = input[3];
1290 (*output) += 4;
1294 static inline void transfer_RGBA16161616_to_YUV101010(unsigned char *(*output), uint16_t *input)
1296 uint32_t r, g, b, a, y, u, v;
1298 a = input[3];
1299 r = (uint32_t)input[0] * a / 0xffff;
1300 g = (uint32_t)input[1] * a / 0xffff;
1301 b = (uint32_t)input[2] * a / 0xffff;
1302 RGB_TO_YUV16(y, u, v, r, g, b);
1303 WRITE_YUV101010(y, u, v);
1307 static inline void transfer_RGBA16161616_to_YUV420P_YUV422P(unsigned char *output_y,
1308 unsigned char *output_u,
1309 unsigned char *output_v,
1310 uint16_t *input,
1311 int output_column)
1313 uint32_t y, u, v, r, g, b, a;
1314 a = input[3];
1315 r = (int32_t)input[0] * a / 0xffffff;
1316 g = (int32_t)input[1] * a / 0xffffff;
1317 b = (int32_t)input[2] * a / 0xffffff;
1319 RGB_TO_YUV(y, u, v, r, g, b);
1321 output_y[output_column] = y;
1322 output_u[output_column / 2] = u;
1323 output_v[output_column / 2] = v;
1326 static inline void transfer_RGBA16161616_to_YUV444P(unsigned char *output_y,
1327 unsigned char *output_u,
1328 unsigned char *output_v,
1329 uint16_t *input,
1330 int output_column)
1332 uint32_t y, u, v, r, g, b, a;
1333 a = input[3];
1334 r = (int32_t)input[0] * a / 0xffffff;
1335 g = (int32_t)input[1] * a / 0xffffff;
1336 b = (int32_t)input[2] * a / 0xffffff;
1338 RGB_TO_YUV(y, u, v, r, g, b);
1340 output_y[output_column] = y;
1341 output_u[output_column] = u;
1342 output_v[output_column] = v;
1367 // ********************************** screen capture *****************************
1369 static inline void transfer_BGR8888_to_RGB888(unsigned char *(*output), unsigned char *input)
1371 *(*output)++ = input[2];
1372 *(*output)++ = input[1];
1373 *(*output)++ = input[0];
1376 static inline void transfer_BGR8888_to_BGR8888(unsigned char *(*output), unsigned char *input)
1378 *(*output)++ = input[0];
1379 *(*output)++ = input[1];
1380 *(*output)++ = input[2];
1381 (*output)++;
1384 static inline void transfer_BGR888_to_RGB888(unsigned char *(*output), unsigned char *input)
1386 *(*output)++ = input[2];
1387 *(*output)++ = input[1];
1388 *(*output)++ = input[0];
1397 // ******************************** YUV888 -> *********************************
1400 static inline void transfer_YUV888_to_RGB8(unsigned char *(*output), unsigned char *input)
1402 int y, u, v;
1403 int r, g, b;
1405 y = (input[0] << 16) | (input[0] << 8) | input[0];
1406 u = input[1];
1407 v = input[2];
1408 YUV_TO_RGB(y, u, v, r, g, b);
1410 *(*output) = (unsigned char)((r & 0xc0) +
1411 ((g & 0xe0) >> 2) +
1412 ((b & 0xe0) >> 5));
1413 (*output)++;
1416 static inline void transfer_YUV888_to_BGR565(unsigned char *(*output), unsigned char *input)
1418 int y, u, v;
1419 int r, g, b;
1421 y = (input[0] << 16) | (input[0] << 8) | input[0];
1422 u = input[1];
1423 v = input[2];
1424 YUV_TO_RGB(y, u, v, r, g, b);
1425 *(uint16_t*)(*output) = ((b & 0xf8) << 8)
1426 + ((g & 0xfc) << 3)
1427 + ((r & 0xf8) >> 3);
1428 (*output) += 2;
1431 static inline void transfer_YUV888_to_RGB565(unsigned char *(*output), unsigned char *input)
1433 int y, u, v;
1434 int r, g, b;
1436 y = (input[0] << 16) | (input[0] << 8) | input[0];
1437 u = input[1];
1438 v = input[2];
1439 YUV_TO_RGB(y, u, v, r, g, b);
1440 *(uint16_t*)(*output) = ((r & 0xf8) << 8)
1441 + ((g & 0xfc) << 3)
1442 + ((b & 0xf8) >> 3);
1443 (*output) += 2;
1446 static inline void transfer_YUV888_to_BGR888(unsigned char *(*output), unsigned char *input)
1448 int y, u, v;
1449 int r, g, b;
1451 y = (input[0] << 16) | (input[0] << 8) | input[0];
1452 u = input[1];
1453 v = input[2];
1454 YUV_TO_RGB(y, u, v, r, g, b);
1456 *(*output)++ = b;
1457 *(*output)++ = g;
1458 *(*output)++ = r;
1461 static inline void transfer_YUV888_to_BGR8888(unsigned char *(*output), unsigned char *input)
1463 int y, u, v;
1464 int r, g, b;
1466 y = (input[0] << 16) | (input[0] << 8) | input[0];
1467 u = input[1];
1468 v = input[2];
1469 YUV_TO_RGB(y, u, v, r, g, b);
1470 *(*output)++ = b;
1471 *(*output)++ = g;
1472 *(*output)++ = r;
1473 (*output)++;
1476 static inline void transfer_YUV888_to_RGB888(unsigned char *(*output), unsigned char *input)
1478 int y, u, v;
1479 int r, g, b;
1481 y = (input[0] << 16) | (input[0] << 8) | input[0];
1482 u = (int)input[1];
1483 v = (int)input[2];
1484 YUV_TO_RGB(y, u, v, r, g, b);
1486 *(*output)++ = r;
1487 *(*output)++ = g;
1488 *(*output)++ = b;
1491 static inline void transfer_YUV888_to_RGBA8888(unsigned char *(*output), unsigned char *input)
1493 int y, u, v;
1494 int r, g, b;
1496 y = (input[0] << 16) | (input[0] << 8) | input[0];
1497 u = input[1];
1498 v = input[2];
1499 YUV_TO_RGB(y, u, v, r, g, b);
1500 *(*output)++ = r;
1501 *(*output)++ = g;
1502 *(*output)++ = b;
1503 *(*output)++ = 0xff;
1506 static inline void transfer_YUV888_to_ARGB8888(unsigned char *(*output), unsigned char *input)
1508 int y, u, v;
1509 int r, g, b;
1511 y = (input[0] << 16) | (input[0] << 8) | input[0];
1512 u = input[1];
1513 v = input[2];
1514 YUV_TO_RGB(y, u, v, r, g, b);
1515 *(*output)++ = 0xff;
1516 *(*output)++ = r;
1517 *(*output)++ = g;
1518 *(*output)++ = b;
1521 static inline void transfer_YUV888_to_RGB_FLOAT(float *(*output), unsigned char *input)
1523 float y = (float)input[0] / 0xff;
1524 int u = input[1];
1525 int v = input[2];
1526 float r, g, b;
1528 YUV_TO_FLOAT(y, u, v, r, g, b);
1530 *(*output)++ = r;
1531 *(*output)++ = g;
1532 *(*output)++ = b;
1535 static inline void transfer_YUV888_to_RGBA_FLOAT(float *(*output), unsigned char *input)
1537 float y = (float)input[0] / 0xff;
1538 int u = input[1];
1539 int v = input[2];
1540 float r, g, b;
1542 YUV_TO_FLOAT(y, u, v, r, g, b);
1544 *(*output)++ = r;
1545 *(*output)++ = g;
1546 *(*output)++ = b;
1547 *(*output)++ = 1.0;
1550 static inline void transfer_YUV888_to_YUVA8888(unsigned char *(*output), unsigned char *input)
1552 *(*output)++ = (int)input[0];
1553 *(*output)++ = input[1];
1554 *(*output)++ = input[2];
1555 *(*output)++ = 0xff;
1558 static inline void transfer_YUV888_to_YUV888(unsigned char *(*output), unsigned char *input)
1560 (*output)[0] = (int)input[0];
1561 (*output)[1] = input[1];
1562 (*output)[2] = input[2];
1563 (*output) += 3;
1567 static inline void transfer_YUV888_to_VYU888(unsigned char *(*output), unsigned char *input)
1569 (*output)[0] = input[2];
1570 (*output)[1] = input[0];
1571 (*output)[2] = input[1];
1572 (*output) += 3;
1576 static inline void transfer_YUV888_to_UYVA8888(unsigned char *(*output), unsigned char *input)
1578 (*output)[0] = input[1];
1579 (*output)[1] = input[0];
1580 (*output)[2] = input[2];
1581 (*output)[3] = 0xff;
1582 (*output) += 4;
1586 static inline void transfer_YUV888_to_YUV101010(unsigned char *(*output), unsigned char *input)
1588 uint16_t y_i = ((uint16_t)input[0]) << 8;
1589 uint16_t u_i = ((uint16_t)input[1]) << 8;
1590 uint16_t v_i = ((uint16_t)input[2]) << 8;
1591 WRITE_YUV101010(y_i, u_i, v_i);
1594 static inline void transfer_YUV888_to_YUV420P_YUV422P(unsigned char *output_y,
1595 unsigned char *output_u,
1596 unsigned char *output_v,
1597 unsigned char *input,
1598 int output_column)
1600 output_y[output_column] = input[0];
1601 output_u[output_column / 2] = input[1];
1602 output_v[output_column / 2] = input[2];
1605 static inline void transfer_YUV888_to_YUV444P(unsigned char *output_y,
1606 unsigned char *output_u,
1607 unsigned char *output_v,
1608 unsigned char *input,
1609 int output_column)
1611 output_y[output_column] = input[0];
1612 output_u[output_column] = input[1];
1613 output_v[output_column] = input[2];
1616 static inline void transfer_YUV888_to_YUV422(unsigned char *(*output),
1617 unsigned char *input,
1618 int j)
1620 // Store U and V for even pixels only
1621 if(!(j & 1))
1623 (*output)[1] = input[1];
1624 (*output)[3] = input[2];
1625 (*output)[0] = input[0];
1627 else
1628 // Store Y and advance output for odd pixels only
1630 (*output)[2] = input[0];
1631 (*output) += 4;
1640 // ******************************** YUVA8888 -> *******************************
1645 static inline void transfer_YUVA8888_to_RGB8(unsigned char *(*output), unsigned char *input)
1647 int y, u, v, a;
1648 int r, g, b;
1650 a = input[3];
1651 y = (input[0] << 16) | (input[0] << 8) | input[0];
1652 u = input[1];
1653 v = input[2];
1654 YUV_TO_RGB(y, u, v, r, g, b);
1656 r *= a;
1657 g *= a;
1658 b *= a;
1660 *(*output) = (unsigned char)(((r & 0xc000) >> 8) +
1661 ((g & 0xe000) >> 10) +
1662 ((b & 0xe000) >> 13));
1663 (*output)++;
1666 static inline void transfer_YUVA8888_to_BGR565(unsigned char *(*output), unsigned char *input)
1668 int y, u, v, a;
1669 int r, g, b;
1671 a = input[3];
1672 y = (input[0] << 16) | (input[0] << 8) | input[0];
1673 u = input[1];
1674 v = input[2];
1675 YUV_TO_RGB(y, u, v, r, g, b);
1677 r *= a;
1678 g *= a;
1679 b *= a;
1681 *(uint16_t*)(*output) = (uint16_t)((b & 0xf800) +
1682 ((g & 0xfc00) >> 5) +
1683 ((r & 0xf800) >> 11));
1684 (*output) += 2;
1687 static inline void transfer_YUVA8888_to_RGB565(unsigned char *(*output), unsigned char *input)
1689 int y, u, v, a;
1690 int r, g, b;
1692 a = input[3];
1693 y = (input[0] << 16) | (input[0] << 8) | input[0];
1694 u = input[1];
1695 v = input[2];
1696 YUV_TO_RGB(y, u, v, r, g, b);
1698 r *= a;
1699 g *= a;
1700 b *= a;
1702 *(uint16_t*)(*output) = (uint16_t)((r & 0xf800) +
1703 ((g & 0xfc00) >> 5) +
1704 ((b & 0xf800) >> 11));
1705 (*output) += 2;
1708 static inline void transfer_YUVA8888_to_BGR888(unsigned char *(*output), unsigned char *input)
1710 int y, u, v, a;
1711 int r, g, b;
1713 a = input[3];
1714 y = (input[0] << 16) | (input[0] << 8) | input[0];
1715 u = input[1];
1716 v = input[2];
1718 YUV_TO_RGB(y, u, v, r, g, b);
1720 r *= a;
1721 g *= a;
1722 b *= a;
1724 *(*output)++ = b / 0xff;
1725 *(*output)++ = g / 0xff;
1726 *(*output)++ = r / 0xff;
1730 static inline void transfer_YUVA8888_to_BGR8888(unsigned char *(*output), unsigned char *input)
1732 int y, u, v, a;
1733 int r, g, b;
1735 a = input[3];
1736 y = (input[0] << 16) | (input[0] << 8) | input[0];
1737 u = input[1];
1738 v = input[2];
1740 YUV_TO_RGB(y, u, v, r, g, b);
1742 r *= a;
1743 g *= a;
1744 b *= a;
1745 *(*output)++ = b / 0xff;
1746 *(*output)++ = g / 0xff;
1747 *(*output)++ = r / 0xff;
1748 (*output)++;
1751 static inline void transfer_YUVA8888_to_RGB888(unsigned char *(*output), unsigned char *input)
1753 int y, u, v, a;
1754 int r, g, b;
1756 a = input[3];
1757 y = (input[0] << 16) | (input[0] << 8) | input[0];
1758 u = input[1];
1759 v = input[2];
1761 YUV_TO_RGB(y, u, v, r, g, b);
1763 r *= a;
1764 g *= a;
1765 b *= a;
1767 *(*output)++ = r / 0xff;
1768 *(*output)++ = g / 0xff;
1769 *(*output)++ = b / 0xff;
1772 static inline void transfer_YUVA8888_to_RGBA8888(unsigned char *(*output), unsigned char *input)
1774 int y, u, v, a;
1775 int r, g, b;
1777 a = input[3];
1778 y = (input[0] << 16) | (input[0] << 8) | input[0];
1779 u = input[1];
1780 v = input[2];
1782 YUV_TO_RGB(y, u, v, r, g, b);
1783 *(*output)++ = r;
1784 *(*output)++ = g;
1785 *(*output)++ = b;
1786 *(*output)++ = a;
1789 static inline void transfer_YUVA8888_to_ARGB8888(unsigned char *(*output), unsigned char *input)
1791 int y, u, v, a;
1792 int r, g, b;
1794 a = input[3];
1795 y = (input[0] << 16) | (input[0] << 8) | input[0];
1796 u = input[1];
1797 v = input[2];
1799 YUV_TO_RGB(y, u, v, r, g, b);
1800 *(*output)++ = a;
1801 *(*output)++ = r;
1802 *(*output)++ = g;
1803 *(*output)++ = b;
1806 static inline void transfer_YUVA8888_to_RGB_FLOAT(float *(*output), unsigned char *input)
1808 float y, a;
1809 int u, v;
1810 float r, g, b;
1812 a = (float)input[3] / 0xff;
1813 y = (float)input[0] / 0xff;
1814 u = input[1];
1815 v = input[2];
1817 YUV_TO_FLOAT(y, u, v, r, g, b);
1819 r *= a;
1820 g *= a;
1821 b *= a;
1823 *(*output)++ = r;
1824 *(*output)++ = g;
1825 *(*output)++ = b;
1828 static inline void transfer_YUVA8888_to_RGBA_FLOAT(float *(*output), unsigned char *input)
1830 float y = (float)input[0] / 0xff;
1831 int u, v;
1832 float r, g, b, a;
1834 a = (float)input[3] / 0xff;
1835 u = input[1];
1836 v = input[2];
1838 YUV_TO_FLOAT(y, u, v, r, g, b);
1840 *(*output)++ = r;
1841 *(*output)++ = g;
1842 *(*output)++ = b;
1843 *(*output)++ = a;
1847 static inline void transfer_YUVA8888_to_VYU888(unsigned char *(*output), unsigned char *input)
1849 int y, u, v, a, anti_a;
1850 a = input[3];
1851 anti_a = 0xff - a;
1852 y = ((uint32_t)input[0] * a) / 0xff;
1853 u = ((uint32_t)input[1] * a + 0x80 * anti_a) / 0xff;
1854 v = ((uint32_t)input[2] * a + 0x80 * anti_a) / 0xff;
1856 *(*output)++ = v;
1857 *(*output)++ = y;
1858 *(*output)++ = u;
1862 static inline void transfer_YUVA8888_to_YUVA8888(unsigned char *(*output), unsigned char *input)
1864 *(*output)++ = input[0];
1865 *(*output)++ = input[1];
1866 *(*output)++ = input[2];
1867 *(*output)++ = input[3];
1870 static inline void transfer_YUVA8888_to_UYVA8888(unsigned char *(*output), unsigned char *input)
1872 *(*output)++ = input[1];
1873 *(*output)++ = input[0];
1874 *(*output)++ = input[2];
1875 *(*output)++ = input[3];
1878 static inline void transfer_YUVA8888_to_YUV101010(unsigned char *(*output), unsigned char *input)
1880 uint16_t y_i = ((uint16_t)input[0] * input[3]) + 0x1fe;
1881 uint16_t u_i = ((uint16_t)input[1] * input[3]) + 0x1fe;
1882 uint16_t v_i = ((uint16_t)input[2] * input[3]) + 0x1fe;
1883 WRITE_YUV101010(y_i, u_i, v_i);
1887 static inline void transfer_YUVA8888_to_YUV420P_YUV422P(unsigned char *output_y,
1888 unsigned char *output_u,
1889 unsigned char *output_v,
1890 unsigned char *input,
1891 int output_column)
1893 int opacity = input[3];
1894 int transparency = 0xff - opacity;
1896 output_y[output_column] = ((input[0] * opacity) >> 8) + 1;
1897 output_u[output_column / 2] = ((input[1] * opacity + 0x80 * transparency) >> 8) + 1;
1898 output_v[output_column / 2] = ((input[2] * opacity + 0x80 * transparency) >> 8) + 1;
1901 static inline void transfer_YUVA8888_to_YUV444P(unsigned char *output_y,
1902 unsigned char *output_u,
1903 unsigned char *output_v,
1904 unsigned char *input,
1905 int output_column)
1907 int opacity = input[3];
1908 int transparency = 0xff - opacity;
1910 output_y[output_column] = ((input[0] * opacity) >> 8) + 1;
1911 output_u[output_column] = ((input[1] * opacity + 0x80 * transparency) >> 8) + 1;
1912 output_v[output_column] = ((input[2] * opacity + 0x80 * transparency) >> 8) + 1;
1915 static inline void transfer_YUVA8888_to_YUV422(unsigned char *(*output),
1916 unsigned char *input,
1917 int j)
1919 int opacity = input[3];
1920 int transparency = 0xff - opacity;
1921 // Store U and V for even pixels only
1922 if(!(j & 1))
1924 (*output)[0] = ((input[0] * opacity) >> 8) + 1;
1925 (*output)[1] = ((input[1] * opacity + 0x80 * transparency) >> 8) + 1;
1926 (*output)[3] = ((input[2] * opacity + 0x80 * transparency) >> 8) + 1;
1928 else
1929 // Store Y and advance output for odd pixels only
1931 (*output)[2] = ((input[0] * opacity) >> 8) + 1;
1932 (*output) += 4;
1945 // ******************************** YUV161616 -> ******************************
1948 static inline void transfer_YUV161616_to_RGB8(unsigned char *(*output), uint16_t *input)
1950 int y, u, v;
1951 int r, g, b;
1953 y = (((int)input[0]) << 8) | (input[0] >> 8);
1954 u = input[1] >> 8;
1955 v = input[2] >> 8;
1956 YUV_TO_RGB(y, u, v, r, g, b);
1958 *(*output) = (unsigned char)((r & 0xc0) +
1959 ((g & 0xe0) >> 2) +
1960 ((b & 0xe0) >> 5));
1961 (*output)++;
1964 static inline void transfer_YUV161616_to_BGR565(unsigned char *(*output), uint16_t *input)
1966 int y, u, v;
1967 int r, g, b;
1969 y = (((int)input[0]) << 8) | (input[0] >> 8);
1970 u = input[1] >> 8;
1971 v = input[2] >> 8;
1972 YUV_TO_RGB(y, u, v, r, g, b);
1973 *(uint16_t*)(*output) = ((b & 0xf8) << 8)
1974 + ((g & 0xfc) << 3)
1975 + ((r & 0xf8) >> 3);
1976 (*output) += 2;
1979 static inline void transfer_YUV161616_to_RGB565(unsigned char *(*output), uint16_t *input)
1981 int y, u, v;
1982 int r, g, b;
1984 y = (((int)input[0]) << 8) | (input[0] >> 8);
1985 u = input[1] >> 8;
1986 v = input[2] >> 8;
1987 YUV_TO_RGB(y, u, v, r, g, b);
1988 *(uint16_t*)(*output) = ((r & 0xf8) << 8)
1989 + ((g & 0xfc) << 3)
1990 + ((b & 0xf8) >> 3);
1991 (*output) += 2;
1994 static inline void transfer_YUV161616_to_BGR888(unsigned char *(*output), uint16_t *input)
1996 int y, u, v;
1997 int r, g, b;
1999 y = (((int)input[0]) << 8) | (input[0] >> 8);
2000 u = input[1];
2001 v = input[2];
2002 YUV_TO_RGB16(y, u, v, r, g, b);
2004 *(*output)++ = b >> 8;
2005 *(*output)++ = g >> 8;
2006 *(*output)++ = r >> 8;
2009 static inline void transfer_YUV161616_to_RGB888(unsigned char *(*output), uint16_t *input)
2011 int y, u, v;
2012 int r, g, b;
2014 y = (((int)input[0]) << 8) | (input[0] >> 8);
2015 u = input[1];
2016 v = input[2];
2017 YUV_TO_RGB16(y, u, v, r, g, b);
2019 *(*output)++ = r >> 8;
2020 *(*output)++ = g >> 8;
2021 *(*output)++ = b >> 8;
2024 static inline void transfer_YUV161616_to_RGBA8888(unsigned char *(*output), uint16_t *input)
2026 int y, u, v;
2027 int r, g, b;
2029 y = (((int)input[0]) << 8) | (input[0] >> 8);
2030 u = input[1];
2031 v = input[2];
2032 YUV_TO_RGB16(y, u, v, r, g, b);
2034 *(*output)++ = r >> 8;
2035 *(*output)++ = g >> 8;
2036 *(*output)++ = b >> 8;
2037 *(*output)++ = 0xff;
2040 static inline void transfer_YUV161616_to_ARGB8888(unsigned char *(*output), uint16_t *input)
2042 int y, u, v;
2043 int r, g, b;
2045 y = (((int)input[0]) << 8) | (input[0] >> 8);
2046 u = input[1];
2047 v = input[2];
2048 YUV_TO_RGB16(y, u, v, r, g, b);
2050 *(*output)++ = 0xff;
2051 *(*output)++ = r >> 8;
2052 *(*output)++ = g >> 8;
2053 *(*output)++ = b >> 8;
2056 static inline void transfer_YUV161616_to_RGB_FLOAT(float *(*output), uint16_t *input)
2058 float y = (float)input[0] / 0xffff;
2059 int u, v;
2060 float r, g, b;
2062 u = input[1];
2063 v = input[2];
2064 YUV16_TO_RGB_FLOAT(y, u, v, r, g, b);
2066 *(*output)++ = r;
2067 *(*output)++ = g;
2068 *(*output)++ = b;
2071 static inline void transfer_YUV161616_to_RGBA_FLOAT(float *(*output), uint16_t *input)
2073 float y = (float)input[0] / 0xffff;
2074 int u, v;
2075 float r, g, b;
2077 u = input[1];
2078 v = input[2];
2079 YUV16_TO_RGB_FLOAT(y, u, v, r, g, b);
2081 *(*output)++ = r;
2082 *(*output)++ = g;
2083 *(*output)++ = b;
2084 *(*output)++ = 1.0;
2087 static inline void transfer_YUV161616_to_BGR8888(unsigned char *(*output), uint16_t *input)
2089 int y, u, v;
2090 int r, g, b;
2092 y = (((int)input[0]) << 8) | (input[0] >> 8);
2093 u = input[1] >> 8;
2094 v = input[2] >> 8;
2095 YUV_TO_RGB(y, u, v, r, g, b);
2096 *(*output)++ = b;
2097 *(*output)++ = g;
2098 *(*output)++ = r;
2099 (*output)++;
2102 static inline void transfer_YUV161616_to_YUV161616(uint16_t *(*output), uint16_t *input)
2104 (*output)[0] = input[0];
2105 (*output)[1] = input[1];
2106 (*output)[2] = input[2];
2107 (*output) += 3;
2110 static inline void transfer_YUV161616_to_YUVA8888(unsigned char *(*output), uint16_t *input)
2112 (*output)[0] = input[0] >> 8;
2113 (*output)[1] = input[1] >> 8;
2114 (*output)[2] = input[2] >> 8;
2115 (*output)[3] = 255;
2116 (*output) += 4;
2120 static inline void transfer_YUV161616_to_VYU888(unsigned char *(*output), uint16_t *input)
2122 (*output)[0] = input[2] >> 8;
2123 (*output)[1] = input[0] >> 8;
2124 (*output)[2] = input[1] >> 8;
2125 (*output) += 3;
2129 static inline void transfer_YUV161616_to_UYVA8888(unsigned char *(*output), uint16_t *input)
2131 (*output)[0] = input[1] >> 8;
2132 (*output)[1] = input[0] >> 8;
2133 (*output)[2] = input[2] >> 8;
2134 (*output)[3] = input[3] >> 8;
2135 (*output) += 4;
2138 static inline void transfer_YUV161616_to_YUV101010(unsigned char *(*output), uint16_t *input)
2140 uint16_t y_i = input[0];
2141 uint16_t u_i = input[1];
2142 uint16_t v_i = input[2];
2143 WRITE_YUV101010(y_i, u_i, v_i);
2146 static inline void transfer_YUV161616_to_YUV420P_YUV422P(unsigned char *output_y,
2147 unsigned char *output_u,
2148 unsigned char *output_v,
2149 uint16_t *input,
2150 int output_column)
2152 output_y[output_column] = input[0] >> 8;
2153 output_u[output_column / 2] = input[1] >> 8;
2154 output_v[output_column / 2] = input[2] >> 8;
2157 static inline void transfer_YUV161616_to_YUV444P(unsigned char *output_y,
2158 unsigned char *output_u,
2159 unsigned char *output_v,
2160 uint16_t *input,
2161 int output_column)
2163 output_y[output_column] = input[0] >> 8;
2164 output_u[output_column] = input[1] >> 8;
2165 output_v[output_column] = input[2] >> 8;
2168 static inline void transfer_YUV161616_to_YUV422(unsigned char *(*output),
2169 uint16_t *input,
2170 int j)
2172 // Store U and V for even pixels only
2173 if(!(j & 1))
2175 (*output)[1] = input[1] >> 8;
2176 (*output)[3] = input[2] >> 8;
2177 (*output)[0] = input[0] >> 8;
2179 else
2180 // Store Y and advance output for odd pixels only
2182 (*output)[2] = input[0] >> 8;
2183 (*output) += 4;
2197 // ******************************** YUVA16161616 -> ***************************
2202 static inline void transfer_YUVA16161616_to_RGB8(unsigned char *(*output), uint16_t *input)
2204 int y, u, v, a;
2205 int r, g, b;
2207 a = input[3];
2208 y = (((int)input[0]) << 8) | (input[0] >> 8);
2209 u = input[1] >> 8;
2210 v = input[2] >> 8;
2211 YUV_TO_RGB(y, u, v, r, g, b);
2213 r *= a;
2214 g *= a;
2215 b *= a;
2217 *(*output) = (unsigned char)(((r & 0xc000) >> 8) +
2218 ((g & 0xe000) >> 10) +
2219 ((b & 0xe000) >> 13));
2220 (*output)++;
2223 static inline void transfer_YUVA16161616_to_BGR565(unsigned char *(*output), uint16_t *input)
2225 int y, u, v, a;
2226 int r, g, b;
2228 a = input[3] >> 8;
2229 y = (((int)input[0]) << 8) | (input[0] >> 8);
2230 u = input[1] >> 8;
2231 v = input[2] >> 8;
2232 YUV_TO_RGB(y, u, v, r, g, b);
2234 r *= a;
2235 g *= a;
2236 b *= a;
2238 *(uint16_t*)(*output) = (uint16_t)((b & 0xf800) +
2239 ((g & 0xfc00) >> 5) +
2240 ((r & 0xf800) >> 11));
2241 (*output) += 2;
2244 static inline void transfer_YUVA16161616_to_RGB565(unsigned char *(*output), uint16_t *input)
2246 int y, u, v, a;
2247 int r, g, b;
2249 a = input[3] >> 8;
2250 y = (((int)input[0]) << 8) | (input[0] >> 8);
2251 u = input[1] >> 8;
2252 v = input[2] >> 8;
2253 YUV_TO_RGB(y, u, v, r, g, b);
2255 r *= a;
2256 g *= a;
2257 b *= a;
2259 *(uint16_t*)(*output) = (uint16_t)((r & 0xf800) +
2260 ((g & 0xfc00) >> 5) +
2261 ((b & 0xf800) >> 11));
2262 (*output) += 2;
2265 static inline void transfer_YUVA16161616_to_BGR888(unsigned char *(*output), uint16_t *input)
2267 int y, u, v, a;
2268 int r, g, b;
2270 a = input[3];
2271 y = (((int)input[0]) << 8) | (input[0] >> 8);
2272 u = input[1];
2273 v = input[2];
2275 YUV_TO_RGB16(y, u, v, r, g, b);
2277 r *= a;
2278 g *= a;
2279 b *= a;
2281 *(*output)++ = b / 0xffff00;
2282 *(*output)++ = g / 0xffff00;
2283 *(*output)++ = r / 0xffff00;
2286 static inline void transfer_YUVA16161616_to_RGB888(unsigned char *(*output), uint16_t *input)
2288 unsigned int y, u, v, a;
2289 unsigned int r, g, b;
2291 a = input[3];
2292 y = (((int)input[0]) << 8) | (input[0] >> 8);
2293 u = input[1];
2294 v = input[2];
2296 YUV_TO_RGB16(y, u, v, r, g, b);
2298 r *= a;
2299 g *= a;
2300 b *= a;
2301 r /= 0xffff00;
2302 g /= 0xffff00;
2303 b /= 0xffff00;
2305 CLAMP(r, 0, 0xff);
2306 CLAMP(g, 0, 0xff);
2307 CLAMP(b, 0, 0xff);
2309 *(*output)++ = r;
2310 *(*output)++ = g;
2311 *(*output)++ = b;
2314 static inline void transfer_YUVA16161616_to_RGBA8888(unsigned char *(*output), uint16_t *input)
2316 unsigned int y, u, v;
2317 unsigned int r, g, b;
2319 y = (((int)input[0]) << 8) | (input[0] >> 8);
2320 u = input[1];
2321 v = input[2];
2323 YUV_TO_RGB16(y, u, v, r, g, b);
2325 *(*output)++ = (r >> 8);
2326 *(*output)++ = (g >> 8);
2327 *(*output)++ = (b >> 8);
2328 *(*output)++ = input[3] >> 8;
2331 static inline void transfer_YUVA16161616_to_ARGB8888(unsigned char *(*output), uint16_t *input)
2333 unsigned int y, u, v;
2334 unsigned int r, g, b;
2336 y = (((int)input[0]) << 8) | (input[0] >> 8);
2337 u = input[1];
2338 v = input[2];
2340 YUV_TO_RGB16(y, u, v, r, g, b);
2342 *(*output)++ = input[3] >> 8;
2343 *(*output)++ = (r >> 8);
2344 *(*output)++ = (g >> 8);
2345 *(*output)++ = (b >> 8);
2348 static inline void transfer_YUVA16161616_to_RGB_FLOAT(float *(*output),
2349 uint16_t *input)
2351 float y;
2352 int u, v;
2353 float r, g, b, a;
2355 y = (float)input[0] / 0xffff;
2356 u = input[1];
2357 v = input[2];
2358 a = (float)input[3] / 0xffff;
2360 YUV16_TO_RGB_FLOAT(y, u, v, r, g, b);
2362 r *= a;
2363 g *= a;
2364 b *= a;
2366 *(*output)++ = r;
2367 *(*output)++ = g;
2368 *(*output)++ = b;
2371 static inline void transfer_YUVA16161616_to_RGBA_FLOAT(float *(*output),
2372 uint16_t *input)
2374 float y;
2375 int u, v;
2376 float r, g, b, a;
2378 y = (float)input[0] / 0xffff;
2379 u = input[1];
2380 v = input[2];
2381 a = (float)input[3] / 0xffff;
2383 YUV16_TO_RGB_FLOAT(y, u, v, r, g, b);
2385 *(*output)++ = r;
2386 *(*output)++ = g;
2387 *(*output)++ = b;
2388 *(*output)++ = a;
2391 static inline void transfer_YUVA16161616_to_BGR8888(unsigned char *(*output),
2392 uint16_t *input)
2394 int y, u, v, a;
2395 int64_t r, g, b;
2397 a = input[3];
2398 y = (((int)input[0]) << 8) | (input[0] >> 8);
2399 u = input[1] >> 8;
2400 v = input[2] >> 8;
2402 YUV_TO_RGB(y, u, v, r, g, b);
2404 r *= a;
2405 g *= a;
2406 b *= a;
2407 b /= 0xffff;
2408 g /= 0xffff;
2409 r /= 0xffff;
2411 *(*output)++ = b;
2412 *(*output)++ = g;
2413 *(*output)++ = r;
2414 (*output)++;
2418 static inline void transfer_YUVA16161616_to_VYU888(unsigned char *(*output), uint16_t *input)
2420 int y, u, v, a, anti_a;
2421 a = input[3];
2422 anti_a = 0xffff - a;
2423 y = ((uint32_t)input[0] * a) / 0xffff00;
2424 u = ((uint32_t)input[1] * a + 0x8000 * anti_a) / 0xffff00;
2425 v = ((uint32_t)input[2] * a + 0x8000 * anti_a) / 0xffff00;
2427 *(*output)++ = v;
2428 *(*output)++ = y;
2429 *(*output)++ = u;
2433 static inline void transfer_YUVA16161616_to_YUVA16161616(uint16_t *(*output), uint16_t *input)
2435 (*output)[0] = input[0];
2436 (*output)[1] = input[1];
2437 (*output)[2] = input[2];
2438 (*output)[3] = input[3];
2439 (*output) += 4;
2442 static inline void transfer_YUVA16161616_to_UYVA8888(unsigned char *(*output), uint16_t *input)
2444 (*output)[0] = input[1] >> 8;
2445 (*output)[1] = input[0] >> 8;
2446 (*output)[2] = input[2] >> 8;
2447 (*output)[3] = input[3] >> 8;
2448 (*output) += 4;
2452 static inline void transfer_YUVA16161616_to_YUV101010(unsigned char *(*output), uint16_t *input)
2454 int64_t opacity = input[3];
2455 int64_t transparency = 0xffff - opacity;
2456 uint16_t y_i = ((int64_t)input[0] * opacity + (int64_t)0x8000 * transparency) / 0xffff;
2457 uint16_t u_i = ((int64_t)input[1] * opacity + (int64_t)0x8000 * transparency) / 0xffff;
2458 uint16_t v_i = ((int64_t)input[2] * opacity + (int64_t)0x8000 * transparency) / 0xffff;
2459 WRITE_YUV101010(y_i, u_i, v_i);
2462 static inline void transfer_YUVA16161616_to_YUV420P_YUV422P(unsigned char *output_y,
2463 unsigned char *output_u,
2464 unsigned char *output_v,
2465 uint16_t *input,
2466 int output_column)
2468 int64_t opacity = input[3];
2469 int64_t transparency = 0xffff - opacity;
2471 output_y[output_column] = ((int64_t)input[0] * opacity) / 0xffff00;
2472 output_u[output_column / 2] = ((int64_t)input[1] * opacity + 0x8000 * transparency) / 0xffff00;
2473 output_v[output_column / 2] = ((int64_t)input[2] * opacity + 0x8000 * transparency) / 0xffff00;
2476 static inline void transfer_YUVA16161616_to_YUV444P(unsigned char *output_y,
2477 unsigned char *output_u,
2478 unsigned char *output_v,
2479 uint16_t *input,
2480 int output_column)
2482 int64_t opacity = input[3];
2483 int64_t transparency = 0xffff - opacity;
2485 output_y[output_column] = ((int64_t)input[0] * opacity) / 0xffff00;
2486 output_u[output_column] = ((int64_t)input[1] * opacity + 0x8000 * transparency) / 0xffff00;
2487 output_v[output_column] = ((int64_t)input[2] * opacity + 0x8000 * transparency) / 0xffff00;
2490 static inline void transfer_YUVA16161616_to_YUV422(unsigned char *(*output),
2491 uint16_t *input,
2492 int j)
2494 int64_t opacity = input[3];
2495 int64_t transparency = 0xffff - opacity;
2497 // Store U and V for even pixels only
2498 if(!(j & 1))
2500 (*output)[0] = ((int64_t)input[0] * opacity) / 0xffff00;
2501 (*output)[1] = ((int64_t)input[1] * opacity + 0x8000 * transparency) / 0xffff00;
2502 (*output)[3] = ((int64_t)input[2] * opacity + 0x8000 * transparency) / 0xffff00;
2504 else
2505 // Store Y and advance output for odd pixels only
2507 (*output)[2] = (input[0] * opacity) / 0xffff00;
2508 (*output) += 4;
2552 // ******************************** Loops *************************************
2554 #define TRANSFER_FRAME_HEAD \
2555 for(i = 0; i < out_h; i++) \
2557 unsigned char *output_row = output_rows[i + out_y] + out_x * out_pixelsize; \
2558 unsigned char *input_row = input_rows[row_table[i]]; \
2559 int bit_counter = 7; \
2560 for(j = 0; j < out_w; j++) \
2563 #define TRANSFER_FRAME_TAIL \
2567 #define TRANSFER_YUV420P_OUT_HEAD \
2568 for(i = 0; i < out_h; i++) \
2570 unsigned char *input_row = input_rows[row_table[i]]; \
2571 unsigned char *output_y = out_y_plane + i * total_out_w + out_x; \
2572 unsigned char *output_u = out_u_plane + i / 2 * total_out_w / 2 + out_x / 2; \
2573 unsigned char *output_v = out_v_plane + i / 2 * total_out_w / 2 + out_x / 2; \
2574 for(j = 0; j < out_w; j++) \
2577 #define TRANSFER_YUV422P_OUT_HEAD \
2578 for(i = 0; i < out_h; i++) \
2580 unsigned char *input_row = input_rows[row_table[i]]; \
2581 unsigned char *output_y = out_y_plane + i * total_out_w + out_x; \
2582 unsigned char *output_u = out_u_plane + i * total_out_w / 2 + out_x / 2; \
2583 unsigned char *output_v = out_v_plane + i * total_out_w / 2 + out_x / 2; \
2584 for(j = 0; j < out_w; j++) \
2587 #define TRANSFER_YUV444P_OUT_HEAD \
2588 for(i = 0; i < out_h; i++) \
2590 unsigned char *input_row = input_rows[row_table[i]]; \
2591 unsigned char *output_y = out_y_plane + i * total_out_w + out_x; \
2592 unsigned char *output_u = out_u_plane + i * total_out_w + out_x; \
2593 unsigned char *output_v = out_v_plane + i * total_out_w + out_x; \
2594 for(j = 0; j < out_w; j++) \
2597 #define TRANSFER_YUV420P_IN_HEAD \
2598 for(i = 0; i < out_h; i++) \
2600 unsigned char *output_row = output_rows[i + out_y] + out_x * out_pixelsize; \
2601 unsigned char *input_y = in_y_plane + row_table[i] * total_in_w; \
2602 unsigned char *input_u = in_u_plane + (row_table[i] / 2) * (total_in_w / 2); \
2603 unsigned char *input_v = in_v_plane + (row_table[i] / 2) * (total_in_w / 2); \
2604 for(j = 0; j < out_w; j++) \
2607 #define TRANSFER_YUV9P_IN_HEAD \
2608 for(i = 0; i < out_h; i++) \
2610 unsigned char *output_row = output_rows[i + out_y] + out_x * out_pixelsize; \
2611 unsigned char *input_y = in_y_plane + row_table[i] * total_in_w; \
2612 unsigned char *input_u = in_u_plane + (row_table[i] / 4) * (total_in_w / 4); \
2613 unsigned char *input_v = in_v_plane + (row_table[i] / 4) * (total_in_w / 4); \
2614 for(j = 0; j < out_w; j++) \
2618 #define TRANSFER_YUV422P_IN_HEAD \
2619 for(i = 0; i < out_h; i++) \
2621 unsigned char *output_row = output_rows[i + out_y] + out_x * out_pixelsize; \
2622 unsigned char *input_y = in_y_plane + row_table[i] * total_in_w; \
2623 unsigned char *input_u = in_u_plane + row_table[i] * (total_in_w / 2); \
2624 unsigned char *input_v = in_v_plane + row_table[i] * (total_in_w / 2); \
2625 for(j = 0; j < out_w; j++) \
2628 #define TRANSFER_YUV444P_IN_HEAD \
2629 for(i = 0; i < out_h; i++) \
2631 unsigned char *output_row = output_rows[i + out_y] + out_x * out_pixelsize; \
2632 unsigned char *input_y = in_y_plane + row_table[i] * total_in_w; \
2633 unsigned char *input_u = in_u_plane + row_table[i] * total_in_w; \
2634 unsigned char *input_v = in_v_plane + row_table[i] * total_in_w; \
2635 for(j = 0; j < out_w; j++) \
2639 #define TRANSFER_YUV422_IN_HEAD \
2640 for(i = 0; i < out_h; i++) \
2642 unsigned char *output_row = output_rows[i + out_y] + ((out_x * out_pixelsize) & 0xfffffffc); \
2643 unsigned char *input_y = in_y_plane + row_table[i] * total_in_w; \
2644 unsigned char *input_u = in_u_plane + row_table[i] * (total_in_w / 2); \
2645 unsigned char *input_v = in_v_plane + row_table[i] * (total_in_w / 2); \
2646 for(j = 0; j < out_w; j++) \
2653 // ******************************** Permutation *******************************
2657 #define PERMUTATION_ARGS \
2658 unsigned char **output_rows, \
2659 unsigned char **input_rows, \
2660 unsigned char *out_y_plane, \
2661 unsigned char *out_u_plane, \
2662 unsigned char *out_v_plane, \
2663 unsigned char *in_y_plane, \
2664 unsigned char *in_u_plane, \
2665 unsigned char *in_v_plane, \
2666 int in_x, \
2667 int in_y, \
2668 int in_w, \
2669 int in_h, \
2670 int out_x, \
2671 int out_y, \
2672 int out_w, \
2673 int out_h, \
2674 int in_colormodel, \
2675 int out_colormodel, \
2676 int bg_color, \
2677 int total_in_w, \
2678 int total_out_w, \
2679 int scale, \
2680 int out_pixelsize, \
2681 int in_pixelsize, \
2682 int *row_table, \
2683 int *column_table, \
2684 int bg_r, \
2685 int bg_g, \
2686 int bg_b