FFmpeg
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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 <stddef.h>
23 #include <stdint.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/intfloat.h"
31 #include "libavutil/intreadwrite.h"
32 #include "libavutil/mathematics.h"
33 #include "libavutil/mem_internal.h"
34 #include "libavutil/pixdesc.h"
35 #include "config.h"
36 #include "rgb2rgb.h"
37 #include "swscale.h"
38 #include "swscale_internal.h"
39 
40 DECLARE_ALIGNED(8, const uint8_t, ff_dither_2x2_4)[][8] = {
41 { 1, 3, 1, 3, 1, 3, 1, 3, },
42 { 2, 0, 2, 0, 2, 0, 2, 0, },
43 { 1, 3, 1, 3, 1, 3, 1, 3, },
44 };
45 
46 DECLARE_ALIGNED(8, const uint8_t, ff_dither_2x2_8)[][8] = {
47 { 6, 2, 6, 2, 6, 2, 6, 2, },
48 { 0, 4, 0, 4, 0, 4, 0, 4, },
49 { 6, 2, 6, 2, 6, 2, 6, 2, },
50 };
51 
52 DECLARE_ALIGNED(8, const uint8_t, ff_dither_4x4_16)[][8] = {
53 { 8, 4, 11, 7, 8, 4, 11, 7, },
54 { 2, 14, 1, 13, 2, 14, 1, 13, },
55 { 10, 6, 9, 5, 10, 6, 9, 5, },
56 { 0, 12, 3, 15, 0, 12, 3, 15, },
57 { 8, 4, 11, 7, 8, 4, 11, 7, },
58 };
59 
60 DECLARE_ALIGNED(8, const uint8_t, ff_dither_8x8_32)[][8] = {
61 { 17, 9, 23, 15, 16, 8, 22, 14, },
62 { 5, 29, 3, 27, 4, 28, 2, 26, },
63 { 21, 13, 19, 11, 20, 12, 18, 10, },
64 { 0, 24, 6, 30, 1, 25, 7, 31, },
65 { 16, 8, 22, 14, 17, 9, 23, 15, },
66 { 4, 28, 2, 26, 5, 29, 3, 27, },
67 { 20, 12, 18, 10, 21, 13, 19, 11, },
68 { 1, 25, 7, 31, 0, 24, 6, 30, },
69 { 17, 9, 23, 15, 16, 8, 22, 14, },
70 };
71 
72 DECLARE_ALIGNED(8, const uint8_t, ff_dither_8x8_73)[][8] = {
73 { 0, 55, 14, 68, 3, 58, 17, 72, },
74 { 37, 18, 50, 32, 40, 22, 54, 35, },
75 { 9, 64, 5, 59, 13, 67, 8, 63, },
76 { 46, 27, 41, 23, 49, 31, 44, 26, },
77 { 2, 57, 16, 71, 1, 56, 15, 70, },
78 { 39, 21, 52, 34, 38, 19, 51, 33, },
79 { 11, 66, 7, 62, 10, 65, 6, 60, },
80 { 48, 30, 43, 25, 47, 29, 42, 24, },
81 { 0, 55, 14, 68, 3, 58, 17, 72, },
82 };
83 
84 #if 1
85 DECLARE_ALIGNED(8, const uint8_t, ff_dither_8x8_220)[][8] = {
86 {117, 62, 158, 103, 113, 58, 155, 100, },
87 { 34, 199, 21, 186, 31, 196, 17, 182, },
88 {144, 89, 131, 76, 141, 86, 127, 72, },
89 { 0, 165, 41, 206, 10, 175, 52, 217, },
90 {110, 55, 151, 96, 120, 65, 162, 107, },
91 { 28, 193, 14, 179, 38, 203, 24, 189, },
92 {138, 83, 124, 69, 148, 93, 134, 79, },
93 { 7, 172, 48, 213, 3, 168, 45, 210, },
94 {117, 62, 158, 103, 113, 58, 155, 100, },
95 };
96 #elif 1
97 // tries to correct a gamma of 1.5
98 DECLARE_ALIGNED(8, const uint8_t, ff_dither_8x8_220)[][8] = {
99 { 0, 143, 18, 200, 2, 156, 25, 215, },
100 { 78, 28, 125, 64, 89, 36, 138, 74, },
101 { 10, 180, 3, 161, 16, 195, 8, 175, },
102 {109, 51, 93, 38, 121, 60, 105, 47, },
103 { 1, 152, 23, 210, 0, 147, 20, 205, },
104 { 85, 33, 134, 71, 81, 30, 130, 67, },
105 { 14, 190, 6, 171, 12, 185, 5, 166, },
106 {117, 57, 101, 44, 113, 54, 97, 41, },
107 { 0, 143, 18, 200, 2, 156, 25, 215, },
108 };
109 #elif 1
110 // tries to correct a gamma of 2.0
111 DECLARE_ALIGNED(8, const uint8_t, ff_dither_8x8_220)[][8] = {
112 { 0, 124, 8, 193, 0, 140, 12, 213, },
113 { 55, 14, 104, 42, 66, 19, 119, 52, },
114 { 3, 168, 1, 145, 6, 187, 3, 162, },
115 { 86, 31, 70, 21, 99, 39, 82, 28, },
116 { 0, 134, 11, 206, 0, 129, 9, 200, },
117 { 62, 17, 114, 48, 58, 16, 109, 45, },
118 { 5, 181, 2, 157, 4, 175, 1, 151, },
119 { 95, 36, 78, 26, 90, 34, 74, 24, },
120 { 0, 124, 8, 193, 0, 140, 12, 213, },
121 };
122 #else
123 // tries to correct a gamma of 2.5
124 DECLARE_ALIGNED(8, const uint8_t, ff_dither_8x8_220)[][8] = {
125 { 0, 107, 3, 187, 0, 125, 6, 212, },
126 { 39, 7, 86, 28, 49, 11, 102, 36, },
127 { 1, 158, 0, 131, 3, 180, 1, 151, },
128 { 68, 19, 52, 12, 81, 25, 64, 17, },
129 { 0, 119, 5, 203, 0, 113, 4, 195, },
130 { 45, 9, 96, 33, 42, 8, 91, 30, },
131 { 2, 172, 1, 144, 2, 165, 0, 137, },
132 { 77, 23, 60, 15, 72, 21, 56, 14, },
133 { 0, 107, 3, 187, 0, 125, 6, 212, },
134 };
135 #endif
136 
137 #define IS_BE_LE 0
138 #define IS_BE_BE 1
139 /* ENDIAN_IDENTIFIER needs to be "BE" or "LE". */
140 #define IS_BE(ENDIAN_IDENTIFIER) IS_BE_ ## ENDIAN_IDENTIFIER
141 
142 #define output_pixel(pos, val, bias, signedness) \
143  if (big_endian) { \
144  AV_WB16(pos, bias + av_clip_ ## signedness ## 16(val >> shift)); \
145  } else { \
146  AV_WL16(pos, bias + av_clip_ ## signedness ## 16(val >> shift)); \
147  }
148 
149 static av_always_inline void
150 yuv2plane1_16_c_template(const int32_t *src, uint16_t *dest, int dstW,
151  int big_endian, int output_bits)
152 {
153  int i;
154  int shift = 3;
155  av_assert0(output_bits == 16);
156 
157  for (i = 0; i < dstW; i++) {
158  int val = src[i] + (1 << (shift - 1));
159  output_pixel(&dest[i], val, 0, uint);
160  }
161 }
162 
163 static av_always_inline void
164 yuv2planeX_16_c_template(const int16_t *filter, int filterSize,
165  const int32_t **src, uint16_t *dest, int dstW,
166  int big_endian, int output_bits)
167 {
168  int i;
169  int shift = 15;
170  av_assert0(output_bits == 16);
171 
172  for (i = 0; i < dstW; i++) {
173  int val = 1 << (shift - 1);
174  int j;
175 
176  /* range of val is [0,0x7FFFFFFF], so 31 bits, but with lanczos/spline
177  * filters (or anything with negative coeffs, the range can be slightly
178  * wider in both directions. To account for this overflow, we subtract
179  * a constant so it always fits in the signed range (assuming a
180  * reasonable filterSize), and re-add that at the end. */
181  val -= 0x40000000;
182  for (j = 0; j < filterSize; j++)
183  val += src[j][i] * (unsigned)filter[j];
184 
185  output_pixel(&dest[i], val, 0x8000, int);
186  }
187 }
188 
189 static av_always_inline void
190 yuv2nv12cX_16_c_template(int big_endian, const uint8_t *chrDither,
191  const int16_t *chrFilter, int chrFilterSize,
192  const int16_t **chrUSrc, const int16_t **chrVSrc,
193  uint8_t *dest8, int chrDstW, int output_bits)
194 {
195  uint16_t *dest = (uint16_t*)dest8;
196  const int32_t **uSrc = (const int32_t **)chrUSrc;
197  const int32_t **vSrc = (const int32_t **)chrVSrc;
198  int shift = 15;
199  int i, j;
200  av_assert0(output_bits == 16);
201 
202  for (i = 0; i < chrDstW; i++) {
203  int u = 1 << (shift - 1);
204  int v = 1 << (shift - 1);
205 
206  /* See yuv2planeX_16_c_template for details. */
207  u -= 0x40000000;
208  v -= 0x40000000;
209  for (j = 0; j < chrFilterSize; j++) {
210  u += uSrc[j][i] * (unsigned)chrFilter[j];
211  v += vSrc[j][i] * (unsigned)chrFilter[j];
212  }
213 
214  output_pixel(&dest[2*i] , u, 0x8000, int);
215  output_pixel(&dest[2*i+1], v, 0x8000, int);
216  }
217 }
218 
219 static av_always_inline void
220 yuv2plane1_float_c_template(const int32_t *src, float *dest, int dstW)
221 {
222  static const int big_endian = HAVE_BIGENDIAN;
223  static const int shift = 3;
224  static const float float_mult = 1.0f / 65535.0f;
225  int i, val;
226  uint16_t val_uint;
227 
228  for (i = 0; i < dstW; ++i){
229  val = src[i] + (1 << (shift - 1));
230  output_pixel(&val_uint, val, 0, uint);
231  dest[i] = float_mult * (float)val_uint;
232  }
233 }
234 
235 static av_always_inline void
236 yuv2plane1_float_bswap_c_template(const int32_t *src, uint32_t *dest, int dstW)
237 {
238  static const int big_endian = HAVE_BIGENDIAN;
239  static const int shift = 3;
240  static const float float_mult = 1.0f / 65535.0f;
241  int i, val;
242  uint16_t val_uint;
243 
244  for (i = 0; i < dstW; ++i){
245  val = src[i] + (1 << (shift - 1));
246  output_pixel(&val_uint, val, 0, uint);
247  dest[i] = av_bswap32(av_float2int(float_mult * (float)val_uint));
248  }
249 }
250 
251 static av_always_inline void
252 yuv2planeX_float_c_template(const int16_t *filter, int filterSize, const int32_t **src,
253  float *dest, int dstW)
254 {
255  static const int big_endian = HAVE_BIGENDIAN;
256  static const int shift = 15;
257  static const float float_mult = 1.0f / 65535.0f;
258  int i, j, val;
259  uint16_t val_uint;
260 
261  for (i = 0; i < dstW; ++i){
262  val = (1 << (shift - 1)) - 0x40000000;
263  for (j = 0; j < filterSize; ++j){
264  val += src[j][i] * (unsigned)filter[j];
265  }
266  output_pixel(&val_uint, val, 0x8000, int);
267  dest[i] = float_mult * (float)val_uint;
268  }
269 }
270 
271 static av_always_inline void
272 yuv2planeX_float_bswap_c_template(const int16_t *filter, int filterSize, const int32_t **src,
273  uint32_t *dest, int dstW)
274 {
275  static const int big_endian = HAVE_BIGENDIAN;
276  static const int shift = 15;
277  static const float float_mult = 1.0f / 65535.0f;
278  int i, j, val;
279  uint16_t val_uint;
280 
281  for (i = 0; i < dstW; ++i){
282  val = (1 << (shift - 1)) - 0x40000000;
283  for (j = 0; j < filterSize; ++j){
284  val += src[j][i] * (unsigned)filter[j];
285  }
286  output_pixel(&val_uint, val, 0x8000, int);
287  dest[i] = av_bswap32(av_float2int(float_mult * (float)val_uint));
288  }
289 }
290 
291 #define yuv2plane1_float(template, dest_type, BE_LE) \
292 static void yuv2plane1_float ## BE_LE ## _c(const int16_t *src, uint8_t *dest, int dstW, \
293  const uint8_t *dither, int offset) \
294 { \
295  template((const int32_t *)src, (dest_type *)dest, dstW); \
296 }
297 
298 #define yuv2planeX_float(template, dest_type, BE_LE) \
299 static void yuv2planeX_float ## BE_LE ## _c(const int16_t *filter, int filterSize, \
300  const int16_t **src, uint8_t *dest, int dstW, \
301  const uint8_t *dither, int offset) \
302 { \
303  template(filter, filterSize, (const int32_t **)src, (dest_type *)dest, dstW); \
304 }
305 
306 #if HAVE_BIGENDIAN
311 #else
316 #endif
317 
318 #undef output_pixel
319 
320 #define output_pixel(pos, val) \
321  if (big_endian) { \
322  AV_WB16(pos, av_clip_uintp2(val >> shift, output_bits)); \
323  } else { \
324  AV_WL16(pos, av_clip_uintp2(val >> shift, output_bits)); \
325  }
326 
327 static av_always_inline void
328 yuv2plane1_10_c_template(const int16_t *src, uint16_t *dest, int dstW,
329  int big_endian, int output_bits)
330 {
331  int i;
332  int shift = 15 - output_bits;
333 
334  for (i = 0; i < dstW; i++) {
335  int val = src[i] + (1 << (shift - 1));
336  output_pixel(&dest[i], val);
337  }
338 }
339 
340 static av_always_inline void
341 yuv2planeX_10_c_template(const int16_t *filter, int filterSize,
342  const int16_t **src, uint16_t *dest, int dstW,
343  int big_endian, int output_bits)
344 {
345  int i;
346  int shift = 11 + 16 - output_bits;
347 
348  for (i = 0; i < dstW; i++) {
349  int val = 1 << (shift - 1);
350  int j;
351 
352  for (j = 0; j < filterSize; j++)
353  val += src[j][i] * filter[j];
354 
355  output_pixel(&dest[i], val);
356  }
357 }
358 
359 #undef output_pixel
360 
361 #define yuv2NBPS(bits, BE_LE, is_be, template_size, typeX_t) \
362 static void yuv2plane1_ ## bits ## BE_LE ## _c(const int16_t *src, \
363  uint8_t *dest, int dstW, \
364  const uint8_t *dither, int offset)\
365 { \
366  yuv2plane1_ ## template_size ## _c_template((const typeX_t *) src, \
367  (uint16_t *) dest, dstW, is_be, bits); \
368 }\
369 static void yuv2planeX_ ## bits ## BE_LE ## _c(const int16_t *filter, int filterSize, \
370  const int16_t **src, uint8_t *dest, int dstW, \
371  const uint8_t *dither, int offset)\
372 { \
373  yuv2planeX_## template_size ## _c_template(filter, \
374  filterSize, (const typeX_t **) src, \
375  (uint16_t *) dest, dstW, is_be, bits); \
376 }
377 
378 yuv2NBPS( 9, BE, 1, 10, int16_t)
379 yuv2NBPS( 9, LE, 0, 10, int16_t)
380 yuv2NBPS(10, BE, 1, 10, int16_t)
381 yuv2NBPS(10, LE, 0, 10, int16_t)
382 yuv2NBPS(12, BE, 1, 10, int16_t)
383 yuv2NBPS(12, LE, 0, 10, int16_t)
384 yuv2NBPS(14, BE, 1, 10, int16_t)
385 yuv2NBPS(14, LE, 0, 10, int16_t)
386 yuv2NBPS(16, BE, 1, 16, int32_t)
387 yuv2NBPS(16, LE, 0, 16, int32_t)
388 
389 
390 static void yuv2nv12cX_16LE_c(enum AVPixelFormat dstFormat, const uint8_t *chrDither,
391  const int16_t *chrFilter, int chrFilterSize,
392  const int16_t **chrUSrc, const int16_t **chrVSrc,
393  uint8_t *dest8, int chrDstW)
394 {
395  yuv2nv12cX_16_c_template(0, chrDither, chrFilter, chrFilterSize, chrUSrc, chrVSrc, dest8, chrDstW, 16);
396 }
397 
398 static void yuv2nv12cX_16BE_c(enum AVPixelFormat dstFormat, const uint8_t *chrDither,
399  const int16_t *chrFilter, int chrFilterSize,
400  const int16_t **chrUSrc, const int16_t **chrVSrc,
401  uint8_t *dest8, int chrDstW)
402 {
403  yuv2nv12cX_16_c_template(1, chrDither, chrFilter, chrFilterSize, chrUSrc, chrVSrc, dest8, chrDstW, 16);
404 }
405 
406 static void yuv2planeX_8_c(const int16_t *filter, int filterSize,
407  const int16_t **src, uint8_t *dest, int dstW,
408  const uint8_t *dither, int offset)
409 {
410  int i;
411  for (i=0; i<dstW; i++) {
412  int val = dither[(i + offset) & 7] << 12;
413  int j;
414  for (j=0; j<filterSize; j++)
415  val += src[j][i] * filter[j];
416 
417  dest[i]= av_clip_uint8(val>>19);
418  }
419 }
420 
421 static void yuv2plane1_8_c(const int16_t *src, uint8_t *dest, int dstW,
422  const uint8_t *dither, int offset)
423 {
424  int i;
425  for (i=0; i<dstW; i++) {
426  int val = (src[i] + dither[(i + offset) & 7]) >> 7;
427  dest[i]= av_clip_uint8(val);
428  }
429 }
430 
431 static void yuv2nv12cX_c(enum AVPixelFormat dstFormat, const uint8_t *chrDither,
432  const int16_t *chrFilter, int chrFilterSize,
433  const int16_t **chrUSrc, const int16_t **chrVSrc,
434  uint8_t *dest, int chrDstW)
435 {
436  int i;
437 
438  if (!isSwappedChroma(dstFormat))
439  for (i=0; i<chrDstW; i++) {
440  int u = chrDither[i & 7] << 12;
441  int v = chrDither[(i + 3) & 7] << 12;
442  int j;
443  for (j=0; j<chrFilterSize; j++) {
444  u += chrUSrc[j][i] * chrFilter[j];
445  v += chrVSrc[j][i] * chrFilter[j];
446  }
447 
448  dest[2*i]= av_clip_uint8(u>>19);
449  dest[2*i+1]= av_clip_uint8(v>>19);
450  }
451  else
452  for (i=0; i<chrDstW; i++) {
453  int u = chrDither[i & 7] << 12;
454  int v = chrDither[(i + 3) & 7] << 12;
455  int j;
456  for (j=0; j<chrFilterSize; j++) {
457  u += chrUSrc[j][i] * chrFilter[j];
458  v += chrVSrc[j][i] * chrFilter[j];
459  }
460 
461  dest[2*i]= av_clip_uint8(v>>19);
462  dest[2*i+1]= av_clip_uint8(u>>19);
463  }
464 }
465 
466 
467 #define output_pixel(pos, val) \
468  if (big_endian) { \
469  AV_WB16(pos, av_clip_uintp2(val >> shift, output_bits) << output_shift); \
470  } else { \
471  AV_WL16(pos, av_clip_uintp2(val >> shift, output_bits) << output_shift); \
472  }
473 
474 static void yuv2p01xl1_c(const int16_t *src,
475  uint16_t *dest, int dstW,
476  int big_endian, int output_bits, int output_shift)
477 {
478  int i;
479  int shift = 15 - output_bits;
480 
481  for (i = 0; i < dstW; i++) {
482  int val = src[i] + (1 << (shift - 1));
483  output_pixel(&dest[i], val);
484  }
485 }
486 
487 static void yuv2p01xlX_c(const int16_t *filter, int filterSize,
488  const int16_t **src, uint16_t *dest, int dstW,
489  int big_endian, int output_bits, int output_shift)
490 {
491  int i, j;
492  int shift = 11 + 16 - output_bits;
493 
494  for (i = 0; i < dstW; i++) {
495  int val = 1 << (shift - 1);
496 
497  for (j = 0; j < filterSize; j++)
498  val += src[j][i] * filter[j];
499 
500  output_pixel(&dest[i], val);
501  }
502 }
503 
504 static void yuv2p01xcX_c(int big_endian, const uint8_t *chrDither,
505  const int16_t *chrFilter, int chrFilterSize,
506  const int16_t **chrUSrc, const int16_t **chrVSrc,
507  uint8_t *dest8, int chrDstW, int output_bits, int output_shift)
508 {
509  uint16_t *dest = (uint16_t*)dest8;
510  int i, j;
511  int shift = 11 + 16 - output_bits;
512 
513  for (i = 0; i < chrDstW; i++) {
514  int u = 1 << (shift - 1);
515  int v = 1 << (shift - 1);
516 
517  for (j = 0; j < chrFilterSize; j++) {
518  u += chrUSrc[j][i] * chrFilter[j];
519  v += chrVSrc[j][i] * chrFilter[j];
520  }
521 
522  output_pixel(&dest[2*i] , u);
523  output_pixel(&dest[2*i+1], v);
524  }
525 }
526 
527 #undef output_pixel
528 
529 #define yuv2p01x_wrapper(fmt, bits, shift) \
530  static void yuv2 ## fmt ## l1_LE_c(const int16_t *src, \
531  uint8_t *dest, int dstW, \
532  const uint8_t *dither, int offset) \
533  { \
534  yuv2p01xl1_c(src, (uint16_t*)dest, dstW, 0, bits, shift); \
535  } \
536  \
537  static void yuv2 ## fmt ## l1_BE_c(const int16_t *src, \
538  uint8_t *dest, int dstW, \
539  const uint8_t *dither, int offset) \
540  { \
541  yuv2p01xl1_c(src, (uint16_t*)dest, dstW, 1, bits, shift); \
542  } \
543  \
544  static void yuv2 ## fmt ## lX_LE_c(const int16_t *filter, \
545  int filterSize, const int16_t **src, \
546  uint8_t *dest, int dstW, \
547  const uint8_t *dither, int offset) \
548  { \
549  yuv2p01xlX_c(filter, filterSize, src, (uint16_t*)dest, dstW, 0, \
550  bits, shift); \
551  } \
552  \
553  static void yuv2 ## fmt ## lX_BE_c(const int16_t *filter, \
554  int filterSize, const int16_t **src, \
555  uint8_t *dest, int dstW, \
556  const uint8_t *dither, int offset) \
557  { \
558  yuv2p01xlX_c(filter, filterSize, src, (uint16_t*)dest, dstW, 1, \
559  bits, shift); \
560  } \
561  \
562  static void yuv2 ## fmt ## cX_LE_c(enum AVPixelFormat dstFormat, \
563  const uint8_t *chrDither, \
564  const int16_t *chrFilter, \
565  int chrFilterSize, \
566  const int16_t **chrUSrc, \
567  const int16_t **chrVSrc, \
568  uint8_t *dest8, int chrDstW) \
569  { \
570  yuv2p01xcX_c(0, chrDither, chrFilter, chrFilterSize, chrUSrc, chrVSrc, \
571  dest8, chrDstW, bits, shift); \
572  } \
573  \
574  static void yuv2 ## fmt ## cX_BE_c(enum AVPixelFormat dstFormat, \
575  const uint8_t *chrDither, \
576  const int16_t *chrFilter, \
577  int chrFilterSize, \
578  const int16_t **chrUSrc, \
579  const int16_t **chrVSrc, \
580  uint8_t *dest8, int chrDstW) \
581  { \
582  yuv2p01xcX_c(1, chrDither, chrFilter, chrFilterSize, chrUSrc, chrVSrc, \
583  dest8, chrDstW, bits, shift); \
584  }
585 
586 yuv2p01x_wrapper(p010, 10, 6)
587 yuv2p01x_wrapper(p012, 12, 4)
588 yuv2p01x_wrapper(nv20, 10, 0)
589 
590 #define accumulate_bit(acc, val) \
591  acc <<= 1; \
592  acc |= (val) >= 234
593 #define output_pixel(pos, acc) \
594  if (target == AV_PIX_FMT_MONOBLACK) { \
595  pos = acc; \
596  } else { \
597  pos = ~acc; \
598  }
599 
600 static av_always_inline void
601 yuv2mono_X_c_template(SwsInternal *c, const int16_t *lumFilter,
602  const int16_t **lumSrc, int lumFilterSize,
603  const int16_t *chrFilter, const int16_t **chrUSrc,
604  const int16_t **chrVSrc, int chrFilterSize,
605  const int16_t **alpSrc, uint8_t *dest, int dstW,
606  int y, enum AVPixelFormat target)
607 {
608  const uint8_t * const d128 = ff_dither_8x8_220[y&7];
609  int i;
610  unsigned acc = 0;
611  int err = 0;
612 
613  for (i = 0; i < dstW; i += 2) {
614  int j;
615  int Y1 = 1 << 18;
616  int Y2 = 1 << 18;
617 
618  for (j = 0; j < lumFilterSize; j++) {
619  Y1 += lumSrc[j][i] * lumFilter[j];
620  Y2 += lumSrc[j][i+1] * lumFilter[j];
621  }
622  Y1 >>= 19;
623  Y2 >>= 19;
624  if ((Y1 | Y2) & 0x100) {
625  Y1 = av_clip_uint8(Y1);
626  Y2 = av_clip_uint8(Y2);
627  }
628  if (c->opts.dither == SWS_DITHER_ED) {
629  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;
630  c->dither_error[0][i] = err;
631  acc = 2*acc + (Y1 >= 128);
632  Y1 -= 220*(acc&1);
633 
634  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);
635  c->dither_error[0][i+1] = Y1;
636  acc = 2*acc + (err >= 128);
637  err -= 220*(acc&1);
638  } else {
639  accumulate_bit(acc, Y1 + d128[(i + 0) & 7]);
640  accumulate_bit(acc, Y2 + d128[(i + 1) & 7]);
641  }
642  if ((i & 7) == 6) {
643  output_pixel(*dest++, acc);
644  }
645  }
646  c->dither_error[0][i] = err;
647 
648  if (i & 6) {
649  output_pixel(*dest, acc);
650  }
651 }
652 
653 static av_always_inline void
654 yuv2mono_2_c_template(SwsInternal *c, const int16_t *buf[2],
655  const int16_t *ubuf[2], const int16_t *vbuf[2],
656  const int16_t *abuf[2], uint8_t *dest, int dstW,
657  int yalpha, int uvalpha, int y,
658  enum AVPixelFormat target)
659 {
660  const int16_t *buf0 = buf[0], *buf1 = buf[1];
661  const uint8_t * const d128 = ff_dither_8x8_220[y & 7];
662  int yalpha1 = 4096 - yalpha;
663  int i;
664  av_assert2(yalpha <= 4096U);
665 
666  if (c->opts.dither == SWS_DITHER_ED) {
667  int err = 0;
668  unsigned acc = 0;
669  for (i = 0; i < dstW; i +=2) {
670  int Y;
671 
672  Y = (buf0[i + 0] * yalpha1 + buf1[i + 0] * yalpha) >> 19;
673  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;
674  c->dither_error[0][i] = err;
675  acc = 2*acc + (Y >= 128);
676  Y -= 220*(acc&1);
677 
678  err = (buf0[i + 1] * yalpha1 + buf1[i + 1] * yalpha) >> 19;
679  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;
680  c->dither_error[0][i+1] = Y;
681  acc = 2*acc + (err >= 128);
682  err -= 220*(acc&1);
683 
684  if ((i & 7) == 6)
685  output_pixel(*dest++, acc);
686  }
687  c->dither_error[0][i] = err;
688  } else {
689  for (i = 0; i < dstW; i += 8) {
690  int Y;
691  unsigned acc = 0;
692 
693  Y = (buf0[i + 0] * yalpha1 + buf1[i + 0] * yalpha) >> 19;
694  accumulate_bit(acc, Y + d128[0]);
695  Y = (buf0[i + 1] * yalpha1 + buf1[i + 1] * yalpha) >> 19;
696  accumulate_bit(acc, Y + d128[1]);
697  Y = (buf0[i + 2] * yalpha1 + buf1[i + 2] * yalpha) >> 19;
698  accumulate_bit(acc, Y + d128[2]);
699  Y = (buf0[i + 3] * yalpha1 + buf1[i + 3] * yalpha) >> 19;
700  accumulate_bit(acc, Y + d128[3]);
701  Y = (buf0[i + 4] * yalpha1 + buf1[i + 4] * yalpha) >> 19;
702  accumulate_bit(acc, Y + d128[4]);
703  Y = (buf0[i + 5] * yalpha1 + buf1[i + 5] * yalpha) >> 19;
704  accumulate_bit(acc, Y + d128[5]);
705  Y = (buf0[i + 6] * yalpha1 + buf1[i + 6] * yalpha) >> 19;
706  accumulate_bit(acc, Y + d128[6]);
707  Y = (buf0[i + 7] * yalpha1 + buf1[i + 7] * yalpha) >> 19;
708  accumulate_bit(acc, Y + d128[7]);
709 
710  output_pixel(*dest++, acc);
711  }
712  }
713 }
714 
715 static av_always_inline void
716 yuv2mono_1_c_template(SwsInternal *c, const int16_t *buf0,
717  const int16_t *ubuf[2], const int16_t *vbuf[2],
718  const int16_t *abuf0, uint8_t *dest, int dstW,
719  int uvalpha, int y, enum AVPixelFormat target)
720 {
721  const uint8_t * const d128 = ff_dither_8x8_220[y & 7];
722  int i;
723 
724  if (c->opts.dither == SWS_DITHER_ED) {
725  int err = 0;
726  unsigned acc = 0;
727  for (i = 0; i < dstW; i +=2) {
728  int Y;
729 
730  Y = ((buf0[i + 0] + 64) >> 7);
731  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;
732  c->dither_error[0][i] = err;
733  acc = 2*acc + (Y >= 128);
734  Y -= 220*(acc&1);
735 
736  err = ((buf0[i + 1] + 64) >> 7);
737  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;
738  c->dither_error[0][i+1] = Y;
739  acc = 2*acc + (err >= 128);
740  err -= 220*(acc&1);
741 
742  if ((i & 7) == 6)
743  output_pixel(*dest++, acc);
744  }
745  c->dither_error[0][i] = err;
746  } else {
747  for (i = 0; i < dstW; i += 8) {
748  unsigned acc = 0;
749  accumulate_bit(acc, ((buf0[i + 0] + 64) >> 7) + d128[0]);
750  accumulate_bit(acc, ((buf0[i + 1] + 64) >> 7) + d128[1]);
751  accumulate_bit(acc, ((buf0[i + 2] + 64) >> 7) + d128[2]);
752  accumulate_bit(acc, ((buf0[i + 3] + 64) >> 7) + d128[3]);
753  accumulate_bit(acc, ((buf0[i + 4] + 64) >> 7) + d128[4]);
754  accumulate_bit(acc, ((buf0[i + 5] + 64) >> 7) + d128[5]);
755  accumulate_bit(acc, ((buf0[i + 6] + 64) >> 7) + d128[6]);
756  accumulate_bit(acc, ((buf0[i + 7] + 64) >> 7) + d128[7]);
757 
758  output_pixel(*dest++, acc);
759  }
760  }
761 }
762 
763 #undef output_pixel
764 #undef accumulate_bit
765 
766 #define YUV2PACKEDWRAPPER(name, base, ext, fmt) \
767 static void name ## ext ## _X_c(SwsInternal *c, const int16_t *lumFilter, \
768  const int16_t **lumSrc, int lumFilterSize, \
769  const int16_t *chrFilter, const int16_t **chrUSrc, \
770  const int16_t **chrVSrc, int chrFilterSize, \
771  const int16_t **alpSrc, uint8_t *dest, int dstW, \
772  int y) \
773 { \
774  name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
775  chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
776  alpSrc, dest, dstW, y, fmt); \
777 } \
778  \
779 static void name ## ext ## _2_c(SwsInternal *c, const int16_t *buf[2], \
780  const int16_t *ubuf[2], const int16_t *vbuf[2], \
781  const int16_t *abuf[2], uint8_t *dest, int dstW, \
782  int yalpha, int uvalpha, int y) \
783 { \
784  name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
785  dest, dstW, yalpha, uvalpha, y, fmt); \
786 } \
787  \
788 static void name ## ext ## _1_c(SwsInternal *c, const int16_t *buf0, \
789  const int16_t *ubuf[2], const int16_t *vbuf[2], \
790  const int16_t *abuf0, uint8_t *dest, int dstW, \
791  int uvalpha, int y) \
792 { \
793  name ## base ## _1_c_template(c, buf0, ubuf, vbuf, \
794  abuf0, dest, dstW, uvalpha, \
795  y, fmt); \
796 }
797 
798 YUV2PACKEDWRAPPER(yuv2mono,, white, AV_PIX_FMT_MONOWHITE)
799 YUV2PACKEDWRAPPER(yuv2mono,, black, AV_PIX_FMT_MONOBLACK)
800 
801 #define output_pixels(pos, Y1, U, Y2, V) \
802  if (target == AV_PIX_FMT_YUYV422) { \
803  dest[pos + 0] = Y1; \
804  dest[pos + 1] = U; \
805  dest[pos + 2] = Y2; \
806  dest[pos + 3] = V; \
807  } else if (target == AV_PIX_FMT_YVYU422) { \
808  dest[pos + 0] = Y1; \
809  dest[pos + 1] = V; \
810  dest[pos + 2] = Y2; \
811  dest[pos + 3] = U; \
812  } else { /* AV_PIX_FMT_UYVY422 */ \
813  dest[pos + 0] = U; \
814  dest[pos + 1] = Y1; \
815  dest[pos + 2] = V; \
816  dest[pos + 3] = Y2; \
817  }
818 
819 static av_always_inline void
820 yuv2422_X_c_template(SwsInternal *c, const int16_t *lumFilter,
821  const int16_t **lumSrc, int lumFilterSize,
822  const int16_t *chrFilter, const int16_t **chrUSrc,
823  const int16_t **chrVSrc, int chrFilterSize,
824  const int16_t **alpSrc, uint8_t *dest, int dstW,
825  int y, enum AVPixelFormat target)
826 {
827  int i;
828 
829  for (i = 0; i < ((dstW + 1) >> 1); i++) {
830  int j;
831  int Y1 = 1 << 18;
832  int Y2 = 1 << 18;
833  int U = 1 << 18;
834  int V = 1 << 18;
835 
836  for (j = 0; j < lumFilterSize; j++) {
837  Y1 += lumSrc[j][i * 2] * lumFilter[j];
838  Y2 += lumSrc[j][i * 2 + 1] * lumFilter[j];
839  }
840  for (j = 0; j < chrFilterSize; j++) {
841  U += chrUSrc[j][i] * chrFilter[j];
842  V += chrVSrc[j][i] * chrFilter[j];
843  }
844  Y1 >>= 19;
845  Y2 >>= 19;
846  U >>= 19;
847  V >>= 19;
848  if ((Y1 | Y2 | U | V) & 0x100) {
849  Y1 = av_clip_uint8(Y1);
850  Y2 = av_clip_uint8(Y2);
851  U = av_clip_uint8(U);
852  V = av_clip_uint8(V);
853  }
854  output_pixels(4*i, Y1, U, Y2, V);
855  }
856 }
857 
858 static av_always_inline void
859 yuv2422_2_c_template(SwsInternal *c, const int16_t *buf[2],
860  const int16_t *ubuf[2], const int16_t *vbuf[2],
861  const int16_t *abuf[2], uint8_t *dest, int dstW,
862  int yalpha, int uvalpha, int y,
863  enum AVPixelFormat target)
864 {
865  const int16_t *buf0 = buf[0], *buf1 = buf[1],
866  *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
867  *vbuf0 = vbuf[0], *vbuf1 = vbuf[1];
868  int yalpha1 = 4096 - yalpha;
869  int uvalpha1 = 4096 - uvalpha;
870  int i;
871  av_assert2(yalpha <= 4096U);
872  av_assert2(uvalpha <= 4096U);
873 
874  for (i = 0; i < ((dstW + 1) >> 1); i++) {
875  int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 19;
876  int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 19;
877  int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha) >> 19;
878  int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha) >> 19;
879 
880  if ((Y1 | Y2 | U | V) & 0x100) {
881  Y1 = av_clip_uint8(Y1);
882  Y2 = av_clip_uint8(Y2);
883  U = av_clip_uint8(U);
884  V = av_clip_uint8(V);
885  }
886 
887  output_pixels(i * 4, Y1, U, Y2, V);
888  }
889 }
890 
891 static av_always_inline void
892 yuv2422_1_c_template(SwsInternal *c, const int16_t *buf0,
893  const int16_t *ubuf[2], const int16_t *vbuf[2],
894  const int16_t *abuf0, uint8_t *dest, int dstW,
895  int uvalpha, int y, enum AVPixelFormat target)
896 {
897  const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
898  int i;
899 
900  if (uvalpha < 2048) {
901  for (i = 0; i < ((dstW + 1) >> 1); i++) {
902  int Y1 = (buf0[i * 2 ]+64) >> 7;
903  int Y2 = (buf0[i * 2 + 1]+64) >> 7;
904  int U = (ubuf0[i] +64) >> 7;
905  int V = (vbuf0[i] +64) >> 7;
906 
907  if ((Y1 | Y2 | U | V) & 0x100) {
908  Y1 = av_clip_uint8(Y1);
909  Y2 = av_clip_uint8(Y2);
910  U = av_clip_uint8(U);
911  V = av_clip_uint8(V);
912  }
913 
914  output_pixels(i * 4, Y1, U, Y2, V);
915  }
916  } else {
917  const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
918  for (i = 0; i < ((dstW + 1) >> 1); i++) {
919  int Y1 = (buf0[i * 2 ] + 64) >> 7;
920  int Y2 = (buf0[i * 2 + 1] + 64) >> 7;
921  int U = (ubuf0[i] + ubuf1[i]+128) >> 8;
922  int V = (vbuf0[i] + vbuf1[i]+128) >> 8;
923 
924  if ((Y1 | Y2 | U | V) & 0x100) {
925  Y1 = av_clip_uint8(Y1);
926  Y2 = av_clip_uint8(Y2);
927  U = av_clip_uint8(U);
928  V = av_clip_uint8(V);
929  }
930 
931  output_pixels(i * 4, Y1, U, Y2, V);
932  }
933  }
934 }
935 
936 #undef output_pixels
937 
938 YUV2PACKEDWRAPPER(yuv2, 422, yuyv422, AV_PIX_FMT_YUYV422)
939 YUV2PACKEDWRAPPER(yuv2, 422, yvyu422, AV_PIX_FMT_YVYU422)
940 YUV2PACKEDWRAPPER(yuv2, 422, uyvy422, AV_PIX_FMT_UYVY422)
941 
942 #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)
943 #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)
944 #define output_pixel(pos, val) \
945  if (is_be) { \
946  AV_WB16(pos, val); \
947  } else { \
948  AV_WL16(pos, val); \
949  }
950 
951 static av_always_inline void
952 yuv2ya16_X_c_template(SwsInternal *c, const int16_t *lumFilter,
953  const int32_t **lumSrc, int lumFilterSize,
954  const int16_t *chrFilter, const int32_t **unused_chrUSrc,
955  const int32_t **unused_chrVSrc, int unused_chrFilterSize,
956  const int32_t **alpSrc, uint16_t *dest, int dstW,
957  int y, enum AVPixelFormat target,
958  int unused_hasAlpha, int unused_eightbytes, int is_be)
959 {
960  int hasAlpha = !!alpSrc;
961  int i;
962 
963  for (i = 0; i < dstW; i++) {
964  int j;
965  int Y = -0x40000000;
966  int A = 0xffff;
967 
968  for (j = 0; j < lumFilterSize; j++)
969  Y += lumSrc[j][i] * lumFilter[j];
970 
971  Y >>= 15;
972  Y += (1<<3) + 0x8000;
973  Y = av_clip_uint16(Y);
974 
975  if (hasAlpha) {
976  A = -0x40000000 + (1<<14);
977  for (j = 0; j < lumFilterSize; j++)
978  A += alpSrc[j][i] * lumFilter[j];
979 
980  A >>= 15;
981  A += 0x8000;
982  A = av_clip_uint16(A);
983  }
984 
985  output_pixel(&dest[2 * i ], Y);
986  output_pixel(&dest[2 * i + 1], A);
987  }
988 }
989 
990 static av_always_inline void
992  const int32_t *unused_ubuf[2], const int32_t *unused_vbuf[2],
993  const int32_t *abuf[2], uint16_t *dest, int dstW,
994  int yalpha, int unused_uvalpha, int y,
995  enum AVPixelFormat target, int unused_hasAlpha,
996  int unused_eightbytes, int is_be)
997 {
998  int hasAlpha = abuf && abuf[0] && abuf[1];
999  const int32_t *buf0 = buf[0], *buf1 = buf[1],
1000  *abuf0 = hasAlpha ? abuf[0] : NULL,
1001  *abuf1 = hasAlpha ? abuf[1] : NULL;
1002  int yalpha1 = 4096 - yalpha;
1003  int i;
1004 
1005  av_assert2(yalpha <= 4096U);
1006 
1007  for (i = 0; i < dstW; i++) {
1008  int Y = (buf0[i] * yalpha1 + buf1[i] * yalpha) >> 15;
1009  int A;
1010 
1011  Y = av_clip_uint16(Y);
1012 
1013  if (hasAlpha) {
1014  A = (abuf0[i] * yalpha1 + abuf1[i] * yalpha) >> 15;
1015  A = av_clip_uint16(A);
1016  }
1017 
1018  output_pixel(&dest[2 * i ], Y);
1019  output_pixel(&dest[2 * i + 1], hasAlpha ? A : 65535);
1020  }
1021 }
1022 
1023 static av_always_inline void
1025  const int32_t *unused_ubuf[2], const int32_t *unused_vbuf[2],
1026  const int32_t *abuf0, uint16_t *dest, int dstW,
1027  int unused_uvalpha, int y, enum AVPixelFormat target,
1028  int unused_hasAlpha, int unused_eightbytes, int is_be)
1029 {
1030  int hasAlpha = !!abuf0;
1031  int i;
1032 
1033  for (i = 0; i < dstW; i++) {
1034  int Y = buf0[i] >> 3;/* 19 - 16 */
1035  int A;
1036 
1037  Y = av_clip_uint16(Y);
1038 
1039  if (hasAlpha) {
1040  A = abuf0[i] >> 3;
1041  if (A & 0x100)
1042  A = av_clip_uint16(A);
1043  }
1044 
1045  output_pixel(&dest[2 * i ], Y);
1046  output_pixel(&dest[2 * i + 1], hasAlpha ? A : 65535);
1047  }
1048 }
1049 
1050 static av_always_inline void
1051 yuv2rgba64_X_c_template(SwsInternal *c, const int16_t *lumFilter,
1052  const int32_t **lumSrc, int lumFilterSize,
1053  const int16_t *chrFilter, const int32_t **chrUSrc,
1054  const int32_t **chrVSrc, int chrFilterSize,
1055  const int32_t **alpSrc, uint16_t *dest, int dstW,
1056  int y, enum AVPixelFormat target, int hasAlpha, int eightbytes,
1057  int is_be)
1058 {
1059  int i;
1060  int A1 = 0xffff<<14, A2 = 0xffff<<14;
1061 
1062  for (i = 0; i < ((dstW + 1) >> 1); i++) {
1063  int j;
1064  unsigned Y1 = -0x40000000;
1065  unsigned Y2 = -0x40000000;
1066  int U = -(128 << 23); // 19
1067  int V = -(128 << 23);
1068  int R, G, B;
1069 
1070  for (j = 0; j < lumFilterSize; j++) {
1071  Y1 += lumSrc[j][i * 2] * (unsigned)lumFilter[j];
1072  Y2 += lumSrc[j][i * 2 + 1] * (unsigned)lumFilter[j];
1073  }
1074  for (j = 0; j < chrFilterSize; j++) {;
1075  U += chrUSrc[j][i] * (unsigned)chrFilter[j];
1076  V += chrVSrc[j][i] * (unsigned)chrFilter[j];
1077  }
1078 
1079  if (hasAlpha) {
1080  A1 = -0x40000000;
1081  A2 = -0x40000000;
1082  for (j = 0; j < lumFilterSize; j++) {
1083  A1 += alpSrc[j][i * 2] * (unsigned)lumFilter[j];
1084  A2 += alpSrc[j][i * 2 + 1] * (unsigned)lumFilter[j];
1085  }
1086  A1 >>= 1;
1087  A1 += 0x20002000;
1088  A2 >>= 1;
1089  A2 += 0x20002000;
1090  }
1091 
1092  // 8 bits: 12+15=27; 16 bits: 12+19=31
1093  Y1 = (int)Y1 >> 14; // 10
1094  Y1 += 0x10000;
1095  Y2 = (int)Y2 >> 14;
1096  Y2 += 0x10000;
1097  U >>= 14;
1098  V >>= 14;
1099 
1100  // 8 bits: 27 -> 17 bits, 16 bits: 31 - 14 = 17 bits
1101  Y1 -= c->yuv2rgb_y_offset;
1102  Y2 -= c->yuv2rgb_y_offset;
1103  Y1 *= c->yuv2rgb_y_coeff;
1104  Y2 *= c->yuv2rgb_y_coeff;
1105  Y1 += (1 << 13) - (1 << 29); // 21
1106  Y2 += (1 << 13) - (1 << 29);
1107  // 8 bits: 17 + 13 bits = 30 bits, 16 bits: 17 + 13 bits = 30 bits
1108 
1109  R = V * c->yuv2rgb_v2r_coeff;
1110  G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
1111  B = U * c->yuv2rgb_u2b_coeff;
1112 
1113  // 8 bits: 30 - 22 = 8 bits, 16 bits: 30 bits - 14 = 16 bits
1114  output_pixel(&dest[0], av_clip_uintp2(((int)(R_B + Y1) >> 14) + (1<<15), 16));
1115  output_pixel(&dest[1], av_clip_uintp2(((int)( G + Y1) >> 14) + (1<<15), 16));
1116  output_pixel(&dest[2], av_clip_uintp2(((int)(B_R + Y1) >> 14) + (1<<15), 16));
1117  if (eightbytes) {
1118  output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14);
1119  output_pixel(&dest[4], av_clip_uintp2(((int)(R_B + Y2) >> 14) + (1<<15), 16));
1120  output_pixel(&dest[5], av_clip_uintp2(((int)( G + Y2) >> 14) + (1<<15), 16));
1121  output_pixel(&dest[6], av_clip_uintp2(((int)(B_R + Y2) >> 14) + (1<<15), 16));
1122  output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14);
1123  dest += 8;
1124  } else {
1125  output_pixel(&dest[3], av_clip_uintp2(((int)(R_B + Y2) >> 14) + (1<<15), 16));
1126  output_pixel(&dest[4], av_clip_uintp2(((int)( G + Y2) >> 14) + (1<<15), 16));
1127  output_pixel(&dest[5], av_clip_uintp2(((int)(B_R + Y2) >> 14) + (1<<15), 16));
1128  dest += 6;
1129  }
1130  }
1131 }
1132 
1133 static av_always_inline void
1135  const int32_t *ubuf[2], const int32_t *vbuf[2],
1136  const int32_t *abuf[2], uint16_t *dest, int dstW,
1137  int yalpha, int uvalpha, int y,
1138  enum AVPixelFormat target, int hasAlpha, int eightbytes,
1139  int is_be)
1140 {
1141  const int32_t *buf0 = buf[0], *buf1 = buf[1],
1142  *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
1143  *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
1144  *abuf0 = hasAlpha ? abuf[0] : NULL,
1145  *abuf1 = hasAlpha ? abuf[1] : NULL;
1146  int yalpha1 = 4096 - yalpha;
1147  int uvalpha1 = 4096 - uvalpha;
1148  int i;
1149  int A1 = 0xffff<<14, A2 = 0xffff<<14;
1150 
1151  av_assert2(yalpha <= 4096U);
1152  av_assert2(uvalpha <= 4096U);
1153 
1154  for (i = 0; i < ((dstW + 1) >> 1); i++) {
1155  unsigned Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 14;
1156  unsigned Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 14;
1157  int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha - (128 << 23)) >> 14;
1158  int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha - (128 << 23)) >> 14;
1159  int R, G, B;
1160 
1161  Y1 -= c->yuv2rgb_y_offset;
1162  Y2 -= c->yuv2rgb_y_offset;
1163  Y1 *= c->yuv2rgb_y_coeff;
1164  Y2 *= c->yuv2rgb_y_coeff;
1165  Y1 += (1 << 13) - (1 << 29);
1166  Y2 += (1 << 13) - (1 << 29);
1167 
1168  R = V * c->yuv2rgb_v2r_coeff;
1169  G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
1170  B = U * c->yuv2rgb_u2b_coeff;
1171 
1172  if (hasAlpha) {
1173  A1 = (abuf0[i * 2 ] * yalpha1 + abuf1[i * 2 ] * yalpha) >> 1;
1174  A2 = (abuf0[i * 2 + 1] * yalpha1 + abuf1[i * 2 + 1] * yalpha) >> 1;
1175 
1176  A1 += 1 << 13;
1177  A2 += 1 << 13;
1178  }
1179 
1180  output_pixel(&dest[0], av_clip_uintp2(((int)(R_B + Y1) >> 14) + (1<<15), 16));
1181  output_pixel(&dest[1], av_clip_uintp2(((int)( G + Y1) >> 14) + (1<<15), 16));
1182  output_pixel(&dest[2], av_clip_uintp2(((int)(B_R + Y1) >> 14) + (1<<15), 16));
1183  if (eightbytes) {
1184  output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14);
1185  output_pixel(&dest[4], av_clip_uintp2(((int)(R_B + Y2) >> 14) + (1<<15), 16));
1186  output_pixel(&dest[5], av_clip_uintp2(((int)( G + Y2) >> 14) + (1<<15), 16));
1187  output_pixel(&dest[6], av_clip_uintp2(((int)(B_R + Y2) >> 14) + (1<<15), 16));
1188  output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14);
1189  dest += 8;
1190  } else {
1191  output_pixel(&dest[3], av_clip_uintp2(((int)(R_B + Y2) >> 14) + (1<<15), 16));
1192  output_pixel(&dest[4], av_clip_uintp2(((int)( G + Y2) >> 14) + (1<<15), 16));
1193  output_pixel(&dest[5], av_clip_uintp2(((int)(B_R + Y2) >> 14) + (1<<15), 16));
1194  dest += 6;
1195  }
1196  }
1197 }
1198 
1199 static av_always_inline void
1201  const int32_t *ubuf[2], const int32_t *vbuf[2],
1202  const int32_t *abuf0, uint16_t *dest, int dstW,
1203  int uvalpha, int y, enum AVPixelFormat target,
1204  int hasAlpha, int eightbytes, int is_be)
1205 {
1206  const int32_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
1207  int i;
1208  int A1 = 0xffff<<14, A2= 0xffff<<14;
1209 
1210  if (uvalpha == 0) {
1211  for (i = 0; i < ((dstW + 1) >> 1); i++) {
1212  SUINT Y1 = (buf0[i * 2] ) >> 2;
1213  SUINT Y2 = (buf0[i * 2 + 1]) >> 2;
1214  int U = (ubuf0[i] - (128 << 11)) >> 2;
1215  int V = (vbuf0[i] - (128 << 11)) >> 2;
1216  int R, G, B;
1217 
1218  Y1 -= c->yuv2rgb_y_offset;
1219  Y2 -= c->yuv2rgb_y_offset;
1220  Y1 *= c->yuv2rgb_y_coeff;
1221  Y2 *= c->yuv2rgb_y_coeff;
1222  Y1 += (1 << 13) - (1 << 29);
1223  Y2 += (1 << 13) - (1 << 29);
1224 
1225  if (hasAlpha) {
1226  A1 = abuf0[i * 2 ] * (1 << 11);
1227  A2 = abuf0[i * 2 + 1] * (1 << 11);
1228 
1229  A1 += 1 << 13;
1230  A2 += 1 << 13;
1231  }
1232 
1233  R = V * c->yuv2rgb_v2r_coeff;
1234  G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
1235  B = U * c->yuv2rgb_u2b_coeff;
1236 
1237  output_pixel(&dest[0], av_clip_uintp2(((int)(R_B + Y1) >> 14) + (1<<15), 16));
1238  output_pixel(&dest[1], av_clip_uintp2(((int)( G + Y1) >> 14) + (1<<15), 16));
1239  output_pixel(&dest[2], av_clip_uintp2(((int)(B_R + Y1) >> 14) + (1<<15), 16));
1240  if (eightbytes) {
1241  output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14);
1242  output_pixel(&dest[4], av_clip_uintp2(((int)(R_B + Y2) >> 14) + (1<<15), 16));
1243  output_pixel(&dest[5], av_clip_uintp2(((int)( G + Y2) >> 14) + (1<<15), 16));
1244  output_pixel(&dest[6], av_clip_uintp2(((int)(B_R + Y2) >> 14) + (1<<15), 16));
1245  output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14);
1246  dest += 8;
1247  } else {
1248  output_pixel(&dest[3], av_clip_uintp2(((int)(R_B + Y2) >> 14) + (1<<15), 16));
1249  output_pixel(&dest[4], av_clip_uintp2(((int)( G + Y2) >> 14) + (1<<15), 16));
1250  output_pixel(&dest[5], av_clip_uintp2(((int)(B_R + Y2) >> 14) + (1<<15), 16));
1251  dest += 6;
1252  }
1253  }
1254  } else {
1255  const int32_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
1256  int A1 = 0xffff<<14, A2 = 0xffff<<14;
1257  int uvalpha1 = 4096 - uvalpha;
1258  av_assert2(uvalpha <= 4096U);
1259 
1260  for (i = 0; i < ((dstW + 1) >> 1); i++) {
1261  SUINT Y1 = (buf0[i * 2] ) >> 2;
1262  SUINT Y2 = (buf0[i * 2 + 1]) >> 2;
1263  int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha - (128 << 23)) >> 14;
1264  int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha - (128 << 23)) >> 14;
1265  int R, G, B;
1266 
1267  Y1 -= c->yuv2rgb_y_offset;
1268  Y2 -= c->yuv2rgb_y_offset;
1269  Y1 *= c->yuv2rgb_y_coeff;
1270  Y2 *= c->yuv2rgb_y_coeff;
1271  Y1 += (1 << 13) - (1 << 29);
1272  Y2 += (1 << 13) - (1 << 29);
1273 
1274  if (hasAlpha) {
1275  A1 = abuf0[i * 2 ] * (1 << 11);
1276  A2 = abuf0[i * 2 + 1] * (1 << 11);
1277 
1278  A1 += 1 << 13;
1279  A2 += 1 << 13;
1280  }
1281 
1282  R = V * c->yuv2rgb_v2r_coeff;
1283  G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
1284  B = U * c->yuv2rgb_u2b_coeff;
1285 
1286  output_pixel(&dest[0], av_clip_uintp2(((int)(R_B + Y1) >> 14) + (1<<15), 16));
1287  output_pixel(&dest[1], av_clip_uintp2(((int)( G + Y1) >> 14) + (1<<15), 16));
1288  output_pixel(&dest[2], av_clip_uintp2(((int)(B_R + Y1) >> 14) + (1<<15), 16));
1289  if (eightbytes) {
1290  output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14);
1291  output_pixel(&dest[4], av_clip_uintp2(((int)(R_B + Y2) >> 14) + (1<<15), 16));
1292  output_pixel(&dest[5], av_clip_uintp2(((int)( G + Y2) >> 14) + (1<<15), 16));
1293  output_pixel(&dest[6], av_clip_uintp2(((int)(B_R + Y2) >> 14) + (1<<15), 16));
1294  output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14);
1295  dest += 8;
1296  } else {
1297  output_pixel(&dest[3], av_clip_uintp2(((int)(R_B + Y2) >> 14) + (1<<15), 16));
1298  output_pixel(&dest[4], av_clip_uintp2(((int)( G + Y2) >> 14) + (1<<15), 16));
1299  output_pixel(&dest[5], av_clip_uintp2(((int)(B_R + Y2) >> 14) + (1<<15), 16));
1300  dest += 6;
1301  }
1302  }
1303  }
1304 }
1305 
1306 static av_always_inline void
1307 yuv2rgba64_full_X_c_template(SwsInternal *c, const int16_t *lumFilter,
1308  const int32_t **lumSrc, int lumFilterSize,
1309  const int16_t *chrFilter, const int32_t **chrUSrc,
1310  const int32_t **chrVSrc, int chrFilterSize,
1311  const int32_t **alpSrc, uint16_t *dest, int dstW,
1312  int y, enum AVPixelFormat target, int hasAlpha,
1313  int eightbytes, int is_be)
1314 {
1315  int i;
1316  int A = 0xffff<<14;
1317 
1318  for (i = 0; i < dstW; i++) {
1319  int j;
1320  int Y = -0x40000000;
1321  int U = -(128 << 23); // 19
1322  int V = -(128 << 23);
1323  int R, G, B;
1324 
1325  for (j = 0; j < lumFilterSize; j++) {
1326  Y += lumSrc[j][i] * (unsigned)lumFilter[j];
1327  }
1328  for (j = 0; j < chrFilterSize; j++) {;
1329  U += chrUSrc[j][i] * (unsigned)chrFilter[j];
1330  V += chrVSrc[j][i] * (unsigned)chrFilter[j];
1331  }
1332 
1333  if (hasAlpha) {
1334  A = -0x40000000;
1335  for (j = 0; j < lumFilterSize; j++) {
1336  A += alpSrc[j][i] * (unsigned)lumFilter[j];
1337  }
1338  A >>= 1;
1339  A += 0x20002000;
1340  }
1341 
1342  // 8bit: 12+15=27; 16-bit: 12+19=31
1343  Y >>= 14; // 10
1344  Y += 0x10000;
1345  U >>= 14;
1346  V >>= 14;
1347 
1348  // 8bit: 27 -> 17bit, 16bit: 31 - 14 = 17bit
1349  Y -= c->yuv2rgb_y_offset;
1350  Y *= c->yuv2rgb_y_coeff;
1351  Y += (1 << 13) - (1<<29); // 21
1352  // 8bit: 17 + 13bit = 30bit, 16bit: 17 + 13bit = 30bit
1353 
1354  R = V * c->yuv2rgb_v2r_coeff;
1355  G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
1356  B = U * c->yuv2rgb_u2b_coeff;
1357 
1358  // 8bit: 30 - 22 = 8bit, 16bit: 30bit - 14 = 16bit
1359  output_pixel(&dest[0], av_clip_uintp2(((int)(R_B + (unsigned)Y)>>14) + (1<<15), 16));
1360  output_pixel(&dest[1], av_clip_uintp2(((int)( G + (unsigned)Y)>>14) + (1<<15), 16));
1361  output_pixel(&dest[2], av_clip_uintp2(((int)(B_R + (unsigned)Y)>>14) + (1<<15), 16));
1362  if (eightbytes) {
1363  output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
1364  dest += 4;
1365  } else {
1366  dest += 3;
1367  }
1368  }
1369 }
1370 
1371 static av_always_inline void
1373  const int32_t *ubuf[2], const int32_t *vbuf[2],
1374  const int32_t *abuf[2], uint16_t *dest, int dstW,
1375  int yalpha, int uvalpha, int y,
1376  enum AVPixelFormat target, int hasAlpha, int eightbytes,
1377  int is_be)
1378 {
1379  const int32_t *buf0 = buf[0], *buf1 = buf[1],
1380  *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
1381  *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
1382  *abuf0 = hasAlpha ? abuf[0] : NULL,
1383  *abuf1 = hasAlpha ? abuf[1] : NULL;
1384  int yalpha1 = 4096 - yalpha;
1385  int uvalpha1 = 4096 - uvalpha;
1386  int i;
1387  int A = 0xffff<<14;
1388 
1389  av_assert2(yalpha <= 4096U);
1390  av_assert2(uvalpha <= 4096U);
1391 
1392  for (i = 0; i < dstW; i++) {
1393  int Y = (buf0[i] * yalpha1 + buf1[i] * yalpha) >> 14;
1394  int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha - (128 << 23)) >> 14;
1395  int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha - (128 << 23)) >> 14;
1396  int R, G, B;
1397 
1398  Y -= c->yuv2rgb_y_offset;
1399  Y *= c->yuv2rgb_y_coeff;
1400  Y += (1 << 13) - (1 << 29);
1401 
1402  R = V * c->yuv2rgb_v2r_coeff;
1403  G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
1404  B = U * c->yuv2rgb_u2b_coeff;
1405 
1406  if (hasAlpha) {
1407  A = (abuf0[i] * yalpha1 + abuf1[i] * yalpha) >> 1;
1408 
1409  A += 1 << 13;
1410  }
1411 
1412  output_pixel(&dest[0], av_clip_uintp2(((R_B + Y) >> 14) + (1<<15), 16));
1413  output_pixel(&dest[1], av_clip_uintp2((( G + Y) >> 14) + (1<<15), 16));
1414  output_pixel(&dest[2], av_clip_uintp2(((B_R + Y) >> 14) + (1<<15), 16));
1415  if (eightbytes) {
1416  output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
1417  dest += 4;
1418  } else {
1419  dest += 3;
1420  }
1421  }
1422 }
1423 
1424 static av_always_inline void
1426  const int32_t *ubuf[2], const int32_t *vbuf[2],
1427  const int32_t *abuf0, uint16_t *dest, int dstW,
1428  int uvalpha, int y, enum AVPixelFormat target,
1429  int hasAlpha, int eightbytes, int is_be)
1430 {
1431  const int32_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
1432  int i;
1433  int A = 0xffff<<14;
1434 
1435  if (uvalpha == 0) {
1436  for (i = 0; i < dstW; i++) {
1437  SUINT Y = (buf0[i]) >> 2;
1438  int U = (ubuf0[i] - (128 << 11)) >> 2;
1439  int V = (vbuf0[i] - (128 << 11)) >> 2;
1440  int R, G, B;
1441 
1442  Y -= c->yuv2rgb_y_offset;
1443  Y *= c->yuv2rgb_y_coeff;
1444  Y += (1 << 13) - (1 << 29);
1445 
1446  if (hasAlpha) {
1447  A = abuf0[i] * (1 << 11);
1448 
1449  A += 1 << 13;
1450  }
1451 
1452  R = V * c->yuv2rgb_v2r_coeff;
1453  G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
1454  B = U * c->yuv2rgb_u2b_coeff;
1455 
1456  output_pixel(&dest[0], av_clip_uintp2(((int)(R_B + Y) >> 14) + (1<<15), 16));
1457  output_pixel(&dest[1], av_clip_uintp2(((int)( G + Y) >> 14) + (1<<15), 16));
1458  output_pixel(&dest[2], av_clip_uintp2(((int)(B_R + Y) >> 14) + (1<<15), 16));
1459  if (eightbytes) {
1460  output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
1461  dest += 4;
1462  } else {
1463  dest += 3;
1464  }
1465  }
1466  } else {
1467  const int32_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
1468  int uvalpha1 = 4096 - uvalpha;
1469  int A = 0xffff<<14;
1470  av_assert2(uvalpha <= 4096U);
1471 
1472  for (i = 0; i < dstW; i++) {
1473  SUINT Y = (buf0[i] ) >> 2;
1474  int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha - (128 << 23)) >> 14;
1475  int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha - (128 << 23)) >> 14;
1476  int R, G, B;
1477 
1478  Y -= c->yuv2rgb_y_offset;
1479  Y *= c->yuv2rgb_y_coeff;
1480  Y += (1 << 13) - (1 << 29);
1481 
1482  if (hasAlpha) {
1483  A = abuf0[i] * (1 << 11);
1484 
1485  A += 1 << 13;
1486  }
1487 
1488  R = V * c->yuv2rgb_v2r_coeff;
1489  G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
1490  B = U * c->yuv2rgb_u2b_coeff;
1491 
1492  output_pixel(&dest[0], av_clip_uintp2(((int)(R_B + Y) >> 14) + (1<<15), 16));
1493  output_pixel(&dest[1], av_clip_uintp2(((int)( G + Y) >> 14) + (1<<15), 16));
1494  output_pixel(&dest[2], av_clip_uintp2(((int)(B_R + Y) >> 14) + (1<<15), 16));
1495  if (eightbytes) {
1496  output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
1497  dest += 4;
1498  } else {
1499  dest += 3;
1500  }
1501  }
1502  }
1503 }
1504 
1505 #undef output_pixel
1506 #undef r_b
1507 #undef b_r
1508 
1509 #define YUV2PACKED16WRAPPER_EXT(name, base, ext, fmt, is_be, hasAlpha, eightbytes) \
1510 static void name ## ext ## _X_c(SwsInternal *c, const int16_t *lumFilter, \
1511  const int16_t **_lumSrc, int lumFilterSize, \
1512  const int16_t *chrFilter, const int16_t **_chrUSrc, \
1513  const int16_t **_chrVSrc, int chrFilterSize, \
1514  const int16_t **_alpSrc, uint8_t *_dest, int dstW, \
1515  int y) \
1516 { \
1517  const int32_t **lumSrc = (const int32_t **) _lumSrc, \
1518  **chrUSrc = (const int32_t **) _chrUSrc, \
1519  **chrVSrc = (const int32_t **) _chrVSrc, \
1520  **alpSrc = (const int32_t **) _alpSrc; \
1521  uint16_t *dest = (uint16_t *) _dest; \
1522  name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
1523  chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
1524  alpSrc, dest, dstW, y, fmt, hasAlpha, eightbytes, is_be); \
1525 } \
1526  \
1527 static void name ## ext ## _2_c(SwsInternal *c, const int16_t *_buf[2], \
1528  const int16_t *_ubuf[2], const int16_t *_vbuf[2], \
1529  const int16_t *_abuf[2], uint8_t *_dest, int dstW, \
1530  int yalpha, int uvalpha, int y) \
1531 { \
1532  const int32_t **buf = (const int32_t **) _buf, \
1533  **ubuf = (const int32_t **) _ubuf, \
1534  **vbuf = (const int32_t **) _vbuf, \
1535  **abuf = (const int32_t **) _abuf; \
1536  uint16_t *dest = (uint16_t *) _dest; \
1537  name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
1538  dest, dstW, yalpha, uvalpha, y, fmt, hasAlpha, eightbytes, is_be); \
1539 } \
1540  \
1541 static void name ## ext ## _1_c(SwsInternal *c, const int16_t *_buf0, \
1542  const int16_t *_ubuf[2], const int16_t *_vbuf[2], \
1543  const int16_t *_abuf0, uint8_t *_dest, int dstW, \
1544  int uvalpha, int y) \
1545 { \
1546  const int32_t *buf0 = (const int32_t *) _buf0, \
1547  **ubuf = (const int32_t **) _ubuf, \
1548  **vbuf = (const int32_t **) _vbuf, \
1549  *abuf0 = (const int32_t *) _abuf0; \
1550  uint16_t *dest = (uint16_t *) _dest; \
1551  name ## base ## _1_c_template(c, buf0, ubuf, vbuf, abuf0, dest, \
1552  dstW, uvalpha, y, fmt, hasAlpha, eightbytes, is_be); \
1553 }
1554 #define YUV2PACKED16WRAPPER(name, base, ext, base_fmt, endianness, hasAlpha, eightbytes) \
1555  YUV2PACKED16WRAPPER_EXT(name, base, ext, base_fmt ## endianness, IS_BE(endianness), hasAlpha, eightbytes)
1556 
1557 YUV2PACKED16WRAPPER(yuv2, rgba64, rgb48be, AV_PIX_FMT_RGB48, BE, 0, 0)
1558 YUV2PACKED16WRAPPER(yuv2, rgba64, rgb48le, AV_PIX_FMT_RGB48, LE, 0, 0)
1559 YUV2PACKED16WRAPPER(yuv2, rgba64, bgr48be, AV_PIX_FMT_BGR48, BE, 0, 0)
1560 YUV2PACKED16WRAPPER(yuv2, rgba64, bgr48le, AV_PIX_FMT_BGR48, LE, 0, 0)
1561 YUV2PACKED16WRAPPER(yuv2, rgba64, rgba64be, AV_PIX_FMT_RGBA64, BE, 1, 1)
1562 YUV2PACKED16WRAPPER(yuv2, rgba64, rgba64le, AV_PIX_FMT_RGBA64, LE, 1, 1)
1563 YUV2PACKED16WRAPPER(yuv2, rgba64, rgbx64be, AV_PIX_FMT_RGBA64, BE, 0, 1)
1564 YUV2PACKED16WRAPPER(yuv2, rgba64, rgbx64le, AV_PIX_FMT_RGBA64, LE, 0, 1)
1565 YUV2PACKED16WRAPPER(yuv2, rgba64, bgra64be, AV_PIX_FMT_BGRA64, BE, 1, 1)
1566 YUV2PACKED16WRAPPER(yuv2, rgba64, bgra64le, AV_PIX_FMT_BGRA64, LE, 1, 1)
1567 YUV2PACKED16WRAPPER(yuv2, rgba64, bgrx64be, AV_PIX_FMT_BGRA64, BE, 0, 1)
1568 YUV2PACKED16WRAPPER(yuv2, rgba64, bgrx64le, AV_PIX_FMT_BGRA64, LE, 0, 1)
1569 YUV2PACKED16WRAPPER(yuv2, ya16, ya16be, AV_PIX_FMT_YA16, BE, 1, 0)
1570 YUV2PACKED16WRAPPER(yuv2, ya16, ya16le, AV_PIX_FMT_YA16, LE, 1, 0)
1571 
1572 YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgb48be_full, AV_PIX_FMT_RGB48, BE, 0, 0)
1573 YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgb48le_full, AV_PIX_FMT_RGB48, LE, 0, 0)
1574 YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgr48be_full, AV_PIX_FMT_BGR48, BE, 0, 0)
1575 YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgr48le_full, AV_PIX_FMT_BGR48, LE, 0, 0)
1576 YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgba64be_full, AV_PIX_FMT_RGBA64, BE, 1, 1)
1577 YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgba64le_full, AV_PIX_FMT_RGBA64, LE, 1, 1)
1578 YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgbx64be_full, AV_PIX_FMT_RGBA64, BE, 0, 1)
1579 YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgbx64le_full, AV_PIX_FMT_RGBA64, LE, 0, 1)
1580 YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgra64be_full, AV_PIX_FMT_BGRA64, BE, 1, 1)
1581 YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgra64le_full, AV_PIX_FMT_BGRA64, LE, 1, 1)
1582 YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgrx64be_full, AV_PIX_FMT_BGRA64, BE, 0, 1)
1583 YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgrx64le_full, AV_PIX_FMT_BGRA64, LE, 0, 1)
1584 
1585 /*
1586  * Write out 2 RGB pixels in the target pixel format. This function takes a
1587  * R/G/B LUT as generated by ff_yuv2rgb_c_init_tables(), which takes care of
1588  * things like endianness conversion and shifting. The caller takes care of
1589  * setting the correct offset in these tables from the chroma (U/V) values.
1590  * This function then uses the luminance (Y1/Y2) values to write out the
1591  * correct RGB values into the destination buffer.
1592  */
1593 static av_always_inline void
1594 yuv2rgb_write(uint8_t *_dest, int i, int Y1, int Y2,
1595  unsigned A1, unsigned A2,
1596  const void *_r, const void *_g, const void *_b, int y,
1597  enum AVPixelFormat target, int hasAlpha)
1598 {
1599  if (target == AV_PIX_FMT_ARGB || target == AV_PIX_FMT_RGBA ||
1600  target == AV_PIX_FMT_ABGR || target == AV_PIX_FMT_BGRA) {
1601  uint32_t *dest = (uint32_t *) _dest;
1602  const uint32_t *r = (const uint32_t *) _r;
1603  const uint32_t *g = (const uint32_t *) _g;
1604  const uint32_t *b = (const uint32_t *) _b;
1605 
1606 #if CONFIG_SMALL
1607  int sh = hasAlpha ? ((target == AV_PIX_FMT_RGB32_1 || target == AV_PIX_FMT_BGR32_1) ? 0 : 24) : 0;
1608 
1609  dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1] + (hasAlpha ? A1 << sh : 0);
1610  dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2] + (hasAlpha ? A2 << sh : 0);
1611 #else
1612  if (hasAlpha) {
1613  int sh = (target == AV_PIX_FMT_RGB32_1 || target == AV_PIX_FMT_BGR32_1) ? 0 : 24;
1614 
1615  av_assert2((((r[Y1] + g[Y1] + b[Y1]) >> sh) & 0xFF) == 0);
1616  dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1] + (A1 << sh);
1617  dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2] + (A2 << sh);
1618  } else {
1619 #if defined(ASSERT_LEVEL) && ASSERT_LEVEL > 1
1620  int sh = (target == AV_PIX_FMT_RGB32_1 || target == AV_PIX_FMT_BGR32_1) ? 0 : 24;
1621 
1622  av_assert2((((r[Y1] + g[Y1] + b[Y1]) >> sh) & 0xFF) == 0xFF);
1623 #endif
1624  dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1];
1625  dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2];
1626  }
1627 #endif
1628  } else if (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) {
1629  uint8_t *dest = (uint8_t *) _dest;
1630  const uint8_t *r = (const uint8_t *) _r;
1631  const uint8_t *g = (const uint8_t *) _g;
1632  const uint8_t *b = (const uint8_t *) _b;
1633 
1634 #define r_b ((target == AV_PIX_FMT_RGB24) ? r : b)
1635 #define b_r ((target == AV_PIX_FMT_RGB24) ? b : r)
1636 
1637  dest[i * 6 + 0] = r_b[Y1];
1638  dest[i * 6 + 1] = g[Y1];
1639  dest[i * 6 + 2] = b_r[Y1];
1640  dest[i * 6 + 3] = r_b[Y2];
1641  dest[i * 6 + 4] = g[Y2];
1642  dest[i * 6 + 5] = b_r[Y2];
1643 #undef r_b
1644 #undef b_r
1645  } else if (target == AV_PIX_FMT_RGB565 || target == AV_PIX_FMT_BGR565 ||
1646  target == AV_PIX_FMT_RGB555 || target == AV_PIX_FMT_BGR555 ||
1647  target == AV_PIX_FMT_RGB444 || target == AV_PIX_FMT_BGR444) {
1648  uint16_t *dest = (uint16_t *) _dest;
1649  const uint16_t *r = (const uint16_t *) _r;
1650  const uint16_t *g = (const uint16_t *) _g;
1651  const uint16_t *b = (const uint16_t *) _b;
1652  int dr1, dg1, db1, dr2, dg2, db2;
1653 
1654  if (target == AV_PIX_FMT_RGB565 || target == AV_PIX_FMT_BGR565) {
1655  dr1 = ff_dither_2x2_8[ y & 1 ][0];
1656  dg1 = ff_dither_2x2_4[ y & 1 ][0];
1657  db1 = ff_dither_2x2_8[(y & 1) ^ 1][0];
1658  dr2 = ff_dither_2x2_8[ y & 1 ][1];
1659  dg2 = ff_dither_2x2_4[ y & 1 ][1];
1660  db2 = ff_dither_2x2_8[(y & 1) ^ 1][1];
1661  } else if (target == AV_PIX_FMT_RGB555 || target == AV_PIX_FMT_BGR555) {
1662  dr1 = ff_dither_2x2_8[ y & 1 ][0];
1663  dg1 = ff_dither_2x2_8[ y & 1 ][1];
1664  db1 = ff_dither_2x2_8[(y & 1) ^ 1][0];
1665  dr2 = ff_dither_2x2_8[ y & 1 ][1];
1666  dg2 = ff_dither_2x2_8[ y & 1 ][0];
1667  db2 = ff_dither_2x2_8[(y & 1) ^ 1][1];
1668  } else {
1669  dr1 = ff_dither_4x4_16[ y & 3 ][0];
1670  dg1 = ff_dither_4x4_16[ y & 3 ][1];
1671  db1 = ff_dither_4x4_16[(y & 3) ^ 3][0];
1672  dr2 = ff_dither_4x4_16[ y & 3 ][1];
1673  dg2 = ff_dither_4x4_16[ y & 3 ][0];
1674  db2 = ff_dither_4x4_16[(y & 3) ^ 3][1];
1675  }
1676 
1677  dest[i * 2 + 0] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1];
1678  dest[i * 2 + 1] = r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2];
1679  } else if (target == AV_PIX_FMT_X2RGB10 || target == AV_PIX_FMT_X2BGR10) {
1680  uint32_t *dest = (uint32_t *) _dest;
1681  const uint32_t *r = (const uint32_t *) _r;
1682  const uint32_t *g = (const uint32_t *) _g;
1683  const uint32_t *b = (const uint32_t *) _b;
1684  dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1];
1685  dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2];
1686  } else /* 8/4 bits */ {
1687  uint8_t *dest = (uint8_t *) _dest;
1688  const uint8_t *r = (const uint8_t *) _r;
1689  const uint8_t *g = (const uint8_t *) _g;
1690  const uint8_t *b = (const uint8_t *) _b;
1691  int dr1, dg1, db1, dr2, dg2, db2;
1692 
1693  if (target == AV_PIX_FMT_RGB8 || target == AV_PIX_FMT_BGR8) {
1694  const uint8_t * const d64 = ff_dither_8x8_73[y & 7];
1695  const uint8_t * const d32 = ff_dither_8x8_32[y & 7];
1696  dr1 = dg1 = d32[(i * 2 + 0) & 7];
1697  db1 = d64[(i * 2 + 0) & 7];
1698  dr2 = dg2 = d32[(i * 2 + 1) & 7];
1699  db2 = d64[(i * 2 + 1) & 7];
1700  } else {
1701  const uint8_t * const d64 = ff_dither_8x8_73 [y & 7];
1702  const uint8_t * const d128 = ff_dither_8x8_220[y & 7];
1703  dr1 = db1 = d128[(i * 2 + 0) & 7];
1704  dg1 = d64[(i * 2 + 0) & 7];
1705  dr2 = db2 = d128[(i * 2 + 1) & 7];
1706  dg2 = d64[(i * 2 + 1) & 7];
1707  }
1708 
1709  if (target == AV_PIX_FMT_RGB4 || target == AV_PIX_FMT_BGR4) {
1710  dest[i] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1] +
1711  ((r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2]) << 4);
1712  } else {
1713  dest[i * 2 + 0] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1];
1714  dest[i * 2 + 1] = r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2];
1715  }
1716  }
1717 }
1718 
1719 static av_always_inline void
1720 yuv2rgb_X_c_template(SwsInternal *c, const int16_t *lumFilter,
1721  const int16_t **lumSrc, int lumFilterSize,
1722  const int16_t *chrFilter, const int16_t **chrUSrc,
1723  const int16_t **chrVSrc, int chrFilterSize,
1724  const int16_t **alpSrc, uint8_t *dest, int dstW,
1725  int y, enum AVPixelFormat target, int hasAlpha)
1726 {
1727  int i;
1728 
1729  for (i = 0; i < ((dstW + 1) >> 1); i++) {
1730  int j, A1, A2;
1731  int Y1 = 1 << 18;
1732  int Y2 = 1 << 18;
1733  int U = 1 << 18;
1734  int V = 1 << 18;
1735  const void *r, *g, *b;
1736 
1737  for (j = 0; j < lumFilterSize; j++) {
1738  Y1 += lumSrc[j][i * 2] * lumFilter[j];
1739  Y2 += lumSrc[j][i * 2 + 1] * lumFilter[j];
1740  }
1741  for (j = 0; j < chrFilterSize; j++) {
1742  U += chrUSrc[j][i] * chrFilter[j];
1743  V += chrVSrc[j][i] * chrFilter[j];
1744  }
1745  Y1 >>= 19;
1746  Y2 >>= 19;
1747  U >>= 19;
1748  V >>= 19;
1749  if (hasAlpha) {
1750  A1 = 1 << 18;
1751  A2 = 1 << 18;
1752  for (j = 0; j < lumFilterSize; j++) {
1753  A1 += alpSrc[j][i * 2 ] * lumFilter[j];
1754  A2 += alpSrc[j][i * 2 + 1] * lumFilter[j];
1755  }
1756  A1 >>= 19;
1757  A2 >>= 19;
1758  if ((A1 | A2) & 0x100) {
1759  A1 = av_clip_uint8(A1);
1760  A2 = av_clip_uint8(A2);
1761  }
1762  }
1763 
1764  r = c->table_rV[V + YUVRGB_TABLE_HEADROOM];
1765  g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]);
1766  b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
1767 
1768  yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
1769  r, g, b, y, target, hasAlpha);
1770  }
1771 }
1772 
1773 static av_always_inline void
1774 yuv2rgb_2_c_template(SwsInternal *c, const int16_t *buf[2],
1775  const int16_t *ubuf[2], const int16_t *vbuf[2],
1776  const int16_t *abuf[2], uint8_t *dest, int dstW,
1777  int yalpha, int uvalpha, int y,
1778  enum AVPixelFormat target, int hasAlpha)
1779 {
1780  const int16_t *buf0 = buf[0], *buf1 = buf[1],
1781  *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
1782  *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
1783  *abuf0 = hasAlpha ? abuf[0] : NULL,
1784  *abuf1 = hasAlpha ? abuf[1] : NULL;
1785  int yalpha1 = 4096 - yalpha;
1786  int uvalpha1 = 4096 - uvalpha;
1787  int i;
1788  av_assert2(yalpha <= 4096U);
1789  av_assert2(uvalpha <= 4096U);
1790 
1791  for (i = 0; i < ((dstW + 1) >> 1); i++) {
1792  int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 19;
1793  int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 19;
1794  int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha) >> 19;
1795  int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha) >> 19;
1796  int A1, A2;
1797  const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM],
1798  *g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]),
1799  *b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
1800 
1801  if (hasAlpha) {
1802  A1 = (abuf0[i * 2 ] * yalpha1 + abuf1[i * 2 ] * yalpha) >> 19;
1803  A2 = (abuf0[i * 2 + 1] * yalpha1 + abuf1[i * 2 + 1] * yalpha) >> 19;
1804  A1 = av_clip_uint8(A1);
1805  A2 = av_clip_uint8(A2);
1806  }
1807 
1808  yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
1809  r, g, b, y, target, hasAlpha);
1810  }
1811 }
1812 
1813 static av_always_inline void
1814 yuv2rgb_1_c_template(SwsInternal *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, enum AVPixelFormat target,
1818  int hasAlpha)
1819 {
1820  const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
1821  int i;
1822 
1823  if (uvalpha == 0) {
1824  for (i = 0; i < ((dstW + 1) >> 1); i++) {
1825  int Y1 = (buf0[i * 2 ] + 64) >> 7;
1826  int Y2 = (buf0[i * 2 + 1] + 64) >> 7;
1827  int U = (ubuf0[i] + 64) >> 7;
1828  int V = (vbuf0[i] + 64) >> 7;
1829  int A1, A2;
1830  const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM],
1831  *g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]),
1832  *b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
1833 
1834  if (hasAlpha) {
1835  A1 = abuf0[i * 2 ] * 255 + 16384 >> 15;
1836  A2 = abuf0[i * 2 + 1] * 255 + 16384 >> 15;
1837  A1 = av_clip_uint8(A1);
1838  A2 = av_clip_uint8(A2);
1839  }
1840 
1841  yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
1842  r, g, b, y, target, hasAlpha);
1843  }
1844  } else {
1845  const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
1846  int uvalpha1 = 4096 - uvalpha;
1847  av_assert2(uvalpha <= 4096U);
1848 
1849  for (i = 0; i < ((dstW + 1) >> 1); i++) {
1850  int Y1 = (buf0[i * 2 ] + 64) >> 7;
1851  int Y2 = (buf0[i * 2 + 1] + 64) >> 7;
1852  int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha + (128 << 11)) >> 19;
1853  int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha + (128 << 11)) >> 19;
1854  int A1, A2;
1855  const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM],
1856  *g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]),
1857  *b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
1858 
1859  if (hasAlpha) {
1860  A1 = (abuf0[i * 2 ] + 64) >> 7;
1861  A2 = (abuf0[i * 2 + 1] + 64) >> 7;
1862  A1 = av_clip_uint8(A1);
1863  A2 = av_clip_uint8(A2);
1864  }
1865 
1866  yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
1867  r, g, b, y, target, hasAlpha);
1868  }
1869  }
1870 }
1871 
1872 #define YUV2RGBWRAPPERX(name, base, ext, fmt, hasAlpha) \
1873 static void name ## ext ## _X_c(SwsInternal *c, const int16_t *lumFilter, \
1874  const int16_t **lumSrc, int lumFilterSize, \
1875  const int16_t *chrFilter, const int16_t **chrUSrc, \
1876  const int16_t **chrVSrc, int chrFilterSize, \
1877  const int16_t **alpSrc, uint8_t *dest, int dstW, \
1878  int y) \
1879 { \
1880  name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
1881  chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
1882  alpSrc, dest, dstW, y, fmt, hasAlpha); \
1883 }
1884 
1885 #define YUV2RGBWRAPPERX2(name, base, ext, fmt, hasAlpha) \
1886 YUV2RGBWRAPPERX(name, base, ext, fmt, hasAlpha) \
1887 static void name ## ext ## _2_c(SwsInternal *c, const int16_t *buf[2], \
1888  const int16_t *ubuf[2], const int16_t *vbuf[2], \
1889  const int16_t *abuf[2], uint8_t *dest, int dstW, \
1890  int yalpha, int uvalpha, int y) \
1891 { \
1892  name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
1893  dest, dstW, yalpha, uvalpha, y, fmt, hasAlpha); \
1894 }
1895 
1896 #define YUV2RGBWRAPPER(name, base, ext, fmt, hasAlpha) \
1897 YUV2RGBWRAPPERX2(name, base, ext, fmt, hasAlpha) \
1898 static void name ## ext ## _1_c(SwsInternal *c, const int16_t *buf0, \
1899  const int16_t *ubuf[2], const int16_t *vbuf[2], \
1900  const int16_t *abuf0, uint8_t *dest, int dstW, \
1901  int uvalpha, int y) \
1902 { \
1903  name ## base ## _1_c_template(c, buf0, ubuf, vbuf, abuf0, dest, \
1904  dstW, uvalpha, y, fmt, hasAlpha); \
1905 }
1906 
1907 #if CONFIG_SMALL
1908 YUV2RGBWRAPPER(yuv2rgb,, 32_1, AV_PIX_FMT_RGB32_1, CONFIG_SWSCALE_ALPHA && c->needAlpha)
1909 YUV2RGBWRAPPER(yuv2rgb,, 32, AV_PIX_FMT_RGB32, CONFIG_SWSCALE_ALPHA && c->needAlpha)
1910 #else
1911 #if CONFIG_SWSCALE_ALPHA
1914 #endif
1917 #endif
1918 YUV2RGBWRAPPER(yuv2, rgb, rgb24, AV_PIX_FMT_RGB24, 0)
1919 YUV2RGBWRAPPER(yuv2, rgb, bgr24, AV_PIX_FMT_BGR24, 0)
1926 YUV2RGBWRAPPER(yuv2, rgb, x2rgb10, AV_PIX_FMT_X2RGB10, 0)
1927 YUV2RGBWRAPPER(yuv2, rgb, x2bgr10, AV_PIX_FMT_X2BGR10, 0)
1928 
1930  uint8_t *dest, int i, int Y, int A, int U, int V,
1931  int y, enum AVPixelFormat target, int hasAlpha, int err[4])
1932 {
1933  int R, G, B;
1934  int isrgb8 = target == AV_PIX_FMT_BGR8 || target == AV_PIX_FMT_RGB8;
1935 
1936  Y -= c->yuv2rgb_y_offset;
1937  Y *= c->yuv2rgb_y_coeff;
1938  Y += 1 << 21;
1939  R = (unsigned)Y + V*(unsigned)c->yuv2rgb_v2r_coeff;
1940  G = (unsigned)Y + V*(unsigned)c->yuv2rgb_v2g_coeff + U*(unsigned)c->yuv2rgb_u2g_coeff;
1941  B = (unsigned)Y + U*(unsigned)c->yuv2rgb_u2b_coeff;
1942  if ((R | G | B) & 0xC0000000) {
1943  R = av_clip_uintp2(R, 30);
1944  G = av_clip_uintp2(G, 30);
1945  B = av_clip_uintp2(B, 30);
1946  }
1947 
1948  switch(target) {
1949  case AV_PIX_FMT_ARGB:
1950  dest[0] = hasAlpha ? A : 255;
1951  dest[1] = R >> 22;
1952  dest[2] = G >> 22;
1953  dest[3] = B >> 22;
1954  break;
1955  case AV_PIX_FMT_RGB24:
1956  dest[0] = R >> 22;
1957  dest[1] = G >> 22;
1958  dest[2] = B >> 22;
1959  break;
1960  case AV_PIX_FMT_RGBA:
1961  dest[0] = R >> 22;
1962  dest[1] = G >> 22;
1963  dest[2] = B >> 22;
1964  dest[3] = hasAlpha ? A : 255;
1965  break;
1966  case AV_PIX_FMT_ABGR:
1967  dest[0] = hasAlpha ? A : 255;
1968  dest[1] = B >> 22;
1969  dest[2] = G >> 22;
1970  dest[3] = R >> 22;
1971  break;
1972  case AV_PIX_FMT_BGR24:
1973  dest[0] = B >> 22;
1974  dest[1] = G >> 22;
1975  dest[2] = R >> 22;
1976  break;
1977  case AV_PIX_FMT_BGRA:
1978  dest[0] = B >> 22;
1979  dest[1] = G >> 22;
1980  dest[2] = R >> 22;
1981  dest[3] = hasAlpha ? A : 255;
1982  break;
1983  case AV_PIX_FMT_X2RGB10LE:
1984  R >>= 20;
1985  G >>= 20;
1986  B >>= 20;
1987  AV_WL32(dest, (3U << 30) + (R << 20) + (G << 10) + B);
1988  break;
1989  case AV_PIX_FMT_X2BGR10LE:
1990  R >>= 20;
1991  G >>= 20;
1992  B >>= 20;
1993  AV_WL32(dest, (3U << 30) + (B << 20) + (G << 10) + R);
1994  break;
1995  case AV_PIX_FMT_BGR4_BYTE:
1996  case AV_PIX_FMT_RGB4_BYTE:
1997  case AV_PIX_FMT_BGR8:
1998  case AV_PIX_FMT_RGB8:
1999  {
2000  int r,g,b;
2001 
2002  switch (c->opts.dither) {
2003  case SWS_DITHER_NONE:
2004  if (isrgb8) {
2005  r = av_clip_uintp2(R >> 27, 3);
2006  g = av_clip_uintp2(G >> 27, 3);
2007  b = av_clip_uintp2(B >> 28, 2);
2008  } else {
2009  r = av_clip_uintp2(R >> 29, 1);
2010  g = av_clip_uintp2(G >> 28, 2);
2011  b = av_clip_uintp2(B >> 29, 1);
2012  }
2013  break;
2014  default:
2015  case SWS_DITHER_AUTO:
2016  case SWS_DITHER_ED:
2017  R >>= 22;
2018  G >>= 22;
2019  B >>= 22;
2020  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;
2021  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;
2022  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;
2023  c->dither_error[0][i] = err[0];
2024  c->dither_error[1][i] = err[1];
2025  c->dither_error[2][i] = err[2];
2026  r = R >> (isrgb8 ? 5 : 7);
2027  g = G >> (isrgb8 ? 5 : 6);
2028  b = B >> (isrgb8 ? 6 : 7);
2029  r = av_clip(r, 0, isrgb8 ? 7 : 1);
2030  g = av_clip(g, 0, isrgb8 ? 7 : 3);
2031  b = av_clip(b, 0, isrgb8 ? 3 : 1);
2032  err[0] = R - r*(isrgb8 ? 36 : 255);
2033  err[1] = G - g*(isrgb8 ? 36 : 85);
2034  err[2] = B - b*(isrgb8 ? 85 : 255);
2035  break;
2036  case SWS_DITHER_A_DITHER:
2037  if (isrgb8) {
2038  /* see http://pippin.gimp.org/a_dither/ for details/origin */
2039 #define A_DITHER(u,v) (((((u)+((v)*236))*119)&0xff))
2040  r = (((R >> 19) + A_DITHER(i,y) -96)>>8);
2041  g = (((G >> 19) + A_DITHER(i + 17,y) - 96)>>8);
2042  b = (((B >> 20) + A_DITHER(i + 17*2,y) -96)>>8);
2043  r = av_clip_uintp2(r, 3);
2044  g = av_clip_uintp2(g, 3);
2045  b = av_clip_uintp2(b, 2);
2046  } else {
2047  r = (((R >> 21) + A_DITHER(i,y)-256)>>8);
2048  g = (((G >> 19) + A_DITHER(i + 17,y)-256)>>8);
2049  b = (((B >> 21) + A_DITHER(i + 17*2,y)-256)>>8);
2050  r = av_clip_uintp2(r, 1);
2051  g = av_clip_uintp2(g, 2);
2052  b = av_clip_uintp2(b, 1);
2053  }
2054  break;
2055  case SWS_DITHER_X_DITHER:
2056  if (isrgb8) {
2057  /* see http://pippin.gimp.org/a_dither/ for details/origin */
2058 #define X_DITHER(u,v) (((((u)^((v)*237))*181)&0x1ff)/2)
2059  r = (((R >> 19) + X_DITHER(i,y) - 96)>>8);
2060  g = (((G >> 19) + X_DITHER(i + 17,y) - 96)>>8);
2061  b = (((B >> 20) + X_DITHER(i + 17*2,y) - 96)>>8);
2062  r = av_clip_uintp2(r, 3);
2063  g = av_clip_uintp2(g, 3);
2064  b = av_clip_uintp2(b, 2);
2065  } else {
2066  r = (((R >> 21) + X_DITHER(i,y)-256)>>8);
2067  g = (((G >> 19) + X_DITHER(i + 17,y)-256)>>8);
2068  b = (((B >> 21) + X_DITHER(i + 17*2,y)-256)>>8);
2069  r = av_clip_uintp2(r, 1);
2070  g = av_clip_uintp2(g, 2);
2071  b = av_clip_uintp2(b, 1);
2072  }
2073 
2074  break;
2075  }
2076 
2077  if(target == AV_PIX_FMT_BGR4_BYTE) {
2078  dest[0] = r + 2*g + 8*b;
2079  } else if(target == AV_PIX_FMT_RGB4_BYTE) {
2080  dest[0] = b + 2*g + 8*r;
2081  } else if(target == AV_PIX_FMT_BGR8) {
2082  dest[0] = r + 8*g + 64*b;
2083  } else if(target == AV_PIX_FMT_RGB8) {
2084  dest[0] = b + 4*g + 32*r;
2085  } else
2086  av_assert2(0);
2087  break;}
2088  }
2089 }
2090 
2091 static av_always_inline void
2092 yuv2rgb_full_X_c_template(SwsInternal *c, const int16_t *lumFilter,
2093  const int16_t **lumSrc, int lumFilterSize,
2094  const int16_t *chrFilter, const int16_t **chrUSrc,
2095  const int16_t **chrVSrc, int chrFilterSize,
2096  const int16_t **alpSrc, uint8_t *dest,
2097  int dstW, int y, enum AVPixelFormat target, int hasAlpha)
2098 {
2099  int i;
2100  int step = (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) ? 3 : 4;
2101  int err[4] = {0};
2102  int A = 0; //init to silence warning
2103 
2104  if( target == AV_PIX_FMT_BGR4_BYTE || target == AV_PIX_FMT_RGB4_BYTE
2105  || target == AV_PIX_FMT_BGR8 || target == AV_PIX_FMT_RGB8)
2106  step = 1;
2107 
2108  for (i = 0; i < dstW; i++) {
2109  int j;
2110  int Y = 1<<9;
2111  int U = (1<<9)-(128 << 19);
2112  int V = (1<<9)-(128 << 19);
2113 
2114  for (j = 0; j < lumFilterSize; j++) {
2115  Y += lumSrc[j][i] * lumFilter[j];
2116  }
2117  for (j = 0; j < chrFilterSize; j++) {
2118  U += chrUSrc[j][i] * chrFilter[j];
2119  V += chrVSrc[j][i] * chrFilter[j];
2120  }
2121  Y >>= 10;
2122  U >>= 10;
2123  V >>= 10;
2124  if (hasAlpha) {
2125  A = 1 << 18;
2126  for (j = 0; j < lumFilterSize; j++) {
2127  A += alpSrc[j][i] * lumFilter[j];
2128  }
2129  A >>= 19;
2130  if (A & 0x100)
2131  A = av_clip_uint8(A);
2132  }
2133  yuv2rgb_write_full(c, dest, i, Y, A, U, V, y, target, hasAlpha, err);
2134  dest += step;
2135  }
2136  c->dither_error[0][i] = err[0];
2137  c->dither_error[1][i] = err[1];
2138  c->dither_error[2][i] = err[2];
2139 }
2140 
2141 static av_always_inline void
2142 yuv2rgb_full_2_c_template(SwsInternal *c, const int16_t *buf[2],
2143  const int16_t *ubuf[2], const int16_t *vbuf[2],
2144  const int16_t *abuf[2], uint8_t *dest, int dstW,
2145  int yalpha, int uvalpha, int y,
2146  enum AVPixelFormat target, int hasAlpha)
2147 {
2148  const int16_t *buf0 = buf[0], *buf1 = buf[1],
2149  *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
2150  *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
2151  *abuf0 = hasAlpha ? abuf[0] : NULL,
2152  *abuf1 = hasAlpha ? abuf[1] : NULL;
2153  int yalpha1 = 4096 - yalpha;
2154  int uvalpha1 = 4096 - uvalpha;
2155  int i;
2156  int step = (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) ? 3 : 4;
2157  int err[4] = {0};
2158  int A = 0; // init to silcene warning
2159 
2160  av_assert2(yalpha <= 4096U);
2161  av_assert2(uvalpha <= 4096U);
2162 
2163  if( target == AV_PIX_FMT_BGR4_BYTE || target == AV_PIX_FMT_RGB4_BYTE
2164  || target == AV_PIX_FMT_BGR8 || target == AV_PIX_FMT_RGB8)
2165  step = 1;
2166 
2167  for (i = 0; i < dstW; i++) {
2168  int Y = ( buf0[i] * yalpha1 + buf1[i] * yalpha ) >> 10; //FIXME rounding
2169  int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha-(128 << 19)) >> 10;
2170  int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha-(128 << 19)) >> 10;
2171 
2172  if (hasAlpha) {
2173  A = (abuf0[i] * yalpha1 + abuf1[i] * yalpha + (1<<18)) >> 19;
2174  if (A & 0x100)
2175  A = av_clip_uint8(A);
2176  }
2177 
2178  yuv2rgb_write_full(c, dest, i, Y, A, U, V, y, target, hasAlpha, err);
2179  dest += step;
2180  }
2181  c->dither_error[0][i] = err[0];
2182  c->dither_error[1][i] = err[1];
2183  c->dither_error[2][i] = err[2];
2184 }
2185 
2186 static av_always_inline void
2188  const int16_t *ubuf[2], const int16_t *vbuf[2],
2189  const int16_t *abuf0, uint8_t *dest, int dstW,
2190  int uvalpha, int y, enum AVPixelFormat target,
2191  int hasAlpha)
2192 {
2193  const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
2194  int i;
2195  int step = (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) ? 3 : 4;
2196  int err[4] = {0};
2197 
2198  if( target == AV_PIX_FMT_BGR4_BYTE || target == AV_PIX_FMT_RGB4_BYTE
2199  || target == AV_PIX_FMT_BGR8 || target == AV_PIX_FMT_RGB8)
2200  step = 1;
2201 
2202  if (uvalpha == 0) {
2203  int A = 0; //init to silence warning
2204  for (i = 0; i < dstW; i++) {
2205  int Y = buf0[i] * 4;
2206  int U = (ubuf0[i] - (128<<7)) * 4;
2207  int V = (vbuf0[i] - (128<<7)) * 4;
2208 
2209  if (hasAlpha) {
2210  A = (abuf0[i] + 64) >> 7;
2211  if (A & 0x100)
2212  A = av_clip_uint8(A);
2213  }
2214 
2215  yuv2rgb_write_full(c, dest, i, Y, A, U, V, y, target, hasAlpha, err);
2216  dest += step;
2217  }
2218  } else {
2219  const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
2220  int A = 0; //init to silence warning
2221  int uvalpha1 = 4096 - uvalpha;
2222  av_assert2(uvalpha <= 4096U);
2223 
2224  for (i = 0; i < dstW; i++) {
2225  int Y = buf0[i] * 4;
2226  int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha - (128 << 19)) >> 10;
2227  int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha - (128 << 19)) >> 10;
2228 
2229  if (hasAlpha) {
2230  A = (abuf0[i] + 64) >> 7;
2231  if (A & 0x100)
2232  A = av_clip_uint8(A);
2233  }
2234 
2235  yuv2rgb_write_full(c, dest, i, Y, A, U, V, y, target, hasAlpha, err);
2236  dest += step;
2237  }
2238  }
2239 
2240  c->dither_error[0][i] = err[0];
2241  c->dither_error[1][i] = err[1];
2242  c->dither_error[2][i] = err[2];
2243 }
2244 
2245 #if CONFIG_SMALL
2246 YUV2RGBWRAPPER(yuv2, rgb_full, bgra32_full, AV_PIX_FMT_BGRA, CONFIG_SWSCALE_ALPHA && c->needAlpha)
2247 YUV2RGBWRAPPER(yuv2, rgb_full, abgr32_full, AV_PIX_FMT_ABGR, CONFIG_SWSCALE_ALPHA && c->needAlpha)
2248 YUV2RGBWRAPPER(yuv2, rgb_full, rgba32_full, AV_PIX_FMT_RGBA, CONFIG_SWSCALE_ALPHA && c->needAlpha)
2249 YUV2RGBWRAPPER(yuv2, rgb_full, argb32_full, AV_PIX_FMT_ARGB, CONFIG_SWSCALE_ALPHA && c->needAlpha)
2250 #else
2251 #if CONFIG_SWSCALE_ALPHA
2252 YUV2RGBWRAPPER(yuv2, rgb_full, bgra32_full, AV_PIX_FMT_BGRA, 1)
2253 YUV2RGBWRAPPER(yuv2, rgb_full, abgr32_full, AV_PIX_FMT_ABGR, 1)
2254 YUV2RGBWRAPPER(yuv2, rgb_full, rgba32_full, AV_PIX_FMT_RGBA, 1)
2255 YUV2RGBWRAPPER(yuv2, rgb_full, argb32_full, AV_PIX_FMT_ARGB, 1)
2256 #endif
2257 YUV2RGBWRAPPER(yuv2, rgb_full, bgrx32_full, AV_PIX_FMT_BGRA, 0)
2258 YUV2RGBWRAPPER(yuv2, rgb_full, xbgr32_full, AV_PIX_FMT_ABGR, 0)
2259 YUV2RGBWRAPPER(yuv2, rgb_full, rgbx32_full, AV_PIX_FMT_RGBA, 0)
2260 YUV2RGBWRAPPER(yuv2, rgb_full, xrgb32_full, AV_PIX_FMT_ARGB, 0)
2261 #endif
2262 YUV2RGBWRAPPER(yuv2, rgb_full, bgr24_full, AV_PIX_FMT_BGR24, 0)
2263 YUV2RGBWRAPPER(yuv2, rgb_full, rgb24_full, AV_PIX_FMT_RGB24, 0)
2264 
2265 YUV2RGBWRAPPER(yuv2, rgb_full, bgr4_byte_full, AV_PIX_FMT_BGR4_BYTE, 0)
2266 YUV2RGBWRAPPER(yuv2, rgb_full, rgb4_byte_full, AV_PIX_FMT_RGB4_BYTE, 0)
2267 YUV2RGBWRAPPER(yuv2, rgb_full, bgr8_full, AV_PIX_FMT_BGR8, 0)
2268 YUV2RGBWRAPPER(yuv2, rgb_full, rgb8_full, AV_PIX_FMT_RGB8, 0)
2269 
2270 YUV2RGBWRAPPER(yuv2, rgb_full, x2rgb10_full, AV_PIX_FMT_X2RGB10LE, 0)
2271 YUV2RGBWRAPPER(yuv2, rgb_full, x2bgr10_full, AV_PIX_FMT_X2BGR10LE, 0)
2272 
2273 static void
2274 yuv2gbrp_full_X_c(SwsInternal *c, const int16_t *lumFilter,
2275  const int16_t **lumSrc, int lumFilterSize,
2276  const int16_t *chrFilter, const int16_t **chrUSrc,
2277  const int16_t **chrVSrc, int chrFilterSize,
2278  const int16_t **alpSrc, uint8_t **dest,
2279  int dstW, int y)
2280 {
2281  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->opts.dst_format);
2282  int i;
2283  int hasAlpha = (desc->flags & AV_PIX_FMT_FLAG_ALPHA) && alpSrc;
2284  uint16_t **dest16 = (uint16_t**)dest;
2285  int SH = 22 + 8 - desc->comp[0].depth;
2286  int A = 0; // init to silence warning
2287 
2288  for (i = 0; i < dstW; i++) {
2289  int j;
2290  int Y = 1 << 9;
2291  int U = (1 << 9) - (128 << 19);
2292  int V = (1 << 9) - (128 << 19);
2293  int R, G, B;
2294 
2295  for (j = 0; j < lumFilterSize; j++)
2296  Y += lumSrc[j][i] * lumFilter[j];
2297 
2298  for (j = 0; j < chrFilterSize; j++) {
2299  U += chrUSrc[j][i] * chrFilter[j];
2300  V += chrVSrc[j][i] * chrFilter[j];
2301  }
2302 
2303  Y >>= 10;
2304  U >>= 10;
2305  V >>= 10;
2306 
2307  if (hasAlpha) {
2308  A = 1 << 18;
2309 
2310  for (j = 0; j < lumFilterSize; j++)
2311  A += alpSrc[j][i] * lumFilter[j];
2312 
2313  if (A & 0xF8000000)
2314  A = av_clip_uintp2(A, 27);
2315  }
2316 
2317  Y -= c->yuv2rgb_y_offset;
2318  Y *= c->yuv2rgb_y_coeff;
2319  Y += 1 << (SH-1);
2320  R = Y + V * c->yuv2rgb_v2r_coeff;
2321  G = Y + V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
2322  B = Y + U * c->yuv2rgb_u2b_coeff;
2323 
2324  if ((R | G | B) & 0xC0000000) {
2325  R = av_clip_uintp2(R, 30);
2326  G = av_clip_uintp2(G, 30);
2327  B = av_clip_uintp2(B, 30);
2328  }
2329 
2330  if (SH != 22) {
2331  dest16[0][i] = G >> SH;
2332  dest16[1][i] = B >> SH;
2333  dest16[2][i] = R >> SH;
2334  if (hasAlpha)
2335  dest16[3][i] = A >> (SH - 3);
2336  } else {
2337  dest[0][i] = G >> 22;
2338  dest[1][i] = B >> 22;
2339  dest[2][i] = R >> 22;
2340  if (hasAlpha)
2341  dest[3][i] = A >> 19;
2342  }
2343  }
2344  if (SH != 22 && (!isBE(c->opts.dst_format)) != (!HAVE_BIGENDIAN)) {
2345  for (i = 0; i < dstW; i++) {
2346  dest16[0][i] = av_bswap16(dest16[0][i]);
2347  dest16[1][i] = av_bswap16(dest16[1][i]);
2348  dest16[2][i] = av_bswap16(dest16[2][i]);
2349  if (hasAlpha)
2350  dest16[3][i] = av_bswap16(dest16[3][i]);
2351  }
2352  }
2353 }
2354 
2355 static void
2356 yuv2gbrp16_full_X_c(SwsInternal *c, const int16_t *lumFilter,
2357  const int16_t **lumSrcx, int lumFilterSize,
2358  const int16_t *chrFilter, const int16_t **chrUSrcx,
2359  const int16_t **chrVSrcx, int chrFilterSize,
2360  const int16_t **alpSrcx, uint8_t **dest,
2361  int dstW, int y)
2362 {
2363  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->opts.dst_format);
2364  int i;
2365  int hasAlpha = (desc->flags & AV_PIX_FMT_FLAG_ALPHA) && alpSrcx;
2366  uint16_t **dest16 = (uint16_t**)dest;
2367  const int32_t **lumSrc = (const int32_t**)lumSrcx;
2368  const int32_t **chrUSrc = (const int32_t**)chrUSrcx;
2369  const int32_t **chrVSrc = (const int32_t**)chrVSrcx;
2370  const int32_t **alpSrc = (const int32_t**)alpSrcx;
2371 
2372  for (i = 0; i < dstW; i++) {
2373  int j;
2374  int Y = -0x40000000;
2375  int U = -(128 << 23);
2376  int V = -(128 << 23);
2377  int R, G, B, A;
2378 
2379  for (j = 0; j < lumFilterSize; j++)
2380  Y += lumSrc[j][i] * (unsigned)lumFilter[j];
2381 
2382  for (j = 0; j < chrFilterSize; j++) {
2383  U += chrUSrc[j][i] * (unsigned)chrFilter[j];
2384  V += chrVSrc[j][i] * (unsigned)chrFilter[j];
2385  }
2386 
2387  Y >>= 14;
2388  Y += 0x10000;
2389  U >>= 14;
2390  V >>= 14;
2391 
2392  if (hasAlpha) {
2393  A = -0x40000000;
2394 
2395  for (j = 0; j < lumFilterSize; j++)
2396  A += alpSrc[j][i] * (unsigned)lumFilter[j];
2397 
2398  A >>= 1;
2399  A += 0x20002000;
2400  }
2401 
2402  Y -= c->yuv2rgb_y_offset;
2403  Y *= c->yuv2rgb_y_coeff;
2404  Y += (1 << 13) - (1 << 29);
2405  R = V * c->yuv2rgb_v2r_coeff;
2406  G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
2407  B = U * c->yuv2rgb_u2b_coeff;
2408 
2409  dest16[2][i] = av_clip_uintp2(((Y + R) >> 14) + (1<<15), 16);
2410  dest16[0][i] = av_clip_uintp2(((Y + G) >> 14) + (1<<15), 16);
2411  dest16[1][i] = av_clip_uintp2(((Y + B) >> 14) + (1<<15), 16);
2412 
2413  if (hasAlpha)
2414  dest16[3][i] = av_clip_uintp2(A, 30) >> 14;
2415  }
2416  if ((!isBE(c->opts.dst_format)) != (!HAVE_BIGENDIAN)) {
2417  for (i = 0; i < dstW; i++) {
2418  dest16[0][i] = av_bswap16(dest16[0][i]);
2419  dest16[1][i] = av_bswap16(dest16[1][i]);
2420  dest16[2][i] = av_bswap16(dest16[2][i]);
2421  if (hasAlpha)
2422  dest16[3][i] = av_bswap16(dest16[3][i]);
2423  }
2424  }
2425 }
2426 
2427 static void
2428 yuv2gbrpf32_full_X_c(SwsInternal *c, const int16_t *lumFilter,
2429  const int16_t **lumSrcx, int lumFilterSize,
2430  const int16_t *chrFilter, const int16_t **chrUSrcx,
2431  const int16_t **chrVSrcx, int chrFilterSize,
2432  const int16_t **alpSrcx, uint8_t **dest,
2433  int dstW, int y)
2434 {
2435  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->opts.dst_format);
2436  int i;
2437  int hasAlpha = (desc->flags & AV_PIX_FMT_FLAG_ALPHA) && alpSrcx;
2438  uint32_t **dest32 = (uint32_t**)dest;
2439  const int32_t **lumSrc = (const int32_t**)lumSrcx;
2440  const int32_t **chrUSrc = (const int32_t**)chrUSrcx;
2441  const int32_t **chrVSrc = (const int32_t**)chrVSrcx;
2442  const int32_t **alpSrc = (const int32_t**)alpSrcx;
2443  static const float float_mult = 1.0f / 65535.0f;
2444 
2445  for (i = 0; i < dstW; i++) {
2446  int j;
2447  int Y = -0x40000000;
2448  int U = -(128 << 23);
2449  int V = -(128 << 23);
2450  int R, G, B, A;
2451 
2452  for (j = 0; j < lumFilterSize; j++)
2453  Y += lumSrc[j][i] * (unsigned)lumFilter[j];
2454 
2455  for (j = 0; j < chrFilterSize; j++) {
2456  U += chrUSrc[j][i] * (unsigned)chrFilter[j];
2457  V += chrVSrc[j][i] * (unsigned)chrFilter[j];
2458  }
2459 
2460  Y >>= 14;
2461  Y += 0x10000;
2462  U >>= 14;
2463  V >>= 14;
2464 
2465  if (hasAlpha) {
2466  A = -0x40000000;
2467 
2468  for (j = 0; j < lumFilterSize; j++)
2469  A += alpSrc[j][i] * (unsigned)lumFilter[j];
2470 
2471  A >>= 1;
2472  A += 0x20002000;
2473  }
2474 
2475  Y -= c->yuv2rgb_y_offset;
2476  Y *= c->yuv2rgb_y_coeff;
2477  Y += (1 << 13) - (1 << 29);
2478  R = V * c->yuv2rgb_v2r_coeff;
2479  G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
2480  B = U * c->yuv2rgb_u2b_coeff;
2481 
2482  R = av_clip_uintp2(((Y + R) >> 14) + (1<<15), 16);
2483  G = av_clip_uintp2(((Y + G) >> 14) + (1<<15), 16);
2484  B = av_clip_uintp2(((Y + B) >> 14) + (1<<15), 16);
2485 
2486  dest32[0][i] = av_float2int(float_mult * (float)G);
2487  dest32[1][i] = av_float2int(float_mult * (float)B);
2488  dest32[2][i] = av_float2int(float_mult * (float)R);
2489  if (hasAlpha)
2490  dest32[3][i] = av_float2int(float_mult * (float)(av_clip_uintp2(A, 30) >> 14));
2491  }
2492  if ((!isBE(c->opts.dst_format)) != (!HAVE_BIGENDIAN)) {
2493  for (i = 0; i < dstW; i++) {
2494  dest32[0][i] = av_bswap32(dest32[0][i]);
2495  dest32[1][i] = av_bswap32(dest32[1][i]);
2496  dest32[2][i] = av_bswap32(dest32[2][i]);
2497  if (hasAlpha)
2498  dest32[3][i] = av_bswap32(dest32[3][i]);
2499  }
2500  }
2501 }
2502 
2503 static void
2504 yuv2ya8_1_c(SwsInternal *c, const int16_t *buf0,
2505  const int16_t *ubuf[2], const int16_t *vbuf[2],
2506  const int16_t *abuf0, uint8_t *dest, int dstW,
2507  int uvalpha, int y)
2508 {
2509  int hasAlpha = !!abuf0;
2510  int i;
2511 
2512  for (i = 0; i < dstW; i++) {
2513  int Y = (buf0[i] + 64) >> 7;
2514  int A;
2515 
2516  Y = av_clip_uint8(Y);
2517 
2518  if (hasAlpha) {
2519  A = (abuf0[i] + 64) >> 7;
2520  if (A & 0x100)
2521  A = av_clip_uint8(A);
2522  }
2523 
2524  dest[i * 2 ] = Y;
2525  dest[i * 2 + 1] = hasAlpha ? A : 255;
2526  }
2527 }
2528 
2529 static void
2530 yuv2ya8_2_c(SwsInternal *c, const int16_t *buf[2],
2531  const int16_t *ubuf[2], const int16_t *vbuf[2],
2532  const int16_t *abuf[2], uint8_t *dest, int dstW,
2533  int yalpha, int uvalpha, int y)
2534 {
2535  int hasAlpha = abuf && abuf[0] && abuf[1];
2536  const int16_t *buf0 = buf[0], *buf1 = buf[1],
2537  *abuf0 = hasAlpha ? abuf[0] : NULL,
2538  *abuf1 = hasAlpha ? abuf[1] : NULL;
2539  int yalpha1 = 4096 - yalpha;
2540  int i;
2541 
2542  av_assert2(yalpha <= 4096U);
2543 
2544  for (i = 0; i < dstW; i++) {
2545  int Y = (buf0[i] * yalpha1 + buf1[i] * yalpha) >> 19;
2546  int A;
2547 
2548  Y = av_clip_uint8(Y);
2549 
2550  if (hasAlpha) {
2551  A = (abuf0[i] * yalpha1 + abuf1[i] * yalpha) >> 19;
2552  A = av_clip_uint8(A);
2553  }
2554 
2555  dest[i * 2 ] = Y;
2556  dest[i * 2 + 1] = hasAlpha ? A : 255;
2557  }
2558 }
2559 
2560 static void
2561 yuv2ya8_X_c(SwsInternal *c, const int16_t *lumFilter,
2562  const int16_t **lumSrc, int lumFilterSize,
2563  const int16_t *chrFilter, const int16_t **chrUSrc,
2564  const int16_t **chrVSrc, int chrFilterSize,
2565  const int16_t **alpSrc, uint8_t *dest, int dstW, int y)
2566 {
2567  int hasAlpha = !!alpSrc;
2568  int i;
2569 
2570  for (i = 0; i < dstW; i++) {
2571  int j;
2572  int Y = 1 << 18, A = 1 << 18;
2573 
2574  for (j = 0; j < lumFilterSize; j++)
2575  Y += lumSrc[j][i] * lumFilter[j];
2576 
2577  Y >>= 19;
2578  if (Y & 0x100)
2579  Y = av_clip_uint8(Y);
2580 
2581  if (hasAlpha) {
2582  for (j = 0; j < lumFilterSize; j++)
2583  A += alpSrc[j][i] * lumFilter[j];
2584 
2585  A >>= 19;
2586 
2587  if (A & 0x100)
2588  A = av_clip_uint8(A);
2589  }
2590 
2591  dest[2 * i ] = Y;
2592  dest[2 * i + 1] = hasAlpha ? A : 255;
2593  }
2594 }
2595 
2596 #define output_pixels(pos, val) \
2597  if (is_be) { \
2598  AV_WB16(pos, val); \
2599  } else { \
2600  AV_WL16(pos, val); \
2601  }
2602 
2603 static av_always_inline void
2604 yuv2ayuv64_X_c(SwsInternal *c, const int16_t *lumFilter,
2605  const int16_t **_lumSrc, int lumFilterSize,
2606  const int16_t *chrFilter, const int16_t **_chrUSrc,
2607  const int16_t **_chrVSrc, int chrFilterSize,
2608  const int16_t **_alpSrc, uint8_t *dest, int dstW, int y,
2609  int A_offset, int Y_offset, int U_offset, int V_offset, int is_be)
2610 {
2611  const int32_t **lumSrc = (const int32_t **) _lumSrc,
2612  **chrUSrc = (const int32_t **) _chrUSrc,
2613  **chrVSrc = (const int32_t **) _chrVSrc,
2614  **alpSrc = (const int32_t **) _alpSrc;
2615  int hasAlpha = !!alpSrc;
2616  int i;
2617 
2618  for (i = 0; i < dstW; i++) {
2619  int Y = 1 << 14, U = 1 << 14;
2620  int V = 1 << 14, A = 1 << 14;
2621  int j;
2622 
2623  Y -= 0x40000000;
2624  U -= 0x40000000;
2625  V -= 0x40000000;
2626  A -= 0x40000000;
2627 
2628  for (j = 0; j < lumFilterSize; j++)
2629  Y += lumSrc[j][i] * (unsigned)lumFilter[j];
2630 
2631  for (j = 0; j < chrFilterSize; j++)
2632  U += chrUSrc[j][i] * (unsigned)chrFilter[j];
2633 
2634  for (j = 0; j < chrFilterSize; j++)
2635  V += chrVSrc[j][i] * (unsigned)chrFilter[j];
2636 
2637  if (hasAlpha)
2638  for (j = 0; j < lumFilterSize; j++)
2639  A += alpSrc[j][i] * (unsigned)lumFilter[j];
2640 
2641  Y = 0x8000 + av_clip_int16(Y >> 15);
2642  U = 0x8000 + av_clip_int16(U >> 15);
2643  V = 0x8000 + av_clip_int16(V >> 15);
2644  if (hasAlpha)
2645  A = 0x8000 + av_clip_int16(A >> 15);
2646 
2647  output_pixels(dest + 8 * i + A_offset, hasAlpha ? A : 65535);
2648  output_pixels(dest + 8 * i + Y_offset, Y);
2649  output_pixels(dest + 8 * i + U_offset, U);
2650  output_pixels(dest + 8 * i + V_offset, V);
2651  }
2652 }
2653 
2654 #define YUV2AYUV64(pixfmt, BE_LE, A, Y, U, V, is_be) \
2655 static void \
2656 yuv2 ## pixfmt ## BE_LE ##_X_c(SwsInternal *c, const int16_t *lumFilter, \
2657  const int16_t **lumSrc, int lumFilterSize, \
2658  const int16_t *chrFilter, const int16_t **chrUSrc, \
2659  const int16_t **chrVSrc, int chrFilterSize, \
2660  const int16_t **alpSrc, uint8_t *dest, int dstW, int y) \
2661 { \
2662  yuv2ayuv64_X_c(c, lumFilter, lumSrc, lumFilterSize, \
2663  chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
2664  alpSrc, dest, dstW, y, A, Y, U, V, is_be); \
2665 }
2666 
2667 YUV2AYUV64(ayuv64, le, 0, 2, 4, 6, 0)
2668 YUV2AYUV64(ayuv64, be, 0, 2, 4, 6, 1)
2669 
2670 YUV2AYUV64(xv48, le, 6, 2, 0, 4, 0)
2671 YUV2AYUV64(xv48, be, 6, 2, 0, 4, 1)
2672 
2673 #undef output_pixels
2674 
2675 static av_always_inline void
2676 yuv2v30_X_c_template(SwsInternal *c, const int16_t *lumFilter,
2677  const int16_t **lumSrc, int lumFilterSize,
2678  const int16_t *chrFilter, const int16_t **chrUSrc,
2679  const int16_t **chrVSrc, int chrFilterSize,
2680  const int16_t **alpSrc, uint8_t *dest, int dstW, int y,
2681  int shift)
2682 {
2683  int i;
2684  for (i = 0; i < dstW; i++) {
2685  int Y = 1 << 16, U = 1 << 16, V = 1 << 16, A = 0x3;
2686  int j;
2687 
2688  for (j = 0; j < lumFilterSize; j++)
2689  Y += lumSrc[j][i] * lumFilter[j];
2690 
2691  for (j = 0; j < chrFilterSize; j++) {
2692  U += chrUSrc[j][i] * chrFilter[j];
2693  V += chrVSrc[j][i] * chrFilter[j];
2694  }
2695 
2696  Y = av_clip_uintp2(Y >> 17, 10);
2697  U = av_clip_uintp2(U >> 17, 10);
2698  V = av_clip_uintp2(V >> 17, 10);
2699 
2700  AV_WL32(dest + 4 * i, U << (shift + 0) |
2701  Y << (shift + 10) |
2702  (unsigned)V << (shift + 20) |
2703  (unsigned)A << (shift ? 0 : 30 /* xv30le = 30, v30xle = 0 */));
2704  }
2705 }
2706 
2707 #define V30LE_WRAPPER(name, shift) \
2708 static void yuv2 ## name ## _X_c(SwsInternal *c, const int16_t *lumFilter, \
2709  const int16_t **lumSrc, int lumFilterSize, \
2710  const int16_t *chrFilter, const int16_t **chrUSrc, \
2711  const int16_t **chrVSrc, int chrFilterSize, \
2712  const int16_t **alpSrc, uint8_t *dest, int dstW, \
2713  int y) \
2714 { \
2715  yuv2v30_X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
2716  chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
2717  alpSrc, dest, dstW, y, shift); \
2718 }
2719 
2720 V30LE_WRAPPER(xv30le, 0)
2721 V30LE_WRAPPER(v30xle, 2)
2722 
2723 #define output_pixels(pos, val, shift, bits, output_shift) \
2724  if (is_be) { \
2725  AV_WB16(pos, av_clip_uintp2(val >> shift, bits) << output_shift); \
2726  } else { \
2727  AV_WL16(pos, av_clip_uintp2(val >> shift, bits) << output_shift); \
2728  }
2729 
2730 static void
2731 yuv2xv36_X_c(SwsInternal *c, const int16_t *lumFilter,
2732  const int16_t **lumSrc, int lumFilterSize,
2733  const int16_t *chrFilter, const int16_t **chrUSrc,
2734  const int16_t **chrVSrc, int chrFilterSize,
2735  const int16_t **alpSrc, uint8_t *dest, int dstW, int y, int is_be)
2736 {
2737  int i;
2738  for (i = 0; i < dstW; i++) {
2739  int Y = 1 << 14, U = 1 << 14, V = 1 << 14, A = 65535;
2740  int j;
2741 
2742  for (j = 0; j < lumFilterSize; j++)
2743  Y += lumSrc[j][i] * lumFilter[j];
2744 
2745  for (j = 0; j < chrFilterSize; j++) {
2746  U += chrUSrc[j][i] * chrFilter[j];
2747  V += chrVSrc[j][i] * chrFilter[j];
2748  }
2749 
2750  output_pixels(dest + 8 * i + 2, Y, 15, 12, 4)
2751  output_pixels(dest + 8 * i + 0, U, 15, 12, 4)
2752  output_pixels(dest + 8 * i + 4, V, 15, 12, 4)
2753  output_pixels(dest + 8 * i + 6, A, 0, 12, 4);
2754  }
2755 }
2756 
2757 #undef output_pixels
2758 
2759 #define YUV2XV36(BE_LE, is_be) \
2760 static void \
2761 yuv2xv36 ## BE_LE ##_X_c(SwsInternal *c, const int16_t *lumFilter, \
2762  const int16_t **lumSrc, int lumFilterSize, \
2763  const int16_t *chrFilter, const int16_t **chrUSrc, \
2764  const int16_t **chrVSrc, int chrFilterSize, \
2765  const int16_t **alpSrc, uint8_t *dest, int dstW, int y) \
2766 { \
2767  yuv2xv36_X_c(c, lumFilter, lumSrc, lumFilterSize, \
2768  chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
2769  alpSrc, dest, dstW, y, is_be); \
2770 }
2771 
2772 YUV2XV36(le, 0)
2773 YUV2XV36(be, 1)
2774 
2775 #define output_pixels(pos, A, Y, U, V) \
2776  if (target == AV_PIX_FMT_AYUV) { \
2777  dest[pos + 0] = A; \
2778  dest[pos + 1] = Y; \
2779  dest[pos + 2] = U; \
2780  dest[pos + 3] = V; \
2781  } else if (target == AV_PIX_FMT_UYVA) { \
2782  dest[pos + 0] = U; \
2783  dest[pos + 1] = Y; \
2784  dest[pos + 2] = V; \
2785  dest[pos + 3] = A; \
2786  } else { /* AV_PIX_FMT_VUYA || AV_PIX_FMT_VUYX */ \
2787  dest[pos + 0] = V; \
2788  dest[pos + 1] = U; \
2789  dest[pos + 2] = Y; \
2790  dest[pos + 3] = A; \
2791  }
2792 
2793 static av_always_inline void
2794 yuv2ayuv_1_c_template(SwsInternal *c, const int16_t *buf0,
2795  const int16_t *ubuf[2], const int16_t *vbuf[2],
2796  const int16_t *abuf0, uint8_t *dest, int dstW,
2797  int uvalpha, int y, enum AVPixelFormat target)
2798 {
2799  int hasAlpha = !!abuf0;
2800  int i;
2801 
2802  if (uvalpha < 2048) {
2803  for (i = 0; i < dstW; i++) {
2804  int Y = (buf0[i] + 64) >> 7;
2805  int U = (ubuf[0][i] + 64) >> 7;
2806  int V = (vbuf[0][i] + 64) >> 7;
2807  int A = 255;
2808 
2809  if (Y & 0x100)
2810  Y = av_clip_uint8(Y);
2811  if (U & 0x100)
2812  U = av_clip_uint8(U);
2813  if (V & 0x100)
2814  V = av_clip_uint8(V);
2815 
2816  if (hasAlpha) {
2817  A = (abuf0[i] + 64) >> 7;
2818  if (A & 0x100)
2819  A = av_clip_uint8(A);
2820  }
2821 
2822  output_pixels(i * 4, A, Y, U, V)
2823  }
2824  } else {
2825  for (i = 0; i < dstW; i++) {
2826  int Y = (buf0[i] + 64) >> 7;
2827  int U = (ubuf[0][i] + ubuf[1][i] + 128) >> 8;
2828  int V = (vbuf[0][i] + vbuf[1][i] + 128) >> 8;
2829  int A = 255;
2830 
2831  if (Y & 0x100)
2832  Y = av_clip_uint8(Y);
2833  if (U & 0x100)
2834  U = av_clip_uint8(U);
2835  if (V & 0x100)
2836  V = av_clip_uint8(V);
2837 
2838  if (hasAlpha) {
2839  A = (abuf0[i] + 64) >> 7;
2840  if (A & 0x100)
2841  A = av_clip_uint8(A);
2842  }
2843 
2844  output_pixels(i * 4, A, Y, U, V)
2845  }
2846  }
2847 }
2848 
2849 static av_always_inline void
2850 yuv2ayuv_2_c_template(SwsInternal *c, const int16_t *buf[2],
2851  const int16_t *ubuf[2], const int16_t *vbuf[2],
2852  const int16_t *abuf[2], uint8_t *dest, int dstW,
2853  int yalpha, int uvalpha, int y,
2854  enum AVPixelFormat target)
2855 {
2856  int hasAlpha = abuf && abuf[0] && abuf[1];
2857  const int16_t *buf0 = buf[0], *buf1 = buf[1],
2858  *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
2859  *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
2860  *abuf0 = hasAlpha ? abuf[0] : NULL,
2861  *abuf1 = hasAlpha ? abuf[1] : NULL;
2862  int yalpha1 = 4096 - yalpha;
2863  int uvalpha1 = 4096 - uvalpha;
2864  int i;
2865 
2866  av_assert2(yalpha <= 4096U);
2867  av_assert2(uvalpha <= 4096U);
2868 
2869  for (i = 0; i < dstW; i++) {
2870  int Y = (buf0[i] * yalpha1 + buf1[i] * yalpha) >> 19;
2871  int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha) >> 19;
2872  int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha) >> 19;
2873  int A = 255;
2874 
2875  if (Y & 0x100)
2876  Y = av_clip_uint8(Y);
2877  if (U & 0x100)
2878  U = av_clip_uint8(U);
2879  if (V & 0x100)
2880  V = av_clip_uint8(V);
2881 
2882  if (hasAlpha) {
2883  A = (abuf0[i] * yalpha1 + abuf1[i] * yalpha) >> 19;
2884  A = av_clip_uint8(A);
2885  }
2886 
2887  output_pixels(i * 4, A, Y, U, V)
2888  }
2889 }
2890 
2891 static av_always_inline void
2892 yuv2ayuv_X_c_template(SwsInternal *c, const int16_t *lumFilter,
2893  const int16_t **lumSrc, int lumFilterSize,
2894  const int16_t *chrFilter, const int16_t **chrUSrc,
2895  const int16_t **chrVSrc, int chrFilterSize,
2896  const int16_t **alpSrc, uint8_t *dest, int dstW,
2897  int y, enum AVPixelFormat target)
2898 {
2899  int i;
2900 
2901  for (i = 0; i < dstW; i++) {
2902  int j;
2903  int Y = 1 << 18, U = 1 << 18;
2904  int V = 1 << 18, A = 255;
2905 
2906  for (j = 0; j < lumFilterSize; j++)
2907  Y += lumSrc[j][i] * lumFilter[j];
2908 
2909  for (j = 0; j < chrFilterSize; j++)
2910  U += chrUSrc[j][i] * chrFilter[j];
2911 
2912  for (j = 0; j < chrFilterSize; j++)
2913  V += chrVSrc[j][i] * chrFilter[j];
2914 
2915  Y >>= 19;
2916  U >>= 19;
2917  V >>= 19;
2918 
2919  if (Y & 0x100)
2920  Y = av_clip_uint8(Y);
2921  if (U & 0x100)
2922  U = av_clip_uint8(U);
2923  if (V & 0x100)
2924  V = av_clip_uint8(V);
2925 
2926  if (alpSrc) {
2927  A = 1 << 18;
2928 
2929  for (j = 0; j < lumFilterSize; j++)
2930  A += alpSrc[j][i] * lumFilter[j];
2931 
2932  A >>= 19;
2933 
2934  if (A & 0x100)
2935  A = av_clip_uint8(A);
2936  }
2937 
2938  output_pixels(i * 4, A, Y, U, V)
2939  }
2940 }
2941 
2942 #undef output_pixels
2943 
2944 #define AYUVPACKEDWRAPPER(name, fmt) \
2945 static void yuv2 ## name ## _X_c(SwsInternal *c, const int16_t *lumFilter, \
2946  const int16_t **lumSrc, int lumFilterSize, \
2947  const int16_t *chrFilter, const int16_t **chrUSrc, \
2948  const int16_t **chrVSrc, int chrFilterSize, \
2949  const int16_t **alpSrc, uint8_t *dest, int dstW, \
2950  int y) \
2951 { \
2952  yuv2ayuv_X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
2953  chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
2954  alpSrc, dest, dstW, y, fmt); \
2955 } \
2956  \
2957 static void yuv2 ## name ## _2_c(SwsInternal *c, const int16_t *buf[2], \
2958  const int16_t *ubuf[2], const int16_t *vbuf[2], \
2959  const int16_t *abuf[2], uint8_t *dest, int dstW, \
2960  int yalpha, int uvalpha, int y) \
2961 { \
2962  yuv2ayuv_2_c_template(c, buf, ubuf, vbuf, abuf, \
2963  dest, dstW, yalpha, uvalpha, y, fmt); \
2964 } \
2965  \
2966 static void yuv2 ## name ## _1_c(SwsInternal *c, const int16_t *buf0, \
2967  const int16_t *ubuf[2], const int16_t *vbuf[2], \
2968  const int16_t *abuf0, uint8_t *dest, int dstW, \
2969  int uvalpha, int y) \
2970 { \
2971  yuv2ayuv_1_c_template(c, buf0, ubuf, vbuf, \
2972  abuf0, dest, dstW, uvalpha, \
2973  y, fmt); \
2974 }
2975 
2979 
2980 #define output_pixel(pos, val, bits) \
2981  AV_WL16(pos, av_clip_uintp2(val >> shift, bits) << output_shift);
2982 
2983 #define yuv2y2xx_wrapper(bits) \
2984  static void \
2985  yuv2y2 ## bits ## le_X_c(SwsInternal *c, const int16_t *lumFilter, \
2986  const int16_t **lumSrc, int lumFilterSize, \
2987  const int16_t *chrFilter, \
2988  const int16_t **chrUSrc, \
2989  const int16_t **chrVSrc, int chrFilterSize, \
2990  const int16_t **alpSrc, \
2991  uint8_t *dest, int dstW, int y) \
2992  { \
2993  int i, j; \
2994  int shift = 11 + 16 - bits; \
2995  int output_shift = 16 - bits; \
2996  for (i = 0; i < ((dstW + 1) >> 1); i++) { \
2997  int Y1 = 1 << (shift - 1), Y2 = 1 << (shift - 1); \
2998  int U = 1 << (shift - 1), V = 1 << (shift - 1); \
2999  \
3000  for (j = 0; j < lumFilterSize; j++) { \
3001  Y1 += lumSrc[j][i * 2] * lumFilter[j]; \
3002  Y2 += lumSrc[j][i * 2 + 1] * lumFilter[j]; \
3003  } \
3004  \
3005  for (j = 0; j < chrFilterSize; j++) { \
3006  U += chrUSrc[j][i] * chrFilter[j]; \
3007  V += chrVSrc[j][i] * chrFilter[j]; \
3008  } \
3009  \
3010  output_pixel(dest + 8 * i + 0, Y1, bits); \
3011  output_pixel(dest + 8 * i + 2, U, bits); \
3012  output_pixel(dest + 8 * i + 4, Y2, bits); \
3013  output_pixel(dest + 8 * i + 6, V, bits); \
3014  } \
3015  }
3016 
3018 yuv2y2xx_wrapper(12)
3019 
3020 static void
3021 yuv2y216le_X_c(SwsInternal *c, const int16_t *lumFilter,
3022  const int16_t **_lumSrc, int lumFilterSize,
3023  const int16_t *chrFilter,
3024  const int16_t **_chrUSrc,
3025  const int16_t **_chrVSrc, int chrFilterSize,
3026  const int16_t **_alpSrc,
3027  uint8_t *dest, int dstW, int y)
3028 {
3029  const int32_t **lumSrc = (const int32_t **)_lumSrc;
3030  const int32_t **chrUSrc = (const int32_t **)_chrUSrc;
3031  const int32_t **chrVSrc = (const int32_t **)_chrVSrc;
3032  int shift = 15;
3033 
3034  for (int i = 0; i < ((dstW + 1) >> 1); i++) {
3035  int Y1 = 1 << (shift - 1), Y2 = 1 << (shift - 1);
3036  int U = 1 << (shift - 1), V = 1 << (shift - 1);
3037 
3038  /* See yuv2planeX_16_c_template for details. */
3039  Y1 -= 0x40000000;
3040  U -= 0x40000000;
3041  Y2 -= 0x40000000;
3042  V -= 0x40000000;
3043 
3044  for (int j = 0; j < lumFilterSize; j++) {
3045  Y1 += lumSrc[j][i * 2] * (unsigned)lumFilter[j];
3046  Y2 += lumSrc[j][i * 2 + 1] * (unsigned)lumFilter[j];
3047  }
3048 
3049  for (int j = 0; j < chrFilterSize; j++) {
3050  U += chrUSrc[j][i] * (unsigned)chrFilter[j];
3051  V += chrVSrc[j][i] * (unsigned)chrFilter[j];
3052  }
3053 
3054  AV_WL16(dest + 8 * i + 0, 0x8000 + av_clip_int16(Y1 >> shift));
3055  AV_WL16(dest + 8 * i + 2, 0x8000 + av_clip_int16(U >> shift));
3056  AV_WL16(dest + 8 * i + 4, 0x8000 + av_clip_int16(Y2 >> shift));
3057  AV_WL16(dest + 8 * i + 6, 0x8000 + av_clip_int16(V >> shift));
3058  }
3059 }
3060 
3061 static void
3062 yuv2vyu444_1_c(SwsInternal *c, const int16_t *buf0,
3063  const int16_t *ubuf[2], const int16_t *vbuf[2],
3064  const int16_t *abuf0, uint8_t *dest, int dstW,
3065  int uvalpha, int y)
3066 {
3067  int i;
3068 
3069  if (uvalpha < 2048) {
3070  for (i = 0; i < dstW; i++) {
3071  int Y = (buf0[i] + 64) >> 7;
3072  int U = (ubuf[0][i] + 64) >> 7;
3073  int V = (vbuf[0][i] + 64) >> 7;
3074 
3075  if (Y & 0x100)
3076  Y = av_clip_uint8(Y);
3077  if (U & 0x100)
3078  U = av_clip_uint8(U);
3079  if (V & 0x100)
3080  V = av_clip_uint8(V);
3081 
3082  dest[3 * i ] = V;
3083  dest[3 * i + 1] = Y;
3084  dest[3 * i + 2] = U;
3085  }
3086  } else {
3087  for (i = 0; i < dstW; i++) {
3088  int Y = (buf0[i] + 64) >> 7;
3089  int U = (ubuf[0][i] + ubuf[1][i] + 128) >> 8;
3090  int V = (vbuf[0][i] + vbuf[1][i] + 128) >> 8;
3091 
3092  if (Y & 0x100)
3093  Y = av_clip_uint8(Y);
3094  if (U & 0x100)
3095  U = av_clip_uint8(U);
3096  if (V & 0x100)
3097  V = av_clip_uint8(V);
3098 
3099  dest[3 * i ] = V;
3100  dest[3 * i + 1] = Y;
3101  dest[3 * i + 2] = U;
3102  }
3103  }
3104 }
3105 
3106 static void
3107 yuv2vyu444_2_c(SwsInternal *c, const int16_t *buf[2],
3108  const int16_t *ubuf[2], const int16_t *vbuf[2],
3109  const int16_t *abuf[2], uint8_t *dest, int dstW,
3110  int yalpha, int uvalpha, int y)
3111 {
3112  const int16_t *buf0 = buf[0], *buf1 = buf[1],
3113  *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
3114  *vbuf0 = vbuf[0], *vbuf1 = vbuf[1];
3115  int yalpha1 = 4096 - yalpha;
3116  int uvalpha1 = 4096 - uvalpha;
3117  int i;
3118 
3119  av_assert2(yalpha <= 4096U);
3120  av_assert2(uvalpha <= 4096U);
3121 
3122  for (i = 0; i < dstW; i++) {
3123  int Y = (buf0[i] * yalpha1 + buf1[i] * yalpha) >> 19;
3124  int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha) >> 19;
3125  int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha) >> 19;
3126 
3127  if (Y & 0x100)
3128  Y = av_clip_uint8(Y);
3129  if (U & 0x100)
3130  U = av_clip_uint8(U);
3131  if (V & 0x100)
3132  V = av_clip_uint8(V);
3133 
3134  dest[3 * i ] = V;
3135  dest[3 * i + 1] = Y;
3136  dest[3 * i + 2] = U;
3137  }
3138 }
3139 
3140 static void
3141 yuv2vyu444_X_c(SwsInternal *c, const int16_t *lumFilter,
3142  const int16_t **lumSrc, int lumFilterSize,
3143  const int16_t *chrFilter, const int16_t **chrUSrc,
3144  const int16_t **chrVSrc, int chrFilterSize,
3145  const int16_t **alpSrc, uint8_t *dest, int dstW, int y)
3146 {
3147  int i;
3148 
3149  for (i = 0; i < dstW; i++) {
3150  int j;
3151  int Y = 1 << 18, U = 1 << 18;
3152  int V = 1 << 18;
3153 
3154  for (j = 0; j < lumFilterSize; j++)
3155  Y += lumSrc[j][i] * lumFilter[j];
3156 
3157  for (j = 0; j < chrFilterSize; j++)
3158  U += chrUSrc[j][i] * chrFilter[j];
3159 
3160  for (j = 0; j < chrFilterSize; j++)
3161  V += chrVSrc[j][i] * chrFilter[j];
3162 
3163  Y >>= 19;
3164  U >>= 19;
3165  V >>= 19;
3166 
3167  if (Y & 0x100)
3168  Y = av_clip_uint8(Y);
3169  if (U & 0x100)
3170  U = av_clip_uint8(U);
3171  if (V & 0x100)
3172  V = av_clip_uint8(V);
3173 
3174  dest[3 * i ] = V;
3175  dest[3 * i + 1] = Y;
3176  dest[3 * i + 2] = U;
3177  }
3178 }
3179 
3180 #undef output_pixel
3181 
3183  yuv2planar1_fn *yuv2plane1,
3185  yuv2interleavedX_fn *yuv2nv12cX,
3186  yuv2packed1_fn *yuv2packed1,
3187  yuv2packed2_fn *yuv2packed2,
3188  yuv2packedX_fn *yuv2packedX,
3189  yuv2anyX_fn *yuv2anyX)
3190 {
3191  enum AVPixelFormat dstFormat = c->opts.dst_format;
3192  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(dstFormat);
3193 
3194  if (isSemiPlanarYUV(dstFormat) && isDataInHighBits(dstFormat)) {
3195  if (desc->comp[0].depth == 10) {
3196  *yuv2plane1 = isBE(dstFormat) ? yuv2p010l1_BE_c : yuv2p010l1_LE_c;
3197  *yuv2planeX = isBE(dstFormat) ? yuv2p010lX_BE_c : yuv2p010lX_LE_c;
3198  *yuv2nv12cX = isBE(dstFormat) ? yuv2p010cX_BE_c : yuv2p010cX_LE_c;
3199  } else if (desc->comp[0].depth == 12) {
3200  *yuv2plane1 = isBE(dstFormat) ? yuv2p012l1_BE_c : yuv2p012l1_LE_c;
3201  *yuv2planeX = isBE(dstFormat) ? yuv2p012lX_BE_c : yuv2p012lX_LE_c;
3202  *yuv2nv12cX = isBE(dstFormat) ? yuv2p012cX_BE_c : yuv2p012cX_LE_c;
3203  } else
3204  av_assert0(0);
3205  } else if (isSemiPlanarYUV(dstFormat) && isNBPS(dstFormat)) {
3206  if (desc->comp[0].depth == 10) {
3207  *yuv2plane1 = isBE(dstFormat) ? yuv2nv20l1_BE_c : yuv2nv20l1_LE_c;
3208  *yuv2planeX = isBE(dstFormat) ? yuv2nv20lX_BE_c : yuv2nv20lX_LE_c;
3209  *yuv2nv12cX = isBE(dstFormat) ? yuv2nv20cX_BE_c : yuv2nv20cX_LE_c;
3210  } else
3211  av_assert0(0);
3212  } else if (is16BPS(dstFormat)) {
3213  *yuv2planeX = isBE(dstFormat) ? yuv2planeX_16BE_c : yuv2planeX_16LE_c;
3214  *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_16BE_c : yuv2plane1_16LE_c;
3215  if (isSemiPlanarYUV(dstFormat)) {
3216  *yuv2nv12cX = isBE(dstFormat) ? yuv2nv12cX_16BE_c : yuv2nv12cX_16LE_c;
3217  }
3218  } else if (isNBPS(dstFormat)) {
3219  if (desc->comp[0].depth == 9) {
3220  *yuv2planeX = isBE(dstFormat) ? yuv2planeX_9BE_c : yuv2planeX_9LE_c;
3221  *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_9BE_c : yuv2plane1_9LE_c;
3222  } else if (desc->comp[0].depth == 10) {
3223  *yuv2planeX = isBE(dstFormat) ? yuv2planeX_10BE_c : yuv2planeX_10LE_c;
3224  *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_10BE_c : yuv2plane1_10LE_c;
3225  } else if (desc->comp[0].depth == 12) {
3226  *yuv2planeX = isBE(dstFormat) ? yuv2planeX_12BE_c : yuv2planeX_12LE_c;
3227  *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_12BE_c : yuv2plane1_12LE_c;
3228  } else if (desc->comp[0].depth == 14) {
3229  *yuv2planeX = isBE(dstFormat) ? yuv2planeX_14BE_c : yuv2planeX_14LE_c;
3230  *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_14BE_c : yuv2plane1_14LE_c;
3231  } else
3232  av_assert0(0);
3233  } else if (dstFormat == AV_PIX_FMT_GRAYF32BE) {
3234  *yuv2planeX = yuv2planeX_floatBE_c;
3235  *yuv2plane1 = yuv2plane1_floatBE_c;
3236  } else if (dstFormat == AV_PIX_FMT_GRAYF32LE) {
3237  *yuv2planeX = yuv2planeX_floatLE_c;
3238  *yuv2plane1 = yuv2plane1_floatLE_c;
3239  } else {
3240  *yuv2plane1 = yuv2plane1_8_c;
3242  if (isSemiPlanarYUV(dstFormat))
3243  *yuv2nv12cX = yuv2nv12cX_c;
3244  }
3245 
3246  if(c->opts.flags & SWS_FULL_CHR_H_INT) {
3247  switch (dstFormat) {
3248  case AV_PIX_FMT_RGBA:
3249 #if CONFIG_SMALL
3250  *yuv2packedX = yuv2rgba32_full_X_c;
3251  *yuv2packed2 = yuv2rgba32_full_2_c;
3252  *yuv2packed1 = yuv2rgba32_full_1_c;
3253 #else
3254 #if CONFIG_SWSCALE_ALPHA
3255  if (c->needAlpha) {
3256  *yuv2packedX = yuv2rgba32_full_X_c;
3257  *yuv2packed2 = yuv2rgba32_full_2_c;
3258  *yuv2packed1 = yuv2rgba32_full_1_c;
3259  } else
3260 #endif /* CONFIG_SWSCALE_ALPHA */
3261  {
3262  *yuv2packedX = yuv2rgbx32_full_X_c;
3263  *yuv2packed2 = yuv2rgbx32_full_2_c;
3264  *yuv2packed1 = yuv2rgbx32_full_1_c;
3265  }
3266 #endif /* !CONFIG_SMALL */
3267  break;
3268  case AV_PIX_FMT_ARGB:
3269 #if CONFIG_SMALL
3270  *yuv2packedX = yuv2argb32_full_X_c;
3271  *yuv2packed2 = yuv2argb32_full_2_c;
3272  *yuv2packed1 = yuv2argb32_full_1_c;
3273 #else
3274 #if CONFIG_SWSCALE_ALPHA
3275  if (c->needAlpha) {
3276  *yuv2packedX = yuv2argb32_full_X_c;
3277  *yuv2packed2 = yuv2argb32_full_2_c;
3278  *yuv2packed1 = yuv2argb32_full_1_c;
3279  } else
3280 #endif /* CONFIG_SWSCALE_ALPHA */
3281  {
3282  *yuv2packedX = yuv2xrgb32_full_X_c;
3283  *yuv2packed2 = yuv2xrgb32_full_2_c;
3284  *yuv2packed1 = yuv2xrgb32_full_1_c;
3285  }
3286 #endif /* !CONFIG_SMALL */
3287  break;
3288  case AV_PIX_FMT_BGRA:
3289 #if CONFIG_SMALL
3290  *yuv2packedX = yuv2bgra32_full_X_c;
3291  *yuv2packed2 = yuv2bgra32_full_2_c;
3292  *yuv2packed1 = yuv2bgra32_full_1_c;
3293 #else
3294 #if CONFIG_SWSCALE_ALPHA
3295  if (c->needAlpha) {
3296  *yuv2packedX = yuv2bgra32_full_X_c;
3297  *yuv2packed2 = yuv2bgra32_full_2_c;
3298  *yuv2packed1 = yuv2bgra32_full_1_c;
3299  } else
3300 #endif /* CONFIG_SWSCALE_ALPHA */
3301  {
3302  *yuv2packedX = yuv2bgrx32_full_X_c;
3303  *yuv2packed2 = yuv2bgrx32_full_2_c;
3304  *yuv2packed1 = yuv2bgrx32_full_1_c;
3305  }
3306 #endif /* !CONFIG_SMALL */
3307  break;
3308  case AV_PIX_FMT_ABGR:
3309 #if CONFIG_SMALL
3310  *yuv2packedX = yuv2abgr32_full_X_c;
3311  *yuv2packed2 = yuv2abgr32_full_2_c;
3312  *yuv2packed1 = yuv2abgr32_full_1_c;
3313 #else
3314 #if CONFIG_SWSCALE_ALPHA
3315  if (c->needAlpha) {
3316  *yuv2packedX = yuv2abgr32_full_X_c;
3317  *yuv2packed2 = yuv2abgr32_full_2_c;
3318  *yuv2packed1 = yuv2abgr32_full_1_c;
3319  } else
3320 #endif /* CONFIG_SWSCALE_ALPHA */
3321  {
3322  *yuv2packedX = yuv2xbgr32_full_X_c;
3323  *yuv2packed2 = yuv2xbgr32_full_2_c;
3324  *yuv2packed1 = yuv2xbgr32_full_1_c;
3325  }
3326 #endif /* !CONFIG_SMALL */
3327  break;
3328  case AV_PIX_FMT_RGBA64LE:
3329 #if CONFIG_SWSCALE_ALPHA
3330  if (c->needAlpha) {
3331  *yuv2packedX = yuv2rgba64le_full_X_c;
3332  *yuv2packed2 = yuv2rgba64le_full_2_c;
3333  *yuv2packed1 = yuv2rgba64le_full_1_c;
3334  } else
3335 #endif /* CONFIG_SWSCALE_ALPHA */
3336  {
3337  *yuv2packedX = yuv2rgbx64le_full_X_c;
3338  *yuv2packed2 = yuv2rgbx64le_full_2_c;
3339  *yuv2packed1 = yuv2rgbx64le_full_1_c;
3340  }
3341  break;
3342  case AV_PIX_FMT_RGBA64BE:
3343 #if CONFIG_SWSCALE_ALPHA
3344  if (c->needAlpha) {
3345  *yuv2packedX = yuv2rgba64be_full_X_c;
3346  *yuv2packed2 = yuv2rgba64be_full_2_c;
3347  *yuv2packed1 = yuv2rgba64be_full_1_c;
3348  } else
3349 #endif /* CONFIG_SWSCALE_ALPHA */
3350  {
3351  *yuv2packedX = yuv2rgbx64be_full_X_c;
3352  *yuv2packed2 = yuv2rgbx64be_full_2_c;
3353  *yuv2packed1 = yuv2rgbx64be_full_1_c;
3354  }
3355  break;
3356  case AV_PIX_FMT_BGRA64LE:
3357 #if CONFIG_SWSCALE_ALPHA
3358  if (c->needAlpha) {
3359  *yuv2packedX = yuv2bgra64le_full_X_c;
3360  *yuv2packed2 = yuv2bgra64le_full_2_c;
3361  *yuv2packed1 = yuv2bgra64le_full_1_c;
3362  } else
3363 #endif /* CONFIG_SWSCALE_ALPHA */
3364  {
3365  *yuv2packedX = yuv2bgrx64le_full_X_c;
3366  *yuv2packed2 = yuv2bgrx64le_full_2_c;
3367  *yuv2packed1 = yuv2bgrx64le_full_1_c;
3368  }
3369  break;
3370  case AV_PIX_FMT_BGRA64BE:
3371 #if CONFIG_SWSCALE_ALPHA
3372  if (c->needAlpha) {
3373  *yuv2packedX = yuv2bgra64be_full_X_c;
3374  *yuv2packed2 = yuv2bgra64be_full_2_c;
3375  *yuv2packed1 = yuv2bgra64be_full_1_c;
3376  } else
3377 #endif /* CONFIG_SWSCALE_ALPHA */
3378  {
3379  *yuv2packedX = yuv2bgrx64be_full_X_c;
3380  *yuv2packed2 = yuv2bgrx64be_full_2_c;
3381  *yuv2packed1 = yuv2bgrx64be_full_1_c;
3382  }
3383  break;
3384 
3385  case AV_PIX_FMT_RGB24:
3386  *yuv2packedX = yuv2rgb24_full_X_c;
3387  *yuv2packed2 = yuv2rgb24_full_2_c;
3388  *yuv2packed1 = yuv2rgb24_full_1_c;
3389  break;
3390  case AV_PIX_FMT_BGR24:
3391  *yuv2packedX = yuv2bgr24_full_X_c;
3392  *yuv2packed2 = yuv2bgr24_full_2_c;
3393  *yuv2packed1 = yuv2bgr24_full_1_c;
3394  break;
3395  case AV_PIX_FMT_RGB48LE:
3396  *yuv2packedX = yuv2rgb48le_full_X_c;
3397  *yuv2packed2 = yuv2rgb48le_full_2_c;
3398  *yuv2packed1 = yuv2rgb48le_full_1_c;
3399  break;
3400  case AV_PIX_FMT_BGR48LE:
3401  *yuv2packedX = yuv2bgr48le_full_X_c;
3402  *yuv2packed2 = yuv2bgr48le_full_2_c;
3403  *yuv2packed1 = yuv2bgr48le_full_1_c;
3404  break;
3405  case AV_PIX_FMT_RGB48BE:
3406  *yuv2packedX = yuv2rgb48be_full_X_c;
3407  *yuv2packed2 = yuv2rgb48be_full_2_c;
3408  *yuv2packed1 = yuv2rgb48be_full_1_c;
3409  break;
3410  case AV_PIX_FMT_BGR48BE:
3411  *yuv2packedX = yuv2bgr48be_full_X_c;
3412  *yuv2packed2 = yuv2bgr48be_full_2_c;
3413  *yuv2packed1 = yuv2bgr48be_full_1_c;
3414  break;
3415  case AV_PIX_FMT_BGR4_BYTE:
3416  *yuv2packedX = yuv2bgr4_byte_full_X_c;
3417  *yuv2packed2 = yuv2bgr4_byte_full_2_c;
3418  *yuv2packed1 = yuv2bgr4_byte_full_1_c;
3419  break;
3420  case AV_PIX_FMT_RGB4_BYTE:
3421  *yuv2packedX = yuv2rgb4_byte_full_X_c;
3422  *yuv2packed2 = yuv2rgb4_byte_full_2_c;
3423  *yuv2packed1 = yuv2rgb4_byte_full_1_c;
3424  break;
3425  case AV_PIX_FMT_BGR8:
3426  *yuv2packedX = yuv2bgr8_full_X_c;
3427  *yuv2packed2 = yuv2bgr8_full_2_c;
3428  *yuv2packed1 = yuv2bgr8_full_1_c;
3429  break;
3430  case AV_PIX_FMT_RGB8:
3431  *yuv2packedX = yuv2rgb8_full_X_c;
3432  *yuv2packed2 = yuv2rgb8_full_2_c;
3433  *yuv2packed1 = yuv2rgb8_full_1_c;
3434  break;
3435  case AV_PIX_FMT_X2RGB10LE:
3436  *yuv2packedX = yuv2x2rgb10_full_X_c;
3437  *yuv2packed2 = yuv2x2rgb10_full_2_c;
3438  *yuv2packed1 = yuv2x2rgb10_full_1_c;
3439  break;
3440  case AV_PIX_FMT_X2BGR10LE:
3441  *yuv2packedX = yuv2x2bgr10_full_X_c;
3442  *yuv2packed2 = yuv2x2bgr10_full_2_c;
3443  *yuv2packed1 = yuv2x2bgr10_full_1_c;
3444  break;
3445  case AV_PIX_FMT_GBRP:
3446  case AV_PIX_FMT_GBRP9BE:
3447  case AV_PIX_FMT_GBRP9LE:
3448  case AV_PIX_FMT_GBRP10BE:
3449  case AV_PIX_FMT_GBRP10LE:
3450  case AV_PIX_FMT_GBRP12BE:
3451  case AV_PIX_FMT_GBRP12LE:
3452  case AV_PIX_FMT_GBRP14BE:
3453  case AV_PIX_FMT_GBRP14LE:
3454  case AV_PIX_FMT_GBRAP:
3455  case AV_PIX_FMT_GBRAP10BE:
3456  case AV_PIX_FMT_GBRAP10LE:
3457  case AV_PIX_FMT_GBRAP12BE:
3458  case AV_PIX_FMT_GBRAP12LE:
3459  case AV_PIX_FMT_GBRAP14BE:
3460  case AV_PIX_FMT_GBRAP14LE:
3461  *yuv2anyX = yuv2gbrp_full_X_c;
3462  break;
3463  case AV_PIX_FMT_GBRP16BE:
3464  case AV_PIX_FMT_GBRP16LE:
3465  case AV_PIX_FMT_GBRAP16BE:
3466  case AV_PIX_FMT_GBRAP16LE:
3467  *yuv2anyX = yuv2gbrp16_full_X_c;
3468  break;
3469  case AV_PIX_FMT_GBRPF32BE:
3470  case AV_PIX_FMT_GBRPF32LE:
3471  case AV_PIX_FMT_GBRAPF32BE:
3472  case AV_PIX_FMT_GBRAPF32LE:
3473  *yuv2anyX = yuv2gbrpf32_full_X_c;
3474  break;
3475  }
3476  if (!*yuv2packedX && !*yuv2anyX)
3477  goto YUV_PACKED;
3478  } else {
3479  YUV_PACKED:
3480  switch (dstFormat) {
3481  case AV_PIX_FMT_RGBA64LE:
3482 #if CONFIG_SWSCALE_ALPHA
3483  if (c->needAlpha) {
3484  *yuv2packed1 = yuv2rgba64le_1_c;
3485  *yuv2packed2 = yuv2rgba64le_2_c;
3486  *yuv2packedX = yuv2rgba64le_X_c;
3487  } else
3488 #endif /* CONFIG_SWSCALE_ALPHA */
3489  {
3490  *yuv2packed1 = yuv2rgbx64le_1_c;
3491  *yuv2packed2 = yuv2rgbx64le_2_c;
3492  *yuv2packedX = yuv2rgbx64le_X_c;
3493  }
3494  break;
3495  case AV_PIX_FMT_RGBA64BE:
3496 #if CONFIG_SWSCALE_ALPHA
3497  if (c->needAlpha) {
3498  *yuv2packed1 = yuv2rgba64be_1_c;
3499  *yuv2packed2 = yuv2rgba64be_2_c;
3500  *yuv2packedX = yuv2rgba64be_X_c;
3501  } else
3502 #endif /* CONFIG_SWSCALE_ALPHA */
3503  {
3504  *yuv2packed1 = yuv2rgbx64be_1_c;
3505  *yuv2packed2 = yuv2rgbx64be_2_c;
3506  *yuv2packedX = yuv2rgbx64be_X_c;
3507  }
3508  break;
3509  case AV_PIX_FMT_BGRA64LE:
3510 #if CONFIG_SWSCALE_ALPHA
3511  if (c->needAlpha) {
3512  *yuv2packed1 = yuv2bgra64le_1_c;
3513  *yuv2packed2 = yuv2bgra64le_2_c;
3514  *yuv2packedX = yuv2bgra64le_X_c;
3515  } else
3516 #endif /* CONFIG_SWSCALE_ALPHA */
3517  {
3518  *yuv2packed1 = yuv2bgrx64le_1_c;
3519  *yuv2packed2 = yuv2bgrx64le_2_c;
3520  *yuv2packedX = yuv2bgrx64le_X_c;
3521  }
3522  break;
3523  case AV_PIX_FMT_BGRA64BE:
3524 #if CONFIG_SWSCALE_ALPHA
3525  if (c->needAlpha) {
3526  *yuv2packed1 = yuv2bgra64be_1_c;
3527  *yuv2packed2 = yuv2bgra64be_2_c;
3528  *yuv2packedX = yuv2bgra64be_X_c;
3529  } else
3530 #endif /* CONFIG_SWSCALE_ALPHA */
3531  {
3532  *yuv2packed1 = yuv2bgrx64be_1_c;
3533  *yuv2packed2 = yuv2bgrx64be_2_c;
3534  *yuv2packedX = yuv2bgrx64be_X_c;
3535  }
3536  break;
3537  case AV_PIX_FMT_RGB48LE:
3538  *yuv2packed1 = yuv2rgb48le_1_c;
3539  *yuv2packed2 = yuv2rgb48le_2_c;
3540  *yuv2packedX = yuv2rgb48le_X_c;
3541  break;
3542  case AV_PIX_FMT_RGB48BE:
3543  *yuv2packed1 = yuv2rgb48be_1_c;
3544  *yuv2packed2 = yuv2rgb48be_2_c;
3545  *yuv2packedX = yuv2rgb48be_X_c;
3546  break;
3547  case AV_PIX_FMT_BGR48LE:
3548  *yuv2packed1 = yuv2bgr48le_1_c;
3549  *yuv2packed2 = yuv2bgr48le_2_c;
3550  *yuv2packedX = yuv2bgr48le_X_c;
3551  break;
3552  case AV_PIX_FMT_BGR48BE:
3553  *yuv2packed1 = yuv2bgr48be_1_c;
3554  *yuv2packed2 = yuv2bgr48be_2_c;
3555  *yuv2packedX = yuv2bgr48be_X_c;
3556  break;
3557  case AV_PIX_FMT_RGB32:
3558  case AV_PIX_FMT_BGR32:
3559 #if CONFIG_SMALL
3560  *yuv2packed1 = yuv2rgb32_1_c;
3561  *yuv2packed2 = yuv2rgb32_2_c;
3562  *yuv2packedX = yuv2rgb32_X_c;
3563 #else
3564 #if CONFIG_SWSCALE_ALPHA
3565  if (c->needAlpha) {
3566  *yuv2packed1 = yuv2rgba32_1_c;
3567  *yuv2packed2 = yuv2rgba32_2_c;
3568  *yuv2packedX = yuv2rgba32_X_c;
3569  } else
3570 #endif /* CONFIG_SWSCALE_ALPHA */
3571  {
3572  *yuv2packed1 = yuv2rgbx32_1_c;
3573  *yuv2packed2 = yuv2rgbx32_2_c;
3574  *yuv2packedX = yuv2rgbx32_X_c;
3575  }
3576 #endif /* !CONFIG_SMALL */
3577  break;
3578  case AV_PIX_FMT_RGB32_1:
3579  case AV_PIX_FMT_BGR32_1:
3580 #if CONFIG_SMALL
3581  *yuv2packed1 = yuv2rgb32_1_1_c;
3582  *yuv2packed2 = yuv2rgb32_1_2_c;
3583  *yuv2packedX = yuv2rgb32_1_X_c;
3584 #else
3585 #if CONFIG_SWSCALE_ALPHA
3586  if (c->needAlpha) {
3587  *yuv2packed1 = yuv2rgba32_1_1_c;
3588  *yuv2packed2 = yuv2rgba32_1_2_c;
3589  *yuv2packedX = yuv2rgba32_1_X_c;
3590  } else
3591 #endif /* CONFIG_SWSCALE_ALPHA */
3592  {
3593  *yuv2packed1 = yuv2rgbx32_1_1_c;
3594  *yuv2packed2 = yuv2rgbx32_1_2_c;
3595  *yuv2packedX = yuv2rgbx32_1_X_c;
3596  }
3597 #endif /* !CONFIG_SMALL */
3598  break;
3599  case AV_PIX_FMT_RGB24:
3600  *yuv2packed1 = yuv2rgb24_1_c;
3601  *yuv2packed2 = yuv2rgb24_2_c;
3602  *yuv2packedX = yuv2rgb24_X_c;
3603  break;
3604  case AV_PIX_FMT_BGR24:
3605  *yuv2packed1 = yuv2bgr24_1_c;
3606  *yuv2packed2 = yuv2bgr24_2_c;
3607  *yuv2packedX = yuv2bgr24_X_c;
3608  break;
3609  case AV_PIX_FMT_RGB565LE:
3610  case AV_PIX_FMT_RGB565BE:
3611  case AV_PIX_FMT_BGR565LE:
3612  case AV_PIX_FMT_BGR565BE:
3613  *yuv2packed1 = yuv2rgb16_1_c;
3614  *yuv2packed2 = yuv2rgb16_2_c;
3615  *yuv2packedX = yuv2rgb16_X_c;
3616  break;
3617  case AV_PIX_FMT_RGB555LE:
3618  case AV_PIX_FMT_RGB555BE:
3619  case AV_PIX_FMT_BGR555LE:
3620  case AV_PIX_FMT_BGR555BE:
3621  *yuv2packed1 = yuv2rgb15_1_c;
3622  *yuv2packed2 = yuv2rgb15_2_c;
3623  *yuv2packedX = yuv2rgb15_X_c;
3624  break;
3625  case AV_PIX_FMT_RGB444LE:
3626  case AV_PIX_FMT_RGB444BE:
3627  case AV_PIX_FMT_BGR444LE:
3628  case AV_PIX_FMT_BGR444BE:
3629  *yuv2packed1 = yuv2rgb12_1_c;
3630  *yuv2packed2 = yuv2rgb12_2_c;
3631  *yuv2packedX = yuv2rgb12_X_c;
3632  break;
3633  case AV_PIX_FMT_RGB8:
3634  case AV_PIX_FMT_BGR8:
3635  *yuv2packed1 = yuv2rgb8_1_c;
3636  *yuv2packed2 = yuv2rgb8_2_c;
3637  *yuv2packedX = yuv2rgb8_X_c;
3638  break;
3639  case AV_PIX_FMT_RGB4:
3640  case AV_PIX_FMT_BGR4:
3641  *yuv2packed1 = yuv2rgb4_1_c;
3642  *yuv2packed2 = yuv2rgb4_2_c;
3643  *yuv2packedX = yuv2rgb4_X_c;
3644  break;
3645  case AV_PIX_FMT_RGB4_BYTE:
3646  case AV_PIX_FMT_BGR4_BYTE:
3647  *yuv2packed1 = yuv2rgb4b_1_c;
3648  *yuv2packed2 = yuv2rgb4b_2_c;
3649  *yuv2packedX = yuv2rgb4b_X_c;
3650  break;
3651  case AV_PIX_FMT_X2RGB10LE:
3652  case AV_PIX_FMT_X2RGB10BE:
3653  *yuv2packed1 = yuv2x2rgb10_1_c;
3654  *yuv2packed2 = yuv2x2rgb10_2_c;
3655  *yuv2packedX = yuv2x2rgb10_X_c;
3656  break;
3657  case AV_PIX_FMT_X2BGR10LE:
3658  case AV_PIX_FMT_X2BGR10BE:
3659  *yuv2packed1 = yuv2x2bgr10_1_c;
3660  *yuv2packed2 = yuv2x2bgr10_2_c;
3661  *yuv2packedX = yuv2x2bgr10_X_c;
3662  break;
3663  }
3664  }
3665  switch (dstFormat) {
3666  case AV_PIX_FMT_MONOWHITE:
3667  *yuv2packed1 = yuv2monowhite_1_c;
3668  *yuv2packed2 = yuv2monowhite_2_c;
3669  *yuv2packedX = yuv2monowhite_X_c;
3670  break;
3671  case AV_PIX_FMT_MONOBLACK:
3672  *yuv2packed1 = yuv2monoblack_1_c;
3673  *yuv2packed2 = yuv2monoblack_2_c;
3674  *yuv2packedX = yuv2monoblack_X_c;
3675  break;
3676  case AV_PIX_FMT_YUYV422:
3677  *yuv2packed1 = yuv2yuyv422_1_c;
3678  *yuv2packed2 = yuv2yuyv422_2_c;
3679  *yuv2packedX = yuv2yuyv422_X_c;
3680  break;
3681  case AV_PIX_FMT_YVYU422:
3682  *yuv2packed1 = yuv2yvyu422_1_c;
3683  *yuv2packed2 = yuv2yvyu422_2_c;
3684  *yuv2packedX = yuv2yvyu422_X_c;
3685  break;
3686  case AV_PIX_FMT_UYVY422:
3687  *yuv2packed1 = yuv2uyvy422_1_c;
3688  *yuv2packed2 = yuv2uyvy422_2_c;
3689  *yuv2packedX = yuv2uyvy422_X_c;
3690  break;
3691  case AV_PIX_FMT_VYU444:
3692  *yuv2packed1 = yuv2vyu444_1_c;
3693  *yuv2packed2 = yuv2vyu444_2_c;
3694  *yuv2packedX = yuv2vyu444_X_c;
3695  break;
3696  case AV_PIX_FMT_YA8:
3697  *yuv2packed1 = yuv2ya8_1_c;
3698  *yuv2packed2 = yuv2ya8_2_c;
3699  *yuv2packedX = yuv2ya8_X_c;
3700  break;
3701  case AV_PIX_FMT_YA16LE:
3702  *yuv2packed1 = yuv2ya16le_1_c;
3703  *yuv2packed2 = yuv2ya16le_2_c;
3704  *yuv2packedX = yuv2ya16le_X_c;
3705  break;
3706  case AV_PIX_FMT_YA16BE:
3707  *yuv2packed1 = yuv2ya16be_1_c;
3708  *yuv2packed2 = yuv2ya16be_2_c;
3709  *yuv2packedX = yuv2ya16be_X_c;
3710  break;
3711  case AV_PIX_FMT_V30XLE:
3712  *yuv2packedX = yuv2v30xle_X_c;
3713  break;
3714  case AV_PIX_FMT_AYUV64LE:
3715  *yuv2packedX = yuv2ayuv64le_X_c;
3716  break;
3717  case AV_PIX_FMT_AYUV64BE:
3718  *yuv2packedX = yuv2ayuv64be_X_c;
3719  break;
3720  case AV_PIX_FMT_AYUV:
3721  *yuv2packed1 = yuv2ayuv_1_c;
3722  *yuv2packed2 = yuv2ayuv_2_c;
3723  *yuv2packedX = yuv2ayuv_X_c;
3724  break;
3725  case AV_PIX_FMT_VUYA:
3726  case AV_PIX_FMT_VUYX:
3727  *yuv2packed1 = yuv2vuyX_1_c;
3728  *yuv2packed2 = yuv2vuyX_2_c;
3729  *yuv2packedX = yuv2vuyX_X_c;
3730  break;
3731  case AV_PIX_FMT_UYVA:
3732  *yuv2packed1 = yuv2uyva_1_c;
3733  *yuv2packed2 = yuv2uyva_2_c;
3734  *yuv2packedX = yuv2uyva_X_c;
3735  break;
3736  case AV_PIX_FMT_XV30LE:
3737  *yuv2packedX = yuv2xv30le_X_c;
3738  break;
3739  case AV_PIX_FMT_XV36LE:
3740  *yuv2packedX = yuv2xv36le_X_c;
3741  break;
3742  case AV_PIX_FMT_XV36BE:
3743  *yuv2packedX = yuv2xv36be_X_c;
3744  break;
3745  case AV_PIX_FMT_XV48LE:
3746  *yuv2packedX = yuv2xv48le_X_c;
3747  break;
3748  case AV_PIX_FMT_XV48BE:
3749  *yuv2packedX = yuv2xv48be_X_c;
3750  break;
3751  case AV_PIX_FMT_Y210LE:
3752  *yuv2packedX = yuv2y210le_X_c;
3753  break;
3754  case AV_PIX_FMT_Y212LE:
3755  *yuv2packedX = yuv2y212le_X_c;
3756  break;
3757  case AV_PIX_FMT_Y216LE:
3758  *yuv2packedX = yuv2y216le_X_c;
3759  break;
3760  }
3761 }
yuv2rgb_full_1_c_template
static av_always_inline void yuv2rgb_full_1_c_template(SwsInternal *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:2187
yuv2p01xcX_c
static void yuv2p01xcX_c(int big_endian, const uint8_t *chrDither, const int16_t *chrFilter, int chrFilterSize, const int16_t **chrUSrc, const int16_t **chrVSrc, uint8_t *dest8, int chrDstW, int output_bits, int output_shift)
Definition: output.c:504
A
#define A(x)
Definition: vpx_arith.h:28
be
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 be(in the first position) for now. Options ------- Then comes the options array. This is what will define the user accessible options. For example
AV_PIX_FMT_XV30LE
@ AV_PIX_FMT_XV30LE
packed XVYU 4:4:4, 32bpp, (msb)2X 10V 10Y 10U(lsb), little-endian, variant of Y410 where alpha channe...
Definition: pixfmt.h:415
yuv2planar1_fn
void(* yuv2planar1_fn)(const int16_t *src, uint8_t *dest, int dstW, const uint8_t *dither, int offset)
Write one line of horizontally scaled data to planar output without any additional vertical scaling (...
Definition: swscale_internal.h:108
YUV2PACKEDWRAPPER
#define YUV2PACKEDWRAPPER(name, base, ext, fmt)
Definition: output.c:766
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
AV_PIX_FMT_BGR48LE
@ AV_PIX_FMT_BGR48LE
packed RGB 16:16:16, 48bpp, 16B, 16G, 16R, the 2-byte value for each R/G/B component is stored as lit...
Definition: pixfmt.h:146
SWS_DITHER_AUTO
@ SWS_DITHER_AUTO
Definition: swscale.h:81
av_clip
#define av_clip
Definition: common.h:100
ff_dither_4x4_16
const uint8_t ff_dither_4x4_16[][8]
Definition: output.c:52
X_DITHER
#define X_DITHER(u, v)
r
const char * r
Definition: vf_curves.c:127
yuv2rgba64_full_X_c_template
static av_always_inline void yuv2rgba64_full_X_c_template(SwsInternal *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, int is_be)
Definition: output.c:1307
AV_PIX_FMT_YA8
@ AV_PIX_FMT_YA8
8 bits gray, 8 bits alpha
Definition: pixfmt.h:140
AV_PIX_FMT_BGRA64BE
@ AV_PIX_FMT_BGRA64BE
packed RGBA 16:16:16:16, 64bpp, 16B, 16G, 16R, 16A, the 2-byte value for each R/G/B/A component is st...
Definition: pixfmt.h:204
AV_WL32
#define AV_WL32(p, v)
Definition: intreadwrite.h:422
mem_internal.h
yuv2p01x_wrapper
#define yuv2p01x_wrapper(fmt, bits, shift)
Definition: output.c:529
AV_PIX_FMT_BGR32
#define AV_PIX_FMT_BGR32
Definition: pixfmt.h:502
AV_PIX_FMT_RGB444LE
@ AV_PIX_FMT_RGB444LE
packed RGB 4:4:4, 16bpp, (msb)4X 4R 4G 4B(lsb), little-endian, X=unused/undefined
Definition: pixfmt.h:136
u
#define u(width, name, range_min, range_max)
Definition: cbs_h2645.c:251
AV_PIX_FMT_GBRP16BE
@ AV_PIX_FMT_GBRP16BE
planar GBR 4:4:4 48bpp, big-endian
Definition: pixfmt.h:171
AV_PIX_FMT_GBRP10BE
@ AV_PIX_FMT_GBRP10BE
planar GBR 4:4:4 30bpp, big-endian
Definition: pixfmt.h:169
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3341
ff_dither_8x8_32
const uint8_t ff_dither_8x8_32[][8]
Definition: output.c:60
av_clip_uintp2
#define av_clip_uintp2
Definition: common.h:124
yuv2rgba64_full_2_c_template
static av_always_inline void yuv2rgba64_full_2_c_template(SwsInternal *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, int is_be)
Definition: output.c:1372
accumulate_bit
#define accumulate_bit(acc, val)
pixdesc.h
AV_PIX_FMT_RGBA64BE
@ AV_PIX_FMT_RGBA64BE
packed RGBA 16:16:16:16, 64bpp, 16R, 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is st...
Definition: pixfmt.h:202
step
trying all byte sequences megabyte in length and selecting the best looking sequence will yield cases to try But a word about which is also called distortion Distortion can be quantified by almost any quality measurement one chooses the sum of squared differences is used but more complex methods that consider psychovisual effects can be used as well It makes no difference in this discussion First step
Definition: rate_distortion.txt:58
yuv2ya8_1_c
static void yuv2ya8_1_c(SwsInternal *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:2504
AV_PIX_FMT_GBRAPF32LE
@ AV_PIX_FMT_GBRAPF32LE
IEEE-754 single precision planar GBRA 4:4:4:4, 128bpp, little-endian.
Definition: pixfmt.h:344
AV_PIX_FMT_X2BGR10BE
@ AV_PIX_FMT_X2BGR10BE
packed BGR 10:10:10, 30bpp, (msb)2X 10B 10G 10R(lsb), big-endian, X=unused/undefined
Definition: pixfmt.h:387
SWS_DITHER_NONE
@ SWS_DITHER_NONE
Definition: swscale.h:80
AV_PIX_FMT_GBRPF32BE
@ AV_PIX_FMT_GBRPF32BE
IEEE-754 single precision planar GBR 4:4:4, 96bpp, big-endian.
Definition: pixfmt.h:341
yuv2mono_1_c_template
static av_always_inline void yuv2mono_1_c_template(SwsInternal *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:716
yuv2nv12cX_16_c_template
static av_always_inline void yuv2nv12cX_16_c_template(int big_endian, const uint8_t *chrDither, const int16_t *chrFilter, int chrFilterSize, const int16_t **chrUSrc, const int16_t **chrVSrc, uint8_t *dest8, int chrDstW, int output_bits)
Definition: output.c:190
b
#define b
Definition: input.c:42
yuv2planeX
static void FUNC() yuv2planeX(const int16_t *filter, int filterSize, const int16_t **src, uint8_t *dest, int dstW, const uint8_t *dither, int offset)
Definition: swscale_ppc_template.c:84
R
#define R
Definition: huffyuv.h:44
AV_PIX_FMT_MONOWHITE
@ AV_PIX_FMT_MONOWHITE
Y , 1bpp, 0 is white, 1 is black, in each byte pixels are ordered from the msb to the lsb.
Definition: pixfmt.h:82
AV_PIX_FMT_RGB32_1
#define AV_PIX_FMT_RGB32_1
Definition: pixfmt.h:501
yuv2ayuv_2_c_template
static av_always_inline void yuv2ayuv_2_c_template(SwsInternal *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:2850
filter
void(* filter)(uint8_t *src, int stride, int qscale)
Definition: h263dsp.c:29
b_r
#define b_r
AV_PIX_FMT_GBRP14BE
@ AV_PIX_FMT_GBRP14BE
planar GBR 4:4:4 42bpp, big-endian
Definition: pixfmt.h:281
AV_PIX_FMT_BGR24
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:76
AV_PIX_FMT_BGRA
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition: pixfmt.h:102
yuv2ya16_1_c_template
static av_always_inline void yuv2ya16_1_c_template(SwsInternal *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, int is_be)
Definition: output.c:1024
mathematics.h
av_float2int
static av_always_inline uint32_t av_float2int(float f)
Reinterpret a float as a 32-bit integer.
Definition: intfloat.h:50
A2
@ A2
Definition: mvs.c:525
yuv2plane1_8_c
static void yuv2plane1_8_c(const int16_t *src, uint8_t *dest, int dstW, const uint8_t *dither, int offset)
Definition: output.c:421
intfloat.h
AV_PIX_FMT_GRAYF32LE
@ AV_PIX_FMT_GRAYF32LE
IEEE-754 single precision Y, 32bpp, little-endian.
Definition: pixfmt.h:364
yuv2planeX_10_c_template
static av_always_inline void yuv2planeX_10_c_template(const int16_t *filter, int filterSize, const int16_t **src, uint16_t *dest, int dstW, int big_endian, int output_bits)
Definition: output.c:341
AV_PIX_FMT_GBRAP14BE
@ AV_PIX_FMT_GBRAP14BE
planar GBR 4:4:4:4 56bpp, big-endian
Definition: pixfmt.h:432
yuv2xv36_X_c
static void yuv2xv36_X_c(SwsInternal *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, int is_be)
Definition: output.c:2731
AV_PIX_FMT_RGB555BE
@ AV_PIX_FMT_RGB555BE
packed RGB 5:5:5, 16bpp, (msb)1X 5R 5G 5B(lsb), big-endian , X=unused/undefined
Definition: pixfmt.h:114
yuv2p01xlX_c
static void yuv2p01xlX_c(const int16_t *filter, int filterSize, const int16_t **src, uint16_t *dest, int dstW, int big_endian, int output_bits, int output_shift)
Definition: output.c:487
AV_PIX_FMT_AYUV64LE
@ AV_PIX_FMT_AYUV64LE
packed AYUV 4:4:4,64bpp (1 Cr & Cb sample per 1x1 Y & A samples), little-endian
Definition: pixfmt.h:302
AV_PIX_FMT_AYUV64BE
@ AV_PIX_FMT_AYUV64BE
packed AYUV 4:4:4,64bpp (1 Cr & Cb sample per 1x1 Y & A samples), big-endian
Definition: pixfmt.h:303
SH
#define SH(val, pdst)
Definition: generic_macros_msa.h:154
yuv2ayuv64_X_c
static av_always_inline void yuv2ayuv64_X_c(SwsInternal *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, int A_offset, int Y_offset, int U_offset, int V_offset, int is_be)
Definition: output.c:2604
yuv2422_1_c_template
static av_always_inline void yuv2422_1_c_template(SwsInternal *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:892
AV_PIX_FMT_GBRAP12LE
@ AV_PIX_FMT_GBRAP12LE
planar GBR 4:4:4:4 48bpp, little-endian
Definition: pixfmt.h:311
is16BPS
static av_always_inline int is16BPS(enum AVPixelFormat pix_fmt)
Definition: swscale_internal.h:727
rgb
Definition: rpzaenc.c:60
AV_PIX_FMT_GBRAP
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:212
yuv2plane1_16_c_template
static av_always_inline void yuv2plane1_16_c_template(const int32_t *src, uint16_t *dest, int dstW, int big_endian, int output_bits)
Definition: output.c:150
val
static double val(void *priv, double ch)
Definition: aeval.c:77
isNBPS
static av_always_inline int isNBPS(enum AVPixelFormat pix_fmt)
Definition: swscale_internal.h:741
SWS_DITHER_X_DITHER
@ SWS_DITHER_X_DITHER
Definition: swscale.h:85
R_B
#define R_B
Definition: output.c:942
yuv2rgb_full_X_c_template
static av_always_inline void yuv2rgb_full_X_c_template(SwsInternal *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:2092
yuv2plane1_float
#define yuv2plane1_float(template, dest_type, BE_LE)
Definition: output.c:291
AV_PIX_FMT_VUYA
@ AV_PIX_FMT_VUYA
packed VUYA 4:4:4:4, 32bpp (1 Cr & Cb sample per 1x1 Y & A samples), VUYAVUYA...
Definition: pixfmt.h:401
yuv2planeX_16_c_template
static av_always_inline void yuv2planeX_16_c_template(const int16_t *filter, int filterSize, const int32_t **src, uint16_t *dest, int dstW, int big_endian, int output_bits)
Definition: output.c:164
r_b
#define r_b
AV_PIX_FMT_BGR8
@ AV_PIX_FMT_BGR8
packed RGB 3:3:2, 8bpp, (msb)2B 3G 3R(lsb)
Definition: pixfmt.h:90
avassert.h
YUV2PACKED16WRAPPER
#define YUV2PACKED16WRAPPER(name, base, ext, base_fmt, endianness, hasAlpha, eightbytes)
Definition: output.c:1554
av_cold
#define av_cold
Definition: attributes.h:90
yuv2planeX_float
#define yuv2planeX_float(template, dest_type, BE_LE)
Definition: output.c:298
YUVRGB_TABLE_HEADROOM
#define YUVRGB_TABLE_HEADROOM
Definition: swscale_internal.h:47
yuv2packed2_fn
void(* yuv2packed2_fn)(SwsInternal *c, const int16_t *lumSrc[2], const int16_t *chrUSrc[2], const int16_t *chrVSrc[2], const int16_t *alpSrc[2], uint8_t *dest, int dstW, int yalpha, int uvalpha, int y)
Write one line of horizontally scaled Y/U/V/A to packed-pixel YUV/RGB output by doing bilinear scalin...
Definition: swscale_internal.h:214
float
float
Definition: af_crystalizer.c:122
AV_PIX_FMT_GBRAP16BE
@ AV_PIX_FMT_GBRAP16BE
planar GBRA 4:4:4:4 64bpp, big-endian
Definition: pixfmt.h:213
yuv2gbrpf32_full_X_c
static void yuv2gbrpf32_full_X_c(SwsInternal *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:2428
intreadwrite.h
AV_PIX_FMT_GBRP16LE
@ AV_PIX_FMT_GBRP16LE
planar GBR 4:4:4 48bpp, little-endian
Definition: pixfmt.h:172
output_pixels
#define output_pixels(pos, Y1, U, Y2, V)
Definition: output.c:2775
g
const char * g
Definition: vf_curves.c:128
AV_PIX_FMT_GBRP12LE
@ AV_PIX_FMT_GBRP12LE
planar GBR 4:4:4 36bpp, little-endian
Definition: pixfmt.h:280
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
B
#define B
Definition: huffyuv.h:42
yuv2plane1_float_bswap_c_template
static av_always_inline void yuv2plane1_float_bswap_c_template(const int32_t *src, uint32_t *dest, int dstW)
Definition: output.c:236
ff_dither_2x2_4
const uint8_t ff_dither_2x2_4[][8]
Definition: output.c:40
ff_dither_8x8_220
const uint8_t ff_dither_8x8_220[][8]
Definition: output.c:85
AV_PIX_FMT_FLAG_ALPHA
#define AV_PIX_FMT_FLAG_ALPHA
The pixel format has an alpha channel.
Definition: pixdesc.h:147
AV_PIX_FMT_RGB4
@ AV_PIX_FMT_RGB4
packed RGB 1:2:1 bitstream, 4bpp, (msb)1R 2G 1B(lsb), a byte contains two pixels, the first pixel in ...
Definition: pixfmt.h:94
AV_PIX_FMT_GBRP10LE
@ AV_PIX_FMT_GBRP10LE
planar GBR 4:4:4 30bpp, little-endian
Definition: pixfmt.h:170
yuv2rgb_write_full
static av_always_inline void yuv2rgb_write_full(SwsInternal *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:1929
AV_PIX_FMT_BGR32_1
#define AV_PIX_FMT_BGR32_1
Definition: pixfmt.h:503
AV_PIX_FMT_RGBA
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:100
if
if(ret)
Definition: filter_design.txt:179
isSemiPlanarYUV
static av_always_inline int isSemiPlanarYUV(enum AVPixelFormat pix_fmt)
Definition: swscale_internal.h:773
yuv2nv12cX_16BE_c
static void yuv2nv12cX_16BE_c(enum AVPixelFormat dstFormat, const uint8_t *chrDither, const int16_t *chrFilter, int chrFilterSize, const int16_t **chrUSrc, const int16_t **chrVSrc, uint8_t *dest8, int chrDstW)
Definition: output.c:398
yuv2NBPS
#define yuv2NBPS(bits, BE_LE, is_be, template_size, typeX_t)
Definition: output.c:361
yuv2ayuv_X_c_template
static av_always_inline void yuv2ayuv_X_c_template(SwsInternal *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:2892
YUV2AYUV64
#define YUV2AYUV64(pixfmt, BE_LE, A, Y, U, V, is_be)
Definition: output.c:2654
yuv2vyu444_2_c
static void yuv2vyu444_2_c(SwsInternal *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:3107
AV_PIX_FMT_RGBA64
#define AV_PIX_FMT_RGBA64
Definition: pixfmt.h:518
AV_PIX_FMT_RGB565LE
@ AV_PIX_FMT_RGB565LE
packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), little-endian
Definition: pixfmt.h:113
AV_PIX_FMT_Y216LE
@ AV_PIX_FMT_Y216LE
packed YUV 4:2:2 like YUYV422, 32bpp, little-endian
Definition: pixfmt.h:461
AV_PIX_FMT_GBRAPF32BE
@ AV_PIX_FMT_GBRAPF32BE
IEEE-754 single precision planar GBRA 4:4:4:4, 128bpp, big-endian.
Definition: pixfmt.h:343
AV_PIX_FMT_GBRAP12BE
@ AV_PIX_FMT_GBRAP12BE
planar GBR 4:4:4:4 48bpp, big-endian
Definition: pixfmt.h:310
av_clip_int16
#define av_clip_int16
Definition: common.h:115
AV_PIX_FMT_BGR48
#define AV_PIX_FMT_BGR48
Definition: pixfmt.h:519
NULL
#define NULL
Definition: coverity.c:32
yuv2rgb_full_2_c_template
static av_always_inline void yuv2rgb_full_2_c_template(SwsInternal *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:2142
AV_PIX_FMT_YUYV422
@ AV_PIX_FMT_YUYV422
packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
Definition: pixfmt.h:74
AV_PIX_FMT_RGB48LE
@ AV_PIX_FMT_RGB48LE
packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as lit...
Definition: pixfmt.h:110
AV_PIX_FMT_YA16LE
@ AV_PIX_FMT_YA16LE
16 bits gray, 16 bits alpha (little-endian)
Definition: pixfmt.h:210
AV_PIX_FMT_MONOBLACK
@ AV_PIX_FMT_MONOBLACK
Y , 1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb.
Definition: pixfmt.h:83
V
#define V
Definition: avdct.c:31
AV_PIX_FMT_BGR565LE
@ AV_PIX_FMT_BGR565LE
packed BGR 5:6:5, 16bpp, (msb) 5B 6G 5R(lsb), little-endian
Definition: pixfmt.h:118
AV_PIX_FMT_RGBA64LE
@ AV_PIX_FMT_RGBA64LE
packed RGBA 16:16:16:16, 64bpp, 16R, 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is st...
Definition: pixfmt.h:203
AV_PIX_FMT_Y210LE
@ AV_PIX_FMT_Y210LE
packed YUV 4:2:2 like YUYV422, 20bpp, data in the high bits, little-endian
Definition: pixfmt.h:382
AV_PIX_FMT_RGB8
@ AV_PIX_FMT_RGB8
packed RGB 3:3:2, 8bpp, (msb)3R 3G 2B(lsb)
Definition: pixfmt.h:93
AV_PIX_FMT_BGR4
@ AV_PIX_FMT_BGR4
packed RGB 1:2:1 bitstream, 4bpp, (msb)1B 2G 1R(lsb), a byte contains two pixels, the first pixel in ...
Definition: pixfmt.h:91
AV_PIX_FMT_BGR555BE
@ AV_PIX_FMT_BGR555BE
packed BGR 5:5:5, 16bpp, (msb)1X 5B 5G 5R(lsb), big-endian , X=unused/undefined
Definition: pixfmt.h:119
yuv2plane1_float_c_template
static av_always_inline void yuv2plane1_float_c_template(const int32_t *src, float *dest, int dstW)
Definition: output.c:220
AV_PIX_FMT_ABGR
@ AV_PIX_FMT_ABGR
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
Definition: pixfmt.h:101
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
AV_PIX_FMT_BGR4_BYTE
@ AV_PIX_FMT_BGR4_BYTE
packed RGB 1:2:1, 8bpp, (msb)1B 2G 1R(lsb)
Definition: pixfmt.h:92
yuv2422_X_c_template
static av_always_inline void yuv2422_X_c_template(SwsInternal *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:820
A_DITHER
#define A_DITHER(u, v)
AV_PIX_FMT_X2RGB10LE
@ AV_PIX_FMT_X2RGB10LE
packed RGB 10:10:10, 30bpp, (msb)2X 10R 10G 10B(lsb), little-endian, X=unused/undefined
Definition: pixfmt.h:384
isDataInHighBits
static av_always_inline int isDataInHighBits(enum AVPixelFormat pix_fmt)
Definition: swscale_internal.h:936
yuv2packedX_fn
void(* yuv2packedX_fn)(SwsInternal *c, const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, const int16_t *chrFilter, const int16_t **chrUSrc, const int16_t **chrVSrc, int chrFilterSize, const int16_t **alpSrc, uint8_t *dest, int dstW, int y)
Write one line of horizontally scaled Y/U/V/A to packed-pixel YUV/RGB output by doing multi-point ver...
Definition: swscale_internal.h:246
yuv2y2xx_wrapper
#define yuv2y2xx_wrapper(bits)
Definition: output.c:2983
AV_PIX_FMT_X2BGR10
#define AV_PIX_FMT_X2BGR10
Definition: pixfmt.h:597
isBE
static av_always_inline int isBE(enum AVPixelFormat pix_fmt)
Definition: swscale_internal.h:748
yuv2rgba64_1_c_template
static av_always_inline void yuv2rgba64_1_c_template(SwsInternal *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, int is_be)
Definition: output.c:1200
AV_PIX_FMT_RGB24
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:75
A1
@ A1
Definition: mvs.c:524
DECLARE_ALIGNED
#define DECLARE_ALIGNED(n, t, v)
Definition: mem_internal.h:104
shift
static int shift(int a, int b)
Definition: bonk.c:261
av_bswap32
#define av_bswap32
Definition: bswap.h:47
yuv2rgba64_2_c_template
static av_always_inline void yuv2rgba64_2_c_template(SwsInternal *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, int is_be)
Definition: output.c:1134
AV_PIX_FMT_RGB444BE
@ AV_PIX_FMT_RGB444BE
packed RGB 4:4:4, 16bpp, (msb)4X 4R 4G 4B(lsb), big-endian, X=unused/undefined
Definition: pixfmt.h:137
AV_PIX_FMT_XV36BE
@ AV_PIX_FMT_XV36BE
packed XVYU 4:4:4, 48bpp, data in the high bits, zeros in the low bits, big-endian,...
Definition: pixfmt.h:417
yuv2planeX_float_bswap_c_template
static av_always_inline void yuv2planeX_float_bswap_c_template(const int16_t *filter, int filterSize, const int32_t **src, uint32_t *dest, int dstW)
Definition: output.c:272
AV_PIX_FMT_YA16BE
@ AV_PIX_FMT_YA16BE
16 bits gray, 16 bits alpha (big-endian)
Definition: pixfmt.h:209
AV_PIX_FMT_RGB48
#define AV_PIX_FMT_RGB48
Definition: pixfmt.h:514
AV_PIX_FMT_BGR555
#define AV_PIX_FMT_BGR555
Definition: pixfmt.h:521
AV_PIX_FMT_GBRP9BE
@ AV_PIX_FMT_GBRP9BE
planar GBR 4:4:4 27bpp, big-endian
Definition: pixfmt.h:167
yuv2ya16_2_c_template
static av_always_inline void yuv2ya16_2_c_template(SwsInternal *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, int is_be)
Definition: output.c:991
AV_PIX_FMT_BGR444BE
@ AV_PIX_FMT_BGR444BE
packed BGR 4:4:4, 16bpp, (msb)4X 4B 4G 4R(lsb), big-endian, X=unused/undefined
Definition: pixfmt.h:139
output_pixel
#define output_pixel(pos, val, bias, signedness)
Definition: output.c:2980
AV_PIX_FMT_GBRP9LE
@ AV_PIX_FMT_GBRP9LE
planar GBR 4:4:4 27bpp, little-endian
Definition: pixfmt.h:168
yuv2422_2_c_template
static av_always_inline void yuv2422_2_c_template(SwsInternal *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:859
yuv2rgb_1_c_template
static av_always_inline void yuv2rgb_1_c_template(SwsInternal *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:1814
AV_WL16
#define AV_WL16(p, v)
Definition: intreadwrite.h:408
AV_PIX_FMT_RGB32
#define AV_PIX_FMT_RGB32
Definition: pixfmt.h:500
AV_PIX_FMT_GBRAP10LE
@ AV_PIX_FMT_GBRAP10LE
planar GBR 4:4:4:4 40bpp, little-endian
Definition: pixfmt.h:314
isSwappedChroma
static av_always_inline int isSwappedChroma(enum AVPixelFormat pix_fmt)
Definition: swscale_internal.h:955
AV_PIX_FMT_BGR565BE
@ AV_PIX_FMT_BGR565BE
packed BGR 5:6:5, 16bpp, (msb) 5B 6G 5R(lsb), big-endian
Definition: pixfmt.h:117
yuv2nv12cX_c
static void yuv2nv12cX_c(enum AVPixelFormat dstFormat, const uint8_t *chrDither, const int16_t *chrFilter, int chrFilterSize, const int16_t **chrUSrc, const int16_t **chrVSrc, uint8_t *dest, int chrDstW)
Definition: output.c:431
offset
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
Definition: writing_filters.txt:86
attributes.h
yuv2rgb_2_c_template
static av_always_inline void yuv2rgb_2_c_template(SwsInternal *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:1774
ff_dither_8x8_73
const uint8_t ff_dither_8x8_73[][8]
Definition: output.c:72
yuv2ya16_X_c_template
static av_always_inline void yuv2ya16_X_c_template(SwsInternal *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, int is_be)
Definition: output.c:952
Y
#define Y
Definition: boxblur.h:37
yuv2anyX_fn
void(* yuv2anyX_fn)(SwsInternal *c, const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, const int16_t *chrFilter, const int16_t **chrUSrc, const int16_t **chrVSrc, int chrFilterSize, const int16_t **alpSrc, uint8_t **dest, int dstW, int y)
Write one line of horizontally scaled Y/U/V/A to YUV/RGB output by doing multi-point vertical scaling...
Definition: swscale_internal.h:280
yuv2rgb_write
static av_always_inline void yuv2rgb_write(uint8_t *_dest, int i, int Y1, int Y2, unsigned A1, unsigned A2, const void *_r, const void *_g, const void *_b, int y, enum AVPixelFormat target, int hasAlpha)
Definition: output.c:1594
AV_PIX_FMT_AYUV
@ AV_PIX_FMT_AYUV
packed AYUV 4:4:4:4, 32bpp (1 Cr & Cb sample per 1x1 Y & A samples), AYUVAYUV...
Definition: pixfmt.h:442
AV_PIX_FMT_ARGB
@ AV_PIX_FMT_ARGB
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
Definition: pixfmt.h:99
AV_PIX_FMT_BGRA64LE
@ AV_PIX_FMT_BGRA64LE
packed RGBA 16:16:16:16, 64bpp, 16B, 16G, 16R, 16A, the 2-byte value for each R/G/B/A component is st...
Definition: pixfmt.h:205
YUV2XV36
#define YUV2XV36(BE_LE, is_be)
Definition: output.c:2759
yuv2planeX_8_c
static void yuv2planeX_8_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:406
AV_PIX_FMT_UYVA
@ AV_PIX_FMT_UYVA
packed UYVA 4:4:4:4, 32bpp (1 Cr & Cb sample per 1x1 Y & A samples), UYVAUYVA...
Definition: pixfmt.h:444
av_assert2
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Definition: avassert.h:67
AV_PIX_FMT_BGRA64
#define AV_PIX_FMT_BGRA64
Definition: pixfmt.h:523
AV_PIX_FMT_RGB555LE
@ AV_PIX_FMT_RGB555LE
packed RGB 5:5:5, 16bpp, (msb)1X 5R 5G 5B(lsb), little-endian, X=unused/undefined
Definition: pixfmt.h:115
AV_PIX_FMT_RGB48BE
@ AV_PIX_FMT_RGB48BE
packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as big...
Definition: pixfmt.h:109
AV_PIX_FMT_YA16
#define AV_PIX_FMT_YA16
Definition: pixfmt.h:513
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
yuv2ya8_2_c
static void yuv2ya8_2_c(SwsInternal *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:2530
AV_PIX_FMT_BGR444
#define AV_PIX_FMT_BGR444
Definition: pixfmt.h:522
AV_PIX_FMT_RGB555
#define AV_PIX_FMT_RGB555
Definition: pixfmt.h:516
yuv2planeX_float_c_template
static av_always_inline void yuv2planeX_float_c_template(const int16_t *filter, int filterSize, const int32_t **src, float *dest, int dstW)
Definition: output.c:252
av_always_inline
#define av_always_inline
Definition: attributes.h:49
swscale_internal.h
yuv2ayuv_1_c_template
static av_always_inline void yuv2ayuv_1_c_template(SwsInternal *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:2794
yuv2interleavedX_fn
void(* yuv2interleavedX_fn)(enum AVPixelFormat dstFormat, const uint8_t *chrDither, const int16_t *chrFilter, int chrFilterSize, const int16_t **chrUSrc, const int16_t **chrVSrc, uint8_t *dest, int dstW)
Write one line of horizontally scaled chroma to interleaved output with multi-point vertical scaling ...
Definition: swscale_internal.h:144
SUINT
#define SUINT
Definition: dct32_template.c:30
yuv2rgba64_full_1_c_template
static av_always_inline void yuv2rgba64_full_1_c_template(SwsInternal *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, int is_be)
Definition: output.c:1425
AV_PIX_FMT_X2RGB10
#define AV_PIX_FMT_X2RGB10
Definition: pixfmt.h:596
AV_PIX_FMT_X2RGB10BE
@ AV_PIX_FMT_X2RGB10BE
packed RGB 10:10:10, 30bpp, (msb)2X 10R 10G 10B(lsb), big-endian, X=unused/undefined
Definition: pixfmt.h:385
AV_PIX_FMT_BGR565
#define AV_PIX_FMT_BGR565
Definition: pixfmt.h:520
AV_PIX_FMT_RGB4_BYTE
@ AV_PIX_FMT_RGB4_BYTE
packed RGB 1:2:1, 8bpp, (msb)1R 2G 1B(lsb)
Definition: pixfmt.h:95
AV_PIX_FMT_GBRPF32LE
@ AV_PIX_FMT_GBRPF32LE
IEEE-754 single precision planar GBR 4:4:4, 96bpp, little-endian.
Definition: pixfmt.h:342
AV_PIX_FMT_RGB565
#define AV_PIX_FMT_RGB565
Definition: pixfmt.h:515
AV_PIX_FMT_GBRAP16LE
@ AV_PIX_FMT_GBRAP16LE
planar GBRA 4:4:4:4 64bpp, little-endian
Definition: pixfmt.h:214
SWS_DITHER_ED
@ SWS_DITHER_ED
Definition: swscale.h:83
AV_PIX_FMT_YVYU422
@ AV_PIX_FMT_YVYU422
packed YUV 4:2:2, 16bpp, Y0 Cr Y1 Cb
Definition: pixfmt.h:207
yuv2packed1_fn
void(* yuv2packed1_fn)(SwsInternal *c, const int16_t *lumSrc, const int16_t *chrUSrc[2], const int16_t *chrVSrc[2], const int16_t *alpSrc, uint8_t *dest, int dstW, int uvalpha, int y)
Write one line of horizontally scaled Y/U/V/A to packed-pixel YUV/RGB output without any additional v...
Definition: swscale_internal.h:181
SwsInternal
Definition: swscale_internal.h:317
bswap.h
yuv2gbrp_full_X_c
static void yuv2gbrp_full_X_c(SwsInternal *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:2274
yuv2v30_X_c_template
static av_always_inline void yuv2v30_X_c_template(SwsInternal *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, int shift)
Definition: output.c:2676
AV_PIX_FMT_Y212LE
@ AV_PIX_FMT_Y212LE
packed YUV 4:2:2 like YUYV422, 24bpp, data in the high bits, zeros in the low bits,...
Definition: pixfmt.h:412
V30LE_WRAPPER
#define V30LE_WRAPPER(name, shift)
Definition: output.c:2707
AV_PIX_FMT_GRAYF32BE
@ AV_PIX_FMT_GRAYF32BE
IEEE-754 single precision Y, 32bpp, big-endian.
Definition: pixfmt.h:363
SWS_FULL_CHR_H_INT
@ SWS_FULL_CHR_H_INT
Perform full chroma upsampling when upscaling to RGB.
Definition: swscale.h:132
YUV2RGBWRAPPER
#define YUV2RGBWRAPPER(name, base, ext, fmt, hasAlpha)
Definition: output.c:1896
AV_PIX_FMT_GBRP12BE
@ AV_PIX_FMT_GBRP12BE
planar GBR 4:4:4 36bpp, big-endian
Definition: pixfmt.h:279
AV_PIX_FMT_UYVY422
@ AV_PIX_FMT_UYVY422
packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
Definition: pixfmt.h:88
U
#define U(x)
Definition: vpx_arith.h:37
yuv2planarX_fn
void(* yuv2planarX_fn)(const int16_t *filter, int filterSize, const int16_t **src, uint8_t *dest, int dstW, const uint8_t *dither, int offset)
Write one line of horizontally scaled data to planar output with multi-point vertical scaling between...
Definition: swscale_internal.h:124
SWS_DITHER_A_DITHER
@ SWS_DITHER_A_DITHER
Definition: swscale.h:84
AV_PIX_FMT_XV48LE
@ AV_PIX_FMT_XV48LE
packed XVYU 4:4:4, 64bpp, little-endian, variant of Y416 where alpha channel is left undefined
Definition: pixfmt.h:464
yuv2vyu444_1_c
static void yuv2vyu444_1_c(SwsInternal *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:3062
av_clip_uint8
#define av_clip_uint8
Definition: common.h:106
G
#define G
Definition: huffyuv.h:43
yuv2ya8_X_c
static void yuv2ya8_X_c(SwsInternal *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:2561
AV_PIX_FMT_RGB565BE
@ AV_PIX_FMT_RGB565BE
packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), big-endian
Definition: pixfmt.h:112
av_clip_uint16
#define av_clip_uint16
Definition: common.h:112
AV_PIX_FMT_GBRP
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:165
desc
const char * desc
Definition: libsvtav1.c:79
avutil.h
AV_PIX_FMT_X2BGR10LE
@ AV_PIX_FMT_X2BGR10LE
packed BGR 10:10:10, 30bpp, (msb)2X 10B 10G 10R(lsb), little-endian, X=unused/undefined
Definition: pixfmt.h:386
AV_PIX_FMT_V30XLE
@ AV_PIX_FMT_V30XLE
packed VYUX 4:4:4 like XV30, 32bpp, (msb)10V 10Y 10U 2X(lsb), little-endian
Definition: pixfmt.h:449
yuv2gbrp16_full_X_c
static void yuv2gbrp16_full_X_c(SwsInternal *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:2356
AV_PIX_FMT_XV48BE
@ AV_PIX_FMT_XV48BE
packed XVYU 4:4:4, 64bpp, big-endian, variant of Y416 where alpha channel is left undefined
Definition: pixfmt.h:463
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
AV_PIX_FMT_BGR555LE
@ AV_PIX_FMT_BGR555LE
packed BGR 5:5:5, 16bpp, (msb)1X 5B 5G 5R(lsb), little-endian, X=unused/undefined
Definition: pixfmt.h:120
ff_sws_init_output_funcs
av_cold void ff_sws_init_output_funcs(SwsInternal *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:3182
AYUVPACKEDWRAPPER
#define AYUVPACKEDWRAPPER(name, fmt)
Definition: output.c:2944
AV_PIX_FMT_XV36LE
@ AV_PIX_FMT_XV36LE
packed XVYU 4:4:4, 48bpp, data in the high bits, zeros in the low bits, little-endian,...
Definition: pixfmt.h:418
B_R
#define B_R
Definition: output.c:943
AV_PIX_FMT_GBRP14LE
@ AV_PIX_FMT_GBRP14LE
planar GBR 4:4:4 42bpp, little-endian
Definition: pixfmt.h:282
int32_t
int32_t
Definition: audioconvert.c:56
yuv2rgb_X_c_template
static av_always_inline void yuv2rgb_X_c_template(SwsInternal *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:1720
AV_PIX_FMT_GBRAP10BE
@ AV_PIX_FMT_GBRAP10BE
planar GBR 4:4:4:4 40bpp, big-endian
Definition: pixfmt.h:313
yuv2vyu444_X_c
static void yuv2vyu444_X_c(SwsInternal *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:3141
d128
const uint8_t * d128
Definition: yuv2rgb.c:458
AV_PIX_FMT_VUYX
@ AV_PIX_FMT_VUYX
packed VUYX 4:4:4:4, 32bpp, Variant of VUYA where alpha channel is left undefined
Definition: pixfmt.h:406
AV_PIX_FMT_VYU444
@ AV_PIX_FMT_VYU444
packed VYU 4:4:4, 24bpp (1 Cr & Cb sample per 1x1 Y), VYUVYU...
Definition: pixfmt.h:446
yuv2rgba64_X_c_template
static av_always_inline void yuv2rgba64_X_c_template(SwsInternal *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, int is_be)
Definition: output.c:1051
av_bswap16
#define av_bswap16
Definition: bswap.h:28
AV_PIX_FMT_BGR444LE
@ AV_PIX_FMT_BGR444LE
packed BGR 4:4:4, 16bpp, (msb)4X 4B 4G 4R(lsb), little-endian, X=unused/undefined
Definition: pixfmt.h:138
yuv2mono_2_c_template
static av_always_inline void yuv2mono_2_c_template(SwsInternal *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:654
yuv2rgb
static void yuv2rgb(uint8_t *out, int ridx, int Y, int U, int V)
Definition: g2meet.c:263
rgb2rgb.h
src
#define src
Definition: vp8dsp.c:248
AV_PIX_FMT_GBRAP14LE
@ AV_PIX_FMT_GBRAP14LE
planar GBR 4:4:4:4 56bpp, little-endian
Definition: pixfmt.h:433
swscale.h
ff_dither_2x2_8
const uint8_t ff_dither_2x2_8[][8]
Definition: output.c:46
yuv2p01xl1_c
static void yuv2p01xl1_c(const int16_t *src, uint16_t *dest, int dstW, int big_endian, int output_bits, int output_shift)
Definition: output.c:474
AV_PIX_FMT_BGR48BE
@ AV_PIX_FMT_BGR48BE
packed RGB 16:16:16, 48bpp, 16B, 16G, 16R, the 2-byte value for each R/G/B component is stored as big...
Definition: pixfmt.h:145
AV_PIX_FMT_RGB444
#define AV_PIX_FMT_RGB444
Definition: pixfmt.h:517
dither
static const uint8_t dither[8][8]
Definition: vf_fspp.c:62