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.
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
17 #include "colormodels.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) \
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); \
35 #define YUV_TO_FLOAT(y, u, v, r, g, b) \
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]; \
45 #define YUV16_TO_RGB_FLOAT(y, u, v, r, g, b) \
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) \
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) \
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); \
77 #define RGB_TO_YUV16(y, u, v, r, g, b) \
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) \
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];
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];
128 static inline void transfer_ARGB8888_to_RGB888(unsigned char *(*output
), unsigned char *input
)
131 (*output
)[0] = input
[1] * a
/ 0xff;
132 (*output
)[1] = input
[2] * a
/ 0xff;
133 (*output
)[2] = input
[3] * a
/ 0xff;
137 static inline void transfer_ARGB8888_to_BGR8888(unsigned char *(*output
), unsigned char *input
)
140 (*output
)[0] = input
[3] * a
/ 0xff;
141 (*output
)[1] = input
[2] * a
/ 0xff;
142 (*output
)[2] = input
[1] * a
/ 0xff;
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));
170 static inline void transfer_RGB888_to_BGR565(unsigned char *(*output
), unsigned char *input
)
173 uint16_t r_s
, g_s
, b_s
;
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);
211 static inline void transfer_RGB888_to_RGB565(unsigned char *(*output
), unsigned char *input
)
217 *(uint16_t*)(*output
) = ((r
& 0xf8) << 8)
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
;
245 static inline void transfer_RGB888_to_ARGB8888(unsigned char *(*output
), unsigned char *input
)
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];
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;
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;
285 static inline void transfer_RGB888_to_ABGR8888(unsigned char *(*output
), unsigned char *input
)
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];
301 static inline void transfer_RGB888_to_YUV888(unsigned char *(*output
), unsigned char *input
)
305 RGB_TO_YUV(y
, u
, v
, input
[0], input
[1], input
[2]);
313 static inline void transfer_RGB888_to_YUV101010(unsigned char *(*output
), unsigned char *input
)
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
)
329 RGB_TO_YUV(y
, u
, v
, input
[0], input
[1], input
[2]);
336 static inline void transfer_RGB888_to_UYVA8888(unsigned char *(*output
), unsigned char *input
)
340 RGB_TO_YUV(y
, u
, v
, input
[0], input
[1], input
[2]);
350 static inline void transfer_RGB888_to_YUVA8888(unsigned char *(*output
), unsigned char *input
)
354 RGB_TO_YUV(y
, u
, v
, input
[0], input
[1], input
[2]);
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
);
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
);
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
,
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
,
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
,
428 RGB_TO_YUV(y
, u
, v
, input
[0], input
[1], input
[2]);
432 // Store U and V for even pixels only
439 // Store Y and advance output for odd pixels only
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;
460 *(*output
) |= (unsigned char)1 << (7 - (*bit_counter
));
463 if((*bit_counter
) == 0)
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
;
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) +
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
;
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) +
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
;
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)+
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
;
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;
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
;
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;
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
;
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;
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
;
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));
580 static inline void transfer_RGBA8888_to_BGR565(unsigned char *(*output
), unsigned char *input
)
582 unsigned int r
, g
, b
, a
;
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) +
593 static inline void transfer_RGBA8888_to_RGB565(unsigned char *(*output
), unsigned char *input
)
595 unsigned int r
, g
, b
, a
;
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) +
608 static inline void transfer_RGBA8888_to_BGR888(unsigned char *(*output
), unsigned char *input
)
610 unsigned int r
, g
, b
, a
;
612 r
= ((unsigned int)input
[0] * a
) / 0xff;
613 g
= ((unsigned int)input
[1] * a
) / 0xff;
614 b
= ((unsigned int)input
[2] * a
) / 0xff;
620 static inline void transfer_RGBA8888_to_RGB888(unsigned char *(*output
), unsigned char *input
)
622 unsigned int r
, g
, b
, a
;
624 r
= ((unsigned int)input
[0] * a
) / 0xff;
625 g
= ((unsigned int)input
[1] * a
) / 0xff;
626 b
= ((unsigned int)input
[2] * a
) / 0xff;
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];
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];
650 static inline void transfer_RGBA8888_to_RGB161616(uint16_t *(*output
), unsigned char *input
)
652 int y
, u
, v
, opacity
, r
, g
, b
;
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;
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];
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
;
692 r
= ((unsigned int)input
[0] * a
) / 0xff;
693 g
= ((unsigned int)input
[1] * a
) / 0xff;
694 b
= ((unsigned int)input
[2] * a
) / 0xff;
701 static inline void transfer_RGBA8888_to_YUV888(unsigned char *(*output
), unsigned char *input
)
703 int y
, u
, v
, a
, r
, g
, b
;
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]);
717 static inline void transfer_RGBA8888_to_YUVA8888(unsigned char *(*output
), unsigned char *input
)
721 RGB_TO_YUV(y
, u
, v
, input
[0], input
[1], input
[2]);
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
;
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
);
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
);
757 *(*output
)++ = (((int)input
[3]) << 8) | input
[3];
760 static inline void transfer_RGBA8888_to_YUV101010(unsigned char *(*output
), unsigned char *input
)
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
;
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]);
788 static inline void transfer_RGBA8888_to_UYVA8888(unsigned char *(*output
), unsigned char *input
)
792 RGB_TO_YUV(y
, u
, v
, input
[0], input
[1], input
[2]);
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
,
806 int y
, u
, v
, a
, r
, g
, b
;
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
,
826 int y
, u
, v
, a
, r
, g
, b
;
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
,
844 int y
, u
, v
, a
, r
, g
, b
;
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
);
855 // Store U and V for even pixels only
862 // Store Y and advance output for odd pixels only
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));
891 static inline void transfer_RGB161616_to_BGR565(unsigned char *(*output
), uint16_t *input
)
897 *(uint16_t*)(*output
) = (b
& 0xf800) |
898 ((g
& 0xfc00) >> 5) |
899 ((r
& 0xf800) >> 11);
903 static inline void transfer_RGB161616_to_RGB565(unsigned char *(*output
), uint16_t *input
)
909 *(uint16_t*)(*output
) = (r
& 0xf800) |
910 ((g
& 0xfc00) >> 5) |
911 ((b
& 0xf800) >> 11);
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;
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;
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;
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;
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;
963 static inline void transfer_RGB161616_to_YUV888(unsigned char *(*output
), uint16_t *input
)
965 int y
, u
, v
, r
, g
, b
;
970 RGB_TO_YUV(y
, u
, v
, r
, g
, b
);
978 static inline void transfer_RGB161616_to_YUVA8888(unsigned char *(*output
), uint16_t *input
)
980 int y
, u
, v
, r
, g
, b
;
986 RGB_TO_YUV(y
, u
, v
, r
, g
, b
);
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
);
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
);
1024 (*output
)[3] = 0xffff;
1028 static inline void transfer_RGB161616_to_YUV101010(unsigned char *(*output
), uint16_t *input
)
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
;
1047 RGB_TO_YUV(y
, u
, v
, r
, g
, b
);
1055 static inline void transfer_RGB161616_to_UYVA8888(unsigned char *(*output
), uint16_t *input
)
1057 int y
, u
, v
, r
, g
, b
;
1063 RGB_TO_YUV(y
, u
, v
, r
, g
, b
);
1068 (*output
)[3] = 0xff;
1073 static inline void transfer_RGB161616_to_YUV420P_YUV422P(unsigned char *output_y
,
1074 unsigned char *output_u
,
1075 unsigned char *output_v
,
1079 int y
, u
, v
, r
, g
, b
;
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
,
1097 int y
, u
, v
, r
, g
, b
;
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));
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));
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));
1154 static inline void transfer_RGBA16161616_to_BGR888(unsigned char *(*output
), uint16_t *input
)
1156 uint32_t r
, g
, b
, a
;
1158 r
= (uint32_t)(input
)[0] * a
;
1159 g
= (uint32_t)(input
)[1] * a
;
1160 b
= (uint32_t)(input
)[2] * a
;
1163 (*output
)[0] = (unsigned char)(b
>> 24);
1164 (*output
)[1] = (unsigned char)(g
>> 24);
1165 (*output
)[2] = (unsigned char)(r
>> 24);
1169 static inline void transfer_RGBA16161616_to_RGB888(unsigned char *(*output
), uint16_t *input
)
1171 uint32_t r
, g
, b
, a
;
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);
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;
1194 static inline void transfer_RGBA16161616_to_BGR8888(unsigned char *(*output
), uint16_t *input
)
1196 uint32_t r
, g
, b
, a
;
1203 (*output
)[0] = (unsigned char)(b
>> 24);
1204 (*output
)[1] = (unsigned char)(g
>> 24);
1205 (*output
)[2] = (unsigned char)(r
>> 24);
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
;
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
);
1242 static inline void transfer_RGBA16161616_to_YUVA8888(unsigned char *(*output
), uint16_t *input
)
1244 int y
, u
, v
, r
, g
, b
;
1250 RGB_TO_YUV(y
, u
, v
, r
, g
, b
);
1255 (*output
)[3] = input
[3] >> 8;
1259 static inline void transfer_RGBA16161616_to_YUV161616(uint16_t *(*output
), uint16_t *input
)
1261 uint32_t y
, u
, v
, r
, g
, b
, a
;
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
);
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
);
1289 (*output
)[3] = input
[3];
1294 static inline void transfer_RGBA16161616_to_YUV101010(unsigned char *(*output
), uint16_t *input
)
1296 uint32_t r
, g
, b
, a
, y
, u
, v
;
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
,
1313 uint32_t y
, u
, v
, r
, g
, b
, a
;
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
,
1332 uint32_t y
, u
, v
, r
, g
, b
, a
;
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];
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
)
1405 y
= (input
[0] << 16) | (input
[0] << 8) | input
[0];
1408 YUV_TO_RGB(y
, u
, v
, r
, g
, b
);
1410 *(*output
) = (unsigned char)((r
& 0xc0) +
1416 static inline void transfer_YUV888_to_BGR565(unsigned char *(*output
), unsigned char *input
)
1421 y
= (input
[0] << 16) | (input
[0] << 8) | input
[0];
1424 YUV_TO_RGB(y
, u
, v
, r
, g
, b
);
1425 *(uint16_t*)(*output
) = ((b
& 0xf8) << 8)
1427 + ((r
& 0xf8) >> 3);
1431 static inline void transfer_YUV888_to_RGB565(unsigned char *(*output
), unsigned char *input
)
1436 y
= (input
[0] << 16) | (input
[0] << 8) | input
[0];
1439 YUV_TO_RGB(y
, u
, v
, r
, g
, b
);
1440 *(uint16_t*)(*output
) = ((r
& 0xf8) << 8)
1442 + ((b
& 0xf8) >> 3);
1446 static inline void transfer_YUV888_to_BGR888(unsigned char *(*output
), unsigned char *input
)
1451 y
= (input
[0] << 16) | (input
[0] << 8) | input
[0];
1454 YUV_TO_RGB(y
, u
, v
, r
, g
, b
);
1461 static inline void transfer_YUV888_to_BGR8888(unsigned char *(*output
), unsigned char *input
)
1466 y
= (input
[0] << 16) | (input
[0] << 8) | input
[0];
1469 YUV_TO_RGB(y
, u
, v
, r
, g
, b
);
1476 static inline void transfer_YUV888_to_RGB888(unsigned char *(*output
), unsigned char *input
)
1481 y
= (input
[0] << 16) | (input
[0] << 8) | input
[0];
1484 YUV_TO_RGB(y
, u
, v
, r
, g
, b
);
1491 static inline void transfer_YUV888_to_RGBA8888(unsigned char *(*output
), unsigned char *input
)
1496 y
= (input
[0] << 16) | (input
[0] << 8) | input
[0];
1499 YUV_TO_RGB(y
, u
, v
, r
, g
, b
);
1503 *(*output
)++ = 0xff;
1506 static inline void transfer_YUV888_to_ARGB8888(unsigned char *(*output
), unsigned char *input
)
1511 y
= (input
[0] << 16) | (input
[0] << 8) | input
[0];
1514 YUV_TO_RGB(y
, u
, v
, r
, g
, b
);
1515 *(*output
)++ = 0xff;
1521 static inline void transfer_YUV888_to_RGB_FLOAT(float *(*output
), unsigned char *input
)
1523 float y
= (float)input
[0] / 0xff;
1528 YUV_TO_FLOAT(y
, u
, v
, r
, g
, b
);
1535 static inline void transfer_YUV888_to_RGBA_FLOAT(float *(*output
), unsigned char *input
)
1537 float y
= (float)input
[0] / 0xff;
1542 YUV_TO_FLOAT(y
, u
, v
, r
, g
, b
);
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];
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];
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;
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
,
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
,
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
,
1620 // Store U and V for even pixels only
1623 (*output
)[1] = input
[1];
1624 (*output
)[3] = input
[2];
1625 (*output
)[0] = input
[0];
1628 // Store Y and advance output for odd pixels only
1630 (*output
)[2] = input
[0];
1640 // ******************************** YUVA8888 -> *******************************
1645 static inline void transfer_YUVA8888_to_RGB8(unsigned char *(*output
), unsigned char *input
)
1651 y
= (input
[0] << 16) | (input
[0] << 8) | input
[0];
1654 YUV_TO_RGB(y
, u
, v
, r
, g
, b
);
1660 *(*output
) = (unsigned char)(((r
& 0xc000) >> 8) +
1661 ((g
& 0xe000) >> 10) +
1662 ((b
& 0xe000) >> 13));
1666 static inline void transfer_YUVA8888_to_BGR565(unsigned char *(*output
), unsigned char *input
)
1672 y
= (input
[0] << 16) | (input
[0] << 8) | input
[0];
1675 YUV_TO_RGB(y
, u
, v
, r
, g
, b
);
1681 *(uint16_t*)(*output
) = (uint16_t)((b
& 0xf800) +
1682 ((g
& 0xfc00) >> 5) +
1683 ((r
& 0xf800) >> 11));
1687 static inline void transfer_YUVA8888_to_RGB565(unsigned char *(*output
), unsigned char *input
)
1693 y
= (input
[0] << 16) | (input
[0] << 8) | input
[0];
1696 YUV_TO_RGB(y
, u
, v
, r
, g
, b
);
1702 *(uint16_t*)(*output
) = (uint16_t)((r
& 0xf800) +
1703 ((g
& 0xfc00) >> 5) +
1704 ((b
& 0xf800) >> 11));
1708 static inline void transfer_YUVA8888_to_BGR888(unsigned char *(*output
), unsigned char *input
)
1714 y
= (input
[0] << 16) | (input
[0] << 8) | input
[0];
1718 YUV_TO_RGB(y
, u
, v
, r
, g
, b
);
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
)
1736 y
= (input
[0] << 16) | (input
[0] << 8) | input
[0];
1740 YUV_TO_RGB(y
, u
, v
, r
, g
, b
);
1745 *(*output
)++ = b
/ 0xff;
1746 *(*output
)++ = g
/ 0xff;
1747 *(*output
)++ = r
/ 0xff;
1751 static inline void transfer_YUVA8888_to_RGB888(unsigned char *(*output
), unsigned char *input
)
1757 y
= (input
[0] << 16) | (input
[0] << 8) | input
[0];
1761 YUV_TO_RGB(y
, u
, v
, r
, g
, b
);
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
)
1778 y
= (input
[0] << 16) | (input
[0] << 8) | input
[0];
1782 YUV_TO_RGB(y
, u
, v
, r
, g
, b
);
1789 static inline void transfer_YUVA8888_to_ARGB8888(unsigned char *(*output
), unsigned char *input
)
1795 y
= (input
[0] << 16) | (input
[0] << 8) | input
[0];
1799 YUV_TO_RGB(y
, u
, v
, r
, g
, b
);
1806 static inline void transfer_YUVA8888_to_RGB_FLOAT(float *(*output
), unsigned char *input
)
1812 a
= (float)input
[3] / 0xff;
1813 y
= (float)input
[0] / 0xff;
1817 YUV_TO_FLOAT(y
, u
, v
, r
, g
, b
);
1828 static inline void transfer_YUVA8888_to_RGBA_FLOAT(float *(*output
), unsigned char *input
)
1830 float y
= (float)input
[0] / 0xff;
1834 a
= (float)input
[3] / 0xff;
1838 YUV_TO_FLOAT(y
, u
, v
, r
, g
, b
);
1847 static inline void transfer_YUVA8888_to_VYU888(unsigned char *(*output
), unsigned char *input
)
1849 int y
, u
, v
, a
, anti_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;
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
,
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
,
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
,
1919 int opacity
= input
[3];
1920 int transparency
= 0xff - opacity
;
1921 // Store U and V for even pixels only
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;
1929 // Store Y and advance output for odd pixels only
1931 (*output
)[2] = ((input
[0] * opacity
) >> 8) + 1;
1945 // ******************************** YUV161616 -> ******************************
1948 static inline void transfer_YUV161616_to_RGB8(unsigned char *(*output
), uint16_t *input
)
1953 y
= (((int)input
[0]) << 8) | (input
[0] >> 8);
1956 YUV_TO_RGB(y
, u
, v
, r
, g
, b
);
1958 *(*output
) = (unsigned char)((r
& 0xc0) +
1964 static inline void transfer_YUV161616_to_BGR565(unsigned char *(*output
), uint16_t *input
)
1969 y
= (((int)input
[0]) << 8) | (input
[0] >> 8);
1972 YUV_TO_RGB(y
, u
, v
, r
, g
, b
);
1973 *(uint16_t*)(*output
) = ((b
& 0xf8) << 8)
1975 + ((r
& 0xf8) >> 3);
1979 static inline void transfer_YUV161616_to_RGB565(unsigned char *(*output
), uint16_t *input
)
1984 y
= (((int)input
[0]) << 8) | (input
[0] >> 8);
1987 YUV_TO_RGB(y
, u
, v
, r
, g
, b
);
1988 *(uint16_t*)(*output
) = ((r
& 0xf8) << 8)
1990 + ((b
& 0xf8) >> 3);
1994 static inline void transfer_YUV161616_to_BGR888(unsigned char *(*output
), uint16_t *input
)
1999 y
= (((int)input
[0]) << 8) | (input
[0] >> 8);
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
)
2014 y
= (((int)input
[0]) << 8) | (input
[0] >> 8);
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
)
2029 y
= (((int)input
[0]) << 8) | (input
[0] >> 8);
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
)
2045 y
= (((int)input
[0]) << 8) | (input
[0] >> 8);
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;
2064 YUV16_TO_RGB_FLOAT(y
, u
, v
, r
, g
, b
);
2071 static inline void transfer_YUV161616_to_RGBA_FLOAT(float *(*output
), uint16_t *input
)
2073 float y
= (float)input
[0] / 0xffff;
2079 YUV16_TO_RGB_FLOAT(y
, u
, v
, r
, g
, b
);
2087 static inline void transfer_YUV161616_to_BGR8888(unsigned char *(*output
), uint16_t *input
)
2092 y
= (((int)input
[0]) << 8) | (input
[0] >> 8);
2095 YUV_TO_RGB(y
, u
, v
, r
, g
, b
);
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];
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;
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;
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;
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
,
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
,
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
),
2172 // Store U and V for even pixels only
2175 (*output
)[1] = input
[1] >> 8;
2176 (*output
)[3] = input
[2] >> 8;
2177 (*output
)[0] = input
[0] >> 8;
2180 // Store Y and advance output for odd pixels only
2182 (*output
)[2] = input
[0] >> 8;
2197 // ******************************** YUVA16161616 -> ***************************
2202 static inline void transfer_YUVA16161616_to_RGB8(unsigned char *(*output
), uint16_t *input
)
2208 y
= (((int)input
[0]) << 8) | (input
[0] >> 8);
2211 YUV_TO_RGB(y
, u
, v
, r
, g
, b
);
2217 *(*output
) = (unsigned char)(((r
& 0xc000) >> 8) +
2218 ((g
& 0xe000) >> 10) +
2219 ((b
& 0xe000) >> 13));
2223 static inline void transfer_YUVA16161616_to_BGR565(unsigned char *(*output
), uint16_t *input
)
2229 y
= (((int)input
[0]) << 8) | (input
[0] >> 8);
2232 YUV_TO_RGB(y
, u
, v
, r
, g
, b
);
2238 *(uint16_t*)(*output
) = (uint16_t)((b
& 0xf800) +
2239 ((g
& 0xfc00) >> 5) +
2240 ((r
& 0xf800) >> 11));
2244 static inline void transfer_YUVA16161616_to_RGB565(unsigned char *(*output
), uint16_t *input
)
2250 y
= (((int)input
[0]) << 8) | (input
[0] >> 8);
2253 YUV_TO_RGB(y
, u
, v
, r
, g
, b
);
2259 *(uint16_t*)(*output
) = (uint16_t)((r
& 0xf800) +
2260 ((g
& 0xfc00) >> 5) +
2261 ((b
& 0xf800) >> 11));
2265 static inline void transfer_YUVA16161616_to_BGR888(unsigned char *(*output
), uint16_t *input
)
2271 y
= (((int)input
[0]) << 8) | (input
[0] >> 8);
2275 YUV_TO_RGB16(y
, u
, v
, r
, g
, b
);
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
;
2292 y
= (((int)input
[0]) << 8) | (input
[0] >> 8);
2296 YUV_TO_RGB16(y
, u
, v
, r
, g
, 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);
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);
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
),
2355 y
= (float)input
[0] / 0xffff;
2358 a
= (float)input
[3] / 0xffff;
2360 YUV16_TO_RGB_FLOAT(y
, u
, v
, r
, g
, b
);
2371 static inline void transfer_YUVA16161616_to_RGBA_FLOAT(float *(*output
),
2378 y
= (float)input
[0] / 0xffff;
2381 a
= (float)input
[3] / 0xffff;
2383 YUV16_TO_RGB_FLOAT(y
, u
, v
, r
, g
, b
);
2391 static inline void transfer_YUVA16161616_to_BGR8888(unsigned char *(*output
),
2398 y
= (((int)input
[0]) << 8) | (input
[0] >> 8);
2402 YUV_TO_RGB(y
, u
, v
, r
, g
, b
);
2418 static inline void transfer_YUVA16161616_to_VYU888(unsigned char *(*output
), uint16_t *input
)
2420 int y
, u
, v
, a
, anti_a
;
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;
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];
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;
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
,
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
,
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
),
2494 int64_t opacity
= input
[3];
2495 int64_t transparency
= 0xffff - opacity
;
2497 // Store U and V for even pixels only
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;
2505 // Store Y and advance output for odd pixels only
2507 (*output
)[2] = (input
[0] * opacity
) / 0xffff00;
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, \
2674 int in_colormodel, \
2675 int out_colormodel, \
2680 int out_pixelsize, \
2683 int *column_table, \