LCOV - code coverage report
Current view: top level - src/libswscale - swscale_unscaled.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 402 1018 39.5 %
Date: 2017-01-19 23:52:33 Functions: 18 40 45.0 %

          Line data    Source code
       1             : /*
       2             :  * Copyright (C) 2001-2011 Michael Niedermayer <michaelni@gmx.at>
       3             :  *
       4             :  * This file is part of FFmpeg.
       5             :  *
       6             :  * FFmpeg is free software; you can redistribute it and/or
       7             :  * modify it under the terms of the GNU Lesser General Public
       8             :  * License as published by the Free Software Foundation; either
       9             :  * version 2.1 of the License, or (at your option) any later version.
      10             :  *
      11             :  * FFmpeg is distributed in the hope that it will be useful,
      12             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      14             :  * Lesser General Public License for more details.
      15             :  *
      16             :  * You should have received a copy of the GNU Lesser General Public
      17             :  * License along with FFmpeg; if not, write to the Free Software
      18             :  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
      19             :  */
      20             : 
      21             : #include <inttypes.h>
      22             : #include <string.h>
      23             : #include <math.h>
      24             : #include <stdio.h>
      25             : #include "config.h"
      26             : #include "swscale.h"
      27             : #include "swscale_internal.h"
      28             : #include "rgb2rgb.h"
      29             : #include "libavutil/intreadwrite.h"
      30             : #include "libavutil/cpu.h"
      31             : #include "libavutil/avutil.h"
      32             : #include "libavutil/mathematics.h"
      33             : #include "libavutil/bswap.h"
      34             : #include "libavutil/pixdesc.h"
      35             : #include "libavutil/avassert.h"
      36             : #include "libavutil/avconfig.h"
      37             : 
      38             : DECLARE_ALIGNED(8, static const uint8_t, dithers)[8][8][8]={
      39             : {
      40             :   {   0,  1,  0,  1,  0,  1,  0,  1,},
      41             :   {   1,  0,  1,  0,  1,  0,  1,  0,},
      42             :   {   0,  1,  0,  1,  0,  1,  0,  1,},
      43             :   {   1,  0,  1,  0,  1,  0,  1,  0,},
      44             :   {   0,  1,  0,  1,  0,  1,  0,  1,},
      45             :   {   1,  0,  1,  0,  1,  0,  1,  0,},
      46             :   {   0,  1,  0,  1,  0,  1,  0,  1,},
      47             :   {   1,  0,  1,  0,  1,  0,  1,  0,},
      48             : },{
      49             :   {   1,  2,  1,  2,  1,  2,  1,  2,},
      50             :   {   3,  0,  3,  0,  3,  0,  3,  0,},
      51             :   {   1,  2,  1,  2,  1,  2,  1,  2,},
      52             :   {   3,  0,  3,  0,  3,  0,  3,  0,},
      53             :   {   1,  2,  1,  2,  1,  2,  1,  2,},
      54             :   {   3,  0,  3,  0,  3,  0,  3,  0,},
      55             :   {   1,  2,  1,  2,  1,  2,  1,  2,},
      56             :   {   3,  0,  3,  0,  3,  0,  3,  0,},
      57             : },{
      58             :   {   2,  4,  3,  5,  2,  4,  3,  5,},
      59             :   {   6,  0,  7,  1,  6,  0,  7,  1,},
      60             :   {   3,  5,  2,  4,  3,  5,  2,  4,},
      61             :   {   7,  1,  6,  0,  7,  1,  6,  0,},
      62             :   {   2,  4,  3,  5,  2,  4,  3,  5,},
      63             :   {   6,  0,  7,  1,  6,  0,  7,  1,},
      64             :   {   3,  5,  2,  4,  3,  5,  2,  4,},
      65             :   {   7,  1,  6,  0,  7,  1,  6,  0,},
      66             : },{
      67             :   {   4,  8,  7, 11,  4,  8,  7, 11,},
      68             :   {  12,  0, 15,  3, 12,  0, 15,  3,},
      69             :   {   6, 10,  5,  9,  6, 10,  5,  9,},
      70             :   {  14,  2, 13,  1, 14,  2, 13,  1,},
      71             :   {   4,  8,  7, 11,  4,  8,  7, 11,},
      72             :   {  12,  0, 15,  3, 12,  0, 15,  3,},
      73             :   {   6, 10,  5,  9,  6, 10,  5,  9,},
      74             :   {  14,  2, 13,  1, 14,  2, 13,  1,},
      75             : },{
      76             :   {   9, 17, 15, 23,  8, 16, 14, 22,},
      77             :   {  25,  1, 31,  7, 24,  0, 30,  6,},
      78             :   {  13, 21, 11, 19, 12, 20, 10, 18,},
      79             :   {  29,  5, 27,  3, 28,  4, 26,  2,},
      80             :   {   8, 16, 14, 22,  9, 17, 15, 23,},
      81             :   {  24,  0, 30,  6, 25,  1, 31,  7,},
      82             :   {  12, 20, 10, 18, 13, 21, 11, 19,},
      83             :   {  28,  4, 26,  2, 29,  5, 27,  3,},
      84             : },{
      85             :   {  18, 34, 30, 46, 17, 33, 29, 45,},
      86             :   {  50,  2, 62, 14, 49,  1, 61, 13,},
      87             :   {  26, 42, 22, 38, 25, 41, 21, 37,},
      88             :   {  58, 10, 54,  6, 57,  9, 53,  5,},
      89             :   {  16, 32, 28, 44, 19, 35, 31, 47,},
      90             :   {  48,  0, 60, 12, 51,  3, 63, 15,},
      91             :   {  24, 40, 20, 36, 27, 43, 23, 39,},
      92             :   {  56,  8, 52,  4, 59, 11, 55,  7,},
      93             : },{
      94             :   {  18, 34, 30, 46, 17, 33, 29, 45,},
      95             :   {  50,  2, 62, 14, 49,  1, 61, 13,},
      96             :   {  26, 42, 22, 38, 25, 41, 21, 37,},
      97             :   {  58, 10, 54,  6, 57,  9, 53,  5,},
      98             :   {  16, 32, 28, 44, 19, 35, 31, 47,},
      99             :   {  48,  0, 60, 12, 51,  3, 63, 15,},
     100             :   {  24, 40, 20, 36, 27, 43, 23, 39,},
     101             :   {  56,  8, 52,  4, 59, 11, 55,  7,},
     102             : },{
     103             :   {  36, 68, 60, 92, 34, 66, 58, 90,},
     104             :   { 100,  4,124, 28, 98,  2,122, 26,},
     105             :   {  52, 84, 44, 76, 50, 82, 42, 74,},
     106             :   { 116, 20,108, 12,114, 18,106, 10,},
     107             :   {  32, 64, 56, 88, 38, 70, 62, 94,},
     108             :   {  96,  0,120, 24,102,  6,126, 30,},
     109             :   {  48, 80, 40, 72, 54, 86, 46, 78,},
     110             :   { 112, 16,104,  8,118, 22,110, 14,},
     111             : }};
     112             : 
     113             : static const uint16_t dither_scale[15][16]={
     114             : {    2,    3,    3,    5,    5,    5,    5,    5,    5,    5,    5,    5,    5,    5,    5,    5,},
     115             : {    2,    3,    7,    7,   13,   13,   25,   25,   25,   25,   25,   25,   25,   25,   25,   25,},
     116             : {    3,    3,    4,   15,   15,   29,   57,   57,   57,  113,  113,  113,  113,  113,  113,  113,},
     117             : {    3,    4,    4,    5,   31,   31,   61,  121,  241,  241,  241,  241,  481,  481,  481,  481,},
     118             : {    3,    4,    5,    5,    6,   63,   63,  125,  249,  497,  993,  993,  993,  993,  993, 1985,},
     119             : {    3,    5,    6,    6,    6,    7,  127,  127,  253,  505, 1009, 2017, 4033, 4033, 4033, 4033,},
     120             : {    3,    5,    6,    7,    7,    7,    8,  255,  255,  509, 1017, 2033, 4065, 8129,16257,16257,},
     121             : {    3,    5,    6,    8,    8,    8,    8,    9,  511,  511, 1021, 2041, 4081, 8161,16321,32641,},
     122             : {    3,    5,    7,    8,    9,    9,    9,    9,   10, 1023, 1023, 2045, 4089, 8177,16353,32705,},
     123             : {    3,    5,    7,    8,   10,   10,   10,   10,   10,   11, 2047, 2047, 4093, 8185,16369,32737,},
     124             : {    3,    5,    7,    8,   10,   11,   11,   11,   11,   11,   12, 4095, 4095, 8189,16377,32753,},
     125             : {    3,    5,    7,    9,   10,   12,   12,   12,   12,   12,   12,   13, 8191, 8191,16381,32761,},
     126             : {    3,    5,    7,    9,   10,   12,   13,   13,   13,   13,   13,   13,   14,16383,16383,32765,},
     127             : {    3,    5,    7,    9,   10,   12,   14,   14,   14,   14,   14,   14,   14,   15,32767,32767,},
     128             : {    3,    5,    7,    9,   11,   12,   14,   15,   15,   15,   15,   15,   15,   15,   16,65535,},
     129             : };
     130             : 
     131             : 
     132          71 : static void fillPlane(uint8_t *plane, int stride, int width, int height, int y,
     133             :                       uint8_t val)
     134             : {
     135             :     int i;
     136          71 :     uint8_t *ptr = plane + stride * y;
     137       20519 :     for (i = 0; i < height; i++) {
     138       20448 :         memset(ptr, val, width);
     139       20448 :         ptr += stride;
     140             :     }
     141          71 : }
     142             : 
     143         228 : static void copyPlane(const uint8_t *src, int srcStride,
     144             :                       int srcSliceY, int srcSliceH, int width,
     145             :                       uint8_t *dst, int dstStride)
     146             : {
     147         228 :     dst += dstStride * srcSliceY;
     148         228 :     if (dstStride == srcStride && srcStride > 0) {
     149         100 :         memcpy(dst, src, srcSliceH * dstStride);
     150             :     } else {
     151             :         int i;
     152       36992 :         for (i = 0; i < srcSliceH; i++) {
     153       36864 :             memcpy(dst, src, width);
     154       36864 :             src += srcStride;
     155       36864 :             dst += dstStride;
     156             :         }
     157             :     }
     158         228 : }
     159             : 
     160         128 : static int planarToNv12Wrapper(SwsContext *c, const uint8_t *src[],
     161             :                                int srcStride[], int srcSliceY,
     162             :                                int srcSliceH, uint8_t *dstParam[],
     163             :                                int dstStride[])
     164             : {
     165         128 :     uint8_t *dst = dstParam[1] + dstStride[1] * srcSliceY / 2;
     166             : 
     167         128 :     copyPlane(src[0], srcStride[0], srcSliceY, srcSliceH, c->srcW,
     168             :               dstParam[0], dstStride[0]);
     169             : 
     170         128 :     if (c->dstFormat == AV_PIX_FMT_NV12)
     171         256 :         interleaveBytes(src[1], src[2], dst, c->srcW / 2, srcSliceH / 2,
     172         192 :                         srcStride[1], srcStride[2], dstStride[1]);
     173             :     else
     174         256 :         interleaveBytes(src[2], src[1], dst, c->srcW / 2, srcSliceH / 2,
     175         192 :                         srcStride[2], srcStride[1], dstStride[1]);
     176             : 
     177         128 :     return srcSliceH;
     178             : }
     179             : 
     180         100 : static int nv12ToPlanarWrapper(SwsContext *c, const uint8_t *src[],
     181             :                                int srcStride[], int srcSliceY,
     182             :                                int srcSliceH, uint8_t *dstParam[],
     183             :                                int dstStride[])
     184             : {
     185         100 :     uint8_t *dst1 = dstParam[1] + dstStride[1] * srcSliceY / 2;
     186         100 :     uint8_t *dst2 = dstParam[2] + dstStride[2] * srcSliceY / 2;
     187             : 
     188         100 :     copyPlane(src[0], srcStride[0], srcSliceY, srcSliceH, c->srcW,
     189             :               dstParam[0], dstStride[0]);
     190             : 
     191         100 :     if (c->srcFormat == AV_PIX_FMT_NV12)
     192         200 :         deinterleaveBytes(src[1], dst1, dst2,c->srcW / 2, srcSliceH / 2,
     193         150 :                           srcStride[1], dstStride[1], dstStride[2]);
     194             :     else
     195         200 :         deinterleaveBytes(src[1], dst2, dst1, c->srcW / 2, srcSliceH / 2,
     196         150 :                           srcStride[1], dstStride[2], dstStride[1]);
     197             : 
     198         100 :     return srcSliceH;
     199             : }
     200             : 
     201           0 : static int planarToP010Wrapper(SwsContext *c, const uint8_t *src8[],
     202             :                                int srcStride[], int srcSliceY,
     203             :                                int srcSliceH, uint8_t *dstParam8[],
     204             :                                int dstStride[])
     205             : {
     206           0 :     const uint16_t **src = (const uint16_t**)src8;
     207           0 :     uint16_t *dstY = (uint16_t*)(dstParam8[0] + dstStride[0] * srcSliceY);
     208           0 :     uint16_t *dstUV = (uint16_t*)(dstParam8[1] + dstStride[1] * srcSliceY / 2);
     209             :     int x, y;
     210             : 
     211           0 :     av_assert0(!(srcStride[0] % 2 || srcStride[1] % 2 || srcStride[2] % 2 ||
     212             :                  dstStride[0] % 2 || dstStride[1] % 2));
     213             : 
     214           0 :     for (y = 0; y < srcSliceH; y++) {
     215           0 :         uint16_t *tdstY = dstY;
     216           0 :         const uint16_t *tsrc0 = src[0];
     217           0 :         for (x = c->srcW; x > 0; x--) {
     218           0 :             *tdstY++ = *tsrc0++ << 6;
     219             :         }
     220           0 :         src[0] += srcStride[0] / 2;
     221           0 :         dstY += dstStride[0] / 2;
     222             : 
     223           0 :         if (!(y & 1)) {
     224           0 :             uint16_t *tdstUV = dstUV;
     225           0 :             const uint16_t *tsrc1 = src[1];
     226           0 :             const uint16_t *tsrc2 = src[2];
     227           0 :             for (x = c->srcW / 2; x > 0; x--) {
     228           0 :                 *tdstUV++ = *tsrc1++ << 6;
     229           0 :                 *tdstUV++ = *tsrc2++ << 6;
     230             :             }
     231           0 :             src[1] += srcStride[1] / 2;
     232           0 :             src[2] += srcStride[2] / 2;
     233           0 :             dstUV += dstStride[1] / 2;
     234             :         }
     235             :     }
     236             : 
     237           0 :     return srcSliceH;
     238             : }
     239             : 
     240             : #if AV_HAVE_BIGENDIAN
     241             : #define output_pixel(p, v) do { \
     242             :         uint16_t *pp = (p); \
     243             :         AV_WL16(pp, (v)); \
     244             :     } while(0)
     245             : #else
     246             : #define output_pixel(p, v) (*p) = (v)
     247             : #endif
     248             : 
     249          13 : static int planar8ToP01xleWrapper(SwsContext *c, const uint8_t *src[],
     250             :                                   int srcStride[], int srcSliceY,
     251             :                                   int srcSliceH, uint8_t *dstParam8[],
     252             :                                   int dstStride[])
     253             : {
     254          13 :     uint16_t *dstY = (uint16_t*)(dstParam8[0] + dstStride[0] * srcSliceY);
     255          13 :     uint16_t *dstUV = (uint16_t*)(dstParam8[1] + dstStride[1] * srcSliceY / 2);
     256             :     int x, y, t;
     257             : 
     258          13 :     av_assert0(!(dstStride[0] % 2 || dstStride[1] % 2));
     259             : 
     260        3757 :     for (y = 0; y < srcSliceH; y++) {
     261        3744 :         uint16_t *tdstY = dstY;
     262        3744 :         const uint8_t *tsrc0 = src[0];
     263     1321632 :         for (x = c->srcW; x > 0; x--) {
     264     1317888 :             t = *tsrc0++;
     265     1317888 :             output_pixel(tdstY++, t | (t << 8));
     266             :         }
     267        3744 :         src[0] += srcStride[0];
     268        3744 :         dstY += dstStride[0] / 2;
     269             : 
     270        3744 :         if (!(y & 1)) {
     271        1872 :             uint16_t *tdstUV = dstUV;
     272        1872 :             const uint8_t *tsrc1 = src[1];
     273        1872 :             const uint8_t *tsrc2 = src[2];
     274      331344 :             for (x = c->srcW / 2; x > 0; x--) {
     275      329472 :                 t = *tsrc1++;
     276      329472 :                 output_pixel(tdstUV++, t | (t << 8));
     277      329472 :                 t = *tsrc2++;
     278      329472 :                 output_pixel(tdstUV++, t | (t << 8));
     279             :             }
     280        1872 :             src[1] += srcStride[1];
     281        1872 :             src[2] += srcStride[2];
     282        1872 :             dstUV += dstStride[1] / 2;
     283             :         }
     284             :     }
     285             : 
     286          13 :     return srcSliceH;
     287             : }
     288             : 
     289             : #undef output_pixel
     290             : 
     291           0 : static int planarToYuy2Wrapper(SwsContext *c, const uint8_t *src[],
     292             :                                int srcStride[], int srcSliceY, int srcSliceH,
     293             :                                uint8_t *dstParam[], int dstStride[])
     294             : {
     295           0 :     uint8_t *dst = dstParam[0] + dstStride[0] * srcSliceY;
     296             : 
     297           0 :     yv12toyuy2(src[0], src[1], src[2], dst, c->srcW, srcSliceH, srcStride[0],
     298           0 :                srcStride[1], dstStride[0]);
     299             : 
     300           0 :     return srcSliceH;
     301             : }
     302             : 
     303           0 : static int planarToUyvyWrapper(SwsContext *c, const uint8_t *src[],
     304             :                                int srcStride[], int srcSliceY, int srcSliceH,
     305             :                                uint8_t *dstParam[], int dstStride[])
     306             : {
     307           0 :     uint8_t *dst = dstParam[0] + dstStride[0] * srcSliceY;
     308             : 
     309           0 :     yv12touyvy(src[0], src[1], src[2], dst, c->srcW, srcSliceH, srcStride[0],
     310           0 :                srcStride[1], dstStride[0]);
     311             : 
     312           0 :     return srcSliceH;
     313             : }
     314             : 
     315           0 : static int yuv422pToYuy2Wrapper(SwsContext *c, const uint8_t *src[],
     316             :                                 int srcStride[], int srcSliceY, int srcSliceH,
     317             :                                 uint8_t *dstParam[], int dstStride[])
     318             : {
     319           0 :     uint8_t *dst = dstParam[0] + dstStride[0] * srcSliceY;
     320             : 
     321           0 :     yuv422ptoyuy2(src[0], src[1], src[2], dst, c->srcW, srcSliceH, srcStride[0],
     322           0 :                   srcStride[1], dstStride[0]);
     323             : 
     324           0 :     return srcSliceH;
     325             : }
     326             : 
     327           0 : static int yuv422pToUyvyWrapper(SwsContext *c, const uint8_t *src[],
     328             :                                 int srcStride[], int srcSliceY, int srcSliceH,
     329             :                                 uint8_t *dstParam[], int dstStride[])
     330             : {
     331           0 :     uint8_t *dst = dstParam[0] + dstStride[0] * srcSliceY;
     332             : 
     333           0 :     yuv422ptouyvy(src[0], src[1], src[2], dst, c->srcW, srcSliceH, srcStride[0],
     334           0 :                   srcStride[1], dstStride[0]);
     335             : 
     336           0 :     return srcSliceH;
     337             : }
     338             : 
     339           0 : static int yuyvToYuv420Wrapper(SwsContext *c, const uint8_t *src[],
     340             :                                int srcStride[], int srcSliceY, int srcSliceH,
     341             :                                uint8_t *dstParam[], int dstStride[])
     342             : {
     343           0 :     uint8_t *ydst = dstParam[0] + dstStride[0] * srcSliceY;
     344           0 :     uint8_t *udst = dstParam[1] + dstStride[1] * srcSliceY / 2;
     345           0 :     uint8_t *vdst = dstParam[2] + dstStride[2] * srcSliceY / 2;
     346             : 
     347           0 :     yuyvtoyuv420(ydst, udst, vdst, src[0], c->srcW, srcSliceH, dstStride[0],
     348           0 :                  dstStride[1], srcStride[0]);
     349             : 
     350           0 :     if (dstParam[3])
     351           0 :         fillPlane(dstParam[3], dstStride[3], c->srcW, srcSliceH, srcSliceY, 255);
     352             : 
     353           0 :     return srcSliceH;
     354             : }
     355             : 
     356           0 : static int yuyvToYuv422Wrapper(SwsContext *c, const uint8_t *src[],
     357             :                                int srcStride[], int srcSliceY, int srcSliceH,
     358             :                                uint8_t *dstParam[], int dstStride[])
     359             : {
     360           0 :     uint8_t *ydst = dstParam[0] + dstStride[0] * srcSliceY;
     361           0 :     uint8_t *udst = dstParam[1] + dstStride[1] * srcSliceY;
     362           0 :     uint8_t *vdst = dstParam[2] + dstStride[2] * srcSliceY;
     363             : 
     364           0 :     yuyvtoyuv422(ydst, udst, vdst, src[0], c->srcW, srcSliceH, dstStride[0],
     365           0 :                  dstStride[1], srcStride[0]);
     366             : 
     367           0 :     return srcSliceH;
     368             : }
     369             : 
     370           0 : static int uyvyToYuv420Wrapper(SwsContext *c, const uint8_t *src[],
     371             :                                int srcStride[], int srcSliceY, int srcSliceH,
     372             :                                uint8_t *dstParam[], int dstStride[])
     373             : {
     374           0 :     uint8_t *ydst = dstParam[0] + dstStride[0] * srcSliceY;
     375           0 :     uint8_t *udst = dstParam[1] + dstStride[1] * srcSliceY / 2;
     376           0 :     uint8_t *vdst = dstParam[2] + dstStride[2] * srcSliceY / 2;
     377             : 
     378           0 :     uyvytoyuv420(ydst, udst, vdst, src[0], c->srcW, srcSliceH, dstStride[0],
     379           0 :                  dstStride[1], srcStride[0]);
     380             : 
     381           0 :     if (dstParam[3])
     382           0 :         fillPlane(dstParam[3], dstStride[3], c->srcW, srcSliceH, srcSliceY, 255);
     383             : 
     384           0 :     return srcSliceH;
     385             : }
     386             : 
     387           0 : static int uyvyToYuv422Wrapper(SwsContext *c, const uint8_t *src[],
     388             :                                int srcStride[], int srcSliceY, int srcSliceH,
     389             :                                uint8_t *dstParam[], int dstStride[])
     390             : {
     391           0 :     uint8_t *ydst = dstParam[0] + dstStride[0] * srcSliceY;
     392           0 :     uint8_t *udst = dstParam[1] + dstStride[1] * srcSliceY;
     393           0 :     uint8_t *vdst = dstParam[2] + dstStride[2] * srcSliceY;
     394             : 
     395           0 :     uyvytoyuv422(ydst, udst, vdst, src[0], c->srcW, srcSliceH, dstStride[0],
     396           0 :                  dstStride[1], srcStride[0]);
     397             : 
     398           0 :     return srcSliceH;
     399             : }
     400             : 
     401           0 : static void gray8aToPacked32(const uint8_t *src, uint8_t *dst, int num_pixels,
     402             :                              const uint8_t *palette)
     403             : {
     404             :     int i;
     405           0 :     for (i = 0; i < num_pixels; i++)
     406           0 :         ((uint32_t *) dst)[i] = ((const uint32_t *) palette)[src[i << 1]] | (src[(i << 1) + 1] << 24);
     407           0 : }
     408             : 
     409           0 : static void gray8aToPacked32_1(const uint8_t *src, uint8_t *dst, int num_pixels,
     410             :                                const uint8_t *palette)
     411             : {
     412             :     int i;
     413             : 
     414           0 :     for (i = 0; i < num_pixels; i++)
     415           0 :         ((uint32_t *) dst)[i] = ((const uint32_t *) palette)[src[i << 1]] | src[(i << 1) + 1];
     416           0 : }
     417             : 
     418           0 : static void gray8aToPacked24(const uint8_t *src, uint8_t *dst, int num_pixels,
     419             :                              const uint8_t *palette)
     420             : {
     421             :     int i;
     422             : 
     423           0 :     for (i = 0; i < num_pixels; i++) {
     424             :         //FIXME slow?
     425           0 :         dst[0] = palette[src[i << 1] * 4 + 0];
     426           0 :         dst[1] = palette[src[i << 1] * 4 + 1];
     427           0 :         dst[2] = palette[src[i << 1] * 4 + 2];
     428           0 :         dst += 3;
     429             :     }
     430           0 : }
     431             : 
     432          13 : static int packed_16bpc_bswap(SwsContext *c, const uint8_t *src[],
     433             :                               int srcStride[], int srcSliceY, int srcSliceH,
     434             :                               uint8_t *dst[], int dstStride[])
     435             : {
     436             :     int i, j, p;
     437             : 
     438          65 :     for (p = 0; p < 4; p++) {
     439          52 :         int srcstr = srcStride[p] / 2;
     440          52 :         int dststr = dstStride[p] / 2;
     441          52 :         uint16_t       *dstPtr =       (uint16_t *) dst[p];
     442          52 :         const uint16_t *srcPtr = (const uint16_t *) src[p];
     443          52 :         int min_stride         = FFMIN(FFABS(srcstr), FFABS(dststr));
     444          52 :         if(!dstPtr || !srcPtr)
     445          39 :             continue;
     446          13 :         dstPtr += (srcSliceY >> c->chrDstVSubSample) * dststr;
     447        3757 :         for (i = 0; i < (srcSliceH >> c->chrDstVSubSample); i++) {
     448     3957408 :             for (j = 0; j < min_stride; j++) {
     449     3953664 :                 dstPtr[j] = av_bswap16(srcPtr[j]);
     450             :             }
     451        3744 :             srcPtr += srcstr;
     452        3744 :             dstPtr += dststr;
     453             :         }
     454             :     }
     455             : 
     456          13 :     return srcSliceH;
     457             : }
     458             : 
     459        3540 : static int palToRgbWrapper(SwsContext *c, const uint8_t *src[], int srcStride[],
     460             :                            int srcSliceY, int srcSliceH, uint8_t *dst[],
     461             :                            int dstStride[])
     462             : {
     463        3540 :     const enum AVPixelFormat srcFormat = c->srcFormat;
     464        3540 :     const enum AVPixelFormat dstFormat = c->dstFormat;
     465        3540 :     void (*conv)(const uint8_t *src, uint8_t *dst, int num_pixels,
     466             :                  const uint8_t *palette) = NULL;
     467             :     int i;
     468        3540 :     uint8_t *dstPtr = dst[0] + dstStride[0] * srcSliceY;
     469        3540 :     const uint8_t *srcPtr = src[0];
     470             : 
     471        3540 :     if (srcFormat == AV_PIX_FMT_YA8) {
     472           0 :         switch (dstFormat) {
     473           0 :         case AV_PIX_FMT_RGB32  : conv = gray8aToPacked32; break;
     474           0 :         case AV_PIX_FMT_BGR32  : conv = gray8aToPacked32; break;
     475           0 :         case AV_PIX_FMT_BGR32_1: conv = gray8aToPacked32_1; break;
     476           0 :         case AV_PIX_FMT_RGB32_1: conv = gray8aToPacked32_1; break;
     477           0 :         case AV_PIX_FMT_RGB24  : conv = gray8aToPacked24; break;
     478           0 :         case AV_PIX_FMT_BGR24  : conv = gray8aToPacked24; break;
     479             :         }
     480        3540 :     } else if (usePal(srcFormat)) {
     481        3540 :         switch (dstFormat) {
     482         213 :         case AV_PIX_FMT_RGB32  : conv = sws_convertPalette8ToPacked32; break;
     483         217 :         case AV_PIX_FMT_BGR32  : conv = sws_convertPalette8ToPacked32; break;
     484           0 :         case AV_PIX_FMT_BGR32_1: conv = sws_convertPalette8ToPacked32; break;
     485           0 :         case AV_PIX_FMT_RGB32_1: conv = sws_convertPalette8ToPacked32; break;
     486        3110 :         case AV_PIX_FMT_RGB24  : conv = sws_convertPalette8ToPacked24; break;
     487           0 :         case AV_PIX_FMT_BGR24  : conv = sws_convertPalette8ToPacked24; break;
     488             :         }
     489             :     }
     490             : 
     491        3540 :     if (!conv)
     492           0 :         av_log(c, AV_LOG_ERROR, "internal error %s -> %s converter\n",
     493             :                av_get_pix_fmt_name(srcFormat), av_get_pix_fmt_name(dstFormat));
     494             :     else {
     495      800030 :         for (i = 0; i < srcSliceH; i++) {
     496      796490 :             conv(srcPtr, dstPtr, c->srcW, (uint8_t *) c->pal_rgb);
     497      796490 :             srcPtr += srcStride[0];
     498      796490 :             dstPtr += dstStride[0];
     499             :         }
     500             :     }
     501             : 
     502        3540 :     return srcSliceH;
     503             : }
     504             : 
     505           0 : static void packed16togbra16(const uint8_t *src, int srcStride,
     506             :                              uint16_t *dst[], int dstStride[], int srcSliceH,
     507             :                              int src_alpha, int swap, int shift, int width)
     508             : {
     509             :     int x, h, i;
     510           0 :     int dst_alpha = dst[3] != NULL;
     511           0 :     for (h = 0; h < srcSliceH; h++) {
     512           0 :         uint16_t *src_line = (uint16_t *)(src + srcStride * h);
     513           0 :         switch (swap) {
     514             :         case 3:
     515           0 :             if (src_alpha && dst_alpha) {
     516           0 :                 for (x = 0; x < width; x++) {
     517           0 :                     dst[0][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
     518           0 :                     dst[1][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
     519           0 :                     dst[2][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
     520           0 :                     dst[3][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
     521             :                 }
     522           0 :             } else if (dst_alpha) {
     523           0 :                 for (x = 0; x < width; x++) {
     524           0 :                     dst[0][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
     525           0 :                     dst[1][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
     526           0 :                     dst[2][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
     527           0 :                     dst[3][x] = 0xFFFF;
     528             :                 }
     529           0 :             } else if (src_alpha) {
     530           0 :                 for (x = 0; x < width; x++) {
     531           0 :                     dst[0][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
     532           0 :                     dst[1][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
     533           0 :                     dst[2][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
     534           0 :                     src_line++;
     535             :                 }
     536             :             } else {
     537           0 :                 for (x = 0; x < width; x++) {
     538           0 :                     dst[0][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
     539           0 :                     dst[1][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
     540           0 :                     dst[2][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
     541             :                 }
     542             :             }
     543           0 :             break;
     544             :         case 2:
     545           0 :             if (src_alpha && dst_alpha) {
     546           0 :                 for (x = 0; x < width; x++) {
     547           0 :                     dst[0][x] = av_bswap16(*src_line++ >> shift);
     548           0 :                     dst[1][x] = av_bswap16(*src_line++ >> shift);
     549           0 :                     dst[2][x] = av_bswap16(*src_line++ >> shift);
     550           0 :                     dst[3][x] = av_bswap16(*src_line++ >> shift);
     551             :                 }
     552           0 :             } else if (dst_alpha) {
     553           0 :                 for (x = 0; x < width; x++) {
     554           0 :                     dst[0][x] = av_bswap16(*src_line++ >> shift);
     555           0 :                     dst[1][x] = av_bswap16(*src_line++ >> shift);
     556           0 :                     dst[2][x] = av_bswap16(*src_line++ >> shift);
     557           0 :                     dst[3][x] = 0xFFFF;
     558             :                 }
     559           0 :             } else if (src_alpha) {
     560           0 :                 for (x = 0; x < width; x++) {
     561           0 :                     dst[0][x] = av_bswap16(*src_line++ >> shift);
     562           0 :                     dst[1][x] = av_bswap16(*src_line++ >> shift);
     563           0 :                     dst[2][x] = av_bswap16(*src_line++ >> shift);
     564           0 :                     src_line++;
     565             :                 }
     566             :             } else {
     567           0 :                 for (x = 0; x < width; x++) {
     568           0 :                     dst[0][x] = av_bswap16(*src_line++ >> shift);
     569           0 :                     dst[1][x] = av_bswap16(*src_line++ >> shift);
     570           0 :                     dst[2][x] = av_bswap16(*src_line++ >> shift);
     571             :                 }
     572             :             }
     573           0 :             break;
     574             :         case 1:
     575           0 :             if (src_alpha && dst_alpha) {
     576           0 :                 for (x = 0; x < width; x++) {
     577           0 :                     dst[0][x] = av_bswap16(*src_line++) >> shift;
     578           0 :                     dst[1][x] = av_bswap16(*src_line++) >> shift;
     579           0 :                     dst[2][x] = av_bswap16(*src_line++) >> shift;
     580           0 :                     dst[3][x] = av_bswap16(*src_line++) >> shift;
     581             :                 }
     582           0 :             } else if (dst_alpha) {
     583           0 :                 for (x = 0; x < width; x++) {
     584           0 :                     dst[0][x] = av_bswap16(*src_line++) >> shift;
     585           0 :                     dst[1][x] = av_bswap16(*src_line++) >> shift;
     586           0 :                     dst[2][x] = av_bswap16(*src_line++) >> shift;
     587           0 :                     dst[3][x] = 0xFFFF;
     588             :                 }
     589           0 :             } else if (src_alpha) {
     590           0 :                 for (x = 0; x < width; x++) {
     591           0 :                     dst[0][x] = av_bswap16(*src_line++) >> shift;
     592           0 :                     dst[1][x] = av_bswap16(*src_line++) >> shift;
     593           0 :                     dst[2][x] = av_bswap16(*src_line++) >> shift;
     594           0 :                     src_line++;
     595             :                 }
     596             :             } else {
     597           0 :                 for (x = 0; x < width; x++) {
     598           0 :                     dst[0][x] = av_bswap16(*src_line++) >> shift;
     599           0 :                     dst[1][x] = av_bswap16(*src_line++) >> shift;
     600           0 :                     dst[2][x] = av_bswap16(*src_line++) >> shift;
     601             :                 }
     602             :             }
     603           0 :             break;
     604             :         default:
     605           0 :             if (src_alpha && dst_alpha) {
     606           0 :                 for (x = 0; x < width; x++) {
     607           0 :                     dst[0][x] = *src_line++ >> shift;
     608           0 :                     dst[1][x] = *src_line++ >> shift;
     609           0 :                     dst[2][x] = *src_line++ >> shift;
     610           0 :                     dst[3][x] = *src_line++ >> shift;
     611             :                 }
     612           0 :             } else if (dst_alpha) {
     613           0 :                 for (x = 0; x < width; x++) {
     614           0 :                     dst[0][x] = *src_line++ >> shift;
     615           0 :                     dst[1][x] = *src_line++ >> shift;
     616           0 :                     dst[2][x] = *src_line++ >> shift;
     617           0 :                     dst[3][x] = 0xFFFF;
     618             :                 }
     619           0 :             } else if (src_alpha) {
     620           0 :                 for (x = 0; x < width; x++) {
     621           0 :                     dst[0][x] = *src_line++ >> shift;
     622           0 :                     dst[1][x] = *src_line++ >> shift;
     623           0 :                     dst[2][x] = *src_line++ >> shift;
     624           0 :                     src_line++;
     625             :                 }
     626             :             } else {
     627           0 :                 for (x = 0; x < width; x++) {
     628           0 :                     dst[0][x] = *src_line++ >> shift;
     629           0 :                     dst[1][x] = *src_line++ >> shift;
     630           0 :                     dst[2][x] = *src_line++ >> shift;
     631             :                 }
     632             :             }
     633             :         }
     634           0 :         for (i = 0; i < 4; i++)
     635           0 :             dst[i] += dstStride[i] >> 1;
     636             :     }
     637           0 : }
     638             : 
     639           0 : static int Rgb16ToPlanarRgb16Wrapper(SwsContext *c, const uint8_t *src[],
     640             :                                      int srcStride[], int srcSliceY, int srcSliceH,
     641             :                                      uint8_t *dst[], int dstStride[])
     642             : {
     643           0 :     uint16_t *dst2013[] = { (uint16_t *)dst[2], (uint16_t *)dst[0], (uint16_t *)dst[1], (uint16_t *)dst[3] };
     644           0 :     uint16_t *dst1023[] = { (uint16_t *)dst[1], (uint16_t *)dst[0], (uint16_t *)dst[2], (uint16_t *)dst[3] };
     645           0 :     int stride2013[] = { dstStride[2], dstStride[0], dstStride[1], dstStride[3] };
     646           0 :     int stride1023[] = { dstStride[1], dstStride[0], dstStride[2], dstStride[3] };
     647           0 :     const AVPixFmtDescriptor *src_format = av_pix_fmt_desc_get(c->srcFormat);
     648           0 :     const AVPixFmtDescriptor *dst_format = av_pix_fmt_desc_get(c->dstFormat);
     649           0 :     int bpc = dst_format->comp[0].depth;
     650           0 :     int alpha = src_format->flags & AV_PIX_FMT_FLAG_ALPHA;
     651           0 :     int swap = 0;
     652             :     int i;
     653             : 
     654           0 :     if ( HAVE_BIGENDIAN && !(src_format->flags & AV_PIX_FMT_FLAG_BE) ||
     655           0 :         !HAVE_BIGENDIAN &&   src_format->flags & AV_PIX_FMT_FLAG_BE)
     656           0 :         swap++;
     657           0 :     if ( HAVE_BIGENDIAN && !(dst_format->flags & AV_PIX_FMT_FLAG_BE) ||
     658           0 :         !HAVE_BIGENDIAN &&   dst_format->flags & AV_PIX_FMT_FLAG_BE)
     659           0 :         swap += 2;
     660             : 
     661           0 :     if ((dst_format->flags & (AV_PIX_FMT_FLAG_PLANAR | AV_PIX_FMT_FLAG_RGB)) !=
     662           0 :         (AV_PIX_FMT_FLAG_PLANAR | AV_PIX_FMT_FLAG_RGB) || bpc < 9) {
     663           0 :         av_log(c, AV_LOG_ERROR, "unsupported conversion to planar RGB %s -> %s\n",
     664             :                src_format->name, dst_format->name);
     665           0 :         return srcSliceH;
     666             :     }
     667             : 
     668           0 :     for(i=0; i<4; i++) {
     669           0 :         dst2013[i] += stride2013[i] * srcSliceY / 2;
     670           0 :         dst1023[i] += stride1023[i] * srcSliceY / 2;
     671             :     }
     672             : 
     673           0 :     switch (c->srcFormat) {
     674             :     case AV_PIX_FMT_RGB48LE:
     675             :     case AV_PIX_FMT_RGB48BE:
     676             :     case AV_PIX_FMT_RGBA64LE:
     677             :     case AV_PIX_FMT_RGBA64BE:
     678           0 :         packed16togbra16(src[0], srcStride[0],
     679             :                          dst2013, stride2013, srcSliceH, alpha, swap,
     680             :                          16 - bpc, c->srcW);
     681           0 :         break;
     682             :     case AV_PIX_FMT_BGR48LE:
     683             :     case AV_PIX_FMT_BGR48BE:
     684             :     case AV_PIX_FMT_BGRA64LE:
     685             :     case AV_PIX_FMT_BGRA64BE:
     686           0 :         packed16togbra16(src[0], srcStride[0],
     687             :                          dst1023, stride1023, srcSliceH, alpha, swap,
     688             :                          16 - bpc, c->srcW);
     689           0 :         break;
     690             :     default:
     691           0 :         av_log(c, AV_LOG_ERROR,
     692             :                "unsupported conversion to planar RGB %s -> %s\n",
     693             :                src_format->name, dst_format->name);
     694             :     }
     695             : 
     696           0 :     return srcSliceH;
     697             : }
     698             : 
     699          13 : static void gbr16ptopacked16(const uint16_t *src[], int srcStride[],
     700             :                              uint8_t *dst, int dstStride, int srcSliceH,
     701             :                              int alpha, int swap, int bpp, int width)
     702             : {
     703             :     int x, h, i;
     704          13 :     int src_alpha = src[3] != NULL;
     705          13 :     int scale_high = 16 - bpp, scale_low = (bpp - 8) * 2;
     706        3757 :     for (h = 0; h < srcSliceH; h++) {
     707        3744 :         uint16_t *dest = (uint16_t *)(dst + dstStride * h);
     708             :         uint16_t component;
     709             : 
     710        3744 :         switch(swap) {
     711             :         case 3:
     712           0 :             if (alpha && !src_alpha) {
     713           0 :                 for (x = 0; x < width; x++) {
     714           0 :                     component = av_bswap16(src[0][x]);
     715           0 :                     *dest++ = av_bswap16(component << scale_high | component >> scale_low);
     716           0 :                     component = av_bswap16(src[1][x]);
     717           0 :                     *dest++ = av_bswap16(component << scale_high | component >> scale_low);
     718           0 :                     component = av_bswap16(src[2][x]);
     719           0 :                     *dest++ = av_bswap16(component << scale_high | component >> scale_low);
     720           0 :                     *dest++ = 0xffff;
     721             :                 }
     722           0 :             } else if (alpha && src_alpha) {
     723           0 :                 for (x = 0; x < width; x++) {
     724           0 :                     component = av_bswap16(src[0][x]);
     725           0 :                     *dest++ = av_bswap16(component << scale_high | component >> scale_low);
     726           0 :                     component = av_bswap16(src[1][x]);
     727           0 :                     *dest++ = av_bswap16(component << scale_high | component >> scale_low);
     728           0 :                     component = av_bswap16(src[2][x]);
     729           0 :                     *dest++ = av_bswap16(component << scale_high | component >> scale_low);
     730           0 :                     component = av_bswap16(src[3][x]);
     731           0 :                     *dest++ = av_bswap16(component << scale_high | component >> scale_low);
     732             :                 }
     733             :             } else {
     734           0 :                 for (x = 0; x < width; x++) {
     735           0 :                     component = av_bswap16(src[0][x]);
     736           0 :                     *dest++ = av_bswap16(component << scale_high | component >> scale_low);
     737           0 :                     component = av_bswap16(src[1][x]);
     738           0 :                     *dest++ = av_bswap16(component << scale_high | component >> scale_low);
     739           0 :                     component = av_bswap16(src[2][x]);
     740           0 :                     *dest++ = av_bswap16(component << scale_high | component >> scale_low);
     741             :                 }
     742             :             }
     743           0 :             break;
     744             :         case 2:
     745           0 :             if (alpha && !src_alpha) {
     746           0 :                 for (x = 0; x < width; x++) {
     747           0 :                     *dest++ = av_bswap16(src[0][x] << scale_high | src[0][x] >> scale_low);
     748           0 :                     *dest++ = av_bswap16(src[1][x] << scale_high | src[1][x] >> scale_low);
     749           0 :                     *dest++ = av_bswap16(src[2][x] << scale_high | src[2][x] >> scale_low);
     750           0 :                     *dest++ = 0xffff;
     751             :                 }
     752           0 :             } else if (alpha && src_alpha) {
     753           0 :                 for (x = 0; x < width; x++) {
     754           0 :                     *dest++ = av_bswap16(src[0][x] << scale_high | src[0][x] >> scale_low);
     755           0 :                     *dest++ = av_bswap16(src[1][x] << scale_high | src[1][x] >> scale_low);
     756           0 :                     *dest++ = av_bswap16(src[2][x] << scale_high | src[2][x] >> scale_low);
     757           0 :                     *dest++ = av_bswap16(src[3][x] << scale_high | src[3][x] >> scale_low);
     758             :                 }
     759             :             } else {
     760           0 :                 for (x = 0; x < width; x++) {
     761           0 :                     *dest++ = av_bswap16(src[0][x] << scale_high | src[0][x] >> scale_low);
     762           0 :                     *dest++ = av_bswap16(src[1][x] << scale_high | src[1][x] >> scale_low);
     763           0 :                     *dest++ = av_bswap16(src[2][x] << scale_high | src[2][x] >> scale_low);
     764             :                 }
     765             :             }
     766           0 :             break;
     767             :         case 1:
     768           0 :             if (alpha && !src_alpha) {
     769           0 :                 for (x = 0; x < width; x++) {
     770           0 :                     *dest++ = av_bswap16(src[0][x]) << scale_high | av_bswap16(src[0][x]) >> scale_low;
     771           0 :                     *dest++ = av_bswap16(src[1][x]) << scale_high | av_bswap16(src[1][x]) >> scale_low;
     772           0 :                     *dest++ = av_bswap16(src[2][x]) << scale_high | av_bswap16(src[2][x]) >> scale_low;
     773           0 :                     *dest++ = 0xffff;
     774             :                 }
     775           0 :             } else if (alpha && src_alpha) {
     776           0 :                 for (x = 0; x < width; x++) {
     777           0 :                     *dest++ = av_bswap16(src[0][x]) << scale_high | av_bswap16(src[0][x]) >> scale_low;
     778           0 :                     *dest++ = av_bswap16(src[1][x]) << scale_high | av_bswap16(src[1][x]) >> scale_low;
     779           0 :                     *dest++ = av_bswap16(src[2][x]) << scale_high | av_bswap16(src[2][x]) >> scale_low;
     780           0 :                     *dest++ = av_bswap16(src[3][x]) << scale_high | av_bswap16(src[3][x]) >> scale_low;
     781             :                 }
     782             :             } else {
     783           0 :                 for (x = 0; x < width; x++) {
     784           0 :                     *dest++ = av_bswap16(src[0][x]) << scale_high | av_bswap16(src[0][x]) >> scale_low;
     785           0 :                     *dest++ = av_bswap16(src[1][x]) << scale_high | av_bswap16(src[1][x]) >> scale_low;
     786           0 :                     *dest++ = av_bswap16(src[2][x]) << scale_high | av_bswap16(src[2][x]) >> scale_low;
     787             :                 }
     788             :             }
     789           0 :             break;
     790             :         default:
     791        3744 :             if (alpha && !src_alpha) {
     792           0 :                 for (x = 0; x < width; x++) {
     793           0 :                     *dest++ = src[0][x] << scale_high | src[0][x] >> scale_low;
     794           0 :                     *dest++ = src[1][x] << scale_high | src[1][x] >> scale_low;
     795           0 :                     *dest++ = src[2][x] << scale_high | src[2][x] >> scale_low;
     796           0 :                     *dest++ = 0xffff;
     797             :                 }
     798        3744 :             } else if (alpha && src_alpha) {
     799           0 :                 for (x = 0; x < width; x++) {
     800           0 :                     *dest++ = src[0][x] << scale_high | src[0][x] >> scale_low;
     801           0 :                     *dest++ = src[1][x] << scale_high | src[1][x] >> scale_low;
     802           0 :                     *dest++ = src[2][x] << scale_high | src[2][x] >> scale_low;
     803           0 :                     *dest++ = src[3][x] << scale_high | src[3][x] >> scale_low;
     804             :                 }
     805             :             } else {
     806     1321632 :                 for (x = 0; x < width; x++) {
     807     1317888 :                     *dest++ = src[0][x] << scale_high | src[0][x] >> scale_low;
     808     1317888 :                     *dest++ = src[1][x] << scale_high | src[1][x] >> scale_low;
     809     1317888 :                     *dest++ = src[2][x] << scale_high | src[2][x] >> scale_low;
     810             :                 }
     811             :             }
     812             :         }
     813       14976 :         for (i = 0; i < 3 + src_alpha; i++)
     814       11232 :             src[i] += srcStride[i] >> 1;
     815             :     }
     816          13 : }
     817             : 
     818          13 : static int planarRgb16ToRgb16Wrapper(SwsContext *c, const uint8_t *src[],
     819             :                                      int srcStride[], int srcSliceY, int srcSliceH,
     820             :                                      uint8_t *dst[], int dstStride[])
     821             : {
     822          13 :     const uint16_t *src102[] = { (uint16_t *)src[1], (uint16_t *)src[0], (uint16_t *)src[2], (uint16_t *)src[3] };
     823          13 :     const uint16_t *src201[] = { (uint16_t *)src[2], (uint16_t *)src[0], (uint16_t *)src[1], (uint16_t *)src[3] };
     824          13 :     int stride102[] = { srcStride[1], srcStride[0], srcStride[2], srcStride[3] };
     825          13 :     int stride201[] = { srcStride[2], srcStride[0], srcStride[1], srcStride[3] };
     826          13 :     const AVPixFmtDescriptor *src_format = av_pix_fmt_desc_get(c->srcFormat);
     827          13 :     const AVPixFmtDescriptor *dst_format = av_pix_fmt_desc_get(c->dstFormat);
     828          13 :     int bits_per_sample = src_format->comp[0].depth;
     829          13 :     int swap = 0;
     830          13 :     if ( HAVE_BIGENDIAN && !(src_format->flags & AV_PIX_FMT_FLAG_BE) ||
     831          13 :         !HAVE_BIGENDIAN &&   src_format->flags & AV_PIX_FMT_FLAG_BE)
     832           0 :         swap++;
     833          13 :     if ( HAVE_BIGENDIAN && !(dst_format->flags & AV_PIX_FMT_FLAG_BE) ||
     834          13 :         !HAVE_BIGENDIAN &&   dst_format->flags & AV_PIX_FMT_FLAG_BE)
     835           0 :         swap += 2;
     836             : 
     837          13 :     if ((src_format->flags & (AV_PIX_FMT_FLAG_PLANAR | AV_PIX_FMT_FLAG_RGB)) !=
     838          13 :         (AV_PIX_FMT_FLAG_PLANAR | AV_PIX_FMT_FLAG_RGB) ||
     839             :         bits_per_sample <= 8) {
     840           0 :         av_log(c, AV_LOG_ERROR, "unsupported planar RGB conversion %s -> %s\n",
     841             :                src_format->name, dst_format->name);
     842           0 :         return srcSliceH;
     843             :     }
     844          13 :     switch (c->dstFormat) {
     845             :     case AV_PIX_FMT_BGR48LE:
     846             :     case AV_PIX_FMT_BGR48BE:
     847           0 :         gbr16ptopacked16(src102, stride102,
     848           0 :                          dst[0] + srcSliceY * dstStride[0], dstStride[0],
     849             :                          srcSliceH, 0, swap, bits_per_sample, c->srcW);
     850           0 :         break;
     851             :     case AV_PIX_FMT_RGB48LE:
     852             :     case AV_PIX_FMT_RGB48BE:
     853          26 :         gbr16ptopacked16(src201, stride201,
     854          13 :                          dst[0] + srcSliceY * dstStride[0], dstStride[0],
     855             :                          srcSliceH, 0, swap, bits_per_sample, c->srcW);
     856          13 :         break;
     857             :     case AV_PIX_FMT_RGBA64LE:
     858             :     case AV_PIX_FMT_RGBA64BE:
     859           0 :          gbr16ptopacked16(src201, stride201,
     860           0 :                           dst[0] + srcSliceY * dstStride[0], dstStride[0],
     861             :                           srcSliceH, 1, swap, bits_per_sample, c->srcW);
     862           0 :         break;
     863             :     case AV_PIX_FMT_BGRA64LE:
     864             :     case AV_PIX_FMT_BGRA64BE:
     865           0 :         gbr16ptopacked16(src102, stride102,
     866           0 :                          dst[0] + srcSliceY * dstStride[0], dstStride[0],
     867             :                          srcSliceH, 1, swap, bits_per_sample, c->srcW);
     868           0 :         break;
     869             :     default:
     870           0 :         av_log(c, AV_LOG_ERROR,
     871             :                "unsupported planar RGB conversion %s -> %s\n",
     872             :                src_format->name, dst_format->name);
     873             :     }
     874             : 
     875          13 :     return srcSliceH;
     876             : }
     877             : 
     878           1 : static void gbr24ptopacked24(const uint8_t *src[], int srcStride[],
     879             :                              uint8_t *dst, int dstStride, int srcSliceH,
     880             :                              int width)
     881             : {
     882             :     int x, h, i;
     883         129 :     for (h = 0; h < srcSliceH; h++) {
     884         128 :         uint8_t *dest = dst + dstStride * h;
     885       16512 :         for (x = 0; x < width; x++) {
     886       16384 :             *dest++ = src[0][x];
     887       16384 :             *dest++ = src[1][x];
     888       16384 :             *dest++ = src[2][x];
     889             :         }
     890             : 
     891         512 :         for (i = 0; i < 3; i++)
     892         384 :             src[i] += srcStride[i];
     893             :     }
     894           1 : }
     895             : 
     896           0 : static void gbr24ptopacked32(const uint8_t *src[], int srcStride[],
     897             :                              uint8_t *dst, int dstStride, int srcSliceH,
     898             :                              int alpha_first, int width)
     899             : {
     900             :     int x, h, i;
     901           0 :     for (h = 0; h < srcSliceH; h++) {
     902           0 :         uint8_t *dest = dst + dstStride * h;
     903             : 
     904           0 :         if (alpha_first) {
     905           0 :             for (x = 0; x < width; x++) {
     906           0 :                 *dest++ = 0xff;
     907           0 :                 *dest++ = src[0][x];
     908           0 :                 *dest++ = src[1][x];
     909           0 :                 *dest++ = src[2][x];
     910             :             }
     911             :         } else {
     912           0 :             for (x = 0; x < width; x++) {
     913           0 :                 *dest++ = src[0][x];
     914           0 :                 *dest++ = src[1][x];
     915           0 :                 *dest++ = src[2][x];
     916           0 :                 *dest++ = 0xff;
     917             :             }
     918             :         }
     919             : 
     920           0 :         for (i = 0; i < 3; i++)
     921           0 :             src[i] += srcStride[i];
     922             :     }
     923           0 : }
     924             : 
     925           1 : static int planarRgbToRgbWrapper(SwsContext *c, const uint8_t *src[],
     926             :                                  int srcStride[], int srcSliceY, int srcSliceH,
     927             :                                  uint8_t *dst[], int dstStride[])
     928             : {
     929           1 :     int alpha_first = 0;
     930           1 :     const uint8_t *src102[] = { src[1], src[0], src[2] };
     931           1 :     const uint8_t *src201[] = { src[2], src[0], src[1] };
     932           1 :     int stride102[] = { srcStride[1], srcStride[0], srcStride[2] };
     933           1 :     int stride201[] = { srcStride[2], srcStride[0], srcStride[1] };
     934             : 
     935           1 :     if (c->srcFormat != AV_PIX_FMT_GBRP) {
     936           0 :         av_log(c, AV_LOG_ERROR, "unsupported planar RGB conversion %s -> %s\n",
     937             :                av_get_pix_fmt_name(c->srcFormat),
     938             :                av_get_pix_fmt_name(c->dstFormat));
     939           0 :         return srcSliceH;
     940             :     }
     941             : 
     942           1 :     switch (c->dstFormat) {
     943             :     case AV_PIX_FMT_BGR24:
     944           0 :         gbr24ptopacked24(src102, stride102,
     945           0 :                          dst[0] + srcSliceY * dstStride[0], dstStride[0],
     946             :                          srcSliceH, c->srcW);
     947           0 :         break;
     948             : 
     949             :     case AV_PIX_FMT_RGB24:
     950           2 :         gbr24ptopacked24(src201, stride201,
     951           1 :                          dst[0] + srcSliceY * dstStride[0], dstStride[0],
     952             :                          srcSliceH, c->srcW);
     953           1 :         break;
     954             : 
     955             :     case AV_PIX_FMT_ARGB:
     956           0 :         alpha_first = 1;
     957             :     case AV_PIX_FMT_RGBA:
     958           0 :         gbr24ptopacked32(src201, stride201,
     959           0 :                          dst[0] + srcSliceY * dstStride[0], dstStride[0],
     960             :                          srcSliceH, alpha_first, c->srcW);
     961           0 :         break;
     962             : 
     963             :     case AV_PIX_FMT_ABGR:
     964           0 :         alpha_first = 1;
     965             :     case AV_PIX_FMT_BGRA:
     966           0 :         gbr24ptopacked32(src102, stride102,
     967           0 :                          dst[0] + srcSliceY * dstStride[0], dstStride[0],
     968             :                          srcSliceH, alpha_first, c->srcW);
     969           0 :         break;
     970             : 
     971             :     default:
     972           0 :         av_log(c, AV_LOG_ERROR,
     973             :                "unsupported planar RGB conversion %s -> %s\n",
     974             :                av_get_pix_fmt_name(c->srcFormat),
     975             :                av_get_pix_fmt_name(c->dstFormat));
     976             :     }
     977             : 
     978           1 :     return srcSliceH;
     979             : }
     980             : 
     981           0 : static int planarRgbToplanarRgbWrapper(SwsContext *c,
     982             :                                        const uint8_t *src[], int srcStride[],
     983             :                                        int srcSliceY, int srcSliceH,
     984             :                                        uint8_t *dst[], int dstStride[])
     985             : {
     986           0 :     copyPlane(src[0], srcStride[0], srcSliceY, srcSliceH, c->srcW,
     987             :               dst[0], dstStride[0]);
     988           0 :     copyPlane(src[1], srcStride[1], srcSliceY, srcSliceH, c->srcW,
     989           0 :               dst[1], dstStride[1]);
     990           0 :     copyPlane(src[2], srcStride[2], srcSliceY, srcSliceH, c->srcW,
     991           0 :               dst[2], dstStride[2]);
     992           0 :     if (dst[3])
     993           0 :         fillPlane(dst[3], dstStride[3], c->srcW, srcSliceH, srcSliceY, 255);
     994             : 
     995           0 :     return srcSliceH;
     996             : }
     997             : 
     998           0 : static void packedtogbr24p(const uint8_t *src, int srcStride,
     999             :                            uint8_t *dst[], int dstStride[], int srcSliceH,
    1000             :                            int alpha_first, int inc_size, int width)
    1001             : {
    1002             :     uint8_t *dest[3];
    1003             :     int x, h;
    1004             : 
    1005           0 :     dest[0] = dst[0];
    1006           0 :     dest[1] = dst[1];
    1007           0 :     dest[2] = dst[2];
    1008             : 
    1009           0 :     if (alpha_first)
    1010           0 :         src++;
    1011             : 
    1012           0 :     for (h = 0; h < srcSliceH; h++) {
    1013           0 :         for (x = 0; x < width; x++) {
    1014           0 :             dest[0][x] = src[0];
    1015           0 :             dest[1][x] = src[1];
    1016           0 :             dest[2][x] = src[2];
    1017             : 
    1018           0 :             src += inc_size;
    1019             :         }
    1020           0 :         src     += srcStride - width * inc_size;
    1021           0 :         dest[0] += dstStride[0];
    1022           0 :         dest[1] += dstStride[1];
    1023           0 :         dest[2] += dstStride[2];
    1024             :     }
    1025           0 : }
    1026             : 
    1027           0 : static int rgbToPlanarRgbWrapper(SwsContext *c, const uint8_t *src[],
    1028             :                                  int srcStride[], int srcSliceY, int srcSliceH,
    1029             :                                  uint8_t *dst[], int dstStride[])
    1030             : {
    1031           0 :     int alpha_first = 0;
    1032           0 :     int stride102[] = { dstStride[1], dstStride[0], dstStride[2] };
    1033           0 :     int stride201[] = { dstStride[2], dstStride[0], dstStride[1] };
    1034           0 :     uint8_t *dst102[] = { dst[1] + srcSliceY * dstStride[1],
    1035           0 :                           dst[0] + srcSliceY * dstStride[0],
    1036           0 :                           dst[2] + srcSliceY * dstStride[2] };
    1037           0 :     uint8_t *dst201[] = { dst[2] + srcSliceY * dstStride[2],
    1038           0 :                           dst[0] + srcSliceY * dstStride[0],
    1039           0 :                           dst[1] + srcSliceY * dstStride[1] };
    1040             : 
    1041           0 :     switch (c->srcFormat) {
    1042             :     case AV_PIX_FMT_RGB24:
    1043           0 :         packedtogbr24p((const uint8_t *) src[0], srcStride[0], dst201,
    1044             :                        stride201, srcSliceH, alpha_first, 3, c->srcW);
    1045           0 :         break;
    1046             :     case AV_PIX_FMT_BGR24:
    1047           0 :         packedtogbr24p((const uint8_t *) src[0], srcStride[0], dst102,
    1048             :                        stride102, srcSliceH, alpha_first, 3, c->srcW);
    1049           0 :         break;
    1050             :     case AV_PIX_FMT_ARGB:
    1051           0 :         alpha_first = 1;
    1052             :     case AV_PIX_FMT_RGBA:
    1053           0 :         packedtogbr24p((const uint8_t *) src[0], srcStride[0], dst201,
    1054             :                        stride201, srcSliceH, alpha_first, 4, c->srcW);
    1055           0 :         break;
    1056             :     case AV_PIX_FMT_ABGR:
    1057           0 :         alpha_first = 1;
    1058             :     case AV_PIX_FMT_BGRA:
    1059           0 :         packedtogbr24p((const uint8_t *) src[0], srcStride[0], dst102,
    1060             :                        stride102, srcSliceH, alpha_first, 4, c->srcW);
    1061           0 :         break;
    1062             :     default:
    1063           0 :         av_log(c, AV_LOG_ERROR,
    1064             :                "unsupported planar RGB conversion %s -> %s\n",
    1065             :                av_get_pix_fmt_name(c->srcFormat),
    1066             :                av_get_pix_fmt_name(c->dstFormat));
    1067             :     }
    1068             : 
    1069           0 :     return srcSliceH;
    1070             : }
    1071             : 
    1072             : #define BAYER_GBRG
    1073             : #define BAYER_8
    1074             : #define BAYER_RENAME(x) bayer_gbrg8_to_##x
    1075             : #include "bayer_template.c"
    1076             : 
    1077             : #define BAYER_GBRG
    1078             : #define BAYER_16LE
    1079             : #define BAYER_RENAME(x) bayer_gbrg16le_to_##x
    1080             : #include "bayer_template.c"
    1081             : 
    1082             : #define BAYER_GBRG
    1083             : #define BAYER_16BE
    1084             : #define BAYER_RENAME(x) bayer_gbrg16be_to_##x
    1085             : #include "bayer_template.c"
    1086             : 
    1087             : #define BAYER_GRBG
    1088             : #define BAYER_8
    1089             : #define BAYER_RENAME(x) bayer_grbg8_to_##x
    1090             : #include "bayer_template.c"
    1091             : 
    1092             : #define BAYER_GRBG
    1093             : #define BAYER_16LE
    1094             : #define BAYER_RENAME(x) bayer_grbg16le_to_##x
    1095             : #include "bayer_template.c"
    1096             : 
    1097             : #define BAYER_GRBG
    1098             : #define BAYER_16BE
    1099             : #define BAYER_RENAME(x) bayer_grbg16be_to_##x
    1100             : #include "bayer_template.c"
    1101             : 
    1102             : #define BAYER_BGGR
    1103             : #define BAYER_8
    1104             : #define BAYER_RENAME(x) bayer_bggr8_to_##x
    1105             : #include "bayer_template.c"
    1106             : 
    1107             : #define BAYER_BGGR
    1108             : #define BAYER_16LE
    1109             : #define BAYER_RENAME(x) bayer_bggr16le_to_##x
    1110             : #include "bayer_template.c"
    1111             : 
    1112             : #define BAYER_BGGR
    1113             : #define BAYER_16BE
    1114             : #define BAYER_RENAME(x) bayer_bggr16be_to_##x
    1115             : #include "bayer_template.c"
    1116             : 
    1117             : #define BAYER_RGGB
    1118             : #define BAYER_8
    1119             : #define BAYER_RENAME(x) bayer_rggb8_to_##x
    1120             : #include "bayer_template.c"
    1121             : 
    1122             : #define BAYER_RGGB
    1123             : #define BAYER_16LE
    1124             : #define BAYER_RENAME(x) bayer_rggb16le_to_##x
    1125             : #include "bayer_template.c"
    1126             : 
    1127             : #define BAYER_RGGB
    1128             : #define BAYER_16BE
    1129             : #define BAYER_RENAME(x) bayer_rggb16be_to_##x
    1130             : #include "bayer_template.c"
    1131             : 
    1132           0 : static int bayer_to_rgb24_wrapper(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY,
    1133             :                                   int srcSliceH, uint8_t* dst[], int dstStride[])
    1134             : {
    1135           0 :     uint8_t *dstPtr= dst[0] + srcSliceY * dstStride[0];
    1136           0 :     const uint8_t *srcPtr= src[0];
    1137             :     int i;
    1138             :     void (*copy)       (const uint8_t *src, int src_stride, uint8_t *dst, int dst_stride, int width);
    1139             :     void (*interpolate)(const uint8_t *src, int src_stride, uint8_t *dst, int dst_stride, int width);
    1140             : 
    1141           0 :     switch(c->srcFormat) {
    1142             : #define CASE(pixfmt, prefix) \
    1143             :     case pixfmt: copy        = bayer_##prefix##_to_rgb24_copy; \
    1144             :                  interpolate = bayer_##prefix##_to_rgb24_interpolate; \
    1145             :                  break;
    1146           0 :     CASE(AV_PIX_FMT_BAYER_BGGR8,    bggr8)
    1147           0 :     CASE(AV_PIX_FMT_BAYER_BGGR16LE, bggr16le)
    1148           0 :     CASE(AV_PIX_FMT_BAYER_BGGR16BE, bggr16be)
    1149           0 :     CASE(AV_PIX_FMT_BAYER_RGGB8,    rggb8)
    1150           0 :     CASE(AV_PIX_FMT_BAYER_RGGB16LE, rggb16le)
    1151           0 :     CASE(AV_PIX_FMT_BAYER_RGGB16BE, rggb16be)
    1152           0 :     CASE(AV_PIX_FMT_BAYER_GBRG8,    gbrg8)
    1153           0 :     CASE(AV_PIX_FMT_BAYER_GBRG16LE, gbrg16le)
    1154           0 :     CASE(AV_PIX_FMT_BAYER_GBRG16BE, gbrg16be)
    1155           0 :     CASE(AV_PIX_FMT_BAYER_GRBG8,    grbg8)
    1156           0 :     CASE(AV_PIX_FMT_BAYER_GRBG16LE, grbg16le)
    1157           0 :     CASE(AV_PIX_FMT_BAYER_GRBG16BE, grbg16be)
    1158             : #undef CASE
    1159           0 :     default: return 0;
    1160             :     }
    1161             : 
    1162           0 :     av_assert0(srcSliceH > 1);
    1163             : 
    1164           0 :     copy(srcPtr, srcStride[0], dstPtr, dstStride[0], c->srcW);
    1165           0 :     srcPtr += 2 * srcStride[0];
    1166           0 :     dstPtr += 2 * dstStride[0];
    1167             : 
    1168           0 :     for (i = 2; i < srcSliceH - 2; i += 2) {
    1169           0 :         interpolate(srcPtr, srcStride[0], dstPtr, dstStride[0], c->srcW);
    1170           0 :         srcPtr += 2 * srcStride[0];
    1171           0 :         dstPtr += 2 * dstStride[0];
    1172             :     }
    1173             : 
    1174           0 :     if (i + 1 == srcSliceH) {
    1175           0 :         copy(srcPtr, -srcStride[0], dstPtr, -dstStride[0], c->srcW);
    1176           0 :     } else if (i < srcSliceH)
    1177           0 :         copy(srcPtr, srcStride[0], dstPtr, dstStride[0], c->srcW);
    1178           0 :     return srcSliceH;
    1179             : }
    1180             : 
    1181           0 : static int bayer_to_yv12_wrapper(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY,
    1182             :                                  int srcSliceH, uint8_t* dst[], int dstStride[])
    1183             : {
    1184           0 :     const uint8_t *srcPtr= src[0];
    1185           0 :     uint8_t *dstY= dst[0] + srcSliceY * dstStride[0];
    1186           0 :     uint8_t *dstU= dst[1] + srcSliceY * dstStride[1] / 2;
    1187           0 :     uint8_t *dstV= dst[2] + srcSliceY * dstStride[2] / 2;
    1188             :     int i;
    1189             :     void (*copy)       (const uint8_t *src, int src_stride, uint8_t *dstY, uint8_t *dstU, uint8_t *dstV, int luma_stride, int width, int32_t *rgb2yuv);
    1190             :     void (*interpolate)(const uint8_t *src, int src_stride, uint8_t *dstY, uint8_t *dstU, uint8_t *dstV, int luma_stride, int width, int32_t *rgb2yuv);
    1191             : 
    1192           0 :     switch(c->srcFormat) {
    1193             : #define CASE(pixfmt, prefix) \
    1194             :     case pixfmt: copy        = bayer_##prefix##_to_yv12_copy; \
    1195             :                  interpolate = bayer_##prefix##_to_yv12_interpolate; \
    1196             :                  break;
    1197           0 :     CASE(AV_PIX_FMT_BAYER_BGGR8,    bggr8)
    1198           0 :     CASE(AV_PIX_FMT_BAYER_BGGR16LE, bggr16le)
    1199           0 :     CASE(AV_PIX_FMT_BAYER_BGGR16BE, bggr16be)
    1200           0 :     CASE(AV_PIX_FMT_BAYER_RGGB8,    rggb8)
    1201           0 :     CASE(AV_PIX_FMT_BAYER_RGGB16LE, rggb16le)
    1202           0 :     CASE(AV_PIX_FMT_BAYER_RGGB16BE, rggb16be)
    1203           0 :     CASE(AV_PIX_FMT_BAYER_GBRG8,    gbrg8)
    1204           0 :     CASE(AV_PIX_FMT_BAYER_GBRG16LE, gbrg16le)
    1205           0 :     CASE(AV_PIX_FMT_BAYER_GBRG16BE, gbrg16be)
    1206           0 :     CASE(AV_PIX_FMT_BAYER_GRBG8,    grbg8)
    1207           0 :     CASE(AV_PIX_FMT_BAYER_GRBG16LE, grbg16le)
    1208           0 :     CASE(AV_PIX_FMT_BAYER_GRBG16BE, grbg16be)
    1209             : #undef CASE
    1210           0 :     default: return 0;
    1211             :     }
    1212             : 
    1213           0 :     av_assert0(srcSliceH > 1);
    1214             : 
    1215           0 :     copy(srcPtr, srcStride[0], dstY, dstU, dstV, dstStride[0], c->srcW, c->input_rgb2yuv_table);
    1216           0 :     srcPtr += 2 * srcStride[0];
    1217           0 :     dstY   += 2 * dstStride[0];
    1218           0 :     dstU   +=     dstStride[1];
    1219           0 :     dstV   +=     dstStride[1];
    1220             : 
    1221           0 :     for (i = 2; i < srcSliceH - 2; i += 2) {
    1222           0 :         interpolate(srcPtr, srcStride[0], dstY, dstU, dstV, dstStride[0], c->srcW, c->input_rgb2yuv_table);
    1223           0 :         srcPtr += 2 * srcStride[0];
    1224           0 :         dstY   += 2 * dstStride[0];
    1225           0 :         dstU   +=     dstStride[1];
    1226           0 :         dstV   +=     dstStride[1];
    1227             :     }
    1228             : 
    1229           0 :     if (i + 1 == srcSliceH) {
    1230           0 :         copy(srcPtr, -srcStride[0], dstY, dstU, dstV, -dstStride[0], c->srcW, c->input_rgb2yuv_table);
    1231           0 :     } else if (i < srcSliceH)
    1232           0 :         copy(srcPtr, srcStride[0], dstY, dstU, dstV, dstStride[0], c->srcW, c->input_rgb2yuv_table);
    1233           0 :     return srcSliceH;
    1234             : }
    1235             : 
    1236             : #define isRGBA32(x) (            \
    1237             :            (x) == AV_PIX_FMT_ARGB   \
    1238             :         || (x) == AV_PIX_FMT_RGBA   \
    1239             :         || (x) == AV_PIX_FMT_BGRA   \
    1240             :         || (x) == AV_PIX_FMT_ABGR   \
    1241             :         )
    1242             : 
    1243             : #define isRGBA64(x) (                \
    1244             :            (x) == AV_PIX_FMT_RGBA64LE   \
    1245             :         || (x) == AV_PIX_FMT_RGBA64BE   \
    1246             :         || (x) == AV_PIX_FMT_BGRA64LE   \
    1247             :         || (x) == AV_PIX_FMT_BGRA64BE   \
    1248             :         )
    1249             : 
    1250             : #define isRGB48(x) (                \
    1251             :            (x) == AV_PIX_FMT_RGB48LE   \
    1252             :         || (x) == AV_PIX_FMT_RGB48BE   \
    1253             :         || (x) == AV_PIX_FMT_BGR48LE   \
    1254             :         || (x) == AV_PIX_FMT_BGR48BE   \
    1255             :         )
    1256             : 
    1257             : /* {RGB,BGR}{15,16,24,32,32_1} -> {RGB,BGR}{15,16,24,32} */
    1258             : typedef void (* rgbConvFn) (const uint8_t *, uint8_t *, int);
    1259        2211 : static rgbConvFn findRgbConvFn(SwsContext *c)
    1260             : {
    1261        2211 :     const enum AVPixelFormat srcFormat = c->srcFormat;
    1262        2211 :     const enum AVPixelFormat dstFormat = c->dstFormat;
    1263        2211 :     const int srcId = c->srcFormatBpp;
    1264        2211 :     const int dstId = c->dstFormatBpp;
    1265        2211 :     rgbConvFn conv = NULL;
    1266             : 
    1267             : #define IS_NOT_NE(bpp, desc) \
    1268             :     (((bpp + 7) >> 3) == 2 && \
    1269             :      (!(desc->flags & AV_PIX_FMT_FLAG_BE) != !HAVE_BIGENDIAN))
    1270             : 
    1271             : #define CONV_IS(src, dst) (srcFormat == AV_PIX_FMT_##src && dstFormat == AV_PIX_FMT_##dst)
    1272             : 
    1273        2211 :     if (isRGBA32(srcFormat) && isRGBA32(dstFormat)) {
    1274          42 :         if (     CONV_IS(ABGR, RGBA)
    1275          21 :               || CONV_IS(ARGB, BGRA)
    1276          21 :               || CONV_IS(BGRA, ARGB)
    1277          21 :               || CONV_IS(RGBA, ABGR)) conv = shuffle_bytes_3210;
    1278          21 :         else if (CONV_IS(ABGR, ARGB)
    1279          21 :               || CONV_IS(ARGB, ABGR)) conv = shuffle_bytes_0321;
    1280          21 :         else if (CONV_IS(ABGR, BGRA)
    1281          21 :               || CONV_IS(ARGB, RGBA)) conv = shuffle_bytes_1230;
    1282          21 :         else if (CONV_IS(BGRA, RGBA)
    1283          21 :               || CONV_IS(RGBA, BGRA)) conv = shuffle_bytes_2103;
    1284           3 :         else if (CONV_IS(BGRA, ABGR)
    1285           3 :               || CONV_IS(RGBA, ARGB)) conv = shuffle_bytes_3012;
    1286        2190 :     } else if (isRGB48(srcFormat) && isRGB48(dstFormat)) {
    1287           2 :         if      (CONV_IS(RGB48LE, BGR48LE)
    1288           1 :               || CONV_IS(BGR48LE, RGB48LE)
    1289           1 :               || CONV_IS(RGB48BE, BGR48BE)
    1290           1 :               || CONV_IS(BGR48BE, RGB48BE)) conv = rgb48tobgr48_nobswap;
    1291           1 :         else if (CONV_IS(RGB48LE, BGR48BE)
    1292           1 :               || CONV_IS(BGR48LE, RGB48BE)
    1293           1 :               || CONV_IS(RGB48BE, BGR48LE)
    1294           1 :               || CONV_IS(BGR48BE, RGB48LE)) conv = rgb48tobgr48_bswap;
    1295        2189 :     } else if (isRGBA64(srcFormat) && isRGB48(dstFormat)) {
    1296           0 :         if      (CONV_IS(RGBA64LE, BGR48LE)
    1297           0 :               || CONV_IS(BGRA64LE, RGB48LE)
    1298           0 :               || CONV_IS(RGBA64BE, BGR48BE)
    1299           0 :               || CONV_IS(BGRA64BE, RGB48BE)) conv = rgb64tobgr48_nobswap;
    1300           0 :         else if (CONV_IS(RGBA64LE, BGR48BE)
    1301           0 :               || CONV_IS(BGRA64LE, RGB48BE)
    1302           0 :               || CONV_IS(RGBA64BE, BGR48LE)
    1303           0 :               || CONV_IS(BGRA64BE, RGB48LE)) conv = rgb64tobgr48_bswap;
    1304           0 :         else if (CONV_IS(RGBA64LE, RGB48LE)
    1305           0 :               || CONV_IS(BGRA64LE, BGR48LE)
    1306           0 :               || CONV_IS(RGBA64BE, RGB48BE)
    1307           0 :               || CONV_IS(BGRA64BE, BGR48BE)) conv = rgb64to48_nobswap;
    1308           0 :         else if (CONV_IS(RGBA64LE, RGB48BE)
    1309           0 :               || CONV_IS(BGRA64LE, BGR48BE)
    1310           0 :               || CONV_IS(RGBA64BE, RGB48LE)
    1311           0 :               || CONV_IS(BGRA64BE, BGR48LE)) conv = rgb64to48_bswap;
    1312             :     } else
    1313             :     /* BGR -> BGR */
    1314        2189 :     if ((isBGRinInt(srcFormat) && isBGRinInt(dstFormat)) ||
    1315        2188 :         (isRGBinInt(srcFormat) && isRGBinInt(dstFormat))) {
    1316        1956 :         switch (srcId | (dstId << 16)) {
    1317           0 :         case 0x000F000C: conv = rgb12to15; break;
    1318           0 :         case 0x000F0010: conv = rgb16to15; break;
    1319           0 :         case 0x000F0018: conv = rgb24to15; break;
    1320           0 :         case 0x000F0020: conv = rgb32to15; break;
    1321           0 :         case 0x0010000F: conv = rgb15to16; break;
    1322           0 :         case 0x00100018: conv = rgb24to16; break;
    1323           0 :         case 0x00100020: conv = rgb32to16; break;
    1324        1098 :         case 0x0018000F: conv = rgb15to24; break;
    1325         193 :         case 0x00180010: conv = rgb16to24; break;
    1326         647 :         case 0x00180020: conv = rgb32to24; break;
    1327           0 :         case 0x0020000F: conv = rgb15to32; break;
    1328           0 :         case 0x00200010: conv = rgb16to32; break;
    1329          12 :         case 0x00200018: conv = rgb24to32; break;
    1330             :         }
    1331        1956 :     } else if ((isBGRinInt(srcFormat) && isRGBinInt(dstFormat)) ||
    1332          14 :                (isRGBinInt(srcFormat) && isBGRinInt(dstFormat))) {
    1333         228 :         switch (srcId | (dstId << 16)) {
    1334           0 :         case 0x000C000C: conv = rgb12tobgr12; break;
    1335           0 :         case 0x000F000F: conv = rgb15tobgr15; break;
    1336           0 :         case 0x000F0010: conv = rgb16tobgr15; break;
    1337           0 :         case 0x000F0018: conv = rgb24tobgr15; break;
    1338           0 :         case 0x000F0020: conv = rgb32tobgr15; break;
    1339           0 :         case 0x0010000F: conv = rgb15tobgr16; break;
    1340           0 :         case 0x00100010: conv = rgb16tobgr16; break;
    1341           0 :         case 0x00100018: conv = rgb24tobgr16; break;
    1342           0 :         case 0x00100020: conv = rgb32tobgr16; break;
    1343         177 :         case 0x0018000F: conv = rgb15tobgr24; break;
    1344           0 :         case 0x00180010: conv = rgb16tobgr24; break;
    1345          38 :         case 0x00180018: conv = rgb24tobgr24; break;
    1346           8 :         case 0x00180020: conv = rgb32tobgr24; break;
    1347           0 :         case 0x0020000F: conv = rgb15tobgr32; break;
    1348           0 :         case 0x00200010: conv = rgb16tobgr32; break;
    1349           2 :         case 0x00200018: conv = rgb24tobgr32; break;
    1350             :         }
    1351             :     }
    1352             : 
    1353             :     if ((dstFormat == AV_PIX_FMT_RGB32_1 || dstFormat == AV_PIX_FMT_BGR32_1) && !isRGBA32(srcFormat) && ALT32_CORR<0)
    1354             :         return NULL;
    1355             : 
    1356             :     // Maintain symmetry between endianness
    1357        2211 :     if (c->flags & SWS_BITEXACT)
    1358          10 :         if ((dstFormat == AV_PIX_FMT_RGB32   || dstFormat == AV_PIX_FMT_BGR32  ) && !isRGBA32(srcFormat) && ALT32_CORR>0)
    1359           0 :             return NULL;
    1360             : 
    1361        2211 :     return conv;
    1362             : }
    1363             : 
    1364             : /* {RGB,BGR}{15,16,24,32,32_1} -> {RGB,BGR}{15,16,24,32} */
    1365        2148 : static int rgbToRgbWrapper(SwsContext *c, const uint8_t *src[], int srcStride[],
    1366             :                            int srcSliceY, int srcSliceH, uint8_t *dst[],
    1367             :                            int dstStride[])
    1368             : 
    1369             : {
    1370        2148 :     const enum AVPixelFormat srcFormat = c->srcFormat;
    1371        2148 :     const enum AVPixelFormat dstFormat = c->dstFormat;
    1372        2148 :     const AVPixFmtDescriptor *desc_src = av_pix_fmt_desc_get(c->srcFormat);
    1373        2148 :     const AVPixFmtDescriptor *desc_dst = av_pix_fmt_desc_get(c->dstFormat);
    1374        2148 :     const int srcBpp = (c->srcFormatBpp + 7) >> 3;
    1375        2148 :     const int dstBpp = (c->dstFormatBpp + 7) >> 3;
    1376        2148 :     rgbConvFn conv = findRgbConvFn(c);
    1377             : 
    1378        2148 :     if (!conv) {
    1379           0 :         av_log(c, AV_LOG_ERROR, "internal error %s -> %s converter\n",
    1380             :                av_get_pix_fmt_name(srcFormat), av_get_pix_fmt_name(dstFormat));
    1381             :     } else {
    1382        2148 :         const uint8_t *srcPtr = src[0];
    1383        2148 :               uint8_t *dstPtr = dst[0];
    1384        2148 :         int src_bswap = IS_NOT_NE(c->srcFormatBpp, desc_src);
    1385        2148 :         int dst_bswap = IS_NOT_NE(c->dstFormatBpp, desc_dst);
    1386             : 
    1387        2148 :         if ((srcFormat == AV_PIX_FMT_RGB32_1 || srcFormat == AV_PIX_FMT_BGR32_1) &&
    1388           1 :             !isRGBA32(dstFormat))
    1389           1 :             srcPtr += ALT32_CORR;
    1390             : 
    1391        2148 :         if ((dstFormat == AV_PIX_FMT_RGB32_1 || dstFormat == AV_PIX_FMT_BGR32_1) &&
    1392           1 :             !isRGBA32(srcFormat)) {
    1393             :             int i;
    1394             :             av_assert0(ALT32_CORR == 1);
    1395         257 :             for (i = 0; i < srcSliceH; i++)
    1396         256 :                 dstPtr[dstStride[0] * (srcSliceY + i)] = 255;
    1397           1 :             dstPtr += ALT32_CORR;
    1398             :         }
    1399             : 
    1400        3405 :         if (dstStride[0] * srcBpp == srcStride[0] * dstBpp && srcStride[0] > 0 &&
    1401        2514 :             !(srcStride[0] % srcBpp) && !dst_bswap && !src_bswap)
    1402        1257 :             conv(srcPtr, dstPtr + dstStride[0] * srcSliceY,
    1403        1257 :                  (srcSliceH - 1) * srcStride[0] + c->srcW * srcBpp);
    1404             :         else {
    1405             :             int i, j;
    1406         891 :             dstPtr += dstStride[0] * srcSliceY;
    1407             : 
    1408      312108 :             for (i = 0; i < srcSliceH; i++) {
    1409      311217 :                 if(src_bswap) {
    1410           0 :                     for(j=0; j<c->srcW; j++)
    1411           0 :                         ((uint16_t*)c->formatConvBuffer)[j] = av_bswap16(((uint16_t*)srcPtr)[j]);
    1412           0 :                     conv(c->formatConvBuffer, dstPtr, c->srcW * srcBpp);
    1413             :                 }else
    1414      311217 :                     conv(srcPtr, dstPtr, c->srcW * srcBpp);
    1415      311217 :                 if(dst_bswap)
    1416           0 :                     for(j=0; j<c->srcW; j++)
    1417           0 :                         ((uint16_t*)dstPtr)[j] = av_bswap16(((uint16_t*)dstPtr)[j]);
    1418      311217 :                 srcPtr += srcStride[0];
    1419      311217 :                 dstPtr += dstStride[0];
    1420             :             }
    1421             :         }
    1422             :     }
    1423        2148 :     return srcSliceH;
    1424             : }
    1425             : 
    1426           0 : static int bgr24ToYv12Wrapper(SwsContext *c, const uint8_t *src[],
    1427             :                               int srcStride[], int srcSliceY, int srcSliceH,
    1428             :                               uint8_t *dst[], int dstStride[])
    1429             : {
    1430           0 :     ff_rgb24toyv12(
    1431             :         src[0],
    1432           0 :         dst[0] +  srcSliceY       * dstStride[0],
    1433           0 :         dst[1] + (srcSliceY >> 1) * dstStride[1],
    1434           0 :         dst[2] + (srcSliceY >> 1) * dstStride[2],
    1435             :         c->srcW, srcSliceH,
    1436           0 :         dstStride[0], dstStride[1], srcStride[0],
    1437           0 :         c->input_rgb2yuv_table);
    1438           0 :     if (dst[3])
    1439           0 :         fillPlane(dst[3], dstStride[3], c->srcW, srcSliceH, srcSliceY, 255);
    1440           0 :     return srcSliceH;
    1441             : }
    1442             : 
    1443           0 : static int yvu9ToYv12Wrapper(SwsContext *c, const uint8_t *src[],
    1444             :                              int srcStride[], int srcSliceY, int srcSliceH,
    1445             :                              uint8_t *dst[], int dstStride[])
    1446             : {
    1447           0 :     copyPlane(src[0], srcStride[0], srcSliceY, srcSliceH, c->srcW,
    1448             :               dst[0], dstStride[0]);
    1449             : 
    1450           0 :     planar2x(src[1], dst[1] + dstStride[1] * (srcSliceY >> 1), c->chrSrcW,
    1451           0 :              srcSliceH >> 2, srcStride[1], dstStride[1]);
    1452           0 :     planar2x(src[2], dst[2] + dstStride[2] * (srcSliceY >> 1), c->chrSrcW,
    1453           0 :              srcSliceH >> 2, srcStride[2], dstStride[2]);
    1454           0 :     if (dst[3])
    1455           0 :         fillPlane(dst[3], dstStride[3], c->srcW, srcSliceH, srcSliceY, 255);
    1456           0 :     return srcSliceH;
    1457             : }
    1458             : 
    1459             : /* unscaled copy like stuff (assumes nearly identical formats) */
    1460           3 : static int packedCopyWrapper(SwsContext *c, const uint8_t *src[],
    1461             :                              int srcStride[], int srcSliceY, int srcSliceH,
    1462             :                              uint8_t *dst[], int dstStride[])
    1463             : {
    1464           3 :     if (dstStride[0] == srcStride[0] && srcStride[0] > 0)
    1465           3 :         memcpy(dst[0] + dstStride[0] * srcSliceY, src[0], srcSliceH * dstStride[0]);
    1466             :     else {
    1467             :         int i;
    1468           0 :         const uint8_t *srcPtr = src[0];
    1469           0 :         uint8_t *dstPtr = dst[0] + dstStride[0] * srcSliceY;
    1470           0 :         int length = 0;
    1471             : 
    1472             :         /* universal length finder */
    1473           0 :         while (length + c->srcW <= FFABS(dstStride[0]) &&
    1474           0 :                length + c->srcW <= FFABS(srcStride[0]))
    1475           0 :             length += c->srcW;
    1476             :         av_assert1(length != 0);
    1477             : 
    1478           0 :         for (i = 0; i < srcSliceH; i++) {
    1479           0 :             memcpy(dstPtr, srcPtr, length);
    1480           0 :             srcPtr += srcStride[0];
    1481           0 :             dstPtr += dstStride[0];
    1482             :         }
    1483             :     }
    1484           3 :     return srcSliceH;
    1485             : }
    1486             : 
    1487             : #define DITHER_COPY(dst, dstStride, src, srcStride, bswap, dbswap)\
    1488             :     uint16_t scale= dither_scale[dst_depth-1][src_depth-1];\
    1489             :     int shift= src_depth-dst_depth + dither_scale[src_depth-2][dst_depth-1];\
    1490             :     for (i = 0; i < height; i++) {\
    1491             :         const uint8_t *dither= dithers[src_depth-9][i&7];\
    1492             :         for (j = 0; j < length-7; j+=8){\
    1493             :             dst[j+0] = dbswap((bswap(src[j+0]) + dither[0])*scale>>shift);\
    1494             :             dst[j+1] = dbswap((bswap(src[j+1]) + dither[1])*scale>>shift);\
    1495             :             dst[j+2] = dbswap((bswap(src[j+2]) + dither[2])*scale>>shift);\
    1496             :             dst[j+3] = dbswap((bswap(src[j+3]) + dither[3])*scale>>shift);\
    1497             :             dst[j+4] = dbswap((bswap(src[j+4]) + dither[4])*scale>>shift);\
    1498             :             dst[j+5] = dbswap((bswap(src[j+5]) + dither[5])*scale>>shift);\
    1499             :             dst[j+6] = dbswap((bswap(src[j+6]) + dither[6])*scale>>shift);\
    1500             :             dst[j+7] = dbswap((bswap(src[j+7]) + dither[7])*scale>>shift);\
    1501             :         }\
    1502             :         for (; j < length; j++)\
    1503             :             dst[j] = dbswap((bswap(src[j]) + dither[j&7])*scale>>shift);\
    1504             :         dst += dstStride;\
    1505             :         src += srcStride;\
    1506             :     }
    1507             : 
    1508         911 : static int planarCopyWrapper(SwsContext *c, const uint8_t *src[],
    1509             :                              int srcStride[], int srcSliceY, int srcSliceH,
    1510             :                              uint8_t *dst[], int dstStride[])
    1511             : {
    1512         911 :     const AVPixFmtDescriptor *desc_src = av_pix_fmt_desc_get(c->srcFormat);
    1513         911 :     const AVPixFmtDescriptor *desc_dst = av_pix_fmt_desc_get(c->dstFormat);
    1514             :     int plane, i, j;
    1515        4555 :     for (plane = 0; plane < 4; plane++) {
    1516        3644 :         int length = (plane == 0 || plane == 3) ? c->srcW  : AV_CEIL_RSHIFT(c->srcW,   c->chrDstHSubSample);
    1517        3644 :         int y =      (plane == 0 || plane == 3) ? srcSliceY: AV_CEIL_RSHIFT(srcSliceY, c->chrDstVSubSample);
    1518        3644 :         int height = (plane == 0 || plane == 3) ? srcSliceH: AV_CEIL_RSHIFT(srcSliceH, c->chrDstVSubSample);
    1519        3644 :         const uint8_t *srcPtr = src[plane];
    1520        3644 :         uint8_t *dstPtr = dst[plane] + dstStride[plane] * y;
    1521        3644 :         int shiftonly = plane == 1 || plane == 2 || (!c->srcRange && plane == 0);
    1522             : 
    1523        3644 :         if (!dst[plane])
    1524         891 :             continue;
    1525             :         // ignore palette for GRAY8
    1526        2753 :         if (plane == 1 && !dst[2]) continue;
    1527        2753 :         if (!src[plane] || (plane == 1 && !src[2])) {
    1528         324 :             if (is16BPS(c->dstFormat) || isNBPS(c->dstFormat)) {
    1529          91 :                 fillPlane16(dst[plane], dstStride[plane], length, height, y,
    1530             :                         plane == 3, desc_dst->comp[plane].depth,
    1531             :                         isBE(c->dstFormat));
    1532             :             } else {
    1533          71 :                 fillPlane(dst[plane], dstStride[plane], length, height, y,
    1534             :                         (plane == 3) ? 255 : 128);
    1535             :             }
    1536             :         } else {
    1537        2591 :             if(isNBPS(c->srcFormat) || isNBPS(c->dstFormat)
    1538         508 :                || (is16BPS(c->srcFormat) != is16BPS(c->dstFormat))
    1539        2359 :             ) {
    1540        2359 :                 const int src_depth = desc_src->comp[plane].depth;
    1541        2359 :                 const int dst_depth = desc_dst->comp[plane].depth;
    1542        2359 :                 const uint16_t *srcPtr2 = (const uint16_t *) srcPtr;
    1543        2359 :                 uint16_t *dstPtr2 = (uint16_t*)dstPtr;
    1544             : 
    1545        2359 :                 if (dst_depth == 8) {
    1546         690 :                     if(isBE(c->srcFormat) == HAVE_BIGENDIAN){
    1547         690 :                         DITHER_COPY(dstPtr, dstStride[plane], srcPtr2, srcStride[plane]/2, , )
    1548             :                     } else {
    1549           0 :                         DITHER_COPY(dstPtr, dstStride[plane], srcPtr2, srcStride[plane]/2, av_bswap16, )
    1550             :                     }
    1551        1669 :                 } else if (src_depth == 8) {
    1552      338930 :                     for (i = 0; i < height; i++) {
    1553             :                         #define COPY816(w)\
    1554             :                         if (shiftonly) {\
    1555             :                             for (j = 0; j < length; j++)\
    1556             :                                 w(&dstPtr2[j], srcPtr[j]<<(dst_depth-8));\
    1557             :                         } else {\
    1558             :                             for (j = 0; j < length; j++)\
    1559             :                                 w(&dstPtr2[j], (srcPtr[j]<<(dst_depth-8)) |\
    1560             :                                                (srcPtr[j]>>(2*8-dst_depth)));\
    1561             :                         }
    1562      337264 :                         if(isBE(c->dstFormat)){
    1563       72576 :                             COPY816(AV_WB16)
    1564             :                         } else {
    1565      264688 :                             COPY816(AV_WL16)
    1566             :                         }
    1567      337264 :                         dstPtr2 += dstStride[plane]/2;
    1568      337264 :                         srcPtr  += srcStride[plane];
    1569             :                     }
    1570           3 :                 } else if (src_depth <= dst_depth) {
    1571        2163 :                     for (i = 0; i < height; i++) {
    1572        2160 :                         j = 0;
    1573        4320 :                         if(isBE(c->srcFormat) == HAVE_BIGENDIAN &&
    1574        2160 :                            isBE(c->dstFormat) == HAVE_BIGENDIAN &&
    1575             :                            shiftonly) {
    1576           0 :                              unsigned shift = dst_depth - src_depth;
    1577             : #if HAVE_FAST_64BIT
    1578             : #define FAST_COPY_UP(shift) \
    1579             :     for (; j < length - 3; j += 4) { \
    1580             :         uint64_t v = AV_RN64A(srcPtr2 + j); \
    1581             :         AV_WN64A(dstPtr2 + j, v << shift); \
    1582             :     }
    1583             : #else
    1584             : #define FAST_COPY_UP(shift) \
    1585             :     for (; j < length - 1; j += 2) { \
    1586             :         uint32_t v = AV_RN32A(srcPtr2 + j); \
    1587             :         AV_WN32A(dstPtr2 + j, v << shift); \
    1588             :     }
    1589             : #endif
    1590           0 :                              switch (shift)
    1591             :                              {
    1592           0 :                              case 6: FAST_COPY_UP(6); break;
    1593           0 :                              case 7: FAST_COPY_UP(7); break;
    1594             :                              }
    1595             :                         }
    1596             : #define COPY_UP(r,w) \
    1597             :     if(shiftonly){\
    1598             :         for (; j < length; j++){ \
    1599             :             unsigned int v= r(&srcPtr2[j]);\
    1600             :             w(&dstPtr2[j], v<<(dst_depth-src_depth));\
    1601             :         }\
    1602             :     }else{\
    1603             :         for (; j < length; j++){ \
    1604             :             unsigned int v= r(&srcPtr2[j]);\
    1605             :             w(&dstPtr2[j], (v<<(dst_depth-src_depth)) | \
    1606             :                         (v>>(2*src_depth-dst_depth)));\
    1607             :         }\
    1608             :     }
    1609        2160 :                         if(isBE(c->srcFormat)){
    1610           0 :                             if(isBE(c->dstFormat)){
    1611           0 :                                 COPY_UP(AV_RB16, AV_WB16)
    1612             :                             } else {
    1613           0 :                                 COPY_UP(AV_RB16, AV_WL16)
    1614             :                             }
    1615             :                         } else {
    1616        2160 :                             if(isBE(c->dstFormat)){
    1617        2160 :                                 COPY_UP(AV_RL16, AV_WB16)
    1618             :                             } else {
    1619           0 :                                 COPY_UP(AV_RL16, AV_WL16)
    1620             :                             }
    1621             :                         }
    1622        2160 :                         dstPtr2 += dstStride[plane]/2;
    1623        2160 :                         srcPtr2 += srcStride[plane]/2;
    1624             :                     }
    1625             :                 } else {
    1626           0 :                     if(isBE(c->srcFormat) == HAVE_BIGENDIAN){
    1627           0 :                         if(isBE(c->dstFormat) == HAVE_BIGENDIAN){
    1628           0 :                             DITHER_COPY(dstPtr2, dstStride[plane]/2, srcPtr2, srcStride[plane]/2, , )
    1629             :                         } else {
    1630           0 :                             DITHER_COPY(dstPtr2, dstStride[plane]/2, srcPtr2, srcStride[plane]/2, , av_bswap16)
    1631             :                         }
    1632             :                     }else{
    1633           0 :                         if(isBE(c->dstFormat) == HAVE_BIGENDIAN){
    1634           0 :                             DITHER_COPY(dstPtr2, dstStride[plane]/2, srcPtr2, srcStride[plane]/2, av_bswap16, )
    1635             :                         } else {
    1636           0 :                             DITHER_COPY(dstPtr2, dstStride[plane]/2, srcPtr2, srcStride[plane]/2, av_bswap16, av_bswap16)
    1637             :                         }
    1638             :                     }
    1639             :                 }
    1640         270 :             } else if (is16BPS(c->srcFormat) && is16BPS(c->dstFormat) &&
    1641          19 :                       isBE(c->srcFormat) != isBE(c->dstFormat)) {
    1642             : 
    1643        8731 :                 for (i = 0; i < height; i++) {
    1644     6303240 :                     for (j = 0; j < length; j++)
    1645     6294528 :                         ((uint16_t *) dstPtr)[j] = av_bswap16(((const uint16_t *) srcPtr)[j]);
    1646        8712 :                     srcPtr += srcStride[plane];
    1647        8712 :                     dstPtr += dstStride[plane];
    1648             :                 }
    1649         351 :             } else if (dstStride[plane] == srcStride[plane] &&
    1650         276 :                        srcStride[plane] > 0 && srcStride[plane] == length) {
    1651           0 :                 memcpy(dst[plane] + dstStride[plane] * y, src[plane],
    1652           0 :                        height * dstStride[plane]);
    1653             :             } else {
    1654         213 :                 if (is16BPS(c->srcFormat) && is16BPS(c->dstFormat))
    1655           0 :                     length *= 2;
    1656         213 :                 else if (desc_src->comp[0].depth == 1)
    1657           0 :                     length >>= 3; // monowhite/black
    1658       41109 :                 for (i = 0; i < height; i++) {
    1659       40896 :                     memcpy(dstPtr, srcPtr, length);
    1660       40896 :                     srcPtr += srcStride[plane];
    1661       40896 :                     dstPtr += dstStride[plane];
    1662             :                 }
    1663             :             }
    1664             :         }
    1665             :     }
    1666         911 :     return srcSliceH;
    1667             : }
    1668             : 
    1669             : 
    1670             : #define IS_DIFFERENT_ENDIANESS(src_fmt, dst_fmt, pix_fmt)          \
    1671             :     ((src_fmt == pix_fmt ## BE && dst_fmt == pix_fmt ## LE) ||     \
    1672             :      (src_fmt == pix_fmt ## LE && dst_fmt == pix_fmt ## BE))
    1673             : 
    1674             : 
    1675        2118 : void ff_get_unscaled_swscale(SwsContext *c)
    1676             : {
    1677        2118 :     const enum AVPixelFormat srcFormat = c->srcFormat;
    1678        2118 :     const enum AVPixelFormat dstFormat = c->dstFormat;
    1679        2118 :     const int flags = c->flags;
    1680        2118 :     const int dstH = c->dstH;
    1681             :     int needsDither;
    1682             : 
    1683        5173 :     needsDither = isAnyRGB(dstFormat) &&
    1684        3507 :             c->dstFormatBpp < 24 &&
    1685         373 :            (c->dstFormatBpp < c->srcFormatBpp || (!isAnyRGB(srcFormat)));
    1686             : 
    1687             :     /* yv12_to_nv12 */
    1688        2118 :     if ((srcFormat == AV_PIX_FMT_YUV420P || srcFormat == AV_PIX_FMT_YUVA420P) &&
    1689        1744 :         (dstFormat == AV_PIX_FMT_NV12 || dstFormat == AV_PIX_FMT_NV21)) {
    1690          22 :         c->swscale = planarToNv12Wrapper;
    1691             :     }
    1692             :     /* nv12_to_yv12 */
    1693        2118 :     if (dstFormat == AV_PIX_FMT_YUV420P &&
    1694         184 :         (srcFormat == AV_PIX_FMT_NV12 || srcFormat == AV_PIX_FMT_NV21)) {
    1695           2 :         c->swscale = nv12ToPlanarWrapper;
    1696             :     }
    1697             :     /* yuv2bgr */
    1698        2118 :     if ((srcFormat == AV_PIX_FMT_YUV420P || srcFormat == AV_PIX_FMT_YUV422P ||
    1699        2550 :          srcFormat == AV_PIX_FMT_YUVA420P) && isAnyRGB(dstFormat) &&
    1700         782 :         !(flags & SWS_ACCURATE_RND) && (c->dither == SWS_DITHER_BAYER || c->dither == SWS_DITHER_AUTO) && !(dstH & 1)) {
    1701           0 :         c->swscale = ff_yuv2rgb_get_func_ptr(c);
    1702             :     }
    1703             :     /* yuv420p10_to_p010 */
    1704        2118 :     if ((srcFormat == AV_PIX_FMT_YUV420P10 || srcFormat == AV_PIX_FMT_YUVA420P10) &&
    1705             :         dstFormat == AV_PIX_FMT_P010) {
    1706           0 :         c->swscale = planarToP010Wrapper;
    1707             :     }
    1708             :     /* yuv420p_to_p010le */
    1709        2118 :     if ((srcFormat == AV_PIX_FMT_YUV420P || srcFormat == AV_PIX_FMT_YUVA420P) &&
    1710             :         dstFormat == AV_PIX_FMT_P010LE) {
    1711           9 :         c->swscale = planar8ToP01xleWrapper;
    1712             :     }
    1713             : 
    1714        2118 :     if (srcFormat == AV_PIX_FMT_YUV410P && !(dstH & 3) &&
    1715           4 :         (dstFormat == AV_PIX_FMT_YUV420P || dstFormat == AV_PIX_FMT_YUVA420P) &&
    1716           3 :         !(flags & SWS_BITEXACT)) {
    1717           0 :         c->swscale = yvu9ToYv12Wrapper;
    1718             :     }
    1719             : 
    1720             :     /* bgr24toYV12 */
    1721        2118 :     if (srcFormat == AV_PIX_FMT_BGR24 &&
    1722          24 :         (dstFormat == AV_PIX_FMT_YUV420P || dstFormat == AV_PIX_FMT_YUVA420P) &&
    1723          20 :         !(flags & SWS_ACCURATE_RND))
    1724           0 :         c->swscale = bgr24ToYv12Wrapper;
    1725             : 
    1726             :     /* RGB/BGR -> RGB/BGR (no dither needed forms) */
    1727        2118 :     if (isAnyRGB(srcFormat) && isAnyRGB(dstFormat) && findRgbConvFn(c)
    1728          45 :         && (!needsDither || (c->flags&(SWS_FAST_BILINEAR|SWS_POINT))))
    1729          45 :         c->swscale = rgbToRgbWrapper;
    1730             : 
    1731             :     /* RGB to planar RGB */
    1732        2118 :     if ((srcFormat == AV_PIX_FMT_GBRP && dstFormat == AV_PIX_FMT_GBRAP) ||
    1733           1 :         (srcFormat == AV_PIX_FMT_GBRAP && dstFormat == AV_PIX_FMT_GBRP))
    1734           0 :         c->swscale = planarRgbToplanarRgbWrapper;
    1735             : 
    1736             : #define isByteRGB(f) (             \
    1737             :         f == AV_PIX_FMT_RGB32   || \
    1738             :         f == AV_PIX_FMT_RGB32_1 || \
    1739             :         f == AV_PIX_FMT_RGB24   || \
    1740             :         f == AV_PIX_FMT_BGR32   || \
    1741             :         f == AV_PIX_FMT_BGR32_1 || \
    1742             :         f == AV_PIX_FMT_BGR24)
    1743             : 
    1744        2118 :     if (srcFormat == AV_PIX_FMT_GBRP && isPlanar(srcFormat) && isByteRGB(dstFormat))
    1745           1 :         c->swscale = planarRgbToRgbWrapper;
    1746             : 
    1747        2118 :     if ((srcFormat == AV_PIX_FMT_RGB48LE  || srcFormat == AV_PIX_FMT_RGB48BE  ||
    1748        2110 :          srcFormat == AV_PIX_FMT_BGR48LE  || srcFormat == AV_PIX_FMT_BGR48BE  ||
    1749        2110 :          srcFormat == AV_PIX_FMT_RGBA64LE || srcFormat == AV_PIX_FMT_RGBA64BE ||
    1750        2109 :          srcFormat == AV_PIX_FMT_BGRA64LE || srcFormat == AV_PIX_FMT_BGRA64BE) &&
    1751           9 :         (dstFormat == AV_PIX_FMT_GBRP9LE  || dstFormat == AV_PIX_FMT_GBRP9BE  ||
    1752           9 :          dstFormat == AV_PIX_FMT_GBRP10LE || dstFormat == AV_PIX_FMT_GBRP10BE ||
    1753           9 :          dstFormat == AV_PIX_FMT_GBRP12LE || dstFormat == AV_PIX_FMT_GBRP12BE ||
    1754           9 :          dstFormat == AV_PIX_FMT_GBRP14LE || dstFormat == AV_PIX_FMT_GBRP14BE ||
    1755           9 :          dstFormat == AV_PIX_FMT_GBRP16LE || dstFormat == AV_PIX_FMT_GBRP16BE ||
    1756           9 :          dstFormat == AV_PIX_FMT_GBRAP12LE || dstFormat == AV_PIX_FMT_GBRAP12BE ||
    1757           9 :          dstFormat == AV_PIX_FMT_GBRAP16LE || dstFormat == AV_PIX_FMT_GBRAP16BE ))
    1758           0 :         c->swscale = Rgb16ToPlanarRgb16Wrapper;
    1759             : 
    1760        2118 :     if ((srcFormat == AV_PIX_FMT_GBRP9LE  || srcFormat == AV_PIX_FMT_GBRP9BE  ||
    1761        2114 :          srcFormat == AV_PIX_FMT_GBRP16LE || srcFormat == AV_PIX_FMT_GBRP16BE ||
    1762        2112 :          srcFormat == AV_PIX_FMT_GBRP10LE || srcFormat == AV_PIX_FMT_GBRP10BE ||
    1763        2112 :          srcFormat == AV_PIX_FMT_GBRP12LE || srcFormat == AV_PIX_FMT_GBRP12BE ||
    1764        2112 :          srcFormat == AV_PIX_FMT_GBRP14LE || srcFormat == AV_PIX_FMT_GBRP14BE ||
    1765        2112 :          srcFormat == AV_PIX_FMT_GBRAP12LE || srcFormat == AV_PIX_FMT_GBRAP12BE ||
    1766        2112 :          srcFormat == AV_PIX_FMT_GBRAP16LE || srcFormat == AV_PIX_FMT_GBRAP16BE) &&
    1767           6 :         (dstFormat == AV_PIX_FMT_RGB48LE  || dstFormat == AV_PIX_FMT_RGB48BE  ||
    1768           6 :          dstFormat == AV_PIX_FMT_BGR48LE  || dstFormat == AV_PIX_FMT_BGR48BE  ||
    1769           6 :          dstFormat == AV_PIX_FMT_RGBA64LE || dstFormat == AV_PIX_FMT_RGBA64BE ||
    1770           6 :          dstFormat == AV_PIX_FMT_BGRA64LE || dstFormat == AV_PIX_FMT_BGRA64BE))
    1771           1 :         c->swscale = planarRgb16ToRgb16Wrapper;
    1772             : 
    1773        4121 :     if (av_pix_fmt_desc_get(srcFormat)->comp[0].depth == 8 &&
    1774        2108 :         isPackedRGB(srcFormat) && dstFormat == AV_PIX_FMT_GBRP)
    1775           0 :         c->swscale = rgbToPlanarRgbWrapper;
    1776             : 
    1777        2118 :     if (isBayer(srcFormat)) {
    1778           0 :         if (dstFormat == AV_PIX_FMT_RGB24)
    1779           0 :             c->swscale = bayer_to_rgb24_wrapper;
    1780           0 :         else if (dstFormat == AV_PIX_FMT_YUV420P)
    1781           0 :             c->swscale = bayer_to_yv12_wrapper;
    1782           0 :         else if (!isBayer(dstFormat)) {
    1783           0 :             av_log(c, AV_LOG_ERROR, "unsupported bayer conversion\n");
    1784           0 :             av_assert0(0);
    1785             :         }
    1786             :     }
    1787             : 
    1788             :     /* bswap 16 bits per pixel/component packed formats */
    1789        2118 :     if (IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BAYER_BGGR16) ||
    1790           0 :         IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BAYER_RGGB16) ||
    1791           0 :         IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BAYER_GBRG16) ||
    1792           0 :         IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BAYER_GRBG16) ||
    1793           0 :         IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BGR444) ||
    1794           0 :         IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BGR48)  ||
    1795           0 :         IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BGRA64) ||
    1796           0 :         IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BGR555) ||
    1797           0 :         IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BGR565) ||
    1798           0 :         IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BGRA64) ||
    1799           0 :         IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GRAY10) ||
    1800           0 :         IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GRAY12) ||
    1801           2 :         IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GRAY16) ||
    1802           2 :         IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YA16)   ||
    1803           0 :         IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_AYUV64) ||
    1804           0 :         IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GBRP9)  ||
    1805           0 :         IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GBRP10) ||
    1806           0 :         IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GBRP12) ||
    1807           0 :         IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GBRP14) ||
    1808           1 :         IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GBRP16) ||
    1809           0 :         IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GBRAP12) ||
    1810           1 :         IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GBRAP16) ||
    1811           0 :         IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_RGB444) ||
    1812           1 :         IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_RGB48)  ||
    1813           1 :         IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_RGBA64) ||
    1814           0 :         IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_RGB555) ||
    1815           0 :         IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_RGB565) ||
    1816           1 :         IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_RGBA64) ||
    1817           0 :         IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_XYZ12)  ||
    1818           0 :         IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV420P9)  ||
    1819           0 :         IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV420P10) ||
    1820           0 :         IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV420P12) ||
    1821           0 :         IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV420P14) ||
    1822           0 :         IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV420P16) ||
    1823           0 :         IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV422P9)  ||
    1824           0 :         IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV422P10) ||
    1825           0 :         IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV422P12) ||
    1826           0 :         IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV422P14) ||
    1827           0 :         IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV422P16) ||
    1828           0 :         IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV440P10) ||
    1829           0 :         IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV440P12) ||
    1830           0 :         IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV444P9)  ||
    1831           0 :         IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV444P10) ||
    1832           0 :         IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV444P12) ||
    1833           0 :         IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV444P14) ||
    1834           0 :         IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV444P16))
    1835           3 :         c->swscale = packed_16bpc_bswap;
    1836             : 
    1837        2118 :     if (usePal(srcFormat) && isByteRGB(dstFormat))
    1838          81 :         c->swscale = palToRgbWrapper;
    1839             : 
    1840        2118 :     if (srcFormat == AV_PIX_FMT_YUV422P) {
    1841          13 :         if (dstFormat == AV_PIX_FMT_YUYV422)
    1842           0 :             c->swscale = yuv422pToYuy2Wrapper;
    1843          13 :         else if (dstFormat == AV_PIX_FMT_UYVY422)
    1844           0 :             c->swscale = yuv422pToUyvyWrapper;
    1845             :     }
    1846             : 
    1847             :     /* LQ converters if -sws 0 or -sws 4*/
    1848        2118 :     if (c->flags&(SWS_FAST_BILINEAR|SWS_POINT)) {
    1849             :         /* yv12_to_yuy2 */
    1850          76 :         if (srcFormat == AV_PIX_FMT_YUV420P || srcFormat == AV_PIX_FMT_YUVA420P) {
    1851          44 :             if (dstFormat == AV_PIX_FMT_YUYV422)
    1852           0 :                 c->swscale = planarToYuy2Wrapper;
    1853          44 :             else if (dstFormat == AV_PIX_FMT_UYVY422)
    1854           0 :                 c->swscale = planarToUyvyWrapper;
    1855             :         }
    1856             :     }
    1857        2118 :     if (srcFormat == AV_PIX_FMT_YUYV422 &&
    1858           1 :        (dstFormat == AV_PIX_FMT_YUV420P || dstFormat == AV_PIX_FMT_YUVA420P))
    1859           0 :         c->swscale = yuyvToYuv420Wrapper;
    1860        2118 :     if (srcFormat == AV_PIX_FMT_UYVY422 &&
    1861           0 :        (dstFormat == AV_PIX_FMT_YUV420P || dstFormat == AV_PIX_FMT_YUVA420P))
    1862           0 :         c->swscale = uyvyToYuv420Wrapper;
    1863        2118 :     if (srcFormat == AV_PIX_FMT_YUYV422 && dstFormat == AV_PIX_FMT_YUV422P)
    1864           0 :         c->swscale = yuyvToYuv422Wrapper;
    1865        2118 :     if (srcFormat == AV_PIX_FMT_UYVY422 && dstFormat == AV_PIX_FMT_YUV422P)
    1866           0 :         c->swscale = uyvyToYuv422Wrapper;
    1867             : 
    1868             : #define isPlanarGray(x) (isGray(x) && (x) != AV_PIX_FMT_YA8 && (x) != AV_PIX_FMT_YA16LE && (x) != AV_PIX_FMT_YA16BE)
    1869             :     /* simple copy */
    1870        2118 :     if ( srcFormat == dstFormat ||
    1871           0 :         (srcFormat == AV_PIX_FMT_YUVA420P && dstFormat == AV_PIX_FMT_YUV420P) ||
    1872        3854 :         (srcFormat == AV_PIX_FMT_YUV420P && dstFormat == AV_PIX_FMT_YUVA420P) ||
    1873        6005 :         (isPlanarYUV(srcFormat) && isPlanarGray(dstFormat)) ||
    1874        3142 :         (isPlanarYUV(dstFormat) && isPlanarGray(srcFormat)) ||
    1875        4113 :         (isPlanarGray(dstFormat) && isPlanarGray(srcFormat)) ||
    1876        4846 :         (isPlanarYUV(srcFormat) && isPlanarYUV(dstFormat) &&
    1877        1542 :          c->chrDstHSubSample == c->chrSrcHSubSample &&
    1878         808 :          c->chrDstVSubSample == c->chrSrcVSubSample &&
    1879         238 :          dstFormat != AV_PIX_FMT_NV12 && dstFormat != AV_PIX_FMT_NV21 &&
    1880         218 :          dstFormat != AV_PIX_FMT_P010LE && dstFormat != AV_PIX_FMT_P010BE &&
    1881         208 :          srcFormat != AV_PIX_FMT_NV12 && srcFormat != AV_PIX_FMT_NV21 &&
    1882         207 :          srcFormat != AV_PIX_FMT_P010LE && srcFormat != AV_PIX_FMT_P010BE))
    1883             :     {
    1884         269 :         if (isPacked(c->srcFormat))
    1885           3 :             c->swscale = packedCopyWrapper;
    1886             :         else /* Planar YUV or gray */
    1887         266 :             c->swscale = planarCopyWrapper;
    1888             :     }
    1889             : 
    1890             :     if (ARCH_PPC)
    1891             :         ff_get_unscaled_swscale_ppc(c);
    1892             :      if (ARCH_ARM)
    1893             :          ff_get_unscaled_swscale_arm(c);
    1894             :     if (ARCH_AARCH64)
    1895             :         ff_get_unscaled_swscale_aarch64(c);
    1896        2118 : }
    1897             : 
    1898             : /* Convert the palette to the same packed 32-bit format as the palette */
    1899       84796 : void sws_convertPalette8ToPacked32(const uint8_t *src, uint8_t *dst,
    1900             :                                    int num_pixels, const uint8_t *palette)
    1901             : {
    1902             :     int i;
    1903             : 
    1904    26209244 :     for (i = 0; i < num_pixels; i++)
    1905    26124448 :         ((uint32_t *) dst)[i] = ((const uint32_t *) palette)[src[i]];
    1906       84796 : }
    1907             : 
    1908             : /* Palette format: ABCD -> dst format: ABC */
    1909      711694 : void sws_convertPalette8ToPacked24(const uint8_t *src, uint8_t *dst,
    1910             :                                    int num_pixels, const uint8_t *palette)
    1911             : {
    1912             :     int i;
    1913             : 
    1914   272370522 :     for (i = 0; i < num_pixels; i++) {
    1915             :         //FIXME slow?
    1916   271658828 :         dst[0] = palette[src[i] * 4 + 0];
    1917   271658828 :         dst[1] = palette[src[i] * 4 + 1];
    1918   271658828 :         dst[2] = palette[src[i] * 4 + 2];
    1919   271658828 :         dst += 3;
    1920             :     }
    1921      711694 : }

Generated by: LCOV version 1.12