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