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