FFmpeg
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
input.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2001-2012 Michael Niedermayer <michaelni@gmx.at>
3  *
4  * This file is part of FFmpeg.
5  *
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.
10  *
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.
15  *
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
19  */
20 
21 #include <assert.h>
22 #include <math.h>
23 #include <stdint.h>
24 #include <stdio.h>
25 #include <string.h>
26 
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"
34 #include "config.h"
35 #include "rgb2rgb.h"
36 #include "swscale.h"
37 #include "swscale_internal.h"
38 
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))
49 
50 #define input_pixel(pos) (isBE(origin) ? AV_RB16(pos) : AV_RL16(pos))
51 
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)
54 
55 static av_always_inline void
56 rgb64ToY_c_template(uint16_t *dst, const uint16_t *src, int width,
57  enum AVPixelFormat origin)
58 {
59  int i;
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]);
64 
65  dst[i] = (RY*r + GY*g + BY*b + (0x2001<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT;
66  }
67 }
68 
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)
73 {
74  int i;
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]);
80 
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;
83  }
84 }
85 
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)
90 {
91  int i;
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;
97 
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;
100  }
101 }
102 
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) \
106 { \
107  const uint16_t *src = (const uint16_t *) _src; \
108  uint16_t *dst = (uint16_t *) _dst; \
109  rgb64ToY_c_template(dst, src, width, origin); \
110 } \
111  \
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) \
115 { \
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); \
120 } \
121  \
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) \
125 { \
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); \
130 }
131 
134 
135 static av_always_inline void rgb48ToY_c_template(uint16_t *dst,
136  const uint16_t *src, int width,
137  enum AVPixelFormat origin)
138 {
139  int i;
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]);
144 
145  dst[i] = (RY * r + GY * g + BY * b + (0x2001 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT;
146  }
147 }
148 
149 static av_always_inline void rgb48ToUV_c_template(uint16_t *dstU,
150  uint16_t *dstV,
151  const uint16_t *src1,
152  const uint16_t *src2,
153  int width,
154  enum AVPixelFormat origin)
155 {
156  int i;
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]);
162 
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;
165  }
166 }
167 
168 static av_always_inline void rgb48ToUV_half_c_template(uint16_t *dstU,
169  uint16_t *dstV,
170  const uint16_t *src1,
171  const uint16_t *src2,
172  int width,
173  enum AVPixelFormat origin)
174 {
175  int i;
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;
184 
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;
187  }
188 }
189 
190 #undef r
191 #undef b
192 #undef input_pixel
193 
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,\
198  int width, \
199  uint32_t *unused) \
200 { \
201  const uint16_t *src = (const uint16_t *)_src; \
202  uint16_t *dst = (uint16_t *)_dst; \
203  rgb48ToY_c_template(dst, src, width, origin); \
204 } \
205  \
206 static void pattern ## 48 ## BE_LE ## ToUV_c(uint8_t *_dstU, \
207  uint8_t *_dstV, \
208  const uint8_t *unused0, \
209  const uint8_t *_src1, \
210  const uint8_t *_src2, \
211  int width, \
212  uint32_t *unused) \
213 { \
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); \
219 } \
220  \
221 static void pattern ## 48 ## BE_LE ## ToUV_half_c(uint8_t *_dstU, \
222  uint8_t *_dstV, \
223  const uint8_t *unused0, \
224  const uint8_t *_src1, \
225  const uint8_t *_src2, \
226  int width, \
227  uint32_t *unused) \
228 { \
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); \
234 }
235 
240 
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])))
248 
249 static av_always_inline void rgb16_32ToY_c_template(int16_t *dst,
250  const uint8_t *src,
251  int width,
252  enum AVPixelFormat origin,
253  int shr, int shg,
254  int shb, int shp,
255  int maskr, int maskg,
256  int maskb, int rsh,
257  int gsh, int bsh, int S)
258 {
259  const int ry = RY << rsh, gy = GY << gsh, by = BY << bsh;
260  const unsigned rnd = (32<<((S)-1)) + (1<<(S-7));
261  int i;
262 
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;
268 
269  dst[i] = (ry * r + gy * g + by * b + rnd) >> ((S)-6);
270  }
271 }
272 
273 static av_always_inline void rgb16_32ToUV_c_template(int16_t *dstU,
274  int16_t *dstV,
275  const uint8_t *src,
276  int width,
277  enum AVPixelFormat origin,
278  int shr, int shg,
279  int shb, int shp,
280  int maskr, int maskg,
281  int maskb, int rsh,
282  int gsh, int bsh, int S)
283 {
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));
287  int i;
288 
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;
294 
295  dstU[i] = (ru * r + gu * g + bu * b + rnd) >> ((S)-6);
296  dstV[i] = (rv * r + gv * g + bv * b + rnd) >> ((S)-6);
297  }
298 }
299 
301  int16_t *dstV,
302  const uint8_t *src,
303  int width,
304  enum AVPixelFormat origin,
305  int shr, int shg,
306  int shb, int shp,
307  int maskr, int maskg,
308  int maskb, int rsh,
309  int gsh, int bsh, int S)
310 {
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));
315  int i;
316 
317  maskr |= maskr << 1;
318  maskb |= maskb << 1;
319  maskg |= maskg << 1;
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;
325 
326  b = (rb & maskb) >> shb;
327  if (shp ||
328  origin == AV_PIX_FMT_BGR565LE || origin == AV_PIX_FMT_BGR565BE ||
329  origin == AV_PIX_FMT_RGB565LE || origin == AV_PIX_FMT_RGB565BE) {
330  g >>= shg;
331  } else {
332  g = (g & maskg) >> shg;
333  }
334  r = (rb & maskr) >> shr;
335 
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);
338  }
339 }
340 
341 #undef input_pixel
342 
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) \
347 { \
348  rgb16_32ToY_c_template((int16_t*)dst, src, width, fmt, shr, shg, shb, shp, \
349  maskr, maskg, maskb, rsh, gsh, bsh, S); \
350 } \
351  \
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) \
355 { \
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); \
359 } \
360  \
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) \
365 { \
366  rgb16_32ToUV_half_c_template((int16_t*)dstU, (int16_t*)dstV, src, width, fmt, \
367  shr, shg, shb, shp, \
368  maskr, maskg, maskb, \
369  rsh, gsh, bsh, S); \
370 }
371 
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)
388 
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)
392 {
393  uint16_t *dstU = (uint16_t *)_dstU;
394  uint16_t *dstV = (uint16_t *)_dstV;
395  int i;
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];
400 
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);
403  }
404 }
405 
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)
408 {
409  int16_t *dst = (int16_t *)_dst;
410  const uint16_t *src = (const uint16_t *)_src;
411  int i;
412  for (i = 0; i < width; i++)
413  dst[i] = src[4 * i + 3];
414 }
415 
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)
417 {
418  int16_t *dst = (int16_t *)_dst;
419  int i;
420  for (i=0; i<width; i++) {
421  dst[i]= src[4*i]<<6;
422  }
423 }
424 
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)
426 {
427  int16_t *dst = (int16_t *)_dst;
428  int i;
429  for (i=0; i<width; i++) {
430  dst[i]= src[4*i+3]<<6;
431  }
432 }
433 
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)
435 {
436  int16_t *dst = (int16_t *)_dst;
437  int i;
438  for (i=0; i<width; i++) {
439  int d= src[i];
440 
441  dst[i]= (pal[d] >> 24)<<6;
442  }
443 }
444 
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)
446 {
447  int16_t *dst = (int16_t *)_dst;
448  int i;
449  for (i = 0; i < width; i++) {
450  int d = src[i];
451 
452  dst[i] = (pal[d] & 0xFF)<<6;
453  }
454 }
455 
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)
459 {
460  uint16_t *dstU = (uint16_t *)_dstU;
461  int16_t *dstV = (int16_t *)_dstV;
462  int i;
463  av_assert1(src1 == src2);
464  for (i = 0; i < width; i++) {
465  int p = pal[src1[i]];
466 
467  dstU[i] = (uint8_t)(p>> 8)<<6;
468  dstV[i] = (uint8_t)(p>>16)<<6;
469  }
470 }
471 
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)
473 {
474  int16_t *dst = (int16_t *)_dst;
475  int i, j;
476  width = (width + 7) >> 3;
477  for (i = 0; i < width; i++) {
478  int d = ~src[i];
479  for (j = 0; j < 8; j++)
480  dst[8*i+j]= ((d>>(7-j))&1) * 16383;
481  }
482  if(width&7){
483  int d= ~src[i];
484  for (j = 0; j < (width&7); j++)
485  dst[8*i+j]= ((d>>(7-j))&1) * 16383;
486  }
487 }
488 
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)
490 {
491  int16_t *dst = (int16_t *)_dst;
492  int i, j;
493  width = (width + 7) >> 3;
494  for (i = 0; i < width; i++) {
495  int d = src[i];
496  for (j = 0; j < 8; j++)
497  dst[8*i+j]= ((d>>(7-j))&1) * 16383;
498  }
499  if(width&7){
500  int d = src[i];
501  for (j = 0; j < (width&7); j++)
502  dst[8*i+j] = ((d>>(7-j))&1) * 16383;
503  }
504 }
505 
506 static void yuy2ToY_c(uint8_t *dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width,
507  uint32_t *unused)
508 {
509  int i;
510  for (i = 0; i < width; i++)
511  dst[i] = src[2 * i];
512 }
513 
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)
516 {
517  int i;
518  for (i = 0; i < width; i++) {
519  dstU[i] = src1[4 * i + 1];
520  dstV[i] = src1[4 * i + 3];
521  }
522  av_assert1(src1 == src2);
523 }
524 
525 static void bswap16Y_c(uint8_t *_dst, const uint8_t *_src, const uint8_t *unused1, const uint8_t *unused2, int width,
526  uint32_t *unused)
527 {
528  int i;
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]);
533 }
534 
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)
537 {
538  int i;
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]);
545  }
546 }
547 
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,
551  uint32_t *unused)
552 {
553  int i;
554  for (i = 0; i < width; i++)
555  dst[i] = src[2 * i + 1];
556 }
557 
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)
560 {
561  int i;
562  for (i = 0; i < width; i++) {
563  dstU[i] = src1[4 * i + 0];
564  dstV[i] = src1[4 * i + 2];
565  }
566  av_assert1(src1 == src2);
567 }
568 
569 static av_always_inline void nvXXtoUV_c(uint8_t *dst1, uint8_t *dst2,
570  const uint8_t *src, int width)
571 {
572  int i;
573  for (i = 0; i < width; i++) {
574  dst1[i] = src[2 * i + 0];
575  dst2[i] = src[2 * i + 1];
576  }
577 }
578 
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)
582 {
583  nvXXtoUV_c(dstU, dstV, src1, width);
584 }
585 
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)
589 {
590  nvXXtoUV_c(dstV, dstU, src1, width);
591 }
592 
593 #define input_pixel(pos) (isBE(origin) ? AV_RB16(pos) : AV_RL16(pos))
594 
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)
597 {
598  int16_t *dst = (int16_t *)_dst;
599  int i;
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];
604 
605  dst[i] = ((RY*r + GY*g + BY*b + (32<<(RGB2YUV_SHIFT-1)) + (1<<(RGB2YUV_SHIFT-7)))>>(RGB2YUV_SHIFT-6));
606  }
607 }
608 
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)
611 {
612  int16_t *dstU = (int16_t *)_dstU;
613  int16_t *dstV = (int16_t *)_dstV;
614  int i;
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];
619 
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);
622  }
623  av_assert1(src1 == src2);
624 }
625 
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)
628 {
629  int16_t *dstU = (int16_t *)_dstU;
630  int16_t *dstV = (int16_t *)_dstV;
631  int i;
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];
636 
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);
639  }
640  av_assert1(src1 == src2);
641 }
642 
643 static void rgb24ToY_c(uint8_t *_dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width,
644  uint32_t *unused)
645 {
646  int16_t *dst = (int16_t *)_dst;
647  int i;
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];
652 
653  dst[i] = ((RY*r + GY*g + BY*b + (32<<(RGB2YUV_SHIFT-1)) + (1<<(RGB2YUV_SHIFT-7)))>>(RGB2YUV_SHIFT-6));
654  }
655 }
656 
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)
659 {
660  int16_t *dstU = (int16_t *)_dstU;
661  int16_t *dstV = (int16_t *)_dstV;
662  int i;
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];
668 
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);
671  }
672 }
673 
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)
676 {
677  int16_t *dstU = (int16_t *)_dstU;
678  int16_t *dstV = (int16_t *)_dstV;
679  int i;
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];
685 
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);
688  }
689 }
690 
691 static void planar_rgb_to_y(uint8_t *_dst, const uint8_t *src[4], int width)
692 {
693  uint16_t *dst = (uint16_t *)_dst;
694  int i;
695  for (i = 0; i < width; i++) {
696  int g = src[0][i];
697  int b = src[1][i];
698  int r = src[2][i];
699 
700  dst[i] = (RY*r + GY*g + BY*b + (0x801<<(RGB2YUV_SHIFT-7))) >> (RGB2YUV_SHIFT-6);
701  }
702 }
703 
704 static void planar_rgb_to_uv(uint8_t *_dstU, uint8_t *_dstV, const uint8_t *src[4], int width)
705 {
706  uint16_t *dstU = (uint16_t *)_dstU;
707  uint16_t *dstV = (uint16_t *)_dstV;
708  int i;
709  for (i = 0; i < width; i++) {
710  int g = src[0][i];
711  int b = src[1][i];
712  int r = src[2][i];
713 
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);
716  }
717 }
718 
719 #define rdpx(src) \
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)
723 {
724  int i;
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);
731 
732  dst[i] = ((RY * r + GY * g + BY * b + (33 << (RGB2YUV_SHIFT + bpc - 9))) >> RGB2YUV_SHIFT);
733  }
734 }
735 
736 static void planar_rgb9le_to_y(uint8_t *dst, const uint8_t *src[4], int w)
737 {
738  planar_rgb16_to_y(dst, src, w, 9, 0);
739 }
740 
741 static void planar_rgb9be_to_y(uint8_t *dst, const uint8_t *src[4], int w)
742 {
743  planar_rgb16_to_y(dst, src, w, 9, 1);
744 }
745 
746 static void planar_rgb10le_to_y(uint8_t *dst, const uint8_t *src[4], int w)
747 {
748  planar_rgb16_to_y(dst, src, w, 10, 0);
749 }
750 
751 static void planar_rgb10be_to_y(uint8_t *dst, const uint8_t *src[4], int w)
752 {
753  planar_rgb16_to_y(dst, src, w, 10, 1);
754 }
755 
756 static void planar_rgb12le_to_y(uint8_t *dst, const uint8_t *src[4], int w)
757 {
758  planar_rgb16_to_y(dst, src, w, 12, 0);
759 }
760 
761 static void planar_rgb12be_to_y(uint8_t *dst, const uint8_t *src[4], int w)
762 {
763  planar_rgb16_to_y(dst, src, w, 12, 1);
764 }
765 
766 static void planar_rgb14le_to_y(uint8_t *dst, const uint8_t *src[4], int w)
767 {
768  planar_rgb16_to_y(dst, src, w, 14, 0);
769 }
770 
771 static void planar_rgb14be_to_y(uint8_t *dst, const uint8_t *src[4], int w)
772 {
773  planar_rgb16_to_y(dst, src, w, 14, 1);
774 }
775 
776 static void planar_rgb16le_to_y(uint8_t *dst, const uint8_t *src[4], int w)
777 {
778  planar_rgb16_to_y(dst, src, w, 16, 0);
779 }
780 
781 static void planar_rgb16be_to_y(uint8_t *dst, const uint8_t *src[4], int w)
782 {
783  planar_rgb16_to_y(dst, src, w, 16, 1);
784 }
785 
787  const uint8_t *_src[4], int width,
788  int bpc, int is_be)
789 {
790  int i;
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);
798 
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;
801  }
802 }
803 #undef rdpx
804 
805 static void planar_rgb9le_to_uv(uint8_t *dstU, uint8_t *dstV,
806  const uint8_t *src[4], int w)
807 {
808  planar_rgb16_to_uv(dstU, dstV, src, w, 9, 0);
809 }
810 
811 static void planar_rgb9be_to_uv(uint8_t *dstU, uint8_t *dstV,
812  const uint8_t *src[4], int w)
813 {
814  planar_rgb16_to_uv(dstU, dstV, src, w, 9, 1);
815 }
816 
817 static void planar_rgb10le_to_uv(uint8_t *dstU, uint8_t *dstV,
818  const uint8_t *src[4], int w)
819 {
820  planar_rgb16_to_uv(dstU, dstV, src, w, 10, 0);
821 }
822 
823 static void planar_rgb10be_to_uv(uint8_t *dstU, uint8_t *dstV,
824  const uint8_t *src[4], int w)
825 {
826  planar_rgb16_to_uv(dstU, dstV, src, w, 10, 1);
827 }
828 
829 static void planar_rgb12le_to_uv(uint8_t *dstU, uint8_t *dstV,
830  const uint8_t *src[4], int w)
831 {
832  planar_rgb16_to_uv(dstU, dstV, src, w, 12, 0);
833 }
834 
835 static void planar_rgb12be_to_uv(uint8_t *dstU, uint8_t *dstV,
836  const uint8_t *src[4], int w)
837 {
838  planar_rgb16_to_uv(dstU, dstV, src, w, 12, 1);
839 }
840 
841 static void planar_rgb14le_to_uv(uint8_t *dstU, uint8_t *dstV,
842  const uint8_t *src[4], int w)
843 {
844  planar_rgb16_to_uv(dstU, dstV, src, w, 14, 0);
845 }
846 
847 static void planar_rgb14be_to_uv(uint8_t *dstU, uint8_t *dstV,
848  const uint8_t *src[4], int w)
849 {
850  planar_rgb16_to_uv(dstU, dstV, src, w, 14, 1);
851 }
852 
853 static void planar_rgb16le_to_uv(uint8_t *dstU, uint8_t *dstV,
854  const uint8_t *src[4], int w)
855 {
856  planar_rgb16_to_uv(dstU, dstV, src, w, 16, 0);
857 }
858 
859 static void planar_rgb16be_to_uv(uint8_t *dstU, uint8_t *dstV,
860  const uint8_t *src[4], int w)
861 {
862  planar_rgb16_to_uv(dstU, dstV, src, w, 16, 1);
863 }
864 
866 {
867  enum AVPixelFormat srcFormat = c->srcFormat;
868 
869  c->chrToYV12 = NULL;
870  switch (srcFormat) {
871  case AV_PIX_FMT_YUYV422:
872  c->chrToYV12 = yuy2ToUV_c;
873  break;
874  case AV_PIX_FMT_UYVY422:
875  c->chrToYV12 = uyvyToUV_c;
876  break;
877  case AV_PIX_FMT_NV12:
878  c->chrToYV12 = nv12ToUV_c;
879  break;
880  case AV_PIX_FMT_NV21:
881  c->chrToYV12 = nv21ToUV_c;
882  break;
883  case AV_PIX_FMT_RGB8:
884  case AV_PIX_FMT_BGR8:
885  case AV_PIX_FMT_PAL8:
888  c->chrToYV12 = palToUV_c;
889  break;
890  case AV_PIX_FMT_GBRP9LE:
892  break;
893  case AV_PIX_FMT_GBRP10LE:
895  break;
896  case AV_PIX_FMT_GBRP12LE:
898  break;
899  case AV_PIX_FMT_GBRP14LE:
901  break;
902  case AV_PIX_FMT_GBRP16LE:
904  break;
905  case AV_PIX_FMT_GBRP9BE:
907  break;
908  case AV_PIX_FMT_GBRP10BE:
910  break;
911  case AV_PIX_FMT_GBRP12BE:
913  break;
914  case AV_PIX_FMT_GBRP14BE:
916  break;
917  case AV_PIX_FMT_GBRP16BE:
919  break;
920  case AV_PIX_FMT_GBRP:
922  break;
923 #if HAVE_BIGENDIAN
939 
949  c->chrToYV12 = bswap16UV_c;
950  break;
951 #else
967 
977  c->chrToYV12 = bswap16UV_c;
978  break;
979 #endif
980  }
981  if (c->chrSrcHSubSample) {
982  switch (srcFormat) {
983  case AV_PIX_FMT_RGBA64BE:
984  c->chrToYV12 = rgb64BEToUV_half_c;
985  break;
986  case AV_PIX_FMT_RGBA64LE:
987  c->chrToYV12 = rgb64LEToUV_half_c;
988  break;
989  case AV_PIX_FMT_RGB48BE:
990  c->chrToYV12 = rgb48BEToUV_half_c;
991  break;
992  case AV_PIX_FMT_RGB48LE:
993  c->chrToYV12 = rgb48LEToUV_half_c;
994  break;
995  case AV_PIX_FMT_BGR48BE:
996  c->chrToYV12 = bgr48BEToUV_half_c;
997  break;
998  case AV_PIX_FMT_BGR48LE:
999  c->chrToYV12 = bgr48LEToUV_half_c;
1000  break;
1001  case AV_PIX_FMT_RGB32:
1002  c->chrToYV12 = bgr32ToUV_half_c;
1003  break;
1004  case AV_PIX_FMT_RGB32_1:
1005  c->chrToYV12 = bgr321ToUV_half_c;
1006  break;
1007  case AV_PIX_FMT_BGR24:
1009  break;
1010  case AV_PIX_FMT_BGR565LE:
1011  c->chrToYV12 = bgr16leToUV_half_c;
1012  break;
1013  case AV_PIX_FMT_BGR565BE:
1014  c->chrToYV12 = bgr16beToUV_half_c;
1015  break;
1016  case AV_PIX_FMT_BGR555LE:
1017  c->chrToYV12 = bgr15leToUV_half_c;
1018  break;
1019  case AV_PIX_FMT_BGR555BE:
1020  c->chrToYV12 = bgr15beToUV_half_c;
1021  break;
1022  case AV_PIX_FMT_GBR24P :
1024  break;
1025  case AV_PIX_FMT_BGR444LE:
1026  c->chrToYV12 = bgr12leToUV_half_c;
1027  break;
1028  case AV_PIX_FMT_BGR444BE:
1029  c->chrToYV12 = bgr12beToUV_half_c;
1030  break;
1031  case AV_PIX_FMT_BGR32:
1032  c->chrToYV12 = rgb32ToUV_half_c;
1033  break;
1034  case AV_PIX_FMT_BGR32_1:
1035  c->chrToYV12 = rgb321ToUV_half_c;
1036  break;
1037  case AV_PIX_FMT_RGB24:
1039  break;
1040  case AV_PIX_FMT_RGB565LE:
1041  c->chrToYV12 = rgb16leToUV_half_c;
1042  break;
1043  case AV_PIX_FMT_RGB565BE:
1044  c->chrToYV12 = rgb16beToUV_half_c;
1045  break;
1046  case AV_PIX_FMT_RGB555LE:
1047  c->chrToYV12 = rgb15leToUV_half_c;
1048  break;
1049  case AV_PIX_FMT_RGB555BE:
1050  c->chrToYV12 = rgb15beToUV_half_c;
1051  break;
1052  case AV_PIX_FMT_RGB444LE:
1053  c->chrToYV12 = rgb12leToUV_half_c;
1054  break;
1055  case AV_PIX_FMT_RGB444BE:
1056  c->chrToYV12 = rgb12beToUV_half_c;
1057  break;
1058  }
1059  } else {
1060  switch (srcFormat) {
1061  case AV_PIX_FMT_RGBA64BE:
1062  c->chrToYV12 = rgb64BEToUV_c;
1063  break;
1064  case AV_PIX_FMT_RGBA64LE:
1065  c->chrToYV12 = rgb64LEToUV_c;
1066  break;
1067  case AV_PIX_FMT_RGB48BE:
1068  c->chrToYV12 = rgb48BEToUV_c;
1069  break;
1070  case AV_PIX_FMT_RGB48LE:
1071  c->chrToYV12 = rgb48LEToUV_c;
1072  break;
1073  case AV_PIX_FMT_BGR48BE:
1074  c->chrToYV12 = bgr48BEToUV_c;
1075  break;
1076  case AV_PIX_FMT_BGR48LE:
1077  c->chrToYV12 = bgr48LEToUV_c;
1078  break;
1079  case AV_PIX_FMT_RGB32:
1080  c->chrToYV12 = bgr32ToUV_c;
1081  break;
1082  case AV_PIX_FMT_RGB32_1:
1083  c->chrToYV12 = bgr321ToUV_c;
1084  break;
1085  case AV_PIX_FMT_BGR24:
1086  c->chrToYV12 = bgr24ToUV_c;
1087  break;
1088  case AV_PIX_FMT_BGR565LE:
1089  c->chrToYV12 = bgr16leToUV_c;
1090  break;
1091  case AV_PIX_FMT_BGR565BE:
1092  c->chrToYV12 = bgr16beToUV_c;
1093  break;
1094  case AV_PIX_FMT_BGR555LE:
1095  c->chrToYV12 = bgr15leToUV_c;
1096  break;
1097  case AV_PIX_FMT_BGR555BE:
1098  c->chrToYV12 = bgr15beToUV_c;
1099  break;
1100  case AV_PIX_FMT_BGR444LE:
1101  c->chrToYV12 = bgr12leToUV_c;
1102  break;
1103  case AV_PIX_FMT_BGR444BE:
1104  c->chrToYV12 = bgr12beToUV_c;
1105  break;
1106  case AV_PIX_FMT_BGR32:
1107  c->chrToYV12 = rgb32ToUV_c;
1108  break;
1109  case AV_PIX_FMT_BGR32_1:
1110  c->chrToYV12 = rgb321ToUV_c;
1111  break;
1112  case AV_PIX_FMT_RGB24:
1113  c->chrToYV12 = rgb24ToUV_c;
1114  break;
1115  case AV_PIX_FMT_RGB565LE:
1116  c->chrToYV12 = rgb16leToUV_c;
1117  break;
1118  case AV_PIX_FMT_RGB565BE:
1119  c->chrToYV12 = rgb16beToUV_c;
1120  break;
1121  case AV_PIX_FMT_RGB555LE:
1122  c->chrToYV12 = rgb15leToUV_c;
1123  break;
1124  case AV_PIX_FMT_RGB555BE:
1125  c->chrToYV12 = rgb15beToUV_c;
1126  break;
1127  case AV_PIX_FMT_RGB444LE:
1128  c->chrToYV12 = rgb12leToUV_c;
1129  break;
1130  case AV_PIX_FMT_RGB444BE:
1131  c->chrToYV12 = rgb12beToUV_c;
1132  break;
1133  }
1134  }
1135 
1136  c->lumToYV12 = NULL;
1137  c->alpToYV12 = NULL;
1138  switch (srcFormat) {
1139  case AV_PIX_FMT_GBRP9LE:
1141  break;
1142  case AV_PIX_FMT_GBRP10LE:
1144  break;
1145  case AV_PIX_FMT_GBRP12LE:
1147  break;
1148  case AV_PIX_FMT_GBRP14LE:
1150  break;
1151  case AV_PIX_FMT_GBRP16LE:
1153  break;
1154  case AV_PIX_FMT_GBRP9BE:
1156  break;
1157  case AV_PIX_FMT_GBRP10BE:
1159  break;
1160  case AV_PIX_FMT_GBRP12BE:
1162  break;
1163  case AV_PIX_FMT_GBRP14BE:
1165  break;
1166  case AV_PIX_FMT_GBRP16BE:
1168  break;
1169  case AV_PIX_FMT_GBRP:
1171  break;
1172 #if HAVE_BIGENDIAN
1173  case AV_PIX_FMT_YUV444P9LE:
1174  case AV_PIX_FMT_YUV422P9LE:
1175  case AV_PIX_FMT_YUV420P9LE:
1188 
1189  case AV_PIX_FMT_GRAY16LE:
1190  c->lumToYV12 = bswap16Y_c;
1191  break;
1201  c->lumToYV12 = bswap16Y_c;
1202  c->alpToYV12 = bswap16Y_c;
1203  break;
1204 #else
1205  case AV_PIX_FMT_YUV444P9BE:
1206  case AV_PIX_FMT_YUV422P9BE:
1207  case AV_PIX_FMT_YUV420P9BE:
1220 
1221  case AV_PIX_FMT_GRAY16BE:
1222  c->lumToYV12 = bswap16Y_c;
1223  break;
1233  c->lumToYV12 = bswap16Y_c;
1234  c->alpToYV12 = bswap16Y_c;
1235  break;
1236 #endif
1237  case AV_PIX_FMT_YUYV422:
1238  case AV_PIX_FMT_Y400A:
1239  c->lumToYV12 = yuy2ToY_c;
1240  break;
1241  case AV_PIX_FMT_UYVY422:
1242  c->lumToYV12 = uyvyToY_c;
1243  break;
1244  case AV_PIX_FMT_BGR24:
1245  c->lumToYV12 = bgr24ToY_c;
1246  break;
1247  case AV_PIX_FMT_BGR565LE:
1248  c->lumToYV12 = bgr16leToY_c;
1249  break;
1250  case AV_PIX_FMT_BGR565BE:
1251  c->lumToYV12 = bgr16beToY_c;
1252  break;
1253  case AV_PIX_FMT_BGR555LE:
1254  c->lumToYV12 = bgr15leToY_c;
1255  break;
1256  case AV_PIX_FMT_BGR555BE:
1257  c->lumToYV12 = bgr15beToY_c;
1258  break;
1259  case AV_PIX_FMT_BGR444LE:
1260  c->lumToYV12 = bgr12leToY_c;
1261  break;
1262  case AV_PIX_FMT_BGR444BE:
1263  c->lumToYV12 = bgr12beToY_c;
1264  break;
1265  case AV_PIX_FMT_RGB24:
1266  c->lumToYV12 = rgb24ToY_c;
1267  break;
1268  case AV_PIX_FMT_RGB565LE:
1269  c->lumToYV12 = rgb16leToY_c;
1270  break;
1271  case AV_PIX_FMT_RGB565BE:
1272  c->lumToYV12 = rgb16beToY_c;
1273  break;
1274  case AV_PIX_FMT_RGB555LE:
1275  c->lumToYV12 = rgb15leToY_c;
1276  break;
1277  case AV_PIX_FMT_RGB555BE:
1278  c->lumToYV12 = rgb15beToY_c;
1279  break;
1280  case AV_PIX_FMT_RGB444LE:
1281  c->lumToYV12 = rgb12leToY_c;
1282  break;
1283  case AV_PIX_FMT_RGB444BE:
1284  c->lumToYV12 = rgb12beToY_c;
1285  break;
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;
1292  break;
1293  case AV_PIX_FMT_MONOBLACK:
1294  c->lumToYV12 = monoblack2Y_c;
1295  break;
1296  case AV_PIX_FMT_MONOWHITE:
1297  c->lumToYV12 = monowhite2Y_c;
1298  break;
1299  case AV_PIX_FMT_RGB32:
1300  c->lumToYV12 = bgr32ToY_c;
1301  break;
1302  case AV_PIX_FMT_RGB32_1:
1303  c->lumToYV12 = bgr321ToY_c;
1304  break;
1305  case AV_PIX_FMT_BGR32:
1306  c->lumToYV12 = rgb32ToY_c;
1307  break;
1308  case AV_PIX_FMT_BGR32_1:
1309  c->lumToYV12 = rgb321ToY_c;
1310  break;
1311  case AV_PIX_FMT_RGB48BE:
1312  c->lumToYV12 = rgb48BEToY_c;
1313  break;
1314  case AV_PIX_FMT_RGB48LE:
1315  c->lumToYV12 = rgb48LEToY_c;
1316  break;
1317  case AV_PIX_FMT_BGR48BE:
1318  c->lumToYV12 = bgr48BEToY_c;
1319  break;
1320  case AV_PIX_FMT_BGR48LE:
1321  c->lumToYV12 = bgr48LEToY_c;
1322  break;
1323  case AV_PIX_FMT_RGBA64BE:
1324  c->lumToYV12 = rgb64BEToY_c;
1325  break;
1326  case AV_PIX_FMT_RGBA64LE:
1327  c->lumToYV12 = rgb64LEToY_c;
1328  break;
1329  }
1330  if (c->alpPixBuf) {
1331  if (is16BPS(srcFormat) || isNBPS(srcFormat)) {
1332  if (HAVE_BIGENDIAN == !isBE(srcFormat))
1333  c->alpToYV12 = bswap16Y_c;
1334  }
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;
1341  break;
1342  case AV_PIX_FMT_ABGR:
1343  case AV_PIX_FMT_ARGB:
1344  c->alpToYV12 = abgrToA_c;
1345  break;
1346  case AV_PIX_FMT_Y400A:
1347  c->alpToYV12 = uyvyToY_c;
1348  break;
1349  case AV_PIX_FMT_PAL8 :
1350  c->alpToYV12 = palToA_c;
1351  break;
1352  }
1353  }
1354 }