FFmpeg
 All Data Structures Namespaces 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 input_pixel(pos) (isBE(origin) ? AV_RB16(pos) : AV_RL16(pos))
40 
41 #define r ((origin == AV_PIX_FMT_BGR48BE || origin == AV_PIX_FMT_BGR48LE) ? b_r : r_b)
42 #define b ((origin == AV_PIX_FMT_BGR48BE || origin == AV_PIX_FMT_BGR48LE) ? r_b : b_r)
43 
44 static av_always_inline void
45 rgb64ToY_c_template(uint16_t *dst, const uint16_t *src, int width,
46  enum AVPixelFormat origin, int32_t *rgb2yuv)
47 {
48  int32_t ry = rgb2yuv[RY_IDX], gy = rgb2yuv[GY_IDX], by = rgb2yuv[BY_IDX];
49  int i;
50  for (i = 0; i < width; i++) {
51  unsigned int r_b = input_pixel(&src[i*4+0]);
52  unsigned int g = input_pixel(&src[i*4+1]);
53  unsigned int b_r = input_pixel(&src[i*4+2]);
54 
55  dst[i] = (ry*r + gy*g + by*b + (0x2001<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT;
56  }
57 }
58 
59 static av_always_inline void
60 rgb64ToUV_c_template(uint16_t *dstU, uint16_t *dstV,
61  const uint16_t *src1, const uint16_t *src2,
62  int width, enum AVPixelFormat origin, int32_t *rgb2yuv)
63 {
64  int i;
65  int32_t ru = rgb2yuv[RU_IDX], gu = rgb2yuv[GU_IDX], bu = rgb2yuv[BU_IDX];
66  int32_t rv = rgb2yuv[RV_IDX], gv = rgb2yuv[GV_IDX], bv = rgb2yuv[BV_IDX];
67  av_assert1(src1==src2);
68  for (i = 0; i < width; i++) {
69  int r_b = input_pixel(&src1[i*4+0]);
70  int g = input_pixel(&src1[i*4+1]);
71  int b_r = input_pixel(&src1[i*4+2]);
72 
73  dstU[i] = (ru*r + gu*g + bu*b + (0x10001<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT;
74  dstV[i] = (rv*r + gv*g + bv*b + (0x10001<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT;
75  }
76 }
77 
78 static av_always_inline void
79 rgb64ToUV_half_c_template(uint16_t *dstU, uint16_t *dstV,
80  const uint16_t *src1, const uint16_t *src2,
81  int width, enum AVPixelFormat origin, int32_t *rgb2yuv)
82 {
83  int i;
84  int32_t ru = rgb2yuv[RU_IDX], gu = rgb2yuv[GU_IDX], bu = rgb2yuv[BU_IDX];
85  int32_t rv = rgb2yuv[RV_IDX], gv = rgb2yuv[GV_IDX], bv = rgb2yuv[BV_IDX];
86  av_assert1(src1==src2);
87  for (i = 0; i < width; i++) {
88  int r_b = (input_pixel(&src1[8 * i + 0]) + input_pixel(&src1[8 * i + 4]) + 1) >> 1;
89  int g = (input_pixel(&src1[8 * i + 1]) + input_pixel(&src1[8 * i + 5]) + 1) >> 1;
90  int b_r = (input_pixel(&src1[8 * i + 2]) + input_pixel(&src1[8 * i + 6]) + 1) >> 1;
91 
92  dstU[i]= (ru*r + gu*g + bu*b + (0x10001<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT;
93  dstV[i]= (rv*r + gv*g + bv*b + (0x10001<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT;
94  }
95 }
96 
97 #define rgb64funcs(pattern, BE_LE, origin) \
98 static void pattern ## 64 ## BE_LE ## ToY_c(uint8_t *_dst, const uint8_t *_src, const uint8_t *unused0, const uint8_t *unused1,\
99  int width, uint32_t *rgb2yuv) \
100 { \
101  const uint16_t *src = (const uint16_t *) _src; \
102  uint16_t *dst = (uint16_t *) _dst; \
103  rgb64ToY_c_template(dst, src, width, origin, rgb2yuv); \
104 } \
105  \
106 static void pattern ## 64 ## BE_LE ## ToUV_c(uint8_t *_dstU, uint8_t *_dstV, \
107  const uint8_t *unused0, const uint8_t *_src1, const uint8_t *_src2, \
108  int width, uint32_t *rgb2yuv) \
109 { \
110  const uint16_t *src1 = (const uint16_t *) _src1, \
111  *src2 = (const uint16_t *) _src2; \
112  uint16_t *dstU = (uint16_t *) _dstU, *dstV = (uint16_t *) _dstV; \
113  rgb64ToUV_c_template(dstU, dstV, src1, src2, width, origin, rgb2yuv); \
114 } \
115  \
116 static void pattern ## 64 ## BE_LE ## ToUV_half_c(uint8_t *_dstU, uint8_t *_dstV, \
117  const uint8_t *unused0, const uint8_t *_src1, const uint8_t *_src2, \
118  int width, uint32_t *rgb2yuv) \
119 { \
120  const uint16_t *src1 = (const uint16_t *) _src1, \
121  *src2 = (const uint16_t *) _src2; \
122  uint16_t *dstU = (uint16_t *) _dstU, *dstV = (uint16_t *) _dstV; \
123  rgb64ToUV_half_c_template(dstU, dstV, src1, src2, width, origin, rgb2yuv); \
124 }
125 
128 
129 static av_always_inline void rgb48ToY_c_template(uint16_t *dst,
130  const uint16_t *src, int width,
131  enum AVPixelFormat origin,
132  int32_t *rgb2yuv)
133 {
134  int32_t ry = rgb2yuv[RY_IDX], gy = rgb2yuv[GY_IDX], by = rgb2yuv[BY_IDX];
135  int i;
136  for (i = 0; i < width; i++) {
137  unsigned int r_b = input_pixel(&src[i * 3 + 0]);
138  unsigned int g = input_pixel(&src[i * 3 + 1]);
139  unsigned int b_r = input_pixel(&src[i * 3 + 2]);
140 
141  dst[i] = (ry*r + gy*g + by*b + (0x2001 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT;
142  }
143 }
144 
145 static av_always_inline void rgb48ToUV_c_template(uint16_t *dstU,
146  uint16_t *dstV,
147  const uint16_t *src1,
148  const uint16_t *src2,
149  int width,
150  enum AVPixelFormat origin,
151  int32_t *rgb2yuv)
152 {
153  int i;
154  int32_t ru = rgb2yuv[RU_IDX], gu = rgb2yuv[GU_IDX], bu = rgb2yuv[BU_IDX];
155  int32_t rv = rgb2yuv[RV_IDX], gv = rgb2yuv[GV_IDX], bv = rgb2yuv[BV_IDX];
156  av_assert1(src1 == src2);
157  for (i = 0; i < width; i++) {
158  int r_b = input_pixel(&src1[i * 3 + 0]);
159  int g = input_pixel(&src1[i * 3 + 1]);
160  int b_r = input_pixel(&src1[i * 3 + 2]);
161 
162  dstU[i] = (ru*r + gu*g + bu*b + (0x10001 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT;
163  dstV[i] = (rv*r + gv*g + bv*b + (0x10001 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT;
164  }
165 }
166 
167 static av_always_inline void rgb48ToUV_half_c_template(uint16_t *dstU,
168  uint16_t *dstV,
169  const uint16_t *src1,
170  const uint16_t *src2,
171  int width,
172  enum AVPixelFormat origin,
173  int32_t *rgb2yuv)
174 {
175  int i;
176  int32_t ru = rgb2yuv[RU_IDX], gu = rgb2yuv[GU_IDX], bu = rgb2yuv[BU_IDX];
177  int32_t rv = rgb2yuv[RV_IDX], gv = rgb2yuv[GV_IDX], bv = rgb2yuv[BV_IDX];
178  av_assert1(src1 == src2);
179  for (i = 0; i < width; i++) {
180  int r_b = (input_pixel(&src1[6 * i + 0]) +
181  input_pixel(&src1[6 * i + 3]) + 1) >> 1;
182  int g = (input_pixel(&src1[6 * i + 1]) +
183  input_pixel(&src1[6 * i + 4]) + 1) >> 1;
184  int b_r = (input_pixel(&src1[6 * i + 2]) +
185  input_pixel(&src1[6 * i + 5]) + 1) >> 1;
186 
187  dstU[i] = (ru*r + gu*g + bu*b + (0x10001 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT;
188  dstV[i] = (rv*r + gv*g + bv*b + (0x10001 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT;
189  }
190 }
191 
192 #undef r
193 #undef b
194 #undef input_pixel
195 
196 #define rgb48funcs(pattern, BE_LE, origin) \
197 static void pattern ## 48 ## BE_LE ## ToY_c(uint8_t *_dst, \
198  const uint8_t *_src, \
199  const uint8_t *unused0, const uint8_t *unused1,\
200  int width, \
201  uint32_t *rgb2yuv) \
202 { \
203  const uint16_t *src = (const uint16_t *)_src; \
204  uint16_t *dst = (uint16_t *)_dst; \
205  rgb48ToY_c_template(dst, src, width, origin, rgb2yuv); \
206 } \
207  \
208 static void pattern ## 48 ## BE_LE ## ToUV_c(uint8_t *_dstU, \
209  uint8_t *_dstV, \
210  const uint8_t *unused0, \
211  const uint8_t *_src1, \
212  const uint8_t *_src2, \
213  int width, \
214  uint32_t *rgb2yuv) \
215 { \
216  const uint16_t *src1 = (const uint16_t *)_src1, \
217  *src2 = (const uint16_t *)_src2; \
218  uint16_t *dstU = (uint16_t *)_dstU, \
219  *dstV = (uint16_t *)_dstV; \
220  rgb48ToUV_c_template(dstU, dstV, src1, src2, width, origin, rgb2yuv); \
221 } \
222  \
223 static void pattern ## 48 ## BE_LE ## ToUV_half_c(uint8_t *_dstU, \
224  uint8_t *_dstV, \
225  const uint8_t *unused0, \
226  const uint8_t *_src1, \
227  const uint8_t *_src2, \
228  int width, \
229  uint32_t *rgb2yuv) \
230 { \
231  const uint16_t *src1 = (const uint16_t *)_src1, \
232  *src2 = (const uint16_t *)_src2; \
233  uint16_t *dstU = (uint16_t *)_dstU, \
234  *dstV = (uint16_t *)_dstV; \
235  rgb48ToUV_half_c_template(dstU, dstV, src1, src2, width, origin, rgb2yuv); \
236 }
237 
242 
243 #define input_pixel(i) ((origin == AV_PIX_FMT_RGBA || \
244  origin == AV_PIX_FMT_BGRA || \
245  origin == AV_PIX_FMT_ARGB || \
246  origin == AV_PIX_FMT_ABGR) \
247  ? AV_RN32A(&src[(i) * 4]) \
248  : (isBE(origin) ? AV_RB16(&src[(i) * 2]) \
249  : AV_RL16(&src[(i) * 2])))
250 
251 static av_always_inline void rgb16_32ToY_c_template(int16_t *dst,
252  const uint8_t *src,
253  int width,
254  enum AVPixelFormat origin,
255  int shr, int shg,
256  int shb, int shp,
257  int maskr, int maskg,
258  int maskb, int rsh,
259  int gsh, int bsh, int S,
260  int32_t *rgb2yuv)
261 {
262  const int ry = rgb2yuv[RY_IDX]<<rsh, gy = rgb2yuv[GY_IDX]<<gsh, by = rgb2yuv[BY_IDX]<<bsh;
263  const unsigned rnd = (32<<((S)-1)) + (1<<(S-7));
264  int i;
265 
266  for (i = 0; i < width; i++) {
267  int px = input_pixel(i) >> shp;
268  int b = (px & maskb) >> shb;
269  int g = (px & maskg) >> shg;
270  int r = (px & maskr) >> shr;
271 
272  dst[i] = (ry * r + gy * g + by * b + rnd) >> ((S)-6);
273  }
274 }
275 
276 static av_always_inline void rgb16_32ToUV_c_template(int16_t *dstU,
277  int16_t *dstV,
278  const uint8_t *src,
279  int width,
280  enum AVPixelFormat origin,
281  int shr, int shg,
282  int shb, int shp,
283  int maskr, int maskg,
284  int maskb, int rsh,
285  int gsh, int bsh, int S,
286  int32_t *rgb2yuv)
287 {
288  const int ru = rgb2yuv[RU_IDX] << rsh, gu = rgb2yuv[GU_IDX] << gsh, bu = rgb2yuv[BU_IDX] << bsh,
289  rv = rgb2yuv[RV_IDX] << rsh, gv = rgb2yuv[GV_IDX] << gsh, bv = rgb2yuv[BV_IDX] << bsh;
290  const unsigned rnd = (256u<<((S)-1)) + (1<<(S-7));
291  int i;
292 
293  for (i = 0; i < width; i++) {
294  int px = input_pixel(i) >> shp;
295  int b = (px & maskb) >> shb;
296  int g = (px & maskg) >> shg;
297  int r = (px & maskr) >> shr;
298 
299  dstU[i] = (ru * r + gu * g + bu * b + rnd) >> ((S)-6);
300  dstV[i] = (rv * r + gv * g + bv * b + rnd) >> ((S)-6);
301  }
302 }
303 
305  int16_t *dstV,
306  const uint8_t *src,
307  int width,
308  enum AVPixelFormat origin,
309  int shr, int shg,
310  int shb, int shp,
311  int maskr, int maskg,
312  int maskb, int rsh,
313  int gsh, int bsh, int S,
314  int32_t *rgb2yuv)
315 {
316  const int ru = rgb2yuv[RU_IDX] << rsh, gu = rgb2yuv[GU_IDX] << gsh, bu = rgb2yuv[BU_IDX] << bsh,
317  rv = rgb2yuv[RV_IDX] << rsh, gv = rgb2yuv[GV_IDX] << gsh, bv = rgb2yuv[BV_IDX] << bsh,
318  maskgx = ~(maskr | maskb);
319  const unsigned rnd = (256U<<(S)) + (1<<(S-6));
320  int i;
321 
322  maskr |= maskr << 1;
323  maskb |= maskb << 1;
324  maskg |= maskg << 1;
325  for (i = 0; i < width; i++) {
326  int px0 = input_pixel(2 * i + 0) >> shp;
327  int px1 = input_pixel(2 * i + 1) >> shp;
328  int b, r, g = (px0 & maskgx) + (px1 & maskgx);
329  int rb = px0 + px1 - g;
330 
331  b = (rb & maskb) >> shb;
332  if (shp ||
333  origin == AV_PIX_FMT_BGR565LE || origin == AV_PIX_FMT_BGR565BE ||
334  origin == AV_PIX_FMT_RGB565LE || origin == AV_PIX_FMT_RGB565BE) {
335  g >>= shg;
336  } else {
337  g = (g & maskg) >> shg;
338  }
339  r = (rb & maskr) >> shr;
340 
341  dstU[i] = (ru * r + gu * g + bu * b + (unsigned)rnd) >> ((S)-6+1);
342  dstV[i] = (rv * r + gv * g + bv * b + (unsigned)rnd) >> ((S)-6+1);
343  }
344 }
345 
346 #undef input_pixel
347 
348 #define rgb16_32_wrapper(fmt, name, shr, shg, shb, shp, maskr, \
349  maskg, maskb, rsh, gsh, bsh, S) \
350 static void name ## ToY_c(uint8_t *dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, \
351  int width, uint32_t *tab) \
352 { \
353  rgb16_32ToY_c_template((int16_t*)dst, src, width, fmt, shr, shg, shb, shp, \
354  maskr, maskg, maskb, rsh, gsh, bsh, S, tab); \
355 } \
356  \
357 static void name ## ToUV_c(uint8_t *dstU, uint8_t *dstV, \
358  const uint8_t *unused0, const uint8_t *src, const uint8_t *dummy, \
359  int width, uint32_t *tab) \
360 { \
361  rgb16_32ToUV_c_template((int16_t*)dstU, (int16_t*)dstV, src, width, fmt, \
362  shr, shg, shb, shp, \
363  maskr, maskg, maskb, rsh, gsh, bsh, S, tab);\
364 } \
365  \
366 static void name ## ToUV_half_c(uint8_t *dstU, uint8_t *dstV, \
367  const uint8_t *unused0, const uint8_t *src, \
368  const uint8_t *dummy, \
369  int width, uint32_t *tab) \
370 { \
371  rgb16_32ToUV_half_c_template((int16_t*)dstU, (int16_t*)dstV, src, width, fmt, \
372  shr, shg, shb, shp, \
373  maskr, maskg, maskb, \
374  rsh, gsh, bsh, S, tab); \
375 }
376 
377 rgb16_32_wrapper(AV_PIX_FMT_BGR32, bgr32, 16, 0, 0, 0, 0xFF0000, 0xFF00, 0x00FF, 8, 0, 8, RGB2YUV_SHIFT + 8)
378 rgb16_32_wrapper(AV_PIX_FMT_BGR32_1, bgr321, 16, 0, 0, 8, 0xFF0000, 0xFF00, 0x00FF, 8, 0, 8, RGB2YUV_SHIFT + 8)
379 rgb16_32_wrapper(AV_PIX_FMT_RGB32, rgb32, 0, 0, 16, 0, 0x00FF, 0xFF00, 0xFF0000, 8, 0, 8, RGB2YUV_SHIFT + 8)
380 rgb16_32_wrapper(AV_PIX_FMT_RGB32_1, rgb321, 0, 0, 16, 8, 0x00FF, 0xFF00, 0xFF0000, 8, 0, 8, RGB2YUV_SHIFT + 8)
381 rgb16_32_wrapper(AV_PIX_FMT_BGR565LE, bgr16le, 0, 0, 0, 0, 0x001F, 0x07E0, 0xF800, 11, 5, 0, RGB2YUV_SHIFT + 8)
382 rgb16_32_wrapper(AV_PIX_FMT_BGR555LE, bgr15le, 0, 0, 0, 0, 0x001F, 0x03E0, 0x7C00, 10, 5, 0, RGB2YUV_SHIFT + 7)
383 rgb16_32_wrapper(AV_PIX_FMT_BGR444LE, bgr12le, 0, 0, 0, 0, 0x000F, 0x00F0, 0x0F00, 8, 4, 0, RGB2YUV_SHIFT + 4)
384 rgb16_32_wrapper(AV_PIX_FMT_RGB565LE, rgb16le, 0, 0, 0, 0, 0xF800, 0x07E0, 0x001F, 0, 5, 11, RGB2YUV_SHIFT + 8)
385 rgb16_32_wrapper(AV_PIX_FMT_RGB555LE, rgb15le, 0, 0, 0, 0, 0x7C00, 0x03E0, 0x001F, 0, 5, 10, RGB2YUV_SHIFT + 7)
386 rgb16_32_wrapper(AV_PIX_FMT_RGB444LE, rgb12le, 0, 0, 0, 0, 0x0F00, 0x00F0, 0x000F, 0, 4, 8, RGB2YUV_SHIFT + 4)
387 rgb16_32_wrapper(AV_PIX_FMT_BGR565BE, bgr16be, 0, 0, 0, 0, 0x001F, 0x07E0, 0xF800, 11, 5, 0, RGB2YUV_SHIFT + 8)
388 rgb16_32_wrapper(AV_PIX_FMT_BGR555BE, bgr15be, 0, 0, 0, 0, 0x001F, 0x03E0, 0x7C00, 10, 5, 0, RGB2YUV_SHIFT + 7)
389 rgb16_32_wrapper(AV_PIX_FMT_BGR444BE, bgr12be, 0, 0, 0, 0, 0x000F, 0x00F0, 0x0F00, 8, 4, 0, RGB2YUV_SHIFT + 4)
390 rgb16_32_wrapper(AV_PIX_FMT_RGB565BE, rgb16be, 0, 0, 0, 0, 0xF800, 0x07E0, 0x001F, 0, 5, 11, RGB2YUV_SHIFT + 8)
391 rgb16_32_wrapper(AV_PIX_FMT_RGB555BE, rgb15be, 0, 0, 0, 0, 0x7C00, 0x03E0, 0x001F, 0, 5, 10, RGB2YUV_SHIFT + 7)
392 rgb16_32_wrapper(AV_PIX_FMT_RGB444BE, rgb12be, 0, 0, 0, 0, 0x0F00, 0x00F0, 0x000F, 0, 4, 8, RGB2YUV_SHIFT + 4)
393 
394 static void gbr24pToUV_half_c(uint8_t *_dstU, uint8_t *_dstV,
395  const uint8_t *gsrc, const uint8_t *bsrc, const uint8_t *rsrc,
396  int width, uint32_t *rgb2yuv)
397 {
398  uint16_t *dstU = (uint16_t *)_dstU;
399  uint16_t *dstV = (uint16_t *)_dstV;
400  int32_t ru = rgb2yuv[RU_IDX], gu = rgb2yuv[GU_IDX], bu = rgb2yuv[BU_IDX];
401  int32_t rv = rgb2yuv[RV_IDX], gv = rgb2yuv[GV_IDX], bv = rgb2yuv[BV_IDX];
402 
403  int i;
404  for (i = 0; i < width; i++) {
405  unsigned int g = gsrc[2*i] + gsrc[2*i+1];
406  unsigned int b = bsrc[2*i] + bsrc[2*i+1];
407  unsigned int r = rsrc[2*i] + rsrc[2*i+1];
408 
409  dstU[i] = (ru*r + gu*g + bu*b + (0x4001<<(RGB2YUV_SHIFT-6))) >> (RGB2YUV_SHIFT-6+1);
410  dstV[i] = (rv*r + gv*g + bv*b + (0x4001<<(RGB2YUV_SHIFT-6))) >> (RGB2YUV_SHIFT-6+1);
411  }
412 }
413 
414 static void rgba64ToA_c(uint8_t *_dst, const uint8_t *_src, const uint8_t *unused1,
415  const uint8_t *unused2, int width, uint32_t *unused)
416 {
417  int16_t *dst = (int16_t *)_dst;
418  const uint16_t *src = (const uint16_t *)_src;
419  int i;
420  for (i = 0; i < width; i++)
421  dst[i] = src[4 * i + 3];
422 }
423 
424 static void abgrToA_c(uint8_t *_dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width, uint32_t *unused)
425 {
426  int16_t *dst = (int16_t *)_dst;
427  int i;
428  for (i=0; i<width; i++) {
429  dst[i]= src[4*i]<<6;
430  }
431 }
432 
433 static void rgbaToA_c(uint8_t *_dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width, uint32_t *unused)
434 {
435  int16_t *dst = (int16_t *)_dst;
436  int i;
437  for (i=0; i<width; i++) {
438  dst[i]= src[4*i+3]<<6;
439  }
440 }
441 
442 static void palToA_c(uint8_t *_dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width, uint32_t *pal)
443 {
444  int16_t *dst = (int16_t *)_dst;
445  int i;
446  for (i=0; i<width; i++) {
447  int d= src[i];
448 
449  dst[i]= (pal[d] >> 24)<<6;
450  }
451 }
452 
453 static void palToY_c(uint8_t *_dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width, uint32_t *pal)
454 {
455  int16_t *dst = (int16_t *)_dst;
456  int i;
457  for (i = 0; i < width; i++) {
458  int d = src[i];
459 
460  dst[i] = (pal[d] & 0xFF)<<6;
461  }
462 }
463 
464 static void palToUV_c(uint8_t *_dstU, uint8_t *_dstV,
465  const uint8_t *unused0, const uint8_t *src1, const uint8_t *src2,
466  int width, uint32_t *pal)
467 {
468  uint16_t *dstU = (uint16_t *)_dstU;
469  int16_t *dstV = (int16_t *)_dstV;
470  int i;
471  av_assert1(src1 == src2);
472  for (i = 0; i < width; i++) {
473  int p = pal[src1[i]];
474 
475  dstU[i] = (uint8_t)(p>> 8)<<6;
476  dstV[i] = (uint8_t)(p>>16)<<6;
477  }
478 }
479 
480 static void monowhite2Y_c(uint8_t *_dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width, uint32_t *unused)
481 {
482  int16_t *dst = (int16_t *)_dst;
483  int i, j;
484  width = (width + 7) >> 3;
485  for (i = 0; i < width; i++) {
486  int d = ~src[i];
487  for (j = 0; j < 8; j++)
488  dst[8*i+j]= ((d>>(7-j))&1) * 16383;
489  }
490  if(width&7){
491  int d= ~src[i];
492  for (j = 0; j < (width&7); j++)
493  dst[8*i+j]= ((d>>(7-j))&1) * 16383;
494  }
495 }
496 
497 static void monoblack2Y_c(uint8_t *_dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width, uint32_t *unused)
498 {
499  int16_t *dst = (int16_t *)_dst;
500  int i, j;
501  width = (width + 7) >> 3;
502  for (i = 0; i < width; i++) {
503  int d = src[i];
504  for (j = 0; j < 8; j++)
505  dst[8*i+j]= ((d>>(7-j))&1) * 16383;
506  }
507  if(width&7){
508  int d = src[i];
509  for (j = 0; j < (width&7); j++)
510  dst[8*i+j] = ((d>>(7-j))&1) * 16383;
511  }
512 }
513 
514 static void yuy2ToY_c(uint8_t *dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width,
515  uint32_t *unused)
516 {
517  int i;
518  for (i = 0; i < width; i++)
519  dst[i] = src[2 * i];
520 }
521 
522 static void yuy2ToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *unused0, const uint8_t *src1,
523  const uint8_t *src2, int width, uint32_t *unused)
524 {
525  int i;
526  for (i = 0; i < width; i++) {
527  dstU[i] = src1[4 * i + 1];
528  dstV[i] = src1[4 * i + 3];
529  }
530  av_assert1(src1 == src2);
531 }
532 
533 static void bswap16Y_c(uint8_t *_dst, const uint8_t *_src, const uint8_t *unused1, const uint8_t *unused2, int width,
534  uint32_t *unused)
535 {
536  int i;
537  const uint16_t *src = (const uint16_t *)_src;
538  uint16_t *dst = (uint16_t *)_dst;
539  for (i = 0; i < width; i++)
540  dst[i] = av_bswap16(src[i]);
541 }
542 
543 static void bswap16UV_c(uint8_t *_dstU, uint8_t *_dstV, const uint8_t *unused0, const uint8_t *_src1,
544  const uint8_t *_src2, int width, uint32_t *unused)
545 {
546  int i;
547  const uint16_t *src1 = (const uint16_t *)_src1,
548  *src2 = (const uint16_t *)_src2;
549  uint16_t *dstU = (uint16_t *)_dstU, *dstV = (uint16_t *)_dstV;
550  for (i = 0; i < width; i++) {
551  dstU[i] = av_bswap16(src1[i]);
552  dstV[i] = av_bswap16(src2[i]);
553  }
554 }
555 
556 /* This is almost identical to the previous, end exists only because
557  * yuy2ToY/UV)(dst, src + 1, ...) would have 100% unaligned accesses. */
558 static void uyvyToY_c(uint8_t *dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width,
559  uint32_t *unused)
560 {
561  int i;
562  for (i = 0; i < width; i++)
563  dst[i] = src[2 * i + 1];
564 }
565 
566 static void uyvyToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *unused0, const uint8_t *src1,
567  const uint8_t *src2, int width, uint32_t *unused)
568 {
569  int i;
570  for (i = 0; i < width; i++) {
571  dstU[i] = src1[4 * i + 0];
572  dstV[i] = src1[4 * i + 2];
573  }
574  av_assert1(src1 == src2);
575 }
576 
577 static av_always_inline void nvXXtoUV_c(uint8_t *dst1, uint8_t *dst2,
578  const uint8_t *src, int width)
579 {
580  int i;
581  for (i = 0; i < width; i++) {
582  dst1[i] = src[2 * i + 0];
583  dst2[i] = src[2 * i + 1];
584  }
585 }
586 
587 static void nv12ToUV_c(uint8_t *dstU, uint8_t *dstV,
588  const uint8_t *unused0, const uint8_t *src1, const uint8_t *src2,
589  int width, uint32_t *unused)
590 {
591  nvXXtoUV_c(dstU, dstV, src1, width);
592 }
593 
594 static void nv21ToUV_c(uint8_t *dstU, uint8_t *dstV,
595  const uint8_t *unused0, const uint8_t *src1, const uint8_t *src2,
596  int width, uint32_t *unused)
597 {
598  nvXXtoUV_c(dstV, dstU, src1, width);
599 }
600 
601 #define input_pixel(pos) (isBE(origin) ? AV_RB16(pos) : AV_RL16(pos))
602 
603 static void bgr24ToY_c(uint8_t *_dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2,
604  int width, uint32_t *rgb2yuv)
605 {
606  int16_t *dst = (int16_t *)_dst;
607  int32_t ry = rgb2yuv[RY_IDX], gy = rgb2yuv[GY_IDX], by = rgb2yuv[BY_IDX];
608  int i;
609  for (i = 0; i < width; i++) {
610  int b = src[i * 3 + 0];
611  int g = src[i * 3 + 1];
612  int r = src[i * 3 + 2];
613 
614  dst[i] = ((ry*r + gy*g + by*b + (32<<(RGB2YUV_SHIFT-1)) + (1<<(RGB2YUV_SHIFT-7)))>>(RGB2YUV_SHIFT-6));
615  }
616 }
617 
618 static void bgr24ToUV_c(uint8_t *_dstU, uint8_t *_dstV, const uint8_t *unused0, const uint8_t *src1,
619  const uint8_t *src2, int width, uint32_t *rgb2yuv)
620 {
621  int16_t *dstU = (int16_t *)_dstU;
622  int16_t *dstV = (int16_t *)_dstV;
623  int32_t ru = rgb2yuv[RU_IDX], gu = rgb2yuv[GU_IDX], bu = rgb2yuv[BU_IDX];
624  int32_t rv = rgb2yuv[RV_IDX], gv = rgb2yuv[GV_IDX], bv = rgb2yuv[BV_IDX];
625  int i;
626  for (i = 0; i < width; i++) {
627  int b = src1[3 * i + 0];
628  int g = src1[3 * i + 1];
629  int r = src1[3 * i + 2];
630 
631  dstU[i] = (ru*r + gu*g + bu*b + (256<<(RGB2YUV_SHIFT-1)) + (1<<(RGB2YUV_SHIFT-7)))>>(RGB2YUV_SHIFT-6);
632  dstV[i] = (rv*r + gv*g + bv*b + (256<<(RGB2YUV_SHIFT-1)) + (1<<(RGB2YUV_SHIFT-7)))>>(RGB2YUV_SHIFT-6);
633  }
634  av_assert1(src1 == src2);
635 }
636 
637 static void bgr24ToUV_half_c(uint8_t *_dstU, uint8_t *_dstV, const uint8_t *unused0, const uint8_t *src1,
638  const uint8_t *src2, int width, uint32_t *rgb2yuv)
639 {
640  int16_t *dstU = (int16_t *)_dstU;
641  int16_t *dstV = (int16_t *)_dstV;
642  int i;
643  int32_t ru = rgb2yuv[RU_IDX], gu = rgb2yuv[GU_IDX], bu = rgb2yuv[BU_IDX];
644  int32_t rv = rgb2yuv[RV_IDX], gv = rgb2yuv[GV_IDX], bv = rgb2yuv[BV_IDX];
645  for (i = 0; i < width; i++) {
646  int b = src1[6 * i + 0] + src1[6 * i + 3];
647  int g = src1[6 * i + 1] + src1[6 * i + 4];
648  int r = src1[6 * i + 2] + src1[6 * i + 5];
649 
650  dstU[i] = (ru*r + gu*g + bu*b + (256<<RGB2YUV_SHIFT) + (1<<(RGB2YUV_SHIFT-6)))>>(RGB2YUV_SHIFT-5);
651  dstV[i] = (rv*r + gv*g + bv*b + (256<<RGB2YUV_SHIFT) + (1<<(RGB2YUV_SHIFT-6)))>>(RGB2YUV_SHIFT-5);
652  }
653  av_assert1(src1 == src2);
654 }
655 
656 static void rgb24ToY_c(uint8_t *_dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width,
657  uint32_t *rgb2yuv)
658 {
659  int16_t *dst = (int16_t *)_dst;
660  int32_t ry = rgb2yuv[RY_IDX], gy = rgb2yuv[GY_IDX], by = rgb2yuv[BY_IDX];
661  int i;
662  for (i = 0; i < width; i++) {
663  int r = src[i * 3 + 0];
664  int g = src[i * 3 + 1];
665  int b = src[i * 3 + 2];
666 
667  dst[i] = ((ry*r + gy*g + by*b + (32<<(RGB2YUV_SHIFT-1)) + (1<<(RGB2YUV_SHIFT-7)))>>(RGB2YUV_SHIFT-6));
668  }
669 }
670 
671 static void rgb24ToUV_c(uint8_t *_dstU, uint8_t *_dstV, const uint8_t *unused0, const uint8_t *src1,
672  const uint8_t *src2, int width, uint32_t *rgb2yuv)
673 {
674  int16_t *dstU = (int16_t *)_dstU;
675  int16_t *dstV = (int16_t *)_dstV;
676  int i;
677  int32_t ru = rgb2yuv[RU_IDX], gu = rgb2yuv[GU_IDX], bu = rgb2yuv[BU_IDX];
678  int32_t rv = rgb2yuv[RV_IDX], gv = rgb2yuv[GV_IDX], bv = rgb2yuv[BV_IDX];
679  av_assert1(src1 == src2);
680  for (i = 0; i < width; i++) {
681  int r = src1[3 * i + 0];
682  int g = src1[3 * i + 1];
683  int b = src1[3 * i + 2];
684 
685  dstU[i] = (ru*r + gu*g + bu*b + (256<<(RGB2YUV_SHIFT-1)) + (1<<(RGB2YUV_SHIFT-7)))>>(RGB2YUV_SHIFT-6);
686  dstV[i] = (rv*r + gv*g + bv*b + (256<<(RGB2YUV_SHIFT-1)) + (1<<(RGB2YUV_SHIFT-7)))>>(RGB2YUV_SHIFT-6);
687  }
688 }
689 
690 static void rgb24ToUV_half_c(uint8_t *_dstU, uint8_t *_dstV, const uint8_t *unused0, const uint8_t *src1,
691  const uint8_t *src2, int width, uint32_t *rgb2yuv)
692 {
693  int16_t *dstU = (int16_t *)_dstU;
694  int16_t *dstV = (int16_t *)_dstV;
695  int i;
696  int32_t ru = rgb2yuv[RU_IDX], gu = rgb2yuv[GU_IDX], bu = rgb2yuv[BU_IDX];
697  int32_t rv = rgb2yuv[RV_IDX], gv = rgb2yuv[GV_IDX], bv = rgb2yuv[BV_IDX];
698  av_assert1(src1 == src2);
699  for (i = 0; i < width; i++) {
700  int r = src1[6 * i + 0] + src1[6 * i + 3];
701  int g = src1[6 * i + 1] + src1[6 * i + 4];
702  int b = src1[6 * i + 2] + src1[6 * i + 5];
703 
704  dstU[i] = (ru*r + gu*g + bu*b + (256<<RGB2YUV_SHIFT) + (1<<(RGB2YUV_SHIFT-6)))>>(RGB2YUV_SHIFT-5);
705  dstV[i] = (rv*r + gv*g + bv*b + (256<<RGB2YUV_SHIFT) + (1<<(RGB2YUV_SHIFT-6)))>>(RGB2YUV_SHIFT-5);
706  }
707 }
708 
709 static void planar_rgb_to_y(uint8_t *_dst, const uint8_t *src[4], int width, int32_t *rgb2yuv)
710 {
711  uint16_t *dst = (uint16_t *)_dst;
712  int32_t ry = rgb2yuv[RY_IDX], gy = rgb2yuv[GY_IDX], by = rgb2yuv[BY_IDX];
713  int i;
714  for (i = 0; i < width; i++) {
715  int g = src[0][i];
716  int b = src[1][i];
717  int r = src[2][i];
718 
719  dst[i] = (ry*r + gy*g + by*b + (0x801<<(RGB2YUV_SHIFT-7))) >> (RGB2YUV_SHIFT-6);
720  }
721 }
722 
723 static void planar_rgb_to_a(uint8_t *_dst, const uint8_t *src[4], int width, int32_t *unused)
724 {
725  uint16_t *dst = (uint16_t *)_dst;
726  int i;
727  for (i = 0; i < width; i++)
728  dst[i] = src[3][i] << 6;
729 }
730 
731 static void planar_rgb_to_uv(uint8_t *_dstU, uint8_t *_dstV, const uint8_t *src[4], int width, int32_t *rgb2yuv)
732 {
733  uint16_t *dstU = (uint16_t *)_dstU;
734  uint16_t *dstV = (uint16_t *)_dstV;
735  int32_t ru = rgb2yuv[RU_IDX], gu = rgb2yuv[GU_IDX], bu = rgb2yuv[BU_IDX];
736  int32_t rv = rgb2yuv[RV_IDX], gv = rgb2yuv[GV_IDX], bv = rgb2yuv[BV_IDX];
737  int i;
738  for (i = 0; i < width; i++) {
739  int g = src[0][i];
740  int b = src[1][i];
741  int r = src[2][i];
742 
743  dstU[i] = (ru*r + gu*g + bu*b + (0x4001<<(RGB2YUV_SHIFT-7))) >> (RGB2YUV_SHIFT-6);
744  dstV[i] = (rv*r + gv*g + bv*b + (0x4001<<(RGB2YUV_SHIFT-7))) >> (RGB2YUV_SHIFT-6);
745  }
746 }
747 
748 #define rdpx(src) \
749  is_be ? AV_RB16(src) : AV_RL16(src)
750 static av_always_inline void planar_rgb16_to_y(uint8_t *_dst, const uint8_t *_src[4],
751  int width, int bpc, int is_be, int32_t *rgb2yuv)
752 {
753  int i;
754  const uint16_t **src = (const uint16_t **)_src;
755  uint16_t *dst = (uint16_t *)_dst;
756  int32_t ry = rgb2yuv[RY_IDX], gy = rgb2yuv[GY_IDX], by = rgb2yuv[BY_IDX];
757  for (i = 0; i < width; i++) {
758  int g = rdpx(src[0] + i);
759  int b = rdpx(src[1] + i);
760  int r = rdpx(src[2] + i);
761 
762  dst[i] = ((ry*r + gy*g + by*b + (33 << (RGB2YUV_SHIFT + bpc - 9))) >> (RGB2YUV_SHIFT + bpc - 14));
763  }
764 }
765 
767  const uint8_t *_src[4], int width,
768  int bpc, int is_be, int32_t *rgb2yuv)
769 {
770  int i;
771  const uint16_t **src = (const uint16_t **)_src;
772  uint16_t *dstU = (uint16_t *)_dstU;
773  uint16_t *dstV = (uint16_t *)_dstV;
774  int32_t ru = rgb2yuv[RU_IDX], gu = rgb2yuv[GU_IDX], bu = rgb2yuv[BU_IDX];
775  int32_t rv = rgb2yuv[RV_IDX], gv = rgb2yuv[GV_IDX], bv = rgb2yuv[BV_IDX];
776  for (i = 0; i < width; i++) {
777  int g = rdpx(src[0] + i);
778  int b = rdpx(src[1] + i);
779  int r = rdpx(src[2] + i);
780 
781  dstU[i] = (ru*r + gu*g + bu*b + (257 << (RGB2YUV_SHIFT + bpc - 9))) >> (RGB2YUV_SHIFT + bpc - 14);
782  dstV[i] = (rv*r + gv*g + bv*b + (257 << (RGB2YUV_SHIFT + bpc - 9))) >> (RGB2YUV_SHIFT + bpc - 14);
783  }
784 }
785 #undef rdpx
786 
787 #define rgb9plus_planar_funcs_endian(nbits, endian_name, endian) \
788 static void planar_rgb##nbits##endian_name##_to_y(uint8_t *dst, const uint8_t *src[4], \
789  int w, int32_t *rgb2yuv) \
790 { \
791  planar_rgb16_to_y(dst, src, w, nbits, endian, rgb2yuv); \
792 } \
793 static void planar_rgb##nbits##endian_name##_to_uv(uint8_t *dstU, uint8_t *dstV, \
794  const uint8_t *src[4], int w, int32_t *rgb2yuv) \
795 { \
796  planar_rgb16_to_uv(dstU, dstV, src, w, nbits, endian, rgb2yuv); \
797 } \
798 
799 #define rgb9plus_planar_funcs(nbits) \
800  rgb9plus_planar_funcs_endian(nbits, le, 0) \
801  rgb9plus_planar_funcs_endian(nbits, be, 1)
802 
808 
810 {
811  enum AVPixelFormat srcFormat = c->srcFormat;
812 
813  c->chrToYV12 = NULL;
814  switch (srcFormat) {
815  case AV_PIX_FMT_YUYV422:
816  c->chrToYV12 = yuy2ToUV_c;
817  break;
818  case AV_PIX_FMT_UYVY422:
819  c->chrToYV12 = uyvyToUV_c;
820  break;
821  case AV_PIX_FMT_NV12:
822  c->chrToYV12 = nv12ToUV_c;
823  break;
824  case AV_PIX_FMT_NV21:
825  c->chrToYV12 = nv21ToUV_c;
826  break;
827  case AV_PIX_FMT_RGB8:
828  case AV_PIX_FMT_BGR8:
829  case AV_PIX_FMT_PAL8:
832  c->chrToYV12 = palToUV_c;
833  break;
834  case AV_PIX_FMT_GBRP9LE:
835  c->readChrPlanar = planar_rgb9le_to_uv;
836  break;
837  case AV_PIX_FMT_GBRP10LE:
838  c->readChrPlanar = planar_rgb10le_to_uv;
839  break;
840  case AV_PIX_FMT_GBRP12LE:
841  c->readChrPlanar = planar_rgb12le_to_uv;
842  break;
843  case AV_PIX_FMT_GBRP14LE:
844  c->readChrPlanar = planar_rgb14le_to_uv;
845  break;
847  case AV_PIX_FMT_GBRP16LE:
848  c->readChrPlanar = planar_rgb16le_to_uv;
849  break;
850  case AV_PIX_FMT_GBRP9BE:
851  c->readChrPlanar = planar_rgb9be_to_uv;
852  break;
853  case AV_PIX_FMT_GBRP10BE:
854  c->readChrPlanar = planar_rgb10be_to_uv;
855  break;
856  case AV_PIX_FMT_GBRP12BE:
857  c->readChrPlanar = planar_rgb12be_to_uv;
858  break;
859  case AV_PIX_FMT_GBRP14BE:
860  c->readChrPlanar = planar_rgb14be_to_uv;
861  break;
863  case AV_PIX_FMT_GBRP16BE:
864  c->readChrPlanar = planar_rgb16be_to_uv;
865  break;
866  case AV_PIX_FMT_GBRAP:
867  case AV_PIX_FMT_GBRP:
868  c->readChrPlanar = planar_rgb_to_uv;
869  break;
870 #if HAVE_BIGENDIAN
886 
896  c->chrToYV12 = bswap16UV_c;
897  break;
898 #else
914 
924  c->chrToYV12 = bswap16UV_c;
925  break;
926 #endif
927  }
928  if (c->chrSrcHSubSample) {
929  switch (srcFormat) {
930  case AV_PIX_FMT_RGBA64BE:
931  c->chrToYV12 = rgb64BEToUV_half_c;
932  break;
933  case AV_PIX_FMT_RGBA64LE:
934  c->chrToYV12 = rgb64LEToUV_half_c;
935  break;
936  case AV_PIX_FMT_RGB48BE:
937  c->chrToYV12 = rgb48BEToUV_half_c;
938  break;
939  case AV_PIX_FMT_RGB48LE:
940  c->chrToYV12 = rgb48LEToUV_half_c;
941  break;
942  case AV_PIX_FMT_BGR48BE:
943  c->chrToYV12 = bgr48BEToUV_half_c;
944  break;
945  case AV_PIX_FMT_BGR48LE:
946  c->chrToYV12 = bgr48LEToUV_half_c;
947  break;
948  case AV_PIX_FMT_RGB32:
949  c->chrToYV12 = bgr32ToUV_half_c;
950  break;
951  case AV_PIX_FMT_RGB32_1:
952  c->chrToYV12 = bgr321ToUV_half_c;
953  break;
954  case AV_PIX_FMT_BGR24:
955  c->chrToYV12 = bgr24ToUV_half_c;
956  break;
957  case AV_PIX_FMT_BGR565LE:
958  c->chrToYV12 = bgr16leToUV_half_c;
959  break;
960  case AV_PIX_FMT_BGR565BE:
961  c->chrToYV12 = bgr16beToUV_half_c;
962  break;
963  case AV_PIX_FMT_BGR555LE:
964  c->chrToYV12 = bgr15leToUV_half_c;
965  break;
966  case AV_PIX_FMT_BGR555BE:
967  c->chrToYV12 = bgr15beToUV_half_c;
968  break;
969  case AV_PIX_FMT_GBRAP:
970  case AV_PIX_FMT_GBRP:
971  c->chrToYV12 = gbr24pToUV_half_c;
972  break;
973  case AV_PIX_FMT_BGR444LE:
974  c->chrToYV12 = bgr12leToUV_half_c;
975  break;
976  case AV_PIX_FMT_BGR444BE:
977  c->chrToYV12 = bgr12beToUV_half_c;
978  break;
979  case AV_PIX_FMT_BGR32:
980  c->chrToYV12 = rgb32ToUV_half_c;
981  break;
982  case AV_PIX_FMT_BGR32_1:
983  c->chrToYV12 = rgb321ToUV_half_c;
984  break;
985  case AV_PIX_FMT_RGB24:
986  c->chrToYV12 = rgb24ToUV_half_c;
987  break;
988  case AV_PIX_FMT_RGB565LE:
989  c->chrToYV12 = rgb16leToUV_half_c;
990  break;
991  case AV_PIX_FMT_RGB565BE:
992  c->chrToYV12 = rgb16beToUV_half_c;
993  break;
994  case AV_PIX_FMT_RGB555LE:
995  c->chrToYV12 = rgb15leToUV_half_c;
996  break;
997  case AV_PIX_FMT_RGB555BE:
998  c->chrToYV12 = rgb15beToUV_half_c;
999  break;
1000  case AV_PIX_FMT_RGB444LE:
1001  c->chrToYV12 = rgb12leToUV_half_c;
1002  break;
1003  case AV_PIX_FMT_RGB444BE:
1004  c->chrToYV12 = rgb12beToUV_half_c;
1005  break;
1006  }
1007  } else {
1008  switch (srcFormat) {
1009  case AV_PIX_FMT_RGBA64BE:
1010  c->chrToYV12 = rgb64BEToUV_c;
1011  break;
1012  case AV_PIX_FMT_RGBA64LE:
1013  c->chrToYV12 = rgb64LEToUV_c;
1014  break;
1015  case AV_PIX_FMT_RGB48BE:
1016  c->chrToYV12 = rgb48BEToUV_c;
1017  break;
1018  case AV_PIX_FMT_RGB48LE:
1019  c->chrToYV12 = rgb48LEToUV_c;
1020  break;
1021  case AV_PIX_FMT_BGR48BE:
1022  c->chrToYV12 = bgr48BEToUV_c;
1023  break;
1024  case AV_PIX_FMT_BGR48LE:
1025  c->chrToYV12 = bgr48LEToUV_c;
1026  break;
1027  case AV_PIX_FMT_RGB32:
1028  c->chrToYV12 = bgr32ToUV_c;
1029  break;
1030  case AV_PIX_FMT_RGB32_1:
1031  c->chrToYV12 = bgr321ToUV_c;
1032  break;
1033  case AV_PIX_FMT_BGR24:
1034  c->chrToYV12 = bgr24ToUV_c;
1035  break;
1036  case AV_PIX_FMT_BGR565LE:
1037  c->chrToYV12 = bgr16leToUV_c;
1038  break;
1039  case AV_PIX_FMT_BGR565BE:
1040  c->chrToYV12 = bgr16beToUV_c;
1041  break;
1042  case AV_PIX_FMT_BGR555LE:
1043  c->chrToYV12 = bgr15leToUV_c;
1044  break;
1045  case AV_PIX_FMT_BGR555BE:
1046  c->chrToYV12 = bgr15beToUV_c;
1047  break;
1048  case AV_PIX_FMT_BGR444LE:
1049  c->chrToYV12 = bgr12leToUV_c;
1050  break;
1051  case AV_PIX_FMT_BGR444BE:
1052  c->chrToYV12 = bgr12beToUV_c;
1053  break;
1054  case AV_PIX_FMT_BGR32:
1055  c->chrToYV12 = rgb32ToUV_c;
1056  break;
1057  case AV_PIX_FMT_BGR32_1:
1058  c->chrToYV12 = rgb321ToUV_c;
1059  break;
1060  case AV_PIX_FMT_RGB24:
1061  c->chrToYV12 = rgb24ToUV_c;
1062  break;
1063  case AV_PIX_FMT_RGB565LE:
1064  c->chrToYV12 = rgb16leToUV_c;
1065  break;
1066  case AV_PIX_FMT_RGB565BE:
1067  c->chrToYV12 = rgb16beToUV_c;
1068  break;
1069  case AV_PIX_FMT_RGB555LE:
1070  c->chrToYV12 = rgb15leToUV_c;
1071  break;
1072  case AV_PIX_FMT_RGB555BE:
1073  c->chrToYV12 = rgb15beToUV_c;
1074  break;
1075  case AV_PIX_FMT_RGB444LE:
1076  c->chrToYV12 = rgb12leToUV_c;
1077  break;
1078  case AV_PIX_FMT_RGB444BE:
1079  c->chrToYV12 = rgb12beToUV_c;
1080  break;
1081  }
1082  }
1083 
1084  c->lumToYV12 = NULL;
1085  c->alpToYV12 = NULL;
1086  switch (srcFormat) {
1087  case AV_PIX_FMT_GBRP9LE:
1088  c->readLumPlanar = planar_rgb9le_to_y;
1089  break;
1090  case AV_PIX_FMT_GBRP10LE:
1091  c->readLumPlanar = planar_rgb10le_to_y;
1092  break;
1093  case AV_PIX_FMT_GBRP12LE:
1094  c->readLumPlanar = planar_rgb12le_to_y;
1095  break;
1096  case AV_PIX_FMT_GBRP14LE:
1097  c->readLumPlanar = planar_rgb14le_to_y;
1098  break;
1099  case AV_PIX_FMT_GBRAP16LE:
1100  case AV_PIX_FMT_GBRP16LE:
1101  c->readLumPlanar = planar_rgb16le_to_y;
1102  break;
1103  case AV_PIX_FMT_GBRP9BE:
1104  c->readLumPlanar = planar_rgb9be_to_y;
1105  break;
1106  case AV_PIX_FMT_GBRP10BE:
1107  c->readLumPlanar = planar_rgb10be_to_y;
1108  break;
1109  case AV_PIX_FMT_GBRP12BE:
1110  c->readLumPlanar = planar_rgb12be_to_y;
1111  break;
1112  case AV_PIX_FMT_GBRP14BE:
1113  c->readLumPlanar = planar_rgb14be_to_y;
1114  break;
1115  case AV_PIX_FMT_GBRAP16BE:
1116  case AV_PIX_FMT_GBRP16BE:
1117  c->readLumPlanar = planar_rgb16be_to_y;
1118  break;
1119  case AV_PIX_FMT_GBRAP:
1120  c->readAlpPlanar = planar_rgb_to_a;
1121  case AV_PIX_FMT_GBRP:
1122  c->readLumPlanar = planar_rgb_to_y;
1123  break;
1124 #if HAVE_BIGENDIAN
1125  case AV_PIX_FMT_YUV444P9LE:
1126  case AV_PIX_FMT_YUV422P9LE:
1127  case AV_PIX_FMT_YUV420P9LE:
1140 
1141  case AV_PIX_FMT_GRAY16LE:
1142  c->lumToYV12 = bswap16Y_c;
1143  break;
1153  c->lumToYV12 = bswap16Y_c;
1154  c->alpToYV12 = bswap16Y_c;
1155  break;
1156 #else
1157  case AV_PIX_FMT_YUV444P9BE:
1158  case AV_PIX_FMT_YUV422P9BE:
1159  case AV_PIX_FMT_YUV420P9BE:
1172 
1173  case AV_PIX_FMT_GRAY16BE:
1174  c->lumToYV12 = bswap16Y_c;
1175  break;
1185  c->lumToYV12 = bswap16Y_c;
1186  c->alpToYV12 = bswap16Y_c;
1187  break;
1188 #endif
1189  case AV_PIX_FMT_YUYV422:
1190  case AV_PIX_FMT_Y400A:
1191  c->lumToYV12 = yuy2ToY_c;
1192  break;
1193  case AV_PIX_FMT_UYVY422:
1194  c->lumToYV12 = uyvyToY_c;
1195  break;
1196  case AV_PIX_FMT_BGR24:
1197  c->lumToYV12 = bgr24ToY_c;
1198  break;
1199  case AV_PIX_FMT_BGR565LE:
1200  c->lumToYV12 = bgr16leToY_c;
1201  break;
1202  case AV_PIX_FMT_BGR565BE:
1203  c->lumToYV12 = bgr16beToY_c;
1204  break;
1205  case AV_PIX_FMT_BGR555LE:
1206  c->lumToYV12 = bgr15leToY_c;
1207  break;
1208  case AV_PIX_FMT_BGR555BE:
1209  c->lumToYV12 = bgr15beToY_c;
1210  break;
1211  case AV_PIX_FMT_BGR444LE:
1212  c->lumToYV12 = bgr12leToY_c;
1213  break;
1214  case AV_PIX_FMT_BGR444BE:
1215  c->lumToYV12 = bgr12beToY_c;
1216  break;
1217  case AV_PIX_FMT_RGB24:
1218  c->lumToYV12 = rgb24ToY_c;
1219  break;
1220  case AV_PIX_FMT_RGB565LE:
1221  c->lumToYV12 = rgb16leToY_c;
1222  break;
1223  case AV_PIX_FMT_RGB565BE:
1224  c->lumToYV12 = rgb16beToY_c;
1225  break;
1226  case AV_PIX_FMT_RGB555LE:
1227  c->lumToYV12 = rgb15leToY_c;
1228  break;
1229  case AV_PIX_FMT_RGB555BE:
1230  c->lumToYV12 = rgb15beToY_c;
1231  break;
1232  case AV_PIX_FMT_RGB444LE:
1233  c->lumToYV12 = rgb12leToY_c;
1234  break;
1235  case AV_PIX_FMT_RGB444BE:
1236  c->lumToYV12 = rgb12beToY_c;
1237  break;
1238  case AV_PIX_FMT_RGB8:
1239  case AV_PIX_FMT_BGR8:
1240  case AV_PIX_FMT_PAL8:
1241  case AV_PIX_FMT_BGR4_BYTE:
1242  case AV_PIX_FMT_RGB4_BYTE:
1243  c->lumToYV12 = palToY_c;
1244  break;
1245  case AV_PIX_FMT_MONOBLACK:
1246  c->lumToYV12 = monoblack2Y_c;
1247  break;
1248  case AV_PIX_FMT_MONOWHITE:
1249  c->lumToYV12 = monowhite2Y_c;
1250  break;
1251  case AV_PIX_FMT_RGB32:
1252  c->lumToYV12 = bgr32ToY_c;
1253  break;
1254  case AV_PIX_FMT_RGB32_1:
1255  c->lumToYV12 = bgr321ToY_c;
1256  break;
1257  case AV_PIX_FMT_BGR32:
1258  c->lumToYV12 = rgb32ToY_c;
1259  break;
1260  case AV_PIX_FMT_BGR32_1:
1261  c->lumToYV12 = rgb321ToY_c;
1262  break;
1263  case AV_PIX_FMT_RGB48BE:
1264  c->lumToYV12 = rgb48BEToY_c;
1265  break;
1266  case AV_PIX_FMT_RGB48LE:
1267  c->lumToYV12 = rgb48LEToY_c;
1268  break;
1269  case AV_PIX_FMT_BGR48BE:
1270  c->lumToYV12 = bgr48BEToY_c;
1271  break;
1272  case AV_PIX_FMT_BGR48LE:
1273  c->lumToYV12 = bgr48LEToY_c;
1274  break;
1275  case AV_PIX_FMT_RGBA64BE:
1276  c->lumToYV12 = rgb64BEToY_c;
1277  break;
1278  case AV_PIX_FMT_RGBA64LE:
1279  c->lumToYV12 = rgb64LEToY_c;
1280  break;
1281  }
1282  if (c->alpPixBuf) {
1283  if (is16BPS(srcFormat) || isNBPS(srcFormat)) {
1284  if (HAVE_BIGENDIAN == !isBE(srcFormat))
1285  c->alpToYV12 = bswap16Y_c;
1286  }
1287  switch (srcFormat) {
1288  case AV_PIX_FMT_RGBA64LE:
1289  case AV_PIX_FMT_RGBA64BE: c->alpToYV12 = rgba64ToA_c; break;
1290  case AV_PIX_FMT_BGRA:
1291  case AV_PIX_FMT_RGBA:
1292  c->alpToYV12 = rgbaToA_c;
1293  break;
1294  case AV_PIX_FMT_ABGR:
1295  case AV_PIX_FMT_ARGB:
1296  c->alpToYV12 = abgrToA_c;
1297  break;
1298  case AV_PIX_FMT_Y400A:
1299  c->alpToYV12 = uyvyToY_c;
1300  break;
1301  case AV_PIX_FMT_PAL8 :
1302  c->alpToYV12 = palToA_c;
1303  break;
1304  }
1305  }
1306 }