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 dstFormat == AV_PIX_FMT_NV24)
415 for (i=0; i<chrDstW; i++) {
416 int u = chrDither[i & 7] << 12;
417 int v = chrDither[(i + 3) & 7] << 12;
419 for (j=0; j<chrFilterSize; j++) {
420 u += chrUSrc[j][i] * chrFilter[j];
421 v += chrVSrc[j][i] * chrFilter[j];
424 dest[2*i]= av_clip_uint8(u>>19);
425 dest[2*i+1]= av_clip_uint8(v>>19);
428 for (i=0; i<chrDstW; i++) {
429 int u = chrDither[i & 7] << 12;
430 int v = chrDither[(i + 3) & 7] << 12;
432 for (j=0; j<chrFilterSize; j++) {
433 u += chrUSrc[j][i] * chrFilter[j];
434 v += chrVSrc[j][i] * chrFilter[j];
437 dest[2*i]= av_clip_uint8(v>>19);
438 dest[2*i+1]= av_clip_uint8(u>>19);
443 #define output_pixel(pos, val) \
445 AV_WB16(pos, av_clip_uintp2(val >> shift, 10) << 6); \
447 AV_WL16(pos, av_clip_uintp2(val >> shift, 10) << 6); \
450 static void yuv2p010l1_c(const int16_t *src,
451 uint16_t *dest, int dstW,
457 for (i = 0; i < dstW; i++) {
458 int val = src[i] + (1 << (shift - 1));
459 output_pixel(&dest[i], val);
463 static void yuv2p010lX_c(const int16_t *filter, int filterSize,
464 const int16_t **src, uint16_t *dest, int dstW,
470 for (i = 0; i < dstW; i++) {
471 int val = 1 << (shift - 1);
473 for (j = 0; j < filterSize; j++)
474 val += src[j][i] * filter[j];
476 output_pixel(&dest[i], val);
480 static void yuv2p010cX_c(SwsContext *c, const int16_t *chrFilter, int chrFilterSize,
481 const int16_t **chrUSrc, const int16_t **chrVSrc,
482 uint8_t *dest8, int chrDstW)
484 uint16_t *dest = (uint16_t*)dest8;
486 int big_endian = c->dstFormat == AV_PIX_FMT_P010BE;
489 for (i = 0; i < chrDstW; i++) {
490 int u = 1 << (shift - 1);
491 int v = 1 << (shift - 1);
493 for (j = 0; j < chrFilterSize; j++) {
494 u += chrUSrc[j][i] * chrFilter[j];
495 v += chrVSrc[j][i] * chrFilter[j];
498 output_pixel(&dest[2*i] , u);
499 output_pixel(&dest[2*i+1], v);
503 static void yuv2p010l1_LE_c(const int16_t *src,
504 uint8_t *dest, int dstW,
505 const uint8_t *dither, int offset)
507 yuv2p010l1_c(src, (uint16_t*)dest, dstW, 0);
510 static void yuv2p010l1_BE_c(const int16_t *src,
511 uint8_t *dest, int dstW,
512 const uint8_t *dither, int offset)
514 yuv2p010l1_c(src, (uint16_t*)dest, dstW, 1);
517 static void yuv2p010lX_LE_c(const int16_t *filter, int filterSize,
518 const int16_t **src, uint8_t *dest, int dstW,
519 const uint8_t *dither, int offset)
521 yuv2p010lX_c(filter, filterSize, src, (uint16_t*)dest, dstW, 0);
524 static void yuv2p010lX_BE_c(const int16_t *filter, int filterSize,
525 const int16_t **src, uint8_t *dest, int dstW,
526 const uint8_t *dither, int offset)
528 yuv2p010lX_c(filter, filterSize, src, (uint16_t*)dest, dstW, 1);
534 #define accumulate_bit(acc, val) \
537 #define output_pixel(pos, acc) \
538 if (target == AV_PIX_FMT_MONOBLACK) { \
544 static av_always_inline void
545 yuv2mono_X_c_template(SwsContext *c, const int16_t *lumFilter,
546 const int16_t **lumSrc, int lumFilterSize,
547 const int16_t *chrFilter, const int16_t **chrUSrc,
548 const int16_t **chrVSrc, int chrFilterSize,
549 const int16_t **alpSrc, uint8_t *dest, int dstW,
550 int y, enum AVPixelFormat target)
552 const uint8_t * const d128 = ff_dither_8x8_220[y&7];
557 for (i = 0; i < dstW; i += 2) {
562 for (j = 0; j < lumFilterSize; j++) {
563 Y1 += lumSrc[j][i] * lumFilter[j];
564 Y2 += lumSrc[j][i+1] * lumFilter[j];
568 if ((Y1 | Y2) & 0x100) {
569 Y1 = av_clip_uint8(Y1);
570 Y2 = av_clip_uint8(Y2);
572 if (c->dither == SWS_DITHER_ED) {
573 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;
574 c->dither_error[0][i] = err;
575 acc = 2*acc + (Y1 >= 128);
578 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);
579 c->dither_error[0][i+1] = Y1;
580 acc = 2*acc + (err >= 128);
583 accumulate_bit(acc, Y1 + d128[(i + 0) & 7]);
584 accumulate_bit(acc, Y2 + d128[(i + 1) & 7]);
587 output_pixel(*dest++, acc);
590 c->dither_error[0][i] = err;
593 output_pixel(*dest, acc);
597 static av_always_inline void
598 yuv2mono_2_c_template(SwsContext *c, const int16_t *buf[2],
599 const int16_t *ubuf[2], const int16_t *vbuf[2],
600 const int16_t *abuf[2], uint8_t *dest, int dstW,
601 int yalpha, int uvalpha, int y,
602 enum AVPixelFormat target)
604 const int16_t *buf0 = buf[0], *buf1 = buf[1];
605 const uint8_t * const d128 = ff_dither_8x8_220[y & 7];
606 int yalpha1 = 4096 - yalpha;
608 av_assert2(yalpha <= 4096U);
610 if (c->dither == SWS_DITHER_ED) {
613 for (i = 0; i < dstW; i +=2) {
616 Y = (buf0[i + 0] * yalpha1 + buf1[i + 0] * yalpha) >> 19;
617 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;
618 c->dither_error[0][i] = err;
619 acc = 2*acc + (Y >= 128);
622 err = (buf0[i + 1] * yalpha1 + buf1[i + 1] * yalpha) >> 19;
623 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;
624 c->dither_error[0][i+1] = Y;
625 acc = 2*acc + (err >= 128);
629 output_pixel(*dest++, acc);
631 c->dither_error[0][i] = err;
633 for (i = 0; i < dstW; i += 8) {
636 Y = (buf0[i + 0] * yalpha1 + buf1[i + 0] * yalpha) >> 19;
637 accumulate_bit(acc, Y + d128[0]);
638 Y = (buf0[i + 1] * yalpha1 + buf1[i + 1] * yalpha) >> 19;
639 accumulate_bit(acc, Y + d128[1]);
640 Y = (buf0[i + 2] * yalpha1 + buf1[i + 2] * yalpha) >> 19;
641 accumulate_bit(acc, Y + d128[2]);
642 Y = (buf0[i + 3] * yalpha1 + buf1[i + 3] * yalpha) >> 19;
643 accumulate_bit(acc, Y + d128[3]);
644 Y = (buf0[i + 4] * yalpha1 + buf1[i + 4] * yalpha) >> 19;
645 accumulate_bit(acc, Y + d128[4]);
646 Y = (buf0[i + 5] * yalpha1 + buf1[i + 5] * yalpha) >> 19;
647 accumulate_bit(acc, Y + d128[5]);
648 Y = (buf0[i + 6] * yalpha1 + buf1[i + 6] * yalpha) >> 19;
649 accumulate_bit(acc, Y + d128[6]);
650 Y = (buf0[i + 7] * yalpha1 + buf1[i + 7] * yalpha) >> 19;
651 accumulate_bit(acc, Y + d128[7]);
653 output_pixel(*dest++, acc);
658 static av_always_inline void
659 yuv2mono_1_c_template(SwsContext *c, const int16_t *buf0,
660 const int16_t *ubuf[2], const int16_t *vbuf[2],
661 const int16_t *abuf0, uint8_t *dest, int dstW,
662 int uvalpha, int y, enum AVPixelFormat target)
664 const uint8_t * const d128 = ff_dither_8x8_220[y & 7];
667 if (c->dither == SWS_DITHER_ED) {
670 for (i = 0; i < dstW; i +=2) {
673 Y = ((buf0[i + 0] + 64) >> 7);
674 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;
675 c->dither_error[0][i] = err;
676 acc = 2*acc + (Y >= 128);
679 err = ((buf0[i + 1] + 64) >> 7);
680 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;
681 c->dither_error[0][i+1] = Y;
682 acc = 2*acc + (err >= 128);
686 output_pixel(*dest++, acc);
688 c->dither_error[0][i] = err;
690 for (i = 0; i < dstW; i += 8) {
692 accumulate_bit(acc, ((buf0[i + 0] + 64) >> 7) + d128[0]);
693 accumulate_bit(acc, ((buf0[i + 1] + 64) >> 7) + d128[1]);
694 accumulate_bit(acc, ((buf0[i + 2] + 64) >> 7) + d128[2]);
695 accumulate_bit(acc, ((buf0[i + 3] + 64) >> 7) + d128[3]);
696 accumulate_bit(acc, ((buf0[i + 4] + 64) >> 7) + d128[4]);
697 accumulate_bit(acc, ((buf0[i + 5] + 64) >> 7) + d128[5]);
698 accumulate_bit(acc, ((buf0[i + 6] + 64) >> 7) + d128[6]);
699 accumulate_bit(acc, ((buf0[i + 7] + 64) >> 7) + d128[7]);
701 output_pixel(*dest++, acc);
707 #undef accumulate_bit
709 #define YUV2PACKEDWRAPPER(name, base, ext, fmt) \
710 static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \
711 const int16_t **lumSrc, int lumFilterSize, \
712 const int16_t *chrFilter, const int16_t **chrUSrc, \
713 const int16_t **chrVSrc, int chrFilterSize, \
714 const int16_t **alpSrc, uint8_t *dest, int dstW, \
717 name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
718 chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
719 alpSrc, dest, dstW, y, fmt); \
722 static void name ## ext ## _2_c(SwsContext *c, const int16_t *buf[2], \
723 const int16_t *ubuf[2], const int16_t *vbuf[2], \
724 const int16_t *abuf[2], uint8_t *dest, int dstW, \
725 int yalpha, int uvalpha, int y) \
727 name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
728 dest, dstW, yalpha, uvalpha, y, fmt); \
731 static void name ## ext ## _1_c(SwsContext *c, const int16_t *buf0, \
732 const int16_t *ubuf[2], const int16_t *vbuf[2], \
733 const int16_t *abuf0, uint8_t *dest, int dstW, \
734 int uvalpha, int y) \
736 name ## base ## _1_c_template(c, buf0, ubuf, vbuf, \
737 abuf0, dest, dstW, uvalpha, \
741 YUV2PACKEDWRAPPER(yuv2mono,, white, AV_PIX_FMT_MONOWHITE)
742 YUV2PACKEDWRAPPER(yuv2mono,, black, AV_PIX_FMT_MONOBLACK)
744 #define output_pixels(pos, Y1, U, Y2, V) \
745 if (target == AV_PIX_FMT_YUYV422) { \
746 dest[pos + 0] = Y1; \
748 dest[pos + 2] = Y2; \
750 } else if (target == AV_PIX_FMT_YVYU422) { \
751 dest[pos + 0] = Y1; \
753 dest[pos + 2] = Y2; \
755 } else { /* AV_PIX_FMT_UYVY422 */ \
757 dest[pos + 1] = Y1; \
759 dest[pos + 3] = Y2; \
762 static av_always_inline void
763 yuv2422_X_c_template(SwsContext *c, const int16_t *lumFilter,
764 const int16_t **lumSrc, int lumFilterSize,
765 const int16_t *chrFilter, const int16_t **chrUSrc,
766 const int16_t **chrVSrc, int chrFilterSize,
767 const int16_t **alpSrc, uint8_t *dest, int dstW,
768 int y, enum AVPixelFormat target)
772 for (i = 0; i < ((dstW + 1) >> 1); i++) {
779 for (j = 0; j < lumFilterSize; j++) {
780 Y1 += lumSrc[j][i * 2] * lumFilter[j];
781 Y2 += lumSrc[j][i * 2 + 1] * lumFilter[j];
783 for (j = 0; j < chrFilterSize; j++) {
784 U += chrUSrc[j][i] * chrFilter[j];
785 V += chrVSrc[j][i] * chrFilter[j];
791 if ((Y1 | Y2 | U | V) & 0x100) {
792 Y1 = av_clip_uint8(Y1);
793 Y2 = av_clip_uint8(Y2);
794 U = av_clip_uint8(U);
795 V = av_clip_uint8(V);
797 output_pixels(4*i, Y1, U, Y2, V);
801 static av_always_inline void
802 yuv2422_2_c_template(SwsContext *c, const int16_t *buf[2],
803 const int16_t *ubuf[2], const int16_t *vbuf[2],
804 const int16_t *abuf[2], uint8_t *dest, int dstW,
805 int yalpha, int uvalpha, int y,
806 enum AVPixelFormat target)
808 const int16_t *buf0 = buf[0], *buf1 = buf[1],
809 *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
810 *vbuf0 = vbuf[0], *vbuf1 = vbuf[1];
811 int yalpha1 = 4096 - yalpha;
812 int uvalpha1 = 4096 - uvalpha;
814 av_assert2(yalpha <= 4096U);
815 av_assert2(uvalpha <= 4096U);
817 for (i = 0; i < ((dstW + 1) >> 1); i++) {
818 int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 19;
819 int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 19;
820 int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha) >> 19;
821 int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha) >> 19;
823 if ((Y1 | Y2 | U | V) & 0x100) {
824 Y1 = av_clip_uint8(Y1);
825 Y2 = av_clip_uint8(Y2);
826 U = av_clip_uint8(U);
827 V = av_clip_uint8(V);
830 output_pixels(i * 4, Y1, U, Y2, V);
834 static av_always_inline void
835 yuv2422_1_c_template(SwsContext *c, const int16_t *buf0,
836 const int16_t *ubuf[2], const int16_t *vbuf[2],
837 const int16_t *abuf0, uint8_t *dest, int dstW,
838 int uvalpha, int y, enum AVPixelFormat target)
840 const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
843 if (uvalpha < 2048) {
844 for (i = 0; i < ((dstW + 1) >> 1); i++) {
845 int Y1 = (buf0[i * 2 ]+64) >> 7;
846 int Y2 = (buf0[i * 2 + 1]+64) >> 7;
847 int U = (ubuf0[i] +64) >> 7;
848 int V = (vbuf0[i] +64) >> 7;
850 if ((Y1 | Y2 | U | V) & 0x100) {
851 Y1 = av_clip_uint8(Y1);
852 Y2 = av_clip_uint8(Y2);
853 U = av_clip_uint8(U);
854 V = av_clip_uint8(V);
857 output_pixels(i * 4, Y1, U, Y2, V);
860 const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
861 for (i = 0; i < ((dstW + 1) >> 1); i++) {
862 int Y1 = (buf0[i * 2 ] + 64) >> 7;
863 int Y2 = (buf0[i * 2 + 1] + 64) >> 7;
864 int U = (ubuf0[i] + ubuf1[i]+128) >> 8;
865 int V = (vbuf0[i] + vbuf1[i]+128) >> 8;
867 if ((Y1 | Y2 | U | V) & 0x100) {
868 Y1 = av_clip_uint8(Y1);
869 Y2 = av_clip_uint8(Y2);
870 U = av_clip_uint8(U);
871 V = av_clip_uint8(V);
874 output_pixels(i * 4, Y1, U, Y2, V);
881 YUV2PACKEDWRAPPER(yuv2, 422, yuyv422, AV_PIX_FMT_YUYV422)
882 YUV2PACKEDWRAPPER(yuv2, 422, yvyu422, AV_PIX_FMT_YVYU422)
883 YUV2PACKEDWRAPPER(yuv2, 422, uyvy422, AV_PIX_FMT_UYVY422)
885 #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)
886 #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)
887 #define output_pixel(pos, val) \
888 if (isBE(target)) { \
894 static av_always_inline void
895 yuv2ya16_X_c_template(SwsContext *c, const int16_t *lumFilter,
896 const int32_t **lumSrc, int lumFilterSize,
897 const int16_t *chrFilter, const int32_t **unused_chrUSrc,
898 const int32_t **unused_chrVSrc, int unused_chrFilterSize,
899 const int32_t **alpSrc, uint16_t *dest, int dstW,
900 int y, enum AVPixelFormat target, int unused_hasAlpha, int unused_eightbytes)
902 int hasAlpha = !!alpSrc;
905 for (i = 0; i < dstW; i++) {
908 int64_t A = 0xffff<<14;
910 for (j = 0; j < lumFilterSize; j++)
911 Y += lumSrc[j][i] * lumFilter[j];
914 Y += (1<<3) + 0x8000;
915 Y = av_clip_uint16(Y);
918 for (j = 0; j < lumFilterSize; j++)
919 A += alpSrc[j][i] * lumFilter[j];
922 A = av_clip_uint16(A);
925 output_pixel(&dest[2 * i ], Y);
926 output_pixel(&dest[2 * i + 1], hasAlpha ? A : 65535);
930 static av_always_inline void
931 yuv2ya16_2_c_template(SwsContext *c, const int32_t *buf[2],
932 const int32_t *unused_ubuf[2], const int32_t *unused_vbuf[2],
933 const int32_t *abuf[2], uint16_t *dest, int dstW,
934 int yalpha, int unused_uvalpha, int y,
935 enum AVPixelFormat target, int unused_hasAlpha, int unused_eightbytes)
937 int hasAlpha = abuf && abuf[0] && abuf[1];
938 const int32_t *buf0 = buf[0], *buf1 = buf[1],
939 *abuf0 = hasAlpha ? abuf[0] : NULL,
940 *abuf1 = hasAlpha ? abuf[1] : NULL;
941 int yalpha1 = 4096 - yalpha;
944 av_assert2(yalpha <= 4096U);
946 for (i = 0; i < dstW; i++) {
947 int Y = (buf0[i] * yalpha1 + buf1[i] * yalpha) >> 15;
950 Y = av_clip_uint16(Y);
953 A = (abuf0[i] * yalpha1 + abuf1[i] * yalpha) >> 15;
954 A = av_clip_uint16(A);
957 output_pixel(&dest[2 * i ], Y);
958 output_pixel(&dest[2 * i + 1], hasAlpha ? A : 65535);
962 static av_always_inline void
963 yuv2ya16_1_c_template(SwsContext *c, const int32_t *buf0,
964 const int32_t *unused_ubuf[2], const int32_t *unused_vbuf[2],
965 const int32_t *abuf0, uint16_t *dest, int dstW,
966 int unused_uvalpha, int y, enum AVPixelFormat target, int unused_hasAlpha, int unused_eightbytes)
968 int hasAlpha = !!abuf0;
971 for (i = 0; i < dstW; i++) {
972 int Y = buf0[i] >> 3;/* 19 - 16 */
975 Y = av_clip_uint16(Y);
980 A = av_clip_uint16(A);
983 output_pixel(&dest[2 * i ], Y);
984 output_pixel(&dest[2 * i + 1], hasAlpha ? A : 65535);
988 static av_always_inline void
989 yuv2rgba64_X_c_template(SwsContext *c, const int16_t *lumFilter,
990 const int32_t **lumSrc, int lumFilterSize,
991 const int16_t *chrFilter, const int32_t **chrUSrc,
992 const int32_t **chrVSrc, int chrFilterSize,
993 const int32_t **alpSrc, uint16_t *dest, int dstW,
994 int y, enum AVPixelFormat target, int hasAlpha, int eightbytes)
997 int A1 = 0xffff<<14, A2 = 0xffff<<14;
999 for (i = 0; i < ((dstW + 1) >> 1); i++) {
1001 int Y1 = -0x40000000;
1002 int Y2 = -0x40000000;
1003 int U = -(128 << 23); // 19
1004 int V = -(128 << 23);
1007 for (j = 0; j < lumFilterSize; j++) {
1008 Y1 += lumSrc[j][i * 2] * (unsigned)lumFilter[j];
1009 Y2 += lumSrc[j][i * 2 + 1] * (unsigned)lumFilter[j];
1011 for (j = 0; j < chrFilterSize; j++) {;
1012 U += chrUSrc[j][i] * (unsigned)chrFilter[j];
1013 V += chrVSrc[j][i] * (unsigned)chrFilter[j];
1019 for (j = 0; j < lumFilterSize; j++) {
1020 A1 += alpSrc[j][i * 2] * (unsigned)lumFilter[j];
1021 A2 += alpSrc[j][i * 2 + 1] * (unsigned)lumFilter[j];
1029 // 8 bits: 12+15=27; 16 bits: 12+19=31
1037 // 8 bits: 27 -> 17 bits, 16 bits: 31 - 14 = 17 bits
1038 Y1 -= c->yuv2rgb_y_offset;
1039 Y2 -= c->yuv2rgb_y_offset;
1040 Y1 *= c->yuv2rgb_y_coeff;
1041 Y2 *= c->yuv2rgb_y_coeff;
1042 Y1 += 1 << 13; // 21
1044 // 8 bits: 17 + 13 bits = 30 bits, 16 bits: 17 + 13 bits = 30 bits
1046 R = V * c->yuv2rgb_v2r_coeff;
1047 G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
1048 B = U * c->yuv2rgb_u2b_coeff;
1050 // 8 bits: 30 - 22 = 8 bits, 16 bits: 30 bits - 14 = 16 bits
1051 output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
1052 output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
1053 output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
1055 output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14);
1056 output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >> 14);
1057 output_pixel(&dest[5], av_clip_uintp2( G + Y2, 30) >> 14);
1058 output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >> 14);
1059 output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14);
1062 output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
1063 output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);
1064 output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
1070 static av_always_inline void
1071 yuv2rgba64_2_c_template(SwsContext *c, const int32_t *buf[2],
1072 const int32_t *ubuf[2], const int32_t *vbuf[2],
1073 const int32_t *abuf[2], uint16_t *dest, int dstW,
1074 int yalpha, int uvalpha, int y,
1075 enum AVPixelFormat target, int hasAlpha, int eightbytes)
1077 const int32_t *buf0 = buf[0], *buf1 = buf[1],
1078 *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
1079 *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
1080 *abuf0 = hasAlpha ? abuf[0] : NULL,
1081 *abuf1 = hasAlpha ? abuf[1] : NULL;
1082 int yalpha1 = 4096 - yalpha;
1083 int uvalpha1 = 4096 - uvalpha;
1085 int A1 = 0xffff<<14, A2 = 0xffff<<14;
1087 av_assert2(yalpha <= 4096U);
1088 av_assert2(uvalpha <= 4096U);
1090 for (i = 0; i < ((dstW + 1) >> 1); i++) {
1091 int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 14;
1092 int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 14;
1093 int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha - (128 << 23)) >> 14;
1094 int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha - (128 << 23)) >> 14;
1097 Y1 -= c->yuv2rgb_y_offset;
1098 Y2 -= c->yuv2rgb_y_offset;
1099 Y1 *= c->yuv2rgb_y_coeff;
1100 Y2 *= c->yuv2rgb_y_coeff;
1104 R = V * c->yuv2rgb_v2r_coeff;
1105 G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
1106 B = U * c->yuv2rgb_u2b_coeff;
1109 A1 = (abuf0[i * 2 ] * yalpha1 + abuf1[i * 2 ] * yalpha) >> 1;
1110 A2 = (abuf0[i * 2 + 1] * yalpha1 + abuf1[i * 2 + 1] * yalpha) >> 1;
1116 output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
1117 output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
1118 output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
1120 output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14);
1121 output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >> 14);
1122 output_pixel(&dest[5], av_clip_uintp2( G + Y2, 30) >> 14);
1123 output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >> 14);
1124 output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14);
1127 output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
1128 output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);
1129 output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
1135 static av_always_inline void
1136 yuv2rgba64_1_c_template(SwsContext *c, const int32_t *buf0,
1137 const int32_t *ubuf[2], const int32_t *vbuf[2],
1138 const int32_t *abuf0, uint16_t *dest, int dstW,
1139 int uvalpha, int y, enum AVPixelFormat target, int hasAlpha, int eightbytes)
1141 const int32_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
1143 int A1 = 0xffff<<14, A2= 0xffff<<14;
1145 if (uvalpha < 2048) {
1146 for (i = 0; i < ((dstW + 1) >> 1); i++) {
1147 int Y1 = (buf0[i * 2] ) >> 2;
1148 int Y2 = (buf0[i * 2 + 1]) >> 2;
1149 int U = (ubuf0[i] - (128 << 11)) >> 2;
1150 int V = (vbuf0[i] - (128 << 11)) >> 2;
1153 Y1 -= c->yuv2rgb_y_offset;
1154 Y2 -= c->yuv2rgb_y_offset;
1155 Y1 *= c->yuv2rgb_y_coeff;
1156 Y2 *= c->yuv2rgb_y_coeff;
1161 A1 = abuf0[i * 2 ] << 11;
1162 A2 = abuf0[i * 2 + 1] << 11;
1168 R = V * c->yuv2rgb_v2r_coeff;
1169 G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
1170 B = U * c->yuv2rgb_u2b_coeff;
1172 output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
1173 output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
1174 output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
1176 output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14);
1177 output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >> 14);
1178 output_pixel(&dest[5], av_clip_uintp2( G + Y2, 30) >> 14);
1179 output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >> 14);
1180 output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14);
1183 output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
1184 output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);
1185 output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
1190 const int32_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
1191 int A1 = 0xffff<<14, A2 = 0xffff<<14;
1192 for (i = 0; i < ((dstW + 1) >> 1); i++) {
1193 int Y1 = (buf0[i * 2] ) >> 2;
1194 int Y2 = (buf0[i * 2 + 1]) >> 2;
1195 int U = (ubuf0[i] + ubuf1[i] - (128 << 12)) >> 3;
1196 int V = (vbuf0[i] + vbuf1[i] - (128 << 12)) >> 3;
1199 Y1 -= c->yuv2rgb_y_offset;
1200 Y2 -= c->yuv2rgb_y_offset;
1201 Y1 *= c->yuv2rgb_y_coeff;
1202 Y2 *= c->yuv2rgb_y_coeff;
1207 A1 = abuf0[i * 2 ] << 11;
1208 A2 = abuf0[i * 2 + 1] << 11;
1214 R = V * c->yuv2rgb_v2r_coeff;
1215 G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
1216 B = U * c->yuv2rgb_u2b_coeff;
1218 output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
1219 output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
1220 output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
1222 output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14);
1223 output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >> 14);
1224 output_pixel(&dest[5], av_clip_uintp2( G + Y2, 30) >> 14);
1225 output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >> 14);
1226 output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14);
1229 output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
1230 output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);
1231 output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
1238 static av_always_inline void
1239 yuv2rgba64_full_X_c_template(SwsContext *c, const int16_t *lumFilter,
1240 const int32_t **lumSrc, int lumFilterSize,
1241 const int16_t *chrFilter, const int32_t **chrUSrc,
1242 const int32_t **chrVSrc, int chrFilterSize,
1243 const int32_t **alpSrc, uint16_t *dest, int dstW,
1244 int y, enum AVPixelFormat target, int hasAlpha, int eightbytes)
1249 for (i = 0; i < dstW; i++) {
1251 int Y = -0x40000000;
1252 int U = -(128 << 23); // 19
1253 int V = -(128 << 23);
1256 for (j = 0; j < lumFilterSize; j++) {
1257 Y += lumSrc[j][i] * (unsigned)lumFilter[j];
1259 for (j = 0; j < chrFilterSize; j++) {;
1260 U += chrUSrc[j][i] * (unsigned)chrFilter[j];
1261 V += chrVSrc[j][i] * (unsigned)chrFilter[j];
1266 for (j = 0; j < lumFilterSize; j++) {
1267 A += alpSrc[j][i] * (unsigned)lumFilter[j];
1273 // 8bit: 12+15=27; 16-bit: 12+19=31
1279 // 8bit: 27 -> 17bit, 16bit: 31 - 14 = 17bit
1280 Y -= c->yuv2rgb_y_offset;
1281 Y *= c->yuv2rgb_y_coeff;
1283 // 8bit: 17 + 13bit = 30bit, 16bit: 17 + 13bit = 30bit
1285 R = V * c->yuv2rgb_v2r_coeff;
1286 G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
1287 B = U * c->yuv2rgb_u2b_coeff;
1289 // 8bit: 30 - 22 = 8bit, 16bit: 30bit - 14 = 16bit
1290 output_pixel(&dest[0], av_clip_uintp2(R_B + Y, 30) >> 14);
1291 output_pixel(&dest[1], av_clip_uintp2( G + Y, 30) >> 14);
1292 output_pixel(&dest[2], av_clip_uintp2(B_R + Y, 30) >> 14);
1294 output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
1302 static av_always_inline void
1303 yuv2rgba64_full_2_c_template(SwsContext *c, const int32_t *buf[2],
1304 const int32_t *ubuf[2], const int32_t *vbuf[2],
1305 const int32_t *abuf[2], uint16_t *dest, int dstW,
1306 int yalpha, int uvalpha, int y,
1307 enum AVPixelFormat target, int hasAlpha, int eightbytes)
1309 const int32_t *buf0 = buf[0], *buf1 = buf[1],
1310 *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
1311 *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
1312 *abuf0 = hasAlpha ? abuf[0] : NULL,
1313 *abuf1 = hasAlpha ? abuf[1] : NULL;
1314 int yalpha1 = 4096 - yalpha;
1315 int uvalpha1 = 4096 - uvalpha;
1319 av_assert2(yalpha <= 4096U);
1320 av_assert2(uvalpha <= 4096U);
1322 for (i = 0; i < dstW; i++) {
1323 int Y = (buf0[i] * yalpha1 + buf1[i] * yalpha) >> 14;
1324 int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha - (128 << 23)) >> 14;
1325 int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha - (128 << 23)) >> 14;
1328 Y -= c->yuv2rgb_y_offset;
1329 Y *= c->yuv2rgb_y_coeff;
1332 R = V * c->yuv2rgb_v2r_coeff;
1333 G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
1334 B = U * c->yuv2rgb_u2b_coeff;
1337 A = (abuf0[i] * yalpha1 + abuf1[i] * yalpha) >> 1;
1342 output_pixel(&dest[0], av_clip_uintp2(R_B + Y, 30) >> 14);
1343 output_pixel(&dest[1], av_clip_uintp2( G + Y, 30) >> 14);
1344 output_pixel(&dest[2], av_clip_uintp2(B_R + Y, 30) >> 14);
1346 output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
1354 static av_always_inline void
1355 yuv2rgba64_full_1_c_template(SwsContext *c, const int32_t *buf0,
1356 const int32_t *ubuf[2], const int32_t *vbuf[2],
1357 const int32_t *abuf0, uint16_t *dest, int dstW,
1358 int uvalpha, int y, enum AVPixelFormat target, int hasAlpha, int eightbytes)
1360 const int32_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
1364 if (uvalpha < 2048) {
1365 for (i = 0; i < dstW; i++) {
1366 int Y = (buf0[i]) >> 2;
1367 int U = (ubuf0[i] - (128 << 11)) >> 2;
1368 int V = (vbuf0[i] - (128 << 11)) >> 2;
1371 Y -= c->yuv2rgb_y_offset;
1372 Y *= c->yuv2rgb_y_coeff;
1381 R = V * c->yuv2rgb_v2r_coeff;
1382 G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
1383 B = U * c->yuv2rgb_u2b_coeff;
1385 output_pixel(&dest[0], av_clip_uintp2(R_B + Y, 30) >> 14);
1386 output_pixel(&dest[1], av_clip_uintp2( G + Y, 30) >> 14);
1387 output_pixel(&dest[2], av_clip_uintp2(B_R + Y, 30) >> 14);
1389 output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
1396 const int32_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
1398 for (i = 0; i < dstW; i++) {
1399 int Y = (buf0[i] ) >> 2;
1400 int U = (ubuf0[i] + ubuf1[i] - (128 << 12)) >> 3;
1401 int V = (vbuf0[i] + vbuf1[i] - (128 << 12)) >> 3;
1404 Y -= c->yuv2rgb_y_offset;
1405 Y *= c->yuv2rgb_y_coeff;
1414 R = V * c->yuv2rgb_v2r_coeff;
1415 G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
1416 B = U * c->yuv2rgb_u2b_coeff;
1418 output_pixel(&dest[0], av_clip_uintp2(R_B + Y, 30) >> 14);
1419 output_pixel(&dest[1], av_clip_uintp2( G + Y, 30) >> 14);
1420 output_pixel(&dest[2], av_clip_uintp2(B_R + Y, 30) >> 14);
1422 output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
1435 #define YUV2PACKED16WRAPPER(name, base, ext, fmt, hasAlpha, eightbytes) \
1436 static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \
1437 const int16_t **_lumSrc, int lumFilterSize, \
1438 const int16_t *chrFilter, const int16_t **_chrUSrc, \
1439 const int16_t **_chrVSrc, int chrFilterSize, \
1440 const int16_t **_alpSrc, uint8_t *_dest, int dstW, \
1443 const int32_t **lumSrc = (const int32_t **) _lumSrc, \
1444 **chrUSrc = (const int32_t **) _chrUSrc, \
1445 **chrVSrc = (const int32_t **) _chrVSrc, \
1446 **alpSrc = (const int32_t **) _alpSrc; \
1447 uint16_t *dest = (uint16_t *) _dest; \
1448 name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
1449 chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
1450 alpSrc, dest, dstW, y, fmt, hasAlpha, eightbytes); \
1453 static void name ## ext ## _2_c(SwsContext *c, const int16_t *_buf[2], \
1454 const int16_t *_ubuf[2], const int16_t *_vbuf[2], \
1455 const int16_t *_abuf[2], uint8_t *_dest, int dstW, \
1456 int yalpha, int uvalpha, int y) \
1458 const int32_t **buf = (const int32_t **) _buf, \
1459 **ubuf = (const int32_t **) _ubuf, \
1460 **vbuf = (const int32_t **) _vbuf, \
1461 **abuf = (const int32_t **) _abuf; \
1462 uint16_t *dest = (uint16_t *) _dest; \
1463 name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
1464 dest, dstW, yalpha, uvalpha, y, fmt, hasAlpha, eightbytes); \
1467 static void name ## ext ## _1_c(SwsContext *c, const int16_t *_buf0, \
1468 const int16_t *_ubuf[2], const int16_t *_vbuf[2], \
1469 const int16_t *_abuf0, uint8_t *_dest, int dstW, \
1470 int uvalpha, int y) \
1472 const int32_t *buf0 = (const int32_t *) _buf0, \
1473 **ubuf = (const int32_t **) _ubuf, \
1474 **vbuf = (const int32_t **) _vbuf, \
1475 *abuf0 = (const int32_t *) _abuf0; \
1476 uint16_t *dest = (uint16_t *) _dest; \
1477 name ## base ## _1_c_template(c, buf0, ubuf, vbuf, abuf0, dest, \
1478 dstW, uvalpha, y, fmt, hasAlpha, eightbytes); \
1481 YUV2PACKED16WRAPPER(yuv2, rgba64, rgb48be, AV_PIX_FMT_RGB48BE, 0, 0)
1482 YUV2PACKED16WRAPPER(yuv2, rgba64, rgb48le, AV_PIX_FMT_RGB48LE, 0, 0)
1483 YUV2PACKED16WRAPPER(yuv2, rgba64, bgr48be, AV_PIX_FMT_BGR48BE, 0, 0)
1484 YUV2PACKED16WRAPPER(yuv2, rgba64, bgr48le, AV_PIX_FMT_BGR48LE, 0, 0)
1485 YUV2PACKED16WRAPPER(yuv2, rgba64, rgba64be, AV_PIX_FMT_RGBA64BE, 1, 1)
1486 YUV2PACKED16WRAPPER(yuv2, rgba64, rgba64le, AV_PIX_FMT_RGBA64LE, 1, 1)
1487 YUV2PACKED16WRAPPER(yuv2, rgba64, rgbx64be, AV_PIX_FMT_RGBA64BE, 0, 1)
1488 YUV2PACKED16WRAPPER(yuv2, rgba64, rgbx64le, AV_PIX_FMT_RGBA64LE, 0, 1)
1489 YUV2PACKED16WRAPPER(yuv2, rgba64, bgra64be, AV_PIX_FMT_BGRA64BE, 1, 1)
1490 YUV2PACKED16WRAPPER(yuv2, rgba64, bgra64le, AV_PIX_FMT_BGRA64LE, 1, 1)
1491 YUV2PACKED16WRAPPER(yuv2, rgba64, bgrx64be, AV_PIX_FMT_BGRA64BE, 0, 1)
1492 YUV2PACKED16WRAPPER(yuv2, rgba64, bgrx64le, AV_PIX_FMT_BGRA64LE, 0, 1)
1493 YUV2PACKED16WRAPPER(yuv2, ya16, ya16be, AV_PIX_FMT_YA16BE, 1, 0)
1494 YUV2PACKED16WRAPPER(yuv2, ya16, ya16le, AV_PIX_FMT_YA16LE, 1, 0)
1496 YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgb48be_full, AV_PIX_FMT_RGB48BE, 0, 0)
1497 YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgb48le_full, AV_PIX_FMT_RGB48LE, 0, 0)
1498 YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgr48be_full, AV_PIX_FMT_BGR48BE, 0, 0)
1499 YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgr48le_full, AV_PIX_FMT_BGR48LE, 0, 0)
1500 YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgba64be_full, AV_PIX_FMT_RGBA64BE, 1, 1)
1501 YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgba64le_full, AV_PIX_FMT_RGBA64LE, 1, 1)
1502 YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgbx64be_full, AV_PIX_FMT_RGBA64BE, 0, 1)
1503 YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgbx64le_full, AV_PIX_FMT_RGBA64LE, 0, 1)
1504 YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgra64be_full, AV_PIX_FMT_BGRA64BE, 1, 1)
1505 YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgra64le_full, AV_PIX_FMT_BGRA64LE, 1, 1)
1506 YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgrx64be_full, AV_PIX_FMT_BGRA64BE, 0, 1)
1507 YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgrx64le_full, AV_PIX_FMT_BGRA64LE, 0, 1)
1510 * Write out 2 RGB pixels in the target pixel format. This function takes a
1511 * R/G/B LUT as generated by ff_yuv2rgb_c_init_tables(), which takes care of
1512 * things like endianness conversion and shifting. The caller takes care of
1513 * setting the correct offset in these tables from the chroma (U/V) values.
1514 * This function then uses the luminance (Y1/Y2) values to write out the
1515 * correct RGB values into the destination buffer.
1517 static av_always_inline void
1518 yuv2rgb_write(uint8_t *_dest, int i, int Y1, int Y2,
1519 unsigned A1, unsigned A2,
1520 const void *_r, const void *_g, const void *_b, int y,
1521 enum AVPixelFormat target, int hasAlpha)
1523 if (target == AV_PIX_FMT_ARGB || target == AV_PIX_FMT_RGBA ||
1524 target == AV_PIX_FMT_ABGR || target == AV_PIX_FMT_BGRA) {
1525 uint32_t *dest = (uint32_t *) _dest;
1526 const uint32_t *r = (const uint32_t *) _r;
1527 const uint32_t *g = (const uint32_t *) _g;
1528 const uint32_t *b = (const uint32_t *) _b;
1531 int sh = hasAlpha ? ((target == AV_PIX_FMT_RGB32_1 || target == AV_PIX_FMT_BGR32_1) ? 0 : 24) : 0;
1533 dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1] + (hasAlpha ? A1 << sh : 0);
1534 dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2] + (hasAlpha ? A2 << sh : 0);
1537 int sh = (target == AV_PIX_FMT_RGB32_1 || target == AV_PIX_FMT_BGR32_1) ? 0 : 24;
1539 av_assert2((((r[Y1] + g[Y1] + b[Y1]) >> sh) & 0xFF) == 0);
1540 dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1] + (A1 << sh);
1541 dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2] + (A2 << sh);
1543 #if defined(ASSERT_LEVEL) && ASSERT_LEVEL > 1
1544 int sh = (target == AV_PIX_FMT_RGB32_1 || target == AV_PIX_FMT_BGR32_1) ? 0 : 24;
1546 av_assert2((((r[Y1] + g[Y1] + b[Y1]) >> sh) & 0xFF) == 0xFF);
1548 dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1];
1549 dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2];
1552 } else if (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) {
1553 uint8_t *dest = (uint8_t *) _dest;
1554 const uint8_t *r = (const uint8_t *) _r;
1555 const uint8_t *g = (const uint8_t *) _g;
1556 const uint8_t *b = (const uint8_t *) _b;
1558 #define r_b ((target == AV_PIX_FMT_RGB24) ? r : b)
1559 #define b_r ((target == AV_PIX_FMT_RGB24) ? b : r)
1561 dest[i * 6 + 0] = r_b[Y1];
1562 dest[i * 6 + 1] = g[Y1];
1563 dest[i * 6 + 2] = b_r[Y1];
1564 dest[i * 6 + 3] = r_b[Y2];
1565 dest[i * 6 + 4] = g[Y2];
1566 dest[i * 6 + 5] = b_r[Y2];
1569 } else if (target == AV_PIX_FMT_RGB565 || target == AV_PIX_FMT_BGR565 ||
1570 target == AV_PIX_FMT_RGB555 || target == AV_PIX_FMT_BGR555 ||
1571 target == AV_PIX_FMT_RGB444 || target == AV_PIX_FMT_BGR444) {
1572 uint16_t *dest = (uint16_t *) _dest;
1573 const uint16_t *r = (const uint16_t *) _r;
1574 const uint16_t *g = (const uint16_t *) _g;
1575 const uint16_t *b = (const uint16_t *) _b;
1576 int dr1, dg1, db1, dr2, dg2, db2;
1578 if (target == AV_PIX_FMT_RGB565 || target == AV_PIX_FMT_BGR565) {
1579 dr1 = ff_dither_2x2_8[ y & 1 ][0];
1580 dg1 = ff_dither_2x2_4[ y & 1 ][0];
1581 db1 = ff_dither_2x2_8[(y & 1) ^ 1][0];
1582 dr2 = ff_dither_2x2_8[ y & 1 ][1];
1583 dg2 = ff_dither_2x2_4[ y & 1 ][1];
1584 db2 = ff_dither_2x2_8[(y & 1) ^ 1][1];
1585 } else if (target == AV_PIX_FMT_RGB555 || target == AV_PIX_FMT_BGR555) {
1586 dr1 = ff_dither_2x2_8[ y & 1 ][0];
1587 dg1 = ff_dither_2x2_8[ y & 1 ][1];
1588 db1 = ff_dither_2x2_8[(y & 1) ^ 1][0];
1589 dr2 = ff_dither_2x2_8[ y & 1 ][1];
1590 dg2 = ff_dither_2x2_8[ y & 1 ][0];
1591 db2 = ff_dither_2x2_8[(y & 1) ^ 1][1];
1593 dr1 = ff_dither_4x4_16[ y & 3 ][0];
1594 dg1 = ff_dither_4x4_16[ y & 3 ][1];
1595 db1 = ff_dither_4x4_16[(y & 3) ^ 3][0];
1596 dr2 = ff_dither_4x4_16[ y & 3 ][1];
1597 dg2 = ff_dither_4x4_16[ y & 3 ][0];
1598 db2 = ff_dither_4x4_16[(y & 3) ^ 3][1];
1601 dest[i * 2 + 0] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1];
1602 dest[i * 2 + 1] = r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2];
1603 } else /* 8/4 bits */ {
1604 uint8_t *dest = (uint8_t *) _dest;
1605 const uint8_t *r = (const uint8_t *) _r;
1606 const uint8_t *g = (const uint8_t *) _g;
1607 const uint8_t *b = (const uint8_t *) _b;
1608 int dr1, dg1, db1, dr2, dg2, db2;
1610 if (target == AV_PIX_FMT_RGB8 || target == AV_PIX_FMT_BGR8) {
1611 const uint8_t * const d64 = ff_dither_8x8_73[y & 7];
1612 const uint8_t * const d32 = ff_dither_8x8_32[y & 7];
1613 dr1 = dg1 = d32[(i * 2 + 0) & 7];
1614 db1 = d64[(i * 2 + 0) & 7];
1615 dr2 = dg2 = d32[(i * 2 + 1) & 7];
1616 db2 = d64[(i * 2 + 1) & 7];
1618 const uint8_t * const d64 = ff_dither_8x8_73 [y & 7];
1619 const uint8_t * const d128 = ff_dither_8x8_220[y & 7];
1620 dr1 = db1 = d128[(i * 2 + 0) & 7];
1621 dg1 = d64[(i * 2 + 0) & 7];
1622 dr2 = db2 = d128[(i * 2 + 1) & 7];
1623 dg2 = d64[(i * 2 + 1) & 7];
1626 if (target == AV_PIX_FMT_RGB4 || target == AV_PIX_FMT_BGR4) {
1627 dest[i] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1] +
1628 ((r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2]) << 4);
1630 dest[i * 2 + 0] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1];
1631 dest[i * 2 + 1] = r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2];
1636 static av_always_inline void
1637 yuv2rgb_X_c_template(SwsContext *c, const int16_t *lumFilter,
1638 const int16_t **lumSrc, int lumFilterSize,
1639 const int16_t *chrFilter, const int16_t **chrUSrc,
1640 const int16_t **chrVSrc, int chrFilterSize,
1641 const int16_t **alpSrc, uint8_t *dest, int dstW,
1642 int y, enum AVPixelFormat target, int hasAlpha)
1646 for (i = 0; i < ((dstW + 1) >> 1); i++) {
1652 const void *r, *g, *b;
1654 for (j = 0; j < lumFilterSize; j++) {
1655 Y1 += lumSrc[j][i * 2] * lumFilter[j];
1656 Y2 += lumSrc[j][i * 2 + 1] * lumFilter[j];
1658 for (j = 0; j < chrFilterSize; j++) {
1659 U += chrUSrc[j][i] * chrFilter[j];
1660 V += chrVSrc[j][i] * chrFilter[j];
1669 for (j = 0; j < lumFilterSize; j++) {
1670 A1 += alpSrc[j][i * 2 ] * lumFilter[j];
1671 A2 += alpSrc[j][i * 2 + 1] * lumFilter[j];
1675 if ((A1 | A2) & 0x100) {
1676 A1 = av_clip_uint8(A1);
1677 A2 = av_clip_uint8(A2);
1681 r = c->table_rV[V + YUVRGB_TABLE_HEADROOM];
1682 g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]);
1683 b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
1685 yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
1686 r, g, b, y, target, hasAlpha);
1690 static av_always_inline void
1691 yuv2rgb_2_c_template(SwsContext *c, const int16_t *buf[2],
1692 const int16_t *ubuf[2], const int16_t *vbuf[2],
1693 const int16_t *abuf[2], uint8_t *dest, int dstW,
1694 int yalpha, int uvalpha, int y,
1695 enum AVPixelFormat target, int hasAlpha)
1697 const int16_t *buf0 = buf[0], *buf1 = buf[1],
1698 *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
1699 *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
1700 *abuf0 = hasAlpha ? abuf[0] : NULL,
1701 *abuf1 = hasAlpha ? abuf[1] : NULL;
1702 int yalpha1 = 4096 - yalpha;
1703 int uvalpha1 = 4096 - uvalpha;
1705 av_assert2(yalpha <= 4096U);
1706 av_assert2(uvalpha <= 4096U);
1708 for (i = 0; i < ((dstW + 1) >> 1); i++) {
1709 int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 19;
1710 int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 19;
1711 int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha) >> 19;
1712 int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha) >> 19;
1714 const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM],
1715 *g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]),
1716 *b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
1719 A1 = (abuf0[i * 2 ] * yalpha1 + abuf1[i * 2 ] * yalpha) >> 19;
1720 A2 = (abuf0[i * 2 + 1] * yalpha1 + abuf1[i * 2 + 1] * yalpha) >> 19;
1721 A1 = av_clip_uint8(A1);
1722 A2 = av_clip_uint8(A2);
1725 yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
1726 r, g, b, y, target, hasAlpha);
1730 static av_always_inline void
1731 yuv2rgb_1_c_template(SwsContext *c, const int16_t *buf0,
1732 const int16_t *ubuf[2], const int16_t *vbuf[2],
1733 const int16_t *abuf0, uint8_t *dest, int dstW,
1734 int uvalpha, int y, enum AVPixelFormat target,
1737 const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
1740 if (uvalpha < 2048) {
1741 for (i = 0; i < ((dstW + 1) >> 1); i++) {
1742 int Y1 = (buf0[i * 2 ] + 64) >> 7;
1743 int Y2 = (buf0[i * 2 + 1] + 64) >> 7;
1744 int U = (ubuf0[i] + 64) >> 7;
1745 int V = (vbuf0[i] + 64) >> 7;
1747 const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM],
1748 *g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]),
1749 *b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
1752 A1 = abuf0[i * 2 ] * 255 + 16384 >> 15;
1753 A2 = abuf0[i * 2 + 1] * 255 + 16384 >> 15;
1754 A1 = av_clip_uint8(A1);
1755 A2 = av_clip_uint8(A2);
1758 yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
1759 r, g, b, y, target, hasAlpha);
1762 const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
1763 for (i = 0; i < ((dstW + 1) >> 1); i++) {
1764 int Y1 = (buf0[i * 2 ] + 64) >> 7;
1765 int Y2 = (buf0[i * 2 + 1] + 64) >> 7;
1766 int U = (ubuf0[i] + ubuf1[i] + 128) >> 8;
1767 int V = (vbuf0[i] + vbuf1[i] + 128) >> 8;
1769 const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM],
1770 *g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]),
1771 *b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
1774 A1 = (abuf0[i * 2 ] + 64) >> 7;
1775 A2 = (abuf0[i * 2 + 1] + 64) >> 7;
1776 A1 = av_clip_uint8(A1);
1777 A2 = av_clip_uint8(A2);
1780 yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
1781 r, g, b, y, target, hasAlpha);
1786 #define YUV2RGBWRAPPERX(name, base, ext, fmt, hasAlpha) \
1787 static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \
1788 const int16_t **lumSrc, int lumFilterSize, \
1789 const int16_t *chrFilter, const int16_t **chrUSrc, \
1790 const int16_t **chrVSrc, int chrFilterSize, \
1791 const int16_t **alpSrc, uint8_t *dest, int dstW, \
1794 name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
1795 chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
1796 alpSrc, dest, dstW, y, fmt, hasAlpha); \
1799 #define YUV2RGBWRAPPERX2(name, base, ext, fmt, hasAlpha) \
1800 YUV2RGBWRAPPERX(name, base, ext, fmt, hasAlpha) \
1801 static void name ## ext ## _2_c(SwsContext *c, const int16_t *buf[2], \
1802 const int16_t *ubuf[2], const int16_t *vbuf[2], \
1803 const int16_t *abuf[2], uint8_t *dest, int dstW, \
1804 int yalpha, int uvalpha, int y) \
1806 name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
1807 dest, dstW, yalpha, uvalpha, y, fmt, hasAlpha); \
1810 #define YUV2RGBWRAPPER(name, base, ext, fmt, hasAlpha) \
1811 YUV2RGBWRAPPERX2(name, base, ext, fmt, hasAlpha) \
1812 static void name ## ext ## _1_c(SwsContext *c, const int16_t *buf0, \
1813 const int16_t *ubuf[2], const int16_t *vbuf[2], \
1814 const int16_t *abuf0, uint8_t *dest, int dstW, \
1815 int uvalpha, int y) \
1817 name ## base ## _1_c_template(c, buf0, ubuf, vbuf, abuf0, dest, \
1818 dstW, uvalpha, y, fmt, hasAlpha); \
1822 YUV2RGBWRAPPER(yuv2rgb,, 32_1, AV_PIX_FMT_RGB32_1, CONFIG_SWSCALE_ALPHA && c->needAlpha)
1823 YUV2RGBWRAPPER(yuv2rgb,, 32, AV_PIX_FMT_RGB32, CONFIG_SWSCALE_ALPHA && c->needAlpha)
1825 #if CONFIG_SWSCALE_ALPHA
1826 YUV2RGBWRAPPER(yuv2rgb,, a32_1, AV_PIX_FMT_RGB32_1, 1)
1827 YUV2RGBWRAPPER(yuv2rgb,, a32, AV_PIX_FMT_RGB32, 1)
1829 YUV2RGBWRAPPER(yuv2rgb,, x32_1, AV_PIX_FMT_RGB32_1, 0)
1830 YUV2RGBWRAPPER(yuv2rgb,, x32, AV_PIX_FMT_RGB32, 0)
1832 YUV2RGBWRAPPER(yuv2, rgb, rgb24, AV_PIX_FMT_RGB24, 0)
1833 YUV2RGBWRAPPER(yuv2, rgb, bgr24, AV_PIX_FMT_BGR24, 0)
1834 YUV2RGBWRAPPER(yuv2rgb,, 16, AV_PIX_FMT_RGB565, 0)
1835 YUV2RGBWRAPPER(yuv2rgb,, 15, AV_PIX_FMT_RGB555, 0)
1836 YUV2RGBWRAPPER(yuv2rgb,, 12, AV_PIX_FMT_RGB444, 0)
1837 YUV2RGBWRAPPER(yuv2rgb,, 8, AV_PIX_FMT_RGB8, 0)
1838 YUV2RGBWRAPPER(yuv2rgb,, 4, AV_PIX_FMT_RGB4, 0)
1839 YUV2RGBWRAPPER(yuv2rgb,, 4b, AV_PIX_FMT_RGB4_BYTE, 0)
1841 static av_always_inline void yuv2rgb_write_full(SwsContext *c,
1842 uint8_t *dest, int i, int Y, int A, int U, int V,
1843 int y, enum AVPixelFormat target, int hasAlpha, int err[4])
1846 int isrgb8 = target == AV_PIX_FMT_BGR8 || target == AV_PIX_FMT_RGB8;
1848 Y -= c->yuv2rgb_y_offset;
1849 Y *= c->yuv2rgb_y_coeff;
1851 R = Y + V*c->yuv2rgb_v2r_coeff;
1852 G = Y + V*c->yuv2rgb_v2g_coeff + U*c->yuv2rgb_u2g_coeff;
1853 B = Y + U*c->yuv2rgb_u2b_coeff;
1854 if ((R | G | B) & 0xC0000000) {
1855 R = av_clip_uintp2(R, 30);
1856 G = av_clip_uintp2(G, 30);
1857 B = av_clip_uintp2(B, 30);
1861 case AV_PIX_FMT_ARGB:
1862 dest[0] = hasAlpha ? A : 255;
1867 case AV_PIX_FMT_RGB24:
1872 case AV_PIX_FMT_RGBA:
1876 dest[3] = hasAlpha ? A : 255;
1878 case AV_PIX_FMT_ABGR:
1879 dest[0] = hasAlpha ? A : 255;
1884 case AV_PIX_FMT_BGR24:
1889 case AV_PIX_FMT_BGRA:
1893 dest[3] = hasAlpha ? A : 255;
1895 case AV_PIX_FMT_BGR4_BYTE:
1896 case AV_PIX_FMT_RGB4_BYTE:
1897 case AV_PIX_FMT_BGR8:
1898 case AV_PIX_FMT_RGB8:
1902 switch (c->dither) {
1904 case SWS_DITHER_AUTO:
1909 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;
1910 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;
1911 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;
1912 c->dither_error[0][i] = err[0];
1913 c->dither_error[1][i] = err[1];
1914 c->dither_error[2][i] = err[2];
1915 r = R >> (isrgb8 ? 5 : 7);
1916 g = G >> (isrgb8 ? 5 : 6);
1917 b = B >> (isrgb8 ? 6 : 7);
1918 r = av_clip(r, 0, isrgb8 ? 7 : 1);
1919 g = av_clip(g, 0, isrgb8 ? 7 : 3);
1920 b = av_clip(b, 0, isrgb8 ? 3 : 1);
1921 err[0] = R - r*(isrgb8 ? 36 : 255);
1922 err[1] = G - g*(isrgb8 ? 36 : 85);
1923 err[2] = B - b*(isrgb8 ? 85 : 255);
1925 case SWS_DITHER_A_DITHER:
1927 /* see http://pippin.gimp.org/a_dither/ for details/origin */
1928 #define A_DITHER(u,v) (((((u)+((v)*236))*119)&0xff))
1929 r = (((R >> 19) + A_DITHER(i,y) -96)>>8);
1930 g = (((G >> 19) + A_DITHER(i + 17,y) - 96)>>8);
1931 b = (((B >> 20) + A_DITHER(i + 17*2,y) -96)>>8);
1932 r = av_clip_uintp2(r, 3);
1933 g = av_clip_uintp2(g, 3);
1934 b = av_clip_uintp2(b, 2);
1936 r = (((R >> 21) + A_DITHER(i,y)-256)>>8);
1937 g = (((G >> 19) + A_DITHER(i + 17,y)-256)>>8);
1938 b = (((B >> 21) + A_DITHER(i + 17*2,y)-256)>>8);
1939 r = av_clip_uintp2(r, 1);
1940 g = av_clip_uintp2(g, 2);
1941 b = av_clip_uintp2(b, 1);
1944 case SWS_DITHER_X_DITHER:
1946 /* see http://pippin.gimp.org/a_dither/ for details/origin */
1947 #define X_DITHER(u,v) (((((u)^((v)*237))*181)&0x1ff)/2)
1948 r = (((R >> 19) + X_DITHER(i,y) - 96)>>8);
1949 g = (((G >> 19) + X_DITHER(i + 17,y) - 96)>>8);
1950 b = (((B >> 20) + X_DITHER(i + 17*2,y) - 96)>>8);
1951 r = av_clip_uintp2(r, 3);
1952 g = av_clip_uintp2(g, 3);
1953 b = av_clip_uintp2(b, 2);
1955 r = (((R >> 21) + X_DITHER(i,y)-256)>>8);
1956 g = (((G >> 19) + X_DITHER(i + 17,y)-256)>>8);
1957 b = (((B >> 21) + X_DITHER(i + 17*2,y)-256)>>8);
1958 r = av_clip_uintp2(r, 1);
1959 g = av_clip_uintp2(g, 2);
1960 b = av_clip_uintp2(b, 1);
1966 if(target == AV_PIX_FMT_BGR4_BYTE) {
1967 dest[0] = r + 2*g + 8*b;
1968 } else if(target == AV_PIX_FMT_RGB4_BYTE) {
1969 dest[0] = b + 2*g + 8*r;
1970 } else if(target == AV_PIX_FMT_BGR8) {
1971 dest[0] = r + 8*g + 64*b;
1972 } else if(target == AV_PIX_FMT_RGB8) {
1973 dest[0] = b + 4*g + 32*r;
1980 static av_always_inline void
1981 yuv2rgb_full_X_c_template(SwsContext *c, const int16_t *lumFilter,
1982 const int16_t **lumSrc, int lumFilterSize,
1983 const int16_t *chrFilter, const int16_t **chrUSrc,
1984 const int16_t **chrVSrc, int chrFilterSize,
1985 const int16_t **alpSrc, uint8_t *dest,
1986 int dstW, int y, enum AVPixelFormat target, int hasAlpha)
1989 int step = (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) ? 3 : 4;
1991 int A = 0; //init to silence warning
1993 if( target == AV_PIX_FMT_BGR4_BYTE || target == AV_PIX_FMT_RGB4_BYTE
1994 || target == AV_PIX_FMT_BGR8 || target == AV_PIX_FMT_RGB8)
1997 for (i = 0; i < dstW; i++) {
2000 int U = (1<<9)-(128 << 19);
2001 int V = (1<<9)-(128 << 19);
2003 for (j = 0; j < lumFilterSize; j++) {
2004 Y += lumSrc[j][i] * lumFilter[j];
2006 for (j = 0; j < chrFilterSize; j++) {
2007 U += chrUSrc[j][i] * chrFilter[j];
2008 V += chrVSrc[j][i] * chrFilter[j];
2015 for (j = 0; j < lumFilterSize; j++) {
2016 A += alpSrc[j][i] * lumFilter[j];
2020 A = av_clip_uint8(A);
2022 yuv2rgb_write_full(c, dest, i, Y, A, U, V, y, target, hasAlpha, err);
2025 c->dither_error[0][i] = err[0];
2026 c->dither_error[1][i] = err[1];
2027 c->dither_error[2][i] = err[2];
2030 static av_always_inline void
2031 yuv2rgb_full_2_c_template(SwsContext *c, const int16_t *buf[2],
2032 const int16_t *ubuf[2], const int16_t *vbuf[2],
2033 const int16_t *abuf[2], uint8_t *dest, int dstW,
2034 int yalpha, int uvalpha, int y,
2035 enum AVPixelFormat target, int hasAlpha)
2037 const int16_t *buf0 = buf[0], *buf1 = buf[1],
2038 *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
2039 *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
2040 *abuf0 = hasAlpha ? abuf[0] : NULL,
2041 *abuf1 = hasAlpha ? abuf[1] : NULL;
2042 int yalpha1 = 4096 - yalpha;
2043 int uvalpha1 = 4096 - uvalpha;
2045 int step = (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) ? 3 : 4;
2047 int A = 0; // init to silcene warning
2049 av_assert2(yalpha <= 4096U);
2050 av_assert2(uvalpha <= 4096U);
2052 if( target == AV_PIX_FMT_BGR4_BYTE || target == AV_PIX_FMT_RGB4_BYTE
2053 || target == AV_PIX_FMT_BGR8 || target == AV_PIX_FMT_RGB8)
2056 for (i = 0; i < dstW; i++) {
2057 int Y = ( buf0[i] * yalpha1 + buf1[i] * yalpha ) >> 10; //FIXME rounding
2058 int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha-(128 << 19)) >> 10;
2059 int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha-(128 << 19)) >> 10;
2062 A = (abuf0[i] * yalpha1 + abuf1[i] * yalpha + (1<<18)) >> 19;
2064 A = av_clip_uint8(A);
2067 yuv2rgb_write_full(c, dest, i, Y, A, U, V, y, target, hasAlpha, err);
2070 c->dither_error[0][i] = err[0];
2071 c->dither_error[1][i] = err[1];
2072 c->dither_error[2][i] = err[2];
2075 static av_always_inline void
2076 yuv2rgb_full_1_c_template(SwsContext *c, const int16_t *buf0,
2077 const int16_t *ubuf[2], const int16_t *vbuf[2],
2078 const int16_t *abuf0, uint8_t *dest, int dstW,
2079 int uvalpha, int y, enum AVPixelFormat target,
2082 const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
2084 int step = (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) ? 3 : 4;
2087 if( target == AV_PIX_FMT_BGR4_BYTE || target == AV_PIX_FMT_RGB4_BYTE
2088 || target == AV_PIX_FMT_BGR8 || target == AV_PIX_FMT_RGB8)
2091 if (uvalpha < 2048) {
2092 int A = 0; //init to silence warning
2093 for (i = 0; i < dstW; i++) {
2094 int Y = buf0[i] << 2;
2095 int U = (ubuf0[i] - (128<<7)) * 4;
2096 int V = (vbuf0[i] - (128<<7)) * 4;
2099 A = (abuf0[i] + 64) >> 7;
2101 A = av_clip_uint8(A);
2104 yuv2rgb_write_full(c, dest, i, Y, A, U, V, y, target, hasAlpha, err);
2108 const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
2109 int A = 0; //init to silence warning
2110 for (i = 0; i < dstW; i++) {
2111 int Y = buf0[i] << 2;
2112 int U = (ubuf0[i] + ubuf1[i] - (128<<8)) << 1;
2113 int V = (vbuf0[i] + vbuf1[i] - (128<<8)) << 1;
2116 A = (abuf0[i] + 64) >> 7;
2118 A = av_clip_uint8(A);
2121 yuv2rgb_write_full(c, dest, i, Y, A, U, V, y, target, hasAlpha, err);
2126 c->dither_error[0][i] = err[0];
2127 c->dither_error[1][i] = err[1];
2128 c->dither_error[2][i] = err[2];
2132 YUV2RGBWRAPPER(yuv2, rgb_full, bgra32_full, AV_PIX_FMT_BGRA, CONFIG_SWSCALE_ALPHA && c->needAlpha)
2133 YUV2RGBWRAPPER(yuv2, rgb_full, abgr32_full, AV_PIX_FMT_ABGR, CONFIG_SWSCALE_ALPHA && c->needAlpha)
2134 YUV2RGBWRAPPER(yuv2, rgb_full, rgba32_full, AV_PIX_FMT_RGBA, CONFIG_SWSCALE_ALPHA && c->needAlpha)
2135 YUV2RGBWRAPPER(yuv2, rgb_full, argb32_full, AV_PIX_FMT_ARGB, CONFIG_SWSCALE_ALPHA && c->needAlpha)
2137 #if CONFIG_SWSCALE_ALPHA
2138 YUV2RGBWRAPPER(yuv2, rgb_full, bgra32_full, AV_PIX_FMT_BGRA, 1)
2139 YUV2RGBWRAPPER(yuv2, rgb_full, abgr32_full, AV_PIX_FMT_ABGR, 1)
2140 YUV2RGBWRAPPER(yuv2, rgb_full, rgba32_full, AV_PIX_FMT_RGBA, 1)
2141 YUV2RGBWRAPPER(yuv2, rgb_full, argb32_full, AV_PIX_FMT_ARGB, 1)
2143 YUV2RGBWRAPPER(yuv2, rgb_full, bgrx32_full, AV_PIX_FMT_BGRA, 0)
2144 YUV2RGBWRAPPER(yuv2, rgb_full, xbgr32_full, AV_PIX_FMT_ABGR, 0)
2145 YUV2RGBWRAPPER(yuv2, rgb_full, rgbx32_full, AV_PIX_FMT_RGBA, 0)
2146 YUV2RGBWRAPPER(yuv2, rgb_full, xrgb32_full, AV_PIX_FMT_ARGB, 0)
2148 YUV2RGBWRAPPER(yuv2, rgb_full, bgr24_full, AV_PIX_FMT_BGR24, 0)
2149 YUV2RGBWRAPPER(yuv2, rgb_full, rgb24_full, AV_PIX_FMT_RGB24, 0)
2151 YUV2RGBWRAPPER(yuv2, rgb_full, bgr4_byte_full, AV_PIX_FMT_BGR4_BYTE, 0)
2152 YUV2RGBWRAPPER(yuv2, rgb_full, rgb4_byte_full, AV_PIX_FMT_RGB4_BYTE, 0)
2153 YUV2RGBWRAPPER(yuv2, rgb_full, bgr8_full, AV_PIX_FMT_BGR8, 0)
2154 YUV2RGBWRAPPER(yuv2, rgb_full, rgb8_full, AV_PIX_FMT_RGB8, 0)
2157 yuv2gbrp_full_X_c(SwsContext *c, const int16_t *lumFilter,
2158 const int16_t **lumSrc, int lumFilterSize,
2159 const int16_t *chrFilter, const int16_t **chrUSrc,
2160 const int16_t **chrVSrc, int chrFilterSize,
2161 const int16_t **alpSrc, uint8_t **dest,
2164 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->dstFormat);
2166 int hasAlpha = (desc->flags & AV_PIX_FMT_FLAG_ALPHA) && alpSrc;
2167 uint16_t **dest16 = (uint16_t**)dest;
2168 int SH = 22 + 8 - desc->comp[0].depth;
2169 int A = 0; // init to silence warning
2171 for (i = 0; i < dstW; i++) {
2174 int U = (1 << 9) - (128 << 19);
2175 int V = (1 << 9) - (128 << 19);
2178 for (j = 0; j < lumFilterSize; j++)
2179 Y += lumSrc[j][i] * lumFilter[j];
2181 for (j = 0; j < chrFilterSize; j++) {
2182 U += chrUSrc[j][i] * chrFilter[j];
2183 V += chrVSrc[j][i] * chrFilter[j];
2193 for (j = 0; j < lumFilterSize; j++)
2194 A += alpSrc[j][i] * lumFilter[j];
2197 A = av_clip_uintp2(A, 27);
2200 Y -= c->yuv2rgb_y_offset;
2201 Y *= c->yuv2rgb_y_coeff;
2203 R = Y + V * c->yuv2rgb_v2r_coeff;
2204 G = Y + V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
2205 B = Y + U * c->yuv2rgb_u2b_coeff;
2207 if ((R | G | B) & 0xC0000000) {
2208 R = av_clip_uintp2(R, 30);
2209 G = av_clip_uintp2(G, 30);
2210 B = av_clip_uintp2(B, 30);
2214 dest16[0][i] = G >> SH;
2215 dest16[1][i] = B >> SH;
2216 dest16[2][i] = R >> SH;
2218 dest16[3][i] = A >> (SH - 3);
2220 dest[0][i] = G >> 22;
2221 dest[1][i] = B >> 22;
2222 dest[2][i] = R >> 22;
2224 dest[3][i] = A >> 19;
2227 if (SH != 22 && (!isBE(c->dstFormat)) != (!HAVE_BIGENDIAN)) {
2228 for (i = 0; i < dstW; i++) {
2229 dest16[0][i] = av_bswap16(dest16[0][i]);
2230 dest16[1][i] = av_bswap16(dest16[1][i]);
2231 dest16[2][i] = av_bswap16(dest16[2][i]);
2233 dest16[3][i] = av_bswap16(dest16[3][i]);
2239 yuv2gbrp16_full_X_c(SwsContext *c, const int16_t *lumFilter,
2240 const int16_t **lumSrcx, int lumFilterSize,
2241 const int16_t *chrFilter, const int16_t **chrUSrcx,
2242 const int16_t **chrVSrcx, int chrFilterSize,
2243 const int16_t **alpSrcx, uint8_t **dest,
2246 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->dstFormat);
2248 int hasAlpha = (desc->flags & AV_PIX_FMT_FLAG_ALPHA) && alpSrcx;
2249 uint16_t **dest16 = (uint16_t**)dest;
2250 const int32_t **lumSrc = (const int32_t**)lumSrcx;
2251 const int32_t **chrUSrc = (const int32_t**)chrUSrcx;
2252 const int32_t **chrVSrc = (const int32_t**)chrVSrcx;
2253 const int32_t **alpSrc = (const int32_t**)alpSrcx;
2255 for (i = 0; i < dstW; i++) {
2257 int Y = -0x40000000;
2258 int U = -(128 << 23);
2259 int V = -(128 << 23);
2262 for (j = 0; j < lumFilterSize; j++)
2263 Y += lumSrc[j][i] * (unsigned)lumFilter[j];
2265 for (j = 0; j < chrFilterSize; j++) {
2266 U += chrUSrc[j][i] * (unsigned)chrFilter[j];
2267 V += chrVSrc[j][i] * (unsigned)chrFilter[j];
2278 for (j = 0; j < lumFilterSize; j++)
2279 A += alpSrc[j][i] * lumFilter[j];
2285 Y -= c->yuv2rgb_y_offset;
2286 Y *= c->yuv2rgb_y_coeff;
2288 R = V * c->yuv2rgb_v2r_coeff;
2289 G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
2290 B = U * c->yuv2rgb_u2b_coeff;
2292 R = av_clip_uintp2(Y + R, 30);
2293 G = av_clip_uintp2(Y + G, 30);
2294 B = av_clip_uintp2(Y + B, 30);
2296 dest16[0][i] = G >> 14;
2297 dest16[1][i] = B >> 14;
2298 dest16[2][i] = R >> 14;
2300 dest16[3][i] = av_clip_uintp2(A, 30) >> 14;
2302 if ((!isBE(c->dstFormat)) != (!HAVE_BIGENDIAN)) {
2303 for (i = 0; i < dstW; i++) {
2304 dest16[0][i] = av_bswap16(dest16[0][i]);
2305 dest16[1][i] = av_bswap16(dest16[1][i]);
2306 dest16[2][i] = av_bswap16(dest16[2][i]);
2308 dest16[3][i] = av_bswap16(dest16[3][i]);
2314 yuv2ya8_1_c(SwsContext *c, const int16_t *buf0,
2315 const int16_t *ubuf[2], const int16_t *vbuf[2],
2316 const int16_t *abuf0, uint8_t *dest, int dstW,
2319 int hasAlpha = !!abuf0;
2322 for (i = 0; i < dstW; i++) {
2323 int Y = (buf0[i] + 64) >> 7;
2326 Y = av_clip_uint8(Y);
2329 A = (abuf0[i] + 64) >> 7;
2331 A = av_clip_uint8(A);
2335 dest[i * 2 + 1] = hasAlpha ? A : 255;
2340 yuv2ya8_2_c(SwsContext *c, const int16_t *buf[2],
2341 const int16_t *ubuf[2], const int16_t *vbuf[2],
2342 const int16_t *abuf[2], uint8_t *dest, int dstW,
2343 int yalpha, int uvalpha, int y)
2345 int hasAlpha = abuf && abuf[0] && abuf[1];
2346 const int16_t *buf0 = buf[0], *buf1 = buf[1],
2347 *abuf0 = hasAlpha ? abuf[0] : NULL,
2348 *abuf1 = hasAlpha ? abuf[1] : NULL;
2349 int yalpha1 = 4096 - yalpha;
2352 av_assert2(yalpha <= 4096U);
2354 for (i = 0; i < dstW; i++) {
2355 int Y = (buf0[i] * yalpha1 + buf1[i] * yalpha) >> 19;
2358 Y = av_clip_uint8(Y);
2361 A = (abuf0[i] * yalpha1 + abuf1[i] * yalpha) >> 19;
2362 A = av_clip_uint8(A);
2366 dest[i * 2 + 1] = hasAlpha ? A : 255;
2371 yuv2ya8_X_c(SwsContext *c, const int16_t *lumFilter,
2372 const int16_t **lumSrc, int lumFilterSize,
2373 const int16_t *chrFilter, const int16_t **chrUSrc,
2374 const int16_t **chrVSrc, int chrFilterSize,
2375 const int16_t **alpSrc, uint8_t *dest, int dstW, int y)
2377 int hasAlpha = !!alpSrc;
2380 for (i = 0; i < dstW; i++) {
2382 int Y = 1 << 18, A = 1 << 18;
2384 for (j = 0; j < lumFilterSize; j++)
2385 Y += lumSrc[j][i] * lumFilter[j];
2389 Y = av_clip_uint8(Y);
2392 for (j = 0; j < lumFilterSize; j++)
2393 A += alpSrc[j][i] * lumFilter[j];
2398 A = av_clip_uint8(A);
2402 dest[2 * i + 1] = hasAlpha ? A : 255;
2407 yuv2ayuv64le_X_c(SwsContext *c, const int16_t *lumFilter,
2408 const int16_t **_lumSrc, int lumFilterSize,
2409 const int16_t *chrFilter, const int16_t **_chrUSrc,
2410 const int16_t **_chrVSrc, int chrFilterSize,
2411 const int16_t **_alpSrc, uint8_t *dest, int dstW, int y)
2413 const int32_t **lumSrc = (const int32_t **) _lumSrc,
2414 **chrUSrc = (const int32_t **) _chrUSrc,
2415 **chrVSrc = (const int32_t **) _chrVSrc,
2416 **alpSrc = (const int32_t **) _alpSrc;
2417 int hasAlpha = !!alpSrc;
2420 for (i = 0; i < dstW; i++) {
2421 int Y = 1 << 14, U = 1 << 14;
2422 int V = 1 << 14, A = 1 << 14;
2430 for (j = 0; j < lumFilterSize; j++)
2431 Y += lumSrc[j][i] * (unsigned)lumFilter[j];
2433 for (j = 0; j < chrFilterSize; j++)
2434 U += chrUSrc[j][i] * (unsigned)chrFilter[j];
2436 for (j = 0; j < chrFilterSize; j++)
2437 V += chrVSrc[j][i] * (unsigned)chrFilter[j];
2440 for (j = 0; j < lumFilterSize; j++)
2441 A += alpSrc[j][i] * (unsigned)lumFilter[j];
2443 Y = 0x8000 + av_clip_int16(Y >> 15);
2444 U = 0x8000 + av_clip_int16(U >> 15);
2445 V = 0x8000 + av_clip_int16(V >> 15);
2446 A = 0x8000 + av_clip_int16(A >> 15);
2448 AV_WL16(dest + 8 * i, hasAlpha ? A : 65535);
2449 AV_WL16(dest + 8 * i + 2, Y);
2450 AV_WL16(dest + 8 * i + 4, U);
2451 AV_WL16(dest + 8 * i + 6, V);
2455 av_cold void ff_sws_init_output_funcs(SwsContext *c,
2456 yuv2planar1_fn *yuv2plane1,
2457 yuv2planarX_fn *yuv2planeX,
2458 yuv2interleavedX_fn *yuv2nv12cX,
2459 yuv2packed1_fn *yuv2packed1,
2460 yuv2packed2_fn *yuv2packed2,
2461 yuv2packedX_fn *yuv2packedX,
2462 yuv2anyX_fn *yuv2anyX)
2464 enum AVPixelFormat dstFormat = c->dstFormat;
2465 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(dstFormat);
2467 if (dstFormat == AV_PIX_FMT_P010LE || dstFormat == AV_PIX_FMT_P010BE) {
2468 *yuv2plane1 = isBE(dstFormat) ? yuv2p010l1_BE_c : yuv2p010l1_LE_c;
2469 *yuv2planeX = isBE(dstFormat) ? yuv2p010lX_BE_c : yuv2p010lX_LE_c;
2470 *yuv2nv12cX = yuv2p010cX_c;
2471 } else if (is16BPS(dstFormat)) {
2472 *yuv2planeX = isBE(dstFormat) ? yuv2planeX_16BE_c : yuv2planeX_16LE_c;
2473 *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_16BE_c : yuv2plane1_16LE_c;
2474 if (dstFormat == AV_PIX_FMT_P016LE || dstFormat == AV_PIX_FMT_P016BE) {
2475 *yuv2nv12cX = yuv2p016cX_c;
2477 } else if (isNBPS(dstFormat)) {
2478 if (desc->comp[0].depth == 9) {
2479 *yuv2planeX = isBE(dstFormat) ? yuv2planeX_9BE_c : yuv2planeX_9LE_c;
2480 *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_9BE_c : yuv2plane1_9LE_c;
2481 } else if (desc->comp[0].depth == 10) {
2482 *yuv2planeX = isBE(dstFormat) ? yuv2planeX_10BE_c : yuv2planeX_10LE_c;
2483 *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_10BE_c : yuv2plane1_10LE_c;
2484 } else if (desc->comp[0].depth == 12) {
2485 *yuv2planeX = isBE(dstFormat) ? yuv2planeX_12BE_c : yuv2planeX_12LE_c;
2486 *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_12BE_c : yuv2plane1_12LE_c;
2487 } else if (desc->comp[0].depth == 14) {
2488 *yuv2planeX = isBE(dstFormat) ? yuv2planeX_14BE_c : yuv2planeX_14LE_c;
2489 *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_14BE_c : yuv2plane1_14LE_c;
2492 } else if (dstFormat == AV_PIX_FMT_GRAYF32BE) {
2493 *yuv2planeX = yuv2planeX_floatBE_c;
2494 *yuv2plane1 = yuv2plane1_floatBE_c;
2495 } else if (dstFormat == AV_PIX_FMT_GRAYF32LE) {
2496 *yuv2planeX = yuv2planeX_floatLE_c;
2497 *yuv2plane1 = yuv2plane1_floatLE_c;
2499 *yuv2plane1 = yuv2plane1_8_c;
2500 *yuv2planeX = yuv2planeX_8_c;
2501 if (dstFormat == AV_PIX_FMT_NV12 || dstFormat == AV_PIX_FMT_NV21 ||
2502 dstFormat == AV_PIX_FMT_NV24 || dstFormat == AV_PIX_FMT_NV42)
2503 *yuv2nv12cX = yuv2nv12cX_c;
2506 if(c->flags & SWS_FULL_CHR_H_INT) {
2507 switch (dstFormat) {
2508 case AV_PIX_FMT_RGBA:
2510 *yuv2packedX = yuv2rgba32_full_X_c;
2511 *yuv2packed2 = yuv2rgba32_full_2_c;
2512 *yuv2packed1 = yuv2rgba32_full_1_c;
2514 #if CONFIG_SWSCALE_ALPHA
2516 *yuv2packedX = yuv2rgba32_full_X_c;
2517 *yuv2packed2 = yuv2rgba32_full_2_c;
2518 *yuv2packed1 = yuv2rgba32_full_1_c;
2520 #endif /* CONFIG_SWSCALE_ALPHA */
2522 *yuv2packedX = yuv2rgbx32_full_X_c;
2523 *yuv2packed2 = yuv2rgbx32_full_2_c;
2524 *yuv2packed1 = yuv2rgbx32_full_1_c;
2526 #endif /* !CONFIG_SMALL */
2528 case AV_PIX_FMT_ARGB:
2530 *yuv2packedX = yuv2argb32_full_X_c;
2531 *yuv2packed2 = yuv2argb32_full_2_c;
2532 *yuv2packed1 = yuv2argb32_full_1_c;
2534 #if CONFIG_SWSCALE_ALPHA
2536 *yuv2packedX = yuv2argb32_full_X_c;
2537 *yuv2packed2 = yuv2argb32_full_2_c;
2538 *yuv2packed1 = yuv2argb32_full_1_c;
2540 #endif /* CONFIG_SWSCALE_ALPHA */
2542 *yuv2packedX = yuv2xrgb32_full_X_c;
2543 *yuv2packed2 = yuv2xrgb32_full_2_c;
2544 *yuv2packed1 = yuv2xrgb32_full_1_c;
2546 #endif /* !CONFIG_SMALL */
2548 case AV_PIX_FMT_BGRA:
2550 *yuv2packedX = yuv2bgra32_full_X_c;
2551 *yuv2packed2 = yuv2bgra32_full_2_c;
2552 *yuv2packed1 = yuv2bgra32_full_1_c;
2554 #if CONFIG_SWSCALE_ALPHA
2556 *yuv2packedX = yuv2bgra32_full_X_c;
2557 *yuv2packed2 = yuv2bgra32_full_2_c;
2558 *yuv2packed1 = yuv2bgra32_full_1_c;
2560 #endif /* CONFIG_SWSCALE_ALPHA */
2562 *yuv2packedX = yuv2bgrx32_full_X_c;
2563 *yuv2packed2 = yuv2bgrx32_full_2_c;
2564 *yuv2packed1 = yuv2bgrx32_full_1_c;
2566 #endif /* !CONFIG_SMALL */
2568 case AV_PIX_FMT_ABGR:
2570 *yuv2packedX = yuv2abgr32_full_X_c;
2571 *yuv2packed2 = yuv2abgr32_full_2_c;
2572 *yuv2packed1 = yuv2abgr32_full_1_c;
2574 #if CONFIG_SWSCALE_ALPHA
2576 *yuv2packedX = yuv2abgr32_full_X_c;
2577 *yuv2packed2 = yuv2abgr32_full_2_c;
2578 *yuv2packed1 = yuv2abgr32_full_1_c;
2580 #endif /* CONFIG_SWSCALE_ALPHA */
2582 *yuv2packedX = yuv2xbgr32_full_X_c;
2583 *yuv2packed2 = yuv2xbgr32_full_2_c;
2584 *yuv2packed1 = yuv2xbgr32_full_1_c;
2586 #endif /* !CONFIG_SMALL */
2588 case AV_PIX_FMT_RGBA64LE:
2589 #if CONFIG_SWSCALE_ALPHA
2591 *yuv2packedX = yuv2rgba64le_full_X_c;
2592 *yuv2packed2 = yuv2rgba64le_full_2_c;
2593 *yuv2packed1 = yuv2rgba64le_full_1_c;
2595 #endif /* CONFIG_SWSCALE_ALPHA */
2597 *yuv2packedX = yuv2rgbx64le_full_X_c;
2598 *yuv2packed2 = yuv2rgbx64le_full_2_c;
2599 *yuv2packed1 = yuv2rgbx64le_full_1_c;
2602 case AV_PIX_FMT_RGBA64BE:
2603 #if CONFIG_SWSCALE_ALPHA
2605 *yuv2packedX = yuv2rgba64be_full_X_c;
2606 *yuv2packed2 = yuv2rgba64be_full_2_c;
2607 *yuv2packed1 = yuv2rgba64be_full_1_c;
2609 #endif /* CONFIG_SWSCALE_ALPHA */
2611 *yuv2packedX = yuv2rgbx64be_full_X_c;
2612 *yuv2packed2 = yuv2rgbx64be_full_2_c;
2613 *yuv2packed1 = yuv2rgbx64be_full_1_c;
2616 case AV_PIX_FMT_BGRA64LE:
2617 #if CONFIG_SWSCALE_ALPHA
2619 *yuv2packedX = yuv2bgra64le_full_X_c;
2620 *yuv2packed2 = yuv2bgra64le_full_2_c;
2621 *yuv2packed1 = yuv2bgra64le_full_1_c;
2623 #endif /* CONFIG_SWSCALE_ALPHA */
2625 *yuv2packedX = yuv2bgrx64le_full_X_c;
2626 *yuv2packed2 = yuv2bgrx64le_full_2_c;
2627 *yuv2packed1 = yuv2bgrx64le_full_1_c;
2630 case AV_PIX_FMT_BGRA64BE:
2631 #if CONFIG_SWSCALE_ALPHA
2633 *yuv2packedX = yuv2bgra64be_full_X_c;
2634 *yuv2packed2 = yuv2bgra64be_full_2_c;
2635 *yuv2packed1 = yuv2bgra64be_full_1_c;
2637 #endif /* CONFIG_SWSCALE_ALPHA */
2639 *yuv2packedX = yuv2bgrx64be_full_X_c;
2640 *yuv2packed2 = yuv2bgrx64be_full_2_c;
2641 *yuv2packed1 = yuv2bgrx64be_full_1_c;
2645 case AV_PIX_FMT_RGB24:
2646 *yuv2packedX = yuv2rgb24_full_X_c;
2647 *yuv2packed2 = yuv2rgb24_full_2_c;
2648 *yuv2packed1 = yuv2rgb24_full_1_c;
2650 case AV_PIX_FMT_BGR24:
2651 *yuv2packedX = yuv2bgr24_full_X_c;
2652 *yuv2packed2 = yuv2bgr24_full_2_c;
2653 *yuv2packed1 = yuv2bgr24_full_1_c;
2655 case AV_PIX_FMT_RGB48LE:
2656 *yuv2packedX = yuv2rgb48le_full_X_c;
2657 *yuv2packed2 = yuv2rgb48le_full_2_c;
2658 *yuv2packed1 = yuv2rgb48le_full_1_c;
2660 case AV_PIX_FMT_BGR48LE:
2661 *yuv2packedX = yuv2bgr48le_full_X_c;
2662 *yuv2packed2 = yuv2bgr48le_full_2_c;
2663 *yuv2packed1 = yuv2bgr48le_full_1_c;
2665 case AV_PIX_FMT_RGB48BE:
2666 *yuv2packedX = yuv2rgb48be_full_X_c;
2667 *yuv2packed2 = yuv2rgb48be_full_2_c;
2668 *yuv2packed1 = yuv2rgb48be_full_1_c;
2670 case AV_PIX_FMT_BGR48BE:
2671 *yuv2packedX = yuv2bgr48be_full_X_c;
2672 *yuv2packed2 = yuv2bgr48be_full_2_c;
2673 *yuv2packed1 = yuv2bgr48be_full_1_c;
2675 case AV_PIX_FMT_BGR4_BYTE:
2676 *yuv2packedX = yuv2bgr4_byte_full_X_c;
2677 *yuv2packed2 = yuv2bgr4_byte_full_2_c;
2678 *yuv2packed1 = yuv2bgr4_byte_full_1_c;
2680 case AV_PIX_FMT_RGB4_BYTE:
2681 *yuv2packedX = yuv2rgb4_byte_full_X_c;
2682 *yuv2packed2 = yuv2rgb4_byte_full_2_c;
2683 *yuv2packed1 = yuv2rgb4_byte_full_1_c;
2685 case AV_PIX_FMT_BGR8:
2686 *yuv2packedX = yuv2bgr8_full_X_c;
2687 *yuv2packed2 = yuv2bgr8_full_2_c;
2688 *yuv2packed1 = yuv2bgr8_full_1_c;
2690 case AV_PIX_FMT_RGB8:
2691 *yuv2packedX = yuv2rgb8_full_X_c;
2692 *yuv2packed2 = yuv2rgb8_full_2_c;
2693 *yuv2packed1 = yuv2rgb8_full_1_c;
2695 case AV_PIX_FMT_GBRP:
2696 case AV_PIX_FMT_GBRP9BE:
2697 case AV_PIX_FMT_GBRP9LE:
2698 case AV_PIX_FMT_GBRP10BE:
2699 case AV_PIX_FMT_GBRP10LE:
2700 case AV_PIX_FMT_GBRP12BE:
2701 case AV_PIX_FMT_GBRP12LE:
2702 case AV_PIX_FMT_GBRP14BE:
2703 case AV_PIX_FMT_GBRP14LE:
2704 case AV_PIX_FMT_GBRAP:
2705 case AV_PIX_FMT_GBRAP10BE:
2706 case AV_PIX_FMT_GBRAP10LE:
2707 case AV_PIX_FMT_GBRAP12BE:
2708 case AV_PIX_FMT_GBRAP12LE:
2709 *yuv2anyX = yuv2gbrp_full_X_c;
2711 case AV_PIX_FMT_GBRP16BE:
2712 case AV_PIX_FMT_GBRP16LE:
2713 case AV_PIX_FMT_GBRAP16BE:
2714 case AV_PIX_FMT_GBRAP16LE:
2715 *yuv2anyX = yuv2gbrp16_full_X_c;
2718 if (!*yuv2packedX && !*yuv2anyX)
2722 switch (dstFormat) {
2723 case AV_PIX_FMT_RGBA64LE:
2724 #if CONFIG_SWSCALE_ALPHA
2726 *yuv2packed1 = yuv2rgba64le_1_c;
2727 *yuv2packed2 = yuv2rgba64le_2_c;
2728 *yuv2packedX = yuv2rgba64le_X_c;
2730 #endif /* CONFIG_SWSCALE_ALPHA */
2732 *yuv2packed1 = yuv2rgbx64le_1_c;
2733 *yuv2packed2 = yuv2rgbx64le_2_c;
2734 *yuv2packedX = yuv2rgbx64le_X_c;
2737 case AV_PIX_FMT_RGBA64BE:
2738 #if CONFIG_SWSCALE_ALPHA
2740 *yuv2packed1 = yuv2rgba64be_1_c;
2741 *yuv2packed2 = yuv2rgba64be_2_c;
2742 *yuv2packedX = yuv2rgba64be_X_c;
2744 #endif /* CONFIG_SWSCALE_ALPHA */
2746 *yuv2packed1 = yuv2rgbx64be_1_c;
2747 *yuv2packed2 = yuv2rgbx64be_2_c;
2748 *yuv2packedX = yuv2rgbx64be_X_c;
2751 case AV_PIX_FMT_BGRA64LE:
2752 #if CONFIG_SWSCALE_ALPHA
2754 *yuv2packed1 = yuv2bgra64le_1_c;
2755 *yuv2packed2 = yuv2bgra64le_2_c;
2756 *yuv2packedX = yuv2bgra64le_X_c;
2758 #endif /* CONFIG_SWSCALE_ALPHA */
2760 *yuv2packed1 = yuv2bgrx64le_1_c;
2761 *yuv2packed2 = yuv2bgrx64le_2_c;
2762 *yuv2packedX = yuv2bgrx64le_X_c;
2765 case AV_PIX_FMT_BGRA64BE:
2766 #if CONFIG_SWSCALE_ALPHA
2768 *yuv2packed1 = yuv2bgra64be_1_c;
2769 *yuv2packed2 = yuv2bgra64be_2_c;
2770 *yuv2packedX = yuv2bgra64be_X_c;
2772 #endif /* CONFIG_SWSCALE_ALPHA */
2774 *yuv2packed1 = yuv2bgrx64be_1_c;
2775 *yuv2packed2 = yuv2bgrx64be_2_c;
2776 *yuv2packedX = yuv2bgrx64be_X_c;
2779 case AV_PIX_FMT_RGB48LE:
2780 *yuv2packed1 = yuv2rgb48le_1_c;
2781 *yuv2packed2 = yuv2rgb48le_2_c;
2782 *yuv2packedX = yuv2rgb48le_X_c;
2784 case AV_PIX_FMT_RGB48BE:
2785 *yuv2packed1 = yuv2rgb48be_1_c;
2786 *yuv2packed2 = yuv2rgb48be_2_c;
2787 *yuv2packedX = yuv2rgb48be_X_c;
2789 case AV_PIX_FMT_BGR48LE:
2790 *yuv2packed1 = yuv2bgr48le_1_c;
2791 *yuv2packed2 = yuv2bgr48le_2_c;
2792 *yuv2packedX = yuv2bgr48le_X_c;
2794 case AV_PIX_FMT_BGR48BE:
2795 *yuv2packed1 = yuv2bgr48be_1_c;
2796 *yuv2packed2 = yuv2bgr48be_2_c;
2797 *yuv2packedX = yuv2bgr48be_X_c;
2799 case AV_PIX_FMT_RGB32:
2800 case AV_PIX_FMT_BGR32:
2802 *yuv2packed1 = yuv2rgb32_1_c;
2803 *yuv2packed2 = yuv2rgb32_2_c;
2804 *yuv2packedX = yuv2rgb32_X_c;
2806 #if CONFIG_SWSCALE_ALPHA
2808 *yuv2packed1 = yuv2rgba32_1_c;
2809 *yuv2packed2 = yuv2rgba32_2_c;
2810 *yuv2packedX = yuv2rgba32_X_c;
2812 #endif /* CONFIG_SWSCALE_ALPHA */
2814 *yuv2packed1 = yuv2rgbx32_1_c;
2815 *yuv2packed2 = yuv2rgbx32_2_c;
2816 *yuv2packedX = yuv2rgbx32_X_c;
2818 #endif /* !CONFIG_SMALL */
2820 case AV_PIX_FMT_RGB32_1:
2821 case AV_PIX_FMT_BGR32_1:
2823 *yuv2packed1 = yuv2rgb32_1_1_c;
2824 *yuv2packed2 = yuv2rgb32_1_2_c;
2825 *yuv2packedX = yuv2rgb32_1_X_c;
2827 #if CONFIG_SWSCALE_ALPHA
2829 *yuv2packed1 = yuv2rgba32_1_1_c;
2830 *yuv2packed2 = yuv2rgba32_1_2_c;
2831 *yuv2packedX = yuv2rgba32_1_X_c;
2833 #endif /* CONFIG_SWSCALE_ALPHA */
2835 *yuv2packed1 = yuv2rgbx32_1_1_c;
2836 *yuv2packed2 = yuv2rgbx32_1_2_c;
2837 *yuv2packedX = yuv2rgbx32_1_X_c;
2839 #endif /* !CONFIG_SMALL */
2841 case AV_PIX_FMT_RGB24:
2842 *yuv2packed1 = yuv2rgb24_1_c;
2843 *yuv2packed2 = yuv2rgb24_2_c;
2844 *yuv2packedX = yuv2rgb24_X_c;
2846 case AV_PIX_FMT_BGR24:
2847 *yuv2packed1 = yuv2bgr24_1_c;
2848 *yuv2packed2 = yuv2bgr24_2_c;
2849 *yuv2packedX = yuv2bgr24_X_c;
2851 case AV_PIX_FMT_RGB565LE:
2852 case AV_PIX_FMT_RGB565BE:
2853 case AV_PIX_FMT_BGR565LE:
2854 case AV_PIX_FMT_BGR565BE:
2855 *yuv2packed1 = yuv2rgb16_1_c;
2856 *yuv2packed2 = yuv2rgb16_2_c;
2857 *yuv2packedX = yuv2rgb16_X_c;
2859 case AV_PIX_FMT_RGB555LE:
2860 case AV_PIX_FMT_RGB555BE:
2861 case AV_PIX_FMT_BGR555LE:
2862 case AV_PIX_FMT_BGR555BE:
2863 *yuv2packed1 = yuv2rgb15_1_c;
2864 *yuv2packed2 = yuv2rgb15_2_c;
2865 *yuv2packedX = yuv2rgb15_X_c;
2867 case AV_PIX_FMT_RGB444LE:
2868 case AV_PIX_FMT_RGB444BE:
2869 case AV_PIX_FMT_BGR444LE:
2870 case AV_PIX_FMT_BGR444BE:
2871 *yuv2packed1 = yuv2rgb12_1_c;
2872 *yuv2packed2 = yuv2rgb12_2_c;
2873 *yuv2packedX = yuv2rgb12_X_c;
2875 case AV_PIX_FMT_RGB8:
2876 case AV_PIX_FMT_BGR8:
2877 *yuv2packed1 = yuv2rgb8_1_c;
2878 *yuv2packed2 = yuv2rgb8_2_c;
2879 *yuv2packedX = yuv2rgb8_X_c;
2881 case AV_PIX_FMT_RGB4:
2882 case AV_PIX_FMT_BGR4:
2883 *yuv2packed1 = yuv2rgb4_1_c;
2884 *yuv2packed2 = yuv2rgb4_2_c;
2885 *yuv2packedX = yuv2rgb4_X_c;
2887 case AV_PIX_FMT_RGB4_BYTE:
2888 case AV_PIX_FMT_BGR4_BYTE:
2889 *yuv2packed1 = yuv2rgb4b_1_c;
2890 *yuv2packed2 = yuv2rgb4b_2_c;
2891 *yuv2packedX = yuv2rgb4b_X_c;
2895 switch (dstFormat) {
2896 case AV_PIX_FMT_MONOWHITE:
2897 *yuv2packed1 = yuv2monowhite_1_c;
2898 *yuv2packed2 = yuv2monowhite_2_c;
2899 *yuv2packedX = yuv2monowhite_X_c;
2901 case AV_PIX_FMT_MONOBLACK:
2902 *yuv2packed1 = yuv2monoblack_1_c;
2903 *yuv2packed2 = yuv2monoblack_2_c;
2904 *yuv2packedX = yuv2monoblack_X_c;
2906 case AV_PIX_FMT_YUYV422:
2907 *yuv2packed1 = yuv2yuyv422_1_c;
2908 *yuv2packed2 = yuv2yuyv422_2_c;
2909 *yuv2packedX = yuv2yuyv422_X_c;
2911 case AV_PIX_FMT_YVYU422:
2912 *yuv2packed1 = yuv2yvyu422_1_c;
2913 *yuv2packed2 = yuv2yvyu422_2_c;
2914 *yuv2packedX = yuv2yvyu422_X_c;
2916 case AV_PIX_FMT_UYVY422:
2917 *yuv2packed1 = yuv2uyvy422_1_c;
2918 *yuv2packed2 = yuv2uyvy422_2_c;
2919 *yuv2packedX = yuv2uyvy422_X_c;
2921 case AV_PIX_FMT_YA8:
2922 *yuv2packed1 = yuv2ya8_1_c;
2923 *yuv2packed2 = yuv2ya8_2_c;
2924 *yuv2packedX = yuv2ya8_X_c;
2926 case AV_PIX_FMT_YA16LE:
2927 *yuv2packed1 = yuv2ya16le_1_c;
2928 *yuv2packed2 = yuv2ya16le_2_c;
2929 *yuv2packedX = yuv2ya16le_X_c;
2931 case AV_PIX_FMT_YA16BE:
2932 *yuv2packed1 = yuv2ya16be_1_c;
2933 *yuv2packed2 = yuv2ya16be_2_c;
2934 *yuv2packedX = yuv2ya16be_X_c;
2936 case AV_PIX_FMT_AYUV64LE:
2937 *yuv2packedX = yuv2ayuv64le_X_c;