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