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

Generated by: LCOV version 1.13