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
27 #include "libavutil/avutil.h"
28 #include "libavutil/bswap.h"
29 #include "libavutil/cpu.h"
30 #include "libavutil/intreadwrite.h"
31 #include "libavutil/mathematics.h"
32 #include "libavutil/pixdesc.h"
33 #include "libavutil/avassert.h"
37 #include "swscale_internal.h"
39 #define RGB2YUV_SHIFT 15
40 #define BY ((int)(0.114 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
41 #define BV (-(int)(0.081 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
42 #define BU ((int)(0.500 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
43 #define GY ((int)(0.587 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
44 #define GV (-(int)(0.419 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
45 #define GU (-(int)(0.331 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
46 #define RY ((int)(0.299 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
47 #define RV ((int)(0.500 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
48 #define RU (-(int)(0.169 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
50 #define input_pixel(pos) (isBE(origin) ? AV_RB16(pos) : AV_RL16(pos))
52 #define r ((origin == AV_PIX_FMT_BGR48BE || origin == AV_PIX_FMT_BGR48LE) ? b_r : r_b)
53 #define b ((origin == AV_PIX_FMT_BGR48BE || origin == AV_PIX_FMT_BGR48LE) ? r_b : b_r)
55 static av_always_inline void
56 rgb64ToY_c_template(uint16_t *dst, const uint16_t *src, int width,
57 enum AVPixelFormat origin)
60 for (i = 0; i < width; i++) {
61 unsigned int r_b = input_pixel(&src[i*4+0]);
62 unsigned int g = input_pixel(&src[i*4+1]);
63 unsigned int b_r = input_pixel(&src[i*4+2]);
65 dst[i] = (RY*r + GY*g + BY*b + (0x2001<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT;
69 static av_always_inline void
70 rgb64ToUV_c_template(uint16_t *dstU, uint16_t *dstV,
71 const uint16_t *src1, const uint16_t *src2,
72 int width, enum AVPixelFormat origin)
75 av_assert1(src1==src2);
76 for (i = 0; i < width; i++) {
77 int r_b = input_pixel(&src1[i*4+0]);
78 int g = input_pixel(&src1[i*4+1]);
79 int b_r = input_pixel(&src1[i*4+2]);
81 dstU[i] = (RU*r + GU*g + BU*b + (0x10001<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT;
82 dstV[i] = (RV*r + GV*g + BV*b + (0x10001<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT;
86 static av_always_inline void
87 rgb64ToUV_half_c_template(uint16_t *dstU, uint16_t *dstV,
88 const uint16_t *src1, const uint16_t *src2,
89 int width, enum AVPixelFormat origin)
92 av_assert1(src1==src2);
93 for (i = 0; i < width; i++) {
94 int r_b = (input_pixel(&src1[8 * i + 0]) + input_pixel(&src1[8 * i + 4]) + 1) >> 1;
95 int g = (input_pixel(&src1[8 * i + 1]) + input_pixel(&src1[8 * i + 5]) + 1) >> 1;
96 int b_r = (input_pixel(&src1[8 * i + 2]) + input_pixel(&src1[8 * i + 6]) + 1) >> 1;
98 dstU[i]= (RU*r + GU*g + BU*b + (0x10001<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT;
99 dstV[i]= (RV*r + GV*g + BV*b + (0x10001<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT;
103 #define rgb64funcs(pattern, BE_LE, origin) \
104 static void pattern ## 64 ## BE_LE ## ToY_c(uint8_t *_dst, const uint8_t *_src, const uint8_t *unused0, const uint8_t *unused1,\
105 int width, uint32_t *unused) \
107 const uint16_t *src = (const uint16_t *) _src; \
108 uint16_t *dst = (uint16_t *) _dst; \
109 rgb64ToY_c_template(dst, src, width, origin); \
112 static void pattern ## 64 ## BE_LE ## ToUV_c(uint8_t *_dstU, uint8_t *_dstV, \
113 const uint8_t *unused0, const uint8_t *_src1, const uint8_t *_src2, \
114 int width, uint32_t *unused) \
116 const uint16_t *src1 = (const uint16_t *) _src1, \
117 *src2 = (const uint16_t *) _src2; \
118 uint16_t *dstU = (uint16_t *) _dstU, *dstV = (uint16_t *) _dstV; \
119 rgb64ToUV_c_template(dstU, dstV, src1, src2, width, origin); \
122 static void pattern ## 64 ## BE_LE ## ToUV_half_c(uint8_t *_dstU, uint8_t *_dstV, \
123 const uint8_t *unused0, const uint8_t *_src1, const uint8_t *_src2, \
124 int width, uint32_t *unused) \
126 const uint16_t *src1 = (const uint16_t *) _src1, \
127 *src2 = (const uint16_t *) _src2; \
128 uint16_t *dstU = (uint16_t *) _dstU, *dstV = (uint16_t *) _dstV; \
129 rgb64ToUV_half_c_template(dstU, dstV, src1, src2, width, origin); \
132 rgb64funcs(rgb, LE, AV_PIX_FMT_RGBA64LE)
133 rgb64funcs(rgb, BE, AV_PIX_FMT_RGBA64BE)
135 static av_always_inline void rgb48ToY_c_template(uint16_t *dst,
136 const uint16_t *src, int width,
137 enum AVPixelFormat origin)
140 for (i = 0; i < width; i++) {
141 unsigned int r_b = input_pixel(&src[i * 3 + 0]);
142 unsigned int g = input_pixel(&src[i * 3 + 1]);
143 unsigned int b_r = input_pixel(&src[i * 3 + 2]);
145 dst[i] = (RY * r + GY * g + BY * b + (0x2001 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT;
149 static av_always_inline void rgb48ToUV_c_template(uint16_t *dstU,
151 const uint16_t *src1,
152 const uint16_t *src2,
154 enum AVPixelFormat origin)
157 av_assert1(src1 == src2);
158 for (i = 0; i < width; i++) {
159 int r_b = input_pixel(&src1[i * 3 + 0]);
160 int g = input_pixel(&src1[i * 3 + 1]);
161 int b_r = input_pixel(&src1[i * 3 + 2]);
163 dstU[i] = (RU * r + GU * g + BU * b + (0x10001 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT;
164 dstV[i] = (RV * r + GV * g + BV * b + (0x10001 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT;
168 static av_always_inline void rgb48ToUV_half_c_template(uint16_t *dstU,
170 const uint16_t *src1,
171 const uint16_t *src2,
173 enum AVPixelFormat origin)
176 av_assert1(src1 == src2);
177 for (i = 0; i < width; i++) {
178 int r_b = (input_pixel(&src1[6 * i + 0]) +
179 input_pixel(&src1[6 * i + 3]) + 1) >> 1;
180 int g = (input_pixel(&src1[6 * i + 1]) +
181 input_pixel(&src1[6 * i + 4]) + 1) >> 1;
182 int b_r = (input_pixel(&src1[6 * i + 2]) +
183 input_pixel(&src1[6 * i + 5]) + 1) >> 1;
185 dstU[i] = (RU * r + GU * g + BU * b + (0x10001 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT;
186 dstV[i] = (RV * r + GV * g + BV * b + (0x10001 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT;
194 #define rgb48funcs(pattern, BE_LE, origin) \
195 static void pattern ## 48 ## BE_LE ## ToY_c(uint8_t *_dst, \
196 const uint8_t *_src, \
197 const uint8_t *unused0, const uint8_t *unused1,\
201 const uint16_t *src = (const uint16_t *)_src; \
202 uint16_t *dst = (uint16_t *)_dst; \
203 rgb48ToY_c_template(dst, src, width, origin); \
206 static void pattern ## 48 ## BE_LE ## ToUV_c(uint8_t *_dstU, \
208 const uint8_t *unused0, \
209 const uint8_t *_src1, \
210 const uint8_t *_src2, \
214 const uint16_t *src1 = (const uint16_t *)_src1, \
215 *src2 = (const uint16_t *)_src2; \
216 uint16_t *dstU = (uint16_t *)_dstU, \
217 *dstV = (uint16_t *)_dstV; \
218 rgb48ToUV_c_template(dstU, dstV, src1, src2, width, origin); \
221 static void pattern ## 48 ## BE_LE ## ToUV_half_c(uint8_t *_dstU, \
223 const uint8_t *unused0, \
224 const uint8_t *_src1, \
225 const uint8_t *_src2, \
229 const uint16_t *src1 = (const uint16_t *)_src1, \
230 *src2 = (const uint16_t *)_src2; \
231 uint16_t *dstU = (uint16_t *)_dstU, \
232 *dstV = (uint16_t *)_dstV; \
233 rgb48ToUV_half_c_template(dstU, dstV, src1, src2, width, origin); \
236 rgb48funcs(rgb, LE, AV_PIX_FMT_RGB48LE)
237 rgb48funcs(rgb, BE, AV_PIX_FMT_RGB48BE)
238 rgb48funcs(bgr, LE, AV_PIX_FMT_BGR48LE)
239 rgb48funcs(bgr, BE, AV_PIX_FMT_BGR48BE)
241 #define input_pixel(i) ((origin == AV_PIX_FMT_RGBA || \
242 origin == AV_PIX_FMT_BGRA || \
243 origin == AV_PIX_FMT_ARGB || \
244 origin == AV_PIX_FMT_ABGR) \
245 ? AV_RN32A(&src[(i) * 4]) \
246 : (isBE(origin) ? AV_RB16(&src[(i) * 2]) \
247 : AV_RL16(&src[(i) * 2])))
249 static av_always_inline void rgb16_32ToY_c_template(int16_t *dst,
252 enum AVPixelFormat origin,
255 int maskr, int maskg,
257 int gsh, int bsh, int S)
259 const int ry = RY << rsh, gy = GY << gsh, by = BY << bsh;
260 const unsigned rnd = (32<<((S)-1)) + (1<<(S-7));
263 for (i = 0; i < width; i++) {
264 int px = input_pixel(i) >> shp;
265 int b = (px & maskb) >> shb;
266 int g = (px & maskg) >> shg;
267 int r = (px & maskr) >> shr;
269 dst[i] = (ry * r + gy * g + by * b + rnd) >> ((S)-6);
273 static av_always_inline void rgb16_32ToUV_c_template(int16_t *dstU,
277 enum AVPixelFormat origin,
280 int maskr, int maskg,
282 int gsh, int bsh, int S)
284 const int ru = RU << rsh, gu = GU << gsh, bu = BU << bsh,
285 rv = RV << rsh, gv = GV << gsh, bv = BV << bsh;
286 const unsigned rnd = (256u<<((S)-1)) + (1<<(S-7));
289 for (i = 0; i < width; i++) {
290 int px = input_pixel(i) >> shp;
291 int b = (px & maskb) >> shb;
292 int g = (px & maskg) >> shg;
293 int r = (px & maskr) >> shr;
295 dstU[i] = (ru * r + gu * g + bu * b + rnd) >> ((S)-6);
296 dstV[i] = (rv * r + gv * g + bv * b + rnd) >> ((S)-6);
300 static av_always_inline void rgb16_32ToUV_half_c_template(int16_t *dstU,
304 enum AVPixelFormat origin,
307 int maskr, int maskg,
309 int gsh, int bsh, int S)
311 const int ru = RU << rsh, gu = GU << gsh, bu = BU << bsh,
312 rv = RV << rsh, gv = GV << gsh, bv = BV << bsh,
313 maskgx = ~(maskr | maskb);
314 const unsigned rnd = (256U<<(S)) + (1<<(S-6));
320 for (i = 0; i < width; i++) {
321 int px0 = input_pixel(2 * i + 0) >> shp;
322 int px1 = input_pixel(2 * i + 1) >> shp;
323 int b, r, g = (px0 & maskgx) + (px1 & maskgx);
324 int rb = px0 + px1 - g;
326 b = (rb & maskb) >> shb;
328 origin == AV_PIX_FMT_BGR565LE || origin == AV_PIX_FMT_BGR565BE ||
329 origin == AV_PIX_FMT_RGB565LE || origin == AV_PIX_FMT_RGB565BE) {
332 g = (g & maskg) >> shg;
334 r = (rb & maskr) >> shr;
336 dstU[i] = (ru * r + gu * g + bu * b + (unsigned)rnd) >> ((S)-6+1);
337 dstV[i] = (rv * r + gv * g + bv * b + (unsigned)rnd) >> ((S)-6+1);
343 #define rgb16_32_wrapper(fmt, name, shr, shg, shb, shp, maskr, \
344 maskg, maskb, rsh, gsh, bsh, S) \
345 static void name ## ToY_c(uint8_t *dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, \
346 int width, uint32_t *unused) \
348 rgb16_32ToY_c_template((int16_t*)dst, src, width, fmt, shr, shg, shb, shp, \
349 maskr, maskg, maskb, rsh, gsh, bsh, S); \
352 static void name ## ToUV_c(uint8_t *dstU, uint8_t *dstV, \
353 const uint8_t *unused0, const uint8_t *src, const uint8_t *dummy, \
354 int width, uint32_t *unused) \
356 rgb16_32ToUV_c_template((int16_t*)dstU, (int16_t*)dstV, src, width, fmt, \
357 shr, shg, shb, shp, \
358 maskr, maskg, maskb, rsh, gsh, bsh, S); \
361 static void name ## ToUV_half_c(uint8_t *dstU, uint8_t *dstV, \
362 const uint8_t *unused0, const uint8_t *src, \
363 const uint8_t *dummy, \
364 int width, uint32_t *unused) \
366 rgb16_32ToUV_half_c_template((int16_t*)dstU, (int16_t*)dstV, src, width, fmt, \
367 shr, shg, shb, shp, \
368 maskr, maskg, maskb, \
372 rgb16_32_wrapper(AV_PIX_FMT_BGR32, bgr32, 16, 0, 0, 0, 0xFF0000, 0xFF00, 0x00FF, 8, 0, 8, RGB2YUV_SHIFT + 8)
373 rgb16_32_wrapper(AV_PIX_FMT_BGR32_1, bgr321, 16, 0, 0, 8, 0xFF0000, 0xFF00, 0x00FF, 8, 0, 8, RGB2YUV_SHIFT + 8)
374 rgb16_32_wrapper(AV_PIX_FMT_RGB32, rgb32, 0, 0, 16, 0, 0x00FF, 0xFF00, 0xFF0000, 8, 0, 8, RGB2YUV_SHIFT + 8)
375 rgb16_32_wrapper(AV_PIX_FMT_RGB32_1, rgb321, 0, 0, 16, 8, 0x00FF, 0xFF00, 0xFF0000, 8, 0, 8, RGB2YUV_SHIFT + 8)
376 rgb16_32_wrapper(AV_PIX_FMT_BGR565LE, bgr16le, 0, 0, 0, 0, 0x001F, 0x07E0, 0xF800, 11, 5, 0, RGB2YUV_SHIFT + 8)
377 rgb16_32_wrapper(AV_PIX_FMT_BGR555LE, bgr15le, 0, 0, 0, 0, 0x001F, 0x03E0, 0x7C00, 10, 5, 0, RGB2YUV_SHIFT + 7)
378 rgb16_32_wrapper(AV_PIX_FMT_BGR444LE, bgr12le, 0, 0, 0, 0, 0x000F, 0x00F0, 0x0F00, 8, 4, 0, RGB2YUV_SHIFT + 4)
379 rgb16_32_wrapper(AV_PIX_FMT_RGB565LE, rgb16le, 0, 0, 0, 0, 0xF800, 0x07E0, 0x001F, 0, 5, 11, RGB2YUV_SHIFT + 8)
380 rgb16_32_wrapper(AV_PIX_FMT_RGB555LE, rgb15le, 0, 0, 0, 0, 0x7C00, 0x03E0, 0x001F, 0, 5, 10, RGB2YUV_SHIFT + 7)
381 rgb16_32_wrapper(AV_PIX_FMT_RGB444LE, rgb12le, 0, 0, 0, 0, 0x0F00, 0x00F0, 0x000F, 0, 4, 8, RGB2YUV_SHIFT + 4)
382 rgb16_32_wrapper(AV_PIX_FMT_BGR565BE, bgr16be, 0, 0, 0, 0, 0x001F, 0x07E0, 0xF800, 11, 5, 0, RGB2YUV_SHIFT + 8)
383 rgb16_32_wrapper(AV_PIX_FMT_BGR555BE, bgr15be, 0, 0, 0, 0, 0x001F, 0x03E0, 0x7C00, 10, 5, 0, RGB2YUV_SHIFT + 7)
384 rgb16_32_wrapper(AV_PIX_FMT_BGR444BE, bgr12be, 0, 0, 0, 0, 0x000F, 0x00F0, 0x0F00, 8, 4, 0, RGB2YUV_SHIFT + 4)
385 rgb16_32_wrapper(AV_PIX_FMT_RGB565BE, rgb16be, 0, 0, 0, 0, 0xF800, 0x07E0, 0x001F, 0, 5, 11, RGB2YUV_SHIFT + 8)
386 rgb16_32_wrapper(AV_PIX_FMT_RGB555BE, rgb15be, 0, 0, 0, 0, 0x7C00, 0x03E0, 0x001F, 0, 5, 10, RGB2YUV_SHIFT + 7)
387 rgb16_32_wrapper(AV_PIX_FMT_RGB444BE, rgb12be, 0, 0, 0, 0, 0x0F00, 0x00F0, 0x000F, 0, 4, 8, RGB2YUV_SHIFT + 4)
389 static void gbr24pToUV_half_c(uint8_t *_dstU, uint8_t *_dstV,
390 const uint8_t *gsrc, const uint8_t *bsrc, const uint8_t *rsrc,
391 int width, uint32_t *unused)
393 uint16_t *dstU = (uint16_t *)_dstU;
394 uint16_t *dstV = (uint16_t *)_dstV;
396 for (i = 0; i < width; i++) {
397 unsigned int g = gsrc[2*i] + gsrc[2*i+1];
398 unsigned int b = bsrc[2*i] + bsrc[2*i+1];
399 unsigned int r = rsrc[2*i] + rsrc[2*i+1];
401 dstU[i] = (RU*r + GU*g + BU*b + (0x4001<<(RGB2YUV_SHIFT-6))) >> (RGB2YUV_SHIFT-6+1);
402 dstV[i] = (RV*r + GV*g + BV*b + (0x4001<<(RGB2YUV_SHIFT-6))) >> (RGB2YUV_SHIFT-6+1);
406 static void rgba64ToA_c(uint8_t *_dst, const uint8_t *_src, const uint8_t *unused1,
407 const uint8_t *unused2, int width, uint32_t *unused)
409 int16_t *dst = (int16_t *)_dst;
410 const uint16_t *src = (const uint16_t *)_src;
412 for (i = 0; i < width; i++)
413 dst[i] = src[4 * i + 3];
416 static void abgrToA_c(uint8_t *_dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width, uint32_t *unused)
418 int16_t *dst = (int16_t *)_dst;
420 for (i=0; i<width; i++) {
425 static void rgbaToA_c(uint8_t *_dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width, uint32_t *unused)
427 int16_t *dst = (int16_t *)_dst;
429 for (i=0; i<width; i++) {
430 dst[i]= src[4*i+3]<<6;
434 static void palToA_c(uint8_t *_dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width, uint32_t *pal)
436 int16_t *dst = (int16_t *)_dst;
438 for (i=0; i<width; i++) {
441 dst[i]= (pal[d] >> 24)<<6;
445 static void palToY_c(uint8_t *_dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width, uint32_t *pal)
447 int16_t *dst = (int16_t *)_dst;
449 for (i = 0; i < width; i++) {
452 dst[i] = (pal[d] & 0xFF)<<6;
456 static void palToUV_c(uint8_t *_dstU, uint8_t *_dstV,
457 const uint8_t *unused0, const uint8_t *src1, const uint8_t *src2,
458 int width, uint32_t *pal)
460 uint16_t *dstU = (uint16_t *)_dstU;
461 int16_t *dstV = (int16_t *)_dstV;
463 av_assert1(src1 == src2);
464 for (i = 0; i < width; i++) {
465 int p = pal[src1[i]];
467 dstU[i] = (uint8_t)(p>> 8)<<6;
468 dstV[i] = (uint8_t)(p>>16)<<6;
472 static void monowhite2Y_c(uint8_t *_dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width, uint32_t *unused)
474 int16_t *dst = (int16_t *)_dst;
476 width = (width + 7) >> 3;
477 for (i = 0; i < width; i++) {
479 for (j = 0; j < 8; j++)
480 dst[8*i+j]= ((d>>(7-j))&1) * 16383;
484 for (j = 0; j < (width&7); j++)
485 dst[8*i+j]= ((d>>(7-j))&1) * 16383;
489 static void monoblack2Y_c(uint8_t *_dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width, uint32_t *unused)
491 int16_t *dst = (int16_t *)_dst;
493 width = (width + 7) >> 3;
494 for (i = 0; i < width; i++) {
496 for (j = 0; j < 8; j++)
497 dst[8*i+j]= ((d>>(7-j))&1) * 16383;
501 for (j = 0; j < (width&7); j++)
502 dst[8*i+j] = ((d>>(7-j))&1) * 16383;
506 static void yuy2ToY_c(uint8_t *dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width,
510 for (i = 0; i < width; i++)
514 static void yuy2ToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *unused0, const uint8_t *src1,
515 const uint8_t *src2, int width, uint32_t *unused)
518 for (i = 0; i < width; i++) {
519 dstU[i] = src1[4 * i + 1];
520 dstV[i] = src1[4 * i + 3];
522 av_assert1(src1 == src2);
525 static void bswap16Y_c(uint8_t *_dst, const uint8_t *_src, const uint8_t *unused1, const uint8_t *unused2, int width,
529 const uint16_t *src = (const uint16_t *)_src;
530 uint16_t *dst = (uint16_t *)_dst;
531 for (i = 0; i < width; i++)
532 dst[i] = av_bswap16(src[i]);
535 static void bswap16UV_c(uint8_t *_dstU, uint8_t *_dstV, const uint8_t *unused0, const uint8_t *_src1,
536 const uint8_t *_src2, int width, uint32_t *unused)
539 const uint16_t *src1 = (const uint16_t *)_src1,
540 *src2 = (const uint16_t *)_src2;
541 uint16_t *dstU = (uint16_t *)_dstU, *dstV = (uint16_t *)_dstV;
542 for (i = 0; i < width; i++) {
543 dstU[i] = av_bswap16(src1[i]);
544 dstV[i] = av_bswap16(src2[i]);
548 /* This is almost identical to the previous, end exists only because
549 * yuy2ToY/UV)(dst, src + 1, ...) would have 100% unaligned accesses. */
550 static void uyvyToY_c(uint8_t *dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width,
554 for (i = 0; i < width; i++)
555 dst[i] = src[2 * i + 1];
558 static void uyvyToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *unused0, const uint8_t *src1,
559 const uint8_t *src2, int width, uint32_t *unused)
562 for (i = 0; i < width; i++) {
563 dstU[i] = src1[4 * i + 0];
564 dstV[i] = src1[4 * i + 2];
566 av_assert1(src1 == src2);
569 static av_always_inline void nvXXtoUV_c(uint8_t *dst1, uint8_t *dst2,
570 const uint8_t *src, int width)
573 for (i = 0; i < width; i++) {
574 dst1[i] = src[2 * i + 0];
575 dst2[i] = src[2 * i + 1];
579 static void nv12ToUV_c(uint8_t *dstU, uint8_t *dstV,
580 const uint8_t *unused0, const uint8_t *src1, const uint8_t *src2,
581 int width, uint32_t *unused)
583 nvXXtoUV_c(dstU, dstV, src1, width);
586 static void nv21ToUV_c(uint8_t *dstU, uint8_t *dstV,
587 const uint8_t *unused0, const uint8_t *src1, const uint8_t *src2,
588 int width, uint32_t *unused)
590 nvXXtoUV_c(dstV, dstU, src1, width);
593 #define input_pixel(pos) (isBE(origin) ? AV_RB16(pos) : AV_RL16(pos))
595 static void bgr24ToY_c(uint8_t *_dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2,
596 int width, uint32_t *unused)
598 int16_t *dst = (int16_t *)_dst;
600 for (i = 0; i < width; i++) {
601 int b = src[i * 3 + 0];
602 int g = src[i * 3 + 1];
603 int r = src[i * 3 + 2];
605 dst[i] = ((RY*r + GY*g + BY*b + (32<<(RGB2YUV_SHIFT-1)) + (1<<(RGB2YUV_SHIFT-7)))>>(RGB2YUV_SHIFT-6));
609 static void bgr24ToUV_c(uint8_t *_dstU, uint8_t *_dstV, const uint8_t *unused0, const uint8_t *src1,
610 const uint8_t *src2, int width, uint32_t *unused)
612 int16_t *dstU = (int16_t *)_dstU;
613 int16_t *dstV = (int16_t *)_dstV;
615 for (i = 0; i < width; i++) {
616 int b = src1[3 * i + 0];
617 int g = src1[3 * i + 1];
618 int r = src1[3 * i + 2];
620 dstU[i] = (RU*r + GU*g + BU*b + (256<<(RGB2YUV_SHIFT-1)) + (1<<(RGB2YUV_SHIFT-7)))>>(RGB2YUV_SHIFT-6);
621 dstV[i] = (RV*r + GV*g + BV*b + (256<<(RGB2YUV_SHIFT-1)) + (1<<(RGB2YUV_SHIFT-7)))>>(RGB2YUV_SHIFT-6);
623 av_assert1(src1 == src2);
626 static void bgr24ToUV_half_c(uint8_t *_dstU, uint8_t *_dstV, const uint8_t *unused0, const uint8_t *src1,
627 const uint8_t *src2, int width, uint32_t *unused)
629 int16_t *dstU = (int16_t *)_dstU;
630 int16_t *dstV = (int16_t *)_dstV;
632 for (i = 0; i < width; i++) {
633 int b = src1[6 * i + 0] + src1[6 * i + 3];
634 int g = src1[6 * i + 1] + src1[6 * i + 4];
635 int r = src1[6 * i + 2] + src1[6 * i + 5];
637 dstU[i] = (RU*r + GU*g + BU*b + (256<<RGB2YUV_SHIFT) + (1<<(RGB2YUV_SHIFT-6)))>>(RGB2YUV_SHIFT-5);
638 dstV[i] = (RV*r + GV*g + BV*b + (256<<RGB2YUV_SHIFT) + (1<<(RGB2YUV_SHIFT-6)))>>(RGB2YUV_SHIFT-5);
640 av_assert1(src1 == src2);
643 static void rgb24ToY_c(uint8_t *_dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width,
646 int16_t *dst = (int16_t *)_dst;
648 for (i = 0; i < width; i++) {
649 int r = src[i * 3 + 0];
650 int g = src[i * 3 + 1];
651 int b = src[i * 3 + 2];
653 dst[i] = ((RY*r + GY*g + BY*b + (32<<(RGB2YUV_SHIFT-1)) + (1<<(RGB2YUV_SHIFT-7)))>>(RGB2YUV_SHIFT-6));
657 static void rgb24ToUV_c(uint8_t *_dstU, uint8_t *_dstV, const uint8_t *unused0, const uint8_t *src1,
658 const uint8_t *src2, int width, uint32_t *unused)
660 int16_t *dstU = (int16_t *)_dstU;
661 int16_t *dstV = (int16_t *)_dstV;
663 av_assert1(src1 == src2);
664 for (i = 0; i < width; i++) {
665 int r = src1[3 * i + 0];
666 int g = src1[3 * i + 1];
667 int b = src1[3 * i + 2];
669 dstU[i] = (RU*r + GU*g + BU*b + (256<<(RGB2YUV_SHIFT-1)) + (1<<(RGB2YUV_SHIFT-7)))>>(RGB2YUV_SHIFT-6);
670 dstV[i] = (RV*r + GV*g + BV*b + (256<<(RGB2YUV_SHIFT-1)) + (1<<(RGB2YUV_SHIFT-7)))>>(RGB2YUV_SHIFT-6);
674 static void rgb24ToUV_half_c(uint8_t *_dstU, uint8_t *_dstV, const uint8_t *unused0, const uint8_t *src1,
675 const uint8_t *src2, int width, uint32_t *unused)
677 int16_t *dstU = (int16_t *)_dstU;
678 int16_t *dstV = (int16_t *)_dstV;
680 av_assert1(src1 == src2);
681 for (i = 0; i < width; i++) {
682 int r = src1[6 * i + 0] + src1[6 * i + 3];
683 int g = src1[6 * i + 1] + src1[6 * i + 4];
684 int b = src1[6 * i + 2] + src1[6 * i + 5];
686 dstU[i] = (RU*r + GU*g + BU*b + (256<<RGB2YUV_SHIFT) + (1<<(RGB2YUV_SHIFT-6)))>>(RGB2YUV_SHIFT-5);
687 dstV[i] = (RV*r + GV*g + BV*b + (256<<RGB2YUV_SHIFT) + (1<<(RGB2YUV_SHIFT-6)))>>(RGB2YUV_SHIFT-5);
691 static void planar_rgb_to_y(uint8_t *_dst, const uint8_t *src[4], int width)
693 uint16_t *dst = (uint16_t *)_dst;
695 for (i = 0; i < width; i++) {
700 dst[i] = (RY*r + GY*g + BY*b + (0x801<<(RGB2YUV_SHIFT-7))) >> (RGB2YUV_SHIFT-6);
704 static void planar_rgb_to_uv(uint8_t *_dstU, uint8_t *_dstV, const uint8_t *src[4], int width)
706 uint16_t *dstU = (uint16_t *)_dstU;
707 uint16_t *dstV = (uint16_t *)_dstV;
709 for (i = 0; i < width; i++) {
714 dstU[i] = (RU*r + GU*g + BU*b + (0x4001<<(RGB2YUV_SHIFT-7))) >> (RGB2YUV_SHIFT-6);
715 dstV[i] = (RV*r + GV*g + BV*b + (0x4001<<(RGB2YUV_SHIFT-7))) >> (RGB2YUV_SHIFT-6);
720 is_be ? AV_RB16(src) : AV_RL16(src)
721 static av_always_inline void planar_rgb16_to_y(uint8_t *_dst, const uint8_t *_src[4],
722 int width, int bpc, int is_be)
725 const uint16_t **src = (const uint16_t **)_src;
726 uint16_t *dst = (uint16_t *)_dst;
727 for (i = 0; i < width; i++) {
728 int g = rdpx(src[0] + i);
729 int b = rdpx(src[1] + i);
730 int r = rdpx(src[2] + i);
732 dst[i] = ((RY * r + GY * g + BY * b + (33 << (RGB2YUV_SHIFT + bpc - 9))) >> RGB2YUV_SHIFT);
736 static void planar_rgb9le_to_y(uint8_t *dst, const uint8_t *src[4], int w)
738 planar_rgb16_to_y(dst, src, w, 9, 0);
741 static void planar_rgb9be_to_y(uint8_t *dst, const uint8_t *src[4], int w)
743 planar_rgb16_to_y(dst, src, w, 9, 1);
746 static void planar_rgb10le_to_y(uint8_t *dst, const uint8_t *src[4], int w)
748 planar_rgb16_to_y(dst, src, w, 10, 0);
751 static void planar_rgb10be_to_y(uint8_t *dst, const uint8_t *src[4], int w)
753 planar_rgb16_to_y(dst, src, w, 10, 1);
756 static void planar_rgb12le_to_y(uint8_t *dst, const uint8_t *src[4], int w)
758 planar_rgb16_to_y(dst, src, w, 12, 0);
761 static void planar_rgb12be_to_y(uint8_t *dst, const uint8_t *src[4], int w)
763 planar_rgb16_to_y(dst, src, w, 12, 1);
766 static void planar_rgb14le_to_y(uint8_t *dst, const uint8_t *src[4], int w)
768 planar_rgb16_to_y(dst, src, w, 14, 0);
771 static void planar_rgb14be_to_y(uint8_t *dst, const uint8_t *src[4], int w)
773 planar_rgb16_to_y(dst, src, w, 14, 1);
776 static void planar_rgb16le_to_y(uint8_t *dst, const uint8_t *src[4], int w)
778 planar_rgb16_to_y(dst, src, w, 16, 0);
781 static void planar_rgb16be_to_y(uint8_t *dst, const uint8_t *src[4], int w)
783 planar_rgb16_to_y(dst, src, w, 16, 1);
786 static av_always_inline void planar_rgb16_to_uv(uint8_t *_dstU, uint8_t *_dstV,
787 const uint8_t *_src[4], int width,
791 const uint16_t **src = (const uint16_t **)_src;
792 uint16_t *dstU = (uint16_t *)_dstU;
793 uint16_t *dstV = (uint16_t *)_dstV;
794 for (i = 0; i < width; i++) {
795 int g = rdpx(src[0] + i);
796 int b = rdpx(src[1] + i);
797 int r = rdpx(src[2] + i);
799 dstU[i] = (RU * r + GU * g + BU * b + (257 << (RGB2YUV_SHIFT + bpc - 9))) >> RGB2YUV_SHIFT;
800 dstV[i] = (RV * r + GV * g + BV * b + (257 << (RGB2YUV_SHIFT + bpc - 9))) >> RGB2YUV_SHIFT;
805 static void planar_rgb9le_to_uv(uint8_t *dstU, uint8_t *dstV,
806 const uint8_t *src[4], int w)
808 planar_rgb16_to_uv(dstU, dstV, src, w, 9, 0);
811 static void planar_rgb9be_to_uv(uint8_t *dstU, uint8_t *dstV,
812 const uint8_t *src[4], int w)
814 planar_rgb16_to_uv(dstU, dstV, src, w, 9, 1);
817 static void planar_rgb10le_to_uv(uint8_t *dstU, uint8_t *dstV,
818 const uint8_t *src[4], int w)
820 planar_rgb16_to_uv(dstU, dstV, src, w, 10, 0);
823 static void planar_rgb10be_to_uv(uint8_t *dstU, uint8_t *dstV,
824 const uint8_t *src[4], int w)
826 planar_rgb16_to_uv(dstU, dstV, src, w, 10, 1);
829 static void planar_rgb12le_to_uv(uint8_t *dstU, uint8_t *dstV,
830 const uint8_t *src[4], int w)
832 planar_rgb16_to_uv(dstU, dstV, src, w, 12, 0);
835 static void planar_rgb12be_to_uv(uint8_t *dstU, uint8_t *dstV,
836 const uint8_t *src[4], int w)
838 planar_rgb16_to_uv(dstU, dstV, src, w, 12, 1);
841 static void planar_rgb14le_to_uv(uint8_t *dstU, uint8_t *dstV,
842 const uint8_t *src[4], int w)
844 planar_rgb16_to_uv(dstU, dstV, src, w, 14, 0);
847 static void planar_rgb14be_to_uv(uint8_t *dstU, uint8_t *dstV,
848 const uint8_t *src[4], int w)
850 planar_rgb16_to_uv(dstU, dstV, src, w, 14, 1);
853 static void planar_rgb16le_to_uv(uint8_t *dstU, uint8_t *dstV,
854 const uint8_t *src[4], int w)
856 planar_rgb16_to_uv(dstU, dstV, src, w, 16, 0);
859 static void planar_rgb16be_to_uv(uint8_t *dstU, uint8_t *dstV,
860 const uint8_t *src[4], int w)
862 planar_rgb16_to_uv(dstU, dstV, src, w, 16, 1);
865 av_cold void ff_sws_init_input_funcs(SwsContext *c)
867 enum AVPixelFormat srcFormat = c->srcFormat;
871 case AV_PIX_FMT_YUYV422:
872 c->chrToYV12 = yuy2ToUV_c;
874 case AV_PIX_FMT_UYVY422:
875 c->chrToYV12 = uyvyToUV_c;
877 case AV_PIX_FMT_NV12:
878 c->chrToYV12 = nv12ToUV_c;
880 case AV_PIX_FMT_NV21:
881 c->chrToYV12 = nv21ToUV_c;
883 case AV_PIX_FMT_RGB8:
884 case AV_PIX_FMT_BGR8:
885 case AV_PIX_FMT_PAL8:
886 case AV_PIX_FMT_BGR4_BYTE:
887 case AV_PIX_FMT_RGB4_BYTE:
888 c->chrToYV12 = palToUV_c;
890 case AV_PIX_FMT_GBRP9LE:
891 c->readChrPlanar = planar_rgb9le_to_uv;
893 case AV_PIX_FMT_GBRP10LE:
894 c->readChrPlanar = planar_rgb10le_to_uv;
896 case AV_PIX_FMT_GBRP12LE:
897 c->readChrPlanar = planar_rgb12le_to_uv;
899 case AV_PIX_FMT_GBRP14LE:
900 c->readChrPlanar = planar_rgb14le_to_uv;
902 case AV_PIX_FMT_GBRP16LE:
903 c->readChrPlanar = planar_rgb16le_to_uv;
905 case AV_PIX_FMT_GBRP9BE:
906 c->readChrPlanar = planar_rgb9be_to_uv;
908 case AV_PIX_FMT_GBRP10BE:
909 c->readChrPlanar = planar_rgb10be_to_uv;
911 case AV_PIX_FMT_GBRP12BE:
912 c->readChrPlanar = planar_rgb12be_to_uv;
914 case AV_PIX_FMT_GBRP14BE:
915 c->readChrPlanar = planar_rgb14be_to_uv;
917 case AV_PIX_FMT_GBRP16BE:
918 c->readChrPlanar = planar_rgb16be_to_uv;
920 case AV_PIX_FMT_GBRP:
921 c->readChrPlanar = planar_rgb_to_uv;
924 case AV_PIX_FMT_YUV444P9LE:
925 case AV_PIX_FMT_YUV422P9LE:
926 case AV_PIX_FMT_YUV420P9LE:
927 case AV_PIX_FMT_YUV422P10LE:
928 case AV_PIX_FMT_YUV444P10LE:
929 case AV_PIX_FMT_YUV420P10LE:
930 case AV_PIX_FMT_YUV422P12LE:
931 case AV_PIX_FMT_YUV444P12LE:
932 case AV_PIX_FMT_YUV420P12LE:
933 case AV_PIX_FMT_YUV422P14LE:
934 case AV_PIX_FMT_YUV444P14LE:
935 case AV_PIX_FMT_YUV420P14LE:
936 case AV_PIX_FMT_YUV420P16LE:
937 case AV_PIX_FMT_YUV422P16LE:
938 case AV_PIX_FMT_YUV444P16LE:
940 case AV_PIX_FMT_YUVA444P9LE:
941 case AV_PIX_FMT_YUVA422P9LE:
942 case AV_PIX_FMT_YUVA420P9LE:
943 case AV_PIX_FMT_YUVA444P10LE:
944 case AV_PIX_FMT_YUVA422P10LE:
945 case AV_PIX_FMT_YUVA420P10LE:
946 case AV_PIX_FMT_YUVA420P16LE:
947 case AV_PIX_FMT_YUVA422P16LE:
948 case AV_PIX_FMT_YUVA444P16LE:
949 c->chrToYV12 = bswap16UV_c;
952 case AV_PIX_FMT_YUV444P9BE:
953 case AV_PIX_FMT_YUV422P9BE:
954 case AV_PIX_FMT_YUV420P9BE:
955 case AV_PIX_FMT_YUV444P10BE:
956 case AV_PIX_FMT_YUV422P10BE:
957 case AV_PIX_FMT_YUV420P10BE:
958 case AV_PIX_FMT_YUV444P12BE:
959 case AV_PIX_FMT_YUV422P12BE:
960 case AV_PIX_FMT_YUV420P12BE:
961 case AV_PIX_FMT_YUV444P14BE:
962 case AV_PIX_FMT_YUV422P14BE:
963 case AV_PIX_FMT_YUV420P14BE:
964 case AV_PIX_FMT_YUV420P16BE:
965 case AV_PIX_FMT_YUV422P16BE:
966 case AV_PIX_FMT_YUV444P16BE:
968 case AV_PIX_FMT_YUVA444P9BE:
969 case AV_PIX_FMT_YUVA422P9BE:
970 case AV_PIX_FMT_YUVA420P9BE:
971 case AV_PIX_FMT_YUVA444P10BE:
972 case AV_PIX_FMT_YUVA422P10BE:
973 case AV_PIX_FMT_YUVA420P10BE:
974 case AV_PIX_FMT_YUVA420P16BE:
975 case AV_PIX_FMT_YUVA422P16BE:
976 case AV_PIX_FMT_YUVA444P16BE:
977 c->chrToYV12 = bswap16UV_c;
981 if (c->chrSrcHSubSample) {
983 case AV_PIX_FMT_RGBA64BE:
984 c->chrToYV12 = rgb64BEToUV_half_c;
986 case AV_PIX_FMT_RGBA64LE:
987 c->chrToYV12 = rgb64LEToUV_half_c;
989 case AV_PIX_FMT_RGB48BE:
990 c->chrToYV12 = rgb48BEToUV_half_c;
992 case AV_PIX_FMT_RGB48LE:
993 c->chrToYV12 = rgb48LEToUV_half_c;
995 case AV_PIX_FMT_BGR48BE:
996 c->chrToYV12 = bgr48BEToUV_half_c;
998 case AV_PIX_FMT_BGR48LE:
999 c->chrToYV12 = bgr48LEToUV_half_c;
1001 case AV_PIX_FMT_RGB32:
1002 c->chrToYV12 = bgr32ToUV_half_c;
1004 case AV_PIX_FMT_RGB32_1:
1005 c->chrToYV12 = bgr321ToUV_half_c;
1007 case AV_PIX_FMT_BGR24:
1008 c->chrToYV12 = bgr24ToUV_half_c;
1010 case AV_PIX_FMT_BGR565LE:
1011 c->chrToYV12 = bgr16leToUV_half_c;
1013 case AV_PIX_FMT_BGR565BE:
1014 c->chrToYV12 = bgr16beToUV_half_c;
1016 case AV_PIX_FMT_BGR555LE:
1017 c->chrToYV12 = bgr15leToUV_half_c;
1019 case AV_PIX_FMT_BGR555BE:
1020 c->chrToYV12 = bgr15beToUV_half_c;
1022 case AV_PIX_FMT_GBR24P :
1023 c->chrToYV12 = gbr24pToUV_half_c;
1025 case AV_PIX_FMT_BGR444LE:
1026 c->chrToYV12 = bgr12leToUV_half_c;
1028 case AV_PIX_FMT_BGR444BE:
1029 c->chrToYV12 = bgr12beToUV_half_c;
1031 case AV_PIX_FMT_BGR32:
1032 c->chrToYV12 = rgb32ToUV_half_c;
1034 case AV_PIX_FMT_BGR32_1:
1035 c->chrToYV12 = rgb321ToUV_half_c;
1037 case AV_PIX_FMT_RGB24:
1038 c->chrToYV12 = rgb24ToUV_half_c;
1040 case AV_PIX_FMT_RGB565LE:
1041 c->chrToYV12 = rgb16leToUV_half_c;
1043 case AV_PIX_FMT_RGB565BE:
1044 c->chrToYV12 = rgb16beToUV_half_c;
1046 case AV_PIX_FMT_RGB555LE:
1047 c->chrToYV12 = rgb15leToUV_half_c;
1049 case AV_PIX_FMT_RGB555BE:
1050 c->chrToYV12 = rgb15beToUV_half_c;
1052 case AV_PIX_FMT_RGB444LE:
1053 c->chrToYV12 = rgb12leToUV_half_c;
1055 case AV_PIX_FMT_RGB444BE:
1056 c->chrToYV12 = rgb12beToUV_half_c;
1060 switch (srcFormat) {
1061 case AV_PIX_FMT_RGBA64BE:
1062 c->chrToYV12 = rgb64BEToUV_c;
1064 case AV_PIX_FMT_RGBA64LE:
1065 c->chrToYV12 = rgb64LEToUV_c;
1067 case AV_PIX_FMT_RGB48BE:
1068 c->chrToYV12 = rgb48BEToUV_c;
1070 case AV_PIX_FMT_RGB48LE:
1071 c->chrToYV12 = rgb48LEToUV_c;
1073 case AV_PIX_FMT_BGR48BE:
1074 c->chrToYV12 = bgr48BEToUV_c;
1076 case AV_PIX_FMT_BGR48LE:
1077 c->chrToYV12 = bgr48LEToUV_c;
1079 case AV_PIX_FMT_RGB32:
1080 c->chrToYV12 = bgr32ToUV_c;
1082 case AV_PIX_FMT_RGB32_1:
1083 c->chrToYV12 = bgr321ToUV_c;
1085 case AV_PIX_FMT_BGR24:
1086 c->chrToYV12 = bgr24ToUV_c;
1088 case AV_PIX_FMT_BGR565LE:
1089 c->chrToYV12 = bgr16leToUV_c;
1091 case AV_PIX_FMT_BGR565BE:
1092 c->chrToYV12 = bgr16beToUV_c;
1094 case AV_PIX_FMT_BGR555LE:
1095 c->chrToYV12 = bgr15leToUV_c;
1097 case AV_PIX_FMT_BGR555BE:
1098 c->chrToYV12 = bgr15beToUV_c;
1100 case AV_PIX_FMT_BGR444LE:
1101 c->chrToYV12 = bgr12leToUV_c;
1103 case AV_PIX_FMT_BGR444BE:
1104 c->chrToYV12 = bgr12beToUV_c;
1106 case AV_PIX_FMT_BGR32:
1107 c->chrToYV12 = rgb32ToUV_c;
1109 case AV_PIX_FMT_BGR32_1:
1110 c->chrToYV12 = rgb321ToUV_c;
1112 case AV_PIX_FMT_RGB24:
1113 c->chrToYV12 = rgb24ToUV_c;
1115 case AV_PIX_FMT_RGB565LE:
1116 c->chrToYV12 = rgb16leToUV_c;
1118 case AV_PIX_FMT_RGB565BE:
1119 c->chrToYV12 = rgb16beToUV_c;
1121 case AV_PIX_FMT_RGB555LE:
1122 c->chrToYV12 = rgb15leToUV_c;
1124 case AV_PIX_FMT_RGB555BE:
1125 c->chrToYV12 = rgb15beToUV_c;
1127 case AV_PIX_FMT_RGB444LE:
1128 c->chrToYV12 = rgb12leToUV_c;
1130 case AV_PIX_FMT_RGB444BE:
1131 c->chrToYV12 = rgb12beToUV_c;
1136 c->lumToYV12 = NULL;
1137 c->alpToYV12 = NULL;
1138 switch (srcFormat) {
1139 case AV_PIX_FMT_GBRP9LE:
1140 c->readLumPlanar = planar_rgb9le_to_y;
1142 case AV_PIX_FMT_GBRP10LE:
1143 c->readLumPlanar = planar_rgb10le_to_y;
1145 case AV_PIX_FMT_GBRP12LE:
1146 c->readLumPlanar = planar_rgb12le_to_y;
1148 case AV_PIX_FMT_GBRP14LE:
1149 c->readLumPlanar = planar_rgb14le_to_y;
1151 case AV_PIX_FMT_GBRP16LE:
1152 c->readLumPlanar = planar_rgb16le_to_y;
1154 case AV_PIX_FMT_GBRP9BE:
1155 c->readLumPlanar = planar_rgb9be_to_y;
1157 case AV_PIX_FMT_GBRP10BE:
1158 c->readLumPlanar = planar_rgb10be_to_y;
1160 case AV_PIX_FMT_GBRP12BE:
1161 c->readLumPlanar = planar_rgb12be_to_y;
1163 case AV_PIX_FMT_GBRP14BE:
1164 c->readLumPlanar = planar_rgb14be_to_y;
1166 case AV_PIX_FMT_GBRP16BE:
1167 c->readLumPlanar = planar_rgb16be_to_y;
1169 case AV_PIX_FMT_GBRP:
1170 c->readLumPlanar = planar_rgb_to_y;
1173 case AV_PIX_FMT_YUV444P9LE:
1174 case AV_PIX_FMT_YUV422P9LE:
1175 case AV_PIX_FMT_YUV420P9LE:
1176 case AV_PIX_FMT_YUV444P10LE:
1177 case AV_PIX_FMT_YUV422P10LE:
1178 case AV_PIX_FMT_YUV420P10LE:
1179 case AV_PIX_FMT_YUV444P12LE:
1180 case AV_PIX_FMT_YUV422P12LE:
1181 case AV_PIX_FMT_YUV420P12LE:
1182 case AV_PIX_FMT_YUV444P14LE:
1183 case AV_PIX_FMT_YUV422P14LE:
1184 case AV_PIX_FMT_YUV420P14LE:
1185 case AV_PIX_FMT_YUV420P16LE:
1186 case AV_PIX_FMT_YUV422P16LE:
1187 case AV_PIX_FMT_YUV444P16LE:
1189 case AV_PIX_FMT_GRAY16LE:
1190 c->lumToYV12 = bswap16Y_c;
1192 case AV_PIX_FMT_YUVA444P9LE:
1193 case AV_PIX_FMT_YUVA422P9LE:
1194 case AV_PIX_FMT_YUVA420P9LE:
1195 case AV_PIX_FMT_YUVA444P10LE:
1196 case AV_PIX_FMT_YUVA422P10LE:
1197 case AV_PIX_FMT_YUVA420P10LE:
1198 case AV_PIX_FMT_YUVA420P16LE:
1199 case AV_PIX_FMT_YUVA422P16LE:
1200 case AV_PIX_FMT_YUVA444P16LE:
1201 c->lumToYV12 = bswap16Y_c;
1202 c->alpToYV12 = bswap16Y_c;
1205 case AV_PIX_FMT_YUV444P9BE:
1206 case AV_PIX_FMT_YUV422P9BE:
1207 case AV_PIX_FMT_YUV420P9BE:
1208 case AV_PIX_FMT_YUV444P10BE:
1209 case AV_PIX_FMT_YUV422P10BE:
1210 case AV_PIX_FMT_YUV420P10BE:
1211 case AV_PIX_FMT_YUV444P12BE:
1212 case AV_PIX_FMT_YUV422P12BE:
1213 case AV_PIX_FMT_YUV420P12BE:
1214 case AV_PIX_FMT_YUV444P14BE:
1215 case AV_PIX_FMT_YUV422P14BE:
1216 case AV_PIX_FMT_YUV420P14BE:
1217 case AV_PIX_FMT_YUV420P16BE:
1218 case AV_PIX_FMT_YUV422P16BE:
1219 case AV_PIX_FMT_YUV444P16BE:
1221 case AV_PIX_FMT_GRAY16BE:
1222 c->lumToYV12 = bswap16Y_c;
1224 case AV_PIX_FMT_YUVA444P9BE:
1225 case AV_PIX_FMT_YUVA422P9BE:
1226 case AV_PIX_FMT_YUVA420P9BE:
1227 case AV_PIX_FMT_YUVA444P10BE:
1228 case AV_PIX_FMT_YUVA422P10BE:
1229 case AV_PIX_FMT_YUVA420P10BE:
1230 case AV_PIX_FMT_YUVA420P16BE:
1231 case AV_PIX_FMT_YUVA422P16BE:
1232 case AV_PIX_FMT_YUVA444P16BE:
1233 c->lumToYV12 = bswap16Y_c;
1234 c->alpToYV12 = bswap16Y_c;
1237 case AV_PIX_FMT_YUYV422:
1238 case AV_PIX_FMT_Y400A:
1239 c->lumToYV12 = yuy2ToY_c;
1241 case AV_PIX_FMT_UYVY422:
1242 c->lumToYV12 = uyvyToY_c;
1244 case AV_PIX_FMT_BGR24:
1245 c->lumToYV12 = bgr24ToY_c;
1247 case AV_PIX_FMT_BGR565LE:
1248 c->lumToYV12 = bgr16leToY_c;
1250 case AV_PIX_FMT_BGR565BE:
1251 c->lumToYV12 = bgr16beToY_c;
1253 case AV_PIX_FMT_BGR555LE:
1254 c->lumToYV12 = bgr15leToY_c;
1256 case AV_PIX_FMT_BGR555BE:
1257 c->lumToYV12 = bgr15beToY_c;
1259 case AV_PIX_FMT_BGR444LE:
1260 c->lumToYV12 = bgr12leToY_c;
1262 case AV_PIX_FMT_BGR444BE:
1263 c->lumToYV12 = bgr12beToY_c;
1265 case AV_PIX_FMT_RGB24:
1266 c->lumToYV12 = rgb24ToY_c;
1268 case AV_PIX_FMT_RGB565LE:
1269 c->lumToYV12 = rgb16leToY_c;
1271 case AV_PIX_FMT_RGB565BE:
1272 c->lumToYV12 = rgb16beToY_c;
1274 case AV_PIX_FMT_RGB555LE:
1275 c->lumToYV12 = rgb15leToY_c;
1277 case AV_PIX_FMT_RGB555BE:
1278 c->lumToYV12 = rgb15beToY_c;
1280 case AV_PIX_FMT_RGB444LE:
1281 c->lumToYV12 = rgb12leToY_c;
1283 case AV_PIX_FMT_RGB444BE:
1284 c->lumToYV12 = rgb12beToY_c;
1286 case AV_PIX_FMT_RGB8:
1287 case AV_PIX_FMT_BGR8:
1288 case AV_PIX_FMT_PAL8:
1289 case AV_PIX_FMT_BGR4_BYTE:
1290 case AV_PIX_FMT_RGB4_BYTE:
1291 c->lumToYV12 = palToY_c;
1293 case AV_PIX_FMT_MONOBLACK:
1294 c->lumToYV12 = monoblack2Y_c;
1296 case AV_PIX_FMT_MONOWHITE:
1297 c->lumToYV12 = monowhite2Y_c;
1299 case AV_PIX_FMT_RGB32:
1300 c->lumToYV12 = bgr32ToY_c;
1302 case AV_PIX_FMT_RGB32_1:
1303 c->lumToYV12 = bgr321ToY_c;
1305 case AV_PIX_FMT_BGR32:
1306 c->lumToYV12 = rgb32ToY_c;
1308 case AV_PIX_FMT_BGR32_1:
1309 c->lumToYV12 = rgb321ToY_c;
1311 case AV_PIX_FMT_RGB48BE:
1312 c->lumToYV12 = rgb48BEToY_c;
1314 case AV_PIX_FMT_RGB48LE:
1315 c->lumToYV12 = rgb48LEToY_c;
1317 case AV_PIX_FMT_BGR48BE:
1318 c->lumToYV12 = bgr48BEToY_c;
1320 case AV_PIX_FMT_BGR48LE:
1321 c->lumToYV12 = bgr48LEToY_c;
1323 case AV_PIX_FMT_RGBA64BE:
1324 c->lumToYV12 = rgb64BEToY_c;
1326 case AV_PIX_FMT_RGBA64LE:
1327 c->lumToYV12 = rgb64LEToY_c;
1331 if (is16BPS(srcFormat) || isNBPS(srcFormat)) {
1332 if (HAVE_BIGENDIAN == !isBE(srcFormat))
1333 c->alpToYV12 = bswap16Y_c;
1335 switch (srcFormat) {
1336 case AV_PIX_FMT_RGBA64LE:
1337 case AV_PIX_FMT_RGBA64BE: c->alpToYV12 = rgba64ToA_c; break;
1338 case AV_PIX_FMT_BGRA:
1339 case AV_PIX_FMT_RGBA:
1340 c->alpToYV12 = rgbaToA_c;
1342 case AV_PIX_FMT_ABGR:
1343 case AV_PIX_FMT_ARGB:
1344 c->alpToYV12 = abgrToA_c;
1346 case AV_PIX_FMT_Y400A:
1347 c->alpToYV12 = uyvyToY_c;
1349 case AV_PIX_FMT_PAL8 :
1350 c->alpToYV12 = palToA_c;