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