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