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