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