LCOV - code coverage report
Current view: top level - libswscale - swscale_unscaled.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 498 1078 46.2 %
Date: 2018-05-20 11:54:08 Functions: 23 40 57.5 %

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

Generated by: LCOV version 1.13