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 output_pixels(i * 4, Y1, U, Y2, V);
859 const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
860 for (i = 0; i < ((dstW + 1) >> 1); i++) {
861 int Y1 = (buf0[i * 2 ] + 64) >> 7;
862 int Y2 = (buf0[i * 2 + 1] + 64) >> 7;
863 int U = (ubuf0[i] + ubuf1[i]+128) >> 8;
864 int V = (vbuf0[i] + vbuf1[i]+128) >> 8;
866 if ((Y1 | Y2 | U | V) & 0x100) {
867 Y1 = av_clip_uint8(Y1);
868 Y2 = av_clip_uint8(Y2);
869 U = av_clip_uint8(U);
870 V = av_clip_uint8(V);
873 output_pixels(i * 4, Y1, U, Y2, V);
880 YUV2PACKEDWRAPPER(yuv2, 422, yuyv422, AV_PIX_FMT_YUYV422)
881 YUV2PACKEDWRAPPER(yuv2, 422, yvyu422, AV_PIX_FMT_YVYU422)
882 YUV2PACKEDWRAPPER(yuv2, 422, uyvy422, AV_PIX_FMT_UYVY422)
884 #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)
885 #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)
886 #define output_pixel(pos, val) \
887 if (isBE(target)) { \
893 static av_always_inline void
894 yuv2ya16_X_c_template(SwsContext *c, const int16_t *lumFilter,
895 const int32_t **lumSrc, int lumFilterSize,
896 const int16_t *chrFilter, const int32_t **unused_chrUSrc,
897 const int32_t **unused_chrVSrc, int unused_chrFilterSize,
898 const int32_t **alpSrc, uint16_t *dest, int dstW,
899 int y, enum AVPixelFormat target, int unused_hasAlpha, int unused_eightbytes)
901 int hasAlpha = !!alpSrc;
904 for (i = 0; i < dstW; i++) {
907 int64_t A = 0xffff<<14;
909 for (j = 0; j < lumFilterSize; j++)
910 Y += lumSrc[j][i] * lumFilter[j];
913 Y = av_clip_uint16(Y);
916 for (j = 0; j < lumFilterSize; j++)
917 A += alpSrc[j][i] * lumFilter[j];
920 A = av_clip_uint16(A);
923 output_pixel(&dest[2 * i ], Y);
924 output_pixel(&dest[2 * i + 1], hasAlpha ? A : 65535);
928 static av_always_inline void
929 yuv2ya16_2_c_template(SwsContext *c, const int32_t *buf[2],
930 const int32_t *unused_ubuf[2], const int32_t *unused_vbuf[2],
931 const int32_t *abuf[2], uint16_t *dest, int dstW,
932 int yalpha, int unused_uvalpha, int y,
933 enum AVPixelFormat target, int unused_hasAlpha, int unused_eightbytes)
935 int hasAlpha = abuf && abuf[0] && abuf[1];
936 const int32_t *buf0 = buf[0], *buf1 = buf[1],
937 *abuf0 = hasAlpha ? abuf[0] : NULL,
938 *abuf1 = hasAlpha ? abuf[1] : NULL;
939 int yalpha1 = 4096 - yalpha;
942 av_assert2(yalpha <= 4096U);
944 for (i = 0; i < dstW; i++) {
945 int Y = (buf0[i] * yalpha1 + buf1[i] * yalpha) >> 15;
948 Y = av_clip_uint16(Y);
951 A = (abuf0[i] * yalpha1 + abuf1[i] * yalpha) >> 15;
952 A = av_clip_uint16(A);
955 output_pixel(&dest[2 * i ], Y);
956 output_pixel(&dest[2 * i + 1], hasAlpha ? A : 65535);
960 static av_always_inline void
961 yuv2ya16_1_c_template(SwsContext *c, const int32_t *buf0,
962 const int32_t *unused_ubuf[2], const int32_t *unused_vbuf[2],
963 const int32_t *abuf0, uint16_t *dest, int dstW,
964 int unused_uvalpha, int y, enum AVPixelFormat target, int unused_hasAlpha, int unused_eightbytes)
966 int hasAlpha = !!abuf0;
969 for (i = 0; i < dstW; i++) {
970 int Y = buf0[i] >> 3;/* 19 - 16 */
973 Y = av_clip_uint16(Y);
978 A = av_clip_uint16(A);
981 output_pixel(&dest[2 * i ], Y);
982 output_pixel(&dest[2 * i + 1], hasAlpha ? A : 65535);
986 static av_always_inline void
987 yuv2rgba64_X_c_template(SwsContext *c, const int16_t *lumFilter,
988 const int32_t **lumSrc, int lumFilterSize,
989 const int16_t *chrFilter, const int32_t **chrUSrc,
990 const int32_t **chrVSrc, int chrFilterSize,
991 const int32_t **alpSrc, uint16_t *dest, int dstW,
992 int y, enum AVPixelFormat target, int hasAlpha, int eightbytes)
995 int A1 = 0xffff<<14, A2 = 0xffff<<14;
997 for (i = 0; i < ((dstW + 1) >> 1); i++) {
999 int Y1 = -0x40000000;
1000 int Y2 = -0x40000000;
1001 int U = -(128 << 23); // 19
1002 int V = -(128 << 23);
1005 for (j = 0; j < lumFilterSize; j++) {
1006 Y1 += lumSrc[j][i * 2] * (unsigned)lumFilter[j];
1007 Y2 += lumSrc[j][i * 2 + 1] * (unsigned)lumFilter[j];
1009 for (j = 0; j < chrFilterSize; j++) {;
1010 U += chrUSrc[j][i] * (unsigned)chrFilter[j];
1011 V += chrVSrc[j][i] * (unsigned)chrFilter[j];
1017 for (j = 0; j < lumFilterSize; j++) {
1018 A1 += alpSrc[j][i * 2] * (unsigned)lumFilter[j];
1019 A2 += alpSrc[j][i * 2 + 1] * (unsigned)lumFilter[j];
1027 // 8 bits: 12+15=27; 16 bits: 12+19=31
1035 // 8 bits: 27 -> 17 bits, 16 bits: 31 - 14 = 17 bits
1036 Y1 -= c->yuv2rgb_y_offset;
1037 Y2 -= c->yuv2rgb_y_offset;
1038 Y1 *= c->yuv2rgb_y_coeff;
1039 Y2 *= c->yuv2rgb_y_coeff;
1040 Y1 += 1 << 13; // 21
1042 // 8 bits: 17 + 13 bits = 30 bits, 16 bits: 17 + 13 bits = 30 bits
1044 R = V * c->yuv2rgb_v2r_coeff;
1045 G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
1046 B = U * c->yuv2rgb_u2b_coeff;
1048 // 8 bits: 30 - 22 = 8 bits, 16 bits: 30 bits - 14 = 16 bits
1049 output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
1050 output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
1051 output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
1053 output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14);
1054 output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >> 14);
1055 output_pixel(&dest[5], av_clip_uintp2( G + Y2, 30) >> 14);
1056 output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >> 14);
1057 output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14);
1060 output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
1061 output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);
1062 output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
1068 static av_always_inline void
1069 yuv2rgba64_2_c_template(SwsContext *c, const int32_t *buf[2],
1070 const int32_t *ubuf[2], const int32_t *vbuf[2],
1071 const int32_t *abuf[2], uint16_t *dest, int dstW,
1072 int yalpha, int uvalpha, int y,
1073 enum AVPixelFormat target, int hasAlpha, int eightbytes)
1075 const int32_t *buf0 = buf[0], *buf1 = buf[1],
1076 *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
1077 *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
1078 *abuf0 = hasAlpha ? abuf[0] : NULL,
1079 *abuf1 = hasAlpha ? abuf[1] : NULL;
1080 int yalpha1 = 4096 - yalpha;
1081 int uvalpha1 = 4096 - uvalpha;
1083 int A1 = 0xffff<<14, A2 = 0xffff<<14;
1085 av_assert2(yalpha <= 4096U);
1086 av_assert2(uvalpha <= 4096U);
1088 for (i = 0; i < ((dstW + 1) >> 1); i++) {
1089 int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 14;
1090 int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 14;
1091 int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha - (128 << 23)) >> 14;
1092 int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha - (128 << 23)) >> 14;
1095 Y1 -= c->yuv2rgb_y_offset;
1096 Y2 -= c->yuv2rgb_y_offset;
1097 Y1 *= c->yuv2rgb_y_coeff;
1098 Y2 *= c->yuv2rgb_y_coeff;
1102 R = V * c->yuv2rgb_v2r_coeff;
1103 G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
1104 B = U * c->yuv2rgb_u2b_coeff;
1107 A1 = (abuf0[i * 2 ] * yalpha1 + abuf1[i * 2 ] * yalpha) >> 1;
1108 A2 = (abuf0[i * 2 + 1] * yalpha1 + abuf1[i * 2 + 1] * yalpha) >> 1;
1114 output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
1115 output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
1116 output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
1118 output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14);
1119 output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >> 14);
1120 output_pixel(&dest[5], av_clip_uintp2( G + Y2, 30) >> 14);
1121 output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >> 14);
1122 output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14);
1125 output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
1126 output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);
1127 output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
1133 static av_always_inline void
1134 yuv2rgba64_1_c_template(SwsContext *c, const int32_t *buf0,
1135 const int32_t *ubuf[2], const int32_t *vbuf[2],
1136 const int32_t *abuf0, uint16_t *dest, int dstW,
1137 int uvalpha, int y, enum AVPixelFormat target, int hasAlpha, int eightbytes)
1139 const int32_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
1141 int A1 = 0xffff<<14, A2= 0xffff<<14;
1143 if (uvalpha < 2048) {
1144 for (i = 0; i < ((dstW + 1) >> 1); i++) {
1145 int Y1 = (buf0[i * 2] ) >> 2;
1146 int Y2 = (buf0[i * 2 + 1]) >> 2;
1147 int U = (ubuf0[i] - (128 << 11)) >> 2;
1148 int V = (vbuf0[i] - (128 << 11)) >> 2;
1151 Y1 -= c->yuv2rgb_y_offset;
1152 Y2 -= c->yuv2rgb_y_offset;
1153 Y1 *= c->yuv2rgb_y_coeff;
1154 Y2 *= c->yuv2rgb_y_coeff;
1159 A1 = abuf0[i * 2 ] << 11;
1160 A2 = abuf0[i * 2 + 1] << 11;
1166 R = V * c->yuv2rgb_v2r_coeff;
1167 G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
1168 B = U * c->yuv2rgb_u2b_coeff;
1170 output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
1171 output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
1172 output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
1174 output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14);
1175 output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >> 14);
1176 output_pixel(&dest[5], av_clip_uintp2( G + Y2, 30) >> 14);
1177 output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >> 14);
1178 output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14);
1181 output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
1182 output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);
1183 output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
1188 const int32_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
1189 int A1 = 0xffff<<14, A2 = 0xffff<<14;
1190 for (i = 0; i < ((dstW + 1) >> 1); i++) {
1191 int Y1 = (buf0[i * 2] ) >> 2;
1192 int Y2 = (buf0[i * 2 + 1]) >> 2;
1193 int U = (ubuf0[i] + ubuf1[i] - (128 << 12)) >> 3;
1194 int V = (vbuf0[i] + vbuf1[i] - (128 << 12)) >> 3;
1197 Y1 -= c->yuv2rgb_y_offset;
1198 Y2 -= c->yuv2rgb_y_offset;
1199 Y1 *= c->yuv2rgb_y_coeff;
1200 Y2 *= c->yuv2rgb_y_coeff;
1205 A1 = abuf0[i * 2 ] << 11;
1206 A2 = abuf0[i * 2 + 1] << 11;
1212 R = V * c->yuv2rgb_v2r_coeff;
1213 G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
1214 B = U * c->yuv2rgb_u2b_coeff;
1216 output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
1217 output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
1218 output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
1220 output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14);
1221 output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >> 14);
1222 output_pixel(&dest[5], av_clip_uintp2( G + Y2, 30) >> 14);
1223 output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >> 14);
1224 output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14);
1227 output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
1228 output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);
1229 output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
1236 static av_always_inline void
1237 yuv2rgba64_full_X_c_template(SwsContext *c, const int16_t *lumFilter,
1238 const int32_t **lumSrc, int lumFilterSize,
1239 const int16_t *chrFilter, const int32_t **chrUSrc,
1240 const int32_t **chrVSrc, int chrFilterSize,
1241 const int32_t **alpSrc, uint16_t *dest, int dstW,
1242 int y, enum AVPixelFormat target, int hasAlpha, int eightbytes)
1247 for (i = 0; i < dstW; i++) {
1249 int Y = -0x40000000;
1250 int U = -(128 << 23); // 19
1251 int V = -(128 << 23);
1254 for (j = 0; j < lumFilterSize; j++) {
1255 Y += lumSrc[j][i] * (unsigned)lumFilter[j];
1257 for (j = 0; j < chrFilterSize; j++) {;
1258 U += chrUSrc[j][i] * (unsigned)chrFilter[j];
1259 V += chrVSrc[j][i] * (unsigned)chrFilter[j];
1264 for (j = 0; j < lumFilterSize; j++) {
1265 A += alpSrc[j][i] * (unsigned)lumFilter[j];
1271 // 8bit: 12+15=27; 16-bit: 12+19=31
1277 // 8bit: 27 -> 17bit, 16bit: 31 - 14 = 17bit
1278 Y -= c->yuv2rgb_y_offset;
1279 Y *= c->yuv2rgb_y_coeff;
1281 // 8bit: 17 + 13bit = 30bit, 16bit: 17 + 13bit = 30bit
1283 R = V * c->yuv2rgb_v2r_coeff;
1284 G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
1285 B = U * c->yuv2rgb_u2b_coeff;
1287 // 8bit: 30 - 22 = 8bit, 16bit: 30bit - 14 = 16bit
1288 output_pixel(&dest[0], av_clip_uintp2(R_B + Y, 30) >> 14);
1289 output_pixel(&dest[1], av_clip_uintp2( G + Y, 30) >> 14);
1290 output_pixel(&dest[2], av_clip_uintp2(B_R + Y, 30) >> 14);
1292 output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
1300 static av_always_inline void
1301 yuv2rgba64_full_2_c_template(SwsContext *c, const int32_t *buf[2],
1302 const int32_t *ubuf[2], const int32_t *vbuf[2],
1303 const int32_t *abuf[2], uint16_t *dest, int dstW,
1304 int yalpha, int uvalpha, int y,
1305 enum AVPixelFormat target, int hasAlpha, int eightbytes)
1307 const int32_t *buf0 = buf[0], *buf1 = buf[1],
1308 *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
1309 *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
1310 *abuf0 = hasAlpha ? abuf[0] : NULL,
1311 *abuf1 = hasAlpha ? abuf[1] : NULL;
1312 int yalpha1 = 4096 - yalpha;
1313 int uvalpha1 = 4096 - uvalpha;
1317 av_assert2(yalpha <= 4096U);
1318 av_assert2(uvalpha <= 4096U);
1320 for (i = 0; i < dstW; i++) {
1321 int Y = (buf0[i] * yalpha1 + buf1[i] * yalpha) >> 14;
1322 int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha - (128 << 23)) >> 14;
1323 int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha - (128 << 23)) >> 14;
1326 Y -= c->yuv2rgb_y_offset;
1327 Y *= c->yuv2rgb_y_coeff;
1330 R = V * c->yuv2rgb_v2r_coeff;
1331 G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
1332 B = U * c->yuv2rgb_u2b_coeff;
1335 A = (abuf0[i] * yalpha1 + abuf1[i] * yalpha) >> 1;
1340 output_pixel(&dest[0], av_clip_uintp2(R_B + Y, 30) >> 14);
1341 output_pixel(&dest[1], av_clip_uintp2( G + Y, 30) >> 14);
1342 output_pixel(&dest[2], av_clip_uintp2(B_R + Y, 30) >> 14);
1344 output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
1352 static av_always_inline void
1353 yuv2rgba64_full_1_c_template(SwsContext *c, const int32_t *buf0,
1354 const int32_t *ubuf[2], const int32_t *vbuf[2],
1355 const int32_t *abuf0, uint16_t *dest, int dstW,
1356 int uvalpha, int y, enum AVPixelFormat target, int hasAlpha, int eightbytes)
1358 const int32_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
1362 if (uvalpha < 2048) {
1363 for (i = 0; i < dstW; i++) {
1364 int Y = (buf0[i]) >> 2;
1365 int U = (ubuf0[i] - (128 << 11)) >> 2;
1366 int V = (vbuf0[i] - (128 << 11)) >> 2;
1369 Y -= c->yuv2rgb_y_offset;
1370 Y *= c->yuv2rgb_y_coeff;
1379 R = V * c->yuv2rgb_v2r_coeff;
1380 G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
1381 B = U * c->yuv2rgb_u2b_coeff;
1383 output_pixel(&dest[0], av_clip_uintp2(R_B + Y, 30) >> 14);
1384 output_pixel(&dest[1], av_clip_uintp2( G + Y, 30) >> 14);
1385 output_pixel(&dest[2], av_clip_uintp2(B_R + Y, 30) >> 14);
1387 output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
1394 const int32_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
1396 for (i = 0; i < dstW; i++) {
1397 int Y = (buf0[i] ) >> 2;
1398 int U = (ubuf0[i] + ubuf1[i] - (128 << 12)) >> 3;
1399 int V = (vbuf0[i] + vbuf1[i] - (128 << 12)) >> 3;
1402 Y -= c->yuv2rgb_y_offset;
1403 Y *= c->yuv2rgb_y_coeff;
1412 R = V * c->yuv2rgb_v2r_coeff;
1413 G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
1414 B = U * c->yuv2rgb_u2b_coeff;
1416 output_pixel(&dest[0], av_clip_uintp2(R_B + Y, 30) >> 14);
1417 output_pixel(&dest[1], av_clip_uintp2( G + Y, 30) >> 14);
1418 output_pixel(&dest[2], av_clip_uintp2(B_R + Y, 30) >> 14);
1420 output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
1433 #define YUV2PACKED16WRAPPER(name, base, ext, fmt, hasAlpha, eightbytes) \
1434 static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \
1435 const int16_t **_lumSrc, int lumFilterSize, \
1436 const int16_t *chrFilter, const int16_t **_chrUSrc, \
1437 const int16_t **_chrVSrc, int chrFilterSize, \
1438 const int16_t **_alpSrc, uint8_t *_dest, int dstW, \
1441 const int32_t **lumSrc = (const int32_t **) _lumSrc, \
1442 **chrUSrc = (const int32_t **) _chrUSrc, \
1443 **chrVSrc = (const int32_t **) _chrVSrc, \
1444 **alpSrc = (const int32_t **) _alpSrc; \
1445 uint16_t *dest = (uint16_t *) _dest; \
1446 name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
1447 chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
1448 alpSrc, dest, dstW, y, fmt, hasAlpha, eightbytes); \
1451 static void name ## ext ## _2_c(SwsContext *c, const int16_t *_buf[2], \
1452 const int16_t *_ubuf[2], const int16_t *_vbuf[2], \
1453 const int16_t *_abuf[2], uint8_t *_dest, int dstW, \
1454 int yalpha, int uvalpha, int y) \
1456 const int32_t **buf = (const int32_t **) _buf, \
1457 **ubuf = (const int32_t **) _ubuf, \
1458 **vbuf = (const int32_t **) _vbuf, \
1459 **abuf = (const int32_t **) _abuf; \
1460 uint16_t *dest = (uint16_t *) _dest; \
1461 name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
1462 dest, dstW, yalpha, uvalpha, y, fmt, hasAlpha, eightbytes); \
1465 static void name ## ext ## _1_c(SwsContext *c, const int16_t *_buf0, \
1466 const int16_t *_ubuf[2], const int16_t *_vbuf[2], \
1467 const int16_t *_abuf0, uint8_t *_dest, int dstW, \
1468 int uvalpha, int y) \
1470 const int32_t *buf0 = (const int32_t *) _buf0, \
1471 **ubuf = (const int32_t **) _ubuf, \
1472 **vbuf = (const int32_t **) _vbuf, \
1473 *abuf0 = (const int32_t *) _abuf0; \
1474 uint16_t *dest = (uint16_t *) _dest; \
1475 name ## base ## _1_c_template(c, buf0, ubuf, vbuf, abuf0, dest, \
1476 dstW, uvalpha, y, fmt, hasAlpha, eightbytes); \
1479 YUV2PACKED16WRAPPER(yuv2, rgba64, rgb48be, AV_PIX_FMT_RGB48BE, 0, 0)
1480 YUV2PACKED16WRAPPER(yuv2, rgba64, rgb48le, AV_PIX_FMT_RGB48LE, 0, 0)
1481 YUV2PACKED16WRAPPER(yuv2, rgba64, bgr48be, AV_PIX_FMT_BGR48BE, 0, 0)
1482 YUV2PACKED16WRAPPER(yuv2, rgba64, bgr48le, AV_PIX_FMT_BGR48LE, 0, 0)
1483 YUV2PACKED16WRAPPER(yuv2, rgba64, rgba64be, AV_PIX_FMT_RGBA64BE, 1, 1)
1484 YUV2PACKED16WRAPPER(yuv2, rgba64, rgba64le, AV_PIX_FMT_RGBA64LE, 1, 1)
1485 YUV2PACKED16WRAPPER(yuv2, rgba64, rgbx64be, AV_PIX_FMT_RGBA64BE, 0, 1)
1486 YUV2PACKED16WRAPPER(yuv2, rgba64, rgbx64le, AV_PIX_FMT_RGBA64LE, 0, 1)
1487 YUV2PACKED16WRAPPER(yuv2, rgba64, bgra64be, AV_PIX_FMT_BGRA64BE, 1, 1)
1488 YUV2PACKED16WRAPPER(yuv2, rgba64, bgra64le, AV_PIX_FMT_BGRA64LE, 1, 1)
1489 YUV2PACKED16WRAPPER(yuv2, rgba64, bgrx64be, AV_PIX_FMT_BGRA64BE, 0, 1)
1490 YUV2PACKED16WRAPPER(yuv2, rgba64, bgrx64le, AV_PIX_FMT_BGRA64LE, 0, 1)
1491 YUV2PACKED16WRAPPER(yuv2, ya16, ya16be, AV_PIX_FMT_YA16BE, 1, 0)
1492 YUV2PACKED16WRAPPER(yuv2, ya16, ya16le, AV_PIX_FMT_YA16LE, 1, 0)
1494 YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgb48be_full, AV_PIX_FMT_RGB48BE, 0, 0)
1495 YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgb48le_full, AV_PIX_FMT_RGB48LE, 0, 0)
1496 YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgr48be_full, AV_PIX_FMT_BGR48BE, 0, 0)
1497 YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgr48le_full, AV_PIX_FMT_BGR48LE, 0, 0)
1498 YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgba64be_full, AV_PIX_FMT_RGBA64BE, 1, 1)
1499 YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgba64le_full, AV_PIX_FMT_RGBA64LE, 1, 1)
1500 YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgbx64be_full, AV_PIX_FMT_RGBA64BE, 0, 1)
1501 YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgbx64le_full, AV_PIX_FMT_RGBA64LE, 0, 1)
1502 YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgra64be_full, AV_PIX_FMT_BGRA64BE, 1, 1)
1503 YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgra64le_full, AV_PIX_FMT_BGRA64LE, 1, 1)
1504 YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgrx64be_full, AV_PIX_FMT_BGRA64BE, 0, 1)
1505 YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgrx64le_full, AV_PIX_FMT_BGRA64LE, 0, 1)
1508 * Write out 2 RGB pixels in the target pixel format. This function takes a
1509 * R/G/B LUT as generated by ff_yuv2rgb_c_init_tables(), which takes care of
1510 * things like endianness conversion and shifting. The caller takes care of
1511 * setting the correct offset in these tables from the chroma (U/V) values.
1512 * This function then uses the luminance (Y1/Y2) values to write out the
1513 * correct RGB values into the destination buffer.
1515 static av_always_inline void
1516 yuv2rgb_write(uint8_t *_dest, int i, int Y1, int Y2,
1517 unsigned A1, unsigned A2,
1518 const void *_r, const void *_g, const void *_b, int y,
1519 enum AVPixelFormat target, int hasAlpha)
1521 if (target == AV_PIX_FMT_ARGB || target == AV_PIX_FMT_RGBA ||
1522 target == AV_PIX_FMT_ABGR || target == AV_PIX_FMT_BGRA) {
1523 uint32_t *dest = (uint32_t *) _dest;
1524 const uint32_t *r = (const uint32_t *) _r;
1525 const uint32_t *g = (const uint32_t *) _g;
1526 const uint32_t *b = (const uint32_t *) _b;
1529 int sh = hasAlpha ? ((target == AV_PIX_FMT_RGB32_1 || target == AV_PIX_FMT_BGR32_1) ? 0 : 24) : 0;
1531 dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1] + (hasAlpha ? A1 << sh : 0);
1532 dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2] + (hasAlpha ? A2 << sh : 0);
1535 int sh = (target == AV_PIX_FMT_RGB32_1 || target == AV_PIX_FMT_BGR32_1) ? 0 : 24;
1537 av_assert2((((r[Y1] + g[Y1] + b[Y1]) >> sh) & 0xFF) == 0);
1538 dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1] + (A1 << sh);
1539 dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2] + (A2 << sh);
1541 #if defined(ASSERT_LEVEL) && ASSERT_LEVEL > 1
1542 int sh = (target == AV_PIX_FMT_RGB32_1 || target == AV_PIX_FMT_BGR32_1) ? 0 : 24;
1544 av_assert2((((r[Y1] + g[Y1] + b[Y1]) >> sh) & 0xFF) == 0xFF);
1546 dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1];
1547 dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2];
1550 } else if (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) {
1551 uint8_t *dest = (uint8_t *) _dest;
1552 const uint8_t *r = (const uint8_t *) _r;
1553 const uint8_t *g = (const uint8_t *) _g;
1554 const uint8_t *b = (const uint8_t *) _b;
1556 #define r_b ((target == AV_PIX_FMT_RGB24) ? r : b)
1557 #define b_r ((target == AV_PIX_FMT_RGB24) ? b : r)
1559 dest[i * 6 + 0] = r_b[Y1];
1560 dest[i * 6 + 1] = g[Y1];
1561 dest[i * 6 + 2] = b_r[Y1];
1562 dest[i * 6 + 3] = r_b[Y2];
1563 dest[i * 6 + 4] = g[Y2];
1564 dest[i * 6 + 5] = b_r[Y2];
1567 } else if (target == AV_PIX_FMT_RGB565 || target == AV_PIX_FMT_BGR565 ||
1568 target == AV_PIX_FMT_RGB555 || target == AV_PIX_FMT_BGR555 ||
1569 target == AV_PIX_FMT_RGB444 || target == AV_PIX_FMT_BGR444) {
1570 uint16_t *dest = (uint16_t *) _dest;
1571 const uint16_t *r = (const uint16_t *) _r;
1572 const uint16_t *g = (const uint16_t *) _g;
1573 const uint16_t *b = (const uint16_t *) _b;
1574 int dr1, dg1, db1, dr2, dg2, db2;
1576 if (target == AV_PIX_FMT_RGB565 || target == AV_PIX_FMT_BGR565) {
1577 dr1 = ff_dither_2x2_8[ y & 1 ][0];
1578 dg1 = ff_dither_2x2_4[ y & 1 ][0];
1579 db1 = ff_dither_2x2_8[(y & 1) ^ 1][0];
1580 dr2 = ff_dither_2x2_8[ y & 1 ][1];
1581 dg2 = ff_dither_2x2_4[ y & 1 ][1];
1582 db2 = ff_dither_2x2_8[(y & 1) ^ 1][1];
1583 } else if (target == AV_PIX_FMT_RGB555 || target == AV_PIX_FMT_BGR555) {
1584 dr1 = ff_dither_2x2_8[ y & 1 ][0];
1585 dg1 = ff_dither_2x2_8[ y & 1 ][1];
1586 db1 = ff_dither_2x2_8[(y & 1) ^ 1][0];
1587 dr2 = ff_dither_2x2_8[ y & 1 ][1];
1588 dg2 = ff_dither_2x2_8[ y & 1 ][0];
1589 db2 = ff_dither_2x2_8[(y & 1) ^ 1][1];
1591 dr1 = ff_dither_4x4_16[ y & 3 ][0];
1592 dg1 = ff_dither_4x4_16[ y & 3 ][1];
1593 db1 = ff_dither_4x4_16[(y & 3) ^ 3][0];
1594 dr2 = ff_dither_4x4_16[ y & 3 ][1];
1595 dg2 = ff_dither_4x4_16[ y & 3 ][0];
1596 db2 = ff_dither_4x4_16[(y & 3) ^ 3][1];
1599 dest[i * 2 + 0] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1];
1600 dest[i * 2 + 1] = r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2];
1601 } else /* 8/4 bits */ {
1602 uint8_t *dest = (uint8_t *) _dest;
1603 const uint8_t *r = (const uint8_t *) _r;
1604 const uint8_t *g = (const uint8_t *) _g;
1605 const uint8_t *b = (const uint8_t *) _b;
1606 int dr1, dg1, db1, dr2, dg2, db2;
1608 if (target == AV_PIX_FMT_RGB8 || target == AV_PIX_FMT_BGR8) {
1609 const uint8_t * const d64 = ff_dither_8x8_73[y & 7];
1610 const uint8_t * const d32 = ff_dither_8x8_32[y & 7];
1611 dr1 = dg1 = d32[(i * 2 + 0) & 7];
1612 db1 = d64[(i * 2 + 0) & 7];
1613 dr2 = dg2 = d32[(i * 2 + 1) & 7];
1614 db2 = d64[(i * 2 + 1) & 7];
1616 const uint8_t * const d64 = ff_dither_8x8_73 [y & 7];
1617 const uint8_t * const d128 = ff_dither_8x8_220[y & 7];
1618 dr1 = db1 = d128[(i * 2 + 0) & 7];
1619 dg1 = d64[(i * 2 + 0) & 7];
1620 dr2 = db2 = d128[(i * 2 + 1) & 7];
1621 dg2 = d64[(i * 2 + 1) & 7];
1624 if (target == AV_PIX_FMT_RGB4 || target == AV_PIX_FMT_BGR4) {
1625 dest[i] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1] +
1626 ((r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2]) << 4);
1628 dest[i * 2 + 0] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1];
1629 dest[i * 2 + 1] = r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2];
1634 static av_always_inline void
1635 yuv2rgb_X_c_template(SwsContext *c, const int16_t *lumFilter,
1636 const int16_t **lumSrc, int lumFilterSize,
1637 const int16_t *chrFilter, const int16_t **chrUSrc,
1638 const int16_t **chrVSrc, int chrFilterSize,
1639 const int16_t **alpSrc, uint8_t *dest, int dstW,
1640 int y, enum AVPixelFormat target, int hasAlpha)
1644 for (i = 0; i < ((dstW + 1) >> 1); i++) {
1650 const void *r, *g, *b;
1652 for (j = 0; j < lumFilterSize; j++) {
1653 Y1 += lumSrc[j][i * 2] * lumFilter[j];
1654 Y2 += lumSrc[j][i * 2 + 1] * lumFilter[j];
1656 for (j = 0; j < chrFilterSize; j++) {
1657 U += chrUSrc[j][i] * chrFilter[j];
1658 V += chrVSrc[j][i] * chrFilter[j];
1667 for (j = 0; j < lumFilterSize; j++) {
1668 A1 += alpSrc[j][i * 2 ] * lumFilter[j];
1669 A2 += alpSrc[j][i * 2 + 1] * lumFilter[j];
1673 if ((A1 | A2) & 0x100) {
1674 A1 = av_clip_uint8(A1);
1675 A2 = av_clip_uint8(A2);
1679 r = c->table_rV[V + YUVRGB_TABLE_HEADROOM];
1680 g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]);
1681 b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
1683 yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
1684 r, g, b, y, target, hasAlpha);
1688 static av_always_inline void
1689 yuv2rgb_2_c_template(SwsContext *c, const int16_t *buf[2],
1690 const int16_t *ubuf[2], const int16_t *vbuf[2],
1691 const int16_t *abuf[2], uint8_t *dest, int dstW,
1692 int yalpha, int uvalpha, int y,
1693 enum AVPixelFormat target, int hasAlpha)
1695 const int16_t *buf0 = buf[0], *buf1 = buf[1],
1696 *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
1697 *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
1698 *abuf0 = hasAlpha ? abuf[0] : NULL,
1699 *abuf1 = hasAlpha ? abuf[1] : NULL;
1700 int yalpha1 = 4096 - yalpha;
1701 int uvalpha1 = 4096 - uvalpha;
1703 av_assert2(yalpha <= 4096U);
1704 av_assert2(uvalpha <= 4096U);
1706 for (i = 0; i < ((dstW + 1) >> 1); i++) {
1707 int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 19;
1708 int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 19;
1709 int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha) >> 19;
1710 int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha) >> 19;
1712 const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM],
1713 *g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]),
1714 *b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
1717 A1 = (abuf0[i * 2 ] * yalpha1 + abuf1[i * 2 ] * yalpha) >> 19;
1718 A2 = (abuf0[i * 2 + 1] * yalpha1 + abuf1[i * 2 + 1] * yalpha) >> 19;
1719 A1 = av_clip_uint8(A1);
1720 A2 = av_clip_uint8(A2);
1723 yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
1724 r, g, b, y, target, hasAlpha);
1728 static av_always_inline void
1729 yuv2rgb_1_c_template(SwsContext *c, const int16_t *buf0,
1730 const int16_t *ubuf[2], const int16_t *vbuf[2],
1731 const int16_t *abuf0, uint8_t *dest, int dstW,
1732 int uvalpha, int y, enum AVPixelFormat target,
1735 const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
1738 if (uvalpha < 2048) {
1739 for (i = 0; i < ((dstW + 1) >> 1); i++) {
1740 int Y1 = (buf0[i * 2 ] + 64) >> 7;
1741 int Y2 = (buf0[i * 2 + 1] + 64) >> 7;
1742 int U = (ubuf0[i] + 64) >> 7;
1743 int V = (vbuf0[i] + 64) >> 7;
1745 const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM],
1746 *g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]),
1747 *b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
1750 A1 = abuf0[i * 2 ] * 255 + 16384 >> 15;
1751 A2 = abuf0[i * 2 + 1] * 255 + 16384 >> 15;
1752 A1 = av_clip_uint8(A1);
1753 A2 = av_clip_uint8(A2);
1756 yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
1757 r, g, b, y, target, hasAlpha);
1760 const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
1761 for (i = 0; i < ((dstW + 1) >> 1); i++) {
1762 int Y1 = (buf0[i * 2 ] + 64) >> 7;
1763 int Y2 = (buf0[i * 2 + 1] + 64) >> 7;
1764 int U = (ubuf0[i] + ubuf1[i] + 128) >> 8;
1765 int V = (vbuf0[i] + vbuf1[i] + 128) >> 8;
1767 const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM],
1768 *g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]),
1769 *b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
1772 A1 = (abuf0[i * 2 ] + 64) >> 7;
1773 A2 = (abuf0[i * 2 + 1] + 64) >> 7;
1774 A1 = av_clip_uint8(A1);
1775 A2 = av_clip_uint8(A2);
1778 yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
1779 r, g, b, y, target, hasAlpha);
1784 #define YUV2RGBWRAPPERX(name, base, ext, fmt, hasAlpha) \
1785 static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \
1786 const int16_t **lumSrc, int lumFilterSize, \
1787 const int16_t *chrFilter, const int16_t **chrUSrc, \
1788 const int16_t **chrVSrc, int chrFilterSize, \
1789 const int16_t **alpSrc, uint8_t *dest, int dstW, \
1792 name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
1793 chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
1794 alpSrc, dest, dstW, y, fmt, hasAlpha); \
1797 #define YUV2RGBWRAPPERX2(name, base, ext, fmt, hasAlpha) \
1798 YUV2RGBWRAPPERX(name, base, ext, fmt, hasAlpha) \
1799 static void name ## ext ## _2_c(SwsContext *c, const int16_t *buf[2], \
1800 const int16_t *ubuf[2], const int16_t *vbuf[2], \
1801 const int16_t *abuf[2], uint8_t *dest, int dstW, \
1802 int yalpha, int uvalpha, int y) \
1804 name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
1805 dest, dstW, yalpha, uvalpha, y, fmt, hasAlpha); \
1808 #define YUV2RGBWRAPPER(name, base, ext, fmt, hasAlpha) \
1809 YUV2RGBWRAPPERX2(name, base, ext, fmt, hasAlpha) \
1810 static void name ## ext ## _1_c(SwsContext *c, const int16_t *buf0, \
1811 const int16_t *ubuf[2], const int16_t *vbuf[2], \
1812 const int16_t *abuf0, uint8_t *dest, int dstW, \
1813 int uvalpha, int y) \
1815 name ## base ## _1_c_template(c, buf0, ubuf, vbuf, abuf0, dest, \
1816 dstW, uvalpha, y, fmt, hasAlpha); \
1820 YUV2RGBWRAPPER(yuv2rgb,, 32_1, AV_PIX_FMT_RGB32_1, CONFIG_SWSCALE_ALPHA && c->needAlpha)
1821 YUV2RGBWRAPPER(yuv2rgb,, 32, AV_PIX_FMT_RGB32, CONFIG_SWSCALE_ALPHA && c->needAlpha)
1823 #if CONFIG_SWSCALE_ALPHA
1824 YUV2RGBWRAPPER(yuv2rgb,, a32_1, AV_PIX_FMT_RGB32_1, 1)
1825 YUV2RGBWRAPPER(yuv2rgb,, a32, AV_PIX_FMT_RGB32, 1)
1827 YUV2RGBWRAPPER(yuv2rgb,, x32_1, AV_PIX_FMT_RGB32_1, 0)
1828 YUV2RGBWRAPPER(yuv2rgb,, x32, AV_PIX_FMT_RGB32, 0)
1830 YUV2RGBWRAPPER(yuv2, rgb, rgb24, AV_PIX_FMT_RGB24, 0)
1831 YUV2RGBWRAPPER(yuv2, rgb, bgr24, AV_PIX_FMT_BGR24, 0)
1832 YUV2RGBWRAPPER(yuv2rgb,, 16, AV_PIX_FMT_RGB565, 0)
1833 YUV2RGBWRAPPER(yuv2rgb,, 15, AV_PIX_FMT_RGB555, 0)
1834 YUV2RGBWRAPPER(yuv2rgb,, 12, AV_PIX_FMT_RGB444, 0)
1835 YUV2RGBWRAPPER(yuv2rgb,, 8, AV_PIX_FMT_RGB8, 0)
1836 YUV2RGBWRAPPER(yuv2rgb,, 4, AV_PIX_FMT_RGB4, 0)
1837 YUV2RGBWRAPPER(yuv2rgb,, 4b, AV_PIX_FMT_RGB4_BYTE, 0)
1839 static av_always_inline void yuv2rgb_write_full(SwsContext *c,
1840 uint8_t *dest, int i, int Y, int A, int U, int V,
1841 int y, enum AVPixelFormat target, int hasAlpha, int err[4])
1844 int isrgb8 = target == AV_PIX_FMT_BGR8 || target == AV_PIX_FMT_RGB8;
1846 Y -= c->yuv2rgb_y_offset;
1847 Y *= c->yuv2rgb_y_coeff;
1849 R = Y + V*c->yuv2rgb_v2r_coeff;
1850 G = Y + V*c->yuv2rgb_v2g_coeff + U*c->yuv2rgb_u2g_coeff;
1851 B = Y + U*c->yuv2rgb_u2b_coeff;
1852 if ((R | G | B) & 0xC0000000) {
1853 R = av_clip_uintp2(R, 30);
1854 G = av_clip_uintp2(G, 30);
1855 B = av_clip_uintp2(B, 30);
1859 case AV_PIX_FMT_ARGB:
1860 dest[0] = hasAlpha ? A : 255;
1865 case AV_PIX_FMT_RGB24:
1870 case AV_PIX_FMT_RGBA:
1874 dest[3] = hasAlpha ? A : 255;
1876 case AV_PIX_FMT_ABGR:
1877 dest[0] = hasAlpha ? A : 255;
1882 case AV_PIX_FMT_BGR24:
1887 case AV_PIX_FMT_BGRA:
1891 dest[3] = hasAlpha ? A : 255;
1893 case AV_PIX_FMT_BGR4_BYTE:
1894 case AV_PIX_FMT_RGB4_BYTE:
1895 case AV_PIX_FMT_BGR8:
1896 case AV_PIX_FMT_RGB8:
1900 switch (c->dither) {
1902 case SWS_DITHER_AUTO:
1907 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;
1908 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;
1909 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;
1910 c->dither_error[0][i] = err[0];
1911 c->dither_error[1][i] = err[1];
1912 c->dither_error[2][i] = err[2];
1913 r = R >> (isrgb8 ? 5 : 7);
1914 g = G >> (isrgb8 ? 5 : 6);
1915 b = B >> (isrgb8 ? 6 : 7);
1916 r = av_clip(r, 0, isrgb8 ? 7 : 1);
1917 g = av_clip(g, 0, isrgb8 ? 7 : 3);
1918 b = av_clip(b, 0, isrgb8 ? 3 : 1);
1919 err[0] = R - r*(isrgb8 ? 36 : 255);
1920 err[1] = G - g*(isrgb8 ? 36 : 85);
1921 err[2] = B - b*(isrgb8 ? 85 : 255);
1923 case SWS_DITHER_A_DITHER:
1925 /* see http://pippin.gimp.org/a_dither/ for details/origin */
1926 #define A_DITHER(u,v) (((((u)+((v)*236))*119)&0xff))
1927 r = (((R >> 19) + A_DITHER(i,y) -96)>>8);
1928 g = (((G >> 19) + A_DITHER(i + 17,y) - 96)>>8);
1929 b = (((B >> 20) + A_DITHER(i + 17*2,y) -96)>>8);
1930 r = av_clip_uintp2(r, 3);
1931 g = av_clip_uintp2(g, 3);
1932 b = av_clip_uintp2(b, 2);
1934 r = (((R >> 21) + A_DITHER(i,y)-256)>>8);
1935 g = (((G >> 19) + A_DITHER(i + 17,y)-256)>>8);
1936 b = (((B >> 21) + A_DITHER(i + 17*2,y)-256)>>8);
1937 r = av_clip_uintp2(r, 1);
1938 g = av_clip_uintp2(g, 2);
1939 b = av_clip_uintp2(b, 1);
1942 case SWS_DITHER_X_DITHER:
1944 /* see http://pippin.gimp.org/a_dither/ for details/origin */
1945 #define X_DITHER(u,v) (((((u)^((v)*237))*181)&0x1ff)/2)
1946 r = (((R >> 19) + X_DITHER(i,y) - 96)>>8);
1947 g = (((G >> 19) + X_DITHER(i + 17,y) - 96)>>8);
1948 b = (((B >> 20) + X_DITHER(i + 17*2,y) - 96)>>8);
1949 r = av_clip_uintp2(r, 3);
1950 g = av_clip_uintp2(g, 3);
1951 b = av_clip_uintp2(b, 2);
1953 r = (((R >> 21) + X_DITHER(i,y)-256)>>8);
1954 g = (((G >> 19) + X_DITHER(i + 17,y)-256)>>8);
1955 b = (((B >> 21) + X_DITHER(i + 17*2,y)-256)>>8);
1956 r = av_clip_uintp2(r, 1);
1957 g = av_clip_uintp2(g, 2);
1958 b = av_clip_uintp2(b, 1);
1964 if(target == AV_PIX_FMT_BGR4_BYTE) {
1965 dest[0] = r + 2*g + 8*b;
1966 } else if(target == AV_PIX_FMT_RGB4_BYTE) {
1967 dest[0] = b + 2*g + 8*r;
1968 } else if(target == AV_PIX_FMT_BGR8) {
1969 dest[0] = r + 8*g + 64*b;
1970 } else if(target == AV_PIX_FMT_RGB8) {
1971 dest[0] = b + 4*g + 32*r;
1978 static av_always_inline void
1979 yuv2rgb_full_X_c_template(SwsContext *c, const int16_t *lumFilter,
1980 const int16_t **lumSrc, int lumFilterSize,
1981 const int16_t *chrFilter, const int16_t **chrUSrc,
1982 const int16_t **chrVSrc, int chrFilterSize,
1983 const int16_t **alpSrc, uint8_t *dest,
1984 int dstW, int y, enum AVPixelFormat target, int hasAlpha)
1987 int step = (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) ? 3 : 4;
1989 int A = 0; //init to silence warning
1991 if( target == AV_PIX_FMT_BGR4_BYTE || target == AV_PIX_FMT_RGB4_BYTE
1992 || target == AV_PIX_FMT_BGR8 || target == AV_PIX_FMT_RGB8)
1995 for (i = 0; i < dstW; i++) {
1998 int U = (1<<9)-(128 << 19);
1999 int V = (1<<9)-(128 << 19);
2001 for (j = 0; j < lumFilterSize; j++) {
2002 Y += lumSrc[j][i] * lumFilter[j];
2004 for (j = 0; j < chrFilterSize; j++) {
2005 U += chrUSrc[j][i] * chrFilter[j];
2006 V += chrVSrc[j][i] * chrFilter[j];
2013 for (j = 0; j < lumFilterSize; j++) {
2014 A += alpSrc[j][i] * lumFilter[j];
2018 A = av_clip_uint8(A);
2020 yuv2rgb_write_full(c, dest, i, Y, A, U, V, y, target, hasAlpha, err);
2023 c->dither_error[0][i] = err[0];
2024 c->dither_error[1][i] = err[1];
2025 c->dither_error[2][i] = err[2];
2028 static av_always_inline void
2029 yuv2rgb_full_2_c_template(SwsContext *c, const int16_t *buf[2],
2030 const int16_t *ubuf[2], const int16_t *vbuf[2],
2031 const int16_t *abuf[2], uint8_t *dest, int dstW,
2032 int yalpha, int uvalpha, int y,
2033 enum AVPixelFormat target, int hasAlpha)
2035 const int16_t *buf0 = buf[0], *buf1 = buf[1],
2036 *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
2037 *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
2038 *abuf0 = hasAlpha ? abuf[0] : NULL,
2039 *abuf1 = hasAlpha ? abuf[1] : NULL;
2040 int yalpha1 = 4096 - yalpha;
2041 int uvalpha1 = 4096 - uvalpha;
2043 int step = (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) ? 3 : 4;
2045 int A = 0; // init to silcene warning
2047 av_assert2(yalpha <= 4096U);
2048 av_assert2(uvalpha <= 4096U);
2050 if( target == AV_PIX_FMT_BGR4_BYTE || target == AV_PIX_FMT_RGB4_BYTE
2051 || target == AV_PIX_FMT_BGR8 || target == AV_PIX_FMT_RGB8)
2054 for (i = 0; i < dstW; i++) {
2055 int Y = ( buf0[i] * yalpha1 + buf1[i] * yalpha ) >> 10; //FIXME rounding
2056 int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha-(128 << 19)) >> 10;
2057 int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha-(128 << 19)) >> 10;
2060 A = (abuf0[i] * yalpha1 + abuf1[i] * yalpha + (1<<18)) >> 19;
2062 A = av_clip_uint8(A);
2065 yuv2rgb_write_full(c, dest, i, Y, A, U, V, y, target, hasAlpha, err);
2068 c->dither_error[0][i] = err[0];
2069 c->dither_error[1][i] = err[1];
2070 c->dither_error[2][i] = err[2];
2073 static av_always_inline void
2074 yuv2rgb_full_1_c_template(SwsContext *c, const int16_t *buf0,
2075 const int16_t *ubuf[2], const int16_t *vbuf[2],
2076 const int16_t *abuf0, uint8_t *dest, int dstW,
2077 int uvalpha, int y, enum AVPixelFormat target,
2080 const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
2082 int step = (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) ? 3 : 4;
2085 if( target == AV_PIX_FMT_BGR4_BYTE || target == AV_PIX_FMT_RGB4_BYTE
2086 || target == AV_PIX_FMT_BGR8 || target == AV_PIX_FMT_RGB8)
2089 if (uvalpha < 2048) {
2090 int A = 0; //init to silence warning
2091 for (i = 0; i < dstW; i++) {
2092 int Y = buf0[i] << 2;
2093 int U = (ubuf0[i] - (128<<7)) * 4;
2094 int V = (vbuf0[i] - (128<<7)) * 4;
2097 A = (abuf0[i] + 64) >> 7;
2099 A = av_clip_uint8(A);
2102 yuv2rgb_write_full(c, dest, i, Y, A, U, V, y, target, hasAlpha, err);
2106 const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
2107 int A = 0; //init to silence warning
2108 for (i = 0; i < dstW; i++) {
2109 int Y = buf0[i] << 2;
2110 int U = (ubuf0[i] + ubuf1[i] - (128<<8)) << 1;
2111 int V = (vbuf0[i] + vbuf1[i] - (128<<8)) << 1;
2114 A = (abuf0[i] + 64) >> 7;
2116 A = av_clip_uint8(A);
2119 yuv2rgb_write_full(c, dest, i, Y, A, U, V, y, target, hasAlpha, err);
2124 c->dither_error[0][i] = err[0];
2125 c->dither_error[1][i] = err[1];
2126 c->dither_error[2][i] = err[2];
2130 YUV2RGBWRAPPER(yuv2, rgb_full, bgra32_full, AV_PIX_FMT_BGRA, CONFIG_SWSCALE_ALPHA && c->needAlpha)
2131 YUV2RGBWRAPPER(yuv2, rgb_full, abgr32_full, AV_PIX_FMT_ABGR, CONFIG_SWSCALE_ALPHA && c->needAlpha)
2132 YUV2RGBWRAPPER(yuv2, rgb_full, rgba32_full, AV_PIX_FMT_RGBA, CONFIG_SWSCALE_ALPHA && c->needAlpha)
2133 YUV2RGBWRAPPER(yuv2, rgb_full, argb32_full, AV_PIX_FMT_ARGB, CONFIG_SWSCALE_ALPHA && c->needAlpha)
2135 #if CONFIG_SWSCALE_ALPHA
2136 YUV2RGBWRAPPER(yuv2, rgb_full, bgra32_full, AV_PIX_FMT_BGRA, 1)
2137 YUV2RGBWRAPPER(yuv2, rgb_full, abgr32_full, AV_PIX_FMT_ABGR, 1)
2138 YUV2RGBWRAPPER(yuv2, rgb_full, rgba32_full, AV_PIX_FMT_RGBA, 1)
2139 YUV2RGBWRAPPER(yuv2, rgb_full, argb32_full, AV_PIX_FMT_ARGB, 1)
2141 YUV2RGBWRAPPER(yuv2, rgb_full, bgrx32_full, AV_PIX_FMT_BGRA, 0)
2142 YUV2RGBWRAPPER(yuv2, rgb_full, xbgr32_full, AV_PIX_FMT_ABGR, 0)
2143 YUV2RGBWRAPPER(yuv2, rgb_full, rgbx32_full, AV_PIX_FMT_RGBA, 0)
2144 YUV2RGBWRAPPER(yuv2, rgb_full, xrgb32_full, AV_PIX_FMT_ARGB, 0)
2146 YUV2RGBWRAPPER(yuv2, rgb_full, bgr24_full, AV_PIX_FMT_BGR24, 0)
2147 YUV2RGBWRAPPER(yuv2, rgb_full, rgb24_full, AV_PIX_FMT_RGB24, 0)
2149 YUV2RGBWRAPPER(yuv2, rgb_full, bgr4_byte_full, AV_PIX_FMT_BGR4_BYTE, 0)
2150 YUV2RGBWRAPPER(yuv2, rgb_full, rgb4_byte_full, AV_PIX_FMT_RGB4_BYTE, 0)
2151 YUV2RGBWRAPPER(yuv2, rgb_full, bgr8_full, AV_PIX_FMT_BGR8, 0)
2152 YUV2RGBWRAPPER(yuv2, rgb_full, rgb8_full, AV_PIX_FMT_RGB8, 0)
2155 yuv2gbrp_full_X_c(SwsContext *c, const int16_t *lumFilter,
2156 const int16_t **lumSrc, int lumFilterSize,
2157 const int16_t *chrFilter, const int16_t **chrUSrc,
2158 const int16_t **chrVSrc, int chrFilterSize,
2159 const int16_t **alpSrc, uint8_t **dest,
2162 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->dstFormat);
2164 int hasAlpha = (desc->flags & AV_PIX_FMT_FLAG_ALPHA) && alpSrc;
2165 uint16_t **dest16 = (uint16_t**)dest;
2166 int SH = 22 + 8 - desc->comp[0].depth;
2167 int A = 0; // init to silence warning
2169 for (i = 0; i < dstW; i++) {
2172 int U = (1 << 9) - (128 << 19);
2173 int V = (1 << 9) - (128 << 19);
2176 for (j = 0; j < lumFilterSize; j++)
2177 Y += lumSrc[j][i] * lumFilter[j];
2179 for (j = 0; j < chrFilterSize; j++) {
2180 U += chrUSrc[j][i] * chrFilter[j];
2181 V += chrVSrc[j][i] * chrFilter[j];
2191 for (j = 0; j < lumFilterSize; j++)
2192 A += alpSrc[j][i] * lumFilter[j];
2195 A = av_clip_uintp2(A, 27);
2198 Y -= c->yuv2rgb_y_offset;
2199 Y *= c->yuv2rgb_y_coeff;
2201 R = Y + V * c->yuv2rgb_v2r_coeff;
2202 G = Y + V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
2203 B = Y + U * c->yuv2rgb_u2b_coeff;
2205 if ((R | G | B) & 0xC0000000) {
2206 R = av_clip_uintp2(R, 30);
2207 G = av_clip_uintp2(G, 30);
2208 B = av_clip_uintp2(B, 30);
2212 dest16[0][i] = G >> SH;
2213 dest16[1][i] = B >> SH;
2214 dest16[2][i] = R >> SH;
2216 dest16[3][i] = A >> (SH - 3);
2218 dest[0][i] = G >> 22;
2219 dest[1][i] = B >> 22;
2220 dest[2][i] = R >> 22;
2222 dest[3][i] = A >> 19;
2225 if (SH != 22 && (!isBE(c->dstFormat)) != (!HAVE_BIGENDIAN)) {
2226 for (i = 0; i < dstW; i++) {
2227 dest16[0][i] = av_bswap16(dest16[0][i]);
2228 dest16[1][i] = av_bswap16(dest16[1][i]);
2229 dest16[2][i] = av_bswap16(dest16[2][i]);
2231 dest16[3][i] = av_bswap16(dest16[3][i]);
2237 yuv2gbrp16_full_X_c(SwsContext *c, const int16_t *lumFilter,
2238 const int16_t **lumSrcx, int lumFilterSize,
2239 const int16_t *chrFilter, const int16_t **chrUSrcx,
2240 const int16_t **chrVSrcx, int chrFilterSize,
2241 const int16_t **alpSrcx, uint8_t **dest,
2244 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->dstFormat);
2246 int hasAlpha = (desc->flags & AV_PIX_FMT_FLAG_ALPHA) && alpSrcx;
2247 uint16_t **dest16 = (uint16_t**)dest;
2248 const int32_t **lumSrc = (const int32_t**)lumSrcx;
2249 const int32_t **chrUSrc = (const int32_t**)chrUSrcx;
2250 const int32_t **chrVSrc = (const int32_t**)chrVSrcx;
2251 const int32_t **alpSrc = (const int32_t**)alpSrcx;
2253 for (i = 0; i < dstW; i++) {
2255 int Y = -0x40000000;
2256 int U = -(128 << 23);
2257 int V = -(128 << 23);
2260 for (j = 0; j < lumFilterSize; j++)
2261 Y += lumSrc[j][i] * (unsigned)lumFilter[j];
2263 for (j = 0; j < chrFilterSize; j++) {
2264 U += chrUSrc[j][i] * (unsigned)chrFilter[j];
2265 V += chrVSrc[j][i] * (unsigned)chrFilter[j];
2276 for (j = 0; j < lumFilterSize; j++)
2277 A += alpSrc[j][i] * lumFilter[j];
2283 Y -= c->yuv2rgb_y_offset;
2284 Y *= c->yuv2rgb_y_coeff;
2286 R = V * c->yuv2rgb_v2r_coeff;
2287 G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
2288 B = U * c->yuv2rgb_u2b_coeff;
2290 R = av_clip_uintp2(Y + R, 30);
2291 G = av_clip_uintp2(Y + G, 30);
2292 B = av_clip_uintp2(Y + B, 30);
2294 dest16[0][i] = G >> 14;
2295 dest16[1][i] = B >> 14;
2296 dest16[2][i] = R >> 14;
2298 dest16[3][i] = av_clip_uintp2(A, 30) >> 14;
2300 if ((!isBE(c->dstFormat)) != (!HAVE_BIGENDIAN)) {
2301 for (i = 0; i < dstW; i++) {
2302 dest16[0][i] = av_bswap16(dest16[0][i]);
2303 dest16[1][i] = av_bswap16(dest16[1][i]);
2304 dest16[2][i] = av_bswap16(dest16[2][i]);
2306 dest16[3][i] = av_bswap16(dest16[3][i]);
2312 yuv2ya8_1_c(SwsContext *c, const int16_t *buf0,
2313 const int16_t *ubuf[2], const int16_t *vbuf[2],
2314 const int16_t *abuf0, uint8_t *dest, int dstW,
2317 int hasAlpha = !!abuf0;
2320 for (i = 0; i < dstW; i++) {
2321 int Y = (buf0[i] + 64) >> 7;
2324 Y = av_clip_uint8(Y);
2327 A = (abuf0[i] + 64) >> 7;
2329 A = av_clip_uint8(A);
2333 dest[i * 2 + 1] = hasAlpha ? A : 255;
2338 yuv2ya8_2_c(SwsContext *c, const int16_t *buf[2],
2339 const int16_t *ubuf[2], const int16_t *vbuf[2],
2340 const int16_t *abuf[2], uint8_t *dest, int dstW,
2341 int yalpha, int uvalpha, int y)
2343 int hasAlpha = abuf && abuf[0] && abuf[1];
2344 const int16_t *buf0 = buf[0], *buf1 = buf[1],
2345 *abuf0 = hasAlpha ? abuf[0] : NULL,
2346 *abuf1 = hasAlpha ? abuf[1] : NULL;
2347 int yalpha1 = 4096 - yalpha;
2350 av_assert2(yalpha <= 4096U);
2352 for (i = 0; i < dstW; i++) {
2353 int Y = (buf0[i] * yalpha1 + buf1[i] * yalpha) >> 19;
2356 Y = av_clip_uint8(Y);
2359 A = (abuf0[i] * yalpha1 + abuf1[i] * yalpha) >> 19;
2360 A = av_clip_uint8(A);
2364 dest[i * 2 + 1] = hasAlpha ? A : 255;
2369 yuv2ya8_X_c(SwsContext *c, const int16_t *lumFilter,
2370 const int16_t **lumSrc, int lumFilterSize,
2371 const int16_t *chrFilter, const int16_t **chrUSrc,
2372 const int16_t **chrVSrc, int chrFilterSize,
2373 const int16_t **alpSrc, uint8_t *dest, int dstW, int y)
2375 int hasAlpha = !!alpSrc;
2378 for (i = 0; i < dstW; i++) {
2380 int Y = 1 << 18, A = 1 << 18;
2382 for (j = 0; j < lumFilterSize; j++)
2383 Y += lumSrc[j][i] * lumFilter[j];
2387 Y = av_clip_uint8(Y);
2390 for (j = 0; j < lumFilterSize; j++)
2391 A += alpSrc[j][i] * lumFilter[j];
2396 A = av_clip_uint8(A);
2400 dest[2 * i + 1] = hasAlpha ? A : 255;
2405 yuv2ayuv64le_X_c(SwsContext *c, const int16_t *lumFilter,
2406 const int16_t **_lumSrc, int lumFilterSize,
2407 const int16_t *chrFilter, const int16_t **_chrUSrc,
2408 const int16_t **_chrVSrc, int chrFilterSize,
2409 const int16_t **_alpSrc, uint8_t *dest, int dstW, int y)
2411 const int32_t **lumSrc = (const int32_t **) _lumSrc,
2412 **chrUSrc = (const int32_t **) _chrUSrc,
2413 **chrVSrc = (const int32_t **) _chrVSrc,
2414 **alpSrc = (const int32_t **) _alpSrc;
2415 int hasAlpha = !!alpSrc;
2418 for (i = 0; i < dstW; i++) {
2419 int Y = 1 << 14, U = 1 << 14;
2420 int V = 1 << 14, A = 1 << 14;
2428 for (j = 0; j < lumFilterSize; j++)
2429 Y += lumSrc[j][i] * (unsigned)lumFilter[j];
2431 for (j = 0; j < chrFilterSize; j++)
2432 U += chrUSrc[j][i] * (unsigned)chrFilter[j];
2434 for (j = 0; j < chrFilterSize; j++)
2435 V += chrVSrc[j][i] * (unsigned)chrFilter[j];
2438 for (j = 0; j < lumFilterSize; j++)
2439 A += alpSrc[j][i] * (unsigned)lumFilter[j];
2441 Y = 0x8000 + av_clip_int16(Y >> 15);
2442 U = 0x8000 + av_clip_int16(U >> 15);
2443 V = 0x8000 + av_clip_int16(V >> 15);
2444 A = 0x8000 + av_clip_int16(A >> 15);
2446 AV_WL16(dest + 8 * i, hasAlpha ? A : 65535);
2447 AV_WL16(dest + 8 * i + 2, Y);
2448 AV_WL16(dest + 8 * i + 4, U);
2449 AV_WL16(dest + 8 * i + 6, V);
2453 av_cold void ff_sws_init_output_funcs(SwsContext *c,
2454 yuv2planar1_fn *yuv2plane1,
2455 yuv2planarX_fn *yuv2planeX,
2456 yuv2interleavedX_fn *yuv2nv12cX,
2457 yuv2packed1_fn *yuv2packed1,
2458 yuv2packed2_fn *yuv2packed2,
2459 yuv2packedX_fn *yuv2packedX,
2460 yuv2anyX_fn *yuv2anyX)
2462 enum AVPixelFormat dstFormat = c->dstFormat;
2463 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(dstFormat);
2465 if (dstFormat == AV_PIX_FMT_P010LE || dstFormat == AV_PIX_FMT_P010BE) {
2466 *yuv2plane1 = isBE(dstFormat) ? yuv2p010l1_BE_c : yuv2p010l1_LE_c;
2467 *yuv2planeX = isBE(dstFormat) ? yuv2p010lX_BE_c : yuv2p010lX_LE_c;
2468 *yuv2nv12cX = yuv2p010cX_c;
2469 } else if (is16BPS(dstFormat)) {
2470 *yuv2planeX = isBE(dstFormat) ? yuv2planeX_16BE_c : yuv2planeX_16LE_c;
2471 *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_16BE_c : yuv2plane1_16LE_c;
2472 if (dstFormat == AV_PIX_FMT_P016LE || dstFormat == AV_PIX_FMT_P016BE) {
2473 *yuv2nv12cX = yuv2p016cX_c;
2475 } else if (isNBPS(dstFormat)) {
2476 if (desc->comp[0].depth == 9) {
2477 *yuv2planeX = isBE(dstFormat) ? yuv2planeX_9BE_c : yuv2planeX_9LE_c;
2478 *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_9BE_c : yuv2plane1_9LE_c;
2479 } else if (desc->comp[0].depth == 10) {
2480 *yuv2planeX = isBE(dstFormat) ? yuv2planeX_10BE_c : yuv2planeX_10LE_c;
2481 *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_10BE_c : yuv2plane1_10LE_c;
2482 } else if (desc->comp[0].depth == 12) {
2483 *yuv2planeX = isBE(dstFormat) ? yuv2planeX_12BE_c : yuv2planeX_12LE_c;
2484 *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_12BE_c : yuv2plane1_12LE_c;
2485 } else if (desc->comp[0].depth == 14) {
2486 *yuv2planeX = isBE(dstFormat) ? yuv2planeX_14BE_c : yuv2planeX_14LE_c;
2487 *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_14BE_c : yuv2plane1_14LE_c;
2490 } else if (dstFormat == AV_PIX_FMT_GRAYF32BE) {
2491 *yuv2planeX = yuv2planeX_floatBE_c;
2492 *yuv2plane1 = yuv2plane1_floatBE_c;
2493 } else if (dstFormat == AV_PIX_FMT_GRAYF32LE) {
2494 *yuv2planeX = yuv2planeX_floatLE_c;
2495 *yuv2plane1 = yuv2plane1_floatLE_c;
2497 *yuv2plane1 = yuv2plane1_8_c;
2498 *yuv2planeX = yuv2planeX_8_c;
2499 if (dstFormat == AV_PIX_FMT_NV12 || dstFormat == AV_PIX_FMT_NV21)
2500 *yuv2nv12cX = yuv2nv12cX_c;
2503 if(c->flags & SWS_FULL_CHR_H_INT) {
2504 switch (dstFormat) {
2505 case AV_PIX_FMT_RGBA:
2507 *yuv2packedX = yuv2rgba32_full_X_c;
2508 *yuv2packed2 = yuv2rgba32_full_2_c;
2509 *yuv2packed1 = yuv2rgba32_full_1_c;
2511 #if CONFIG_SWSCALE_ALPHA
2513 *yuv2packedX = yuv2rgba32_full_X_c;
2514 *yuv2packed2 = yuv2rgba32_full_2_c;
2515 *yuv2packed1 = yuv2rgba32_full_1_c;
2517 #endif /* CONFIG_SWSCALE_ALPHA */
2519 *yuv2packedX = yuv2rgbx32_full_X_c;
2520 *yuv2packed2 = yuv2rgbx32_full_2_c;
2521 *yuv2packed1 = yuv2rgbx32_full_1_c;
2523 #endif /* !CONFIG_SMALL */
2525 case AV_PIX_FMT_ARGB:
2527 *yuv2packedX = yuv2argb32_full_X_c;
2528 *yuv2packed2 = yuv2argb32_full_2_c;
2529 *yuv2packed1 = yuv2argb32_full_1_c;
2531 #if CONFIG_SWSCALE_ALPHA
2533 *yuv2packedX = yuv2argb32_full_X_c;
2534 *yuv2packed2 = yuv2argb32_full_2_c;
2535 *yuv2packed1 = yuv2argb32_full_1_c;
2537 #endif /* CONFIG_SWSCALE_ALPHA */
2539 *yuv2packedX = yuv2xrgb32_full_X_c;
2540 *yuv2packed2 = yuv2xrgb32_full_2_c;
2541 *yuv2packed1 = yuv2xrgb32_full_1_c;
2543 #endif /* !CONFIG_SMALL */
2545 case AV_PIX_FMT_BGRA:
2547 *yuv2packedX = yuv2bgra32_full_X_c;
2548 *yuv2packed2 = yuv2bgra32_full_2_c;
2549 *yuv2packed1 = yuv2bgra32_full_1_c;
2551 #if CONFIG_SWSCALE_ALPHA
2553 *yuv2packedX = yuv2bgra32_full_X_c;
2554 *yuv2packed2 = yuv2bgra32_full_2_c;
2555 *yuv2packed1 = yuv2bgra32_full_1_c;
2557 #endif /* CONFIG_SWSCALE_ALPHA */
2559 *yuv2packedX = yuv2bgrx32_full_X_c;
2560 *yuv2packed2 = yuv2bgrx32_full_2_c;
2561 *yuv2packed1 = yuv2bgrx32_full_1_c;
2563 #endif /* !CONFIG_SMALL */
2565 case AV_PIX_FMT_ABGR:
2567 *yuv2packedX = yuv2abgr32_full_X_c;
2568 *yuv2packed2 = yuv2abgr32_full_2_c;
2569 *yuv2packed1 = yuv2abgr32_full_1_c;
2571 #if CONFIG_SWSCALE_ALPHA
2573 *yuv2packedX = yuv2abgr32_full_X_c;
2574 *yuv2packed2 = yuv2abgr32_full_2_c;
2575 *yuv2packed1 = yuv2abgr32_full_1_c;
2577 #endif /* CONFIG_SWSCALE_ALPHA */
2579 *yuv2packedX = yuv2xbgr32_full_X_c;
2580 *yuv2packed2 = yuv2xbgr32_full_2_c;
2581 *yuv2packed1 = yuv2xbgr32_full_1_c;
2583 #endif /* !CONFIG_SMALL */
2585 case AV_PIX_FMT_RGBA64LE:
2586 #if CONFIG_SWSCALE_ALPHA
2588 *yuv2packedX = yuv2rgba64le_full_X_c;
2589 *yuv2packed2 = yuv2rgba64le_full_2_c;
2590 *yuv2packed1 = yuv2rgba64le_full_1_c;
2592 #endif /* CONFIG_SWSCALE_ALPHA */
2594 *yuv2packedX = yuv2rgbx64le_full_X_c;
2595 *yuv2packed2 = yuv2rgbx64le_full_2_c;
2596 *yuv2packed1 = yuv2rgbx64le_full_1_c;
2599 case AV_PIX_FMT_RGBA64BE:
2600 #if CONFIG_SWSCALE_ALPHA
2602 *yuv2packedX = yuv2rgba64be_full_X_c;
2603 *yuv2packed2 = yuv2rgba64be_full_2_c;
2604 *yuv2packed1 = yuv2rgba64be_full_1_c;
2606 #endif /* CONFIG_SWSCALE_ALPHA */
2608 *yuv2packedX = yuv2rgbx64be_full_X_c;
2609 *yuv2packed2 = yuv2rgbx64be_full_2_c;
2610 *yuv2packed1 = yuv2rgbx64be_full_1_c;
2613 case AV_PIX_FMT_BGRA64LE:
2614 #if CONFIG_SWSCALE_ALPHA
2616 *yuv2packedX = yuv2bgra64le_full_X_c;
2617 *yuv2packed2 = yuv2bgra64le_full_2_c;
2618 *yuv2packed1 = yuv2bgra64le_full_1_c;
2620 #endif /* CONFIG_SWSCALE_ALPHA */
2622 *yuv2packedX = yuv2bgrx64le_full_X_c;
2623 *yuv2packed2 = yuv2bgrx64le_full_2_c;
2624 *yuv2packed1 = yuv2bgrx64le_full_1_c;
2627 case AV_PIX_FMT_BGRA64BE:
2628 #if CONFIG_SWSCALE_ALPHA
2630 *yuv2packedX = yuv2bgra64be_full_X_c;
2631 *yuv2packed2 = yuv2bgra64be_full_2_c;
2632 *yuv2packed1 = yuv2bgra64be_full_1_c;
2634 #endif /* CONFIG_SWSCALE_ALPHA */
2636 *yuv2packedX = yuv2bgrx64be_full_X_c;
2637 *yuv2packed2 = yuv2bgrx64be_full_2_c;
2638 *yuv2packed1 = yuv2bgrx64be_full_1_c;
2642 case AV_PIX_FMT_RGB24:
2643 *yuv2packedX = yuv2rgb24_full_X_c;
2644 *yuv2packed2 = yuv2rgb24_full_2_c;
2645 *yuv2packed1 = yuv2rgb24_full_1_c;
2647 case AV_PIX_FMT_BGR24:
2648 *yuv2packedX = yuv2bgr24_full_X_c;
2649 *yuv2packed2 = yuv2bgr24_full_2_c;
2650 *yuv2packed1 = yuv2bgr24_full_1_c;
2652 case AV_PIX_FMT_RGB48LE:
2653 *yuv2packedX = yuv2rgb48le_full_X_c;
2654 *yuv2packed2 = yuv2rgb48le_full_2_c;
2655 *yuv2packed1 = yuv2rgb48le_full_1_c;
2657 case AV_PIX_FMT_BGR48LE:
2658 *yuv2packedX = yuv2bgr48le_full_X_c;
2659 *yuv2packed2 = yuv2bgr48le_full_2_c;
2660 *yuv2packed1 = yuv2bgr48le_full_1_c;
2662 case AV_PIX_FMT_RGB48BE:
2663 *yuv2packedX = yuv2rgb48be_full_X_c;
2664 *yuv2packed2 = yuv2rgb48be_full_2_c;
2665 *yuv2packed1 = yuv2rgb48be_full_1_c;
2667 case AV_PIX_FMT_BGR48BE:
2668 *yuv2packedX = yuv2bgr48be_full_X_c;
2669 *yuv2packed2 = yuv2bgr48be_full_2_c;
2670 *yuv2packed1 = yuv2bgr48be_full_1_c;
2672 case AV_PIX_FMT_BGR4_BYTE:
2673 *yuv2packedX = yuv2bgr4_byte_full_X_c;
2674 *yuv2packed2 = yuv2bgr4_byte_full_2_c;
2675 *yuv2packed1 = yuv2bgr4_byte_full_1_c;
2677 case AV_PIX_FMT_RGB4_BYTE:
2678 *yuv2packedX = yuv2rgb4_byte_full_X_c;
2679 *yuv2packed2 = yuv2rgb4_byte_full_2_c;
2680 *yuv2packed1 = yuv2rgb4_byte_full_1_c;
2682 case AV_PIX_FMT_BGR8:
2683 *yuv2packedX = yuv2bgr8_full_X_c;
2684 *yuv2packed2 = yuv2bgr8_full_2_c;
2685 *yuv2packed1 = yuv2bgr8_full_1_c;
2687 case AV_PIX_FMT_RGB8:
2688 *yuv2packedX = yuv2rgb8_full_X_c;
2689 *yuv2packed2 = yuv2rgb8_full_2_c;
2690 *yuv2packed1 = yuv2rgb8_full_1_c;
2692 case AV_PIX_FMT_GBRP:
2693 case AV_PIX_FMT_GBRP9BE:
2694 case AV_PIX_FMT_GBRP9LE:
2695 case AV_PIX_FMT_GBRP10BE:
2696 case AV_PIX_FMT_GBRP10LE:
2697 case AV_PIX_FMT_GBRP12BE:
2698 case AV_PIX_FMT_GBRP12LE:
2699 case AV_PIX_FMT_GBRP14BE:
2700 case AV_PIX_FMT_GBRP14LE:
2701 case AV_PIX_FMT_GBRAP:
2702 case AV_PIX_FMT_GBRAP10BE:
2703 case AV_PIX_FMT_GBRAP10LE:
2704 case AV_PIX_FMT_GBRAP12BE:
2705 case AV_PIX_FMT_GBRAP12LE:
2706 *yuv2anyX = yuv2gbrp_full_X_c;
2708 case AV_PIX_FMT_GBRP16BE:
2709 case AV_PIX_FMT_GBRP16LE:
2710 case AV_PIX_FMT_GBRAP16BE:
2711 case AV_PIX_FMT_GBRAP16LE:
2712 *yuv2anyX = yuv2gbrp16_full_X_c;
2715 if (!*yuv2packedX && !*yuv2anyX)
2719 switch (dstFormat) {
2720 case AV_PIX_FMT_RGBA64LE:
2721 #if CONFIG_SWSCALE_ALPHA
2723 *yuv2packed1 = yuv2rgba64le_1_c;
2724 *yuv2packed2 = yuv2rgba64le_2_c;
2725 *yuv2packedX = yuv2rgba64le_X_c;
2727 #endif /* CONFIG_SWSCALE_ALPHA */
2729 *yuv2packed1 = yuv2rgbx64le_1_c;
2730 *yuv2packed2 = yuv2rgbx64le_2_c;
2731 *yuv2packedX = yuv2rgbx64le_X_c;
2734 case AV_PIX_FMT_RGBA64BE:
2735 #if CONFIG_SWSCALE_ALPHA
2737 *yuv2packed1 = yuv2rgba64be_1_c;
2738 *yuv2packed2 = yuv2rgba64be_2_c;
2739 *yuv2packedX = yuv2rgba64be_X_c;
2741 #endif /* CONFIG_SWSCALE_ALPHA */
2743 *yuv2packed1 = yuv2rgbx64be_1_c;
2744 *yuv2packed2 = yuv2rgbx64be_2_c;
2745 *yuv2packedX = yuv2rgbx64be_X_c;
2748 case AV_PIX_FMT_BGRA64LE:
2749 #if CONFIG_SWSCALE_ALPHA
2751 *yuv2packed1 = yuv2bgra64le_1_c;
2752 *yuv2packed2 = yuv2bgra64le_2_c;
2753 *yuv2packedX = yuv2bgra64le_X_c;
2755 #endif /* CONFIG_SWSCALE_ALPHA */
2757 *yuv2packed1 = yuv2bgrx64le_1_c;
2758 *yuv2packed2 = yuv2bgrx64le_2_c;
2759 *yuv2packedX = yuv2bgrx64le_X_c;
2762 case AV_PIX_FMT_BGRA64BE:
2763 #if CONFIG_SWSCALE_ALPHA
2765 *yuv2packed1 = yuv2bgra64be_1_c;
2766 *yuv2packed2 = yuv2bgra64be_2_c;
2767 *yuv2packedX = yuv2bgra64be_X_c;
2769 #endif /* CONFIG_SWSCALE_ALPHA */
2771 *yuv2packed1 = yuv2bgrx64be_1_c;
2772 *yuv2packed2 = yuv2bgrx64be_2_c;
2773 *yuv2packedX = yuv2bgrx64be_X_c;
2776 case AV_PIX_FMT_RGB48LE:
2777 *yuv2packed1 = yuv2rgb48le_1_c;
2778 *yuv2packed2 = yuv2rgb48le_2_c;
2779 *yuv2packedX = yuv2rgb48le_X_c;
2781 case AV_PIX_FMT_RGB48BE:
2782 *yuv2packed1 = yuv2rgb48be_1_c;
2783 *yuv2packed2 = yuv2rgb48be_2_c;
2784 *yuv2packedX = yuv2rgb48be_X_c;
2786 case AV_PIX_FMT_BGR48LE:
2787 *yuv2packed1 = yuv2bgr48le_1_c;
2788 *yuv2packed2 = yuv2bgr48le_2_c;
2789 *yuv2packedX = yuv2bgr48le_X_c;
2791 case AV_PIX_FMT_BGR48BE:
2792 *yuv2packed1 = yuv2bgr48be_1_c;
2793 *yuv2packed2 = yuv2bgr48be_2_c;
2794 *yuv2packedX = yuv2bgr48be_X_c;
2796 case AV_PIX_FMT_RGB32:
2797 case AV_PIX_FMT_BGR32:
2799 *yuv2packed1 = yuv2rgb32_1_c;
2800 *yuv2packed2 = yuv2rgb32_2_c;
2801 *yuv2packedX = yuv2rgb32_X_c;
2803 #if CONFIG_SWSCALE_ALPHA
2805 *yuv2packed1 = yuv2rgba32_1_c;
2806 *yuv2packed2 = yuv2rgba32_2_c;
2807 *yuv2packedX = yuv2rgba32_X_c;
2809 #endif /* CONFIG_SWSCALE_ALPHA */
2811 *yuv2packed1 = yuv2rgbx32_1_c;
2812 *yuv2packed2 = yuv2rgbx32_2_c;
2813 *yuv2packedX = yuv2rgbx32_X_c;
2815 #endif /* !CONFIG_SMALL */
2817 case AV_PIX_FMT_RGB32_1:
2818 case AV_PIX_FMT_BGR32_1:
2820 *yuv2packed1 = yuv2rgb32_1_1_c;
2821 *yuv2packed2 = yuv2rgb32_1_2_c;
2822 *yuv2packedX = yuv2rgb32_1_X_c;
2824 #if CONFIG_SWSCALE_ALPHA
2826 *yuv2packed1 = yuv2rgba32_1_1_c;
2827 *yuv2packed2 = yuv2rgba32_1_2_c;
2828 *yuv2packedX = yuv2rgba32_1_X_c;
2830 #endif /* CONFIG_SWSCALE_ALPHA */
2832 *yuv2packed1 = yuv2rgbx32_1_1_c;
2833 *yuv2packed2 = yuv2rgbx32_1_2_c;
2834 *yuv2packedX = yuv2rgbx32_1_X_c;
2836 #endif /* !CONFIG_SMALL */
2838 case AV_PIX_FMT_RGB24:
2839 *yuv2packed1 = yuv2rgb24_1_c;
2840 *yuv2packed2 = yuv2rgb24_2_c;
2841 *yuv2packedX = yuv2rgb24_X_c;
2843 case AV_PIX_FMT_BGR24:
2844 *yuv2packed1 = yuv2bgr24_1_c;
2845 *yuv2packed2 = yuv2bgr24_2_c;
2846 *yuv2packedX = yuv2bgr24_X_c;
2848 case AV_PIX_FMT_RGB565LE:
2849 case AV_PIX_FMT_RGB565BE:
2850 case AV_PIX_FMT_BGR565LE:
2851 case AV_PIX_FMT_BGR565BE:
2852 *yuv2packed1 = yuv2rgb16_1_c;
2853 *yuv2packed2 = yuv2rgb16_2_c;
2854 *yuv2packedX = yuv2rgb16_X_c;
2856 case AV_PIX_FMT_RGB555LE:
2857 case AV_PIX_FMT_RGB555BE:
2858 case AV_PIX_FMT_BGR555LE:
2859 case AV_PIX_FMT_BGR555BE:
2860 *yuv2packed1 = yuv2rgb15_1_c;
2861 *yuv2packed2 = yuv2rgb15_2_c;
2862 *yuv2packedX = yuv2rgb15_X_c;
2864 case AV_PIX_FMT_RGB444LE:
2865 case AV_PIX_FMT_RGB444BE:
2866 case AV_PIX_FMT_BGR444LE:
2867 case AV_PIX_FMT_BGR444BE:
2868 *yuv2packed1 = yuv2rgb12_1_c;
2869 *yuv2packed2 = yuv2rgb12_2_c;
2870 *yuv2packedX = yuv2rgb12_X_c;
2872 case AV_PIX_FMT_RGB8:
2873 case AV_PIX_FMT_BGR8:
2874 *yuv2packed1 = yuv2rgb8_1_c;
2875 *yuv2packed2 = yuv2rgb8_2_c;
2876 *yuv2packedX = yuv2rgb8_X_c;
2878 case AV_PIX_FMT_RGB4:
2879 case AV_PIX_FMT_BGR4:
2880 *yuv2packed1 = yuv2rgb4_1_c;
2881 *yuv2packed2 = yuv2rgb4_2_c;
2882 *yuv2packedX = yuv2rgb4_X_c;
2884 case AV_PIX_FMT_RGB4_BYTE:
2885 case AV_PIX_FMT_BGR4_BYTE:
2886 *yuv2packed1 = yuv2rgb4b_1_c;
2887 *yuv2packed2 = yuv2rgb4b_2_c;
2888 *yuv2packedX = yuv2rgb4b_X_c;
2892 switch (dstFormat) {
2893 case AV_PIX_FMT_MONOWHITE:
2894 *yuv2packed1 = yuv2monowhite_1_c;
2895 *yuv2packed2 = yuv2monowhite_2_c;
2896 *yuv2packedX = yuv2monowhite_X_c;
2898 case AV_PIX_FMT_MONOBLACK:
2899 *yuv2packed1 = yuv2monoblack_1_c;
2900 *yuv2packed2 = yuv2monoblack_2_c;
2901 *yuv2packedX = yuv2monoblack_X_c;
2903 case AV_PIX_FMT_YUYV422:
2904 *yuv2packed1 = yuv2yuyv422_1_c;
2905 *yuv2packed2 = yuv2yuyv422_2_c;
2906 *yuv2packedX = yuv2yuyv422_X_c;
2908 case AV_PIX_FMT_YVYU422:
2909 *yuv2packed1 = yuv2yvyu422_1_c;
2910 *yuv2packed2 = yuv2yvyu422_2_c;
2911 *yuv2packedX = yuv2yvyu422_X_c;
2913 case AV_PIX_FMT_UYVY422:
2914 *yuv2packed1 = yuv2uyvy422_1_c;
2915 *yuv2packed2 = yuv2uyvy422_2_c;
2916 *yuv2packedX = yuv2uyvy422_X_c;
2918 case AV_PIX_FMT_YA8:
2919 *yuv2packed1 = yuv2ya8_1_c;
2920 *yuv2packed2 = yuv2ya8_2_c;
2921 *yuv2packedX = yuv2ya8_X_c;
2923 case AV_PIX_FMT_YA16LE:
2924 *yuv2packed1 = yuv2ya16le_1_c;
2925 *yuv2packed2 = yuv2ya16le_2_c;
2926 *yuv2packedX = yuv2ya16le_X_c;
2928 case AV_PIX_FMT_YA16BE:
2929 *yuv2packed1 = yuv2ya16be_1_c;
2930 *yuv2packed2 = yuv2ya16be_2_c;
2931 *yuv2packedX = yuv2ya16be_X_c;
2933 case AV_PIX_FMT_AYUV64LE:
2934 *yuv2packedX = yuv2ayuv64le_X_c;