FFmpeg
output.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2001-2012 Michael Niedermayer <michaelni@gmx.at>
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include <math.h>
22 #include <stdint.h>
23 #include <stdio.h>
24 #include <string.h>
25 
26 #include "libavutil/attributes.h"
27 #include "libavutil/avutil.h"
28 #include "libavutil/avassert.h"
29 #include "libavutil/bswap.h"
30 #include "libavutil/intreadwrite.h"
31 #include "libavutil/mathematics.h"
32 #include "libavutil/mem_internal.h"
33 #include "libavutil/pixdesc.h"
34 #include "config.h"
35 #include "rgb2rgb.h"
36 #include "swscale.h"
37 #include "swscale_internal.h"
38 
39 DECLARE_ALIGNED(8, const uint8_t, ff_dither_2x2_4)[][8] = {
40 { 1, 3, 1, 3, 1, 3, 1, 3, },
41 { 2, 0, 2, 0, 2, 0, 2, 0, },
42 { 1, 3, 1, 3, 1, 3, 1, 3, },
43 };
44 
45 DECLARE_ALIGNED(8, const uint8_t, ff_dither_2x2_8)[][8] = {
46 { 6, 2, 6, 2, 6, 2, 6, 2, },
47 { 0, 4, 0, 4, 0, 4, 0, 4, },
48 { 6, 2, 6, 2, 6, 2, 6, 2, },
49 };
50 
51 DECLARE_ALIGNED(8, const uint8_t, ff_dither_4x4_16)[][8] = {
52 { 8, 4, 11, 7, 8, 4, 11, 7, },
53 { 2, 14, 1, 13, 2, 14, 1, 13, },
54 { 10, 6, 9, 5, 10, 6, 9, 5, },
55 { 0, 12, 3, 15, 0, 12, 3, 15, },
56 { 8, 4, 11, 7, 8, 4, 11, 7, },
57 };
58 
59 DECLARE_ALIGNED(8, const uint8_t, ff_dither_8x8_32)[][8] = {
60 { 17, 9, 23, 15, 16, 8, 22, 14, },
61 { 5, 29, 3, 27, 4, 28, 2, 26, },
62 { 21, 13, 19, 11, 20, 12, 18, 10, },
63 { 0, 24, 6, 30, 1, 25, 7, 31, },
64 { 16, 8, 22, 14, 17, 9, 23, 15, },
65 { 4, 28, 2, 26, 5, 29, 3, 27, },
66 { 20, 12, 18, 10, 21, 13, 19, 11, },
67 { 1, 25, 7, 31, 0, 24, 6, 30, },
68 { 17, 9, 23, 15, 16, 8, 22, 14, },
69 };
70 
71 DECLARE_ALIGNED(8, const uint8_t, ff_dither_8x8_73)[][8] = {
72 { 0, 55, 14, 68, 3, 58, 17, 72, },
73 { 37, 18, 50, 32, 40, 22, 54, 35, },
74 { 9, 64, 5, 59, 13, 67, 8, 63, },
75 { 46, 27, 41, 23, 49, 31, 44, 26, },
76 { 2, 57, 16, 71, 1, 56, 15, 70, },
77 { 39, 21, 52, 34, 38, 19, 51, 33, },
78 { 11, 66, 7, 62, 10, 65, 6, 60, },
79 { 48, 30, 43, 25, 47, 29, 42, 24, },
80 { 0, 55, 14, 68, 3, 58, 17, 72, },
81 };
82 
83 #if 1
84 DECLARE_ALIGNED(8, const uint8_t, ff_dither_8x8_220)[][8] = {
85 {117, 62, 158, 103, 113, 58, 155, 100, },
86 { 34, 199, 21, 186, 31, 196, 17, 182, },
87 {144, 89, 131, 76, 141, 86, 127, 72, },
88 { 0, 165, 41, 206, 10, 175, 52, 217, },
89 {110, 55, 151, 96, 120, 65, 162, 107, },
90 { 28, 193, 14, 179, 38, 203, 24, 189, },
91 {138, 83, 124, 69, 148, 93, 134, 79, },
92 { 7, 172, 48, 213, 3, 168, 45, 210, },
93 {117, 62, 158, 103, 113, 58, 155, 100, },
94 };
95 #elif 1
96 // tries to correct a gamma of 1.5
97 DECLARE_ALIGNED(8, const uint8_t, ff_dither_8x8_220)[][8] = {
98 { 0, 143, 18, 200, 2, 156, 25, 215, },
99 { 78, 28, 125, 64, 89, 36, 138, 74, },
100 { 10, 180, 3, 161, 16, 195, 8, 175, },
101 {109, 51, 93, 38, 121, 60, 105, 47, },
102 { 1, 152, 23, 210, 0, 147, 20, 205, },
103 { 85, 33, 134, 71, 81, 30, 130, 67, },
104 { 14, 190, 6, 171, 12, 185, 5, 166, },
105 {117, 57, 101, 44, 113, 54, 97, 41, },
106 { 0, 143, 18, 200, 2, 156, 25, 215, },
107 };
108 #elif 1
109 // tries to correct a gamma of 2.0
110 DECLARE_ALIGNED(8, const uint8_t, ff_dither_8x8_220)[][8] = {
111 { 0, 124, 8, 193, 0, 140, 12, 213, },
112 { 55, 14, 104, 42, 66, 19, 119, 52, },
113 { 3, 168, 1, 145, 6, 187, 3, 162, },
114 { 86, 31, 70, 21, 99, 39, 82, 28, },
115 { 0, 134, 11, 206, 0, 129, 9, 200, },
116 { 62, 17, 114, 48, 58, 16, 109, 45, },
117 { 5, 181, 2, 157, 4, 175, 1, 151, },
118 { 95, 36, 78, 26, 90, 34, 74, 24, },
119 { 0, 124, 8, 193, 0, 140, 12, 213, },
120 };
121 #else
122 // tries to correct a gamma of 2.5
123 DECLARE_ALIGNED(8, const uint8_t, ff_dither_8x8_220)[][8] = {
124 { 0, 107, 3, 187, 0, 125, 6, 212, },
125 { 39, 7, 86, 28, 49, 11, 102, 36, },
126 { 1, 158, 0, 131, 3, 180, 1, 151, },
127 { 68, 19, 52, 12, 81, 25, 64, 17, },
128 { 0, 119, 5, 203, 0, 113, 4, 195, },
129 { 45, 9, 96, 33, 42, 8, 91, 30, },
130 { 2, 172, 1, 144, 2, 165, 0, 137, },
131 { 77, 23, 60, 15, 72, 21, 56, 14, },
132 { 0, 107, 3, 187, 0, 125, 6, 212, },
133 };
134 #endif
135 
136 #define output_pixel(pos, val, bias, signedness) \
137  if (big_endian) { \
138  AV_WB16(pos, bias + av_clip_ ## signedness ## 16(val >> shift)); \
139  } else { \
140  AV_WL16(pos, bias + av_clip_ ## signedness ## 16(val >> shift)); \
141  }
142 
143 static av_always_inline void
144 yuv2plane1_16_c_template(const int32_t *src, uint16_t *dest, int dstW,
145  int big_endian, int output_bits)
146 {
147  int i;
148  int shift = 3;
149  av_assert0(output_bits == 16);
150 
151  for (i = 0; i < dstW; i++) {
152  int val = src[i] + (1 << (shift - 1));
153  output_pixel(&dest[i], val, 0, uint);
154  }
155 }
156 
157 static av_always_inline void
158 yuv2planeX_16_c_template(const int16_t *filter, int filterSize,
159  const int32_t **src, uint16_t *dest, int dstW,
160  int big_endian, int output_bits)
161 {
162  int i;
163  int shift = 15;
164  av_assert0(output_bits == 16);
165 
166  for (i = 0; i < dstW; i++) {
167  int val = 1 << (shift - 1);
168  int j;
169 
170  /* range of val is [0,0x7FFFFFFF], so 31 bits, but with lanczos/spline
171  * filters (or anything with negative coeffs, the range can be slightly
172  * wider in both directions. To account for this overflow, we subtract
173  * a constant so it always fits in the signed range (assuming a
174  * reasonable filterSize), and re-add that at the end. */
175  val -= 0x40000000;
176  for (j = 0; j < filterSize; j++)
177  val += src[j][i] * (unsigned)filter[j];
178 
179  output_pixel(&dest[i], val, 0x8000, int);
180  }
181 }
182 
183 static void yuv2p016cX_c(enum AVPixelFormat dstFormat, const uint8_t *chrDither,
184  const int16_t *chrFilter, int chrFilterSize,
185  const int16_t **chrUSrc, const int16_t **chrVSrc,
186  uint8_t *dest8, int chrDstW)
187 {
188  uint16_t *dest = (uint16_t*)dest8;
189  const int32_t **uSrc = (const int32_t **)chrUSrc;
190  const int32_t **vSrc = (const int32_t **)chrVSrc;
191  int shift = 15;
192  int big_endian = dstFormat == AV_PIX_FMT_P016BE;
193  int i, j;
194 
195  for (i = 0; i < chrDstW; i++) {
196  int u = 1 << (shift - 1);
197  int v = 1 << (shift - 1);
198 
199  /* See yuv2planeX_16_c_template for details. */
200  u -= 0x40000000;
201  v -= 0x40000000;
202  for (j = 0; j < chrFilterSize; j++) {
203  u += uSrc[j][i] * (unsigned)chrFilter[j];
204  v += vSrc[j][i] * (unsigned)chrFilter[j];
205  }
206 
207  output_pixel(&dest[2*i] , u, 0x8000, int);
208  output_pixel(&dest[2*i+1], v, 0x8000, int);
209  }
210 }
211 
212 static av_always_inline void
213 yuv2plane1_float_c_template(const int32_t *src, float *dest, int dstW)
214 {
215  static const int big_endian = HAVE_BIGENDIAN;
216  static const int shift = 3;
217  static const float float_mult = 1.0f / 65535.0f;
218  int i, val;
219  uint16_t val_uint;
220 
221  for (i = 0; i < dstW; ++i){
222  val = src[i] + (1 << (shift - 1));
223  output_pixel(&val_uint, val, 0, uint);
224  dest[i] = float_mult * (float)val_uint;
225  }
226 }
227 
228 static av_always_inline void
229 yuv2plane1_float_bswap_c_template(const int32_t *src, uint32_t *dest, int dstW)
230 {
231  static const int big_endian = HAVE_BIGENDIAN;
232  static const int shift = 3;
233  static const float float_mult = 1.0f / 65535.0f;
234  int i, val;
235  uint16_t val_uint;
236 
237  for (i = 0; i < dstW; ++i){
238  val = src[i] + (1 << (shift - 1));
239  output_pixel(&val_uint, val, 0, uint);
240  dest[i] = av_bswap32(av_float2int(float_mult * (float)val_uint));
241  }
242 }
243 
244 static av_always_inline void
245 yuv2planeX_float_c_template(const int16_t *filter, int filterSize, const int32_t **src,
246  float *dest, int dstW)
247 {
248  static const int big_endian = HAVE_BIGENDIAN;
249  static const int shift = 15;
250  static const float float_mult = 1.0f / 65535.0f;
251  int i, j, val;
252  uint16_t val_uint;
253 
254  for (i = 0; i < dstW; ++i){
255  val = (1 << (shift - 1)) - 0x40000000;
256  for (j = 0; j < filterSize; ++j){
257  val += src[j][i] * (unsigned)filter[j];
258  }
259  output_pixel(&val_uint, val, 0x8000, int);
260  dest[i] = float_mult * (float)val_uint;
261  }
262 }
263 
264 static av_always_inline void
265 yuv2planeX_float_bswap_c_template(const int16_t *filter, int filterSize, const int32_t **src,
266  uint32_t *dest, int dstW)
267 {
268  static const int big_endian = HAVE_BIGENDIAN;
269  static const int shift = 15;
270  static const float float_mult = 1.0f / 65535.0f;
271  int i, j, val;
272  uint16_t val_uint;
273 
274  for (i = 0; i < dstW; ++i){
275  val = (1 << (shift - 1)) - 0x40000000;
276  for (j = 0; j < filterSize; ++j){
277  val += src[j][i] * (unsigned)filter[j];
278  }
279  output_pixel(&val_uint, val, 0x8000, int);
280  dest[i] = av_bswap32(av_float2int(float_mult * (float)val_uint));
281  }
282 }
283 
284 #define yuv2plane1_float(template, dest_type, BE_LE) \
285 static void yuv2plane1_float ## BE_LE ## _c(const int16_t *src, uint8_t *dest, int dstW, \
286  const uint8_t *dither, int offset) \
287 { \
288  template((const int32_t *)src, (dest_type *)dest, dstW); \
289 }
290 
291 #define yuv2planeX_float(template, dest_type, BE_LE) \
292 static void yuv2planeX_float ## BE_LE ## _c(const int16_t *filter, int filterSize, \
293  const int16_t **src, uint8_t *dest, int dstW, \
294  const uint8_t *dither, int offset) \
295 { \
296  template(filter, filterSize, (const int32_t **)src, (dest_type *)dest, dstW); \
297 }
298 
299 #if HAVE_BIGENDIAN
304 #else
309 #endif
310 
311 #undef output_pixel
312 
313 #define output_pixel(pos, val) \
314  if (big_endian) { \
315  AV_WB16(pos, av_clip_uintp2(val >> shift, output_bits)); \
316  } else { \
317  AV_WL16(pos, av_clip_uintp2(val >> shift, output_bits)); \
318  }
319 
320 static av_always_inline void
321 yuv2plane1_10_c_template(const int16_t *src, uint16_t *dest, int dstW,
322  int big_endian, int output_bits)
323 {
324  int i;
325  int shift = 15 - output_bits;
326 
327  for (i = 0; i < dstW; i++) {
328  int val = src[i] + (1 << (shift - 1));
329  output_pixel(&dest[i], val);
330  }
331 }
332 
333 static av_always_inline void
334 yuv2planeX_10_c_template(const int16_t *filter, int filterSize,
335  const int16_t **src, uint16_t *dest, int dstW,
336  int big_endian, int output_bits)
337 {
338  int i;
339  int shift = 11 + 16 - output_bits;
340 
341  for (i = 0; i < dstW; i++) {
342  int val = 1 << (shift - 1);
343  int j;
344 
345  for (j = 0; j < filterSize; j++)
346  val += src[j][i] * filter[j];
347 
348  output_pixel(&dest[i], val);
349  }
350 }
351 
352 #undef output_pixel
353 
354 #define yuv2NBPS(bits, BE_LE, is_be, template_size, typeX_t) \
355 static void yuv2plane1_ ## bits ## BE_LE ## _c(const int16_t *src, \
356  uint8_t *dest, int dstW, \
357  const uint8_t *dither, int offset)\
358 { \
359  yuv2plane1_ ## template_size ## _c_template((const typeX_t *) src, \
360  (uint16_t *) dest, dstW, is_be, bits); \
361 }\
362 static void yuv2planeX_ ## bits ## BE_LE ## _c(const int16_t *filter, int filterSize, \
363  const int16_t **src, uint8_t *dest, int dstW, \
364  const uint8_t *dither, int offset)\
365 { \
366  yuv2planeX_## template_size ## _c_template(filter, \
367  filterSize, (const typeX_t **) src, \
368  (uint16_t *) dest, dstW, is_be, bits); \
369 }
370 yuv2NBPS( 9, BE, 1, 10, int16_t)
371 yuv2NBPS( 9, LE, 0, 10, int16_t)
372 yuv2NBPS(10, BE, 1, 10, int16_t)
373 yuv2NBPS(10, LE, 0, 10, int16_t)
374 yuv2NBPS(12, BE, 1, 10, int16_t)
375 yuv2NBPS(12, LE, 0, 10, int16_t)
376 yuv2NBPS(14, BE, 1, 10, int16_t)
377 yuv2NBPS(14, LE, 0, 10, int16_t)
378 yuv2NBPS(16, BE, 1, 16, int32_t)
379 yuv2NBPS(16, LE, 0, 16, int32_t)
380 
381 static void yuv2planeX_8_c(const int16_t *filter, int filterSize,
382  const int16_t **src, uint8_t *dest, int dstW,
383  const uint8_t *dither, int offset)
384 {
385  int i;
386  for (i=0; i<dstW; i++) {
387  int val = dither[(i + offset) & 7] << 12;
388  int j;
389  for (j=0; j<filterSize; j++)
390  val += src[j][i] * filter[j];
391 
392  dest[i]= av_clip_uint8(val>>19);
393  }
394 }
395 
396 static void yuv2plane1_8_c(const int16_t *src, uint8_t *dest, int dstW,
397  const uint8_t *dither, int offset)
398 {
399  int i;
400  for (i=0; i<dstW; i++) {
401  int val = (src[i] + dither[(i + offset) & 7]) >> 7;
402  dest[i]= av_clip_uint8(val);
403  }
404 }
405 
406 static void yuv2nv12cX_c(enum AVPixelFormat dstFormat, const uint8_t *chrDither,
407  const int16_t *chrFilter, int chrFilterSize,
408  const int16_t **chrUSrc, const int16_t **chrVSrc,
409  uint8_t *dest, int chrDstW)
410 {
411  int i;
412 
413  if (dstFormat == AV_PIX_FMT_NV12 ||
414  dstFormat == AV_PIX_FMT_NV24)
415  for (i=0; i<chrDstW; i++) {
416  int u = chrDither[i & 7] << 12;
417  int v = chrDither[(i + 3) & 7] << 12;
418  int j;
419  for (j=0; j<chrFilterSize; j++) {
420  u += chrUSrc[j][i] * chrFilter[j];
421  v += chrVSrc[j][i] * chrFilter[j];
422  }
423 
424  dest[2*i]= av_clip_uint8(u>>19);
425  dest[2*i+1]= av_clip_uint8(v>>19);
426  }
427  else
428  for (i=0; i<chrDstW; i++) {
429  int u = chrDither[i & 7] << 12;
430  int v = chrDither[(i + 3) & 7] << 12;
431  int j;
432  for (j=0; j<chrFilterSize; j++) {
433  u += chrUSrc[j][i] * chrFilter[j];
434  v += chrVSrc[j][i] * chrFilter[j];
435  }
436 
437  dest[2*i]= av_clip_uint8(v>>19);
438  dest[2*i+1]= av_clip_uint8(u>>19);
439  }
440 }
441 
442 
443 #define output_pixel(pos, val) \
444  if (big_endian) { \
445  AV_WB16(pos, av_clip_uintp2(val >> shift, 10) << 6); \
446  } else { \
447  AV_WL16(pos, av_clip_uintp2(val >> shift, 10) << 6); \
448  }
449 
450 static void yuv2p010l1_c(const int16_t *src,
451  uint16_t *dest, int dstW,
452  int big_endian)
453 {
454  int i;
455  int shift = 5;
456 
457  for (i = 0; i < dstW; i++) {
458  int val = src[i] + (1 << (shift - 1));
459  output_pixel(&dest[i], val);
460  }
461 }
462 
463 static void yuv2p010lX_c(const int16_t *filter, int filterSize,
464  const int16_t **src, uint16_t *dest, int dstW,
465  int big_endian)
466 {
467  int i, j;
468  int shift = 17;
469 
470  for (i = 0; i < dstW; i++) {
471  int val = 1 << (shift - 1);
472 
473  for (j = 0; j < filterSize; j++)
474  val += src[j][i] * filter[j];
475 
476  output_pixel(&dest[i], val);
477  }
478 }
479 
480 static void yuv2p010cX_c(enum AVPixelFormat dstFormat, const uint8_t *chrDither,
481  const int16_t *chrFilter, int chrFilterSize,
482  const int16_t **chrUSrc, const int16_t **chrVSrc,
483  uint8_t *dest8, int chrDstW)
484 {
485  uint16_t *dest = (uint16_t*)dest8;
486  int shift = 17;
487  int big_endian = dstFormat == AV_PIX_FMT_P010BE;
488  int i, j;
489 
490  for (i = 0; i < chrDstW; i++) {
491  int u = 1 << (shift - 1);
492  int v = 1 << (shift - 1);
493 
494  for (j = 0; j < chrFilterSize; j++) {
495  u += chrUSrc[j][i] * chrFilter[j];
496  v += chrVSrc[j][i] * chrFilter[j];
497  }
498 
499  output_pixel(&dest[2*i] , u);
500  output_pixel(&dest[2*i+1], v);
501  }
502 }
503 
504 static void yuv2p010l1_LE_c(const int16_t *src,
505  uint8_t *dest, int dstW,
506  const uint8_t *dither, int offset)
507 {
508  yuv2p010l1_c(src, (uint16_t*)dest, dstW, 0);
509 }
510 
511 static void yuv2p010l1_BE_c(const int16_t *src,
512  uint8_t *dest, int dstW,
513  const uint8_t *dither, int offset)
514 {
515  yuv2p010l1_c(src, (uint16_t*)dest, dstW, 1);
516 }
517 
518 static void yuv2p010lX_LE_c(const int16_t *filter, int filterSize,
519  const int16_t **src, uint8_t *dest, int dstW,
520  const uint8_t *dither, int offset)
521 {
522  yuv2p010lX_c(filter, filterSize, src, (uint16_t*)dest, dstW, 0);
523 }
524 
525 static void yuv2p010lX_BE_c(const int16_t *filter, int filterSize,
526  const int16_t **src, uint8_t *dest, int dstW,
527  const uint8_t *dither, int offset)
528 {
529  yuv2p010lX_c(filter, filterSize, src, (uint16_t*)dest, dstW, 1);
530 }
531 
532 #undef output_pixel
533 
534 
535 #define accumulate_bit(acc, val) \
536  acc <<= 1; \
537  acc |= (val) >= 234
538 #define output_pixel(pos, acc) \
539  if (target == AV_PIX_FMT_MONOBLACK) { \
540  pos = acc; \
541  } else { \
542  pos = ~acc; \
543  }
544 
545 static av_always_inline void
546 yuv2mono_X_c_template(SwsContext *c, const int16_t *lumFilter,
547  const int16_t **lumSrc, int lumFilterSize,
548  const int16_t *chrFilter, const int16_t **chrUSrc,
549  const int16_t **chrVSrc, int chrFilterSize,
550  const int16_t **alpSrc, uint8_t *dest, int dstW,
551  int y, enum AVPixelFormat target)
552 {
553  const uint8_t * const d128 = ff_dither_8x8_220[y&7];
554  int i;
555  unsigned acc = 0;
556  int err = 0;
557 
558  for (i = 0; i < dstW; i += 2) {
559  int j;
560  int Y1 = 1 << 18;
561  int Y2 = 1 << 18;
562 
563  for (j = 0; j < lumFilterSize; j++) {
564  Y1 += lumSrc[j][i] * lumFilter[j];
565  Y2 += lumSrc[j][i+1] * lumFilter[j];
566  }
567  Y1 >>= 19;
568  Y2 >>= 19;
569  if ((Y1 | Y2) & 0x100) {
570  Y1 = av_clip_uint8(Y1);
571  Y2 = av_clip_uint8(Y2);
572  }
573  if (c->dither == SWS_DITHER_ED) {
574  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;
575  c->dither_error[0][i] = err;
576  acc = 2*acc + (Y1 >= 128);
577  Y1 -= 220*(acc&1);
578 
579  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);
580  c->dither_error[0][i+1] = Y1;
581  acc = 2*acc + (err >= 128);
582  err -= 220*(acc&1);
583  } else {
584  accumulate_bit(acc, Y1 + d128[(i + 0) & 7]);
585  accumulate_bit(acc, Y2 + d128[(i + 1) & 7]);
586  }
587  if ((i & 7) == 6) {
588  output_pixel(*dest++, acc);
589  }
590  }
591  c->dither_error[0][i] = err;
592 
593  if (i & 6) {
594  output_pixel(*dest, acc);
595  }
596 }
597 
598 static av_always_inline void
599 yuv2mono_2_c_template(SwsContext *c, const int16_t *buf[2],
600  const int16_t *ubuf[2], const int16_t *vbuf[2],
601  const int16_t *abuf[2], uint8_t *dest, int dstW,
602  int yalpha, int uvalpha, int y,
603  enum AVPixelFormat target)
604 {
605  const int16_t *buf0 = buf[0], *buf1 = buf[1];
606  const uint8_t * const d128 = ff_dither_8x8_220[y & 7];
607  int yalpha1 = 4096 - yalpha;
608  int i;
609  av_assert2(yalpha <= 4096U);
610 
611  if (c->dither == SWS_DITHER_ED) {
612  int err = 0;
613  int acc = 0;
614  for (i = 0; i < dstW; i +=2) {
615  int Y;
616 
617  Y = (buf0[i + 0] * yalpha1 + buf1[i + 0] * yalpha) >> 19;
618  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;
619  c->dither_error[0][i] = err;
620  acc = 2*acc + (Y >= 128);
621  Y -= 220*(acc&1);
622 
623  err = (buf0[i + 1] * yalpha1 + buf1[i + 1] * yalpha) >> 19;
624  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;
625  c->dither_error[0][i+1] = Y;
626  acc = 2*acc + (err >= 128);
627  err -= 220*(acc&1);
628 
629  if ((i & 7) == 6)
630  output_pixel(*dest++, acc);
631  }
632  c->dither_error[0][i] = err;
633  } else {
634  for (i = 0; i < dstW; i += 8) {
635  int Y, acc = 0;
636 
637  Y = (buf0[i + 0] * yalpha1 + buf1[i + 0] * yalpha) >> 19;
638  accumulate_bit(acc, Y + d128[0]);
639  Y = (buf0[i + 1] * yalpha1 + buf1[i + 1] * yalpha) >> 19;
640  accumulate_bit(acc, Y + d128[1]);
641  Y = (buf0[i + 2] * yalpha1 + buf1[i + 2] * yalpha) >> 19;
642  accumulate_bit(acc, Y + d128[2]);
643  Y = (buf0[i + 3] * yalpha1 + buf1[i + 3] * yalpha) >> 19;
644  accumulate_bit(acc, Y + d128[3]);
645  Y = (buf0[i + 4] * yalpha1 + buf1[i + 4] * yalpha) >> 19;
646  accumulate_bit(acc, Y + d128[4]);
647  Y = (buf0[i + 5] * yalpha1 + buf1[i + 5] * yalpha) >> 19;
648  accumulate_bit(acc, Y + d128[5]);
649  Y = (buf0[i + 6] * yalpha1 + buf1[i + 6] * yalpha) >> 19;
650  accumulate_bit(acc, Y + d128[6]);
651  Y = (buf0[i + 7] * yalpha1 + buf1[i + 7] * yalpha) >> 19;
652  accumulate_bit(acc, Y + d128[7]);
653 
654  output_pixel(*dest++, acc);
655  }
656  }
657 }
658 
659 static av_always_inline void
660 yuv2mono_1_c_template(SwsContext *c, const int16_t *buf0,
661  const int16_t *ubuf[2], const int16_t *vbuf[2],
662  const int16_t *abuf0, uint8_t *dest, int dstW,
663  int uvalpha, int y, enum AVPixelFormat target)
664 {
665  const uint8_t * const d128 = ff_dither_8x8_220[y & 7];
666  int i;
667 
668  if (c->dither == SWS_DITHER_ED) {
669  int err = 0;
670  int acc = 0;
671  for (i = 0; i < dstW; i +=2) {
672  int Y;
673 
674  Y = ((buf0[i + 0] + 64) >> 7);
675  Y += (7*err + 1*c->dither_error[0][i] + 5*c->dither_error[0][i+1] + 3*c->dither_error[0][i+2] + 8 - 256)>>4;
676  c->dither_error[0][i] = err;
677  acc = 2*acc + (Y >= 128);
678  Y -= 220*(acc&1);
679 
680  err = ((buf0[i + 1] + 64) >> 7);
681  err += (7*Y + 1*c->dither_error[0][i+1] + 5*c->dither_error[0][i+2] + 3*c->dither_error[0][i+3] + 8 - 256)>>4;
682  c->dither_error[0][i+1] = Y;
683  acc = 2*acc + (err >= 128);
684  err -= 220*(acc&1);
685 
686  if ((i & 7) == 6)
687  output_pixel(*dest++, acc);
688  }
689  c->dither_error[0][i] = err;
690  } else {
691  for (i = 0; i < dstW; i += 8) {
692  int acc = 0;
693  accumulate_bit(acc, ((buf0[i + 0] + 64) >> 7) + d128[0]);
694  accumulate_bit(acc, ((buf0[i + 1] + 64) >> 7) + d128[1]);
695  accumulate_bit(acc, ((buf0[i + 2] + 64) >> 7) + d128[2]);
696  accumulate_bit(acc, ((buf0[i + 3] + 64) >> 7) + d128[3]);
697  accumulate_bit(acc, ((buf0[i + 4] + 64) >> 7) + d128[4]);
698  accumulate_bit(acc, ((buf0[i + 5] + 64) >> 7) + d128[5]);
699  accumulate_bit(acc, ((buf0[i + 6] + 64) >> 7) + d128[6]);
700  accumulate_bit(acc, ((buf0[i + 7] + 64) >> 7) + d128[7]);
701 
702  output_pixel(*dest++, acc);
703  }
704  }
705 }
706 
707 #undef output_pixel
708 #undef accumulate_bit
709 
710 #define YUV2PACKEDWRAPPER(name, base, ext, fmt) \
711 static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \
712  const int16_t **lumSrc, int lumFilterSize, \
713  const int16_t *chrFilter, const int16_t **chrUSrc, \
714  const int16_t **chrVSrc, int chrFilterSize, \
715  const int16_t **alpSrc, uint8_t *dest, int dstW, \
716  int y) \
717 { \
718  name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
719  chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
720  alpSrc, dest, dstW, y, fmt); \
721 } \
722  \
723 static void name ## ext ## _2_c(SwsContext *c, const int16_t *buf[2], \
724  const int16_t *ubuf[2], const int16_t *vbuf[2], \
725  const int16_t *abuf[2], uint8_t *dest, int dstW, \
726  int yalpha, int uvalpha, int y) \
727 { \
728  name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
729  dest, dstW, yalpha, uvalpha, y, fmt); \
730 } \
731  \
732 static void name ## ext ## _1_c(SwsContext *c, const int16_t *buf0, \
733  const int16_t *ubuf[2], const int16_t *vbuf[2], \
734  const int16_t *abuf0, uint8_t *dest, int dstW, \
735  int uvalpha, int y) \
736 { \
737  name ## base ## _1_c_template(c, buf0, ubuf, vbuf, \
738  abuf0, dest, dstW, uvalpha, \
739  y, fmt); \
740 }
741 
742 YUV2PACKEDWRAPPER(yuv2mono,, white, AV_PIX_FMT_MONOWHITE)
743 YUV2PACKEDWRAPPER(yuv2mono,, black, AV_PIX_FMT_MONOBLACK)
744 
745 #define output_pixels(pos, Y1, U, Y2, V) \
746  if (target == AV_PIX_FMT_YUYV422) { \
747  dest[pos + 0] = Y1; \
748  dest[pos + 1] = U; \
749  dest[pos + 2] = Y2; \
750  dest[pos + 3] = V; \
751  } else if (target == AV_PIX_FMT_YVYU422) { \
752  dest[pos + 0] = Y1; \
753  dest[pos + 1] = V; \
754  dest[pos + 2] = Y2; \
755  dest[pos + 3] = U; \
756  } else { /* AV_PIX_FMT_UYVY422 */ \
757  dest[pos + 0] = U; \
758  dest[pos + 1] = Y1; \
759  dest[pos + 2] = V; \
760  dest[pos + 3] = Y2; \
761  }
762 
763 static av_always_inline void
764 yuv2422_X_c_template(SwsContext *c, const int16_t *lumFilter,
765  const int16_t **lumSrc, int lumFilterSize,
766  const int16_t *chrFilter, const int16_t **chrUSrc,
767  const int16_t **chrVSrc, int chrFilterSize,
768  const int16_t **alpSrc, uint8_t *dest, int dstW,
769  int y, enum AVPixelFormat target)
770 {
771  int i;
772 
773  for (i = 0; i < ((dstW + 1) >> 1); i++) {
774  int j;
775  int Y1 = 1 << 18;
776  int Y2 = 1 << 18;
777  int U = 1 << 18;
778  int V = 1 << 18;
779 
780  for (j = 0; j < lumFilterSize; j++) {
781  Y1 += lumSrc[j][i * 2] * lumFilter[j];
782  Y2 += lumSrc[j][i * 2 + 1] * lumFilter[j];
783  }
784  for (j = 0; j < chrFilterSize; j++) {
785  U += chrUSrc[j][i] * chrFilter[j];
786  V += chrVSrc[j][i] * chrFilter[j];
787  }
788  Y1 >>= 19;
789  Y2 >>= 19;
790  U >>= 19;
791  V >>= 19;
792  if ((Y1 | Y2 | U | V) & 0x100) {
793  Y1 = av_clip_uint8(Y1);
794  Y2 = av_clip_uint8(Y2);
795  U = av_clip_uint8(U);
796  V = av_clip_uint8(V);
797  }
798  output_pixels(4*i, Y1, U, Y2, V);
799  }
800 }
801 
802 static av_always_inline void
803 yuv2422_2_c_template(SwsContext *c, const int16_t *buf[2],
804  const int16_t *ubuf[2], const int16_t *vbuf[2],
805  const int16_t *abuf[2], uint8_t *dest, int dstW,
806  int yalpha, int uvalpha, int y,
807  enum AVPixelFormat target)
808 {
809  const int16_t *buf0 = buf[0], *buf1 = buf[1],
810  *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
811  *vbuf0 = vbuf[0], *vbuf1 = vbuf[1];
812  int yalpha1 = 4096 - yalpha;
813  int uvalpha1 = 4096 - uvalpha;
814  int i;
815  av_assert2(yalpha <= 4096U);
816  av_assert2(uvalpha <= 4096U);
817 
818  for (i = 0; i < ((dstW + 1) >> 1); i++) {
819  int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 19;
820  int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 19;
821  int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha) >> 19;
822  int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha) >> 19;
823 
824  if ((Y1 | Y2 | U | V) & 0x100) {
825  Y1 = av_clip_uint8(Y1);
826  Y2 = av_clip_uint8(Y2);
827  U = av_clip_uint8(U);
828  V = av_clip_uint8(V);
829  }
830 
831  output_pixels(i * 4, Y1, U, Y2, V);
832  }
833 }
834 
835 static av_always_inline void
836 yuv2422_1_c_template(SwsContext *c, const int16_t *buf0,
837  const int16_t *ubuf[2], const int16_t *vbuf[2],
838  const int16_t *abuf0, uint8_t *dest, int dstW,
839  int uvalpha, int y, enum AVPixelFormat target)
840 {
841  const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
842  int i;
843 
844  if (uvalpha < 2048) {
845  for (i = 0; i < ((dstW + 1) >> 1); i++) {
846  int Y1 = (buf0[i * 2 ]+64) >> 7;
847  int Y2 = (buf0[i * 2 + 1]+64) >> 7;
848  int U = (ubuf0[i] +64) >> 7;
849  int V = (vbuf0[i] +64) >> 7;
850 
851  if ((Y1 | Y2 | U | V) & 0x100) {
852  Y1 = av_clip_uint8(Y1);
853  Y2 = av_clip_uint8(Y2);
854  U = av_clip_uint8(U);
855  V = av_clip_uint8(V);
856  }
857 
858  output_pixels(i * 4, Y1, U, Y2, V);
859  }
860  } else {
861  const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
862  for (i = 0; i < ((dstW + 1) >> 1); i++) {
863  int Y1 = (buf0[i * 2 ] + 64) >> 7;
864  int Y2 = (buf0[i * 2 + 1] + 64) >> 7;
865  int U = (ubuf0[i] + ubuf1[i]+128) >> 8;
866  int V = (vbuf0[i] + vbuf1[i]+128) >> 8;
867 
868  if ((Y1 | Y2 | U | V) & 0x100) {
869  Y1 = av_clip_uint8(Y1);
870  Y2 = av_clip_uint8(Y2);
871  U = av_clip_uint8(U);
872  V = av_clip_uint8(V);
873  }
874 
875  output_pixels(i * 4, Y1, U, Y2, V);
876  }
877  }
878 }
879 
880 #undef output_pixels
881 
882 YUV2PACKEDWRAPPER(yuv2, 422, yuyv422, AV_PIX_FMT_YUYV422)
883 YUV2PACKEDWRAPPER(yuv2, 422, yvyu422, AV_PIX_FMT_YVYU422)
884 YUV2PACKEDWRAPPER(yuv2, 422, uyvy422, AV_PIX_FMT_UYVY422)
885 
886 #define R_B ((target == AV_PIX_FMT_RGB48LE || target == AV_PIX_FMT_RGB48BE || target == AV_PIX_FMT_RGBA64LE || target == AV_PIX_FMT_RGBA64BE) ? R : B)
887 #define B_R ((target == AV_PIX_FMT_RGB48LE || target == AV_PIX_FMT_RGB48BE || target == AV_PIX_FMT_RGBA64LE || target == AV_PIX_FMT_RGBA64BE) ? B : R)
888 #define output_pixel(pos, val) \
889  if (isBE(target)) { \
890  AV_WB16(pos, val); \
891  } else { \
892  AV_WL16(pos, val); \
893  }
894 
895 static av_always_inline void
896 yuv2ya16_X_c_template(SwsContext *c, const int16_t *lumFilter,
897  const int32_t **lumSrc, int lumFilterSize,
898  const int16_t *chrFilter, const int32_t **unused_chrUSrc,
899  const int32_t **unused_chrVSrc, int unused_chrFilterSize,
900  const int32_t **alpSrc, uint16_t *dest, int dstW,
901  int y, enum AVPixelFormat target, int unused_hasAlpha, int unused_eightbytes)
902 {
903  int hasAlpha = !!alpSrc;
904  int i;
905 
906  for (i = 0; i < dstW; i++) {
907  int j;
908  int Y = -0x40000000;
909  int A = 0xffff;
910 
911  for (j = 0; j < lumFilterSize; j++)
912  Y += lumSrc[j][i] * lumFilter[j];
913 
914  Y >>= 15;
915  Y += (1<<3) + 0x8000;
916  Y = av_clip_uint16(Y);
917 
918  if (hasAlpha) {
919  A = -0x40000000 + (1<<14);
920  for (j = 0; j < lumFilterSize; j++)
921  A += alpSrc[j][i] * lumFilter[j];
922 
923  A >>= 15;
924  A += 0x8000;
925  A = av_clip_uint16(A);
926  }
927 
928  output_pixel(&dest[2 * i ], Y);
929  output_pixel(&dest[2 * i + 1], A);
930  }
931 }
932 
933 static av_always_inline void
935  const int32_t *unused_ubuf[2], const int32_t *unused_vbuf[2],
936  const int32_t *abuf[2], uint16_t *dest, int dstW,
937  int yalpha, int unused_uvalpha, int y,
938  enum AVPixelFormat target, int unused_hasAlpha, int unused_eightbytes)
939 {
940  int hasAlpha = abuf && abuf[0] && abuf[1];
941  const int32_t *buf0 = buf[0], *buf1 = buf[1],
942  *abuf0 = hasAlpha ? abuf[0] : NULL,
943  *abuf1 = hasAlpha ? abuf[1] : NULL;
944  int yalpha1 = 4096 - yalpha;
945  int i;
946 
947  av_assert2(yalpha <= 4096U);
948 
949  for (i = 0; i < dstW; i++) {
950  int Y = (buf0[i] * yalpha1 + buf1[i] * yalpha) >> 15;
951  int A;
952 
953  Y = av_clip_uint16(Y);
954 
955  if (hasAlpha) {
956  A = (abuf0[i] * yalpha1 + abuf1[i] * yalpha) >> 15;
957  A = av_clip_uint16(A);
958  }
959 
960  output_pixel(&dest[2 * i ], Y);
961  output_pixel(&dest[2 * i + 1], hasAlpha ? A : 65535);
962  }
963 }
964 
965 static av_always_inline void
967  const int32_t *unused_ubuf[2], const int32_t *unused_vbuf[2],
968  const int32_t *abuf0, uint16_t *dest, int dstW,
969  int unused_uvalpha, int y, enum AVPixelFormat target, int unused_hasAlpha, int unused_eightbytes)
970 {
971  int hasAlpha = !!abuf0;
972  int i;
973 
974  for (i = 0; i < dstW; i++) {
975  int Y = buf0[i] >> 3;/* 19 - 16 */
976  int A;
977 
978  Y = av_clip_uint16(Y);
979 
980  if (hasAlpha) {
981  A = abuf0[i] >> 3;
982  if (A & 0x100)
983  A = av_clip_uint16(A);
984  }
985 
986  output_pixel(&dest[2 * i ], Y);
987  output_pixel(&dest[2 * i + 1], hasAlpha ? A : 65535);
988  }
989 }
990 
991 static av_always_inline void
992 yuv2rgba64_X_c_template(SwsContext *c, const int16_t *lumFilter,
993  const int32_t **lumSrc, int lumFilterSize,
994  const int16_t *chrFilter, const int32_t **chrUSrc,
995  const int32_t **chrVSrc, int chrFilterSize,
996  const int32_t **alpSrc, uint16_t *dest, int dstW,
997  int y, enum AVPixelFormat target, int hasAlpha, int eightbytes)
998 {
999  int i;
1000  int A1 = 0xffff<<14, A2 = 0xffff<<14;
1001 
1002  for (i = 0; i < ((dstW + 1) >> 1); i++) {
1003  int j;
1004  int Y1 = -0x40000000;
1005  int Y2 = -0x40000000;
1006  int U = -(128 << 23); // 19
1007  int V = -(128 << 23);
1008  int R, G, B;
1009 
1010  for (j = 0; j < lumFilterSize; j++) {
1011  Y1 += lumSrc[j][i * 2] * (unsigned)lumFilter[j];
1012  Y2 += lumSrc[j][i * 2 + 1] * (unsigned)lumFilter[j];
1013  }
1014  for (j = 0; j < chrFilterSize; j++) {;
1015  U += chrUSrc[j][i] * (unsigned)chrFilter[j];
1016  V += chrVSrc[j][i] * (unsigned)chrFilter[j];
1017  }
1018 
1019  if (hasAlpha) {
1020  A1 = -0x40000000;
1021  A2 = -0x40000000;
1022  for (j = 0; j < lumFilterSize; j++) {
1023  A1 += alpSrc[j][i * 2] * (unsigned)lumFilter[j];
1024  A2 += alpSrc[j][i * 2 + 1] * (unsigned)lumFilter[j];
1025  }
1026  A1 >>= 1;
1027  A1 += 0x20002000;
1028  A2 >>= 1;
1029  A2 += 0x20002000;
1030  }
1031 
1032  // 8 bits: 12+15=27; 16 bits: 12+19=31
1033  Y1 >>= 14; // 10
1034  Y1 += 0x10000;
1035  Y2 >>= 14;
1036  Y2 += 0x10000;
1037  U >>= 14;
1038  V >>= 14;
1039 
1040  // 8 bits: 27 -> 17 bits, 16 bits: 31 - 14 = 17 bits
1041  Y1 -= c->yuv2rgb_y_offset;
1042  Y2 -= c->yuv2rgb_y_offset;
1043  Y1 *= c->yuv2rgb_y_coeff;
1044  Y2 *= c->yuv2rgb_y_coeff;
1045  Y1 += 1 << 13; // 21
1046  Y2 += 1 << 13;
1047  // 8 bits: 17 + 13 bits = 30 bits, 16 bits: 17 + 13 bits = 30 bits
1048 
1049  R = V * c->yuv2rgb_v2r_coeff;
1050  G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
1051  B = U * c->yuv2rgb_u2b_coeff;
1052 
1053  // 8 bits: 30 - 22 = 8 bits, 16 bits: 30 bits - 14 = 16 bits
1054  output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
1055  output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
1056  output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
1057  if (eightbytes) {
1058  output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14);
1059  output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >> 14);
1060  output_pixel(&dest[5], av_clip_uintp2( G + Y2, 30) >> 14);
1061  output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >> 14);
1062  output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14);
1063  dest += 8;
1064  } else {
1065  output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
1066  output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);
1067  output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
1068  dest += 6;
1069  }
1070  }
1071 }
1072 
1073 static av_always_inline void
1075  const int32_t *ubuf[2], const int32_t *vbuf[2],
1076  const int32_t *abuf[2], uint16_t *dest, int dstW,
1077  int yalpha, int uvalpha, int y,
1078  enum AVPixelFormat target, int hasAlpha, int eightbytes)
1079 {
1080  const int32_t *buf0 = buf[0], *buf1 = buf[1],
1081  *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
1082  *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
1083  *abuf0 = hasAlpha ? abuf[0] : NULL,
1084  *abuf1 = hasAlpha ? abuf[1] : NULL;
1085  int yalpha1 = 4096 - yalpha;
1086  int uvalpha1 = 4096 - uvalpha;
1087  int i;
1088  int A1 = 0xffff<<14, A2 = 0xffff<<14;
1089 
1090  av_assert2(yalpha <= 4096U);
1091  av_assert2(uvalpha <= 4096U);
1092 
1093  for (i = 0; i < ((dstW + 1) >> 1); i++) {
1094  int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 14;
1095  int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 14;
1096  int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha - (128 << 23)) >> 14;
1097  int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha - (128 << 23)) >> 14;
1098  int R, G, B;
1099 
1100  Y1 -= c->yuv2rgb_y_offset;
1101  Y2 -= c->yuv2rgb_y_offset;
1102  Y1 *= c->yuv2rgb_y_coeff;
1103  Y2 *= c->yuv2rgb_y_coeff;
1104  Y1 += 1 << 13;
1105  Y2 += 1 << 13;
1106 
1107  R = V * c->yuv2rgb_v2r_coeff;
1108  G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
1109  B = U * c->yuv2rgb_u2b_coeff;
1110 
1111  if (hasAlpha) {
1112  A1 = (abuf0[i * 2 ] * yalpha1 + abuf1[i * 2 ] * yalpha) >> 1;
1113  A2 = (abuf0[i * 2 + 1] * yalpha1 + abuf1[i * 2 + 1] * yalpha) >> 1;
1114 
1115  A1 += 1 << 13;
1116  A2 += 1 << 13;
1117  }
1118 
1119  output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
1120  output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
1121  output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
1122  if (eightbytes) {
1123  output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14);
1124  output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >> 14);
1125  output_pixel(&dest[5], av_clip_uintp2( G + Y2, 30) >> 14);
1126  output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >> 14);
1127  output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14);
1128  dest += 8;
1129  } else {
1130  output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
1131  output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);
1132  output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
1133  dest += 6;
1134  }
1135  }
1136 }
1137 
1138 static av_always_inline void
1140  const int32_t *ubuf[2], const int32_t *vbuf[2],
1141  const int32_t *abuf0, uint16_t *dest, int dstW,
1142  int uvalpha, int y, enum AVPixelFormat target, int hasAlpha, int eightbytes)
1143 {
1144  const int32_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
1145  int i;
1146  int A1 = 0xffff<<14, A2= 0xffff<<14;
1147 
1148  if (uvalpha < 2048) {
1149  for (i = 0; i < ((dstW + 1) >> 1); i++) {
1150  int Y1 = (buf0[i * 2] ) >> 2;
1151  int Y2 = (buf0[i * 2 + 1]) >> 2;
1152  int U = (ubuf0[i] - (128 << 11)) >> 2;
1153  int V = (vbuf0[i] - (128 << 11)) >> 2;
1154  int R, G, B;
1155 
1156  Y1 -= c->yuv2rgb_y_offset;
1157  Y2 -= c->yuv2rgb_y_offset;
1158  Y1 *= c->yuv2rgb_y_coeff;
1159  Y2 *= c->yuv2rgb_y_coeff;
1160  Y1 += 1 << 13;
1161  Y2 += 1 << 13;
1162 
1163  if (hasAlpha) {
1164  A1 = abuf0[i * 2 ] << 11;
1165  A2 = abuf0[i * 2 + 1] << 11;
1166 
1167  A1 += 1 << 13;
1168  A2 += 1 << 13;
1169  }
1170 
1171  R = V * c->yuv2rgb_v2r_coeff;
1172  G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
1173  B = U * c->yuv2rgb_u2b_coeff;
1174 
1175  output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
1176  output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
1177  output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
1178  if (eightbytes) {
1179  output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14);
1180  output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >> 14);
1181  output_pixel(&dest[5], av_clip_uintp2( G + Y2, 30) >> 14);
1182  output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >> 14);
1183  output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14);
1184  dest += 8;
1185  } else {
1186  output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
1187  output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);
1188  output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
1189  dest += 6;
1190  }
1191  }
1192  } else {
1193  const int32_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
1194  int A1 = 0xffff<<14, A2 = 0xffff<<14;
1195  for (i = 0; i < ((dstW + 1) >> 1); i++) {
1196  int Y1 = (buf0[i * 2] ) >> 2;
1197  int Y2 = (buf0[i * 2 + 1]) >> 2;
1198  int U = (ubuf0[i] + ubuf1[i] - (128 << 12)) >> 3;
1199  int V = (vbuf0[i] + vbuf1[i] - (128 << 12)) >> 3;
1200  int R, G, B;
1201 
1202  Y1 -= c->yuv2rgb_y_offset;
1203  Y2 -= c->yuv2rgb_y_offset;
1204  Y1 *= c->yuv2rgb_y_coeff;
1205  Y2 *= c->yuv2rgb_y_coeff;
1206  Y1 += 1 << 13;
1207  Y2 += 1 << 13;
1208 
1209  if (hasAlpha) {
1210  A1 = abuf0[i * 2 ] << 11;
1211  A2 = abuf0[i * 2 + 1] << 11;
1212 
1213  A1 += 1 << 13;
1214  A2 += 1 << 13;
1215  }
1216 
1217  R = V * c->yuv2rgb_v2r_coeff;
1218  G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
1219  B = U * c->yuv2rgb_u2b_coeff;
1220 
1221  output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
1222  output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
1223  output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
1224  if (eightbytes) {
1225  output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14);
1226  output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >> 14);
1227  output_pixel(&dest[5], av_clip_uintp2( G + Y2, 30) >> 14);
1228  output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >> 14);
1229  output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14);
1230  dest += 8;
1231  } else {
1232  output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
1233  output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);
1234  output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
1235  dest += 6;
1236  }
1237  }
1238  }
1239 }
1240 
1241 static av_always_inline void
1242 yuv2rgba64_full_X_c_template(SwsContext *c, const int16_t *lumFilter,
1243  const int32_t **lumSrc, int lumFilterSize,
1244  const int16_t *chrFilter, const int32_t **chrUSrc,
1245  const int32_t **chrVSrc, int chrFilterSize,
1246  const int32_t **alpSrc, uint16_t *dest, int dstW,
1247  int y, enum AVPixelFormat target, int hasAlpha, int eightbytes)
1248 {
1249  int i;
1250  int A = 0xffff<<14;
1251 
1252  for (i = 0; i < dstW; i++) {
1253  int j;
1254  int Y = -0x40000000;
1255  int U = -(128 << 23); // 19
1256  int V = -(128 << 23);
1257  int R, G, B;
1258 
1259  for (j = 0; j < lumFilterSize; j++) {
1260  Y += lumSrc[j][i] * (unsigned)lumFilter[j];
1261  }
1262  for (j = 0; j < chrFilterSize; j++) {;
1263  U += chrUSrc[j][i] * (unsigned)chrFilter[j];
1264  V += chrVSrc[j][i] * (unsigned)chrFilter[j];
1265  }
1266 
1267  if (hasAlpha) {
1268  A = -0x40000000;
1269  for (j = 0; j < lumFilterSize; j++) {
1270  A += alpSrc[j][i] * (unsigned)lumFilter[j];
1271  }
1272  A >>= 1;
1273  A += 0x20002000;
1274  }
1275 
1276  // 8bit: 12+15=27; 16-bit: 12+19=31
1277  Y >>= 14; // 10
1278  Y += 0x10000;
1279  U >>= 14;
1280  V >>= 14;
1281 
1282  // 8bit: 27 -> 17bit, 16bit: 31 - 14 = 17bit
1283  Y -= c->yuv2rgb_y_offset;
1284  Y *= c->yuv2rgb_y_coeff;
1285  Y += 1 << 13; // 21
1286  // 8bit: 17 + 13bit = 30bit, 16bit: 17 + 13bit = 30bit
1287 
1288  R = V * c->yuv2rgb_v2r_coeff;
1289  G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
1290  B = U * c->yuv2rgb_u2b_coeff;
1291 
1292  // 8bit: 30 - 22 = 8bit, 16bit: 30bit - 14 = 16bit
1293  output_pixel(&dest[0], av_clip_uintp2(R_B + Y, 30) >> 14);
1294  output_pixel(&dest[1], av_clip_uintp2( G + Y, 30) >> 14);
1295  output_pixel(&dest[2], av_clip_uintp2(B_R + Y, 30) >> 14);
1296  if (eightbytes) {
1297  output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
1298  dest += 4;
1299  } else {
1300  dest += 3;
1301  }
1302  }
1303 }
1304 
1305 static av_always_inline void
1307  const int32_t *ubuf[2], const int32_t *vbuf[2],
1308  const int32_t *abuf[2], uint16_t *dest, int dstW,
1309  int yalpha, int uvalpha, int y,
1310  enum AVPixelFormat target, int hasAlpha, int eightbytes)
1311 {
1312  const int32_t *buf0 = buf[0], *buf1 = buf[1],
1313  *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
1314  *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
1315  *abuf0 = hasAlpha ? abuf[0] : NULL,
1316  *abuf1 = hasAlpha ? abuf[1] : NULL;
1317  int yalpha1 = 4096 - yalpha;
1318  int uvalpha1 = 4096 - uvalpha;
1319  int i;
1320  int A = 0xffff<<14;
1321 
1322  av_assert2(yalpha <= 4096U);
1323  av_assert2(uvalpha <= 4096U);
1324 
1325  for (i = 0; i < dstW; i++) {
1326  int Y = (buf0[i] * yalpha1 + buf1[i] * yalpha) >> 14;
1327  int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha - (128 << 23)) >> 14;
1328  int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha - (128 << 23)) >> 14;
1329  int R, G, B;
1330 
1331  Y -= c->yuv2rgb_y_offset;
1332  Y *= c->yuv2rgb_y_coeff;
1333  Y += 1 << 13;
1334 
1335  R = V * c->yuv2rgb_v2r_coeff;
1336  G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
1337  B = U * c->yuv2rgb_u2b_coeff;
1338 
1339  if (hasAlpha) {
1340  A = (abuf0[i] * yalpha1 + abuf1[i] * yalpha) >> 1;
1341 
1342  A += 1 << 13;
1343  }
1344 
1345  output_pixel(&dest[0], av_clip_uintp2(R_B + Y, 30) >> 14);
1346  output_pixel(&dest[1], av_clip_uintp2( G + Y, 30) >> 14);
1347  output_pixel(&dest[2], av_clip_uintp2(B_R + Y, 30) >> 14);
1348  if (eightbytes) {
1349  output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
1350  dest += 4;
1351  } else {
1352  dest += 3;
1353  }
1354  }
1355 }
1356 
1357 static av_always_inline void
1359  const int32_t *ubuf[2], const int32_t *vbuf[2],
1360  const int32_t *abuf0, uint16_t *dest, int dstW,
1361  int uvalpha, int y, enum AVPixelFormat target, int hasAlpha, int eightbytes)
1362 {
1363  const int32_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
1364  int i;
1365  int A = 0xffff<<14;
1366 
1367  if (uvalpha < 2048) {
1368  for (i = 0; i < dstW; i++) {
1369  int Y = (buf0[i]) >> 2;
1370  int U = (ubuf0[i] - (128 << 11)) >> 2;
1371  int V = (vbuf0[i] - (128 << 11)) >> 2;
1372  int R, G, B;
1373 
1374  Y -= c->yuv2rgb_y_offset;
1375  Y *= c->yuv2rgb_y_coeff;
1376  Y += 1 << 13;
1377 
1378  if (hasAlpha) {
1379  A = abuf0[i] << 11;
1380 
1381  A += 1 << 13;
1382  }
1383 
1384  R = V * c->yuv2rgb_v2r_coeff;
1385  G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
1386  B = U * c->yuv2rgb_u2b_coeff;
1387 
1388  output_pixel(&dest[0], av_clip_uintp2(R_B + Y, 30) >> 14);
1389  output_pixel(&dest[1], av_clip_uintp2( G + Y, 30) >> 14);
1390  output_pixel(&dest[2], av_clip_uintp2(B_R + Y, 30) >> 14);
1391  if (eightbytes) {
1392  output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
1393  dest += 4;
1394  } else {
1395  dest += 3;
1396  }
1397  }
1398  } else {
1399  const int32_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
1400  int A = 0xffff<<14;
1401  for (i = 0; i < dstW; i++) {
1402  int Y = (buf0[i] ) >> 2;
1403  int U = (ubuf0[i] + ubuf1[i] - (128 << 12)) >> 3;
1404  int V = (vbuf0[i] + vbuf1[i] - (128 << 12)) >> 3;
1405  int R, G, B;
1406 
1407  Y -= c->yuv2rgb_y_offset;
1408  Y *= c->yuv2rgb_y_coeff;
1409  Y += 1 << 13;
1410 
1411  if (hasAlpha) {
1412  A = abuf0[i] << 11;
1413 
1414  A += 1 << 13;
1415  }
1416 
1417  R = V * c->yuv2rgb_v2r_coeff;
1418  G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
1419  B = U * c->yuv2rgb_u2b_coeff;
1420 
1421  output_pixel(&dest[0], av_clip_uintp2(R_B + Y, 30) >> 14);
1422  output_pixel(&dest[1], av_clip_uintp2( G + Y, 30) >> 14);
1423  output_pixel(&dest[2], av_clip_uintp2(B_R + Y, 30) >> 14);
1424  if (eightbytes) {
1425  output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
1426  dest += 4;
1427  } else {
1428  dest += 3;
1429  }
1430  }
1431  }
1432 }
1433 
1434 #undef output_pixel
1435 #undef r_b
1436 #undef b_r
1437 
1438 #define YUV2PACKED16WRAPPER(name, base, ext, fmt, hasAlpha, eightbytes) \
1439 static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \
1440  const int16_t **_lumSrc, int lumFilterSize, \
1441  const int16_t *chrFilter, const int16_t **_chrUSrc, \
1442  const int16_t **_chrVSrc, int chrFilterSize, \
1443  const int16_t **_alpSrc, uint8_t *_dest, int dstW, \
1444  int y) \
1445 { \
1446  const int32_t **lumSrc = (const int32_t **) _lumSrc, \
1447  **chrUSrc = (const int32_t **) _chrUSrc, \
1448  **chrVSrc = (const int32_t **) _chrVSrc, \
1449  **alpSrc = (const int32_t **) _alpSrc; \
1450  uint16_t *dest = (uint16_t *) _dest; \
1451  name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
1452  chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
1453  alpSrc, dest, dstW, y, fmt, hasAlpha, eightbytes); \
1454 } \
1455  \
1456 static void name ## ext ## _2_c(SwsContext *c, const int16_t *_buf[2], \
1457  const int16_t *_ubuf[2], const int16_t *_vbuf[2], \
1458  const int16_t *_abuf[2], uint8_t *_dest, int dstW, \
1459  int yalpha, int uvalpha, int y) \
1460 { \
1461  const int32_t **buf = (const int32_t **) _buf, \
1462  **ubuf = (const int32_t **) _ubuf, \
1463  **vbuf = (const int32_t **) _vbuf, \
1464  **abuf = (const int32_t **) _abuf; \
1465  uint16_t *dest = (uint16_t *) _dest; \
1466  name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
1467  dest, dstW, yalpha, uvalpha, y, fmt, hasAlpha, eightbytes); \
1468 } \
1469  \
1470 static void name ## ext ## _1_c(SwsContext *c, const int16_t *_buf0, \
1471  const int16_t *_ubuf[2], const int16_t *_vbuf[2], \
1472  const int16_t *_abuf0, uint8_t *_dest, int dstW, \
1473  int uvalpha, int y) \
1474 { \
1475  const int32_t *buf0 = (const int32_t *) _buf0, \
1476  **ubuf = (const int32_t **) _ubuf, \
1477  **vbuf = (const int32_t **) _vbuf, \
1478  *abuf0 = (const int32_t *) _abuf0; \
1479  uint16_t *dest = (uint16_t *) _dest; \
1480  name ## base ## _1_c_template(c, buf0, ubuf, vbuf, abuf0, dest, \
1481  dstW, uvalpha, y, fmt, hasAlpha, eightbytes); \
1482 }
1483 
1484 YUV2PACKED16WRAPPER(yuv2, rgba64, rgb48be, AV_PIX_FMT_RGB48BE, 0, 0)
1485 YUV2PACKED16WRAPPER(yuv2, rgba64, rgb48le, AV_PIX_FMT_RGB48LE, 0, 0)
1486 YUV2PACKED16WRAPPER(yuv2, rgba64, bgr48be, AV_PIX_FMT_BGR48BE, 0, 0)
1487 YUV2PACKED16WRAPPER(yuv2, rgba64, bgr48le, AV_PIX_FMT_BGR48LE, 0, 0)
1488 YUV2PACKED16WRAPPER(yuv2, rgba64, rgba64be, AV_PIX_FMT_RGBA64BE, 1, 1)
1489 YUV2PACKED16WRAPPER(yuv2, rgba64, rgba64le, AV_PIX_FMT_RGBA64LE, 1, 1)
1490 YUV2PACKED16WRAPPER(yuv2, rgba64, rgbx64be, AV_PIX_FMT_RGBA64BE, 0, 1)
1491 YUV2PACKED16WRAPPER(yuv2, rgba64, rgbx64le, AV_PIX_FMT_RGBA64LE, 0, 1)
1492 YUV2PACKED16WRAPPER(yuv2, rgba64, bgra64be, AV_PIX_FMT_BGRA64BE, 1, 1)
1493 YUV2PACKED16WRAPPER(yuv2, rgba64, bgra64le, AV_PIX_FMT_BGRA64LE, 1, 1)
1494 YUV2PACKED16WRAPPER(yuv2, rgba64, bgrx64be, AV_PIX_FMT_BGRA64BE, 0, 1)
1495 YUV2PACKED16WRAPPER(yuv2, rgba64, bgrx64le, AV_PIX_FMT_BGRA64LE, 0, 1)
1496 YUV2PACKED16WRAPPER(yuv2, ya16, ya16be, AV_PIX_FMT_YA16BE, 1, 0)
1497 YUV2PACKED16WRAPPER(yuv2, ya16, ya16le, AV_PIX_FMT_YA16LE, 1, 0)
1498 
1499 YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgb48be_full, AV_PIX_FMT_RGB48BE, 0, 0)
1500 YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgb48le_full, AV_PIX_FMT_RGB48LE, 0, 0)
1501 YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgr48be_full, AV_PIX_FMT_BGR48BE, 0, 0)
1502 YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgr48le_full, AV_PIX_FMT_BGR48LE, 0, 0)
1503 YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgba64be_full, AV_PIX_FMT_RGBA64BE, 1, 1)
1504 YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgba64le_full, AV_PIX_FMT_RGBA64LE, 1, 1)
1505 YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgbx64be_full, AV_PIX_FMT_RGBA64BE, 0, 1)
1506 YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgbx64le_full, AV_PIX_FMT_RGBA64LE, 0, 1)
1507 YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgra64be_full, AV_PIX_FMT_BGRA64BE, 1, 1)
1508 YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgra64le_full, AV_PIX_FMT_BGRA64LE, 1, 1)
1509 YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgrx64be_full, AV_PIX_FMT_BGRA64BE, 0, 1)
1510 YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgrx64le_full, AV_PIX_FMT_BGRA64LE, 0, 1)
1511 
1512 /*
1513  * Write out 2 RGB pixels in the target pixel format. This function takes a
1514  * R/G/B LUT as generated by ff_yuv2rgb_c_init_tables(), which takes care of
1515  * things like endianness conversion and shifting. The caller takes care of
1516  * setting the correct offset in these tables from the chroma (U/V) values.
1517  * This function then uses the luminance (Y1/Y2) values to write out the
1518  * correct RGB values into the destination buffer.
1519  */
1520 static av_always_inline void
1521 yuv2rgb_write(uint8_t *_dest, int i, int Y1, int Y2,
1522  unsigned A1, unsigned A2,
1523  const void *_r, const void *_g, const void *_b, int y,
1524  enum AVPixelFormat target, int hasAlpha)
1525 {
1526  if (target == AV_PIX_FMT_ARGB || target == AV_PIX_FMT_RGBA ||
1527  target == AV_PIX_FMT_ABGR || target == AV_PIX_FMT_BGRA) {
1528  uint32_t *dest = (uint32_t *) _dest;
1529  const uint32_t *r = (const uint32_t *) _r;
1530  const uint32_t *g = (const uint32_t *) _g;
1531  const uint32_t *b = (const uint32_t *) _b;
1532 
1533 #if CONFIG_SMALL
1534  int sh = hasAlpha ? ((target == AV_PIX_FMT_RGB32_1 || target == AV_PIX_FMT_BGR32_1) ? 0 : 24) : 0;
1535 
1536  dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1] + (hasAlpha ? A1 << sh : 0);
1537  dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2] + (hasAlpha ? A2 << sh : 0);
1538 #else
1539  if (hasAlpha) {
1540  int sh = (target == AV_PIX_FMT_RGB32_1 || target == AV_PIX_FMT_BGR32_1) ? 0 : 24;
1541 
1542  av_assert2((((r[Y1] + g[Y1] + b[Y1]) >> sh) & 0xFF) == 0);
1543  dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1] + (A1 << sh);
1544  dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2] + (A2 << sh);
1545  } else {
1546 #if defined(ASSERT_LEVEL) && ASSERT_LEVEL > 1
1547  int sh = (target == AV_PIX_FMT_RGB32_1 || target == AV_PIX_FMT_BGR32_1) ? 0 : 24;
1548 
1549  av_assert2((((r[Y1] + g[Y1] + b[Y1]) >> sh) & 0xFF) == 0xFF);
1550 #endif
1551  dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1];
1552  dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2];
1553  }
1554 #endif
1555  } else if (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) {
1556  uint8_t *dest = (uint8_t *) _dest;
1557  const uint8_t *r = (const uint8_t *) _r;
1558  const uint8_t *g = (const uint8_t *) _g;
1559  const uint8_t *b = (const uint8_t *) _b;
1560 
1561 #define r_b ((target == AV_PIX_FMT_RGB24) ? r : b)
1562 #define b_r ((target == AV_PIX_FMT_RGB24) ? b : r)
1563 
1564  dest[i * 6 + 0] = r_b[Y1];
1565  dest[i * 6 + 1] = g[Y1];
1566  dest[i * 6 + 2] = b_r[Y1];
1567  dest[i * 6 + 3] = r_b[Y2];
1568  dest[i * 6 + 4] = g[Y2];
1569  dest[i * 6 + 5] = b_r[Y2];
1570 #undef r_b
1571 #undef b_r
1572  } else if (target == AV_PIX_FMT_RGB565 || target == AV_PIX_FMT_BGR565 ||
1573  target == AV_PIX_FMT_RGB555 || target == AV_PIX_FMT_BGR555 ||
1574  target == AV_PIX_FMT_RGB444 || target == AV_PIX_FMT_BGR444) {
1575  uint16_t *dest = (uint16_t *) _dest;
1576  const uint16_t *r = (const uint16_t *) _r;
1577  const uint16_t *g = (const uint16_t *) _g;
1578  const uint16_t *b = (const uint16_t *) _b;
1579  int dr1, dg1, db1, dr2, dg2, db2;
1580 
1581  if (target == AV_PIX_FMT_RGB565 || target == AV_PIX_FMT_BGR565) {
1582  dr1 = ff_dither_2x2_8[ y & 1 ][0];
1583  dg1 = ff_dither_2x2_4[ y & 1 ][0];
1584  db1 = ff_dither_2x2_8[(y & 1) ^ 1][0];
1585  dr2 = ff_dither_2x2_8[ y & 1 ][1];
1586  dg2 = ff_dither_2x2_4[ y & 1 ][1];
1587  db2 = ff_dither_2x2_8[(y & 1) ^ 1][1];
1588  } else if (target == AV_PIX_FMT_RGB555 || target == AV_PIX_FMT_BGR555) {
1589  dr1 = ff_dither_2x2_8[ y & 1 ][0];
1590  dg1 = ff_dither_2x2_8[ y & 1 ][1];
1591  db1 = ff_dither_2x2_8[(y & 1) ^ 1][0];
1592  dr2 = ff_dither_2x2_8[ y & 1 ][1];
1593  dg2 = ff_dither_2x2_8[ y & 1 ][0];
1594  db2 = ff_dither_2x2_8[(y & 1) ^ 1][1];
1595  } else {
1596  dr1 = ff_dither_4x4_16[ y & 3 ][0];
1597  dg1 = ff_dither_4x4_16[ y & 3 ][1];
1598  db1 = ff_dither_4x4_16[(y & 3) ^ 3][0];
1599  dr2 = ff_dither_4x4_16[ y & 3 ][1];
1600  dg2 = ff_dither_4x4_16[ y & 3 ][0];
1601  db2 = ff_dither_4x4_16[(y & 3) ^ 3][1];
1602  }
1603 
1604  dest[i * 2 + 0] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1];
1605  dest[i * 2 + 1] = r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2];
1606  } else if (target == AV_PIX_FMT_X2RGB10) {
1607  uint32_t *dest = (uint32_t *) _dest;
1608  const uint32_t *r = (const uint32_t *) _r;
1609  const uint32_t *g = (const uint32_t *) _g;
1610  const uint32_t *b = (const uint32_t *) _b;
1611  dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1];
1612  dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2];
1613  } else /* 8/4 bits */ {
1614  uint8_t *dest = (uint8_t *) _dest;
1615  const uint8_t *r = (const uint8_t *) _r;
1616  const uint8_t *g = (const uint8_t *) _g;
1617  const uint8_t *b = (const uint8_t *) _b;
1618  int dr1, dg1, db1, dr2, dg2, db2;
1619 
1620  if (target == AV_PIX_FMT_RGB8 || target == AV_PIX_FMT_BGR8) {
1621  const uint8_t * const d64 = ff_dither_8x8_73[y & 7];
1622  const uint8_t * const d32 = ff_dither_8x8_32[y & 7];
1623  dr1 = dg1 = d32[(i * 2 + 0) & 7];
1624  db1 = d64[(i * 2 + 0) & 7];
1625  dr2 = dg2 = d32[(i * 2 + 1) & 7];
1626  db2 = d64[(i * 2 + 1) & 7];
1627  } else {
1628  const uint8_t * const d64 = ff_dither_8x8_73 [y & 7];
1629  const uint8_t * const d128 = ff_dither_8x8_220[y & 7];
1630  dr1 = db1 = d128[(i * 2 + 0) & 7];
1631  dg1 = d64[(i * 2 + 0) & 7];
1632  dr2 = db2 = d128[(i * 2 + 1) & 7];
1633  dg2 = d64[(i * 2 + 1) & 7];
1634  }
1635 
1636  if (target == AV_PIX_FMT_RGB4 || target == AV_PIX_FMT_BGR4) {
1637  dest[i] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1] +
1638  ((r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2]) << 4);
1639  } else {
1640  dest[i * 2 + 0] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1];
1641  dest[i * 2 + 1] = r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2];
1642  }
1643  }
1644 }
1645 
1646 static av_always_inline void
1647 yuv2rgb_X_c_template(SwsContext *c, const int16_t *lumFilter,
1648  const int16_t **lumSrc, int lumFilterSize,
1649  const int16_t *chrFilter, const int16_t **chrUSrc,
1650  const int16_t **chrVSrc, int chrFilterSize,
1651  const int16_t **alpSrc, uint8_t *dest, int dstW,
1652  int y, enum AVPixelFormat target, int hasAlpha)
1653 {
1654  int i;
1655 
1656  for (i = 0; i < ((dstW + 1) >> 1); i++) {
1657  int j, A1, A2;
1658  int Y1 = 1 << 18;
1659  int Y2 = 1 << 18;
1660  int U = 1 << 18;
1661  int V = 1 << 18;
1662  const void *r, *g, *b;
1663 
1664  for (j = 0; j < lumFilterSize; j++) {
1665  Y1 += lumSrc[j][i * 2] * lumFilter[j];
1666  Y2 += lumSrc[j][i * 2 + 1] * lumFilter[j];
1667  }
1668  for (j = 0; j < chrFilterSize; j++) {
1669  U += chrUSrc[j][i] * chrFilter[j];
1670  V += chrVSrc[j][i] * chrFilter[j];
1671  }
1672  Y1 >>= 19;
1673  Y2 >>= 19;
1674  U >>= 19;
1675  V >>= 19;
1676  if (hasAlpha) {
1677  A1 = 1 << 18;
1678  A2 = 1 << 18;
1679  for (j = 0; j < lumFilterSize; j++) {
1680  A1 += alpSrc[j][i * 2 ] * lumFilter[j];
1681  A2 += alpSrc[j][i * 2 + 1] * lumFilter[j];
1682  }
1683  A1 >>= 19;
1684  A2 >>= 19;
1685  if ((A1 | A2) & 0x100) {
1686  A1 = av_clip_uint8(A1);
1687  A2 = av_clip_uint8(A2);
1688  }
1689  }
1690 
1691  r = c->table_rV[V + YUVRGB_TABLE_HEADROOM];
1692  g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]);
1693  b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
1694 
1695  yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
1696  r, g, b, y, target, hasAlpha);
1697  }
1698 }
1699 
1700 static av_always_inline void
1701 yuv2rgb_2_c_template(SwsContext *c, const int16_t *buf[2],
1702  const int16_t *ubuf[2], const int16_t *vbuf[2],
1703  const int16_t *abuf[2], uint8_t *dest, int dstW,
1704  int yalpha, int uvalpha, int y,
1705  enum AVPixelFormat target, int hasAlpha)
1706 {
1707  const int16_t *buf0 = buf[0], *buf1 = buf[1],
1708  *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
1709  *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
1710  *abuf0 = hasAlpha ? abuf[0] : NULL,
1711  *abuf1 = hasAlpha ? abuf[1] : NULL;
1712  int yalpha1 = 4096 - yalpha;
1713  int uvalpha1 = 4096 - uvalpha;
1714  int i;
1715  av_assert2(yalpha <= 4096U);
1716  av_assert2(uvalpha <= 4096U);
1717 
1718  for (i = 0; i < ((dstW + 1) >> 1); i++) {
1719  int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 19;
1720  int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 19;
1721  int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha) >> 19;
1722  int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha) >> 19;
1723  int A1, A2;
1724  const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM],
1725  *g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]),
1726  *b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
1727 
1728  if (hasAlpha) {
1729  A1 = (abuf0[i * 2 ] * yalpha1 + abuf1[i * 2 ] * yalpha) >> 19;
1730  A2 = (abuf0[i * 2 + 1] * yalpha1 + abuf1[i * 2 + 1] * yalpha) >> 19;
1731  A1 = av_clip_uint8(A1);
1732  A2 = av_clip_uint8(A2);
1733  }
1734 
1735  yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
1736  r, g, b, y, target, hasAlpha);
1737  }
1738 }
1739 
1740 static av_always_inline void
1741 yuv2rgb_1_c_template(SwsContext *c, const int16_t *buf0,
1742  const int16_t *ubuf[2], const int16_t *vbuf[2],
1743  const int16_t *abuf0, uint8_t *dest, int dstW,
1744  int uvalpha, int y, enum AVPixelFormat target,
1745  int hasAlpha)
1746 {
1747  const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
1748  int i;
1749 
1750  if (uvalpha < 2048) {
1751  for (i = 0; i < ((dstW + 1) >> 1); i++) {
1752  int Y1 = (buf0[i * 2 ] + 64) >> 7;
1753  int Y2 = (buf0[i * 2 + 1] + 64) >> 7;
1754  int U = (ubuf0[i] + 64) >> 7;
1755  int V = (vbuf0[i] + 64) >> 7;
1756  int A1, A2;
1757  const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM],
1758  *g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]),
1759  *b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
1760 
1761  if (hasAlpha) {
1762  A1 = abuf0[i * 2 ] * 255 + 16384 >> 15;
1763  A2 = abuf0[i * 2 + 1] * 255 + 16384 >> 15;
1764  A1 = av_clip_uint8(A1);
1765  A2 = av_clip_uint8(A2);
1766  }
1767 
1768  yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
1769  r, g, b, y, target, hasAlpha);
1770  }
1771  } else {
1772  const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
1773  for (i = 0; i < ((dstW + 1) >> 1); i++) {
1774  int Y1 = (buf0[i * 2 ] + 64) >> 7;
1775  int Y2 = (buf0[i * 2 + 1] + 64) >> 7;
1776  int U = (ubuf0[i] + ubuf1[i] + 128) >> 8;
1777  int V = (vbuf0[i] + vbuf1[i] + 128) >> 8;
1778  int A1, A2;
1779  const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM],
1780  *g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]),
1781  *b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
1782 
1783  if (hasAlpha) {
1784  A1 = (abuf0[i * 2 ] + 64) >> 7;
1785  A2 = (abuf0[i * 2 + 1] + 64) >> 7;
1786  A1 = av_clip_uint8(A1);
1787  A2 = av_clip_uint8(A2);
1788  }
1789 
1790  yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
1791  r, g, b, y, target, hasAlpha);
1792  }
1793  }
1794 }
1795 
1796 #define YUV2RGBWRAPPERX(name, base, ext, fmt, hasAlpha) \
1797 static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \
1798  const int16_t **lumSrc, int lumFilterSize, \
1799  const int16_t *chrFilter, const int16_t **chrUSrc, \
1800  const int16_t **chrVSrc, int chrFilterSize, \
1801  const int16_t **alpSrc, uint8_t *dest, int dstW, \
1802  int y) \
1803 { \
1804  name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
1805  chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
1806  alpSrc, dest, dstW, y, fmt, hasAlpha); \
1807 }
1808 
1809 #define YUV2RGBWRAPPERX2(name, base, ext, fmt, hasAlpha) \
1810 YUV2RGBWRAPPERX(name, base, ext, fmt, hasAlpha) \
1811 static void name ## ext ## _2_c(SwsContext *c, const int16_t *buf[2], \
1812  const int16_t *ubuf[2], const int16_t *vbuf[2], \
1813  const int16_t *abuf[2], uint8_t *dest, int dstW, \
1814  int yalpha, int uvalpha, int y) \
1815 { \
1816  name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
1817  dest, dstW, yalpha, uvalpha, y, fmt, hasAlpha); \
1818 }
1819 
1820 #define YUV2RGBWRAPPER(name, base, ext, fmt, hasAlpha) \
1821 YUV2RGBWRAPPERX2(name, base, ext, fmt, hasAlpha) \
1822 static void name ## ext ## _1_c(SwsContext *c, const int16_t *buf0, \
1823  const int16_t *ubuf[2], const int16_t *vbuf[2], \
1824  const int16_t *abuf0, uint8_t *dest, int dstW, \
1825  int uvalpha, int y) \
1826 { \
1827  name ## base ## _1_c_template(c, buf0, ubuf, vbuf, abuf0, dest, \
1828  dstW, uvalpha, y, fmt, hasAlpha); \
1829 }
1830 
1831 #if CONFIG_SMALL
1832 YUV2RGBWRAPPER(yuv2rgb,, 32_1, AV_PIX_FMT_RGB32_1, CONFIG_SWSCALE_ALPHA && c->needAlpha)
1833 YUV2RGBWRAPPER(yuv2rgb,, 32, AV_PIX_FMT_RGB32, CONFIG_SWSCALE_ALPHA && c->needAlpha)
1834 #else
1835 #if CONFIG_SWSCALE_ALPHA
1838 #endif
1841 #endif
1842 YUV2RGBWRAPPER(yuv2, rgb, rgb24, AV_PIX_FMT_RGB24, 0)
1843 YUV2RGBWRAPPER(yuv2, rgb, bgr24, AV_PIX_FMT_BGR24, 0)
1850 YUV2RGBWRAPPER(yuv2, rgb, x2rgb10, AV_PIX_FMT_X2RGB10, 0)
1851 
1853  uint8_t *dest, int i, int Y, int A, int U, int V,
1854  int y, enum AVPixelFormat target, int hasAlpha, int err[4])
1855 {
1856  int R, G, B;
1857  int isrgb8 = target == AV_PIX_FMT_BGR8 || target == AV_PIX_FMT_RGB8;
1858 
1859  Y -= c->yuv2rgb_y_offset;
1860  Y *= c->yuv2rgb_y_coeff;
1861  Y += 1 << 21;
1862  R = (unsigned)Y + V*c->yuv2rgb_v2r_coeff;
1863  G = (unsigned)Y + V*c->yuv2rgb_v2g_coeff + U*c->yuv2rgb_u2g_coeff;
1864  B = (unsigned)Y + U*c->yuv2rgb_u2b_coeff;
1865  if ((R | G | B) & 0xC0000000) {
1866  R = av_clip_uintp2(R, 30);
1867  G = av_clip_uintp2(G, 30);
1868  B = av_clip_uintp2(B, 30);
1869  }
1870 
1871  switch(target) {
1872  case AV_PIX_FMT_ARGB:
1873  dest[0] = hasAlpha ? A : 255;
1874  dest[1] = R >> 22;
1875  dest[2] = G >> 22;
1876  dest[3] = B >> 22;
1877  break;
1878  case AV_PIX_FMT_RGB24:
1879  dest[0] = R >> 22;
1880  dest[1] = G >> 22;
1881  dest[2] = B >> 22;
1882  break;
1883  case AV_PIX_FMT_RGBA:
1884  dest[0] = R >> 22;
1885  dest[1] = G >> 22;
1886  dest[2] = B >> 22;
1887  dest[3] = hasAlpha ? A : 255;
1888  break;
1889  case AV_PIX_FMT_ABGR:
1890  dest[0] = hasAlpha ? A : 255;
1891  dest[1] = B >> 22;
1892  dest[2] = G >> 22;
1893  dest[3] = R >> 22;
1894  break;
1895  case AV_PIX_FMT_BGR24:
1896  dest[0] = B >> 22;
1897  dest[1] = G >> 22;
1898  dest[2] = R >> 22;
1899  break;
1900  case AV_PIX_FMT_BGRA:
1901  dest[0] = B >> 22;
1902  dest[1] = G >> 22;
1903  dest[2] = R >> 22;
1904  dest[3] = hasAlpha ? A : 255;
1905  break;
1906  case AV_PIX_FMT_BGR4_BYTE:
1907  case AV_PIX_FMT_RGB4_BYTE:
1908  case AV_PIX_FMT_BGR8:
1909  case AV_PIX_FMT_RGB8:
1910  {
1911  int r,g,b;
1912 
1913  switch (c->dither) {
1914  case SWS_DITHER_NONE:
1915  if (isrgb8) {
1916  r = av_clip_uintp2(R >> 27, 3);
1917  g = av_clip_uintp2(G >> 27, 3);
1918  b = av_clip_uintp2(B >> 28, 2);
1919  } else {
1920  r = av_clip_uintp2(R >> 29, 1);
1921  g = av_clip_uintp2(G >> 28, 2);
1922  b = av_clip_uintp2(B >> 29, 1);
1923  }
1924  break;
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] * 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] * 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 * c->yuv2rgb_v2r_coeff;
2226  G = Y + V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
2227  B = Y + U * 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 }
yuv2packed2_fn
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...
Definition: swscale_internal.h:222
yuv2planar1_fn
void(* yuv2planar1_fn)(const int16_t *src, uint8_t *dest, int dstW, const uint8_t *dither, int offset)
Write one line of horizontally scaled data to planar output without any additional vertical scaling (...
Definition: swscale_internal.h:116
yuv2packed1_fn
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...
Definition: swscale_internal.h:189
YUV2PACKEDWRAPPER
#define YUV2PACKEDWRAPPER(name, base, ext, fmt)
Definition: output.c:710
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
AV_PIX_FMT_BGR48LE
@ AV_PIX_FMT_BGR48LE
packed RGB 16:16:16, 48bpp, 16B, 16G, 16R, the 2-byte value for each R/G/B component is stored as lit...
Definition: pixfmt.h:139
av_clip
#define av_clip
Definition: common.h:96
ff_dither_4x4_16
const uint8_t ff_dither_4x4_16[][8]
Definition: output.c:51
X_DITHER
#define X_DITHER(u, v)
r
const char * r
Definition: vf_curves.c:116
acc
int acc
Definition: yuv2rgb.c:554
AV_PIX_FMT_YA8
@ AV_PIX_FMT_YA8
8 bits gray, 8 bits alpha
Definition: pixfmt.h:133
AV_PIX_FMT_BGRA64BE
@ AV_PIX_FMT_BGRA64BE
packed RGBA 16:16:16:16, 64bpp, 16B, 16G, 16R, 16A, the 2-byte value for each R/G/B/A component is st...
Definition: pixfmt.h:197
yuv2rgb_X_c_template
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:1647
mem_internal.h
AV_PIX_FMT_BGR32
#define AV_PIX_FMT_BGR32
Definition: pixfmt.h:364
AV_PIX_FMT_RGB444LE
@ AV_PIX_FMT_RGB444LE
packed RGB 4:4:4, 16bpp, (msb)4X 4R 4G 4B(lsb), little-endian, X=unused/undefined
Definition: pixfmt.h:129
u
#define u(width, name, range_min, range_max)
Definition: cbs_h2645.c:264
AV_PIX_FMT_GBRP16BE
@ AV_PIX_FMT_GBRP16BE
planar GBR 4:4:4 48bpp, big-endian
Definition: pixfmt.h:164
AV_PIX_FMT_GBRP10BE
@ AV_PIX_FMT_GBRP10BE
planar GBR 4:4:4 30bpp, big-endian
Definition: pixfmt.h:162
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2540
ff_dither_8x8_32
const uint8_t ff_dither_8x8_32[][8]
Definition: output.c:59
av_clip_uintp2
#define av_clip_uintp2
Definition: common.h:120
yuv2rgb_full_1_c_template
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
yuv2rgba64_full_X_c_template
static av_always_inline void yuv2rgba64_full_X_c_template(SwsContext *c, const int16_t *lumFilter, const int32_t **lumSrc, int lumFilterSize, const int16_t *chrFilter, const int32_t **chrUSrc, const int32_t **chrVSrc, int chrFilterSize, const int32_t **alpSrc, uint16_t *dest, int dstW, int y, enum AVPixelFormat target, int hasAlpha, int eightbytes)
Definition: output.c:1242
SWS_DITHER_A_DITHER
@ SWS_DITHER_A_DITHER
Definition: swscale_internal.h:75
accumulate_bit
#define accumulate_bit(acc, val)
Definition: output.c:535
pixdesc.h
AV_PIX_FMT_RGBA64BE
@ AV_PIX_FMT_RGBA64BE
packed RGBA 16:16:16:16, 64bpp, 16R, 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is st...
Definition: pixfmt.h:195
step
trying all byte sequences megabyte in length and selecting the best looking sequence will yield cases to try But a word about which is also called distortion Distortion can be quantified by almost any quality measurement one chooses the sum of squared differences is used but more complex methods that consider psychovisual effects can be used as well It makes no difference in this discussion First step
Definition: rate_distortion.txt:58
AV_PIX_FMT_GBRAPF32LE
@ AV_PIX_FMT_GBRAPF32LE
IEEE-754 single precision planar GBRA 4:4:4:4, 128bpp, little-endian.
Definition: pixfmt.h:311
AV_PIX_FMT_GBRPF32BE
@ AV_PIX_FMT_GBRPF32BE
IEEE-754 single precision planar GBR 4:4:4, 96bpp, big-endian.
Definition: pixfmt.h:308
R
#define R
Definition: huffyuvdsp.h:34
b
#define b
Definition: input.c:40
yuv2planeX
static void FUNC() yuv2planeX(const int16_t *filter, int filterSize, const int16_t **src, uint8_t *dest, int dstW, const uint8_t *dither, int offset)
Definition: swscale_ppc_template.c:84
AV_PIX_FMT_MONOWHITE
@ AV_PIX_FMT_MONOWHITE
Y , 1bpp, 0 is white, 1 is black, in each byte pixels are ordered from the msb to the lsb.
Definition: pixfmt.h:75
AV_PIX_FMT_P010BE
@ AV_PIX_FMT_P010BE
like NV12, with 10bpp per component, data in the high bits, zeros in the low bits,...
Definition: pixfmt.h:275
AV_PIX_FMT_RGB32_1
#define AV_PIX_FMT_RGB32_1
Definition: pixfmt.h:363
yuv2rgba64_X_c_template
static av_always_inline void yuv2rgba64_X_c_template(SwsContext *c, const int16_t *lumFilter, const int32_t **lumSrc, int lumFilterSize, const int16_t *chrFilter, const int32_t **chrUSrc, const int32_t **chrVSrc, int chrFilterSize, const int32_t **alpSrc, uint16_t *dest, int dstW, int y, enum AVPixelFormat target, int hasAlpha, int eightbytes)
Definition: output.c:992
b_r
#define b_r
AV_PIX_FMT_GBRP14BE
@ AV_PIX_FMT_GBRP14BE
planar GBR 4:4:4 42bpp, big-endian
Definition: pixfmt.h:246
AV_PIX_FMT_BGR24
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:69
AV_PIX_FMT_BGRA
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition: pixfmt.h:95
mathematics.h
yuv2rgb_full_X_c_template
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
filter
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce then the filter should push the output frames on the output link immediately As an exception to the previous rule if the input frame is enough to produce several output frames then the filter needs output only at least one per link The additional frames can be left buffered in the filter
Definition: filter_design.txt:228
yuv2422_2_c_template
static av_always_inline void yuv2422_2_c_template(SwsContext *c, const int16_t *buf[2], const int16_t *ubuf[2], const int16_t *vbuf[2], const int16_t *abuf[2], uint8_t *dest, int dstW, int yalpha, int uvalpha, int y, enum AVPixelFormat target)
Definition: output.c:803
av_float2int
static av_always_inline uint32_t av_float2int(float f)
Reinterpret a float as a 32-bit integer.
Definition: intfloat.h:50
yuv2plane1_8_c
static void yuv2plane1_8_c(const int16_t *src, uint8_t *dest, int dstW, const uint8_t *dither, int offset)
Definition: output.c:396
AV_PIX_FMT_GRAYF32LE
@ AV_PIX_FMT_GRAYF32LE
IEEE-754 single precision Y, 32bpp, little-endian.
Definition: pixfmt.h:331
yuv2planeX_10_c_template
static av_always_inline void yuv2planeX_10_c_template(const int16_t *filter, int filterSize, const int16_t **src, uint16_t *dest, int dstW, int big_endian, int output_bits)
Definition: output.c:334
AV_PIX_FMT_RGB555BE
@ AV_PIX_FMT_RGB555BE
packed RGB 5:5:5, 16bpp, (msb)1X 5R 5G 5B(lsb), big-endian , X=unused/undefined
Definition: pixfmt.h:107
AV_PIX_FMT_AYUV64LE
@ AV_PIX_FMT_AYUV64LE
packed AYUV 4:4:4,64bpp (1 Cr & Cb sample per 1x1 Y & A samples), little-endian
Definition: pixfmt.h:269
SH
#define SH(val, pdst)
Definition: generic_macros_msa.h:154
AV_PIX_FMT_GBRAP12LE
@ AV_PIX_FMT_GBRAP12LE
planar GBR 4:4:4:4 48bpp, little-endian
Definition: pixfmt.h:278
A
#define A(x)
Definition: vp56_arith.h:28
is16BPS
static av_always_inline int is16BPS(enum AVPixelFormat pix_fmt)
Definition: swscale_internal.h:696
rgb
Definition: rpzaenc.c:59
AV_PIX_FMT_GBRAP
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:205
yuv2anyX_fn
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...
Definition: swscale_internal.h:288
yuv2422_X_c_template
static av_always_inline void yuv2422_X_c_template(SwsContext *c, const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, const int16_t *chrFilter, const int16_t **chrUSrc, const int16_t **chrVSrc, int chrFilterSize, const int16_t **alpSrc, uint8_t *dest, int dstW, int y, enum AVPixelFormat target)
Definition: output.c:764
U
#define U(x)
Definition: vp56_arith.h:37
yuv2mono_1_c_template
static av_always_inline void yuv2mono_1_c_template(SwsContext *c, const int16_t *buf0, const int16_t *ubuf[2], const int16_t *vbuf[2], const int16_t *abuf0, uint8_t *dest, int dstW, int uvalpha, int y, enum AVPixelFormat target)
Definition: output.c:660
yuv2plane1_16_c_template
static av_always_inline void yuv2plane1_16_c_template(const int32_t *src, uint16_t *dest, int dstW, int big_endian, int output_bits)
Definition: output.c:144
yuv2422_1_c_template
static av_always_inline void yuv2422_1_c_template(SwsContext *c, const int16_t *buf0, const int16_t *ubuf[2], const int16_t *vbuf[2], const int16_t *abuf0, uint8_t *dest, int dstW, int uvalpha, int y, enum AVPixelFormat target)
Definition: output.c:836
yuv2gbrp_full_X_c
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
val
static double val(void *priv, double ch)
Definition: aeval.c:76
isNBPS
static av_always_inline int isNBPS(enum AVPixelFormat pix_fmt)
Definition: swscale_internal.h:710
R_B
#define R_B
Definition: output.c:886
yuv2plane1_float
#define yuv2plane1_float(template, dest_type, BE_LE)
Definition: output.c:284
av_bswap32
#define av_bswap32
Definition: bswap.h:33
yuv2planeX_16_c_template
static av_always_inline void yuv2planeX_16_c_template(const int16_t *filter, int filterSize, const int32_t **src, uint16_t *dest, int dstW, int big_endian, int output_bits)
Definition: output.c:158
r_b
#define r_b
AV_PIX_FMT_BGR8
@ AV_PIX_FMT_BGR8
packed RGB 3:3:2, 8bpp, (msb)2B 3G 3R(lsb)
Definition: pixfmt.h:83
avassert.h
av_cold
#define av_cold
Definition: attributes.h:90
yuv2mono_2_c_template
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:599
yuv2planeX_float
#define yuv2planeX_float(template, dest_type, BE_LE)
Definition: output.c:291
YUVRGB_TABLE_HEADROOM
#define YUVRGB_TABLE_HEADROOM
Definition: swscale_internal.h:43
SWS_DITHER_ED
@ SWS_DITHER_ED
Definition: swscale_internal.h:74
AV_PIX_FMT_GBRAP16BE
@ AV_PIX_FMT_GBRAP16BE
planar GBRA 4:4:4:4 64bpp, big-endian
Definition: pixfmt.h:206
yuv2rgb_full_2_c_template
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
intreadwrite.h
AV_PIX_FMT_GBRP16LE
@ AV_PIX_FMT_GBRP16LE
planar GBR 4:4:4 48bpp, little-endian
Definition: pixfmt.h:165
output_pixels
#define output_pixels(pos, Y1, U, Y2, V)
Definition: output.c:745
g
const char * g
Definition: vf_curves.c:117
yuv2p010l1_LE_c
static void yuv2p010l1_LE_c(const int16_t *src, uint8_t *dest, int dstW, const uint8_t *dither, int offset)
Definition: output.c:504
AV_PIX_FMT_P016BE
@ AV_PIX_FMT_P016BE
like NV12, with 16bpp per component, big-endian
Definition: pixfmt.h:291
AV_PIX_FMT_GBRP12LE
@ AV_PIX_FMT_GBRP12LE
planar GBR 4:4:4 36bpp, little-endian
Definition: pixfmt.h:245
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
yuv2plane1_float_bswap_c_template
static av_always_inline void yuv2plane1_float_bswap_c_template(const int32_t *src, uint32_t *dest, int dstW)
Definition: output.c:229
ff_dither_2x2_4
const uint8_t ff_dither_2x2_4[][8]
Definition: output.c:39
ff_dither_8x8_220
const uint8_t ff_dither_8x8_220[][8]
Definition: output.c:84
AV_PIX_FMT_FLAG_ALPHA
#define AV_PIX_FMT_FLAG_ALPHA
The pixel format has an alpha channel.
Definition: pixdesc.h:147
yuv2ya8_X_c
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
YUV2PACKED16WRAPPER
#define YUV2PACKED16WRAPPER(name, base, ext, fmt, hasAlpha, eightbytes)
Definition: output.c:1438
yuv2mono_X_c_template
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:546
AV_PIX_FMT_RGB4
@ AV_PIX_FMT_RGB4
packed RGB 1:2:1 bitstream, 4bpp, (msb)1R 2G 1B(lsb), a byte contains two pixels, the first pixel in ...
Definition: pixfmt.h:87
AV_PIX_FMT_GBRP10LE
@ AV_PIX_FMT_GBRP10LE
planar GBR 4:4:4 30bpp, little-endian
Definition: pixfmt.h:163
AV_PIX_FMT_BGR32_1
#define AV_PIX_FMT_BGR32_1
Definition: pixfmt.h:365
yuv2rgba64_full_2_c_template
static av_always_inline void yuv2rgba64_full_2_c_template(SwsContext *c, const int32_t *buf[2], const int32_t *ubuf[2], const int32_t *vbuf[2], const int32_t *abuf[2], uint16_t *dest, int dstW, int yalpha, int uvalpha, int y, enum AVPixelFormat target, int hasAlpha, int eightbytes)
Definition: output.c:1306
AV_PIX_FMT_RGBA
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:93
if
if(ret)
Definition: filter_design.txt:179
yuv2NBPS
#define yuv2NBPS(bits, BE_LE, is_be, template_size, typeX_t)
Definition: output.c:354
SWS_DITHER_NONE
@ SWS_DITHER_NONE
Definition: swscale_internal.h:71
AV_PIX_FMT_RGB565LE
@ AV_PIX_FMT_RGB565LE
packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), little-endian
Definition: pixfmt.h:106
AV_PIX_FMT_GBRAPF32BE
@ AV_PIX_FMT_GBRAPF32BE
IEEE-754 single precision planar GBRA 4:4:4:4, 128bpp, big-endian.
Definition: pixfmt.h:310
AV_PIX_FMT_GBRAP12BE
@ AV_PIX_FMT_GBRAP12BE
planar GBR 4:4:4:4 48bpp, big-endian
Definition: pixfmt.h:277
av_clip_int16
#define av_clip_int16
Definition: common.h:111
NULL
#define NULL
Definition: coverity.c:32
yuv2rgba64_full_1_c_template
static av_always_inline void yuv2rgba64_full_1_c_template(SwsContext *c, const int32_t *buf0, const int32_t *ubuf[2], const int32_t *vbuf[2], const int32_t *abuf0, uint16_t *dest, int dstW, int uvalpha, int y, enum AVPixelFormat target, int hasAlpha, int eightbytes)
Definition: output.c:1358
AV_PIX_FMT_YUYV422
@ AV_PIX_FMT_YUYV422
packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
Definition: pixfmt.h:67
AV_PIX_FMT_RGB48LE
@ AV_PIX_FMT_RGB48LE
packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as lit...
Definition: pixfmt.h:103
AV_PIX_FMT_YA16LE
@ AV_PIX_FMT_YA16LE
16 bits gray, 16 bits alpha (little-endian)
Definition: pixfmt.h:203
yuv2gbrp16_full_X_c
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
AV_PIX_FMT_MONOBLACK
@ AV_PIX_FMT_MONOBLACK
Y , 1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb.
Definition: pixfmt.h:76
V
#define V
Definition: avdct.c:30
AV_PIX_FMT_BGR565LE
@ AV_PIX_FMT_BGR565LE
packed BGR 5:6:5, 16bpp, (msb) 5B 6G 5R(lsb), little-endian
Definition: pixfmt.h:111
AV_PIX_FMT_RGBA64LE
@ AV_PIX_FMT_RGBA64LE
packed RGBA 16:16:16:16, 64bpp, 16R, 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is st...
Definition: pixfmt.h:196
src
#define src
Definition: vp8dsp.c:255
AV_PIX_FMT_RGB8
@ AV_PIX_FMT_RGB8
packed RGB 3:3:2, 8bpp, (msb)2R 3G 3B(lsb)
Definition: pixfmt.h:86
yuv2ya8_2_c
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
AV_PIX_FMT_BGR4
@ AV_PIX_FMT_BGR4
packed RGB 1:2:1 bitstream, 4bpp, (msb)1B 2G 1R(lsb), a byte contains two pixels, the first pixel in ...
Definition: pixfmt.h:84
AV_PIX_FMT_BGR555BE
@ AV_PIX_FMT_BGR555BE
packed BGR 5:5:5, 16bpp, (msb)1X 5B 5G 5R(lsb), big-endian , X=unused/undefined
Definition: pixfmt.h:112
yuv2plane1_float_c_template
static av_always_inline void yuv2plane1_float_c_template(const int32_t *src, float *dest, int dstW)
Definition: output.c:213
A2
#define A2
Definition: binkdsp.c:32
AV_PIX_FMT_ABGR
@ AV_PIX_FMT_ABGR
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
Definition: pixfmt.h:94
yuv2p010lX_c
static void yuv2p010lX_c(const int16_t *filter, int filterSize, const int16_t **src, uint16_t *dest, int dstW, int big_endian)
Definition: output.c:463
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
AV_PIX_FMT_BGR4_BYTE
@ AV_PIX_FMT_BGR4_BYTE
packed RGB 1:2:1, 8bpp, (msb)1B 2G 1R(lsb)
Definition: pixfmt.h:85
A_DITHER
#define A_DITHER(u, v)
AV_PIX_FMT_X2RGB10LE
@ AV_PIX_FMT_X2RGB10LE
packed RGB 10:10:10, 30bpp, (msb)2X 10R 10G 10B(lsb), little-endian, X=unused/undefined
Definition: pixfmt.h:351
d64
const uint8_t * d64
Definition: yuv2rgb.c:502
isBE
static av_always_inline int isBE(enum AVPixelFormat pix_fmt)
Definition: swscale_internal.h:717
AV_PIX_FMT_RGB24
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:68
AV_PIX_FMT_RGB444BE
@ AV_PIX_FMT_RGB444BE
packed RGB 4:4:4, 16bpp, (msb)4X 4R 4G 4B(lsb), big-endian, X=unused/undefined
Definition: pixfmt.h:130
SWS_FULL_CHR_H_INT
#define SWS_FULL_CHR_H_INT
Definition: swscale.h:80
yuv2planeX_float_bswap_c_template
static av_always_inline void yuv2planeX_float_bswap_c_template(const int16_t *filter, int filterSize, const int32_t **src, uint32_t *dest, int dstW)
Definition: output.c:265
AV_PIX_FMT_YA16BE
@ AV_PIX_FMT_YA16BE
16 bits gray, 16 bits alpha (big-endian)
Definition: pixfmt.h:202
AV_PIX_FMT_BGR555
#define AV_PIX_FMT_BGR555
Definition: pixfmt.h:382
AV_PIX_FMT_GBRP9BE
@ AV_PIX_FMT_GBRP9BE
planar GBR 4:4:4 27bpp, big-endian
Definition: pixfmt.h:160
AV_PIX_FMT_BGR444BE
@ AV_PIX_FMT_BGR444BE
packed BGR 4:4:4, 16bpp, (msb)4X 4B 4G 4R(lsb), big-endian, X=unused/undefined
Definition: pixfmt.h:132
output_pixel
#define output_pixel(pos, val, bias, signedness)
Definition: output.c:888
AV_PIX_FMT_GBRP9LE
@ AV_PIX_FMT_GBRP9LE
planar GBR 4:4:4 27bpp, little-endian
Definition: pixfmt.h:161
yuv2ya16_2_c_template
static av_always_inline void yuv2ya16_2_c_template(SwsContext *c, const int32_t *buf[2], const int32_t *unused_ubuf[2], const int32_t *unused_vbuf[2], const int32_t *abuf[2], uint16_t *dest, int dstW, int yalpha, int unused_uvalpha, int y, enum AVPixelFormat target, int unused_hasAlpha, int unused_eightbytes)
Definition: output.c:934
AV_WL16
#define AV_WL16(p, v)
Definition: intreadwrite.h:412
AV_PIX_FMT_RGB32
#define AV_PIX_FMT_RGB32
Definition: pixfmt.h:362
AV_PIX_FMT_GBRAP10LE
@ AV_PIX_FMT_GBRAP10LE
planar GBR 4:4:4:4 40bpp, little-endian
Definition: pixfmt.h:281
AV_PIX_FMT_BGR565BE
@ AV_PIX_FMT_BGR565BE
packed BGR 5:6:5, 16bpp, (msb) 5B 6G 5R(lsb), big-endian
Definition: pixfmt.h:110
yuv2nv12cX_c
static void yuv2nv12cX_c(enum AVPixelFormat dstFormat, const uint8_t *chrDither, const int16_t *chrFilter, int chrFilterSize, const int16_t **chrUSrc, const int16_t **chrVSrc, uint8_t *dest, int chrDstW)
Definition: output.c:406
av_bswap16
#define av_bswap16
Definition: bswap.h:31
offset
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
Definition: writing_filters.txt:86
attributes.h
yuv2rgb_write_full
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:1852
ff_dither_8x8_73
const uint8_t ff_dither_8x8_73[][8]
Definition: output.c:71
Y
#define Y
Definition: boxblur.h:37
yuv2rgb_write
static av_always_inline void yuv2rgb_write(uint8_t *_dest, int i, int Y1, int Y2, unsigned A1, unsigned A2, const void *_r, const void *_g, const void *_b, int y, enum AVPixelFormat target, int hasAlpha)
Definition: output.c:1521
AV_PIX_FMT_ARGB
@ AV_PIX_FMT_ARGB
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
Definition: pixfmt.h:92
AV_PIX_FMT_BGRA64LE
@ AV_PIX_FMT_BGRA64LE
packed RGBA 16:16:16:16, 64bpp, 16B, 16G, 16R, 16A, the 2-byte value for each R/G/B/A component is st...
Definition: pixfmt.h:198
DECLARE_ALIGNED
#define DECLARE_ALIGNED(n, t, v)
Definition: mem.h:116
av_assert2
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Definition: avassert.h:64
AV_PIX_FMT_RGB555LE
@ AV_PIX_FMT_RGB555LE
packed RGB 5:5:5, 16bpp, (msb)1X 5R 5G 5B(lsb), little-endian, X=unused/undefined
Definition: pixfmt.h:108
i
int i
Definition: input.c:406
AV_PIX_FMT_RGB48BE
@ AV_PIX_FMT_RGB48BE
packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as big...
Definition: pixfmt.h:102
yuv2p010l1_c
static void yuv2p010l1_c(const int16_t *src, uint16_t *dest, int dstW, int big_endian)
Definition: output.c:450
yuv2ya16_1_c_template
static av_always_inline void yuv2ya16_1_c_template(SwsContext *c, const int32_t *buf0, const int32_t *unused_ubuf[2], const int32_t *unused_vbuf[2], const int32_t *abuf0, uint16_t *dest, int dstW, int unused_uvalpha, int y, enum AVPixelFormat target, int unused_hasAlpha, int unused_eightbytes)
Definition: output.c:966
yuv2p010cX_c
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:480
AV_PIX_FMT_NV24
@ 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:338
AV_PIX_FMT_BGR444
#define AV_PIX_FMT_BGR444
Definition: pixfmt.h:383
AV_PIX_FMT_RGB555
#define AV_PIX_FMT_RGB555
Definition: pixfmt.h:377
yuv2planeX_float_c_template
static av_always_inline void yuv2planeX_float_c_template(const int16_t *filter, int filterSize, const int32_t **src, float *dest, int dstW)
Definition: output.c:245
av_always_inline
#define av_always_inline
Definition: attributes.h:49
swscale_internal.h
yuv2interleavedX_fn
void(* yuv2interleavedX_fn)(enum AVPixelFormat dstFormat, const uint8_t *chrDither, const int16_t *chrFilter, int chrFilterSize, const int16_t **chrUSrc, const int16_t **chrVSrc, uint8_t *dest, int dstW)
Write one line of horizontally scaled chroma to interleaved output with multi-point vertical scaling ...
Definition: swscale_internal.h:152
yuv2gbrpf32_full_X_c
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
AV_PIX_FMT_X2RGB10
#define AV_PIX_FMT_X2RGB10
Definition: pixfmt.h:442
AV_PIX_FMT_X2RGB10BE
@ AV_PIX_FMT_X2RGB10BE
packed RGB 10:10:10, 30bpp, (msb)2X 10R 10G 10B(lsb), big-endian, X=unused/undefined
Definition: pixfmt.h:352
AV_PIX_FMT_NV21
@ AV_PIX_FMT_NV21
as above, but U and V bytes are swapped
Definition: pixfmt.h:90
AV_PIX_FMT_BGR565
#define AV_PIX_FMT_BGR565
Definition: pixfmt.h:381
AV_PIX_FMT_RGB4_BYTE
@ AV_PIX_FMT_RGB4_BYTE
packed RGB 1:2:1, 8bpp, (msb)1R 2G 1B(lsb)
Definition: pixfmt.h:88
AV_PIX_FMT_GBRPF32LE
@ AV_PIX_FMT_GBRPF32LE
IEEE-754 single precision planar GBR 4:4:4, 96bpp, little-endian.
Definition: pixfmt.h:309
AV_PIX_FMT_NV42
@ AV_PIX_FMT_NV42
as above, but U and V bytes are swapped
Definition: pixfmt.h:339
AV_PIX_FMT_RGB565
#define AV_PIX_FMT_RGB565
Definition: pixfmt.h:376
AV_PIX_FMT_GBRAP16LE
@ AV_PIX_FMT_GBRAP16LE
planar GBRA 4:4:4:4 64bpp, little-endian
Definition: pixfmt.h:207
AV_PIX_FMT_YVYU422
@ AV_PIX_FMT_YVYU422
packed YUV 4:2:2, 16bpp, Y0 Cr Y1 Cb
Definition: pixfmt.h:200
ff_sws_init_output_funcs
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
G
#define G
Definition: huffyuvdsp.h:33
bswap.h
AV_PIX_FMT_NV12
@ 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_P016LE
@ AV_PIX_FMT_P016LE
like NV12, with 16bpp per component, little-endian
Definition: pixfmt.h:290
yuv2p010lX_LE_c
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:518
AV_PIX_FMT_GRAYF32BE
@ AV_PIX_FMT_GRAYF32BE
IEEE-754 single precision Y, 32bpp, big-endian.
Definition: pixfmt.h:330
yuv2ya8_1_c
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
YUV2RGBWRAPPER
#define YUV2RGBWRAPPER(name, base, ext, fmt, hasAlpha)
Definition: output.c:1820
d128
const uint8_t * d128
Definition: yuv2rgb.c:553
AV_PIX_FMT_GBRP12BE
@ AV_PIX_FMT_GBRP12BE
planar GBR 4:4:4 36bpp, big-endian
Definition: pixfmt.h:244
AV_PIX_FMT_UYVY422
@ AV_PIX_FMT_UYVY422
packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
Definition: pixfmt.h:81
yuv2planarX_fn
void(* yuv2planarX_fn)(const int16_t *filter, int filterSize, const int16_t **src, uint8_t *dest, int dstW, const uint8_t *dither, int offset)
Write one line of horizontally scaled data to planar output with multi-point vertical scaling between...
Definition: swscale_internal.h:132
B
#define B
Definition: huffyuvdsp.h:32
yuv2packedX_fn
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...
Definition: swscale_internal.h:254
yuv2p010lX_BE_c
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:525
yuv2ya16_X_c_template
static av_always_inline void yuv2ya16_X_c_template(SwsContext *c, const int16_t *lumFilter, const int32_t **lumSrc, int lumFilterSize, const int16_t *chrFilter, const int32_t **unused_chrUSrc, const int32_t **unused_chrVSrc, int unused_chrFilterSize, const int32_t **alpSrc, uint16_t *dest, int dstW, int y, enum AVPixelFormat target, int unused_hasAlpha, int unused_eightbytes)
Definition: output.c:896
av_clip_uint8
#define av_clip_uint8
Definition: common.h:102
AV_PIX_FMT_RGB565BE
@ AV_PIX_FMT_RGB565BE
packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), big-endian
Definition: pixfmt.h:105
av_clip_uint16
#define av_clip_uint16
Definition: common.h:108
shift
static int shift(int a, int b)
Definition: sonic.c:83
AV_PIX_FMT_GBRP
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:158
desc
const char * desc
Definition: libsvtav1.c:79
d32
const uint8_t * d32
Definition: yuv2rgb.c:501
avutil.h
yuv2p016cX_c
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:183
AV_PIX_FMT_P010LE
@ AV_PIX_FMT_P010LE
like NV12, with 10bpp per component, data in the high bits, zeros in the low bits,...
Definition: pixfmt.h:274
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
AV_PIX_FMT_BGR555LE
@ AV_PIX_FMT_BGR555LE
packed BGR 5:5:5, 16bpp, (msb)1X 5B 5G 5R(lsb), little-endian, X=unused/undefined
Definition: pixfmt.h:113
yuv2rgb_1_c_template
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:1741
SWS_DITHER_AUTO
@ SWS_DITHER_AUTO
Definition: swscale_internal.h:72
B_R
#define B_R
Definition: output.c:887
AV_PIX_FMT_GBRP14LE
@ AV_PIX_FMT_GBRP14LE
planar GBR 4:4:4 42bpp, little-endian
Definition: pixfmt.h:247
int32_t
int32_t
Definition: audioconvert.c:56
yuv2rgb_2_c_template
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:1701
A1
#define A1
Definition: binkdsp.c:31
AV_PIX_FMT_GBRAP10BE
@ AV_PIX_FMT_GBRAP10BE
planar GBR 4:4:4:4 40bpp, big-endian
Definition: pixfmt.h:280
yuv2p010l1_BE_c
static void yuv2p010l1_BE_c(const int16_t *src, uint8_t *dest, int dstW, const uint8_t *dither, int offset)
Definition: output.c:511
yuv2rgba64_1_c_template
static av_always_inline void yuv2rgba64_1_c_template(SwsContext *c, const int32_t *buf0, const int32_t *ubuf[2], const int32_t *vbuf[2], const int32_t *abuf0, uint16_t *dest, int dstW, int uvalpha, int y, enum AVPixelFormat target, int hasAlpha, int eightbytes)
Definition: output.c:1139
yuv2rgba64_2_c_template
static av_always_inline void yuv2rgba64_2_c_template(SwsContext *c, const int32_t *buf[2], const int32_t *ubuf[2], const int32_t *vbuf[2], const int32_t *abuf[2], uint16_t *dest, int dstW, int yalpha, int uvalpha, int y, enum AVPixelFormat target, int hasAlpha, int eightbytes)
Definition: output.c:1074
SWS_DITHER_X_DITHER
@ SWS_DITHER_X_DITHER
Definition: swscale_internal.h:76
SwsContext
Definition: swscale_internal.h:300
AV_PIX_FMT_BGR444LE
@ AV_PIX_FMT_BGR444LE
packed BGR 4:4:4, 16bpp, (msb)4X 4B 4G 4R(lsb), little-endian, X=unused/undefined
Definition: pixfmt.h:131
yuv2rgb
static void yuv2rgb(uint8_t *out, int ridx, int Y, int U, int V)
Definition: g2meet.c:261
rgb2rgb.h
swscale.h
yuv2ayuv64le_X_c
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
ff_dither_2x2_8
const uint8_t ff_dither_2x2_8[][8]
Definition: output.c:45
AV_PIX_FMT_BGR48BE
@ AV_PIX_FMT_BGR48BE
packed RGB 16:16:16, 48bpp, 16B, 16G, 16R, the 2-byte value for each R/G/B component is stored as big...
Definition: pixfmt.h:138
AV_PIX_FMT_RGB444
#define AV_PIX_FMT_RGB444
Definition: pixfmt.h:378
dither
static const uint8_t dither[8][8]
Definition: vf_fspp.c:58