FFmpeg  4.3.9
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/cpu.h"
31 #include "libavutil/intreadwrite.h"
32 #include "libavutil/mathematics.h"
33 #include "libavutil/pixdesc.h"
34 #include "config.h"
35 #include "rgb2rgb.h"
36 #include "swscale.h"
37 #include "swscale_internal.h"
38 
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 
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 
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 
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 
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
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 output_pixel(pos, val, bias, signedness) \
137  if (big_endian) { \
138  AV_WB16(pos, bias + av_clip_ ## signedness ## 16(val >> shift)); \
139  } else { \
140  AV_WL16(pos, bias + av_clip_ ## signedness ## 16(val >> shift)); \
141  }
142 
143 static av_always_inline void
144 yuv2plane1_16_c_template(const int32_t *src, uint16_t *dest, int dstW,
145  int big_endian, int output_bits)
146 {
147  int i;
148  int shift = 3;
149  av_assert0(output_bits == 16);
150 
151  for (i = 0; i < dstW; i++) {
152  int val = src[i] + (1 << (shift - 1));
153  output_pixel(&dest[i], val, 0, uint);
154  }
155 }
156 
157 static av_always_inline void
158 yuv2planeX_16_c_template(const int16_t *filter, int filterSize,
159  const int32_t **src, uint16_t *dest, int dstW,
160  int big_endian, int output_bits)
161 {
162  int i;
163  int shift = 15;
164  av_assert0(output_bits == 16);
165 
166  for (i = 0; i < dstW; i++) {
167  int val = 1 << (shift - 1);
168  int j;
169 
170  /* range of val is [0,0x7FFFFFFF], so 31 bits, but with lanczos/spline
171  * filters (or anything with negative coeffs, the range can be slightly
172  * wider in both directions. To account for this overflow, we subtract
173  * a constant so it always fits in the signed range (assuming a
174  * reasonable filterSize), and re-add that at the end. */
175  val -= 0x40000000;
176  for (j = 0; j < filterSize; j++)
177  val += src[j][i] * (unsigned)filter[j];
178 
179  output_pixel(&dest[i], val, 0x8000, int);
180  }
181 }
182 
183 static void yuv2p016cX_c(SwsContext *c, const int16_t *chrFilter, int chrFilterSize,
184  const int16_t **chrUSrc, const int16_t **chrVSrc,
185  uint8_t *dest8, int chrDstW)
186 {
187  uint16_t *dest = (uint16_t*)dest8;
188  const int32_t **uSrc = (const int32_t **)chrUSrc;
189  const int32_t **vSrc = (const int32_t **)chrVSrc;
190  int shift = 15;
191  int big_endian = c->dstFormat == AV_PIX_FMT_P016BE;
192  int i, j;
193 
194  for (i = 0; i < chrDstW; i++) {
195  int u = 1 << (shift - 1);
196  int v = 1 << (shift - 1);
197 
198  /* See yuv2planeX_16_c_template for details. */
199  u -= 0x40000000;
200  v -= 0x40000000;
201  for (j = 0; j < chrFilterSize; j++) {
202  u += uSrc[j][i] * (unsigned)chrFilter[j];
203  v += vSrc[j][i] * (unsigned)chrFilter[j];
204  }
205 
206  output_pixel(&dest[2*i] , u, 0x8000, int);
207  output_pixel(&dest[2*i+1], v, 0x8000, int);
208  }
209 }
210 
211 static av_always_inline void
212 yuv2plane1_float_c_template(const int32_t *src, float *dest, int dstW)
213 {
214  static const int big_endian = HAVE_BIGENDIAN;
215  static const int shift = 3;
216  static const float float_mult = 1.0f / 65535.0f;
217  int i, val;
218  uint16_t val_uint;
219 
220  for (i = 0; i < dstW; ++i){
221  val = src[i] + (1 << (shift - 1));
222  output_pixel(&val_uint, val, 0, uint);
223  dest[i] = float_mult * (float)val_uint;
224  }
225 }
226 
227 static av_always_inline void
228 yuv2plane1_float_bswap_c_template(const int32_t *src, uint32_t *dest, int dstW)
229 {
230  static const int big_endian = HAVE_BIGENDIAN;
231  static const int shift = 3;
232  static const float float_mult = 1.0f / 65535.0f;
233  int i, val;
234  uint16_t val_uint;
235 
236  for (i = 0; i < dstW; ++i){
237  val = src[i] + (1 << (shift - 1));
238  output_pixel(&val_uint, val, 0, uint);
239  dest[i] = av_bswap32(av_float2int(float_mult * (float)val_uint));
240  }
241 }
242 
243 static av_always_inline void
244 yuv2planeX_float_c_template(const int16_t *filter, int filterSize, const int32_t **src,
245  float *dest, int dstW)
246 {
247  static const int big_endian = HAVE_BIGENDIAN;
248  static const int shift = 15;
249  static const float float_mult = 1.0f / 65535.0f;
250  int i, j, val;
251  uint16_t val_uint;
252 
253  for (i = 0; i < dstW; ++i){
254  val = (1 << (shift - 1)) - 0x40000000;
255  for (j = 0; j < filterSize; ++j){
256  val += src[j][i] * (unsigned)filter[j];
257  }
258  output_pixel(&val_uint, val, 0x8000, int);
259  dest[i] = float_mult * (float)val_uint;
260  }
261 }
262 
263 static av_always_inline void
264 yuv2planeX_float_bswap_c_template(const int16_t *filter, int filterSize, const int32_t **src,
265  uint32_t *dest, int dstW)
266 {
267  static const int big_endian = HAVE_BIGENDIAN;
268  static const int shift = 15;
269  static const float float_mult = 1.0f / 65535.0f;
270  int i, j, val;
271  uint16_t val_uint;
272 
273  for (i = 0; i < dstW; ++i){
274  val = (1 << (shift - 1)) - 0x40000000;
275  for (j = 0; j < filterSize; ++j){
276  val += src[j][i] * (unsigned)filter[j];
277  }
278  output_pixel(&val_uint, val, 0x8000, int);
279  dest[i] = av_bswap32(av_float2int(float_mult * (float)val_uint));
280  }
281 }
282 
283 #define yuv2plane1_float(template, dest_type, BE_LE) \
284 static void yuv2plane1_float ## BE_LE ## _c(const int16_t *src, uint8_t *dest, int dstW, \
285  const uint8_t *dither, int offset) \
286 { \
287  template((const int32_t *)src, (dest_type *)dest, dstW); \
288 }
289 
290 #define yuv2planeX_float(template, dest_type, BE_LE) \
291 static void yuv2planeX_float ## BE_LE ## _c(const int16_t *filter, int filterSize, \
292  const int16_t **src, uint8_t *dest, int dstW, \
293  const uint8_t *dither, int offset) \
294 { \
295  template(filter, filterSize, (const int32_t **)src, (dest_type *)dest, dstW); \
296 }
297 
298 #if HAVE_BIGENDIAN
303 #else
308 #endif
309 
310 #undef output_pixel
311 
312 #define output_pixel(pos, val) \
313  if (big_endian) { \
314  AV_WB16(pos, av_clip_uintp2(val >> shift, output_bits)); \
315  } else { \
316  AV_WL16(pos, av_clip_uintp2(val >> shift, output_bits)); \
317  }
318 
319 static av_always_inline void
320 yuv2plane1_10_c_template(const int16_t *src, uint16_t *dest, int dstW,
321  int big_endian, int output_bits)
322 {
323  int i;
324  int shift = 15 - output_bits;
325 
326  for (i = 0; i < dstW; i++) {
327  int val = src[i] + (1 << (shift - 1));
328  output_pixel(&dest[i], val);
329  }
330 }
331 
332 static av_always_inline void
333 yuv2planeX_10_c_template(const int16_t *filter, int filterSize,
334  const int16_t **src, uint16_t *dest, int dstW,
335  int big_endian, int output_bits)
336 {
337  int i;
338  int shift = 11 + 16 - output_bits;
339 
340  for (i = 0; i < dstW; i++) {
341  int val = 1 << (shift - 1);
342  int j;
343 
344  for (j = 0; j < filterSize; j++)
345  val += src[j][i] * filter[j];
346 
347  output_pixel(&dest[i], val);
348  }
349 }
350 
351 #undef output_pixel
352 
353 #define yuv2NBPS(bits, BE_LE, is_be, template_size, typeX_t) \
354 static void yuv2plane1_ ## bits ## BE_LE ## _c(const int16_t *src, \
355  uint8_t *dest, int dstW, \
356  const uint8_t *dither, int offset)\
357 { \
358  yuv2plane1_ ## template_size ## _c_template((const typeX_t *) src, \
359  (uint16_t *) dest, dstW, is_be, bits); \
360 }\
361 static void yuv2planeX_ ## bits ## BE_LE ## _c(const int16_t *filter, int filterSize, \
362  const int16_t **src, uint8_t *dest, int dstW, \
363  const uint8_t *dither, int offset)\
364 { \
365  yuv2planeX_## template_size ## _c_template(filter, \
366  filterSize, (const typeX_t **) src, \
367  (uint16_t *) dest, dstW, is_be, bits); \
368 }
369 yuv2NBPS( 9, BE, 1, 10, int16_t)
370 yuv2NBPS( 9, LE, 0, 10, int16_t)
371 yuv2NBPS(10, BE, 1, 10, int16_t)
372 yuv2NBPS(10, LE, 0, 10, int16_t)
373 yuv2NBPS(12, BE, 1, 10, int16_t)
374 yuv2NBPS(12, LE, 0, 10, int16_t)
375 yuv2NBPS(14, BE, 1, 10, int16_t)
376 yuv2NBPS(14, LE, 0, 10, int16_t)
377 yuv2NBPS(16, BE, 1, 16, int32_t)
378 yuv2NBPS(16, LE, 0, 16, int32_t)
379 
380 static void yuv2planeX_8_c(const int16_t *filter, int filterSize,
381  const int16_t **src, uint8_t *dest, int dstW,
382  const uint8_t *dither, int offset)
383 {
384  int i;
385  for (i=0; i<dstW; i++) {
386  int val = dither[(i + offset) & 7] << 12;
387  int j;
388  for (j=0; j<filterSize; j++)
389  val += src[j][i] * filter[j];
390 
391  dest[i]= av_clip_uint8(val>>19);
392  }
393 }
394 
395 static void yuv2plane1_8_c(const int16_t *src, uint8_t *dest, int dstW,
396  const uint8_t *dither, int offset)
397 {
398  int i;
399  for (i=0; i<dstW; i++) {
400  int val = (src[i] + dither[(i + offset) & 7]) >> 7;
401  dest[i]= av_clip_uint8(val);
402  }
403 }
404 
405 static void yuv2nv12cX_c(SwsContext *c, const int16_t *chrFilter, int chrFilterSize,
406  const int16_t **chrUSrc, const int16_t **chrVSrc,
407  uint8_t *dest, int chrDstW)
408 {
409  enum AVPixelFormat dstFormat = c->dstFormat;
410  const uint8_t *chrDither = c->chrDither8;
411  int i;
412 
413  if (dstFormat == AV_PIX_FMT_NV12 ||
414  dstFormat == AV_PIX_FMT_NV24)
415  for (i=0; i<chrDstW; i++) {
416  int u = chrDither[i & 7] << 12;
417  int v = chrDither[(i + 3) & 7] << 12;
418  int j;
419  for (j=0; j<chrFilterSize; j++) {
420  u += chrUSrc[j][i] * chrFilter[j];
421  v += chrVSrc[j][i] * chrFilter[j];
422  }
423 
424  dest[2*i]= av_clip_uint8(u>>19);
425  dest[2*i+1]= av_clip_uint8(v>>19);
426  }
427  else
428  for (i=0; i<chrDstW; i++) {
429  int u = chrDither[i & 7] << 12;
430  int v = chrDither[(i + 3) & 7] << 12;
431  int j;
432  for (j=0; j<chrFilterSize; j++) {
433  u += chrUSrc[j][i] * chrFilter[j];
434  v += chrVSrc[j][i] * chrFilter[j];
435  }
436 
437  dest[2*i]= av_clip_uint8(v>>19);
438  dest[2*i+1]= av_clip_uint8(u>>19);
439  }
440 }
441 
442 
443 #define output_pixel(pos, val) \
444  if (big_endian) { \
445  AV_WB16(pos, av_clip_uintp2(val >> shift, 10) << 6); \
446  } else { \
447  AV_WL16(pos, av_clip_uintp2(val >> shift, 10) << 6); \
448  }
449 
450 static void yuv2p010l1_c(const int16_t *src,
451  uint16_t *dest, int dstW,
452  int big_endian)
453 {
454  int i;
455  int shift = 5;
456 
457  for (i = 0; i < dstW; i++) {
458  int val = src[i] + (1 << (shift - 1));
459  output_pixel(&dest[i], val);
460  }
461 }
462 
463 static void yuv2p010lX_c(const int16_t *filter, int filterSize,
464  const int16_t **src, uint16_t *dest, int dstW,
465  int big_endian)
466 {
467  int i, j;
468  int shift = 17;
469 
470  for (i = 0; i < dstW; i++) {
471  int val = 1 << (shift - 1);
472 
473  for (j = 0; j < filterSize; j++)
474  val += src[j][i] * filter[j];
475 
476  output_pixel(&dest[i], val);
477  }
478 }
479 
480 static void yuv2p010cX_c(SwsContext *c, const int16_t *chrFilter, int chrFilterSize,
481  const int16_t **chrUSrc, const int16_t **chrVSrc,
482  uint8_t *dest8, int chrDstW)
483 {
484  uint16_t *dest = (uint16_t*)dest8;
485  int shift = 17;
486  int big_endian = c->dstFormat == AV_PIX_FMT_P010BE;
487  int i, j;
488 
489  for (i = 0; i < chrDstW; i++) {
490  int u = 1 << (shift - 1);
491  int v = 1 << (shift - 1);
492 
493  for (j = 0; j < chrFilterSize; j++) {
494  u += chrUSrc[j][i] * chrFilter[j];
495  v += chrVSrc[j][i] * chrFilter[j];
496  }
497 
498  output_pixel(&dest[2*i] , u);
499  output_pixel(&dest[2*i+1], v);
500  }
501 }
502 
503 static void yuv2p010l1_LE_c(const int16_t *src,
504  uint8_t *dest, int dstW,
505  const uint8_t *dither, int offset)
506 {
507  yuv2p010l1_c(src, (uint16_t*)dest, dstW, 0);
508 }
509 
510 static void yuv2p010l1_BE_c(const int16_t *src,
511  uint8_t *dest, int dstW,
512  const uint8_t *dither, int offset)
513 {
514  yuv2p010l1_c(src, (uint16_t*)dest, dstW, 1);
515 }
516 
517 static void yuv2p010lX_LE_c(const int16_t *filter, int filterSize,
518  const int16_t **src, uint8_t *dest, int dstW,
519  const uint8_t *dither, int offset)
520 {
521  yuv2p010lX_c(filter, filterSize, src, (uint16_t*)dest, dstW, 0);
522 }
523 
524 static void yuv2p010lX_BE_c(const int16_t *filter, int filterSize,
525  const int16_t **src, uint8_t *dest, int dstW,
526  const uint8_t *dither, int offset)
527 {
528  yuv2p010lX_c(filter, filterSize, src, (uint16_t*)dest, dstW, 1);
529 }
530 
531 #undef output_pixel
532 
533 
534 #define accumulate_bit(acc, val) \
535  acc <<= 1; \
536  acc |= (val) >= 234
537 #define output_pixel(pos, acc) \
538  if (target == AV_PIX_FMT_MONOBLACK) { \
539  pos = acc; \
540  } else { \
541  pos = ~acc; \
542  }
543 
544 static av_always_inline void
545 yuv2mono_X_c_template(SwsContext *c, const int16_t *lumFilter,
546  const int16_t **lumSrc, int lumFilterSize,
547  const int16_t *chrFilter, const int16_t **chrUSrc,
548  const int16_t **chrVSrc, int chrFilterSize,
549  const int16_t **alpSrc, uint8_t *dest, int dstW,
550  int y, enum AVPixelFormat target)
551 {
552  const uint8_t * const d128 = ff_dither_8x8_220[y&7];
553  int i;
554  unsigned acc = 0;
555  int err = 0;
556 
557  for (i = 0; i < dstW; i += 2) {
558  int j;
559  int Y1 = 1 << 18;
560  int Y2 = 1 << 18;
561 
562  for (j = 0; j < lumFilterSize; j++) {
563  Y1 += lumSrc[j][i] * lumFilter[j];
564  Y2 += lumSrc[j][i+1] * lumFilter[j];
565  }
566  Y1 >>= 19;
567  Y2 >>= 19;
568  if ((Y1 | Y2) & 0x100) {
569  Y1 = av_clip_uint8(Y1);
570  Y2 = av_clip_uint8(Y2);
571  }
572  if (c->dither == SWS_DITHER_ED) {
573  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;
574  c->dither_error[0][i] = err;
575  acc = 2*acc + (Y1 >= 128);
576  Y1 -= 220*(acc&1);
577 
578  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);
579  c->dither_error[0][i+1] = Y1;
580  acc = 2*acc + (err >= 128);
581  err -= 220*(acc&1);
582  } else {
583  accumulate_bit(acc, Y1 + d128[(i + 0) & 7]);
584  accumulate_bit(acc, Y2 + d128[(i + 1) & 7]);
585  }
586  if ((i & 7) == 6) {
587  output_pixel(*dest++, acc);
588  }
589  }
590  c->dither_error[0][i] = err;
591 
592  if (i & 6) {
593  output_pixel(*dest, acc);
594  }
595 }
596 
597 static av_always_inline void
598 yuv2mono_2_c_template(SwsContext *c, const int16_t *buf[2],
599  const int16_t *ubuf[2], const int16_t *vbuf[2],
600  const int16_t *abuf[2], uint8_t *dest, int dstW,
601  int yalpha, int uvalpha, int y,
602  enum AVPixelFormat target)
603 {
604  const int16_t *buf0 = buf[0], *buf1 = buf[1];
605  const uint8_t * const d128 = ff_dither_8x8_220[y & 7];
606  int yalpha1 = 4096 - yalpha;
607  int i;
608  av_assert2(yalpha <= 4096U);
609 
610  if (c->dither == SWS_DITHER_ED) {
611  int err = 0;
612  unsigned acc = 0;
613  for (i = 0; i < dstW; i +=2) {
614  int Y;
615 
616  Y = (buf0[i + 0] * yalpha1 + buf1[i + 0] * yalpha) >> 19;
617  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;
618  c->dither_error[0][i] = err;
619  acc = 2*acc + (Y >= 128);
620  Y -= 220*(acc&1);
621 
622  err = (buf0[i + 1] * yalpha1 + buf1[i + 1] * yalpha) >> 19;
623  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;
624  c->dither_error[0][i+1] = Y;
625  acc = 2*acc + (err >= 128);
626  err -= 220*(acc&1);
627 
628  if ((i & 7) == 6)
629  output_pixel(*dest++, acc);
630  }
631  c->dither_error[0][i] = err;
632  } else {
633  for (i = 0; i < dstW; i += 8) {
634  int Y;
635  unsigned acc = 0;
636 
637  Y = (buf0[i + 0] * yalpha1 + buf1[i + 0] * yalpha) >> 19;
638  accumulate_bit(acc, Y + d128[0]);
639  Y = (buf0[i + 1] * yalpha1 + buf1[i + 1] * yalpha) >> 19;
640  accumulate_bit(acc, Y + d128[1]);
641  Y = (buf0[i + 2] * yalpha1 + buf1[i + 2] * yalpha) >> 19;
642  accumulate_bit(acc, Y + d128[2]);
643  Y = (buf0[i + 3] * yalpha1 + buf1[i + 3] * yalpha) >> 19;
644  accumulate_bit(acc, Y + d128[3]);
645  Y = (buf0[i + 4] * yalpha1 + buf1[i + 4] * yalpha) >> 19;
646  accumulate_bit(acc, Y + d128[4]);
647  Y = (buf0[i + 5] * yalpha1 + buf1[i + 5] * yalpha) >> 19;
648  accumulate_bit(acc, Y + d128[5]);
649  Y = (buf0[i + 6] * yalpha1 + buf1[i + 6] * yalpha) >> 19;
650  accumulate_bit(acc, Y + d128[6]);
651  Y = (buf0[i + 7] * yalpha1 + buf1[i + 7] * yalpha) >> 19;
652  accumulate_bit(acc, Y + d128[7]);
653 
654  output_pixel(*dest++, acc);
655  }
656  }
657 }
658 
659 static av_always_inline void
660 yuv2mono_1_c_template(SwsContext *c, const int16_t *buf0,
661  const int16_t *ubuf[2], const int16_t *vbuf[2],
662  const int16_t *abuf0, uint8_t *dest, int dstW,
663  int uvalpha, int y, enum AVPixelFormat target)
664 {
665  const uint8_t * const d128 = ff_dither_8x8_220[y & 7];
666  int i;
667 
668  if (c->dither == SWS_DITHER_ED) {
669  int err = 0;
670  unsigned acc = 0;
671  for (i = 0; i < dstW; i +=2) {
672  int Y;
673 
674  Y = ((buf0[i + 0] + 64) >> 7);
675  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;
676  c->dither_error[0][i] = err;
677  acc = 2*acc + (Y >= 128);
678  Y -= 220*(acc&1);
679 
680  err = ((buf0[i + 1] + 64) >> 7);
681  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;
682  c->dither_error[0][i+1] = Y;
683  acc = 2*acc + (err >= 128);
684  err -= 220*(acc&1);
685 
686  if ((i & 7) == 6)
687  output_pixel(*dest++, acc);
688  }
689  c->dither_error[0][i] = err;
690  } else {
691  for (i = 0; i < dstW; i += 8) {
692  unsigned acc = 0;
693  accumulate_bit(acc, ((buf0[i + 0] + 64) >> 7) + d128[0]);
694  accumulate_bit(acc, ((buf0[i + 1] + 64) >> 7) + d128[1]);
695  accumulate_bit(acc, ((buf0[i + 2] + 64) >> 7) + d128[2]);
696  accumulate_bit(acc, ((buf0[i + 3] + 64) >> 7) + d128[3]);
697  accumulate_bit(acc, ((buf0[i + 4] + 64) >> 7) + d128[4]);
698  accumulate_bit(acc, ((buf0[i + 5] + 64) >> 7) + d128[5]);
699  accumulate_bit(acc, ((buf0[i + 6] + 64) >> 7) + d128[6]);
700  accumulate_bit(acc, ((buf0[i + 7] + 64) >> 7) + d128[7]);
701 
702  output_pixel(*dest++, acc);
703  }
704  }
705 }
706 
707 #undef output_pixel
708 #undef accumulate_bit
709 
710 #define YUV2PACKEDWRAPPER(name, base, ext, fmt) \
711 static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \
712  const int16_t **lumSrc, int lumFilterSize, \
713  const int16_t *chrFilter, const int16_t **chrUSrc, \
714  const int16_t **chrVSrc, int chrFilterSize, \
715  const int16_t **alpSrc, uint8_t *dest, int dstW, \
716  int y) \
717 { \
718  name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
719  chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
720  alpSrc, dest, dstW, y, fmt); \
721 } \
722  \
723 static void name ## ext ## _2_c(SwsContext *c, const int16_t *buf[2], \
724  const int16_t *ubuf[2], const int16_t *vbuf[2], \
725  const int16_t *abuf[2], uint8_t *dest, int dstW, \
726  int yalpha, int uvalpha, int y) \
727 { \
728  name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
729  dest, dstW, yalpha, uvalpha, y, fmt); \
730 } \
731  \
732 static void name ## ext ## _1_c(SwsContext *c, const int16_t *buf0, \
733  const int16_t *ubuf[2], const int16_t *vbuf[2], \
734  const int16_t *abuf0, uint8_t *dest, int dstW, \
735  int uvalpha, int y) \
736 { \
737  name ## base ## _1_c_template(c, buf0, ubuf, vbuf, \
738  abuf0, dest, dstW, uvalpha, \
739  y, fmt); \
740 }
741 
742 YUV2PACKEDWRAPPER(yuv2mono,, white, AV_PIX_FMT_MONOWHITE)
743 YUV2PACKEDWRAPPER(yuv2mono,, black, AV_PIX_FMT_MONOBLACK)
744 
745 #define output_pixels(pos, Y1, U, Y2, V) \
746  if (target == AV_PIX_FMT_YUYV422) { \
747  dest[pos + 0] = Y1; \
748  dest[pos + 1] = U; \
749  dest[pos + 2] = Y2; \
750  dest[pos + 3] = V; \
751  } else if (target == AV_PIX_FMT_YVYU422) { \
752  dest[pos + 0] = Y1; \
753  dest[pos + 1] = V; \
754  dest[pos + 2] = Y2; \
755  dest[pos + 3] = U; \
756  } else { /* AV_PIX_FMT_UYVY422 */ \
757  dest[pos + 0] = U; \
758  dest[pos + 1] = Y1; \
759  dest[pos + 2] = V; \
760  dest[pos + 3] = Y2; \
761  }
762 
763 static av_always_inline void
764 yuv2422_X_c_template(SwsContext *c, const int16_t *lumFilter,
765  const int16_t **lumSrc, int lumFilterSize,
766  const int16_t *chrFilter, const int16_t **chrUSrc,
767  const int16_t **chrVSrc, int chrFilterSize,
768  const int16_t **alpSrc, uint8_t *dest, int dstW,
769  int y, enum AVPixelFormat target)
770 {
771  int i;
772 
773  for (i = 0; i < ((dstW + 1) >> 1); i++) {
774  int j;
775  int Y1 = 1 << 18;
776  int Y2 = 1 << 18;
777  int U = 1 << 18;
778  int V = 1 << 18;
779 
780  for (j = 0; j < lumFilterSize; j++) {
781  Y1 += lumSrc[j][i * 2] * lumFilter[j];
782  Y2 += lumSrc[j][i * 2 + 1] * lumFilter[j];
783  }
784  for (j = 0; j < chrFilterSize; j++) {
785  U += chrUSrc[j][i] * chrFilter[j];
786  V += chrVSrc[j][i] * chrFilter[j];
787  }
788  Y1 >>= 19;
789  Y2 >>= 19;
790  U >>= 19;
791  V >>= 19;
792  if ((Y1 | Y2 | U | V) & 0x100) {
793  Y1 = av_clip_uint8(Y1);
794  Y2 = av_clip_uint8(Y2);
795  U = av_clip_uint8(U);
796  V = av_clip_uint8(V);
797  }
798  output_pixels(4*i, Y1, U, Y2, V);
799  }
800 }
801 
802 static av_always_inline void
803 yuv2422_2_c_template(SwsContext *c, const int16_t *buf[2],
804  const int16_t *ubuf[2], const int16_t *vbuf[2],
805  const int16_t *abuf[2], uint8_t *dest, int dstW,
806  int yalpha, int uvalpha, int y,
807  enum AVPixelFormat target)
808 {
809  const int16_t *buf0 = buf[0], *buf1 = buf[1],
810  *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
811  *vbuf0 = vbuf[0], *vbuf1 = vbuf[1];
812  int yalpha1 = 4096 - yalpha;
813  int uvalpha1 = 4096 - uvalpha;
814  int i;
815  av_assert2(yalpha <= 4096U);
816  av_assert2(uvalpha <= 4096U);
817 
818  for (i = 0; i < ((dstW + 1) >> 1); i++) {
819  int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 19;
820  int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 19;
821  int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha) >> 19;
822  int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha) >> 19;
823 
824  if ((Y1 | Y2 | U | V) & 0x100) {
825  Y1 = av_clip_uint8(Y1);
826  Y2 = av_clip_uint8(Y2);
827  U = av_clip_uint8(U);
828  V = av_clip_uint8(V);
829  }
830 
831  output_pixels(i * 4, Y1, U, Y2, V);
832  }
833 }
834 
835 static av_always_inline void
836 yuv2422_1_c_template(SwsContext *c, const int16_t *buf0,
837  const int16_t *ubuf[2], const int16_t *vbuf[2],
838  const int16_t *abuf0, uint8_t *dest, int dstW,
839  int uvalpha, int y, enum AVPixelFormat target)
840 {
841  const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
842  int i;
843 
844  if (uvalpha < 2048) {
845  for (i = 0; i < ((dstW + 1) >> 1); i++) {
846  int Y1 = (buf0[i * 2 ]+64) >> 7;
847  int Y2 = (buf0[i * 2 + 1]+64) >> 7;
848  int U = (ubuf0[i] +64) >> 7;
849  int V = (vbuf0[i] +64) >> 7;
850 
851  if ((Y1 | Y2 | U | V) & 0x100) {
852  Y1 = av_clip_uint8(Y1);
853  Y2 = av_clip_uint8(Y2);
854  U = av_clip_uint8(U);
855  V = av_clip_uint8(V);
856  }
857 
858  output_pixels(i * 4, Y1, U, Y2, V);
859  }
860  } else {
861  const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
862  for (i = 0; i < ((dstW + 1) >> 1); i++) {
863  int Y1 = (buf0[i * 2 ] + 64) >> 7;
864  int Y2 = (buf0[i * 2 + 1] + 64) >> 7;
865  int U = (ubuf0[i] + ubuf1[i]+128) >> 8;
866  int V = (vbuf0[i] + vbuf1[i]+128) >> 8;
867 
868  if ((Y1 | Y2 | U | V) & 0x100) {
869  Y1 = av_clip_uint8(Y1);
870  Y2 = av_clip_uint8(Y2);
871  U = av_clip_uint8(U);
872  V = av_clip_uint8(V);
873  }
874 
875  output_pixels(i * 4, Y1, U, Y2, V);
876  }
877  }
878 }
879 
880 #undef output_pixels
881 
882 YUV2PACKEDWRAPPER(yuv2, 422, yuyv422, AV_PIX_FMT_YUYV422)
883 YUV2PACKEDWRAPPER(yuv2, 422, yvyu422, AV_PIX_FMT_YVYU422)
884 YUV2PACKEDWRAPPER(yuv2, 422, uyvy422, AV_PIX_FMT_UYVY422)
885 
886 #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)
887 #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)
888 #define output_pixel(pos, val) \
889  if (isBE(target)) { \
890  AV_WB16(pos, val); \
891  } else { \
892  AV_WL16(pos, val); \
893  }
894 
895 static av_always_inline void
896 yuv2ya16_X_c_template(SwsContext *c, const int16_t *lumFilter,
897  const int32_t **lumSrc, int lumFilterSize,
898  const int16_t *chrFilter, const int32_t **unused_chrUSrc,
899  const int32_t **unused_chrVSrc, int unused_chrFilterSize,
900  const int32_t **alpSrc, uint16_t *dest, int dstW,
901  int y, enum AVPixelFormat target, int unused_hasAlpha, int unused_eightbytes)
902 {
903  int hasAlpha = !!alpSrc;
904  int i;
905 
906  for (i = 0; i < dstW; i++) {
907  int j;
908  int Y = -0x40000000;
909  int A = 0xffff;
910 
911  for (j = 0; j < lumFilterSize; j++)
912  Y += lumSrc[j][i] * lumFilter[j];
913 
914  Y >>= 15;
915  Y += (1<<3) + 0x8000;
916  Y = av_clip_uint16(Y);
917 
918  if (hasAlpha) {
919  A = -0x40000000 + (1<<14);
920  for (j = 0; j < lumFilterSize; j++)
921  A += alpSrc[j][i] * lumFilter[j];
922 
923  A >>= 15;
924  A += 0x8000;
925  A = av_clip_uint16(A);
926  }
927 
928  output_pixel(&dest[2 * i ], Y);
929  output_pixel(&dest[2 * i + 1], A);
930  }
931 }
932 
933 static av_always_inline void
935  const int32_t *unused_ubuf[2], const int32_t *unused_vbuf[2],
936  const int32_t *abuf[2], uint16_t *dest, int dstW,
937  int yalpha, int unused_uvalpha, int y,
938  enum AVPixelFormat target, int unused_hasAlpha, int unused_eightbytes)
939 {
940  int hasAlpha = abuf && abuf[0] && abuf[1];
941  const int32_t *buf0 = buf[0], *buf1 = buf[1],
942  *abuf0 = hasAlpha ? abuf[0] : NULL,
943  *abuf1 = hasAlpha ? abuf[1] : NULL;
944  int yalpha1 = 4096 - yalpha;
945  int i;
946 
947  av_assert2(yalpha <= 4096U);
948 
949  for (i = 0; i < dstW; i++) {
950  int Y = (buf0[i] * yalpha1 + buf1[i] * yalpha) >> 15;
951  int A;
952 
953  Y = av_clip_uint16(Y);
954 
955  if (hasAlpha) {
956  A = (abuf0[i] * yalpha1 + abuf1[i] * yalpha) >> 15;
957  A = av_clip_uint16(A);
958  }
959 
960  output_pixel(&dest[2 * i ], Y);
961  output_pixel(&dest[2 * i + 1], hasAlpha ? A : 65535);
962  }
963 }
964 
965 static av_always_inline void
967  const int32_t *unused_ubuf[2], const int32_t *unused_vbuf[2],
968  const int32_t *abuf0, uint16_t *dest, int dstW,
969  int unused_uvalpha, int y, enum AVPixelFormat target, int unused_hasAlpha, int unused_eightbytes)
970 {
971  int hasAlpha = !!abuf0;
972  int i;
973 
974  for (i = 0; i < dstW; i++) {
975  int Y = buf0[i] >> 3;/* 19 - 16 */
976  int A;
977 
978  Y = av_clip_uint16(Y);
979 
980  if (hasAlpha) {
981  A = abuf0[i] >> 3;
982  if (A & 0x100)
983  A = av_clip_uint16(A);
984  }
985 
986  output_pixel(&dest[2 * i ], Y);
987  output_pixel(&dest[2 * i + 1], hasAlpha ? A : 65535);
988  }
989 }
990 
991 static av_always_inline void
992 yuv2rgba64_X_c_template(SwsContext *c, const int16_t *lumFilter,
993  const int32_t **lumSrc, int lumFilterSize,
994  const int16_t *chrFilter, const int32_t **chrUSrc,
995  const int32_t **chrVSrc, int chrFilterSize,
996  const int32_t **alpSrc, uint16_t *dest, int dstW,
997  int y, enum AVPixelFormat target, int hasAlpha, int eightbytes)
998 {
999  int i;
1000  int A1 = 0xffff<<14, A2 = 0xffff<<14;
1001 
1002  for (i = 0; i < ((dstW + 1) >> 1); i++) {
1003  int j;
1004  unsigned Y1 = -0x40000000;
1005  unsigned Y2 = -0x40000000;
1006  int U = -(128 << 23); // 19
1007  int V = -(128 << 23);
1008  int R, G, B;
1009 
1010  for (j = 0; j < lumFilterSize; j++) {
1011  Y1 += lumSrc[j][i * 2] * (unsigned)lumFilter[j];
1012  Y2 += lumSrc[j][i * 2 + 1] * (unsigned)lumFilter[j];
1013  }
1014  for (j = 0; j < chrFilterSize; j++) {;
1015  U += chrUSrc[j][i] * (unsigned)chrFilter[j];
1016  V += chrVSrc[j][i] * (unsigned)chrFilter[j];
1017  }
1018 
1019  if (hasAlpha) {
1020  A1 = -0x40000000;
1021  A2 = -0x40000000;
1022  for (j = 0; j < lumFilterSize; j++) {
1023  A1 += alpSrc[j][i * 2] * (unsigned)lumFilter[j];
1024  A2 += alpSrc[j][i * 2 + 1] * (unsigned)lumFilter[j];
1025  }
1026  A1 >>= 1;
1027  A1 += 0x20002000;
1028  A2 >>= 1;
1029  A2 += 0x20002000;
1030  }
1031 
1032  // 8 bits: 12+15=27; 16 bits: 12+19=31
1033  Y1 = (int)Y1 >> 14; // 10
1034  Y1 += 0x10000;
1035  Y2 = (int)Y2 >> 14;
1036  Y2 += 0x10000;
1037  U >>= 14;
1038  V >>= 14;
1039 
1040  // 8 bits: 27 -> 17 bits, 16 bits: 31 - 14 = 17 bits
1041  Y1 -= c->yuv2rgb_y_offset;
1042  Y2 -= c->yuv2rgb_y_offset;
1043  Y1 *= c->yuv2rgb_y_coeff;
1044  Y2 *= c->yuv2rgb_y_coeff;
1045  Y1 += (1 << 13) - (1 << 29); // 21
1046  Y2 += (1 << 13) - (1 << 29);
1047  // 8 bits: 17 + 13 bits = 30 bits, 16 bits: 17 + 13 bits = 30 bits
1048 
1049  R = V * c->yuv2rgb_v2r_coeff;
1050  G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
1051  B = U * c->yuv2rgb_u2b_coeff;
1052 
1053  // 8 bits: 30 - 22 = 8 bits, 16 bits: 30 bits - 14 = 16 bits
1054  output_pixel(&dest[0], av_clip_uintp2(((int)(R_B + Y1) >> 14) + (1<<15), 16));
1055  output_pixel(&dest[1], av_clip_uintp2(((int)( G + Y1) >> 14) + (1<<15), 16));
1056  output_pixel(&dest[2], av_clip_uintp2(((int)(B_R + Y1) >> 14) + (1<<15), 16));
1057  if (eightbytes) {
1058  output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14);
1059  output_pixel(&dest[4], av_clip_uintp2(((int)(R_B + Y2) >> 14) + (1<<15), 16));
1060  output_pixel(&dest[5], av_clip_uintp2(((int)( G + Y2) >> 14) + (1<<15), 16));
1061  output_pixel(&dest[6], av_clip_uintp2(((int)(B_R + Y2) >> 14) + (1<<15), 16));
1062  output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14);
1063  dest += 8;
1064  } else {
1065  output_pixel(&dest[3], av_clip_uintp2(((int)(R_B + Y2) >> 14) + (1<<15), 16));
1066  output_pixel(&dest[4], av_clip_uintp2(((int)( G + Y2) >> 14) + (1<<15), 16));
1067  output_pixel(&dest[5], av_clip_uintp2(((int)(B_R + Y2) >> 14) + (1<<15), 16));
1068  dest += 6;
1069  }
1070  }
1071 }
1072 
1073 static av_always_inline void
1075  const int32_t *ubuf[2], const int32_t *vbuf[2],
1076  const int32_t *abuf[2], uint16_t *dest, int dstW,
1077  int yalpha, int uvalpha, int y,
1078  enum AVPixelFormat target, int hasAlpha, int eightbytes)
1079 {
1080  const int32_t *buf0 = buf[0], *buf1 = buf[1],
1081  *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
1082  *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
1083  *abuf0 = hasAlpha ? abuf[0] : NULL,
1084  *abuf1 = hasAlpha ? abuf[1] : NULL;
1085  int yalpha1 = 4096 - yalpha;
1086  int uvalpha1 = 4096 - uvalpha;
1087  int i;
1088  int A1 = 0xffff<<14, A2 = 0xffff<<14;
1089 
1090  av_assert2(yalpha <= 4096U);
1091  av_assert2(uvalpha <= 4096U);
1092 
1093  for (i = 0; i < ((dstW + 1) >> 1); i++) {
1094  unsigned Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 14;
1095  unsigned Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 14;
1096  int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha - (128 << 23)) >> 14;
1097  int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha - (128 << 23)) >> 14;
1098  int R, G, B;
1099 
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);
1105  Y2 += (1 << 13) - (1 << 29);
1106 
1107  R = V * c->yuv2rgb_v2r_coeff;
1108  G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
1109  B = U * c->yuv2rgb_u2b_coeff;
1110 
1111  if (hasAlpha) {
1112  A1 = (abuf0[i * 2 ] * yalpha1 + abuf1[i * 2 ] * yalpha) >> 1;
1113  A2 = (abuf0[i * 2 + 1] * yalpha1 + abuf1[i * 2 + 1] * yalpha) >> 1;
1114 
1115  A1 += 1 << 13;
1116  A2 += 1 << 13;
1117  }
1118 
1119  output_pixel(&dest[0], av_clip_uintp2(((int)(R_B + Y1) >> 14) + (1<<15), 16));
1120  output_pixel(&dest[1], av_clip_uintp2(((int)( G + Y1) >> 14) + (1<<15), 16));
1121  output_pixel(&dest[2], av_clip_uintp2(((int)(B_R + Y1) >> 14) + (1<<15), 16));
1122  if (eightbytes) {
1123  output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14);
1124  output_pixel(&dest[4], av_clip_uintp2(((int)(R_B + Y2) >> 14) + (1<<15), 16));
1125  output_pixel(&dest[5], av_clip_uintp2(((int)( G + Y2) >> 14) + (1<<15), 16));
1126  output_pixel(&dest[6], av_clip_uintp2(((int)(B_R + Y2) >> 14) + (1<<15), 16));
1127  output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14);
1128  dest += 8;
1129  } else {
1130  output_pixel(&dest[3], av_clip_uintp2(((int)(R_B + Y2) >> 14) + (1<<15), 16));
1131  output_pixel(&dest[4], av_clip_uintp2(((int)( G + Y2) >> 14) + (1<<15), 16));
1132  output_pixel(&dest[5], av_clip_uintp2(((int)(B_R + Y2) >> 14) + (1<<15), 16));
1133  dest += 6;
1134  }
1135  }
1136 }
1137 
1138 static av_always_inline void
1140  const int32_t *ubuf[2], const int32_t *vbuf[2],
1141  const int32_t *abuf0, uint16_t *dest, int dstW,
1142  int uvalpha, int y, enum AVPixelFormat target, int hasAlpha, int eightbytes)
1143 {
1144  const int32_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
1145  int i;
1146  int A1 = 0xffff<<14, A2= 0xffff<<14;
1147 
1148  if (uvalpha < 2048) {
1149  for (i = 0; i < ((dstW + 1) >> 1); i++) {
1150  SUINT Y1 = (buf0[i * 2] ) >> 2;
1151  SUINT Y2 = (buf0[i * 2 + 1]) >> 2;
1152  int U = (ubuf0[i] - (128 << 11)) >> 2;
1153  int V = (vbuf0[i] - (128 << 11)) >> 2;
1154  int R, G, B;
1155 
1156  Y1 -= c->yuv2rgb_y_offset;
1157  Y2 -= c->yuv2rgb_y_offset;
1158  Y1 *= c->yuv2rgb_y_coeff;
1159  Y2 *= c->yuv2rgb_y_coeff;
1160  Y1 += (1 << 13) - (1 << 29);
1161  Y2 += (1 << 13) - (1 << 29);
1162 
1163  if (hasAlpha) {
1164  A1 = abuf0[i * 2 ] * (1 << 11);
1165  A2 = abuf0[i * 2 + 1] * (1 << 11);
1166 
1167  A1 += 1 << 13;
1168  A2 += 1 << 13;
1169  }
1170 
1171  R = V * c->yuv2rgb_v2r_coeff;
1172  G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
1173  B = U * c->yuv2rgb_u2b_coeff;
1174 
1175  output_pixel(&dest[0], av_clip_uintp2(((int)(R_B + Y1) >> 14) + (1<<15), 16));
1176  output_pixel(&dest[1], av_clip_uintp2(((int)( G + Y1) >> 14) + (1<<15), 16));
1177  output_pixel(&dest[2], av_clip_uintp2(((int)(B_R + Y1) >> 14) + (1<<15), 16));
1178  if (eightbytes) {
1179  output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14);
1180  output_pixel(&dest[4], av_clip_uintp2(((int)(R_B + Y2) >> 14) + (1<<15), 16));
1181  output_pixel(&dest[5], av_clip_uintp2(((int)( G + Y2) >> 14) + (1<<15), 16));
1182  output_pixel(&dest[6], av_clip_uintp2(((int)(B_R + Y2) >> 14) + (1<<15), 16));
1183  output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14);
1184  dest += 8;
1185  } else {
1186  output_pixel(&dest[3], av_clip_uintp2(((int)(R_B + Y2) >> 14) + (1<<15), 16));
1187  output_pixel(&dest[4], av_clip_uintp2(((int)( G + Y2) >> 14) + (1<<15), 16));
1188  output_pixel(&dest[5], av_clip_uintp2(((int)(B_R + Y2) >> 14) + (1<<15), 16));
1189  dest += 6;
1190  }
1191  }
1192  } else {
1193  const int32_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
1194  int A1 = 0xffff<<14, A2 = 0xffff<<14;
1195  for (i = 0; i < ((dstW + 1) >> 1); i++) {
1196  SUINT Y1 = (buf0[i * 2] ) >> 2;
1197  SUINT Y2 = (buf0[i * 2 + 1]) >> 2;
1198  int U = (ubuf0[i] + ubuf1[i] - (128 << 12)) >> 3;
1199  int V = (vbuf0[i] + vbuf1[i] - (128 << 12)) >> 3;
1200  int R, G, B;
1201 
1202  Y1 -= c->yuv2rgb_y_offset;
1203  Y2 -= c->yuv2rgb_y_offset;
1204  Y1 *= c->yuv2rgb_y_coeff;
1205  Y2 *= c->yuv2rgb_y_coeff;
1206  Y1 += (1 << 13) - (1 << 29);
1207  Y2 += (1 << 13) - (1 << 29);
1208 
1209  if (hasAlpha) {
1210  A1 = abuf0[i * 2 ] * (1 << 11);
1211  A2 = abuf0[i * 2 + 1] * (1 << 11);
1212 
1213  A1 += 1 << 13;
1214  A2 += 1 << 13;
1215  }
1216 
1217  R = V * c->yuv2rgb_v2r_coeff;
1218  G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
1219  B = U * c->yuv2rgb_u2b_coeff;
1220 
1221  output_pixel(&dest[0], av_clip_uintp2(((int)(R_B + Y1) >> 14) + (1<<15), 16));
1222  output_pixel(&dest[1], av_clip_uintp2(((int)( G + Y1) >> 14) + (1<<15), 16));
1223  output_pixel(&dest[2], av_clip_uintp2(((int)(B_R + Y1) >> 14) + (1<<15), 16));
1224  if (eightbytes) {
1225  output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14);
1226  output_pixel(&dest[4], av_clip_uintp2(((int)(R_B + Y2) >> 14) + (1<<15), 16));
1227  output_pixel(&dest[5], av_clip_uintp2(((int)( G + Y2) >> 14) + (1<<15), 16));
1228  output_pixel(&dest[6], av_clip_uintp2(((int)(B_R + Y2) >> 14) + (1<<15), 16));
1229  output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14);
1230  dest += 8;
1231  } else {
1232  output_pixel(&dest[3], av_clip_uintp2(((int)(R_B + Y2) >> 14) + (1<<15), 16));
1233  output_pixel(&dest[4], av_clip_uintp2(((int)( G + Y2) >> 14) + (1<<15), 16));
1234  output_pixel(&dest[5], av_clip_uintp2(((int)(B_R + Y2) >> 14) + (1<<15), 16));
1235  dest += 6;
1236  }
1237  }
1238  }
1239 }
1240 
1241 static av_always_inline void
1242 yuv2rgba64_full_X_c_template(SwsContext *c, const int16_t *lumFilter,
1243  const int32_t **lumSrc, int lumFilterSize,
1244  const int16_t *chrFilter, const int32_t **chrUSrc,
1245  const int32_t **chrVSrc, int chrFilterSize,
1246  const int32_t **alpSrc, uint16_t *dest, int dstW,
1247  int y, enum AVPixelFormat target, int hasAlpha, int eightbytes)
1248 {
1249  int i;
1250  int A = 0xffff<<14;
1251 
1252  for (i = 0; i < dstW; i++) {
1253  int j;
1254  int Y = -0x40000000;
1255  int U = -(128 << 23); // 19
1256  int V = -(128 << 23);
1257  int R, G, B;
1258 
1259  for (j = 0; j < lumFilterSize; j++) {
1260  Y += lumSrc[j][i] * (unsigned)lumFilter[j];
1261  }
1262  for (j = 0; j < chrFilterSize; j++) {;
1263  U += chrUSrc[j][i] * (unsigned)chrFilter[j];
1264  V += chrVSrc[j][i] * (unsigned)chrFilter[j];
1265  }
1266 
1267  if (hasAlpha) {
1268  A = -0x40000000;
1269  for (j = 0; j < lumFilterSize; j++) {
1270  A += alpSrc[j][i] * (unsigned)lumFilter[j];
1271  }
1272  A >>= 1;
1273  A += 0x20002000;
1274  }
1275 
1276  // 8bit: 12+15=27; 16-bit: 12+19=31
1277  Y >>= 14; // 10
1278  Y += 0x10000;
1279  U >>= 14;
1280  V >>= 14;
1281 
1282  // 8bit: 27 -> 17bit, 16bit: 31 - 14 = 17bit
1283  Y -= c->yuv2rgb_y_offset;
1284  Y *= c->yuv2rgb_y_coeff;
1285  Y += (1 << 13) - (1<<29); // 21
1286  // 8bit: 17 + 13bit = 30bit, 16bit: 17 + 13bit = 30bit
1287 
1288  R = V * c->yuv2rgb_v2r_coeff;
1289  G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
1290  B = U * c->yuv2rgb_u2b_coeff;
1291 
1292  // 8bit: 30 - 22 = 8bit, 16bit: 30bit - 14 = 16bit
1293  output_pixel(&dest[0], av_clip_uintp2(((int)(R_B + (unsigned)Y)>>14) + (1<<15), 16));
1294  output_pixel(&dest[1], av_clip_uintp2(((int)( G + (unsigned)Y)>>14) + (1<<15), 16));
1295  output_pixel(&dest[2], av_clip_uintp2(((int)(B_R + (unsigned)Y)>>14) + (1<<15), 16));
1296  if (eightbytes) {
1297  output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
1298  dest += 4;
1299  } else {
1300  dest += 3;
1301  }
1302  }
1303 }
1304 
1305 static av_always_inline void
1307  const int32_t *ubuf[2], const int32_t *vbuf[2],
1308  const int32_t *abuf[2], uint16_t *dest, int dstW,
1309  int yalpha, int uvalpha, int y,
1310  enum AVPixelFormat target, int hasAlpha, int eightbytes)
1311 {
1312  const int32_t *buf0 = buf[0], *buf1 = buf[1],
1313  *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
1314  *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
1315  *abuf0 = hasAlpha ? abuf[0] : NULL,
1316  *abuf1 = hasAlpha ? abuf[1] : NULL;
1317  int yalpha1 = 4096 - yalpha;
1318  int uvalpha1 = 4096 - uvalpha;
1319  int i;
1320  int A = 0xffff<<14;
1321 
1322  av_assert2(yalpha <= 4096U);
1323  av_assert2(uvalpha <= 4096U);
1324 
1325  for (i = 0; i < dstW; i++) {
1326  int Y = (buf0[i] * yalpha1 + buf1[i] * yalpha) >> 14;
1327  int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha - (128 << 23)) >> 14;
1328  int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha - (128 << 23)) >> 14;
1329  int R, G, B;
1330 
1331  Y -= c->yuv2rgb_y_offset;
1332  Y *= c->yuv2rgb_y_coeff;
1333  Y += (1 << 13) - (1 << 29);
1334 
1335  R = V * c->yuv2rgb_v2r_coeff;
1336  G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
1337  B = U * c->yuv2rgb_u2b_coeff;
1338 
1339  if (hasAlpha) {
1340  A = (abuf0[i] * yalpha1 + abuf1[i] * yalpha) >> 1;
1341 
1342  A += 1 << 13;
1343  }
1344 
1345  output_pixel(&dest[0], av_clip_uintp2(((R_B + Y) >> 14) + (1<<15), 16));
1346  output_pixel(&dest[1], av_clip_uintp2((( G + Y) >> 14) + (1<<15), 16));
1347  output_pixel(&dest[2], av_clip_uintp2(((B_R + Y) >> 14) + (1<<15), 16));
1348  if (eightbytes) {
1349  output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
1350  dest += 4;
1351  } else {
1352  dest += 3;
1353  }
1354  }
1355 }
1356 
1357 static av_always_inline void
1359  const int32_t *ubuf[2], const int32_t *vbuf[2],
1360  const int32_t *abuf0, uint16_t *dest, int dstW,
1361  int uvalpha, int y, enum AVPixelFormat target, int hasAlpha, int eightbytes)
1362 {
1363  const int32_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
1364  int i;
1365  int A = 0xffff<<14;
1366 
1367  if (uvalpha < 2048) {
1368  for (i = 0; i < dstW; i++) {
1369  SUINT Y = (buf0[i]) >> 2;
1370  int U = (ubuf0[i] - (128 << 11)) >> 2;
1371  int V = (vbuf0[i] - (128 << 11)) >> 2;
1372  int R, G, B;
1373 
1374  Y -= c->yuv2rgb_y_offset;
1375  Y *= c->yuv2rgb_y_coeff;
1376  Y += (1 << 13) - (1 << 29);
1377 
1378  if (hasAlpha) {
1379  A = abuf0[i] * (1 << 11);
1380 
1381  A += 1 << 13;
1382  }
1383 
1384  R = V * c->yuv2rgb_v2r_coeff;
1385  G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
1386  B = U * c->yuv2rgb_u2b_coeff;
1387 
1388  output_pixel(&dest[0], av_clip_uintp2(((int)(R_B + Y) >> 14) + (1<<15), 16));
1389  output_pixel(&dest[1], av_clip_uintp2(((int)( G + Y) >> 14) + (1<<15), 16));
1390  output_pixel(&dest[2], av_clip_uintp2(((int)(B_R + Y) >> 14) + (1<<15), 16));
1391  if (eightbytes) {
1392  output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
1393  dest += 4;
1394  } else {
1395  dest += 3;
1396  }
1397  }
1398  } else {
1399  const int32_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
1400  int A = 0xffff<<14;
1401  for (i = 0; i < dstW; i++) {
1402  SUINT Y = (buf0[i] ) >> 2;
1403  int U = (ubuf0[i] + ubuf1[i] - (128 << 12)) >> 3;
1404  int V = (vbuf0[i] + vbuf1[i] - (128 << 12)) >> 3;
1405  int R, G, B;
1406 
1407  Y -= c->yuv2rgb_y_offset;
1408  Y *= c->yuv2rgb_y_coeff;
1409  Y += (1 << 13) - (1 << 29);
1410 
1411  if (hasAlpha) {
1412  A = abuf0[i] * (1 << 11);
1413 
1414  A += 1 << 13;
1415  }
1416 
1417  R = V * c->yuv2rgb_v2r_coeff;
1418  G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
1419  B = U * c->yuv2rgb_u2b_coeff;
1420 
1421  output_pixel(&dest[0], av_clip_uintp2(((int)(R_B + Y) >> 14) + (1<<15), 16));
1422  output_pixel(&dest[1], av_clip_uintp2(((int)( G + Y) >> 14) + (1<<15), 16));
1423  output_pixel(&dest[2], av_clip_uintp2(((int)(B_R + Y) >> 14) + (1<<15), 16));
1424  if (eightbytes) {
1425  output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
1426  dest += 4;
1427  } else {
1428  dest += 3;
1429  }
1430  }
1431  }
1432 }
1433 
1434 #undef output_pixel
1435 #undef r_b
1436 #undef b_r
1437 
1438 #define YUV2PACKED16WRAPPER(name, base, ext, fmt, hasAlpha, eightbytes) \
1439 static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \
1440  const int16_t **_lumSrc, int lumFilterSize, \
1441  const int16_t *chrFilter, const int16_t **_chrUSrc, \
1442  const int16_t **_chrVSrc, int chrFilterSize, \
1443  const int16_t **_alpSrc, uint8_t *_dest, int dstW, \
1444  int y) \
1445 { \
1446  const int32_t **lumSrc = (const int32_t **) _lumSrc, \
1447  **chrUSrc = (const int32_t **) _chrUSrc, \
1448  **chrVSrc = (const int32_t **) _chrVSrc, \
1449  **alpSrc = (const int32_t **) _alpSrc; \
1450  uint16_t *dest = (uint16_t *) _dest; \
1451  name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
1452  chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
1453  alpSrc, dest, dstW, y, fmt, hasAlpha, eightbytes); \
1454 } \
1455  \
1456 static void name ## ext ## _2_c(SwsContext *c, const int16_t *_buf[2], \
1457  const int16_t *_ubuf[2], const int16_t *_vbuf[2], \
1458  const int16_t *_abuf[2], uint8_t *_dest, int dstW, \
1459  int yalpha, int uvalpha, int y) \
1460 { \
1461  const int32_t **buf = (const int32_t **) _buf, \
1462  **ubuf = (const int32_t **) _ubuf, \
1463  **vbuf = (const int32_t **) _vbuf, \
1464  **abuf = (const int32_t **) _abuf; \
1465  uint16_t *dest = (uint16_t *) _dest; \
1466  name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
1467  dest, dstW, yalpha, uvalpha, y, fmt, hasAlpha, eightbytes); \
1468 } \
1469  \
1470 static void name ## ext ## _1_c(SwsContext *c, const int16_t *_buf0, \
1471  const int16_t *_ubuf[2], const int16_t *_vbuf[2], \
1472  const int16_t *_abuf0, uint8_t *_dest, int dstW, \
1473  int uvalpha, int y) \
1474 { \
1475  const int32_t *buf0 = (const int32_t *) _buf0, \
1476  **ubuf = (const int32_t **) _ubuf, \
1477  **vbuf = (const int32_t **) _vbuf, \
1478  *abuf0 = (const int32_t *) _abuf0; \
1479  uint16_t *dest = (uint16_t *) _dest; \
1480  name ## base ## _1_c_template(c, buf0, ubuf, vbuf, abuf0, dest, \
1481  dstW, uvalpha, y, fmt, hasAlpha, eightbytes); \
1482 }
1483 
1484 YUV2PACKED16WRAPPER(yuv2, rgba64, rgb48be, AV_PIX_FMT_RGB48BE, 0, 0)
1485 YUV2PACKED16WRAPPER(yuv2, rgba64, rgb48le, AV_PIX_FMT_RGB48LE, 0, 0)
1486 YUV2PACKED16WRAPPER(yuv2, rgba64, bgr48be, AV_PIX_FMT_BGR48BE, 0, 0)
1487 YUV2PACKED16WRAPPER(yuv2, rgba64, bgr48le, AV_PIX_FMT_BGR48LE, 0, 0)
1488 YUV2PACKED16WRAPPER(yuv2, rgba64, rgba64be, AV_PIX_FMT_RGBA64BE, 1, 1)
1489 YUV2PACKED16WRAPPER(yuv2, rgba64, rgba64le, AV_PIX_FMT_RGBA64LE, 1, 1)
1490 YUV2PACKED16WRAPPER(yuv2, rgba64, rgbx64be, AV_PIX_FMT_RGBA64BE, 0, 1)
1491 YUV2PACKED16WRAPPER(yuv2, rgba64, rgbx64le, AV_PIX_FMT_RGBA64LE, 0, 1)
1492 YUV2PACKED16WRAPPER(yuv2, rgba64, bgra64be, AV_PIX_FMT_BGRA64BE, 1, 1)
1493 YUV2PACKED16WRAPPER(yuv2, rgba64, bgra64le, AV_PIX_FMT_BGRA64LE, 1, 1)
1494 YUV2PACKED16WRAPPER(yuv2, rgba64, bgrx64be, AV_PIX_FMT_BGRA64BE, 0, 1)
1495 YUV2PACKED16WRAPPER(yuv2, rgba64, bgrx64le, AV_PIX_FMT_BGRA64LE, 0, 1)
1496 YUV2PACKED16WRAPPER(yuv2, ya16, ya16be, AV_PIX_FMT_YA16BE, 1, 0)
1497 YUV2PACKED16WRAPPER(yuv2, ya16, ya16le, AV_PIX_FMT_YA16LE, 1, 0)
1498 
1499 YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgb48be_full, AV_PIX_FMT_RGB48BE, 0, 0)
1500 YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgb48le_full, AV_PIX_FMT_RGB48LE, 0, 0)
1501 YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgr48be_full, AV_PIX_FMT_BGR48BE, 0, 0)
1502 YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgr48le_full, AV_PIX_FMT_BGR48LE, 0, 0)
1503 YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgba64be_full, AV_PIX_FMT_RGBA64BE, 1, 1)
1504 YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgba64le_full, AV_PIX_FMT_RGBA64LE, 1, 1)
1505 YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgbx64be_full, AV_PIX_FMT_RGBA64BE, 0, 1)
1506 YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgbx64le_full, AV_PIX_FMT_RGBA64LE, 0, 1)
1507 YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgra64be_full, AV_PIX_FMT_BGRA64BE, 1, 1)
1508 YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgra64le_full, AV_PIX_FMT_BGRA64LE, 1, 1)
1509 YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgrx64be_full, AV_PIX_FMT_BGRA64BE, 0, 1)
1510 YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgrx64le_full, AV_PIX_FMT_BGRA64LE, 0, 1)
1511 
1512 /*
1513  * Write out 2 RGB pixels in the target pixel format. This function takes a
1514  * R/G/B LUT as generated by ff_yuv2rgb_c_init_tables(), which takes care of
1515  * things like endianness conversion and shifting. The caller takes care of
1516  * setting the correct offset in these tables from the chroma (U/V) values.
1517  * This function then uses the luminance (Y1/Y2) values to write out the
1518  * correct RGB values into the destination buffer.
1519  */
1520 static av_always_inline void
1521 yuv2rgb_write(uint8_t *_dest, int i, int Y1, int Y2,
1522  unsigned A1, unsigned A2,
1523  const void *_r, const void *_g, const void *_b, int y,
1524  enum AVPixelFormat target, int hasAlpha)
1525 {
1526  if (target == AV_PIX_FMT_ARGB || target == AV_PIX_FMT_RGBA ||
1527  target == AV_PIX_FMT_ABGR || target == AV_PIX_FMT_BGRA) {
1528  uint32_t *dest = (uint32_t *) _dest;
1529  const uint32_t *r = (const uint32_t *) _r;
1530  const uint32_t *g = (const uint32_t *) _g;
1531  const uint32_t *b = (const uint32_t *) _b;
1532 
1533 #if CONFIG_SMALL
1534  int sh = hasAlpha ? ((target == AV_PIX_FMT_RGB32_1 || target == AV_PIX_FMT_BGR32_1) ? 0 : 24) : 0;
1535 
1536  dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1] + (hasAlpha ? A1 << sh : 0);
1537  dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2] + (hasAlpha ? A2 << sh : 0);
1538 #else
1539  if (hasAlpha) {
1540  int sh = (target == AV_PIX_FMT_RGB32_1 || target == AV_PIX_FMT_BGR32_1) ? 0 : 24;
1541 
1542  av_assert2((((r[Y1] + g[Y1] + b[Y1]) >> sh) & 0xFF) == 0);
1543  dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1] + (A1 << sh);
1544  dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2] + (A2 << sh);
1545  } else {
1546 #if defined(ASSERT_LEVEL) && ASSERT_LEVEL > 1
1547  int sh = (target == AV_PIX_FMT_RGB32_1 || target == AV_PIX_FMT_BGR32_1) ? 0 : 24;
1548 
1549  av_assert2((((r[Y1] + g[Y1] + b[Y1]) >> sh) & 0xFF) == 0xFF);
1550 #endif
1551  dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1];
1552  dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2];
1553  }
1554 #endif
1555  } else if (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) {
1556  uint8_t *dest = (uint8_t *) _dest;
1557  const uint8_t *r = (const uint8_t *) _r;
1558  const uint8_t *g = (const uint8_t *) _g;
1559  const uint8_t *b = (const uint8_t *) _b;
1560 
1561 #define r_b ((target == AV_PIX_FMT_RGB24) ? r : b)
1562 #define b_r ((target == AV_PIX_FMT_RGB24) ? b : r)
1563 
1564  dest[i * 6 + 0] = r_b[Y1];
1565  dest[i * 6 + 1] = g[Y1];
1566  dest[i * 6 + 2] = b_r[Y1];
1567  dest[i * 6 + 3] = r_b[Y2];
1568  dest[i * 6 + 4] = g[Y2];
1569  dest[i * 6 + 5] = b_r[Y2];
1570 #undef r_b
1571 #undef b_r
1572  } else if (target == AV_PIX_FMT_RGB565 || target == AV_PIX_FMT_BGR565 ||
1573  target == AV_PIX_FMT_RGB555 || target == AV_PIX_FMT_BGR555 ||
1574  target == AV_PIX_FMT_RGB444 || target == AV_PIX_FMT_BGR444) {
1575  uint16_t *dest = (uint16_t *) _dest;
1576  const uint16_t *r = (const uint16_t *) _r;
1577  const uint16_t *g = (const uint16_t *) _g;
1578  const uint16_t *b = (const uint16_t *) _b;
1579  int dr1, dg1, db1, dr2, dg2, db2;
1580 
1581  if (target == AV_PIX_FMT_RGB565 || target == AV_PIX_FMT_BGR565) {
1582  dr1 = ff_dither_2x2_8[ y & 1 ][0];
1583  dg1 = ff_dither_2x2_4[ y & 1 ][0];
1584  db1 = ff_dither_2x2_8[(y & 1) ^ 1][0];
1585  dr2 = ff_dither_2x2_8[ y & 1 ][1];
1586  dg2 = ff_dither_2x2_4[ y & 1 ][1];
1587  db2 = ff_dither_2x2_8[(y & 1) ^ 1][1];
1588  } else if (target == AV_PIX_FMT_RGB555 || target == AV_PIX_FMT_BGR555) {
1589  dr1 = ff_dither_2x2_8[ y & 1 ][0];
1590  dg1 = ff_dither_2x2_8[ y & 1 ][1];
1591  db1 = ff_dither_2x2_8[(y & 1) ^ 1][0];
1592  dr2 = ff_dither_2x2_8[ y & 1 ][1];
1593  dg2 = ff_dither_2x2_8[ y & 1 ][0];
1594  db2 = ff_dither_2x2_8[(y & 1) ^ 1][1];
1595  } else {
1596  dr1 = ff_dither_4x4_16[ y & 3 ][0];
1597  dg1 = ff_dither_4x4_16[ y & 3 ][1];
1598  db1 = ff_dither_4x4_16[(y & 3) ^ 3][0];
1599  dr2 = ff_dither_4x4_16[ y & 3 ][1];
1600  dg2 = ff_dither_4x4_16[ y & 3 ][0];
1601  db2 = ff_dither_4x4_16[(y & 3) ^ 3][1];
1602  }
1603 
1604  dest[i * 2 + 0] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1];
1605  dest[i * 2 + 1] = r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2];
1606  } else /* 8/4 bits */ {
1607  uint8_t *dest = (uint8_t *) _dest;
1608  const uint8_t *r = (const uint8_t *) _r;
1609  const uint8_t *g = (const uint8_t *) _g;
1610  const uint8_t *b = (const uint8_t *) _b;
1611  int dr1, dg1, db1, dr2, dg2, db2;
1612 
1613  if (target == AV_PIX_FMT_RGB8 || target == AV_PIX_FMT_BGR8) {
1614  const uint8_t * const d64 = ff_dither_8x8_73[y & 7];
1615  const uint8_t * const d32 = ff_dither_8x8_32[y & 7];
1616  dr1 = dg1 = d32[(i * 2 + 0) & 7];
1617  db1 = d64[(i * 2 + 0) & 7];
1618  dr2 = dg2 = d32[(i * 2 + 1) & 7];
1619  db2 = d64[(i * 2 + 1) & 7];
1620  } else {
1621  const uint8_t * const d64 = ff_dither_8x8_73 [y & 7];
1622  const uint8_t * const d128 = ff_dither_8x8_220[y & 7];
1623  dr1 = db1 = d128[(i * 2 + 0) & 7];
1624  dg1 = d64[(i * 2 + 0) & 7];
1625  dr2 = db2 = d128[(i * 2 + 1) & 7];
1626  dg2 = d64[(i * 2 + 1) & 7];
1627  }
1628 
1629  if (target == AV_PIX_FMT_RGB4 || target == AV_PIX_FMT_BGR4) {
1630  dest[i] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1] +
1631  ((r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2]) << 4);
1632  } else {
1633  dest[i * 2 + 0] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1];
1634  dest[i * 2 + 1] = r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2];
1635  }
1636  }
1637 }
1638 
1639 static av_always_inline void
1640 yuv2rgb_X_c_template(SwsContext *c, const int16_t *lumFilter,
1641  const int16_t **lumSrc, int lumFilterSize,
1642  const int16_t *chrFilter, const int16_t **chrUSrc,
1643  const int16_t **chrVSrc, int chrFilterSize,
1644  const int16_t **alpSrc, uint8_t *dest, int dstW,
1645  int y, enum AVPixelFormat target, int hasAlpha)
1646 {
1647  int i;
1648 
1649  for (i = 0; i < ((dstW + 1) >> 1); i++) {
1650  int j, A1, A2;
1651  int Y1 = 1 << 18;
1652  int Y2 = 1 << 18;
1653  int U = 1 << 18;
1654  int V = 1 << 18;
1655  const void *r, *g, *b;
1656 
1657  for (j = 0; j < lumFilterSize; j++) {
1658  Y1 += lumSrc[j][i * 2] * lumFilter[j];
1659  Y2 += lumSrc[j][i * 2 + 1] * lumFilter[j];
1660  }
1661  for (j = 0; j < chrFilterSize; j++) {
1662  U += chrUSrc[j][i] * chrFilter[j];
1663  V += chrVSrc[j][i] * chrFilter[j];
1664  }
1665  Y1 >>= 19;
1666  Y2 >>= 19;
1667  U >>= 19;
1668  V >>= 19;
1669  if (hasAlpha) {
1670  A1 = 1 << 18;
1671  A2 = 1 << 18;
1672  for (j = 0; j < lumFilterSize; j++) {
1673  A1 += alpSrc[j][i * 2 ] * lumFilter[j];
1674  A2 += alpSrc[j][i * 2 + 1] * lumFilter[j];
1675  }
1676  A1 >>= 19;
1677  A2 >>= 19;
1678  if ((A1 | A2) & 0x100) {
1679  A1 = av_clip_uint8(A1);
1680  A2 = av_clip_uint8(A2);
1681  }
1682  }
1683 
1684  r = c->table_rV[V + YUVRGB_TABLE_HEADROOM];
1686  b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
1687 
1688  yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
1689  r, g, b, y, target, hasAlpha);
1690  }
1691 }
1692 
1693 static av_always_inline void
1694 yuv2rgb_2_c_template(SwsContext *c, const int16_t *buf[2],
1695  const int16_t *ubuf[2], const int16_t *vbuf[2],
1696  const int16_t *abuf[2], uint8_t *dest, int dstW,
1697  int yalpha, int uvalpha, int y,
1698  enum AVPixelFormat target, int hasAlpha)
1699 {
1700  const int16_t *buf0 = buf[0], *buf1 = buf[1],
1701  *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
1702  *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
1703  *abuf0 = hasAlpha ? abuf[0] : NULL,
1704  *abuf1 = hasAlpha ? abuf[1] : NULL;
1705  int yalpha1 = 4096 - yalpha;
1706  int uvalpha1 = 4096 - uvalpha;
1707  int i;
1708  av_assert2(yalpha <= 4096U);
1709  av_assert2(uvalpha <= 4096U);
1710 
1711  for (i = 0; i < ((dstW + 1) >> 1); i++) {
1712  int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 19;
1713  int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 19;
1714  int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha) >> 19;
1715  int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha) >> 19;
1716  int A1, A2;
1717  const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM],
1719  *b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
1720 
1721  if (hasAlpha) {
1722  A1 = (abuf0[i * 2 ] * yalpha1 + abuf1[i * 2 ] * yalpha) >> 19;
1723  A2 = (abuf0[i * 2 + 1] * yalpha1 + abuf1[i * 2 + 1] * yalpha) >> 19;
1724  A1 = av_clip_uint8(A1);
1725  A2 = av_clip_uint8(A2);
1726  }
1727 
1728  yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
1729  r, g, b, y, target, hasAlpha);
1730  }
1731 }
1732 
1733 static av_always_inline void
1734 yuv2rgb_1_c_template(SwsContext *c, const int16_t *buf0,
1735  const int16_t *ubuf[2], const int16_t *vbuf[2],
1736  const int16_t *abuf0, uint8_t *dest, int dstW,
1737  int uvalpha, int y, enum AVPixelFormat target,
1738  int hasAlpha)
1739 {
1740  const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
1741  int i;
1742 
1743  if (uvalpha < 2048) {
1744  for (i = 0; i < ((dstW + 1) >> 1); i++) {
1745  int Y1 = (buf0[i * 2 ] + 64) >> 7;
1746  int Y2 = (buf0[i * 2 + 1] + 64) >> 7;
1747  int U = (ubuf0[i] + 64) >> 7;
1748  int V = (vbuf0[i] + 64) >> 7;
1749  int A1, A2;
1750  const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM],
1752  *b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
1753 
1754  if (hasAlpha) {
1755  A1 = abuf0[i * 2 ] * 255 + 16384 >> 15;
1756  A2 = abuf0[i * 2 + 1] * 255 + 16384 >> 15;
1757  A1 = av_clip_uint8(A1);
1758  A2 = av_clip_uint8(A2);
1759  }
1760 
1761  yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
1762  r, g, b, y, target, hasAlpha);
1763  }
1764  } else {
1765  const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
1766  for (i = 0; i < ((dstW + 1) >> 1); i++) {
1767  int Y1 = (buf0[i * 2 ] + 64) >> 7;
1768  int Y2 = (buf0[i * 2 + 1] + 64) >> 7;
1769  int U = (ubuf0[i] + ubuf1[i] + 128) >> 8;
1770  int V = (vbuf0[i] + vbuf1[i] + 128) >> 8;
1771  int A1, A2;
1772  const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM],
1774  *b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
1775 
1776  if (hasAlpha) {
1777  A1 = (abuf0[i * 2 ] + 64) >> 7;
1778  A2 = (abuf0[i * 2 + 1] + 64) >> 7;
1779  A1 = av_clip_uint8(A1);
1780  A2 = av_clip_uint8(A2);
1781  }
1782 
1783  yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
1784  r, g, b, y, target, hasAlpha);
1785  }
1786  }
1787 }
1788 
1789 #define YUV2RGBWRAPPERX(name, base, ext, fmt, hasAlpha) \
1790 static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \
1791  const int16_t **lumSrc, int lumFilterSize, \
1792  const int16_t *chrFilter, const int16_t **chrUSrc, \
1793  const int16_t **chrVSrc, int chrFilterSize, \
1794  const int16_t **alpSrc, uint8_t *dest, int dstW, \
1795  int y) \
1796 { \
1797  name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
1798  chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
1799  alpSrc, dest, dstW, y, fmt, hasAlpha); \
1800 }
1801 
1802 #define YUV2RGBWRAPPERX2(name, base, ext, fmt, hasAlpha) \
1803 YUV2RGBWRAPPERX(name, base, ext, fmt, hasAlpha) \
1804 static void name ## ext ## _2_c(SwsContext *c, const int16_t *buf[2], \
1805  const int16_t *ubuf[2], const int16_t *vbuf[2], \
1806  const int16_t *abuf[2], uint8_t *dest, int dstW, \
1807  int yalpha, int uvalpha, int y) \
1808 { \
1809  name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
1810  dest, dstW, yalpha, uvalpha, y, fmt, hasAlpha); \
1811 }
1812 
1813 #define YUV2RGBWRAPPER(name, base, ext, fmt, hasAlpha) \
1814 YUV2RGBWRAPPERX2(name, base, ext, fmt, hasAlpha) \
1815 static void name ## ext ## _1_c(SwsContext *c, const int16_t *buf0, \
1816  const int16_t *ubuf[2], const int16_t *vbuf[2], \
1817  const int16_t *abuf0, uint8_t *dest, int dstW, \
1818  int uvalpha, int y) \
1819 { \
1820  name ## base ## _1_c_template(c, buf0, ubuf, vbuf, abuf0, dest, \
1821  dstW, uvalpha, y, fmt, hasAlpha); \
1822 }
1823 
1824 #if CONFIG_SMALL
1827 #else
1828 #if CONFIG_SWSCALE_ALPHA
1829 YUV2RGBWRAPPER(yuv2rgb,, a32_1, AV_PIX_FMT_RGB32_1, 1)
1830 YUV2RGBWRAPPER(yuv2rgb,, a32, AV_PIX_FMT_RGB32, 1)
1831 #endif
1832 YUV2RGBWRAPPER(yuv2rgb,, x32_1, AV_PIX_FMT_RGB32_1, 0)
1833 YUV2RGBWRAPPER(yuv2rgb,, x32, AV_PIX_FMT_RGB32, 0)
1834 #endif
1835 YUV2RGBWRAPPER(yuv2, rgb, rgb24, AV_PIX_FMT_RGB24, 0)
1836 YUV2RGBWRAPPER(yuv2, rgb, bgr24, AV_PIX_FMT_BGR24, 0)
1837 YUV2RGBWRAPPER(yuv2rgb,, 16, AV_PIX_FMT_RGB565, 0)
1838 YUV2RGBWRAPPER(yuv2rgb,, 15, AV_PIX_FMT_RGB555, 0)
1839 YUV2RGBWRAPPER(yuv2rgb,, 12, AV_PIX_FMT_RGB444, 0)
1840 YUV2RGBWRAPPER(yuv2rgb,, 8, AV_PIX_FMT_RGB8, 0)
1841 YUV2RGBWRAPPER(yuv2rgb,, 4, AV_PIX_FMT_RGB4, 0)
1842 YUV2RGBWRAPPER(yuv2rgb,, 4b, AV_PIX_FMT_RGB4_BYTE, 0)
1843 
1845  uint8_t *dest, int i, int Y, int A, int U, int V,
1846  int y, enum AVPixelFormat target, int hasAlpha, int err[4])
1847 {
1848  int R, G, B;
1849  int isrgb8 = target == AV_PIX_FMT_BGR8 || target == AV_PIX_FMT_RGB8;
1850 
1851  Y -= c->yuv2rgb_y_offset;
1852  Y *= c->yuv2rgb_y_coeff;
1853  Y += 1 << 21;
1854  R = (unsigned)Y + V*(unsigned)c->yuv2rgb_v2r_coeff;
1855  G = (unsigned)Y + V*(unsigned)c->yuv2rgb_v2g_coeff + U*(unsigned)c->yuv2rgb_u2g_coeff;
1856  B = (unsigned)Y + U*(unsigned)c->yuv2rgb_u2b_coeff;
1857  if ((R | G | B) & 0xC0000000) {
1858  R = av_clip_uintp2(R, 30);
1859  G = av_clip_uintp2(G, 30);
1860  B = av_clip_uintp2(B, 30);
1861  }
1862 
1863  switch(target) {
1864  case AV_PIX_FMT_ARGB:
1865  dest[0] = hasAlpha ? A : 255;
1866  dest[1] = R >> 22;
1867  dest[2] = G >> 22;
1868  dest[3] = B >> 22;
1869  break;
1870  case AV_PIX_FMT_RGB24:
1871  dest[0] = R >> 22;
1872  dest[1] = G >> 22;
1873  dest[2] = B >> 22;
1874  break;
1875  case AV_PIX_FMT_RGBA:
1876  dest[0] = R >> 22;
1877  dest[1] = G >> 22;
1878  dest[2] = B >> 22;
1879  dest[3] = hasAlpha ? A : 255;
1880  break;
1881  case AV_PIX_FMT_ABGR:
1882  dest[0] = hasAlpha ? A : 255;
1883  dest[1] = B >> 22;
1884  dest[2] = G >> 22;
1885  dest[3] = R >> 22;
1886  break;
1887  case AV_PIX_FMT_BGR24:
1888  dest[0] = B >> 22;
1889  dest[1] = G >> 22;
1890  dest[2] = R >> 22;
1891  break;
1892  case AV_PIX_FMT_BGRA:
1893  dest[0] = B >> 22;
1894  dest[1] = G >> 22;
1895  dest[2] = R >> 22;
1896  dest[3] = hasAlpha ? A : 255;
1897  break;
1898  case AV_PIX_FMT_BGR4_BYTE:
1899  case AV_PIX_FMT_RGB4_BYTE:
1900  case AV_PIX_FMT_BGR8:
1901  case AV_PIX_FMT_RGB8:
1902  {
1903  int r,g,b;
1904 
1905  switch (c->dither) {
1906  default:
1907  case SWS_DITHER_AUTO:
1908  case SWS_DITHER_ED:
1909  R >>= 22;
1910  G >>= 22;
1911  B >>= 22;
1912  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;
1913  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;
1914  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;
1915  c->dither_error[0][i] = err[0];
1916  c->dither_error[1][i] = err[1];
1917  c->dither_error[2][i] = err[2];
1918  r = R >> (isrgb8 ? 5 : 7);
1919  g = G >> (isrgb8 ? 5 : 6);
1920  b = B >> (isrgb8 ? 6 : 7);
1921  r = av_clip(r, 0, isrgb8 ? 7 : 1);
1922  g = av_clip(g, 0, isrgb8 ? 7 : 3);
1923  b = av_clip(b, 0, isrgb8 ? 3 : 1);
1924  err[0] = R - r*(isrgb8 ? 36 : 255);
1925  err[1] = G - g*(isrgb8 ? 36 : 85);
1926  err[2] = B - b*(isrgb8 ? 85 : 255);
1927  break;
1928  case SWS_DITHER_A_DITHER:
1929  if (isrgb8) {
1930  /* see http://pippin.gimp.org/a_dither/ for details/origin */
1931 #define A_DITHER(u,v) (((((u)+((v)*236))*119)&0xff))
1932  r = (((R >> 19) + A_DITHER(i,y) -96)>>8);
1933  g = (((G >> 19) + A_DITHER(i + 17,y) - 96)>>8);
1934  b = (((B >> 20) + A_DITHER(i + 17*2,y) -96)>>8);
1935  r = av_clip_uintp2(r, 3);
1936  g = av_clip_uintp2(g, 3);
1937  b = av_clip_uintp2(b, 2);
1938  } else {
1939  r = (((R >> 21) + A_DITHER(i,y)-256)>>8);
1940  g = (((G >> 19) + A_DITHER(i + 17,y)-256)>>8);
1941  b = (((B >> 21) + A_DITHER(i + 17*2,y)-256)>>8);
1942  r = av_clip_uintp2(r, 1);
1943  g = av_clip_uintp2(g, 2);
1944  b = av_clip_uintp2(b, 1);
1945  }
1946  break;
1947  case SWS_DITHER_X_DITHER:
1948  if (isrgb8) {
1949  /* see http://pippin.gimp.org/a_dither/ for details/origin */
1950 #define X_DITHER(u,v) (((((u)^((v)*237))*181)&0x1ff)/2)
1951  r = (((R >> 19) + X_DITHER(i,y) - 96)>>8);
1952  g = (((G >> 19) + X_DITHER(i + 17,y) - 96)>>8);
1953  b = (((B >> 20) + X_DITHER(i + 17*2,y) - 96)>>8);
1954  r = av_clip_uintp2(r, 3);
1955  g = av_clip_uintp2(g, 3);
1956  b = av_clip_uintp2(b, 2);
1957  } else {
1958  r = (((R >> 21) + X_DITHER(i,y)-256)>>8);
1959  g = (((G >> 19) + X_DITHER(i + 17,y)-256)>>8);
1960  b = (((B >> 21) + X_DITHER(i + 17*2,y)-256)>>8);
1961  r = av_clip_uintp2(r, 1);
1962  g = av_clip_uintp2(g, 2);
1963  b = av_clip_uintp2(b, 1);
1964  }
1965 
1966  break;
1967  }
1968 
1969  if(target == AV_PIX_FMT_BGR4_BYTE) {
1970  dest[0] = r + 2*g + 8*b;
1971  } else if(target == AV_PIX_FMT_RGB4_BYTE) {
1972  dest[0] = b + 2*g + 8*r;
1973  } else if(target == AV_PIX_FMT_BGR8) {
1974  dest[0] = r + 8*g + 64*b;
1975  } else if(target == AV_PIX_FMT_RGB8) {
1976  dest[0] = b + 4*g + 32*r;
1977  } else
1978  av_assert2(0);
1979  break;}
1980  }
1981 }
1982 
1983 static av_always_inline void
1984 yuv2rgb_full_X_c_template(SwsContext *c, const int16_t *lumFilter,
1985  const int16_t **lumSrc, int lumFilterSize,
1986  const int16_t *chrFilter, const int16_t **chrUSrc,
1987  const int16_t **chrVSrc, int chrFilterSize,
1988  const int16_t **alpSrc, uint8_t *dest,
1989  int dstW, int y, enum AVPixelFormat target, int hasAlpha)
1990 {
1991  int i;
1992  int step = (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) ? 3 : 4;
1993  int err[4] = {0};
1994  int A = 0; //init to silence warning
1995 
1996  if( target == AV_PIX_FMT_BGR4_BYTE || target == AV_PIX_FMT_RGB4_BYTE
1997  || target == AV_PIX_FMT_BGR8 || target == AV_PIX_FMT_RGB8)
1998  step = 1;
1999 
2000  for (i = 0; i < dstW; i++) {
2001  int j;
2002  int Y = 1<<9;
2003  int U = (1<<9)-(128 << 19);
2004  int V = (1<<9)-(128 << 19);
2005 
2006  for (j = 0; j < lumFilterSize; j++) {
2007  Y += lumSrc[j][i] * lumFilter[j];
2008  }
2009  for (j = 0; j < chrFilterSize; j++) {
2010  U += chrUSrc[j][i] * chrFilter[j];
2011  V += chrVSrc[j][i] * chrFilter[j];
2012  }
2013  Y >>= 10;
2014  U >>= 10;
2015  V >>= 10;
2016  if (hasAlpha) {
2017  A = 1 << 18;
2018  for (j = 0; j < lumFilterSize; j++) {
2019  A += alpSrc[j][i] * lumFilter[j];
2020  }
2021  A >>= 19;
2022  if (A & 0x100)
2023  A = av_clip_uint8(A);
2024  }
2025  yuv2rgb_write_full(c, dest, i, Y, A, U, V, y, target, hasAlpha, err);
2026  dest += step;
2027  }
2028  c->dither_error[0][i] = err[0];
2029  c->dither_error[1][i] = err[1];
2030  c->dither_error[2][i] = err[2];
2031 }
2032 
2033 static av_always_inline void
2034 yuv2rgb_full_2_c_template(SwsContext *c, const int16_t *buf[2],
2035  const int16_t *ubuf[2], const int16_t *vbuf[2],
2036  const int16_t *abuf[2], uint8_t *dest, int dstW,
2037  int yalpha, int uvalpha, int y,
2038  enum AVPixelFormat target, int hasAlpha)
2039 {
2040  const int16_t *buf0 = buf[0], *buf1 = buf[1],
2041  *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
2042  *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
2043  *abuf0 = hasAlpha ? abuf[0] : NULL,
2044  *abuf1 = hasAlpha ? abuf[1] : NULL;
2045  int yalpha1 = 4096 - yalpha;
2046  int uvalpha1 = 4096 - uvalpha;
2047  int i;
2048  int step = (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) ? 3 : 4;
2049  int err[4] = {0};
2050  int A = 0; // init to silcene warning
2051 
2052  av_assert2(yalpha <= 4096U);
2053  av_assert2(uvalpha <= 4096U);
2054 
2055  if( target == AV_PIX_FMT_BGR4_BYTE || target == AV_PIX_FMT_RGB4_BYTE
2056  || target == AV_PIX_FMT_BGR8 || target == AV_PIX_FMT_RGB8)
2057  step = 1;
2058 
2059  for (i = 0; i < dstW; i++) {
2060  int Y = ( buf0[i] * yalpha1 + buf1[i] * yalpha ) >> 10; //FIXME rounding
2061  int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha-(128 << 19)) >> 10;
2062  int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha-(128 << 19)) >> 10;
2063 
2064  if (hasAlpha) {
2065  A = (abuf0[i] * yalpha1 + abuf1[i] * yalpha + (1<<18)) >> 19;
2066  if (A & 0x100)
2067  A = av_clip_uint8(A);
2068  }
2069 
2070  yuv2rgb_write_full(c, dest, i, Y, A, U, V, y, target, hasAlpha, err);
2071  dest += step;
2072  }
2073  c->dither_error[0][i] = err[0];
2074  c->dither_error[1][i] = err[1];
2075  c->dither_error[2][i] = err[2];
2076 }
2077 
2078 static av_always_inline void
2080  const int16_t *ubuf[2], const int16_t *vbuf[2],
2081  const int16_t *abuf0, uint8_t *dest, int dstW,
2082  int uvalpha, int y, enum AVPixelFormat target,
2083  int hasAlpha)
2084 {
2085  const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
2086  int i;
2087  int step = (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) ? 3 : 4;
2088  int err[4] = {0};
2089 
2090  if( target == AV_PIX_FMT_BGR4_BYTE || target == AV_PIX_FMT_RGB4_BYTE
2091  || target == AV_PIX_FMT_BGR8 || target == AV_PIX_FMT_RGB8)
2092  step = 1;
2093 
2094  if (uvalpha < 2048) {
2095  int A = 0; //init to silence warning
2096  for (i = 0; i < dstW; i++) {
2097  int Y = buf0[i] * 4;
2098  int U = (ubuf0[i] - (128<<7)) * 4;
2099  int V = (vbuf0[i] - (128<<7)) * 4;
2100 
2101  if (hasAlpha) {
2102  A = (abuf0[i] + 64) >> 7;
2103  if (A & 0x100)
2104  A = av_clip_uint8(A);
2105  }
2106 
2107  yuv2rgb_write_full(c, dest, i, Y, A, U, V, y, target, hasAlpha, err);
2108  dest += step;
2109  }
2110  } else {
2111  const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
2112  int A = 0; //init to silence warning
2113  for (i = 0; i < dstW; i++) {
2114  int Y = buf0[i] * 4;
2115  int U = (ubuf0[i] + ubuf1[i] - (128<<8)) * 2;
2116  int V = (vbuf0[i] + vbuf1[i] - (128<<8)) * 2;
2117 
2118  if (hasAlpha) {
2119  A = (abuf0[i] + 64) >> 7;
2120  if (A & 0x100)
2121  A = av_clip_uint8(A);
2122  }
2123 
2124  yuv2rgb_write_full(c, dest, i, Y, A, U, V, y, target, hasAlpha, err);
2125  dest += step;
2126  }
2127  }
2128 
2129  c->dither_error[0][i] = err[0];
2130  c->dither_error[1][i] = err[1];
2131  c->dither_error[2][i] = err[2];
2132 }
2133 
2134 #if CONFIG_SMALL
2135 YUV2RGBWRAPPER(yuv2, rgb_full, bgra32_full, AV_PIX_FMT_BGRA, CONFIG_SWSCALE_ALPHA && c->needAlpha)
2136 YUV2RGBWRAPPER(yuv2, rgb_full, abgr32_full, AV_PIX_FMT_ABGR, CONFIG_SWSCALE_ALPHA && c->needAlpha)
2137 YUV2RGBWRAPPER(yuv2, rgb_full, rgba32_full, AV_PIX_FMT_RGBA, CONFIG_SWSCALE_ALPHA && c->needAlpha)
2138 YUV2RGBWRAPPER(yuv2, rgb_full, argb32_full, AV_PIX_FMT_ARGB, CONFIG_SWSCALE_ALPHA && c->needAlpha)
2139 #else
2140 #if CONFIG_SWSCALE_ALPHA
2141 YUV2RGBWRAPPER(yuv2, rgb_full, bgra32_full, AV_PIX_FMT_BGRA, 1)
2142 YUV2RGBWRAPPER(yuv2, rgb_full, abgr32_full, AV_PIX_FMT_ABGR, 1)
2143 YUV2RGBWRAPPER(yuv2, rgb_full, rgba32_full, AV_PIX_FMT_RGBA, 1)
2144 YUV2RGBWRAPPER(yuv2, rgb_full, argb32_full, AV_PIX_FMT_ARGB, 1)
2145 #endif
2146 YUV2RGBWRAPPER(yuv2, rgb_full, bgrx32_full, AV_PIX_FMT_BGRA, 0)
2147 YUV2RGBWRAPPER(yuv2, rgb_full, xbgr32_full, AV_PIX_FMT_ABGR, 0)
2148 YUV2RGBWRAPPER(yuv2, rgb_full, rgbx32_full, AV_PIX_FMT_RGBA, 0)
2149 YUV2RGBWRAPPER(yuv2, rgb_full, xrgb32_full, AV_PIX_FMT_ARGB, 0)
2150 #endif
2151 YUV2RGBWRAPPER(yuv2, rgb_full, bgr24_full, AV_PIX_FMT_BGR24, 0)
2152 YUV2RGBWRAPPER(yuv2, rgb_full, rgb24_full, AV_PIX_FMT_RGB24, 0)
2153 
2154 YUV2RGBWRAPPER(yuv2, rgb_full, bgr4_byte_full, AV_PIX_FMT_BGR4_BYTE, 0)
2155 YUV2RGBWRAPPER(yuv2, rgb_full, rgb4_byte_full, AV_PIX_FMT_RGB4_BYTE, 0)
2156 YUV2RGBWRAPPER(yuv2, rgb_full, bgr8_full, AV_PIX_FMT_BGR8, 0)
2157 YUV2RGBWRAPPER(yuv2, rgb_full, rgb8_full, AV_PIX_FMT_RGB8, 0)
2158 
2159 static void
2160 yuv2gbrp_full_X_c(SwsContext *c, const int16_t *lumFilter,
2161  const int16_t **lumSrc, int lumFilterSize,
2162  const int16_t *chrFilter, const int16_t **chrUSrc,
2163  const int16_t **chrVSrc, int chrFilterSize,
2164  const int16_t **alpSrc, uint8_t **dest,
2165  int dstW, int y)
2166 {
2168  int i;
2169  int hasAlpha = (desc->flags & AV_PIX_FMT_FLAG_ALPHA) && alpSrc;
2170  uint16_t **dest16 = (uint16_t**)dest;
2171  int SH = 22 + 8 - desc->comp[0].depth;
2172  int A = 0; // init to silence warning
2173 
2174  for (i = 0; i < dstW; i++) {
2175  int j;
2176  int Y = 1 << 9;
2177  int U = (1 << 9) - (128 << 19);
2178  int V = (1 << 9) - (128 << 19);
2179  int R, G, B;
2180 
2181  for (j = 0; j < lumFilterSize; j++)
2182  Y += lumSrc[j][i] * lumFilter[j];
2183 
2184  for (j = 0; j < chrFilterSize; j++) {
2185  U += chrUSrc[j][i] * chrFilter[j];
2186  V += chrVSrc[j][i] * chrFilter[j];
2187  }
2188 
2189  Y >>= 10;
2190  U >>= 10;
2191  V >>= 10;
2192 
2193  if (hasAlpha) {
2194  A = 1 << 18;
2195 
2196  for (j = 0; j < lumFilterSize; j++)
2197  A += alpSrc[j][i] * lumFilter[j];
2198 
2199  if (A & 0xF8000000)
2200  A = av_clip_uintp2(A, 27);
2201  }
2202 
2203  Y -= c->yuv2rgb_y_offset;
2204  Y *= c->yuv2rgb_y_coeff;
2205  Y += 1 << (SH-1);
2206  R = Y + V * c->yuv2rgb_v2r_coeff;
2207  G = Y + V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
2208  B = Y + U * c->yuv2rgb_u2b_coeff;
2209 
2210  if ((R | G | B) & 0xC0000000) {
2211  R = av_clip_uintp2(R, 30);
2212  G = av_clip_uintp2(G, 30);
2213  B = av_clip_uintp2(B, 30);
2214  }
2215 
2216  if (SH != 22) {
2217  dest16[0][i] = G >> SH;
2218  dest16[1][i] = B >> SH;
2219  dest16[2][i] = R >> SH;
2220  if (hasAlpha)
2221  dest16[3][i] = A >> (SH - 3);
2222  } else {
2223  dest[0][i] = G >> 22;
2224  dest[1][i] = B >> 22;
2225  dest[2][i] = R >> 22;
2226  if (hasAlpha)
2227  dest[3][i] = A >> 19;
2228  }
2229  }
2230  if (SH != 22 && (!isBE(c->dstFormat)) != (!HAVE_BIGENDIAN)) {
2231  for (i = 0; i < dstW; i++) {
2232  dest16[0][i] = av_bswap16(dest16[0][i]);
2233  dest16[1][i] = av_bswap16(dest16[1][i]);
2234  dest16[2][i] = av_bswap16(dest16[2][i]);
2235  if (hasAlpha)
2236  dest16[3][i] = av_bswap16(dest16[3][i]);
2237  }
2238  }
2239 }
2240 
2241 static void
2242 yuv2gbrp16_full_X_c(SwsContext *c, const int16_t *lumFilter,
2243  const int16_t **lumSrcx, int lumFilterSize,
2244  const int16_t *chrFilter, const int16_t **chrUSrcx,
2245  const int16_t **chrVSrcx, int chrFilterSize,
2246  const int16_t **alpSrcx, uint8_t **dest,
2247  int dstW, int y)
2248 {
2250  int i;
2251  int hasAlpha = (desc->flags & AV_PIX_FMT_FLAG_ALPHA) && alpSrcx;
2252  uint16_t **dest16 = (uint16_t**)dest;
2253  const int32_t **lumSrc = (const int32_t**)lumSrcx;
2254  const int32_t **chrUSrc = (const int32_t**)chrUSrcx;
2255  const int32_t **chrVSrc = (const int32_t**)chrVSrcx;
2256  const int32_t **alpSrc = (const int32_t**)alpSrcx;
2257 
2258  for (i = 0; i < dstW; i++) {
2259  int j;
2260  int Y = -0x40000000;
2261  int U = -(128 << 23);
2262  int V = -(128 << 23);
2263  int R, G, B, A;
2264 
2265  for (j = 0; j < lumFilterSize; j++)
2266  Y += lumSrc[j][i] * (unsigned)lumFilter[j];
2267 
2268  for (j = 0; j < chrFilterSize; j++) {
2269  U += chrUSrc[j][i] * (unsigned)chrFilter[j];
2270  V += chrVSrc[j][i] * (unsigned)chrFilter[j];
2271  }
2272 
2273  Y >>= 14;
2274  Y += 0x10000;
2275  U >>= 14;
2276  V >>= 14;
2277 
2278  if (hasAlpha) {
2279  A = -0x40000000;
2280 
2281  for (j = 0; j < lumFilterSize; j++)
2282  A += alpSrc[j][i] * (unsigned)lumFilter[j];
2283 
2284  A >>= 1;
2285  A += 0x20002000;
2286  }
2287 
2288  Y -= c->yuv2rgb_y_offset;
2289  Y *= c->yuv2rgb_y_coeff;
2290  Y += 1 << 13;
2291  R = V * c->yuv2rgb_v2r_coeff;
2292  G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
2293  B = U * c->yuv2rgb_u2b_coeff;
2294 
2295  R = av_clip_uintp2(Y + R, 30);
2296  G = av_clip_uintp2(Y + G, 30);
2297  B = av_clip_uintp2(Y + B, 30);
2298 
2299  dest16[0][i] = G >> 14;
2300  dest16[1][i] = B >> 14;
2301  dest16[2][i] = R >> 14;
2302  if (hasAlpha)
2303  dest16[3][i] = av_clip_uintp2(A, 30) >> 14;
2304  }
2305  if ((!isBE(c->dstFormat)) != (!HAVE_BIGENDIAN)) {
2306  for (i = 0; i < dstW; i++) {
2307  dest16[0][i] = av_bswap16(dest16[0][i]);
2308  dest16[1][i] = av_bswap16(dest16[1][i]);
2309  dest16[2][i] = av_bswap16(dest16[2][i]);
2310  if (hasAlpha)
2311  dest16[3][i] = av_bswap16(dest16[3][i]);
2312  }
2313  }
2314 }
2315 
2316 static void
2317 yuv2gbrpf32_full_X_c(SwsContext *c, const int16_t *lumFilter,
2318  const int16_t **lumSrcx, int lumFilterSize,
2319  const int16_t *chrFilter, const int16_t **chrUSrcx,
2320  const int16_t **chrVSrcx, int chrFilterSize,
2321  const int16_t **alpSrcx, uint8_t **dest,
2322  int dstW, int y)
2323 {
2325  int i;
2326  int hasAlpha = (desc->flags & AV_PIX_FMT_FLAG_ALPHA) && alpSrcx;
2327  uint32_t **dest32 = (uint32_t**)dest;
2328  const int32_t **lumSrc = (const int32_t**)lumSrcx;
2329  const int32_t **chrUSrc = (const int32_t**)chrUSrcx;
2330  const int32_t **chrVSrc = (const int32_t**)chrVSrcx;
2331  const int32_t **alpSrc = (const int32_t**)alpSrcx;
2332  static const float float_mult = 1.0f / 65535.0f;
2333 
2334  for (i = 0; i < dstW; i++) {
2335  int j;
2336  int Y = -0x40000000;
2337  int U = -(128 << 23);
2338  int V = -(128 << 23);
2339  int R, G, B, A;
2340 
2341  for (j = 0; j < lumFilterSize; j++)
2342  Y += lumSrc[j][i] * (unsigned)lumFilter[j];
2343 
2344  for (j = 0; j < chrFilterSize; j++) {
2345  U += chrUSrc[j][i] * (unsigned)chrFilter[j];
2346  V += chrVSrc[j][i] * (unsigned)chrFilter[j];
2347  }
2348 
2349  Y >>= 14;
2350  Y += 0x10000;
2351  U >>= 14;
2352  V >>= 14;
2353 
2354  if (hasAlpha) {
2355  A = -0x40000000;
2356 
2357  for (j = 0; j < lumFilterSize; j++)
2358  A += alpSrc[j][i] * (unsigned)lumFilter[j];
2359 
2360  A >>= 1;
2361  A += 0x20002000;
2362  }
2363 
2364  Y -= c->yuv2rgb_y_offset;
2365  Y *= c->yuv2rgb_y_coeff;
2366  Y += 1 << 13;
2367  R = V * c->yuv2rgb_v2r_coeff;
2368  G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
2369  B = U * c->yuv2rgb_u2b_coeff;
2370 
2371  R = av_clip_uintp2(Y + R, 30);
2372  G = av_clip_uintp2(Y + G, 30);
2373  B = av_clip_uintp2(Y + B, 30);
2374 
2375  dest32[0][i] = av_float2int(float_mult * (float)(G >> 14));
2376  dest32[1][i] = av_float2int(float_mult * (float)(B >> 14));
2377  dest32[2][i] = av_float2int(float_mult * (float)(R >> 14));
2378  if (hasAlpha)
2379  dest32[3][i] = av_float2int(float_mult * (float)(av_clip_uintp2(A, 30) >> 14));
2380  }
2381  if ((!isBE(c->dstFormat)) != (!HAVE_BIGENDIAN)) {
2382  for (i = 0; i < dstW; i++) {
2383  dest32[0][i] = av_bswap32(dest32[0][i]);
2384  dest32[1][i] = av_bswap32(dest32[1][i]);
2385  dest32[2][i] = av_bswap32(dest32[2][i]);
2386  if (hasAlpha)
2387  dest32[3][i] = av_bswap32(dest32[3][i]);
2388  }
2389  }
2390 }
2391 
2392 static void
2393 yuv2ya8_1_c(SwsContext *c, const int16_t *buf0,
2394  const int16_t *ubuf[2], const int16_t *vbuf[2],
2395  const int16_t *abuf0, uint8_t *dest, int dstW,
2396  int uvalpha, int y)
2397 {
2398  int hasAlpha = !!abuf0;
2399  int i;
2400 
2401  for (i = 0; i < dstW; i++) {
2402  int Y = (buf0[i] + 64) >> 7;
2403  int A;
2404 
2405  Y = av_clip_uint8(Y);
2406 
2407  if (hasAlpha) {
2408  A = (abuf0[i] + 64) >> 7;
2409  if (A & 0x100)
2410  A = av_clip_uint8(A);
2411  }
2412 
2413  dest[i * 2 ] = Y;
2414  dest[i * 2 + 1] = hasAlpha ? A : 255;
2415  }
2416 }
2417 
2418 static void
2419 yuv2ya8_2_c(SwsContext *c, const int16_t *buf[2],
2420  const int16_t *ubuf[2], const int16_t *vbuf[2],
2421  const int16_t *abuf[2], uint8_t *dest, int dstW,
2422  int yalpha, int uvalpha, int y)
2423 {
2424  int hasAlpha = abuf && abuf[0] && abuf[1];
2425  const int16_t *buf0 = buf[0], *buf1 = buf[1],
2426  *abuf0 = hasAlpha ? abuf[0] : NULL,
2427  *abuf1 = hasAlpha ? abuf[1] : NULL;
2428  int yalpha1 = 4096 - yalpha;
2429  int i;
2430 
2431  av_assert2(yalpha <= 4096U);
2432 
2433  for (i = 0; i < dstW; i++) {
2434  int Y = (buf0[i] * yalpha1 + buf1[i] * yalpha) >> 19;
2435  int A;
2436 
2437  Y = av_clip_uint8(Y);
2438 
2439  if (hasAlpha) {
2440  A = (abuf0[i] * yalpha1 + abuf1[i] * yalpha) >> 19;
2441  A = av_clip_uint8(A);
2442  }
2443 
2444  dest[i * 2 ] = Y;
2445  dest[i * 2 + 1] = hasAlpha ? A : 255;
2446  }
2447 }
2448 
2449 static void
2450 yuv2ya8_X_c(SwsContext *c, const int16_t *lumFilter,
2451  const int16_t **lumSrc, int lumFilterSize,
2452  const int16_t *chrFilter, const int16_t **chrUSrc,
2453  const int16_t **chrVSrc, int chrFilterSize,
2454  const int16_t **alpSrc, uint8_t *dest, int dstW, int y)
2455 {
2456  int hasAlpha = !!alpSrc;
2457  int i;
2458 
2459  for (i = 0; i < dstW; i++) {
2460  int j;
2461  int Y = 1 << 18, A = 1 << 18;
2462 
2463  for (j = 0; j < lumFilterSize; j++)
2464  Y += lumSrc[j][i] * lumFilter[j];
2465 
2466  Y >>= 19;
2467  if (Y & 0x100)
2468  Y = av_clip_uint8(Y);
2469 
2470  if (hasAlpha) {
2471  for (j = 0; j < lumFilterSize; j++)
2472  A += alpSrc[j][i] * lumFilter[j];
2473 
2474  A >>= 19;
2475 
2476  if (A & 0x100)
2477  A = av_clip_uint8(A);
2478  }
2479 
2480  dest[2 * i ] = Y;
2481  dest[2 * i + 1] = hasAlpha ? A : 255;
2482  }
2483 }
2484 
2485 static void
2486 yuv2ayuv64le_X_c(SwsContext *c, const int16_t *lumFilter,
2487  const int16_t **_lumSrc, int lumFilterSize,
2488  const int16_t *chrFilter, const int16_t **_chrUSrc,
2489  const int16_t **_chrVSrc, int chrFilterSize,
2490  const int16_t **_alpSrc, uint8_t *dest, int dstW, int y)
2491 {
2492  const int32_t **lumSrc = (const int32_t **) _lumSrc,
2493  **chrUSrc = (const int32_t **) _chrUSrc,
2494  **chrVSrc = (const int32_t **) _chrVSrc,
2495  **alpSrc = (const int32_t **) _alpSrc;
2496  int hasAlpha = !!alpSrc;
2497  int i;
2498 
2499  for (i = 0; i < dstW; i++) {
2500  int Y = 1 << 14, U = 1 << 14;
2501  int V = 1 << 14, A = 1 << 14;
2502  int j;
2503 
2504  Y -= 0x40000000;
2505  U -= 0x40000000;
2506  V -= 0x40000000;
2507  A -= 0x40000000;
2508 
2509  for (j = 0; j < lumFilterSize; j++)
2510  Y += lumSrc[j][i] * (unsigned)lumFilter[j];
2511 
2512  for (j = 0; j < chrFilterSize; j++)
2513  U += chrUSrc[j][i] * (unsigned)chrFilter[j];
2514 
2515  for (j = 0; j < chrFilterSize; j++)
2516  V += chrVSrc[j][i] * (unsigned)chrFilter[j];
2517 
2518  if (hasAlpha)
2519  for (j = 0; j < lumFilterSize; j++)
2520  A += alpSrc[j][i] * (unsigned)lumFilter[j];
2521 
2522  Y = 0x8000 + av_clip_int16(Y >> 15);
2523  U = 0x8000 + av_clip_int16(U >> 15);
2524  V = 0x8000 + av_clip_int16(V >> 15);
2525  A = 0x8000 + av_clip_int16(A >> 15);
2526 
2527  AV_WL16(dest + 8 * i, hasAlpha ? A : 65535);
2528  AV_WL16(dest + 8 * i + 2, Y);
2529  AV_WL16(dest + 8 * i + 4, U);
2530  AV_WL16(dest + 8 * i + 6, V);
2531  }
2532 }
2533 
2535  yuv2planar1_fn *yuv2plane1,
2537  yuv2interleavedX_fn *yuv2nv12cX,
2538  yuv2packed1_fn *yuv2packed1,
2539  yuv2packed2_fn *yuv2packed2,
2540  yuv2packedX_fn *yuv2packedX,
2541  yuv2anyX_fn *yuv2anyX)
2542 {
2543  enum AVPixelFormat dstFormat = c->dstFormat;
2544  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(dstFormat);
2545 
2546  if (dstFormat == AV_PIX_FMT_P010LE || dstFormat == AV_PIX_FMT_P010BE) {
2547  *yuv2plane1 = isBE(dstFormat) ? yuv2p010l1_BE_c : yuv2p010l1_LE_c;
2548  *yuv2planeX = isBE(dstFormat) ? yuv2p010lX_BE_c : yuv2p010lX_LE_c;
2549  *yuv2nv12cX = yuv2p010cX_c;
2550  } else if (is16BPS(dstFormat)) {
2551  *yuv2planeX = isBE(dstFormat) ? yuv2planeX_16BE_c : yuv2planeX_16LE_c;
2552  *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_16BE_c : yuv2plane1_16LE_c;
2553  if (dstFormat == AV_PIX_FMT_P016LE || dstFormat == AV_PIX_FMT_P016BE) {
2554  *yuv2nv12cX = yuv2p016cX_c;
2555  }
2556  } else if (isNBPS(dstFormat)) {
2557  if (desc->comp[0].depth == 9) {
2558  *yuv2planeX = isBE(dstFormat) ? yuv2planeX_9BE_c : yuv2planeX_9LE_c;
2559  *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_9BE_c : yuv2plane1_9LE_c;
2560  } else if (desc->comp[0].depth == 10) {
2561  *yuv2planeX = isBE(dstFormat) ? yuv2planeX_10BE_c : yuv2planeX_10LE_c;
2562  *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_10BE_c : yuv2plane1_10LE_c;
2563  } else if (desc->comp[0].depth == 12) {
2564  *yuv2planeX = isBE(dstFormat) ? yuv2planeX_12BE_c : yuv2planeX_12LE_c;
2565  *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_12BE_c : yuv2plane1_12LE_c;
2566  } else if (desc->comp[0].depth == 14) {
2567  *yuv2planeX = isBE(dstFormat) ? yuv2planeX_14BE_c : yuv2planeX_14LE_c;
2568  *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_14BE_c : yuv2plane1_14LE_c;
2569  } else
2570  av_assert0(0);
2571  } else if (dstFormat == AV_PIX_FMT_GRAYF32BE) {
2572  *yuv2planeX = yuv2planeX_floatBE_c;
2573  *yuv2plane1 = yuv2plane1_floatBE_c;
2574  } else if (dstFormat == AV_PIX_FMT_GRAYF32LE) {
2575  *yuv2planeX = yuv2planeX_floatLE_c;
2576  *yuv2plane1 = yuv2plane1_floatLE_c;
2577  } else {
2578  *yuv2plane1 = yuv2plane1_8_c;
2579  *yuv2planeX = yuv2planeX_8_c;
2580  if (dstFormat == AV_PIX_FMT_NV12 || dstFormat == AV_PIX_FMT_NV21 ||
2581  dstFormat == AV_PIX_FMT_NV24 || dstFormat == AV_PIX_FMT_NV42)
2582  *yuv2nv12cX = yuv2nv12cX_c;
2583  }
2584 
2585  if(c->flags & SWS_FULL_CHR_H_INT) {
2586  switch (dstFormat) {
2587  case AV_PIX_FMT_RGBA:
2588 #if CONFIG_SMALL
2589  *yuv2packedX = yuv2rgba32_full_X_c;
2590  *yuv2packed2 = yuv2rgba32_full_2_c;
2591  *yuv2packed1 = yuv2rgba32_full_1_c;
2592 #else
2593 #if CONFIG_SWSCALE_ALPHA
2594  if (c->needAlpha) {
2595  *yuv2packedX = yuv2rgba32_full_X_c;
2596  *yuv2packed2 = yuv2rgba32_full_2_c;
2597  *yuv2packed1 = yuv2rgba32_full_1_c;
2598  } else
2599 #endif /* CONFIG_SWSCALE_ALPHA */
2600  {
2601  *yuv2packedX = yuv2rgbx32_full_X_c;
2602  *yuv2packed2 = yuv2rgbx32_full_2_c;
2603  *yuv2packed1 = yuv2rgbx32_full_1_c;
2604  }
2605 #endif /* !CONFIG_SMALL */
2606  break;
2607  case AV_PIX_FMT_ARGB:
2608 #if CONFIG_SMALL
2609  *yuv2packedX = yuv2argb32_full_X_c;
2610  *yuv2packed2 = yuv2argb32_full_2_c;
2611  *yuv2packed1 = yuv2argb32_full_1_c;
2612 #else
2613 #if CONFIG_SWSCALE_ALPHA
2614  if (c->needAlpha) {
2615  *yuv2packedX = yuv2argb32_full_X_c;
2616  *yuv2packed2 = yuv2argb32_full_2_c;
2617  *yuv2packed1 = yuv2argb32_full_1_c;
2618  } else
2619 #endif /* CONFIG_SWSCALE_ALPHA */
2620  {
2621  *yuv2packedX = yuv2xrgb32_full_X_c;
2622  *yuv2packed2 = yuv2xrgb32_full_2_c;
2623  *yuv2packed1 = yuv2xrgb32_full_1_c;
2624  }
2625 #endif /* !CONFIG_SMALL */
2626  break;
2627  case AV_PIX_FMT_BGRA:
2628 #if CONFIG_SMALL
2629  *yuv2packedX = yuv2bgra32_full_X_c;
2630  *yuv2packed2 = yuv2bgra32_full_2_c;
2631  *yuv2packed1 = yuv2bgra32_full_1_c;
2632 #else
2633 #if CONFIG_SWSCALE_ALPHA
2634  if (c->needAlpha) {
2635  *yuv2packedX = yuv2bgra32_full_X_c;
2636  *yuv2packed2 = yuv2bgra32_full_2_c;
2637  *yuv2packed1 = yuv2bgra32_full_1_c;
2638  } else
2639 #endif /* CONFIG_SWSCALE_ALPHA */
2640  {
2641  *yuv2packedX = yuv2bgrx32_full_X_c;
2642  *yuv2packed2 = yuv2bgrx32_full_2_c;
2643  *yuv2packed1 = yuv2bgrx32_full_1_c;
2644  }
2645 #endif /* !CONFIG_SMALL */
2646  break;
2647  case AV_PIX_FMT_ABGR:
2648 #if CONFIG_SMALL
2649  *yuv2packedX = yuv2abgr32_full_X_c;
2650  *yuv2packed2 = yuv2abgr32_full_2_c;
2651  *yuv2packed1 = yuv2abgr32_full_1_c;
2652 #else
2653 #if CONFIG_SWSCALE_ALPHA
2654  if (c->needAlpha) {
2655  *yuv2packedX = yuv2abgr32_full_X_c;
2656  *yuv2packed2 = yuv2abgr32_full_2_c;
2657  *yuv2packed1 = yuv2abgr32_full_1_c;
2658  } else
2659 #endif /* CONFIG_SWSCALE_ALPHA */
2660  {
2661  *yuv2packedX = yuv2xbgr32_full_X_c;
2662  *yuv2packed2 = yuv2xbgr32_full_2_c;
2663  *yuv2packed1 = yuv2xbgr32_full_1_c;
2664  }
2665 #endif /* !CONFIG_SMALL */
2666  break;
2667  case AV_PIX_FMT_RGBA64LE:
2668 #if CONFIG_SWSCALE_ALPHA
2669  if (c->needAlpha) {
2670  *yuv2packedX = yuv2rgba64le_full_X_c;
2671  *yuv2packed2 = yuv2rgba64le_full_2_c;
2672  *yuv2packed1 = yuv2rgba64le_full_1_c;
2673  } else
2674 #endif /* CONFIG_SWSCALE_ALPHA */
2675  {
2676  *yuv2packedX = yuv2rgbx64le_full_X_c;
2677  *yuv2packed2 = yuv2rgbx64le_full_2_c;
2678  *yuv2packed1 = yuv2rgbx64le_full_1_c;
2679  }
2680  break;
2681  case AV_PIX_FMT_RGBA64BE:
2682 #if CONFIG_SWSCALE_ALPHA
2683  if (c->needAlpha) {
2684  *yuv2packedX = yuv2rgba64be_full_X_c;
2685  *yuv2packed2 = yuv2rgba64be_full_2_c;
2686  *yuv2packed1 = yuv2rgba64be_full_1_c;
2687  } else
2688 #endif /* CONFIG_SWSCALE_ALPHA */
2689  {
2690  *yuv2packedX = yuv2rgbx64be_full_X_c;
2691  *yuv2packed2 = yuv2rgbx64be_full_2_c;
2692  *yuv2packed1 = yuv2rgbx64be_full_1_c;
2693  }
2694  break;
2695  case AV_PIX_FMT_BGRA64LE:
2696 #if CONFIG_SWSCALE_ALPHA
2697  if (c->needAlpha) {
2698  *yuv2packedX = yuv2bgra64le_full_X_c;
2699  *yuv2packed2 = yuv2bgra64le_full_2_c;
2700  *yuv2packed1 = yuv2bgra64le_full_1_c;
2701  } else
2702 #endif /* CONFIG_SWSCALE_ALPHA */
2703  {
2704  *yuv2packedX = yuv2bgrx64le_full_X_c;
2705  *yuv2packed2 = yuv2bgrx64le_full_2_c;
2706  *yuv2packed1 = yuv2bgrx64le_full_1_c;
2707  }
2708  break;
2709  case AV_PIX_FMT_BGRA64BE:
2710 #if CONFIG_SWSCALE_ALPHA
2711  if (c->needAlpha) {
2712  *yuv2packedX = yuv2bgra64be_full_X_c;
2713  *yuv2packed2 = yuv2bgra64be_full_2_c;
2714  *yuv2packed1 = yuv2bgra64be_full_1_c;
2715  } else
2716 #endif /* CONFIG_SWSCALE_ALPHA */
2717  {
2718  *yuv2packedX = yuv2bgrx64be_full_X_c;
2719  *yuv2packed2 = yuv2bgrx64be_full_2_c;
2720  *yuv2packed1 = yuv2bgrx64be_full_1_c;
2721  }
2722  break;
2723 
2724  case AV_PIX_FMT_RGB24:
2725  *yuv2packedX = yuv2rgb24_full_X_c;
2726  *yuv2packed2 = yuv2rgb24_full_2_c;
2727  *yuv2packed1 = yuv2rgb24_full_1_c;
2728  break;
2729  case AV_PIX_FMT_BGR24:
2730  *yuv2packedX = yuv2bgr24_full_X_c;
2731  *yuv2packed2 = yuv2bgr24_full_2_c;
2732  *yuv2packed1 = yuv2bgr24_full_1_c;
2733  break;
2734  case AV_PIX_FMT_RGB48LE:
2735  *yuv2packedX = yuv2rgb48le_full_X_c;
2736  *yuv2packed2 = yuv2rgb48le_full_2_c;
2737  *yuv2packed1 = yuv2rgb48le_full_1_c;
2738  break;
2739  case AV_PIX_FMT_BGR48LE:
2740  *yuv2packedX = yuv2bgr48le_full_X_c;
2741  *yuv2packed2 = yuv2bgr48le_full_2_c;
2742  *yuv2packed1 = yuv2bgr48le_full_1_c;
2743  break;
2744  case AV_PIX_FMT_RGB48BE:
2745  *yuv2packedX = yuv2rgb48be_full_X_c;
2746  *yuv2packed2 = yuv2rgb48be_full_2_c;
2747  *yuv2packed1 = yuv2rgb48be_full_1_c;
2748  break;
2749  case AV_PIX_FMT_BGR48BE:
2750  *yuv2packedX = yuv2bgr48be_full_X_c;
2751  *yuv2packed2 = yuv2bgr48be_full_2_c;
2752  *yuv2packed1 = yuv2bgr48be_full_1_c;
2753  break;
2754  case AV_PIX_FMT_BGR4_BYTE:
2755  *yuv2packedX = yuv2bgr4_byte_full_X_c;
2756  *yuv2packed2 = yuv2bgr4_byte_full_2_c;
2757  *yuv2packed1 = yuv2bgr4_byte_full_1_c;
2758  break;
2759  case AV_PIX_FMT_RGB4_BYTE:
2760  *yuv2packedX = yuv2rgb4_byte_full_X_c;
2761  *yuv2packed2 = yuv2rgb4_byte_full_2_c;
2762  *yuv2packed1 = yuv2rgb4_byte_full_1_c;
2763  break;
2764  case AV_PIX_FMT_BGR8:
2765  *yuv2packedX = yuv2bgr8_full_X_c;
2766  *yuv2packed2 = yuv2bgr8_full_2_c;
2767  *yuv2packed1 = yuv2bgr8_full_1_c;
2768  break;
2769  case AV_PIX_FMT_RGB8:
2770  *yuv2packedX = yuv2rgb8_full_X_c;
2771  *yuv2packed2 = yuv2rgb8_full_2_c;
2772  *yuv2packed1 = yuv2rgb8_full_1_c;
2773  break;
2774  case AV_PIX_FMT_GBRP:
2775  case AV_PIX_FMT_GBRP9BE:
2776  case AV_PIX_FMT_GBRP9LE:
2777  case AV_PIX_FMT_GBRP10BE:
2778  case AV_PIX_FMT_GBRP10LE:
2779  case AV_PIX_FMT_GBRP12BE:
2780  case AV_PIX_FMT_GBRP12LE:
2781  case AV_PIX_FMT_GBRP14BE:
2782  case AV_PIX_FMT_GBRP14LE:
2783  case AV_PIX_FMT_GBRAP:
2784  case AV_PIX_FMT_GBRAP10BE:
2785  case AV_PIX_FMT_GBRAP10LE:
2786  case AV_PIX_FMT_GBRAP12BE:
2787  case AV_PIX_FMT_GBRAP12LE:
2788  *yuv2anyX = yuv2gbrp_full_X_c;
2789  break;
2790  case AV_PIX_FMT_GBRP16BE:
2791  case AV_PIX_FMT_GBRP16LE:
2792  case AV_PIX_FMT_GBRAP16BE:
2793  case AV_PIX_FMT_GBRAP16LE:
2794  *yuv2anyX = yuv2gbrp16_full_X_c;
2795  break;
2796  case AV_PIX_FMT_GBRPF32BE:
2797  case AV_PIX_FMT_GBRPF32LE:
2798  case AV_PIX_FMT_GBRAPF32BE:
2799  case AV_PIX_FMT_GBRAPF32LE:
2800  *yuv2anyX = yuv2gbrpf32_full_X_c;
2801  break;
2802  }
2803  if (!*yuv2packedX && !*yuv2anyX)
2804  goto YUV_PACKED;
2805  } else {
2806  YUV_PACKED:
2807  switch (dstFormat) {
2808  case AV_PIX_FMT_RGBA64LE:
2809 #if CONFIG_SWSCALE_ALPHA
2810  if (c->needAlpha) {
2811  *yuv2packed1 = yuv2rgba64le_1_c;
2812  *yuv2packed2 = yuv2rgba64le_2_c;
2813  *yuv2packedX = yuv2rgba64le_X_c;
2814  } else
2815 #endif /* CONFIG_SWSCALE_ALPHA */
2816  {
2817  *yuv2packed1 = yuv2rgbx64le_1_c;
2818  *yuv2packed2 = yuv2rgbx64le_2_c;
2819  *yuv2packedX = yuv2rgbx64le_X_c;
2820  }
2821  break;
2822  case AV_PIX_FMT_RGBA64BE:
2823 #if CONFIG_SWSCALE_ALPHA
2824  if (c->needAlpha) {
2825  *yuv2packed1 = yuv2rgba64be_1_c;
2826  *yuv2packed2 = yuv2rgba64be_2_c;
2827  *yuv2packedX = yuv2rgba64be_X_c;
2828  } else
2829 #endif /* CONFIG_SWSCALE_ALPHA */
2830  {
2831  *yuv2packed1 = yuv2rgbx64be_1_c;
2832  *yuv2packed2 = yuv2rgbx64be_2_c;
2833  *yuv2packedX = yuv2rgbx64be_X_c;
2834  }
2835  break;
2836  case AV_PIX_FMT_BGRA64LE:
2837 #if CONFIG_SWSCALE_ALPHA
2838  if (c->needAlpha) {
2839  *yuv2packed1 = yuv2bgra64le_1_c;
2840  *yuv2packed2 = yuv2bgra64le_2_c;
2841  *yuv2packedX = yuv2bgra64le_X_c;
2842  } else
2843 #endif /* CONFIG_SWSCALE_ALPHA */
2844  {
2845  *yuv2packed1 = yuv2bgrx64le_1_c;
2846  *yuv2packed2 = yuv2bgrx64le_2_c;
2847  *yuv2packedX = yuv2bgrx64le_X_c;
2848  }
2849  break;
2850  case AV_PIX_FMT_BGRA64BE:
2851 #if CONFIG_SWSCALE_ALPHA
2852  if (c->needAlpha) {
2853  *yuv2packed1 = yuv2bgra64be_1_c;
2854  *yuv2packed2 = yuv2bgra64be_2_c;
2855  *yuv2packedX = yuv2bgra64be_X_c;
2856  } else
2857 #endif /* CONFIG_SWSCALE_ALPHA */
2858  {
2859  *yuv2packed1 = yuv2bgrx64be_1_c;
2860  *yuv2packed2 = yuv2bgrx64be_2_c;
2861  *yuv2packedX = yuv2bgrx64be_X_c;
2862  }
2863  break;
2864  case AV_PIX_FMT_RGB48LE:
2865  *yuv2packed1 = yuv2rgb48le_1_c;
2866  *yuv2packed2 = yuv2rgb48le_2_c;
2867  *yuv2packedX = yuv2rgb48le_X_c;
2868  break;
2869  case AV_PIX_FMT_RGB48BE:
2870  *yuv2packed1 = yuv2rgb48be_1_c;
2871  *yuv2packed2 = yuv2rgb48be_2_c;
2872  *yuv2packedX = yuv2rgb48be_X_c;
2873  break;
2874  case AV_PIX_FMT_BGR48LE:
2875  *yuv2packed1 = yuv2bgr48le_1_c;
2876  *yuv2packed2 = yuv2bgr48le_2_c;
2877  *yuv2packedX = yuv2bgr48le_X_c;
2878  break;
2879  case AV_PIX_FMT_BGR48BE:
2880  *yuv2packed1 = yuv2bgr48be_1_c;
2881  *yuv2packed2 = yuv2bgr48be_2_c;
2882  *yuv2packedX = yuv2bgr48be_X_c;
2883  break;
2884  case AV_PIX_FMT_RGB32:
2885  case AV_PIX_FMT_BGR32:
2886 #if CONFIG_SMALL
2887  *yuv2packed1 = yuv2rgb32_1_c;
2888  *yuv2packed2 = yuv2rgb32_2_c;
2889  *yuv2packedX = yuv2rgb32_X_c;
2890 #else
2891 #if CONFIG_SWSCALE_ALPHA
2892  if (c->needAlpha) {
2893  *yuv2packed1 = yuv2rgba32_1_c;
2894  *yuv2packed2 = yuv2rgba32_2_c;
2895  *yuv2packedX = yuv2rgba32_X_c;
2896  } else
2897 #endif /* CONFIG_SWSCALE_ALPHA */
2898  {
2899  *yuv2packed1 = yuv2rgbx32_1_c;
2900  *yuv2packed2 = yuv2rgbx32_2_c;
2901  *yuv2packedX = yuv2rgbx32_X_c;
2902  }
2903 #endif /* !CONFIG_SMALL */
2904  break;
2905  case AV_PIX_FMT_RGB32_1:
2906  case AV_PIX_FMT_BGR32_1:
2907 #if CONFIG_SMALL
2908  *yuv2packed1 = yuv2rgb32_1_1_c;
2909  *yuv2packed2 = yuv2rgb32_1_2_c;
2910  *yuv2packedX = yuv2rgb32_1_X_c;
2911 #else
2912 #if CONFIG_SWSCALE_ALPHA
2913  if (c->needAlpha) {
2914  *yuv2packed1 = yuv2rgba32_1_1_c;
2915  *yuv2packed2 = yuv2rgba32_1_2_c;
2916  *yuv2packedX = yuv2rgba32_1_X_c;
2917  } else
2918 #endif /* CONFIG_SWSCALE_ALPHA */
2919  {
2920  *yuv2packed1 = yuv2rgbx32_1_1_c;
2921  *yuv2packed2 = yuv2rgbx32_1_2_c;
2922  *yuv2packedX = yuv2rgbx32_1_X_c;
2923  }
2924 #endif /* !CONFIG_SMALL */
2925  break;
2926  case AV_PIX_FMT_RGB24:
2927  *yuv2packed1 = yuv2rgb24_1_c;
2928  *yuv2packed2 = yuv2rgb24_2_c;
2929  *yuv2packedX = yuv2rgb24_X_c;
2930  break;
2931  case AV_PIX_FMT_BGR24:
2932  *yuv2packed1 = yuv2bgr24_1_c;
2933  *yuv2packed2 = yuv2bgr24_2_c;
2934  *yuv2packedX = yuv2bgr24_X_c;
2935  break;
2936  case AV_PIX_FMT_RGB565LE:
2937  case AV_PIX_FMT_RGB565BE:
2938  case AV_PIX_FMT_BGR565LE:
2939  case AV_PIX_FMT_BGR565BE:
2940  *yuv2packed1 = yuv2rgb16_1_c;
2941  *yuv2packed2 = yuv2rgb16_2_c;
2942  *yuv2packedX = yuv2rgb16_X_c;
2943  break;
2944  case AV_PIX_FMT_RGB555LE:
2945  case AV_PIX_FMT_RGB555BE:
2946  case AV_PIX_FMT_BGR555LE:
2947  case AV_PIX_FMT_BGR555BE:
2948  *yuv2packed1 = yuv2rgb15_1_c;
2949  *yuv2packed2 = yuv2rgb15_2_c;
2950  *yuv2packedX = yuv2rgb15_X_c;
2951  break;
2952  case AV_PIX_FMT_RGB444LE:
2953  case AV_PIX_FMT_RGB444BE:
2954  case AV_PIX_FMT_BGR444LE:
2955  case AV_PIX_FMT_BGR444BE:
2956  *yuv2packed1 = yuv2rgb12_1_c;
2957  *yuv2packed2 = yuv2rgb12_2_c;
2958  *yuv2packedX = yuv2rgb12_X_c;
2959  break;
2960  case AV_PIX_FMT_RGB8:
2961  case AV_PIX_FMT_BGR8:
2962  *yuv2packed1 = yuv2rgb8_1_c;
2963  *yuv2packed2 = yuv2rgb8_2_c;
2964  *yuv2packedX = yuv2rgb8_X_c;
2965  break;
2966  case AV_PIX_FMT_RGB4:
2967  case AV_PIX_FMT_BGR4:
2968  *yuv2packed1 = yuv2rgb4_1_c;
2969  *yuv2packed2 = yuv2rgb4_2_c;
2970  *yuv2packedX = yuv2rgb4_X_c;
2971  break;
2972  case AV_PIX_FMT_RGB4_BYTE:
2973  case AV_PIX_FMT_BGR4_BYTE:
2974  *yuv2packed1 = yuv2rgb4b_1_c;
2975  *yuv2packed2 = yuv2rgb4b_2_c;
2976  *yuv2packedX = yuv2rgb4b_X_c;
2977  break;
2978  }
2979  }
2980  switch (dstFormat) {
2981  case AV_PIX_FMT_MONOWHITE:
2982  *yuv2packed1 = yuv2monowhite_1_c;
2983  *yuv2packed2 = yuv2monowhite_2_c;
2984  *yuv2packedX = yuv2monowhite_X_c;
2985  break;
2986  case AV_PIX_FMT_MONOBLACK:
2987  *yuv2packed1 = yuv2monoblack_1_c;
2988  *yuv2packed2 = yuv2monoblack_2_c;
2989  *yuv2packedX = yuv2monoblack_X_c;
2990  break;
2991  case AV_PIX_FMT_YUYV422:
2992  *yuv2packed1 = yuv2yuyv422_1_c;
2993  *yuv2packed2 = yuv2yuyv422_2_c;
2994  *yuv2packedX = yuv2yuyv422_X_c;
2995  break;
2996  case AV_PIX_FMT_YVYU422:
2997  *yuv2packed1 = yuv2yvyu422_1_c;
2998  *yuv2packed2 = yuv2yvyu422_2_c;
2999  *yuv2packedX = yuv2yvyu422_X_c;
3000  break;
3001  case AV_PIX_FMT_UYVY422:
3002  *yuv2packed1 = yuv2uyvy422_1_c;
3003  *yuv2packed2 = yuv2uyvy422_2_c;
3004  *yuv2packedX = yuv2uyvy422_X_c;
3005  break;
3006  case AV_PIX_FMT_YA8:
3007  *yuv2packed1 = yuv2ya8_1_c;
3008  *yuv2packed2 = yuv2ya8_2_c;
3009  *yuv2packedX = yuv2ya8_X_c;
3010  break;
3011  case AV_PIX_FMT_YA16LE:
3012  *yuv2packed1 = yuv2ya16le_1_c;
3013  *yuv2packed2 = yuv2ya16le_2_c;
3014  *yuv2packedX = yuv2ya16le_X_c;
3015  break;
3016  case AV_PIX_FMT_YA16BE:
3017  *yuv2packed1 = yuv2ya16be_1_c;
3018  *yuv2packed2 = yuv2ya16be_2_c;
3019  *yuv2packedX = yuv2ya16be_X_c;
3020  break;
3021  case AV_PIX_FMT_AYUV64LE:
3022  *yuv2packedX = yuv2ayuv64le_X_c;
3023  break;
3024  }
3025 }
packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
Definition: pixfmt.h:81
IEEE-754 single precision Y, 32bpp, big-endian.
Definition: pixfmt.h:340
planar GBR 4:4:4:4 40bpp, little-endian
Definition: pixfmt.h:291
#define NULL
Definition: coverity.c:32
static av_always_inline void yuv2rgb_1_c_template(SwsContext *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:1734
static void yuv2ayuv64le_X_c(SwsContext *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:2486
av_cold void ff_sws_init_output_funcs(SwsContext *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:2534
static void yuv2gbrp16_full_X_c(SwsContext *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:2242
static int shift(int a, int b)
Definition: sonic.c:82
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2549
#define YUVRGB_TABLE_HEADROOM
#define X_DITHER(u, v)
static void yuv2p010lX_BE_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:524
8 bits gray, 8 bits alpha
Definition: pixfmt.h:143
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:208
#define A1
Definition: binkdsp.c:31
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:68
packed RGB 1:2:1 bitstream, 4bpp, (msb)1B 2G 1R(lsb), a byte contains two pixels, the first pixel in ...
Definition: pixfmt.h:84
const char * g
Definition: vf_curves.c:115
const char * desc
Definition: nvenc.c:79
#define accumulate_bit(acc, val)
Definition: output.c:534
int acc
Definition: yuv2rgb.c:555
static void yuv2rgb(uint8_t *out, int ridx, int Y, int U, int V)
Definition: g2meet.c:281
const uint8_t ff_dither_2x2_8[][8]
Definition: output.c:45
static av_always_inline void yuv2rgb_full_1_c_template(SwsContext *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:2079
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:168
packed RGB 5:5:5, 16bpp, (msb)1X 5R 5G 5B(lsb), little-endian, X=unused/undefined ...
Definition: pixfmt.h:108
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:207
const char * b
Definition: vf_curves.c:116
static void yuv2p010l1_LE_c(const int16_t *src, uint8_t *dest, int dstW, const uint8_t *dither, int offset)
Definition: output.c:503
uint8_t * table_bU[256+2 *YUVRGB_TABLE_HEADROOM]
#define av_bswap16
Definition: bswap.h:31
static av_always_inline int is16BPS(enum AVPixelFormat pix_fmt)
Convenience header that includes libavutil&#39;s core.
packed BGR 5:6:5, 16bpp, (msb) 5B 6G 5R(lsb), little-endian
Definition: pixfmt.h:111
planar GBR 4:4:4 36bpp, little-endian
Definition: pixfmt.h:255
packed RGB 4:4:4, 16bpp, (msb)4X 4R 4G 4B(lsb), big-endian, X=unused/undefined
Definition: pixfmt.h:140
#define SUINT
#define AV_PIX_FMT_RGB444
Definition: pixfmt.h:386
planar GBR 4:4:4 36bpp, big-endian
Definition: pixfmt.h:254
const uint8_t ff_dither_8x8_220[][8]
Definition: output.c:84
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:144
#define r_b
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:158
packed RGB 1:2:1 bitstream, 4bpp, (msb)1R 2G 1B(lsb), a byte contains two pixels, the first pixel in ...
Definition: pixfmt.h:87
#define output_pixels(pos, Y1, U, Y2, V)
Definition: output.c:745
Macro definitions for various function/variable attributes.
#define b_r
packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), little-endian
Definition: pixfmt.h:106
packed RGB 1:2:1, 8bpp, (msb)1B 2G 1R(lsb)
Definition: pixfmt.h:85
const uint8_t ff_dither_8x8_32[][8]
Definition: output.c:59
planar GBRA 4:4:4:4 64bpp, big-endian
Definition: pixfmt.h:216
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
const uint8_t ff_dither_2x2_4[][8]
Definition: output.c:39
static void filter(int16_t *output, ptrdiff_t out_stride, int16_t *low, ptrdiff_t low_stride, int16_t *high, ptrdiff_t high_stride, int len, int clip)
Definition: cfhd.c:196
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:117
uint8_t
#define av_cold
Definition: attributes.h:88
#define AV_PIX_FMT_FLAG_ALPHA
The pixel format has an alpha channel.
Definition: pixdesc.h:177
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Definition: avassert.h:64
const uint8_t ff_dither_4x4_16[][8]
Definition: output.c:51
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:103
static av_always_inline void yuv2ya16_2_c_template(SwsContext *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)
Definition: output.c:934
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:205
static void yuv2ya8_2_c(SwsContext *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:2419
packed RGB 4:4:4, 16bpp, (msb)4X 4R 4G 4B(lsb), little-endian, X=unused/undefined ...
Definition: pixfmt.h:139
#define SWS_FULL_CHR_H_INT
Definition: swscale.h:79
#define u(width, name, range_min, range_max)
Definition: cbs_h2645.c:262
packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), big-endian
Definition: pixfmt.h:105
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
Definition: pixfmt.h:94
static void yuv2gbrp_full_X_c(SwsContext *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:2160
static av_always_inline void yuv2422_2_c_template(SwsContext *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:803
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
Definition: mem.h:112
planar GBR 4:4:4 48bpp, big-endian
Definition: pixfmt.h:174
void(* yuv2planar1_fn)(const int16_t *src, uint8_t *dest, int dstW, const uint8_t *dither, int offset)
Write one line of horizontally scaled data to planar output without any additional vertical scaling (...
static av_always_inline void yuv2rgb_full_2_c_template(SwsContext *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:2034
external API header
static av_always_inline void yuv2rgb_full_X_c_template(SwsContext *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:1984
enum AVPixelFormat dstFormat
Destination pixel format.
uint8_t * table_gU[256+2 *YUVRGB_TABLE_HEADROOM]
static void yuv2p010cX_c(SwsContext *c, const int16_t *chrFilter, int chrFilterSize, const int16_t **chrUSrc, const int16_t **chrVSrc, uint8_t *dest8, int chrDstW)
Definition: output.c:480
static void yuv2p010l1_c(const int16_t *src, uint16_t *dest, int dstW, int big_endian)
Definition: output.c:450
#define A(x)
Definition: vp56_arith.h:28
#define yuv2planeX_float(template, dest_type, BE_LE)
Definition: output.c:290
int * dither_error[4]
#define U(x)
Definition: vp56_arith.h:37
#define src
Definition: vp8dsp.c:254
planar GBR 4:4:4 27bpp, big-endian
Definition: pixfmt.h:170
#define A2
Definition: binkdsp.c:32
#define B_R
Definition: output.c:887
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
#define AV_PIX_FMT_BGR32_1
Definition: pixfmt.h:373
static av_always_inline void yuv2rgba64_full_1_c_template(SwsContext *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)
Definition: output.c:1358
16 bits gray, 16 bits alpha (big-endian)
Definition: pixfmt.h:212
#define R
Definition: huffyuvdsp.h:34
like NV12, with 16bpp per component, big-endian
Definition: pixfmt.h:301
static void yuv2p010l1_BE_c(const int16_t *src, uint8_t *dest, int dstW, const uint8_t *dither, int offset)
Definition: output.c:510
const uint8_t * d64
Definition: yuv2rgb.c:503
#define B
Definition: huffyuvdsp.h:32
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition: pixfmt.h:95
const char * r
Definition: vf_curves.c:114
static const uint8_t dither[8][8]
Definition: vf_fspp.c:57
static av_always_inline void yuv2rgba64_X_c_template(SwsContext *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)
Definition: output.c:992
static void yuv2p010lX_LE_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:517
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
Definition: pixfmt.h:89
simple assert() macros that are a bit more flexible than ISO C assert().
like NV12, with 16bpp per component, little-endian
Definition: pixfmt.h:300
like NV12, with 10bpp per component, data in the high bits, zeros in the low bits, big-endian
Definition: pixfmt.h:285
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:333
static const uint8_t offset[127][2]
Definition: vf_spp.c:93
static av_always_inline void yuv2plane1_float_c_template(const int32_t *src, float *dest, int dstW)
Definition: output.c:212
#define yuv2NBPS(bits, BE_LE, is_be, template_size, typeX_t)
Definition: output.c:353
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
Definition: pixfmt.h:92
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:149
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:93
static av_always_inline void yuv2mono_2_c_template(SwsContext *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:598
static av_always_inline void yuv2422_1_c_template(SwsContext *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:836
uint64_t flags
Combination of AV_PIX_FMT_FLAG_...
Definition: pixdesc.h:106
planar YUV 4:4:4, 24bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
Definition: pixfmt.h:348
as above, but U and V bytes are swapped
Definition: pixfmt.h:90
planar GBR 4:4:4:4 48bpp, big-endian
Definition: pixfmt.h:287
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:244
planar GBR 4:4:4:4 40bpp, big-endian
Definition: pixfmt.h:290
#define Y
Definition: boxblur.h:38
IEEE-754 single precision planar GBR 4:4:4, 96bpp, little-endian.
Definition: pixfmt.h:319
static void yuv2ya8_X_c(SwsContext *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:2450
packed RGB 1:2:1, 8bpp, (msb)1R 2G 1B(lsb)
Definition: pixfmt.h:88
static av_always_inline void yuv2mono_1_c_template(SwsContext *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:660
static av_always_inline void yuv2plane1_float_bswap_c_template(const int32_t *src, uint32_t *dest, int dstW)
Definition: output.c:228
static void yuv2plane1_8_c(const int16_t *src, uint8_t *dest, int dstW, const uint8_t *dither, int offset)
Definition: output.c:395
int32_t
packed YUV 4:2:2, 16bpp, Y0 Cr Y1 Cb
Definition: pixfmt.h:210
int table_gV[256+2 *YUVRGB_TABLE_HEADROOM]
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:69
uint8_t * table_rV[256+2 *YUVRGB_TABLE_HEADROOM]
like NV12, with 10bpp per component, data in the high bits, zeros in the low bits, little-endian
Definition: pixfmt.h:284
static av_always_inline void yuv2ya16_X_c_template(SwsContext *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)
Definition: output.c:896
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:148
packed BGR 5:6:5, 16bpp, (msb) 5B 6G 5R(lsb), big-endian
Definition: pixfmt.h:110
planar GBR 4:4:4:4 48bpp, little-endian
Definition: pixfmt.h:288
#define AV_PIX_FMT_BGR555
Definition: pixfmt.h:390
#define AV_PIX_FMT_BGR32
Definition: pixfmt.h:372
static av_always_inline int isBE(enum AVPixelFormat pix_fmt)
#define YUV2PACKED16WRAPPER(name, base, ext, fmt, hasAlpha, eightbytes)
Definition: output.c:1438
packed RGB 3:3:2, 8bpp, (msb)2B 3G 3R(lsb)
Definition: pixfmt.h:83
#define av_bswap32
Definition: bswap.h:33
void(* yuv2packedX_fn)(struct SwsContext *c, const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, const int16_t *chrFilter, const int16_t **chrUSrc, const int16_t **chrVSrc, int chrFilterSize, const int16_t **alpSrc, uint8_t *dest, int dstW, int y)
Write one line of horizontally scaled Y/U/V/A to packed-pixel YUV/RGB output by doing multi-point ver...
static av_always_inline void yuv2mono_X_c_template(SwsContext *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:545
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
static void yuv2ya8_1_c(SwsContext *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:2393
planar GBR 4:4:4 30bpp, big-endian
Definition: pixfmt.h:172
#define AV_PIX_FMT_RGB32
Definition: pixfmt.h:370
void(* yuv2packed1_fn)(struct SwsContext *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...
static av_always_inline void yuv2rgb_2_c_template(SwsContext *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:1694
packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
Definition: pixfmt.h:67
planar GBR 4:4:4 42bpp, little-endian
Definition: pixfmt.h:257
const uint8_t ff_dither_8x8_73[][8]
Definition: output.c:71
as above, but U and V bytes are swapped
Definition: pixfmt.h:349
IEEE-754 single precision planar GBR 4:4:4, 96bpp, big-endian.
Definition: pixfmt.h:318
static av_always_inline void yuv2422_X_c_template(SwsContext *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:764
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...
byte swapping routines
const uint8_t * d32
Definition: yuv2rgb.c:502
planar GBR 4:4:4 42bpp, big-endian
Definition: pixfmt.h:256
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:1521
packed BGR 5:5:5, 16bpp, (msb)1X 5B 5G 5R(lsb), little-endian, X=unused/undefined ...
Definition: pixfmt.h:113
#define SH(val, pdst)
static av_always_inline void yuv2rgba64_full_X_c_template(SwsContext *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)
Definition: output.c:1242
static void yuv2p010lX_c(const int16_t *filter, int filterSize, const int16_t **src, uint16_t *dest, int dstW, int big_endian)
Definition: output.c:463
static av_always_inline uint32_t av_float2int(float f)
Reinterpret a float as a 32-bit integer.
Definition: intfloat.h:50
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:264
#define YUV2RGBWRAPPER(name, base, ext, fmt, hasAlpha)
Definition: output.c:1813
#define AV_PIX_FMT_BGR565
Definition: pixfmt.h:389
const uint8_t * chrDither8
static av_always_inline void yuv2ya16_1_c_template(SwsContext *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)
Definition: output.c:966
packed RGB 5:5:5, 16bpp, (msb)1X 5R 5G 5B(lsb), big-endian , X=unused/undefined
Definition: pixfmt.h:107
packed BGR 4:4:4, 16bpp, (msb)4X 4B 4G 4R(lsb), big-endian, X=unused/undefined
Definition: pixfmt.h:142
SwsDither dither
#define A_DITHER(u, v)
static void yuv2gbrpf32_full_X_c(SwsContext *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:2317
Y , 1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb...
Definition: pixfmt.h:76
int
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)
#define CONFIG_SWSCALE_ALPHA
Definition: config.h:558
if(ret< 0)
Definition: vf_mcdeint.c:279
Y , 1bpp, 0 is white, 1 is black, in each byte pixels are ordered from the msb to the lsb...
Definition: pixfmt.h:75
#define G
Definition: huffyuvdsp.h:33
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:215
static av_always_inline void yuv2rgb_X_c_template(SwsContext *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:1640
IEEE-754 single precision planar GBRA 4:4:4:4, 128bpp, little-endian.
Definition: pixfmt.h:321
planar GBR 4:4:4 27bpp, little-endian
Definition: pixfmt.h:171
static double c[64]
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:102
#define AV_PIX_FMT_BGR444
Definition: pixfmt.h:391
#define AV_WL16(p, v)
Definition: intreadwrite.h:412
void(* yuv2packed2_fn)(struct SwsContext *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...
#define output_pixel(pos, val, bias, signedness)
Definition: output.c:888
const uint8_t * d128
Definition: yuv2rgb.c:554
packed RGB 3:3:2, 8bpp, (msb)2R 3G 3B(lsb)
Definition: pixfmt.h:86
#define AV_PIX_FMT_RGB555
Definition: pixfmt.h:385
static av_always_inline void yuv2rgb_write_full(SwsContext *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:1844
IEEE-754 single precision planar GBRA 4:4:4:4, 128bpp, big-endian.
Definition: pixfmt.h:320
static av_always_inline void yuv2rgba64_full_2_c_template(SwsContext *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)
Definition: output.c:1306
static av_always_inline void yuv2rgba64_1_c_template(SwsContext *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)
Definition: output.c:1139
#define AV_PIX_FMT_RGB32_1
Definition: pixfmt.h:371
void(* yuv2interleavedX_fn)(struct SwsContext *c, const int16_t *chrFilter, int chrFilterSize, const int16_t **chrUSrc, const int16_t **chrVSrc, uint8_t *dest, int dstW)
Write one line of horizontally scaled chroma to interleaved output with multi-point vertical scaling ...
static void yuv2nv12cX_c(SwsContext *c, const int16_t *chrFilter, int chrFilterSize, const int16_t **chrUSrc, const int16_t **chrVSrc, uint8_t *dest, int chrDstW)
Definition: output.c:405
static av_always_inline void yuv2rgba64_2_c_template(SwsContext *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)
Definition: output.c:1074
16 bits gray, 16 bits alpha (little-endian)
Definition: pixfmt.h:213
void(* yuv2anyX_fn)(struct SwsContext *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...
#define AV_PIX_FMT_RGB565
Definition: pixfmt.h:384
packed BGR 5:5:5, 16bpp, (msb)1X 5B 5G 5R(lsb), big-endian , X=unused/undefined
Definition: pixfmt.h:112
#define R_B
Definition: output.c:886
#define av_always_inline
Definition: attributes.h:45
planar GBR 4:4:4 48bpp, little-endian
Definition: pixfmt.h:175
packed BGR 4:4:4, 16bpp, (msb)4X 4B 4G 4R(lsb), little-endian, X=unused/undefined ...
Definition: pixfmt.h:141
#define HAVE_BIGENDIAN
Definition: config.h:199
#define yuv2plane1_float(template, dest_type, BE_LE)
Definition: output.c:283
static void yuv2p016cX_c(SwsContext *c, const int16_t *chrFilter, int chrFilterSize, const int16_t **chrUSrc, const int16_t **chrVSrc, uint8_t *dest8, int chrDstW)
Definition: output.c:183
int depth
Number of bits in the component.
Definition: pixdesc.h:58
IEEE-754 single precision Y, 32bpp, little-endian.
Definition: pixfmt.h:341
planar GBRA 4:4:4:4 64bpp, little-endian
Definition: pixfmt.h:217
#define YUV2PACKEDWRAPPER(name, base, ext, fmt)
Definition: output.c:710
int flags
Flags passed by the user to select scaler algorithm, optimizations, subsampling, etc...
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
static double val(void *priv, double ch)
Definition: aeval.c:76
static av_always_inline int isNBPS(enum AVPixelFormat pix_fmt)
planar GBR 4:4:4 30bpp, little-endian
Definition: pixfmt.h:173
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:206
packed AYUV 4:4:4,64bpp (1 Cr & Cb sample per 1x1 Y & A samples), little-endian
Definition: pixfmt.h:279
#define V
Definition: avdct.c:30