"Fossies" - the Fresh Open Source Software Archive

Member "quicktime4linux-2.3/cmodel_permutation.h" (9 Jan 2007, 58724 Bytes) of package /linux/privat/old/quicktime4linux-2.3-src.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /*
    2  * This library is free software; you can redistribute it and/or modify it
    3  * under the terms of the GNU Lesser General Public License as published
    4  * by the Free Software Foundation; either version 2 of the License, or
    5  * (at your option) any later version.
    6  * 
    7  * This library is distributed in the hope that it will be useful, but
    8  * WITHOUT ANY WARRANTY; without even the implied warranty of
    9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   10  * Lesser General Public License for more details.
   11  * 
   12  * You should have received a copy of the GNU Lesser General Public
   13  * License along with this library; if not, write to the Free Software
   14  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 
   15  * USA
   16  */
   17 #include "colormodels.h"
   18 #include <stdint.h>
   19 
   20 // All variables are unsigned
   21 // y -> 24 bits u, v, -> 8 bits r, g, b -> 8 bits
   22 #define YUV_TO_RGB(y, u, v, r, g, b) \
   23 { \
   24     (r) = ((y + yuv_table->vtor_tab[v]) >> 16); \
   25     (g) = ((y + yuv_table->utog_tab[u] + yuv_table->vtog_tab[v]) >> 16); \
   26     (b) = ((y + yuv_table->utob_tab[u]) >> 16); \
   27     CLAMP(r, 0, 0xff); \
   28     CLAMP(g, 0, 0xff); \
   29     CLAMP(b, 0, 0xff); \
   30 }
   31 
   32 // y -> 0 - 1 float
   33 // u, v, -> 8 bits
   34 // r, g, b -> float
   35 #define YUV_TO_FLOAT(y, u, v, r, g, b) \
   36 { \
   37     (r) = y + yuv_table->vtor_float_tab[v]; \
   38     (g) = y + yuv_table->utog_float_tab[u] + yuv_table->vtog_float_tab[v]; \
   39     (b) = y + yuv_table->utob_float_tab[u]; \
   40 }
   41 
   42 // y -> 0 - 1 float
   43 // u, v, -> 16 bits
   44 // r, g, b -> float
   45 #define YUV16_TO_RGB_FLOAT(y, u, v, r, g, b) \
   46 { \
   47     (r) = y + yuv_table->v16tor_float_tab[v]; \
   48     (g) = y + yuv_table->u16tog_float_tab[u] + yuv_table->v16tog_float_tab[v]; \
   49     (b) = y + yuv_table->u16tob_float_tab[u]; \
   50 }
   51 
   52 // y -> 24 bits   u, v-> 16 bits
   53 #define YUV_TO_RGB16(y, u, v, r, g, b) \
   54 { \
   55     (r) = ((y + yuv_table->vtor_tab16[v]) >> 8); \
   56     (g) = ((y + yuv_table->utog_tab16[u] + yuv_table->vtog_tab16[v]) >> 8); \
   57     (b) = ((y + yuv_table->utob_tab16[u]) >> 8); \
   58     CLAMP(r, 0, 0xffff); \
   59     CLAMP(g, 0, 0xffff); \
   60     CLAMP(b, 0, 0xffff); \
   61 }
   62 
   63 
   64 
   65 
   66 #define RGB_TO_YUV(y, u, v, r, g, b) \
   67 { \
   68     y = ((yuv_table->rtoy_tab[r] + yuv_table->gtoy_tab[g] + yuv_table->btoy_tab[b]) >> 16); \
   69     u = ((yuv_table->rtou_tab[r] + yuv_table->gtou_tab[g] + yuv_table->btou_tab[b]) >> 16); \
   70     v = ((yuv_table->rtov_tab[r] + yuv_table->gtov_tab[g] + yuv_table->btov_tab[b]) >> 16); \
   71     CLAMP(y, 0, 0xff); \
   72     CLAMP(u, 0, 0xff); \
   73     CLAMP(v, 0, 0xff); \
   74 }
   75 
   76 // r, g, b -> 16 bits
   77 #define RGB_TO_YUV16(y, u, v, r, g, b) \
   78 { \
   79     y = ((yuv_table->rtoy_tab16[r] + yuv_table->gtoy_tab16[g] + yuv_table->btoy_tab16[b]) >> 8); \
   80     u = ((yuv_table->rtou_tab16[r] + yuv_table->gtou_tab16[g] + yuv_table->btou_tab16[b]) >> 8); \
   81     v = ((yuv_table->rtov_tab16[r] + yuv_table->gtov_tab16[g] + yuv_table->btov_tab16[b]) >> 8); \
   82     CLAMP(y, 0, 0xffff); \
   83     CLAMP(u, 0, 0xffff); \
   84     CLAMP(v, 0, 0xffff); \
   85 }
   86 
   87 #define WRITE_YUV101010(y, u, v) \
   88 { \
   89     uint32_t output_i = ((y & 0xffc0) << 16) | \
   90         ((u & 0xffc0) << 6) | \
   91         ((v & 0xffc0) >> 4); \
   92     *(*output)++ = (output_i & 0xff); \
   93     *(*output)++ = (output_i & 0xff00) >> 8; \
   94     *(*output)++ = (output_i & 0xff0000) >> 16; \
   95     *(*output)++ = (output_i & 0xff000000) >> 24; \
   96 }
   97 
   98 
   99 
  100 // ****************************** Pixel transfers *****************************
  101 
  102 
  103 
  104 
  105 
  106 
  107 // ****************************** ARGB8888 -> *********************************
  108 
  109 static inline void transfer_ARGB8888_to_ARGB8888(unsigned char *(*output), unsigned char *input)
  110 {
  111     (*output)[0] = input[0];
  112     (*output)[1] = input[1];
  113     (*output)[2] = input[2];
  114     (*output)[3] = input[3];
  115     (*output) += 4;
  116 }
  117 
  118 static inline void transfer_ARGB8888_to_RGBA8888(unsigned char *(*output), unsigned char *input)
  119 {
  120     (*output)[0] = input[1];
  121     (*output)[1] = input[2];
  122     (*output)[2] = input[3];
  123     (*output)[3] = input[0];
  124     (*output) += 4;
  125 }
  126 
  127 
  128 static inline void transfer_ARGB8888_to_RGB888(unsigned char *(*output), unsigned char *input)
  129 {
  130     int a = input[0];
  131     (*output)[0] = input[1] * a / 0xff;
  132     (*output)[1] = input[2] * a / 0xff;
  133     (*output)[2] = input[3] * a / 0xff;
  134     (*output) += 3;
  135 }
  136 
  137 static inline void transfer_ARGB8888_to_BGR8888(unsigned char *(*output), unsigned char *input)
  138 {
  139     int a = input[0];
  140     (*output)[0] = input[3] * a / 0xff;
  141     (*output)[1] = input[2] * a / 0xff;
  142     (*output)[2] = input[1] * a / 0xff;
  143     (*output) += 3;
  144 }
  145 
  146 
  147 
  148 
  149 
  150 
  151 
  152 
  153 
  154 
  155 
  156 
  157 
  158 
  159 
  160 // ******************************** RGB888 -> *********************************
  161 
  162 static inline void transfer_RGB888_to_RGB8(unsigned char *(*output), unsigned char *input)
  163 {
  164     *(*output) = (unsigned char)((input[0] & 0xc0) +
  165                              ((input[1] & 0xe0) >> 2) +
  166                              ((input[2] & 0xe0) >> 5));
  167     (*output)++;
  168 }
  169 
  170 static inline void transfer_RGB888_to_BGR565(unsigned char *(*output), unsigned char *input)
  171 {
  172     uint16_t r, g, b;
  173     uint16_t r_s, g_s, b_s;
  174     r = *input++;
  175     g = *input++;
  176     b = *input;
  177     
  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;
  186 
  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;
  195 
  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;
  204 
  205     *(uint16_t*)(*output) = ((b_s & 0xf8) << 8)
  206              + ((g_s & 0xfc) << 3)
  207              + ((r_s & 0xf8) >> 3);
  208     (*output) += 2;
  209 }
  210 
  211 static inline void transfer_RGB888_to_RGB565(unsigned char *(*output), unsigned char *input)
  212 {
  213     uint16_t r, g, b;
  214     r = *input++;
  215     g = *input++;
  216     b = *input;
  217     *(uint16_t*)(*output) = ((r & 0xf8) << 8)
  218              + ((g & 0xfc) << 3)
  219              + ((b & 0xf8) >> 3);
  220     (*output) += 2;
  221 }
  222 
  223 static inline void transfer_RGB888_to_BGR888(unsigned char *(*output), unsigned char *input)
  224 {
  225     *(*output)++ = input[2];
  226     *(*output)++ = input[1];
  227     *(*output)++ = input[0];
  228 }
  229 
  230 static inline void transfer_RGB888_to_RGB888(unsigned char *(*output), unsigned char *input)
  231 {
  232     *(*output)++ = *input++;
  233     *(*output)++ = *input++;
  234     *(*output)++ = *input;
  235 }
  236 
  237 static inline void transfer_RGB888_to_RGBA8888(unsigned char *(*output), unsigned char *input)
  238 {
  239     *(*output)++ = *input++;
  240     *(*output)++ = *input++;
  241     *(*output)++ = *input;
  242     *(*output)++ = 0xff;
  243 }
  244 
  245 static inline void transfer_RGB888_to_ARGB8888(unsigned char *(*output), unsigned char *input)
  246 {
  247     *(*output)++ = 0xff;
  248     *(*output)++ = *input++;
  249     *(*output)++ = *input++;
  250     *(*output)++ = *input;
  251 }
  252 
  253 static inline void transfer_RGB888_to_RGB161616(uint16_t *(*output), unsigned char *input)
  254 {
  255     (*output)[0] = (input[0] << 8) | input[0];
  256     (*output)[1] = (input[1] << 8) | input[1];
  257     (*output)[2] = (input[2] << 8) | input[2];
  258     (*output) += 3;
  259 }
  260 
  261 static inline void transfer_RGB888_to_RGBA16161616(uint16_t *(*output), unsigned char *input)
  262 {
  263     (*output)[0] = (input[0] << 8) | input[0];
  264     (*output)[1] = (input[1] << 8) | input[1];
  265     (*output)[2] = (input[2] << 8) | input[2];
  266     (*output)[3] = 0xffff;
  267     (*output) += 4;
  268 }
  269 
  270 static inline void transfer_RGB888_to_RGB_FLOAT(float *(*output), unsigned char *input)
  271 {
  272     *(*output)++ = (float)*input++ / 0xff;
  273     *(*output)++ = (float)*input++ / 0xff;
  274     *(*output)++ = (float)*input / 0xff;
  275 }
  276 
  277 static inline void transfer_RGB888_to_RGBA_FLOAT(float *(*output), unsigned char *input)
  278 {
  279     *(*output)++ = (float)*input++ / 0xff;
  280     *(*output)++ = (float)*input++ / 0xff;
  281     *(*output)++ = (float)*input / 0xff;
  282     *(*output)++ = 1.0;
  283 }
  284 
  285 static inline void transfer_RGB888_to_ABGR8888(unsigned char *(*output), unsigned char *input)
  286 {
  287     *(*output)++ = 0xff;
  288     *(*output)++ = input[2];
  289     *(*output)++ = input[1];
  290     *(*output)++ = input[0];
  291 }
  292 
  293 static inline void transfer_RGB888_to_BGR8888(unsigned char *(*output), unsigned char *input)
  294 {
  295     *(*output)++ = input[2];
  296     *(*output)++ = input[1];
  297     *(*output)++ = input[0];
  298     (*output)++;
  299 }
  300 
  301 static inline void transfer_RGB888_to_YUV888(unsigned char *(*output), unsigned char *input)
  302 {
  303     int y, u, v;
  304 
  305     RGB_TO_YUV(y, u, v, input[0], input[1], input[2]);
  306 
  307     *(*output)++ = y;
  308     *(*output)++ = u;
  309     *(*output)++ = v;
  310 }
  311 
  312 
  313 static inline void transfer_RGB888_to_YUV101010(unsigned char *(*output), unsigned char *input)
  314 {
  315     int r, g, b;
  316     int y, u, v;
  317 
  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);
  323 }
  324 
  325 static inline void transfer_RGB888_to_VYU888(unsigned char *(*output), unsigned char *input)
  326 {
  327     int y, u, v;
  328 
  329     RGB_TO_YUV(y, u, v, input[0], input[1], input[2]);
  330 
  331     *(*output)++ = v;
  332     *(*output)++ = y;
  333     *(*output)++ = u;
  334 }
  335 
  336 static inline void transfer_RGB888_to_UYVA8888(unsigned char *(*output), unsigned char *input)
  337 {
  338     int y, u, v;
  339 
  340     RGB_TO_YUV(y, u, v, input[0], input[1], input[2]);
  341 
  342     *(*output)++ = u;
  343     *(*output)++ = y;
  344     *(*output)++ = v;
  345     *(*output)++ = 0xff;
  346 }
  347 
  348 
  349 
  350 static inline void transfer_RGB888_to_YUVA8888(unsigned char *(*output), unsigned char *input)
  351 {
  352     int y, u, v;
  353 
  354     RGB_TO_YUV(y, u, v, input[0], input[1], input[2]);
  355 
  356     *(*output)++ = y;
  357     *(*output)++ = u;
  358     *(*output)++ = v;
  359     *(*output)++ = 255;
  360 }
  361 
  362 static inline void transfer_RGB888_to_YUV161616(uint16_t *(*output), unsigned char *input)
  363 {
  364     int y, u, v, opacity, r, g, b;
  365     
  366     r = ((int)input[0] << 8) | input[0];
  367     g = ((int)input[1] << 8) | input[1];
  368     b = ((int)input[2] << 8) | input[2];
  369 
  370     RGB_TO_YUV16(y, u, v, r, g, b);
  371 
  372     *(*output)++ = y;
  373     *(*output)++ = u;
  374     *(*output)++ = v;
  375 }
  376 
  377 static inline void transfer_RGB888_to_YUVA16161616(uint16_t *(*output), unsigned char *input)
  378 {
  379     int y, u, v, r, g, b;
  380 
  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);
  385 
  386     *(*output)++ = y;
  387     *(*output)++ = u;
  388     *(*output)++ = v;
  389     *(*output)++ = 0xffff;
  390 }
  391 
  392 static inline void transfer_RGB888_to_YUV420P_YUV422P(unsigned char *output_y, 
  393     unsigned char *output_u, 
  394     unsigned char *output_v, 
  395     unsigned char *input,
  396     int output_column)
  397 {
  398     int y, u, v;
  399 
  400     RGB_TO_YUV(y, u, v, input[0], input[1], input[2]);
  401 
  402     output_y[output_column] = y;
  403     output_u[output_column / 2] = u;
  404     output_v[output_column / 2] = v;
  405 }
  406 
  407 static inline void transfer_RGB888_to_YUV444P(unsigned char *output_y, 
  408     unsigned char *output_u, 
  409     unsigned char *output_v, 
  410     unsigned char *input,
  411     int output_column)
  412 {
  413     int y, u, v;
  414 
  415     RGB_TO_YUV(y, u, v, input[0], input[1], input[2]);
  416 
  417     output_y[output_column] = y;
  418     output_u[output_column] = u;
  419     output_v[output_column] = v;
  420 }
  421 
  422 static inline void transfer_RGB888_to_YUV422(unsigned char *(*output), 
  423     unsigned char *input,
  424     int j)
  425 {
  426     int y, u, v;
  427 
  428     RGB_TO_YUV(y, u, v, input[0], input[1], input[2]);
  429 
  430     if(!(j & 1))
  431     { 
  432 // Store U and V for even pixels only
  433          (*output)[1] = u;
  434          (*output)[3] = v;
  435          (*output)[0] = y;
  436     }
  437     else
  438     { 
  439 // Store Y and advance output for odd pixels only
  440          (*output)[2] = y;
  441          (*output) += 4;
  442     }
  443 
  444 }
  445 
  446 
  447 
  448 
  449 
  450 
  451 
  452 // *************************** RGBA8888 -> ************************************
  453 
  454 static inline void transfer_RGBA8888_to_TRANSPARENCY(unsigned char *(*output), unsigned char *input, int (*bit_counter))
  455 {
  456     if((*bit_counter) == 7) *(*output) = 0;
  457 
  458     if(input[3] < 127) 
  459     {
  460         *(*output) |= (unsigned char)1 << (7 - (*bit_counter));
  461     }
  462 
  463     if((*bit_counter) == 0)
  464     {
  465         (*output)++;
  466         (*bit_counter) = 7;
  467     }
  468     else
  469         (*bit_counter)--;
  470 }
  471 
  472 // These routines blend in a background color since they should be
  473 // exclusively used for widgets.
  474 
  475 static inline void transfer_RGBA8888_to_RGB8bg(unsigned char *(*output), unsigned char *input, int bg_r, int bg_g, int bg_b)
  476 {
  477     unsigned int r, g, b, a, anti_a;
  478     a = input[3];
  479     anti_a = 255 - a;
  480     r = ((unsigned int)input[0] * a + bg_r * anti_a) / 0xff;
  481     g = ((unsigned int)input[1] * a + bg_g * anti_a) / 0xff;
  482     b = ((unsigned int)input[2] * a + bg_b * anti_a) / 0xff;
  483     *(*output) = (unsigned char)((r & 0xc0) + 
  484                 ((g & 0xe0) >> 2) + 
  485                 ((b & 0xe0) >> 5));
  486     (*output)++;
  487 }
  488 
  489 static inline void transfer_RGBA8888_to_BGR565bg(unsigned char *(*output), unsigned char *input, int bg_r, int bg_g, int bg_b)
  490 {
  491     unsigned int r, g, b, a, anti_a;
  492     a = input[3];
  493     anti_a = 255 - a;
  494     r = ((unsigned int)input[0] * a + bg_r * anti_a) / 0xff;
  495     g = ((unsigned int)input[1] * a + bg_g * anti_a) / 0xff;
  496     b = ((unsigned int)input[2] * a + bg_b * anti_a) / 0xff;
  497     *(uint16_t*)(*output) = (uint16_t)(((b & 0xf8) << 8) + 
  498                 ((g & 0xfc) << 3) + 
  499                 ((r & 0xf8) >> 3));
  500     (*output) += 2;
  501 }
  502 
  503 static inline void transfer_RGBA8888_to_RGB565bg(unsigned char *(*output), unsigned char *input, int bg_r, int bg_g, int bg_b)
  504 {
  505     unsigned int r, g, b, a, anti_a;
  506     a = input[3];
  507     anti_a = 255 - a;
  508     r = ((unsigned int)input[0] * a + bg_r * anti_a) / 0xff;
  509     g = ((unsigned int)input[1] * a + bg_g * anti_a) / 0xff;
  510     b = ((unsigned int)input[2] * a + bg_b * anti_a) / 0xff;
  511     *(uint16_t*)(*output) = (uint16_t)(((r & 0xf8) << 8)+ 
  512                 ((g & 0xfc) << 3) + 
  513                 ((b & 0xf8) >> 3));
  514     (*output) += 2;
  515 }
  516 
  517 static inline void transfer_RGBA8888_to_BGR888bg(unsigned char *(*output), unsigned char *input, int bg_r, int bg_g, int bg_b)
  518 {
  519     unsigned int r, g, b, a, anti_a;
  520     a = input[3];
  521     anti_a = 255 - a;
  522     r = ((unsigned int)input[0] * a + bg_r * anti_a) / 0xff;
  523     g = ((unsigned int)input[1] * a + bg_g * anti_a) / 0xff;
  524     b = ((unsigned int)input[2] * a + bg_b * anti_a) / 0xff;
  525     *(*output)++ = b;
  526     *(*output)++ = g;
  527     *(*output)++ = r;
  528 }
  529 
  530 static inline void transfer_RGBA8888_to_RGB888bg(unsigned char *(*output), unsigned char *input, int bg_r, int bg_g, int bg_b)
  531 {
  532     unsigned int r, g, b, a, anti_a;
  533     a = input[3];
  534     anti_a = 255 - a;
  535     r = ((unsigned int)input[0] * a + bg_r * anti_a) / 0xff;
  536     g = ((unsigned int)input[1] * a + bg_g * anti_a) / 0xff;
  537     b = ((unsigned int)input[2] * a + bg_b * anti_a) / 0xff;
  538     *(*output)++ = r;
  539     *(*output)++ = g;
  540     *(*output)++ = b;
  541 }
  542 
  543 static inline void transfer_RGBA8888_to_BGR8888bg(unsigned char *(*output), unsigned char *input, int bg_r, int bg_g, int bg_b)
  544 {
  545     unsigned int r, g, b, a, anti_a;
  546     a = input[3];
  547     anti_a = 255 - a;
  548 
  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;
  552 
  553     *(*output)++ = b;
  554     *(*output)++ = g;
  555     *(*output)++ = r;
  556     (*output)++;
  557 }
  558 
  559 
  560 
  561 
  562 
  563 
  564 
  565 // These routines blend in a black background
  566 
  567 static inline void transfer_RGBA8888_to_RGB8(unsigned char *(*output), unsigned char *input)
  568 {
  569     unsigned int r, g, b, a;
  570     a = input[3];
  571     r = (unsigned int)input[0] * a;
  572     g = (unsigned int)input[1] * a;
  573     b = (unsigned int)input[2] * a;
  574     *(*output) = (unsigned char)(((r & 0xc000) >> 8) + 
  575                 ((g & 0xe000) >> 10) + 
  576                 ((b & 0xe000) >> 13));
  577     (*output)++;
  578 }
  579 
  580 static inline void transfer_RGBA8888_to_BGR565(unsigned char *(*output), unsigned char *input)
  581 {
  582     unsigned int r, g, b, a;
  583     a = input[3];
  584     r = ((unsigned int)input[0] * a) / 0xff;
  585     g = ((unsigned int)input[1] * a) / 0xff;
  586     b = ((unsigned int)input[2] * a) / 0xff;
  587     *(uint16_t*)(*output) = (uint16_t)(((b & 0xf8) << 8) + 
  588                 ((g & 0xfc) << 3) + 
  589                 ((r & 0xf8) >> 3));
  590     (*output) += 2;
  591 }
  592 
  593 static inline void transfer_RGBA8888_to_RGB565(unsigned char *(*output), unsigned char *input)
  594 {
  595     unsigned int r, g, b, a;
  596     a = input[3];
  597     r = ((unsigned int)input[0] * a) / 0xff;
  598     g = ((unsigned int)input[1] * a) / 0xff;
  599     b = ((unsigned int)input[2] * a) / 0xff;
  600 
  601 
  602     *(uint16_t*)(*output) = (uint16_t)(((r & 0xf8) << 8) + 
  603                 ((g & 0xfc) << 3) + 
  604                 ((b & 0xf8) >> 3));
  605     (*output) += 2;
  606 }
  607 
  608 static inline void transfer_RGBA8888_to_BGR888(unsigned char *(*output), unsigned char *input)
  609 {
  610     unsigned int r, g, b, a;
  611     a = input[3];
  612     r = ((unsigned int)input[0] * a) / 0xff;
  613     g = ((unsigned int)input[1] * a) / 0xff;
  614     b = ((unsigned int)input[2] * a) / 0xff;
  615     *(*output)++ = b;
  616     *(*output)++ = g;
  617     *(*output)++ = r;
  618 }
  619 
  620 static inline void transfer_RGBA8888_to_RGB888(unsigned char *(*output), unsigned char *input)
  621 {
  622     unsigned int r, g, b, a;
  623     a = input[3];
  624     r = ((unsigned int)input[0] * a) / 0xff;
  625     g = ((unsigned int)input[1] * a) / 0xff;
  626     b = ((unsigned int)input[2] * a) / 0xff;
  627     *(*output)++ = r;
  628     *(*output)++ = g;
  629     *(*output)++ = b;
  630 }
  631 
  632 static inline void transfer_RGBA8888_to_RGBA8888(unsigned char *(*output), unsigned char *input)
  633 {
  634     (*output)[0] = input[0];
  635     (*output)[1] = input[1];
  636     (*output)[2] = input[2];
  637     (*output)[3] = input[3];
  638     (*output) += 4;
  639 }
  640 
  641 static inline void transfer_RGBA8888_to_ARGB8888(unsigned char *(*output), unsigned char *input)
  642 {
  643     (*output)[0] = input[3];
  644     (*output)[1] = input[0];
  645     (*output)[2] = input[1];
  646     (*output)[3] = input[2];
  647     (*output) += 4;
  648 }
  649 
  650 static inline void transfer_RGBA8888_to_RGB161616(uint16_t *(*output), unsigned char *input)
  651 {
  652     int y, u, v, opacity, r, g, b;
  653     
  654     opacity = input[3];
  655     (*output)[0] = (((int)input[0] << 8) | input[0]) * opacity / 0xff;
  656     (*output)[1] = (((int)input[1] << 8) | input[1]) * opacity / 0xff;
  657     (*output)[2] = (((int)input[2] << 8) | input[2]) * opacity / 0xff;
  658     (*output) += 3;
  659 }
  660 
  661 static inline void transfer_RGBA8888_to_RGBA16161616(uint16_t *(*output), unsigned char *input)
  662 {
  663     int y, u, v, r, g, b;
  664 
  665     (*output)[0] = (((int)input[0]) << 8) | input[0];
  666     (*output)[1] = (((int)input[1]) << 8) | input[1];
  667     (*output)[2] = (((int)input[2]) << 8) | input[2];
  668     (*output)[3] = (((int)input[3]) << 8) | input[3];
  669     (*output) += 4;
  670 }
  671 
  672 static inline void transfer_RGBA8888_to_RGB_FLOAT(float *(*output), unsigned char *input)
  673 {
  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;
  678 }
  679 
  680 static inline void transfer_RGBA8888_to_RGBA_FLOAT(float *(*output), unsigned char *input)
  681 {
  682     *(*output)++ = (float)*input++ / 0xff;
  683     *(*output)++ = (float)*input++ / 0xff;
  684     *(*output)++ = (float)*input++ / 0xff;
  685     *(*output)++ = (float)*input / 0xff;
  686 }
  687 
  688 static inline void transfer_RGBA8888_to_BGR8888(unsigned char *(*output), unsigned char *input)
  689 {
  690     unsigned int r, g, b, a;
  691     a = input[3];
  692     r = ((unsigned int)input[0] * a) / 0xff;
  693     g = ((unsigned int)input[1] * a) / 0xff;
  694     b = ((unsigned int)input[2] * a) / 0xff;
  695     *(*output)++ = b;
  696     *(*output)++ = g;
  697     *(*output)++ = r;
  698     (*output)++;
  699 }
  700 
  701 static inline void transfer_RGBA8888_to_YUV888(unsigned char *(*output), unsigned char *input)
  702 {
  703     int y, u, v, a, r, g, b;
  704     
  705     a = input[3];
  706     r = (input[0] * a) / 0xff;
  707     g = (input[1] * a) / 0xff;
  708     b = (input[2] * a) / 0xff;
  709 
  710     RGB_TO_YUV(y, u, v, input[0], input[1], input[2]);
  711 
  712     *(*output)++ = y;
  713     *(*output)++ = u;
  714     *(*output)++ = v;
  715 }
  716 
  717 static inline void transfer_RGBA8888_to_YUVA8888(unsigned char *(*output), unsigned char *input)
  718 {
  719     int y, u, v;
  720 
  721     RGB_TO_YUV(y, u, v, input[0], input[1], input[2]);
  722 
  723     *(*output)++ = y;
  724     *(*output)++ = u;
  725     *(*output)++ = v;
  726     *(*output)++ = input[3];
  727 }
  728 
  729 static inline void transfer_RGBA8888_to_YUV161616(uint16_t *(*output), unsigned char *input)
  730 {
  731     int y, u, v, opacity, r, g, b;
  732     
  733     opacity = input[3];
  734     r = (((int)input[0] << 8) | input[0]) * opacity / 0xff;
  735     g = (((int)input[1] << 8) | input[1]) * opacity / 0xff;
  736     b = (((int)input[2] << 8) | input[2]) * opacity / 0xff;
  737 
  738     RGB_TO_YUV16(y, u, v, r, g, b);
  739 
  740     *(*output)++ = y;
  741     *(*output)++ = u;
  742     *(*output)++ = v;
  743 }
  744 
  745 static inline void transfer_RGBA8888_to_YUVA16161616(uint16_t *(*output), unsigned char *input)
  746 {
  747     int y, u, v, r, g, b;
  748 
  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);
  753 
  754     *(*output)++ = y;
  755     *(*output)++ = u;
  756     *(*output)++ = v;
  757     *(*output)++ = (((int)input[3]) << 8) | input[3];
  758 }
  759 
  760 static inline void transfer_RGBA8888_to_YUV101010(unsigned char *(*output), unsigned char *input)
  761 {
  762     int r, g, b;
  763     int y, u, v;
  764 
  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);
  770 }
  771 
  772 static inline void transfer_RGBA8888_to_VYU888(unsigned char *(*output), unsigned char *input)
  773 {
  774     int y, u, v, a, r, g, b;
  775     
  776     a = input[3];
  777     r = ((input[0] * a) >> 8) + 1;
  778     g = ((input[1] * a) >> 8) + 1;
  779     b = ((input[2] * a) >> 8) + 1;
  780 
  781     RGB_TO_YUV(y, u, v, input[0], input[1], input[2]);
  782 
  783     *(*output)++ = v;
  784     *(*output)++ = y;
  785     *(*output)++ = u;
  786 }
  787 
  788 static inline void transfer_RGBA8888_to_UYVA8888(unsigned char *(*output), unsigned char *input)
  789 {
  790     int y, u, v;
  791 
  792     RGB_TO_YUV(y, u, v, input[0], input[1], input[2]);
  793 
  794     *(*output)++ = u;
  795     *(*output)++ = y;
  796     *(*output)++ = v;
  797     *(*output)++ = input[3];
  798 }
  799 
  800 static inline void transfer_RGBA888_to_YUV420P_YUV422P(unsigned char *output_y, 
  801     unsigned char *output_u, 
  802     unsigned char *output_v, 
  803     unsigned char *input,
  804     int output_column)
  805 {
  806     int y, u, v, a, r, g, b;
  807     
  808     a = input[3];
  809     r = (input[0] * a) / 0xff;
  810     g = (input[1] * a) / 0xff;
  811     b = (input[2] * a) / 0xff;
  812 
  813     RGB_TO_YUV(y, u, v, r, g, b);
  814 
  815     output_y[output_column] = y;
  816     output_u[output_column / 2] = u;
  817     output_v[output_column / 2] = v;
  818 }
  819 
  820 static inline void transfer_RGBA888_to_YUV444P(unsigned char *output_y, 
  821     unsigned char *output_u, 
  822     unsigned char *output_v, 
  823     unsigned char *input,
  824     int output_column)
  825 {
  826     int y, u, v, a, r, g, b;
  827     
  828     a = input[3];
  829     r = (input[0] * a) / 0xff;
  830     g = (input[1] * a) / 0xff;
  831     b = (input[2] * a) / 0xff;
  832 
  833     RGB_TO_YUV(y, u, v, r, g, b);
  834 
  835     output_y[output_column] = y;
  836     output_u[output_column] = u;
  837     output_v[output_column] = v;
  838 }
  839 
  840 static inline void transfer_RGBA888_to_YUV422(unsigned char *(*output), 
  841     unsigned char *input,
  842     int j)
  843 {
  844     int y, u, v, a, r, g, b;
  845     
  846     a = input[3];
  847     r = (input[0] * a) / 0xff;
  848     g = (input[1] * a) / 0xff;
  849     b = (input[2] * a) / 0xff;
  850 
  851     RGB_TO_YUV(y, u, v, r, g, b);
  852 
  853     if(!(j & 1))
  854     { 
  855 // Store U and V for even pixels only
  856          (*output)[1] = u;
  857          (*output)[3] = v;
  858          (*output)[0] = y;
  859     }
  860     else
  861     { 
  862 // Store Y and advance output for odd pixels only
  863          (*output)[2] = y;
  864          (*output) += 4;
  865     }
  866 
  867 }
  868 
  869 
  870 
  871 
  872 
  873 
  874 
  875 
  876 
  877 
  878 
  879 
  880 
  881 // ******************************** RGB161616 -> *********************************
  882 
  883 static inline void transfer_RGB161616_to_RGB8(unsigned char *(*output), uint16_t *input)
  884 {
  885     *(*output) = (unsigned char)(((input[0] & 0xc000) >> 8) +
  886                              ((input[1] & 0xe000) >> 10) +
  887                              ((input[2] & 0xe000) >> 13));
  888     (*output)++;
  889 }
  890 
  891 static inline void transfer_RGB161616_to_BGR565(unsigned char *(*output), uint16_t *input)
  892 {
  893     uint16_t r, g, b;
  894     r = *input++;
  895     g = *input++;
  896     b = *input;
  897     *(uint16_t*)(*output) = (b & 0xf800) |
  898              ((g & 0xfc00) >> 5) |
  899              ((r & 0xf800) >> 11);
  900     (*output) += 2;
  901 }
  902 
  903 static inline void transfer_RGB161616_to_RGB565(unsigned char *(*output), uint16_t *input)
  904 {
  905     uint16_t r, g, b;
  906     r = *input++;
  907     g = *input++;
  908     b = *input;
  909     *(uint16_t*)(*output) = (r & 0xf800) |
  910              ((g & 0xfc00) >> 5) |
  911              ((b & 0xf800) >> 11);
  912     (*output) += 2;
  913 }
  914 
  915 static inline void transfer_RGB161616_to_BGR888(unsigned char *(*output), uint16_t *input)
  916 {
  917     (*output)[0] = input[2] >> 8;
  918     (*output)[1] = input[1] >> 8;
  919     (*output)[2] = input[0] >> 8;
  920     (*output) += 3;
  921 }
  922 
  923 static inline void transfer_RGB161616_to_RGB888(unsigned char *(*output), uint16_t *input)
  924 {
  925     (*output)[0] = input[0] >> 8;
  926     (*output)[1] = input[1] >> 8;
  927     (*output)[2] = input[2] >> 8;
  928     (*output) += 3;
  929 }
  930 
  931 static inline void transfer_RGB161616_to_RGBA8888(unsigned char *(*output), uint16_t *input)
  932 {
  933     (*output)[0] = input[0] >> 8;
  934     (*output)[1] = input[1] >> 8;
  935     (*output)[2] = input[2] >> 8;
  936     (*output)[3] = 0xff;
  937     (*output) += 4;
  938 }
  939 
  940 static inline void transfer_RGB161616_to_BGR8888(unsigned char *(*output), uint16_t *input)
  941 {
  942     (*output)[0] = input[2] >> 8;
  943     (*output)[1] = input[1] >> 8;
  944     (*output)[2] = input[0] >> 8;
  945     (*output) += 4;
  946 }
  947 
  948 static inline void transfer_RGB161616_to_YUV888(unsigned char *(*output), uint16_t *input)
  949 {
  950     int y, u, v, r, g, b;
  951     r = input[0] >> 8;
  952     g = input[1] >> 8;
  953     b = input[2] >> 8;
  954 
  955     RGB_TO_YUV(y, u, v, r, g, b);
  956 
  957     (*output)[0] = y;
  958     (*output)[1] = u;
  959     (*output)[2] = v;
  960     (*output) += 3;
  961 }
  962 
  963 static inline void transfer_RGB161616_to_YUVA8888(unsigned char *(*output), uint16_t *input)
  964 {
  965     int y, u, v, r, g, b;
  966 
  967     r = input[0] >> 8;
  968     g = input[1] >> 8;
  969     b = input[2] >> 8;
  970 
  971     RGB_TO_YUV(y, u, v, r, g, b);
  972 
  973     (*output)[0] = y;
  974     (*output)[1] = u;
  975     (*output)[2] = v;
  976     (*output)[3] = 255;
  977     (*output) += 4;
  978 }
  979 
  980 
  981 static inline void transfer_RGB161616_to_YUV101010(unsigned char *(*output), uint16_t *input)
  982 {
  983     int r, g, b;
  984     int y, u, v;
  985 
  986     r = input[0];
  987     g = input[1];
  988     b = input[2];
  989     RGB_TO_YUV16(y, u, v, r, g, b);
  990     WRITE_YUV101010(y, u, v);
  991 }
  992 
  993 static inline void transfer_RGB161616_to_VYU888(unsigned char *(*output), uint16_t *input)
  994 {
  995     int y, u, v, r, g, b;
  996     r = input[0] >> 8;
  997     g = input[1] >> 8;
  998     b = input[2] >> 8;
  999 
 1000     RGB_TO_YUV(y, u, v, r, g, b);
 1001 
 1002     (*output)[0] = v;
 1003     (*output)[1] = y;
 1004     (*output)[2] = u;
 1005     (*output) += 3;
 1006 }
 1007 
 1008 static inline void transfer_RGB161616_to_UYVA8888(unsigned char *(*output), uint16_t *input)
 1009 {
 1010     int y, u, v, r, g, b;
 1011 
 1012     r = input[0] >> 8;
 1013     g = input[1] >> 8;
 1014     b = input[2] >> 8;
 1015 
 1016     RGB_TO_YUV(y, u, v, r, g, b);
 1017 
 1018     (*output)[0] = u;
 1019     (*output)[1] = y;
 1020     (*output)[2] = v;
 1021     (*output)[3] = 0xff;
 1022     (*output) += 4;
 1023 }
 1024 
 1025 
 1026 static inline void transfer_RGB161616_to_YUV420P_YUV422P(unsigned char *output_y, 
 1027     unsigned char *output_u, 
 1028     unsigned char *output_v, 
 1029     uint16_t *input,
 1030     int output_column)
 1031 {
 1032     int y, u, v, r, g, b;
 1033     r = input[0] >> 8;
 1034     g = input[1] >> 8;
 1035     b = input[2] >> 8;
 1036 
 1037     RGB_TO_YUV(y, u, v, r, g, b);
 1038 
 1039     output_y[output_column] = y;
 1040     output_u[output_column / 2] = u;
 1041     output_v[output_column / 2] = v;
 1042 }
 1043 
 1044 static inline void transfer_RGB161616_to_YUV444P(unsigned char *output_y, 
 1045     unsigned char *output_u, 
 1046     unsigned char *output_v, 
 1047     uint16_t *input,
 1048     int output_column)
 1049 {
 1050     int y, u, v, r, g, b;
 1051     r = input[0] >> 8;
 1052     g = input[1] >> 8;
 1053     b = input[2] >> 8;
 1054 
 1055     RGB_TO_YUV(y, u, v, r, g, b);
 1056 
 1057     output_y[output_column] = y;
 1058     output_u[output_column] = u;
 1059     output_v[output_column] = v;
 1060 }
 1061 
 1062 
 1063 // ****************************** RGBA16161616 -> *****************************
 1064 
 1065 static inline void transfer_RGBA16161616_to_RGB8(unsigned char *(*output), uint16_t *input)
 1066 {
 1067     unsigned int r, g, b, a;
 1068     a = (input)[3] >> 8;
 1069     r = (unsigned int)(input)[0] * a;
 1070     g = (unsigned int)(input)[1] * a;
 1071     b = (unsigned int)(input)[2] * a;
 1072 
 1073     *(*output) = (unsigned char)(((r & 0xc00000) >> 16) + 
 1074                 ((g & 0xe00000) >> 18) + 
 1075                 ((b & 0xe00000) >> 21));
 1076     (*output)++;
 1077 }
 1078 
 1079 static inline void transfer_RGBA16161616_to_BGR565(unsigned char *(*output), uint16_t *input)
 1080 {
 1081     unsigned int r, g, b, a;
 1082     a = (input)[3] >> 8;
 1083     r = (unsigned int)(input)[0] * a;
 1084     g = (unsigned int)(input)[1] * a;
 1085     b = (unsigned int)(input)[2] * a;
 1086 
 1087     *(uint16_t*)(*output) = (uint16_t)(((b & 0xf80000) >> 8) + 
 1088                 ((g & 0xfc0000) >> 13) + 
 1089                 ((r & 0xf80000) >> 19));
 1090     (*output) += 2;
 1091 }
 1092 
 1093 static inline void transfer_RGBA16161616_to_RGB565(unsigned char *(*output), uint16_t *input)
 1094 {
 1095     unsigned int r, g, b, a;
 1096     a = (input)[3] >> 8;
 1097     r = (unsigned int)(input)[0] * a;
 1098     g = (unsigned int)(input)[1] * a;
 1099     b = (unsigned int)(input)[2] * a;
 1100 
 1101     *(uint16_t*)(*output) = (uint16_t)(((r & 0xf80000) >> 8) + 
 1102                 ((g & 0xfc0000) >> 13) + 
 1103                 ((b & 0xf80000) >> 19));
 1104     (*output) += 2;
 1105 }
 1106 
 1107 static inline void transfer_RGBA16161616_to_BGR888(unsigned char *(*output), uint16_t *input)
 1108 {
 1109     uint32_t r, g, b, a;
 1110     a = input[3];
 1111     r = (uint32_t)(input)[0] * a;
 1112     g = (uint32_t)(input)[1] * a;
 1113     b = (uint32_t)(input)[2] * a;
 1114 
 1115 // For display only
 1116     (*output)[0] = (unsigned char)(b >> 24);
 1117     (*output)[1] = (unsigned char)(g >> 24);
 1118     (*output)[2] = (unsigned char)(r >> 24);
 1119     (*output) += 3;
 1120 }
 1121 
 1122 static inline void transfer_RGBA16161616_to_RGB888(unsigned char *(*output), uint16_t *input)
 1123 {
 1124     uint32_t r, g, b, a;
 1125     a = input[3];
 1126     r = (unsigned int)(input)[0] * a;
 1127     g = (unsigned int)(input)[1] * a;
 1128     b = (unsigned int)(input)[2] * a;
 1129 
 1130     (*output)[0] = (unsigned char)(r / 0xffffff);
 1131     (*output)[1] = (unsigned char)(g / 0xffffff);
 1132     (*output)[2] = (unsigned char)(b / 0xffffff);
 1133     (*output) += 3;
 1134 }
 1135 
 1136 
 1137 static inline void transfer_RGBA16161616_to_RGBA8888(unsigned char *(*output), unsigned char *input)
 1138 {
 1139     (*output)[0] = input[0] >> 8;
 1140     (*output)[1] = input[1] >> 8;
 1141     (*output)[2] = input[2] >> 8;
 1142     (*output)[3] = input[3] >> 8;
 1143     (*output) += 4;
 1144 }
 1145 
 1146 
 1147 static inline void transfer_RGBA16161616_to_BGR8888(unsigned char *(*output), uint16_t *input)
 1148 {
 1149     uint32_t r, g, b, a;
 1150     a = input[3];
 1151     r = (input)[0] * a;
 1152     g = (input)[1] * a;
 1153     b = (input)[2] * a;
 1154 
 1155 // For display only
 1156     (*output)[0] = (unsigned char)(b >> 24);
 1157     (*output)[1] = (unsigned char)(g >> 24);
 1158     (*output)[2] = (unsigned char)(r >> 24);
 1159     (*output) += 4;
 1160 }
 1161 
 1162 static inline void transfer_RGBA16161616_to_YUV101010(unsigned char *(*output), uint16_t *input)
 1163 {
 1164     uint32_t r, g, b, a, y, u, v;
 1165 
 1166     a = input[3];
 1167     r = (uint32_t)input[0] * a / 0xffff;
 1168     g = (uint32_t)input[1] * a / 0xffff;
 1169     b = (uint32_t)input[2] * a / 0xffff;
 1170     RGB_TO_YUV16(y, u, v, r, g, b);
 1171     WRITE_YUV101010(y, u, v);
 1172 }
 1173 
 1174 
 1175 static inline void transfer_RGBA16161616_to_YUV420P_YUV422P(unsigned char *output_y, 
 1176     unsigned char *output_u, 
 1177     unsigned char *output_v, 
 1178     uint16_t *input,
 1179     int output_column)
 1180 {
 1181     uint32_t y, u, v, r, g, b, a;
 1182     a = input[3];
 1183     r = (int32_t)input[0] * a / 0xffffff;
 1184     g = (int32_t)input[1] * a / 0xffffff;
 1185     b = (int32_t)input[2] * a / 0xffffff;
 1186 
 1187     RGB_TO_YUV(y, u, v, r, g, b);
 1188 
 1189     output_y[output_column] = y;
 1190     output_u[output_column / 2] = u;
 1191     output_v[output_column / 2] = v;
 1192 }
 1193 
 1194 static inline void transfer_RGBA16161616_to_YUV444P(unsigned char *output_y, 
 1195     unsigned char *output_u, 
 1196     unsigned char *output_v, 
 1197     uint16_t *input,
 1198     int output_column)
 1199 {
 1200     uint32_t y, u, v, r, g, b, a;
 1201     a = input[3];
 1202     r = (int32_t)input[0] * a / 0xffffff;
 1203     g = (int32_t)input[1] * a / 0xffffff;
 1204     b = (int32_t)input[2] * a / 0xffffff;
 1205 
 1206     RGB_TO_YUV(y, u, v, r, g, b);
 1207 
 1208     output_y[output_column] = y;
 1209     output_u[output_column] = u;
 1210     output_v[output_column] = v;
 1211 }
 1212 
 1213 
 1214 
 1215 
 1216 
 1217 
 1218 
 1219 
 1220 
 1221 
 1222 
 1223 
 1224 
 1225 
 1226 
 1227 
 1228 
 1229 
 1230 
 1231 
 1232 
 1233 
 1234 
 1235 // ********************************** screen capture *****************************
 1236 
 1237 static inline void transfer_BGR8888_to_RGB888(unsigned char *(*output), unsigned char *input)
 1238 {
 1239     *(*output)++ = input[2];
 1240     *(*output)++ = input[1];
 1241     *(*output)++ = input[0];
 1242 }
 1243 
 1244 static inline void transfer_BGR8888_to_BGR8888(unsigned char *(*output), unsigned char *input)
 1245 {
 1246     *(*output)++ = input[0];
 1247     *(*output)++ = input[1];
 1248     *(*output)++ = input[2];
 1249     (*output)++;
 1250 }
 1251 
 1252 static inline void transfer_BGR888_to_RGB888(unsigned char *(*output), unsigned char *input)
 1253 {
 1254     *(*output)++ = input[2];
 1255     *(*output)++ = input[1];
 1256     *(*output)++ = input[0];
 1257 }
 1258 
 1259 
 1260 
 1261 
 1262 
 1263 
 1264 
 1265 // ******************************** YUV888 -> *********************************
 1266 
 1267 
 1268 static inline void transfer_YUV888_to_RGB8(unsigned char *(*output), unsigned char *input)
 1269 {
 1270     int y, u, v;
 1271     int r, g, b;
 1272     
 1273     y = (input[0] << 16) | (input[0] << 8) | input[0];
 1274     u = input[1];
 1275     v = input[2];
 1276     YUV_TO_RGB(y, u, v, r, g, b);
 1277 
 1278     *(*output) = (unsigned char)((r & 0xc0) +
 1279                              ((g & 0xe0) >> 2) +
 1280                              ((b & 0xe0) >> 5));
 1281     (*output)++;
 1282 }
 1283 
 1284 static inline void transfer_YUV888_to_BGR565(unsigned char *(*output), unsigned char *input)
 1285 {
 1286     int y, u, v;
 1287     int r, g, b;
 1288     
 1289     y = (input[0] << 16) | (input[0] << 8) | input[0];
 1290     u = input[1];
 1291     v = input[2];
 1292     YUV_TO_RGB(y, u, v, r, g, b);
 1293     *(uint16_t*)(*output) = ((b & 0xf8) << 8)
 1294              + ((g & 0xfc) << 3)
 1295              + ((r & 0xf8) >> 3);
 1296     (*output) += 2;
 1297 }
 1298 
 1299 static inline void transfer_YUV888_to_RGB565(unsigned char *(*output), unsigned char *input)
 1300 {
 1301     int y, u, v;
 1302     int r, g, b;
 1303     
 1304     y = (input[0] << 16) | (input[0] << 8) | input[0];
 1305     u = input[1];
 1306     v = input[2];
 1307     YUV_TO_RGB(y, u, v, r, g, b);
 1308     *(uint16_t*)(*output) = ((r & 0xf8) << 8)
 1309              + ((g & 0xfc) << 3)
 1310              + ((b & 0xf8) >> 3);
 1311     (*output) += 2;
 1312 }
 1313 
 1314 static inline void transfer_YUV888_to_BGR888(unsigned char *(*output), unsigned char *input)
 1315 {
 1316     int y, u, v;
 1317     int r, g, b;
 1318     
 1319     y = (input[0] << 16) | (input[0] << 8) | input[0];
 1320     u = input[1];
 1321     v = input[2];
 1322     YUV_TO_RGB(y, u, v, r, g, b);
 1323 
 1324     *(*output)++ = b;
 1325     *(*output)++ = g;
 1326     *(*output)++ = r;
 1327 }
 1328 
 1329 static inline void transfer_YUV888_to_BGR8888(unsigned char *(*output), unsigned char *input)
 1330 {
 1331     int y, u, v;
 1332     int r, g, b;
 1333 
 1334     y = (input[0] << 16) | (input[0] << 8) | input[0];
 1335     u = input[1];
 1336     v = input[2];
 1337     YUV_TO_RGB(y, u, v, r, g, b);
 1338     *(*output)++ = b;
 1339     *(*output)++ = g;
 1340     *(*output)++ = r;
 1341     (*output)++;
 1342 }
 1343 
 1344 static inline void transfer_YUV888_to_RGB888(unsigned char *(*output), unsigned char *input)
 1345 {
 1346     int y, u, v;
 1347     int r, g, b;
 1348     
 1349     y = (input[0] << 16) | (input[0] << 8) | input[0];
 1350     u = (int)input[1];
 1351     v = (int)input[2];
 1352     YUV_TO_RGB(y, u, v, r, g, b);
 1353 
 1354     *(*output)++ = r;
 1355     *(*output)++ = g;
 1356     *(*output)++ = b;
 1357 }
 1358 
 1359 static inline void transfer_YUV888_to_RGBA8888(unsigned char *(*output), unsigned char *input)
 1360 {
 1361     int y, u, v;
 1362     int r, g, b;
 1363 
 1364     y = (input[0] << 16) | (input[0] << 8) | input[0];
 1365     u = input[1];
 1366     v = input[2];
 1367     YUV_TO_RGB(y, u, v, r, g, b);
 1368     *(*output)++ = r;
 1369     *(*output)++ = g;
 1370     *(*output)++ = b;
 1371     *(*output)++ = 0xff;
 1372 }
 1373 
 1374 static inline void transfer_YUV888_to_ARGB8888(unsigned char *(*output), unsigned char *input)
 1375 {
 1376     int y, u, v;
 1377     int r, g, b;
 1378 
 1379     y = (input[0] << 16) | (input[0] << 8) | input[0];
 1380     u = input[1];
 1381     v = input[2];
 1382     YUV_TO_RGB(y, u, v, r, g, b);
 1383     *(*output)++ = 0xff;
 1384     *(*output)++ = r;
 1385     *(*output)++ = g;
 1386     *(*output)++ = b;
 1387 }
 1388 
 1389 static inline void transfer_YUV888_to_RGB_FLOAT(float *(*output), unsigned char *input)
 1390 {
 1391     float y = (float)input[0] / 0xff;
 1392     int u = input[1];
 1393     int v = input[2];
 1394     float r, g, b;
 1395     
 1396     YUV_TO_FLOAT(y, u, v, r, g, b);
 1397 
 1398     *(*output)++ = r;
 1399     *(*output)++ = g;
 1400     *(*output)++ = b;
 1401 }
 1402 
 1403 static inline void transfer_YUV888_to_RGBA_FLOAT(float *(*output), unsigned char *input)
 1404 {
 1405     float y = (float)input[0] / 0xff;
 1406     int u = input[1];
 1407     int v = input[2];
 1408     float r, g, b;
 1409     
 1410     YUV_TO_FLOAT(y, u, v, r, g, b);
 1411 
 1412     *(*output)++ = r;
 1413     *(*output)++ = g;
 1414     *(*output)++ = b;
 1415     *(*output)++ = 1.0;
 1416 }
 1417 
 1418 static inline void transfer_YUV888_to_YUVA8888(unsigned char *(*output), unsigned char *input)
 1419 {
 1420     *(*output)++ = (int)input[0];
 1421     *(*output)++ = input[1];
 1422     *(*output)++ = input[2];
 1423     *(*output)++ = 0xff;
 1424 }
 1425 
 1426 static inline void transfer_YUV888_to_YUV888(unsigned char *(*output), unsigned char *input)
 1427 {
 1428     (*output)[0] = (int)input[0];
 1429     (*output)[1] = input[1];
 1430     (*output)[2] = input[2];
 1431     (*output) += 3;
 1432 }
 1433 
 1434 
 1435 static inline void transfer_YUV888_to_VYU888(unsigned char *(*output), unsigned char *input)
 1436 {
 1437     (*output)[0] = input[2];
 1438     (*output)[1] = input[0];
 1439     (*output)[2] = input[1];
 1440     (*output) += 3;
 1441 }
 1442 
 1443 
 1444 static inline void transfer_YUV888_to_UYVA8888(unsigned char *(*output), unsigned char *input)
 1445 {
 1446     (*output)[0] = input[1];
 1447     (*output)[1] = input[0];
 1448     (*output)[2] = input[2];
 1449     (*output)[3] = 0xff;
 1450     (*output) += 4;
 1451 }
 1452 
 1453 
 1454 static inline void transfer_YUV888_to_YUV101010(unsigned char *(*output), unsigned char *input)
 1455 {
 1456     uint16_t y_i = ((uint16_t)input[0]) << 8;
 1457     uint16_t u_i = ((uint16_t)input[1]) << 8;
 1458     uint16_t v_i = ((uint16_t)input[2]) << 8;
 1459     WRITE_YUV101010(y_i, u_i, v_i);
 1460 }
 1461 
 1462 static inline void transfer_YUV888_to_YUV420P_YUV422P(unsigned char *output_y, 
 1463     unsigned char *output_u, 
 1464     unsigned char *output_v, 
 1465     unsigned char *input,
 1466     int output_column)
 1467 {
 1468     output_y[output_column] = input[0];
 1469     output_u[output_column / 2] = input[1];
 1470     output_v[output_column / 2] = input[2];
 1471 }
 1472 
 1473 static inline void transfer_YUV888_to_YUV444P(unsigned char *output_y, 
 1474     unsigned char *output_u, 
 1475     unsigned char *output_v, 
 1476     unsigned char *input,
 1477     int output_column)
 1478 {
 1479     output_y[output_column] = input[0];
 1480     output_u[output_column] = input[1];
 1481     output_v[output_column] = input[2];
 1482 }
 1483 
 1484 static inline void transfer_YUV888_to_YUV422(unsigned char *(*output), 
 1485     unsigned char *input,
 1486     int j)
 1487 {
 1488 // Store U and V for even pixels only
 1489     if(!(j & 1))
 1490     {
 1491         (*output)[1] = input[1];
 1492         (*output)[3] = input[2];
 1493         (*output)[0] = input[0];
 1494     }
 1495     else
 1496 // Store Y and advance output for odd pixels only
 1497     {
 1498         (*output)[2] = input[0];
 1499         (*output) += 4;
 1500     }
 1501 }
 1502 
 1503 
 1504 
 1505 
 1506 
 1507 
 1508 // ******************************** YUVA8888 -> *******************************
 1509 
 1510 
 1511 
 1512 
 1513 static inline void transfer_YUVA8888_to_RGB8(unsigned char *(*output), unsigned char *input)
 1514 {
 1515     int y, u, v, a;
 1516     int r, g, b;
 1517     
 1518     a = input[3];
 1519     y = (input[0] << 16) | (input[0] << 8) | input[0];
 1520     u = input[1];
 1521     v = input[2];
 1522     YUV_TO_RGB(y, u, v, r, g, b);
 1523     
 1524     r *= a;
 1525     g *= a;
 1526     b *= a;
 1527 
 1528     *(*output) = (unsigned char)(((r & 0xc000) >> 8) + 
 1529                 ((g & 0xe000) >> 10) + 
 1530                 ((b & 0xe000) >> 13));
 1531     (*output)++;
 1532 }
 1533 
 1534 static inline void transfer_YUVA8888_to_BGR565(unsigned char *(*output), unsigned char *input)
 1535 {
 1536     int y, u, v, a;
 1537     int r, g, b;
 1538     
 1539     a = input[3];
 1540     y = (input[0] << 16) | (input[0] << 8) | input[0];
 1541     u = input[1];
 1542     v = input[2];
 1543     YUV_TO_RGB(y, u, v, r, g, b);
 1544         
 1545     r *= a;
 1546     g *= a;
 1547     b *= a;
 1548 
 1549     *(uint16_t*)(*output) = (uint16_t)((b & 0xf800) + 
 1550                 ((g & 0xfc00) >> 5) + 
 1551                 ((r & 0xf800) >> 11));
 1552     (*output) += 2;
 1553 }
 1554 
 1555 static inline void transfer_YUVA8888_to_RGB565(unsigned char *(*output), unsigned char *input)
 1556 {
 1557     int y, u, v, a;
 1558     int r, g, b;
 1559     
 1560     a = input[3];
 1561     y = (input[0] << 16) | (input[0] << 8) | input[0];
 1562     u = input[1];
 1563     v = input[2];
 1564     YUV_TO_RGB(y, u, v, r, g, b);
 1565         
 1566     r *= a;
 1567     g *= a;
 1568     b *= a;
 1569 
 1570     *(uint16_t*)(*output) = (uint16_t)((r & 0xf800) + 
 1571                 ((g & 0xfc00) >> 5) + 
 1572                 ((b & 0xf800) >> 11));
 1573     (*output) += 2;
 1574 }
 1575 
 1576 static inline void transfer_YUVA8888_to_BGR888(unsigned char *(*output), unsigned char *input)
 1577 {
 1578     int y, u, v, a;
 1579     int r, g, b;
 1580     
 1581     a = input[3];
 1582     y = (input[0] << 16) | (input[0] << 8) | input[0];
 1583     u = input[1];
 1584     v = input[2];
 1585 
 1586     YUV_TO_RGB(y, u, v, r, g, b);
 1587         
 1588     r *= a;
 1589     g *= a;
 1590     b *= a;
 1591 
 1592     *(*output)++ = b / 0xff;
 1593     *(*output)++ = g / 0xff;
 1594     *(*output)++ = r / 0xff;
 1595 }
 1596 
 1597 
 1598 static inline void transfer_YUVA8888_to_BGR8888(unsigned char *(*output), unsigned char *input)
 1599 {
 1600     int y, u, v, a;
 1601     int r, g, b;
 1602 
 1603     a = input[3];
 1604     y = (input[0] << 16) | (input[0] << 8) | input[0];
 1605     u = input[1];
 1606     v = input[2];
 1607 
 1608     YUV_TO_RGB(y, u, v, r, g, b);
 1609     
 1610     r *= a;
 1611     g *= a;
 1612     b *= a;
 1613     *(*output)++ = b / 0xff;
 1614     *(*output)++ = g / 0xff;
 1615     *(*output)++ = r / 0xff;
 1616     (*output)++;
 1617 }
 1618 
 1619 static inline void transfer_YUVA8888_to_RGB888(unsigned char *(*output), unsigned char *input)
 1620 {
 1621     int y, u, v, a;
 1622     int r, g, b;
 1623     
 1624     a = input[3];
 1625     y = (input[0] << 16) | (input[0] << 8) | input[0];
 1626     u = input[1];
 1627     v = input[2];
 1628 
 1629     YUV_TO_RGB(y, u, v, r, g, b);
 1630         
 1631     r *= a;
 1632     g *= a;
 1633     b *= a;
 1634 
 1635     *(*output)++ = r / 0xff;
 1636     *(*output)++ = g / 0xff;
 1637     *(*output)++ = b / 0xff;
 1638 }
 1639 
 1640 static inline void transfer_YUVA8888_to_RGBA8888(unsigned char *(*output), unsigned char *input)
 1641 {
 1642     int y, u, v, a;
 1643     int r, g, b;
 1644 
 1645     a = input[3];
 1646     y = (input[0] << 16) | (input[0] << 8) | input[0];
 1647     u = input[1];
 1648     v = input[2];
 1649 
 1650     YUV_TO_RGB(y, u, v, r, g, b);
 1651     *(*output)++ = r;
 1652     *(*output)++ = g;
 1653     *(*output)++ = b;
 1654     *(*output)++ = a;
 1655 }
 1656 
 1657 static inline void transfer_YUVA8888_to_ARGB8888(unsigned char *(*output), unsigned char *input)
 1658 {
 1659     int y, u, v, a;
 1660     int r, g, b;
 1661 
 1662     a = input[3];
 1663     y = (input[0] << 16) | (input[0] << 8) | input[0];
 1664     u = input[1];
 1665     v = input[2];
 1666 
 1667     YUV_TO_RGB(y, u, v, r, g, b);
 1668     *(*output)++ = a;
 1669     *(*output)++ = r;
 1670     *(*output)++ = g;
 1671     *(*output)++ = b;
 1672 }
 1673 
 1674 static inline void transfer_YUVA8888_to_RGB_FLOAT(float *(*output), unsigned char *input)
 1675 {
 1676     float y, a;
 1677     int u, v;
 1678     float r, g, b;
 1679 
 1680     a = (float)input[3] / 0xff;
 1681     y = (float)input[0] / 0xff;
 1682     u = input[1];
 1683     v = input[2];
 1684 
 1685     YUV_TO_FLOAT(y, u, v, r, g, b);
 1686         
 1687     r *= a;
 1688     g *= a;
 1689     b *= a;
 1690 
 1691     *(*output)++ = r;
 1692     *(*output)++ = g;
 1693     *(*output)++ = b;
 1694 }
 1695 
 1696 static inline void transfer_YUVA8888_to_RGBA_FLOAT(float *(*output), unsigned char *input)
 1697 {
 1698     float y = (float)input[0] / 0xff;
 1699     int u, v;
 1700     float r, g, b, a;
 1701 
 1702     a = (float)input[3] / 0xff;
 1703     u = input[1];
 1704     v = input[2];
 1705 
 1706     YUV_TO_FLOAT(y, u, v, r, g, b);
 1707 
 1708     *(*output)++ = r;
 1709     *(*output)++ = g;
 1710     *(*output)++ = b;
 1711     *(*output)++ = a;
 1712 }
 1713 
 1714 
 1715 static inline void transfer_YUVA8888_to_VYU888(unsigned char *(*output), unsigned char *input)
 1716 {
 1717     int y, u, v, a, anti_a;
 1718     a = input[3];
 1719     anti_a = 0xff - a;
 1720     y = ((uint32_t)input[0] * a) / 0xff;
 1721     u = ((uint32_t)input[1] * a + 0x80 * anti_a) / 0xff;
 1722     v = ((uint32_t)input[2] * a + 0x80 * anti_a) / 0xff;
 1723     
 1724     *(*output)++ = v;
 1725     *(*output)++ = y;
 1726     *(*output)++ = u;
 1727 }
 1728 
 1729 
 1730 static inline void transfer_YUVA8888_to_YUVA8888(unsigned char *(*output), unsigned char *input)
 1731 {
 1732     *(*output)++ = input[0];
 1733     *(*output)++ = input[1];
 1734     *(*output)++ = input[2];
 1735     *(*output)++ = input[3];
 1736 }
 1737 
 1738 static inline void transfer_YUVA8888_to_UYVA8888(unsigned char *(*output), unsigned char *input)
 1739 {
 1740     *(*output)++ = input[1];
 1741     *(*output)++ = input[0];
 1742     *(*output)++ = input[2];
 1743     *(*output)++ = input[3];
 1744 }
 1745 
 1746 static inline void transfer_YUVA8888_to_YUV101010(unsigned char *(*output), unsigned char *input)
 1747 {
 1748     uint16_t y_i = ((uint16_t)input[0] * input[3]) + 0x1fe;
 1749     uint16_t u_i = ((uint16_t)input[1] * input[3]) + 0x1fe;
 1750     uint16_t v_i = ((uint16_t)input[2] * input[3]) + 0x1fe;
 1751     WRITE_YUV101010(y_i, u_i, v_i);
 1752 }
 1753 
 1754 
 1755 static inline void transfer_YUVA8888_to_YUV420P_YUV422P(unsigned char *output_y, 
 1756     unsigned char *output_u, 
 1757     unsigned char *output_v, 
 1758     unsigned char *input,
 1759     int output_column)
 1760 {
 1761     int opacity = input[3];
 1762     int transparency = 0xff - opacity;
 1763 
 1764     output_y[output_column] =     ((input[0] * opacity) >> 8) + 1;
 1765     output_u[output_column / 2] = ((input[1] * opacity + 0x80 * transparency) >> 8) + 1;
 1766     output_v[output_column / 2] = ((input[2] * opacity + 0x80 * transparency) >> 8) + 1;
 1767 }
 1768 
 1769 static inline void transfer_YUVA8888_to_YUV444P(unsigned char *output_y, 
 1770     unsigned char *output_u, 
 1771     unsigned char *output_v, 
 1772     unsigned char *input,
 1773     int output_column)
 1774 {
 1775     int opacity = input[3];
 1776     int transparency = 0xff - opacity;
 1777 
 1778     output_y[output_column] =     ((input[0] * opacity) >> 8) + 1;
 1779     output_u[output_column] = ((input[1] * opacity + 0x80 * transparency) >> 8) + 1;
 1780     output_v[output_column] = ((input[2] * opacity + 0x80 * transparency) >> 8) + 1;
 1781 }
 1782 
 1783 static inline void transfer_YUVA8888_to_YUV422(unsigned char *(*output), 
 1784     unsigned char *input,
 1785     int j)
 1786 {
 1787     int opacity = input[3];
 1788     int transparency = 0xff - opacity;
 1789 // Store U and V for even pixels only
 1790     if(!(j & 1))
 1791     {
 1792         (*output)[0] = ((input[0] * opacity) >> 8) + 1;
 1793         (*output)[1] = ((input[1] * opacity + 0x80 * transparency) >> 8) + 1;
 1794         (*output)[3] = ((input[2] * opacity + 0x80 * transparency) >> 8) + 1;
 1795     }
 1796     else
 1797 // Store Y and advance output for odd pixels only
 1798     {
 1799         (*output)[2] = ((input[0] * opacity) >> 8) + 1;
 1800         (*output) += 4;
 1801     }
 1802 }
 1803 
 1804 
 1805 
 1806 
 1807 
 1808 
 1809 
 1810 
 1811 
 1812 
 1813 // ******************************** YUV161616 -> ******************************
 1814 
 1815 
 1816 static inline void transfer_YUV161616_to_RGB8(unsigned char *(*output), uint16_t *input)
 1817 {
 1818     int y, u, v;
 1819     int r, g, b;
 1820     
 1821     y = (((int)input[0]) << 8) | (input[0] >> 8);
 1822     u = input[1] >> 8;
 1823     v = input[2] >> 8;
 1824     YUV_TO_RGB(y, u, v, r, g, b);
 1825 
 1826     *(*output) = (unsigned char)((r & 0xc0) +
 1827                              ((g & 0xe0) >> 2) +
 1828                              ((b & 0xe0) >> 5));
 1829     (*output)++;
 1830 }
 1831 
 1832 static inline void transfer_YUV161616_to_BGR565(unsigned char *(*output), uint16_t *input)
 1833 {
 1834     int y, u, v;
 1835     int r, g, b;
 1836     
 1837     y = (((int)input[0]) << 8) | (input[0] >> 8);
 1838     u = input[1] >> 8;
 1839     v = input[2] >> 8;
 1840     YUV_TO_RGB(y, u, v, r, g, b);
 1841     *(uint16_t*)(*output) = ((b & 0xf8) << 8)
 1842              + ((g & 0xfc) << 3)
 1843              + ((r & 0xf8) >> 3);
 1844     (*output) += 2;
 1845 }
 1846 
 1847 static inline void transfer_YUV161616_to_RGB565(unsigned char *(*output), uint16_t *input)
 1848 {
 1849     int y, u, v;
 1850     int r, g, b;
 1851     
 1852     y = (((int)input[0]) << 8) | (input[0] >> 8);
 1853     u = input[1] >> 8;
 1854     v = input[2] >> 8;
 1855     YUV_TO_RGB(y, u, v, r, g, b);
 1856     *(uint16_t*)(*output) = ((r & 0xf8) << 8)
 1857              + ((g & 0xfc) << 3)
 1858              + ((b & 0xf8) >> 3);
 1859     (*output) += 2;
 1860 }
 1861 
 1862 static inline void transfer_YUV161616_to_BGR888(unsigned char *(*output), uint16_t *input)
 1863 {
 1864     int y, u, v;
 1865     int r, g, b;
 1866     
 1867     y = (((int)input[0]) << 8) | (input[0] >> 8);
 1868     u = input[1];
 1869     v = input[2];
 1870     YUV_TO_RGB16(y, u, v, r, g, b);
 1871 
 1872     *(*output)++ = b >> 8;
 1873     *(*output)++ = g >> 8;
 1874     *(*output)++ = r >> 8;
 1875 }
 1876 
 1877 static inline void transfer_YUV161616_to_RGB888(unsigned char *(*output), uint16_t *input)
 1878 {
 1879     int y, u, v;
 1880     int r, g, b;
 1881     
 1882     y = (((int)input[0]) << 8) | (input[0] >> 8);
 1883     u = input[1];
 1884     v = input[2];
 1885     YUV_TO_RGB16(y, u, v, r, g, b);
 1886 
 1887     *(*output)++ = r >> 8;
 1888     *(*output)++ = g >> 8;
 1889     *(*output)++ = b >> 8;
 1890 }
 1891 
 1892 static inline void transfer_YUV161616_to_RGBA8888(unsigned char *(*output), uint16_t *input)
 1893 {
 1894     int y, u, v;
 1895     int r, g, b;
 1896     
 1897     y = (((int)input[0]) << 8) | (input[0] >> 8);
 1898     u = input[1];
 1899     v = input[2];
 1900     YUV_TO_RGB16(y, u, v, r, g, b);
 1901 
 1902     *(*output)++ = r >> 8;
 1903     *(*output)++ = g >> 8;
 1904     *(*output)++ = b >> 8;
 1905     *(*output)++ = 0xff;
 1906 }
 1907 
 1908 static inline void transfer_YUV161616_to_ARGB8888(unsigned char *(*output), uint16_t *input)
 1909 {
 1910     int y, u, v;
 1911     int r, g, b;
 1912     
 1913     y = (((int)input[0]) << 8) | (input[0] >> 8);
 1914     u = input[1];
 1915     v = input[2];
 1916     YUV_TO_RGB16(y, u, v, r, g, b);
 1917 
 1918     *(*output)++ = 0xff;
 1919     *(*output)++ = r >> 8;
 1920     *(*output)++ = g >> 8;
 1921     *(*output)++ = b >> 8;
 1922 }
 1923 
 1924 static inline void transfer_YUV161616_to_RGB_FLOAT(float *(*output), uint16_t *input)
 1925 {
 1926     float y = (float)input[0] / 0xffff;
 1927     int u, v;
 1928     float r, g, b;
 1929     
 1930     u = input[1];
 1931     v = input[2];
 1932     YUV16_TO_RGB_FLOAT(y, u, v, r, g, b);
 1933 
 1934     *(*output)++ = r;
 1935     *(*output)++ = g;
 1936     *(*output)++ = b;
 1937 }
 1938 
 1939 static inline void transfer_YUV161616_to_RGBA_FLOAT(float *(*output), uint16_t *input)
 1940 {
 1941     float y = (float)input[0] / 0xffff;
 1942     int u, v;
 1943     float r, g, b;
 1944     
 1945     u = input[1];
 1946     v = input[2];
 1947     YUV16_TO_RGB_FLOAT(y, u, v, r, g, b);
 1948 
 1949     *(*output)++ = r;
 1950     *(*output)++ = g;
 1951     *(*output)++ = b;
 1952     *(*output)++ = 1.0;
 1953 }
 1954 
 1955 static inline void transfer_YUV161616_to_BGR8888(unsigned char *(*output), uint16_t *input)
 1956 {
 1957     int y, u, v;
 1958     int r, g, b;
 1959 
 1960     y = (((int)input[0]) << 8) | (input[0] >> 8);
 1961     u = input[1] >> 8;
 1962     v = input[2] >> 8;
 1963     YUV_TO_RGB(y, u, v, r, g, b);
 1964     *(*output)++ = b;
 1965     *(*output)++ = g;
 1966     *(*output)++ = r;
 1967     (*output)++;
 1968 }
 1969 
 1970 static inline void transfer_YUV161616_to_YUV161616(uint16_t *(*output), uint16_t *input)
 1971 {
 1972     (*output)[0] = input[0];
 1973     (*output)[1] = input[1];
 1974     (*output)[2] = input[2];
 1975     (*output) += 3;
 1976 }
 1977 
 1978 static inline void transfer_YUV161616_to_YUVA8888(unsigned char *(*output), uint16_t *input)
 1979 {
 1980     (*output)[0] = input[0] >> 8;
 1981     (*output)[1] = input[1] >> 8;
 1982     (*output)[2] = input[2] >> 8;
 1983     (*output)[3] = 255;
 1984     (*output) += 4;
 1985 }
 1986 
 1987 
 1988 static inline void transfer_YUV161616_to_VYU888(unsigned char *(*output), uint16_t *input)
 1989 {
 1990     (*output)[0] = input[2] >> 8;
 1991     (*output)[1] = input[0] >> 8;
 1992     (*output)[2] = input[1] >> 8;
 1993     (*output) += 3;
 1994 }
 1995 
 1996 
 1997 static inline void transfer_YUV161616_to_UYVA8888(unsigned char *(*output), uint16_t *input)
 1998 {
 1999     (*output)[0] = input[1] >> 8;
 2000     (*output)[1] = input[0] >> 8;
 2001     (*output)[2] = input[2] >> 8;
 2002     (*output)[3] = input[3] >> 8;
 2003     (*output) += 4;
 2004 }
 2005 
 2006 static inline void transfer_YUV161616_to_YUV101010(unsigned char *(*output), uint16_t *input)
 2007 {
 2008     uint16_t y_i = input[0];
 2009     uint16_t u_i = input[1];
 2010     uint16_t v_i = input[2];
 2011     WRITE_YUV101010(y_i, u_i, v_i);
 2012 }
 2013 
 2014 static inline void transfer_YUV161616_to_YUV420P_YUV422P(unsigned char *output_y, 
 2015     unsigned char *output_u, 
 2016     unsigned char *output_v, 
 2017     uint16_t *input,
 2018     int output_column)
 2019 {
 2020     output_y[output_column] = input[0] >> 8;
 2021     output_u[output_column / 2] = input[1] >> 8;
 2022     output_v[output_column / 2] = input[2] >> 8;
 2023 }
 2024 
 2025 static inline void transfer_YUV161616_to_YUV444P(unsigned char *output_y, 
 2026     unsigned char *output_u, 
 2027     unsigned char *output_v, 
 2028     uint16_t *input,
 2029     int output_column)
 2030 {
 2031     output_y[output_column] = input[0] >> 8;
 2032     output_u[output_column] = input[1] >> 8;
 2033     output_v[output_column] = input[2] >> 8;
 2034 }
 2035 
 2036 static inline void transfer_YUV161616_to_YUV422(unsigned char *(*output), 
 2037     uint16_t *input,
 2038     int j)
 2039 {
 2040 // Store U and V for even pixels only
 2041     if(!(j & 1))
 2042     {
 2043         (*output)[1] = input[1] >> 8;
 2044         (*output)[3] = input[2] >> 8;
 2045         (*output)[0] = input[0] >> 8;
 2046     }
 2047     else
 2048 // Store Y and advance output for odd pixels only
 2049     {
 2050         (*output)[2] = input[0] >> 8;
 2051         (*output) += 4;
 2052     }
 2053 }
 2054 
 2055 
 2056 
 2057 
 2058 
 2059 
 2060 
 2061 
 2062 
 2063 
 2064 
 2065 // ******************************** YUVA16161616 -> ***************************
 2066 
 2067 
 2068 
 2069 
 2070 static inline void transfer_YUVA16161616_to_RGB8(unsigned char *(*output), uint16_t *input)
 2071 {
 2072     int y, u, v, a;
 2073     int r, g, b;
 2074     
 2075     a = input[3];
 2076     y = (((int)input[0]) << 8) | (input[0] >> 8);
 2077     u = input[1] >> 8;
 2078     v = input[2] >> 8;
 2079     YUV_TO_RGB(y, u, v, r, g, b);
 2080     
 2081     r *= a;
 2082     g *= a;
 2083     b *= a;
 2084 
 2085     *(*output) = (unsigned char)(((r & 0xc000) >> 8) + 
 2086                 ((g & 0xe000) >> 10) + 
 2087                 ((b & 0xe000) >> 13));
 2088     (*output)++;
 2089 }
 2090 
 2091 static inline void transfer_YUVA16161616_to_BGR565(unsigned char *(*output), uint16_t *input)
 2092 {
 2093     int y, u, v, a;
 2094     int r, g, b;
 2095     
 2096     a = input[3] >> 8;
 2097     y = (((int)input[0]) << 8) | (input[0] >> 8);
 2098     u = input[1] >> 8;
 2099     v = input[2] >> 8;
 2100     YUV_TO_RGB(y, u, v, r, g, b);
 2101         
 2102     r *= a;
 2103     g *= a;
 2104     b *= a;
 2105 
 2106     *(uint16_t*)(*output) = (uint16_t)((b & 0xf800) + 
 2107                 ((g & 0xfc00) >> 5) + 
 2108                 ((r & 0xf800) >> 11));
 2109     (*output) += 2;
 2110 }
 2111 
 2112 static inline void transfer_YUVA16161616_to_RGB565(unsigned char *(*output), uint16_t *input)
 2113 {
 2114     int y, u, v, a;
 2115     int r, g, b;
 2116     
 2117     a = input[3] >> 8;
 2118     y = (((int)input[0]) << 8) | (input[0] >> 8);
 2119     u = input[1] >> 8;
 2120     v = input[2] >> 8;
 2121     YUV_TO_RGB(y, u, v, r, g, b);
 2122         
 2123     r *= a;
 2124     g *= a;
 2125     b *= a;
 2126 
 2127     *(uint16_t*)(*output) = (uint16_t)((r & 0xf800) + 
 2128                 ((g & 0xfc00) >> 5) + 
 2129                 ((b & 0xf800) >> 11));
 2130     (*output) += 2;
 2131 }
 2132 
 2133 static inline void transfer_YUVA16161616_to_BGR888(unsigned char *(*output), uint16_t *input)
 2134 {
 2135     int y, u, v, a;
 2136     int r, g, b;
 2137     
 2138     a = input[3];
 2139     y = (((int)input[0]) << 8) | (input[0] >> 8);
 2140     u = input[1];
 2141     v = input[2];
 2142 
 2143     YUV_TO_RGB16(y, u, v, r, g, b);
 2144         
 2145     r *= a;
 2146     g *= a;
 2147     b *= a;
 2148 
 2149     *(*output)++ = b / 0xffff00;
 2150     *(*output)++ = g / 0xffff00;
 2151     *(*output)++ = r / 0xffff00;
 2152 }
 2153 
 2154 static inline void transfer_YUVA16161616_to_RGB888(unsigned char *(*output), uint16_t *input)
 2155 {
 2156     unsigned int y, u, v, a;
 2157     unsigned int r, g, b;
 2158 
 2159     a = input[3];
 2160     y = (((int)input[0]) << 8) | (input[0] >> 8);
 2161     u = input[1];
 2162     v = input[2];
 2163 
 2164     YUV_TO_RGB16(y, u, v, r, g, b);
 2165     
 2166     r *= a;
 2167     g *= a;
 2168     b *= a;
 2169     r /= 0xffff00;
 2170     g /= 0xffff00;
 2171     b /= 0xffff00;
 2172 
 2173     CLAMP(r, 0, 0xff);
 2174     CLAMP(g, 0, 0xff);
 2175     CLAMP(b, 0, 0xff);
 2176 
 2177     *(*output)++ = r;
 2178     *(*output)++ = g;
 2179     *(*output)++ = b;
 2180 }
 2181 
 2182 static inline void transfer_YUVA16161616_to_RGBA8888(unsigned char *(*output), uint16_t *input)
 2183 {
 2184     unsigned int y, u, v;
 2185     unsigned int r, g, b;
 2186     
 2187     y = (((int)input[0]) << 8) | (input[0] >> 8);
 2188     u = input[1];
 2189     v = input[2];
 2190 
 2191     YUV_TO_RGB16(y, u, v, r, g, b);
 2192 
 2193     *(*output)++ = (r >> 8);
 2194     *(*output)++ = (g >> 8);
 2195     *(*output)++ = (b >> 8);
 2196     *(*output)++ = input[3] >> 8;
 2197 }
 2198 
 2199 static inline void transfer_YUVA16161616_to_ARGB8888(unsigned char *(*output), uint16_t *input)
 2200 {
 2201     unsigned int y, u, v;
 2202     unsigned int r, g, b;
 2203     
 2204     y = (((int)input[0]) << 8) | (input[0] >> 8);
 2205     u = input[1];
 2206     v = input[2];
 2207 
 2208     YUV_TO_RGB16(y, u, v, r, g, b);
 2209 
 2210     *(*output)++ = input[3] >> 8;
 2211     *(*output)++ = (r >> 8);
 2212     *(*output)++ = (g >> 8);
 2213     *(*output)++ = (b >> 8);
 2214 }
 2215 
 2216 static inline void transfer_YUVA16161616_to_RGB_FLOAT(float *(*output), 
 2217     uint16_t *input)
 2218 {
 2219     float y;
 2220     int u, v;
 2221     float r, g, b, a;
 2222 
 2223     y = (float)input[0] / 0xffff;
 2224     u = input[1];
 2225     v = input[2];
 2226     a = (float)input[3] / 0xffff;
 2227 
 2228     YUV16_TO_RGB_FLOAT(y, u, v, r, g, b);
 2229     
 2230     r *= a;
 2231     g *= a;
 2232     b *= a;
 2233 
 2234     *(*output)++ = r;
 2235     *(*output)++ = g;
 2236     *(*output)++ = b;
 2237 }
 2238 
 2239 static inline void transfer_YUVA16161616_to_RGBA_FLOAT(float *(*output), 
 2240     uint16_t *input)
 2241 {
 2242     float y;
 2243     int u, v;
 2244     float r, g, b, a;
 2245     
 2246     y = (float)input[0] / 0xffff;
 2247     u = input[1];
 2248     v = input[2];
 2249     a = (float)input[3] / 0xffff;
 2250 
 2251     YUV16_TO_RGB_FLOAT(y, u, v, r, g, b);
 2252 
 2253     *(*output)++ = r;
 2254     *(*output)++ = g;
 2255     *(*output)++ = b;
 2256     *(*output)++ = a;
 2257 }
 2258 
 2259 static inline void transfer_YUVA16161616_to_BGR8888(unsigned char *(*output), 
 2260     uint16_t *input)
 2261 {
 2262     int y, u, v, a;
 2263     int64_t r, g, b;
 2264 
 2265     a = input[3];
 2266     y = (((int)input[0]) << 8) | (input[0] >> 8);
 2267     u = input[1] >> 8;
 2268     v = input[2] >> 8;
 2269 
 2270     YUV_TO_RGB(y, u, v, r, g, b);
 2271 
 2272     r *= a;
 2273     g *= a;
 2274     b *= a;
 2275     b /= 0xffff;
 2276     g /= 0xffff;
 2277     r /= 0xffff;
 2278 
 2279     *(*output)++ = b;
 2280     *(*output)++ = g;
 2281     *(*output)++ = r;
 2282     (*output)++;
 2283 }
 2284 
 2285 
 2286 static inline void transfer_YUVA16161616_to_VYU888(unsigned char *(*output), uint16_t *input)
 2287 {
 2288     int y, u, v, a, anti_a;
 2289     a = input[3];
 2290     anti_a = 0xffff - a;
 2291     y = ((uint32_t)input[0] * a) / 0xffff00;
 2292     u = ((uint32_t)input[1] * a + 0x8000 * anti_a) / 0xffff00;
 2293     v = ((uint32_t)input[2] * a + 0x8000 * anti_a) / 0xffff00;
 2294 
 2295     *(*output)++ = v;
 2296     *(*output)++ = y;
 2297     *(*output)++ = u;
 2298 }
 2299 
 2300 
 2301 static inline void transfer_YUVA16161616_to_YUVA16161616(uint16_t *(*output), uint16_t *input)
 2302 {
 2303     (*output)[0] = input[0];
 2304     (*output)[1] = input[1];
 2305     (*output)[2] = input[2];
 2306     (*output)[3] = input[3];
 2307     (*output) += 4;
 2308 }
 2309 
 2310 static inline void transfer_YUVA16161616_to_UYVA8888(unsigned char *(*output), uint16_t *input)
 2311 {
 2312     (*output)[0] = input[1] >> 8;
 2313     (*output)[1] = input[0] >> 8;
 2314     (*output)[2] = input[2] >> 8;
 2315     (*output)[3] = input[3] >> 8;
 2316     (*output) += 4;
 2317 }
 2318 
 2319 
 2320 static inline void transfer_YUVA16161616_to_YUV101010(unsigned char *(*output), uint16_t *input)
 2321 {
 2322     int64_t opacity = input[3];
 2323     int64_t transparency = 0xffff - opacity;
 2324     uint16_t y_i = ((int64_t)input[0] * opacity + (int64_t)0x8000 * transparency) / 0xffff;
 2325     uint16_t u_i = ((int64_t)input[1] * opacity + (int64_t)0x8000 * transparency) / 0xffff;
 2326     uint16_t v_i = ((int64_t)input[2] * opacity + (int64_t)0x8000 * transparency) / 0xffff;
 2327     WRITE_YUV101010(y_i, u_i, v_i);
 2328 }
 2329 
 2330 static inline void transfer_YUVA16161616_to_YUV420P_YUV422P(unsigned char *output_y, 
 2331     unsigned char *output_u, 
 2332     unsigned char *output_v, 
 2333     uint16_t *input,
 2334     int output_column)
 2335 {
 2336     int64_t opacity = input[3];
 2337     int64_t transparency = 0xffff - opacity;
 2338 
 2339     output_y[output_column] =     ((int64_t)input[0] * opacity) / 0xffff00;
 2340     output_u[output_column / 2] = ((int64_t)input[1] * opacity + 0x8000 * transparency) / 0xffff00;
 2341     output_v[output_column / 2] = ((int64_t)input[2] * opacity + 0x8000 * transparency) / 0xffff00;
 2342 }
 2343 
 2344 static inline void transfer_YUVA16161616_to_YUV444P(unsigned char *output_y, 
 2345     unsigned char *output_u, 
 2346     unsigned char *output_v, 
 2347     uint16_t *input,
 2348     int output_column)
 2349 {
 2350     int64_t opacity = input[3];
 2351     int64_t transparency = 0xffff - opacity;
 2352 
 2353     output_y[output_column] = ((int64_t)input[0] * opacity) / 0xffff00;
 2354     output_u[output_column] = ((int64_t)input[1] * opacity + 0x8000 * transparency) / 0xffff00;
 2355     output_v[output_column] = ((int64_t)input[2] * opacity + 0x8000 * transparency) / 0xffff00;
 2356 }
 2357 
 2358 static inline void transfer_YUVA16161616_to_YUV422(unsigned char *(*output), 
 2359     uint16_t *input,
 2360     int j)
 2361 {
 2362     int64_t opacity = input[3];
 2363     int64_t transparency = 0xffff - opacity;
 2364 
 2365 // Store U and V for even pixels only
 2366     if(!(j & 1))
 2367     {
 2368         (*output)[0] = ((int64_t)input[0] * opacity) / 0xffff00;
 2369         (*output)[1] = ((int64_t)input[1] * opacity + 0x8000 * transparency) / 0xffff00;
 2370         (*output)[3] = ((int64_t)input[2] * opacity + 0x8000 * transparency) / 0xffff00;
 2371     }
 2372     else
 2373 // Store Y and advance output for odd pixels only
 2374     {
 2375         (*output)[2] = (input[0] * opacity) / 0xffff00;
 2376         (*output) += 4;
 2377     }
 2378 }
 2379 
 2380 
 2381 
 2382 
 2383 
 2384 
 2385 
 2386 
 2387 
 2388 
 2389 
 2390 
 2391 
 2392 
 2393 
 2394 
 2395 
 2396 
 2397 
 2398 
 2399 
 2400 
 2401 
 2402 
 2403 
 2404 
 2405 
 2406 
 2407 
 2408 
 2409 
 2410 
 2411 
 2412 
 2413 
 2414 
 2415 
 2416 
 2417 
 2418 
 2419 
 2420 // ******************************** Loops *************************************
 2421 
 2422 #define TRANSFER_FRAME_HEAD \
 2423     for(i = 0; i < out_h; i++) \
 2424     { \
 2425         unsigned char *output_row = output_rows[i + out_y] + out_x * out_pixelsize; \
 2426         unsigned char *input_row = input_rows[row_table[i]]; \
 2427         int bit_counter = 7; \
 2428         for(j = 0; j < out_w; j++) \
 2429         {
 2430 
 2431 #define TRANSFER_FRAME_TAIL \
 2432         } \
 2433     }
 2434 
 2435 #define TRANSFER_YUV420P_OUT_HEAD \
 2436     for(i = 0; i < out_h; i++) \
 2437     { \
 2438         unsigned char *input_row = input_rows[row_table[i]]; \
 2439         unsigned char *output_y = out_y_plane + i * total_out_w + out_x; \
 2440         unsigned char *output_u = out_u_plane + i / 2 * total_out_w / 2 + out_x / 2; \
 2441         unsigned char *output_v = out_v_plane + i / 2 * total_out_w / 2 + out_x / 2; \
 2442         for(j = 0; j < out_w; j++) \
 2443         {
 2444 
 2445 #define TRANSFER_YUV422P_OUT_HEAD \
 2446     for(i = 0; i < out_h; i++) \
 2447     { \
 2448         unsigned char *input_row = input_rows[row_table[i]]; \
 2449         unsigned char *output_y = out_y_plane + i * total_out_w + out_x; \
 2450         unsigned char *output_u = out_u_plane + i * total_out_w / 2 + out_x / 2; \
 2451         unsigned char *output_v = out_v_plane + i * total_out_w / 2 + out_x / 2; \
 2452         for(j = 0; j < out_w; j++) \
 2453         {
 2454 
 2455 #define TRANSFER_YUV444P_OUT_HEAD \
 2456     for(i = 0; i < out_h; i++) \
 2457     { \
 2458         unsigned char *input_row = input_rows[row_table[i]]; \
 2459         unsigned char *output_y = out_y_plane + i * total_out_w + out_x; \
 2460         unsigned char *output_u = out_u_plane + i * total_out_w + out_x; \
 2461         unsigned char *output_v = out_v_plane + i * total_out_w + out_x; \
 2462         for(j = 0; j < out_w; j++) \
 2463         {
 2464 
 2465 #define TRANSFER_YUV420P_IN_HEAD \
 2466     for(i = 0; i < out_h; i++) \
 2467     { \
 2468         unsigned char *output_row = output_rows[i + out_y] + out_x * out_pixelsize; \
 2469         unsigned char *input_y = in_y_plane + row_table[i] * total_in_w; \
 2470         unsigned char *input_u = in_u_plane + (row_table[i] / 2) * (total_in_w / 2); \
 2471         unsigned char *input_v = in_v_plane + (row_table[i] / 2) * (total_in_w / 2); \
 2472         for(j = 0; j < out_w; j++) \
 2473         {
 2474 
 2475 #define TRANSFER_YUV9P_IN_HEAD \
 2476     for(i = 0; i < out_h; i++) \
 2477     { \
 2478         unsigned char *output_row = output_rows[i + out_y] + out_x * out_pixelsize; \
 2479         unsigned char *input_y = in_y_plane + row_table[i] * total_in_w; \
 2480         unsigned char *input_u = in_u_plane + (row_table[i] / 4) * (total_in_w / 4); \
 2481         unsigned char *input_v = in_v_plane + (row_table[i] / 4) * (total_in_w / 4); \
 2482         for(j = 0; j < out_w; j++) \
 2483         {
 2484 
 2485 
 2486 #define TRANSFER_YUV422P_IN_HEAD \
 2487     for(i = 0; i < out_h; i++) \
 2488     { \
 2489         unsigned char *output_row = output_rows[i + out_y] + out_x * out_pixelsize; \
 2490         unsigned char *input_y = in_y_plane + row_table[i] * total_in_w; \
 2491         unsigned char *input_u = in_u_plane + row_table[i] * (total_in_w / 2); \
 2492         unsigned char *input_v = in_v_plane + row_table[i] * (total_in_w / 2); \
 2493         for(j = 0; j < out_w; j++) \
 2494         {
 2495 
 2496 #define TRANSFER_YUV444P_IN_HEAD \
 2497     for(i = 0; i < out_h; i++) \
 2498     { \
 2499         unsigned char *output_row = output_rows[i + out_y] + out_x * out_pixelsize; \
 2500         unsigned char *input_y = in_y_plane + row_table[i] * total_in_w; \
 2501         unsigned char *input_u = in_u_plane + row_table[i] * total_in_w; \
 2502         unsigned char *input_v = in_v_plane + row_table[i] * total_in_w; \
 2503         for(j = 0; j < out_w; j++) \
 2504         {
 2505 
 2506 
 2507 #define TRANSFER_YUV422_IN_HEAD \
 2508     for(i = 0; i < out_h; i++) \
 2509     { \
 2510         unsigned char *output_row = output_rows[i + out_y] + ((out_x * out_pixelsize) & 0xfffffffc); \
 2511         unsigned char *input_y = in_y_plane + row_table[i] * total_in_w; \
 2512         unsigned char *input_u = in_u_plane + row_table[i] * (total_in_w / 2); \
 2513         unsigned char *input_v = in_v_plane + row_table[i] * (total_in_w / 2); \
 2514         for(j = 0; j < out_w; j++) \
 2515         {
 2516 
 2517 
 2518 
 2519 
 2520 
 2521 // ******************************** Permutation *******************************
 2522 
 2523 
 2524 
 2525 #define PERMUTATION_ARGS \
 2526     unsigned char **output_rows,  \
 2527     unsigned char **input_rows, \
 2528     unsigned char *out_y_plane, \
 2529     unsigned char *out_u_plane, \
 2530     unsigned char *out_v_plane, \
 2531     unsigned char *in_y_plane, \
 2532     unsigned char *in_u_plane, \
 2533     unsigned char *in_v_plane, \
 2534     int in_x,  \
 2535     int in_y,  \
 2536     int in_w,  \
 2537     int in_h, \
 2538     int out_x,  \
 2539     int out_y,  \
 2540     int out_w,  \
 2541     int out_h, \
 2542     int in_colormodel,  \
 2543     int out_colormodel, \
 2544     int bg_color, \
 2545     int total_in_w, \
 2546     int total_out_w, \
 2547     int scale, \
 2548     int out_pixelsize, \
 2549     int in_pixelsize, \
 2550     int *row_table, \
 2551     int *column_table, \
 2552     int bg_r, \
 2553     int bg_g, \
 2554     int bg_b