FFmpeg
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
output.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2001-2012 Michael Niedermayer <michaelni@gmx.at>
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include <assert.h>
22 #include <math.h>
23 #include <stdint.h>
24 #include <stdio.h>
25 #include <string.h>
26 
27 #include "libavutil/attributes.h"
28 #include "libavutil/avutil.h"
29 #include "libavutil/avassert.h"
30 #include "libavutil/bswap.h"
31 #include "libavutil/cpu.h"
32 #include "libavutil/intreadwrite.h"
33 #include "libavutil/mathematics.h"
34 #include "libavutil/pixdesc.h"
35 #include "config.h"
36 #include "rgb2rgb.h"
37 #include "swscale.h"
38 #include "swscale_internal.h"
39 
41 { 1, 3, 1, 3, 1, 3, 1, 3, },
42 { 2, 0, 2, 0, 2, 0, 2, 0, },
43 { 1, 3, 1, 3, 1, 3, 1, 3, },
44 };
45 
47 { 6, 2, 6, 2, 6, 2, 6, 2, },
48 { 0, 4, 0, 4, 0, 4, 0, 4, },
49 { 6, 2, 6, 2, 6, 2, 6, 2, },
50 };
51 
53 { 8, 4, 11, 7, 8, 4, 11, 7, },
54 { 2, 14, 1, 13, 2, 14, 1, 13, },
55 { 10, 6, 9, 5, 10, 6, 9, 5, },
56 { 0, 12, 3, 15, 0, 12, 3, 15, },
57 { 8, 4, 11, 7, 8, 4, 11, 7, },
58 };
59 
61 { 17, 9, 23, 15, 16, 8, 22, 14, },
62 { 5, 29, 3, 27, 4, 28, 2, 26, },
63 { 21, 13, 19, 11, 20, 12, 18, 10, },
64 { 0, 24, 6, 30, 1, 25, 7, 31, },
65 { 16, 8, 22, 14, 17, 9, 23, 15, },
66 { 4, 28, 2, 26, 5, 29, 3, 27, },
67 { 20, 12, 18, 10, 21, 13, 19, 11, },
68 { 1, 25, 7, 31, 0, 24, 6, 30, },
69 { 17, 9, 23, 15, 16, 8, 22, 14, },
70 };
71 
73 { 0, 55, 14, 68, 3, 58, 17, 72, },
74 { 37, 18, 50, 32, 40, 22, 54, 35, },
75 { 9, 64, 5, 59, 13, 67, 8, 63, },
76 { 46, 27, 41, 23, 49, 31, 44, 26, },
77 { 2, 57, 16, 71, 1, 56, 15, 70, },
78 { 39, 21, 52, 34, 38, 19, 51, 33, },
79 { 11, 66, 7, 62, 10, 65, 6, 60, },
80 { 48, 30, 43, 25, 47, 29, 42, 24, },
81 { 0, 55, 14, 68, 3, 58, 17, 72, },
82 };
83 
84 #if 1
86 {117, 62, 158, 103, 113, 58, 155, 100, },
87 { 34, 199, 21, 186, 31, 196, 17, 182, },
88 {144, 89, 131, 76, 141, 86, 127, 72, },
89 { 0, 165, 41, 206, 10, 175, 52, 217, },
90 {110, 55, 151, 96, 120, 65, 162, 107, },
91 { 28, 193, 14, 179, 38, 203, 24, 189, },
92 {138, 83, 124, 69, 148, 93, 134, 79, },
93 { 7, 172, 48, 213, 3, 168, 45, 210, },
94 {117, 62, 158, 103, 113, 58, 155, 100, },
95 };
96 #elif 1
97 // tries to correct a gamma of 1.5
98 DECLARE_ALIGNED(8, const uint8_t, dither_8x8_220)[][8]={
99 { 0, 143, 18, 200, 2, 156, 25, 215, },
100 { 78, 28, 125, 64, 89, 36, 138, 74, },
101 { 10, 180, 3, 161, 16, 195, 8, 175, },
102 {109, 51, 93, 38, 121, 60, 105, 47, },
103 { 1, 152, 23, 210, 0, 147, 20, 205, },
104 { 85, 33, 134, 71, 81, 30, 130, 67, },
105 { 14, 190, 6, 171, 12, 185, 5, 166, },
106 {117, 57, 101, 44, 113, 54, 97, 41, },
107 { 0, 143, 18, 200, 2, 156, 25, 215, },
108 };
109 #elif 1
110 // tries to correct a gamma of 2.0
111 DECLARE_ALIGNED(8, const uint8_t, dither_8x8_220)[][8]={
112 { 0, 124, 8, 193, 0, 140, 12, 213, },
113 { 55, 14, 104, 42, 66, 19, 119, 52, },
114 { 3, 168, 1, 145, 6, 187, 3, 162, },
115 { 86, 31, 70, 21, 99, 39, 82, 28, },
116 { 0, 134, 11, 206, 0, 129, 9, 200, },
117 { 62, 17, 114, 48, 58, 16, 109, 45, },
118 { 5, 181, 2, 157, 4, 175, 1, 151, },
119 { 95, 36, 78, 26, 90, 34, 74, 24, },
120 { 0, 124, 8, 193, 0, 140, 12, 213, },
121 };
122 #else
123 // tries to correct a gamma of 2.5
124 DECLARE_ALIGNED(8, const uint8_t, dither_8x8_220)[][8]={
125 { 0, 107, 3, 187, 0, 125, 6, 212, },
126 { 39, 7, 86, 28, 49, 11, 102, 36, },
127 { 1, 158, 0, 131, 3, 180, 1, 151, },
128 { 68, 19, 52, 12, 81, 25, 64, 17, },
129 { 0, 119, 5, 203, 0, 113, 4, 195, },
130 { 45, 9, 96, 33, 42, 8, 91, 30, },
131 { 2, 172, 1, 144, 2, 165, 0, 137, },
132 { 77, 23, 60, 15, 72, 21, 56, 14, },
133 { 0, 107, 3, 187, 0, 125, 6, 212, },
134 };
135 #endif
136 
137 #define output_pixel(pos, val, bias, signedness) \
138  if (big_endian) { \
139  AV_WB16(pos, bias + av_clip_ ## signedness ## 16(val >> shift)); \
140  } else { \
141  AV_WL16(pos, bias + av_clip_ ## signedness ## 16(val >> shift)); \
142  }
143 
144 static av_always_inline void
145 yuv2plane1_16_c_template(const int32_t *src, uint16_t *dest, int dstW,
146  int big_endian, int output_bits)
147 {
148  int i;
149  int shift = 3;
150  av_assert0(output_bits == 16);
151 
152  for (i = 0; i < dstW; i++) {
153  int val = src[i] + (1 << (shift - 1));
154  output_pixel(&dest[i], val, 0, uint);
155  }
156 }
157 
158 static av_always_inline void
159 yuv2planeX_16_c_template(const int16_t *filter, int filterSize,
160  const int32_t **src, uint16_t *dest, int dstW,
161  int big_endian, int output_bits)
162 {
163  int i;
164  int shift = 15;
165  av_assert0(output_bits == 16);
166 
167  for (i = 0; i < dstW; i++) {
168  int val = 1 << (shift - 1);
169  int j;
170 
171  /* range of val is [0,0x7FFFFFFF], so 31 bits, but with lanczos/spline
172  * filters (or anything with negative coeffs, the range can be slightly
173  * wider in both directions. To account for this overflow, we subtract
174  * a constant so it always fits in the signed range (assuming a
175  * reasonable filterSize), and re-add that at the end. */
176  val -= 0x40000000;
177  for (j = 0; j < filterSize; j++)
178  val += src[j][i] * (unsigned)filter[j];
179 
180  output_pixel(&dest[i], val, 0x8000, int);
181  }
182 }
183 
184 #undef output_pixel
185 
186 #define output_pixel(pos, val) \
187  if (big_endian) { \
188  AV_WB16(pos, av_clip_uintp2(val >> shift, output_bits)); \
189  } else { \
190  AV_WL16(pos, av_clip_uintp2(val >> shift, output_bits)); \
191  }
192 
193 static av_always_inline void
194 yuv2plane1_10_c_template(const int16_t *src, uint16_t *dest, int dstW,
195  int big_endian, int output_bits)
196 {
197  int i;
198  int shift = 15 - output_bits;
199 
200  for (i = 0; i < dstW; i++) {
201  int val = src[i] + (1 << (shift - 1));
202  output_pixel(&dest[i], val);
203  }
204 }
205 
206 static av_always_inline void
207 yuv2planeX_10_c_template(const int16_t *filter, int filterSize,
208  const int16_t **src, uint16_t *dest, int dstW,
209  int big_endian, int output_bits)
210 {
211  int i;
212  int shift = 11 + 16 - output_bits;
213 
214  for (i = 0; i < dstW; i++) {
215  int val = 1 << (shift - 1);
216  int j;
217 
218  for (j = 0; j < filterSize; j++)
219  val += src[j][i] * filter[j];
220 
221  output_pixel(&dest[i], val);
222  }
223 }
224 
225 #undef output_pixel
226 
227 #define yuv2NBPS(bits, BE_LE, is_be, template_size, typeX_t) \
228 static void yuv2plane1_ ## bits ## BE_LE ## _c(const int16_t *src, \
229  uint8_t *dest, int dstW, \
230  const uint8_t *dither, int offset)\
231 { \
232  yuv2plane1_ ## template_size ## _c_template((const typeX_t *) src, \
233  (uint16_t *) dest, dstW, is_be, bits); \
234 }\
235 static void yuv2planeX_ ## bits ## BE_LE ## _c(const int16_t *filter, int filterSize, \
236  const int16_t **src, uint8_t *dest, int dstW, \
237  const uint8_t *dither, int offset)\
238 { \
239  yuv2planeX_## template_size ## _c_template(filter, \
240  filterSize, (const typeX_t **) src, \
241  (uint16_t *) dest, dstW, is_be, bits); \
242 }
243 yuv2NBPS( 9, BE, 1, 10, int16_t)
244 yuv2NBPS( 9, LE, 0, 10, int16_t)
245 yuv2NBPS(10, BE, 1, 10, int16_t)
246 yuv2NBPS(10, LE, 0, 10, int16_t)
247 yuv2NBPS(12, BE, 1, 10, int16_t)
248 yuv2NBPS(12, LE, 0, 10, int16_t)
249 yuv2NBPS(14, BE, 1, 10, int16_t)
250 yuv2NBPS(14, LE, 0, 10, int16_t)
251 yuv2NBPS(16, BE, 1, 16, int32_t)
252 yuv2NBPS(16, LE, 0, 16, int32_t)
253 
254 static void yuv2planeX_8_c(const int16_t *filter, int filterSize,
255  const int16_t **src, uint8_t *dest, int dstW,
256  const uint8_t *dither, int offset)
257 {
258  int i;
259  for (i=0; i<dstW; i++) {
260  int val = dither[(i + offset) & 7] << 12;
261  int j;
262  for (j=0; j<filterSize; j++)
263  val += src[j][i] * filter[j];
264 
265  dest[i]= av_clip_uint8(val>>19);
266  }
267 }
268 
269 static void yuv2plane1_8_c(const int16_t *src, uint8_t *dest, int dstW,
270  const uint8_t *dither, int offset)
271 {
272  int i;
273  for (i=0; i<dstW; i++) {
274  int val = (src[i] + dither[(i + offset) & 7]) >> 7;
275  dest[i]= av_clip_uint8(val);
276  }
277 }
278 
279 static void yuv2nv12cX_c(SwsContext *c, const int16_t *chrFilter, int chrFilterSize,
280  const int16_t **chrUSrc, const int16_t **chrVSrc,
281  uint8_t *dest, int chrDstW)
282 {
283  enum AVPixelFormat dstFormat = c->dstFormat;
284  const uint8_t *chrDither = c->chrDither8;
285  int i;
286 
287  if (dstFormat == AV_PIX_FMT_NV12)
288  for (i=0; i<chrDstW; i++) {
289  int u = chrDither[i & 7] << 12;
290  int v = chrDither[(i + 3) & 7] << 12;
291  int j;
292  for (j=0; j<chrFilterSize; j++) {
293  u += chrUSrc[j][i] * chrFilter[j];
294  v += chrVSrc[j][i] * chrFilter[j];
295  }
296 
297  dest[2*i]= av_clip_uint8(u>>19);
298  dest[2*i+1]= av_clip_uint8(v>>19);
299  }
300  else
301  for (i=0; i<chrDstW; i++) {
302  int u = chrDither[i & 7] << 12;
303  int v = chrDither[(i + 3) & 7] << 12;
304  int j;
305  for (j=0; j<chrFilterSize; j++) {
306  u += chrUSrc[j][i] * chrFilter[j];
307  v += chrVSrc[j][i] * chrFilter[j];
308  }
309 
310  dest[2*i]= av_clip_uint8(v>>19);
311  dest[2*i+1]= av_clip_uint8(u>>19);
312  }
313 }
314 
315 #define accumulate_bit(acc, val) \
316  acc <<= 1; \
317  acc |= (val) >= (128 + 110)
318 #define output_pixel(pos, acc) \
319  if (target == AV_PIX_FMT_MONOBLACK) { \
320  pos = acc; \
321  } else { \
322  pos = ~acc; \
323  }
324 
325 static av_always_inline void
326 yuv2mono_X_c_template(SwsContext *c, const int16_t *lumFilter,
327  const int16_t **lumSrc, int lumFilterSize,
328  const int16_t *chrFilter, const int16_t **chrUSrc,
329  const int16_t **chrVSrc, int chrFilterSize,
330  const int16_t **alpSrc, uint8_t *dest, int dstW,
331  int y, enum AVPixelFormat target)
332 {
333  const uint8_t * const d128=dither_8x8_220[y&7];
334  int i;
335  unsigned acc = 0;
336 
337  for (i = 0; i < dstW; i += 2) {
338  int j;
339  int Y1 = 1 << 18;
340  int Y2 = 1 << 18;
341 
342  for (j = 0; j < lumFilterSize; j++) {
343  Y1 += lumSrc[j][i] * lumFilter[j];
344  Y2 += lumSrc[j][i+1] * lumFilter[j];
345  }
346  Y1 >>= 19;
347  Y2 >>= 19;
348  if ((Y1 | Y2) & 0x100) {
349  Y1 = av_clip_uint8(Y1);
350  Y2 = av_clip_uint8(Y2);
351  }
352  accumulate_bit(acc, Y1 + d128[(i + 0) & 7]);
353  accumulate_bit(acc, Y2 + d128[(i + 1) & 7]);
354  if ((i & 7) == 6) {
355  output_pixel(*dest++, acc);
356  }
357  }
358 
359  if (i & 6) {
360  output_pixel(*dest, acc);
361  }
362 }
363 
364 static av_always_inline void
365 yuv2mono_2_c_template(SwsContext *c, const int16_t *buf[2],
366  const int16_t *ubuf[2], const int16_t *vbuf[2],
367  const int16_t *abuf[2], uint8_t *dest, int dstW,
368  int yalpha, int uvalpha, int y,
369  enum AVPixelFormat target)
370 {
371  const int16_t *buf0 = buf[0], *buf1 = buf[1];
372  const uint8_t * const d128 = dither_8x8_220[y & 7];
373  int yalpha1 = 4096 - yalpha;
374  int i;
375 
376  for (i = 0; i < dstW; i += 8) {
377  int Y, acc = 0;
378 
379  Y = (buf0[i + 0] * yalpha1 + buf1[i + 0] * yalpha) >> 19;
380  accumulate_bit(acc, Y + d128[0]);
381  Y = (buf0[i + 1] * yalpha1 + buf1[i + 1] * yalpha) >> 19;
382  accumulate_bit(acc, Y + d128[1]);
383  Y = (buf0[i + 2] * yalpha1 + buf1[i + 2] * yalpha) >> 19;
384  accumulate_bit(acc, Y + d128[2]);
385  Y = (buf0[i + 3] * yalpha1 + buf1[i + 3] * yalpha) >> 19;
386  accumulate_bit(acc, Y + d128[3]);
387  Y = (buf0[i + 4] * yalpha1 + buf1[i + 4] * yalpha) >> 19;
388  accumulate_bit(acc, Y + d128[4]);
389  Y = (buf0[i + 5] * yalpha1 + buf1[i + 5] * yalpha) >> 19;
390  accumulate_bit(acc, Y + d128[5]);
391  Y = (buf0[i + 6] * yalpha1 + buf1[i + 6] * yalpha) >> 19;
392  accumulate_bit(acc, Y + d128[6]);
393  Y = (buf0[i + 7] * yalpha1 + buf1[i + 7] * yalpha) >> 19;
394  accumulate_bit(acc, Y + d128[7]);
395 
396  output_pixel(*dest++, acc);
397  }
398 }
399 
400 static av_always_inline void
401 yuv2mono_1_c_template(SwsContext *c, const int16_t *buf0,
402  const int16_t *ubuf[2], const int16_t *vbuf[2],
403  const int16_t *abuf0, uint8_t *dest, int dstW,
404  int uvalpha, int y, enum AVPixelFormat target)
405 {
406  const uint8_t * const d128 = dither_8x8_220[y & 7];
407  int i;
408 
409  for (i = 0; i < dstW; i += 8) {
410  int acc = 0;
411 
412  accumulate_bit(acc, ((buf0[i + 0] + 64) >> 7) + d128[0]);
413  accumulate_bit(acc, ((buf0[i + 1] + 64) >> 7) + d128[1]);
414  accumulate_bit(acc, ((buf0[i + 2] + 64) >> 7) + d128[2]);
415  accumulate_bit(acc, ((buf0[i + 3] + 64) >> 7) + d128[3]);
416  accumulate_bit(acc, ((buf0[i + 4] + 64) >> 7) + d128[4]);
417  accumulate_bit(acc, ((buf0[i + 5] + 64) >> 7) + d128[5]);
418  accumulate_bit(acc, ((buf0[i + 6] + 64) >> 7) + d128[6]);
419  accumulate_bit(acc, ((buf0[i + 7] + 64) >> 7) + d128[7]);
420 
421  output_pixel(*dest++, acc);
422  }
423 }
424 
425 #undef output_pixel
426 #undef accumulate_bit
427 
428 #define YUV2PACKEDWRAPPER(name, base, ext, fmt) \
429 static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \
430  const int16_t **lumSrc, int lumFilterSize, \
431  const int16_t *chrFilter, const int16_t **chrUSrc, \
432  const int16_t **chrVSrc, int chrFilterSize, \
433  const int16_t **alpSrc, uint8_t *dest, int dstW, \
434  int y) \
435 { \
436  name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
437  chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
438  alpSrc, dest, dstW, y, fmt); \
439 } \
440  \
441 static void name ## ext ## _2_c(SwsContext *c, const int16_t *buf[2], \
442  const int16_t *ubuf[2], const int16_t *vbuf[2], \
443  const int16_t *abuf[2], uint8_t *dest, int dstW, \
444  int yalpha, int uvalpha, int y) \
445 { \
446  name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
447  dest, dstW, yalpha, uvalpha, y, fmt); \
448 } \
449  \
450 static void name ## ext ## _1_c(SwsContext *c, const int16_t *buf0, \
451  const int16_t *ubuf[2], const int16_t *vbuf[2], \
452  const int16_t *abuf0, uint8_t *dest, int dstW, \
453  int uvalpha, int y) \
454 { \
455  name ## base ## _1_c_template(c, buf0, ubuf, vbuf, \
456  abuf0, dest, dstW, uvalpha, \
457  y, fmt); \
458 }
459 
460 YUV2PACKEDWRAPPER(yuv2mono,, white, AV_PIX_FMT_MONOWHITE)
461 YUV2PACKEDWRAPPER(yuv2mono,, black, AV_PIX_FMT_MONOBLACK)
462 
463 #define output_pixels(pos, Y1, U, Y2, V) \
464  if (target == AV_PIX_FMT_YUYV422) { \
465  dest[pos + 0] = Y1; \
466  dest[pos + 1] = U; \
467  dest[pos + 2] = Y2; \
468  dest[pos + 3] = V; \
469  } else { \
470  dest[pos + 0] = U; \
471  dest[pos + 1] = Y1; \
472  dest[pos + 2] = V; \
473  dest[pos + 3] = Y2; \
474  }
475 
476 static av_always_inline void
477 yuv2422_X_c_template(SwsContext *c, const int16_t *lumFilter,
478  const int16_t **lumSrc, int lumFilterSize,
479  const int16_t *chrFilter, const int16_t **chrUSrc,
480  const int16_t **chrVSrc, int chrFilterSize,
481  const int16_t **alpSrc, uint8_t *dest, int dstW,
482  int y, enum AVPixelFormat target)
483 {
484  int i;
485 
486  for (i = 0; i < ((dstW + 1) >> 1); i++) {
487  int j;
488  int Y1 = 1 << 18;
489  int Y2 = 1 << 18;
490  int U = 1 << 18;
491  int V = 1 << 18;
492 
493  for (j = 0; j < lumFilterSize; j++) {
494  Y1 += lumSrc[j][i * 2] * lumFilter[j];
495  Y2 += lumSrc[j][i * 2 + 1] * lumFilter[j];
496  }
497  for (j = 0; j < chrFilterSize; j++) {
498  U += chrUSrc[j][i] * chrFilter[j];
499  V += chrVSrc[j][i] * chrFilter[j];
500  }
501  Y1 >>= 19;
502  Y2 >>= 19;
503  U >>= 19;
504  V >>= 19;
505  if ((Y1 | Y2 | U | V) & 0x100) {
506  Y1 = av_clip_uint8(Y1);
507  Y2 = av_clip_uint8(Y2);
508  U = av_clip_uint8(U);
509  V = av_clip_uint8(V);
510  }
511  output_pixels(4*i, Y1, U, Y2, V);
512  }
513 }
514 
515 static av_always_inline void
516 yuv2422_2_c_template(SwsContext *c, const int16_t *buf[2],
517  const int16_t *ubuf[2], const int16_t *vbuf[2],
518  const int16_t *abuf[2], uint8_t *dest, int dstW,
519  int yalpha, int uvalpha, int y,
520  enum AVPixelFormat target)
521 {
522  const int16_t *buf0 = buf[0], *buf1 = buf[1],
523  *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
524  *vbuf0 = vbuf[0], *vbuf1 = vbuf[1];
525  int yalpha1 = 4096 - yalpha;
526  int uvalpha1 = 4096 - uvalpha;
527  int i;
528 
529  for (i = 0; i < ((dstW + 1) >> 1); i++) {
530  int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 19;
531  int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 19;
532  int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha) >> 19;
533  int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha) >> 19;
534 
535  if ((Y1 | Y2 | U | V) & 0x100) {
536  Y1 = av_clip_uint8(Y1);
537  Y2 = av_clip_uint8(Y2);
538  U = av_clip_uint8(U);
539  V = av_clip_uint8(V);
540  }
541 
542  output_pixels(i * 4, Y1, U, Y2, V);
543  }
544 }
545 
546 static av_always_inline void
547 yuv2422_1_c_template(SwsContext *c, const int16_t *buf0,
548  const int16_t *ubuf[2], const int16_t *vbuf[2],
549  const int16_t *abuf0, uint8_t *dest, int dstW,
550  int uvalpha, int y, enum AVPixelFormat target)
551 {
552  const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
553  int i;
554 
555  if (uvalpha < 2048) {
556  for (i = 0; i < ((dstW + 1) >> 1); i++) {
557  int Y1 = (buf0[i * 2 ]+64) >> 7;
558  int Y2 = (buf0[i * 2 + 1]+64) >> 7;
559  int U = (ubuf0[i] +64) >> 7;
560  int V = (vbuf0[i] +64) >> 7;
561 
562  if ((Y1 | Y2 | U | V) & 0x100) {
563  Y1 = av_clip_uint8(Y1);
564  Y2 = av_clip_uint8(Y2);
565  U = av_clip_uint8(U);
566  V = av_clip_uint8(V);
567  }
568 
569  Y1 = av_clip_uint8(Y1);
570  Y2 = av_clip_uint8(Y2);
571  U = av_clip_uint8(U);
572  V = av_clip_uint8(V);
573 
574  output_pixels(i * 4, Y1, U, Y2, V);
575  }
576  } else {
577  const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
578  for (i = 0; i < ((dstW + 1) >> 1); i++) {
579  int Y1 = (buf0[i * 2 ] + 64) >> 7;
580  int Y2 = (buf0[i * 2 + 1] + 64) >> 7;
581  int U = (ubuf0[i] + ubuf1[i]+128) >> 8;
582  int V = (vbuf0[i] + vbuf1[i]+128) >> 8;
583 
584  if ((Y1 | Y2 | U | V) & 0x100) {
585  Y1 = av_clip_uint8(Y1);
586  Y2 = av_clip_uint8(Y2);
587  U = av_clip_uint8(U);
588  V = av_clip_uint8(V);
589  }
590 
591  Y1 = av_clip_uint8(Y1);
592  Y2 = av_clip_uint8(Y2);
593  U = av_clip_uint8(U);
594  V = av_clip_uint8(V);
595 
596  output_pixels(i * 4, Y1, U, Y2, V);
597  }
598  }
599 }
600 
601 #undef output_pixels
602 
603 YUV2PACKEDWRAPPER(yuv2, 422, yuyv422, AV_PIX_FMT_YUYV422)
604 YUV2PACKEDWRAPPER(yuv2, 422, uyvy422, AV_PIX_FMT_UYVY422)
605 
606 #define R_B ((target == AV_PIX_FMT_RGB48LE || target == AV_PIX_FMT_RGB48BE) ? R : B)
607 #define B_R ((target == AV_PIX_FMT_RGB48LE || target == AV_PIX_FMT_RGB48BE) ? B : R)
608 #define output_pixel(pos, val) \
609  if (isBE(target)) { \
610  AV_WB16(pos, val); \
611  } else { \
612  AV_WL16(pos, val); \
613  }
614 
615 static av_always_inline void
616 yuv2rgb48_X_c_template(SwsContext *c, const int16_t *lumFilter,
617  const int32_t **lumSrc, int lumFilterSize,
618  const int16_t *chrFilter, const int32_t **chrUSrc,
619  const int32_t **chrVSrc, int chrFilterSize,
620  const int32_t **alpSrc, uint16_t *dest, int dstW,
621  int y, enum AVPixelFormat target)
622 {
623  int i;
624 
625  for (i = 0; i < ((dstW + 1) >> 1); i++) {
626  int j;
627  int Y1 = -0x40000000;
628  int Y2 = -0x40000000;
629  int U = -128 << 23; // 19
630  int V = -128 << 23;
631  int R, G, B;
632 
633  for (j = 0; j < lumFilterSize; j++) {
634  Y1 += lumSrc[j][i * 2] * (unsigned)lumFilter[j];
635  Y2 += lumSrc[j][i * 2 + 1] * (unsigned)lumFilter[j];
636  }
637  for (j = 0; j < chrFilterSize; j++) {;
638  U += chrUSrc[j][i] * (unsigned)chrFilter[j];
639  V += chrVSrc[j][i] * (unsigned)chrFilter[j];
640  }
641 
642  // 8bit: 12+15=27; 16-bit: 12+19=31
643  Y1 >>= 14; // 10
644  Y1 += 0x10000;
645  Y2 >>= 14;
646  Y2 += 0x10000;
647  U >>= 14;
648  V >>= 14;
649 
650  // 8bit: 27 -> 17bit, 16bit: 31 - 14 = 17bit
651  Y1 -= c->yuv2rgb_y_offset;
652  Y2 -= c->yuv2rgb_y_offset;
653  Y1 *= c->yuv2rgb_y_coeff;
654  Y2 *= c->yuv2rgb_y_coeff;
655  Y1 += 1 << 13; // 21
656  Y2 += 1 << 13;
657  // 8bit: 17 + 13bit = 30bit, 16bit: 17 + 13bit = 30bit
658 
659  R = V * c->yuv2rgb_v2r_coeff;
660  G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
661  B = U * c->yuv2rgb_u2b_coeff;
662 
663  // 8bit: 30 - 22 = 8bit, 16bit: 30bit - 14 = 16bit
664  output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
665  output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
666  output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
667  output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
668  output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);
669  output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
670  dest += 6;
671  }
672 }
673 
674 static av_always_inline void
676  const int32_t *ubuf[2], const int32_t *vbuf[2],
677  const int32_t *abuf[2], uint16_t *dest, int dstW,
678  int yalpha, int uvalpha, int y,
679  enum AVPixelFormat target)
680 {
681  const int32_t *buf0 = buf[0], *buf1 = buf[1],
682  *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
683  *vbuf0 = vbuf[0], *vbuf1 = vbuf[1];
684  int yalpha1 = 4096 - yalpha;
685  int uvalpha1 = 4096 - uvalpha;
686  int i;
687 
688  for (i = 0; i < ((dstW + 1) >> 1); i++) {
689  int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 14;
690  int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 14;
691  int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha + (-128 << 23)) >> 14;
692  int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha + (-128 << 23)) >> 14;
693  int R, G, B;
694 
695  Y1 -= c->yuv2rgb_y_offset;
696  Y2 -= c->yuv2rgb_y_offset;
697  Y1 *= c->yuv2rgb_y_coeff;
698  Y2 *= c->yuv2rgb_y_coeff;
699  Y1 += 1 << 13;
700  Y2 += 1 << 13;
701 
702  R = V * c->yuv2rgb_v2r_coeff;
703  G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
704  B = U * c->yuv2rgb_u2b_coeff;
705 
706  output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
707  output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
708  output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
709  output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
710  output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);
711  output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
712  dest += 6;
713  }
714 }
715 
716 static av_always_inline void
718  const int32_t *ubuf[2], const int32_t *vbuf[2],
719  const int32_t *abuf0, uint16_t *dest, int dstW,
720  int uvalpha, int y, enum AVPixelFormat target)
721 {
722  const int32_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
723  int i;
724 
725  if (uvalpha < 2048) {
726  for (i = 0; i < ((dstW + 1) >> 1); i++) {
727  int Y1 = (buf0[i * 2] ) >> 2;
728  int Y2 = (buf0[i * 2 + 1]) >> 2;
729  int U = (ubuf0[i] + (-128 << 11)) >> 2;
730  int V = (vbuf0[i] + (-128 << 11)) >> 2;
731  int R, G, B;
732 
733  Y1 -= c->yuv2rgb_y_offset;
734  Y2 -= c->yuv2rgb_y_offset;
735  Y1 *= c->yuv2rgb_y_coeff;
736  Y2 *= c->yuv2rgb_y_coeff;
737  Y1 += 1 << 13;
738  Y2 += 1 << 13;
739 
740  R = V * c->yuv2rgb_v2r_coeff;
741  G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
742  B = U * c->yuv2rgb_u2b_coeff;
743 
744  output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
745  output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
746  output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
747  output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
748  output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);
749  output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
750  dest += 6;
751  }
752  } else {
753  const int32_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
754  for (i = 0; i < ((dstW + 1) >> 1); i++) {
755  int Y1 = (buf0[i * 2] ) >> 2;
756  int Y2 = (buf0[i * 2 + 1]) >> 2;
757  int U = (ubuf0[i] + ubuf1[i] + (-128 << 12)) >> 3;
758  int V = (vbuf0[i] + vbuf1[i] + (-128 << 12)) >> 3;
759  int R, G, B;
760 
761  Y1 -= c->yuv2rgb_y_offset;
762  Y2 -= c->yuv2rgb_y_offset;
763  Y1 *= c->yuv2rgb_y_coeff;
764  Y2 *= c->yuv2rgb_y_coeff;
765  Y1 += 1 << 13;
766  Y2 += 1 << 13;
767 
768  R = V * c->yuv2rgb_v2r_coeff;
769  G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
770  B = U * c->yuv2rgb_u2b_coeff;
771 
772  output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
773  output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
774  output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
775  output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
776  output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);
777  output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
778  dest += 6;
779  }
780  }
781 }
782 
783 #undef output_pixel
784 #undef r_b
785 #undef b_r
786 
787 #define YUV2PACKED16WRAPPER(name, base, ext, fmt) \
788 static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \
789  const int16_t **_lumSrc, int lumFilterSize, \
790  const int16_t *chrFilter, const int16_t **_chrUSrc, \
791  const int16_t **_chrVSrc, int chrFilterSize, \
792  const int16_t **_alpSrc, uint8_t *_dest, int dstW, \
793  int y) \
794 { \
795  const int32_t **lumSrc = (const int32_t **) _lumSrc, \
796  **chrUSrc = (const int32_t **) _chrUSrc, \
797  **chrVSrc = (const int32_t **) _chrVSrc, \
798  **alpSrc = (const int32_t **) _alpSrc; \
799  uint16_t *dest = (uint16_t *) _dest; \
800  name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
801  chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
802  alpSrc, dest, dstW, y, fmt); \
803 } \
804  \
805 static void name ## ext ## _2_c(SwsContext *c, const int16_t *_buf[2], \
806  const int16_t *_ubuf[2], const int16_t *_vbuf[2], \
807  const int16_t *_abuf[2], uint8_t *_dest, int dstW, \
808  int yalpha, int uvalpha, int y) \
809 { \
810  const int32_t **buf = (const int32_t **) _buf, \
811  **ubuf = (const int32_t **) _ubuf, \
812  **vbuf = (const int32_t **) _vbuf, \
813  **abuf = (const int32_t **) _abuf; \
814  uint16_t *dest = (uint16_t *) _dest; \
815  name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
816  dest, dstW, yalpha, uvalpha, y, fmt); \
817 } \
818  \
819 static void name ## ext ## _1_c(SwsContext *c, const int16_t *_buf0, \
820  const int16_t *_ubuf[2], const int16_t *_vbuf[2], \
821  const int16_t *_abuf0, uint8_t *_dest, int dstW, \
822  int uvalpha, int y) \
823 { \
824  const int32_t *buf0 = (const int32_t *) _buf0, \
825  **ubuf = (const int32_t **) _ubuf, \
826  **vbuf = (const int32_t **) _vbuf, \
827  *abuf0 = (const int32_t *) _abuf0; \
828  uint16_t *dest = (uint16_t *) _dest; \
829  name ## base ## _1_c_template(c, buf0, ubuf, vbuf, abuf0, dest, \
830  dstW, uvalpha, y, fmt); \
831 }
832 
833 YUV2PACKED16WRAPPER(yuv2, rgb48, rgb48be, AV_PIX_FMT_RGB48BE)
834 YUV2PACKED16WRAPPER(yuv2, rgb48, rgb48le, AV_PIX_FMT_RGB48LE)
835 YUV2PACKED16WRAPPER(yuv2, rgb48, bgr48be, AV_PIX_FMT_BGR48BE)
836 YUV2PACKED16WRAPPER(yuv2, rgb48, bgr48le, AV_PIX_FMT_BGR48LE)
837 
838 /*
839  * Write out 2 RGB pixels in the target pixel format. This function takes a
840  * R/G/B LUT as generated by ff_yuv2rgb_c_init_tables(), which takes care of
841  * things like endianness conversion and shifting. The caller takes care of
842  * setting the correct offset in these tables from the chroma (U/V) values.
843  * This function then uses the luminance (Y1/Y2) values to write out the
844  * correct RGB values into the destination buffer.
845  */
846 static av_always_inline void
847 yuv2rgb_write(uint8_t *_dest, int i, int Y1, int Y2,
848  unsigned A1, unsigned A2,
849  const void *_r, const void *_g, const void *_b, int y,
850  enum AVPixelFormat target, int hasAlpha)
851 {
852  if (target == AV_PIX_FMT_ARGB || target == AV_PIX_FMT_RGBA ||
853  target == AV_PIX_FMT_ABGR || target == AV_PIX_FMT_BGRA) {
854  uint32_t *dest = (uint32_t *) _dest;
855  const uint32_t *r = (const uint32_t *) _r;
856  const uint32_t *g = (const uint32_t *) _g;
857  const uint32_t *b = (const uint32_t *) _b;
858 
859 #if CONFIG_SMALL
860  int sh = hasAlpha ? ((target == AV_PIX_FMT_RGB32_1 || target == AV_PIX_FMT_BGR32_1) ? 0 : 24) : 0;
861 
862  dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1] + (hasAlpha ? A1 << sh : 0);
863  dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2] + (hasAlpha ? A2 << sh : 0);
864 #else
865  if (hasAlpha) {
866  int sh = (target == AV_PIX_FMT_RGB32_1 || target == AV_PIX_FMT_BGR32_1) ? 0 : 24;
867 
868  dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1] + (A1 << sh);
869  dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2] + (A2 << sh);
870  } else {
871  dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1];
872  dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2];
873  }
874 #endif
875  } else if (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) {
876  uint8_t *dest = (uint8_t *) _dest;
877  const uint8_t *r = (const uint8_t *) _r;
878  const uint8_t *g = (const uint8_t *) _g;
879  const uint8_t *b = (const uint8_t *) _b;
880 
881 #define r_b ((target == AV_PIX_FMT_RGB24) ? r : b)
882 #define b_r ((target == AV_PIX_FMT_RGB24) ? b : r)
883 
884  dest[i * 6 + 0] = r_b[Y1];
885  dest[i * 6 + 1] = g[Y1];
886  dest[i * 6 + 2] = b_r[Y1];
887  dest[i * 6 + 3] = r_b[Y2];
888  dest[i * 6 + 4] = g[Y2];
889  dest[i * 6 + 5] = b_r[Y2];
890 #undef r_b
891 #undef b_r
892  } else if (target == AV_PIX_FMT_RGB565 || target == AV_PIX_FMT_BGR565 ||
893  target == AV_PIX_FMT_RGB555 || target == AV_PIX_FMT_BGR555 ||
894  target == AV_PIX_FMT_RGB444 || target == AV_PIX_FMT_BGR444) {
895  uint16_t *dest = (uint16_t *) _dest;
896  const uint16_t *r = (const uint16_t *) _r;
897  const uint16_t *g = (const uint16_t *) _g;
898  const uint16_t *b = (const uint16_t *) _b;
899  int dr1, dg1, db1, dr2, dg2, db2;
900 
901  if (target == AV_PIX_FMT_RGB565 || target == AV_PIX_FMT_BGR565) {
902  dr1 = dither_2x2_8[ y & 1 ][0];
903  dg1 = dither_2x2_4[ y & 1 ][0];
904  db1 = dither_2x2_8[(y & 1) ^ 1][0];
905  dr2 = dither_2x2_8[ y & 1 ][1];
906  dg2 = dither_2x2_4[ y & 1 ][1];
907  db2 = dither_2x2_8[(y & 1) ^ 1][1];
908  } else if (target == AV_PIX_FMT_RGB555 || target == AV_PIX_FMT_BGR555) {
909  dr1 = dither_2x2_8[ y & 1 ][0];
910  dg1 = dither_2x2_8[ y & 1 ][1];
911  db1 = dither_2x2_8[(y & 1) ^ 1][0];
912  dr2 = dither_2x2_8[ y & 1 ][1];
913  dg2 = dither_2x2_8[ y & 1 ][0];
914  db2 = dither_2x2_8[(y & 1) ^ 1][1];
915  } else {
916  dr1 = dither_4x4_16[ y & 3 ][0];
917  dg1 = dither_4x4_16[ y & 3 ][1];
918  db1 = dither_4x4_16[(y & 3) ^ 3][0];
919  dr2 = dither_4x4_16[ y & 3 ][1];
920  dg2 = dither_4x4_16[ y & 3 ][0];
921  db2 = dither_4x4_16[(y & 3) ^ 3][1];
922  }
923 
924  dest[i * 2 + 0] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1];
925  dest[i * 2 + 1] = r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2];
926  } else /* 8/4-bit */ {
927  uint8_t *dest = (uint8_t *) _dest;
928  const uint8_t *r = (const uint8_t *) _r;
929  const uint8_t *g = (const uint8_t *) _g;
930  const uint8_t *b = (const uint8_t *) _b;
931  int dr1, dg1, db1, dr2, dg2, db2;
932 
933  if (target == AV_PIX_FMT_RGB8 || target == AV_PIX_FMT_BGR8) {
934  const uint8_t * const d64 = dither_8x8_73[y & 7];
935  const uint8_t * const d32 = dither_8x8_32[y & 7];
936  dr1 = dg1 = d32[(i * 2 + 0) & 7];
937  db1 = d64[(i * 2 + 0) & 7];
938  dr2 = dg2 = d32[(i * 2 + 1) & 7];
939  db2 = d64[(i * 2 + 1) & 7];
940  } else {
941  const uint8_t * const d64 = dither_8x8_73 [y & 7];
942  const uint8_t * const d128 = dither_8x8_220[y & 7];
943  dr1 = db1 = d128[(i * 2 + 0) & 7];
944  dg1 = d64[(i * 2 + 0) & 7];
945  dr2 = db2 = d128[(i * 2 + 1) & 7];
946  dg2 = d64[(i * 2 + 1) & 7];
947  }
948 
949  if (target == AV_PIX_FMT_RGB4 || target == AV_PIX_FMT_BGR4) {
950  dest[i] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1] +
951  ((r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2]) << 4);
952  } else {
953  dest[i * 2 + 0] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1];
954  dest[i * 2 + 1] = r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2];
955  }
956  }
957 }
958 
959 static av_always_inline void
960 yuv2rgb_X_c_template(SwsContext *c, const int16_t *lumFilter,
961  const int16_t **lumSrc, int lumFilterSize,
962  const int16_t *chrFilter, const int16_t **chrUSrc,
963  const int16_t **chrVSrc, int chrFilterSize,
964  const int16_t **alpSrc, uint8_t *dest, int dstW,
965  int y, enum AVPixelFormat target, int hasAlpha)
966 {
967  int i;
968 
969  for (i = 0; i < ((dstW + 1) >> 1); i++) {
970  int j, A1, A2;
971  int Y1 = 1 << 18;
972  int Y2 = 1 << 18;
973  int U = 1 << 18;
974  int V = 1 << 18;
975  const void *r, *g, *b;
976 
977  for (j = 0; j < lumFilterSize; j++) {
978  Y1 += lumSrc[j][i * 2] * lumFilter[j];
979  Y2 += lumSrc[j][i * 2 + 1] * lumFilter[j];
980  }
981  for (j = 0; j < chrFilterSize; j++) {
982  U += chrUSrc[j][i] * chrFilter[j];
983  V += chrVSrc[j][i] * chrFilter[j];
984  }
985  Y1 >>= 19;
986  Y2 >>= 19;
987  U >>= 19;
988  V >>= 19;
989  if (hasAlpha) {
990  A1 = 1 << 18;
991  A2 = 1 << 18;
992  for (j = 0; j < lumFilterSize; j++) {
993  A1 += alpSrc[j][i * 2 ] * lumFilter[j];
994  A2 += alpSrc[j][i * 2 + 1] * lumFilter[j];
995  }
996  A1 >>= 19;
997  A2 >>= 19;
998  if ((A1 | A2) & 0x100) {
999  A1 = av_clip_uint8(A1);
1000  A2 = av_clip_uint8(A2);
1001  }
1002  }
1003 
1004  r = c->table_rV[V + YUVRGB_TABLE_HEADROOM];
1006  b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
1007 
1008  yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
1009  r, g, b, y, target, hasAlpha);
1010  }
1011 }
1012 
1013 static av_always_inline void
1014 yuv2rgb_2_c_template(SwsContext *c, const int16_t *buf[2],
1015  const int16_t *ubuf[2], const int16_t *vbuf[2],
1016  const int16_t *abuf[2], uint8_t *dest, int dstW,
1017  int yalpha, int uvalpha, int y,
1018  enum AVPixelFormat target, int hasAlpha)
1019 {
1020  const int16_t *buf0 = buf[0], *buf1 = buf[1],
1021  *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
1022  *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
1023  *abuf0 = hasAlpha ? abuf[0] : NULL,
1024  *abuf1 = hasAlpha ? abuf[1] : NULL;
1025  int yalpha1 = 4096 - yalpha;
1026  int uvalpha1 = 4096 - uvalpha;
1027  int i;
1028 
1029  for (i = 0; i < ((dstW + 1) >> 1); i++) {
1030  int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 19;
1031  int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 19;
1032  int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha) >> 19;
1033  int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha) >> 19;
1034  int A1, A2;
1035  const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM],
1037  *b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
1038 
1039  if (hasAlpha) {
1040  A1 = (abuf0[i * 2 ] * yalpha1 + abuf1[i * 2 ] * yalpha) >> 19;
1041  A2 = (abuf0[i * 2 + 1] * yalpha1 + abuf1[i * 2 + 1] * yalpha) >> 19;
1042  A1 = av_clip_uint8(A1);
1043  A2 = av_clip_uint8(A2);
1044  }
1045 
1046  yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
1047  r, g, b, y, target, hasAlpha);
1048  }
1049 }
1050 
1051 static av_always_inline void
1052 yuv2rgb_1_c_template(SwsContext *c, const int16_t *buf0,
1053  const int16_t *ubuf[2], const int16_t *vbuf[2],
1054  const int16_t *abuf0, uint8_t *dest, int dstW,
1055  int uvalpha, int y, enum AVPixelFormat target,
1056  int hasAlpha)
1057 {
1058  const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
1059  int i;
1060 
1061  if (uvalpha < 2048) {
1062  for (i = 0; i < ((dstW + 1) >> 1); i++) {
1063  int Y1 = (buf0[i * 2 ] + 64) >> 7;
1064  int Y2 = (buf0[i * 2 + 1] + 64) >> 7;
1065  int U = (ubuf0[i] + 64) >> 7;
1066  int V = (vbuf0[i] + 64) >> 7;
1067  int A1, A2;
1068  const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM],
1070  *b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
1071 
1072  if (hasAlpha) {
1073  A1 = abuf0[i * 2 ] * 255 + 16384 >> 15;
1074  A2 = abuf0[i * 2 + 1] * 255 + 16384 >> 15;
1075  A1 = av_clip_uint8(A1);
1076  A2 = av_clip_uint8(A2);
1077  }
1078 
1079  yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
1080  r, g, b, y, target, hasAlpha);
1081  }
1082  } else {
1083  const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
1084  for (i = 0; i < ((dstW + 1) >> 1); i++) {
1085  int Y1 = (buf0[i * 2 ] + 64) >> 7;
1086  int Y2 = (buf0[i * 2 + 1] + 64) >> 7;
1087  int U = (ubuf0[i] + ubuf1[i] + 128) >> 8;
1088  int V = (vbuf0[i] + vbuf1[i] + 128) >> 8;
1089  int A1, A2;
1090  const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM],
1092  *b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
1093 
1094  if (hasAlpha) {
1095  A1 = (abuf0[i * 2 ] + 64) >> 7;
1096  A2 = (abuf0[i * 2 + 1] + 64) >> 7;
1097  A1 = av_clip_uint8(A1);
1098  A2 = av_clip_uint8(A2);
1099  }
1100 
1101  yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
1102  r, g, b, y, target, hasAlpha);
1103  }
1104  }
1105 }
1106 
1107 #define YUV2RGBWRAPPERX(name, base, ext, fmt, hasAlpha) \
1108 static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \
1109  const int16_t **lumSrc, int lumFilterSize, \
1110  const int16_t *chrFilter, const int16_t **chrUSrc, \
1111  const int16_t **chrVSrc, int chrFilterSize, \
1112  const int16_t **alpSrc, uint8_t *dest, int dstW, \
1113  int y) \
1114 { \
1115  name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
1116  chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
1117  alpSrc, dest, dstW, y, fmt, hasAlpha); \
1118 }
1119 #define YUV2RGBWRAPPER(name, base, ext, fmt, hasAlpha) \
1120 YUV2RGBWRAPPERX(name, base, ext, fmt, hasAlpha) \
1121 static void name ## ext ## _2_c(SwsContext *c, const int16_t *buf[2], \
1122  const int16_t *ubuf[2], const int16_t *vbuf[2], \
1123  const int16_t *abuf[2], uint8_t *dest, int dstW, \
1124  int yalpha, int uvalpha, int y) \
1125 { \
1126  name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
1127  dest, dstW, yalpha, uvalpha, y, fmt, hasAlpha); \
1128 } \
1129  \
1130 static void name ## ext ## _1_c(SwsContext *c, const int16_t *buf0, \
1131  const int16_t *ubuf[2], const int16_t *vbuf[2], \
1132  const int16_t *abuf0, uint8_t *dest, int dstW, \
1133  int uvalpha, int y) \
1134 { \
1135  name ## base ## _1_c_template(c, buf0, ubuf, vbuf, abuf0, dest, \
1136  dstW, uvalpha, y, fmt, hasAlpha); \
1137 }
1138 
1139 #if CONFIG_SMALL
1140 YUV2RGBWRAPPER(yuv2rgb,, 32_1, AV_PIX_FMT_RGB32_1, CONFIG_SWSCALE_ALPHA && c->alpPixBuf)
1141 YUV2RGBWRAPPER(yuv2rgb,, 32, AV_PIX_FMT_RGB32, CONFIG_SWSCALE_ALPHA && c->alpPixBuf)
1142 #else
1143 #if CONFIG_SWSCALE_ALPHA
1144 YUV2RGBWRAPPER(yuv2rgb,, a32_1, AV_PIX_FMT_RGB32_1, 1)
1145 YUV2RGBWRAPPER(yuv2rgb,, a32, AV_PIX_FMT_RGB32, 1)
1146 #endif
1147 YUV2RGBWRAPPER(yuv2rgb,, x32_1, AV_PIX_FMT_RGB32_1, 0)
1148 YUV2RGBWRAPPER(yuv2rgb,, x32, AV_PIX_FMT_RGB32, 0)
1149 #endif
1150 YUV2RGBWRAPPER(yuv2, rgb, rgb24, AV_PIX_FMT_RGB24, 0)
1151 YUV2RGBWRAPPER(yuv2, rgb, bgr24, AV_PIX_FMT_BGR24, 0)
1152 YUV2RGBWRAPPER(yuv2rgb,, 16, AV_PIX_FMT_RGB565, 0)
1153 YUV2RGBWRAPPER(yuv2rgb,, 15, AV_PIX_FMT_RGB555, 0)
1154 YUV2RGBWRAPPER(yuv2rgb,, 12, AV_PIX_FMT_RGB444, 0)
1155 YUV2RGBWRAPPER(yuv2rgb,, 8, AV_PIX_FMT_RGB8, 0)
1156 YUV2RGBWRAPPER(yuv2rgb,, 4, AV_PIX_FMT_RGB4, 0)
1157 YUV2RGBWRAPPER(yuv2rgb,, 4b, AV_PIX_FMT_RGB4_BYTE, 0)
1158 
1159 static av_always_inline void
1160 yuv2rgb_full_X_c_template(SwsContext *c, const int16_t *lumFilter,
1161  const int16_t **lumSrc, int lumFilterSize,
1162  const int16_t *chrFilter, const int16_t **chrUSrc,
1163  const int16_t **chrVSrc, int chrFilterSize,
1164  const int16_t **alpSrc, uint8_t *dest,
1165  int dstW, int y, enum AVPixelFormat target, int hasAlpha)
1166 {
1167  int i;
1168  int step = (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) ? 3 : 4;
1169 
1170  for (i = 0; i < dstW; i++) {
1171  int j;
1172  int Y = 1<<9;
1173  int U = (1<<9)-(128 << 19);
1174  int V = (1<<9)-(128 << 19);
1175  int R, G, B, A;
1176 
1177  for (j = 0; j < lumFilterSize; j++) {
1178  Y += lumSrc[j][i] * lumFilter[j];
1179  }
1180  for (j = 0; j < chrFilterSize; j++) {
1181  U += chrUSrc[j][i] * chrFilter[j];
1182  V += chrVSrc[j][i] * chrFilter[j];
1183  }
1184  Y >>= 10;
1185  U >>= 10;
1186  V >>= 10;
1187  if (hasAlpha) {
1188  A = 1 << 18;
1189  for (j = 0; j < lumFilterSize; j++) {
1190  A += alpSrc[j][i] * lumFilter[j];
1191  }
1192  A >>= 19;
1193  if (A & 0x100)
1194  A = av_clip_uint8(A);
1195  }
1196  Y -= c->yuv2rgb_y_offset;
1197  Y *= c->yuv2rgb_y_coeff;
1198  Y += 1 << 21;
1199  R = Y + V*c->yuv2rgb_v2r_coeff;
1200  G = Y + V*c->yuv2rgb_v2g_coeff + U*c->yuv2rgb_u2g_coeff;
1201  B = Y + U*c->yuv2rgb_u2b_coeff;
1202  if ((R | G | B) & 0xC0000000) {
1203  R = av_clip_uintp2(R, 30);
1204  G = av_clip_uintp2(G, 30);
1205  B = av_clip_uintp2(B, 30);
1206  }
1207 
1208  switch(target) {
1209  case AV_PIX_FMT_ARGB:
1210  dest[0] = hasAlpha ? A : 255;
1211  dest[1] = R >> 22;
1212  dest[2] = G >> 22;
1213  dest[3] = B >> 22;
1214  break;
1215  case AV_PIX_FMT_RGB24:
1216  dest[0] = R >> 22;
1217  dest[1] = G >> 22;
1218  dest[2] = B >> 22;
1219  break;
1220  case AV_PIX_FMT_RGBA:
1221  dest[0] = R >> 22;
1222  dest[1] = G >> 22;
1223  dest[2] = B >> 22;
1224  dest[3] = hasAlpha ? A : 255;
1225  break;
1226  case AV_PIX_FMT_ABGR:
1227  dest[0] = hasAlpha ? A : 255;
1228  dest[1] = B >> 22;
1229  dest[2] = G >> 22;
1230  dest[3] = R >> 22;
1231  break;
1232  case AV_PIX_FMT_BGR24:
1233  dest[0] = B >> 22;
1234  dest[1] = G >> 22;
1235  dest[2] = R >> 22;
1236  break;
1237  case AV_PIX_FMT_BGRA:
1238  dest[0] = B >> 22;
1239  dest[1] = G >> 22;
1240  dest[2] = R >> 22;
1241  dest[3] = hasAlpha ? A : 255;
1242  break;
1243  }
1244  dest += step;
1245  }
1246 }
1247 
1248 #if CONFIG_SMALL
1249 YUV2RGBWRAPPERX(yuv2, rgb_full, bgra32_full, AV_PIX_FMT_BGRA, CONFIG_SWSCALE_ALPHA && c->alpPixBuf)
1250 YUV2RGBWRAPPERX(yuv2, rgb_full, abgr32_full, AV_PIX_FMT_ABGR, CONFIG_SWSCALE_ALPHA && c->alpPixBuf)
1251 YUV2RGBWRAPPERX(yuv2, rgb_full, rgba32_full, AV_PIX_FMT_RGBA, CONFIG_SWSCALE_ALPHA && c->alpPixBuf)
1252 YUV2RGBWRAPPERX(yuv2, rgb_full, argb32_full, AV_PIX_FMT_ARGB, CONFIG_SWSCALE_ALPHA && c->alpPixBuf)
1253 #else
1254 #if CONFIG_SWSCALE_ALPHA
1255 YUV2RGBWRAPPERX(yuv2, rgb_full, bgra32_full, AV_PIX_FMT_BGRA, 1)
1256 YUV2RGBWRAPPERX(yuv2, rgb_full, abgr32_full, AV_PIX_FMT_ABGR, 1)
1257 YUV2RGBWRAPPERX(yuv2, rgb_full, rgba32_full, AV_PIX_FMT_RGBA, 1)
1258 YUV2RGBWRAPPERX(yuv2, rgb_full, argb32_full, AV_PIX_FMT_ARGB, 1)
1259 #endif
1260 YUV2RGBWRAPPERX(yuv2, rgb_full, bgrx32_full, AV_PIX_FMT_BGRA, 0)
1261 YUV2RGBWRAPPERX(yuv2, rgb_full, xbgr32_full, AV_PIX_FMT_ABGR, 0)
1262 YUV2RGBWRAPPERX(yuv2, rgb_full, rgbx32_full, AV_PIX_FMT_RGBA, 0)
1263 YUV2RGBWRAPPERX(yuv2, rgb_full, xrgb32_full, AV_PIX_FMT_ARGB, 0)
1264 #endif
1265 YUV2RGBWRAPPERX(yuv2, rgb_full, bgr24_full, AV_PIX_FMT_BGR24, 0)
1266 YUV2RGBWRAPPERX(yuv2, rgb_full, rgb24_full, AV_PIX_FMT_RGB24, 0)
1267 
1269  yuv2planar1_fn *yuv2plane1,
1270  yuv2planarX_fn *yuv2planeX,
1271  yuv2interleavedX_fn *yuv2nv12cX,
1272  yuv2packed1_fn *yuv2packed1,
1273  yuv2packed2_fn *yuv2packed2,
1274  yuv2packedX_fn *yuv2packedX)
1275 {
1276  enum AVPixelFormat dstFormat = c->dstFormat;
1277  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(dstFormat);
1278 
1279  if (is16BPS(dstFormat)) {
1280  *yuv2planeX = isBE(dstFormat) ? yuv2planeX_16BE_c : yuv2planeX_16LE_c;
1281  *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_16BE_c : yuv2plane1_16LE_c;
1282  } else if (is9_OR_10BPS(dstFormat)) {
1283  if (desc->comp[0].depth_minus1 == 8) {
1284  *yuv2planeX = isBE(dstFormat) ? yuv2planeX_9BE_c : yuv2planeX_9LE_c;
1285  *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_9BE_c : yuv2plane1_9LE_c;
1286  } else if (desc->comp[0].depth_minus1 == 9) {
1287  *yuv2planeX = isBE(dstFormat) ? yuv2planeX_10BE_c : yuv2planeX_10LE_c;
1288  *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_10BE_c : yuv2plane1_10LE_c;
1289  } else if (desc->comp[0].depth_minus1 == 11) {
1290  *yuv2planeX = isBE(dstFormat) ? yuv2planeX_12BE_c : yuv2planeX_12LE_c;
1291  *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_12BE_c : yuv2plane1_12LE_c;
1292  } else if (desc->comp[0].depth_minus1 == 13) {
1293  *yuv2planeX = isBE(dstFormat) ? yuv2planeX_14BE_c : yuv2planeX_14LE_c;
1294  *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_14BE_c : yuv2plane1_14LE_c;
1295  } else
1296  av_assert0(0);
1297  } else {
1298  *yuv2plane1 = yuv2plane1_8_c;
1299  *yuv2planeX = yuv2planeX_8_c;
1300  if (dstFormat == AV_PIX_FMT_NV12 || dstFormat == AV_PIX_FMT_NV21)
1301  *yuv2nv12cX = yuv2nv12cX_c;
1302  }
1303 
1304  if(c->flags & SWS_FULL_CHR_H_INT) {
1305  switch (dstFormat) {
1306  case AV_PIX_FMT_RGBA:
1307 #if CONFIG_SMALL
1308  *yuv2packedX = yuv2rgba32_full_X_c;
1309 #else
1310 #if CONFIG_SWSCALE_ALPHA
1311  if (c->alpPixBuf) {
1312  *yuv2packedX = yuv2rgba32_full_X_c;
1313  } else
1314 #endif /* CONFIG_SWSCALE_ALPHA */
1315  {
1316  *yuv2packedX = yuv2rgbx32_full_X_c;
1317  }
1318 #endif /* !CONFIG_SMALL */
1319  break;
1320  case AV_PIX_FMT_ARGB:
1321 #if CONFIG_SMALL
1322  *yuv2packedX = yuv2argb32_full_X_c;
1323 #else
1324 #if CONFIG_SWSCALE_ALPHA
1325  if (c->alpPixBuf) {
1326  *yuv2packedX = yuv2argb32_full_X_c;
1327  } else
1328 #endif /* CONFIG_SWSCALE_ALPHA */
1329  {
1330  *yuv2packedX = yuv2xrgb32_full_X_c;
1331  }
1332 #endif /* !CONFIG_SMALL */
1333  break;
1334  case AV_PIX_FMT_BGRA:
1335 #if CONFIG_SMALL
1336  *yuv2packedX = yuv2bgra32_full_X_c;
1337 #else
1338 #if CONFIG_SWSCALE_ALPHA
1339  if (c->alpPixBuf) {
1340  *yuv2packedX = yuv2bgra32_full_X_c;
1341  } else
1342 #endif /* CONFIG_SWSCALE_ALPHA */
1343  {
1344  *yuv2packedX = yuv2bgrx32_full_X_c;
1345  }
1346 #endif /* !CONFIG_SMALL */
1347  break;
1348  case AV_PIX_FMT_ABGR:
1349 #if CONFIG_SMALL
1350  *yuv2packedX = yuv2abgr32_full_X_c;
1351 #else
1352 #if CONFIG_SWSCALE_ALPHA
1353  if (c->alpPixBuf) {
1354  *yuv2packedX = yuv2abgr32_full_X_c;
1355  } else
1356 #endif /* CONFIG_SWSCALE_ALPHA */
1357  {
1358  *yuv2packedX = yuv2xbgr32_full_X_c;
1359  }
1360 #endif /* !CONFIG_SMALL */
1361  break;
1362  case AV_PIX_FMT_RGB24:
1363  *yuv2packedX = yuv2rgb24_full_X_c;
1364  break;
1365  case AV_PIX_FMT_BGR24:
1366  *yuv2packedX = yuv2bgr24_full_X_c;
1367  break;
1368  }
1369  if(!*yuv2packedX)
1370  goto YUV_PACKED;
1371  } else {
1372  YUV_PACKED:
1373  switch (dstFormat) {
1374  case AV_PIX_FMT_RGB48LE:
1375  *yuv2packed1 = yuv2rgb48le_1_c;
1376  *yuv2packed2 = yuv2rgb48le_2_c;
1377  *yuv2packedX = yuv2rgb48le_X_c;
1378  break;
1379  case AV_PIX_FMT_RGB48BE:
1380  *yuv2packed1 = yuv2rgb48be_1_c;
1381  *yuv2packed2 = yuv2rgb48be_2_c;
1382  *yuv2packedX = yuv2rgb48be_X_c;
1383  break;
1384  case AV_PIX_FMT_BGR48LE:
1385  *yuv2packed1 = yuv2bgr48le_1_c;
1386  *yuv2packed2 = yuv2bgr48le_2_c;
1387  *yuv2packedX = yuv2bgr48le_X_c;
1388  break;
1389  case AV_PIX_FMT_BGR48BE:
1390  *yuv2packed1 = yuv2bgr48be_1_c;
1391  *yuv2packed2 = yuv2bgr48be_2_c;
1392  *yuv2packedX = yuv2bgr48be_X_c;
1393  break;
1394  case AV_PIX_FMT_RGB32:
1395  case AV_PIX_FMT_BGR32:
1396 #if CONFIG_SMALL
1397  *yuv2packed1 = yuv2rgb32_1_c;
1398  *yuv2packed2 = yuv2rgb32_2_c;
1399  *yuv2packedX = yuv2rgb32_X_c;
1400 #else
1401 #if CONFIG_SWSCALE_ALPHA
1402  if (c->alpPixBuf) {
1403  *yuv2packed1 = yuv2rgba32_1_c;
1404  *yuv2packed2 = yuv2rgba32_2_c;
1405  *yuv2packedX = yuv2rgba32_X_c;
1406  } else
1407 #endif /* CONFIG_SWSCALE_ALPHA */
1408  {
1409  *yuv2packed1 = yuv2rgbx32_1_c;
1410  *yuv2packed2 = yuv2rgbx32_2_c;
1411  *yuv2packedX = yuv2rgbx32_X_c;
1412  }
1413 #endif /* !CONFIG_SMALL */
1414  break;
1415  case AV_PIX_FMT_RGB32_1:
1416  case AV_PIX_FMT_BGR32_1:
1417 #if CONFIG_SMALL
1418  *yuv2packed1 = yuv2rgb32_1_1_c;
1419  *yuv2packed2 = yuv2rgb32_1_2_c;
1420  *yuv2packedX = yuv2rgb32_1_X_c;
1421 #else
1422 #if CONFIG_SWSCALE_ALPHA
1423  if (c->alpPixBuf) {
1424  *yuv2packed1 = yuv2rgba32_1_1_c;
1425  *yuv2packed2 = yuv2rgba32_1_2_c;
1426  *yuv2packedX = yuv2rgba32_1_X_c;
1427  } else
1428 #endif /* CONFIG_SWSCALE_ALPHA */
1429  {
1430  *yuv2packed1 = yuv2rgbx32_1_1_c;
1431  *yuv2packed2 = yuv2rgbx32_1_2_c;
1432  *yuv2packedX = yuv2rgbx32_1_X_c;
1433  }
1434 #endif /* !CONFIG_SMALL */
1435  break;
1436  case AV_PIX_FMT_RGB24:
1437  *yuv2packed1 = yuv2rgb24_1_c;
1438  *yuv2packed2 = yuv2rgb24_2_c;
1439  *yuv2packedX = yuv2rgb24_X_c;
1440  break;
1441  case AV_PIX_FMT_BGR24:
1442  *yuv2packed1 = yuv2bgr24_1_c;
1443  *yuv2packed2 = yuv2bgr24_2_c;
1444  *yuv2packedX = yuv2bgr24_X_c;
1445  break;
1446  case AV_PIX_FMT_RGB565LE:
1447  case AV_PIX_FMT_RGB565BE:
1448  case AV_PIX_FMT_BGR565LE:
1449  case AV_PIX_FMT_BGR565BE:
1450  *yuv2packed1 = yuv2rgb16_1_c;
1451  *yuv2packed2 = yuv2rgb16_2_c;
1452  *yuv2packedX = yuv2rgb16_X_c;
1453  break;
1454  case AV_PIX_FMT_RGB555LE:
1455  case AV_PIX_FMT_RGB555BE:
1456  case AV_PIX_FMT_BGR555LE:
1457  case AV_PIX_FMT_BGR555BE:
1458  *yuv2packed1 = yuv2rgb15_1_c;
1459  *yuv2packed2 = yuv2rgb15_2_c;
1460  *yuv2packedX = yuv2rgb15_X_c;
1461  break;
1462  case AV_PIX_FMT_RGB444LE:
1463  case AV_PIX_FMT_RGB444BE:
1464  case AV_PIX_FMT_BGR444LE:
1465  case AV_PIX_FMT_BGR444BE:
1466  *yuv2packed1 = yuv2rgb12_1_c;
1467  *yuv2packed2 = yuv2rgb12_2_c;
1468  *yuv2packedX = yuv2rgb12_X_c;
1469  break;
1470  case AV_PIX_FMT_RGB8:
1471  case AV_PIX_FMT_BGR8:
1472  *yuv2packed1 = yuv2rgb8_1_c;
1473  *yuv2packed2 = yuv2rgb8_2_c;
1474  *yuv2packedX = yuv2rgb8_X_c;
1475  break;
1476  case AV_PIX_FMT_RGB4:
1477  case AV_PIX_FMT_BGR4:
1478  *yuv2packed1 = yuv2rgb4_1_c;
1479  *yuv2packed2 = yuv2rgb4_2_c;
1480  *yuv2packedX = yuv2rgb4_X_c;
1481  break;
1482  case AV_PIX_FMT_RGB4_BYTE:
1483  case AV_PIX_FMT_BGR4_BYTE:
1484  *yuv2packed1 = yuv2rgb4b_1_c;
1485  *yuv2packed2 = yuv2rgb4b_2_c;
1486  *yuv2packedX = yuv2rgb4b_X_c;
1487  break;
1488  }
1489  }
1490  switch (dstFormat) {
1491  case AV_PIX_FMT_MONOWHITE:
1492  *yuv2packed1 = yuv2monowhite_1_c;
1493  *yuv2packed2 = yuv2monowhite_2_c;
1494  *yuv2packedX = yuv2monowhite_X_c;
1495  break;
1496  case AV_PIX_FMT_MONOBLACK:
1497  *yuv2packed1 = yuv2monoblack_1_c;
1498  *yuv2packed2 = yuv2monoblack_2_c;
1499  *yuv2packedX = yuv2monoblack_X_c;
1500  break;
1501  case AV_PIX_FMT_YUYV422:
1502  *yuv2packed1 = yuv2yuyv422_1_c;
1503  *yuv2packed2 = yuv2yuyv422_2_c;
1504  *yuv2packedX = yuv2yuyv422_X_c;
1505  break;
1506  case AV_PIX_FMT_UYVY422:
1507  *yuv2packed1 = yuv2uyvy422_1_c;
1508  *yuv2packed2 = yuv2uyvy422_2_c;
1509  *yuv2packedX = yuv2uyvy422_X_c;
1510  break;
1511  }
1512 }