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