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; \
93 *(*output)++ = output_i >> 8; \
94 *(*output)++ = output_i >> 16; \
95 *(*output)++ = output_i >> 24; \
99 // ****************************** Pixel transfers *****************************
106 // ****************************** ARGB8888 -> *********************************
108 static inline void transfer_ARGB8888_to_ARGB8888(unsigned char *(*output), unsigned char *input)
110 (*output)[0] = input[0];
111 (*output)[1] = input[1];
112 (*output)[2] = input[2];
113 (*output)[3] = input[3];
117 static inline void transfer_ARGB8888_to_RGBA8888(unsigned char *(*output), unsigned char *input)
119 (*output)[0] = input[1];
120 (*output)[1] = input[2];
121 (*output)[2] = input[3];
122 (*output)[3] = input[0];
127 static inline void transfer_ARGB8888_to_RGB888(unsigned char *(*output), unsigned char *input)
130 (*output)[0] = input[1] * a / 0xff;
131 (*output)[1] = input[2] * a / 0xff;
132 (*output)[2] = input[3] * a / 0xff;
136 static inline void transfer_ARGB8888_to_BGR8888(unsigned char *(*output), unsigned char *input)
139 (*output)[0] = input[3] * a / 0xff;
140 (*output)[1] = input[2] * a / 0xff;
141 (*output)[2] = input[1] * a / 0xff;
159 // ******************************** RGB888 -> *********************************
161 static inline void transfer_RGB888_to_RGB8(unsigned char *(*output), unsigned char *input)
163 *(*output) = (unsigned char)((input[0] & 0xc0) +
164 ((input[1] & 0xe0) >> 2) +
165 ((input[2] & 0xe0) >> 5));
169 static inline void transfer_RGB888_to_BGR565(unsigned char *(*output), unsigned char *input)
172 uint16_t r_s, g_s, b_s;
177 r_s = (r & 0x01) << 7;
178 r_s |= (r & 0x02) << 5;
179 r_s |= (r & 0x04) << 3;
180 r_s |= (r & 0x08) << 1;
181 r_s |= (r & 0x10) >> 1;
182 r_s |= (r & 0x20) >> 3;
183 r_s |= (r & 0x40) >> 5;
184 r_s |= (r & 0x80) >> 7;
186 g_s = (g & 0x01) << 7;
187 g_s |= (g & 0x02) << 5;
188 g_s |= (g & 0x04) << 3;
189 g_s |= (g & 0x08) << 1;
190 g_s |= (g & 0x10) >> 1;
191 g_s |= (g & 0x20) >> 3;
192 g_s |= (g & 0x40) >> 5;
193 g_s |= (g & 0x80) >> 7;
195 b_s = (b & 0x01) << 7;
196 b_s |= (b & 0x02) << 5;
197 b_s |= (b & 0x04) << 3;
198 b_s |= (b & 0x08) << 1;
199 b_s |= (b & 0x10) >> 1;
200 b_s |= (b & 0x20) >> 3;
201 b_s |= (b & 0x40) >> 5;
202 b_s |= (b & 0x80) >> 7;
204 *(uint16_t*)(*output) = ((b_s & 0xf8) << 8)
205 + ((g_s & 0xfc) << 3)
206 + ((r_s & 0xf8) >> 3);
210 static inline void transfer_RGB888_to_RGB565(unsigned char *(*output), unsigned char *input)
216 *(uint16_t*)(*output) = ((r & 0xf8) << 8)
222 static inline void transfer_RGB888_to_BGR888(unsigned char *(*output), unsigned char *input)
224 *(*output)++ = input[2];
225 *(*output)++ = input[1];
226 *(*output)++ = input[0];
229 static inline void transfer_RGB888_to_RGB888(unsigned char *(*output), unsigned char *input)
231 *(*output)++ = *input++;
232 *(*output)++ = *input++;
233 *(*output)++ = *input;
236 static inline void transfer_RGB888_to_RGBA8888(unsigned char *(*output), unsigned char *input)
238 *(*output)++ = *input++;
239 *(*output)++ = *input++;
240 *(*output)++ = *input;
244 static inline void transfer_RGB888_to_ARGB8888(unsigned char *(*output), unsigned char *input)
247 *(*output)++ = *input++;
248 *(*output)++ = *input++;
249 *(*output)++ = *input;
252 static inline void transfer_RGB888_to_RGB161616(uint16_t *(*output), unsigned char *input)
254 (*output)[0] = (input[0] << 8) | input[0];
255 (*output)[1] = (input[1] << 8) | input[1];
256 (*output)[2] = (input[2] << 8) | input[2];
260 static inline void transfer_RGB888_to_RGBA16161616(uint16_t *(*output), unsigned char *input)
262 (*output)[0] = (input[0] << 8) | input[0];
263 (*output)[1] = (input[1] << 8) | input[1];
264 (*output)[2] = (input[2] << 8) | input[2];
265 (*output)[3] = 0xffff;
269 static inline void transfer_RGB888_to_RGB_FLOAT(float *(*output), unsigned char *input)
271 *(*output)++ = (float)*input++ / 0xff;
272 *(*output)++ = (float)*input++ / 0xff;
273 *(*output)++ = (float)*input / 0xff;
276 static inline void transfer_RGB888_to_RGBA_FLOAT(float *(*output), unsigned char *input)
278 *(*output)++ = (float)*input++ / 0xff;
279 *(*output)++ = (float)*input++ / 0xff;
280 *(*output)++ = (float)*input / 0xff;
284 static inline void transfer_RGB888_to_ABGR8888(unsigned char *(*output), unsigned char *input)
287 *(*output)++ = input[2];
288 *(*output)++ = input[1];
289 *(*output)++ = input[0];
292 static inline void transfer_RGB888_to_BGR8888(unsigned char *(*output), unsigned char *input)
294 *(*output)++ = input[2];
295 *(*output)++ = input[1];
296 *(*output)++ = input[0];
300 static inline void transfer_RGB888_to_YUV888(unsigned char *(*output), unsigned char *input)
304 RGB_TO_YUV(y, u, v, input[0], input[1], input[2]);
312 static inline void transfer_RGB888_to_YUV101010(unsigned char *(*output), unsigned char *input)
317 r = ((uint16_t)input[0]) << 8;
318 g = ((uint16_t)input[1]) << 8;
319 b = ((uint16_t)input[2]) << 8;
320 RGB_TO_YUV16(y, u, v, r, g, b);
321 WRITE_YUV101010(y, u, v);
324 static inline void transfer_RGB888_to_VYU888(unsigned char *(*output), unsigned char *input)
328 RGB_TO_YUV(y, u, v, input[0], input[1], input[2]);
335 static inline void transfer_RGB888_to_UYVA8888(unsigned char *(*output), unsigned char *input)
339 RGB_TO_YUV(y, u, v, input[0], input[1], input[2]);
349 static inline void transfer_RGB888_to_YUVA8888(unsigned char *(*output), unsigned char *input)
353 RGB_TO_YUV(y, u, v, input[0], input[1], input[2]);
361 static inline void transfer_RGB888_to_YUV161616(uint16_t *(*output), unsigned char *input)
363 int y, u, v, r, g, b;
365 r = ((int)input[0] << 8) | input[0];
366 g = ((int)input[1] << 8) | input[1];
367 b = ((int)input[2] << 8) | input[2];
369 RGB_TO_YUV16(y, u, v, r, g, b);
376 static inline void transfer_RGB888_to_YUVA16161616(uint16_t *(*output), unsigned char *input)
378 int y, u, v, r, g, b;
380 r = (((int)input[0]) << 8) | input[0];
381 g = (((int)input[1]) << 8) | input[1];
382 b = (((int)input[2]) << 8) | input[2];
383 RGB_TO_YUV16(y, u, v, r, g, b);
388 *(*output)++ = 0xffff;
391 static inline void transfer_RGB888_to_YUV420P_YUV422P(unsigned char *output_y,
392 unsigned char *output_u,
393 unsigned char *output_v,
394 unsigned char *input,
399 RGB_TO_YUV(y, u, v, input[0], input[1], input[2]);
401 output_y[output_column] = y;
402 output_u[output_column / 2] = u;
403 output_v[output_column / 2] = v;
406 static inline void transfer_RGB888_to_YUV444P(unsigned char *output_y,
407 unsigned char *output_u,
408 unsigned char *output_v,
409 unsigned char *input,
414 RGB_TO_YUV(y, u, v, input[0], input[1], input[2]);
416 output_y[output_column] = y;
417 output_u[output_column] = u;
418 output_v[output_column] = v;
421 static inline void transfer_RGB888_to_YUV422(unsigned char *(*output),
422 unsigned char *input,
427 RGB_TO_YUV(y, u, v, input[0], input[1], input[2]);
431 // Store U and V for even pixels only
438 // Store Y and advance output for odd pixels only
451 // *************************** RGBA8888 -> ************************************
453 static inline void transfer_RGBA8888_to_TRANSPARENCY(unsigned char *(*output), unsigned char *input, int (*bit_counter))
455 if((*bit_counter) == 7) *(*output) = 0;
459 *(*output) |= (unsigned char)1 << (7 - (*bit_counter));
462 if((*bit_counter) == 0)
471 // These routines blend in a background color since they should be
472 // exclusively used for widgets.
474 static inline void transfer_RGBA8888_to_RGB8bg(unsigned char *(*output), unsigned char *input, int bg_r, int bg_g, int bg_b)
476 unsigned int r, g, b, a, anti_a;
479 r = ((unsigned int)input[0] * a + bg_r * anti_a) / 0xff;
480 g = ((unsigned int)input[1] * a + bg_g * anti_a) / 0xff;
481 b = ((unsigned int)input[2] * a + bg_b * anti_a) / 0xff;
482 *(*output) = (unsigned char)((r & 0xc0) +
488 static inline void transfer_RGBA8888_to_BGR565bg(unsigned char *(*output), unsigned char *input, int bg_r, int bg_g, int bg_b)
490 unsigned int r, g, b, a, anti_a;
493 r = ((unsigned int)input[0] * a + bg_r * anti_a) / 0xff;
494 g = ((unsigned int)input[1] * a + bg_g * anti_a) / 0xff;
495 b = ((unsigned int)input[2] * a + bg_b * anti_a) / 0xff;
496 *(uint16_t*)(*output) = (uint16_t)(((b & 0xf8) << 8) +
502 static inline void transfer_RGBA8888_to_RGB565bg(unsigned char *(*output), unsigned char *input, int bg_r, int bg_g, int bg_b)
504 unsigned int r, g, b, a, anti_a;
507 r = ((unsigned int)input[0] * a + bg_r * anti_a) / 0xff;
508 g = ((unsigned int)input[1] * a + bg_g * anti_a) / 0xff;
509 b = ((unsigned int)input[2] * a + bg_b * anti_a) / 0xff;
510 *(uint16_t*)(*output) = (uint16_t)(((r & 0xf8) << 8)+
516 static inline void transfer_RGBA8888_to_BGR888bg(unsigned char *(*output), unsigned char *input, int bg_r, int bg_g, int bg_b)
518 unsigned int r, g, b, a, anti_a;
521 r = ((unsigned int)input[0] * a + bg_r * anti_a) / 0xff;
522 g = ((unsigned int)input[1] * a + bg_g * anti_a) / 0xff;
523 b = ((unsigned int)input[2] * a + bg_b * anti_a) / 0xff;
529 static inline void transfer_RGBA8888_to_RGB888bg(unsigned char *(*output), unsigned char *input, int bg_r, int bg_g, int bg_b)
531 unsigned int r, g, b, a, anti_a;
534 r = ((unsigned int)input[0] * a + bg_r * anti_a) / 0xff;
535 g = ((unsigned int)input[1] * a + bg_g * anti_a) / 0xff;
536 b = ((unsigned int)input[2] * a + bg_b * anti_a) / 0xff;
542 static inline void transfer_RGBA8888_to_BGR8888bg(unsigned char *(*output), unsigned char *input, int bg_r, int bg_g, int bg_b)
544 unsigned int r, g, b, a, anti_a;
548 r = ((unsigned int)input[0] * a + bg_r * anti_a) / 0xff;
549 g = ((unsigned int)input[1] * a + bg_g * anti_a) / 0xff;
550 b = ((unsigned int)input[2] * a + bg_b * anti_a) / 0xff;
564 // These routines blend in a black background
566 static inline void transfer_RGBA8888_to_RGB8(unsigned char *(*output), unsigned char *input)
568 unsigned int r, g, b, a;
570 r = (unsigned int)input[0] * a;
571 g = (unsigned int)input[1] * a;
572 b = (unsigned int)input[2] * a;
573 *(*output) = (unsigned char)(((r & 0xc000) >> 8) +
574 ((g & 0xe000) >> 10) +
575 ((b & 0xe000) >> 13));
579 static inline void transfer_RGBA8888_to_BGR565(unsigned char *(*output), unsigned char *input)
581 unsigned int r, g, b, a;
583 r = ((unsigned int)input[0] * a) / 0xff;
584 g = ((unsigned int)input[1] * a) / 0xff;
585 b = ((unsigned int)input[2] * a) / 0xff;
586 *(uint16_t*)(*output) = (uint16_t)(((b & 0xf8) << 8) +
592 static inline void transfer_RGBA8888_to_RGB565(unsigned char *(*output), unsigned char *input)
594 unsigned int r, g, b, a;
596 r = ((unsigned int)input[0] * a) / 0xff;
597 g = ((unsigned int)input[1] * a) / 0xff;
598 b = ((unsigned int)input[2] * a) / 0xff;
601 *(uint16_t*)(*output) = (uint16_t)(((r & 0xf8) << 8) +
607 static inline void transfer_RGBA8888_to_BGR888(unsigned char *(*output), unsigned char *input)
609 unsigned int r, g, b, a;
611 r = ((unsigned int)input[0] * a) / 0xff;
612 g = ((unsigned int)input[1] * a) / 0xff;
613 b = ((unsigned int)input[2] * a) / 0xff;
619 static inline void transfer_RGBA8888_to_RGB888(unsigned char *(*output), unsigned char *input)
621 unsigned int r, g, b, a;
623 r = ((unsigned int)input[0] * a) / 0xff;
624 g = ((unsigned int)input[1] * a) / 0xff;
625 b = ((unsigned int)input[2] * a) / 0xff;
631 static inline void transfer_RGBA8888_to_RGBA8888(unsigned char *(*output), unsigned char *input)
633 (*output)[0] = input[0];
634 (*output)[1] = input[1];
635 (*output)[2] = input[2];
636 (*output)[3] = input[3];
640 static inline void transfer_RGBA8888_to_ARGB8888(unsigned char *(*output), unsigned char *input)
642 (*output)[0] = input[3];
643 (*output)[1] = input[0];
644 (*output)[2] = input[1];
645 (*output)[3] = input[2];
649 static inline void transfer_RGBA8888_to_RGB161616(uint16_t *(*output), unsigned char *input)
651 int opacity = input[3];
652 (*output)[0] = (((int)input[0] << 8) | input[0]) * opacity / 0xff;
653 (*output)[1] = (((int)input[1] << 8) | input[1]) * opacity / 0xff;
654 (*output)[2] = (((int)input[2] << 8) | input[2]) * opacity / 0xff;
658 static inline void transfer_RGBA8888_to_RGBA16161616(uint16_t *(*output), unsigned char *input)
660 (*output)[0] = (((int)input[0]) << 8) | input[0];
661 (*output)[1] = (((int)input[1]) << 8) | input[1];
662 (*output)[2] = (((int)input[2]) << 8) | input[2];
663 (*output)[3] = (((int)input[3]) << 8) | input[3];
667 static inline void transfer_RGBA8888_to_RGB_FLOAT(float *(*output), unsigned char *input)
669 float opacity = (float)input[3];
670 *(*output)++ = (float)*input++ * opacity / 0xff / 0xff;
671 *(*output)++ = (float)*input++ * opacity / 0xff / 0xff;
672 *(*output)++ = (float)*input * opacity / 0xff / 0xff;
675 static inline void transfer_RGBA8888_to_RGBA_FLOAT(float *(*output), unsigned char *input)
677 *(*output)++ = (float)*input++ / 0xff;
678 *(*output)++ = (float)*input++ / 0xff;
679 *(*output)++ = (float)*input++ / 0xff;
680 *(*output)++ = (float)*input / 0xff;
683 static inline void transfer_RGBA8888_to_BGR8888(unsigned char *(*output), unsigned char *input)
685 unsigned int r, g, b, a;
687 r = ((unsigned int)input[0] * a) / 0xff;
688 g = ((unsigned int)input[1] * a) / 0xff;
689 b = ((unsigned int)input[2] * a) / 0xff;
696 static inline void transfer_RGBA8888_to_YUV888(unsigned char *(*output), unsigned char *input)
698 int y, u, v, a, r, g, b;
701 r = (input[0] * a) / 0xff;
702 g = (input[1] * a) / 0xff;
703 b = (input[2] * a) / 0xff;
705 RGB_TO_YUV(y, u, v, r, g, b);
712 static inline void transfer_RGBA8888_to_YUVA8888(unsigned char *(*output), unsigned char *input)
716 RGB_TO_YUV(y, u, v, input[0], input[1], input[2]);
721 *(*output)++ = input[3];
724 static inline void transfer_RGBA8888_to_YUV161616(uint16_t *(*output), unsigned char *input)
726 int y, u, v, opacity, r, g, b;
729 r = (((int)input[0] << 8) | input[0]) * opacity / 0xff;
730 g = (((int)input[1] << 8) | input[1]) * opacity / 0xff;
731 b = (((int)input[2] << 8) | input[2]) * opacity / 0xff;
733 RGB_TO_YUV16(y, u, v, r, g, b);
740 static inline void transfer_RGBA8888_to_YUVA16161616(uint16_t *(*output), unsigned char *input)
742 int y, u, v, r, g, b;
744 r = (((int)input[0]) << 8) | input[0];
745 g = (((int)input[1]) << 8) | input[1];
746 b = (((int)input[2]) << 8) | input[2];
747 RGB_TO_YUV16(y, u, v, r, g, b);
752 *(*output)++ = (((int)input[3]) << 8) | input[3];
755 static inline void transfer_RGBA8888_to_YUV101010(unsigned char *(*output), unsigned char *input)
760 r = ((uint16_t)input[0] * input[3]) + 0x1fe;
761 g = ((uint16_t)input[1] * input[3]) + 0x1fe;
762 b = ((uint16_t)input[2] * input[3]) + 0x1fe;
763 RGB_TO_YUV16(y, u, v, r, g, b);
764 WRITE_YUV101010(y, u, v);
767 static inline void transfer_RGBA8888_to_VYU888(unsigned char *(*output), unsigned char *input)
769 int y, u, v, a, r, g, b;
772 r = ((input[0] * a) >> 8) + 1;
773 g = ((input[1] * a) >> 8) + 1;
774 b = ((input[2] * a) >> 8) + 1;
776 RGB_TO_YUV(y, u, v, r, g, b);
783 static inline void transfer_RGBA8888_to_UYVA8888(unsigned char *(*output), unsigned char *input)
787 RGB_TO_YUV(y, u, v, input[0], input[1], input[2]);
792 *(*output)++ = input[3];
795 static inline void transfer_RGBA888_to_YUV420P_YUV422P(unsigned char *output_y,
796 unsigned char *output_u,
797 unsigned char *output_v,
798 unsigned char *input,
801 int y, u, v, a, r, g, b;
804 r = (input[0] * a) / 0xff;
805 g = (input[1] * a) / 0xff;
806 b = (input[2] * a) / 0xff;
808 RGB_TO_YUV(y, u, v, r, g, b);
810 output_y[output_column] = y;
811 output_u[output_column / 2] = u;
812 output_v[output_column / 2] = v;
815 static inline void transfer_RGBA888_to_YUV444P(unsigned char *output_y,
816 unsigned char *output_u,
817 unsigned char *output_v,
818 unsigned char *input,
821 int y, u, v, a, r, g, b;
824 r = (input[0] * a) / 0xff;
825 g = (input[1] * a) / 0xff;
826 b = (input[2] * a) / 0xff;
828 RGB_TO_YUV(y, u, v, r, g, b);
830 output_y[output_column] = y;
831 output_u[output_column] = u;
832 output_v[output_column] = v;
835 static inline void transfer_RGBA888_to_YUV422(unsigned char *(*output),
836 unsigned char *input,
839 int y, u, v, a, r, g, b;
842 r = (input[0] * a) / 0xff;
843 g = (input[1] * a) / 0xff;
844 b = (input[2] * a) / 0xff;
846 RGB_TO_YUV(y, u, v, r, g, b);
850 // Store U and V for even pixels only
857 // Store Y and advance output for odd pixels only
876 // ******************************** RGB161616 -> *********************************
878 static inline void transfer_RGB161616_to_RGB8(unsigned char *(*output), uint16_t *input)
880 *(*output) = (unsigned char)(((input[0] & 0xc000) >> 8) +
881 ((input[1] & 0xe000) >> 10) +
882 ((input[2] & 0xe000) >> 13));
886 static inline void transfer_RGB161616_to_BGR565(unsigned char *(*output), uint16_t *input)
892 *(uint16_t*)(*output) = (b & 0xf800) |
893 ((g & 0xfc00) >> 5) |
894 ((r & 0xf800) >> 11);
898 static inline void transfer_RGB161616_to_RGB565(unsigned char *(*output), uint16_t *input)
904 *(uint16_t*)(*output) = (r & 0xf800) |
905 ((g & 0xfc00) >> 5) |
906 ((b & 0xf800) >> 11);
910 static inline void transfer_RGB161616_to_BGR888(unsigned char *(*output), uint16_t *input)
912 (*output)[0] = input[2] >> 8;
913 (*output)[1] = input[1] >> 8;
914 (*output)[2] = input[0] >> 8;
918 static inline void transfer_RGB161616_to_RGB888(unsigned char *(*output), uint16_t *input)
920 (*output)[0] = input[0] >> 8;
921 (*output)[1] = input[1] >> 8;
922 (*output)[2] = input[2] >> 8;
926 static inline void transfer_RGB161616_to_RGBA8888(unsigned char *(*output), uint16_t *input)
928 (*output)[0] = input[0] >> 8;
929 (*output)[1] = input[1] >> 8;
930 (*output)[2] = input[2] >> 8;
935 static inline void transfer_RGB161616_to_BGR8888(unsigned char *(*output), uint16_t *input)
937 (*output)[0] = input[2] >> 8;
938 (*output)[1] = input[1] >> 8;
939 (*output)[2] = input[0] >> 8;
943 static inline void transfer_RGB161616_to_RGB_FLOAT(float *(*output), uint16_t *input)
945 *(*output)++ = (float)*input++ / 0xffff;
946 *(*output)++ = (float)*input++ / 0xffff;
947 *(*output)++ = (float)*input / 0xffff;
950 static inline void transfer_RGB161616_to_RGBA_FLOAT(float *(*output), uint16_t *input)
952 *(*output)++ = (float)*input++ / 0xffff;
953 *(*output)++ = (float)*input++ / 0xffff;
954 *(*output)++ = (float)*input / 0xffff;
958 static inline void transfer_RGB161616_to_YUV888(unsigned char *(*output), uint16_t *input)
960 int y, u, v, r, g, b;
965 RGB_TO_YUV(y, u, v, r, g, b);
973 static inline void transfer_RGB161616_to_YUVA8888(unsigned char *(*output), uint16_t *input)
975 int y, u, v, r, g, b;
981 RGB_TO_YUV(y, u, v, r, g, b);
990 static inline void transfer_RGB161616_to_YUV161616(uint16_t *(*output), uint16_t *input)
992 uint32_t y, u, v, r, g, b;
994 r = (uint32_t)input[0];
995 g = (uint32_t)input[1];
996 b = (uint32_t)input[2];
998 RGB_TO_YUV16(y, u, v, r, g, b);
1006 static inline void transfer_RGB161616_to_YUVA16161616(uint16_t *(*output), uint16_t *input)
1008 uint32_t y, u, v, r, g, b;
1010 r = (uint32_t)input[0];
1011 g = (uint32_t)input[1];
1012 b = (uint32_t)input[2];
1014 RGB_TO_YUV16(y, u, v, r, g, b);
1019 (*output)[3] = 0xffff;
1023 static inline void transfer_RGB161616_to_YUV101010(unsigned char *(*output), uint16_t *input)
1031 RGB_TO_YUV16(y, u, v, r, g, b);
1032 WRITE_YUV101010(y, u, v);
1035 static inline void transfer_RGB161616_to_VYU888(unsigned char *(*output), uint16_t *input)
1037 int y, u, v, r, g, b;
1042 RGB_TO_YUV(y, u, v, r, g, b);
1050 static inline void transfer_RGB161616_to_UYVA8888(unsigned char *(*output), uint16_t *input)
1052 int y, u, v, r, g, b;
1058 RGB_TO_YUV(y, u, v, r, g, b);
1063 (*output)[3] = 0xff;
1068 static inline void transfer_RGB161616_to_YUV420P_YUV422P(unsigned char *output_y,
1069 unsigned char *output_u,
1070 unsigned char *output_v,
1074 int y, u, v, r, g, b;
1079 RGB_TO_YUV(y, u, v, r, g, b);
1081 output_y[output_column] = y;
1082 output_u[output_column / 2] = u;
1083 output_v[output_column / 2] = v;
1086 static inline void transfer_RGB161616_to_YUV444P(unsigned char *output_y,
1087 unsigned char *output_u,
1088 unsigned char *output_v,
1092 int y, u, v, r, g, b;
1097 RGB_TO_YUV(y, u, v, r, g, b);
1099 output_y[output_column] = y;
1100 output_u[output_column] = u;
1101 output_v[output_column] = v;
1105 // ****************************** RGBA16161616 -> *****************************
1107 static inline void transfer_RGBA16161616_to_RGB8(unsigned char *(*output), uint16_t *input)
1109 unsigned int r, g, b, a;
1110 a = (input)[3] >> 8;
1111 r = (unsigned int)(input)[0] * a;
1112 g = (unsigned int)(input)[1] * a;
1113 b = (unsigned int)(input)[2] * a;
1115 *(*output) = (unsigned char)(((r & 0xc00000) >> 16) +
1116 ((g & 0xe00000) >> 18) +
1117 ((b & 0xe00000) >> 21));
1121 static inline void transfer_RGBA16161616_to_BGR565(unsigned char *(*output), uint16_t *input)
1123 unsigned int r, g, b, a;
1124 a = (input)[3] >> 8;
1125 r = (unsigned int)(input)[0] * a;
1126 g = (unsigned int)(input)[1] * a;
1127 b = (unsigned int)(input)[2] * a;
1129 *(uint16_t*)(*output) = (uint16_t)(((b & 0xf80000) >> 8) +
1130 ((g & 0xfc0000) >> 13) +
1131 ((r & 0xf80000) >> 19));
1135 static inline void transfer_RGBA16161616_to_RGB565(unsigned char *(*output), uint16_t *input)
1137 unsigned int r, g, b, a;
1138 a = (input)[3] >> 8;
1139 r = (unsigned int)(input)[0] * a;
1140 g = (unsigned int)(input)[1] * a;
1141 b = (unsigned int)(input)[2] * a;
1143 *(uint16_t*)(*output) = (uint16_t)(((r & 0xf80000) >> 8) +
1144 ((g & 0xfc0000) >> 13) +
1145 ((b & 0xf80000) >> 19));
1149 static inline void transfer_RGBA16161616_to_BGR888(unsigned char *(*output), uint16_t *input)
1151 uint32_t r, g, b, a;
1153 r = (uint32_t)(input)[0] * a;
1154 g = (uint32_t)(input)[1] * a;
1155 b = (uint32_t)(input)[2] * a;
1158 (*output)[0] = (unsigned char)(b >> 24);
1159 (*output)[1] = (unsigned char)(g >> 24);
1160 (*output)[2] = (unsigned char)(r >> 24);
1164 static inline void transfer_RGBA16161616_to_RGB888(unsigned char *(*output), uint16_t *input)
1166 uint32_t r, g, b, a;
1168 r = (unsigned int)(input)[0] * a;
1169 g = (unsigned int)(input)[1] * a;
1170 b = (unsigned int)(input)[2] * a;
1172 (*output)[0] = (unsigned char)(r / 0xffffff);
1173 (*output)[1] = (unsigned char)(g / 0xffffff);
1174 (*output)[2] = (unsigned char)(b / 0xffffff);
1179 static inline void transfer_RGBA16161616_to_RGBA8888(unsigned char *(*output), uint16_t *input)
1181 (*output)[0] = input[0] >> 8;
1182 (*output)[1] = input[1] >> 8;
1183 (*output)[2] = input[2] >> 8;
1184 (*output)[3] = input[3] >> 8;
1189 static inline void transfer_RGBA16161616_to_BGR8888(unsigned char *(*output), uint16_t *input)
1191 uint32_t r, g, b, a;
1198 (*output)[0] = (unsigned char)(b >> 24);
1199 (*output)[1] = (unsigned char)(g >> 24);
1200 (*output)[2] = (unsigned char)(r >> 24);
1204 static inline void transfer_RGBA16161616_to_RGB_FLOAT(float *(*output), uint16_t *input)
1206 float opacity = (float)input[3];
1207 *(*output)++ = (float)*input++ * opacity / 0xffff / 0xffff;
1208 *(*output)++ = (float)*input++ * opacity / 0xffff / 0xffff;
1209 *(*output)++ = (float)*input * opacity / 0xffff / 0xffff;
1212 static inline void transfer_RGBA16161616_to_RGBA_FLOAT(float *(*output), uint16_t *input)
1214 *(*output)++ = (float)*input++ / 0xffff;
1215 *(*output)++ = (float)*input++ / 0xffff;
1216 *(*output)++ = (float)*input++ / 0xffff;
1217 *(*output)++ = (float)*input / 0xffff;
1220 static inline void transfer_RGBA16161616_to_YUV888(unsigned char *(*output), uint16_t *input)
1222 uint32_t y, u, v, r, g, b, a;
1225 r = (uint32_t)input[0] * a / 0xffffff;
1226 g = (uint32_t)input[1] * a / 0xffffff;
1227 b = (uint32_t)input[2] * a / 0xffffff;
1229 RGB_TO_YUV(y, u, v, r, g, b);
1237 static inline void transfer_RGBA16161616_to_YUVA8888(unsigned char *(*output), uint16_t *input)
1239 int y, u, v, r, g, b;
1245 RGB_TO_YUV(y, u, v, r, g, b);
1250 (*output)[3] = input[3] >> 8;
1254 static inline void transfer_RGBA16161616_to_YUV161616(uint16_t *(*output), uint16_t *input)
1256 uint32_t y, u, v, r, g, b, a;
1259 r = (uint32_t)input[0] * a / 0xffff;
1260 g = (uint32_t)input[1] * a / 0xffff;
1261 b = (uint32_t)input[2] * a / 0xffff;
1263 RGB_TO_YUV16(y, u, v, r, g, b);
1271 static inline void transfer_RGBA16161616_to_YUVA16161616(uint16_t *(*output), uint16_t *input)
1273 uint32_t y, u, v, r, g, b;
1275 r = (uint32_t)input[0];
1276 g = (uint32_t)input[1];
1277 b = (uint32_t)input[2];
1279 RGB_TO_YUV16(y, u, v, r, g, b);
1284 (*output)[3] = input[3];
1289 static inline void transfer_RGBA16161616_to_YUV101010(unsigned char *(*output), uint16_t *input)
1291 uint32_t r, g, b, a, y, u, v;
1294 r = (uint32_t)input[0] * a / 0xffff;
1295 g = (uint32_t)input[1] * a / 0xffff;
1296 b = (uint32_t)input[2] * a / 0xffff;
1297 RGB_TO_YUV16(y, u, v, r, g, b);
1298 WRITE_YUV101010(y, u, v);
1302 static inline void transfer_RGBA16161616_to_YUV420P_YUV422P(unsigned char *output_y,
1303 unsigned char *output_u,
1304 unsigned char *output_v,
1308 uint32_t y, u, v, r, g, b, a;
1310 r = (int32_t)input[0] * a / 0xffffff;
1311 g = (int32_t)input[1] * a / 0xffffff;
1312 b = (int32_t)input[2] * a / 0xffffff;
1314 RGB_TO_YUV(y, u, v, r, g, b);
1316 output_y[output_column] = y;
1317 output_u[output_column / 2] = u;
1318 output_v[output_column / 2] = v;
1321 static inline void transfer_RGBA16161616_to_YUV444P(unsigned char *output_y,
1322 unsigned char *output_u,
1323 unsigned char *output_v,
1327 uint32_t y, u, v, r, g, b, a;
1329 r = (int32_t)input[0] * a / 0xffffff;
1330 g = (int32_t)input[1] * a / 0xffffff;
1331 b = (int32_t)input[2] * a / 0xffffff;
1333 RGB_TO_YUV(y, u, v, r, g, b);
1335 output_y[output_column] = y;
1336 output_u[output_column] = u;
1337 output_v[output_column] = v;
1362 // ********************************** screen capture *****************************
1364 static inline void transfer_BGR8888_to_RGB888(unsigned char *(*output), unsigned char *input)
1366 *(*output)++ = input[2];
1367 *(*output)++ = input[1];
1368 *(*output)++ = input[0];
1371 static inline void transfer_BGR8888_to_BGR8888(unsigned char *(*output), unsigned char *input)
1373 *(*output)++ = input[0];
1374 *(*output)++ = input[1];
1375 *(*output)++ = input[2];
1379 static inline void transfer_BGR888_to_RGB888(unsigned char *(*output), unsigned char *input)
1381 *(*output)++ = input[2];
1382 *(*output)++ = input[1];
1383 *(*output)++ = input[0];
1392 // ******************************** YUV888 -> *********************************
1395 static inline void transfer_YUV888_to_RGB8(unsigned char *(*output), unsigned char *input)
1400 y = (input[0] << 16) | (input[0] << 8) | input[0];
1403 YUV_TO_RGB(y, u, v, r, g, b);
1405 *(*output) = (unsigned char)((r & 0xc0) +
1411 static inline void transfer_YUV888_to_BGR565(unsigned char *(*output), unsigned char *input)
1416 y = (input[0] << 16) | (input[0] << 8) | input[0];
1419 YUV_TO_RGB(y, u, v, r, g, b);
1420 *(uint16_t*)(*output) = ((b & 0xf8) << 8)
1422 + ((r & 0xf8) >> 3);
1426 static inline void transfer_YUV888_to_RGB565(unsigned char *(*output), unsigned char *input)
1431 y = (input[0] << 16) | (input[0] << 8) | input[0];
1434 YUV_TO_RGB(y, u, v, r, g, b);
1435 *(uint16_t*)(*output) = ((r & 0xf8) << 8)
1437 + ((b & 0xf8) >> 3);
1441 static inline void transfer_YUV888_to_BGR888(unsigned char *(*output), unsigned char *input)
1446 y = (input[0] << 16) | (input[0] << 8) | input[0];
1449 YUV_TO_RGB(y, u, v, r, g, b);
1456 static inline void transfer_YUV888_to_BGR8888(unsigned char *(*output), unsigned char *input)
1461 y = (input[0] << 16) | (input[0] << 8) | input[0];
1464 YUV_TO_RGB(y, u, v, r, g, b);
1471 static inline void transfer_YUV888_to_RGB888(unsigned char *(*output), unsigned char *input)
1476 y = (input[0] << 16) | (input[0] << 8) | input[0];
1479 YUV_TO_RGB(y, u, v, r, g, b);
1486 static inline void transfer_YUV888_to_RGBA8888(unsigned char *(*output), unsigned char *input)
1491 y = (input[0] << 16) | (input[0] << 8) | input[0];
1494 YUV_TO_RGB(y, u, v, r, g, b);
1498 *(*output)++ = 0xff;
1501 static inline void transfer_YUV888_to_ARGB8888(unsigned char *(*output), unsigned char *input)
1506 y = (input[0] << 16) | (input[0] << 8) | input[0];
1509 YUV_TO_RGB(y, u, v, r, g, b);
1510 *(*output)++ = 0xff;
1516 static inline void transfer_YUV888_to_RGB_FLOAT(float *(*output), unsigned char *input)
1518 float y = (float)input[0] / 0xff;
1523 YUV_TO_FLOAT(y, u, v, r, g, b);
1530 static inline void transfer_YUV888_to_RGBA_FLOAT(float *(*output), unsigned char *input)
1532 float y = (float)input[0] / 0xff;
1537 YUV_TO_FLOAT(y, u, v, r, g, b);
1545 static inline void transfer_YUV888_to_YUVA8888(unsigned char *(*output), unsigned char *input)
1547 *(*output)++ = (int)input[0];
1548 *(*output)++ = input[1];
1549 *(*output)++ = input[2];
1550 *(*output)++ = 0xff;
1553 static inline void transfer_YUV888_to_YUV888(unsigned char *(*output), unsigned char *input)
1555 (*output)[0] = (int)input[0];
1556 (*output)[1] = input[1];
1557 (*output)[2] = input[2];
1562 static inline void transfer_YUV888_to_VYU888(unsigned char *(*output), unsigned char *input)
1564 (*output)[0] = input[2];
1565 (*output)[1] = input[0];
1566 (*output)[2] = input[1];
1571 static inline void transfer_YUV888_to_UYVA8888(unsigned char *(*output), unsigned char *input)
1573 (*output)[0] = input[1];
1574 (*output)[1] = input[0];
1575 (*output)[2] = input[2];
1576 (*output)[3] = 0xff;
1581 static inline void transfer_YUV888_to_YUV101010(unsigned char *(*output), unsigned char *input)
1583 uint16_t y_i = ((uint16_t)input[0]) << 8;
1584 uint16_t u_i = ((uint16_t)input[1]) << 8;
1585 uint16_t v_i = ((uint16_t)input[2]) << 8;
1586 WRITE_YUV101010(y_i, u_i, v_i);
1589 static inline void transfer_YUV888_to_YUV420P_YUV422P(unsigned char *output_y,
1590 unsigned char *output_u,
1591 unsigned char *output_v,
1592 unsigned char *input,
1595 output_y[output_column] = input[0];
1596 output_u[output_column / 2] = input[1];
1597 output_v[output_column / 2] = input[2];
1600 static inline void transfer_YUV888_to_YUV444P(unsigned char *output_y,
1601 unsigned char *output_u,
1602 unsigned char *output_v,
1603 unsigned char *input,
1606 output_y[output_column] = input[0];
1607 output_u[output_column] = input[1];
1608 output_v[output_column] = input[2];
1611 static inline void transfer_YUV888_to_YUV422(unsigned char *(*output),
1612 unsigned char *input,
1615 // Store U and V for even pixels only
1618 (*output)[1] = input[1];
1619 (*output)[3] = input[2];
1620 (*output)[0] = input[0];
1623 // Store Y and advance output for odd pixels only
1625 (*output)[2] = input[0];
1635 // ******************************** YUVA8888 -> *******************************
1640 static inline void transfer_YUVA8888_to_RGB8(unsigned char *(*output), unsigned char *input)
1646 y = (input[0] << 16) | (input[0] << 8) | input[0];
1649 YUV_TO_RGB(y, u, v, r, g, b);
1655 *(*output) = (unsigned char)(((r & 0xc000) >> 8) +
1656 ((g & 0xe000) >> 10) +
1657 ((b & 0xe000) >> 13));
1661 static inline void transfer_YUVA8888_to_BGR565(unsigned char *(*output), unsigned char *input)
1667 y = (input[0] << 16) | (input[0] << 8) | input[0];
1670 YUV_TO_RGB(y, u, v, r, g, b);
1676 *(uint16_t*)(*output) = (uint16_t)((b & 0xf800) +
1677 ((g & 0xfc00) >> 5) +
1678 ((r & 0xf800) >> 11));
1682 static inline void transfer_YUVA8888_to_RGB565(unsigned char *(*output), unsigned char *input)
1688 y = (input[0] << 16) | (input[0] << 8) | input[0];
1691 YUV_TO_RGB(y, u, v, r, g, b);
1697 *(uint16_t*)(*output) = (uint16_t)((r & 0xf800) +
1698 ((g & 0xfc00) >> 5) +
1699 ((b & 0xf800) >> 11));
1703 static inline void transfer_YUVA8888_to_BGR888(unsigned char *(*output), unsigned char *input)
1709 y = (input[0] << 16) | (input[0] << 8) | input[0];
1713 YUV_TO_RGB(y, u, v, r, g, b);
1719 *(*output)++ = b / 0xff;
1720 *(*output)++ = g / 0xff;
1721 *(*output)++ = r / 0xff;
1725 static inline void transfer_YUVA8888_to_BGR8888(unsigned char *(*output), unsigned char *input)
1731 y = (input[0] << 16) | (input[0] << 8) | input[0];
1735 YUV_TO_RGB(y, u, v, r, g, b);
1740 *(*output)++ = b / 0xff;
1741 *(*output)++ = g / 0xff;
1742 *(*output)++ = r / 0xff;
1746 static inline void transfer_YUVA8888_to_RGB888(unsigned char *(*output), unsigned char *input)
1752 y = (input[0] << 16) | (input[0] << 8) | input[0];
1756 YUV_TO_RGB(y, u, v, r, g, b);
1762 *(*output)++ = r / 0xff;
1763 *(*output)++ = g / 0xff;
1764 *(*output)++ = b / 0xff;
1767 static inline void transfer_YUVA8888_to_RGBA8888(unsigned char *(*output), unsigned char *input)
1773 y = (input[0] << 16) | (input[0] << 8) | input[0];
1777 YUV_TO_RGB(y, u, v, r, g, b);
1784 static inline void transfer_YUVA8888_to_ARGB8888(unsigned char *(*output), unsigned char *input)
1790 y = (input[0] << 16) | (input[0] << 8) | input[0];
1794 YUV_TO_RGB(y, u, v, r, g, b);
1801 static inline void transfer_YUVA8888_to_RGB_FLOAT(float *(*output), unsigned char *input)
1807 a = (float)input[3] / 0xff;
1808 y = (float)input[0] / 0xff;
1812 YUV_TO_FLOAT(y, u, v, r, g, b);
1823 static inline void transfer_YUVA8888_to_RGBA_FLOAT(float *(*output), unsigned char *input)
1825 float y = (float)input[0] / 0xff;
1829 a = (float)input[3] / 0xff;
1833 YUV_TO_FLOAT(y, u, v, r, g, b);
1841 static inline void transfer_YUVA8888_to_YUV888(unsigned char *(*output), unsigned char *input)
1843 int y, u, v, a, anti_a;
1846 y = ((uint32_t)input[0] * a) / 0xff;
1847 u = ((uint32_t)input[1] * a + 0x80 * anti_a) / 0xff;
1848 v = ((uint32_t)input[2] * a + 0x80 * anti_a) / 0xff;
1857 static inline void transfer_YUVA8888_to_VYU888(unsigned char *(*output), unsigned char *input)
1859 int y, u, v, a, anti_a;
1862 y = ((uint32_t)input[0] * a) / 0xff;
1863 u = ((uint32_t)input[1] * a + 0x80 * anti_a) / 0xff;
1864 v = ((uint32_t)input[2] * a + 0x80 * anti_a) / 0xff;
1872 static inline void transfer_YUVA8888_to_YUVA8888(unsigned char *(*output), unsigned char *input)
1874 *(*output)++ = input[0];
1875 *(*output)++ = input[1];
1876 *(*output)++ = input[2];
1877 *(*output)++ = input[3];
1880 static inline void transfer_YUVA8888_to_UYVA8888(unsigned char *(*output), unsigned char *input)
1882 *(*output)++ = input[1];
1883 *(*output)++ = input[0];
1884 *(*output)++ = input[2];
1885 *(*output)++ = input[3];
1888 static inline void transfer_YUVA8888_to_YUV101010(unsigned char *(*output), unsigned char *input)
1890 uint16_t y_i = ((uint16_t)input[0] * input[3]) + 0x1fe;
1891 uint16_t u_i = ((uint16_t)input[1] * input[3]) + 0x1fe;
1892 uint16_t v_i = ((uint16_t)input[2] * input[3]) + 0x1fe;
1893 WRITE_YUV101010(y_i, u_i, v_i);
1897 static inline void transfer_YUVA8888_to_YUV420P_YUV422P(unsigned char *output_y,
1898 unsigned char *output_u,
1899 unsigned char *output_v,
1900 unsigned char *input,
1903 int opacity = input[3];
1904 int transparency = 0xff - opacity;
1906 output_y[output_column] = ((input[0] * opacity) >> 8) + 1;
1907 output_u[output_column / 2] = ((input[1] * opacity + 0x80 * transparency) >> 8) + 1;
1908 output_v[output_column / 2] = ((input[2] * opacity + 0x80 * transparency) >> 8) + 1;
1911 static inline void transfer_YUVA8888_to_YUV444P(unsigned char *output_y,
1912 unsigned char *output_u,
1913 unsigned char *output_v,
1914 unsigned char *input,
1917 int opacity = input[3];
1918 int transparency = 0xff - opacity;
1920 output_y[output_column] = ((input[0] * opacity) >> 8) + 1;
1921 output_u[output_column] = ((input[1] * opacity + 0x80 * transparency) >> 8) + 1;
1922 output_v[output_column] = ((input[2] * opacity + 0x80 * transparency) >> 8) + 1;
1925 static inline void transfer_YUVA8888_to_YUV422(unsigned char *(*output),
1926 unsigned char *input,
1929 int opacity = input[3];
1930 int transparency = 0xff - opacity;
1931 // Store U and V for even pixels only
1934 (*output)[0] = ((input[0] * opacity) >> 8) + 1;
1935 (*output)[1] = ((input[1] * opacity + 0x80 * transparency) >> 8) + 1;
1936 (*output)[3] = ((input[2] * opacity + 0x80 * transparency) >> 8) + 1;
1939 // Store Y and advance output for odd pixels only
1941 (*output)[2] = ((input[0] * opacity) >> 8) + 1;
1955 // ******************************** YUV161616 -> ******************************
1958 static inline void transfer_YUV161616_to_RGB8(unsigned char *(*output), uint16_t *input)
1963 y = (((int)input[0]) << 8) | (input[0] >> 8);
1966 YUV_TO_RGB(y, u, v, r, g, b);
1968 *(*output) = (unsigned char)((r & 0xc0) +
1974 static inline void transfer_YUV161616_to_BGR565(unsigned char *(*output), uint16_t *input)
1979 y = (((int)input[0]) << 8) | (input[0] >> 8);
1982 YUV_TO_RGB(y, u, v, r, g, b);
1983 *(uint16_t*)(*output) = ((b & 0xf8) << 8)
1985 + ((r & 0xf8) >> 3);
1989 static inline void transfer_YUV161616_to_RGB565(unsigned char *(*output), uint16_t *input)
1994 y = (((int)input[0]) << 8) | (input[0] >> 8);
1997 YUV_TO_RGB(y, u, v, r, g, b);
1998 *(uint16_t*)(*output) = ((r & 0xf8) << 8)
2000 + ((b & 0xf8) >> 3);
2004 static inline void transfer_YUV161616_to_BGR888(unsigned char *(*output), uint16_t *input)
2009 y = (((int)input[0]) << 8) | (input[0] >> 8);
2012 YUV_TO_RGB16(y, u, v, r, g, b);
2014 *(*output)++ = b >> 8;
2015 *(*output)++ = g >> 8;
2016 *(*output)++ = r >> 8;
2019 static inline void transfer_YUV161616_to_RGB888(unsigned char *(*output), uint16_t *input)
2024 y = (((int)input[0]) << 8) | (input[0] >> 8);
2027 YUV_TO_RGB16(y, u, v, r, g, b);
2029 *(*output)++ = r >> 8;
2030 *(*output)++ = g >> 8;
2031 *(*output)++ = b >> 8;
2034 static inline void transfer_YUV161616_to_RGBA8888(unsigned char *(*output), uint16_t *input)
2039 y = (((int)input[0]) << 8) | (input[0] >> 8);
2042 YUV_TO_RGB16(y, u, v, r, g, b);
2044 *(*output)++ = r >> 8;
2045 *(*output)++ = g >> 8;
2046 *(*output)++ = b >> 8;
2047 *(*output)++ = 0xff;
2050 static inline void transfer_YUV161616_to_ARGB8888(unsigned char *(*output), uint16_t *input)
2055 y = (((int)input[0]) << 8) | (input[0] >> 8);
2058 YUV_TO_RGB16(y, u, v, r, g, b);
2060 *(*output)++ = 0xff;
2061 *(*output)++ = r >> 8;
2062 *(*output)++ = g >> 8;
2063 *(*output)++ = b >> 8;
2066 static inline void transfer_YUV161616_to_RGB_FLOAT(float *(*output), uint16_t *input)
2068 float y = (float)input[0] / 0xffff;
2074 YUV16_TO_RGB_FLOAT(y, u, v, r, g, b);
2081 static inline void transfer_YUV161616_to_RGBA_FLOAT(float *(*output), uint16_t *input)
2083 float y = (float)input[0] / 0xffff;
2089 YUV16_TO_RGB_FLOAT(y, u, v, r, g, b);
2097 static inline void transfer_YUV161616_to_BGR8888(unsigned char *(*output), uint16_t *input)
2102 y = (((int)input[0]) << 8) | (input[0] >> 8);
2105 YUV_TO_RGB(y, u, v, r, g, b);
2112 static inline void transfer_YUV161616_to_YUV161616(uint16_t *(*output), uint16_t *input)
2114 (*output)[0] = input[0];
2115 (*output)[1] = input[1];
2116 (*output)[2] = input[2];
2120 static inline void transfer_YUV161616_to_YUVA8888(unsigned char *(*output), uint16_t *input)
2122 (*output)[0] = input[0] >> 8;
2123 (*output)[1] = input[1] >> 8;
2124 (*output)[2] = input[2] >> 8;
2130 static inline void transfer_YUV161616_to_VYU888(unsigned char *(*output), uint16_t *input)
2132 (*output)[0] = input[2] >> 8;
2133 (*output)[1] = input[0] >> 8;
2134 (*output)[2] = input[1] >> 8;
2139 static inline void transfer_YUV161616_to_UYVA8888(unsigned char *(*output), uint16_t *input)
2141 (*output)[0] = input[1] >> 8;
2142 (*output)[1] = input[0] >> 8;
2143 (*output)[2] = input[2] >> 8;
2144 (*output)[3] = input[3] >> 8;
2148 static inline void transfer_YUV161616_to_YUV101010(unsigned char *(*output), uint16_t *input)
2150 uint16_t y_i = input[0];
2151 uint16_t u_i = input[1];
2152 uint16_t v_i = input[2];
2153 WRITE_YUV101010(y_i, u_i, v_i);
2156 static inline void transfer_YUV161616_to_YUV420P_YUV422P(unsigned char *output_y,
2157 unsigned char *output_u,
2158 unsigned char *output_v,
2162 output_y[output_column] = input[0] >> 8;
2163 output_u[output_column / 2] = input[1] >> 8;
2164 output_v[output_column / 2] = input[2] >> 8;
2167 static inline void transfer_YUV161616_to_YUV444P(unsigned char *output_y,
2168 unsigned char *output_u,
2169 unsigned char *output_v,
2173 output_y[output_column] = input[0] >> 8;
2174 output_u[output_column] = input[1] >> 8;
2175 output_v[output_column] = input[2] >> 8;
2178 static inline void transfer_YUV161616_to_YUV422(unsigned char *(*output),
2182 // Store U and V for even pixels only
2185 (*output)[1] = input[1] >> 8;
2186 (*output)[3] = input[2] >> 8;
2187 (*output)[0] = input[0] >> 8;
2190 // Store Y and advance output for odd pixels only
2192 (*output)[2] = input[0] >> 8;
2207 // ******************************** YUVA16161616 -> ***************************
2212 static inline void transfer_YUVA16161616_to_RGB8(unsigned char *(*output), uint16_t *input)
2218 y = (((int)input[0]) << 8) | (input[0] >> 8);
2221 YUV_TO_RGB(y, u, v, r, g, b);
2227 *(*output) = (unsigned char)(((r & 0xc000) >> 8) +
2228 ((g & 0xe000) >> 10) +
2229 ((b & 0xe000) >> 13));
2233 static inline void transfer_YUVA16161616_to_BGR565(unsigned char *(*output), uint16_t *input)
2239 y = (((int)input[0]) << 8) | (input[0] >> 8);
2242 YUV_TO_RGB(y, u, v, r, g, b);
2248 *(uint16_t*)(*output) = (uint16_t)((b & 0xf800) +
2249 ((g & 0xfc00) >> 5) +
2250 ((r & 0xf800) >> 11));
2254 static inline void transfer_YUVA16161616_to_RGB565(unsigned char *(*output), uint16_t *input)
2260 y = (((int)input[0]) << 8) | (input[0] >> 8);
2263 YUV_TO_RGB(y, u, v, r, g, b);
2269 *(uint16_t*)(*output) = (uint16_t)((r & 0xf800) +
2270 ((g & 0xfc00) >> 5) +
2271 ((b & 0xf800) >> 11));
2275 static inline void transfer_YUVA16161616_to_BGR888(unsigned char *(*output), uint16_t *input)
2281 y = (((int)input[0]) << 8) | (input[0] >> 8);
2285 YUV_TO_RGB16(y, u, v, r, g, b);
2291 *(*output)++ = b / 0xffff00;
2292 *(*output)++ = g / 0xffff00;
2293 *(*output)++ = r / 0xffff00;
2296 static inline void transfer_YUVA16161616_to_RGB888(unsigned char *(*output), uint16_t *input)
2298 unsigned int y, u, v, a;
2299 unsigned int r, g, b;
2302 y = (((int)input[0]) << 8) | (input[0] >> 8);
2306 YUV_TO_RGB16(y, u, v, r, g, b);
2324 static inline void transfer_YUVA16161616_to_RGBA8888(unsigned char *(*output), uint16_t *input)
2326 unsigned int y, u, v;
2327 unsigned int r, g, b;
2329 y = (((int)input[0]) << 8) | (input[0] >> 8);
2333 YUV_TO_RGB16(y, u, v, r, g, b);
2335 *(*output)++ = (r >> 8);
2336 *(*output)++ = (g >> 8);
2337 *(*output)++ = (b >> 8);
2338 *(*output)++ = input[3] >> 8;
2341 static inline void transfer_YUVA16161616_to_ARGB8888(unsigned char *(*output), uint16_t *input)
2343 unsigned int y, u, v;
2344 unsigned int r, g, b;
2346 y = (((int)input[0]) << 8) | (input[0] >> 8);
2350 YUV_TO_RGB16(y, u, v, r, g, b);
2352 *(*output)++ = input[3] >> 8;
2353 *(*output)++ = (r >> 8);
2354 *(*output)++ = (g >> 8);
2355 *(*output)++ = (b >> 8);
2358 static inline void transfer_YUVA16161616_to_RGB_FLOAT(float *(*output),
2365 y = (float)input[0] / 0xffff;
2368 a = (float)input[3] / 0xffff;
2370 YUV16_TO_RGB_FLOAT(y, u, v, r, g, b);
2381 static inline void transfer_YUVA16161616_to_RGBA_FLOAT(float *(*output),
2388 y = (float)input[0] / 0xffff;
2391 a = (float)input[3] / 0xffff;
2393 YUV16_TO_RGB_FLOAT(y, u, v, r, g, b);
2401 static inline void transfer_YUVA16161616_to_BGR8888(unsigned char *(*output),
2408 y = (((int)input[0]) << 8) | (input[0] >> 8);
2412 YUV_TO_RGB(y, u, v, r, g, b);
2428 static inline void transfer_YUVA16161616_to_VYU888(unsigned char *(*output), uint16_t *input)
2430 int y, u, v, a, anti_a;
2432 anti_a = 0xffff - a;
2433 y = ((uint32_t)input[0] * a) / 0xffff00;
2434 u = ((uint32_t)input[1] * a + 0x8000 * anti_a) / 0xffff00;
2435 v = ((uint32_t)input[2] * a + 0x8000 * anti_a) / 0xffff00;
2443 static inline void transfer_YUVA16161616_to_YUVA16161616(uint16_t *(*output), uint16_t *input)
2445 (*output)[0] = input[0];
2446 (*output)[1] = input[1];
2447 (*output)[2] = input[2];
2448 (*output)[3] = input[3];
2452 static inline void transfer_YUVA16161616_to_UYVA8888(unsigned char *(*output), uint16_t *input)
2454 (*output)[0] = input[1] >> 8;
2455 (*output)[1] = input[0] >> 8;
2456 (*output)[2] = input[2] >> 8;
2457 (*output)[3] = input[3] >> 8;
2462 static inline void transfer_YUVA16161616_to_YUV101010(unsigned char *(*output), uint16_t *input)
2464 int64_t opacity = input[3];
2465 int64_t transparency = 0xffff - opacity;
2466 uint16_t y_i = ((int64_t)input[0] * opacity + (int64_t)0x8000 * transparency) / 0xffff;
2467 uint16_t u_i = ((int64_t)input[1] * opacity + (int64_t)0x8000 * transparency) / 0xffff;
2468 uint16_t v_i = ((int64_t)input[2] * opacity + (int64_t)0x8000 * transparency) / 0xffff;
2469 WRITE_YUV101010(y_i, u_i, v_i);
2472 static inline void transfer_YUVA16161616_to_YUV420P_YUV422P(unsigned char *output_y,
2473 unsigned char *output_u,
2474 unsigned char *output_v,
2478 int64_t opacity = input[3];
2479 int64_t transparency = 0xffff - opacity;
2481 output_y[output_column] = ((int64_t)input[0] * opacity) / 0xffff00;
2482 output_u[output_column / 2] = ((int64_t)input[1] * opacity + 0x8000 * transparency) / 0xffff00;
2483 output_v[output_column / 2] = ((int64_t)input[2] * opacity + 0x8000 * transparency) / 0xffff00;
2486 static inline void transfer_YUVA16161616_to_YUV444P(unsigned char *output_y,
2487 unsigned char *output_u,
2488 unsigned char *output_v,
2492 int64_t opacity = input[3];
2493 int64_t transparency = 0xffff - opacity;
2495 output_y[output_column] = ((int64_t)input[0] * opacity) / 0xffff00;
2496 output_u[output_column] = ((int64_t)input[1] * opacity + 0x8000 * transparency) / 0xffff00;
2497 output_v[output_column] = ((int64_t)input[2] * opacity + 0x8000 * transparency) / 0xffff00;
2500 static inline void transfer_YUVA16161616_to_YUV422(unsigned char *(*output),
2504 int64_t opacity = input[3];
2505 int64_t transparency = 0xffff - opacity;
2507 // Store U and V for even pixels only
2510 (*output)[0] = ((int64_t)input[0] * opacity) / 0xffff00;
2511 (*output)[1] = ((int64_t)input[1] * opacity + 0x8000 * transparency) / 0xffff00;
2512 (*output)[3] = ((int64_t)input[2] * opacity + 0x8000 * transparency) / 0xffff00;
2515 // Store Y and advance output for odd pixels only
2517 (*output)[2] = (input[0] * opacity) / 0xffff00;
2559 #define ZTYP(ty) typedef ty z_##ty __attribute__ ((__unused__))
2563 // ******************************** Loops *************************************
2565 #define TRANSFER_FRAME_HEAD \
2566 for(i = 0; i < out_h; i++) \
2568 unsigned char *output_row = output_rows[i + out_y] + out_x * out_pixelsize; \
2569 unsigned char *input_row = input_rows[row_table[i]]; \
2570 z_int bit_counter = 7; \
2571 for(j = 0; j < out_w; j++) \
2574 #define TRANSFER_FRAME_TAIL \
2578 #define TRANSFER_YUV420P_OUT_HEAD \
2579 for(i = 0; i < out_h; i++) \
2581 unsigned char *input_row = input_rows[row_table[i]]; \
2582 unsigned char *output_y = out_y_plane + i * total_out_w + out_x; \
2583 unsigned char *output_u = out_u_plane + i / 2 * total_out_w / 2 + out_x / 2; \
2584 unsigned char *output_v = out_v_plane + i / 2 * total_out_w / 2 + out_x / 2; \
2585 for(j = 0; j < out_w; j++) \
2588 #define TRANSFER_YUV422P_OUT_HEAD \
2589 for(i = 0; i < out_h; i++) \
2591 unsigned char *input_row = input_rows[row_table[i]]; \
2592 unsigned char *output_y = out_y_plane + i * total_out_w + out_x; \
2593 unsigned char *output_u = out_u_plane + i * total_out_w / 2 + out_x / 2; \
2594 unsigned char *output_v = out_v_plane + i * total_out_w / 2 + out_x / 2; \
2595 for(j = 0; j < out_w; j++) \
2598 #define TRANSFER_YUV444P_OUT_HEAD \
2599 for(i = 0; i < out_h; i++) \
2601 unsigned char *input_row = input_rows[row_table[i]]; \
2602 unsigned char *output_y = out_y_plane + i * total_out_w + out_x; \
2603 unsigned char *output_u = out_u_plane + i * total_out_w + out_x; \
2604 unsigned char *output_v = out_v_plane + i * total_out_w + out_x; \
2605 for(j = 0; j < out_w; j++) \
2608 #define TRANSFER_YUV420P_IN_HEAD \
2609 for(i = 0; i < out_h; i++) \
2611 unsigned char *output_row = output_rows[i + out_y] + out_x * out_pixelsize; \
2612 unsigned char *input_y = in_y_plane + row_table[i] * total_in_w; \
2613 unsigned char *input_u = in_u_plane + (row_table[i] / 2) * (total_in_w / 2); \
2614 unsigned char *input_v = in_v_plane + (row_table[i] / 2) * (total_in_w / 2); \
2615 for(j = 0; j < out_w; j++) \
2618 #define TRANSFER_YUV9P_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] / 4) * (total_in_w / 4); \
2624 unsigned char *input_v = in_v_plane + (row_table[i] / 4) * (total_in_w / 4); \
2625 for(j = 0; j < out_w; j++) \
2629 #define TRANSFER_YUV422P_IN_HEAD \
2630 for(i = 0; i < out_h; i++) \
2632 unsigned char *output_row = output_rows[i + out_y] + out_x * out_pixelsize; \
2633 unsigned char *input_y = in_y_plane + row_table[i] * total_in_w; \
2634 unsigned char *input_u = in_u_plane + row_table[i] * (total_in_w / 2); \
2635 unsigned char *input_v = in_v_plane + row_table[i] * (total_in_w / 2); \
2636 for(j = 0; j < out_w; j++) \
2639 #define TRANSFER_YUV444P_IN_HEAD \
2640 for(i = 0; i < out_h; i++) \
2642 unsigned char *output_row = output_rows[i + out_y] + out_x * out_pixelsize; \
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; \
2645 unsigned char *input_v = in_v_plane + row_table[i] * total_in_w; \
2646 for(j = 0; j < out_w; j++) \
2650 #define TRANSFER_YUV422_IN_HEAD \
2651 for(i = 0; i < out_h; i++) \
2653 unsigned char *output_row = output_rows[i + out_y] + ((out_x * out_pixelsize) & 0xfffffffc); \
2654 unsigned char *input_y = in_y_plane + row_table[i] * total_in_w; \
2655 unsigned char *input_u = in_u_plane + row_table[i] * (total_in_w / 2); \
2656 unsigned char *input_v = in_v_plane + row_table[i] * (total_in_w / 2); \
2657 for(j = 0; j < out_w; j++) \
2664 // ******************************** Permutation *******************************
2668 #define PERMUTATION_ARGS \
2669 unsigned char **output_rows, \
2670 unsigned char **input_rows, \
2671 unsigned char *out_y_plane, \
2672 unsigned char *out_u_plane, \
2673 unsigned char *out_v_plane, \
2674 unsigned char *in_y_plane, \
2675 unsigned char *in_u_plane, \
2676 unsigned char *in_v_plane, \
2685 int in_colormodel, \
2686 int out_colormodel, \
2691 int out_pixelsize, \
2694 int *column_table, \
2699 void cmodel_float(PERMUTATION_ARGS);
2700 void cmodel_yuv420p(PERMUTATION_ARGS);
2701 void cmodel_yuv9p(PERMUTATION_ARGS);
2702 void cmodel_yuv444p(PERMUTATION_ARGS);
2703 void cmodel_yuv422(PERMUTATION_ARGS);
2704 void cmodel_default(PERMUTATION_ARGS);