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