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/avutil.h"
27 #include "libavutil/bswap.h"
28 #include "libavutil/cpu.h"
29 #include "libavutil/intreadwrite.h"
30 #include "libavutil/mathematics.h"
31 #include "libavutil/pixdesc.h"
32 #include "libavutil/avassert.h"
36 #include "swscale_internal.h"
38 #define input_pixel(pos) (isBE(origin) ? AV_RB16(pos) : AV_RL16(pos))
40 #define r ((origin == AV_PIX_FMT_BGR48BE || origin == AV_PIX_FMT_BGR48LE || origin == AV_PIX_FMT_BGRA64BE || origin == AV_PIX_FMT_BGRA64LE) ? b_r : r_b)
41 #define b ((origin == AV_PIX_FMT_BGR48BE || origin == AV_PIX_FMT_BGR48LE || origin == AV_PIX_FMT_BGRA64BE || origin == AV_PIX_FMT_BGRA64LE) ? r_b : b_r)
43 static av_always_inline void
44 rgb64ToY_c_template(uint16_t *dst, const uint16_t *src, int width,
45 enum AVPixelFormat origin, int32_t *rgb2yuv)
47 int32_t ry = rgb2yuv[RY_IDX], gy = rgb2yuv[GY_IDX], by = rgb2yuv[BY_IDX];
49 for (i = 0; i < width; i++) {
50 unsigned int r_b = input_pixel(&src[i*4+0]);
51 unsigned int g = input_pixel(&src[i*4+1]);
52 unsigned int b_r = input_pixel(&src[i*4+2]);
54 dst[i] = (ry*r + gy*g + by*b + (0x2001<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT;
58 static av_always_inline void
59 rgb64ToUV_c_template(uint16_t *dstU, uint16_t *dstV,
60 const uint16_t *src1, const uint16_t *src2,
61 int width, enum AVPixelFormat origin, int32_t *rgb2yuv)
64 int32_t ru = rgb2yuv[RU_IDX], gu = rgb2yuv[GU_IDX], bu = rgb2yuv[BU_IDX];
65 int32_t rv = rgb2yuv[RV_IDX], gv = rgb2yuv[GV_IDX], bv = rgb2yuv[BV_IDX];
66 av_assert1(src1==src2);
67 for (i = 0; i < width; i++) {
68 int r_b = input_pixel(&src1[i*4+0]);
69 int g = input_pixel(&src1[i*4+1]);
70 int b_r = input_pixel(&src1[i*4+2]);
72 dstU[i] = (ru*r + gu*g + bu*b + (0x10001<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT;
73 dstV[i] = (rv*r + gv*g + bv*b + (0x10001<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT;
77 static av_always_inline void
78 rgb64ToUV_half_c_template(uint16_t *dstU, uint16_t *dstV,
79 const uint16_t *src1, const uint16_t *src2,
80 int width, enum AVPixelFormat origin, int32_t *rgb2yuv)
83 int32_t ru = rgb2yuv[RU_IDX], gu = rgb2yuv[GU_IDX], bu = rgb2yuv[BU_IDX];
84 int32_t rv = rgb2yuv[RV_IDX], gv = rgb2yuv[GV_IDX], bv = rgb2yuv[BV_IDX];
85 av_assert1(src1==src2);
86 for (i = 0; i < width; i++) {
87 int r_b = (input_pixel(&src1[8 * i + 0]) + input_pixel(&src1[8 * i + 4]) + 1) >> 1;
88 int g = (input_pixel(&src1[8 * i + 1]) + input_pixel(&src1[8 * i + 5]) + 1) >> 1;
89 int b_r = (input_pixel(&src1[8 * i + 2]) + input_pixel(&src1[8 * i + 6]) + 1) >> 1;
91 dstU[i]= (ru*r + gu*g + bu*b + (0x10001<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT;
92 dstV[i]= (rv*r + gv*g + bv*b + (0x10001<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT;
96 #define rgb64funcs(pattern, BE_LE, origin) \
97 static void pattern ## 64 ## BE_LE ## ToY_c(uint8_t *_dst, const uint8_t *_src, const uint8_t *unused0, const uint8_t *unused1,\
98 int width, uint32_t *rgb2yuv) \
100 const uint16_t *src = (const uint16_t *) _src; \
101 uint16_t *dst = (uint16_t *) _dst; \
102 rgb64ToY_c_template(dst, src, width, origin, rgb2yuv); \
105 static void pattern ## 64 ## BE_LE ## ToUV_c(uint8_t *_dstU, uint8_t *_dstV, \
106 const uint8_t *unused0, const uint8_t *_src1, const uint8_t *_src2, \
107 int width, uint32_t *rgb2yuv) \
109 const uint16_t *src1 = (const uint16_t *) _src1, \
110 *src2 = (const uint16_t *) _src2; \
111 uint16_t *dstU = (uint16_t *) _dstU, *dstV = (uint16_t *) _dstV; \
112 rgb64ToUV_c_template(dstU, dstV, src1, src2, width, origin, rgb2yuv); \
115 static void pattern ## 64 ## BE_LE ## ToUV_half_c(uint8_t *_dstU, uint8_t *_dstV, \
116 const uint8_t *unused0, const uint8_t *_src1, const uint8_t *_src2, \
117 int width, uint32_t *rgb2yuv) \
119 const uint16_t *src1 = (const uint16_t *) _src1, \
120 *src2 = (const uint16_t *) _src2; \
121 uint16_t *dstU = (uint16_t *) _dstU, *dstV = (uint16_t *) _dstV; \
122 rgb64ToUV_half_c_template(dstU, dstV, src1, src2, width, origin, rgb2yuv); \
125 rgb64funcs(rgb, LE, AV_PIX_FMT_RGBA64LE)
126 rgb64funcs(rgb, BE, AV_PIX_FMT_RGBA64BE)
127 rgb64funcs(bgr, LE, AV_PIX_FMT_BGRA64LE)
128 rgb64funcs(bgr, BE, AV_PIX_FMT_BGRA64BE)
130 static av_always_inline void rgb48ToY_c_template(uint16_t *dst,
131 const uint16_t *src, int width,
132 enum AVPixelFormat origin,
135 int32_t ry = rgb2yuv[RY_IDX], gy = rgb2yuv[GY_IDX], by = rgb2yuv[BY_IDX];
137 for (i = 0; i < width; i++) {
138 unsigned int r_b = input_pixel(&src[i * 3 + 0]);
139 unsigned int g = input_pixel(&src[i * 3 + 1]);
140 unsigned int b_r = input_pixel(&src[i * 3 + 2]);
142 dst[i] = (ry*r + gy*g + by*b + (0x2001 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT;
146 static av_always_inline void rgb48ToUV_c_template(uint16_t *dstU,
148 const uint16_t *src1,
149 const uint16_t *src2,
151 enum AVPixelFormat origin,
155 int32_t ru = rgb2yuv[RU_IDX], gu = rgb2yuv[GU_IDX], bu = rgb2yuv[BU_IDX];
156 int32_t rv = rgb2yuv[RV_IDX], gv = rgb2yuv[GV_IDX], bv = rgb2yuv[BV_IDX];
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,
177 int32_t ru = rgb2yuv[RU_IDX], gu = rgb2yuv[GU_IDX], bu = rgb2yuv[BU_IDX];
178 int32_t rv = rgb2yuv[RV_IDX], gv = rgb2yuv[GV_IDX], bv = rgb2yuv[BV_IDX];
179 av_assert1(src1 == src2);
180 for (i = 0; i < width; i++) {
181 int r_b = (input_pixel(&src1[6 * i + 0]) +
182 input_pixel(&src1[6 * i + 3]) + 1) >> 1;
183 int g = (input_pixel(&src1[6 * i + 1]) +
184 input_pixel(&src1[6 * i + 4]) + 1) >> 1;
185 int b_r = (input_pixel(&src1[6 * i + 2]) +
186 input_pixel(&src1[6 * i + 5]) + 1) >> 1;
188 dstU[i] = (ru*r + gu*g + bu*b + (0x10001 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT;
189 dstV[i] = (rv*r + gv*g + bv*b + (0x10001 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT;
197 #define rgb48funcs(pattern, BE_LE, origin) \
198 static void pattern ## 48 ## BE_LE ## ToY_c(uint8_t *_dst, \
199 const uint8_t *_src, \
200 const uint8_t *unused0, const uint8_t *unused1,\
204 const uint16_t *src = (const uint16_t *)_src; \
205 uint16_t *dst = (uint16_t *)_dst; \
206 rgb48ToY_c_template(dst, src, width, origin, rgb2yuv); \
209 static void pattern ## 48 ## BE_LE ## ToUV_c(uint8_t *_dstU, \
211 const uint8_t *unused0, \
212 const uint8_t *_src1, \
213 const uint8_t *_src2, \
217 const uint16_t *src1 = (const uint16_t *)_src1, \
218 *src2 = (const uint16_t *)_src2; \
219 uint16_t *dstU = (uint16_t *)_dstU, \
220 *dstV = (uint16_t *)_dstV; \
221 rgb48ToUV_c_template(dstU, dstV, src1, src2, width, origin, rgb2yuv); \
224 static void pattern ## 48 ## BE_LE ## ToUV_half_c(uint8_t *_dstU, \
226 const uint8_t *unused0, \
227 const uint8_t *_src1, \
228 const uint8_t *_src2, \
232 const uint16_t *src1 = (const uint16_t *)_src1, \
233 *src2 = (const uint16_t *)_src2; \
234 uint16_t *dstU = (uint16_t *)_dstU, \
235 *dstV = (uint16_t *)_dstV; \
236 rgb48ToUV_half_c_template(dstU, dstV, src1, src2, width, origin, rgb2yuv); \
239 rgb48funcs(rgb, LE, AV_PIX_FMT_RGB48LE)
240 rgb48funcs(rgb, BE, AV_PIX_FMT_RGB48BE)
241 rgb48funcs(bgr, LE, AV_PIX_FMT_BGR48LE)
242 rgb48funcs(bgr, BE, AV_PIX_FMT_BGR48BE)
244 #define input_pixel(i) ((origin == AV_PIX_FMT_RGBA || \
245 origin == AV_PIX_FMT_BGRA || \
246 origin == AV_PIX_FMT_ARGB || \
247 origin == AV_PIX_FMT_ABGR) \
248 ? AV_RN32A(&src[(i) * 4]) \
249 : (isBE(origin) ? AV_RB16(&src[(i) * 2]) \
250 : AV_RL16(&src[(i) * 2])))
252 static av_always_inline void rgb16_32ToY_c_template(int16_t *dst,
255 enum AVPixelFormat origin,
258 int maskr, int maskg,
260 int gsh, int bsh, int S,
263 const int ry = rgb2yuv[RY_IDX]<<rsh, gy = rgb2yuv[GY_IDX]<<gsh, by = rgb2yuv[BY_IDX]<<bsh;
264 const unsigned rnd = (32<<((S)-1)) + (1<<(S-7));
267 for (i = 0; i < width; i++) {
268 int px = input_pixel(i) >> shp;
269 int b = (px & maskb) >> shb;
270 int g = (px & maskg) >> shg;
271 int r = (px & maskr) >> shr;
273 dst[i] = (ry * r + gy * g + by * b + rnd) >> ((S)-6);
277 static av_always_inline void rgb16_32ToUV_c_template(int16_t *dstU,
281 enum AVPixelFormat origin,
284 int maskr, int maskg,
286 int gsh, int bsh, int S,
289 const int ru = rgb2yuv[RU_IDX] << rsh, gu = rgb2yuv[GU_IDX] << gsh, bu = rgb2yuv[BU_IDX] << bsh,
290 rv = rgb2yuv[RV_IDX] << rsh, gv = rgb2yuv[GV_IDX] << gsh, bv = rgb2yuv[BV_IDX] << bsh;
291 const unsigned rnd = (256u<<((S)-1)) + (1<<(S-7));
294 for (i = 0; i < width; i++) {
295 int px = input_pixel(i) >> shp;
296 int b = (px & maskb) >> shb;
297 int g = (px & maskg) >> shg;
298 int r = (px & maskr) >> shr;
300 dstU[i] = (ru * r + gu * g + bu * b + rnd) >> ((S)-6);
301 dstV[i] = (rv * r + gv * g + bv * b + rnd) >> ((S)-6);
305 static av_always_inline void rgb16_32ToUV_half_c_template(int16_t *dstU,
309 enum AVPixelFormat origin,
312 int maskr, int maskg,
314 int gsh, int bsh, int S,
317 const int ru = rgb2yuv[RU_IDX] << rsh, gu = rgb2yuv[GU_IDX] << gsh, bu = rgb2yuv[BU_IDX] << bsh,
318 rv = rgb2yuv[RV_IDX] << rsh, gv = rgb2yuv[GV_IDX] << gsh, bv = rgb2yuv[BV_IDX] << bsh,
319 maskgx = ~(maskr | maskb);
320 const unsigned rnd = (256U<<(S)) + (1<<(S-6));
326 for (i = 0; i < width; i++) {
327 unsigned px0 = input_pixel(2 * i + 0) >> shp;
328 unsigned px1 = input_pixel(2 * i + 1) >> shp;
329 int b, r, g = (px0 & maskgx) + (px1 & maskgx);
330 int rb = px0 + px1 - g;
332 b = (rb & maskb) >> shb;
334 origin == AV_PIX_FMT_BGR565LE || origin == AV_PIX_FMT_BGR565BE ||
335 origin == AV_PIX_FMT_RGB565LE || origin == AV_PIX_FMT_RGB565BE) {
338 g = (g & maskg) >> shg;
340 r = (rb & maskr) >> shr;
342 dstU[i] = (ru * r + gu * g + bu * b + (unsigned)rnd) >> ((S)-6+1);
343 dstV[i] = (rv * r + gv * g + bv * b + (unsigned)rnd) >> ((S)-6+1);
349 #define rgb16_32_wrapper(fmt, name, shr, shg, shb, shp, maskr, \
350 maskg, maskb, rsh, gsh, bsh, S) \
351 static void name ## ToY_c(uint8_t *dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, \
352 int width, uint32_t *tab) \
354 rgb16_32ToY_c_template((int16_t*)dst, src, width, fmt, shr, shg, shb, shp, \
355 maskr, maskg, maskb, rsh, gsh, bsh, S, tab); \
358 static void name ## ToUV_c(uint8_t *dstU, uint8_t *dstV, \
359 const uint8_t *unused0, const uint8_t *src, const uint8_t *dummy, \
360 int width, uint32_t *tab) \
362 rgb16_32ToUV_c_template((int16_t*)dstU, (int16_t*)dstV, src, width, fmt, \
363 shr, shg, shb, shp, \
364 maskr, maskg, maskb, rsh, gsh, bsh, S, tab);\
367 static void name ## ToUV_half_c(uint8_t *dstU, uint8_t *dstV, \
368 const uint8_t *unused0, const uint8_t *src, \
369 const uint8_t *dummy, \
370 int width, uint32_t *tab) \
372 rgb16_32ToUV_half_c_template((int16_t*)dstU, (int16_t*)dstV, src, width, fmt, \
373 shr, shg, shb, shp, \
374 maskr, maskg, maskb, \
375 rsh, gsh, bsh, S, tab); \
378 rgb16_32_wrapper(AV_PIX_FMT_BGR32, bgr32, 16, 0, 0, 0, 0xFF0000, 0xFF00, 0x00FF, 8, 0, 8, RGB2YUV_SHIFT + 8)
379 rgb16_32_wrapper(AV_PIX_FMT_BGR32_1, bgr321, 16, 0, 0, 8, 0xFF0000, 0xFF00, 0x00FF, 8, 0, 8, RGB2YUV_SHIFT + 8)
380 rgb16_32_wrapper(AV_PIX_FMT_RGB32, rgb32, 0, 0, 16, 0, 0x00FF, 0xFF00, 0xFF0000, 8, 0, 8, RGB2YUV_SHIFT + 8)
381 rgb16_32_wrapper(AV_PIX_FMT_RGB32_1, rgb321, 0, 0, 16, 8, 0x00FF, 0xFF00, 0xFF0000, 8, 0, 8, RGB2YUV_SHIFT + 8)
382 rgb16_32_wrapper(AV_PIX_FMT_BGR565LE, bgr16le, 0, 0, 0, 0, 0x001F, 0x07E0, 0xF800, 11, 5, 0, RGB2YUV_SHIFT + 8)
383 rgb16_32_wrapper(AV_PIX_FMT_BGR555LE, bgr15le, 0, 0, 0, 0, 0x001F, 0x03E0, 0x7C00, 10, 5, 0, RGB2YUV_SHIFT + 7)
384 rgb16_32_wrapper(AV_PIX_FMT_BGR444LE, bgr12le, 0, 0, 0, 0, 0x000F, 0x00F0, 0x0F00, 8, 4, 0, RGB2YUV_SHIFT + 4)
385 rgb16_32_wrapper(AV_PIX_FMT_RGB565LE, rgb16le, 0, 0, 0, 0, 0xF800, 0x07E0, 0x001F, 0, 5, 11, RGB2YUV_SHIFT + 8)
386 rgb16_32_wrapper(AV_PIX_FMT_RGB555LE, rgb15le, 0, 0, 0, 0, 0x7C00, 0x03E0, 0x001F, 0, 5, 10, RGB2YUV_SHIFT + 7)
387 rgb16_32_wrapper(AV_PIX_FMT_RGB444LE, rgb12le, 0, 0, 0, 0, 0x0F00, 0x00F0, 0x000F, 0, 4, 8, RGB2YUV_SHIFT + 4)
388 rgb16_32_wrapper(AV_PIX_FMT_BGR565BE, bgr16be, 0, 0, 0, 0, 0x001F, 0x07E0, 0xF800, 11, 5, 0, RGB2YUV_SHIFT + 8)
389 rgb16_32_wrapper(AV_PIX_FMT_BGR555BE, bgr15be, 0, 0, 0, 0, 0x001F, 0x03E0, 0x7C00, 10, 5, 0, RGB2YUV_SHIFT + 7)
390 rgb16_32_wrapper(AV_PIX_FMT_BGR444BE, bgr12be, 0, 0, 0, 0, 0x000F, 0x00F0, 0x0F00, 8, 4, 0, RGB2YUV_SHIFT + 4)
391 rgb16_32_wrapper(AV_PIX_FMT_RGB565BE, rgb16be, 0, 0, 0, 0, 0xF800, 0x07E0, 0x001F, 0, 5, 11, RGB2YUV_SHIFT + 8)
392 rgb16_32_wrapper(AV_PIX_FMT_RGB555BE, rgb15be, 0, 0, 0, 0, 0x7C00, 0x03E0, 0x001F, 0, 5, 10, RGB2YUV_SHIFT + 7)
393 rgb16_32_wrapper(AV_PIX_FMT_RGB444BE, rgb12be, 0, 0, 0, 0, 0x0F00, 0x00F0, 0x000F, 0, 4, 8, RGB2YUV_SHIFT + 4)
395 static void gbr24pToUV_half_c(uint8_t *_dstU, uint8_t *_dstV,
396 const uint8_t *gsrc, const uint8_t *bsrc, const uint8_t *rsrc,
397 int width, uint32_t *rgb2yuv)
399 uint16_t *dstU = (uint16_t *)_dstU;
400 uint16_t *dstV = (uint16_t *)_dstV;
401 int32_t ru = rgb2yuv[RU_IDX], gu = rgb2yuv[GU_IDX], bu = rgb2yuv[BU_IDX];
402 int32_t rv = rgb2yuv[RV_IDX], gv = rgb2yuv[GV_IDX], bv = rgb2yuv[BV_IDX];
405 for (i = 0; i < width; i++) {
406 unsigned int g = gsrc[2*i] + gsrc[2*i+1];
407 unsigned int b = bsrc[2*i] + bsrc[2*i+1];
408 unsigned int r = rsrc[2*i] + rsrc[2*i+1];
410 dstU[i] = (ru*r + gu*g + bu*b + (0x4001<<(RGB2YUV_SHIFT-6))) >> (RGB2YUV_SHIFT-6+1);
411 dstV[i] = (rv*r + gv*g + bv*b + (0x4001<<(RGB2YUV_SHIFT-6))) >> (RGB2YUV_SHIFT-6+1);
415 static void rgba64leToA_c(uint8_t *_dst, const uint8_t *_src, const uint8_t *unused1,
416 const uint8_t *unused2, int width, uint32_t *unused)
418 int16_t *dst = (int16_t *)_dst;
419 const uint16_t *src = (const uint16_t *)_src;
421 for (i = 0; i < width; i++)
422 dst[i] = AV_RL16(src + 4 * i + 3);
425 static void rgba64beToA_c(uint8_t *_dst, const uint8_t *_src, const uint8_t *unused1,
426 const uint8_t *unused2, int width, uint32_t *unused)
428 int16_t *dst = (int16_t *)_dst;
429 const uint16_t *src = (const uint16_t *)_src;
431 for (i = 0; i < width; i++)
432 dst[i] = AV_RB16(src + 4 * i + 3);
435 static void abgrToA_c(uint8_t *_dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width, uint32_t *unused)
437 int16_t *dst = (int16_t *)_dst;
439 for (i=0; i<width; i++) {
444 static void rgbaToA_c(uint8_t *_dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width, uint32_t *unused)
446 int16_t *dst = (int16_t *)_dst;
448 for (i=0; i<width; i++) {
449 dst[i]= src[4*i+3]<<6;
453 static void palToA_c(uint8_t *_dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width, uint32_t *pal)
455 int16_t *dst = (int16_t *)_dst;
457 for (i=0; i<width; i++) {
460 dst[i]= (pal[d] >> 24)<<6;
464 static void palToY_c(uint8_t *_dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width, uint32_t *pal)
466 int16_t *dst = (int16_t *)_dst;
468 for (i = 0; i < width; i++) {
471 dst[i] = (pal[d] & 0xFF)<<6;
475 static void palToUV_c(uint8_t *_dstU, uint8_t *_dstV,
476 const uint8_t *unused0, const uint8_t *src1, const uint8_t *src2,
477 int width, uint32_t *pal)
479 uint16_t *dstU = (uint16_t *)_dstU;
480 int16_t *dstV = (int16_t *)_dstV;
482 av_assert1(src1 == src2);
483 for (i = 0; i < width; i++) {
484 int p = pal[src1[i]];
486 dstU[i] = (uint8_t)(p>> 8)<<6;
487 dstV[i] = (uint8_t)(p>>16)<<6;
491 static void monowhite2Y_c(uint8_t *_dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width, uint32_t *unused)
493 int16_t *dst = (int16_t *)_dst;
495 width = (width + 7) >> 3;
496 for (i = 0; i < width; i++) {
498 for (j = 0; j < 8; j++)
499 dst[8*i+j]= ((d>>(7-j))&1) * 16383;
503 for (j = 0; j < (width&7); j++)
504 dst[8*i+j]= ((d>>(7-j))&1) * 16383;
508 static void monoblack2Y_c(uint8_t *_dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width, uint32_t *unused)
510 int16_t *dst = (int16_t *)_dst;
512 width = (width + 7) >> 3;
513 for (i = 0; i < width; i++) {
515 for (j = 0; j < 8; j++)
516 dst[8*i+j]= ((d>>(7-j))&1) * 16383;
520 for (j = 0; j < (width&7); j++)
521 dst[8*i+j] = ((d>>(7-j))&1) * 16383;
525 static void yuy2ToY_c(uint8_t *dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width,
529 for (i = 0; i < width; i++)
533 static void yuy2ToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *unused0, const uint8_t *src1,
534 const uint8_t *src2, int width, uint32_t *unused)
537 for (i = 0; i < width; i++) {
538 dstU[i] = src1[4 * i + 1];
539 dstV[i] = src1[4 * i + 3];
541 av_assert1(src1 == src2);
544 static void yvy2ToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *unused0, const uint8_t *src1,
545 const uint8_t *src2, int width, uint32_t *unused)
548 for (i = 0; i < width; i++) {
549 dstV[i] = src1[4 * i + 1];
550 dstU[i] = src1[4 * i + 3];
552 av_assert1(src1 == src2);
555 static void bswap16Y_c(uint8_t *_dst, const uint8_t *_src, const uint8_t *unused1, const uint8_t *unused2, int width,
559 const uint16_t *src = (const uint16_t *)_src;
560 uint16_t *dst = (uint16_t *)_dst;
561 for (i = 0; i < width; i++)
562 dst[i] = av_bswap16(src[i]);
565 static void bswap16UV_c(uint8_t *_dstU, uint8_t *_dstV, const uint8_t *unused0, const uint8_t *_src1,
566 const uint8_t *_src2, int width, uint32_t *unused)
569 const uint16_t *src1 = (const uint16_t *)_src1,
570 *src2 = (const uint16_t *)_src2;
571 uint16_t *dstU = (uint16_t *)_dstU, *dstV = (uint16_t *)_dstV;
572 for (i = 0; i < width; i++) {
573 dstU[i] = av_bswap16(src1[i]);
574 dstV[i] = av_bswap16(src2[i]);
578 static void read_ya16le_gray_c(uint8_t *dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width,
582 for (i = 0; i < width; i++)
583 AV_WN16(dst + i * 2, AV_RL16(src + i * 4));
586 static void read_ya16le_alpha_c(uint8_t *dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width,
590 for (i = 0; i < width; i++)
591 AV_WN16(dst + i * 2, AV_RL16(src + i * 4 + 2));
594 static void read_ya16be_gray_c(uint8_t *dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width,
598 for (i = 0; i < width; i++)
599 AV_WN16(dst + i * 2, AV_RB16(src + i * 4));
602 static void read_ya16be_alpha_c(uint8_t *dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width,
606 for (i = 0; i < width; i++)
607 AV_WN16(dst + i * 2, AV_RB16(src + i * 4 + 2));
610 static void read_ayuv64le_Y_c(uint8_t *dst, const uint8_t *src, const uint8_t *unused0, const uint8_t *unused1, int width,
614 for (i = 0; i < width; i++)
615 AV_WN16(dst + i * 2, AV_RL16(src + i * 8 + 2));
619 static void read_ayuv64le_UV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *unused0, const uint8_t *src,
620 const uint8_t *unused1, int width, uint32_t *unused2)
623 for (i = 0; i < width; i++) {
624 AV_WN16(dstU + i * 2, AV_RL16(src + i * 8 + 4));
625 AV_WN16(dstV + i * 2, AV_RL16(src + i * 8 + 6));
629 static void read_ayuv64le_A_c(uint8_t *dst, const uint8_t *src, const uint8_t *unused0, const uint8_t *unused1, int width,
633 for (i = 0; i < width; i++)
634 AV_WN16(dst + i * 2, AV_RL16(src + i * 8));
637 /* This is almost identical to the previous, end exists only because
638 * yuy2ToY/UV)(dst, src + 1, ...) would have 100% unaligned accesses. */
639 static void uyvyToY_c(uint8_t *dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width,
643 for (i = 0; i < width; i++)
644 dst[i] = src[2 * i + 1];
647 static void uyvyToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *unused0, const uint8_t *src1,
648 const uint8_t *src2, int width, uint32_t *unused)
651 for (i = 0; i < width; i++) {
652 dstU[i] = src1[4 * i + 0];
653 dstV[i] = src1[4 * i + 2];
655 av_assert1(src1 == src2);
658 static av_always_inline void nvXXtoUV_c(uint8_t *dst1, uint8_t *dst2,
659 const uint8_t *src, int width)
662 for (i = 0; i < width; i++) {
663 dst1[i] = src[2 * i + 0];
664 dst2[i] = src[2 * i + 1];
668 static void nv12ToUV_c(uint8_t *dstU, uint8_t *dstV,
669 const uint8_t *unused0, const uint8_t *src1, const uint8_t *src2,
670 int width, uint32_t *unused)
672 nvXXtoUV_c(dstU, dstV, src1, width);
675 static void nv21ToUV_c(uint8_t *dstU, uint8_t *dstV,
676 const uint8_t *unused0, const uint8_t *src1, const uint8_t *src2,
677 int width, uint32_t *unused)
679 nvXXtoUV_c(dstV, dstU, src1, width);
682 static void p010LEToY_c(uint8_t *dst, const uint8_t *src, const uint8_t *unused1,
683 const uint8_t *unused2, int width, uint32_t *unused)
686 for (i = 0; i < width; i++) {
687 AV_WN16(dst + i * 2, AV_RL16(src + i * 2) >> 6);
691 static void p010BEToY_c(uint8_t *dst, const uint8_t *src, const uint8_t *unused1,
692 const uint8_t *unused2, int width, uint32_t *unused)
695 for (i = 0; i < width; i++) {
696 AV_WN16(dst + i * 2, AV_RB16(src + i * 2) >> 6);
700 static void p010LEToUV_c(uint8_t *dstU, uint8_t *dstV,
701 const uint8_t *unused0, const uint8_t *src1, const uint8_t *src2,
702 int width, uint32_t *unused)
705 for (i = 0; i < width; i++) {
706 AV_WN16(dstU + i * 2, AV_RL16(src1 + i * 4 + 0) >> 6);
707 AV_WN16(dstV + i * 2, AV_RL16(src1 + i * 4 + 2) >> 6);
711 static void p010BEToUV_c(uint8_t *dstU, uint8_t *dstV,
712 const uint8_t *unused0, const uint8_t *src1, const uint8_t *src2,
713 int width, uint32_t *unused)
716 for (i = 0; i < width; i++) {
717 AV_WN16(dstU + i * 2, AV_RB16(src1 + i * 4 + 0) >> 6);
718 AV_WN16(dstV + i * 2, AV_RB16(src1 + i * 4 + 2) >> 6);
722 static void p016LEToUV_c(uint8_t *dstU, uint8_t *dstV,
723 const uint8_t *unused0, const uint8_t *src1, const uint8_t *src2,
724 int width, uint32_t *unused)
727 for (i = 0; i < width; i++) {
728 AV_WN16(dstU + i * 2, AV_RL16(src1 + i * 4 + 0));
729 AV_WN16(dstV + i * 2, AV_RL16(src1 + i * 4 + 2));
733 static void p016BEToUV_c(uint8_t *dstU, uint8_t *dstV,
734 const uint8_t *unused0, const uint8_t *src1, const uint8_t *src2,
735 int width, uint32_t *unused)
738 for (i = 0; i < width; i++) {
739 AV_WN16(dstU + i * 2, AV_RB16(src1 + i * 4 + 0));
740 AV_WN16(dstV + i * 2, AV_RB16(src1 + i * 4 + 2));
744 #define input_pixel(pos) (isBE(origin) ? AV_RB16(pos) : AV_RL16(pos))
746 static void bgr24ToY_c(uint8_t *_dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2,
747 int width, uint32_t *rgb2yuv)
749 int16_t *dst = (int16_t *)_dst;
750 int32_t ry = rgb2yuv[RY_IDX], gy = rgb2yuv[GY_IDX], by = rgb2yuv[BY_IDX];
752 for (i = 0; i < width; i++) {
753 int b = src[i * 3 + 0];
754 int g = src[i * 3 + 1];
755 int r = src[i * 3 + 2];
757 dst[i] = ((ry*r + gy*g + by*b + (32<<(RGB2YUV_SHIFT-1)) + (1<<(RGB2YUV_SHIFT-7)))>>(RGB2YUV_SHIFT-6));
761 static void bgr24ToUV_c(uint8_t *_dstU, uint8_t *_dstV, const uint8_t *unused0, const uint8_t *src1,
762 const uint8_t *src2, int width, uint32_t *rgb2yuv)
764 int16_t *dstU = (int16_t *)_dstU;
765 int16_t *dstV = (int16_t *)_dstV;
766 int32_t ru = rgb2yuv[RU_IDX], gu = rgb2yuv[GU_IDX], bu = rgb2yuv[BU_IDX];
767 int32_t rv = rgb2yuv[RV_IDX], gv = rgb2yuv[GV_IDX], bv = rgb2yuv[BV_IDX];
769 for (i = 0; i < width; i++) {
770 int b = src1[3 * i + 0];
771 int g = src1[3 * i + 1];
772 int r = src1[3 * i + 2];
774 dstU[i] = (ru*r + gu*g + bu*b + (256<<(RGB2YUV_SHIFT-1)) + (1<<(RGB2YUV_SHIFT-7)))>>(RGB2YUV_SHIFT-6);
775 dstV[i] = (rv*r + gv*g + bv*b + (256<<(RGB2YUV_SHIFT-1)) + (1<<(RGB2YUV_SHIFT-7)))>>(RGB2YUV_SHIFT-6);
777 av_assert1(src1 == src2);
780 static void bgr24ToUV_half_c(uint8_t *_dstU, uint8_t *_dstV, const uint8_t *unused0, const uint8_t *src1,
781 const uint8_t *src2, int width, uint32_t *rgb2yuv)
783 int16_t *dstU = (int16_t *)_dstU;
784 int16_t *dstV = (int16_t *)_dstV;
786 int32_t ru = rgb2yuv[RU_IDX], gu = rgb2yuv[GU_IDX], bu = rgb2yuv[BU_IDX];
787 int32_t rv = rgb2yuv[RV_IDX], gv = rgb2yuv[GV_IDX], bv = rgb2yuv[BV_IDX];
788 for (i = 0; i < width; i++) {
789 int b = src1[6 * i + 0] + src1[6 * i + 3];
790 int g = src1[6 * i + 1] + src1[6 * i + 4];
791 int r = src1[6 * i + 2] + src1[6 * i + 5];
793 dstU[i] = (ru*r + gu*g + bu*b + (256<<RGB2YUV_SHIFT) + (1<<(RGB2YUV_SHIFT-6)))>>(RGB2YUV_SHIFT-5);
794 dstV[i] = (rv*r + gv*g + bv*b + (256<<RGB2YUV_SHIFT) + (1<<(RGB2YUV_SHIFT-6)))>>(RGB2YUV_SHIFT-5);
796 av_assert1(src1 == src2);
799 static void rgb24ToY_c(uint8_t *_dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width,
802 int16_t *dst = (int16_t *)_dst;
803 int32_t ry = rgb2yuv[RY_IDX], gy = rgb2yuv[GY_IDX], by = rgb2yuv[BY_IDX];
805 for (i = 0; i < width; i++) {
806 int r = src[i * 3 + 0];
807 int g = src[i * 3 + 1];
808 int b = src[i * 3 + 2];
810 dst[i] = ((ry*r + gy*g + by*b + (32<<(RGB2YUV_SHIFT-1)) + (1<<(RGB2YUV_SHIFT-7)))>>(RGB2YUV_SHIFT-6));
814 static void rgb24ToUV_c(uint8_t *_dstU, uint8_t *_dstV, const uint8_t *unused0, const uint8_t *src1,
815 const uint8_t *src2, int width, uint32_t *rgb2yuv)
817 int16_t *dstU = (int16_t *)_dstU;
818 int16_t *dstV = (int16_t *)_dstV;
820 int32_t ru = rgb2yuv[RU_IDX], gu = rgb2yuv[GU_IDX], bu = rgb2yuv[BU_IDX];
821 int32_t rv = rgb2yuv[RV_IDX], gv = rgb2yuv[GV_IDX], bv = rgb2yuv[BV_IDX];
822 av_assert1(src1 == src2);
823 for (i = 0; i < width; i++) {
824 int r = src1[3 * i + 0];
825 int g = src1[3 * i + 1];
826 int b = src1[3 * i + 2];
828 dstU[i] = (ru*r + gu*g + bu*b + (256<<(RGB2YUV_SHIFT-1)) + (1<<(RGB2YUV_SHIFT-7)))>>(RGB2YUV_SHIFT-6);
829 dstV[i] = (rv*r + gv*g + bv*b + (256<<(RGB2YUV_SHIFT-1)) + (1<<(RGB2YUV_SHIFT-7)))>>(RGB2YUV_SHIFT-6);
833 static void rgb24ToUV_half_c(uint8_t *_dstU, uint8_t *_dstV, const uint8_t *unused0, const uint8_t *src1,
834 const uint8_t *src2, int width, uint32_t *rgb2yuv)
836 int16_t *dstU = (int16_t *)_dstU;
837 int16_t *dstV = (int16_t *)_dstV;
839 int32_t ru = rgb2yuv[RU_IDX], gu = rgb2yuv[GU_IDX], bu = rgb2yuv[BU_IDX];
840 int32_t rv = rgb2yuv[RV_IDX], gv = rgb2yuv[GV_IDX], bv = rgb2yuv[BV_IDX];
841 av_assert1(src1 == src2);
842 for (i = 0; i < width; i++) {
843 int r = src1[6 * i + 0] + src1[6 * i + 3];
844 int g = src1[6 * i + 1] + src1[6 * i + 4];
845 int b = src1[6 * i + 2] + src1[6 * i + 5];
847 dstU[i] = (ru*r + gu*g + bu*b + (256<<RGB2YUV_SHIFT) + (1<<(RGB2YUV_SHIFT-6)))>>(RGB2YUV_SHIFT-5);
848 dstV[i] = (rv*r + gv*g + bv*b + (256<<RGB2YUV_SHIFT) + (1<<(RGB2YUV_SHIFT-6)))>>(RGB2YUV_SHIFT-5);
852 static void planar_rgb_to_y(uint8_t *_dst, const uint8_t *src[4], int width, int32_t *rgb2yuv)
854 uint16_t *dst = (uint16_t *)_dst;
855 int32_t ry = rgb2yuv[RY_IDX], gy = rgb2yuv[GY_IDX], by = rgb2yuv[BY_IDX];
857 for (i = 0; i < width; i++) {
862 dst[i] = (ry*r + gy*g + by*b + (0x801<<(RGB2YUV_SHIFT-7))) >> (RGB2YUV_SHIFT-6);
866 static void planar_rgb_to_a(uint8_t *_dst, const uint8_t *src[4], int width, int32_t *unused)
868 uint16_t *dst = (uint16_t *)_dst;
870 for (i = 0; i < width; i++)
871 dst[i] = src[3][i] << 6;
874 static void planar_rgb_to_uv(uint8_t *_dstU, uint8_t *_dstV, const uint8_t *src[4], int width, int32_t *rgb2yuv)
876 uint16_t *dstU = (uint16_t *)_dstU;
877 uint16_t *dstV = (uint16_t *)_dstV;
878 int32_t ru = rgb2yuv[RU_IDX], gu = rgb2yuv[GU_IDX], bu = rgb2yuv[BU_IDX];
879 int32_t rv = rgb2yuv[RV_IDX], gv = rgb2yuv[GV_IDX], bv = rgb2yuv[BV_IDX];
881 for (i = 0; i < width; i++) {
886 dstU[i] = (ru*r + gu*g + bu*b + (0x4001<<(RGB2YUV_SHIFT-7))) >> (RGB2YUV_SHIFT-6);
887 dstV[i] = (rv*r + gv*g + bv*b + (0x4001<<(RGB2YUV_SHIFT-7))) >> (RGB2YUV_SHIFT-6);
892 is_be ? AV_RB16(src) : AV_RL16(src)
893 static av_always_inline void planar_rgb16_to_y(uint8_t *_dst, const uint8_t *_src[4],
894 int width, int bpc, int is_be, int32_t *rgb2yuv)
897 const uint16_t **src = (const uint16_t **)_src;
898 uint16_t *dst = (uint16_t *)_dst;
899 int32_t ry = rgb2yuv[RY_IDX], gy = rgb2yuv[GY_IDX], by = rgb2yuv[BY_IDX];
900 int shift = bpc < 16 ? bpc : 14;
901 for (i = 0; i < width; i++) {
902 int g = rdpx(src[0] + i);
903 int b = rdpx(src[1] + i);
904 int r = rdpx(src[2] + i);
906 dst[i] = ((ry*r + gy*g + by*b + (33 << (RGB2YUV_SHIFT + bpc - 9))) >> (RGB2YUV_SHIFT + shift - 14));
910 static av_always_inline void planar_rgb16_to_a(uint8_t *_dst, const uint8_t *_src[4],
911 int width, int bpc, int is_be, int32_t *rgb2yuv)
914 const uint16_t **src = (const uint16_t **)_src;
915 uint16_t *dst = (uint16_t *)_dst;
916 int shift = bpc < 16 ? bpc : 14;
918 for (i = 0; i < width; i++) {
919 dst[i] = rdpx(src[3] + i) << (14 - shift);
923 static av_always_inline void planar_rgb16_to_uv(uint8_t *_dstU, uint8_t *_dstV,
924 const uint8_t *_src[4], int width,
925 int bpc, int is_be, int32_t *rgb2yuv)
928 const uint16_t **src = (const uint16_t **)_src;
929 uint16_t *dstU = (uint16_t *)_dstU;
930 uint16_t *dstV = (uint16_t *)_dstV;
931 int32_t ru = rgb2yuv[RU_IDX], gu = rgb2yuv[GU_IDX], bu = rgb2yuv[BU_IDX];
932 int32_t rv = rgb2yuv[RV_IDX], gv = rgb2yuv[GV_IDX], bv = rgb2yuv[BV_IDX];
933 int shift = bpc < 16 ? bpc : 14;
934 for (i = 0; i < width; i++) {
935 int g = rdpx(src[0] + i);
936 int b = rdpx(src[1] + i);
937 int r = rdpx(src[2] + i);
939 dstU[i] = (ru*r + gu*g + bu*b + (257 << (RGB2YUV_SHIFT + bpc - 9))) >> (RGB2YUV_SHIFT + shift - 14);
940 dstV[i] = (rv*r + gv*g + bv*b + (257 << (RGB2YUV_SHIFT + bpc - 9))) >> (RGB2YUV_SHIFT + shift - 14);
945 #define rgb9plus_planar_funcs_endian(nbits, endian_name, endian) \
946 static void planar_rgb##nbits##endian_name##_to_y(uint8_t *dst, const uint8_t *src[4], \
947 int w, int32_t *rgb2yuv) \
949 planar_rgb16_to_y(dst, src, w, nbits, endian, rgb2yuv); \
951 static void planar_rgb##nbits##endian_name##_to_uv(uint8_t *dstU, uint8_t *dstV, \
952 const uint8_t *src[4], int w, int32_t *rgb2yuv) \
954 planar_rgb16_to_uv(dstU, dstV, src, w, nbits, endian, rgb2yuv); \
957 #define rgb9plus_planar_transparency_funcs(nbits) \
958 static void planar_rgb##nbits##le_to_a(uint8_t *dst, const uint8_t *src[4], \
959 int w, int32_t *rgb2yuv) \
961 planar_rgb16_to_a(dst, src, w, nbits, 0, rgb2yuv); \
963 static void planar_rgb##nbits##be_to_a(uint8_t *dst, const uint8_t *src[4], \
964 int w, int32_t *rgb2yuv) \
966 planar_rgb16_to_a(dst, src, w, nbits, 1, rgb2yuv); \
969 #define rgb9plus_planar_funcs(nbits) \
970 rgb9plus_planar_funcs_endian(nbits, le, 0) \
971 rgb9plus_planar_funcs_endian(nbits, be, 1)
973 rgb9plus_planar_funcs(9)
974 rgb9plus_planar_funcs(10)
975 rgb9plus_planar_funcs(12)
976 rgb9plus_planar_funcs(14)
977 rgb9plus_planar_funcs(16)
979 rgb9plus_planar_transparency_funcs(10)
980 rgb9plus_planar_transparency_funcs(12)
981 rgb9plus_planar_transparency_funcs(16)
983 av_cold void ff_sws_init_input_funcs(SwsContext *c)
985 enum AVPixelFormat srcFormat = c->srcFormat;
989 case AV_PIX_FMT_YUYV422:
990 c->chrToYV12 = yuy2ToUV_c;
992 case AV_PIX_FMT_YVYU422:
993 c->chrToYV12 = yvy2ToUV_c;
995 case AV_PIX_FMT_UYVY422:
996 c->chrToYV12 = uyvyToUV_c;
998 case AV_PIX_FMT_NV12:
999 c->chrToYV12 = nv12ToUV_c;
1001 case AV_PIX_FMT_NV21:
1002 c->chrToYV12 = nv21ToUV_c;
1004 case AV_PIX_FMT_RGB8:
1005 case AV_PIX_FMT_BGR8:
1006 case AV_PIX_FMT_PAL8:
1007 case AV_PIX_FMT_BGR4_BYTE:
1008 case AV_PIX_FMT_RGB4_BYTE:
1009 c->chrToYV12 = palToUV_c;
1011 case AV_PIX_FMT_GBRP9LE:
1012 c->readChrPlanar = planar_rgb9le_to_uv;
1014 case AV_PIX_FMT_GBRAP10LE:
1015 case AV_PIX_FMT_GBRP10LE:
1016 c->readChrPlanar = planar_rgb10le_to_uv;
1018 case AV_PIX_FMT_GBRAP12LE:
1019 case AV_PIX_FMT_GBRP12LE:
1020 c->readChrPlanar = planar_rgb12le_to_uv;
1022 case AV_PIX_FMT_GBRP14LE:
1023 c->readChrPlanar = planar_rgb14le_to_uv;
1025 case AV_PIX_FMT_GBRAP16LE:
1026 case AV_PIX_FMT_GBRP16LE:
1027 c->readChrPlanar = planar_rgb16le_to_uv;
1029 case AV_PIX_FMT_GBRP9BE:
1030 c->readChrPlanar = planar_rgb9be_to_uv;
1032 case AV_PIX_FMT_GBRAP10BE:
1033 case AV_PIX_FMT_GBRP10BE:
1034 c->readChrPlanar = planar_rgb10be_to_uv;
1036 case AV_PIX_FMT_GBRAP12BE:
1037 case AV_PIX_FMT_GBRP12BE:
1038 c->readChrPlanar = planar_rgb12be_to_uv;
1040 case AV_PIX_FMT_GBRP14BE:
1041 c->readChrPlanar = planar_rgb14be_to_uv;
1043 case AV_PIX_FMT_GBRAP16BE:
1044 case AV_PIX_FMT_GBRP16BE:
1045 c->readChrPlanar = planar_rgb16be_to_uv;
1047 case AV_PIX_FMT_GBRAP:
1048 case AV_PIX_FMT_GBRP:
1049 c->readChrPlanar = planar_rgb_to_uv;
1052 case AV_PIX_FMT_YUV420P9LE:
1053 case AV_PIX_FMT_YUV422P9LE:
1054 case AV_PIX_FMT_YUV444P9LE:
1055 case AV_PIX_FMT_YUV420P10LE:
1056 case AV_PIX_FMT_YUV422P10LE:
1057 case AV_PIX_FMT_YUV440P10LE:
1058 case AV_PIX_FMT_YUV444P10LE:
1059 case AV_PIX_FMT_YUV420P12LE:
1060 case AV_PIX_FMT_YUV422P12LE:
1061 case AV_PIX_FMT_YUV440P12LE:
1062 case AV_PIX_FMT_YUV444P12LE:
1063 case AV_PIX_FMT_YUV420P14LE:
1064 case AV_PIX_FMT_YUV422P14LE:
1065 case AV_PIX_FMT_YUV444P14LE:
1066 case AV_PIX_FMT_YUV420P16LE:
1067 case AV_PIX_FMT_YUV422P16LE:
1068 case AV_PIX_FMT_YUV444P16LE:
1070 case AV_PIX_FMT_YUVA420P9LE:
1071 case AV_PIX_FMT_YUVA422P9LE:
1072 case AV_PIX_FMT_YUVA444P9LE:
1073 case AV_PIX_FMT_YUVA420P10LE:
1074 case AV_PIX_FMT_YUVA422P10LE:
1075 case AV_PIX_FMT_YUVA444P10LE:
1076 case AV_PIX_FMT_YUVA420P16LE:
1077 case AV_PIX_FMT_YUVA422P16LE:
1078 case AV_PIX_FMT_YUVA444P16LE:
1079 c->chrToYV12 = bswap16UV_c;
1082 case AV_PIX_FMT_YUV420P9BE:
1083 case AV_PIX_FMT_YUV422P9BE:
1084 case AV_PIX_FMT_YUV444P9BE:
1085 case AV_PIX_FMT_YUV420P10BE:
1086 case AV_PIX_FMT_YUV422P10BE:
1087 case AV_PIX_FMT_YUV440P10BE:
1088 case AV_PIX_FMT_YUV444P10BE:
1089 case AV_PIX_FMT_YUV420P12BE:
1090 case AV_PIX_FMT_YUV422P12BE:
1091 case AV_PIX_FMT_YUV440P12BE:
1092 case AV_PIX_FMT_YUV444P12BE:
1093 case AV_PIX_FMT_YUV420P14BE:
1094 case AV_PIX_FMT_YUV422P14BE:
1095 case AV_PIX_FMT_YUV444P14BE:
1096 case AV_PIX_FMT_YUV420P16BE:
1097 case AV_PIX_FMT_YUV422P16BE:
1098 case AV_PIX_FMT_YUV444P16BE:
1100 case AV_PIX_FMT_YUVA420P9BE:
1101 case AV_PIX_FMT_YUVA422P9BE:
1102 case AV_PIX_FMT_YUVA444P9BE:
1103 case AV_PIX_FMT_YUVA420P10BE:
1104 case AV_PIX_FMT_YUVA422P10BE:
1105 case AV_PIX_FMT_YUVA444P10BE:
1106 case AV_PIX_FMT_YUVA420P16BE:
1107 case AV_PIX_FMT_YUVA422P16BE:
1108 case AV_PIX_FMT_YUVA444P16BE:
1109 c->chrToYV12 = bswap16UV_c;
1112 case AV_PIX_FMT_AYUV64LE:
1113 c->chrToYV12 = read_ayuv64le_UV_c;
1115 case AV_PIX_FMT_P010LE:
1116 c->chrToYV12 = p010LEToUV_c;
1118 case AV_PIX_FMT_P010BE:
1119 c->chrToYV12 = p010BEToUV_c;
1121 case AV_PIX_FMT_P016LE:
1122 c->chrToYV12 = p016LEToUV_c;
1124 case AV_PIX_FMT_P016BE:
1125 c->chrToYV12 = p016BEToUV_c;
1128 if (c->chrSrcHSubSample) {
1129 switch (srcFormat) {
1130 case AV_PIX_FMT_RGBA64BE:
1131 c->chrToYV12 = rgb64BEToUV_half_c;
1133 case AV_PIX_FMT_RGBA64LE:
1134 c->chrToYV12 = rgb64LEToUV_half_c;
1136 case AV_PIX_FMT_BGRA64BE:
1137 c->chrToYV12 = bgr64BEToUV_half_c;
1139 case AV_PIX_FMT_BGRA64LE:
1140 c->chrToYV12 = bgr64LEToUV_half_c;
1142 case AV_PIX_FMT_RGB48BE:
1143 c->chrToYV12 = rgb48BEToUV_half_c;
1145 case AV_PIX_FMT_RGB48LE:
1146 c->chrToYV12 = rgb48LEToUV_half_c;
1148 case AV_PIX_FMT_BGR48BE:
1149 c->chrToYV12 = bgr48BEToUV_half_c;
1151 case AV_PIX_FMT_BGR48LE:
1152 c->chrToYV12 = bgr48LEToUV_half_c;
1154 case AV_PIX_FMT_RGB32:
1155 c->chrToYV12 = bgr32ToUV_half_c;
1157 case AV_PIX_FMT_RGB32_1:
1158 c->chrToYV12 = bgr321ToUV_half_c;
1160 case AV_PIX_FMT_BGR24:
1161 c->chrToYV12 = bgr24ToUV_half_c;
1163 case AV_PIX_FMT_BGR565LE:
1164 c->chrToYV12 = bgr16leToUV_half_c;
1166 case AV_PIX_FMT_BGR565BE:
1167 c->chrToYV12 = bgr16beToUV_half_c;
1169 case AV_PIX_FMT_BGR555LE:
1170 c->chrToYV12 = bgr15leToUV_half_c;
1172 case AV_PIX_FMT_BGR555BE:
1173 c->chrToYV12 = bgr15beToUV_half_c;
1175 case AV_PIX_FMT_GBRAP:
1176 case AV_PIX_FMT_GBRP:
1177 c->chrToYV12 = gbr24pToUV_half_c;
1179 case AV_PIX_FMT_BGR444LE:
1180 c->chrToYV12 = bgr12leToUV_half_c;
1182 case AV_PIX_FMT_BGR444BE:
1183 c->chrToYV12 = bgr12beToUV_half_c;
1185 case AV_PIX_FMT_BGR32:
1186 c->chrToYV12 = rgb32ToUV_half_c;
1188 case AV_PIX_FMT_BGR32_1:
1189 c->chrToYV12 = rgb321ToUV_half_c;
1191 case AV_PIX_FMT_RGB24:
1192 c->chrToYV12 = rgb24ToUV_half_c;
1194 case AV_PIX_FMT_RGB565LE:
1195 c->chrToYV12 = rgb16leToUV_half_c;
1197 case AV_PIX_FMT_RGB565BE:
1198 c->chrToYV12 = rgb16beToUV_half_c;
1200 case AV_PIX_FMT_RGB555LE:
1201 c->chrToYV12 = rgb15leToUV_half_c;
1203 case AV_PIX_FMT_RGB555BE:
1204 c->chrToYV12 = rgb15beToUV_half_c;
1206 case AV_PIX_FMT_RGB444LE:
1207 c->chrToYV12 = rgb12leToUV_half_c;
1209 case AV_PIX_FMT_RGB444BE:
1210 c->chrToYV12 = rgb12beToUV_half_c;
1214 switch (srcFormat) {
1215 case AV_PIX_FMT_RGBA64BE:
1216 c->chrToYV12 = rgb64BEToUV_c;
1218 case AV_PIX_FMT_RGBA64LE:
1219 c->chrToYV12 = rgb64LEToUV_c;
1221 case AV_PIX_FMT_BGRA64BE:
1222 c->chrToYV12 = bgr64BEToUV_c;
1224 case AV_PIX_FMT_BGRA64LE:
1225 c->chrToYV12 = bgr64LEToUV_c;
1227 case AV_PIX_FMT_RGB48BE:
1228 c->chrToYV12 = rgb48BEToUV_c;
1230 case AV_PIX_FMT_RGB48LE:
1231 c->chrToYV12 = rgb48LEToUV_c;
1233 case AV_PIX_FMT_BGR48BE:
1234 c->chrToYV12 = bgr48BEToUV_c;
1236 case AV_PIX_FMT_BGR48LE:
1237 c->chrToYV12 = bgr48LEToUV_c;
1239 case AV_PIX_FMT_RGB32:
1240 c->chrToYV12 = bgr32ToUV_c;
1242 case AV_PIX_FMT_RGB32_1:
1243 c->chrToYV12 = bgr321ToUV_c;
1245 case AV_PIX_FMT_BGR24:
1246 c->chrToYV12 = bgr24ToUV_c;
1248 case AV_PIX_FMT_BGR565LE:
1249 c->chrToYV12 = bgr16leToUV_c;
1251 case AV_PIX_FMT_BGR565BE:
1252 c->chrToYV12 = bgr16beToUV_c;
1254 case AV_PIX_FMT_BGR555LE:
1255 c->chrToYV12 = bgr15leToUV_c;
1257 case AV_PIX_FMT_BGR555BE:
1258 c->chrToYV12 = bgr15beToUV_c;
1260 case AV_PIX_FMT_BGR444LE:
1261 c->chrToYV12 = bgr12leToUV_c;
1263 case AV_PIX_FMT_BGR444BE:
1264 c->chrToYV12 = bgr12beToUV_c;
1266 case AV_PIX_FMT_BGR32:
1267 c->chrToYV12 = rgb32ToUV_c;
1269 case AV_PIX_FMT_BGR32_1:
1270 c->chrToYV12 = rgb321ToUV_c;
1272 case AV_PIX_FMT_RGB24:
1273 c->chrToYV12 = rgb24ToUV_c;
1275 case AV_PIX_FMT_RGB565LE:
1276 c->chrToYV12 = rgb16leToUV_c;
1278 case AV_PIX_FMT_RGB565BE:
1279 c->chrToYV12 = rgb16beToUV_c;
1281 case AV_PIX_FMT_RGB555LE:
1282 c->chrToYV12 = rgb15leToUV_c;
1284 case AV_PIX_FMT_RGB555BE:
1285 c->chrToYV12 = rgb15beToUV_c;
1287 case AV_PIX_FMT_RGB444LE:
1288 c->chrToYV12 = rgb12leToUV_c;
1290 case AV_PIX_FMT_RGB444BE:
1291 c->chrToYV12 = rgb12beToUV_c;
1296 c->lumToYV12 = NULL;
1297 c->alpToYV12 = NULL;
1298 switch (srcFormat) {
1299 case AV_PIX_FMT_GBRP9LE:
1300 c->readLumPlanar = planar_rgb9le_to_y;
1302 case AV_PIX_FMT_GBRAP10LE:
1303 c->readAlpPlanar = planar_rgb10le_to_a;
1304 case AV_PIX_FMT_GBRP10LE:
1305 c->readLumPlanar = planar_rgb10le_to_y;
1307 case AV_PIX_FMT_GBRAP12LE:
1308 c->readAlpPlanar = planar_rgb12le_to_a;
1309 case AV_PIX_FMT_GBRP12LE:
1310 c->readLumPlanar = planar_rgb12le_to_y;
1312 case AV_PIX_FMT_GBRP14LE:
1313 c->readLumPlanar = planar_rgb14le_to_y;
1315 case AV_PIX_FMT_GBRAP16LE:
1316 c->readAlpPlanar = planar_rgb16le_to_a;
1317 case AV_PIX_FMT_GBRP16LE:
1318 c->readLumPlanar = planar_rgb16le_to_y;
1320 case AV_PIX_FMT_GBRP9BE:
1321 c->readLumPlanar = planar_rgb9be_to_y;
1323 case AV_PIX_FMT_GBRAP10BE:
1324 c->readAlpPlanar = planar_rgb10be_to_a;
1325 case AV_PIX_FMT_GBRP10BE:
1326 c->readLumPlanar = planar_rgb10be_to_y;
1328 case AV_PIX_FMT_GBRAP12BE:
1329 c->readAlpPlanar = planar_rgb12be_to_a;
1330 case AV_PIX_FMT_GBRP12BE:
1331 c->readLumPlanar = planar_rgb12be_to_y;
1333 case AV_PIX_FMT_GBRP14BE:
1334 c->readLumPlanar = planar_rgb14be_to_y;
1336 case AV_PIX_FMT_GBRAP16BE:
1337 c->readAlpPlanar = planar_rgb16be_to_a;
1338 case AV_PIX_FMT_GBRP16BE:
1339 c->readLumPlanar = planar_rgb16be_to_y;
1341 case AV_PIX_FMT_GBRAP:
1342 c->readAlpPlanar = planar_rgb_to_a;
1343 case AV_PIX_FMT_GBRP:
1344 c->readLumPlanar = planar_rgb_to_y;
1347 case AV_PIX_FMT_YUV420P9LE:
1348 case AV_PIX_FMT_YUV422P9LE:
1349 case AV_PIX_FMT_YUV444P9LE:
1350 case AV_PIX_FMT_YUV420P10LE:
1351 case AV_PIX_FMT_YUV422P10LE:
1352 case AV_PIX_FMT_YUV440P10LE:
1353 case AV_PIX_FMT_YUV444P10LE:
1354 case AV_PIX_FMT_YUV420P12LE:
1355 case AV_PIX_FMT_YUV422P12LE:
1356 case AV_PIX_FMT_YUV440P12LE:
1357 case AV_PIX_FMT_YUV444P12LE:
1358 case AV_PIX_FMT_YUV420P14LE:
1359 case AV_PIX_FMT_YUV422P14LE:
1360 case AV_PIX_FMT_YUV444P14LE:
1361 case AV_PIX_FMT_YUV420P16LE:
1362 case AV_PIX_FMT_YUV422P16LE:
1363 case AV_PIX_FMT_YUV444P16LE:
1365 case AV_PIX_FMT_GRAY9LE:
1366 case AV_PIX_FMT_GRAY10LE:
1367 case AV_PIX_FMT_GRAY12LE:
1368 case AV_PIX_FMT_GRAY16LE:
1370 case AV_PIX_FMT_P016LE:
1371 c->lumToYV12 = bswap16Y_c;
1373 case AV_PIX_FMT_YUVA420P9LE:
1374 case AV_PIX_FMT_YUVA422P9LE:
1375 case AV_PIX_FMT_YUVA444P9LE:
1376 case AV_PIX_FMT_YUVA420P10LE:
1377 case AV_PIX_FMT_YUVA422P10LE:
1378 case AV_PIX_FMT_YUVA444P10LE:
1379 case AV_PIX_FMT_YUVA420P16LE:
1380 case AV_PIX_FMT_YUVA422P16LE:
1381 case AV_PIX_FMT_YUVA444P16LE:
1382 c->lumToYV12 = bswap16Y_c;
1383 c->alpToYV12 = bswap16Y_c;
1386 case AV_PIX_FMT_YUV420P9BE:
1387 case AV_PIX_FMT_YUV422P9BE:
1388 case AV_PIX_FMT_YUV444P9BE:
1389 case AV_PIX_FMT_YUV420P10BE:
1390 case AV_PIX_FMT_YUV422P10BE:
1391 case AV_PIX_FMT_YUV440P10BE:
1392 case AV_PIX_FMT_YUV444P10BE:
1393 case AV_PIX_FMT_YUV420P12BE:
1394 case AV_PIX_FMT_YUV422P12BE:
1395 case AV_PIX_FMT_YUV440P12BE:
1396 case AV_PIX_FMT_YUV444P12BE:
1397 case AV_PIX_FMT_YUV420P14BE:
1398 case AV_PIX_FMT_YUV422P14BE:
1399 case AV_PIX_FMT_YUV444P14BE:
1400 case AV_PIX_FMT_YUV420P16BE:
1401 case AV_PIX_FMT_YUV422P16BE:
1402 case AV_PIX_FMT_YUV444P16BE:
1404 case AV_PIX_FMT_GRAY9BE:
1405 case AV_PIX_FMT_GRAY10BE:
1406 case AV_PIX_FMT_GRAY12BE:
1407 case AV_PIX_FMT_GRAY16BE:
1409 case AV_PIX_FMT_P016BE:
1410 c->lumToYV12 = bswap16Y_c;
1412 case AV_PIX_FMT_YUVA420P9BE:
1413 case AV_PIX_FMT_YUVA422P9BE:
1414 case AV_PIX_FMT_YUVA444P9BE:
1415 case AV_PIX_FMT_YUVA420P10BE:
1416 case AV_PIX_FMT_YUVA422P10BE:
1417 case AV_PIX_FMT_YUVA444P10BE:
1418 case AV_PIX_FMT_YUVA420P16BE:
1419 case AV_PIX_FMT_YUVA422P16BE:
1420 case AV_PIX_FMT_YUVA444P16BE:
1421 c->lumToYV12 = bswap16Y_c;
1422 c->alpToYV12 = bswap16Y_c;
1425 case AV_PIX_FMT_YA16LE:
1426 c->lumToYV12 = read_ya16le_gray_c;
1428 case AV_PIX_FMT_YA16BE:
1429 c->lumToYV12 = read_ya16be_gray_c;
1431 case AV_PIX_FMT_AYUV64LE:
1432 c->lumToYV12 = read_ayuv64le_Y_c;
1434 case AV_PIX_FMT_YUYV422:
1435 case AV_PIX_FMT_YVYU422:
1436 case AV_PIX_FMT_YA8:
1437 c->lumToYV12 = yuy2ToY_c;
1439 case AV_PIX_FMT_UYVY422:
1440 c->lumToYV12 = uyvyToY_c;
1442 case AV_PIX_FMT_BGR24:
1443 c->lumToYV12 = bgr24ToY_c;
1445 case AV_PIX_FMT_BGR565LE:
1446 c->lumToYV12 = bgr16leToY_c;
1448 case AV_PIX_FMT_BGR565BE:
1449 c->lumToYV12 = bgr16beToY_c;
1451 case AV_PIX_FMT_BGR555LE:
1452 c->lumToYV12 = bgr15leToY_c;
1454 case AV_PIX_FMT_BGR555BE:
1455 c->lumToYV12 = bgr15beToY_c;
1457 case AV_PIX_FMT_BGR444LE:
1458 c->lumToYV12 = bgr12leToY_c;
1460 case AV_PIX_FMT_BGR444BE:
1461 c->lumToYV12 = bgr12beToY_c;
1463 case AV_PIX_FMT_RGB24:
1464 c->lumToYV12 = rgb24ToY_c;
1466 case AV_PIX_FMT_RGB565LE:
1467 c->lumToYV12 = rgb16leToY_c;
1469 case AV_PIX_FMT_RGB565BE:
1470 c->lumToYV12 = rgb16beToY_c;
1472 case AV_PIX_FMT_RGB555LE:
1473 c->lumToYV12 = rgb15leToY_c;
1475 case AV_PIX_FMT_RGB555BE:
1476 c->lumToYV12 = rgb15beToY_c;
1478 case AV_PIX_FMT_RGB444LE:
1479 c->lumToYV12 = rgb12leToY_c;
1481 case AV_PIX_FMT_RGB444BE:
1482 c->lumToYV12 = rgb12beToY_c;
1484 case AV_PIX_FMT_RGB8:
1485 case AV_PIX_FMT_BGR8:
1486 case AV_PIX_FMT_PAL8:
1487 case AV_PIX_FMT_BGR4_BYTE:
1488 case AV_PIX_FMT_RGB4_BYTE:
1489 c->lumToYV12 = palToY_c;
1491 case AV_PIX_FMT_MONOBLACK:
1492 c->lumToYV12 = monoblack2Y_c;
1494 case AV_PIX_FMT_MONOWHITE:
1495 c->lumToYV12 = monowhite2Y_c;
1497 case AV_PIX_FMT_RGB32:
1498 c->lumToYV12 = bgr32ToY_c;
1500 case AV_PIX_FMT_RGB32_1:
1501 c->lumToYV12 = bgr321ToY_c;
1503 case AV_PIX_FMT_BGR32:
1504 c->lumToYV12 = rgb32ToY_c;
1506 case AV_PIX_FMT_BGR32_1:
1507 c->lumToYV12 = rgb321ToY_c;
1509 case AV_PIX_FMT_RGB48BE:
1510 c->lumToYV12 = rgb48BEToY_c;
1512 case AV_PIX_FMT_RGB48LE:
1513 c->lumToYV12 = rgb48LEToY_c;
1515 case AV_PIX_FMT_BGR48BE:
1516 c->lumToYV12 = bgr48BEToY_c;
1518 case AV_PIX_FMT_BGR48LE:
1519 c->lumToYV12 = bgr48LEToY_c;
1521 case AV_PIX_FMT_RGBA64BE:
1522 c->lumToYV12 = rgb64BEToY_c;
1524 case AV_PIX_FMT_RGBA64LE:
1525 c->lumToYV12 = rgb64LEToY_c;
1527 case AV_PIX_FMT_BGRA64BE:
1528 c->lumToYV12 = bgr64BEToY_c;
1530 case AV_PIX_FMT_BGRA64LE:
1531 c->lumToYV12 = bgr64LEToY_c;
1533 case AV_PIX_FMT_P010LE:
1534 c->lumToYV12 = p010LEToY_c;
1536 case AV_PIX_FMT_P010BE:
1537 c->lumToYV12 = p010BEToY_c;
1541 if (is16BPS(srcFormat) || isNBPS(srcFormat)) {
1542 if (HAVE_BIGENDIAN == !isBE(srcFormat) && !c->readAlpPlanar)
1543 c->alpToYV12 = bswap16Y_c;
1545 switch (srcFormat) {
1546 case AV_PIX_FMT_BGRA64LE:
1547 case AV_PIX_FMT_RGBA64LE: c->alpToYV12 = rgba64leToA_c; break;
1548 case AV_PIX_FMT_BGRA64BE:
1549 case AV_PIX_FMT_RGBA64BE: c->alpToYV12 = rgba64beToA_c; break;
1550 case AV_PIX_FMT_BGRA:
1551 case AV_PIX_FMT_RGBA:
1552 c->alpToYV12 = rgbaToA_c;
1554 case AV_PIX_FMT_ABGR:
1555 case AV_PIX_FMT_ARGB:
1556 c->alpToYV12 = abgrToA_c;
1558 case AV_PIX_FMT_YA8:
1559 c->alpToYV12 = uyvyToY_c;
1561 case AV_PIX_FMT_YA16LE:
1562 c->alpToYV12 = read_ya16le_alpha_c;
1564 case AV_PIX_FMT_YA16BE:
1565 c->alpToYV12 = read_ya16be_alpha_c;
1567 case AV_PIX_FMT_AYUV64LE:
1568 c->alpToYV12 = read_ayuv64le_A_c;
1570 case AV_PIX_FMT_PAL8 :
1571 c->alpToYV12 = palToA_c;