FFmpeg  1.2.4
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  int shift = bpc < 16 ? bpc : 14;
728  for (i = 0; i < width; i++) {
729  int g = rdpx(src[0] + i);
730  int b = rdpx(src[1] + i);
731  int r = rdpx(src[2] + i);
732 
733  dst[i] = ((RY * r + GY * g + BY * b + (33 << (RGB2YUV_SHIFT + bpc - 9))) >> (RGB2YUV_SHIFT + shift - 14));
734  }
735 }
736 
737 static void planar_rgb9le_to_y(uint8_t *dst, const uint8_t *src[4], int w)
738 {
739  planar_rgb16_to_y(dst, src, w, 9, 0);
740 }
741 
742 static void planar_rgb9be_to_y(uint8_t *dst, const uint8_t *src[4], int w)
743 {
744  planar_rgb16_to_y(dst, src, w, 9, 1);
745 }
746 
747 static void planar_rgb10le_to_y(uint8_t *dst, const uint8_t *src[4], int w)
748 {
749  planar_rgb16_to_y(dst, src, w, 10, 0);
750 }
751 
752 static void planar_rgb10be_to_y(uint8_t *dst, const uint8_t *src[4], int w)
753 {
754  planar_rgb16_to_y(dst, src, w, 10, 1);
755 }
756 
757 static void planar_rgb12le_to_y(uint8_t *dst, const uint8_t *src[4], int w)
758 {
759  planar_rgb16_to_y(dst, src, w, 12, 0);
760 }
761 
762 static void planar_rgb12be_to_y(uint8_t *dst, const uint8_t *src[4], int w)
763 {
764  planar_rgb16_to_y(dst, src, w, 12, 1);
765 }
766 
767 static void planar_rgb14le_to_y(uint8_t *dst, const uint8_t *src[4], int w)
768 {
769  planar_rgb16_to_y(dst, src, w, 14, 0);
770 }
771 
772 static void planar_rgb14be_to_y(uint8_t *dst, const uint8_t *src[4], int w)
773 {
774  planar_rgb16_to_y(dst, src, w, 14, 1);
775 }
776 
777 static void planar_rgb16le_to_y(uint8_t *dst, const uint8_t *src[4], int w)
778 {
779  planar_rgb16_to_y(dst, src, w, 16, 0);
780 }
781 
782 static void planar_rgb16be_to_y(uint8_t *dst, const uint8_t *src[4], int w)
783 {
784  planar_rgb16_to_y(dst, src, w, 16, 1);
785 }
786 
788  const uint8_t *_src[4], int width,
789  int bpc, int is_be)
790 {
791  int i;
792  const uint16_t **src = (const uint16_t **)_src;
793  uint16_t *dstU = (uint16_t *)_dstU;
794  uint16_t *dstV = (uint16_t *)_dstV;
795  int shift = bpc < 16 ? bpc : 14;
796  for (i = 0; i < width; i++) {
797  int g = rdpx(src[0] + i);
798  int b = rdpx(src[1] + i);
799  int r = rdpx(src[2] + i);
800 
801  dstU[i] = (RU * r + GU * g + BU * b + (257 << (RGB2YUV_SHIFT + bpc - 9))) >> (RGB2YUV_SHIFT + shift - 14);
802  dstV[i] = (RV * r + GV * g + BV * b + (257 << (RGB2YUV_SHIFT + bpc - 9))) >> (RGB2YUV_SHIFT + shift - 14);
803  }
804 }
805 #undef rdpx
806 
807 static void planar_rgb9le_to_uv(uint8_t *dstU, uint8_t *dstV,
808  const uint8_t *src[4], int w)
809 {
810  planar_rgb16_to_uv(dstU, dstV, src, w, 9, 0);
811 }
812 
813 static void planar_rgb9be_to_uv(uint8_t *dstU, uint8_t *dstV,
814  const uint8_t *src[4], int w)
815 {
816  planar_rgb16_to_uv(dstU, dstV, src, w, 9, 1);
817 }
818 
819 static void planar_rgb10le_to_uv(uint8_t *dstU, uint8_t *dstV,
820  const uint8_t *src[4], int w)
821 {
822  planar_rgb16_to_uv(dstU, dstV, src, w, 10, 0);
823 }
824 
825 static void planar_rgb10be_to_uv(uint8_t *dstU, uint8_t *dstV,
826  const uint8_t *src[4], int w)
827 {
828  planar_rgb16_to_uv(dstU, dstV, src, w, 10, 1);
829 }
830 
831 static void planar_rgb12le_to_uv(uint8_t *dstU, uint8_t *dstV,
832  const uint8_t *src[4], int w)
833 {
834  planar_rgb16_to_uv(dstU, dstV, src, w, 12, 0);
835 }
836 
837 static void planar_rgb12be_to_uv(uint8_t *dstU, uint8_t *dstV,
838  const uint8_t *src[4], int w)
839 {
840  planar_rgb16_to_uv(dstU, dstV, src, w, 12, 1);
841 }
842 
843 static void planar_rgb14le_to_uv(uint8_t *dstU, uint8_t *dstV,
844  const uint8_t *src[4], int w)
845 {
846  planar_rgb16_to_uv(dstU, dstV, src, w, 14, 0);
847 }
848 
849 static void planar_rgb14be_to_uv(uint8_t *dstU, uint8_t *dstV,
850  const uint8_t *src[4], int w)
851 {
852  planar_rgb16_to_uv(dstU, dstV, src, w, 14, 1);
853 }
854 
855 static void planar_rgb16le_to_uv(uint8_t *dstU, uint8_t *dstV,
856  const uint8_t *src[4], int w)
857 {
858  planar_rgb16_to_uv(dstU, dstV, src, w, 16, 0);
859 }
860 
861 static void planar_rgb16be_to_uv(uint8_t *dstU, uint8_t *dstV,
862  const uint8_t *src[4], int w)
863 {
864  planar_rgb16_to_uv(dstU, dstV, src, w, 16, 1);
865 }
866 
868 {
869  enum AVPixelFormat srcFormat = c->srcFormat;
870 
871  c->chrToYV12 = NULL;
872  switch (srcFormat) {
873  case AV_PIX_FMT_YUYV422:
874  c->chrToYV12 = yuy2ToUV_c;
875  break;
876  case AV_PIX_FMT_UYVY422:
877  c->chrToYV12 = uyvyToUV_c;
878  break;
879  case AV_PIX_FMT_NV12:
880  c->chrToYV12 = nv12ToUV_c;
881  break;
882  case AV_PIX_FMT_NV21:
883  c->chrToYV12 = nv21ToUV_c;
884  break;
885  case AV_PIX_FMT_RGB8:
886  case AV_PIX_FMT_BGR8:
887  case AV_PIX_FMT_PAL8:
890  c->chrToYV12 = palToUV_c;
891  break;
892  case AV_PIX_FMT_GBRP9LE:
894  break;
895  case AV_PIX_FMT_GBRP10LE:
897  break;
898  case AV_PIX_FMT_GBRP12LE:
900  break;
901  case AV_PIX_FMT_GBRP14LE:
903  break;
904  case AV_PIX_FMT_GBRP16LE:
906  break;
907  case AV_PIX_FMT_GBRP9BE:
909  break;
910  case AV_PIX_FMT_GBRP10BE:
912  break;
913  case AV_PIX_FMT_GBRP12BE:
915  break;
916  case AV_PIX_FMT_GBRP14BE:
918  break;
919  case AV_PIX_FMT_GBRP16BE:
921  break;
922  case AV_PIX_FMT_GBRP:
924  break;
925 #if HAVE_BIGENDIAN
941 
951  c->chrToYV12 = bswap16UV_c;
952  break;
953 #else
969 
979  c->chrToYV12 = bswap16UV_c;
980  break;
981 #endif
982  }
983  if (c->chrSrcHSubSample) {
984  switch (srcFormat) {
985  case AV_PIX_FMT_RGBA64BE:
986  c->chrToYV12 = rgb64BEToUV_half_c;
987  break;
988  case AV_PIX_FMT_RGBA64LE:
989  c->chrToYV12 = rgb64LEToUV_half_c;
990  break;
991  case AV_PIX_FMT_RGB48BE:
992  c->chrToYV12 = rgb48BEToUV_half_c;
993  break;
994  case AV_PIX_FMT_RGB48LE:
995  c->chrToYV12 = rgb48LEToUV_half_c;
996  break;
997  case AV_PIX_FMT_BGR48BE:
998  c->chrToYV12 = bgr48BEToUV_half_c;
999  break;
1000  case AV_PIX_FMT_BGR48LE:
1001  c->chrToYV12 = bgr48LEToUV_half_c;
1002  break;
1003  case AV_PIX_FMT_RGB32:
1004  c->chrToYV12 = bgr32ToUV_half_c;
1005  break;
1006  case AV_PIX_FMT_RGB32_1:
1007  c->chrToYV12 = bgr321ToUV_half_c;
1008  break;
1009  case AV_PIX_FMT_BGR24:
1011  break;
1012  case AV_PIX_FMT_BGR565LE:
1013  c->chrToYV12 = bgr16leToUV_half_c;
1014  break;
1015  case AV_PIX_FMT_BGR565BE:
1016  c->chrToYV12 = bgr16beToUV_half_c;
1017  break;
1018  case AV_PIX_FMT_BGR555LE:
1019  c->chrToYV12 = bgr15leToUV_half_c;
1020  break;
1021  case AV_PIX_FMT_BGR555BE:
1022  c->chrToYV12 = bgr15beToUV_half_c;
1023  break;
1024  case AV_PIX_FMT_GBR24P :
1026  break;
1027  case AV_PIX_FMT_BGR444LE:
1028  c->chrToYV12 = bgr12leToUV_half_c;
1029  break;
1030  case AV_PIX_FMT_BGR444BE:
1031  c->chrToYV12 = bgr12beToUV_half_c;
1032  break;
1033  case AV_PIX_FMT_BGR32:
1034  c->chrToYV12 = rgb32ToUV_half_c;
1035  break;
1036  case AV_PIX_FMT_BGR32_1:
1037  c->chrToYV12 = rgb321ToUV_half_c;
1038  break;
1039  case AV_PIX_FMT_RGB24:
1041  break;
1042  case AV_PIX_FMT_RGB565LE:
1043  c->chrToYV12 = rgb16leToUV_half_c;
1044  break;
1045  case AV_PIX_FMT_RGB565BE:
1046  c->chrToYV12 = rgb16beToUV_half_c;
1047  break;
1048  case AV_PIX_FMT_RGB555LE:
1049  c->chrToYV12 = rgb15leToUV_half_c;
1050  break;
1051  case AV_PIX_FMT_RGB555BE:
1052  c->chrToYV12 = rgb15beToUV_half_c;
1053  break;
1054  case AV_PIX_FMT_RGB444LE:
1055  c->chrToYV12 = rgb12leToUV_half_c;
1056  break;
1057  case AV_PIX_FMT_RGB444BE:
1058  c->chrToYV12 = rgb12beToUV_half_c;
1059  break;
1060  }
1061  } else {
1062  switch (srcFormat) {
1063  case AV_PIX_FMT_RGBA64BE:
1064  c->chrToYV12 = rgb64BEToUV_c;
1065  break;
1066  case AV_PIX_FMT_RGBA64LE:
1067  c->chrToYV12 = rgb64LEToUV_c;
1068  break;
1069  case AV_PIX_FMT_RGB48BE:
1070  c->chrToYV12 = rgb48BEToUV_c;
1071  break;
1072  case AV_PIX_FMT_RGB48LE:
1073  c->chrToYV12 = rgb48LEToUV_c;
1074  break;
1075  case AV_PIX_FMT_BGR48BE:
1076  c->chrToYV12 = bgr48BEToUV_c;
1077  break;
1078  case AV_PIX_FMT_BGR48LE:
1079  c->chrToYV12 = bgr48LEToUV_c;
1080  break;
1081  case AV_PIX_FMT_RGB32:
1082  c->chrToYV12 = bgr32ToUV_c;
1083  break;
1084  case AV_PIX_FMT_RGB32_1:
1085  c->chrToYV12 = bgr321ToUV_c;
1086  break;
1087  case AV_PIX_FMT_BGR24:
1088  c->chrToYV12 = bgr24ToUV_c;
1089  break;
1090  case AV_PIX_FMT_BGR565LE:
1091  c->chrToYV12 = bgr16leToUV_c;
1092  break;
1093  case AV_PIX_FMT_BGR565BE:
1094  c->chrToYV12 = bgr16beToUV_c;
1095  break;
1096  case AV_PIX_FMT_BGR555LE:
1097  c->chrToYV12 = bgr15leToUV_c;
1098  break;
1099  case AV_PIX_FMT_BGR555BE:
1100  c->chrToYV12 = bgr15beToUV_c;
1101  break;
1102  case AV_PIX_FMT_BGR444LE:
1103  c->chrToYV12 = bgr12leToUV_c;
1104  break;
1105  case AV_PIX_FMT_BGR444BE:
1106  c->chrToYV12 = bgr12beToUV_c;
1107  break;
1108  case AV_PIX_FMT_BGR32:
1109  c->chrToYV12 = rgb32ToUV_c;
1110  break;
1111  case AV_PIX_FMT_BGR32_1:
1112  c->chrToYV12 = rgb321ToUV_c;
1113  break;
1114  case AV_PIX_FMT_RGB24:
1115  c->chrToYV12 = rgb24ToUV_c;
1116  break;
1117  case AV_PIX_FMT_RGB565LE:
1118  c->chrToYV12 = rgb16leToUV_c;
1119  break;
1120  case AV_PIX_FMT_RGB565BE:
1121  c->chrToYV12 = rgb16beToUV_c;
1122  break;
1123  case AV_PIX_FMT_RGB555LE:
1124  c->chrToYV12 = rgb15leToUV_c;
1125  break;
1126  case AV_PIX_FMT_RGB555BE:
1127  c->chrToYV12 = rgb15beToUV_c;
1128  break;
1129  case AV_PIX_FMT_RGB444LE:
1130  c->chrToYV12 = rgb12leToUV_c;
1131  break;
1132  case AV_PIX_FMT_RGB444BE:
1133  c->chrToYV12 = rgb12beToUV_c;
1134  break;
1135  }
1136  }
1137 
1138  c->lumToYV12 = NULL;
1139  c->alpToYV12 = NULL;
1140  switch (srcFormat) {
1141  case AV_PIX_FMT_GBRP9LE:
1143  break;
1144  case AV_PIX_FMT_GBRP10LE:
1146  break;
1147  case AV_PIX_FMT_GBRP12LE:
1149  break;
1150  case AV_PIX_FMT_GBRP14LE:
1152  break;
1153  case AV_PIX_FMT_GBRP16LE:
1155  break;
1156  case AV_PIX_FMT_GBRP9BE:
1158  break;
1159  case AV_PIX_FMT_GBRP10BE:
1161  break;
1162  case AV_PIX_FMT_GBRP12BE:
1164  break;
1165  case AV_PIX_FMT_GBRP14BE:
1167  break;
1168  case AV_PIX_FMT_GBRP16BE:
1170  break;
1171  case AV_PIX_FMT_GBRP:
1173  break;
1174 #if HAVE_BIGENDIAN
1175  case AV_PIX_FMT_YUV444P9LE:
1176  case AV_PIX_FMT_YUV422P9LE:
1177  case AV_PIX_FMT_YUV420P9LE:
1190 
1191  case AV_PIX_FMT_GRAY16LE:
1192  c->lumToYV12 = bswap16Y_c;
1193  break;
1203  c->lumToYV12 = bswap16Y_c;
1204  c->alpToYV12 = bswap16Y_c;
1205  break;
1206 #else
1207  case AV_PIX_FMT_YUV444P9BE:
1208  case AV_PIX_FMT_YUV422P9BE:
1209  case AV_PIX_FMT_YUV420P9BE:
1222 
1223  case AV_PIX_FMT_GRAY16BE:
1224  c->lumToYV12 = bswap16Y_c;
1225  break;
1235  c->lumToYV12 = bswap16Y_c;
1236  c->alpToYV12 = bswap16Y_c;
1237  break;
1238 #endif
1239  case AV_PIX_FMT_YUYV422:
1240  case AV_PIX_FMT_Y400A:
1241  c->lumToYV12 = yuy2ToY_c;
1242  break;
1243  case AV_PIX_FMT_UYVY422:
1244  c->lumToYV12 = uyvyToY_c;
1245  break;
1246  case AV_PIX_FMT_BGR24:
1247  c->lumToYV12 = bgr24ToY_c;
1248  break;
1249  case AV_PIX_FMT_BGR565LE:
1250  c->lumToYV12 = bgr16leToY_c;
1251  break;
1252  case AV_PIX_FMT_BGR565BE:
1253  c->lumToYV12 = bgr16beToY_c;
1254  break;
1255  case AV_PIX_FMT_BGR555LE:
1256  c->lumToYV12 = bgr15leToY_c;
1257  break;
1258  case AV_PIX_FMT_BGR555BE:
1259  c->lumToYV12 = bgr15beToY_c;
1260  break;
1261  case AV_PIX_FMT_BGR444LE:
1262  c->lumToYV12 = bgr12leToY_c;
1263  break;
1264  case AV_PIX_FMT_BGR444BE:
1265  c->lumToYV12 = bgr12beToY_c;
1266  break;
1267  case AV_PIX_FMT_RGB24:
1268  c->lumToYV12 = rgb24ToY_c;
1269  break;
1270  case AV_PIX_FMT_RGB565LE:
1271  c->lumToYV12 = rgb16leToY_c;
1272  break;
1273  case AV_PIX_FMT_RGB565BE:
1274  c->lumToYV12 = rgb16beToY_c;
1275  break;
1276  case AV_PIX_FMT_RGB555LE:
1277  c->lumToYV12 = rgb15leToY_c;
1278  break;
1279  case AV_PIX_FMT_RGB555BE:
1280  c->lumToYV12 = rgb15beToY_c;
1281  break;
1282  case AV_PIX_FMT_RGB444LE:
1283  c->lumToYV12 = rgb12leToY_c;
1284  break;
1285  case AV_PIX_FMT_RGB444BE:
1286  c->lumToYV12 = rgb12beToY_c;
1287  break;
1288  case AV_PIX_FMT_RGB8:
1289  case AV_PIX_FMT_BGR8:
1290  case AV_PIX_FMT_PAL8:
1291  case AV_PIX_FMT_BGR4_BYTE:
1292  case AV_PIX_FMT_RGB4_BYTE:
1293  c->lumToYV12 = palToY_c;
1294  break;
1295  case AV_PIX_FMT_MONOBLACK:
1296  c->lumToYV12 = monoblack2Y_c;
1297  break;
1298  case AV_PIX_FMT_MONOWHITE:
1299  c->lumToYV12 = monowhite2Y_c;
1300  break;
1301  case AV_PIX_FMT_RGB32:
1302  c->lumToYV12 = bgr32ToY_c;
1303  break;
1304  case AV_PIX_FMT_RGB32_1:
1305  c->lumToYV12 = bgr321ToY_c;
1306  break;
1307  case AV_PIX_FMT_BGR32:
1308  c->lumToYV12 = rgb32ToY_c;
1309  break;
1310  case AV_PIX_FMT_BGR32_1:
1311  c->lumToYV12 = rgb321ToY_c;
1312  break;
1313  case AV_PIX_FMT_RGB48BE:
1314  c->lumToYV12 = rgb48BEToY_c;
1315  break;
1316  case AV_PIX_FMT_RGB48LE:
1317  c->lumToYV12 = rgb48LEToY_c;
1318  break;
1319  case AV_PIX_FMT_BGR48BE:
1320  c->lumToYV12 = bgr48BEToY_c;
1321  break;
1322  case AV_PIX_FMT_BGR48LE:
1323  c->lumToYV12 = bgr48LEToY_c;
1324  break;
1325  case AV_PIX_FMT_RGBA64BE:
1326  c->lumToYV12 = rgb64BEToY_c;
1327  break;
1328  case AV_PIX_FMT_RGBA64LE:
1329  c->lumToYV12 = rgb64LEToY_c;
1330  break;
1331  }
1332  if (c->alpPixBuf) {
1333  if (is16BPS(srcFormat) || isNBPS(srcFormat)) {
1334  if (HAVE_BIGENDIAN == !isBE(srcFormat))
1335  c->alpToYV12 = bswap16Y_c;
1336  }
1337  switch (srcFormat) {
1338  case AV_PIX_FMT_RGBA64LE:
1339  case AV_PIX_FMT_RGBA64BE: c->alpToYV12 = rgba64ToA_c; break;
1340  case AV_PIX_FMT_BGRA:
1341  case AV_PIX_FMT_RGBA:
1342  c->alpToYV12 = rgbaToA_c;
1343  break;
1344  case AV_PIX_FMT_ABGR:
1345  case AV_PIX_FMT_ARGB:
1346  c->alpToYV12 = abgrToA_c;
1347  break;
1348  case AV_PIX_FMT_Y400A:
1349  c->alpToYV12 = uyvyToY_c;
1350  break;
1351  case AV_PIX_FMT_PAL8 :
1352  c->alpToYV12 = palToA_c;
1353  break;
1354  }
1355  }
1356 }