Libav
input.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2001-2003 Michael Niedermayer <michaelni@gmx.at>
3  *
4  * This file is part of Libav.
5  *
6  * Libav 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  * Libav 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 Libav; 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 "config.h"
34 #include "rgb2rgb.h"
35 #include "swscale.h"
36 #include "swscale_internal.h"
37 
38 #define RGB2YUV_SHIFT 15
39 #define BY ((int)(0.114 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
40 #define BV (-(int)(0.081 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
41 #define BU ((int)(0.500 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
42 #define GY ((int)(0.587 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
43 #define GV (-(int)(0.419 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
44 #define GU (-(int)(0.331 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
45 #define RY ((int)(0.299 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
46 #define RV ((int)(0.500 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
47 #define RU (-(int)(0.169 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
48 
49 #define input_pixel(pos) (isBE(origin) ? AV_RB16(pos) : AV_RL16(pos))
50 
51 #define r ((origin == AV_PIX_FMT_BGR48BE || origin == AV_PIX_FMT_BGR48LE) ? b_r : r_b)
52 #define b ((origin == AV_PIX_FMT_BGR48BE || origin == AV_PIX_FMT_BGR48LE) ? r_b : b_r)
53 
54 static av_always_inline void rgb48ToY_c_template(uint16_t *dst,
55  const uint16_t *src, int width,
56  enum AVPixelFormat origin)
57 {
58  int i;
59  for (i = 0; i < width; i++) {
60  unsigned int r_b = input_pixel(&src[i * 3 + 0]);
61  unsigned int g = input_pixel(&src[i * 3 + 1]);
62  unsigned int b_r = input_pixel(&src[i * 3 + 2]);
63 
64  dst[i] = (RY * r + GY * g + BY * b + (0x2001 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT;
65  }
66 }
67 
68 static av_always_inline void rgb48ToUV_c_template(uint16_t *dstU,
69  uint16_t *dstV,
70  const uint16_t *src1,
71  const uint16_t *src2,
72  int width,
73  enum AVPixelFormat origin)
74 {
75  int i;
76  assert(src1 == src2);
77  for (i = 0; i < width; i++) {
78  int r_b = input_pixel(&src1[i * 3 + 0]);
79  int g = input_pixel(&src1[i * 3 + 1]);
80  int b_r = input_pixel(&src1[i * 3 + 2]);
81 
82  dstU[i] = (RU * r + GU * g + BU * b + (0x10001 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT;
83  dstV[i] = (RV * r + GV * g + BV * b + (0x10001 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT;
84  }
85 }
86 
87 static av_always_inline void rgb48ToUV_half_c_template(uint16_t *dstU,
88  uint16_t *dstV,
89  const uint16_t *src1,
90  const uint16_t *src2,
91  int width,
92  enum AVPixelFormat origin)
93 {
94  int i;
95  assert(src1 == src2);
96  for (i = 0; i < width; i++) {
97  int r_b = (input_pixel(&src1[6 * i + 0]) +
98  input_pixel(&src1[6 * i + 3]) + 1) >> 1;
99  int g = (input_pixel(&src1[6 * i + 1]) +
100  input_pixel(&src1[6 * i + 4]) + 1) >> 1;
101  int b_r = (input_pixel(&src1[6 * i + 2]) +
102  input_pixel(&src1[6 * i + 5]) + 1) >> 1;
103 
104  dstU[i] = (RU * r + GU * g + BU * b + (0x10001 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT;
105  dstV[i] = (RV * r + GV * g + BV * b + (0x10001 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT;
106  }
107 }
108 
109 #undef r
110 #undef b
111 #undef input_pixel
112 
113 #define rgb48funcs(pattern, BE_LE, origin) \
114 static void pattern ## 48 ## BE_LE ## ToY_c(uint8_t *_dst, \
115  const uint8_t *_src, \
116  int width, \
117  uint32_t *unused) \
118 { \
119  const uint16_t *src = (const uint16_t *)_src; \
120  uint16_t *dst = (uint16_t *)_dst; \
121  rgb48ToY_c_template(dst, src, width, origin); \
122 } \
123  \
124 static void pattern ## 48 ## BE_LE ## ToUV_c(uint8_t *_dstU, \
125  uint8_t *_dstV, \
126  const uint8_t *_src1, \
127  const uint8_t *_src2, \
128  int width, \
129  uint32_t *unused) \
130 { \
131  const uint16_t *src1 = (const uint16_t *)_src1, \
132  *src2 = (const uint16_t *)_src2; \
133  uint16_t *dstU = (uint16_t *)_dstU, \
134  *dstV = (uint16_t *)_dstV; \
135  rgb48ToUV_c_template(dstU, dstV, src1, src2, width, origin); \
136 } \
137  \
138 static void pattern ## 48 ## BE_LE ## ToUV_half_c(uint8_t *_dstU, \
139  uint8_t *_dstV, \
140  const uint8_t *_src1, \
141  const uint8_t *_src2, \
142  int width, \
143  uint32_t *unused) \
144 { \
145  const uint16_t *src1 = (const uint16_t *)_src1, \
146  *src2 = (const uint16_t *)_src2; \
147  uint16_t *dstU = (uint16_t *)_dstU, \
148  *dstV = (uint16_t *)_dstV; \
149  rgb48ToUV_half_c_template(dstU, dstV, src1, src2, width, origin); \
150 }
151 
156 
157 #define input_pixel(i) ((origin == AV_PIX_FMT_RGBA || \
158  origin == AV_PIX_FMT_BGRA || \
159  origin == AV_PIX_FMT_ARGB || \
160  origin == AV_PIX_FMT_ABGR) \
161  ? AV_RN32A(&src[(i) * 4]) \
162  : (isBE(origin) ? AV_RB16(&src[(i) * 2]) \
163  : AV_RL16(&src[(i) * 2])))
164 
165 static av_always_inline void rgb16_32ToY_c_template(uint8_t *dst,
166  const uint8_t *src,
167  int width,
168  enum AVPixelFormat origin,
169  int shr, int shg,
170  int shb, int shp,
171  int maskr, int maskg,
172  int maskb, int rsh,
173  int gsh, int bsh, int S)
174 {
175  const int ry = RY << rsh, gy = GY << gsh, by = BY << bsh;
176  const unsigned rnd = 33u << (S - 1);
177  int i;
178 
179  for (i = 0; i < width; i++) {
180  int px = input_pixel(i) >> shp;
181  int b = (px & maskb) >> shb;
182  int g = (px & maskg) >> shg;
183  int r = (px & maskr) >> shr;
184 
185  dst[i] = (ry * r + gy * g + by * b + rnd) >> S;
186  }
187 }
188 
190  uint8_t *dstV,
191  const uint8_t *src,
192  int width,
193  enum AVPixelFormat origin,
194  int shr, int shg,
195  int shb, int shp,
196  int maskr, int maskg,
197  int maskb, int rsh,
198  int gsh, int bsh, int S)
199 {
200  const int ru = RU << rsh, gu = GU << gsh, bu = BU << bsh,
201  rv = RV << rsh, gv = GV << gsh, bv = BV << bsh;
202  const unsigned rnd = 257u << (S - 1);
203  int i;
204 
205  for (i = 0; i < width; i++) {
206  int px = input_pixel(i) >> shp;
207  int b = (px & maskb) >> shb;
208  int g = (px & maskg) >> shg;
209  int r = (px & maskr) >> shr;
210 
211  dstU[i] = (ru * r + gu * g + bu * b + rnd) >> S;
212  dstV[i] = (rv * r + gv * g + bv * b + rnd) >> S;
213  }
214 }
215 
217  uint8_t *dstV,
218  const uint8_t *src,
219  int width,
220  enum AVPixelFormat origin,
221  int shr, int shg,
222  int shb, int shp,
223  int maskr, int maskg,
224  int maskb, int rsh,
225  int gsh, int bsh, int S)
226 {
227  const int ru = RU << rsh, gu = GU << gsh, bu = BU << bsh,
228  rv = RV << rsh, gv = GV << gsh, bv = BV << bsh,
229  maskgx = ~(maskr | maskb);
230  const unsigned rnd = 257u << S;
231  int i;
232 
233  maskr |= maskr << 1;
234  maskb |= maskb << 1;
235  maskg |= maskg << 1;
236  for (i = 0; i < width; i++) {
237  int px0 = input_pixel(2 * i + 0) >> shp;
238  int px1 = input_pixel(2 * i + 1) >> shp;
239  int b, r, g = (px0 & maskgx) + (px1 & maskgx);
240  int rb = px0 + px1 - g;
241 
242  b = (rb & maskb) >> shb;
243  if (shp ||
244  origin == AV_PIX_FMT_BGR565LE || origin == AV_PIX_FMT_BGR565BE ||
245  origin == AV_PIX_FMT_RGB565LE || origin == AV_PIX_FMT_RGB565BE) {
246  g >>= shg;
247  } else {
248  g = (g & maskg) >> shg;
249  }
250  r = (rb & maskr) >> shr;
251 
252  dstU[i] = (ru * r + gu * g + bu * b + rnd) >> (S + 1);
253  dstV[i] = (rv * r + gv * g + bv * b + rnd) >> (S + 1);
254  }
255 }
256 
257 #undef input_pixel
258 
259 #define rgb16_32_wrapper(fmt, name, shr, shg, shb, shp, maskr, \
260  maskg, maskb, rsh, gsh, bsh, S) \
261 static void name ## ToY_c(uint8_t *dst, const uint8_t *src, \
262  int width, uint32_t *unused) \
263 { \
264  rgb16_32ToY_c_template(dst, src, width, fmt, shr, shg, shb, shp, \
265  maskr, maskg, maskb, rsh, gsh, bsh, S); \
266 } \
267  \
268 static void name ## ToUV_c(uint8_t *dstU, uint8_t *dstV, \
269  const uint8_t *src, const uint8_t *dummy, \
270  int width, uint32_t *unused) \
271 { \
272  rgb16_32ToUV_c_template(dstU, dstV, src, width, fmt, \
273  shr, shg, shb, shp, \
274  maskr, maskg, maskb, rsh, gsh, bsh, S); \
275 } \
276  \
277 static void name ## ToUV_half_c(uint8_t *dstU, uint8_t *dstV, \
278  const uint8_t *src, \
279  const uint8_t *dummy, \
280  int width, uint32_t *unused) \
281 { \
282  rgb16_32ToUV_half_c_template(dstU, dstV, src, width, fmt, \
283  shr, shg, shb, shp, \
284  maskr, maskg, maskb, \
285  rsh, gsh, bsh, S); \
286 }
287 
288 rgb16_32_wrapper(AV_PIX_FMT_BGR32, bgr32, 16, 0, 0, 0, 0xFF0000, 0xFF00, 0x00FF, 8, 0, 8, RGB2YUV_SHIFT + 8)
289 rgb16_32_wrapper(AV_PIX_FMT_BGR32_1, bgr321, 16, 0, 0, 8, 0xFF0000, 0xFF00, 0x00FF, 8, 0, 8, RGB2YUV_SHIFT + 8)
290 rgb16_32_wrapper(AV_PIX_FMT_RGB32, rgb32, 0, 0, 16, 0, 0x00FF, 0xFF00, 0xFF0000, 8, 0, 8, RGB2YUV_SHIFT + 8)
291 rgb16_32_wrapper(AV_PIX_FMT_RGB32_1, rgb321, 0, 0, 16, 8, 0x00FF, 0xFF00, 0xFF0000, 8, 0, 8, RGB2YUV_SHIFT + 8)
292 rgb16_32_wrapper(AV_PIX_FMT_BGR565LE, bgr16le, 0, 0, 0, 0, 0x001F, 0x07E0, 0xF800, 11, 5, 0, RGB2YUV_SHIFT + 8)
293 rgb16_32_wrapper(AV_PIX_FMT_BGR555LE, bgr15le, 0, 0, 0, 0, 0x001F, 0x03E0, 0x7C00, 10, 5, 0, RGB2YUV_SHIFT + 7)
294 rgb16_32_wrapper(AV_PIX_FMT_BGR444LE, bgr12le, 0, 0, 0, 0, 0x000F, 0x00F0, 0x0F00, 8, 4, 0, RGB2YUV_SHIFT + 4)
295 rgb16_32_wrapper(AV_PIX_FMT_RGB565LE, rgb16le, 0, 0, 0, 0, 0xF800, 0x07E0, 0x001F, 0, 5, 11, RGB2YUV_SHIFT + 8)
296 rgb16_32_wrapper(AV_PIX_FMT_RGB555LE, rgb15le, 0, 0, 0, 0, 0x7C00, 0x03E0, 0x001F, 0, 5, 10, RGB2YUV_SHIFT + 7)
297 rgb16_32_wrapper(AV_PIX_FMT_RGB444LE, rgb12le, 0, 0, 0, 0, 0x0F00, 0x00F0, 0x000F, 0, 4, 8, RGB2YUV_SHIFT + 4)
298 rgb16_32_wrapper(AV_PIX_FMT_BGR565BE, bgr16be, 0, 0, 0, 0, 0x001F, 0x07E0, 0xF800, 11, 5, 0, RGB2YUV_SHIFT + 8)
299 rgb16_32_wrapper(AV_PIX_FMT_BGR555BE, bgr15be, 0, 0, 0, 0, 0x001F, 0x03E0, 0x7C00, 10, 5, 0, RGB2YUV_SHIFT + 7)
300 rgb16_32_wrapper(AV_PIX_FMT_BGR444BE, bgr12be, 0, 0, 0, 0, 0x000F, 0x00F0, 0x0F00, 8, 4, 0, RGB2YUV_SHIFT + 4)
301 rgb16_32_wrapper(AV_PIX_FMT_RGB565BE, rgb16be, 0, 0, 0, 0, 0xF800, 0x07E0, 0x001F, 0, 5, 11, RGB2YUV_SHIFT + 8)
302 rgb16_32_wrapper(AV_PIX_FMT_RGB555BE, rgb15be, 0, 0, 0, 0, 0x7C00, 0x03E0, 0x001F, 0, 5, 10, RGB2YUV_SHIFT + 7)
303 rgb16_32_wrapper(AV_PIX_FMT_RGB444BE, rgb12be, 0, 0, 0, 0, 0x0F00, 0x00F0, 0x000F, 0, 4, 8, RGB2YUV_SHIFT + 4)
304 
305 static void abgrToA_c(uint8_t *dst, const uint8_t *src, int width,
306  uint32_t *unused)
307 {
308  int i;
309  for (i = 0; i < width; i++)
310  dst[i] = src[4 * i];
311 }
312 
313 static void rgbaToA_c(uint8_t *dst, const uint8_t *src, int width,
314  uint32_t *unused)
315 {
316  int i;
317  for (i = 0; i < width; i++)
318  dst[i] = src[4 * i + 3];
319 }
320 
321 static void palToY_c(uint8_t *dst, const uint8_t *src, int width, uint32_t *pal)
322 {
323  int i;
324  for (i = 0; i < width; i++) {
325  int d = src[i];
326 
327  dst[i] = pal[d] & 0xFF;
328  }
329 }
330 
331 static void palToUV_c(uint8_t *dstU, uint8_t *dstV,
332  const uint8_t *src1, const uint8_t *src2,
333  int width, uint32_t *pal)
334 {
335  int i;
336  assert(src1 == src2);
337  for (i = 0; i < width; i++) {
338  int p = pal[src1[i]];
339 
340  dstU[i] = p >> 8;
341  dstV[i] = p >> 16;
342  }
343 }
344 
345 static void monowhite2Y_c(uint8_t *dst, const uint8_t *src,
346  int width, uint32_t *unused)
347 {
348  int i, j;
349  width = (width + 7) >> 3;
350  for (i = 0; i < width; i++) {
351  int d = ~src[i];
352  for (j = 0; j < 8; j++)
353  dst[8 * i + j] = ((d >> (7 - j)) & 1) * 255;
354  }
355 }
356 
357 static void monoblack2Y_c(uint8_t *dst, const uint8_t *src,
358  int width, uint32_t *unused)
359 {
360  int i, j;
361  width = (width + 7) >> 3;
362  for (i = 0; i < width; i++) {
363  int d = src[i];
364  for (j = 0; j < 8; j++)
365  dst[8 * i + j] = ((d >> (7 - j)) & 1) * 255;
366  }
367 }
368 
369 static void yuy2ToY_c(uint8_t *dst, const uint8_t *src, int width,
370  uint32_t *unused)
371 {
372  int i;
373  for (i = 0; i < width; i++)
374  dst[i] = src[2 * i];
375 }
376 
377 static void yuy2ToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1,
378  const uint8_t *src2, int width, uint32_t *unused)
379 {
380  int i;
381  for (i = 0; i < width; i++) {
382  dstU[i] = src1[4 * i + 1];
383  dstV[i] = src1[4 * i + 3];
384  }
385  assert(src1 == src2);
386 }
387 
388 static void yvy2ToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1,
389  const uint8_t *src2, int width, uint32_t *unused)
390 {
391  int i;
392  for (i = 0; i < width; i++) {
393  dstV[i] = src1[4 * i + 1];
394  dstU[i] = src1[4 * i + 3];
395  }
396  assert(src1 == src2);
397 }
398 
399 static void bswap16Y_c(uint8_t *_dst, const uint8_t *_src, int width,
400  uint32_t *unused)
401 {
402  int i;
403  const uint16_t *src = (const uint16_t *)_src;
404  uint16_t *dst = (uint16_t *)_dst;
405  for (i = 0; i < width; i++)
406  dst[i] = av_bswap16(src[i]);
407 }
408 
409 static void bswap16UV_c(uint8_t *_dstU, uint8_t *_dstV, const uint8_t *_src1,
410  const uint8_t *_src2, int width, uint32_t *unused)
411 {
412  int i;
413  const uint16_t *src1 = (const uint16_t *)_src1,
414  *src2 = (const uint16_t *)_src2;
415  uint16_t *dstU = (uint16_t *)_dstU, *dstV = (uint16_t *)_dstV;
416  for (i = 0; i < width; i++) {
417  dstU[i] = av_bswap16(src1[i]);
418  dstV[i] = av_bswap16(src2[i]);
419  }
420 }
421 
422 static void read_ya16le_gray_c(uint8_t *dst, const uint8_t *src, int width,
423  uint32_t *unused)
424 {
425  int i;
426  for (i = 0; i < width; i++)
427  AV_WN16(dst + i * 2, AV_RL16(src + i * 4));
428 }
429 
430 static void read_ya16le_alpha_c(uint8_t *dst, const uint8_t *src, int width,
431  uint32_t *unused)
432 {
433  int i;
434  for (i = 0; i < width; i++)
435  AV_WN16(dst + i * 2, AV_RL16(src + i * 4 + 2));
436 }
437 
438 static void read_ya16be_gray_c(uint8_t *dst, const uint8_t *src, int width,
439  uint32_t *unused)
440 {
441  int i;
442  for (i = 0; i < width; i++)
443  AV_WN16(dst + i * 2, AV_RB16(src + i * 4));
444 }
445 
446 static void read_ya16be_alpha_c(uint8_t *dst, const uint8_t *src, int width,
447  uint32_t *unused)
448 {
449  int i;
450  for (i = 0; i < width; i++)
451  AV_WN16(dst + i * 2, AV_RB16(src + i * 4 + 2));
452 }
453 
454 /* This is almost identical to the previous, end exists only because
455  * yuy2ToY/UV)(dst, src + 1, ...) would have 100% unaligned accesses. */
456 static void uyvyToY_c(uint8_t *dst, const uint8_t *src, int width,
457  uint32_t *unused)
458 {
459  int i;
460  for (i = 0; i < width; i++)
461  dst[i] = src[2 * i + 1];
462 }
463 
464 static void uyvyToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1,
465  const uint8_t *src2, int width, uint32_t *unused)
466 {
467  int i;
468  for (i = 0; i < width; i++) {
469  dstU[i] = src1[4 * i + 0];
470  dstV[i] = src1[4 * i + 2];
471  }
472  assert(src1 == src2);
473 }
474 
475 static av_always_inline void nvXXtoUV_c(uint8_t *dst1, uint8_t *dst2,
476  const uint8_t *src, int width)
477 {
478  int i;
479  for (i = 0; i < width; i++) {
480  dst1[i] = src[2 * i + 0];
481  dst2[i] = src[2 * i + 1];
482  }
483 }
484 
485 static void nv12ToUV_c(uint8_t *dstU, uint8_t *dstV,
486  const uint8_t *src1, const uint8_t *src2,
487  int width, uint32_t *unused)
488 {
489  nvXXtoUV_c(dstU, dstV, src1, width);
490 }
491 
492 static void nv21ToUV_c(uint8_t *dstU, uint8_t *dstV,
493  const uint8_t *src1, const uint8_t *src2,
494  int width, uint32_t *unused)
495 {
496  nvXXtoUV_c(dstV, dstU, src1, width);
497 }
498 
499 static void p010LEToY_c(uint8_t *dst, const uint8_t *src, int width, uint32_t *unused)
500 {
501  int i;
502  for (i = 0; i < width; i++) {
503  AV_WN16(dst + i * 2, AV_RL16(src + i * 2) >> 6);
504  }
505 }
506 
507 static void p010BEToY_c(uint8_t *dst, const uint8_t *src, int width, uint32_t *unused)
508 {
509  int i;
510  for (i = 0; i < width; i++) {
511  AV_WN16(dst + i * 2, AV_RB16(src + i * 2) >> 6);
512  }
513 }
514 
515 static void p010LEToUV_c(uint8_t *dstU, uint8_t *dstV,
516  const uint8_t *src1, const uint8_t *src2,
517  int width, uint32_t *unused)
518 {
519  int i;
520  for (i = 0; i < width; i++) {
521  AV_WN16(dstU + i * 2, AV_RL16(src1 + i * 4 + 0) >> 6);
522  AV_WN16(dstV + i * 2, AV_RL16(src1 + i * 4 + 2) >> 6);
523  }
524 }
525 
526 static void p010BEToUV_c(uint8_t *dstU, uint8_t *dstV,
527  const uint8_t *src1, const uint8_t *src2,
528  int width, uint32_t *unused)
529 {
530  int i;
531  for (i = 0; i < width; i++) {
532  AV_WN16(dstU + i * 2, AV_RB16(src1 + i * 4 + 0) >> 6);
533  AV_WN16(dstV + i * 2, AV_RB16(src1 + i * 4 + 2) >> 6);
534  }
535 }
536 
537 #define input_pixel(pos) (isBE(origin) ? AV_RB16(pos) : AV_RL16(pos))
538 
539 static void bgr24ToY_c(uint8_t *dst, const uint8_t *src,
540  int width, uint32_t *unused)
541 {
542  int i;
543  for (i = 0; i < width; i++) {
544  int b = src[i * 3 + 0];
545  int g = src[i * 3 + 1];
546  int r = src[i * 3 + 2];
547 
548  dst[i] = ((RY * r + GY * g + BY * b + (33 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT);
549  }
550 }
551 
552 static void bgr24ToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1,
553  const uint8_t *src2, int width, uint32_t *unused)
554 {
555  int i;
556  for (i = 0; i < width; i++) {
557  int b = src1[3 * i + 0];
558  int g = src1[3 * i + 1];
559  int r = src1[3 * i + 2];
560 
561  dstU[i] = (RU * r + GU * g + BU * b + (257 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT;
562  dstV[i] = (RV * r + GV * g + BV * b + (257 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT;
563  }
564  assert(src1 == src2);
565 }
566 
567 static void bgr24ToUV_half_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1,
568  const uint8_t *src2, int width, uint32_t *unused)
569 {
570  int i;
571  for (i = 0; i < width; i++) {
572  int b = src1[6 * i + 0] + src1[6 * i + 3];
573  int g = src1[6 * i + 1] + src1[6 * i + 4];
574  int r = src1[6 * i + 2] + src1[6 * i + 5];
575 
576  dstU[i] = (RU * r + GU * g + BU * b + (257 << RGB2YUV_SHIFT)) >> (RGB2YUV_SHIFT + 1);
577  dstV[i] = (RV * r + GV * g + BV * b + (257 << RGB2YUV_SHIFT)) >> (RGB2YUV_SHIFT + 1);
578  }
579  assert(src1 == src2);
580 }
581 
582 static void rgb24ToY_c(uint8_t *dst, const uint8_t *src, int width,
583  uint32_t *unused)
584 {
585  int i;
586  for (i = 0; i < width; i++) {
587  int r = src[i * 3 + 0];
588  int g = src[i * 3 + 1];
589  int b = src[i * 3 + 2];
590 
591  dst[i] = ((RY * r + GY * g + BY * b + (33 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT);
592  }
593 }
594 
595 static void rgb24ToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1,
596  const uint8_t *src2, int width, uint32_t *unused)
597 {
598  int i;
599  assert(src1 == src2);
600  for (i = 0; i < width; i++) {
601  int r = src1[3 * i + 0];
602  int g = src1[3 * i + 1];
603  int b = src1[3 * i + 2];
604 
605  dstU[i] = (RU * r + GU * g + BU * b + (257 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT;
606  dstV[i] = (RV * r + GV * g + BV * b + (257 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT;
607  }
608 }
609 
610 static void rgb24ToUV_half_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1,
611  const uint8_t *src2, int width, uint32_t *unused)
612 {
613  int i;
614  assert(src1 == src2);
615  for (i = 0; i < width; i++) {
616  int r = src1[6 * i + 0] + src1[6 * i + 3];
617  int g = src1[6 * i + 1] + src1[6 * i + 4];
618  int b = src1[6 * i + 2] + src1[6 * i + 5];
619 
620  dstU[i] = (RU * r + GU * g + BU * b + (257 << RGB2YUV_SHIFT)) >> (RGB2YUV_SHIFT + 1);
621  dstV[i] = (RV * r + GV * g + BV * b + (257 << RGB2YUV_SHIFT)) >> (RGB2YUV_SHIFT + 1);
622  }
623 }
624 
625 static void planar_rgb_to_y(uint8_t *dst, const uint8_t *src[4], int width)
626 {
627  int i;
628  for (i = 0; i < width; i++) {
629  int g = src[0][i];
630  int b = src[1][i];
631  int r = src[2][i];
632 
633  dst[i] = ((RY * r + GY * g + BY * b + (33 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT);
634  }
635 }
636 
637 static void planar_rgb_to_a(uint8_t *dst, const uint8_t *src[4], int width)
638 {
639  int i;
640  for (i = 0; i < width; i++)
641  dst[i] = src[3][i];
642 }
643 
644 static void planar_rgb_to_uv(uint8_t *dstU, uint8_t *dstV, const uint8_t *src[4], int width)
645 {
646  int i;
647  for (i = 0; i < width; i++) {
648  int g = src[0][i];
649  int b = src[1][i];
650  int r = src[2][i];
651 
652  dstU[i] = (RU * r + GU * g + BU * b + (257 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT;
653  dstV[i] = (RV * r + GV * g + BV * b + (257 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT;
654  }
655 }
656 
657 #define rdpx(src) \
658  is_be ? AV_RB16(src) : AV_RL16(src)
659 static av_always_inline void planar_rgb16_to_y(uint8_t *_dst, const uint8_t *_src[4],
660  int width, int bpc, int is_be)
661 {
662  int i;
663  const uint16_t **src = (const uint16_t **)_src;
664  uint16_t *dst = (uint16_t *)_dst;
665  for (i = 0; i < width; i++) {
666  int g = rdpx(src[0] + i);
667  int b = rdpx(src[1] + i);
668  int r = rdpx(src[2] + i);
669 
670  dst[i] = ((RY * r + GY * g + BY * b + (33 << (RGB2YUV_SHIFT + bpc - 9))) >> RGB2YUV_SHIFT);
671  }
672 }
673 
674 static void planar_rgb9le_to_y(uint8_t *dst, const uint8_t *src[4], int w)
675 {
676  planar_rgb16_to_y(dst, src, w, 9, 0);
677 }
678 
679 static void planar_rgb9be_to_y(uint8_t *dst, const uint8_t *src[4], int w)
680 {
681  planar_rgb16_to_y(dst, src, w, 9, 1);
682 }
683 
684 static void planar_rgb10le_to_y(uint8_t *dst, const uint8_t *src[4], int w)
685 {
686  planar_rgb16_to_y(dst, src, w, 10, 0);
687 }
688 
689 static void planar_rgb10be_to_y(uint8_t *dst, const uint8_t *src[4], int w)
690 {
691  planar_rgb16_to_y(dst, src, w, 10, 1);
692 }
693 
694 static void planar_rgb16le_to_y(uint8_t *dst, const uint8_t *src[4], int w)
695 {
696  planar_rgb16_to_y(dst, src, w, 16, 0);
697 }
698 
699 static void planar_rgb16be_to_y(uint8_t *dst, const uint8_t *src[4], int w)
700 {
701  planar_rgb16_to_y(dst, src, w, 16, 1);
702 }
703 
705  const uint8_t *_src[4], int width,
706  int bpc, int is_be)
707 {
708  int i;
709  const uint16_t **src = (const uint16_t **)_src;
710  uint16_t *dstU = (uint16_t *)_dstU;
711  uint16_t *dstV = (uint16_t *)_dstV;
712  for (i = 0; i < width; i++) {
713  int g = rdpx(src[0] + i);
714  int b = rdpx(src[1] + i);
715  int r = rdpx(src[2] + i);
716 
717  dstU[i] = (RU * r + GU * g + BU * b + (257 << (RGB2YUV_SHIFT + bpc - 9))) >> RGB2YUV_SHIFT;
718  dstV[i] = (RV * r + GV * g + BV * b + (257 << (RGB2YUV_SHIFT + bpc - 9))) >> RGB2YUV_SHIFT;
719  }
720 }
721 #undef rdpx
722 
723 static void planar_rgb9le_to_uv(uint8_t *dstU, uint8_t *dstV,
724  const uint8_t *src[4], int w)
725 {
726  planar_rgb16_to_uv(dstU, dstV, src, w, 9, 0);
727 }
728 
729 static void planar_rgb9be_to_uv(uint8_t *dstU, uint8_t *dstV,
730  const uint8_t *src[4], int w)
731 {
732  planar_rgb16_to_uv(dstU, dstV, src, w, 9, 1);
733 }
734 
735 static void planar_rgb10le_to_uv(uint8_t *dstU, uint8_t *dstV,
736  const uint8_t *src[4], int w)
737 {
738  planar_rgb16_to_uv(dstU, dstV, src, w, 10, 0);
739 }
740 
741 static void planar_rgb10be_to_uv(uint8_t *dstU, uint8_t *dstV,
742  const uint8_t *src[4], int w)
743 {
744  planar_rgb16_to_uv(dstU, dstV, src, w, 10, 1);
745 }
746 
747 static void planar_rgb16le_to_uv(uint8_t *dstU, uint8_t *dstV,
748  const uint8_t *src[4], int w)
749 {
750  planar_rgb16_to_uv(dstU, dstV, src, w, 16, 0);
751 }
752 
753 static void planar_rgb16be_to_uv(uint8_t *dstU, uint8_t *dstV,
754  const uint8_t *src[4], int w)
755 {
756  planar_rgb16_to_uv(dstU, dstV, src, w, 16, 1);
757 }
758 
760 {
761  enum AVPixelFormat srcFormat = c->srcFormat;
762 
763  c->chrToYV12 = NULL;
764  switch (srcFormat) {
765  case AV_PIX_FMT_YUYV422:
766  c->chrToYV12 = yuy2ToUV_c;
767  break;
768  case AV_PIX_FMT_YVYU422:
769  c->chrToYV12 = yvy2ToUV_c;
770  break;
771  case AV_PIX_FMT_UYVY422:
772  c->chrToYV12 = uyvyToUV_c;
773  break;
774  case AV_PIX_FMT_NV12:
775  c->chrToYV12 = nv12ToUV_c;
776  break;
777  case AV_PIX_FMT_NV21:
778  c->chrToYV12 = nv21ToUV_c;
779  break;
780  case AV_PIX_FMT_RGB8:
781  case AV_PIX_FMT_BGR8:
782  case AV_PIX_FMT_PAL8:
785  c->chrToYV12 = palToUV_c;
786  break;
787  case AV_PIX_FMT_GBRP9LE:
789  break;
790  case AV_PIX_FMT_GBRP10LE:
792  break;
794  case AV_PIX_FMT_GBRP16LE:
796  break;
797  case AV_PIX_FMT_GBRP9BE:
799  break;
800  case AV_PIX_FMT_GBRP10BE:
802  break;
804  case AV_PIX_FMT_GBRP16BE:
806  break;
807  case AV_PIX_FMT_GBRAP:
808  case AV_PIX_FMT_GBRP:
810  break;
811 #if HAVE_BIGENDIAN
830  c->chrToYV12 = bswap16UV_c;
831  break;
832 #else
851  c->chrToYV12 = bswap16UV_c;
852  break;
853 #endif
854  case AV_PIX_FMT_P010LE:
855  c->chrToYV12 = p010LEToUV_c;
856  break;
857  case AV_PIX_FMT_P010BE:
858  c->chrToYV12 = p010BEToUV_c;
859  break;
860  }
861  if (c->chrSrcHSubSample) {
862  switch (srcFormat) {
863  case AV_PIX_FMT_RGB48BE:
864  c->chrToYV12 = rgb48BEToUV_half_c;
865  break;
866  case AV_PIX_FMT_RGB48LE:
867  c->chrToYV12 = rgb48LEToUV_half_c;
868  break;
869  case AV_PIX_FMT_BGR48BE:
870  c->chrToYV12 = bgr48BEToUV_half_c;
871  break;
872  case AV_PIX_FMT_BGR48LE:
873  c->chrToYV12 = bgr48LEToUV_half_c;
874  break;
875  case AV_PIX_FMT_RGB32:
876  c->chrToYV12 = bgr32ToUV_half_c;
877  break;
878  case AV_PIX_FMT_RGB32_1:
879  c->chrToYV12 = bgr321ToUV_half_c;
880  break;
881  case AV_PIX_FMT_BGR24:
883  break;
884  case AV_PIX_FMT_BGR565LE:
885  c->chrToYV12 = bgr16leToUV_half_c;
886  break;
887  case AV_PIX_FMT_BGR565BE:
888  c->chrToYV12 = bgr16beToUV_half_c;
889  break;
890  case AV_PIX_FMT_BGR555LE:
891  c->chrToYV12 = bgr15leToUV_half_c;
892  break;
893  case AV_PIX_FMT_BGR555BE:
894  c->chrToYV12 = bgr15beToUV_half_c;
895  break;
896  case AV_PIX_FMT_BGR444LE:
897  c->chrToYV12 = bgr12leToUV_half_c;
898  break;
899  case AV_PIX_FMT_BGR444BE:
900  c->chrToYV12 = bgr12beToUV_half_c;
901  break;
902  case AV_PIX_FMT_BGR32:
903  c->chrToYV12 = rgb32ToUV_half_c;
904  break;
905  case AV_PIX_FMT_BGR32_1:
906  c->chrToYV12 = rgb321ToUV_half_c;
907  break;
908  case AV_PIX_FMT_RGB24:
910  break;
911  case AV_PIX_FMT_RGB565LE:
912  c->chrToYV12 = rgb16leToUV_half_c;
913  break;
914  case AV_PIX_FMT_RGB565BE:
915  c->chrToYV12 = rgb16beToUV_half_c;
916  break;
917  case AV_PIX_FMT_RGB555LE:
918  c->chrToYV12 = rgb15leToUV_half_c;
919  break;
920  case AV_PIX_FMT_RGB555BE:
921  c->chrToYV12 = rgb15beToUV_half_c;
922  break;
923  case AV_PIX_FMT_RGB444LE:
924  c->chrToYV12 = rgb12leToUV_half_c;
925  break;
926  case AV_PIX_FMT_RGB444BE:
927  c->chrToYV12 = rgb12beToUV_half_c;
928  break;
929  }
930  } else {
931  switch (srcFormat) {
932  case AV_PIX_FMT_RGB48BE:
933  c->chrToYV12 = rgb48BEToUV_c;
934  break;
935  case AV_PIX_FMT_RGB48LE:
936  c->chrToYV12 = rgb48LEToUV_c;
937  break;
938  case AV_PIX_FMT_BGR48BE:
939  c->chrToYV12 = bgr48BEToUV_c;
940  break;
941  case AV_PIX_FMT_BGR48LE:
942  c->chrToYV12 = bgr48LEToUV_c;
943  break;
944  case AV_PIX_FMT_RGB32:
945  c->chrToYV12 = bgr32ToUV_c;
946  break;
947  case AV_PIX_FMT_RGB32_1:
948  c->chrToYV12 = bgr321ToUV_c;
949  break;
950  case AV_PIX_FMT_BGR24:
951  c->chrToYV12 = bgr24ToUV_c;
952  break;
953  case AV_PIX_FMT_BGR565LE:
954  c->chrToYV12 = bgr16leToUV_c;
955  break;
956  case AV_PIX_FMT_BGR565BE:
957  c->chrToYV12 = bgr16beToUV_c;
958  break;
959  case AV_PIX_FMT_BGR555LE:
960  c->chrToYV12 = bgr15leToUV_c;
961  break;
962  case AV_PIX_FMT_BGR555BE:
963  c->chrToYV12 = bgr15beToUV_c;
964  break;
965  case AV_PIX_FMT_BGR444LE:
966  c->chrToYV12 = bgr12leToUV_c;
967  break;
968  case AV_PIX_FMT_BGR444BE:
969  c->chrToYV12 = bgr12beToUV_c;
970  break;
971  case AV_PIX_FMT_BGR32:
972  c->chrToYV12 = rgb32ToUV_c;
973  break;
974  case AV_PIX_FMT_BGR32_1:
975  c->chrToYV12 = rgb321ToUV_c;
976  break;
977  case AV_PIX_FMT_RGB24:
978  c->chrToYV12 = rgb24ToUV_c;
979  break;
980  case AV_PIX_FMT_RGB565LE:
981  c->chrToYV12 = rgb16leToUV_c;
982  break;
983  case AV_PIX_FMT_RGB565BE:
984  c->chrToYV12 = rgb16beToUV_c;
985  break;
986  case AV_PIX_FMT_RGB555LE:
987  c->chrToYV12 = rgb15leToUV_c;
988  break;
989  case AV_PIX_FMT_RGB555BE:
990  c->chrToYV12 = rgb15beToUV_c;
991  break;
992  case AV_PIX_FMT_RGB444LE:
993  c->chrToYV12 = rgb12leToUV_c;
994  break;
995  case AV_PIX_FMT_RGB444BE:
996  c->chrToYV12 = rgb12beToUV_c;
997  break;
998  }
999  }
1000 
1001  c->lumToYV12 = NULL;
1002  c->alpToYV12 = NULL;
1003  switch (srcFormat) {
1004  case AV_PIX_FMT_GBRP9LE:
1006  break;
1007  case AV_PIX_FMT_GBRP10LE:
1009  break;
1010  case AV_PIX_FMT_GBRAP16LE:
1011  case AV_PIX_FMT_GBRP16LE:
1013  break;
1014  case AV_PIX_FMT_GBRP9BE:
1016  break;
1017  case AV_PIX_FMT_GBRP10BE:
1019  break;
1020  case AV_PIX_FMT_GBRAP16BE:
1021  case AV_PIX_FMT_GBRP16BE:
1023  break;
1024  case AV_PIX_FMT_GBRAP:
1026  case AV_PIX_FMT_GBRP:
1028  break;
1029 #if HAVE_BIGENDIAN
1030  case AV_PIX_FMT_YUV444P9LE:
1031  case AV_PIX_FMT_YUV422P9LE:
1032  case AV_PIX_FMT_YUV420P9LE:
1039  case AV_PIX_FMT_GRAY16LE:
1040  c->lumToYV12 = bswap16Y_c;
1041  break;
1051  c->lumToYV12 = bswap16Y_c;
1052  c->alpToYV12 = bswap16Y_c;
1053  break;
1054 #else
1055  case AV_PIX_FMT_YUV444P9BE:
1056  case AV_PIX_FMT_YUV422P9BE:
1057  case AV_PIX_FMT_YUV420P9BE:
1064  case AV_PIX_FMT_GRAY16BE:
1065  c->lumToYV12 = bswap16Y_c;
1066  break;
1076  c->lumToYV12 = bswap16Y_c;
1077  c->alpToYV12 = bswap16Y_c;
1078  break;
1079 #endif
1080  case AV_PIX_FMT_YA16LE:
1083  break;
1084  case AV_PIX_FMT_YA16BE:
1087  break;
1088  case AV_PIX_FMT_YUYV422:
1089  case AV_PIX_FMT_YVYU422:
1090  case AV_PIX_FMT_YA8:
1091  c->lumToYV12 = yuy2ToY_c;
1092  break;
1093  case AV_PIX_FMT_UYVY422:
1094  c->lumToYV12 = uyvyToY_c;
1095  break;
1096  case AV_PIX_FMT_BGR24:
1097  c->lumToYV12 = bgr24ToY_c;
1098  break;
1099  case AV_PIX_FMT_BGR565LE:
1100  c->lumToYV12 = bgr16leToY_c;
1101  break;
1102  case AV_PIX_FMT_BGR565BE:
1103  c->lumToYV12 = bgr16beToY_c;
1104  break;
1105  case AV_PIX_FMT_BGR555LE:
1106  c->lumToYV12 = bgr15leToY_c;
1107  break;
1108  case AV_PIX_FMT_BGR555BE:
1109  c->lumToYV12 = bgr15beToY_c;
1110  break;
1111  case AV_PIX_FMT_BGR444LE:
1112  c->lumToYV12 = bgr12leToY_c;
1113  break;
1114  case AV_PIX_FMT_BGR444BE:
1115  c->lumToYV12 = bgr12beToY_c;
1116  break;
1117  case AV_PIX_FMT_RGB24:
1118  c->lumToYV12 = rgb24ToY_c;
1119  break;
1120  case AV_PIX_FMT_RGB565LE:
1121  c->lumToYV12 = rgb16leToY_c;
1122  break;
1123  case AV_PIX_FMT_RGB565BE:
1124  c->lumToYV12 = rgb16beToY_c;
1125  break;
1126  case AV_PIX_FMT_RGB555LE:
1127  c->lumToYV12 = rgb15leToY_c;
1128  break;
1129  case AV_PIX_FMT_RGB555BE:
1130  c->lumToYV12 = rgb15beToY_c;
1131  break;
1132  case AV_PIX_FMT_RGB444LE:
1133  c->lumToYV12 = rgb12leToY_c;
1134  break;
1135  case AV_PIX_FMT_RGB444BE:
1136  c->lumToYV12 = rgb12beToY_c;
1137  break;
1138  case AV_PIX_FMT_RGB8:
1139  case AV_PIX_FMT_BGR8:
1140  case AV_PIX_FMT_PAL8:
1141  case AV_PIX_FMT_BGR4_BYTE:
1142  case AV_PIX_FMT_RGB4_BYTE:
1143  c->lumToYV12 = palToY_c;
1144  break;
1145  case AV_PIX_FMT_MONOBLACK:
1146  c->lumToYV12 = monoblack2Y_c;
1147  break;
1148  case AV_PIX_FMT_MONOWHITE:
1149  c->lumToYV12 = monowhite2Y_c;
1150  break;
1151  case AV_PIX_FMT_RGB32:
1152  c->lumToYV12 = bgr32ToY_c;
1153  break;
1154  case AV_PIX_FMT_RGB32_1:
1155  c->lumToYV12 = bgr321ToY_c;
1156  break;
1157  case AV_PIX_FMT_BGR32:
1158  c->lumToYV12 = rgb32ToY_c;
1159  break;
1160  case AV_PIX_FMT_BGR32_1:
1161  c->lumToYV12 = rgb321ToY_c;
1162  break;
1163  case AV_PIX_FMT_RGB48BE:
1164  c->lumToYV12 = rgb48BEToY_c;
1165  break;
1166  case AV_PIX_FMT_RGB48LE:
1167  c->lumToYV12 = rgb48LEToY_c;
1168  break;
1169  case AV_PIX_FMT_BGR48BE:
1170  c->lumToYV12 = bgr48BEToY_c;
1171  break;
1172  case AV_PIX_FMT_BGR48LE:
1173  c->lumToYV12 = bgr48LEToY_c;
1174  break;
1175  case AV_PIX_FMT_P010LE:
1176  c->lumToYV12 = p010LEToY_c;
1177  break;
1178  case AV_PIX_FMT_P010BE:
1179  c->lumToYV12 = p010BEToY_c;
1180  break;
1181  }
1182  if (c->alpPixBuf) {
1183  switch (srcFormat) {
1184  case AV_PIX_FMT_BGRA:
1185  case AV_PIX_FMT_RGBA:
1186  c->alpToYV12 = rgbaToA_c;
1187  break;
1188  case AV_PIX_FMT_ABGR:
1189  case AV_PIX_FMT_ARGB:
1190  c->alpToYV12 = abgrToA_c;
1191  break;
1192  case AV_PIX_FMT_YA8:
1193  c->alpToYV12 = uyvyToY_c;
1194  break;
1195  }
1196  }
1197 }
packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
Definition: pixfmt.h:78
int16_t ** alpPixBuf
Ring buffer for scaled horizontal alpha plane lines to be fed to the vertical scaler.
planar YUV 4:2:2, 18bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
Definition: pixfmt.h:159
static void planar_rgb_to_uv(uint8_t *dstU, uint8_t *dstV, const uint8_t *src[4], int width)
Definition: input.c:644
static void planar_rgb9le_to_y(uint8_t *dst, const uint8_t *src[4], int w)
Definition: input.c:674
static void monowhite2Y_c(uint8_t *dst, const uint8_t *src, int width, uint32_t *unused)
Definition: input.c:345
static void read_ya16be_alpha_c(uint8_t *dst, const uint8_t *src, int width, uint32_t *unused)
Definition: input.c:446
static void read_ya16le_gray_c(uint8_t *dst, const uint8_t *src, int width, uint32_t *unused)
Definition: input.c:422
static void planar_rgb16le_to_y(uint8_t *dst, const uint8_t *src[4], int w)
Definition: input.c:694
static void bswap16UV_c(uint8_t *_dstU, uint8_t *_dstV, const uint8_t *_src1, const uint8_t *_src2, int width, uint32_t *unused)
Definition: input.c:409
RGB2YUV_SHIFT RGB2YUV_SHIFT bgr15le
Definition: input.c:293
planar YUV 4:2:0, 15bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
Definition: pixfmt.h:152
8 bits gray, 8 bits alpha
Definition: pixfmt.h:143
static void yuy2ToY_c(uint8_t *dst, const uint8_t *src, int width, uint32_t *unused)
Definition: input.c:369
#define b_r
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:61
planar YUV 4:4:4, 27bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
Definition: pixfmt.h:155
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:162
packed RGB 5:5:5, 16bpp, (msb)1A 5R 5G 5B(lsb), little-endian, most significant bit to 0 ...
Definition: pixfmt.h:112
#define GY
Definition: input.c:42
#define av_bswap16
Definition: bswap.h:31
planar YUV 4:4:4 40bpp, (1 Cr & Cb sample per 1x1 Y & A samples, little-endian)
Definition: pixfmt.h:182
external API header
#define AV_RL16
Definition: intreadwrite.h:42
packed BGR 5:6:5, 16bpp, (msb) 5B 6G 5R(lsb), little-endian
Definition: pixfmt.h:115
planar YUV 4:2:0, 13.5bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian
Definition: pixfmt.h:149
static void monoblack2Y_c(uint8_t *dst, const uint8_t *src, int width, uint32_t *unused)
Definition: input.c:357
packed RGB 4:4:4, 16bpp, (msb)4A 4R 4G 4B(lsb), big-endian, most significant bits to 0 ...
Definition: pixfmt.h:140
planar YUV 4:2:0, 24bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
Definition: pixfmt.h:128
packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), little-endian
Definition: pixfmt.h:110
packed RGB 1:2:1, 8bpp, (msb)1B 2G 1R(lsb)
Definition: pixfmt.h:82
#define BY
Definition: input.c:39
RGB2YUV_SHIFT RGB2YUV_SHIFT RGB2YUV_SHIFT RGB2YUV_SHIFT RGB2YUV_SHIFT RGB2YUV_SHIFT RGB2YUV_SHIFT rgb12be
Definition: input.c:303
planar YUV 4:2:0 22.5bpp, (1 Cr & Cb sample per 2x2 Y & A samples), little-endian ...
Definition: pixfmt.h:172
planar GBRA 4:4:4:4 64bpp, big-endian
Definition: pixfmt.h:209
planar YUV 4:2:0 40bpp, (1 Cr & Cb sample per 2x2 Y & A samples, big-endian)
Definition: pixfmt.h:183
static void uyvyToY_c(uint8_t *dst, const uint8_t *src, int width, uint32_t *unused)
Definition: input.c:456
uint8_t
#define av_cold
Definition: attributes.h:66
#define GU
Definition: input.c:44
static void planar_rgb16le_to_uv(uint8_t *dstU, uint8_t *dstV, const uint8_t *src[4], int w)
Definition: input.c:747
8 bits with AV_PIX_FMT_RGB32 palette
Definition: pixfmt.h:70
packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as lit...
Definition: pixfmt.h:107
RGB2YUV_SHIFT RGB2YUV_SHIFT RGB2YUV_SHIFT RGB2YUV_SHIFT RGB2YUV_SHIFT RGB2YUV_SHIFT RGB2YUV_SHIFT static RGB2YUV_SHIFT void abgrToA_c(uint8_t *dst, const uint8_t *src, int width, uint32_t *unused)
Definition: input.c:305
static void planar_rgb9le_to_uv(uint8_t *dstU, uint8_t *dstV, const uint8_t *src[4], int w)
Definition: input.c:723
RGB2YUV_SHIFT RGB2YUV_SHIFT RGB2YUV_SHIFT rgb16le
Definition: input.c:295
#define b
Definition: input.c:52
void(* readAlpPlanar)(uint8_t *dst, const uint8_t *src[4], int width)
bgr321
Definition: input.c:289
void(* chrToYV12)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, int width, uint32_t *pal)
Unscaled conversion of chroma planes to YV12 for horizontal scaler.
packed RGB 4:4:4, 16bpp, (msb)4A 4R 4G 4B(lsb), little-endian, most significant bits to 0 ...
Definition: pixfmt.h:139
static void planar_rgb9be_to_uv(uint8_t *dstU, uint8_t *dstV, const uint8_t *src[4], int w)
Definition: input.c:729
packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), big-endian
Definition: pixfmt.h:109
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
Definition: pixfmt.h:91
planar YUV 4:2:0 40bpp, (1 Cr & Cb sample per 2x2 Y & A samples, little-endian)
Definition: pixfmt.h:184
planar GBR 4:4:4 48bpp, big-endian
Definition: pixfmt.h:167
static void planar_rgb_to_y(uint8_t *dst, const uint8_t *src[4], int width)
Definition: input.c:625
static void read_ya16be_gray_c(uint8_t *dst, const uint8_t *src, int width, uint32_t *unused)
Definition: input.c:438
#define input_pixel(pos)
Definition: input.c:537
static void p010LEToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, int width, uint32_t *unused)
Definition: input.c:515
planar YUV 4:4:4 64bpp, (1 Cr & Cb sample per 1x1 Y & A samples, big-endian)
Definition: pixfmt.h:187
static void nv12ToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, int width, uint32_t *unused)
Definition: input.c:485
external api for the swscale stuff
av_cold void ff_sws_init_input_funcs(SwsContext *c)
Definition: input.c:759
int chrSrcHSubSample
Binary logarithm of horizontal subsampling factor between luma/alpha and chroma planes in source imag...
#define r
Definition: input.c:51
static void planar_rgb9be_to_y(uint8_t *dst, const uint8_t *src[4], int w)
Definition: input.c:679
planar YUV 4:2:0, 13.5bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
Definition: pixfmt.h:150
static void rgb24ToY_c(uint8_t *dst, const uint8_t *src, int width, uint32_t *unused)
Definition: input.c:582
#define src
Definition: vp8dsp.c:254
planar GBR 4:4:4 27bpp, big-endian
Definition: pixfmt.h:163
planar YUV 4:4:4, 30bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
Definition: pixfmt.h:158
static void read_ya16le_alpha_c(uint8_t *dst, const uint8_t *src, int width, uint32_t *unused)
Definition: input.c:430
#define AV_PIX_FMT_BGR32_1
Definition: pixfmt.h:245
16 bits gray, 16 bits alpha (big-endian)
Definition: pixfmt.h:205
#define S(s, c, i)
#define r_b
#define AV_RB16
Definition: intreadwrite.h:53
planar YUV 4:4:4, 48bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
Definition: pixfmt.h:133
static void bswap16Y_c(uint8_t *_dst, const uint8_t *_src, int width, uint32_t *unused)
Definition: input.c:399
static av_always_inline void rgb16_32ToUV_c_template(uint8_t *dstU, uint8_t *dstV, const uint8_t *src, int width, enum AVPixelFormat origin, int shr, int shg, int shb, int shp, int maskr, int maskg, int maskb, int rsh, int gsh, int bsh, int S)
Definition: input.c:189
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition: pixfmt.h:92
g
Definition: yuv2rgb.c:546
planar YUV 4:4:4 36bpp, (1 Cr & Cb sample per 1x1 Y & A samples), big-endian
Definition: pixfmt.h:175
planar YUV 4:2:2, 20bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
Definition: pixfmt.h:154
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
Definition: pixfmt.h:86
planar YUV 4:2:2, 32bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
Definition: pixfmt.h:131
like NV12, with 10bpp per component, data in the high bits, zeros in the low bits, big-endian
Definition: pixfmt.h:231
#define BU
Definition: input.c:41
planar YUV 4:4:4 36bpp, (1 Cr & Cb sample per 1x1 Y & A samples), little-endian
Definition: pixfmt.h:176
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
Definition: pixfmt.h:89
packed RGB 16:16:16, 48bpp, 16B, 16G, 16R, the 2-byte value for each R/G/B component is stored as lit...
Definition: pixfmt.h:148
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:90
planar YUV 4:2:0 25bpp, (1 Cr & Cb sample per 2x2 Y & A samples, big-endian)
Definition: pixfmt.h:177
as above, but U and V bytes are swapped
Definition: pixfmt.h:87
#define rgb16_32_wrapper(fmt, name, shr, shg, shb, shp, maskr, maskg, maskb, rsh, gsh, bsh, S)
Definition: input.c:259
void(* lumToYV12)(uint8_t *dst, const uint8_t *src, int width, uint32_t *pal)
Unscaled conversion of luma plane to YV12 for horizontal scaler.
static void planar_rgb10be_to_uv(uint8_t *dstU, uint8_t *dstV, const uint8_t *src[4], int w)
Definition: input.c:741
RGB2YUV_SHIFT RGB2YUV_SHIFT RGB2YUV_SHIFT RGB2YUV_SHIFT rgb12le
Definition: input.c:297
packed RGB 1:2:1, 8bpp, (msb)1R 2G 1B(lsb)
Definition: pixfmt.h:85
static void planar_rgb10le_to_uv(uint8_t *dstU, uint8_t *dstV, const uint8_t *src[4], int w)
Definition: input.c:735
static av_always_inline void rgb48ToUV_c_template(uint16_t *dstU, uint16_t *dstV, const uint16_t *src1, const uint16_t *src2, int width, enum AVPixelFormat origin)
Definition: input.c:68
planar YUV 4:4:4 40bpp, (1 Cr & Cb sample per 1x1 Y & A samples, big-endian)
Definition: pixfmt.h:181
packed YUV 4:2:2, 16bpp, Y0 Cr Y1 Cb
Definition: pixfmt.h:201
static void uyvyToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, int width, uint32_t *unused)
Definition: input.c:464
planar YUV 4:2:2 27bpp, (1 Cr & Cb sample per 2x1 Y & A samples), big-endian
Definition: pixfmt.h:173
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:62
planar YUV 4:2:0, 15bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian
Definition: pixfmt.h:151
static void bgr24ToUV_half_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, int width, uint32_t *unused)
Definition: input.c:567
#define rgb48funcs(pattern, BE_LE, origin)
Definition: input.c:113
like NV12, with 10bpp per component, data in the high bits, zeros in the low bits, little-endian
Definition: pixfmt.h:230
planar YUV 4:2:2, 18bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
Definition: pixfmt.h:160
packed RGB 16:16:16, 48bpp, 16B, 16G, 16R, the 2-byte value for each R/G/B component is stored as big...
Definition: pixfmt.h:147
packed BGR 5:6:5, 16bpp, (msb) 5B 6G 5R(lsb), big-endian
Definition: pixfmt.h:114
static void rgb24ToUV_half_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, int width, uint32_t *unused)
Definition: input.c:610
static void yvy2ToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, int width, uint32_t *unused)
Definition: input.c:388
#define AV_PIX_FMT_BGR32
Definition: pixfmt.h:244
static void planar_rgb10be_to_y(uint8_t *dst, const uint8_t *src[4], int w)
Definition: input.c:689
NULL
Definition: eval.c:55
packed RGB 3:3:2, 8bpp, (msb)2B 3G 3R(lsb)
Definition: pixfmt.h:80
static int width
Definition: utils.c:156
#define src1
Definition: h264pred.c:139
planar YUV 4:2:0, 24bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian
Definition: pixfmt.h:129
RGB2YUV_SHIFT rgb321
Definition: input.c:291
static void planar_rgb10le_to_y(uint8_t *dst, const uint8_t *src[4], int w)
Definition: input.c:684
planar GBR 4:4:4 30bpp, big-endian
Definition: pixfmt.h:165
static void bgr24ToY_c(uint8_t *dst, const uint8_t *src, int width, uint32_t *unused)
Definition: input.c:539
planar YUV 4:2:2 48bpp, (1 Cr & Cb sample per 2x1 Y & A samples, big-endian)
Definition: pixfmt.h:185
#define AV_PIX_FMT_RGB32
Definition: pixfmt.h:242
packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
Definition: pixfmt.h:60
RGB2YUV_SHIFT RGB2YUV_SHIFT RGB2YUV_SHIFT RGB2YUV_SHIFT RGB2YUV_SHIFT bgr15be
Definition: input.c:299
planar YUV 4:2:2 48bpp, (1 Cr & Cb sample per 2x1 Y & A samples, little-endian)
Definition: pixfmt.h:186
planar YUV 4:4:4 64bpp, (1 Cr & Cb sample per 1x1 Y & A samples, little-endian)
Definition: pixfmt.h:188
Y , 16bpp, big-endian.
Definition: pixfmt.h:94
byte swapping routines
planar YUV 4:2:0 22.5bpp, (1 Cr & Cb sample per 2x2 Y & A samples), big-endian
Definition: pixfmt.h:171
packed BGR 5:5:5, 16bpp, (msb)1A 5B 5G 5R(lsb), little-endian, most significant bit to 1 ...
Definition: pixfmt.h:117
#define u(width,...)
void(* readChrPlanar)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src[4], int width)
static av_always_inline void rgb16_32ToUV_half_c_template(uint8_t *dstU, uint8_t *dstV, const uint8_t *src, int width, enum AVPixelFormat origin, int shr, int shg, int shb, int shp, int maskr, int maskg, int maskb, int rsh, int gsh, int bsh, int S)
Definition: input.c:216
static void planar_rgb_to_a(uint8_t *dst, const uint8_t *src[4], int width)
Definition: input.c:637
planar YUV 4:2:2 30bpp, (1 Cr & Cb sample per 2x1 Y & A samples, little-endian)
Definition: pixfmt.h:180
packed RGB 5:5:5, 16bpp, (msb)1A 5R 5G 5B(lsb), big-endian, most significant bit to 0 ...
Definition: pixfmt.h:111
#define RU
Definition: input.c:47
packed BGR 4:4:4, 16bpp, (msb)4A 4B 4G 4R(lsb), big-endian, most significant bits to 1 ...
Definition: pixfmt.h:142
planar YUV 4:4:4, 27bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
Definition: pixfmt.h:156
planar YUV 4:4:4, 48bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
Definition: pixfmt.h:132
static av_always_inline void rgb48ToUV_half_c_template(uint16_t *dstU, uint16_t *dstV, const uint16_t *src1, const uint16_t *src2, int width, enum AVPixelFormat origin)
Definition: input.c:87
Y , 1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb...
Definition: pixfmt.h:69
#define GV
Definition: input.c:43
Y , 1bpp, 0 is white, 1 is black, in each byte pixels are ordered from the msb to the lsb...
Definition: pixfmt.h:68
void(* readLumPlanar)(uint8_t *dst, const uint8_t *src[4], int width)
Functions to read planar input, such as planar RGB, and convert internally to Y/UV/A.
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:208
planar GBR 4:4:4 27bpp, little-endian
Definition: pixfmt.h:164
packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as big...
Definition: pixfmt.h:106
static av_always_inline void rgb48ToY_c_template(uint16_t *dst, const uint16_t *src, int width, enum AVPixelFormat origin)
Definition: input.c:54
#define RGB2YUV_SHIFT
Definition: input.c:38
#define rnd()
Definition: checkasm.h:65
static void rgbaToA_c(uint8_t *dst, const uint8_t *src, int width, uint32_t *unused)
Definition: input.c:313
enum AVPixelFormat srcFormat
Source pixel format.
static void rgb24ToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, int width, uint32_t *unused)
Definition: input.c:595
planar YUV 4:2:2, 32bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
Definition: pixfmt.h:130
packed RGB 3:3:2, 8bpp, (msb)2R 3G 3B(lsb)
Definition: pixfmt.h:83
#define RY
Definition: input.c:45
planar YUV 4:2:0 25bpp, (1 Cr & Cb sample per 2x2 Y & A samples, little-endian)
Definition: pixfmt.h:178
RGB2YUV_SHIFT RGB2YUV_SHIFT RGB2YUV_SHIFT RGB2YUV_SHIFT RGB2YUV_SHIFT RGB2YUV_SHIFT rgb16be
Definition: input.c:301
static void p010BEToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, int width, uint32_t *unused)
Definition: input.c:526
static void p010LEToY_c(uint8_t *dst, const uint8_t *src, int width, uint32_t *unused)
Definition: input.c:499
static void nv21ToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, int width, uint32_t *unused)
Definition: input.c:492
#define RV
Definition: input.c:46
#define rdpx(src)
Definition: input.c:657
#define AV_PIX_FMT_RGB32_1
Definition: pixfmt.h:243
Y , 16bpp, little-endian.
Definition: pixfmt.h:95
16 bits gray, 16 bits alpha (little-endian)
Definition: pixfmt.h:206
static void p010BEToY_c(uint8_t *dst, const uint8_t *src, int width, uint32_t *unused)
Definition: input.c:507
planar YUV 4:2:2 30bpp, (1 Cr & Cb sample per 2x1 Y & A samples, big-endian)
Definition: pixfmt.h:179
packed BGR 5:5:5, 16bpp, (msb)1A 5B 5G 5R(lsb), big-endian, most significant bit to 1 ...
Definition: pixfmt.h:116
#define AV_WN16(p, v)
Definition: intreadwrite.h:345
#define av_always_inline
Definition: attributes.h:40
static void planar_rgb16be_to_y(uint8_t *dst, const uint8_t *src[4], int w)
Definition: input.c:699
planar GBR 4:4:4 48bpp, little-endian
Definition: pixfmt.h:168
packed BGR 4:4:4, 16bpp, (msb)4A 4B 4G 4R(lsb), little-endian, most significant bits to 1 ...
Definition: pixfmt.h:141
static void bgr24ToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, int width, uint32_t *unused)
Definition: input.c:552
planar YUV 4:2:2 27bpp, (1 Cr & Cb sample per 2x1 Y & A samples), little-endian
Definition: pixfmt.h:174
static av_always_inline void planar_rgb16_to_uv(uint8_t *_dstU, uint8_t *_dstV, const uint8_t *_src[4], int width, int bpc, int is_be)
Definition: input.c:704
static av_always_inline void nvXXtoUV_c(uint8_t *dst1, uint8_t *dst2, const uint8_t *src, int width)
Definition: input.c:475
static void yuy2ToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, int width, uint32_t *unused)
Definition: input.c:377
void(* alpToYV12)(uint8_t *dst, const uint8_t *src, int width, uint32_t *pal)
Unscaled conversion of alpha plane to YV12 for horizontal scaler.
planar GBRA 4:4:4:4 64bpp, little-endian
Definition: pixfmt.h:210
#define BV
Definition: input.c:40
static void planar_rgb16be_to_uv(uint8_t *dstU, uint8_t *dstV, const uint8_t *src[4], int w)
Definition: input.c:753
AVPixelFormat
Pixel format.
Definition: pixfmt.h:57
static void palToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, int width, uint32_t *pal)
Definition: input.c:331
planar YUV 4:4:4, 30bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
Definition: pixfmt.h:157
static av_always_inline void planar_rgb16_to_y(uint8_t *_dst, const uint8_t *_src[4], int width, int bpc, int is_be)
Definition: input.c:659
planar GBR 4:4:4 30bpp, little-endian
Definition: pixfmt.h:166
static void palToY_c(uint8_t *dst, const uint8_t *src, int width, uint32_t *pal)
Definition: input.c:321
planar YUV 4:2:2, 20bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
Definition: pixfmt.h:153