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