2 * Copyright (C) 2001-2012 Michael Niedermayer <michaelni@gmx.at>
4 * This file is part of FFmpeg.
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.
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.
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
26 #include "libavutil/attributes.h"
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"
37 #include "swscale_internal.h"
39 DECLARE_ALIGNED(8, const uint8_t, ff_dither_2x2_4)[][8] = {
40 { 1, 3, 1, 3, 1, 3, 1, 3, },
41 { 2, 0, 2, 0, 2, 0, 2, 0, },
42 { 1, 3, 1, 3, 1, 3, 1, 3, },
45 DECLARE_ALIGNED(8, const uint8_t, ff_dither_2x2_8)[][8] = {
46 { 6, 2, 6, 2, 6, 2, 6, 2, },
47 { 0, 4, 0, 4, 0, 4, 0, 4, },
48 { 6, 2, 6, 2, 6, 2, 6, 2, },
51 DECLARE_ALIGNED(8, const uint8_t, ff_dither_4x4_16)[][8] = {
52 { 8, 4, 11, 7, 8, 4, 11, 7, },
53 { 2, 14, 1, 13, 2, 14, 1, 13, },
54 { 10, 6, 9, 5, 10, 6, 9, 5, },
55 { 0, 12, 3, 15, 0, 12, 3, 15, },
56 { 8, 4, 11, 7, 8, 4, 11, 7, },
59 DECLARE_ALIGNED(8, const uint8_t, ff_dither_8x8_32)[][8] = {
60 { 17, 9, 23, 15, 16, 8, 22, 14, },
61 { 5, 29, 3, 27, 4, 28, 2, 26, },
62 { 21, 13, 19, 11, 20, 12, 18, 10, },
63 { 0, 24, 6, 30, 1, 25, 7, 31, },
64 { 16, 8, 22, 14, 17, 9, 23, 15, },
65 { 4, 28, 2, 26, 5, 29, 3, 27, },
66 { 20, 12, 18, 10, 21, 13, 19, 11, },
67 { 1, 25, 7, 31, 0, 24, 6, 30, },
68 { 17, 9, 23, 15, 16, 8, 22, 14, },
71 DECLARE_ALIGNED(8, const uint8_t, ff_dither_8x8_73)[][8] = {
72 { 0, 55, 14, 68, 3, 58, 17, 72, },
73 { 37, 18, 50, 32, 40, 22, 54, 35, },
74 { 9, 64, 5, 59, 13, 67, 8, 63, },
75 { 46, 27, 41, 23, 49, 31, 44, 26, },
76 { 2, 57, 16, 71, 1, 56, 15, 70, },
77 { 39, 21, 52, 34, 38, 19, 51, 33, },
78 { 11, 66, 7, 62, 10, 65, 6, 60, },
79 { 48, 30, 43, 25, 47, 29, 42, 24, },
80 { 0, 55, 14, 68, 3, 58, 17, 72, },
84 DECLARE_ALIGNED(8, const uint8_t, ff_dither_8x8_220)[][8] = {
85 {117, 62, 158, 103, 113, 58, 155, 100, },
86 { 34, 199, 21, 186, 31, 196, 17, 182, },
87 {144, 89, 131, 76, 141, 86, 127, 72, },
88 { 0, 165, 41, 206, 10, 175, 52, 217, },
89 {110, 55, 151, 96, 120, 65, 162, 107, },
90 { 28, 193, 14, 179, 38, 203, 24, 189, },
91 {138, 83, 124, 69, 148, 93, 134, 79, },
92 { 7, 172, 48, 213, 3, 168, 45, 210, },
93 {117, 62, 158, 103, 113, 58, 155, 100, },
96 // tries to correct a gamma of 1.5
97 DECLARE_ALIGNED(8, const uint8_t, ff_dither_8x8_220)[][8] = {
98 { 0, 143, 18, 200, 2, 156, 25, 215, },
99 { 78, 28, 125, 64, 89, 36, 138, 74, },
100 { 10, 180, 3, 161, 16, 195, 8, 175, },
101 {109, 51, 93, 38, 121, 60, 105, 47, },
102 { 1, 152, 23, 210, 0, 147, 20, 205, },
103 { 85, 33, 134, 71, 81, 30, 130, 67, },
104 { 14, 190, 6, 171, 12, 185, 5, 166, },
105 {117, 57, 101, 44, 113, 54, 97, 41, },
106 { 0, 143, 18, 200, 2, 156, 25, 215, },
109 // tries to correct a gamma of 2.0
110 DECLARE_ALIGNED(8, const uint8_t, ff_dither_8x8_220)[][8] = {
111 { 0, 124, 8, 193, 0, 140, 12, 213, },
112 { 55, 14, 104, 42, 66, 19, 119, 52, },
113 { 3, 168, 1, 145, 6, 187, 3, 162, },
114 { 86, 31, 70, 21, 99, 39, 82, 28, },
115 { 0, 134, 11, 206, 0, 129, 9, 200, },
116 { 62, 17, 114, 48, 58, 16, 109, 45, },
117 { 5, 181, 2, 157, 4, 175, 1, 151, },
118 { 95, 36, 78, 26, 90, 34, 74, 24, },
119 { 0, 124, 8, 193, 0, 140, 12, 213, },
122 // tries to correct a gamma of 2.5
123 DECLARE_ALIGNED(8, const uint8_t, ff_dither_8x8_220)[][8] = {
124 { 0, 107, 3, 187, 0, 125, 6, 212, },
125 { 39, 7, 86, 28, 49, 11, 102, 36, },
126 { 1, 158, 0, 131, 3, 180, 1, 151, },
127 { 68, 19, 52, 12, 81, 25, 64, 17, },
128 { 0, 119, 5, 203, 0, 113, 4, 195, },
129 { 45, 9, 96, 33, 42, 8, 91, 30, },
130 { 2, 172, 1, 144, 2, 165, 0, 137, },
131 { 77, 23, 60, 15, 72, 21, 56, 14, },
132 { 0, 107, 3, 187, 0, 125, 6, 212, },
136 #define output_pixel(pos, val, bias, signedness) \
138 AV_WB16(pos, bias + av_clip_ ## signedness ## 16(val >> shift)); \
140 AV_WL16(pos, bias + av_clip_ ## signedness ## 16(val >> shift)); \
143 static av_always_inline void
144 yuv2plane1_16_c_template(const int32_t *src, uint16_t *dest, int dstW,
145 int big_endian, int output_bits)
149 av_assert0(output_bits == 16);
151 for (i = 0; i < dstW; i++) {
152 int val = src[i] + (1 << (shift - 1));
153 output_pixel(&dest[i], val, 0, uint);
157 static av_always_inline void
158 yuv2planeX_16_c_template(const int16_t *filter, int filterSize,
159 const int32_t **src, uint16_t *dest, int dstW,
160 int big_endian, int output_bits)
164 av_assert0(output_bits == 16);
166 for (i = 0; i < dstW; i++) {
167 int val = 1 << (shift - 1);
170 /* range of val is [0,0x7FFFFFFF], so 31 bits, but with lanczos/spline
171 * filters (or anything with negative coeffs, the range can be slightly
172 * wider in both directions. To account for this overflow, we subtract
173 * a constant so it always fits in the signed range (assuming a
174 * reasonable filterSize), and re-add that at the end. */
176 for (j = 0; j < filterSize; j++)
177 val += src[j][i] * (unsigned)filter[j];
179 output_pixel(&dest[i], val, 0x8000, int);
183 static void yuv2p016cX_c(SwsContext *c, const int16_t *chrFilter, int chrFilterSize,
184 const int16_t **chrUSrc, const int16_t **chrVSrc,
185 uint8_t *dest8, int chrDstW)
187 uint16_t *dest = (uint16_t*)dest8;
188 const int32_t **uSrc = (const int32_t **)chrUSrc;
189 const int32_t **vSrc = (const int32_t **)chrVSrc;
191 int big_endian = c->dstFormat == AV_PIX_FMT_P016BE;
194 for (i = 0; i < chrDstW; i++) {
195 int u = 1 << (shift - 1);
196 int v = 1 << (shift - 1);
198 /* See yuv2planeX_16_c_template for details. */
201 for (j = 0; j < chrFilterSize; j++) {
202 u += uSrc[j][i] * (unsigned)chrFilter[j];
203 v += vSrc[j][i] * (unsigned)chrFilter[j];
206 output_pixel(&dest[2*i] , u, 0x8000, int);
207 output_pixel(&dest[2*i+1], v, 0x8000, int);
211 static av_always_inline void
212 yuv2plane1_float_c_template(const int32_t *src, float *dest, int dstW)
214 static const int big_endian = HAVE_BIGENDIAN;
215 static const int shift = 3;
216 static const float float_mult = 1.0f / 65535.0f;
220 for (i = 0; i < dstW; ++i){
221 val = src[i] + (1 << (shift - 1));
222 output_pixel(&val_uint, val, 0, uint);
223 dest[i] = float_mult * (float)val_uint;
227 static av_always_inline void
228 yuv2plane1_float_bswap_c_template(const int32_t *src, uint32_t *dest, int dstW)
230 static const int big_endian = HAVE_BIGENDIAN;
231 static const int shift = 3;
232 static const float float_mult = 1.0f / 65535.0f;
236 for (i = 0; i < dstW; ++i){
237 val = src[i] + (1 << (shift - 1));
238 output_pixel(&val_uint, val, 0, uint);
239 dest[i] = av_bswap32(av_float2int(float_mult * (float)val_uint));
243 static av_always_inline void
244 yuv2planeX_float_c_template(const int16_t *filter, int filterSize, const int32_t **src,
245 float *dest, int dstW)
247 static const int big_endian = HAVE_BIGENDIAN;
248 static const int shift = 15;
249 static const float float_mult = 1.0f / 65535.0f;
253 for (i = 0; i < dstW; ++i){
254 val = (1 << (shift - 1)) - 0x40000000;
255 for (j = 0; j < filterSize; ++j){
256 val += src[j][i] * (unsigned)filter[j];
258 output_pixel(&val_uint, val, 0x8000, int);
259 dest[i] = float_mult * (float)val_uint;
263 static av_always_inline void
264 yuv2planeX_float_bswap_c_template(const int16_t *filter, int filterSize, const int32_t **src,
265 uint32_t *dest, int dstW)
267 static const int big_endian = HAVE_BIGENDIAN;
268 static const int shift = 15;
269 static const float float_mult = 1.0f / 65535.0f;
273 for (i = 0; i < dstW; ++i){
274 val = (1 << (shift - 1)) - 0x40000000;
275 for (j = 0; j < filterSize; ++j){
276 val += src[j][i] * (unsigned)filter[j];
278 output_pixel(&val_uint, val, 0x8000, int);
279 dest[i] = av_bswap32(av_float2int(float_mult * (float)val_uint));
283 #define yuv2plane1_float(template, dest_type, BE_LE) \
284 static void yuv2plane1_float ## BE_LE ## _c(const int16_t *src, uint8_t *dest, int dstW, \
285 const uint8_t *dither, int offset) \
287 template((const int32_t *)src, (dest_type *)dest, dstW); \
290 #define yuv2planeX_float(template, dest_type, BE_LE) \
291 static void yuv2planeX_float ## BE_LE ## _c(const int16_t *filter, int filterSize, \
292 const int16_t **src, uint8_t *dest, int dstW, \
293 const uint8_t *dither, int offset) \
295 template(filter, filterSize, (const int32_t **)src, (dest_type *)dest, dstW); \
299 yuv2plane1_float(yuv2plane1_float_c_template, float, BE)
300 yuv2plane1_float(yuv2plane1_float_bswap_c_template, uint32_t, LE)
301 yuv2planeX_float(yuv2planeX_float_c_template, float, BE)
302 yuv2planeX_float(yuv2planeX_float_bswap_c_template, uint32_t, LE)
304 yuv2plane1_float(yuv2plane1_float_c_template, float, LE)
305 yuv2plane1_float(yuv2plane1_float_bswap_c_template, uint32_t, BE)
306 yuv2planeX_float(yuv2planeX_float_c_template, float, LE)
307 yuv2planeX_float(yuv2planeX_float_bswap_c_template, uint32_t, BE)
312 #define output_pixel(pos, val) \
314 AV_WB16(pos, av_clip_uintp2(val >> shift, output_bits)); \
316 AV_WL16(pos, av_clip_uintp2(val >> shift, output_bits)); \
319 static av_always_inline void
320 yuv2plane1_10_c_template(const int16_t *src, uint16_t *dest, int dstW,
321 int big_endian, int output_bits)
324 int shift = 15 - output_bits;
326 for (i = 0; i < dstW; i++) {
327 int val = src[i] + (1 << (shift - 1));
328 output_pixel(&dest[i], val);
332 static av_always_inline void
333 yuv2planeX_10_c_template(const int16_t *filter, int filterSize,
334 const int16_t **src, uint16_t *dest, int dstW,
335 int big_endian, int output_bits)
338 int shift = 11 + 16 - output_bits;
340 for (i = 0; i < dstW; i++) {
341 int val = 1 << (shift - 1);
344 for (j = 0; j < filterSize; j++)
345 val += src[j][i] * filter[j];
347 output_pixel(&dest[i], val);
353 #define yuv2NBPS(bits, BE_LE, is_be, template_size, typeX_t) \
354 static void yuv2plane1_ ## bits ## BE_LE ## _c(const int16_t *src, \
355 uint8_t *dest, int dstW, \
356 const uint8_t *dither, int offset)\
358 yuv2plane1_ ## template_size ## _c_template((const typeX_t *) src, \
359 (uint16_t *) dest, dstW, is_be, bits); \
361 static void yuv2planeX_ ## bits ## BE_LE ## _c(const int16_t *filter, int filterSize, \
362 const int16_t **src, uint8_t *dest, int dstW, \
363 const uint8_t *dither, int offset)\
365 yuv2planeX_## template_size ## _c_template(filter, \
366 filterSize, (const typeX_t **) src, \
367 (uint16_t *) dest, dstW, is_be, bits); \
369 yuv2NBPS( 9, BE, 1, 10, int16_t)
370 yuv2NBPS( 9, LE, 0, 10, int16_t)
371 yuv2NBPS(10, BE, 1, 10, int16_t)
372 yuv2NBPS(10, LE, 0, 10, int16_t)
373 yuv2NBPS(12, BE, 1, 10, int16_t)
374 yuv2NBPS(12, LE, 0, 10, int16_t)
375 yuv2NBPS(14, BE, 1, 10, int16_t)
376 yuv2NBPS(14, LE, 0, 10, int16_t)
377 yuv2NBPS(16, BE, 1, 16, int32_t)
378 yuv2NBPS(16, LE, 0, 16, int32_t)
380 static void yuv2planeX_8_c(const int16_t *filter, int filterSize,
381 const int16_t **src, uint8_t *dest, int dstW,
382 const uint8_t *dither, int offset)
385 for (i=0; i<dstW; i++) {
386 int val = dither[(i + offset) & 7] << 12;
388 for (j=0; j<filterSize; j++)
389 val += src[j][i] * filter[j];
391 dest[i]= av_clip_uint8(val>>19);
395 static void yuv2plane1_8_c(const int16_t *src, uint8_t *dest, int dstW,
396 const uint8_t *dither, int offset)
399 for (i=0; i<dstW; i++) {
400 int val = (src[i] + dither[(i + offset) & 7]) >> 7;
401 dest[i]= av_clip_uint8(val);
405 static void yuv2nv12cX_c(SwsContext *c, const int16_t *chrFilter, int chrFilterSize,
406 const int16_t **chrUSrc, const int16_t **chrVSrc,
407 uint8_t *dest, int chrDstW)
409 enum AVPixelFormat dstFormat = c->dstFormat;
410 const uint8_t *chrDither = c->chrDither8;
413 if (dstFormat == AV_PIX_FMT_NV12)
414 for (i=0; i<chrDstW; i++) {
415 int u = chrDither[i & 7] << 12;
416 int v = chrDither[(i + 3) & 7] << 12;
418 for (j=0; j<chrFilterSize; j++) {
419 u += chrUSrc[j][i] * chrFilter[j];
420 v += chrVSrc[j][i] * chrFilter[j];
423 dest[2*i]= av_clip_uint8(u>>19);
424 dest[2*i+1]= av_clip_uint8(v>>19);
427 for (i=0; i<chrDstW; i++) {
428 int u = chrDither[i & 7] << 12;
429 int v = chrDither[(i + 3) & 7] << 12;
431 for (j=0; j<chrFilterSize; j++) {
432 u += chrUSrc[j][i] * chrFilter[j];
433 v += chrVSrc[j][i] * chrFilter[j];
436 dest[2*i]= av_clip_uint8(v>>19);
437 dest[2*i+1]= av_clip_uint8(u>>19);
442 #define output_pixel(pos, val) \
444 AV_WB16(pos, av_clip_uintp2(val >> shift, 10) << 6); \
446 AV_WL16(pos, av_clip_uintp2(val >> shift, 10) << 6); \
449 static void yuv2p010l1_c(const int16_t *src,
450 uint16_t *dest, int dstW,
456 for (i = 0; i < dstW; i++) {
457 int val = src[i] + (1 << (shift - 1));
458 output_pixel(&dest[i], val);
462 static void yuv2p010lX_c(const int16_t *filter, int filterSize,
463 const int16_t **src, uint16_t *dest, int dstW,
469 for (i = 0; i < dstW; i++) {
470 int val = 1 << (shift - 1);
472 for (j = 0; j < filterSize; j++)
473 val += src[j][i] * filter[j];
475 output_pixel(&dest[i], val);
479 static void yuv2p010cX_c(SwsContext *c, const int16_t *chrFilter, int chrFilterSize,
480 const int16_t **chrUSrc, const int16_t **chrVSrc,
481 uint8_t *dest8, int chrDstW)
483 uint16_t *dest = (uint16_t*)dest8;
485 int big_endian = c->dstFormat == AV_PIX_FMT_P010BE;
488 for (i = 0; i < chrDstW; i++) {
489 int u = 1 << (shift - 1);
490 int v = 1 << (shift - 1);
492 for (j = 0; j < chrFilterSize; j++) {
493 u += chrUSrc[j][i] * chrFilter[j];
494 v += chrVSrc[j][i] * chrFilter[j];
497 output_pixel(&dest[2*i] , u);
498 output_pixel(&dest[2*i+1], v);
502 static void yuv2p010l1_LE_c(const int16_t *src,
503 uint8_t *dest, int dstW,
504 const uint8_t *dither, int offset)
506 yuv2p010l1_c(src, (uint16_t*)dest, dstW, 0);
509 static void yuv2p010l1_BE_c(const int16_t *src,
510 uint8_t *dest, int dstW,
511 const uint8_t *dither, int offset)
513 yuv2p010l1_c(src, (uint16_t*)dest, dstW, 1);
516 static void yuv2p010lX_LE_c(const int16_t *filter, int filterSize,
517 const int16_t **src, uint8_t *dest, int dstW,
518 const uint8_t *dither, int offset)
520 yuv2p010lX_c(filter, filterSize, src, (uint16_t*)dest, dstW, 0);
523 static void yuv2p010lX_BE_c(const int16_t *filter, int filterSize,
524 const int16_t **src, uint8_t *dest, int dstW,
525 const uint8_t *dither, int offset)
527 yuv2p010lX_c(filter, filterSize, src, (uint16_t*)dest, dstW, 1);
533 #define accumulate_bit(acc, val) \
536 #define output_pixel(pos, acc) \
537 if (target == AV_PIX_FMT_MONOBLACK) { \
543 static av_always_inline void
544 yuv2mono_X_c_template(SwsContext *c, const int16_t *lumFilter,
545 const int16_t **lumSrc, int lumFilterSize,
546 const int16_t *chrFilter, const int16_t **chrUSrc,
547 const int16_t **chrVSrc, int chrFilterSize,
548 const int16_t **alpSrc, uint8_t *dest, int dstW,
549 int y, enum AVPixelFormat target)
551 const uint8_t * const d128 = ff_dither_8x8_220[y&7];
556 for (i = 0; i < dstW; i += 2) {
561 for (j = 0; j < lumFilterSize; j++) {
562 Y1 += lumSrc[j][i] * lumFilter[j];
563 Y2 += lumSrc[j][i+1] * lumFilter[j];
567 if ((Y1 | Y2) & 0x100) {
568 Y1 = av_clip_uint8(Y1);
569 Y2 = av_clip_uint8(Y2);
571 if (c->dither == SWS_DITHER_ED) {
572 Y1 += (7*err + 1*c->dither_error[0][i] + 5*c->dither_error[0][i+1] + 3*c->dither_error[0][i+2] + 8 - 256)>>4;
573 c->dither_error[0][i] = err;
574 acc = 2*acc + (Y1 >= 128);
577 err = Y2 + ((7*Y1 + 1*c->dither_error[0][i+1] + 5*c->dither_error[0][i+2] + 3*c->dither_error[0][i+3] + 8 - 256)>>4);
578 c->dither_error[0][i+1] = Y1;
579 acc = 2*acc + (err >= 128);
582 accumulate_bit(acc, Y1 + d128[(i + 0) & 7]);
583 accumulate_bit(acc, Y2 + d128[(i + 1) & 7]);
586 output_pixel(*dest++, acc);
589 c->dither_error[0][i] = err;
592 output_pixel(*dest, acc);
596 static av_always_inline void
597 yuv2mono_2_c_template(SwsContext *c, const int16_t *buf[2],
598 const int16_t *ubuf[2], const int16_t *vbuf[2],
599 const int16_t *abuf[2], uint8_t *dest, int dstW,
600 int yalpha, int uvalpha, int y,
601 enum AVPixelFormat target)
603 const int16_t *buf0 = buf[0], *buf1 = buf[1];
604 const uint8_t * const d128 = ff_dither_8x8_220[y & 7];
605 int yalpha1 = 4096 - yalpha;
607 av_assert2(yalpha <= 4096U);
609 if (c->dither == SWS_DITHER_ED) {
612 for (i = 0; i < dstW; i +=2) {
615 Y = (buf0[i + 0] * yalpha1 + buf1[i + 0] * yalpha) >> 19;
616 Y += (7*err + 1*c->dither_error[0][i] + 5*c->dither_error[0][i+1] + 3*c->dither_error[0][i+2] + 8 - 256)>>4;
617 c->dither_error[0][i] = err;
618 acc = 2*acc + (Y >= 128);
621 err = (buf0[i + 1] * yalpha1 + buf1[i + 1] * yalpha) >> 19;
622 err += (7*Y + 1*c->dither_error[0][i+1] + 5*c->dither_error[0][i+2] + 3*c->dither_error[0][i+3] + 8 - 256)>>4;
623 c->dither_error[0][i+1] = Y;
624 acc = 2*acc + (err >= 128);
628 output_pixel(*dest++, acc);
630 c->dither_error[0][i] = err;
632 for (i = 0; i < dstW; i += 8) {
635 Y = (buf0[i + 0] * yalpha1 + buf1[i + 0] * yalpha) >> 19;
636 accumulate_bit(acc, Y + d128[0]);
637 Y = (buf0[i + 1] * yalpha1 + buf1[i + 1] * yalpha) >> 19;
638 accumulate_bit(acc, Y + d128[1]);
639 Y = (buf0[i + 2] * yalpha1 + buf1[i + 2] * yalpha) >> 19;
640 accumulate_bit(acc, Y + d128[2]);
641 Y = (buf0[i + 3] * yalpha1 + buf1[i + 3] * yalpha) >> 19;
642 accumulate_bit(acc, Y + d128[3]);
643 Y = (buf0[i + 4] * yalpha1 + buf1[i + 4] * yalpha) >> 19;
644 accumulate_bit(acc, Y + d128[4]);
645 Y = (buf0[i + 5] * yalpha1 + buf1[i + 5] * yalpha) >> 19;
646 accumulate_bit(acc, Y + d128[5]);
647 Y = (buf0[i + 6] * yalpha1 + buf1[i + 6] * yalpha) >> 19;
648 accumulate_bit(acc, Y + d128[6]);
649 Y = (buf0[i + 7] * yalpha1 + buf1[i + 7] * yalpha) >> 19;
650 accumulate_bit(acc, Y + d128[7]);
652 output_pixel(*dest++, acc);
657 static av_always_inline void
658 yuv2mono_1_c_template(SwsContext *c, const int16_t *buf0,
659 const int16_t *ubuf[2], const int16_t *vbuf[2],
660 const int16_t *abuf0, uint8_t *dest, int dstW,
661 int uvalpha, int y, enum AVPixelFormat target)
663 const uint8_t * const d128 = ff_dither_8x8_220[y & 7];
666 if (c->dither == SWS_DITHER_ED) {
669 for (i = 0; i < dstW; i +=2) {
672 Y = ((buf0[i + 0] + 64) >> 7);
673 Y += (7*err + 1*c->dither_error[0][i] + 5*c->dither_error[0][i+1] + 3*c->dither_error[0][i+2] + 8 - 256)>>4;
674 c->dither_error[0][i] = err;
675 acc = 2*acc + (Y >= 128);
678 err = ((buf0[i + 1] + 64) >> 7);
679 err += (7*Y + 1*c->dither_error[0][i+1] + 5*c->dither_error[0][i+2] + 3*c->dither_error[0][i+3] + 8 - 256)>>4;
680 c->dither_error[0][i+1] = Y;
681 acc = 2*acc + (err >= 128);
685 output_pixel(*dest++, acc);
687 c->dither_error[0][i] = err;
689 for (i = 0; i < dstW; i += 8) {
691 accumulate_bit(acc, ((buf0[i + 0] + 64) >> 7) + d128[0]);
692 accumulate_bit(acc, ((buf0[i + 1] + 64) >> 7) + d128[1]);
693 accumulate_bit(acc, ((buf0[i + 2] + 64) >> 7) + d128[2]);
694 accumulate_bit(acc, ((buf0[i + 3] + 64) >> 7) + d128[3]);
695 accumulate_bit(acc, ((buf0[i + 4] + 64) >> 7) + d128[4]);
696 accumulate_bit(acc, ((buf0[i + 5] + 64) >> 7) + d128[5]);
697 accumulate_bit(acc, ((buf0[i + 6] + 64) >> 7) + d128[6]);
698 accumulate_bit(acc, ((buf0[i + 7] + 64) >> 7) + d128[7]);
700 output_pixel(*dest++, acc);
706 #undef accumulate_bit
708 #define YUV2PACKEDWRAPPER(name, base, ext, fmt) \
709 static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \
710 const int16_t **lumSrc, int lumFilterSize, \
711 const int16_t *chrFilter, const int16_t **chrUSrc, \
712 const int16_t **chrVSrc, int chrFilterSize, \
713 const int16_t **alpSrc, uint8_t *dest, int dstW, \
716 name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
717 chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
718 alpSrc, dest, dstW, y, fmt); \
721 static void name ## ext ## _2_c(SwsContext *c, const int16_t *buf[2], \
722 const int16_t *ubuf[2], const int16_t *vbuf[2], \
723 const int16_t *abuf[2], uint8_t *dest, int dstW, \
724 int yalpha, int uvalpha, int y) \
726 name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
727 dest, dstW, yalpha, uvalpha, y, fmt); \
730 static void name ## ext ## _1_c(SwsContext *c, const int16_t *buf0, \
731 const int16_t *ubuf[2], const int16_t *vbuf[2], \
732 const int16_t *abuf0, uint8_t *dest, int dstW, \
733 int uvalpha, int y) \
735 name ## base ## _1_c_template(c, buf0, ubuf, vbuf, \
736 abuf0, dest, dstW, uvalpha, \
740 YUV2PACKEDWRAPPER(yuv2mono,, white, AV_PIX_FMT_MONOWHITE)
741 YUV2PACKEDWRAPPER(yuv2mono,, black, AV_PIX_FMT_MONOBLACK)
743 #define output_pixels(pos, Y1, U, Y2, V) \
744 if (target == AV_PIX_FMT_YUYV422) { \
745 dest[pos + 0] = Y1; \
747 dest[pos + 2] = Y2; \
749 } else if (target == AV_PIX_FMT_YVYU422) { \
750 dest[pos + 0] = Y1; \
752 dest[pos + 2] = Y2; \
754 } else { /* AV_PIX_FMT_UYVY422 */ \
756 dest[pos + 1] = Y1; \
758 dest[pos + 3] = Y2; \
761 static av_always_inline void
762 yuv2422_X_c_template(SwsContext *c, const int16_t *lumFilter,
763 const int16_t **lumSrc, int lumFilterSize,
764 const int16_t *chrFilter, const int16_t **chrUSrc,
765 const int16_t **chrVSrc, int chrFilterSize,
766 const int16_t **alpSrc, uint8_t *dest, int dstW,
767 int y, enum AVPixelFormat target)
771 for (i = 0; i < ((dstW + 1) >> 1); i++) {
778 for (j = 0; j < lumFilterSize; j++) {
779 Y1 += lumSrc[j][i * 2] * lumFilter[j];
780 Y2 += lumSrc[j][i * 2 + 1] * lumFilter[j];
782 for (j = 0; j < chrFilterSize; j++) {
783 U += chrUSrc[j][i] * chrFilter[j];
784 V += chrVSrc[j][i] * chrFilter[j];
790 if ((Y1 | Y2 | U | V) & 0x100) {
791 Y1 = av_clip_uint8(Y1);
792 Y2 = av_clip_uint8(Y2);
793 U = av_clip_uint8(U);
794 V = av_clip_uint8(V);
796 output_pixels(4*i, Y1, U, Y2, V);
800 static av_always_inline void
801 yuv2422_2_c_template(SwsContext *c, const int16_t *buf[2],
802 const int16_t *ubuf[2], const int16_t *vbuf[2],
803 const int16_t *abuf[2], uint8_t *dest, int dstW,
804 int yalpha, int uvalpha, int y,
805 enum AVPixelFormat target)
807 const int16_t *buf0 = buf[0], *buf1 = buf[1],
808 *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
809 *vbuf0 = vbuf[0], *vbuf1 = vbuf[1];
810 int yalpha1 = 4096 - yalpha;
811 int uvalpha1 = 4096 - uvalpha;
813 av_assert2(yalpha <= 4096U);
814 av_assert2(uvalpha <= 4096U);
816 for (i = 0; i < ((dstW + 1) >> 1); i++) {
817 int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 19;
818 int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 19;
819 int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha) >> 19;
820 int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha) >> 19;
822 if ((Y1 | Y2 | U | V) & 0x100) {
823 Y1 = av_clip_uint8(Y1);
824 Y2 = av_clip_uint8(Y2);
825 U = av_clip_uint8(U);
826 V = av_clip_uint8(V);
829 output_pixels(i * 4, Y1, U, Y2, V);
833 static av_always_inline void
834 yuv2422_1_c_template(SwsContext *c, const int16_t *buf0,
835 const int16_t *ubuf[2], const int16_t *vbuf[2],
836 const int16_t *abuf0, uint8_t *dest, int dstW,
837 int uvalpha, int y, enum AVPixelFormat target)
839 const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
842 if (uvalpha < 2048) {
843 for (i = 0; i < ((dstW + 1) >> 1); i++) {
844 int Y1 = (buf0[i * 2 ]+64) >> 7;
845 int Y2 = (buf0[i * 2 + 1]+64) >> 7;
846 int U = (ubuf0[i] +64) >> 7;
847 int V = (vbuf0[i] +64) >> 7;
849 if ((Y1 | Y2 | U | V) & 0x100) {
850 Y1 = av_clip_uint8(Y1);
851 Y2 = av_clip_uint8(Y2);
852 U = av_clip_uint8(U);
853 V = av_clip_uint8(V);
856 Y1 = av_clip_uint8(Y1);
857 Y2 = av_clip_uint8(Y2);
858 U = av_clip_uint8(U);
859 V = av_clip_uint8(V);
861 output_pixels(i * 4, Y1, U, Y2, V);
864 const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
865 for (i = 0; i < ((dstW + 1) >> 1); i++) {
866 int Y1 = (buf0[i * 2 ] + 64) >> 7;
867 int Y2 = (buf0[i * 2 + 1] + 64) >> 7;
868 int U = (ubuf0[i] + ubuf1[i]+128) >> 8;
869 int V = (vbuf0[i] + vbuf1[i]+128) >> 8;
871 if ((Y1 | Y2 | U | V) & 0x100) {
872 Y1 = av_clip_uint8(Y1);
873 Y2 = av_clip_uint8(Y2);
874 U = av_clip_uint8(U);
875 V = av_clip_uint8(V);
878 Y1 = av_clip_uint8(Y1);
879 Y2 = av_clip_uint8(Y2);
880 U = av_clip_uint8(U);
881 V = av_clip_uint8(V);
883 output_pixels(i * 4, Y1, U, Y2, V);
890 YUV2PACKEDWRAPPER(yuv2, 422, yuyv422, AV_PIX_FMT_YUYV422)
891 YUV2PACKEDWRAPPER(yuv2, 422, yvyu422, AV_PIX_FMT_YVYU422)
892 YUV2PACKEDWRAPPER(yuv2, 422, uyvy422, AV_PIX_FMT_UYVY422)
894 #define R_B ((target == AV_PIX_FMT_RGB48LE || target == AV_PIX_FMT_RGB48BE || target == AV_PIX_FMT_RGBA64LE || target == AV_PIX_FMT_RGBA64BE) ? R : B)
895 #define B_R ((target == AV_PIX_FMT_RGB48LE || target == AV_PIX_FMT_RGB48BE || target == AV_PIX_FMT_RGBA64LE || target == AV_PIX_FMT_RGBA64BE) ? B : R)
896 #define output_pixel(pos, val) \
897 if (isBE(target)) { \
903 static av_always_inline void
904 yuv2rgba64_X_c_template(SwsContext *c, const int16_t *lumFilter,
905 const int32_t **lumSrc, int lumFilterSize,
906 const int16_t *chrFilter, const int32_t **chrUSrc,
907 const int32_t **chrVSrc, int chrFilterSize,
908 const int32_t **alpSrc, uint16_t *dest, int dstW,
909 int y, enum AVPixelFormat target, int hasAlpha, int eightbytes)
912 int A1 = 0xffff<<14, A2 = 0xffff<<14;
914 for (i = 0; i < ((dstW + 1) >> 1); i++) {
916 int Y1 = -0x40000000;
917 int Y2 = -0x40000000;
918 int U = -(128 << 23); // 19
919 int V = -(128 << 23);
922 for (j = 0; j < lumFilterSize; j++) {
923 Y1 += lumSrc[j][i * 2] * (unsigned)lumFilter[j];
924 Y2 += lumSrc[j][i * 2 + 1] * (unsigned)lumFilter[j];
926 for (j = 0; j < chrFilterSize; j++) {;
927 U += chrUSrc[j][i] * (unsigned)chrFilter[j];
928 V += chrVSrc[j][i] * (unsigned)chrFilter[j];
934 for (j = 0; j < lumFilterSize; j++) {
935 A1 += alpSrc[j][i * 2] * (unsigned)lumFilter[j];
936 A2 += alpSrc[j][i * 2 + 1] * (unsigned)lumFilter[j];
944 // 8 bits: 12+15=27; 16 bits: 12+19=31
952 // 8 bits: 27 -> 17 bits, 16 bits: 31 - 14 = 17 bits
953 Y1 -= c->yuv2rgb_y_offset;
954 Y2 -= c->yuv2rgb_y_offset;
955 Y1 *= c->yuv2rgb_y_coeff;
956 Y2 *= c->yuv2rgb_y_coeff;
959 // 8 bits: 17 + 13 bits = 30 bits, 16 bits: 17 + 13 bits = 30 bits
961 R = V * c->yuv2rgb_v2r_coeff;
962 G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
963 B = U * c->yuv2rgb_u2b_coeff;
965 // 8 bits: 30 - 22 = 8 bits, 16 bits: 30 bits - 14 = 16 bits
966 output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
967 output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
968 output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
970 output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14);
971 output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >> 14);
972 output_pixel(&dest[5], av_clip_uintp2( G + Y2, 30) >> 14);
973 output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >> 14);
974 output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14);
977 output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
978 output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);
979 output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
985 static av_always_inline void
986 yuv2rgba64_2_c_template(SwsContext *c, const int32_t *buf[2],
987 const int32_t *ubuf[2], const int32_t *vbuf[2],
988 const int32_t *abuf[2], uint16_t *dest, int dstW,
989 int yalpha, int uvalpha, int y,
990 enum AVPixelFormat target, int hasAlpha, int eightbytes)
992 const int32_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 = 4096 - yalpha;
998 int uvalpha1 = 4096 - uvalpha;
1000 int A1 = 0xffff<<14, A2 = 0xffff<<14;
1002 av_assert2(yalpha <= 4096U);
1003 av_assert2(uvalpha <= 4096U);
1005 for (i = 0; i < ((dstW + 1) >> 1); i++) {
1006 int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 14;
1007 int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 14;
1008 int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha - (128 << 23)) >> 14;
1009 int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha - (128 << 23)) >> 14;
1012 Y1 -= c->yuv2rgb_y_offset;
1013 Y2 -= c->yuv2rgb_y_offset;
1014 Y1 *= c->yuv2rgb_y_coeff;
1015 Y2 *= c->yuv2rgb_y_coeff;
1019 R = V * c->yuv2rgb_v2r_coeff;
1020 G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
1021 B = U * c->yuv2rgb_u2b_coeff;
1024 A1 = (abuf0[i * 2 ] * yalpha1 + abuf1[i * 2 ] * yalpha) >> 1;
1025 A2 = (abuf0[i * 2 + 1] * yalpha1 + abuf1[i * 2 + 1] * yalpha) >> 1;
1031 output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
1032 output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
1033 output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
1035 output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14);
1036 output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >> 14);
1037 output_pixel(&dest[5], av_clip_uintp2( G + Y2, 30) >> 14);
1038 output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >> 14);
1039 output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14);
1042 output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
1043 output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);
1044 output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
1050 static av_always_inline void
1051 yuv2rgba64_1_c_template(SwsContext *c, const int32_t *buf0,
1052 const int32_t *ubuf[2], const int32_t *vbuf[2],
1053 const int32_t *abuf0, uint16_t *dest, int dstW,
1054 int uvalpha, int y, enum AVPixelFormat target, int hasAlpha, int eightbytes)
1056 const int32_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
1058 int A1 = 0xffff<<14, A2= 0xffff<<14;
1060 if (uvalpha < 2048) {
1061 for (i = 0; i < ((dstW + 1) >> 1); i++) {
1062 int Y1 = (buf0[i * 2] ) >> 2;
1063 int Y2 = (buf0[i * 2 + 1]) >> 2;
1064 int U = (ubuf0[i] - (128 << 11)) >> 2;
1065 int V = (vbuf0[i] - (128 << 11)) >> 2;
1068 Y1 -= c->yuv2rgb_y_offset;
1069 Y2 -= c->yuv2rgb_y_offset;
1070 Y1 *= c->yuv2rgb_y_coeff;
1071 Y2 *= c->yuv2rgb_y_coeff;
1076 A1 = abuf0[i * 2 ] << 11;
1077 A2 = abuf0[i * 2 + 1] << 11;
1083 R = V * c->yuv2rgb_v2r_coeff;
1084 G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
1085 B = U * c->yuv2rgb_u2b_coeff;
1087 output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
1088 output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
1089 output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
1091 output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14);
1092 output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >> 14);
1093 output_pixel(&dest[5], av_clip_uintp2( G + Y2, 30) >> 14);
1094 output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >> 14);
1095 output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14);
1098 output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
1099 output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);
1100 output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
1105 const int32_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
1106 int A1 = 0xffff<<14, A2 = 0xffff<<14;
1107 for (i = 0; i < ((dstW + 1) >> 1); i++) {
1108 int Y1 = (buf0[i * 2] ) >> 2;
1109 int Y2 = (buf0[i * 2 + 1]) >> 2;
1110 int U = (ubuf0[i] + ubuf1[i] - (128 << 12)) >> 3;
1111 int V = (vbuf0[i] + vbuf1[i] - (128 << 12)) >> 3;
1114 Y1 -= c->yuv2rgb_y_offset;
1115 Y2 -= c->yuv2rgb_y_offset;
1116 Y1 *= c->yuv2rgb_y_coeff;
1117 Y2 *= c->yuv2rgb_y_coeff;
1122 A1 = abuf0[i * 2 ] << 11;
1123 A2 = abuf0[i * 2 + 1] << 11;
1129 R = V * c->yuv2rgb_v2r_coeff;
1130 G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
1131 B = U * c->yuv2rgb_u2b_coeff;
1133 output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
1134 output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
1135 output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
1137 output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14);
1138 output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >> 14);
1139 output_pixel(&dest[5], av_clip_uintp2( G + Y2, 30) >> 14);
1140 output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >> 14);
1141 output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14);
1144 output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
1145 output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);
1146 output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
1153 static av_always_inline void
1154 yuv2rgba64_full_X_c_template(SwsContext *c, const int16_t *lumFilter,
1155 const int32_t **lumSrc, int lumFilterSize,
1156 const int16_t *chrFilter, const int32_t **chrUSrc,
1157 const int32_t **chrVSrc, int chrFilterSize,
1158 const int32_t **alpSrc, uint16_t *dest, int dstW,
1159 int y, enum AVPixelFormat target, int hasAlpha, int eightbytes)
1164 for (i = 0; i < dstW; i++) {
1166 int Y = -0x40000000;
1167 int U = -(128 << 23); // 19
1168 int V = -(128 << 23);
1171 for (j = 0; j < lumFilterSize; j++) {
1172 Y += lumSrc[j][i] * (unsigned)lumFilter[j];
1174 for (j = 0; j < chrFilterSize; j++) {;
1175 U += chrUSrc[j][i] * (unsigned)chrFilter[j];
1176 V += chrVSrc[j][i] * (unsigned)chrFilter[j];
1181 for (j = 0; j < lumFilterSize; j++) {
1182 A += alpSrc[j][i] * (unsigned)lumFilter[j];
1188 // 8bit: 12+15=27; 16-bit: 12+19=31
1194 // 8bit: 27 -> 17bit, 16bit: 31 - 14 = 17bit
1195 Y -= c->yuv2rgb_y_offset;
1196 Y *= c->yuv2rgb_y_coeff;
1198 // 8bit: 17 + 13bit = 30bit, 16bit: 17 + 13bit = 30bit
1200 R = V * c->yuv2rgb_v2r_coeff;
1201 G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
1202 B = U * c->yuv2rgb_u2b_coeff;
1204 // 8bit: 30 - 22 = 8bit, 16bit: 30bit - 14 = 16bit
1205 output_pixel(&dest[0], av_clip_uintp2(R_B + Y, 30) >> 14);
1206 output_pixel(&dest[1], av_clip_uintp2( G + Y, 30) >> 14);
1207 output_pixel(&dest[2], av_clip_uintp2(B_R + Y, 30) >> 14);
1209 output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
1217 static av_always_inline void
1218 yuv2rgba64_full_2_c_template(SwsContext *c, const int32_t *buf[2],
1219 const int32_t *ubuf[2], const int32_t *vbuf[2],
1220 const int32_t *abuf[2], uint16_t *dest, int dstW,
1221 int yalpha, int uvalpha, int y,
1222 enum AVPixelFormat target, int hasAlpha, int eightbytes)
1224 const int32_t *buf0 = buf[0], *buf1 = buf[1],
1225 *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
1226 *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
1227 *abuf0 = hasAlpha ? abuf[0] : NULL,
1228 *abuf1 = hasAlpha ? abuf[1] : NULL;
1229 int yalpha1 = 4096 - yalpha;
1230 int uvalpha1 = 4096 - uvalpha;
1234 av_assert2(yalpha <= 4096U);
1235 av_assert2(uvalpha <= 4096U);
1237 for (i = 0; i < dstW; i++) {
1238 int Y = (buf0[i] * yalpha1 + buf1[i] * yalpha) >> 14;
1239 int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha - (128 << 23)) >> 14;
1240 int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha - (128 << 23)) >> 14;
1243 Y -= c->yuv2rgb_y_offset;
1244 Y *= c->yuv2rgb_y_coeff;
1247 R = V * c->yuv2rgb_v2r_coeff;
1248 G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
1249 B = U * c->yuv2rgb_u2b_coeff;
1252 A = (abuf0[i] * yalpha1 + abuf1[i] * yalpha) >> 1;
1257 output_pixel(&dest[0], av_clip_uintp2(R_B + Y, 30) >> 14);
1258 output_pixel(&dest[1], av_clip_uintp2( G + Y, 30) >> 14);
1259 output_pixel(&dest[2], av_clip_uintp2(B_R + Y, 30) >> 14);
1261 output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
1269 static av_always_inline void
1270 yuv2rgba64_full_1_c_template(SwsContext *c, const int32_t *buf0,
1271 const int32_t *ubuf[2], const int32_t *vbuf[2],
1272 const int32_t *abuf0, uint16_t *dest, int dstW,
1273 int uvalpha, int y, enum AVPixelFormat target, int hasAlpha, int eightbytes)
1275 const int32_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
1279 if (uvalpha < 2048) {
1280 for (i = 0; i < dstW; i++) {
1281 int Y = (buf0[i]) >> 2;
1282 int U = (ubuf0[i] - (128 << 11)) >> 2;
1283 int V = (vbuf0[i] - (128 << 11)) >> 2;
1286 Y -= c->yuv2rgb_y_offset;
1287 Y *= c->yuv2rgb_y_coeff;
1296 R = V * c->yuv2rgb_v2r_coeff;
1297 G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
1298 B = U * c->yuv2rgb_u2b_coeff;
1300 output_pixel(&dest[0], av_clip_uintp2(R_B + Y, 30) >> 14);
1301 output_pixel(&dest[1], av_clip_uintp2( G + Y, 30) >> 14);
1302 output_pixel(&dest[2], av_clip_uintp2(B_R + Y, 30) >> 14);
1304 output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
1311 const int32_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
1313 for (i = 0; i < dstW; i++) {
1314 int Y = (buf0[i] ) >> 2;
1315 int U = (ubuf0[i] + ubuf1[i] - (128 << 12)) >> 3;
1316 int V = (vbuf0[i] + vbuf1[i] - (128 << 12)) >> 3;
1319 Y -= c->yuv2rgb_y_offset;
1320 Y *= c->yuv2rgb_y_coeff;
1329 R = V * c->yuv2rgb_v2r_coeff;
1330 G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
1331 B = U * c->yuv2rgb_u2b_coeff;
1333 output_pixel(&dest[0], av_clip_uintp2(R_B + Y, 30) >> 14);
1334 output_pixel(&dest[1], av_clip_uintp2( G + Y, 30) >> 14);
1335 output_pixel(&dest[2], av_clip_uintp2(B_R + Y, 30) >> 14);
1337 output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
1350 #define YUV2PACKED16WRAPPER(name, base, ext, fmt, hasAlpha, eightbytes) \
1351 static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \
1352 const int16_t **_lumSrc, int lumFilterSize, \
1353 const int16_t *chrFilter, const int16_t **_chrUSrc, \
1354 const int16_t **_chrVSrc, int chrFilterSize, \
1355 const int16_t **_alpSrc, uint8_t *_dest, int dstW, \
1358 const int32_t **lumSrc = (const int32_t **) _lumSrc, \
1359 **chrUSrc = (const int32_t **) _chrUSrc, \
1360 **chrVSrc = (const int32_t **) _chrVSrc, \
1361 **alpSrc = (const int32_t **) _alpSrc; \
1362 uint16_t *dest = (uint16_t *) _dest; \
1363 name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
1364 chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
1365 alpSrc, dest, dstW, y, fmt, hasAlpha, eightbytes); \
1368 static void name ## ext ## _2_c(SwsContext *c, const int16_t *_buf[2], \
1369 const int16_t *_ubuf[2], const int16_t *_vbuf[2], \
1370 const int16_t *_abuf[2], uint8_t *_dest, int dstW, \
1371 int yalpha, int uvalpha, int y) \
1373 const int32_t **buf = (const int32_t **) _buf, \
1374 **ubuf = (const int32_t **) _ubuf, \
1375 **vbuf = (const int32_t **) _vbuf, \
1376 **abuf = (const int32_t **) _abuf; \
1377 uint16_t *dest = (uint16_t *) _dest; \
1378 name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
1379 dest, dstW, yalpha, uvalpha, y, fmt, hasAlpha, eightbytes); \
1382 static void name ## ext ## _1_c(SwsContext *c, const int16_t *_buf0, \
1383 const int16_t *_ubuf[2], const int16_t *_vbuf[2], \
1384 const int16_t *_abuf0, uint8_t *_dest, int dstW, \
1385 int uvalpha, int y) \
1387 const int32_t *buf0 = (const int32_t *) _buf0, \
1388 **ubuf = (const int32_t **) _ubuf, \
1389 **vbuf = (const int32_t **) _vbuf, \
1390 *abuf0 = (const int32_t *) _abuf0; \
1391 uint16_t *dest = (uint16_t *) _dest; \
1392 name ## base ## _1_c_template(c, buf0, ubuf, vbuf, abuf0, dest, \
1393 dstW, uvalpha, y, fmt, hasAlpha, eightbytes); \
1396 YUV2PACKED16WRAPPER(yuv2, rgba64, rgb48be, AV_PIX_FMT_RGB48BE, 0, 0)
1397 YUV2PACKED16WRAPPER(yuv2, rgba64, rgb48le, AV_PIX_FMT_RGB48LE, 0, 0)
1398 YUV2PACKED16WRAPPER(yuv2, rgba64, bgr48be, AV_PIX_FMT_BGR48BE, 0, 0)
1399 YUV2PACKED16WRAPPER(yuv2, rgba64, bgr48le, AV_PIX_FMT_BGR48LE, 0, 0)
1400 YUV2PACKED16WRAPPER(yuv2, rgba64, rgba64be, AV_PIX_FMT_RGBA64BE, 1, 1)
1401 YUV2PACKED16WRAPPER(yuv2, rgba64, rgba64le, AV_PIX_FMT_RGBA64LE, 1, 1)
1402 YUV2PACKED16WRAPPER(yuv2, rgba64, rgbx64be, AV_PIX_FMT_RGBA64BE, 0, 1)
1403 YUV2PACKED16WRAPPER(yuv2, rgba64, rgbx64le, AV_PIX_FMT_RGBA64LE, 0, 1)
1404 YUV2PACKED16WRAPPER(yuv2, rgba64, bgra64be, AV_PIX_FMT_BGRA64BE, 1, 1)
1405 YUV2PACKED16WRAPPER(yuv2, rgba64, bgra64le, AV_PIX_FMT_BGRA64LE, 1, 1)
1406 YUV2PACKED16WRAPPER(yuv2, rgba64, bgrx64be, AV_PIX_FMT_BGRA64BE, 0, 1)
1407 YUV2PACKED16WRAPPER(yuv2, rgba64, bgrx64le, AV_PIX_FMT_BGRA64LE, 0, 1)
1409 YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgb48be_full, AV_PIX_FMT_RGB48BE, 0, 0)
1410 YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgb48le_full, AV_PIX_FMT_RGB48LE, 0, 0)
1411 YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgr48be_full, AV_PIX_FMT_BGR48BE, 0, 0)
1412 YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgr48le_full, AV_PIX_FMT_BGR48LE, 0, 0)
1413 YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgba64be_full, AV_PIX_FMT_RGBA64BE, 1, 1)
1414 YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgba64le_full, AV_PIX_FMT_RGBA64LE, 1, 1)
1415 YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgbx64be_full, AV_PIX_FMT_RGBA64BE, 0, 1)
1416 YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgbx64le_full, AV_PIX_FMT_RGBA64LE, 0, 1)
1417 YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgra64be_full, AV_PIX_FMT_BGRA64BE, 1, 1)
1418 YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgra64le_full, AV_PIX_FMT_BGRA64LE, 1, 1)
1419 YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgrx64be_full, AV_PIX_FMT_BGRA64BE, 0, 1)
1420 YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgrx64le_full, AV_PIX_FMT_BGRA64LE, 0, 1)
1423 * Write out 2 RGB pixels in the target pixel format. This function takes a
1424 * R/G/B LUT as generated by ff_yuv2rgb_c_init_tables(), which takes care of
1425 * things like endianness conversion and shifting. The caller takes care of
1426 * setting the correct offset in these tables from the chroma (U/V) values.
1427 * This function then uses the luminance (Y1/Y2) values to write out the
1428 * correct RGB values into the destination buffer.
1430 static av_always_inline void
1431 yuv2rgb_write(uint8_t *_dest, int i, int Y1, int Y2,
1432 unsigned A1, unsigned A2,
1433 const void *_r, const void *_g, const void *_b, int y,
1434 enum AVPixelFormat target, int hasAlpha)
1436 if (target == AV_PIX_FMT_ARGB || target == AV_PIX_FMT_RGBA ||
1437 target == AV_PIX_FMT_ABGR || target == AV_PIX_FMT_BGRA) {
1438 uint32_t *dest = (uint32_t *) _dest;
1439 const uint32_t *r = (const uint32_t *) _r;
1440 const uint32_t *g = (const uint32_t *) _g;
1441 const uint32_t *b = (const uint32_t *) _b;
1444 int sh = hasAlpha ? ((target == AV_PIX_FMT_RGB32_1 || target == AV_PIX_FMT_BGR32_1) ? 0 : 24) : 0;
1446 dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1] + (hasAlpha ? A1 << sh : 0);
1447 dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2] + (hasAlpha ? A2 << sh : 0);
1450 int sh = (target == AV_PIX_FMT_RGB32_1 || target == AV_PIX_FMT_BGR32_1) ? 0 : 24;
1452 av_assert2((((r[Y1] + g[Y1] + b[Y1]) >> sh) & 0xFF) == 0);
1453 dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1] + (A1 << sh);
1454 dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2] + (A2 << sh);
1456 #if defined(ASSERT_LEVEL) && ASSERT_LEVEL > 1
1457 int sh = (target == AV_PIX_FMT_RGB32_1 || target == AV_PIX_FMT_BGR32_1) ? 0 : 24;
1459 av_assert2((((r[Y1] + g[Y1] + b[Y1]) >> sh) & 0xFF) == 0xFF);
1461 dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1];
1462 dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2];
1465 } else if (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) {
1466 uint8_t *dest = (uint8_t *) _dest;
1467 const uint8_t *r = (const uint8_t *) _r;
1468 const uint8_t *g = (const uint8_t *) _g;
1469 const uint8_t *b = (const uint8_t *) _b;
1471 #define r_b ((target == AV_PIX_FMT_RGB24) ? r : b)
1472 #define b_r ((target == AV_PIX_FMT_RGB24) ? b : r)
1474 dest[i * 6 + 0] = r_b[Y1];
1475 dest[i * 6 + 1] = g[Y1];
1476 dest[i * 6 + 2] = b_r[Y1];
1477 dest[i * 6 + 3] = r_b[Y2];
1478 dest[i * 6 + 4] = g[Y2];
1479 dest[i * 6 + 5] = b_r[Y2];
1482 } else if (target == AV_PIX_FMT_RGB565 || target == AV_PIX_FMT_BGR565 ||
1483 target == AV_PIX_FMT_RGB555 || target == AV_PIX_FMT_BGR555 ||
1484 target == AV_PIX_FMT_RGB444 || target == AV_PIX_FMT_BGR444) {
1485 uint16_t *dest = (uint16_t *) _dest;
1486 const uint16_t *r = (const uint16_t *) _r;
1487 const uint16_t *g = (const uint16_t *) _g;
1488 const uint16_t *b = (const uint16_t *) _b;
1489 int dr1, dg1, db1, dr2, dg2, db2;
1491 if (target == AV_PIX_FMT_RGB565 || target == AV_PIX_FMT_BGR565) {
1492 dr1 = ff_dither_2x2_8[ y & 1 ][0];
1493 dg1 = ff_dither_2x2_4[ y & 1 ][0];
1494 db1 = ff_dither_2x2_8[(y & 1) ^ 1][0];
1495 dr2 = ff_dither_2x2_8[ y & 1 ][1];
1496 dg2 = ff_dither_2x2_4[ y & 1 ][1];
1497 db2 = ff_dither_2x2_8[(y & 1) ^ 1][1];
1498 } else if (target == AV_PIX_FMT_RGB555 || target == AV_PIX_FMT_BGR555) {
1499 dr1 = ff_dither_2x2_8[ y & 1 ][0];
1500 dg1 = ff_dither_2x2_8[ y & 1 ][1];
1501 db1 = ff_dither_2x2_8[(y & 1) ^ 1][0];
1502 dr2 = ff_dither_2x2_8[ y & 1 ][1];
1503 dg2 = ff_dither_2x2_8[ y & 1 ][0];
1504 db2 = ff_dither_2x2_8[(y & 1) ^ 1][1];
1506 dr1 = ff_dither_4x4_16[ y & 3 ][0];
1507 dg1 = ff_dither_4x4_16[ y & 3 ][1];
1508 db1 = ff_dither_4x4_16[(y & 3) ^ 3][0];
1509 dr2 = ff_dither_4x4_16[ y & 3 ][1];
1510 dg2 = ff_dither_4x4_16[ y & 3 ][0];
1511 db2 = ff_dither_4x4_16[(y & 3) ^ 3][1];
1514 dest[i * 2 + 0] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1];
1515 dest[i * 2 + 1] = r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2];
1516 } else /* 8/4 bits */ {
1517 uint8_t *dest = (uint8_t *) _dest;
1518 const uint8_t *r = (const uint8_t *) _r;
1519 const uint8_t *g = (const uint8_t *) _g;
1520 const uint8_t *b = (const uint8_t *) _b;
1521 int dr1, dg1, db1, dr2, dg2, db2;
1523 if (target == AV_PIX_FMT_RGB8 || target == AV_PIX_FMT_BGR8) {
1524 const uint8_t * const d64 = ff_dither_8x8_73[y & 7];
1525 const uint8_t * const d32 = ff_dither_8x8_32[y & 7];
1526 dr1 = dg1 = d32[(i * 2 + 0) & 7];
1527 db1 = d64[(i * 2 + 0) & 7];
1528 dr2 = dg2 = d32[(i * 2 + 1) & 7];
1529 db2 = d64[(i * 2 + 1) & 7];
1531 const uint8_t * const d64 = ff_dither_8x8_73 [y & 7];
1532 const uint8_t * const d128 = ff_dither_8x8_220[y & 7];
1533 dr1 = db1 = d128[(i * 2 + 0) & 7];
1534 dg1 = d64[(i * 2 + 0) & 7];
1535 dr2 = db2 = d128[(i * 2 + 1) & 7];
1536 dg2 = d64[(i * 2 + 1) & 7];
1539 if (target == AV_PIX_FMT_RGB4 || target == AV_PIX_FMT_BGR4) {
1540 dest[i] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1] +
1541 ((r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2]) << 4);
1543 dest[i * 2 + 0] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1];
1544 dest[i * 2 + 1] = r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2];
1549 static av_always_inline void
1550 yuv2rgb_X_c_template(SwsContext *c, const int16_t *lumFilter,
1551 const int16_t **lumSrc, int lumFilterSize,
1552 const int16_t *chrFilter, const int16_t **chrUSrc,
1553 const int16_t **chrVSrc, int chrFilterSize,
1554 const int16_t **alpSrc, uint8_t *dest, int dstW,
1555 int y, enum AVPixelFormat target, int hasAlpha)
1559 for (i = 0; i < ((dstW + 1) >> 1); i++) {
1565 const void *r, *g, *b;
1567 for (j = 0; j < lumFilterSize; j++) {
1568 Y1 += lumSrc[j][i * 2] * lumFilter[j];
1569 Y2 += lumSrc[j][i * 2 + 1] * lumFilter[j];
1571 for (j = 0; j < chrFilterSize; j++) {
1572 U += chrUSrc[j][i] * chrFilter[j];
1573 V += chrVSrc[j][i] * chrFilter[j];
1582 for (j = 0; j < lumFilterSize; j++) {
1583 A1 += alpSrc[j][i * 2 ] * lumFilter[j];
1584 A2 += alpSrc[j][i * 2 + 1] * lumFilter[j];
1588 if ((A1 | A2) & 0x100) {
1589 A1 = av_clip_uint8(A1);
1590 A2 = av_clip_uint8(A2);
1594 r = c->table_rV[V + YUVRGB_TABLE_HEADROOM];
1595 g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]);
1596 b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
1598 yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
1599 r, g, b, y, target, hasAlpha);
1603 static av_always_inline void
1604 yuv2rgb_2_c_template(SwsContext *c, const int16_t *buf[2],
1605 const int16_t *ubuf[2], const int16_t *vbuf[2],
1606 const int16_t *abuf[2], uint8_t *dest, int dstW,
1607 int yalpha, int uvalpha, int y,
1608 enum AVPixelFormat target, int hasAlpha)
1610 const int16_t *buf0 = buf[0], *buf1 = buf[1],
1611 *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
1612 *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
1613 *abuf0 = hasAlpha ? abuf[0] : NULL,
1614 *abuf1 = hasAlpha ? abuf[1] : NULL;
1615 int yalpha1 = 4096 - yalpha;
1616 int uvalpha1 = 4096 - uvalpha;
1618 av_assert2(yalpha <= 4096U);
1619 av_assert2(uvalpha <= 4096U);
1621 for (i = 0; i < ((dstW + 1) >> 1); i++) {
1622 int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 19;
1623 int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 19;
1624 int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha) >> 19;
1625 int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha) >> 19;
1627 const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM],
1628 *g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]),
1629 *b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
1632 A1 = (abuf0[i * 2 ] * yalpha1 + abuf1[i * 2 ] * yalpha) >> 19;
1633 A2 = (abuf0[i * 2 + 1] * yalpha1 + abuf1[i * 2 + 1] * yalpha) >> 19;
1634 A1 = av_clip_uint8(A1);
1635 A2 = av_clip_uint8(A2);
1638 yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
1639 r, g, b, y, target, hasAlpha);
1643 static av_always_inline void
1644 yuv2rgb_1_c_template(SwsContext *c, const int16_t *buf0,
1645 const int16_t *ubuf[2], const int16_t *vbuf[2],
1646 const int16_t *abuf0, uint8_t *dest, int dstW,
1647 int uvalpha, int y, enum AVPixelFormat target,
1650 const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
1653 if (uvalpha < 2048) {
1654 for (i = 0; i < ((dstW + 1) >> 1); i++) {
1655 int Y1 = (buf0[i * 2 ] + 64) >> 7;
1656 int Y2 = (buf0[i * 2 + 1] + 64) >> 7;
1657 int U = (ubuf0[i] + 64) >> 7;
1658 int V = (vbuf0[i] + 64) >> 7;
1660 const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM],
1661 *g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]),
1662 *b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
1665 A1 = abuf0[i * 2 ] * 255 + 16384 >> 15;
1666 A2 = abuf0[i * 2 + 1] * 255 + 16384 >> 15;
1667 A1 = av_clip_uint8(A1);
1668 A2 = av_clip_uint8(A2);
1671 yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
1672 r, g, b, y, target, hasAlpha);
1675 const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
1676 for (i = 0; i < ((dstW + 1) >> 1); i++) {
1677 int Y1 = (buf0[i * 2 ] + 64) >> 7;
1678 int Y2 = (buf0[i * 2 + 1] + 64) >> 7;
1679 int U = (ubuf0[i] + ubuf1[i] + 128) >> 8;
1680 int V = (vbuf0[i] + vbuf1[i] + 128) >> 8;
1682 const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM],
1683 *g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]),
1684 *b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
1687 A1 = (abuf0[i * 2 ] + 64) >> 7;
1688 A2 = (abuf0[i * 2 + 1] + 64) >> 7;
1689 A1 = av_clip_uint8(A1);
1690 A2 = av_clip_uint8(A2);
1693 yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
1694 r, g, b, y, target, hasAlpha);
1699 #define YUV2RGBWRAPPERX(name, base, ext, fmt, hasAlpha) \
1700 static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \
1701 const int16_t **lumSrc, int lumFilterSize, \
1702 const int16_t *chrFilter, const int16_t **chrUSrc, \
1703 const int16_t **chrVSrc, int chrFilterSize, \
1704 const int16_t **alpSrc, uint8_t *dest, int dstW, \
1707 name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
1708 chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
1709 alpSrc, dest, dstW, y, fmt, hasAlpha); \
1712 #define YUV2RGBWRAPPERX2(name, base, ext, fmt, hasAlpha) \
1713 YUV2RGBWRAPPERX(name, base, ext, fmt, hasAlpha) \
1714 static void name ## ext ## _2_c(SwsContext *c, const int16_t *buf[2], \
1715 const int16_t *ubuf[2], const int16_t *vbuf[2], \
1716 const int16_t *abuf[2], uint8_t *dest, int dstW, \
1717 int yalpha, int uvalpha, int y) \
1719 name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
1720 dest, dstW, yalpha, uvalpha, y, fmt, hasAlpha); \
1723 #define YUV2RGBWRAPPER(name, base, ext, fmt, hasAlpha) \
1724 YUV2RGBWRAPPERX2(name, base, ext, fmt, hasAlpha) \
1725 static void name ## ext ## _1_c(SwsContext *c, const int16_t *buf0, \
1726 const int16_t *ubuf[2], const int16_t *vbuf[2], \
1727 const int16_t *abuf0, uint8_t *dest, int dstW, \
1728 int uvalpha, int y) \
1730 name ## base ## _1_c_template(c, buf0, ubuf, vbuf, abuf0, dest, \
1731 dstW, uvalpha, y, fmt, hasAlpha); \
1735 YUV2RGBWRAPPER(yuv2rgb,, 32_1, AV_PIX_FMT_RGB32_1, CONFIG_SWSCALE_ALPHA && c->needAlpha)
1736 YUV2RGBWRAPPER(yuv2rgb,, 32, AV_PIX_FMT_RGB32, CONFIG_SWSCALE_ALPHA && c->needAlpha)
1738 #if CONFIG_SWSCALE_ALPHA
1739 YUV2RGBWRAPPER(yuv2rgb,, a32_1, AV_PIX_FMT_RGB32_1, 1)
1740 YUV2RGBWRAPPER(yuv2rgb,, a32, AV_PIX_FMT_RGB32, 1)
1742 YUV2RGBWRAPPER(yuv2rgb,, x32_1, AV_PIX_FMT_RGB32_1, 0)
1743 YUV2RGBWRAPPER(yuv2rgb,, x32, AV_PIX_FMT_RGB32, 0)
1745 YUV2RGBWRAPPER(yuv2, rgb, rgb24, AV_PIX_FMT_RGB24, 0)
1746 YUV2RGBWRAPPER(yuv2, rgb, bgr24, AV_PIX_FMT_BGR24, 0)
1747 YUV2RGBWRAPPER(yuv2rgb,, 16, AV_PIX_FMT_RGB565, 0)
1748 YUV2RGBWRAPPER(yuv2rgb,, 15, AV_PIX_FMT_RGB555, 0)
1749 YUV2RGBWRAPPER(yuv2rgb,, 12, AV_PIX_FMT_RGB444, 0)
1750 YUV2RGBWRAPPER(yuv2rgb,, 8, AV_PIX_FMT_RGB8, 0)
1751 YUV2RGBWRAPPER(yuv2rgb,, 4, AV_PIX_FMT_RGB4, 0)
1752 YUV2RGBWRAPPER(yuv2rgb,, 4b, AV_PIX_FMT_RGB4_BYTE, 0)
1754 static av_always_inline void yuv2rgb_write_full(SwsContext *c,
1755 uint8_t *dest, int i, int Y, int A, int U, int V,
1756 int y, enum AVPixelFormat target, int hasAlpha, int err[4])
1759 int isrgb8 = target == AV_PIX_FMT_BGR8 || target == AV_PIX_FMT_RGB8;
1761 Y -= c->yuv2rgb_y_offset;
1762 Y *= c->yuv2rgb_y_coeff;
1764 R = Y + V*c->yuv2rgb_v2r_coeff;
1765 G = Y + V*c->yuv2rgb_v2g_coeff + U*c->yuv2rgb_u2g_coeff;
1766 B = Y + U*c->yuv2rgb_u2b_coeff;
1767 if ((R | G | B) & 0xC0000000) {
1768 R = av_clip_uintp2(R, 30);
1769 G = av_clip_uintp2(G, 30);
1770 B = av_clip_uintp2(B, 30);
1774 case AV_PIX_FMT_ARGB:
1775 dest[0] = hasAlpha ? A : 255;
1780 case AV_PIX_FMT_RGB24:
1785 case AV_PIX_FMT_RGBA:
1789 dest[3] = hasAlpha ? A : 255;
1791 case AV_PIX_FMT_ABGR:
1792 dest[0] = hasAlpha ? A : 255;
1797 case AV_PIX_FMT_BGR24:
1802 case AV_PIX_FMT_BGRA:
1806 dest[3] = hasAlpha ? A : 255;
1808 case AV_PIX_FMT_BGR4_BYTE:
1809 case AV_PIX_FMT_RGB4_BYTE:
1810 case AV_PIX_FMT_BGR8:
1811 case AV_PIX_FMT_RGB8:
1815 switch (c->dither) {
1817 case SWS_DITHER_AUTO:
1822 R += (7*err[0] + 1*c->dither_error[0][i] + 5*c->dither_error[0][i+1] + 3*c->dither_error[0][i+2])>>4;
1823 G += (7*err[1] + 1*c->dither_error[1][i] + 5*c->dither_error[1][i+1] + 3*c->dither_error[1][i+2])>>4;
1824 B += (7*err[2] + 1*c->dither_error[2][i] + 5*c->dither_error[2][i+1] + 3*c->dither_error[2][i+2])>>4;
1825 c->dither_error[0][i] = err[0];
1826 c->dither_error[1][i] = err[1];
1827 c->dither_error[2][i] = err[2];
1828 r = R >> (isrgb8 ? 5 : 7);
1829 g = G >> (isrgb8 ? 5 : 6);
1830 b = B >> (isrgb8 ? 6 : 7);
1831 r = av_clip(r, 0, isrgb8 ? 7 : 1);
1832 g = av_clip(g, 0, isrgb8 ? 7 : 3);
1833 b = av_clip(b, 0, isrgb8 ? 3 : 1);
1834 err[0] = R - r*(isrgb8 ? 36 : 255);
1835 err[1] = G - g*(isrgb8 ? 36 : 85);
1836 err[2] = B - b*(isrgb8 ? 85 : 255);
1838 case SWS_DITHER_A_DITHER:
1840 /* see http://pippin.gimp.org/a_dither/ for details/origin */
1841 #define A_DITHER(u,v) (((((u)+((v)*236))*119)&0xff))
1842 r = (((R >> 19) + A_DITHER(i,y) -96)>>8);
1843 g = (((G >> 19) + A_DITHER(i + 17,y) - 96)>>8);
1844 b = (((B >> 20) + A_DITHER(i + 17*2,y) -96)>>8);
1845 r = av_clip_uintp2(r, 3);
1846 g = av_clip_uintp2(g, 3);
1847 b = av_clip_uintp2(b, 2);
1849 r = (((R >> 21) + A_DITHER(i,y)-256)>>8);
1850 g = (((G >> 19) + A_DITHER(i + 17,y)-256)>>8);
1851 b = (((B >> 21) + A_DITHER(i + 17*2,y)-256)>>8);
1852 r = av_clip_uintp2(r, 1);
1853 g = av_clip_uintp2(g, 2);
1854 b = av_clip_uintp2(b, 1);
1857 case SWS_DITHER_X_DITHER:
1859 /* see http://pippin.gimp.org/a_dither/ for details/origin */
1860 #define X_DITHER(u,v) (((((u)^((v)*237))*181)&0x1ff)/2)
1861 r = (((R >> 19) + X_DITHER(i,y) - 96)>>8);
1862 g = (((G >> 19) + X_DITHER(i + 17,y) - 96)>>8);
1863 b = (((B >> 20) + X_DITHER(i + 17*2,y) - 96)>>8);
1864 r = av_clip_uintp2(r, 3);
1865 g = av_clip_uintp2(g, 3);
1866 b = av_clip_uintp2(b, 2);
1868 r = (((R >> 21) + X_DITHER(i,y)-256)>>8);
1869 g = (((G >> 19) + X_DITHER(i + 17,y)-256)>>8);
1870 b = (((B >> 21) + X_DITHER(i + 17*2,y)-256)>>8);
1871 r = av_clip_uintp2(r, 1);
1872 g = av_clip_uintp2(g, 2);
1873 b = av_clip_uintp2(b, 1);
1879 if(target == AV_PIX_FMT_BGR4_BYTE) {
1880 dest[0] = r + 2*g + 8*b;
1881 } else if(target == AV_PIX_FMT_RGB4_BYTE) {
1882 dest[0] = b + 2*g + 8*r;
1883 } else if(target == AV_PIX_FMT_BGR8) {
1884 dest[0] = r + 8*g + 64*b;
1885 } else if(target == AV_PIX_FMT_RGB8) {
1886 dest[0] = b + 4*g + 32*r;
1893 static av_always_inline void
1894 yuv2rgb_full_X_c_template(SwsContext *c, const int16_t *lumFilter,
1895 const int16_t **lumSrc, int lumFilterSize,
1896 const int16_t *chrFilter, const int16_t **chrUSrc,
1897 const int16_t **chrVSrc, int chrFilterSize,
1898 const int16_t **alpSrc, uint8_t *dest,
1899 int dstW, int y, enum AVPixelFormat target, int hasAlpha)
1902 int step = (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) ? 3 : 4;
1904 int A = 0; //init to silence warning
1906 if( target == AV_PIX_FMT_BGR4_BYTE || target == AV_PIX_FMT_RGB4_BYTE
1907 || target == AV_PIX_FMT_BGR8 || target == AV_PIX_FMT_RGB8)
1910 for (i = 0; i < dstW; i++) {
1913 int U = (1<<9)-(128 << 19);
1914 int V = (1<<9)-(128 << 19);
1916 for (j = 0; j < lumFilterSize; j++) {
1917 Y += lumSrc[j][i] * lumFilter[j];
1919 for (j = 0; j < chrFilterSize; j++) {
1920 U += chrUSrc[j][i] * chrFilter[j];
1921 V += chrVSrc[j][i] * chrFilter[j];
1928 for (j = 0; j < lumFilterSize; j++) {
1929 A += alpSrc[j][i] * lumFilter[j];
1933 A = av_clip_uint8(A);
1935 yuv2rgb_write_full(c, dest, i, Y, A, U, V, y, target, hasAlpha, err);
1938 c->dither_error[0][i] = err[0];
1939 c->dither_error[1][i] = err[1];
1940 c->dither_error[2][i] = err[2];
1943 static av_always_inline void
1944 yuv2rgb_full_2_c_template(SwsContext *c, const int16_t *buf[2],
1945 const int16_t *ubuf[2], const int16_t *vbuf[2],
1946 const int16_t *abuf[2], uint8_t *dest, int dstW,
1947 int yalpha, int uvalpha, int y,
1948 enum AVPixelFormat target, int hasAlpha)
1950 const int16_t *buf0 = buf[0], *buf1 = buf[1],
1951 *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
1952 *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
1953 *abuf0 = hasAlpha ? abuf[0] : NULL,
1954 *abuf1 = hasAlpha ? abuf[1] : NULL;
1955 int yalpha1 = 4096 - yalpha;
1956 int uvalpha1 = 4096 - uvalpha;
1958 int step = (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) ? 3 : 4;
1960 int A = 0; // init to silcene warning
1962 av_assert2(yalpha <= 4096U);
1963 av_assert2(uvalpha <= 4096U);
1965 if( target == AV_PIX_FMT_BGR4_BYTE || target == AV_PIX_FMT_RGB4_BYTE
1966 || target == AV_PIX_FMT_BGR8 || target == AV_PIX_FMT_RGB8)
1969 for (i = 0; i < dstW; i++) {
1970 int Y = ( buf0[i] * yalpha1 + buf1[i] * yalpha ) >> 10; //FIXME rounding
1971 int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha-(128 << 19)) >> 10;
1972 int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha-(128 << 19)) >> 10;
1975 A = (abuf0[i] * yalpha1 + abuf1[i] * yalpha + (1<<18)) >> 19;
1977 A = av_clip_uint8(A);
1980 yuv2rgb_write_full(c, dest, i, Y, A, U, V, y, target, hasAlpha, err);
1983 c->dither_error[0][i] = err[0];
1984 c->dither_error[1][i] = err[1];
1985 c->dither_error[2][i] = err[2];
1988 static av_always_inline void
1989 yuv2rgb_full_1_c_template(SwsContext *c, const int16_t *buf0,
1990 const int16_t *ubuf[2], const int16_t *vbuf[2],
1991 const int16_t *abuf0, uint8_t *dest, int dstW,
1992 int uvalpha, int y, enum AVPixelFormat target,
1995 const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
1997 int step = (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) ? 3 : 4;
2000 if( target == AV_PIX_FMT_BGR4_BYTE || target == AV_PIX_FMT_RGB4_BYTE
2001 || target == AV_PIX_FMT_BGR8 || target == AV_PIX_FMT_RGB8)
2004 if (uvalpha < 2048) {
2005 int A = 0; //init to silence warning
2006 for (i = 0; i < dstW; i++) {
2007 int Y = buf0[i] << 2;
2008 int U = (ubuf0[i] - (128<<7)) * 4;
2009 int V = (vbuf0[i] - (128<<7)) * 4;
2012 A = (abuf0[i] + 64) >> 7;
2014 A = av_clip_uint8(A);
2017 yuv2rgb_write_full(c, dest, i, Y, A, U, V, y, target, hasAlpha, err);
2021 const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
2022 int A = 0; //init to silence warning
2023 for (i = 0; i < dstW; i++) {
2024 int Y = buf0[i] << 2;
2025 int U = (ubuf0[i] + ubuf1[i] - (128<<8)) << 1;
2026 int V = (vbuf0[i] + vbuf1[i] - (128<<8)) << 1;
2029 A = (abuf0[i] + 64) >> 7;
2031 A = av_clip_uint8(A);
2034 yuv2rgb_write_full(c, dest, i, Y, A, U, V, y, target, hasAlpha, err);
2039 c->dither_error[0][i] = err[0];
2040 c->dither_error[1][i] = err[1];
2041 c->dither_error[2][i] = err[2];
2045 YUV2RGBWRAPPER(yuv2, rgb_full, bgra32_full, AV_PIX_FMT_BGRA, CONFIG_SWSCALE_ALPHA && c->needAlpha)
2046 YUV2RGBWRAPPER(yuv2, rgb_full, abgr32_full, AV_PIX_FMT_ABGR, CONFIG_SWSCALE_ALPHA && c->needAlpha)
2047 YUV2RGBWRAPPER(yuv2, rgb_full, rgba32_full, AV_PIX_FMT_RGBA, CONFIG_SWSCALE_ALPHA && c->needAlpha)
2048 YUV2RGBWRAPPER(yuv2, rgb_full, argb32_full, AV_PIX_FMT_ARGB, CONFIG_SWSCALE_ALPHA && c->needAlpha)
2050 #if CONFIG_SWSCALE_ALPHA
2051 YUV2RGBWRAPPER(yuv2, rgb_full, bgra32_full, AV_PIX_FMT_BGRA, 1)
2052 YUV2RGBWRAPPER(yuv2, rgb_full, abgr32_full, AV_PIX_FMT_ABGR, 1)
2053 YUV2RGBWRAPPER(yuv2, rgb_full, rgba32_full, AV_PIX_FMT_RGBA, 1)
2054 YUV2RGBWRAPPER(yuv2, rgb_full, argb32_full, AV_PIX_FMT_ARGB, 1)
2056 YUV2RGBWRAPPER(yuv2, rgb_full, bgrx32_full, AV_PIX_FMT_BGRA, 0)
2057 YUV2RGBWRAPPER(yuv2, rgb_full, xbgr32_full, AV_PIX_FMT_ABGR, 0)
2058 YUV2RGBWRAPPER(yuv2, rgb_full, rgbx32_full, AV_PIX_FMT_RGBA, 0)
2059 YUV2RGBWRAPPER(yuv2, rgb_full, xrgb32_full, AV_PIX_FMT_ARGB, 0)
2061 YUV2RGBWRAPPER(yuv2, rgb_full, bgr24_full, AV_PIX_FMT_BGR24, 0)
2062 YUV2RGBWRAPPER(yuv2, rgb_full, rgb24_full, AV_PIX_FMT_RGB24, 0)
2064 YUV2RGBWRAPPER(yuv2, rgb_full, bgr4_byte_full, AV_PIX_FMT_BGR4_BYTE, 0)
2065 YUV2RGBWRAPPER(yuv2, rgb_full, rgb4_byte_full, AV_PIX_FMT_RGB4_BYTE, 0)
2066 YUV2RGBWRAPPER(yuv2, rgb_full, bgr8_full, AV_PIX_FMT_BGR8, 0)
2067 YUV2RGBWRAPPER(yuv2, rgb_full, rgb8_full, AV_PIX_FMT_RGB8, 0)
2070 yuv2gbrp_full_X_c(SwsContext *c, const int16_t *lumFilter,
2071 const int16_t **lumSrc, int lumFilterSize,
2072 const int16_t *chrFilter, const int16_t **chrUSrc,
2073 const int16_t **chrVSrc, int chrFilterSize,
2074 const int16_t **alpSrc, uint8_t **dest,
2077 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->dstFormat);
2079 int hasAlpha = (desc->flags & AV_PIX_FMT_FLAG_ALPHA) && alpSrc;
2080 uint16_t **dest16 = (uint16_t**)dest;
2081 int SH = 22 + 8 - desc->comp[0].depth;
2082 int A = 0; // init to silence warning
2084 for (i = 0; i < dstW; i++) {
2087 int U = (1 << 9) - (128 << 19);
2088 int V = (1 << 9) - (128 << 19);
2091 for (j = 0; j < lumFilterSize; j++)
2092 Y += lumSrc[j][i] * lumFilter[j];
2094 for (j = 0; j < chrFilterSize; j++) {
2095 U += chrUSrc[j][i] * chrFilter[j];
2096 V += chrVSrc[j][i] * chrFilter[j];
2106 for (j = 0; j < lumFilterSize; j++)
2107 A += alpSrc[j][i] * lumFilter[j];
2110 A = av_clip_uintp2(A, 27);
2113 Y -= c->yuv2rgb_y_offset;
2114 Y *= c->yuv2rgb_y_coeff;
2116 R = Y + V * c->yuv2rgb_v2r_coeff;
2117 G = Y + V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
2118 B = Y + U * c->yuv2rgb_u2b_coeff;
2120 if ((R | G | B) & 0xC0000000) {
2121 R = av_clip_uintp2(R, 30);
2122 G = av_clip_uintp2(G, 30);
2123 B = av_clip_uintp2(B, 30);
2127 dest16[0][i] = G >> SH;
2128 dest16[1][i] = B >> SH;
2129 dest16[2][i] = R >> SH;
2131 dest16[3][i] = A >> (SH - 3);
2133 dest[0][i] = G >> 22;
2134 dest[1][i] = B >> 22;
2135 dest[2][i] = R >> 22;
2137 dest[3][i] = A >> 19;
2140 if (SH != 22 && (!isBE(c->dstFormat)) != (!HAVE_BIGENDIAN)) {
2141 for (i = 0; i < dstW; i++) {
2142 dest16[0][i] = av_bswap16(dest16[0][i]);
2143 dest16[1][i] = av_bswap16(dest16[1][i]);
2144 dest16[2][i] = av_bswap16(dest16[2][i]);
2146 dest16[3][i] = av_bswap16(dest16[3][i]);
2152 yuv2gbrp16_full_X_c(SwsContext *c, const int16_t *lumFilter,
2153 const int16_t **lumSrcx, int lumFilterSize,
2154 const int16_t *chrFilter, const int16_t **chrUSrcx,
2155 const int16_t **chrVSrcx, int chrFilterSize,
2156 const int16_t **alpSrcx, uint8_t **dest,
2159 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->dstFormat);
2161 int hasAlpha = (desc->flags & AV_PIX_FMT_FLAG_ALPHA) && alpSrcx;
2162 uint16_t **dest16 = (uint16_t**)dest;
2163 const int32_t **lumSrc = (const int32_t**)lumSrcx;
2164 const int32_t **chrUSrc = (const int32_t**)chrUSrcx;
2165 const int32_t **chrVSrc = (const int32_t**)chrVSrcx;
2166 const int32_t **alpSrc = (const int32_t**)alpSrcx;
2168 for (i = 0; i < dstW; i++) {
2170 int Y = -0x40000000;
2171 int U = -(128 << 23);
2172 int V = -(128 << 23);
2175 for (j = 0; j < lumFilterSize; j++)
2176 Y += lumSrc[j][i] * (unsigned)lumFilter[j];
2178 for (j = 0; j < chrFilterSize; j++) {
2179 U += chrUSrc[j][i] * (unsigned)chrFilter[j];
2180 V += chrVSrc[j][i] * (unsigned)chrFilter[j];
2191 for (j = 0; j < lumFilterSize; j++)
2192 A += alpSrc[j][i] * lumFilter[j];
2198 Y -= c->yuv2rgb_y_offset;
2199 Y *= c->yuv2rgb_y_coeff;
2201 R = V * c->yuv2rgb_v2r_coeff;
2202 G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
2203 B = U * c->yuv2rgb_u2b_coeff;
2205 R = av_clip_uintp2(Y + R, 30);
2206 G = av_clip_uintp2(Y + G, 30);
2207 B = av_clip_uintp2(Y + B, 30);
2209 dest16[0][i] = G >> 14;
2210 dest16[1][i] = B >> 14;
2211 dest16[2][i] = R >> 14;
2213 dest16[3][i] = av_clip_uintp2(A, 30) >> 14;
2215 if ((!isBE(c->dstFormat)) != (!HAVE_BIGENDIAN)) {
2216 for (i = 0; i < dstW; i++) {
2217 dest16[0][i] = av_bswap16(dest16[0][i]);
2218 dest16[1][i] = av_bswap16(dest16[1][i]);
2219 dest16[2][i] = av_bswap16(dest16[2][i]);
2221 dest16[3][i] = av_bswap16(dest16[3][i]);
2227 yuv2ya8_1_c(SwsContext *c, const int16_t *buf0,
2228 const int16_t *ubuf[2], const int16_t *vbuf[2],
2229 const int16_t *abuf0, uint8_t *dest, int dstW,
2232 int hasAlpha = !!abuf0;
2235 for (i = 0; i < dstW; i++) {
2236 int Y = (buf0[i] + 64) >> 7;
2239 Y = av_clip_uint8(Y);
2242 A = (abuf0[i] + 64) >> 7;
2244 A = av_clip_uint8(A);
2248 dest[i * 2 + 1] = hasAlpha ? A : 255;
2253 yuv2ya8_2_c(SwsContext *c, const int16_t *buf[2],
2254 const int16_t *ubuf[2], const int16_t *vbuf[2],
2255 const int16_t *abuf[2], uint8_t *dest, int dstW,
2256 int yalpha, int uvalpha, int y)
2258 int hasAlpha = abuf && abuf[0] && abuf[1];
2259 const int16_t *buf0 = buf[0], *buf1 = buf[1],
2260 *abuf0 = hasAlpha ? abuf[0] : NULL,
2261 *abuf1 = hasAlpha ? abuf[1] : NULL;
2262 int yalpha1 = 4096 - yalpha;
2265 av_assert2(yalpha <= 4096U);
2267 for (i = 0; i < dstW; i++) {
2268 int Y = (buf0[i] * yalpha1 + buf1[i] * yalpha) >> 19;
2271 Y = av_clip_uint8(Y);
2274 A = (abuf0[i] * yalpha1 + abuf1[i] * yalpha) >> 19;
2275 A = av_clip_uint8(A);
2279 dest[i * 2 + 1] = hasAlpha ? A : 255;
2284 yuv2ya8_X_c(SwsContext *c, const int16_t *lumFilter,
2285 const int16_t **lumSrc, int lumFilterSize,
2286 const int16_t *chrFilter, const int16_t **chrUSrc,
2287 const int16_t **chrVSrc, int chrFilterSize,
2288 const int16_t **alpSrc, uint8_t *dest, int dstW, int y)
2290 int hasAlpha = !!alpSrc;
2293 for (i = 0; i < dstW; i++) {
2295 int Y = 1 << 18, A = 1 << 18;
2297 for (j = 0; j < lumFilterSize; j++)
2298 Y += lumSrc[j][i] * lumFilter[j];
2302 Y = av_clip_uint8(Y);
2305 for (j = 0; j < lumFilterSize; j++)
2306 A += alpSrc[j][i] * lumFilter[j];
2311 A = av_clip_uint8(A);
2315 dest[2 * i + 1] = hasAlpha ? A : 255;
2320 yuv2ayuv64le_X_c(SwsContext *c, const int16_t *lumFilter,
2321 const int16_t **_lumSrc, int lumFilterSize,
2322 const int16_t *chrFilter, const int16_t **_chrUSrc,
2323 const int16_t **_chrVSrc, int chrFilterSize,
2324 const int16_t **_alpSrc, uint8_t *dest, int dstW, int y)
2326 const int32_t **lumSrc = (const int32_t **) _lumSrc,
2327 **chrUSrc = (const int32_t **) _chrUSrc,
2328 **chrVSrc = (const int32_t **) _chrVSrc,
2329 **alpSrc = (const int32_t **) _alpSrc;
2330 int hasAlpha = !!alpSrc;
2333 for (i = 0; i < dstW; i++) {
2334 int Y = 1 << 14, U = 1 << 14;
2335 int V = 1 << 14, A = 1 << 14;
2343 for (j = 0; j < lumFilterSize; j++)
2344 Y += lumSrc[j][i] * (unsigned)lumFilter[j];
2346 for (j = 0; j < chrFilterSize; j++)
2347 U += chrUSrc[j][i] * (unsigned)chrFilter[j];
2349 for (j = 0; j < chrFilterSize; j++)
2350 V += chrVSrc[j][i] * (unsigned)chrFilter[j];
2353 for (j = 0; j < lumFilterSize; j++)
2354 A += alpSrc[j][i] * (unsigned)lumFilter[j];
2356 Y = 0x8000 + av_clip_int16(Y >> 15);
2357 U = 0x8000 + av_clip_int16(U >> 15);
2358 V = 0x8000 + av_clip_int16(V >> 15);
2359 A = 0x8000 + av_clip_int16(A >> 15);
2361 AV_WL16(dest + 8 * i, hasAlpha ? A : 65535);
2362 AV_WL16(dest + 8 * i + 2, Y);
2363 AV_WL16(dest + 8 * i + 4, U);
2364 AV_WL16(dest + 8 * i + 6, V);
2368 av_cold void ff_sws_init_output_funcs(SwsContext *c,
2369 yuv2planar1_fn *yuv2plane1,
2370 yuv2planarX_fn *yuv2planeX,
2371 yuv2interleavedX_fn *yuv2nv12cX,
2372 yuv2packed1_fn *yuv2packed1,
2373 yuv2packed2_fn *yuv2packed2,
2374 yuv2packedX_fn *yuv2packedX,
2375 yuv2anyX_fn *yuv2anyX)
2377 enum AVPixelFormat dstFormat = c->dstFormat;
2378 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(dstFormat);
2380 if (dstFormat == AV_PIX_FMT_P010LE || dstFormat == AV_PIX_FMT_P010BE) {
2381 *yuv2plane1 = isBE(dstFormat) ? yuv2p010l1_BE_c : yuv2p010l1_LE_c;
2382 *yuv2planeX = isBE(dstFormat) ? yuv2p010lX_BE_c : yuv2p010lX_LE_c;
2383 *yuv2nv12cX = yuv2p010cX_c;
2384 } else if (is16BPS(dstFormat)) {
2385 *yuv2planeX = isBE(dstFormat) ? yuv2planeX_16BE_c : yuv2planeX_16LE_c;
2386 *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_16BE_c : yuv2plane1_16LE_c;
2387 if (dstFormat == AV_PIX_FMT_P016LE || dstFormat == AV_PIX_FMT_P016BE) {
2388 *yuv2nv12cX = yuv2p016cX_c;
2390 } else if (isNBPS(dstFormat)) {
2391 if (desc->comp[0].depth == 9) {
2392 *yuv2planeX = isBE(dstFormat) ? yuv2planeX_9BE_c : yuv2planeX_9LE_c;
2393 *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_9BE_c : yuv2plane1_9LE_c;
2394 } else if (desc->comp[0].depth == 10) {
2395 *yuv2planeX = isBE(dstFormat) ? yuv2planeX_10BE_c : yuv2planeX_10LE_c;
2396 *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_10BE_c : yuv2plane1_10LE_c;
2397 } else if (desc->comp[0].depth == 12) {
2398 *yuv2planeX = isBE(dstFormat) ? yuv2planeX_12BE_c : yuv2planeX_12LE_c;
2399 *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_12BE_c : yuv2plane1_12LE_c;
2400 } else if (desc->comp[0].depth == 14) {
2401 *yuv2planeX = isBE(dstFormat) ? yuv2planeX_14BE_c : yuv2planeX_14LE_c;
2402 *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_14BE_c : yuv2plane1_14LE_c;
2405 } else if (dstFormat == AV_PIX_FMT_GRAYF32BE) {
2406 *yuv2planeX = yuv2planeX_floatBE_c;
2407 *yuv2plane1 = yuv2plane1_floatBE_c;
2408 } else if (dstFormat == AV_PIX_FMT_GRAYF32LE) {
2409 *yuv2planeX = yuv2planeX_floatLE_c;
2410 *yuv2plane1 = yuv2plane1_floatLE_c;
2412 *yuv2plane1 = yuv2plane1_8_c;
2413 *yuv2planeX = yuv2planeX_8_c;
2414 if (dstFormat == AV_PIX_FMT_NV12 || dstFormat == AV_PIX_FMT_NV21)
2415 *yuv2nv12cX = yuv2nv12cX_c;
2418 if(c->flags & SWS_FULL_CHR_H_INT) {
2419 switch (dstFormat) {
2420 case AV_PIX_FMT_RGBA:
2422 *yuv2packedX = yuv2rgba32_full_X_c;
2423 *yuv2packed2 = yuv2rgba32_full_2_c;
2424 *yuv2packed1 = yuv2rgba32_full_1_c;
2426 #if CONFIG_SWSCALE_ALPHA
2428 *yuv2packedX = yuv2rgba32_full_X_c;
2429 *yuv2packed2 = yuv2rgba32_full_2_c;
2430 *yuv2packed1 = yuv2rgba32_full_1_c;
2432 #endif /* CONFIG_SWSCALE_ALPHA */
2434 *yuv2packedX = yuv2rgbx32_full_X_c;
2435 *yuv2packed2 = yuv2rgbx32_full_2_c;
2436 *yuv2packed1 = yuv2rgbx32_full_1_c;
2438 #endif /* !CONFIG_SMALL */
2440 case AV_PIX_FMT_ARGB:
2442 *yuv2packedX = yuv2argb32_full_X_c;
2443 *yuv2packed2 = yuv2argb32_full_2_c;
2444 *yuv2packed1 = yuv2argb32_full_1_c;
2446 #if CONFIG_SWSCALE_ALPHA
2448 *yuv2packedX = yuv2argb32_full_X_c;
2449 *yuv2packed2 = yuv2argb32_full_2_c;
2450 *yuv2packed1 = yuv2argb32_full_1_c;
2452 #endif /* CONFIG_SWSCALE_ALPHA */
2454 *yuv2packedX = yuv2xrgb32_full_X_c;
2455 *yuv2packed2 = yuv2xrgb32_full_2_c;
2456 *yuv2packed1 = yuv2xrgb32_full_1_c;
2458 #endif /* !CONFIG_SMALL */
2460 case AV_PIX_FMT_BGRA:
2462 *yuv2packedX = yuv2bgra32_full_X_c;
2463 *yuv2packed2 = yuv2bgra32_full_2_c;
2464 *yuv2packed1 = yuv2bgra32_full_1_c;
2466 #if CONFIG_SWSCALE_ALPHA
2468 *yuv2packedX = yuv2bgra32_full_X_c;
2469 *yuv2packed2 = yuv2bgra32_full_2_c;
2470 *yuv2packed1 = yuv2bgra32_full_1_c;
2472 #endif /* CONFIG_SWSCALE_ALPHA */
2474 *yuv2packedX = yuv2bgrx32_full_X_c;
2475 *yuv2packed2 = yuv2bgrx32_full_2_c;
2476 *yuv2packed1 = yuv2bgrx32_full_1_c;
2478 #endif /* !CONFIG_SMALL */
2480 case AV_PIX_FMT_ABGR:
2482 *yuv2packedX = yuv2abgr32_full_X_c;
2483 *yuv2packed2 = yuv2abgr32_full_2_c;
2484 *yuv2packed1 = yuv2abgr32_full_1_c;
2486 #if CONFIG_SWSCALE_ALPHA
2488 *yuv2packedX = yuv2abgr32_full_X_c;
2489 *yuv2packed2 = yuv2abgr32_full_2_c;
2490 *yuv2packed1 = yuv2abgr32_full_1_c;
2492 #endif /* CONFIG_SWSCALE_ALPHA */
2494 *yuv2packedX = yuv2xbgr32_full_X_c;
2495 *yuv2packed2 = yuv2xbgr32_full_2_c;
2496 *yuv2packed1 = yuv2xbgr32_full_1_c;
2498 #endif /* !CONFIG_SMALL */
2500 case AV_PIX_FMT_RGBA64LE:
2501 #if CONFIG_SWSCALE_ALPHA
2503 *yuv2packedX = yuv2rgba64le_full_X_c;
2504 *yuv2packed2 = yuv2rgba64le_full_2_c;
2505 *yuv2packed1 = yuv2rgba64le_full_1_c;
2507 #endif /* CONFIG_SWSCALE_ALPHA */
2509 *yuv2packedX = yuv2rgbx64le_full_X_c;
2510 *yuv2packed2 = yuv2rgbx64le_full_2_c;
2511 *yuv2packed1 = yuv2rgbx64le_full_1_c;
2514 case AV_PIX_FMT_RGBA64BE:
2515 #if CONFIG_SWSCALE_ALPHA
2517 *yuv2packedX = yuv2rgba64be_full_X_c;
2518 *yuv2packed2 = yuv2rgba64be_full_2_c;
2519 *yuv2packed1 = yuv2rgba64be_full_1_c;
2521 #endif /* CONFIG_SWSCALE_ALPHA */
2523 *yuv2packedX = yuv2rgbx64be_full_X_c;
2524 *yuv2packed2 = yuv2rgbx64be_full_2_c;
2525 *yuv2packed1 = yuv2rgbx64be_full_1_c;
2528 case AV_PIX_FMT_BGRA64LE:
2529 #if CONFIG_SWSCALE_ALPHA
2531 *yuv2packedX = yuv2bgra64le_full_X_c;
2532 *yuv2packed2 = yuv2bgra64le_full_2_c;
2533 *yuv2packed1 = yuv2bgra64le_full_1_c;
2535 #endif /* CONFIG_SWSCALE_ALPHA */
2537 *yuv2packedX = yuv2bgrx64le_full_X_c;
2538 *yuv2packed2 = yuv2bgrx64le_full_2_c;
2539 *yuv2packed1 = yuv2bgrx64le_full_1_c;
2542 case AV_PIX_FMT_BGRA64BE:
2543 #if CONFIG_SWSCALE_ALPHA
2545 *yuv2packedX = yuv2bgra64be_full_X_c;
2546 *yuv2packed2 = yuv2bgra64be_full_2_c;
2547 *yuv2packed1 = yuv2bgra64be_full_1_c;
2549 #endif /* CONFIG_SWSCALE_ALPHA */
2551 *yuv2packedX = yuv2bgrx64be_full_X_c;
2552 *yuv2packed2 = yuv2bgrx64be_full_2_c;
2553 *yuv2packed1 = yuv2bgrx64be_full_1_c;
2557 case AV_PIX_FMT_RGB24:
2558 *yuv2packedX = yuv2rgb24_full_X_c;
2559 *yuv2packed2 = yuv2rgb24_full_2_c;
2560 *yuv2packed1 = yuv2rgb24_full_1_c;
2562 case AV_PIX_FMT_BGR24:
2563 *yuv2packedX = yuv2bgr24_full_X_c;
2564 *yuv2packed2 = yuv2bgr24_full_2_c;
2565 *yuv2packed1 = yuv2bgr24_full_1_c;
2567 case AV_PIX_FMT_RGB48LE:
2568 *yuv2packedX = yuv2rgb48le_full_X_c;
2569 *yuv2packed2 = yuv2rgb48le_full_2_c;
2570 *yuv2packed1 = yuv2rgb48le_full_1_c;
2572 case AV_PIX_FMT_BGR48LE:
2573 *yuv2packedX = yuv2bgr48le_full_X_c;
2574 *yuv2packed2 = yuv2bgr48le_full_2_c;
2575 *yuv2packed1 = yuv2bgr48le_full_1_c;
2577 case AV_PIX_FMT_RGB48BE:
2578 *yuv2packedX = yuv2rgb48be_full_X_c;
2579 *yuv2packed2 = yuv2rgb48be_full_2_c;
2580 *yuv2packed1 = yuv2rgb48be_full_1_c;
2582 case AV_PIX_FMT_BGR48BE:
2583 *yuv2packedX = yuv2bgr48be_full_X_c;
2584 *yuv2packed2 = yuv2bgr48be_full_2_c;
2585 *yuv2packed1 = yuv2bgr48be_full_1_c;
2587 case AV_PIX_FMT_BGR4_BYTE:
2588 *yuv2packedX = yuv2bgr4_byte_full_X_c;
2589 *yuv2packed2 = yuv2bgr4_byte_full_2_c;
2590 *yuv2packed1 = yuv2bgr4_byte_full_1_c;
2592 case AV_PIX_FMT_RGB4_BYTE:
2593 *yuv2packedX = yuv2rgb4_byte_full_X_c;
2594 *yuv2packed2 = yuv2rgb4_byte_full_2_c;
2595 *yuv2packed1 = yuv2rgb4_byte_full_1_c;
2597 case AV_PIX_FMT_BGR8:
2598 *yuv2packedX = yuv2bgr8_full_X_c;
2599 *yuv2packed2 = yuv2bgr8_full_2_c;
2600 *yuv2packed1 = yuv2bgr8_full_1_c;
2602 case AV_PIX_FMT_RGB8:
2603 *yuv2packedX = yuv2rgb8_full_X_c;
2604 *yuv2packed2 = yuv2rgb8_full_2_c;
2605 *yuv2packed1 = yuv2rgb8_full_1_c;
2607 case AV_PIX_FMT_GBRP:
2608 case AV_PIX_FMT_GBRP9BE:
2609 case AV_PIX_FMT_GBRP9LE:
2610 case AV_PIX_FMT_GBRP10BE:
2611 case AV_PIX_FMT_GBRP10LE:
2612 case AV_PIX_FMT_GBRP12BE:
2613 case AV_PIX_FMT_GBRP12LE:
2614 case AV_PIX_FMT_GBRP14BE:
2615 case AV_PIX_FMT_GBRP14LE:
2616 case AV_PIX_FMT_GBRAP:
2617 case AV_PIX_FMT_GBRAP10BE:
2618 case AV_PIX_FMT_GBRAP10LE:
2619 case AV_PIX_FMT_GBRAP12BE:
2620 case AV_PIX_FMT_GBRAP12LE:
2621 *yuv2anyX = yuv2gbrp_full_X_c;
2623 case AV_PIX_FMT_GBRP16BE:
2624 case AV_PIX_FMT_GBRP16LE:
2625 case AV_PIX_FMT_GBRAP16BE:
2626 case AV_PIX_FMT_GBRAP16LE:
2627 *yuv2anyX = yuv2gbrp16_full_X_c;
2630 if (!*yuv2packedX && !*yuv2anyX)
2634 switch (dstFormat) {
2635 case AV_PIX_FMT_RGBA64LE:
2636 #if CONFIG_SWSCALE_ALPHA
2638 *yuv2packed1 = yuv2rgba64le_1_c;
2639 *yuv2packed2 = yuv2rgba64le_2_c;
2640 *yuv2packedX = yuv2rgba64le_X_c;
2642 #endif /* CONFIG_SWSCALE_ALPHA */
2644 *yuv2packed1 = yuv2rgbx64le_1_c;
2645 *yuv2packed2 = yuv2rgbx64le_2_c;
2646 *yuv2packedX = yuv2rgbx64le_X_c;
2649 case AV_PIX_FMT_RGBA64BE:
2650 #if CONFIG_SWSCALE_ALPHA
2652 *yuv2packed1 = yuv2rgba64be_1_c;
2653 *yuv2packed2 = yuv2rgba64be_2_c;
2654 *yuv2packedX = yuv2rgba64be_X_c;
2656 #endif /* CONFIG_SWSCALE_ALPHA */
2658 *yuv2packed1 = yuv2rgbx64be_1_c;
2659 *yuv2packed2 = yuv2rgbx64be_2_c;
2660 *yuv2packedX = yuv2rgbx64be_X_c;
2663 case AV_PIX_FMT_BGRA64LE:
2664 #if CONFIG_SWSCALE_ALPHA
2666 *yuv2packed1 = yuv2bgra64le_1_c;
2667 *yuv2packed2 = yuv2bgra64le_2_c;
2668 *yuv2packedX = yuv2bgra64le_X_c;
2670 #endif /* CONFIG_SWSCALE_ALPHA */
2672 *yuv2packed1 = yuv2bgrx64le_1_c;
2673 *yuv2packed2 = yuv2bgrx64le_2_c;
2674 *yuv2packedX = yuv2bgrx64le_X_c;
2677 case AV_PIX_FMT_BGRA64BE:
2678 #if CONFIG_SWSCALE_ALPHA
2680 *yuv2packed1 = yuv2bgra64be_1_c;
2681 *yuv2packed2 = yuv2bgra64be_2_c;
2682 *yuv2packedX = yuv2bgra64be_X_c;
2684 #endif /* CONFIG_SWSCALE_ALPHA */
2686 *yuv2packed1 = yuv2bgrx64be_1_c;
2687 *yuv2packed2 = yuv2bgrx64be_2_c;
2688 *yuv2packedX = yuv2bgrx64be_X_c;
2691 case AV_PIX_FMT_RGB48LE:
2692 *yuv2packed1 = yuv2rgb48le_1_c;
2693 *yuv2packed2 = yuv2rgb48le_2_c;
2694 *yuv2packedX = yuv2rgb48le_X_c;
2696 case AV_PIX_FMT_RGB48BE:
2697 *yuv2packed1 = yuv2rgb48be_1_c;
2698 *yuv2packed2 = yuv2rgb48be_2_c;
2699 *yuv2packedX = yuv2rgb48be_X_c;
2701 case AV_PIX_FMT_BGR48LE:
2702 *yuv2packed1 = yuv2bgr48le_1_c;
2703 *yuv2packed2 = yuv2bgr48le_2_c;
2704 *yuv2packedX = yuv2bgr48le_X_c;
2706 case AV_PIX_FMT_BGR48BE:
2707 *yuv2packed1 = yuv2bgr48be_1_c;
2708 *yuv2packed2 = yuv2bgr48be_2_c;
2709 *yuv2packedX = yuv2bgr48be_X_c;
2711 case AV_PIX_FMT_RGB32:
2712 case AV_PIX_FMT_BGR32:
2714 *yuv2packed1 = yuv2rgb32_1_c;
2715 *yuv2packed2 = yuv2rgb32_2_c;
2716 *yuv2packedX = yuv2rgb32_X_c;
2718 #if CONFIG_SWSCALE_ALPHA
2720 *yuv2packed1 = yuv2rgba32_1_c;
2721 *yuv2packed2 = yuv2rgba32_2_c;
2722 *yuv2packedX = yuv2rgba32_X_c;
2724 #endif /* CONFIG_SWSCALE_ALPHA */
2726 *yuv2packed1 = yuv2rgbx32_1_c;
2727 *yuv2packed2 = yuv2rgbx32_2_c;
2728 *yuv2packedX = yuv2rgbx32_X_c;
2730 #endif /* !CONFIG_SMALL */
2732 case AV_PIX_FMT_RGB32_1:
2733 case AV_PIX_FMT_BGR32_1:
2735 *yuv2packed1 = yuv2rgb32_1_1_c;
2736 *yuv2packed2 = yuv2rgb32_1_2_c;
2737 *yuv2packedX = yuv2rgb32_1_X_c;
2739 #if CONFIG_SWSCALE_ALPHA
2741 *yuv2packed1 = yuv2rgba32_1_1_c;
2742 *yuv2packed2 = yuv2rgba32_1_2_c;
2743 *yuv2packedX = yuv2rgba32_1_X_c;
2745 #endif /* CONFIG_SWSCALE_ALPHA */
2747 *yuv2packed1 = yuv2rgbx32_1_1_c;
2748 *yuv2packed2 = yuv2rgbx32_1_2_c;
2749 *yuv2packedX = yuv2rgbx32_1_X_c;
2751 #endif /* !CONFIG_SMALL */
2753 case AV_PIX_FMT_RGB24:
2754 *yuv2packed1 = yuv2rgb24_1_c;
2755 *yuv2packed2 = yuv2rgb24_2_c;
2756 *yuv2packedX = yuv2rgb24_X_c;
2758 case AV_PIX_FMT_BGR24:
2759 *yuv2packed1 = yuv2bgr24_1_c;
2760 *yuv2packed2 = yuv2bgr24_2_c;
2761 *yuv2packedX = yuv2bgr24_X_c;
2763 case AV_PIX_FMT_RGB565LE:
2764 case AV_PIX_FMT_RGB565BE:
2765 case AV_PIX_FMT_BGR565LE:
2766 case AV_PIX_FMT_BGR565BE:
2767 *yuv2packed1 = yuv2rgb16_1_c;
2768 *yuv2packed2 = yuv2rgb16_2_c;
2769 *yuv2packedX = yuv2rgb16_X_c;
2771 case AV_PIX_FMT_RGB555LE:
2772 case AV_PIX_FMT_RGB555BE:
2773 case AV_PIX_FMT_BGR555LE:
2774 case AV_PIX_FMT_BGR555BE:
2775 *yuv2packed1 = yuv2rgb15_1_c;
2776 *yuv2packed2 = yuv2rgb15_2_c;
2777 *yuv2packedX = yuv2rgb15_X_c;
2779 case AV_PIX_FMT_RGB444LE:
2780 case AV_PIX_FMT_RGB444BE:
2781 case AV_PIX_FMT_BGR444LE:
2782 case AV_PIX_FMT_BGR444BE:
2783 *yuv2packed1 = yuv2rgb12_1_c;
2784 *yuv2packed2 = yuv2rgb12_2_c;
2785 *yuv2packedX = yuv2rgb12_X_c;
2787 case AV_PIX_FMT_RGB8:
2788 case AV_PIX_FMT_BGR8:
2789 *yuv2packed1 = yuv2rgb8_1_c;
2790 *yuv2packed2 = yuv2rgb8_2_c;
2791 *yuv2packedX = yuv2rgb8_X_c;
2793 case AV_PIX_FMT_RGB4:
2794 case AV_PIX_FMT_BGR4:
2795 *yuv2packed1 = yuv2rgb4_1_c;
2796 *yuv2packed2 = yuv2rgb4_2_c;
2797 *yuv2packedX = yuv2rgb4_X_c;
2799 case AV_PIX_FMT_RGB4_BYTE:
2800 case AV_PIX_FMT_BGR4_BYTE:
2801 *yuv2packed1 = yuv2rgb4b_1_c;
2802 *yuv2packed2 = yuv2rgb4b_2_c;
2803 *yuv2packedX = yuv2rgb4b_X_c;
2807 switch (dstFormat) {
2808 case AV_PIX_FMT_MONOWHITE:
2809 *yuv2packed1 = yuv2monowhite_1_c;
2810 *yuv2packed2 = yuv2monowhite_2_c;
2811 *yuv2packedX = yuv2monowhite_X_c;
2813 case AV_PIX_FMT_MONOBLACK:
2814 *yuv2packed1 = yuv2monoblack_1_c;
2815 *yuv2packed2 = yuv2monoblack_2_c;
2816 *yuv2packedX = yuv2monoblack_X_c;
2818 case AV_PIX_FMT_YUYV422:
2819 *yuv2packed1 = yuv2yuyv422_1_c;
2820 *yuv2packed2 = yuv2yuyv422_2_c;
2821 *yuv2packedX = yuv2yuyv422_X_c;
2823 case AV_PIX_FMT_YVYU422:
2824 *yuv2packed1 = yuv2yvyu422_1_c;
2825 *yuv2packed2 = yuv2yvyu422_2_c;
2826 *yuv2packedX = yuv2yvyu422_X_c;
2828 case AV_PIX_FMT_UYVY422:
2829 *yuv2packed1 = yuv2uyvy422_1_c;
2830 *yuv2packed2 = yuv2uyvy422_2_c;
2831 *yuv2packedX = yuv2uyvy422_X_c;
2833 case AV_PIX_FMT_YA8:
2834 *yuv2packed1 = yuv2ya8_1_c;
2835 *yuv2packed2 = yuv2ya8_2_c;
2836 *yuv2packedX = yuv2ya8_X_c;
2838 case AV_PIX_FMT_AYUV64LE:
2839 *yuv2packedX = yuv2ayuv64le_X_c;