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