Coverage Report

Created: 2026-10-28 07:09

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ffmpeg/libswscale/output.c
Line
Count
Source
1
/*
2
 * Copyright (C) 2001-2012 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 <math.h>
22
#include <stddef.h>
23
#include <stdint.h>
24
#include <string.h>
25
26
#include "libavutil/attributes.h"
27
#include "libavutil/avutil.h"
28
#include "libavutil/avassert.h"
29
#include "libavutil/bswap.h"
30
#include "libavutil/intfloat.h"
31
#include "libavutil/intreadwrite.h"
32
#include "libavutil/mathematics.h"
33
#include "libavutil/mem_internal.h"
34
#include "libavutil/pixdesc.h"
35
#include "config.h"
36
#include "rgb2rgb.h"
37
#include "swscale.h"
38
#include "swscale_internal.h"
39
40
DECLARE_ALIGNED(8, const uint8_t, ff_dither_2x2_4)[][8] = {
41
{  1,   3,   1,   3,   1,   3,   1,   3, },
42
{  2,   0,   2,   0,   2,   0,   2,   0, },
43
{  1,   3,   1,   3,   1,   3,   1,   3, },
44
};
45
46
DECLARE_ALIGNED(8, const uint8_t, ff_dither_2x2_8)[][8] = {
47
{  6,   2,   6,   2,   6,   2,   6,   2, },
48
{  0,   4,   0,   4,   0,   4,   0,   4, },
49
{  6,   2,   6,   2,   6,   2,   6,   2, },
50
};
51
52
DECLARE_ALIGNED(8, const uint8_t, ff_dither_4x4_16)[][8] = {
53
{  8,   4,  11,   7,   8,   4,  11,   7, },
54
{  2,  14,   1,  13,   2,  14,   1,  13, },
55
{ 10,   6,   9,   5,  10,   6,   9,   5, },
56
{  0,  12,   3,  15,   0,  12,   3,  15, },
57
{  8,   4,  11,   7,   8,   4,  11,   7, },
58
};
59
60
DECLARE_ALIGNED(8, const uint8_t, ff_dither_8x8_32)[][8] = {
61
{ 17,   9,  23,  15,  16,   8,  22,  14, },
62
{  5,  29,   3,  27,   4,  28,   2,  26, },
63
{ 21,  13,  19,  11,  20,  12,  18,  10, },
64
{  0,  24,   6,  30,   1,  25,   7,  31, },
65
{ 16,   8,  22,  14,  17,   9,  23,  15, },
66
{  4,  28,   2,  26,   5,  29,   3,  27, },
67
{ 20,  12,  18,  10,  21,  13,  19,  11, },
68
{  1,  25,   7,  31,   0,  24,   6,  30, },
69
{ 17,   9,  23,  15,  16,   8,  22,  14, },
70
};
71
72
DECLARE_ALIGNED(8, const uint8_t, ff_dither_8x8_73)[][8] = {
73
{  0,  55,  14,  68,   3,  58,  17,  72, },
74
{ 37,  18,  50,  32,  40,  22,  54,  35, },
75
{  9,  64,   5,  59,  13,  67,   8,  63, },
76
{ 46,  27,  41,  23,  49,  31,  44,  26, },
77
{  2,  57,  16,  71,   1,  56,  15,  70, },
78
{ 39,  21,  52,  34,  38,  19,  51,  33, },
79
{ 11,  66,   7,  62,  10,  65,   6,  60, },
80
{ 48,  30,  43,  25,  47,  29,  42,  24, },
81
{  0,  55,  14,  68,   3,  58,  17,  72, },
82
};
83
84
#if 1
85
DECLARE_ALIGNED(8, const uint8_t, ff_dither_8x8_220)[][8] = {
86
{117,  62, 158, 103, 113,  58, 155, 100, },
87
{ 34, 199,  21, 186,  31, 196,  17, 182, },
88
{144,  89, 131,  76, 141,  86, 127,  72, },
89
{  0, 165,  41, 206,  10, 175,  52, 217, },
90
{110,  55, 151,  96, 120,  65, 162, 107, },
91
{ 28, 193,  14, 179,  38, 203,  24, 189, },
92
{138,  83, 124,  69, 148,  93, 134,  79, },
93
{  7, 172,  48, 213,   3, 168,  45, 210, },
94
{117,  62, 158, 103, 113,  58, 155, 100, },
95
};
96
#elif 1
97
// tries to correct a gamma of 1.5
98
DECLARE_ALIGNED(8, const uint8_t, ff_dither_8x8_220)[][8] = {
99
{  0, 143,  18, 200,   2, 156,  25, 215, },
100
{ 78,  28, 125,  64,  89,  36, 138,  74, },
101
{ 10, 180,   3, 161,  16, 195,   8, 175, },
102
{109,  51,  93,  38, 121,  60, 105,  47, },
103
{  1, 152,  23, 210,   0, 147,  20, 205, },
104
{ 85,  33, 134,  71,  81,  30, 130,  67, },
105
{ 14, 190,   6, 171,  12, 185,   5, 166, },
106
{117,  57, 101,  44, 113,  54,  97,  41, },
107
{  0, 143,  18, 200,   2, 156,  25, 215, },
108
};
109
#elif 1
110
// tries to correct a gamma of 2.0
111
DECLARE_ALIGNED(8, const uint8_t, ff_dither_8x8_220)[][8] = {
112
{  0, 124,   8, 193,   0, 140,  12, 213, },
113
{ 55,  14, 104,  42,  66,  19, 119,  52, },
114
{  3, 168,   1, 145,   6, 187,   3, 162, },
115
{ 86,  31,  70,  21,  99,  39,  82,  28, },
116
{  0, 134,  11, 206,   0, 129,   9, 200, },
117
{ 62,  17, 114,  48,  58,  16, 109,  45, },
118
{  5, 181,   2, 157,   4, 175,   1, 151, },
119
{ 95,  36,  78,  26,  90,  34,  74,  24, },
120
{  0, 124,   8, 193,   0, 140,  12, 213, },
121
};
122
#else
123
// tries to correct a gamma of 2.5
124
DECLARE_ALIGNED(8, const uint8_t, ff_dither_8x8_220)[][8] = {
125
{  0, 107,   3, 187,   0, 125,   6, 212, },
126
{ 39,   7,  86,  28,  49,  11, 102,  36, },
127
{  1, 158,   0, 131,   3, 180,   1, 151, },
128
{ 68,  19,  52,  12,  81,  25,  64,  17, },
129
{  0, 119,   5, 203,   0, 113,   4, 195, },
130
{ 45,   9,  96,  33,  42,   8,  91,  30, },
131
{  2, 172,   1, 144,   2, 165,   0, 137, },
132
{ 77,  23,  60,  15,  72,  21,  56,  14, },
133
{  0, 107,   3, 187,   0, 125,   6, 212, },
134
};
135
#endif
136
137
#define IS_BE_LE 0
138
#define IS_BE_BE 1
139
/* ENDIAN_IDENTIFIER needs to be "BE" or "LE". */
140
#define IS_BE(ENDIAN_IDENTIFIER) IS_BE_ ## ENDIAN_IDENTIFIER
141
142
#define output_pixel(pos, val, bias, signedness) \
143
0
    if (big_endian) { \
144
0
        AV_WB16(pos, bias + av_clip_ ## signedness ## 16(val >> shift)); \
145
0
    } else { \
146
0
        AV_WL16(pos, bias + av_clip_ ## signedness ## 16(val >> shift)); \
147
0
    }
148
149
static av_always_inline void
150
yuv2plane1_16_c_template(const int32_t *src, uint16_t *dest, int dstW,
151
                         int big_endian, int output_bits)
152
0
{
153
0
    int i;
154
0
    int shift = 3;
155
0
    av_assert0(output_bits == 16);
156
157
0
    for (i = 0; i < dstW; i++) {
158
0
        int val = src[i] + (1 << (shift - 1));
159
0
        output_pixel(&dest[i], val, 0, uint);
160
0
    }
161
0
}
162
163
static av_always_inline void
164
yuv2planeX_16_c_template(const int16_t *filter, int filterSize,
165
                         const int32_t **src, uint16_t *dest, int dstW,
166
                         int big_endian, int output_bits)
167
0
{
168
0
    int i;
169
0
    int shift = 15;
170
0
    av_assert0(output_bits == 16);
171
172
0
    for (i = 0; i < dstW; i++) {
173
0
        int val = 1 << (shift - 1);
174
0
        int j;
175
176
        /* range of val is [0,0x7FFFFFFF], so 31 bits, but with lanczos/spline
177
         * filters (or anything with negative coeffs, the range can be slightly
178
         * wider in both directions. To account for this overflow, we subtract
179
         * a constant so it always fits in the signed range (assuming a
180
         * reasonable filterSize), and re-add that at the end. */
181
0
        val -= 0x40000000;
182
0
        for (j = 0; j < filterSize; j++)
183
0
            val += src[j][i] * (unsigned)filter[j];
184
185
0
        output_pixel(&dest[i], val, 0x8000, int);
186
0
    }
187
0
}
188
189
static av_always_inline void
190
yuv2nv12cX_16_c_template(int big_endian, const uint8_t *chrDither,
191
                         const int16_t *chrFilter, int chrFilterSize,
192
                         const int16_t **chrUSrc, const int16_t **chrVSrc,
193
                         uint8_t *dest8, int chrDstW, int output_bits)
194
0
{
195
0
    uint16_t *dest = (uint16_t*)dest8;
196
0
    const int32_t **uSrc = (const int32_t **)chrUSrc;
197
0
    const int32_t **vSrc = (const int32_t **)chrVSrc;
198
0
    int shift = 15;
199
0
    int i, j;
200
0
    av_assert0(output_bits == 16);
201
202
0
    for (i = 0; i < chrDstW; i++) {
203
0
        int u = 1 << (shift - 1);
204
0
        int v = 1 << (shift - 1);
205
206
        /* See yuv2planeX_16_c_template for details. */
207
0
        u -= 0x40000000;
208
0
        v -= 0x40000000;
209
0
        for (j = 0; j < chrFilterSize; j++) {
210
0
            u += uSrc[j][i] * (unsigned)chrFilter[j];
211
0
            v += vSrc[j][i] * (unsigned)chrFilter[j];
212
0
        }
213
214
0
        output_pixel(&dest[2*i]  , u, 0x8000, int);
215
0
        output_pixel(&dest[2*i+1], v, 0x8000, int);
216
0
    }
217
0
}
218
219
static av_always_inline void
220
yuv2plane1_float_c_template(const int32_t *src, float *dest, int dstW)
221
0
{
222
0
    static const int big_endian = HAVE_BIGENDIAN;
223
0
    static const int shift = 3;
224
0
    static const float float_mult = 1.0f / 65535.0f;
225
0
    int i, val;
226
0
    uint16_t val_uint;
227
228
0
    for (i = 0; i < dstW; ++i){
229
0
        val = src[i] + (1 << (shift - 1));
230
0
        output_pixel(&val_uint, val, 0, uint);
231
0
        dest[i] = float_mult * (float)val_uint;
232
0
    }
233
0
}
234
235
static av_always_inline void
236
yuv2plane1_float_bswap_c_template(const int32_t *src, uint32_t *dest, int dstW)
237
0
{
238
0
    static const int big_endian = HAVE_BIGENDIAN;
239
0
    static const int shift = 3;
240
0
    static const float float_mult = 1.0f / 65535.0f;
241
0
    int i, val;
242
0
    uint16_t val_uint;
243
244
0
    for (i = 0; i < dstW; ++i){
245
0
        val = src[i] + (1 << (shift - 1));
246
0
        output_pixel(&val_uint, val, 0, uint);
247
0
        dest[i] = av_bswap32(av_float2int(float_mult * (float)val_uint));
248
0
    }
249
0
}
250
251
static av_always_inline void
252
yuv2planeX_float_c_template(const int16_t *filter, int filterSize, const int32_t **src,
253
                            float *dest, int dstW)
254
0
{
255
0
    static const int big_endian = HAVE_BIGENDIAN;
256
0
    static const int shift = 15;
257
0
    static const float float_mult = 1.0f / 65535.0f;
258
0
    int i, j, val;
259
0
    uint16_t val_uint;
260
261
0
    for (i = 0; i < dstW; ++i){
262
0
        val = (1 << (shift - 1)) - 0x40000000;
263
0
        for (j = 0; j < filterSize; ++j){
264
0
            val += src[j][i] * (unsigned)filter[j];
265
0
        }
266
0
        output_pixel(&val_uint, val, 0x8000, int);
267
0
        dest[i] = float_mult * (float)val_uint;
268
0
    }
269
0
}
270
271
static av_always_inline void
272
yuv2planeX_float_bswap_c_template(const int16_t *filter, int filterSize, const int32_t **src,
273
                            uint32_t *dest, int dstW)
274
0
{
275
0
    static const int big_endian = HAVE_BIGENDIAN;
276
0
    static const int shift = 15;
277
0
    static const float float_mult = 1.0f / 65535.0f;
278
0
    int i, j, val;
279
0
    uint16_t val_uint;
280
281
0
    for (i = 0; i < dstW; ++i){
282
0
        val = (1 << (shift - 1)) - 0x40000000;
283
0
        for (j = 0; j < filterSize; ++j){
284
0
            val += src[j][i] * (unsigned)filter[j];
285
0
        }
286
0
        output_pixel(&val_uint, val, 0x8000, int);
287
0
        dest[i] = av_bswap32(av_float2int(float_mult * (float)val_uint));
288
0
    }
289
0
}
290
291
#define yuv2plane1_float(template, dest_type, BE_LE) \
292
static void yuv2plane1_float ## BE_LE ## _c(const int16_t *src, uint8_t *dest, int dstW, \
293
0
                                            const uint8_t *dither, int offset) \
294
0
{ \
295
0
    template((const int32_t *)src, (dest_type *)dest, dstW); \
296
0
}
Unexecuted instantiation: output.c:yuv2plane1_floatBE_c
Unexecuted instantiation: output.c:yuv2plane1_floatLE_c
297
298
#define yuv2planeX_float(template, dest_type, BE_LE) \
299
static void yuv2planeX_float ## BE_LE ## _c(const int16_t *filter, int filterSize, \
300
                                            const int16_t **src, uint8_t *dest, int dstW, \
301
0
                                            const uint8_t *dither, int offset) \
302
0
{ \
303
0
    template(filter, filterSize, (const int32_t **)src, (dest_type *)dest, dstW); \
304
0
}
Unexecuted instantiation: output.c:yuv2planeX_floatBE_c
Unexecuted instantiation: output.c:yuv2planeX_floatLE_c
305
306
#if HAVE_BIGENDIAN
307
yuv2plane1_float(yuv2plane1_float_c_template,       float,    BE)
308
yuv2plane1_float(yuv2plane1_float_bswap_c_template, uint32_t, LE)
309
yuv2planeX_float(yuv2planeX_float_c_template,       float,    BE)
310
yuv2planeX_float(yuv2planeX_float_bswap_c_template, uint32_t, LE)
311
#else
312
yuv2plane1_float(yuv2plane1_float_c_template,       float,    LE)
313
yuv2plane1_float(yuv2plane1_float_bswap_c_template, uint32_t, BE)
314
yuv2planeX_float(yuv2planeX_float_c_template,       float,    LE)
315
yuv2planeX_float(yuv2planeX_float_bswap_c_template, uint32_t, BE)
316
#endif
317
318
#undef output_pixel
319
320
#define output_pixel(pos, val) \
321
0
    if (big_endian) { \
322
0
        AV_WB16(pos, av_clip_uintp2(val >> shift, output_bits)); \
323
0
    } else { \
324
0
        AV_WL16(pos, av_clip_uintp2(val >> shift, output_bits)); \
325
0
    }
326
327
static av_always_inline void
328
yuv2plane1_10_c_template(const int16_t *src, uint16_t *dest, int dstW,
329
                         int big_endian, int output_bits)
330
0
{
331
0
    int i;
332
0
    int shift = 15 - output_bits;
333
334
0
    for (i = 0; i < dstW; i++) {
335
0
        int val = src[i] + (1 << (shift - 1));
336
0
        output_pixel(&dest[i], val);
337
0
    }
338
0
}
339
340
static av_always_inline void
341
yuv2planeX_10_c_template(const int16_t *filter, int filterSize,
342
                         const int16_t **src, uint16_t *dest, int dstW,
343
                         int big_endian, int output_bits)
344
0
{
345
0
    int i;
346
0
    int shift = 11 + 16 - output_bits;
347
348
0
    for (i = 0; i < dstW; i++) {
349
0
        int val = 1 << (shift - 1);
350
0
        int j;
351
352
0
        for (j = 0; j < filterSize; j++)
353
0
            val += src[j][i] * filter[j];
354
355
0
        output_pixel(&dest[i], val);
356
0
    }
357
0
}
358
359
#undef output_pixel
360
361
#define yuv2NBPS(bits, BE_LE, is_be, template_size, typeX_t) \
362
static void yuv2plane1_ ## bits ## BE_LE ## _c(const int16_t *src, \
363
                              uint8_t *dest, int dstW, \
364
0
                              const uint8_t *dither, int offset)\
365
0
{ \
366
0
    yuv2plane1_ ## template_size ## _c_template((const typeX_t *) src, \
367
0
                         (uint16_t *) dest, dstW, is_be, bits); \
368
0
}\
Unexecuted instantiation: output.c:yuv2plane1_16BE_c
Unexecuted instantiation: output.c:yuv2plane1_16LE_c
Unexecuted instantiation: output.c:yuv2plane1_9BE_c
Unexecuted instantiation: output.c:yuv2plane1_9LE_c
Unexecuted instantiation: output.c:yuv2plane1_10BE_c
Unexecuted instantiation: output.c:yuv2plane1_10LE_c
Unexecuted instantiation: output.c:yuv2plane1_12BE_c
Unexecuted instantiation: output.c:yuv2plane1_12LE_c
Unexecuted instantiation: output.c:yuv2plane1_14BE_c
Unexecuted instantiation: output.c:yuv2plane1_14LE_c
369
static void yuv2planeX_ ## bits ## BE_LE ## _c(const int16_t *filter, int filterSize, \
370
                              const int16_t **src, uint8_t *dest, int dstW, \
371
0
                              const uint8_t *dither, int offset)\
372
0
{ \
373
0
    yuv2planeX_## template_size ## _c_template(filter, \
374
0
                         filterSize, (const typeX_t **) src, \
375
0
                         (uint16_t *) dest, dstW, is_be, bits); \
376
0
}
Unexecuted instantiation: output.c:yuv2planeX_16BE_c
Unexecuted instantiation: output.c:yuv2planeX_16LE_c
Unexecuted instantiation: output.c:yuv2planeX_9BE_c
Unexecuted instantiation: output.c:yuv2planeX_9LE_c
Unexecuted instantiation: output.c:yuv2planeX_10BE_c
Unexecuted instantiation: output.c:yuv2planeX_10LE_c
Unexecuted instantiation: output.c:yuv2planeX_12BE_c
Unexecuted instantiation: output.c:yuv2planeX_12LE_c
Unexecuted instantiation: output.c:yuv2planeX_14BE_c
Unexecuted instantiation: output.c:yuv2planeX_14LE_c
377
378
yuv2NBPS( 9, BE, 1, 10, int16_t)
379
yuv2NBPS( 9, LE, 0, 10, int16_t)
380
yuv2NBPS(10, BE, 1, 10, int16_t)
381
yuv2NBPS(10, LE, 0, 10, int16_t)
382
yuv2NBPS(12, BE, 1, 10, int16_t)
383
yuv2NBPS(12, LE, 0, 10, int16_t)
384
yuv2NBPS(14, BE, 1, 10, int16_t)
385
yuv2NBPS(14, LE, 0, 10, int16_t)
386
yuv2NBPS(16, BE, 1, 16, int32_t)
387
yuv2NBPS(16, LE, 0, 16, int32_t)
388
389
#define output_pixel(pos, val) \
390
0
    if (big_endian) { \
391
0
        AV_WB16(pos, av_clip_uintp2(val >> shift, output_bits) << (16 - output_bits)); \
392
0
    } else { \
393
0
        AV_WL16(pos, av_clip_uintp2(val >> shift, output_bits) << (16 - output_bits)); \
394
0
    }
395
396
static av_always_inline void
397
yuv2msbplane1_10_c_template(const int16_t *src, uint16_t *dest, int dstW,
398
                            int big_endian, int output_bits)
399
0
{
400
0
    int i;
401
0
    int shift = 15 - output_bits;
402
403
0
    for (i = 0; i < dstW; i++) {
404
0
        int val = src[i] + (1 << (shift - 1));
405
0
        output_pixel(&dest[i], val);
406
0
    }
407
0
}
408
409
static av_always_inline void
410
yuv2msbplaneX_10_c_template(const int16_t *filter, int filterSize,
411
                            const int16_t **src, uint16_t *dest, int dstW,
412
                            int big_endian, int output_bits)
413
0
{
414
0
    int i;
415
0
    int shift = 11 + 16 - output_bits;
416
417
0
    for (i = 0; i < dstW; i++) {
418
0
        int val = 1 << (shift - 1);
419
0
        int j;
420
421
0
        for (j = 0; j < filterSize; j++)
422
0
            val += src[j][i] * filter[j];
423
424
0
        output_pixel(&dest[i], val);
425
0
    }
426
0
}
427
428
#define yuv2MSBNBPS(bits, BE_LE, is_be, template_size, typeX_t) \
429
static void yuv2msbplane1_ ## bits ## BE_LE ## _c(const int16_t *src, \
430
                              uint8_t *dest, int dstW, \
431
0
                              const uint8_t *dither, int offset)\
432
0
{ \
433
0
    yuv2msbplane1_ ## template_size ## _c_template((const typeX_t *) src, \
434
0
                         (uint16_t *) dest, dstW, is_be, bits); \
435
0
}\
Unexecuted instantiation: output.c:yuv2msbplane1_10BE_c
Unexecuted instantiation: output.c:yuv2msbplane1_10LE_c
Unexecuted instantiation: output.c:yuv2msbplane1_12BE_c
Unexecuted instantiation: output.c:yuv2msbplane1_12LE_c
436
static void yuv2msbplaneX_ ## bits ## BE_LE ## _c(const int16_t *filter, int filterSize, \
437
                              const int16_t **src, uint8_t *dest, int dstW, \
438
0
                              const uint8_t *dither, int offset)\
439
0
{ \
440
0
    yuv2msbplaneX_## template_size ## _c_template(filter, \
441
0
                         filterSize, (const typeX_t **) src, \
442
0
                         (uint16_t *) dest, dstW, is_be, bits); \
443
0
}
Unexecuted instantiation: output.c:yuv2msbplaneX_10BE_c
Unexecuted instantiation: output.c:yuv2msbplaneX_10LE_c
Unexecuted instantiation: output.c:yuv2msbplaneX_12BE_c
Unexecuted instantiation: output.c:yuv2msbplaneX_12LE_c
444
445
yuv2MSBNBPS(10, BE, 1, 10, int16_t)
446
yuv2MSBNBPS(10, LE, 0, 10, int16_t)
447
yuv2MSBNBPS(12, BE, 1, 10, int16_t)
448
yuv2MSBNBPS(12, LE, 0, 10, int16_t)
449
450
#undef output_pixel
451
452
static void yuv2nv12cX_16LE_c(enum AVPixelFormat dstFormat, const uint8_t *chrDither,
453
                              const int16_t *chrFilter, int chrFilterSize,
454
                              const int16_t **chrUSrc, const int16_t **chrVSrc,
455
                              uint8_t *dest8, int chrDstW)
456
0
{
457
0
    yuv2nv12cX_16_c_template(0, chrDither, chrFilter, chrFilterSize, chrUSrc, chrVSrc, dest8, chrDstW, 16);
458
0
}
459
460
static void yuv2nv12cX_16BE_c(enum AVPixelFormat dstFormat, const uint8_t *chrDither,
461
                              const int16_t *chrFilter, int chrFilterSize,
462
                              const int16_t **chrUSrc, const int16_t **chrVSrc,
463
                              uint8_t *dest8, int chrDstW)
464
0
{
465
0
    yuv2nv12cX_16_c_template(1, chrDither, chrFilter, chrFilterSize, chrUSrc, chrVSrc, dest8, chrDstW, 16);
466
0
}
467
468
static void yuv2planeX_8_c(const int16_t *filter, int filterSize,
469
                           const int16_t **src, uint8_t *dest, int dstW,
470
                           const uint8_t *dither, int offset)
471
0
{
472
0
    int i;
473
0
    for (i=0; i<dstW; i++) {
474
0
        int val = dither[(i + offset) & 7] << 12;
475
0
        int j;
476
0
        for (j=0; j<filterSize; j++) {
477
0
            val += (unsigned)(src[j][i] * filter[j]);
478
479
0
        }
480
481
0
        dest[i]= av_clip_uint8(val>>19);
482
0
    }
483
0
}
484
485
static void yuv2plane1_8_c(const int16_t *src, uint8_t *dest, int dstW,
486
                           const uint8_t *dither, int offset)
487
0
{
488
0
    int i;
489
0
    for (i=0; i<dstW; i++) {
490
0
        int val = (src[i] + dither[(i + offset) & 7]) >> 7;
491
0
        dest[i]= av_clip_uint8(val);
492
0
    }
493
0
}
494
495
static void yuv2nv12cX_c(enum AVPixelFormat dstFormat, const uint8_t *chrDither,
496
                         const int16_t *chrFilter, int chrFilterSize,
497
                         const int16_t **chrUSrc, const int16_t **chrVSrc,
498
                         uint8_t *dest, int chrDstW)
499
0
{
500
0
    int i;
501
502
0
    if (!isSwappedChroma(dstFormat))
503
0
        for (i=0; i<chrDstW; i++) {
504
0
            int u = chrDither[i & 7] << 12;
505
0
            int v = chrDither[(i + 3) & 7] << 12;
506
0
            int j;
507
0
            for (j=0; j<chrFilterSize; j++) {
508
0
                u += chrUSrc[j][i] * (unsigned)chrFilter[j];
509
0
                v += chrVSrc[j][i] * (unsigned)chrFilter[j];
510
0
            }
511
512
0
            dest[2*i]= av_clip_uint8(u>>19);
513
0
            dest[2*i+1]= av_clip_uint8(v>>19);
514
0
        }
515
0
    else
516
0
        for (i=0; i<chrDstW; i++) {
517
0
            int u = chrDither[i & 7] << 12;
518
0
            int v = chrDither[(i + 3) & 7] << 12;
519
0
            int j;
520
0
            for (j=0; j<chrFilterSize; j++) {
521
0
                u += chrUSrc[j][i] * (unsigned)chrFilter[j];
522
0
                v += chrVSrc[j][i] * (unsigned)chrFilter[j];
523
0
            }
524
525
0
            dest[2*i]= av_clip_uint8(v>>19);
526
0
            dest[2*i+1]= av_clip_uint8(u>>19);
527
0
        }
528
0
}
529
530
531
#define output_pixel(pos, val) \
532
0
    if (big_endian) { \
533
0
        AV_WB16(pos, av_clip_uintp2(val >> shift, output_bits) << output_shift); \
534
0
    } else { \
535
0
        AV_WL16(pos, av_clip_uintp2(val >> shift, output_bits) << output_shift); \
536
0
    }
537
538
static void yuv2p01xl1_c(const int16_t *src,
539
                         uint16_t *dest, int dstW,
540
                         int big_endian, int output_bits, int output_shift)
541
0
{
542
0
    int i;
543
0
    int shift = 15 - output_bits;
544
545
0
    for (i = 0; i < dstW; i++) {
546
0
        int val = src[i] + (1 << (shift - 1));
547
0
        output_pixel(&dest[i], val);
548
0
    }
549
0
}
550
551
static void yuv2p01xlX_c(const int16_t *filter, int filterSize,
552
                         const int16_t **src, uint16_t *dest, int dstW,
553
                         int big_endian, int output_bits, int output_shift)
554
0
{
555
0
    int i, j;
556
0
    int shift = 11 + 16 - output_bits;
557
558
0
    for (i = 0; i < dstW; i++) {
559
0
        int val = 1 << (shift - 1);
560
561
0
        for (j = 0; j < filterSize; j++)
562
0
            val += src[j][i] * filter[j];
563
564
0
        output_pixel(&dest[i], val);
565
0
    }
566
0
}
567
568
static void yuv2p01xcX_c(int big_endian, const uint8_t *chrDither,
569
                         const int16_t *chrFilter, int chrFilterSize,
570
                         const int16_t **chrUSrc, const int16_t **chrVSrc,
571
                         uint8_t *dest8, int chrDstW, int output_bits, int output_shift)
572
0
{
573
0
    uint16_t *dest = (uint16_t*)dest8;
574
0
    int i, j;
575
0
    int shift = 11 + 16 - output_bits;
576
577
0
    for (i = 0; i < chrDstW; i++) {
578
0
        int u = 1 << (shift - 1);
579
0
        int v = 1 << (shift - 1);
580
581
0
        for (j = 0; j < chrFilterSize; j++) {
582
0
            u += chrUSrc[j][i] * (unsigned)chrFilter[j];
583
0
            v += chrVSrc[j][i] * (unsigned)chrFilter[j];
584
0
        }
585
586
0
        output_pixel(&dest[2*i]  , u);
587
0
        output_pixel(&dest[2*i+1], v);
588
0
    }
589
0
}
590
591
#undef output_pixel
592
593
#define yuv2p01x_wrapper(fmt, bits, shift)                                     \
594
    static void yuv2 ## fmt ## l1_LE_c(const int16_t *src,                     \
595
                                          uint8_t *dest, int dstW,             \
596
                                          const uint8_t *dither, int offset)   \
597
0
    {                                                                          \
598
0
        yuv2p01xl1_c(src, (uint16_t*)dest, dstW, 0, bits, shift);              \
599
0
    }                                                                          \
Unexecuted instantiation: output.c:yuv2p010l1_LE_c
Unexecuted instantiation: output.c:yuv2p012l1_LE_c
Unexecuted instantiation: output.c:yuv2nv20l1_LE_c
600
                                                                               \
601
    static void yuv2 ## fmt ## l1_BE_c(const int16_t *src,                     \
602
                                          uint8_t *dest, int dstW,             \
603
                                          const uint8_t *dither, int offset)   \
604
0
    {                                                                          \
605
0
        yuv2p01xl1_c(src, (uint16_t*)dest, dstW, 1, bits, shift);              \
606
0
    }                                                                          \
Unexecuted instantiation: output.c:yuv2p010l1_BE_c
Unexecuted instantiation: output.c:yuv2p012l1_BE_c
Unexecuted instantiation: output.c:yuv2nv20l1_BE_c
607
                                                                               \
608
    static void yuv2 ## fmt ## lX_LE_c(const int16_t *filter,                  \
609
                                          int filterSize, const int16_t **src, \
610
                                          uint8_t *dest, int dstW,             \
611
                                          const uint8_t *dither, int offset)   \
612
0
    {                                                                          \
613
0
        yuv2p01xlX_c(filter, filterSize, src, (uint16_t*)dest, dstW, 0,        \
614
0
                     bits, shift);                                             \
615
0
    }                                                                          \
Unexecuted instantiation: output.c:yuv2p010lX_LE_c
Unexecuted instantiation: output.c:yuv2p012lX_LE_c
Unexecuted instantiation: output.c:yuv2nv20lX_LE_c
616
                                                                               \
617
    static void yuv2 ## fmt ## lX_BE_c(const int16_t *filter,                  \
618
                                          int filterSize, const int16_t **src, \
619
                                          uint8_t *dest, int dstW,             \
620
                                          const uint8_t *dither, int offset)   \
621
0
    {                                                                          \
622
0
        yuv2p01xlX_c(filter, filterSize, src, (uint16_t*)dest, dstW, 1,        \
623
0
                     bits, shift);                                             \
624
0
    }                                                                          \
Unexecuted instantiation: output.c:yuv2p010lX_BE_c
Unexecuted instantiation: output.c:yuv2p012lX_BE_c
Unexecuted instantiation: output.c:yuv2nv20lX_BE_c
625
                                                                               \
626
    static void yuv2 ## fmt ## cX_LE_c(enum AVPixelFormat dstFormat,           \
627
                                          const uint8_t *chrDither,            \
628
                                          const int16_t *chrFilter,            \
629
                                          int chrFilterSize,                   \
630
                                          const int16_t **chrUSrc,             \
631
                                          const int16_t **chrVSrc,             \
632
                                          uint8_t *dest8, int chrDstW)         \
633
0
    {                                                                          \
634
0
        yuv2p01xcX_c(0, chrDither, chrFilter, chrFilterSize, chrUSrc, chrVSrc, \
635
0
                     dest8, chrDstW, bits, shift);                             \
636
0
    }                                                                          \
Unexecuted instantiation: output.c:yuv2p010cX_LE_c
Unexecuted instantiation: output.c:yuv2p012cX_LE_c
Unexecuted instantiation: output.c:yuv2nv20cX_LE_c
637
                                                                               \
638
    static void yuv2 ## fmt ## cX_BE_c(enum AVPixelFormat dstFormat,           \
639
                                          const uint8_t *chrDither,            \
640
                                          const int16_t *chrFilter,            \
641
                                          int chrFilterSize,                   \
642
                                          const int16_t **chrUSrc,             \
643
                                          const int16_t **chrVSrc,             \
644
                                          uint8_t *dest8, int chrDstW)         \
645
0
    {                                                                          \
646
0
        yuv2p01xcX_c(1, chrDither, chrFilter, chrFilterSize, chrUSrc, chrVSrc, \
647
0
                     dest8, chrDstW, bits, shift);                             \
648
0
    }
Unexecuted instantiation: output.c:yuv2p010cX_BE_c
Unexecuted instantiation: output.c:yuv2p012cX_BE_c
Unexecuted instantiation: output.c:yuv2nv20cX_BE_c
649
650
yuv2p01x_wrapper(p010, 10, 6)
651
yuv2p01x_wrapper(p012, 12, 4)
652
yuv2p01x_wrapper(nv20, 10, 0)
653
654
#define accumulate_bit(acc, val) \
655
0
    acc <<= 1; \
656
0
    acc |= (val) >= 234
657
#define output_pixel(pos, acc) \
658
0
    if (target == AV_PIX_FMT_MONOBLACK) { \
659
0
        pos = acc; \
660
0
    } else { \
661
0
        pos = ~acc; \
662
0
    }
663
664
static av_always_inline void
665
yuv2mono_X_c_template(SwsInternal *c, const int16_t *lumFilter,
666
                      const int16_t **lumSrc, int lumFilterSize,
667
                      const int16_t *chrFilter, const int16_t **chrUSrc,
668
                      const int16_t **chrVSrc, int chrFilterSize,
669
                      const int16_t **alpSrc, uint8_t *dest, int dstW,
670
                      int y, enum AVPixelFormat target)
671
0
{
672
0
    const uint8_t * const d128 = ff_dither_8x8_220[y&7];
673
0
    int i;
674
0
    unsigned acc = 0;
675
0
    int err = 0;
676
677
0
    for (i = 0; i < dstW; i += 2) {
678
0
        int j;
679
0
        int Y1 = 1 << 18;
680
0
        int Y2 = 1 << 18;
681
682
0
        for (j = 0; j < lumFilterSize; j++) {
683
0
            Y1 += lumSrc[j][i]   * (unsigned)lumFilter[j];
684
0
            Y2 += lumSrc[j][i+1] * (unsigned)lumFilter[j];
685
0
        }
686
0
        Y1 >>= 19;
687
0
        Y2 >>= 19;
688
0
        if ((Y1 | Y2) & 0x100) {
689
0
            Y1 = av_clip_uint8(Y1);
690
0
            Y2 = av_clip_uint8(Y2);
691
0
        }
692
0
        if (c->opts.dither == SWS_DITHER_ED) {
693
0
            Y1 += (7*err + 1*c->dither_error[0][i] + 5*c->dither_error[0][i+1] + 3*c->dither_error[0][i+2] + 8 - 256)>>4;
694
0
            c->dither_error[0][i] = err;
695
0
            acc = 2*acc + (Y1 >= 128);
696
0
            Y1 -= 220*(acc&1);
697
698
0
            err = Y2 + ((7*Y1 + 1*c->dither_error[0][i+1] + 5*c->dither_error[0][i+2] + 3*c->dither_error[0][i+3] + 8 - 256)>>4);
699
0
            c->dither_error[0][i+1] = Y1;
700
0
            acc = 2*acc + (err >= 128);
701
0
            err -= 220*(acc&1);
702
0
        } else {
703
0
            accumulate_bit(acc, Y1 + d128[(i + 0) & 7]);
704
0
            accumulate_bit(acc, Y2 + d128[(i + 1) & 7]);
705
0
        }
706
0
        if ((i & 7) == 6) {
707
0
            output_pixel(*dest++, acc);
708
0
        }
709
0
    }
710
0
    c->dither_error[0][i] = err;
711
712
0
    if (i & 6) {
713
0
        output_pixel(*dest, acc);
714
0
    }
715
0
}
716
717
static av_always_inline void
718
yuv2mono_2_c_template(SwsInternal *c, const int16_t *buf[2],
719
                      const int16_t *ubuf[2], const int16_t *vbuf[2],
720
                      const int16_t *abuf[2], uint8_t *dest, int dstW,
721
                      int yalpha, int uvalpha, int y,
722
                      enum AVPixelFormat target)
723
0
{
724
0
    const int16_t *buf0  = buf[0],  *buf1  = buf[1];
725
0
    const uint8_t * const d128 = ff_dither_8x8_220[y & 7];
726
0
    int  yalpha1 = 4096 - yalpha;
727
0
    int i;
728
0
    av_assert2(yalpha  <= 4096U);
729
730
0
    if (c->opts.dither == SWS_DITHER_ED) {
731
0
        int err = 0;
732
0
        unsigned acc = 0;
733
0
        for (i = 0; i < dstW; i +=2) {
734
0
            int Y;
735
736
0
            Y = (buf0[i + 0] * yalpha1 + buf1[i + 0] * yalpha) >> 19;
737
0
            Y += (7*err + 1*c->dither_error[0][i] + 5*c->dither_error[0][i+1] + 3*c->dither_error[0][i+2] + 8 - 256)>>4;
738
0
            c->dither_error[0][i] = err;
739
0
            acc = 2*acc + (Y >= 128);
740
0
            Y -= 220*(acc&1);
741
742
0
            err = (buf0[i + 1] * yalpha1 + buf1[i + 1] * yalpha) >> 19;
743
0
            err += (7*Y + 1*c->dither_error[0][i+1] + 5*c->dither_error[0][i+2] + 3*c->dither_error[0][i+3] + 8 - 256)>>4;
744
0
            c->dither_error[0][i+1] = Y;
745
0
            acc = 2*acc + (err >= 128);
746
0
            err -= 220*(acc&1);
747
748
0
            if ((i & 7) == 6)
749
0
                output_pixel(*dest++, acc);
750
0
        }
751
0
        c->dither_error[0][i] = err;
752
0
        if (i & 6)
753
0
            output_pixel(*dest, acc << (8 - (i & 7)));
754
0
    } else {
755
0
        for (i = 0; i < dstW; i += 8) {
756
0
            int Y;
757
0
            unsigned acc = 0;
758
759
0
            Y = (buf0[i + 0] * yalpha1 + buf1[i + 0] * yalpha) >> 19;
760
0
            accumulate_bit(acc, Y + d128[0]);
761
0
            Y = (buf0[i + 1] * yalpha1 + buf1[i + 1] * yalpha) >> 19;
762
0
            accumulate_bit(acc, Y + d128[1]);
763
0
            Y = (buf0[i + 2] * yalpha1 + buf1[i + 2] * yalpha) >> 19;
764
0
            accumulate_bit(acc, Y + d128[2]);
765
0
            Y = (buf0[i + 3] * yalpha1 + buf1[i + 3] * yalpha) >> 19;
766
0
            accumulate_bit(acc, Y + d128[3]);
767
0
            Y = (buf0[i + 4] * yalpha1 + buf1[i + 4] * yalpha) >> 19;
768
0
            accumulate_bit(acc, Y + d128[4]);
769
0
            Y = (buf0[i + 5] * yalpha1 + buf1[i + 5] * yalpha) >> 19;
770
0
            accumulate_bit(acc, Y + d128[5]);
771
0
            Y = (buf0[i + 6] * yalpha1 + buf1[i + 6] * yalpha) >> 19;
772
0
            accumulate_bit(acc, Y + d128[6]);
773
0
            Y = (buf0[i + 7] * yalpha1 + buf1[i + 7] * yalpha) >> 19;
774
0
            accumulate_bit(acc, Y + d128[7]);
775
776
0
            output_pixel(*dest++, acc);
777
0
        }
778
0
    }
779
0
}
780
781
static av_always_inline void
782
yuv2mono_1_c_template(SwsInternal *c, const int16_t *buf0,
783
                      const int16_t *ubuf[2], const int16_t *vbuf[2],
784
                      const int16_t *abuf0, uint8_t *dest, int dstW,
785
                      int uvalpha, int y, enum AVPixelFormat target)
786
0
{
787
0
    const uint8_t * const d128 = ff_dither_8x8_220[y & 7];
788
0
    int i;
789
790
0
    if (c->opts.dither == SWS_DITHER_ED) {
791
0
        int err = 0;
792
0
        unsigned acc = 0;
793
0
        for (i = 0; i < dstW; i +=2) {
794
0
            int Y;
795
796
0
            Y = ((buf0[i + 0] + 64) >> 7);
797
0
            Y += (7*err + 1*c->dither_error[0][i] + 5*c->dither_error[0][i+1] + 3*c->dither_error[0][i+2] + 8 - 256)>>4;
798
0
            c->dither_error[0][i] = err;
799
0
            acc = 2*acc + (Y >= 128);
800
0
            Y -= 220*(acc&1);
801
802
0
            err = ((buf0[i + 1] + 64) >> 7);
803
0
            err += (7*Y + 1*c->dither_error[0][i+1] + 5*c->dither_error[0][i+2] + 3*c->dither_error[0][i+3] + 8 - 256)>>4;
804
0
            c->dither_error[0][i+1] = Y;
805
0
            acc = 2*acc + (err >= 128);
806
0
            err -= 220*(acc&1);
807
808
0
            if ((i & 7) == 6)
809
0
                output_pixel(*dest++, acc);
810
0
        }
811
0
        c->dither_error[0][i] = err;
812
0
        if (i & 6)
813
0
            output_pixel(*dest, acc << (8 - (i & 7)));
814
0
    } else {
815
0
        for (i = 0; i < dstW; i += 8) {
816
0
            unsigned acc = 0;
817
0
            accumulate_bit(acc, ((buf0[i + 0] + 64) >> 7) + d128[0]);
818
0
            accumulate_bit(acc, ((buf0[i + 1] + 64) >> 7) + d128[1]);
819
0
            accumulate_bit(acc, ((buf0[i + 2] + 64) >> 7) + d128[2]);
820
0
            accumulate_bit(acc, ((buf0[i + 3] + 64) >> 7) + d128[3]);
821
0
            accumulate_bit(acc, ((buf0[i + 4] + 64) >> 7) + d128[4]);
822
0
            accumulate_bit(acc, ((buf0[i + 5] + 64) >> 7) + d128[5]);
823
0
            accumulate_bit(acc, ((buf0[i + 6] + 64) >> 7) + d128[6]);
824
0
            accumulate_bit(acc, ((buf0[i + 7] + 64) >> 7) + d128[7]);
825
826
0
            output_pixel(*dest++, acc);
827
0
        }
828
0
    }
829
0
}
830
831
#undef output_pixel
832
#undef accumulate_bit
833
834
#define YUV2PACKEDWRAPPER(name, base, ext, fmt) \
835
static void name ## ext ## _X_c(SwsInternal *c, const int16_t *lumFilter, \
836
                                const int16_t **lumSrc, int lumFilterSize, \
837
                                const int16_t *chrFilter, const int16_t **chrUSrc, \
838
                                const int16_t **chrVSrc, int chrFilterSize, \
839
                                const int16_t **alpSrc, uint8_t *dest, int dstW, \
840
0
                                int y) \
841
0
{ \
842
0
    name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
843
0
                                  chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
844
0
                                  alpSrc, dest, dstW, y, fmt); \
845
0
} \
Unexecuted instantiation: output.c:yuv2monowhite_X_c
Unexecuted instantiation: output.c:yuv2monoblack_X_c
Unexecuted instantiation: output.c:yuv2yuyv422_X_c
Unexecuted instantiation: output.c:yuv2yvyu422_X_c
Unexecuted instantiation: output.c:yuv2uyvy422_X_c
846
 \
847
static void name ## ext ## _2_c(SwsInternal *c, const int16_t *buf[2], \
848
                                const int16_t *ubuf[2], const int16_t *vbuf[2], \
849
                                const int16_t *abuf[2], uint8_t *dest, int dstW, \
850
0
                                int yalpha, int uvalpha, int y) \
851
0
{ \
852
0
    name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
853
0
                                  dest, dstW, yalpha, uvalpha, y, fmt); \
854
0
} \
Unexecuted instantiation: output.c:yuv2monowhite_2_c
Unexecuted instantiation: output.c:yuv2monoblack_2_c
Unexecuted instantiation: output.c:yuv2yuyv422_2_c
Unexecuted instantiation: output.c:yuv2yvyu422_2_c
Unexecuted instantiation: output.c:yuv2uyvy422_2_c
855
 \
856
static void name ## ext ## _1_c(SwsInternal *c, const int16_t *buf0, \
857
                                const int16_t *ubuf[2], const int16_t *vbuf[2], \
858
                                const int16_t *abuf0, uint8_t *dest, int dstW, \
859
0
                                int uvalpha, int y) \
860
0
{ \
861
0
    name ## base ## _1_c_template(c, buf0, ubuf, vbuf, \
862
0
                                  abuf0, dest, dstW, uvalpha, \
863
0
                                  y, fmt); \
864
0
}
Unexecuted instantiation: output.c:yuv2monowhite_1_c
Unexecuted instantiation: output.c:yuv2monoblack_1_c
Unexecuted instantiation: output.c:yuv2yuyv422_1_c
Unexecuted instantiation: output.c:yuv2yvyu422_1_c
Unexecuted instantiation: output.c:yuv2uyvy422_1_c
865
866
YUV2PACKEDWRAPPER(yuv2mono,, white, AV_PIX_FMT_MONOWHITE)
867
YUV2PACKEDWRAPPER(yuv2mono,, black, AV_PIX_FMT_MONOBLACK)
868
869
#define output_pixels(pos, Y1, U, Y2, V) \
870
0
    if (target == AV_PIX_FMT_YUYV422) { \
871
0
        dest[pos + 0] = Y1; \
872
0
        dest[pos + 1] = U;  \
873
0
        dest[pos + 2] = Y2; \
874
0
        dest[pos + 3] = V;  \
875
0
    } else if (target == AV_PIX_FMT_YVYU422) { \
876
0
        dest[pos + 0] = Y1; \
877
0
        dest[pos + 1] = V;  \
878
0
        dest[pos + 2] = Y2; \
879
0
        dest[pos + 3] = U;  \
880
0
    } else { /* AV_PIX_FMT_UYVY422 */ \
881
0
        dest[pos + 0] = U;  \
882
0
        dest[pos + 1] = Y1; \
883
0
        dest[pos + 2] = V;  \
884
0
        dest[pos + 3] = Y2; \
885
0
    }
886
887
static av_always_inline void
888
yuv2422_X_c_template(SwsInternal *c, const int16_t *lumFilter,
889
                     const int16_t **lumSrc, int lumFilterSize,
890
                     const int16_t *chrFilter, const int16_t **chrUSrc,
891
                     const int16_t **chrVSrc, int chrFilterSize,
892
                     const int16_t **alpSrc, uint8_t *dest, int dstW,
893
                     int y, enum AVPixelFormat target)
894
0
{
895
0
    int i;
896
897
0
    for (i = 0; i < ((dstW + 1) >> 1); i++) {
898
0
        int j;
899
0
        int Y1 = 1 << 18;
900
0
        int Y2 = 1 << 18;
901
0
        int U  = 1 << 18;
902
0
        int V  = 1 << 18;
903
904
0
        for (j = 0; j < lumFilterSize; j++) {
905
0
            Y1 += lumSrc[j][i * 2]     * (unsigned)lumFilter[j];
906
0
            Y2 += lumSrc[j][i * 2 + 1] * (unsigned)lumFilter[j];
907
0
        }
908
0
        for (j = 0; j < chrFilterSize; j++) {
909
0
            U += chrUSrc[j][i] * (unsigned)chrFilter[j];
910
0
            V += chrVSrc[j][i] * (unsigned)chrFilter[j];
911
0
        }
912
0
        Y1 >>= 19;
913
0
        Y2 >>= 19;
914
0
        U  >>= 19;
915
0
        V  >>= 19;
916
0
        if ((Y1 | Y2 | U | V) & 0x100) {
917
0
            Y1 = av_clip_uint8(Y1);
918
0
            Y2 = av_clip_uint8(Y2);
919
0
            U  = av_clip_uint8(U);
920
0
            V  = av_clip_uint8(V);
921
0
        }
922
0
        output_pixels(4*i, Y1, U, Y2, V);
923
0
    }
924
0
}
925
926
static av_always_inline void
927
yuv2422_2_c_template(SwsInternal *c, const int16_t *buf[2],
928
                     const int16_t *ubuf[2], const int16_t *vbuf[2],
929
                     const int16_t *abuf[2], uint8_t *dest, int dstW,
930
                     int yalpha, int uvalpha, int y,
931
                     enum AVPixelFormat target)
932
0
{
933
0
    const int16_t *buf0  = buf[0],  *buf1  = buf[1],
934
0
                  *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
935
0
                  *vbuf0 = vbuf[0], *vbuf1 = vbuf[1];
936
0
    int  yalpha1 = 4096 - yalpha;
937
0
    int uvalpha1 = 4096 - uvalpha;
938
0
    int i;
939
0
    av_assert2(yalpha  <= 4096U);
940
0
    av_assert2(uvalpha <= 4096U);
941
942
0
    for (i = 0; i < ((dstW + 1) >> 1); i++) {
943
0
        int Y1 = (buf0[i * 2]     * yalpha1  + buf1[i * 2]     * yalpha)  >> 19;
944
0
        int Y2 = (buf0[i * 2 + 1] * yalpha1  + buf1[i * 2 + 1] * yalpha)  >> 19;
945
0
        int U  = (ubuf0[i]        * uvalpha1 + ubuf1[i]        * uvalpha) >> 19;
946
0
        int V  = (vbuf0[i]        * uvalpha1 + vbuf1[i]        * uvalpha) >> 19;
947
948
0
        if ((Y1 | Y2 | U | V) & 0x100) {
949
0
            Y1 = av_clip_uint8(Y1);
950
0
            Y2 = av_clip_uint8(Y2);
951
0
            U  = av_clip_uint8(U);
952
0
            V  = av_clip_uint8(V);
953
0
        }
954
955
0
        output_pixels(i * 4, Y1, U, Y2, V);
956
0
    }
957
0
}
958
959
static av_always_inline void
960
yuv2422_1_c_template(SwsInternal *c, const int16_t *buf0,
961
                     const int16_t *ubuf[2], const int16_t *vbuf[2],
962
                     const int16_t *abuf0, uint8_t *dest, int dstW,
963
                     int uvalpha, int y, enum AVPixelFormat target)
964
0
{
965
0
    const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
966
0
    int i;
967
968
0
    if (uvalpha < 2048) {
969
0
        for (i = 0; i < ((dstW + 1) >> 1); i++) {
970
0
            int Y1 = (buf0[i * 2    ]+64) >> 7;
971
0
            int Y2 = (buf0[i * 2 + 1]+64) >> 7;
972
0
            int U  = (ubuf0[i]       +64) >> 7;
973
0
            int V  = (vbuf0[i]       +64) >> 7;
974
975
0
            if ((Y1 | Y2 | U | V) & 0x100) {
976
0
                Y1 = av_clip_uint8(Y1);
977
0
                Y2 = av_clip_uint8(Y2);
978
0
                U  = av_clip_uint8(U);
979
0
                V  = av_clip_uint8(V);
980
0
            }
981
982
0
            output_pixels(i * 4, Y1, U, Y2, V);
983
0
        }
984
0
    } else {
985
0
        const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
986
0
        for (i = 0; i < ((dstW + 1) >> 1); i++) {
987
0
            int Y1 = (buf0[i * 2    ]    + 64) >> 7;
988
0
            int Y2 = (buf0[i * 2 + 1]    + 64) >> 7;
989
0
            int U  = (ubuf0[i] + ubuf1[i]+128) >> 8;
990
0
            int V  = (vbuf0[i] + vbuf1[i]+128) >> 8;
991
992
0
            if ((Y1 | Y2 | U | V) & 0x100) {
993
0
                Y1 = av_clip_uint8(Y1);
994
0
                Y2 = av_clip_uint8(Y2);
995
0
                U  = av_clip_uint8(U);
996
0
                V  = av_clip_uint8(V);
997
0
            }
998
999
0
            output_pixels(i * 4, Y1, U, Y2, V);
1000
0
        }
1001
0
    }
1002
0
}
1003
1004
#undef output_pixels
1005
1006
YUV2PACKEDWRAPPER(yuv2, 422, yuyv422, AV_PIX_FMT_YUYV422)
1007
YUV2PACKEDWRAPPER(yuv2, 422, yvyu422, AV_PIX_FMT_YVYU422)
1008
YUV2PACKEDWRAPPER(yuv2, 422, uyvy422, AV_PIX_FMT_UYVY422)
1009
1010
#define R_B ((target == AV_PIX_FMT_RGB48LE || target == AV_PIX_FMT_RGB48BE || target == AV_PIX_FMT_RGBA64LE || target == AV_PIX_FMT_RGBA64BE) ? R : B)
1011
#define B_R ((target == AV_PIX_FMT_RGB48LE || target == AV_PIX_FMT_RGB48BE || target == AV_PIX_FMT_RGBA64LE || target == AV_PIX_FMT_RGBA64BE) ? B : R)
1012
#define output_pixel(pos, val) \
1013
0
    if (is_be) { \
1014
0
        AV_WB16(pos, val); \
1015
0
    } else { \
1016
0
        AV_WL16(pos, val); \
1017
0
    }
1018
1019
static av_always_inline void
1020
yuv2ya16_X_c_template(SwsInternal *c, const int16_t *lumFilter,
1021
                        const int32_t **lumSrc, int lumFilterSize,
1022
                        const int16_t *chrFilter, const int32_t **unused_chrUSrc,
1023
                        const int32_t **unused_chrVSrc, int unused_chrFilterSize,
1024
                        const int32_t **alpSrc, uint16_t *dest, int dstW,
1025
                        int y, enum AVPixelFormat target,
1026
                        int unused_hasAlpha, int unused_eightbytes, int is_be)
1027
0
{
1028
0
    int hasAlpha = !!alpSrc;
1029
0
    int i;
1030
1031
0
    for (i = 0; i < dstW; i++) {
1032
0
        int j;
1033
0
        int Y = -0x40000000;
1034
0
        int A = 0xffff;
1035
1036
0
        for (j = 0; j < lumFilterSize; j++)
1037
0
            Y += lumSrc[j][i] * (unsigned)lumFilter[j];
1038
1039
0
        Y >>= 15;
1040
0
        Y += (1<<3) + 0x8000;
1041
0
        Y = av_clip_uint16(Y);
1042
1043
0
        if (hasAlpha) {
1044
0
            A = -0x40000000 + (1<<14);
1045
0
            for (j = 0; j < lumFilterSize; j++)
1046
0
                A += alpSrc[j][i] * (unsigned)lumFilter[j];
1047
1048
0
            A >>= 15;
1049
0
            A += 0x8000;
1050
0
            A = av_clip_uint16(A);
1051
0
        }
1052
1053
0
        output_pixel(&dest[2 * i    ], Y);
1054
0
        output_pixel(&dest[2 * i + 1], A);
1055
0
    }
1056
0
}
1057
1058
static av_always_inline void
1059
yuv2ya16_2_c_template(SwsInternal *c, const int32_t *buf[2],
1060
                        const int32_t *unused_ubuf[2], const int32_t *unused_vbuf[2],
1061
                        const int32_t *abuf[2], uint16_t *dest, int dstW,
1062
                        int yalpha_param, int unused_uvalpha, int y,
1063
                        enum AVPixelFormat target, int unused_hasAlpha,
1064
                        int unused_eightbytes, int is_be)
1065
0
{
1066
0
    unsigned  yalpha =  yalpha_param;
1067
0
    int hasAlpha = abuf && abuf[0] && abuf[1];
1068
0
    const int32_t *buf0  = buf[0],  *buf1  = buf[1],
1069
0
    *abuf0 = hasAlpha ? abuf[0] : NULL,
1070
0
    *abuf1 = hasAlpha ? abuf[1] : NULL;
1071
0
    unsigned  yalpha1 = 4096 - yalpha;
1072
0
    int i;
1073
1074
0
    av_assert2(yalpha  <= 4096U);
1075
1076
0
    for (i = 0; i < dstW; i++) {
1077
0
        int Y = (int)(buf0[i] * yalpha1 + buf1[i] * yalpha) >> 15;
1078
0
        int A;
1079
1080
0
        Y = av_clip_uint16(Y);
1081
1082
0
        if (hasAlpha) {
1083
0
            A = (int)(abuf0[i] * yalpha1 + abuf1[i] * yalpha) >> 15;
1084
0
            A = av_clip_uint16(A);
1085
0
        }
1086
1087
0
        output_pixel(&dest[2 * i    ], Y);
1088
0
        output_pixel(&dest[2 * i + 1], hasAlpha ? A : 65535);
1089
0
    }
1090
0
}
1091
1092
static av_always_inline void
1093
yuv2ya16_1_c_template(SwsInternal *c, const int32_t *buf0,
1094
                        const int32_t *unused_ubuf[2], const int32_t *unused_vbuf[2],
1095
                        const int32_t *abuf0, uint16_t *dest, int dstW,
1096
                        int unused_uvalpha, int y, enum AVPixelFormat target,
1097
                        int unused_hasAlpha, int unused_eightbytes, int is_be)
1098
0
{
1099
0
    int hasAlpha = !!abuf0;
1100
0
    int i;
1101
1102
0
    for (i = 0; i < dstW; i++) {
1103
0
        int Y = buf0[i] >> 3;/* 19 - 16 */
1104
0
        int A;
1105
1106
0
        Y = av_clip_uint16(Y);
1107
1108
0
        if (hasAlpha) {
1109
0
            A = abuf0[i] >> 3;
1110
0
            if (A & 0x100)
1111
0
                A = av_clip_uint16(A);
1112
0
        }
1113
1114
0
        output_pixel(&dest[2 * i    ], Y);
1115
0
        output_pixel(&dest[2 * i + 1], hasAlpha ? A : 65535);
1116
0
    }
1117
0
}
1118
1119
static av_always_inline void
1120
yuv2rgba64_X_c_template(SwsInternal *c, const int16_t *lumFilter,
1121
                       const int32_t **lumSrc, int lumFilterSize,
1122
                       const int16_t *chrFilter, const int32_t **chrUSrc,
1123
                       const int32_t **chrVSrc, int chrFilterSize,
1124
                       const int32_t **alpSrc, uint16_t *dest, int dstW,
1125
                       int y, enum AVPixelFormat target, int hasAlpha, int eightbytes,
1126
                       int is_be)
1127
0
{
1128
0
    int i;
1129
0
    int A1 = 0xffff<<14, A2 = 0xffff<<14;
1130
1131
0
    for (i = 0; i < ((dstW + 1) >> 1); i++) {
1132
0
        int j;
1133
0
        unsigned Y1 = -0x40000000;
1134
0
        unsigned Y2 = -0x40000000;
1135
0
        unsigned U  = -(128 << 23); // 19
1136
0
        unsigned V  = -(128 << 23);
1137
0
        int R, G, B;
1138
1139
0
        for (j = 0; j < lumFilterSize; j++) {
1140
0
            Y1 += lumSrc[j][i * 2]     * (unsigned)lumFilter[j];
1141
0
            Y2 += lumSrc[j][i * 2 + 1] * (unsigned)lumFilter[j];
1142
0
        }
1143
0
        for (j = 0; j < chrFilterSize; j++) {;
1144
0
            U += chrUSrc[j][i] * (unsigned)chrFilter[j];
1145
0
            V += chrVSrc[j][i] * (unsigned)chrFilter[j];
1146
0
        }
1147
1148
0
        if (hasAlpha) {
1149
0
            A1 = -0x40000000;
1150
0
            A2 = -0x40000000;
1151
0
            for (j = 0; j < lumFilterSize; j++) {
1152
0
                A1 += alpSrc[j][i * 2]     * (unsigned)lumFilter[j];
1153
0
                A2 += alpSrc[j][i * 2 + 1] * (unsigned)lumFilter[j];
1154
0
            }
1155
0
            A1 >>= 1;
1156
0
            A1 += 0x20002000;
1157
0
            A2 >>= 1;
1158
0
            A2 += 0x20002000;
1159
0
        }
1160
1161
        // 8 bits: 12+15=27; 16 bits: 12+19=31
1162
0
        Y1 = (int)Y1 >> 14; // 10
1163
0
        Y1 += 0x10000;
1164
0
        Y2 = (int)Y2 >> 14;
1165
0
        Y2 += 0x10000;
1166
0
        U  = (int)U >> 14;
1167
0
        V  = (int)V >> 14;
1168
1169
        // 8 bits: 27 -> 17 bits, 16 bits: 31 - 14 = 17 bits
1170
0
        Y1 -= c->yuv2rgb_y_offset;
1171
0
        Y2 -= c->yuv2rgb_y_offset;
1172
0
        Y1 *= c->yuv2rgb_y_coeff;
1173
0
        Y2 *= c->yuv2rgb_y_coeff;
1174
0
        Y1 += (1 << 13) - (1 << 29); // 21
1175
0
        Y2 += (1 << 13) - (1 << 29);
1176
        // 8 bits: 17 + 13 bits = 30 bits, 16 bits: 17 + 13 bits = 30 bits
1177
1178
0
        R = V * c->yuv2rgb_v2r_coeff;
1179
0
        G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
1180
0
        B =                            U * c->yuv2rgb_u2b_coeff;
1181
1182
        // 8 bits: 30 - 22 = 8 bits, 16 bits: 30 bits - 14 = 16 bits
1183
0
        output_pixel(&dest[0], av_clip_uintp2(((int)(R_B + Y1) >> 14) + (1<<15), 16));
1184
0
        output_pixel(&dest[1], av_clip_uintp2(((int)(  G + Y1) >> 14) + (1<<15), 16));
1185
0
        output_pixel(&dest[2], av_clip_uintp2(((int)(B_R + Y1) >> 14) + (1<<15), 16));
1186
0
        if (eightbytes) {
1187
0
            output_pixel(&dest[3], av_clip_uintp2(A1      , 30) >> 14);
1188
0
            output_pixel(&dest[4], av_clip_uintp2(((int)(R_B + Y2) >> 14) + (1<<15), 16));
1189
0
            output_pixel(&dest[5], av_clip_uintp2(((int)(  G + Y2) >> 14) + (1<<15), 16));
1190
0
            output_pixel(&dest[6], av_clip_uintp2(((int)(B_R + Y2) >> 14) + (1<<15), 16));
1191
0
            output_pixel(&dest[7], av_clip_uintp2(A2      , 30) >> 14);
1192
0
            dest += 8;
1193
0
        } else {
1194
0
            output_pixel(&dest[3], av_clip_uintp2(((int)(R_B + Y2) >> 14) + (1<<15), 16));
1195
0
            output_pixel(&dest[4], av_clip_uintp2(((int)(  G + Y2) >> 14) + (1<<15), 16));
1196
0
            output_pixel(&dest[5], av_clip_uintp2(((int)(B_R + Y2) >> 14) + (1<<15), 16));
1197
0
            dest += 6;
1198
0
        }
1199
0
    }
1200
0
}
1201
1202
static av_always_inline void
1203
yuv2rgba64_2_c_template(SwsInternal *c, const int32_t *buf[2],
1204
                       const int32_t *ubuf[2], const int32_t *vbuf[2],
1205
                       const int32_t *abuf[2], uint16_t *dest, int dstW,
1206
                       int yalpha_param, int uvalpha_param, int y,
1207
                       enum AVPixelFormat target, int hasAlpha, int eightbytes,
1208
                       int is_be)
1209
0
{
1210
0
    unsigned  yalpha =  yalpha_param;
1211
0
    unsigned uvalpha = uvalpha_param;
1212
0
    const int32_t *buf0  = buf[0],  *buf1  = buf[1],
1213
0
                  *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
1214
0
                  *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
1215
0
                  *abuf0 = hasAlpha ? abuf[0] : NULL,
1216
0
                  *abuf1 = hasAlpha ? abuf[1] : NULL;
1217
0
    unsigned  yalpha1 = 4096 - yalpha;
1218
0
    unsigned uvalpha1 = 4096 - uvalpha;
1219
0
    int i;
1220
0
    int A1 = 0xffff<<14, A2 = 0xffff<<14;
1221
1222
0
    av_assert2(yalpha  <= 4096U);
1223
0
    av_assert2(uvalpha <= 4096U);
1224
1225
0
    for (i = 0; i < ((dstW + 1) >> 1); i++) {
1226
0
        unsigned Y1 = (int)(buf0[i * 2]     * yalpha1  + buf1[i * 2]     * yalpha) >> 14;
1227
0
        unsigned Y2 = (int)(buf0[i * 2 + 1] * yalpha1  + buf1[i * 2 + 1] * yalpha) >> 14;
1228
0
        int U  = (int)(ubuf0[i]        * uvalpha1 + ubuf1[i]        * uvalpha - (128 << 23)) >> 14;
1229
0
        int V  = (int)(vbuf0[i]        * uvalpha1 + vbuf1[i]        * uvalpha - (128 << 23)) >> 14;
1230
0
        int R, G, B;
1231
1232
0
        Y1 -= c->yuv2rgb_y_offset;
1233
0
        Y2 -= c->yuv2rgb_y_offset;
1234
0
        Y1 *= c->yuv2rgb_y_coeff;
1235
0
        Y2 *= c->yuv2rgb_y_coeff;
1236
0
        Y1 += (1 << 13) - (1 << 29);
1237
0
        Y2 += (1 << 13) - (1 << 29);
1238
1239
0
        R = (SUINT)V * c->yuv2rgb_v2r_coeff;
1240
0
        G = (SUINT)V * c->yuv2rgb_v2g_coeff + (SUINT)U * c->yuv2rgb_u2g_coeff;
1241
0
        B =                                   (SUINT)U * c->yuv2rgb_u2b_coeff;
1242
1243
0
        if (hasAlpha) {
1244
0
            A1 = (int)(abuf0[i * 2    ] * yalpha1 + abuf1[i * 2    ] * yalpha) >> 1;
1245
0
            A2 = (int)(abuf0[i * 2 + 1] * yalpha1 + abuf1[i * 2 + 1] * yalpha) >> 1;
1246
1247
0
            A1 += 1 << 13;
1248
0
            A2 += 1 << 13;
1249
0
        }
1250
1251
0
        output_pixel(&dest[0], av_clip_uintp2(((int)(R_B + Y1) >> 14) + (1<<15), 16));
1252
0
        output_pixel(&dest[1], av_clip_uintp2(((int)(  G + Y1) >> 14) + (1<<15), 16));
1253
0
        output_pixel(&dest[2], av_clip_uintp2(((int)(B_R + Y1) >> 14) + (1<<15), 16));
1254
0
        if (eightbytes) {
1255
0
            output_pixel(&dest[3], av_clip_uintp2(A1      , 30) >> 14);
1256
0
            output_pixel(&dest[4], av_clip_uintp2(((int)(R_B + Y2) >> 14) + (1<<15), 16));
1257
0
            output_pixel(&dest[5], av_clip_uintp2(((int)(  G + Y2) >> 14) + (1<<15), 16));
1258
0
            output_pixel(&dest[6], av_clip_uintp2(((int)(B_R + Y2) >> 14) + (1<<15), 16));
1259
0
            output_pixel(&dest[7], av_clip_uintp2(A2      , 30) >> 14);
1260
0
            dest += 8;
1261
0
        } else {
1262
0
            output_pixel(&dest[3], av_clip_uintp2(((int)(R_B + Y2) >> 14) + (1<<15), 16));
1263
0
            output_pixel(&dest[4], av_clip_uintp2(((int)(  G + Y2) >> 14) + (1<<15), 16));
1264
0
            output_pixel(&dest[5], av_clip_uintp2(((int)(B_R + Y2) >> 14) + (1<<15), 16));
1265
0
            dest += 6;
1266
0
        }
1267
0
    }
1268
0
}
1269
1270
static av_always_inline void
1271
yuv2rgba64_1_c_template(SwsInternal *c, const int32_t *buf0,
1272
                       const int32_t *ubuf[2], const int32_t *vbuf[2],
1273
                       const int32_t *abuf0, uint16_t *dest, int dstW,
1274
                       int uvalpha, int y, enum AVPixelFormat target,
1275
                       int hasAlpha, int eightbytes, int is_be)
1276
0
{
1277
0
    const int32_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
1278
0
    int i;
1279
0
    SUINT A1 = 0xffff<<14, A2= 0xffff<<14;
1280
1281
0
    if (uvalpha == 0) {
1282
0
        for (i = 0; i < ((dstW + 1) >> 1); i++) {
1283
0
            SUINT Y1 = (buf0[i * 2]    ) >> 2;
1284
0
            SUINT Y2 = (buf0[i * 2 + 1]) >> 2;
1285
0
            SUINT U  = (ubuf0[i] - (128 << 11)) >> 2;
1286
0
            SUINT V  = (vbuf0[i] - (128 << 11)) >> 2;
1287
0
            int R, G, B;
1288
1289
0
            Y1 -= c->yuv2rgb_y_offset;
1290
0
            Y2 -= c->yuv2rgb_y_offset;
1291
0
            Y1 *= c->yuv2rgb_y_coeff;
1292
0
            Y2 *= c->yuv2rgb_y_coeff;
1293
0
            Y1 += (1 << 13) - (1 << 29);
1294
0
            Y2 += (1 << 13) - (1 << 29);
1295
1296
0
            if (hasAlpha) {
1297
0
                A1 = abuf0[i * 2    ] * (SUINT)(1 << 11);
1298
0
                A2 = abuf0[i * 2 + 1] * (SUINT)(1 << 11);
1299
1300
0
                A1 += 1 << 13;
1301
0
                A2 += 1 << 13;
1302
0
            }
1303
1304
0
            R = V * c->yuv2rgb_v2r_coeff;
1305
0
            G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
1306
0
            B =                            U * c->yuv2rgb_u2b_coeff;
1307
1308
0
            output_pixel(&dest[0], av_clip_uintp2(((int)(R_B + Y1) >> 14) + (1<<15), 16));
1309
0
            output_pixel(&dest[1], av_clip_uintp2(((int)(  G + Y1) >> 14) + (1<<15), 16));
1310
0
            output_pixel(&dest[2], av_clip_uintp2(((int)(B_R + Y1) >> 14) + (1<<15), 16));
1311
0
            if (eightbytes) {
1312
0
                output_pixel(&dest[3], av_clip_uintp2(A1      , 30) >> 14);
1313
0
                output_pixel(&dest[4], av_clip_uintp2(((int)(R_B + Y2) >> 14) + (1<<15), 16));
1314
0
                output_pixel(&dest[5], av_clip_uintp2(((int)(  G + Y2) >> 14) + (1<<15), 16));
1315
0
                output_pixel(&dest[6], av_clip_uintp2(((int)(B_R + Y2) >> 14) + (1<<15), 16));
1316
0
                output_pixel(&dest[7], av_clip_uintp2(A2      , 30) >> 14);
1317
0
                dest += 8;
1318
0
            } else {
1319
0
                output_pixel(&dest[3], av_clip_uintp2(((int)(R_B + Y2) >> 14) + (1<<15), 16));
1320
0
                output_pixel(&dest[4], av_clip_uintp2(((int)(  G + Y2) >> 14) + (1<<15), 16));
1321
0
                output_pixel(&dest[5], av_clip_uintp2(((int)(B_R + Y2) >> 14) + (1<<15), 16));
1322
0
                dest += 6;
1323
0
            }
1324
0
        }
1325
0
    } else {
1326
0
        const int32_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
1327
0
        SUINT A1 = 0xffff<<14, A2 = 0xffff<<14;
1328
0
        unsigned uvalpha1 = 4096 - uvalpha;
1329
0
        av_assert2(uvalpha <= 4096U);
1330
1331
0
        for (i = 0; i < ((dstW + 1) >> 1); i++) {
1332
0
            SUINT Y1 = (buf0[i * 2]    ) >> 2;
1333
0
            SUINT Y2 = (buf0[i * 2 + 1]) >> 2;
1334
0
            SUINT U = (int)((SUINT)ubuf0[i] * uvalpha1 + (SUINT)ubuf1[i] * uvalpha - (128 << 23)) >> 14;
1335
0
            SUINT V = (int)((SUINT)vbuf0[i] * uvalpha1 + (SUINT)vbuf1[i] * uvalpha - (128 << 23)) >> 14;
1336
0
            int R, G, B;
1337
1338
0
            Y1 -= c->yuv2rgb_y_offset;
1339
0
            Y2 -= c->yuv2rgb_y_offset;
1340
0
            Y1 *= c->yuv2rgb_y_coeff;
1341
0
            Y2 *= c->yuv2rgb_y_coeff;
1342
0
            Y1 += (1 << 13) - (1 << 29);
1343
0
            Y2 += (1 << 13) - (1 << 29);
1344
1345
0
            if (hasAlpha) {
1346
0
                A1 = abuf0[i * 2    ] * (SUINT)(1 << 11);
1347
0
                A2 = abuf0[i * 2 + 1] * (SUINT)(1 << 11);
1348
1349
0
                A1 += 1 << 13;
1350
0
                A2 += 1 << 13;
1351
0
            }
1352
1353
0
            R = V * c->yuv2rgb_v2r_coeff;
1354
0
            G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
1355
0
            B =                            U * c->yuv2rgb_u2b_coeff;
1356
1357
0
            output_pixel(&dest[0], av_clip_uintp2(((int)(R_B + Y1) >> 14) + (1<<15), 16));
1358
0
            output_pixel(&dest[1], av_clip_uintp2(((int)(  G + Y1) >> 14) + (1<<15), 16));
1359
0
            output_pixel(&dest[2], av_clip_uintp2(((int)(B_R + Y1) >> 14) + (1<<15), 16));
1360
0
            if (eightbytes) {
1361
0
                output_pixel(&dest[3], av_clip_uintp2(A1      , 30) >> 14);
1362
0
                output_pixel(&dest[4], av_clip_uintp2(((int)(R_B + Y2) >> 14) + (1<<15), 16));
1363
0
                output_pixel(&dest[5], av_clip_uintp2(((int)(  G + Y2) >> 14) + (1<<15), 16));
1364
0
                output_pixel(&dest[6], av_clip_uintp2(((int)(B_R + Y2) >> 14) + (1<<15), 16));
1365
0
                output_pixel(&dest[7], av_clip_uintp2(A2      , 30) >> 14);
1366
0
                dest += 8;
1367
0
            } else {
1368
0
                output_pixel(&dest[3], av_clip_uintp2(((int)(R_B + Y2) >> 14) + (1<<15), 16));
1369
0
                output_pixel(&dest[4], av_clip_uintp2(((int)(  G + Y2) >> 14) + (1<<15), 16));
1370
0
                output_pixel(&dest[5], av_clip_uintp2(((int)(B_R + Y2) >> 14) + (1<<15), 16));
1371
0
                dest += 6;
1372
0
            }
1373
0
        }
1374
0
    }
1375
0
}
1376
1377
static av_always_inline void
1378
yuv2rgba64_full_X_c_template(SwsInternal *c, const int16_t *lumFilter,
1379
                       const int32_t **lumSrc, int lumFilterSize,
1380
                       const int16_t *chrFilter, const int32_t **chrUSrc,
1381
                       const int32_t **chrVSrc, int chrFilterSize,
1382
                       const int32_t **alpSrc, uint16_t *dest, int dstW,
1383
                       int y, enum AVPixelFormat target, int hasAlpha,
1384
                       int eightbytes, int is_be)
1385
0
{
1386
0
    int i;
1387
0
    int A = 0xffff<<14;
1388
1389
0
    for (i = 0; i < dstW; i++) {
1390
0
        int j;
1391
0
        int Y  = -0x40000000;
1392
0
        int U  = -(128 << 23); // 19
1393
0
        int V  = -(128 << 23);
1394
0
        int R, G, B;
1395
1396
0
        for (j = 0; j < lumFilterSize; j++) {
1397
0
            Y += lumSrc[j][i]  * (unsigned)lumFilter[j];
1398
0
        }
1399
0
        for (j = 0; j < chrFilterSize; j++) {;
1400
0
            U += chrUSrc[j][i] * (unsigned)chrFilter[j];
1401
0
            V += chrVSrc[j][i] * (unsigned)chrFilter[j];
1402
0
        }
1403
1404
0
        if (hasAlpha) {
1405
0
            A = -0x40000000;
1406
0
            for (j = 0; j < lumFilterSize; j++) {
1407
0
                A += alpSrc[j][i] * (unsigned)lumFilter[j];
1408
0
            }
1409
0
            A >>= 1;
1410
0
            A += 0x20002000;
1411
0
        }
1412
1413
        // 8bit: 12+15=27; 16-bit: 12+19=31
1414
0
        Y  >>= 14; // 10
1415
0
        Y += 0x10000;
1416
0
        U  >>= 14;
1417
0
        V  >>= 14;
1418
1419
        // 8bit: 27 -> 17bit, 16bit: 31 - 14 = 17bit
1420
0
        Y -= c->yuv2rgb_y_offset;
1421
0
        Y *= c->yuv2rgb_y_coeff;
1422
0
        Y += (1 << 13) - (1<<29); // 21
1423
        // 8bit: 17 + 13bit = 30bit, 16bit: 17 + 13bit = 30bit
1424
1425
0
        R = (unsigned)V * c->yuv2rgb_v2r_coeff;
1426
0
        G = (unsigned)V * c->yuv2rgb_v2g_coeff + (unsigned)U * c->yuv2rgb_u2g_coeff;
1427
0
        B =                                      (unsigned)U * c->yuv2rgb_u2b_coeff;
1428
1429
        // 8bit: 30 - 22 = 8bit, 16bit: 30bit - 14 = 16bit
1430
0
        output_pixel(&dest[0], av_clip_uintp2(((int)(R_B + (unsigned)Y)>>14) + (1<<15), 16));
1431
0
        output_pixel(&dest[1], av_clip_uintp2(((int)(  G + (unsigned)Y)>>14) + (1<<15), 16));
1432
0
        output_pixel(&dest[2], av_clip_uintp2(((int)(B_R + (unsigned)Y)>>14) + (1<<15), 16));
1433
0
        if (eightbytes) {
1434
0
            output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
1435
0
            dest += 4;
1436
0
        } else {
1437
0
            dest += 3;
1438
0
        }
1439
0
    }
1440
0
}
1441
1442
static av_always_inline void
1443
yuv2rgba64_full_2_c_template(SwsInternal *c, const int32_t *buf[2],
1444
                       const int32_t *ubuf[2], const int32_t *vbuf[2],
1445
                       const int32_t *abuf[2], uint16_t *dest, int dstW,
1446
                       int yalpha_param, int uvalpha_param, int y,
1447
                       enum AVPixelFormat target, int hasAlpha, int eightbytes,
1448
                       int is_be)
1449
0
{
1450
0
    unsigned  yalpha =  yalpha_param;
1451
0
    unsigned uvalpha = uvalpha_param;
1452
0
    const int32_t *buf0  = buf[0],  *buf1  = buf[1],
1453
0
                  *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
1454
0
                  *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
1455
0
                  *abuf0 = hasAlpha ? abuf[0] : NULL,
1456
0
                  *abuf1 = hasAlpha ? abuf[1] : NULL;
1457
0
    unsigned  yalpha1 = 4096 - yalpha;
1458
0
    unsigned uvalpha1 = 4096 - uvalpha;
1459
0
    int i;
1460
0
    int A = 0xffff<<14;
1461
1462
0
    av_assert2(yalpha  <= 4096U);
1463
0
    av_assert2(uvalpha <= 4096U);
1464
1465
0
    for (i = 0; i < dstW; i++) {
1466
0
        unsigned Y  = (int)(buf0[i]     * yalpha1  + buf1[i]     * yalpha) >> 14;
1467
0
        unsigned U  = (int)(ubuf0[i]   * uvalpha1 + ubuf1[i]     * uvalpha - (128 << 23)) >> 14;
1468
0
        unsigned V  = (int)(vbuf0[i]   * uvalpha1 + vbuf1[i]     * uvalpha - (128 << 23)) >> 14;
1469
0
        int R, G, B;
1470
1471
0
        Y -= c->yuv2rgb_y_offset;
1472
0
        Y *= c->yuv2rgb_y_coeff;
1473
0
        Y += (1 << 13) - (1 << 29);
1474
1475
0
        R = V * c->yuv2rgb_v2r_coeff;
1476
0
        G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
1477
0
        B =                            U * c->yuv2rgb_u2b_coeff;
1478
1479
0
        if (hasAlpha) {
1480
0
            A = (int)(abuf0[i] * yalpha1 + abuf1[i] * yalpha) >> 1;
1481
1482
0
            A += 1 << 13;
1483
0
        }
1484
1485
0
        output_pixel(&dest[0], av_clip_uintp2(((int)(R_B + Y) >> 14) + (1<<15), 16));
1486
0
        output_pixel(&dest[1], av_clip_uintp2(((int)(  G + Y) >> 14) + (1<<15), 16));
1487
0
        output_pixel(&dest[2], av_clip_uintp2(((int)(B_R + Y) >> 14) + (1<<15), 16));
1488
0
        if (eightbytes) {
1489
0
            output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
1490
0
            dest += 4;
1491
0
        } else {
1492
0
            dest += 3;
1493
0
        }
1494
0
    }
1495
0
}
1496
1497
static av_always_inline void
1498
yuv2rgba64_full_1_c_template(SwsInternal *c, const int32_t *buf0,
1499
                       const int32_t *ubuf[2], const int32_t *vbuf[2],
1500
                       const int32_t *abuf0, uint16_t *dest, int dstW,
1501
                       int uvalpha, int y, enum AVPixelFormat target,
1502
                       int hasAlpha, int eightbytes, int is_be)
1503
0
{
1504
0
    const int32_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
1505
0
    int i;
1506
0
    SUINT A = 0xffff<<14;
1507
1508
0
    if (uvalpha == 0) {
1509
0
        for (i = 0; i < dstW; i++) {
1510
0
            SUINT Y  = (buf0[i]) >> 2;
1511
0
            SUINT U  = (ubuf0[i] - (128 << 11)) >> 2;
1512
0
            SUINT V  = (vbuf0[i] - (128 << 11)) >> 2;
1513
0
            int R, G, B;
1514
1515
0
            Y -= c->yuv2rgb_y_offset;
1516
0
            Y *= c->yuv2rgb_y_coeff;
1517
0
            Y += (1 << 13) - (1 << 29);
1518
1519
0
            if (hasAlpha) {
1520
0
                A = abuf0[i] * (SUINT)(1 << 11);
1521
1522
0
                A += 1 << 13;
1523
0
            }
1524
1525
0
            R = V * c->yuv2rgb_v2r_coeff;
1526
0
            G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
1527
0
            B =                            U * c->yuv2rgb_u2b_coeff;
1528
1529
0
            output_pixel(&dest[0], av_clip_uintp2(((int)(R_B + Y) >> 14) + (1<<15), 16));
1530
0
            output_pixel(&dest[1], av_clip_uintp2(((int)(  G + Y) >> 14) + (1<<15), 16));
1531
0
            output_pixel(&dest[2], av_clip_uintp2(((int)(B_R + Y) >> 14) + (1<<15), 16));
1532
0
            if (eightbytes) {
1533
0
                output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
1534
0
                dest += 4;
1535
0
            } else {
1536
0
                dest += 3;
1537
0
            }
1538
0
        }
1539
0
    } else {
1540
0
        const int32_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
1541
0
        unsigned uvalpha1 = 4096 - uvalpha;
1542
0
        SUINT A = 0xffff<<14;
1543
0
        av_assert2(uvalpha <= 4096U);
1544
1545
0
        for (i = 0; i < dstW; i++) {
1546
0
            SUINT Y  = (buf0[i]    ) >> 2;
1547
0
            SUINT U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha - (128 << 23)) >> 14;
1548
0
            SUINT V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha - (128 << 23)) >> 14;
1549
0
            int R, G, B;
1550
1551
0
            Y -= c->yuv2rgb_y_offset;
1552
0
            Y *= c->yuv2rgb_y_coeff;
1553
0
            Y += (1 << 13) - (1 << 29);
1554
1555
0
            if (hasAlpha) {
1556
0
                A = abuf0[i] * (SUINT)(1 << 11);
1557
1558
0
                A += 1 << 13;
1559
0
            }
1560
1561
0
            R = V * c->yuv2rgb_v2r_coeff;
1562
0
            G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
1563
0
            B =                            U * c->yuv2rgb_u2b_coeff;
1564
1565
0
            output_pixel(&dest[0], av_clip_uintp2(((int)(R_B + Y) >> 14) + (1<<15), 16));
1566
0
            output_pixel(&dest[1], av_clip_uintp2(((int)(  G + Y) >> 14) + (1<<15), 16));
1567
0
            output_pixel(&dest[2], av_clip_uintp2(((int)(B_R + Y) >> 14) + (1<<15), 16));
1568
0
            if (eightbytes) {
1569
0
                output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
1570
0
                dest += 4;
1571
0
            } else {
1572
0
                dest += 3;
1573
0
            }
1574
0
        }
1575
0
    }
1576
0
}
1577
1578
#undef output_pixel
1579
#undef r_b
1580
#undef b_r
1581
1582
#define YUV2PACKED16WRAPPER_EXT(name, base, ext, fmt, is_be, hasAlpha, eightbytes) \
1583
static void name ## ext ## _X_c(SwsInternal *c, const int16_t *lumFilter, \
1584
                        const int16_t **_lumSrc, int lumFilterSize, \
1585
                        const int16_t *chrFilter, const int16_t **_chrUSrc, \
1586
                        const int16_t **_chrVSrc, int chrFilterSize, \
1587
                        const int16_t **_alpSrc, uint8_t *_dest, int dstW, \
1588
0
                        int y) \
1589
0
{ \
1590
0
    const int32_t **lumSrc  = (const int32_t **) _lumSrc, \
1591
0
                  **chrUSrc = (const int32_t **) _chrUSrc, \
1592
0
                  **chrVSrc = (const int32_t **) _chrVSrc, \
1593
0
                  **alpSrc  = (const int32_t **) _alpSrc; \
1594
0
    uint16_t *dest = (uint16_t *) _dest; \
1595
0
    name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
1596
0
                          chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
1597
0
                          alpSrc, dest, dstW, y, fmt, hasAlpha, eightbytes, is_be); \
1598
0
} \
Unexecuted instantiation: output.c:yuv2rgba64le_full_X_c
Unexecuted instantiation: output.c:yuv2rgbx64le_full_X_c
Unexecuted instantiation: output.c:yuv2rgba64be_full_X_c
Unexecuted instantiation: output.c:yuv2rgbx64be_full_X_c
Unexecuted instantiation: output.c:yuv2bgra64le_full_X_c
Unexecuted instantiation: output.c:yuv2bgrx64le_full_X_c
Unexecuted instantiation: output.c:yuv2bgra64be_full_X_c
Unexecuted instantiation: output.c:yuv2bgrx64be_full_X_c
Unexecuted instantiation: output.c:yuv2rgb48le_full_X_c
Unexecuted instantiation: output.c:yuv2bgr48le_full_X_c
Unexecuted instantiation: output.c:yuv2rgb48be_full_X_c
Unexecuted instantiation: output.c:yuv2bgr48be_full_X_c
Unexecuted instantiation: output.c:yuv2rgba64le_X_c
Unexecuted instantiation: output.c:yuv2rgbx64le_X_c
Unexecuted instantiation: output.c:yuv2rgba64be_X_c
Unexecuted instantiation: output.c:yuv2rgbx64be_X_c
Unexecuted instantiation: output.c:yuv2bgra64le_X_c
Unexecuted instantiation: output.c:yuv2bgrx64le_X_c
Unexecuted instantiation: output.c:yuv2bgra64be_X_c
Unexecuted instantiation: output.c:yuv2bgrx64be_X_c
Unexecuted instantiation: output.c:yuv2rgb48le_X_c
Unexecuted instantiation: output.c:yuv2rgb48be_X_c
Unexecuted instantiation: output.c:yuv2bgr48le_X_c
Unexecuted instantiation: output.c:yuv2bgr48be_X_c
Unexecuted instantiation: output.c:yuv2ya16le_X_c
Unexecuted instantiation: output.c:yuv2ya16be_X_c
1599
 \
1600
static void name ## ext ## _2_c(SwsInternal *c, const int16_t *_buf[2], \
1601
                        const int16_t *_ubuf[2], const int16_t *_vbuf[2], \
1602
                        const int16_t *_abuf[2], uint8_t *_dest, int dstW, \
1603
0
                        int yalpha, int uvalpha, int y) \
1604
0
{ \
1605
0
    const int32_t **buf  = (const int32_t **) _buf, \
1606
0
                  **ubuf = (const int32_t **) _ubuf, \
1607
0
                  **vbuf = (const int32_t **) _vbuf, \
1608
0
                  **abuf = (const int32_t **) _abuf; \
1609
0
    uint16_t *dest = (uint16_t *) _dest; \
1610
0
    name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
1611
0
                          dest, dstW, yalpha, uvalpha, y, fmt, hasAlpha, eightbytes, is_be); \
1612
0
} \
Unexecuted instantiation: output.c:yuv2rgba64le_full_2_c
Unexecuted instantiation: output.c:yuv2rgbx64le_full_2_c
Unexecuted instantiation: output.c:yuv2rgba64be_full_2_c
Unexecuted instantiation: output.c:yuv2rgbx64be_full_2_c
Unexecuted instantiation: output.c:yuv2bgra64le_full_2_c
Unexecuted instantiation: output.c:yuv2bgrx64le_full_2_c
Unexecuted instantiation: output.c:yuv2bgra64be_full_2_c
Unexecuted instantiation: output.c:yuv2bgrx64be_full_2_c
Unexecuted instantiation: output.c:yuv2rgb48le_full_2_c
Unexecuted instantiation: output.c:yuv2bgr48le_full_2_c
Unexecuted instantiation: output.c:yuv2rgb48be_full_2_c
Unexecuted instantiation: output.c:yuv2bgr48be_full_2_c
Unexecuted instantiation: output.c:yuv2rgba64le_2_c
Unexecuted instantiation: output.c:yuv2rgbx64le_2_c
Unexecuted instantiation: output.c:yuv2rgba64be_2_c
Unexecuted instantiation: output.c:yuv2rgbx64be_2_c
Unexecuted instantiation: output.c:yuv2bgra64le_2_c
Unexecuted instantiation: output.c:yuv2bgrx64le_2_c
Unexecuted instantiation: output.c:yuv2bgra64be_2_c
Unexecuted instantiation: output.c:yuv2bgrx64be_2_c
Unexecuted instantiation: output.c:yuv2rgb48le_2_c
Unexecuted instantiation: output.c:yuv2rgb48be_2_c
Unexecuted instantiation: output.c:yuv2bgr48le_2_c
Unexecuted instantiation: output.c:yuv2bgr48be_2_c
Unexecuted instantiation: output.c:yuv2ya16le_2_c
Unexecuted instantiation: output.c:yuv2ya16be_2_c
1613
 \
1614
static void name ## ext ## _1_c(SwsInternal *c, const int16_t *_buf0, \
1615
                        const int16_t *_ubuf[2], const int16_t *_vbuf[2], \
1616
                        const int16_t *_abuf0, uint8_t *_dest, int dstW, \
1617
0
                        int uvalpha, int y) \
1618
0
{ \
1619
0
    const int32_t *buf0  = (const int32_t *)  _buf0, \
1620
0
                 **ubuf  = (const int32_t **) _ubuf, \
1621
0
                 **vbuf  = (const int32_t **) _vbuf, \
1622
0
                  *abuf0 = (const int32_t *)  _abuf0; \
1623
0
    uint16_t *dest = (uint16_t *) _dest; \
1624
0
    name ## base ## _1_c_template(c, buf0, ubuf, vbuf, abuf0, dest, \
1625
0
                                  dstW, uvalpha, y, fmt, hasAlpha, eightbytes, is_be); \
1626
0
}
Unexecuted instantiation: output.c:yuv2rgba64le_full_1_c
Unexecuted instantiation: output.c:yuv2rgbx64le_full_1_c
Unexecuted instantiation: output.c:yuv2rgba64be_full_1_c
Unexecuted instantiation: output.c:yuv2rgbx64be_full_1_c
Unexecuted instantiation: output.c:yuv2bgra64le_full_1_c
Unexecuted instantiation: output.c:yuv2bgrx64le_full_1_c
Unexecuted instantiation: output.c:yuv2bgra64be_full_1_c
Unexecuted instantiation: output.c:yuv2bgrx64be_full_1_c
Unexecuted instantiation: output.c:yuv2rgb48le_full_1_c
Unexecuted instantiation: output.c:yuv2bgr48le_full_1_c
Unexecuted instantiation: output.c:yuv2rgb48be_full_1_c
Unexecuted instantiation: output.c:yuv2bgr48be_full_1_c
Unexecuted instantiation: output.c:yuv2rgba64le_1_c
Unexecuted instantiation: output.c:yuv2rgbx64le_1_c
Unexecuted instantiation: output.c:yuv2rgba64be_1_c
Unexecuted instantiation: output.c:yuv2rgbx64be_1_c
Unexecuted instantiation: output.c:yuv2bgra64le_1_c
Unexecuted instantiation: output.c:yuv2bgrx64le_1_c
Unexecuted instantiation: output.c:yuv2bgra64be_1_c
Unexecuted instantiation: output.c:yuv2bgrx64be_1_c
Unexecuted instantiation: output.c:yuv2rgb48le_1_c
Unexecuted instantiation: output.c:yuv2rgb48be_1_c
Unexecuted instantiation: output.c:yuv2bgr48le_1_c
Unexecuted instantiation: output.c:yuv2bgr48be_1_c
Unexecuted instantiation: output.c:yuv2ya16le_1_c
Unexecuted instantiation: output.c:yuv2ya16be_1_c
1627
#define YUV2PACKED16WRAPPER(name, base, ext, base_fmt, endianness, hasAlpha, eightbytes) \
1628
    YUV2PACKED16WRAPPER_EXT(name, base, ext, base_fmt ## endianness, IS_BE(endianness), hasAlpha, eightbytes)
1629
1630
YUV2PACKED16WRAPPER(yuv2, rgba64, rgb48be, AV_PIX_FMT_RGB48, BE, 0, 0)
1631
YUV2PACKED16WRAPPER(yuv2, rgba64, rgb48le, AV_PIX_FMT_RGB48, LE, 0, 0)
1632
YUV2PACKED16WRAPPER(yuv2, rgba64, bgr48be, AV_PIX_FMT_BGR48, BE, 0, 0)
1633
YUV2PACKED16WRAPPER(yuv2, rgba64, bgr48le, AV_PIX_FMT_BGR48, LE, 0, 0)
1634
YUV2PACKED16WRAPPER(yuv2, rgba64, rgba64be, AV_PIX_FMT_RGBA64, BE, 1, 1)
1635
YUV2PACKED16WRAPPER(yuv2, rgba64, rgba64le, AV_PIX_FMT_RGBA64, LE, 1, 1)
1636
YUV2PACKED16WRAPPER(yuv2, rgba64, rgbx64be, AV_PIX_FMT_RGBA64, BE, 0, 1)
1637
YUV2PACKED16WRAPPER(yuv2, rgba64, rgbx64le, AV_PIX_FMT_RGBA64, LE, 0, 1)
1638
YUV2PACKED16WRAPPER(yuv2, rgba64, bgra64be, AV_PIX_FMT_BGRA64, BE, 1, 1)
1639
YUV2PACKED16WRAPPER(yuv2, rgba64, bgra64le, AV_PIX_FMT_BGRA64, LE, 1, 1)
1640
YUV2PACKED16WRAPPER(yuv2, rgba64, bgrx64be, AV_PIX_FMT_BGRA64, BE, 0, 1)
1641
YUV2PACKED16WRAPPER(yuv2, rgba64, bgrx64le, AV_PIX_FMT_BGRA64, LE, 0, 1)
1642
YUV2PACKED16WRAPPER(yuv2, ya16, ya16be, AV_PIX_FMT_YA16, BE, 1, 0)
1643
YUV2PACKED16WRAPPER(yuv2, ya16, ya16le, AV_PIX_FMT_YA16, LE, 1, 0)
1644
1645
YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgb48be_full, AV_PIX_FMT_RGB48, BE, 0, 0)
1646
YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgb48le_full, AV_PIX_FMT_RGB48, LE, 0, 0)
1647
YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgr48be_full, AV_PIX_FMT_BGR48, BE, 0, 0)
1648
YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgr48le_full, AV_PIX_FMT_BGR48, LE, 0, 0)
1649
YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgba64be_full, AV_PIX_FMT_RGBA64, BE, 1, 1)
1650
YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgba64le_full, AV_PIX_FMT_RGBA64, LE, 1, 1)
1651
YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgbx64be_full, AV_PIX_FMT_RGBA64, BE, 0, 1)
1652
YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgbx64le_full, AV_PIX_FMT_RGBA64, LE, 0, 1)
1653
YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgra64be_full, AV_PIX_FMT_BGRA64, BE, 1, 1)
1654
YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgra64le_full, AV_PIX_FMT_BGRA64, LE, 1, 1)
1655
YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgrx64be_full, AV_PIX_FMT_BGRA64, BE, 0, 1)
1656
YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgrx64le_full, AV_PIX_FMT_BGRA64, LE, 0, 1)
1657
1658
/*
1659
 * Write out 2 RGB pixels in the target pixel format. This function takes a
1660
 * R/G/B LUT as generated by ff_yuv2rgb_c_init_tables(), which takes care of
1661
 * things like endianness conversion and shifting. The caller takes care of
1662
 * setting the correct offset in these tables from the chroma (U/V) values.
1663
 * This function then uses the luminance (Y1/Y2) values to write out the
1664
 * correct RGB values into the destination buffer.
1665
 */
1666
static av_always_inline void
1667
yuv2rgb_write(uint8_t *_dest, int i, int Y1, int Y2,
1668
              unsigned A1, unsigned A2,
1669
              const void *_r, const void *_g, const void *_b, int y,
1670
              enum AVPixelFormat target, int hasAlpha)
1671
0
{
1672
0
    if (target == AV_PIX_FMT_ARGB || target == AV_PIX_FMT_RGBA ||
1673
0
        target == AV_PIX_FMT_ABGR || target == AV_PIX_FMT_BGRA) {
1674
0
        uint32_t *dest = (uint32_t *) _dest;
1675
0
        const uint32_t *r = (const uint32_t *) _r;
1676
0
        const uint32_t *g = (const uint32_t *) _g;
1677
0
        const uint32_t *b = (const uint32_t *) _b;
1678
1679
#if CONFIG_SMALL
1680
        int sh = hasAlpha ? ((target == AV_PIX_FMT_RGB32_1 || target == AV_PIX_FMT_BGR32_1) ? 0 : 24) : 0;
1681
1682
        dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1] + (hasAlpha ? A1 << sh : 0);
1683
        dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2] + (hasAlpha ? A2 << sh : 0);
1684
#else
1685
0
        if (hasAlpha) {
1686
0
            int sh = (target == AV_PIX_FMT_RGB32_1 || target == AV_PIX_FMT_BGR32_1) ? 0 : 24;
1687
1688
0
            av_assert2((((r[Y1] + g[Y1] + b[Y1]) >> sh) & 0xFF) == 0);
1689
0
            dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1] + (A1 << sh);
1690
0
            dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2] + (A2 << sh);
1691
0
        } else {
1692
#if defined(ASSERT_LEVEL) && ASSERT_LEVEL > 1
1693
            int sh = (target == AV_PIX_FMT_RGB32_1 || target == AV_PIX_FMT_BGR32_1) ? 0 : 24;
1694
1695
            av_assert2((((r[Y1] + g[Y1] + b[Y1]) >> sh) & 0xFF) == 0xFF);
1696
#endif
1697
0
            dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1];
1698
0
            dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2];
1699
0
        }
1700
0
#endif
1701
0
    } else if (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) {
1702
0
        uint8_t *dest = (uint8_t *) _dest;
1703
0
        const uint8_t *r = (const uint8_t *) _r;
1704
0
        const uint8_t *g = (const uint8_t *) _g;
1705
0
        const uint8_t *b = (const uint8_t *) _b;
1706
1707
0
#define r_b ((target == AV_PIX_FMT_RGB24) ? r : b)
1708
0
#define b_r ((target == AV_PIX_FMT_RGB24) ? b : r)
1709
1710
0
        dest[i * 6 + 0] = r_b[Y1];
1711
0
        dest[i * 6 + 1] =   g[Y1];
1712
0
        dest[i * 6 + 2] = b_r[Y1];
1713
0
        dest[i * 6 + 3] = r_b[Y2];
1714
0
        dest[i * 6 + 4] =   g[Y2];
1715
0
        dest[i * 6 + 5] = b_r[Y2];
1716
0
#undef r_b
1717
0
#undef b_r
1718
0
    } else if (target == AV_PIX_FMT_RGB565 || target == AV_PIX_FMT_BGR565 ||
1719
0
               target == AV_PIX_FMT_RGB555 || target == AV_PIX_FMT_BGR555 ||
1720
0
               target == AV_PIX_FMT_RGB444 || target == AV_PIX_FMT_BGR444) {
1721
0
        uint16_t *dest = (uint16_t *) _dest;
1722
0
        const uint16_t *r = (const uint16_t *) _r;
1723
0
        const uint16_t *g = (const uint16_t *) _g;
1724
0
        const uint16_t *b = (const uint16_t *) _b;
1725
0
        int dr1, dg1, db1, dr2, dg2, db2;
1726
1727
0
        if (target == AV_PIX_FMT_RGB565 || target == AV_PIX_FMT_BGR565) {
1728
0
            dr1 = ff_dither_2x2_8[ y & 1     ][0];
1729
0
            dg1 = ff_dither_2x2_4[ y & 1     ][0];
1730
0
            db1 = ff_dither_2x2_8[(y & 1) ^ 1][0];
1731
0
            dr2 = ff_dither_2x2_8[ y & 1     ][1];
1732
0
            dg2 = ff_dither_2x2_4[ y & 1     ][1];
1733
0
            db2 = ff_dither_2x2_8[(y & 1) ^ 1][1];
1734
0
        } else if (target == AV_PIX_FMT_RGB555 || target == AV_PIX_FMT_BGR555) {
1735
0
            dr1 = ff_dither_2x2_8[ y & 1     ][0];
1736
0
            dg1 = ff_dither_2x2_8[ y & 1     ][1];
1737
0
            db1 = ff_dither_2x2_8[(y & 1) ^ 1][0];
1738
0
            dr2 = ff_dither_2x2_8[ y & 1     ][1];
1739
0
            dg2 = ff_dither_2x2_8[ y & 1     ][0];
1740
0
            db2 = ff_dither_2x2_8[(y & 1) ^ 1][1];
1741
0
        } else {
1742
0
            dr1 = ff_dither_4x4_16[ y & 3     ][0];
1743
0
            dg1 = ff_dither_4x4_16[ y & 3     ][1];
1744
0
            db1 = ff_dither_4x4_16[(y & 3) ^ 3][0];
1745
0
            dr2 = ff_dither_4x4_16[ y & 3     ][1];
1746
0
            dg2 = ff_dither_4x4_16[ y & 3     ][0];
1747
0
            db2 = ff_dither_4x4_16[(y & 3) ^ 3][1];
1748
0
        }
1749
1750
0
        dest[i * 2 + 0] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1];
1751
0
        dest[i * 2 + 1] = r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2];
1752
0
    } else if (target == AV_PIX_FMT_X2RGB10 || target == AV_PIX_FMT_X2BGR10) {
1753
0
        uint32_t *dest = (uint32_t *) _dest;
1754
0
        const uint32_t *r = (const uint32_t *) _r;
1755
0
        const uint32_t *g = (const uint32_t *) _g;
1756
0
        const uint32_t *b = (const uint32_t *) _b;
1757
0
        dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1];
1758
0
        dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2];
1759
0
    } else /* 8/4 bits */ {
1760
0
        uint8_t *dest = (uint8_t *) _dest;
1761
0
        const uint8_t *r = (const uint8_t *) _r;
1762
0
        const uint8_t *g = (const uint8_t *) _g;
1763
0
        const uint8_t *b = (const uint8_t *) _b;
1764
0
        int dr1, dg1, db1, dr2, dg2, db2;
1765
1766
0
        if (target == AV_PIX_FMT_RGB8 || target == AV_PIX_FMT_BGR8) {
1767
0
            const uint8_t * const d64 = ff_dither_8x8_73[y & 7];
1768
0
            const uint8_t * const d32 = ff_dither_8x8_32[y & 7];
1769
0
            dr1 = dg1 = d32[(i * 2 + 0) & 7];
1770
0
            db1 =       d64[(i * 2 + 0) & 7];
1771
0
            dr2 = dg2 = d32[(i * 2 + 1) & 7];
1772
0
            db2 =       d64[(i * 2 + 1) & 7];
1773
0
        } else {
1774
0
            const uint8_t * const d64  = ff_dither_8x8_73 [y & 7];
1775
0
            const uint8_t * const d128 = ff_dither_8x8_220[y & 7];
1776
0
            dr1 = db1 = d128[(i * 2 + 0) & 7];
1777
0
            dg1 =        d64[(i * 2 + 0) & 7];
1778
0
            dr2 = db2 = d128[(i * 2 + 1) & 7];
1779
0
            dg2 =        d64[(i * 2 + 1) & 7];
1780
0
        }
1781
1782
0
        if (target == AV_PIX_FMT_RGB4 || target == AV_PIX_FMT_BGR4) {
1783
0
            dest[i] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1] +
1784
0
                    ((r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2]) << 4);
1785
0
        } else {
1786
0
            dest[i * 2 + 0] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1];
1787
0
            dest[i * 2 + 1] = r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2];
1788
0
        }
1789
0
    }
1790
0
}
1791
1792
static av_always_inline void
1793
yuv2rgb_X_c_template(SwsInternal *c, const int16_t *lumFilter,
1794
                     const int16_t **lumSrc, int lumFilterSize,
1795
                     const int16_t *chrFilter, const int16_t **chrUSrc,
1796
                     const int16_t **chrVSrc, int chrFilterSize,
1797
                     const int16_t **alpSrc, uint8_t *dest, int dstW,
1798
                     int y, enum AVPixelFormat target, int hasAlpha)
1799
0
{
1800
0
    int i;
1801
1802
0
    for (i = 0; i < ((dstW + 1) >> 1); i++) {
1803
0
        int j, A1, A2;
1804
0
        int Y1 = 1 << 18;
1805
0
        int Y2 = 1 << 18;
1806
0
        int U  = 1 << 18;
1807
0
        int V  = 1 << 18;
1808
0
        const void *r, *g, *b;
1809
1810
0
        for (j = 0; j < lumFilterSize; j++) {
1811
0
            Y1 += lumSrc[j][i * 2]     * (unsigned)lumFilter[j];
1812
0
            Y2 += lumSrc[j][i * 2 + 1] * (unsigned)lumFilter[j];
1813
0
        }
1814
0
        for (j = 0; j < chrFilterSize; j++) {
1815
0
            U += chrUSrc[j][i] * (unsigned)chrFilter[j];
1816
0
            V += chrVSrc[j][i] * (unsigned)chrFilter[j];
1817
0
        }
1818
0
        Y1 >>= 19;
1819
0
        Y2 >>= 19;
1820
0
        U  >>= 19;
1821
0
        V  >>= 19;
1822
0
        if (hasAlpha) {
1823
0
            A1 = 1 << 18;
1824
0
            A2 = 1 << 18;
1825
0
            for (j = 0; j < lumFilterSize; j++) {
1826
0
                A1 += alpSrc[j][i * 2    ] * (unsigned)lumFilter[j];
1827
0
                A2 += alpSrc[j][i * 2 + 1] * (unsigned)lumFilter[j];
1828
0
            }
1829
0
            A1 >>= 19;
1830
0
            A2 >>= 19;
1831
0
            if ((A1 | A2) & 0x100) {
1832
0
                A1 = av_clip_uint8(A1);
1833
0
                A2 = av_clip_uint8(A2);
1834
0
            }
1835
0
        }
1836
1837
0
        r =  c->table_rV[V + YUVRGB_TABLE_HEADROOM];
1838
0
        g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]);
1839
0
        b =  c->table_bU[U + YUVRGB_TABLE_HEADROOM];
1840
1841
0
        yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
1842
0
                      r, g, b, y, target, hasAlpha);
1843
0
    }
1844
0
}
1845
1846
static av_always_inline void
1847
yuv2rgb_2_c_template(SwsInternal *c, const int16_t *buf[2],
1848
                     const int16_t *ubuf[2], const int16_t *vbuf[2],
1849
                     const int16_t *abuf[2], uint8_t *dest, int dstW,
1850
                     int yalpha, int uvalpha, int y,
1851
                     enum AVPixelFormat target, int hasAlpha)
1852
0
{
1853
0
    const int16_t *buf0  = buf[0],  *buf1  = buf[1],
1854
0
                  *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
1855
0
                  *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
1856
0
                  *abuf0 = hasAlpha ? abuf[0] : NULL,
1857
0
                  *abuf1 = hasAlpha ? abuf[1] : NULL;
1858
0
    int  yalpha1 = 4096 - yalpha;
1859
0
    int uvalpha1 = 4096 - uvalpha;
1860
0
    int i;
1861
0
    av_assert2(yalpha  <= 4096U);
1862
0
    av_assert2(uvalpha <= 4096U);
1863
1864
0
    for (i = 0; i < ((dstW + 1) >> 1); i++) {
1865
0
        int Y1 = (buf0[i * 2]     * yalpha1  + buf1[i * 2]     * yalpha)  >> 19;
1866
0
        int Y2 = (buf0[i * 2 + 1] * yalpha1  + buf1[i * 2 + 1] * yalpha)  >> 19;
1867
0
        int U  = (ubuf0[i]        * uvalpha1 + ubuf1[i]        * uvalpha) >> 19;
1868
0
        int V  = (vbuf0[i]        * uvalpha1 + vbuf1[i]        * uvalpha) >> 19;
1869
0
        int A1, A2;
1870
0
        const void *r =  c->table_rV[V + YUVRGB_TABLE_HEADROOM],
1871
0
                   *g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]),
1872
0
                   *b =  c->table_bU[U + YUVRGB_TABLE_HEADROOM];
1873
1874
0
        if (hasAlpha) {
1875
0
            A1 = (abuf0[i * 2    ] * yalpha1 + abuf1[i * 2    ] * yalpha) >> 19;
1876
0
            A2 = (abuf0[i * 2 + 1] * yalpha1 + abuf1[i * 2 + 1] * yalpha) >> 19;
1877
0
            A1 = av_clip_uint8(A1);
1878
0
            A2 = av_clip_uint8(A2);
1879
0
        }
1880
1881
0
        yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
1882
0
                      r, g, b, y, target, hasAlpha);
1883
0
    }
1884
0
}
1885
1886
static av_always_inline void
1887
yuv2rgb_1_c_template(SwsInternal *c, const int16_t *buf0,
1888
                     const int16_t *ubuf[2], const int16_t *vbuf[2],
1889
                     const int16_t *abuf0, uint8_t *dest, int dstW,
1890
                     int uvalpha, int y, enum AVPixelFormat target,
1891
                     int hasAlpha)
1892
0
{
1893
0
    const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
1894
0
    int i;
1895
1896
0
    if (uvalpha == 0) {
1897
0
        for (i = 0; i < ((dstW + 1) >> 1); i++) {
1898
0
            int Y1 = (buf0[i * 2    ] + 64) >> 7;
1899
0
            int Y2 = (buf0[i * 2 + 1] + 64) >> 7;
1900
0
            int U  = (ubuf0[i]        + 64) >> 7;
1901
0
            int V  = (vbuf0[i]        + 64) >> 7;
1902
0
            int A1, A2;
1903
0
            const void *r =  c->table_rV[V + YUVRGB_TABLE_HEADROOM],
1904
0
                       *g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]),
1905
0
                       *b =  c->table_bU[U + YUVRGB_TABLE_HEADROOM];
1906
1907
0
            if (hasAlpha) {
1908
0
                A1 = abuf0[i * 2    ] * 255 + 16384 >> 15;
1909
0
                A2 = abuf0[i * 2 + 1] * 255 + 16384 >> 15;
1910
0
                A1 = av_clip_uint8(A1);
1911
0
                A2 = av_clip_uint8(A2);
1912
0
            }
1913
1914
0
            yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
1915
0
                          r, g, b, y, target, hasAlpha);
1916
0
        }
1917
0
    } else {
1918
0
        const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
1919
0
        int uvalpha1 = 4096 - uvalpha;
1920
0
        av_assert2(uvalpha <= 4096U);
1921
1922
0
        for (i = 0; i < ((dstW + 1) >> 1); i++) {
1923
0
            int Y1 = (buf0[i * 2    ]     +  64) >> 7;
1924
0
            int Y2 = (buf0[i * 2 + 1]     +  64) >> 7;
1925
0
            int U  = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha + (128 << 11)) >> 19;
1926
0
            int V  = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha + (128 << 11)) >> 19;
1927
0
            int A1, A2;
1928
0
            const void *r =  c->table_rV[V + YUVRGB_TABLE_HEADROOM],
1929
0
                       *g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]),
1930
0
                       *b =  c->table_bU[U + YUVRGB_TABLE_HEADROOM];
1931
1932
0
            if (hasAlpha) {
1933
0
                A1 = (abuf0[i * 2    ] + 64) >> 7;
1934
0
                A2 = (abuf0[i * 2 + 1] + 64) >> 7;
1935
0
                A1 = av_clip_uint8(A1);
1936
0
                A2 = av_clip_uint8(A2);
1937
0
            }
1938
1939
0
            yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
1940
0
                          r, g, b, y, target, hasAlpha);
1941
0
        }
1942
0
    }
1943
0
}
1944
1945
#define YUV2RGBWRAPPERX(name, base, ext, fmt, hasAlpha) \
1946
static void name ## ext ## _X_c(SwsInternal *c, const int16_t *lumFilter, \
1947
                                const int16_t **lumSrc, int lumFilterSize, \
1948
                                const int16_t *chrFilter, const int16_t **chrUSrc, \
1949
                                const int16_t **chrVSrc, int chrFilterSize, \
1950
                                const int16_t **alpSrc, uint8_t *dest, int dstW, \
1951
0
                                int y) \
1952
0
{ \
1953
0
    name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
1954
0
                                  chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
1955
0
                                  alpSrc, dest, dstW, y, fmt, hasAlpha); \
1956
0
}
Unexecuted instantiation: output.c:yuv2rgba32_full_X_c
Unexecuted instantiation: output.c:yuv2rgbx32_full_X_c
Unexecuted instantiation: output.c:yuv2argb32_full_X_c
Unexecuted instantiation: output.c:yuv2xrgb32_full_X_c
Unexecuted instantiation: output.c:yuv2bgra32_full_X_c
Unexecuted instantiation: output.c:yuv2bgrx32_full_X_c
Unexecuted instantiation: output.c:yuv2abgr32_full_X_c
Unexecuted instantiation: output.c:yuv2xbgr32_full_X_c
Unexecuted instantiation: output.c:yuv2rgb24_full_X_c
Unexecuted instantiation: output.c:yuv2bgr24_full_X_c
Unexecuted instantiation: output.c:yuv2bgr4_byte_full_X_c
Unexecuted instantiation: output.c:yuv2rgb4_byte_full_X_c
Unexecuted instantiation: output.c:yuv2bgr8_full_X_c
Unexecuted instantiation: output.c:yuv2rgb8_full_X_c
Unexecuted instantiation: output.c:yuv2x2rgb10_full_X_c
Unexecuted instantiation: output.c:yuv2x2bgr10_full_X_c
Unexecuted instantiation: output.c:yuv2rgba32_X_c
Unexecuted instantiation: output.c:yuv2rgbx32_X_c
Unexecuted instantiation: output.c:yuv2rgba32_1_X_c
Unexecuted instantiation: output.c:yuv2rgbx32_1_X_c
Unexecuted instantiation: output.c:yuv2rgb24_X_c
Unexecuted instantiation: output.c:yuv2bgr24_X_c
Unexecuted instantiation: output.c:yuv2rgb16_X_c
Unexecuted instantiation: output.c:yuv2rgb15_X_c
Unexecuted instantiation: output.c:yuv2rgb12_X_c
Unexecuted instantiation: output.c:yuv2rgb8_X_c
Unexecuted instantiation: output.c:yuv2rgb4_X_c
Unexecuted instantiation: output.c:yuv2rgb4b_X_c
Unexecuted instantiation: output.c:yuv2x2rgb10_X_c
Unexecuted instantiation: output.c:yuv2x2bgr10_X_c
1957
1958
#define YUV2RGBWRAPPERX2(name, base, ext, fmt, hasAlpha) \
1959
YUV2RGBWRAPPERX(name, base, ext, fmt, hasAlpha) \
1960
static void name ## ext ## _2_c(SwsInternal *c, const int16_t *buf[2], \
1961
                                const int16_t *ubuf[2], const int16_t *vbuf[2], \
1962
                                const int16_t *abuf[2], uint8_t *dest, int dstW, \
1963
0
                                int yalpha, int uvalpha, int y) \
1964
0
{ \
1965
0
    name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
1966
0
                                  dest, dstW, yalpha, uvalpha, y, fmt, hasAlpha); \
1967
0
}
Unexecuted instantiation: output.c:yuv2rgba32_full_2_c
Unexecuted instantiation: output.c:yuv2rgbx32_full_2_c
Unexecuted instantiation: output.c:yuv2argb32_full_2_c
Unexecuted instantiation: output.c:yuv2xrgb32_full_2_c
Unexecuted instantiation: output.c:yuv2bgra32_full_2_c
Unexecuted instantiation: output.c:yuv2bgrx32_full_2_c
Unexecuted instantiation: output.c:yuv2abgr32_full_2_c
Unexecuted instantiation: output.c:yuv2xbgr32_full_2_c
Unexecuted instantiation: output.c:yuv2rgb24_full_2_c
Unexecuted instantiation: output.c:yuv2bgr24_full_2_c
Unexecuted instantiation: output.c:yuv2bgr4_byte_full_2_c
Unexecuted instantiation: output.c:yuv2rgb4_byte_full_2_c
Unexecuted instantiation: output.c:yuv2bgr8_full_2_c
Unexecuted instantiation: output.c:yuv2rgb8_full_2_c
Unexecuted instantiation: output.c:yuv2x2rgb10_full_2_c
Unexecuted instantiation: output.c:yuv2x2bgr10_full_2_c
Unexecuted instantiation: output.c:yuv2rgba32_2_c
Unexecuted instantiation: output.c:yuv2rgbx32_2_c
Unexecuted instantiation: output.c:yuv2rgba32_1_2_c
Unexecuted instantiation: output.c:yuv2rgbx32_1_2_c
Unexecuted instantiation: output.c:yuv2rgb24_2_c
Unexecuted instantiation: output.c:yuv2bgr24_2_c
Unexecuted instantiation: output.c:yuv2rgb16_2_c
Unexecuted instantiation: output.c:yuv2rgb15_2_c
Unexecuted instantiation: output.c:yuv2rgb12_2_c
Unexecuted instantiation: output.c:yuv2rgb8_2_c
Unexecuted instantiation: output.c:yuv2rgb4_2_c
Unexecuted instantiation: output.c:yuv2rgb4b_2_c
Unexecuted instantiation: output.c:yuv2x2rgb10_2_c
Unexecuted instantiation: output.c:yuv2x2bgr10_2_c
1968
1969
#define YUV2RGBWRAPPER(name, base, ext, fmt, hasAlpha) \
1970
YUV2RGBWRAPPERX2(name, base, ext, fmt, hasAlpha) \
1971
static void name ## ext ## _1_c(SwsInternal *c, const int16_t *buf0, \
1972
                                const int16_t *ubuf[2], const int16_t *vbuf[2], \
1973
                                const int16_t *abuf0, uint8_t *dest, int dstW, \
1974
0
                                int uvalpha, int y) \
1975
0
{ \
1976
0
    name ## base ## _1_c_template(c, buf0, ubuf, vbuf, abuf0, dest, \
1977
0
                                  dstW, uvalpha, y, fmt, hasAlpha); \
1978
0
}
Unexecuted instantiation: output.c:yuv2rgba32_full_1_c
Unexecuted instantiation: output.c:yuv2rgbx32_full_1_c
Unexecuted instantiation: output.c:yuv2argb32_full_1_c
Unexecuted instantiation: output.c:yuv2xrgb32_full_1_c
Unexecuted instantiation: output.c:yuv2bgra32_full_1_c
Unexecuted instantiation: output.c:yuv2bgrx32_full_1_c
Unexecuted instantiation: output.c:yuv2abgr32_full_1_c
Unexecuted instantiation: output.c:yuv2xbgr32_full_1_c
Unexecuted instantiation: output.c:yuv2rgb24_full_1_c
Unexecuted instantiation: output.c:yuv2bgr24_full_1_c
Unexecuted instantiation: output.c:yuv2bgr4_byte_full_1_c
Unexecuted instantiation: output.c:yuv2rgb4_byte_full_1_c
Unexecuted instantiation: output.c:yuv2bgr8_full_1_c
Unexecuted instantiation: output.c:yuv2rgb8_full_1_c
Unexecuted instantiation: output.c:yuv2x2rgb10_full_1_c
Unexecuted instantiation: output.c:yuv2x2bgr10_full_1_c
Unexecuted instantiation: output.c:yuv2rgba32_1_c
Unexecuted instantiation: output.c:yuv2rgbx32_1_c
Unexecuted instantiation: output.c:yuv2rgba32_1_1_c
Unexecuted instantiation: output.c:yuv2rgbx32_1_1_c
Unexecuted instantiation: output.c:yuv2rgb24_1_c
Unexecuted instantiation: output.c:yuv2bgr24_1_c
Unexecuted instantiation: output.c:yuv2rgb16_1_c
Unexecuted instantiation: output.c:yuv2rgb15_1_c
Unexecuted instantiation: output.c:yuv2rgb12_1_c
Unexecuted instantiation: output.c:yuv2rgb8_1_c
Unexecuted instantiation: output.c:yuv2rgb4_1_c
Unexecuted instantiation: output.c:yuv2rgb4b_1_c
Unexecuted instantiation: output.c:yuv2x2rgb10_1_c
Unexecuted instantiation: output.c:yuv2x2bgr10_1_c
1979
1980
#if CONFIG_SMALL
1981
YUV2RGBWRAPPER(yuv2rgb,,  32_1,  AV_PIX_FMT_RGB32_1,   CONFIG_SWSCALE_ALPHA && c->needAlpha)
1982
YUV2RGBWRAPPER(yuv2rgb,,  32,    AV_PIX_FMT_RGB32,     CONFIG_SWSCALE_ALPHA && c->needAlpha)
1983
#else
1984
#if CONFIG_SWSCALE_ALPHA
1985
YUV2RGBWRAPPER(yuv2rgb,, a32_1,  AV_PIX_FMT_RGB32_1,   1)
1986
YUV2RGBWRAPPER(yuv2rgb,, a32,    AV_PIX_FMT_RGB32,     1)
1987
#endif
1988
YUV2RGBWRAPPER(yuv2rgb,, x32_1,  AV_PIX_FMT_RGB32_1,   0)
1989
YUV2RGBWRAPPER(yuv2rgb,, x32,    AV_PIX_FMT_RGB32,     0)
1990
#endif
1991
YUV2RGBWRAPPER(yuv2, rgb, rgb24, AV_PIX_FMT_RGB24,   0)
1992
YUV2RGBWRAPPER(yuv2, rgb, bgr24, AV_PIX_FMT_BGR24,   0)
1993
YUV2RGBWRAPPER(yuv2rgb,,  16,    AV_PIX_FMT_RGB565,    0)
1994
YUV2RGBWRAPPER(yuv2rgb,,  15,    AV_PIX_FMT_RGB555,    0)
1995
YUV2RGBWRAPPER(yuv2rgb,,  12,    AV_PIX_FMT_RGB444,    0)
1996
YUV2RGBWRAPPER(yuv2rgb,,   8,    AV_PIX_FMT_RGB8,      0)
1997
YUV2RGBWRAPPER(yuv2rgb,,   4,    AV_PIX_FMT_RGB4,      0)
1998
YUV2RGBWRAPPER(yuv2rgb,,   4b,   AV_PIX_FMT_RGB4_BYTE, 0)
1999
YUV2RGBWRAPPER(yuv2, rgb, x2rgb10, AV_PIX_FMT_X2RGB10, 0)
2000
YUV2RGBWRAPPER(yuv2, rgb, x2bgr10, AV_PIX_FMT_X2BGR10, 0)
2001
2002
static av_always_inline void yuv2rgb_write_full(SwsInternal *c,
2003
    uint8_t *dest, int i, int Y, int A, int U, int V,
2004
    int y, enum AVPixelFormat target, int hasAlpha, int err[4])
2005
0
{
2006
0
    int R, G, B;
2007
0
    int isrgb8 = target == AV_PIX_FMT_BGR8 || target == AV_PIX_FMT_RGB8;
2008
2009
0
    Y -= c->yuv2rgb_y_offset;
2010
0
    Y *= (unsigned)c->yuv2rgb_y_coeff;
2011
0
    Y += 1U << 21;
2012
0
    R = (unsigned)Y + V*(unsigned)c->yuv2rgb_v2r_coeff;
2013
0
    G = (unsigned)Y + V*(unsigned)c->yuv2rgb_v2g_coeff + U*(unsigned)c->yuv2rgb_u2g_coeff;
2014
0
    B = (unsigned)Y +                                    U*(unsigned)c->yuv2rgb_u2b_coeff;
2015
0
    if ((R | G | B) & 0xC0000000) {
2016
0
        R = av_clip_uintp2(R, 30);
2017
0
        G = av_clip_uintp2(G, 30);
2018
0
        B = av_clip_uintp2(B, 30);
2019
0
    }
2020
2021
0
    switch(target) {
2022
0
    case AV_PIX_FMT_ARGB:
2023
0
        dest[0] = hasAlpha ? A : 255;
2024
0
        dest[1] = R >> 22;
2025
0
        dest[2] = G >> 22;
2026
0
        dest[3] = B >> 22;
2027
0
        break;
2028
0
    case AV_PIX_FMT_RGB24:
2029
0
        dest[0] = R >> 22;
2030
0
        dest[1] = G >> 22;
2031
0
        dest[2] = B >> 22;
2032
0
        break;
2033
0
    case AV_PIX_FMT_RGBA:
2034
0
        dest[0] = R >> 22;
2035
0
        dest[1] = G >> 22;
2036
0
        dest[2] = B >> 22;
2037
0
        dest[3] = hasAlpha ? A : 255;
2038
0
        break;
2039
0
    case AV_PIX_FMT_ABGR:
2040
0
        dest[0] = hasAlpha ? A : 255;
2041
0
        dest[1] = B >> 22;
2042
0
        dest[2] = G >> 22;
2043
0
        dest[3] = R >> 22;
2044
0
        break;
2045
0
    case AV_PIX_FMT_BGR24:
2046
0
        dest[0] = B >> 22;
2047
0
        dest[1] = G >> 22;
2048
0
        dest[2] = R >> 22;
2049
0
        break;
2050
0
    case AV_PIX_FMT_BGRA:
2051
0
        dest[0] = B >> 22;
2052
0
        dest[1] = G >> 22;
2053
0
        dest[2] = R >> 22;
2054
0
        dest[3] = hasAlpha ? A : 255;
2055
0
        break;
2056
0
    case AV_PIX_FMT_X2RGB10LE:
2057
0
        R >>= 20;
2058
0
        G >>= 20;
2059
0
        B >>= 20;
2060
0
        AV_WL32(dest, (3U << 30) + (R << 20) + (G << 10) + B);
2061
0
        break;
2062
0
    case AV_PIX_FMT_X2BGR10LE:
2063
0
        R >>= 20;
2064
0
        G >>= 20;
2065
0
        B >>= 20;
2066
0
        AV_WL32(dest, (3U << 30) + (B << 20) + (G << 10) + R);
2067
0
        break;
2068
0
    case AV_PIX_FMT_BGR4_BYTE:
2069
0
    case AV_PIX_FMT_RGB4_BYTE:
2070
0
    case AV_PIX_FMT_BGR8:
2071
0
    case AV_PIX_FMT_RGB8:
2072
0
    {
2073
0
        int r,g,b;
2074
2075
0
        switch (c->opts.dither) {
2076
0
        case SWS_DITHER_NONE:
2077
0
            if (isrgb8) {
2078
0
                r = av_clip_uintp2(R >> 27, 3);
2079
0
                g = av_clip_uintp2(G >> 27, 3);
2080
0
                b = av_clip_uintp2(B >> 28, 2);
2081
0
            } else {
2082
0
                r = av_clip_uintp2(R >> 29, 1);
2083
0
                g = av_clip_uintp2(G >> 28, 2);
2084
0
                b = av_clip_uintp2(B >> 29, 1);
2085
0
            }
2086
0
            break;
2087
0
        default:
2088
0
        case SWS_DITHER_AUTO:
2089
0
        case SWS_DITHER_ED:
2090
0
            R >>= 22;
2091
0
            G >>= 22;
2092
0
            B >>= 22;
2093
0
            R += (7*err[0] + 1*c->dither_error[0][i] + 5*c->dither_error[0][i+1] + 3*c->dither_error[0][i+2])>>4;
2094
0
            G += (7*err[1] + 1*c->dither_error[1][i] + 5*c->dither_error[1][i+1] + 3*c->dither_error[1][i+2])>>4;
2095
0
            B += (7*err[2] + 1*c->dither_error[2][i] + 5*c->dither_error[2][i+1] + 3*c->dither_error[2][i+2])>>4;
2096
0
            c->dither_error[0][i] = err[0];
2097
0
            c->dither_error[1][i] = err[1];
2098
0
            c->dither_error[2][i] = err[2];
2099
0
            r = R >> (isrgb8 ? 5 : 7);
2100
0
            g = G >> (isrgb8 ? 5 : 6);
2101
0
            b = B >> (isrgb8 ? 6 : 7);
2102
0
            r = av_clip(r, 0, isrgb8 ? 7 : 1);
2103
0
            g = av_clip(g, 0, isrgb8 ? 7 : 3);
2104
0
            b = av_clip(b, 0, isrgb8 ? 3 : 1);
2105
0
            err[0] = R - r*(isrgb8 ? 36 : 255);
2106
0
            err[1] = G - g*(isrgb8 ? 36 : 85);
2107
0
            err[2] = B - b*(isrgb8 ? 85 : 255);
2108
0
            break;
2109
0
        case SWS_DITHER_A_DITHER:
2110
0
            if (isrgb8) {
2111
  /* see http://pippin.gimp.org/a_dither/ for details/origin */
2112
0
#define A_DITHER(u,v)   (((((u)+((v)*236))*119)&0xff))
2113
0
                r = (((R >> 19) + A_DITHER(i,y)  -96)>>8);
2114
0
                g = (((G >> 19) + A_DITHER(i + 17,y) - 96)>>8);
2115
0
                b = (((B >> 20) + A_DITHER(i + 17*2,y) -96)>>8);
2116
0
                r = av_clip_uintp2(r, 3);
2117
0
                g = av_clip_uintp2(g, 3);
2118
0
                b = av_clip_uintp2(b, 2);
2119
0
            } else {
2120
0
                r = (((R >> 21) + A_DITHER(i,y)-256)>>8);
2121
0
                g = (((G >> 19) + A_DITHER(i + 17,y)-256)>>8);
2122
0
                b = (((B >> 21) + A_DITHER(i + 17*2,y)-256)>>8);
2123
0
                r = av_clip_uintp2(r, 1);
2124
0
                g = av_clip_uintp2(g, 2);
2125
0
                b = av_clip_uintp2(b, 1);
2126
0
            }
2127
0
            break;
2128
0
        case SWS_DITHER_X_DITHER:
2129
0
            if (isrgb8) {
2130
  /* see http://pippin.gimp.org/a_dither/ for details/origin */
2131
0
#define X_DITHER(u,v)   (((((u)^((v)*237))*181)&0x1ff)/2)
2132
0
                r = (((R >> 19) + X_DITHER(i,y) - 96)>>8);
2133
0
                g = (((G >> 19) + X_DITHER(i + 17,y) - 96)>>8);
2134
0
                b = (((B >> 20) + X_DITHER(i + 17*2,y) - 96)>>8);
2135
0
                r = av_clip_uintp2(r, 3);
2136
0
                g = av_clip_uintp2(g, 3);
2137
0
                b = av_clip_uintp2(b, 2);
2138
0
            } else {
2139
0
                r = (((R >> 21) + X_DITHER(i,y)-256)>>8);
2140
0
                g = (((G >> 19) + X_DITHER(i + 17,y)-256)>>8);
2141
0
                b = (((B >> 21) + X_DITHER(i + 17*2,y)-256)>>8);
2142
0
                r = av_clip_uintp2(r, 1);
2143
0
                g = av_clip_uintp2(g, 2);
2144
0
                b = av_clip_uintp2(b, 1);
2145
0
            }
2146
2147
0
            break;
2148
0
        }
2149
2150
0
        if(target == AV_PIX_FMT_BGR4_BYTE) {
2151
0
            dest[0] = r + 2*g + 8*b;
2152
0
        } else if(target == AV_PIX_FMT_RGB4_BYTE) {
2153
0
            dest[0] = b + 2*g + 8*r;
2154
0
        } else if(target == AV_PIX_FMT_BGR8) {
2155
0
            dest[0] = r + 8*g + 64*b;
2156
0
        } else if(target == AV_PIX_FMT_RGB8) {
2157
0
            dest[0] = b + 4*g + 32*r;
2158
0
        } else
2159
0
            av_assert2(0);
2160
0
        break;}
2161
0
    }
2162
0
}
2163
2164
static av_always_inline void
2165
yuv2rgb_full_X_c_template(SwsInternal *c, const int16_t *lumFilter,
2166
                          const int16_t **lumSrc, int lumFilterSize,
2167
                          const int16_t *chrFilter, const int16_t **chrUSrc,
2168
                          const int16_t **chrVSrc, int chrFilterSize,
2169
                          const int16_t **alpSrc, uint8_t *dest,
2170
                          int dstW, int y, enum AVPixelFormat target, int hasAlpha)
2171
0
{
2172
0
    int i;
2173
0
    int step = (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) ? 3 : 4;
2174
0
    int err[4] = {0};
2175
0
    int A = 0; //init to silence warning
2176
2177
0
    if(   target == AV_PIX_FMT_BGR4_BYTE || target == AV_PIX_FMT_RGB4_BYTE
2178
0
       || target == AV_PIX_FMT_BGR8      || target == AV_PIX_FMT_RGB8)
2179
0
        step = 1;
2180
2181
0
    for (i = 0; i < dstW; i++) {
2182
0
        int j;
2183
0
        int Y = 1<<9;
2184
0
        int U = (1<<9)-(128 << 19);
2185
0
        int V = (1<<9)-(128 << 19);
2186
2187
0
        for (j = 0; j < lumFilterSize; j++) {
2188
0
            Y += lumSrc[j][i] * (unsigned)lumFilter[j];
2189
0
        }
2190
0
        for (j = 0; j < chrFilterSize; j++) {
2191
0
            U += chrUSrc[j][i] * (unsigned)chrFilter[j];
2192
0
            V += chrVSrc[j][i] * (unsigned)chrFilter[j];
2193
0
        }
2194
0
        Y >>= 10;
2195
0
        U >>= 10;
2196
0
        V >>= 10;
2197
0
        if (hasAlpha) {
2198
0
            A = 1 << 18;
2199
0
            for (j = 0; j < lumFilterSize; j++) {
2200
0
                A += alpSrc[j][i] * (unsigned)lumFilter[j];
2201
0
            }
2202
0
            A >>= 19;
2203
0
            if (A & 0x100)
2204
0
                A = av_clip_uint8(A);
2205
0
        }
2206
0
        yuv2rgb_write_full(c, dest, i, Y, A, U, V, y, target, hasAlpha, err);
2207
0
        dest += step;
2208
0
    }
2209
0
    c->dither_error[0][i] = err[0];
2210
0
    c->dither_error[1][i] = err[1];
2211
0
    c->dither_error[2][i] = err[2];
2212
0
}
2213
2214
static av_always_inline void
2215
yuv2rgb_full_2_c_template(SwsInternal *c, const int16_t *buf[2],
2216
                     const int16_t *ubuf[2], const int16_t *vbuf[2],
2217
                     const int16_t *abuf[2], uint8_t *dest, int dstW,
2218
                     int yalpha, int uvalpha, int y,
2219
                     enum AVPixelFormat target, int hasAlpha)
2220
0
{
2221
0
    const int16_t *buf0  = buf[0],  *buf1  = buf[1],
2222
0
                  *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
2223
0
                  *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
2224
0
                  *abuf0 = hasAlpha ? abuf[0] : NULL,
2225
0
                  *abuf1 = hasAlpha ? abuf[1] : NULL;
2226
0
    int  yalpha1 = 4096 - yalpha;
2227
0
    int uvalpha1 = 4096 - uvalpha;
2228
0
    int i;
2229
0
    int step = (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) ? 3 : 4;
2230
0
    int err[4] = {0};
2231
0
    int A = 0; // init to silcene warning
2232
2233
0
    av_assert2(yalpha  <= 4096U);
2234
0
    av_assert2(uvalpha <= 4096U);
2235
2236
0
    if(   target == AV_PIX_FMT_BGR4_BYTE || target == AV_PIX_FMT_RGB4_BYTE
2237
0
       || target == AV_PIX_FMT_BGR8      || target == AV_PIX_FMT_RGB8)
2238
0
        step = 1;
2239
2240
0
    for (i = 0; i < dstW; i++) {
2241
0
        int Y = ( buf0[i] * yalpha1  +  buf1[i] * yalpha             ) >> 10; //FIXME rounding
2242
0
        int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha-(128 << 19)) >> 10;
2243
0
        int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha-(128 << 19)) >> 10;
2244
2245
0
        if (hasAlpha) {
2246
0
            A = (abuf0[i] * yalpha1 + abuf1[i] * yalpha + (1<<18)) >> 19;
2247
0
            if (A & 0x100)
2248
0
                A = av_clip_uint8(A);
2249
0
        }
2250
2251
0
        yuv2rgb_write_full(c, dest, i, Y, A, U, V, y, target, hasAlpha, err);
2252
0
        dest += step;
2253
0
    }
2254
0
    c->dither_error[0][i] = err[0];
2255
0
    c->dither_error[1][i] = err[1];
2256
0
    c->dither_error[2][i] = err[2];
2257
0
}
2258
2259
static av_always_inline void
2260
yuv2rgb_full_1_c_template(SwsInternal *c, const int16_t *buf0,
2261
                     const int16_t *ubuf[2], const int16_t *vbuf[2],
2262
                     const int16_t *abuf0, uint8_t *dest, int dstW,
2263
                     int uvalpha, int y, enum AVPixelFormat target,
2264
                     int hasAlpha)
2265
0
{
2266
0
    const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
2267
0
    int i;
2268
0
    int step = (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) ? 3 : 4;
2269
0
    int err[4] = {0};
2270
2271
0
    if(   target == AV_PIX_FMT_BGR4_BYTE || target == AV_PIX_FMT_RGB4_BYTE
2272
0
       || target == AV_PIX_FMT_BGR8      || target == AV_PIX_FMT_RGB8)
2273
0
        step = 1;
2274
2275
0
    if (uvalpha == 0) {
2276
0
        int A = 0; //init to silence warning
2277
0
        for (i = 0; i < dstW; i++) {
2278
0
            int Y = buf0[i] * 4;
2279
0
            int U = (ubuf0[i] - (128<<7)) * 4;
2280
0
            int V = (vbuf0[i] - (128<<7)) * 4;
2281
2282
0
            if (hasAlpha) {
2283
0
                A = (abuf0[i] + 64) >> 7;
2284
0
                if (A & 0x100)
2285
0
                    A = av_clip_uint8(A);
2286
0
            }
2287
2288
0
            yuv2rgb_write_full(c, dest, i, Y, A, U, V, y, target, hasAlpha, err);
2289
0
            dest += step;
2290
0
        }
2291
0
    } else {
2292
0
        const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
2293
0
        int A = 0; //init to silence warning
2294
0
        int uvalpha1 = 4096 - uvalpha;
2295
0
        av_assert2(uvalpha <= 4096U);
2296
2297
0
        for (i = 0; i < dstW; i++) {
2298
0
            int Y = buf0[i] * 4;
2299
0
            int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha - (128 << 19)) >> 10;
2300
0
            int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha - (128 << 19)) >> 10;
2301
2302
0
            if (hasAlpha) {
2303
0
                A = (abuf0[i] + 64) >> 7;
2304
0
                if (A & 0x100)
2305
0
                    A = av_clip_uint8(A);
2306
0
            }
2307
2308
0
            yuv2rgb_write_full(c, dest, i, Y, A, U, V, y, target, hasAlpha, err);
2309
0
            dest += step;
2310
0
        }
2311
0
    }
2312
2313
0
    c->dither_error[0][i] = err[0];
2314
0
    c->dither_error[1][i] = err[1];
2315
0
    c->dither_error[2][i] = err[2];
2316
0
}
2317
2318
#if CONFIG_SMALL
2319
YUV2RGBWRAPPER(yuv2, rgb_full, bgra32_full, AV_PIX_FMT_BGRA,  CONFIG_SWSCALE_ALPHA && c->needAlpha)
2320
YUV2RGBWRAPPER(yuv2, rgb_full, abgr32_full, AV_PIX_FMT_ABGR,  CONFIG_SWSCALE_ALPHA && c->needAlpha)
2321
YUV2RGBWRAPPER(yuv2, rgb_full, rgba32_full, AV_PIX_FMT_RGBA,  CONFIG_SWSCALE_ALPHA && c->needAlpha)
2322
YUV2RGBWRAPPER(yuv2, rgb_full, argb32_full, AV_PIX_FMT_ARGB,  CONFIG_SWSCALE_ALPHA && c->needAlpha)
2323
#else
2324
#if CONFIG_SWSCALE_ALPHA
2325
YUV2RGBWRAPPER(yuv2, rgb_full, bgra32_full, AV_PIX_FMT_BGRA,  1)
2326
YUV2RGBWRAPPER(yuv2, rgb_full, abgr32_full, AV_PIX_FMT_ABGR,  1)
2327
YUV2RGBWRAPPER(yuv2, rgb_full, rgba32_full, AV_PIX_FMT_RGBA,  1)
2328
YUV2RGBWRAPPER(yuv2, rgb_full, argb32_full, AV_PIX_FMT_ARGB,  1)
2329
#endif
2330
YUV2RGBWRAPPER(yuv2, rgb_full, bgrx32_full, AV_PIX_FMT_BGRA,  0)
2331
YUV2RGBWRAPPER(yuv2, rgb_full, xbgr32_full, AV_PIX_FMT_ABGR,  0)
2332
YUV2RGBWRAPPER(yuv2, rgb_full, rgbx32_full, AV_PIX_FMT_RGBA,  0)
2333
YUV2RGBWRAPPER(yuv2, rgb_full, xrgb32_full, AV_PIX_FMT_ARGB,  0)
2334
#endif
2335
YUV2RGBWRAPPER(yuv2, rgb_full, bgr24_full,  AV_PIX_FMT_BGR24, 0)
2336
YUV2RGBWRAPPER(yuv2, rgb_full, rgb24_full,  AV_PIX_FMT_RGB24, 0)
2337
2338
YUV2RGBWRAPPER(yuv2, rgb_full, bgr4_byte_full,  AV_PIX_FMT_BGR4_BYTE, 0)
2339
YUV2RGBWRAPPER(yuv2, rgb_full, rgb4_byte_full,  AV_PIX_FMT_RGB4_BYTE, 0)
2340
YUV2RGBWRAPPER(yuv2, rgb_full, bgr8_full,   AV_PIX_FMT_BGR8,  0)
2341
YUV2RGBWRAPPER(yuv2, rgb_full, rgb8_full,   AV_PIX_FMT_RGB8,  0)
2342
2343
YUV2RGBWRAPPER(yuv2, rgb_full, x2rgb10_full, AV_PIX_FMT_X2RGB10LE,  0)
2344
YUV2RGBWRAPPER(yuv2, rgb_full, x2bgr10_full, AV_PIX_FMT_X2BGR10LE,  0)
2345
2346
static void
2347
yuv2gbrp_full_X_c(SwsInternal *c, const int16_t *lumFilter,
2348
                  const int16_t **lumSrc, int lumFilterSize,
2349
                  const int16_t *chrFilter, const int16_t **chrUSrc,
2350
                  const int16_t **chrVSrc, int chrFilterSize,
2351
                  const int16_t **alpSrc, uint8_t **dest,
2352
                  int dstW, int y)
2353
0
{
2354
0
    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->opts.dst_format);
2355
0
    int i;
2356
0
    int hasAlpha = (desc->flags & AV_PIX_FMT_FLAG_ALPHA) && alpSrc;
2357
0
    uint16_t **dest16 = (uint16_t**)dest;
2358
0
    int SH = 22 + 8 - desc->comp[0].depth;
2359
0
    int A = 0; // init to silence warning
2360
2361
0
    for (i = 0; i < dstW; i++) {
2362
0
        int j;
2363
0
        int Y = 1 << 9;
2364
0
        int U = (1 << 9) - (128 << 19);
2365
0
        int V = (1 << 9) - (128 << 19);
2366
0
        int R, G, B;
2367
2368
0
        for (j = 0; j < lumFilterSize; j++)
2369
0
            Y += lumSrc[j][i] * (unsigned)lumFilter[j];
2370
2371
0
        for (j = 0; j < chrFilterSize; j++) {
2372
0
            U += chrUSrc[j][i] * (unsigned)chrFilter[j];
2373
0
            V += chrVSrc[j][i] * (unsigned)chrFilter[j];
2374
0
        }
2375
2376
0
        Y >>= 10;
2377
0
        U >>= 10;
2378
0
        V >>= 10;
2379
2380
0
        if (hasAlpha) {
2381
0
            A = 1 << 18;
2382
2383
0
            for (j = 0; j < lumFilterSize; j++)
2384
0
                A += alpSrc[j][i] * (unsigned)lumFilter[j];
2385
2386
0
            if (A & 0xF8000000)
2387
0
                A =  av_clip_uintp2(A, 27);
2388
0
        }
2389
2390
0
        Y -= c->yuv2rgb_y_offset;
2391
0
        Y *= c->yuv2rgb_y_coeff;
2392
0
        Y += 1 << (SH-1);
2393
0
        R = Y + V * (unsigned)c->yuv2rgb_v2r_coeff;
2394
0
        G = Y + V * (unsigned)c->yuv2rgb_v2g_coeff + U * (unsigned)c->yuv2rgb_u2g_coeff;
2395
0
        B = Y +                                      U * (unsigned)c->yuv2rgb_u2b_coeff;
2396
2397
0
        if ((R | G | B) & 0xC0000000) {
2398
0
            R = av_clip_uintp2(R, 30);
2399
0
            G = av_clip_uintp2(G, 30);
2400
0
            B = av_clip_uintp2(B, 30);
2401
0
        }
2402
2403
0
        if (SH != 22) {
2404
0
            dest16[0][i] = G >> SH;
2405
0
            dest16[1][i] = B >> SH;
2406
0
            dest16[2][i] = R >> SH;
2407
0
            if (hasAlpha)
2408
0
                dest16[3][i] = A >> (SH - 3);
2409
0
        } else {
2410
0
            dest[0][i] = G >> 22;
2411
0
            dest[1][i] = B >> 22;
2412
0
            dest[2][i] = R >> 22;
2413
0
            if (hasAlpha)
2414
0
                dest[3][i] = A >> 19;
2415
0
        }
2416
0
    }
2417
0
    if (SH != 22 && (!isBE(c->opts.dst_format)) != (!HAVE_BIGENDIAN)) {
2418
0
        for (i = 0; i < dstW; i++) {
2419
0
            dest16[0][i] = av_bswap16(dest16[0][i]);
2420
0
            dest16[1][i] = av_bswap16(dest16[1][i]);
2421
0
            dest16[2][i] = av_bswap16(dest16[2][i]);
2422
0
            if (hasAlpha)
2423
0
                dest16[3][i] = av_bswap16(dest16[3][i]);
2424
0
        }
2425
0
    }
2426
0
}
2427
2428
static void
2429
yuv2gbrpmsb_full_X_c(SwsInternal *c, const int16_t *lumFilter,
2430
                     const int16_t **lumSrc, int lumFilterSize,
2431
                     const int16_t *chrFilter, const int16_t **chrUSrc,
2432
                     const int16_t **chrVSrc, int chrFilterSize,
2433
                     const int16_t **alpSrc, uint8_t **dest,
2434
                     int dstW, int y)
2435
0
{
2436
0
    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->opts.dst_format);
2437
0
    int hasAlpha = (desc->flags & AV_PIX_FMT_FLAG_ALPHA) && alpSrc;
2438
0
    uint16_t **dest16 = (uint16_t**)dest;
2439
0
    int shift = 16 - desc->comp[0].depth;
2440
0
    int i;
2441
2442
0
    yuv2gbrp_full_X_c(c, lumFilter, lumSrc, lumFilterSize,
2443
0
                      chrFilter, chrUSrc, chrVSrc, chrFilterSize,
2444
0
                      alpSrc, dest, dstW, y);
2445
2446
0
    if (desc->comp[0].depth <= 8)
2447
0
        return;
2448
2449
0
    if ((!isBE(c->opts.dst_format)) != (!HAVE_BIGENDIAN)) {
2450
0
        for (i = 0; i < dstW; i++) {
2451
0
            dest16[0][i] = av_bswap16(av_bswap16(dest16[0][i]) << shift);
2452
0
            dest16[1][i] = av_bswap16(av_bswap16(dest16[1][i]) << shift);
2453
0
            dest16[2][i] = av_bswap16(av_bswap16(dest16[2][i]) << shift);
2454
0
            if (hasAlpha)
2455
0
                dest16[3][i] = av_bswap16(av_bswap16(dest16[3][i]) << shift);
2456
0
        }
2457
0
    } else {
2458
0
        for (i = 0; i < dstW; i++) {
2459
0
            dest16[0][i] = dest16[0][i] << shift;
2460
0
            dest16[1][i] = dest16[1][i] << shift;
2461
0
            dest16[2][i] = dest16[2][i] << shift;
2462
0
            if (hasAlpha)
2463
0
                dest16[3][i] = dest16[3][i] << shift;
2464
0
        }
2465
0
    }
2466
0
}
2467
2468
static void
2469
yuv2gbrp16_full_X_c(SwsInternal *c, const int16_t *lumFilter,
2470
                    const int16_t **lumSrcx, int lumFilterSize,
2471
                    const int16_t *chrFilter, const int16_t **chrUSrcx,
2472
                    const int16_t **chrVSrcx, int chrFilterSize,
2473
                    const int16_t **alpSrcx, uint8_t **dest,
2474
                    int dstW, int y)
2475
0
{
2476
0
    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->opts.dst_format);
2477
0
    int i;
2478
0
    int hasAlpha = (desc->flags & AV_PIX_FMT_FLAG_ALPHA) && alpSrcx;
2479
0
    uint16_t **dest16 = (uint16_t**)dest;
2480
0
    const int32_t **lumSrc  = (const int32_t**)lumSrcx;
2481
0
    const int32_t **chrUSrc = (const int32_t**)chrUSrcx;
2482
0
    const int32_t **chrVSrc = (const int32_t**)chrVSrcx;
2483
0
    const int32_t **alpSrc  = (const int32_t**)alpSrcx;
2484
2485
0
    for (i = 0; i < dstW; i++) {
2486
0
        int j;
2487
0
        int Y = -0x40000000;
2488
0
        int U = -(128 << 23);
2489
0
        int V = -(128 << 23);
2490
0
        int R, G, B, A;
2491
2492
0
        for (j = 0; j < lumFilterSize; j++)
2493
0
            Y += lumSrc[j][i] * (unsigned)lumFilter[j];
2494
2495
0
        for (j = 0; j < chrFilterSize; j++) {
2496
0
            U += chrUSrc[j][i] * (unsigned)chrFilter[j];
2497
0
            V += chrVSrc[j][i] * (unsigned)chrFilter[j];
2498
0
        }
2499
2500
0
        Y >>= 14;
2501
0
        Y += 0x10000;
2502
0
        U >>= 14;
2503
0
        V >>= 14;
2504
2505
0
        if (hasAlpha) {
2506
0
            A = -0x40000000;
2507
2508
0
            for (j = 0; j < lumFilterSize; j++)
2509
0
                A += alpSrc[j][i] * (unsigned)lumFilter[j];
2510
2511
0
            A >>= 1;
2512
0
            A += 0x20002000;
2513
0
        }
2514
2515
0
        Y -= c->yuv2rgb_y_offset;
2516
0
        Y *= c->yuv2rgb_y_coeff;
2517
0
        Y += (1 << 13) - (1 << 29);
2518
0
        R = V * c->yuv2rgb_v2r_coeff;
2519
0
        G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
2520
0
        B =                            U * c->yuv2rgb_u2b_coeff;
2521
2522
0
        dest16[2][i] = av_clip_uintp2(((Y + (int64_t)R) >> 14) + (1<<15), 16);
2523
0
        dest16[0][i] = av_clip_uintp2(((Y + (int64_t)G) >> 14) + (1<<15), 16);
2524
0
        dest16[1][i] = av_clip_uintp2(((Y + (int64_t)B) >> 14) + (1<<15), 16);
2525
2526
0
        if (hasAlpha)
2527
0
            dest16[3][i] = av_clip_uintp2(A, 30) >> 14;
2528
0
    }
2529
0
    if ((!isBE(c->opts.dst_format)) != (!HAVE_BIGENDIAN)) {
2530
0
        for (i = 0; i < dstW; i++) {
2531
0
            dest16[0][i] = av_bswap16(dest16[0][i]);
2532
0
            dest16[1][i] = av_bswap16(dest16[1][i]);
2533
0
            dest16[2][i] = av_bswap16(dest16[2][i]);
2534
0
            if (hasAlpha)
2535
0
                dest16[3][i] = av_bswap16(dest16[3][i]);
2536
0
        }
2537
0
    }
2538
0
}
2539
2540
static void
2541
yuv2gbrpf32_full_X_c(SwsInternal *c, const int16_t *lumFilter,
2542
                    const int16_t **lumSrcx, int lumFilterSize,
2543
                    const int16_t *chrFilter, const int16_t **chrUSrcx,
2544
                    const int16_t **chrVSrcx, int chrFilterSize,
2545
                    const int16_t **alpSrcx, uint8_t **dest,
2546
                    int dstW, int y)
2547
0
{
2548
0
    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->opts.dst_format);
2549
0
    int i;
2550
0
    int hasAlpha = (desc->flags & AV_PIX_FMT_FLAG_ALPHA) && alpSrcx;
2551
0
    uint32_t **dest32 = (uint32_t**)dest;
2552
0
    const int32_t **lumSrc  = (const int32_t**)lumSrcx;
2553
0
    const int32_t **chrUSrc = (const int32_t**)chrUSrcx;
2554
0
    const int32_t **chrVSrc = (const int32_t**)chrVSrcx;
2555
0
    const int32_t **alpSrc  = (const int32_t**)alpSrcx;
2556
0
    static const float float_mult = 1.0f / 65535.0f;
2557
2558
0
    for (i = 0; i < dstW; i++) {
2559
0
        int j;
2560
0
        int Y = -0x40000000;
2561
0
        int U = -(128 << 23);
2562
0
        int V = -(128 << 23);
2563
0
        int R, G, B, A;
2564
2565
0
        for (j = 0; j < lumFilterSize; j++)
2566
0
            Y += lumSrc[j][i] * (unsigned)lumFilter[j];
2567
2568
0
        for (j = 0; j < chrFilterSize; j++) {
2569
0
            U += chrUSrc[j][i] * (unsigned)chrFilter[j];
2570
0
            V += chrVSrc[j][i] * (unsigned)chrFilter[j];
2571
0
        }
2572
2573
0
        Y >>= 14;
2574
0
        Y += 0x10000;
2575
0
        U >>= 14;
2576
0
        V >>= 14;
2577
2578
0
        if (hasAlpha) {
2579
0
            A = -0x40000000;
2580
2581
0
            for (j = 0; j < lumFilterSize; j++)
2582
0
                A += alpSrc[j][i] * (unsigned)lumFilter[j];
2583
2584
0
            A >>= 1;
2585
0
            A += 0x20002000;
2586
0
        }
2587
2588
0
        Y -= c->yuv2rgb_y_offset;
2589
0
        Y *= c->yuv2rgb_y_coeff;
2590
0
        Y += (1 << 13) - (1 << 29);
2591
0
        R = V * c->yuv2rgb_v2r_coeff;
2592
0
        G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
2593
0
        B =                            U * c->yuv2rgb_u2b_coeff;
2594
2595
0
        R = av_clip_uintp2(((Y + R) >> 14) + (1<<15), 16);
2596
0
        G = av_clip_uintp2(((Y + G) >> 14) + (1<<15), 16);
2597
0
        B = av_clip_uintp2(((Y + B) >> 14) + (1<<15), 16);
2598
2599
0
        dest32[0][i] = av_float2int(float_mult * (float)G);
2600
0
        dest32[1][i] = av_float2int(float_mult * (float)B);
2601
0
        dest32[2][i] = av_float2int(float_mult * (float)R);
2602
0
        if (hasAlpha)
2603
0
            dest32[3][i] = av_float2int(float_mult * (float)(av_clip_uintp2(A, 30) >> 14));
2604
0
    }
2605
0
    if ((!isBE(c->opts.dst_format)) != (!HAVE_BIGENDIAN)) {
2606
0
        for (i = 0; i < dstW; i++) {
2607
0
            dest32[0][i] = av_bswap32(dest32[0][i]);
2608
0
            dest32[1][i] = av_bswap32(dest32[1][i]);
2609
0
            dest32[2][i] = av_bswap32(dest32[2][i]);
2610
0
            if (hasAlpha)
2611
0
                dest32[3][i] = av_bswap32(dest32[3][i]);
2612
0
        }
2613
0
    }
2614
0
}
2615
2616
static void
2617
yuv2ya8_1_c(SwsInternal *c, const int16_t *buf0,
2618
            const int16_t *ubuf[2], const int16_t *vbuf[2],
2619
            const int16_t *abuf0, uint8_t *dest, int dstW,
2620
            int uvalpha, int y)
2621
0
{
2622
0
    int hasAlpha = !!abuf0;
2623
0
    int i;
2624
2625
0
    for (i = 0; i < dstW; i++) {
2626
0
        int Y = (buf0[i] + 64) >> 7;
2627
0
        int A;
2628
2629
0
        Y = av_clip_uint8(Y);
2630
2631
0
        if (hasAlpha) {
2632
0
            A = (abuf0[i] + 64) >> 7;
2633
0
            if (A & 0x100)
2634
0
                A = av_clip_uint8(A);
2635
0
        }
2636
2637
0
        dest[i * 2    ] = Y;
2638
0
        dest[i * 2 + 1] = hasAlpha ? A : 255;
2639
0
    }
2640
0
}
2641
2642
static void
2643
yuv2ya8_2_c(SwsInternal *c, const int16_t *buf[2],
2644
            const int16_t *ubuf[2], const int16_t *vbuf[2],
2645
            const int16_t *abuf[2], uint8_t *dest, int dstW,
2646
            int yalpha, int uvalpha, int y)
2647
0
{
2648
0
    int hasAlpha = abuf && abuf[0] && abuf[1];
2649
0
    const int16_t *buf0  = buf[0],  *buf1  = buf[1],
2650
0
                  *abuf0 = hasAlpha ? abuf[0] : NULL,
2651
0
                  *abuf1 = hasAlpha ? abuf[1] : NULL;
2652
0
    int  yalpha1 = 4096 - yalpha;
2653
0
    int i;
2654
2655
0
    av_assert2(yalpha  <= 4096U);
2656
2657
0
    for (i = 0; i < dstW; i++) {
2658
0
        int Y = (buf0[i] * yalpha1 + buf1[i] * yalpha) >> 19;
2659
0
        int A;
2660
2661
0
        Y = av_clip_uint8(Y);
2662
2663
0
        if (hasAlpha) {
2664
0
            A = (abuf0[i] * yalpha1 + abuf1[i] * yalpha) >> 19;
2665
0
            A = av_clip_uint8(A);
2666
0
        }
2667
2668
0
        dest[i * 2    ] = Y;
2669
0
        dest[i * 2 + 1] = hasAlpha ? A : 255;
2670
0
    }
2671
0
}
2672
2673
static void
2674
yuv2ya8_X_c(SwsInternal *c, const int16_t *lumFilter,
2675
            const int16_t **lumSrc, int lumFilterSize,
2676
            const int16_t *chrFilter, const int16_t **chrUSrc,
2677
            const int16_t **chrVSrc, int chrFilterSize,
2678
            const int16_t **alpSrc, uint8_t *dest, int dstW, int y)
2679
0
{
2680
0
    int hasAlpha = !!alpSrc;
2681
0
    int i;
2682
2683
0
    for (i = 0; i < dstW; i++) {
2684
0
        int j;
2685
0
        int Y = 1 << 18, A = 1 << 18;
2686
2687
0
        for (j = 0; j < lumFilterSize; j++)
2688
0
            Y += lumSrc[j][i] * (unsigned)lumFilter[j];
2689
2690
0
        Y >>= 19;
2691
0
        if (Y  & 0x100)
2692
0
            Y = av_clip_uint8(Y);
2693
2694
0
        if (hasAlpha) {
2695
0
            for (j = 0; j < lumFilterSize; j++)
2696
0
                A += alpSrc[j][i] * (unsigned)lumFilter[j];
2697
2698
0
            A >>= 19;
2699
2700
0
            if (A & 0x100)
2701
0
                A = av_clip_uint8(A);
2702
0
        }
2703
2704
0
        dest[2 * i    ] = Y;
2705
0
        dest[2 * i + 1] = hasAlpha ? A : 255;
2706
0
    }
2707
0
}
2708
2709
#define output_pixels(pos, val) \
2710
0
    if (is_be) { \
2711
0
        AV_WB16(pos, val); \
2712
0
    } else { \
2713
0
        AV_WL16(pos, val); \
2714
0
    }
2715
2716
static av_always_inline void
2717
yuv2ayuv64_X_c(SwsInternal *c, const int16_t *lumFilter,
2718
               const int16_t **_lumSrc, int lumFilterSize,
2719
               const int16_t *chrFilter, const int16_t **_chrUSrc,
2720
               const int16_t **_chrVSrc, int chrFilterSize,
2721
               const int16_t **_alpSrc, uint8_t *dest, int dstW, int y,
2722
               int A_offset, int Y_offset, int U_offset, int V_offset, int is_be)
2723
0
{
2724
0
    const int32_t **lumSrc  = (const int32_t **) _lumSrc,
2725
0
                  **chrUSrc = (const int32_t **) _chrUSrc,
2726
0
                  **chrVSrc = (const int32_t **) _chrVSrc,
2727
0
                  **alpSrc  = (const int32_t **) _alpSrc;
2728
0
    int hasAlpha = !!alpSrc;
2729
0
    int i;
2730
2731
0
    for (i = 0; i < dstW; i++) {
2732
0
        int Y = 1 << 14, U = 1 << 14;
2733
0
        int V = 1 << 14, A = 1 << 14;
2734
0
        int j;
2735
2736
0
        Y -= 0x40000000;
2737
0
        U -= 0x40000000;
2738
0
        V -= 0x40000000;
2739
0
        A -= 0x40000000;
2740
2741
0
        for (j = 0; j < lumFilterSize; j++)
2742
0
            Y += lumSrc[j][i] * (unsigned)lumFilter[j];
2743
2744
0
        for (j = 0; j < chrFilterSize; j++)
2745
0
            U += chrUSrc[j][i] * (unsigned)chrFilter[j];
2746
2747
0
        for (j = 0; j < chrFilterSize; j++)
2748
0
            V += chrVSrc[j][i] * (unsigned)chrFilter[j];
2749
2750
0
        if (hasAlpha)
2751
0
            for (j = 0; j < lumFilterSize; j++)
2752
0
                A += alpSrc[j][i] * (unsigned)lumFilter[j];
2753
2754
0
        Y = 0x8000 + av_clip_int16(Y >> 15);
2755
0
        U = 0x8000 + av_clip_int16(U >> 15);
2756
0
        V = 0x8000 + av_clip_int16(V >> 15);
2757
0
        if (hasAlpha)
2758
0
            A = 0x8000 + av_clip_int16(A >> 15);
2759
2760
0
        output_pixels(dest + 8 * i + A_offset, hasAlpha ? A : 65535);
2761
0
        output_pixels(dest + 8 * i + Y_offset, Y);
2762
0
        output_pixels(dest + 8 * i + U_offset, U);
2763
0
        output_pixels(dest + 8 * i + V_offset, V);
2764
0
    }
2765
0
}
2766
2767
#define YUV2AYUV64(pixfmt, BE_LE, A, Y, U, V, is_be) \
2768
static void \
2769
yuv2 ## pixfmt ## BE_LE ##_X_c(SwsInternal *c, const int16_t *lumFilter, \
2770
               const int16_t **lumSrc, int lumFilterSize, \
2771
               const int16_t *chrFilter, const int16_t **chrUSrc, \
2772
               const int16_t **chrVSrc, int chrFilterSize, \
2773
0
               const int16_t **alpSrc, uint8_t *dest, int dstW, int y) \
2774
0
{ \
2775
0
    yuv2ayuv64_X_c(c, lumFilter, lumSrc, lumFilterSize, \
2776
0
                   chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
2777
0
                   alpSrc, dest, dstW, y, A, Y, U, V, is_be); \
2778
0
}
Unexecuted instantiation: output.c:yuv2ayuv64le_X_c
Unexecuted instantiation: output.c:yuv2ayuv64be_X_c
Unexecuted instantiation: output.c:yuv2xv48le_X_c
Unexecuted instantiation: output.c:yuv2xv48be_X_c
2779
2780
YUV2AYUV64(ayuv64, le, 0, 2, 4, 6, 0)
2781
YUV2AYUV64(ayuv64, be, 0, 2, 4, 6, 1)
2782
2783
YUV2AYUV64(xv48, le, 6, 2, 0, 4, 0)
2784
YUV2AYUV64(xv48, be, 6, 2, 0, 4, 1)
2785
2786
#undef output_pixels
2787
2788
static av_always_inline void
2789
yuv2v30_X_c_template(SwsInternal *c, const int16_t *lumFilter,
2790
                     const int16_t **lumSrc, int lumFilterSize,
2791
                     const int16_t *chrFilter, const int16_t **chrUSrc,
2792
                     const int16_t **chrVSrc, int chrFilterSize,
2793
                     const int16_t **alpSrc, uint8_t *dest, int dstW, int y,
2794
                     int shift)
2795
0
{
2796
0
    int i;
2797
0
    for (i = 0; i < dstW; i++) {
2798
0
        int Y = 1 << 16, U = 1 << 16, V = 1 << 16, A = 0x3;
2799
0
        int j;
2800
2801
0
        for (j = 0; j < lumFilterSize; j++)
2802
0
            Y += lumSrc[j][i] * (unsigned)lumFilter[j];
2803
2804
0
        for (j = 0; j < chrFilterSize; j++) {
2805
0
            U += chrUSrc[j][i] * (unsigned)chrFilter[j];
2806
0
            V += chrVSrc[j][i] * (unsigned)chrFilter[j];
2807
0
        }
2808
2809
0
        Y = av_clip_uintp2(Y >> 17, 10);
2810
0
        U = av_clip_uintp2(U >> 17, 10);
2811
0
        V = av_clip_uintp2(V >> 17, 10);
2812
2813
0
        AV_WL32(dest + 4 * i, U << (shift +  0)  |
2814
0
                              Y << (shift + 10)  |
2815
0
                    (unsigned)V << (shift + 20)  |
2816
0
                    (unsigned)A << (shift ? 0 : 30 /* xv30le = 30, v30xle = 0 */));
2817
0
    }
2818
0
}
2819
2820
#define V30LE_WRAPPER(name, shift) \
2821
static void yuv2 ## name ## _X_c(SwsInternal *c, const int16_t *lumFilter, \
2822
                                 const int16_t **lumSrc, int lumFilterSize, \
2823
                                 const int16_t *chrFilter, const int16_t **chrUSrc, \
2824
                                 const int16_t **chrVSrc, int chrFilterSize, \
2825
                                 const int16_t **alpSrc, uint8_t *dest, int dstW, \
2826
0
                                 int y) \
2827
0
{ \
2828
0
    yuv2v30_X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
2829
0
                         chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
2830
0
                         alpSrc, dest, dstW, y, shift); \
2831
0
}
Unexecuted instantiation: output.c:yuv2v30xle_X_c
Unexecuted instantiation: output.c:yuv2xv30le_X_c
2832
2833
V30LE_WRAPPER(xv30le, 0)
2834
V30LE_WRAPPER(v30xle, 2)
2835
2836
#define output_pixels(pos, val, shift, bits, output_shift) \
2837
0
    if (is_be) { \
2838
0
        AV_WB16(pos, av_clip_uintp2(val >> shift, bits) << output_shift); \
2839
0
    } else { \
2840
0
        AV_WL16(pos, av_clip_uintp2(val >> shift, bits) << output_shift); \
2841
0
    }
2842
2843
static void
2844
yuv2xv36_X_c(SwsInternal *c, const int16_t *lumFilter,
2845
             const int16_t **lumSrc, int lumFilterSize,
2846
             const int16_t *chrFilter, const int16_t **chrUSrc,
2847
             const int16_t **chrVSrc, int chrFilterSize,
2848
             const int16_t **alpSrc, uint8_t *dest, int dstW, int y, int is_be)
2849
0
{
2850
0
    int i;
2851
0
    for (i = 0; i < dstW; i++) {
2852
0
        int Y = 1 << 14, U = 1 << 14, V = 1 << 14, A = 65535;
2853
0
        int j;
2854
2855
0
        for (j = 0; j < lumFilterSize; j++)
2856
0
            Y += lumSrc[j][i] * (unsigned)lumFilter[j];
2857
2858
0
        for (j = 0; j < chrFilterSize; j++) {
2859
0
            U += chrUSrc[j][i] * (unsigned)chrFilter[j];
2860
0
            V += chrVSrc[j][i] * (unsigned)chrFilter[j];
2861
0
        }
2862
2863
0
        output_pixels(dest + 8 * i + 2, Y, 15, 12, 4)
2864
0
        output_pixels(dest + 8 * i + 0, U, 15, 12, 4)
2865
0
        output_pixels(dest + 8 * i + 4, V, 15, 12, 4)
2866
0
        output_pixels(dest + 8 * i + 6, A,  0, 12, 4);
2867
0
    }
2868
0
}
2869
2870
#undef output_pixels
2871
2872
#define YUV2XV36(BE_LE, is_be) \
2873
static void \
2874
yuv2xv36 ## BE_LE ##_X_c(SwsInternal *c, const int16_t *lumFilter, \
2875
                         const int16_t **lumSrc, int lumFilterSize, \
2876
                         const int16_t *chrFilter, const int16_t **chrUSrc, \
2877
                         const int16_t **chrVSrc, int chrFilterSize, \
2878
0
                         const int16_t **alpSrc, uint8_t *dest, int dstW, int y) \
2879
0
{ \
2880
0
    yuv2xv36_X_c(c, lumFilter, lumSrc, lumFilterSize, \
2881
0
                 chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
2882
0
                 alpSrc, dest, dstW, y, is_be); \
2883
0
}
Unexecuted instantiation: output.c:yuv2xv36le_X_c
Unexecuted instantiation: output.c:yuv2xv36be_X_c
2884
2885
YUV2XV36(le, 0)
2886
YUV2XV36(be, 1)
2887
2888
#define output_pixels(pos, A, Y, U, V) \
2889
0
    if (target == AV_PIX_FMT_AYUV) { \
2890
0
        dest[pos + 0] = A; \
2891
0
        dest[pos + 1] = Y;  \
2892
0
        dest[pos + 2] = U; \
2893
0
        dest[pos + 3] = V;  \
2894
0
    } else if (target == AV_PIX_FMT_UYVA) { \
2895
0
        dest[pos + 0] = U; \
2896
0
        dest[pos + 1] = Y;  \
2897
0
        dest[pos + 2] = V; \
2898
0
        dest[pos + 3] = A;  \
2899
0
    } else { /* AV_PIX_FMT_VUYA || AV_PIX_FMT_VUYX */ \
2900
0
        dest[pos + 0] = V;  \
2901
0
        dest[pos + 1] = U; \
2902
0
        dest[pos + 2] = Y;  \
2903
0
        dest[pos + 3] = A; \
2904
0
    }
2905
2906
static av_always_inline void
2907
yuv2ayuv_1_c_template(SwsInternal *c, const int16_t *buf0,
2908
                      const int16_t *ubuf[2], const int16_t *vbuf[2],
2909
                      const int16_t *abuf0, uint8_t *dest, int dstW,
2910
                      int uvalpha, int y, enum AVPixelFormat target)
2911
0
{
2912
0
    int hasAlpha = !!abuf0;
2913
0
    int i;
2914
2915
0
    if (uvalpha < 2048) {
2916
0
        for (i = 0; i < dstW; i++) {
2917
0
            int Y = (buf0[i] + 64) >> 7;
2918
0
            int U = (ubuf[0][i] + 64) >> 7;
2919
0
            int V = (vbuf[0][i] + 64) >> 7;
2920
0
            int A = 255;
2921
2922
0
            if (Y & 0x100)
2923
0
                Y = av_clip_uint8(Y);
2924
0
            if (U & 0x100)
2925
0
                U = av_clip_uint8(U);
2926
0
            if (V & 0x100)
2927
0
                V = av_clip_uint8(V);
2928
2929
0
            if (hasAlpha) {
2930
0
                A = (abuf0[i] + 64) >> 7;
2931
0
                if (A & 0x100)
2932
0
                    A = av_clip_uint8(A);
2933
0
            }
2934
2935
0
            output_pixels(i * 4, A, Y, U, V)
2936
0
        }
2937
0
    } else {
2938
0
        for (i = 0; i < dstW; i++) {
2939
0
            int Y = (buf0[i] + 64) >> 7;
2940
0
            int U = (ubuf[0][i] + ubuf[1][i] + 128) >> 8;
2941
0
            int V = (vbuf[0][i] + vbuf[1][i] + 128) >> 8;
2942
0
            int A = 255;
2943
2944
0
            if (Y & 0x100)
2945
0
                Y = av_clip_uint8(Y);
2946
0
            if (U & 0x100)
2947
0
                U = av_clip_uint8(U);
2948
0
            if (V & 0x100)
2949
0
                V = av_clip_uint8(V);
2950
2951
0
            if (hasAlpha) {
2952
0
                A = (abuf0[i] + 64) >> 7;
2953
0
                if (A & 0x100)
2954
0
                    A = av_clip_uint8(A);
2955
0
            }
2956
2957
0
            output_pixels(i * 4, A, Y, U, V)
2958
0
        }
2959
0
    }
2960
0
}
2961
2962
static av_always_inline void
2963
yuv2ayuv_2_c_template(SwsInternal *c, const int16_t *buf[2],
2964
                      const int16_t *ubuf[2], const int16_t *vbuf[2],
2965
                      const int16_t *abuf[2], uint8_t *dest, int dstW,
2966
                      int yalpha, int uvalpha, int y,
2967
                      enum AVPixelFormat target)
2968
0
{
2969
0
    int hasAlpha = abuf && abuf[0] && abuf[1];
2970
0
    const int16_t *buf0  = buf[0],  *buf1  = buf[1],
2971
0
                  *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
2972
0
                  *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
2973
0
                  *abuf0 = hasAlpha ? abuf[0] : NULL,
2974
0
                  *abuf1 = hasAlpha ? abuf[1] : NULL;
2975
0
    int yalpha1  = 4096 - yalpha;
2976
0
    int uvalpha1 = 4096 - uvalpha;
2977
0
    int i;
2978
2979
0
    av_assert2(yalpha  <= 4096U);
2980
0
    av_assert2(uvalpha <= 4096U);
2981
2982
0
    for (i = 0; i < dstW; i++) {
2983
0
        int Y = (buf0[i]  * yalpha1  + buf1[i]  * yalpha)  >> 19;
2984
0
        int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha) >> 19;
2985
0
        int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha) >> 19;
2986
0
        int A = 255;
2987
2988
0
        if (Y & 0x100)
2989
0
            Y = av_clip_uint8(Y);
2990
0
        if (U & 0x100)
2991
0
            U = av_clip_uint8(U);
2992
0
        if (V & 0x100)
2993
0
            V = av_clip_uint8(V);
2994
2995
0
        if (hasAlpha) {
2996
0
            A = (abuf0[i] * yalpha1 + abuf1[i] * yalpha) >> 19;
2997
0
            A = av_clip_uint8(A);
2998
0
        }
2999
3000
0
        output_pixels(i * 4, A, Y, U, V)
3001
0
    }
3002
0
}
3003
3004
static av_always_inline void
3005
yuv2ayuv_X_c_template(SwsInternal *c, const int16_t *lumFilter,
3006
                      const int16_t **lumSrc, int lumFilterSize,
3007
                      const int16_t *chrFilter, const int16_t **chrUSrc,
3008
                      const int16_t **chrVSrc, int chrFilterSize,
3009
                      const int16_t **alpSrc, uint8_t *dest, int dstW,
3010
                      int y, enum AVPixelFormat target)
3011
0
{
3012
0
    int i;
3013
3014
0
    for (i = 0; i < dstW; i++) {
3015
0
        int j;
3016
0
        int Y = 1 << 18, U = 1 << 18;
3017
0
        int V = 1 << 18, A = 255;
3018
3019
0
        for (j = 0; j < lumFilterSize; j++)
3020
0
            Y += lumSrc[j][i] * (unsigned)lumFilter[j];
3021
3022
0
        for (j = 0; j < chrFilterSize; j++)
3023
0
            U += chrUSrc[j][i] * (unsigned)chrFilter[j];
3024
3025
0
        for (j = 0; j < chrFilterSize; j++)
3026
0
            V += chrVSrc[j][i] * (unsigned)chrFilter[j];
3027
3028
0
        Y >>= 19;
3029
0
        U >>= 19;
3030
0
        V >>= 19;
3031
3032
0
        if (Y  & 0x100)
3033
0
            Y = av_clip_uint8(Y);
3034
0
        if (U  & 0x100)
3035
0
            U = av_clip_uint8(U);
3036
0
        if (V  & 0x100)
3037
0
            V = av_clip_uint8(V);
3038
3039
0
        if (alpSrc) {
3040
0
            A = 1 << 18;
3041
3042
0
            for (j = 0; j < lumFilterSize; j++)
3043
0
                A += alpSrc[j][i] * (unsigned)lumFilter[j];
3044
3045
0
            A >>= 19;
3046
3047
0
            if (A & 0x100)
3048
0
                A = av_clip_uint8(A);
3049
0
        }
3050
3051
0
        output_pixels(i * 4, A, Y, U, V)
3052
0
    }
3053
0
}
3054
3055
#undef output_pixels
3056
3057
#define AYUVPACKEDWRAPPER(name, fmt) \
3058
static void yuv2 ## name ## _X_c(SwsInternal *c, const int16_t *lumFilter, \
3059
                                 const int16_t **lumSrc, int lumFilterSize, \
3060
                                 const int16_t *chrFilter, const int16_t **chrUSrc, \
3061
                                 const int16_t **chrVSrc, int chrFilterSize, \
3062
                                 const int16_t **alpSrc, uint8_t *dest, int dstW, \
3063
0
                                 int y) \
3064
0
{ \
3065
0
    yuv2ayuv_X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
3066
0
                          chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
3067
0
                          alpSrc, dest, dstW, y, fmt); \
3068
0
} \
Unexecuted instantiation: output.c:yuv2ayuv_X_c
Unexecuted instantiation: output.c:yuv2vuyX_X_c
Unexecuted instantiation: output.c:yuv2uyva_X_c
3069
 \
3070
static void yuv2 ## name ## _2_c(SwsInternal *c, const int16_t *buf[2], \
3071
                                 const int16_t *ubuf[2], const int16_t *vbuf[2], \
3072
                                 const int16_t *abuf[2], uint8_t *dest, int dstW, \
3073
0
                                 int yalpha, int uvalpha, int y) \
3074
0
{ \
3075
0
    yuv2ayuv_2_c_template(c, buf, ubuf, vbuf, abuf, \
3076
0
                          dest, dstW, yalpha, uvalpha, y, fmt); \
3077
0
} \
Unexecuted instantiation: output.c:yuv2ayuv_2_c
Unexecuted instantiation: output.c:yuv2vuyX_2_c
Unexecuted instantiation: output.c:yuv2uyva_2_c
3078
 \
3079
static void yuv2 ## name ## _1_c(SwsInternal *c, const int16_t *buf0, \
3080
                                 const int16_t *ubuf[2], const int16_t *vbuf[2], \
3081
                                 const int16_t *abuf0, uint8_t *dest, int dstW, \
3082
0
                                 int uvalpha, int y) \
3083
0
{ \
3084
0
    yuv2ayuv_1_c_template(c, buf0, ubuf, vbuf, \
3085
0
                          abuf0, dest, dstW, uvalpha, \
3086
0
                          y, fmt); \
3087
0
}
Unexecuted instantiation: output.c:yuv2ayuv_1_c
Unexecuted instantiation: output.c:yuv2vuyX_1_c
Unexecuted instantiation: output.c:yuv2uyva_1_c
3088
3089
AYUVPACKEDWRAPPER(vuyX, AV_PIX_FMT_VUYX)
3090
AYUVPACKEDWRAPPER(ayuv, AV_PIX_FMT_AYUV)
3091
AYUVPACKEDWRAPPER(uyva, AV_PIX_FMT_UYVA)
3092
3093
#define output_pixel(pos, val, bits) \
3094
0
    AV_WL16(pos, av_clip_uintp2(val >> shift, bits) << output_shift);
3095
3096
#define yuv2y2xx_wrapper(bits)                                          \
3097
    static void                                                         \
3098
    yuv2y2 ## bits ## le_X_c(SwsInternal *c, const int16_t *lumFilter,  \
3099
                            const int16_t **lumSrc, int lumFilterSize,  \
3100
                            const int16_t *chrFilter,                   \
3101
                            const int16_t **chrUSrc,                    \
3102
                            const int16_t **chrVSrc, int chrFilterSize, \
3103
                            const int16_t **alpSrc,                     \
3104
                            uint8_t *dest, int dstW, int y)             \
3105
0
    {                                                                   \
3106
0
        int i, j;                                                       \
3107
0
        int shift = 11 + 16 - bits;                                     \
3108
0
        int output_shift = 16 - bits;                                   \
3109
0
        for (i = 0; i < ((dstW + 1) >> 1); i++) {                       \
3110
0
            int Y1 = 1 << (shift - 1), Y2 = 1 << (shift - 1);           \
3111
0
            int U  = 1 << (shift - 1), V  = 1 << (shift - 1);           \
3112
0
                                                                        \
3113
0
            for (j = 0; j < lumFilterSize; j++) {                       \
3114
0
                Y1 += lumSrc[j][i * 2]     * (unsigned)lumFilter[j];    \
3115
0
                Y2 += lumSrc[j][i * 2 + 1] * (unsigned)lumFilter[j];    \
3116
0
            }                                                           \
3117
0
                                                                        \
3118
0
            for (j = 0; j < chrFilterSize; j++) {                       \
3119
0
                U += chrUSrc[j][i] * (unsigned)chrFilter[j];            \
3120
0
                V += chrVSrc[j][i] * (unsigned)chrFilter[j];            \
3121
0
            }                                                           \
3122
0
                                                                        \
3123
0
            output_pixel(dest + 8 * i + 0, Y1, bits);                   \
3124
0
            output_pixel(dest + 8 * i + 2,  U, bits);                   \
3125
0
            output_pixel(dest + 8 * i + 4, Y2, bits);                   \
3126
0
            output_pixel(dest + 8 * i + 6,  V, bits);                   \
3127
0
        }                                                               \
3128
0
    }
Unexecuted instantiation: output.c:yuv2y210le_X_c
Unexecuted instantiation: output.c:yuv2y212le_X_c
3129
3130
yuv2y2xx_wrapper(10)
3131
yuv2y2xx_wrapper(12)
3132
3133
static void
3134
yuv2y216le_X_c(SwsInternal *c, const int16_t *lumFilter,
3135
               const int16_t **_lumSrc, int lumFilterSize,
3136
               const int16_t *chrFilter,
3137
               const int16_t **_chrUSrc,
3138
               const int16_t **_chrVSrc, int chrFilterSize,
3139
               const int16_t **_alpSrc,
3140
               uint8_t *dest, int dstW, int y)
3141
0
{
3142
0
    const int32_t **lumSrc  = (const int32_t **)_lumSrc;
3143
0
    const int32_t **chrUSrc = (const int32_t **)_chrUSrc;
3144
0
    const int32_t **chrVSrc = (const int32_t **)_chrVSrc;
3145
0
    int shift = 15;
3146
3147
0
    for (int i = 0; i < ((dstW + 1) >> 1); i++) {
3148
0
        int Y1 = 1 << (shift - 1), Y2 = 1 << (shift - 1);
3149
0
        int U  = 1 << (shift - 1), V  = 1 << (shift - 1);
3150
3151
        /* See yuv2planeX_16_c_template for details. */
3152
0
        Y1 -= 0x40000000;
3153
0
        U  -= 0x40000000;
3154
0
        Y2 -= 0x40000000;
3155
0
        V  -= 0x40000000;
3156
3157
0
        for (int j = 0; j < lumFilterSize; j++) {
3158
0
            Y1 += lumSrc[j][i * 2]     * (unsigned)lumFilter[j];
3159
0
            Y2 += lumSrc[j][i * 2 + 1] * (unsigned)lumFilter[j];
3160
0
        }
3161
3162
0
        for (int j = 0; j < chrFilterSize; j++) {
3163
0
            U += chrUSrc[j][i] * (unsigned)chrFilter[j];
3164
0
            V += chrVSrc[j][i] * (unsigned)chrFilter[j];
3165
0
        }
3166
3167
0
        AV_WL16(dest + 8 * i + 0, 0x8000 + av_clip_int16(Y1 >> shift));
3168
0
        AV_WL16(dest + 8 * i + 2, 0x8000 + av_clip_int16(U  >> shift));
3169
0
        AV_WL16(dest + 8 * i + 4, 0x8000 + av_clip_int16(Y2 >> shift));
3170
0
        AV_WL16(dest + 8 * i + 6, 0x8000 + av_clip_int16(V  >> shift));
3171
0
    }
3172
0
}
3173
3174
static void
3175
yuv2vyu444_1_c(SwsInternal *c, const int16_t *buf0,
3176
               const int16_t *ubuf[2], const int16_t *vbuf[2],
3177
               const int16_t *abuf0, uint8_t *dest, int dstW,
3178
               int uvalpha, int y)
3179
0
{
3180
0
    int i;
3181
3182
0
    if (uvalpha < 2048) {
3183
0
        for (i = 0; i < dstW; i++) {
3184
0
            int Y = (buf0[i] + 64) >> 7;
3185
0
            int U = (ubuf[0][i] + 64) >> 7;
3186
0
            int V = (vbuf[0][i] + 64) >> 7;
3187
3188
0
            if (Y & 0x100)
3189
0
                Y = av_clip_uint8(Y);
3190
0
            if (U & 0x100)
3191
0
                U = av_clip_uint8(U);
3192
0
            if (V & 0x100)
3193
0
                V = av_clip_uint8(V);
3194
3195
0
            dest[3 * i    ] = V;
3196
0
            dest[3 * i + 1] = Y;
3197
0
            dest[3 * i + 2] = U;
3198
0
        }
3199
0
    } else {
3200
0
        for (i = 0; i < dstW; i++) {
3201
0
            int Y = (buf0[i] + 64) >> 7;
3202
0
            int U = (ubuf[0][i] + ubuf[1][i] + 128) >> 8;
3203
0
            int V = (vbuf[0][i] + vbuf[1][i] + 128) >> 8;
3204
3205
0
            if (Y & 0x100)
3206
0
                Y = av_clip_uint8(Y);
3207
0
            if (U & 0x100)
3208
0
                U = av_clip_uint8(U);
3209
0
            if (V & 0x100)
3210
0
                V = av_clip_uint8(V);
3211
3212
0
            dest[3 * i    ] = V;
3213
0
            dest[3 * i + 1] = Y;
3214
0
            dest[3 * i + 2] = U;
3215
0
        }
3216
0
    }
3217
0
}
3218
3219
static void
3220
yuv2vyu444_2_c(SwsInternal *c, const int16_t *buf[2],
3221
               const int16_t *ubuf[2], const int16_t *vbuf[2],
3222
               const int16_t *abuf[2], uint8_t *dest, int dstW,
3223
               int yalpha, int uvalpha, int y)
3224
0
{
3225
0
    const int16_t *buf0  = buf[0],  *buf1  = buf[1],
3226
0
                  *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
3227
0
                  *vbuf0 = vbuf[0], *vbuf1 = vbuf[1];
3228
0
    int yalpha1  = 4096 - yalpha;
3229
0
    int uvalpha1 = 4096 - uvalpha;
3230
0
    int i;
3231
3232
0
    av_assert2(yalpha  <= 4096U);
3233
0
    av_assert2(uvalpha <= 4096U);
3234
3235
0
    for (i = 0; i < dstW; i++) {
3236
0
        int Y = (buf0[i]  * yalpha1  + buf1[i]  * yalpha)  >> 19;
3237
0
        int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha) >> 19;
3238
0
        int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha) >> 19;
3239
3240
0
        if (Y & 0x100)
3241
0
            Y = av_clip_uint8(Y);
3242
0
        if (U & 0x100)
3243
0
            U = av_clip_uint8(U);
3244
0
        if (V & 0x100)
3245
0
            V = av_clip_uint8(V);
3246
3247
0
        dest[3 * i    ] = V;
3248
0
        dest[3 * i + 1] = Y;
3249
0
        dest[3 * i + 2] = U;
3250
0
    }
3251
0
}
3252
3253
static void
3254
yuv2vyu444_X_c(SwsInternal *c, const int16_t *lumFilter,
3255
               const int16_t **lumSrc, int lumFilterSize,
3256
               const int16_t *chrFilter, const int16_t **chrUSrc,
3257
               const int16_t **chrVSrc, int chrFilterSize,
3258
               const int16_t **alpSrc, uint8_t *dest, int dstW, int y)
3259
0
{
3260
0
    int i;
3261
3262
0
    for (i = 0; i < dstW; i++) {
3263
0
        int j;
3264
0
        int Y = 1 << 18, U = 1 << 18;
3265
0
        int V = 1 << 18;
3266
3267
0
        for (j = 0; j < lumFilterSize; j++)
3268
0
            Y += lumSrc[j][i] * (unsigned)lumFilter[j];
3269
3270
0
        for (j = 0; j < chrFilterSize; j++)
3271
0
            U += chrUSrc[j][i] * (unsigned)chrFilter[j];
3272
3273
0
        for (j = 0; j < chrFilterSize; j++)
3274
0
            V += chrVSrc[j][i] * (unsigned)chrFilter[j];
3275
3276
0
        Y >>= 19;
3277
0
        U >>= 19;
3278
0
        V >>= 19;
3279
3280
0
        if (Y  & 0x100)
3281
0
            Y = av_clip_uint8(Y);
3282
0
        if (U  & 0x100)
3283
0
            U = av_clip_uint8(U);
3284
0
        if (V  & 0x100)
3285
0
            V = av_clip_uint8(V);
3286
3287
0
        dest[3 * i    ] = V;
3288
0
        dest[3 * i + 1] = Y;
3289
0
        dest[3 * i + 2] = U;
3290
0
    }
3291
0
}
3292
3293
#undef output_pixel
3294
3295
av_cold void ff_sws_init_output_funcs(SwsInternal *c,
3296
                                      yuv2planar1_fn *yuv2plane1,
3297
                                      yuv2planarX_fn *yuv2planeX,
3298
                                      yuv2interleavedX_fn *yuv2nv12cX,
3299
                                      yuv2packed1_fn *yuv2packed1,
3300
                                      yuv2packed2_fn *yuv2packed2,
3301
                                      yuv2packedX_fn *yuv2packedX,
3302
                                      yuv2anyX_fn *yuv2anyX)
3303
0
{
3304
0
    enum AVPixelFormat dstFormat = c->opts.dst_format;
3305
0
    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(dstFormat);
3306
3307
0
    if (isSemiPlanarYUV(dstFormat) && isDataInHighBits(dstFormat)) {
3308
0
        if (desc->comp[0].depth == 10) {
3309
0
            *yuv2plane1 = isBE(dstFormat) ? yuv2p010l1_BE_c : yuv2p010l1_LE_c;
3310
0
            *yuv2planeX = isBE(dstFormat) ? yuv2p010lX_BE_c : yuv2p010lX_LE_c;
3311
0
            *yuv2nv12cX = isBE(dstFormat) ? yuv2p010cX_BE_c : yuv2p010cX_LE_c;
3312
0
        } else if (desc->comp[0].depth == 12) {
3313
0
            *yuv2plane1 = isBE(dstFormat) ? yuv2p012l1_BE_c : yuv2p012l1_LE_c;
3314
0
            *yuv2planeX = isBE(dstFormat) ? yuv2p012lX_BE_c : yuv2p012lX_LE_c;
3315
0
            *yuv2nv12cX = isBE(dstFormat) ? yuv2p012cX_BE_c : yuv2p012cX_LE_c;
3316
0
        } else
3317
0
            av_assert0(0);
3318
0
    } else if (isSemiPlanarYUV(dstFormat) && isNBPS(dstFormat)) {
3319
0
        if (desc->comp[0].depth == 10) {
3320
0
            *yuv2plane1 = isBE(dstFormat) ? yuv2nv20l1_BE_c : yuv2nv20l1_LE_c;
3321
0
            *yuv2planeX = isBE(dstFormat) ? yuv2nv20lX_BE_c : yuv2nv20lX_LE_c;
3322
0
            *yuv2nv12cX = isBE(dstFormat) ? yuv2nv20cX_BE_c : yuv2nv20cX_LE_c;
3323
0
        } else
3324
0
            av_assert0(0);
3325
0
    } else if (is16BPS(dstFormat)) {
3326
0
        *yuv2planeX = isBE(dstFormat) ? yuv2planeX_16BE_c  : yuv2planeX_16LE_c;
3327
0
        *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_16BE_c  : yuv2plane1_16LE_c;
3328
0
        if (isSemiPlanarYUV(dstFormat)) {
3329
0
          *yuv2nv12cX = isBE(dstFormat) ? yuv2nv12cX_16BE_c : yuv2nv12cX_16LE_c;
3330
0
        }
3331
0
    } else if (isDataInHighBits(dstFormat) && isNBPS(dstFormat)) {
3332
0
        if (desc->comp[0].depth == 10) {
3333
0
            *yuv2planeX = isBE(dstFormat) ? yuv2msbplaneX_10BE_c  : yuv2msbplaneX_10LE_c;
3334
0
            *yuv2plane1 = isBE(dstFormat) ? yuv2msbplane1_10BE_c  : yuv2msbplane1_10LE_c;
3335
0
        } else if (desc->comp[0].depth == 12) {
3336
0
            *yuv2planeX = isBE(dstFormat) ? yuv2msbplaneX_12BE_c  : yuv2msbplaneX_12LE_c;
3337
0
            *yuv2plane1 = isBE(dstFormat) ? yuv2msbplane1_12BE_c  : yuv2msbplane1_12LE_c;
3338
0
        } else
3339
0
            av_assert0(0);
3340
0
    } else if (isNBPS(dstFormat)) {
3341
0
        if (desc->comp[0].depth == 9) {
3342
0
            *yuv2planeX = isBE(dstFormat) ? yuv2planeX_9BE_c  : yuv2planeX_9LE_c;
3343
0
            *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_9BE_c  : yuv2plane1_9LE_c;
3344
0
        } else if (desc->comp[0].depth == 10) {
3345
0
            *yuv2planeX = isBE(dstFormat) ? yuv2planeX_10BE_c  : yuv2planeX_10LE_c;
3346
0
            *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_10BE_c  : yuv2plane1_10LE_c;
3347
0
        } else if (desc->comp[0].depth == 12) {
3348
0
            *yuv2planeX = isBE(dstFormat) ? yuv2planeX_12BE_c  : yuv2planeX_12LE_c;
3349
0
            *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_12BE_c  : yuv2plane1_12LE_c;
3350
0
        } else if (desc->comp[0].depth == 14) {
3351
0
            *yuv2planeX = isBE(dstFormat) ? yuv2planeX_14BE_c  : yuv2planeX_14LE_c;
3352
0
            *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_14BE_c  : yuv2plane1_14LE_c;
3353
0
        } else
3354
0
            av_assert0(0);
3355
0
    } else if (dstFormat == AV_PIX_FMT_GRAYF32BE) {
3356
0
        *yuv2planeX = yuv2planeX_floatBE_c;
3357
0
        *yuv2plane1 = yuv2plane1_floatBE_c;
3358
0
    } else if (dstFormat == AV_PIX_FMT_GRAYF32LE) {
3359
0
        *yuv2planeX = yuv2planeX_floatLE_c;
3360
0
        *yuv2plane1 = yuv2plane1_floatLE_c;
3361
0
    } else {
3362
0
        *yuv2plane1 = yuv2plane1_8_c;
3363
0
        *yuv2planeX = yuv2planeX_8_c;
3364
0
        if (isSemiPlanarYUV(dstFormat))
3365
0
            *yuv2nv12cX = yuv2nv12cX_c;
3366
0
    }
3367
3368
0
    if(c->opts.flags & SWS_FULL_CHR_H_INT) {
3369
0
        switch (dstFormat) {
3370
0
            case AV_PIX_FMT_RGBA:
3371
#if CONFIG_SMALL
3372
                *yuv2packedX = yuv2rgba32_full_X_c;
3373
                *yuv2packed2 = yuv2rgba32_full_2_c;
3374
                *yuv2packed1 = yuv2rgba32_full_1_c;
3375
#else
3376
0
#if CONFIG_SWSCALE_ALPHA
3377
0
                if (c->needAlpha) {
3378
0
                    *yuv2packedX = yuv2rgba32_full_X_c;
3379
0
                    *yuv2packed2 = yuv2rgba32_full_2_c;
3380
0
                    *yuv2packed1 = yuv2rgba32_full_1_c;
3381
0
                } else
3382
0
#endif /* CONFIG_SWSCALE_ALPHA */
3383
0
                {
3384
0
                    *yuv2packedX = yuv2rgbx32_full_X_c;
3385
0
                    *yuv2packed2 = yuv2rgbx32_full_2_c;
3386
0
                    *yuv2packed1 = yuv2rgbx32_full_1_c;
3387
0
                }
3388
0
#endif /* !CONFIG_SMALL */
3389
0
                break;
3390
0
            case AV_PIX_FMT_ARGB:
3391
#if CONFIG_SMALL
3392
                *yuv2packedX = yuv2argb32_full_X_c;
3393
                *yuv2packed2 = yuv2argb32_full_2_c;
3394
                *yuv2packed1 = yuv2argb32_full_1_c;
3395
#else
3396
0
#if CONFIG_SWSCALE_ALPHA
3397
0
                if (c->needAlpha) {
3398
0
                    *yuv2packedX = yuv2argb32_full_X_c;
3399
0
                    *yuv2packed2 = yuv2argb32_full_2_c;
3400
0
                    *yuv2packed1 = yuv2argb32_full_1_c;
3401
0
                } else
3402
0
#endif /* CONFIG_SWSCALE_ALPHA */
3403
0
                {
3404
0
                    *yuv2packedX = yuv2xrgb32_full_X_c;
3405
0
                    *yuv2packed2 = yuv2xrgb32_full_2_c;
3406
0
                    *yuv2packed1 = yuv2xrgb32_full_1_c;
3407
0
                }
3408
0
#endif /* !CONFIG_SMALL */
3409
0
                break;
3410
0
            case AV_PIX_FMT_BGRA:
3411
#if CONFIG_SMALL
3412
                *yuv2packedX = yuv2bgra32_full_X_c;
3413
                *yuv2packed2 = yuv2bgra32_full_2_c;
3414
                *yuv2packed1 = yuv2bgra32_full_1_c;
3415
#else
3416
0
#if CONFIG_SWSCALE_ALPHA
3417
0
                if (c->needAlpha) {
3418
0
                    *yuv2packedX = yuv2bgra32_full_X_c;
3419
0
                    *yuv2packed2 = yuv2bgra32_full_2_c;
3420
0
                    *yuv2packed1 = yuv2bgra32_full_1_c;
3421
0
                } else
3422
0
#endif /* CONFIG_SWSCALE_ALPHA */
3423
0
                {
3424
0
                    *yuv2packedX = yuv2bgrx32_full_X_c;
3425
0
                    *yuv2packed2 = yuv2bgrx32_full_2_c;
3426
0
                    *yuv2packed1 = yuv2bgrx32_full_1_c;
3427
0
                }
3428
0
#endif /* !CONFIG_SMALL */
3429
0
                break;
3430
0
            case AV_PIX_FMT_ABGR:
3431
#if CONFIG_SMALL
3432
                *yuv2packedX = yuv2abgr32_full_X_c;
3433
                *yuv2packed2 = yuv2abgr32_full_2_c;
3434
                *yuv2packed1 = yuv2abgr32_full_1_c;
3435
#else
3436
0
#if CONFIG_SWSCALE_ALPHA
3437
0
                if (c->needAlpha) {
3438
0
                    *yuv2packedX = yuv2abgr32_full_X_c;
3439
0
                    *yuv2packed2 = yuv2abgr32_full_2_c;
3440
0
                    *yuv2packed1 = yuv2abgr32_full_1_c;
3441
0
                } else
3442
0
#endif /* CONFIG_SWSCALE_ALPHA */
3443
0
                {
3444
0
                    *yuv2packedX = yuv2xbgr32_full_X_c;
3445
0
                    *yuv2packed2 = yuv2xbgr32_full_2_c;
3446
0
                    *yuv2packed1 = yuv2xbgr32_full_1_c;
3447
0
                }
3448
0
#endif /* !CONFIG_SMALL */
3449
0
                break;
3450
0
        case AV_PIX_FMT_RGBA64LE:
3451
0
#if CONFIG_SWSCALE_ALPHA
3452
0
            if (c->needAlpha) {
3453
0
                *yuv2packedX = yuv2rgba64le_full_X_c;
3454
0
                *yuv2packed2 = yuv2rgba64le_full_2_c;
3455
0
                *yuv2packed1 = yuv2rgba64le_full_1_c;
3456
0
            } else
3457
0
#endif /* CONFIG_SWSCALE_ALPHA */
3458
0
            {
3459
0
                *yuv2packedX = yuv2rgbx64le_full_X_c;
3460
0
                *yuv2packed2 = yuv2rgbx64le_full_2_c;
3461
0
                *yuv2packed1 = yuv2rgbx64le_full_1_c;
3462
0
            }
3463
0
            break;
3464
0
        case AV_PIX_FMT_RGBA64BE:
3465
0
#if CONFIG_SWSCALE_ALPHA
3466
0
            if (c->needAlpha) {
3467
0
                *yuv2packedX = yuv2rgba64be_full_X_c;
3468
0
                *yuv2packed2 = yuv2rgba64be_full_2_c;
3469
0
                *yuv2packed1 = yuv2rgba64be_full_1_c;
3470
0
            } else
3471
0
#endif /* CONFIG_SWSCALE_ALPHA */
3472
0
            {
3473
0
                *yuv2packedX = yuv2rgbx64be_full_X_c;
3474
0
                *yuv2packed2 = yuv2rgbx64be_full_2_c;
3475
0
                *yuv2packed1 = yuv2rgbx64be_full_1_c;
3476
0
            }
3477
0
            break;
3478
0
        case AV_PIX_FMT_BGRA64LE:
3479
0
#if CONFIG_SWSCALE_ALPHA
3480
0
            if (c->needAlpha) {
3481
0
                *yuv2packedX = yuv2bgra64le_full_X_c;
3482
0
                *yuv2packed2 = yuv2bgra64le_full_2_c;
3483
0
                *yuv2packed1 = yuv2bgra64le_full_1_c;
3484
0
            } else
3485
0
#endif /* CONFIG_SWSCALE_ALPHA */
3486
0
            {
3487
0
                *yuv2packedX = yuv2bgrx64le_full_X_c;
3488
0
                *yuv2packed2 = yuv2bgrx64le_full_2_c;
3489
0
                *yuv2packed1 = yuv2bgrx64le_full_1_c;
3490
0
            }
3491
0
            break;
3492
0
        case AV_PIX_FMT_BGRA64BE:
3493
0
#if CONFIG_SWSCALE_ALPHA
3494
0
            if (c->needAlpha) {
3495
0
                *yuv2packedX = yuv2bgra64be_full_X_c;
3496
0
                *yuv2packed2 = yuv2bgra64be_full_2_c;
3497
0
                *yuv2packed1 = yuv2bgra64be_full_1_c;
3498
0
            } else
3499
0
#endif /* CONFIG_SWSCALE_ALPHA */
3500
0
            {
3501
0
                *yuv2packedX = yuv2bgrx64be_full_X_c;
3502
0
                *yuv2packed2 = yuv2bgrx64be_full_2_c;
3503
0
                *yuv2packed1 = yuv2bgrx64be_full_1_c;
3504
0
            }
3505
0
            break;
3506
3507
0
        case AV_PIX_FMT_RGB24:
3508
0
            *yuv2packedX = yuv2rgb24_full_X_c;
3509
0
            *yuv2packed2 = yuv2rgb24_full_2_c;
3510
0
            *yuv2packed1 = yuv2rgb24_full_1_c;
3511
0
            break;
3512
0
        case AV_PIX_FMT_BGR24:
3513
0
            *yuv2packedX = yuv2bgr24_full_X_c;
3514
0
            *yuv2packed2 = yuv2bgr24_full_2_c;
3515
0
            *yuv2packed1 = yuv2bgr24_full_1_c;
3516
0
            break;
3517
0
        case AV_PIX_FMT_RGB48LE:
3518
0
            *yuv2packedX = yuv2rgb48le_full_X_c;
3519
0
            *yuv2packed2 = yuv2rgb48le_full_2_c;
3520
0
            *yuv2packed1 = yuv2rgb48le_full_1_c;
3521
0
            break;
3522
0
        case AV_PIX_FMT_BGR48LE:
3523
0
            *yuv2packedX = yuv2bgr48le_full_X_c;
3524
0
            *yuv2packed2 = yuv2bgr48le_full_2_c;
3525
0
            *yuv2packed1 = yuv2bgr48le_full_1_c;
3526
0
            break;
3527
0
        case AV_PIX_FMT_RGB48BE:
3528
0
            *yuv2packedX = yuv2rgb48be_full_X_c;
3529
0
            *yuv2packed2 = yuv2rgb48be_full_2_c;
3530
0
            *yuv2packed1 = yuv2rgb48be_full_1_c;
3531
0
            break;
3532
0
        case AV_PIX_FMT_BGR48BE:
3533
0
            *yuv2packedX = yuv2bgr48be_full_X_c;
3534
0
            *yuv2packed2 = yuv2bgr48be_full_2_c;
3535
0
            *yuv2packed1 = yuv2bgr48be_full_1_c;
3536
0
            break;
3537
0
        case AV_PIX_FMT_BGR4_BYTE:
3538
0
            *yuv2packedX = yuv2bgr4_byte_full_X_c;
3539
0
            *yuv2packed2 = yuv2bgr4_byte_full_2_c;
3540
0
            *yuv2packed1 = yuv2bgr4_byte_full_1_c;
3541
0
            break;
3542
0
        case AV_PIX_FMT_RGB4_BYTE:
3543
0
            *yuv2packedX = yuv2rgb4_byte_full_X_c;
3544
0
            *yuv2packed2 = yuv2rgb4_byte_full_2_c;
3545
0
            *yuv2packed1 = yuv2rgb4_byte_full_1_c;
3546
0
            break;
3547
0
        case AV_PIX_FMT_BGR8:
3548
0
            *yuv2packedX = yuv2bgr8_full_X_c;
3549
0
            *yuv2packed2 = yuv2bgr8_full_2_c;
3550
0
            *yuv2packed1 = yuv2bgr8_full_1_c;
3551
0
            break;
3552
0
        case AV_PIX_FMT_RGB8:
3553
0
            *yuv2packedX = yuv2rgb8_full_X_c;
3554
0
            *yuv2packed2 = yuv2rgb8_full_2_c;
3555
0
            *yuv2packed1 = yuv2rgb8_full_1_c;
3556
0
            break;
3557
0
        case AV_PIX_FMT_X2RGB10LE:
3558
0
            *yuv2packedX = yuv2x2rgb10_full_X_c;
3559
0
            *yuv2packed2 = yuv2x2rgb10_full_2_c;
3560
0
            *yuv2packed1 = yuv2x2rgb10_full_1_c;
3561
0
            break;
3562
0
        case AV_PIX_FMT_X2BGR10LE:
3563
0
            *yuv2packedX = yuv2x2bgr10_full_X_c;
3564
0
            *yuv2packed2 = yuv2x2bgr10_full_2_c;
3565
0
            *yuv2packed1 = yuv2x2bgr10_full_1_c;
3566
0
            break;
3567
0
        case AV_PIX_FMT_GBRP:
3568
0
        case AV_PIX_FMT_GBRP9BE:
3569
0
        case AV_PIX_FMT_GBRP9LE:
3570
0
        case AV_PIX_FMT_GBRP10BE:
3571
0
        case AV_PIX_FMT_GBRP10LE:
3572
0
        case AV_PIX_FMT_GBRP12BE:
3573
0
        case AV_PIX_FMT_GBRP12LE:
3574
0
        case AV_PIX_FMT_GBRP14BE:
3575
0
        case AV_PIX_FMT_GBRP14LE:
3576
0
        case AV_PIX_FMT_GBRAP:
3577
0
        case AV_PIX_FMT_GBRAP10BE:
3578
0
        case AV_PIX_FMT_GBRAP10LE:
3579
0
        case AV_PIX_FMT_GBRAP12BE:
3580
0
        case AV_PIX_FMT_GBRAP12LE:
3581
0
        case AV_PIX_FMT_GBRAP14BE:
3582
0
        case AV_PIX_FMT_GBRAP14LE:
3583
0
            *yuv2anyX = yuv2gbrp_full_X_c;
3584
0
            break;
3585
0
        case AV_PIX_FMT_GBRP10MSBBE:
3586
0
        case AV_PIX_FMT_GBRP10MSBLE:
3587
0
        case AV_PIX_FMT_GBRP12MSBBE:
3588
0
        case AV_PIX_FMT_GBRP12MSBLE:
3589
0
            *yuv2anyX = yuv2gbrpmsb_full_X_c;
3590
0
            break;
3591
0
        case AV_PIX_FMT_GBRP16BE:
3592
0
        case AV_PIX_FMT_GBRP16LE:
3593
0
        case AV_PIX_FMT_GBRAP16BE:
3594
0
        case AV_PIX_FMT_GBRAP16LE:
3595
0
            *yuv2anyX = yuv2gbrp16_full_X_c;
3596
0
            break;
3597
0
        case AV_PIX_FMT_GBRPF32BE:
3598
0
        case AV_PIX_FMT_GBRPF32LE:
3599
0
        case AV_PIX_FMT_GBRAPF32BE:
3600
0
        case AV_PIX_FMT_GBRAPF32LE:
3601
0
            *yuv2anyX = yuv2gbrpf32_full_X_c;
3602
0
            break;
3603
0
        }
3604
0
        if (!*yuv2packedX && !*yuv2anyX)
3605
0
            goto YUV_PACKED;
3606
0
    } else {
3607
0
        YUV_PACKED:
3608
0
        switch (dstFormat) {
3609
0
        case AV_PIX_FMT_RGBA64LE:
3610
0
#if CONFIG_SWSCALE_ALPHA
3611
0
            if (c->needAlpha) {
3612
0
                *yuv2packed1 = yuv2rgba64le_1_c;
3613
0
                *yuv2packed2 = yuv2rgba64le_2_c;
3614
0
                *yuv2packedX = yuv2rgba64le_X_c;
3615
0
            } else
3616
0
#endif /* CONFIG_SWSCALE_ALPHA */
3617
0
            {
3618
0
                *yuv2packed1 = yuv2rgbx64le_1_c;
3619
0
                *yuv2packed2 = yuv2rgbx64le_2_c;
3620
0
                *yuv2packedX = yuv2rgbx64le_X_c;
3621
0
            }
3622
0
            break;
3623
0
        case AV_PIX_FMT_RGBA64BE:
3624
0
#if CONFIG_SWSCALE_ALPHA
3625
0
            if (c->needAlpha) {
3626
0
                *yuv2packed1 = yuv2rgba64be_1_c;
3627
0
                *yuv2packed2 = yuv2rgba64be_2_c;
3628
0
                *yuv2packedX = yuv2rgba64be_X_c;
3629
0
            } else
3630
0
#endif /* CONFIG_SWSCALE_ALPHA */
3631
0
            {
3632
0
                *yuv2packed1 = yuv2rgbx64be_1_c;
3633
0
                *yuv2packed2 = yuv2rgbx64be_2_c;
3634
0
                *yuv2packedX = yuv2rgbx64be_X_c;
3635
0
            }
3636
0
            break;
3637
0
        case AV_PIX_FMT_BGRA64LE:
3638
0
#if CONFIG_SWSCALE_ALPHA
3639
0
            if (c->needAlpha) {
3640
0
                *yuv2packed1 = yuv2bgra64le_1_c;
3641
0
                *yuv2packed2 = yuv2bgra64le_2_c;
3642
0
                *yuv2packedX = yuv2bgra64le_X_c;
3643
0
            } else
3644
0
#endif /* CONFIG_SWSCALE_ALPHA */
3645
0
            {
3646
0
                *yuv2packed1 = yuv2bgrx64le_1_c;
3647
0
                *yuv2packed2 = yuv2bgrx64le_2_c;
3648
0
                *yuv2packedX = yuv2bgrx64le_X_c;
3649
0
            }
3650
0
            break;
3651
0
        case AV_PIX_FMT_BGRA64BE:
3652
0
#if CONFIG_SWSCALE_ALPHA
3653
0
            if (c->needAlpha) {
3654
0
                *yuv2packed1 = yuv2bgra64be_1_c;
3655
0
                *yuv2packed2 = yuv2bgra64be_2_c;
3656
0
                *yuv2packedX = yuv2bgra64be_X_c;
3657
0
            } else
3658
0
#endif /* CONFIG_SWSCALE_ALPHA */
3659
0
            {
3660
0
                *yuv2packed1 = yuv2bgrx64be_1_c;
3661
0
                *yuv2packed2 = yuv2bgrx64be_2_c;
3662
0
                *yuv2packedX = yuv2bgrx64be_X_c;
3663
0
            }
3664
0
            break;
3665
0
        case AV_PIX_FMT_RGB48LE:
3666
0
            *yuv2packed1 = yuv2rgb48le_1_c;
3667
0
            *yuv2packed2 = yuv2rgb48le_2_c;
3668
0
            *yuv2packedX = yuv2rgb48le_X_c;
3669
0
            break;
3670
0
        case AV_PIX_FMT_RGB48BE:
3671
0
            *yuv2packed1 = yuv2rgb48be_1_c;
3672
0
            *yuv2packed2 = yuv2rgb48be_2_c;
3673
0
            *yuv2packedX = yuv2rgb48be_X_c;
3674
0
            break;
3675
0
        case AV_PIX_FMT_BGR48LE:
3676
0
            *yuv2packed1 = yuv2bgr48le_1_c;
3677
0
            *yuv2packed2 = yuv2bgr48le_2_c;
3678
0
            *yuv2packedX = yuv2bgr48le_X_c;
3679
0
            break;
3680
0
        case AV_PIX_FMT_BGR48BE:
3681
0
            *yuv2packed1 = yuv2bgr48be_1_c;
3682
0
            *yuv2packed2 = yuv2bgr48be_2_c;
3683
0
            *yuv2packedX = yuv2bgr48be_X_c;
3684
0
            break;
3685
0
        case AV_PIX_FMT_RGB32:
3686
0
        case AV_PIX_FMT_BGR32:
3687
#if CONFIG_SMALL
3688
            *yuv2packed1 = yuv2rgb32_1_c;
3689
            *yuv2packed2 = yuv2rgb32_2_c;
3690
            *yuv2packedX = yuv2rgb32_X_c;
3691
#else
3692
0
#if CONFIG_SWSCALE_ALPHA
3693
0
                if (c->needAlpha) {
3694
0
                    *yuv2packed1 = yuv2rgba32_1_c;
3695
0
                    *yuv2packed2 = yuv2rgba32_2_c;
3696
0
                    *yuv2packedX = yuv2rgba32_X_c;
3697
0
                } else
3698
0
#endif /* CONFIG_SWSCALE_ALPHA */
3699
0
                {
3700
0
                    *yuv2packed1 = yuv2rgbx32_1_c;
3701
0
                    *yuv2packed2 = yuv2rgbx32_2_c;
3702
0
                    *yuv2packedX = yuv2rgbx32_X_c;
3703
0
                }
3704
0
#endif /* !CONFIG_SMALL */
3705
0
            break;
3706
0
        case AV_PIX_FMT_RGB32_1:
3707
0
        case AV_PIX_FMT_BGR32_1:
3708
#if CONFIG_SMALL
3709
                *yuv2packed1 = yuv2rgb32_1_1_c;
3710
                *yuv2packed2 = yuv2rgb32_1_2_c;
3711
                *yuv2packedX = yuv2rgb32_1_X_c;
3712
#else
3713
0
#if CONFIG_SWSCALE_ALPHA
3714
0
                if (c->needAlpha) {
3715
0
                    *yuv2packed1 = yuv2rgba32_1_1_c;
3716
0
                    *yuv2packed2 = yuv2rgba32_1_2_c;
3717
0
                    *yuv2packedX = yuv2rgba32_1_X_c;
3718
0
                } else
3719
0
#endif /* CONFIG_SWSCALE_ALPHA */
3720
0
                {
3721
0
                    *yuv2packed1 = yuv2rgbx32_1_1_c;
3722
0
                    *yuv2packed2 = yuv2rgbx32_1_2_c;
3723
0
                    *yuv2packedX = yuv2rgbx32_1_X_c;
3724
0
                }
3725
0
#endif /* !CONFIG_SMALL */
3726
0
                break;
3727
0
        case AV_PIX_FMT_RGB24:
3728
0
            *yuv2packed1 = yuv2rgb24_1_c;
3729
0
            *yuv2packed2 = yuv2rgb24_2_c;
3730
0
            *yuv2packedX = yuv2rgb24_X_c;
3731
0
            break;
3732
0
        case AV_PIX_FMT_BGR24:
3733
0
            *yuv2packed1 = yuv2bgr24_1_c;
3734
0
            *yuv2packed2 = yuv2bgr24_2_c;
3735
0
            *yuv2packedX = yuv2bgr24_X_c;
3736
0
            break;
3737
0
        case AV_PIX_FMT_RGB565LE:
3738
0
        case AV_PIX_FMT_RGB565BE:
3739
0
        case AV_PIX_FMT_BGR565LE:
3740
0
        case AV_PIX_FMT_BGR565BE:
3741
0
            *yuv2packed1 = yuv2rgb16_1_c;
3742
0
            *yuv2packed2 = yuv2rgb16_2_c;
3743
0
            *yuv2packedX = yuv2rgb16_X_c;
3744
0
            break;
3745
0
        case AV_PIX_FMT_RGB555LE:
3746
0
        case AV_PIX_FMT_RGB555BE:
3747
0
        case AV_PIX_FMT_BGR555LE:
3748
0
        case AV_PIX_FMT_BGR555BE:
3749
0
            *yuv2packed1 = yuv2rgb15_1_c;
3750
0
            *yuv2packed2 = yuv2rgb15_2_c;
3751
0
            *yuv2packedX = yuv2rgb15_X_c;
3752
0
            break;
3753
0
        case AV_PIX_FMT_RGB444LE:
3754
0
        case AV_PIX_FMT_RGB444BE:
3755
0
        case AV_PIX_FMT_BGR444LE:
3756
0
        case AV_PIX_FMT_BGR444BE:
3757
0
            *yuv2packed1 = yuv2rgb12_1_c;
3758
0
            *yuv2packed2 = yuv2rgb12_2_c;
3759
0
            *yuv2packedX = yuv2rgb12_X_c;
3760
0
            break;
3761
0
        case AV_PIX_FMT_RGB8:
3762
0
        case AV_PIX_FMT_BGR8:
3763
0
            *yuv2packed1 = yuv2rgb8_1_c;
3764
0
            *yuv2packed2 = yuv2rgb8_2_c;
3765
0
            *yuv2packedX = yuv2rgb8_X_c;
3766
0
            break;
3767
0
        case AV_PIX_FMT_RGB4:
3768
0
        case AV_PIX_FMT_BGR4:
3769
0
            *yuv2packed1 = yuv2rgb4_1_c;
3770
0
            *yuv2packed2 = yuv2rgb4_2_c;
3771
0
            *yuv2packedX = yuv2rgb4_X_c;
3772
0
            break;
3773
0
        case AV_PIX_FMT_RGB4_BYTE:
3774
0
        case AV_PIX_FMT_BGR4_BYTE:
3775
0
            *yuv2packed1 = yuv2rgb4b_1_c;
3776
0
            *yuv2packed2 = yuv2rgb4b_2_c;
3777
0
            *yuv2packedX = yuv2rgb4b_X_c;
3778
0
            break;
3779
0
        case AV_PIX_FMT_X2RGB10LE:
3780
0
        case AV_PIX_FMT_X2RGB10BE:
3781
0
            *yuv2packed1 = yuv2x2rgb10_1_c;
3782
0
            *yuv2packed2 = yuv2x2rgb10_2_c;
3783
0
            *yuv2packedX = yuv2x2rgb10_X_c;
3784
0
            break;
3785
0
        case AV_PIX_FMT_X2BGR10LE:
3786
0
        case AV_PIX_FMT_X2BGR10BE:
3787
0
            *yuv2packed1 = yuv2x2bgr10_1_c;
3788
0
            *yuv2packed2 = yuv2x2bgr10_2_c;
3789
0
            *yuv2packedX = yuv2x2bgr10_X_c;
3790
0
            break;
3791
0
        }
3792
0
    }
3793
0
    switch (dstFormat) {
3794
0
    case AV_PIX_FMT_MONOWHITE:
3795
0
        *yuv2packed1 = yuv2monowhite_1_c;
3796
0
        *yuv2packed2 = yuv2monowhite_2_c;
3797
0
        *yuv2packedX = yuv2monowhite_X_c;
3798
0
        break;
3799
0
    case AV_PIX_FMT_MONOBLACK:
3800
0
        *yuv2packed1 = yuv2monoblack_1_c;
3801
0
        *yuv2packed2 = yuv2monoblack_2_c;
3802
0
        *yuv2packedX = yuv2monoblack_X_c;
3803
0
        break;
3804
0
    case AV_PIX_FMT_YUYV422:
3805
0
        *yuv2packed1 = yuv2yuyv422_1_c;
3806
0
        *yuv2packed2 = yuv2yuyv422_2_c;
3807
0
        *yuv2packedX = yuv2yuyv422_X_c;
3808
0
        break;
3809
0
    case AV_PIX_FMT_YVYU422:
3810
0
        *yuv2packed1 = yuv2yvyu422_1_c;
3811
0
        *yuv2packed2 = yuv2yvyu422_2_c;
3812
0
        *yuv2packedX = yuv2yvyu422_X_c;
3813
0
        break;
3814
0
    case AV_PIX_FMT_UYVY422:
3815
0
        *yuv2packed1 = yuv2uyvy422_1_c;
3816
0
        *yuv2packed2 = yuv2uyvy422_2_c;
3817
0
        *yuv2packedX = yuv2uyvy422_X_c;
3818
0
        break;
3819
0
    case AV_PIX_FMT_VYU444:
3820
0
        *yuv2packed1 = yuv2vyu444_1_c;
3821
0
        *yuv2packed2 = yuv2vyu444_2_c;
3822
0
        *yuv2packedX = yuv2vyu444_X_c;
3823
0
        break;
3824
0
    case AV_PIX_FMT_YA8:
3825
0
        *yuv2packed1 = yuv2ya8_1_c;
3826
0
        *yuv2packed2 = yuv2ya8_2_c;
3827
0
        *yuv2packedX = yuv2ya8_X_c;
3828
0
        break;
3829
0
    case AV_PIX_FMT_YA16LE:
3830
0
        *yuv2packed1 = yuv2ya16le_1_c;
3831
0
        *yuv2packed2 = yuv2ya16le_2_c;
3832
0
        *yuv2packedX = yuv2ya16le_X_c;
3833
0
        break;
3834
0
    case AV_PIX_FMT_YA16BE:
3835
0
        *yuv2packed1 = yuv2ya16be_1_c;
3836
0
        *yuv2packed2 = yuv2ya16be_2_c;
3837
0
        *yuv2packedX = yuv2ya16be_X_c;
3838
0
        break;
3839
0
    case AV_PIX_FMT_V30XLE:
3840
0
        *yuv2packedX = yuv2v30xle_X_c;
3841
0
        break;
3842
0
    case AV_PIX_FMT_AYUV64LE:
3843
0
        *yuv2packedX = yuv2ayuv64le_X_c;
3844
0
        break;
3845
0
    case AV_PIX_FMT_AYUV64BE:
3846
0
        *yuv2packedX = yuv2ayuv64be_X_c;
3847
0
        break;
3848
0
    case AV_PIX_FMT_AYUV:
3849
0
        *yuv2packed1 = yuv2ayuv_1_c;
3850
0
        *yuv2packed2 = yuv2ayuv_2_c;
3851
0
        *yuv2packedX = yuv2ayuv_X_c;
3852
0
        break;
3853
0
    case AV_PIX_FMT_VUYA:
3854
0
    case AV_PIX_FMT_VUYX:
3855
0
        *yuv2packed1 = yuv2vuyX_1_c;
3856
0
        *yuv2packed2 = yuv2vuyX_2_c;
3857
0
        *yuv2packedX = yuv2vuyX_X_c;
3858
0
        break;
3859
0
    case AV_PIX_FMT_UYVA:
3860
0
        *yuv2packed1 = yuv2uyva_1_c;
3861
0
        *yuv2packed2 = yuv2uyva_2_c;
3862
0
        *yuv2packedX = yuv2uyva_X_c;
3863
0
        break;
3864
0
    case AV_PIX_FMT_XV30LE:
3865
0
        *yuv2packedX = yuv2xv30le_X_c;
3866
0
        break;
3867
0
    case AV_PIX_FMT_XV36LE:
3868
0
        *yuv2packedX = yuv2xv36le_X_c;
3869
0
        break;
3870
0
    case AV_PIX_FMT_XV36BE:
3871
0
        *yuv2packedX = yuv2xv36be_X_c;
3872
0
        break;
3873
0
    case AV_PIX_FMT_XV48LE:
3874
0
        *yuv2packedX = yuv2xv48le_X_c;
3875
0
        break;
3876
0
    case AV_PIX_FMT_XV48BE:
3877
0
        *yuv2packedX = yuv2xv48be_X_c;
3878
0
        break;
3879
0
    case AV_PIX_FMT_Y210LE:
3880
0
        *yuv2packedX = yuv2y210le_X_c;
3881
0
        break;
3882
0
    case AV_PIX_FMT_Y212LE:
3883
0
        *yuv2packedX = yuv2y212le_X_c;
3884
0
        break;
3885
0
    case AV_PIX_FMT_Y216LE:
3886
0
        *yuv2packedX = yuv2y216le_X_c;
3887
0
        break;
3888
0
    }
3889
0
}