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