FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
yuv2rgb.c
Go to the documentation of this file.
1 /*
2  * software YUV to RGB converter
3  *
4  * Copyright (C) 2009 Konstantin Shishkov
5  *
6  * 1,4,8bpp support and context / deglobalize stuff
7  * by Michael Niedermayer (michaelni@gmx.at)
8  *
9  * This file is part of FFmpeg.
10  *
11  * FFmpeg is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * FFmpeg is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public
22  * License along with FFmpeg; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24  */
25 
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <inttypes.h>
29 
30 #include "libavutil/cpu.h"
31 #include "libavutil/bswap.h"
32 #include "config.h"
33 #include "rgb2rgb.h"
34 #include "swscale.h"
35 #include "swscale_internal.h"
36 #include "libavutil/pixdesc.h"
37 
38 /* Color space conversion coefficients for YCbCr -> RGB mapping.
39  *
40  * Entries are {crv, cbu, cgu, cgv}
41  *
42  * crv = (255 / 224) * 65536 * (1 - cr) / 0.5
43  * cbu = (255 / 224) * 65536 * (1 - cb) / 0.5
44  * cgu = (255 / 224) * 65536 * (cb / cg) * (1 - cb) / 0.5
45  * cgv = (255 / 224) * 65536 * (cr / cg) * (1 - cr) / 0.5
46  *
47  * where Y = cr * R + cg * G + cb * B and cr + cg + cb = 1.
48  */
49 const int32_t ff_yuv2rgb_coeffs[11][4] = {
50  { 117489, 138438, 13975, 34925 }, /* no sequence_display_extension */
51  { 117489, 138438, 13975, 34925 }, /* ITU-R Rec. 709 (1990) */
52  { 104597, 132201, 25675, 53279 }, /* unspecified */
53  { 104597, 132201, 25675, 53279 }, /* reserved */
54  { 104448, 132798, 24759, 53109 }, /* FCC */
55  { 104597, 132201, 25675, 53279 }, /* ITU-R Rec. 624-4 System B, G */
56  { 104597, 132201, 25675, 53279 }, /* SMPTE 170M */
57  { 117579, 136230, 16907, 35559 }, /* SMPTE 240M (1987) */
58  { 0 }, /* YCgCo */
59  { 110013, 140363, 12277, 42626 }, /* Bt-2020-NCL */
60  { 110013, 140363, 12277, 42626 }, /* Bt-2020-CL */
61 };
62 
63 const int *sws_getCoefficients(int colorspace)
64 {
65  if (colorspace > 10 || colorspace < 0 || colorspace == 8)
66  colorspace = SWS_CS_DEFAULT;
67  return ff_yuv2rgb_coeffs[colorspace];
68 }
69 
70 #define LOADCHROMA(i) \
71  U = pu[i]; \
72  V = pv[i]; \
73  r = (void *)c->table_rV[V+YUVRGB_TABLE_HEADROOM]; \
74  g = (void *)(c->table_gU[U+YUVRGB_TABLE_HEADROOM] + c->table_gV[V+YUVRGB_TABLE_HEADROOM]); \
75  b = (void *)c->table_bU[U+YUVRGB_TABLE_HEADROOM];
76 
77 #define PUTRGB(dst, src, i) \
78  Y = src[2 * i]; \
79  dst[2 * i] = r[Y] + g[Y] + b[Y]; \
80  Y = src[2 * i + 1]; \
81  dst[2 * i + 1] = r[Y] + g[Y] + b[Y];
82 
83 #define PUTRGB24(dst, src, i) \
84  Y = src[2 * i]; \
85  dst[6 * i + 0] = r[Y]; \
86  dst[6 * i + 1] = g[Y]; \
87  dst[6 * i + 2] = b[Y]; \
88  Y = src[2 * i + 1]; \
89  dst[6 * i + 3] = r[Y]; \
90  dst[6 * i + 4] = g[Y]; \
91  dst[6 * i + 5] = b[Y];
92 
93 #define PUTBGR24(dst, src, i) \
94  Y = src[2 * i]; \
95  dst[6 * i + 0] = b[Y]; \
96  dst[6 * i + 1] = g[Y]; \
97  dst[6 * i + 2] = r[Y]; \
98  Y = src[2 * i + 1]; \
99  dst[6 * i + 3] = b[Y]; \
100  dst[6 * i + 4] = g[Y]; \
101  dst[6 * i + 5] = r[Y];
102 
103 #define PUTRGBA(dst, ysrc, asrc, i, s) \
104  Y = ysrc[2 * i]; \
105  dst[2 * i] = r[Y] + g[Y] + b[Y] + (asrc[2 * i] << s); \
106  Y = ysrc[2 * i + 1]; \
107  dst[2 * i + 1] = r[Y] + g[Y] + b[Y] + (asrc[2 * i + 1] << s);
108 
109 #define PUTRGB48(dst, src, i) \
110  Y = src[ 2 * i]; \
111  dst[12 * i + 0] = dst[12 * i + 1] = r[Y]; \
112  dst[12 * i + 2] = dst[12 * i + 3] = g[Y]; \
113  dst[12 * i + 4] = dst[12 * i + 5] = b[Y]; \
114  Y = src[ 2 * i + 1]; \
115  dst[12 * i + 6] = dst[12 * i + 7] = r[Y]; \
116  dst[12 * i + 8] = dst[12 * i + 9] = g[Y]; \
117  dst[12 * i + 10] = dst[12 * i + 11] = b[Y];
118 
119 #define PUTBGR48(dst, src, i) \
120  Y = src[2 * i]; \
121  dst[12 * i + 0] = dst[12 * i + 1] = b[Y]; \
122  dst[12 * i + 2] = dst[12 * i + 3] = g[Y]; \
123  dst[12 * i + 4] = dst[12 * i + 5] = r[Y]; \
124  Y = src[2 * i + 1]; \
125  dst[12 * i + 6] = dst[12 * i + 7] = b[Y]; \
126  dst[12 * i + 8] = dst[12 * i + 9] = g[Y]; \
127  dst[12 * i + 10] = dst[12 * i + 11] = r[Y];
128 
129 #define YUV2RGBFUNC(func_name, dst_type, alpha) \
130  static int func_name(SwsContext *c, const uint8_t *src[], \
131  int srcStride[], int srcSliceY, int srcSliceH, \
132  uint8_t *dst[], int dstStride[]) \
133  { \
134  int y; \
135  \
136  if (!alpha && c->srcFormat == AV_PIX_FMT_YUV422P) { \
137  srcStride[1] *= 2; \
138  srcStride[2] *= 2; \
139  } \
140  for (y = 0; y < srcSliceH; y += 2) { \
141  dst_type *dst_1 = \
142  (dst_type *)(dst[0] + (y + srcSliceY) * dstStride[0]); \
143  dst_type *dst_2 = \
144  (dst_type *)(dst[0] + (y + srcSliceY + 1) * dstStride[0]); \
145  dst_type av_unused *r, *g, *b; \
146  const uint8_t *py_1 = src[0] + y * srcStride[0]; \
147  const uint8_t *py_2 = py_1 + srcStride[0]; \
148  const uint8_t *pu = src[1] + (y >> 1) * srcStride[1]; \
149  const uint8_t *pv = src[2] + (y >> 1) * srcStride[2]; \
150  const uint8_t av_unused *pa_1, *pa_2; \
151  unsigned int h_size = c->dstW >> 3; \
152  if (alpha) { \
153  pa_1 = src[3] + y * srcStride[3]; \
154  pa_2 = pa_1 + srcStride[3]; \
155  } \
156  while (h_size--) { \
157  int av_unused U, V, Y; \
158 
159 #define ENDYUV2RGBLINE(dst_delta, ss) \
160  pu += 4 >> ss; \
161  pv += 4 >> ss; \
162  py_1 += 8 >> ss; \
163  py_2 += 8 >> ss; \
164  dst_1 += dst_delta >> ss; \
165  dst_2 += dst_delta >> ss; \
166  } \
167  if (c->dstW & (4 >> ss)) { \
168  int av_unused Y, U, V; \
169 
170 #define ENDYUV2RGBFUNC() \
171  } \
172  } \
173  return srcSliceH; \
174  }
175 
176 #define CLOSEYUV2RGBFUNC(dst_delta) \
177  ENDYUV2RGBLINE(dst_delta, 0) \
178  ENDYUV2RGBFUNC()
179 
180 YUV2RGBFUNC(yuv2rgb_c_48, uint8_t, 0)
181  LOADCHROMA(0);
182  PUTRGB48(dst_1, py_1, 0);
183  PUTRGB48(dst_2, py_2, 0);
184 
185  LOADCHROMA(1);
186  PUTRGB48(dst_2, py_2, 1);
187  PUTRGB48(dst_1, py_1, 1);
188 
189  LOADCHROMA(2);
190  PUTRGB48(dst_1, py_1, 2);
191  PUTRGB48(dst_2, py_2, 2);
192 
193  LOADCHROMA(3);
194  PUTRGB48(dst_2, py_2, 3);
195  PUTRGB48(dst_1, py_1, 3);
196 ENDYUV2RGBLINE(48, 0)
197  LOADCHROMA(0);
198  PUTRGB48(dst_1, py_1, 0);
199  PUTRGB48(dst_2, py_2, 0);
200 
201  LOADCHROMA(1);
202  PUTRGB48(dst_2, py_2, 1);
203  PUTRGB48(dst_1, py_1, 1);
204 ENDYUV2RGBLINE(48, 1)
205  LOADCHROMA(0);
206  PUTRGB48(dst_1, py_1, 0);
207  PUTRGB48(dst_2, py_2, 0);
209 
210 YUV2RGBFUNC(yuv2rgb_c_bgr48, uint8_t, 0)
211  LOADCHROMA(0);
212  PUTBGR48(dst_1, py_1, 0);
213  PUTBGR48(dst_2, py_2, 0);
214 
215  LOADCHROMA(1);
216  PUTBGR48(dst_2, py_2, 1);
217  PUTBGR48(dst_1, py_1, 1);
218 
219  LOADCHROMA(2);
220  PUTBGR48(dst_1, py_1, 2);
221  PUTBGR48(dst_2, py_2, 2);
222 
223  LOADCHROMA(3);
224  PUTBGR48(dst_2, py_2, 3);
225  PUTBGR48(dst_1, py_1, 3);
226 ENDYUV2RGBLINE(48, 0)
227  LOADCHROMA(0);
228  PUTBGR48(dst_1, py_1, 0);
229  PUTBGR48(dst_2, py_2, 0);
230 
231  LOADCHROMA(1);
232  PUTBGR48(dst_2, py_2, 1);
233  PUTBGR48(dst_1, py_1, 1);
234 ENDYUV2RGBLINE(48, 1)
235  LOADCHROMA(0);
236  PUTBGR48(dst_1, py_1, 0);
237  PUTBGR48(dst_2, py_2, 0);
239 
240 YUV2RGBFUNC(yuv2rgb_c_32, uint32_t, 0)
241  LOADCHROMA(0);
242  PUTRGB(dst_1, py_1, 0);
243  PUTRGB(dst_2, py_2, 0);
244 
245  LOADCHROMA(1);
246  PUTRGB(dst_2, py_2, 1);
247  PUTRGB(dst_1, py_1, 1);
248 
249  LOADCHROMA(2);
250  PUTRGB(dst_1, py_1, 2);
251  PUTRGB(dst_2, py_2, 2);
252 
253  LOADCHROMA(3);
254  PUTRGB(dst_2, py_2, 3);
255  PUTRGB(dst_1, py_1, 3);
256 ENDYUV2RGBLINE(8, 0)
257  LOADCHROMA(0);
258  PUTRGB(dst_1, py_1, 0);
259  PUTRGB(dst_2, py_2, 0);
260 
261  LOADCHROMA(1);
262  PUTRGB(dst_2, py_2, 1);
263  PUTRGB(dst_1, py_1, 1);
264 ENDYUV2RGBLINE(8, 1)
265  LOADCHROMA(0);
266  PUTRGB(dst_1, py_1, 0);
267  PUTRGB(dst_2, py_2, 0);
269 
270 YUV2RGBFUNC(yuva2rgba_c, uint32_t, 1)
271  LOADCHROMA(0);
272  PUTRGBA(dst_1, py_1, pa_1, 0, 24);
273  PUTRGBA(dst_2, py_2, pa_2, 0, 24);
274 
275  LOADCHROMA(1);
276  PUTRGBA(dst_2, py_2, pa_2, 1, 24);
277  PUTRGBA(dst_1, py_1, pa_1, 1, 24);
278 
279  LOADCHROMA(2);
280  PUTRGBA(dst_1, py_1, pa_1, 2, 24);
281  PUTRGBA(dst_2, py_2, pa_2, 2, 24);
282 
283  LOADCHROMA(3);
284  PUTRGBA(dst_2, py_2, pa_2, 3, 24);
285  PUTRGBA(dst_1, py_1, pa_1, 3, 24);
286  pa_1 += 8;
287  pa_2 += 8;
288 ENDYUV2RGBLINE(8, 0)
289  LOADCHROMA(0);
290  PUTRGBA(dst_1, py_1, pa_1, 0, 24);
291  PUTRGBA(dst_2, py_2, pa_2, 0, 24);
292 
293  LOADCHROMA(1);
294  PUTRGBA(dst_2, py_2, pa_2, 1, 24);
295  PUTRGBA(dst_1, py_1, pa_1, 1, 24);
296  pa_1 += 4;
297  pa_2 += 4;
298 ENDYUV2RGBLINE(8, 1)
299  LOADCHROMA(0);
300  PUTRGBA(dst_1, py_1, pa_1, 0, 24);
301  PUTRGBA(dst_2, py_2, pa_2, 0, 24);
303 
304 YUV2RGBFUNC(yuva2argb_c, uint32_t, 1)
305  LOADCHROMA(0);
306  PUTRGBA(dst_1, py_1, pa_1, 0, 0);
307  PUTRGBA(dst_2, py_2, pa_2, 0, 0);
308 
309  LOADCHROMA(1);
310  PUTRGBA(dst_2, py_2, pa_2, 1, 0);
311  PUTRGBA(dst_1, py_1, pa_1, 1, 0);
312 
313  LOADCHROMA(2);
314  PUTRGBA(dst_1, py_1, pa_1, 2, 0);
315  PUTRGBA(dst_2, py_2, pa_2, 2, 0);
316 
317  LOADCHROMA(3);
318  PUTRGBA(dst_2, py_2, pa_2, 3, 0);
319  PUTRGBA(dst_1, py_1, pa_1, 3, 0);
320  pa_1 += 8;
321  pa_2 += 8;
322 ENDYUV2RGBLINE(8, 0)
323  LOADCHROMA(0);
324  PUTRGBA(dst_1, py_1, pa_1, 0, 0);
325  PUTRGBA(dst_2, py_2, pa_2, 0, 0);
326 
327  LOADCHROMA(1);
328  PUTRGBA(dst_2, py_2, pa_2, 1, 0);
329  PUTRGBA(dst_1, py_1, pa_1, 1, 0);
330  pa_1 += 4;
331  pa_2 += 4;
332 ENDYUV2RGBLINE(8, 1)
333  LOADCHROMA(0);
334  PUTRGBA(dst_1, py_1, pa_1, 0, 0);
335  PUTRGBA(dst_2, py_2, pa_2, 0, 0);
337 
338 YUV2RGBFUNC(yuv2rgb_c_24_rgb, uint8_t, 0)
339  LOADCHROMA(0);
340  PUTRGB24(dst_1, py_1, 0);
341  PUTRGB24(dst_2, py_2, 0);
342 
343  LOADCHROMA(1);
344  PUTRGB24(dst_2, py_2, 1);
345  PUTRGB24(dst_1, py_1, 1);
346 
347  LOADCHROMA(2);
348  PUTRGB24(dst_1, py_1, 2);
349  PUTRGB24(dst_2, py_2, 2);
350 
351  LOADCHROMA(3);
352  PUTRGB24(dst_2, py_2, 3);
353  PUTRGB24(dst_1, py_1, 3);
354 ENDYUV2RGBLINE(24, 0)
355  LOADCHROMA(0);
356  PUTRGB24(dst_1, py_1, 0);
357  PUTRGB24(dst_2, py_2, 0);
358 
359  LOADCHROMA(1);
360  PUTRGB24(dst_2, py_2, 1);
361  PUTRGB24(dst_1, py_1, 1);
362 ENDYUV2RGBLINE(24, 1)
363  LOADCHROMA(0);
364  PUTRGB24(dst_1, py_1, 0);
365  PUTRGB24(dst_2, py_2, 0);
367 
368 // only trivial mods from yuv2rgb_c_24_rgb
369 YUV2RGBFUNC(yuv2rgb_c_24_bgr, uint8_t, 0)
370  LOADCHROMA(0);
371  PUTBGR24(dst_1, py_1, 0);
372  PUTBGR24(dst_2, py_2, 0);
373 
374  LOADCHROMA(1);
375  PUTBGR24(dst_2, py_2, 1);
376  PUTBGR24(dst_1, py_1, 1);
377 
378  LOADCHROMA(2);
379  PUTBGR24(dst_1, py_1, 2);
380  PUTBGR24(dst_2, py_2, 2);
381 
382  LOADCHROMA(3);
383  PUTBGR24(dst_2, py_2, 3);
384  PUTBGR24(dst_1, py_1, 3);
385 ENDYUV2RGBLINE(24, 0)
386  LOADCHROMA(0);
387  PUTBGR24(dst_1, py_1, 0);
388  PUTBGR24(dst_2, py_2, 0);
389 
390  LOADCHROMA(1);
391  PUTBGR24(dst_2, py_2, 1);
392  PUTBGR24(dst_1, py_1, 1);
393 ENDYUV2RGBLINE(24, 1)
394  LOADCHROMA(0);
395  PUTBGR24(dst_1, py_1, 0);
396  PUTBGR24(dst_2, py_2, 0);
398 
399 YUV2RGBFUNC(yuv2rgb_c_16_ordered_dither, uint16_t, 0)
400  const uint8_t *d16 = ff_dither_2x2_8[y & 1];
401  const uint8_t *e16 = ff_dither_2x2_4[y & 1];
402  const uint8_t *f16 = ff_dither_2x2_8[(y & 1)^1];
403 
404 #define PUTRGB16(dst, src, i, o) \
405  Y = src[2 * i]; \
406  dst[2 * i] = r[Y + d16[0 + o]] + \
407  g[Y + e16[0 + o]] + \
408  b[Y + f16[0 + o]]; \
409  Y = src[2 * i + 1]; \
410  dst[2 * i + 1] = r[Y + d16[1 + o]] + \
411  g[Y + e16[1 + o]] + \
412  b[Y + f16[1 + o]];
413  LOADCHROMA(0);
414  PUTRGB16(dst_1, py_1, 0, 0);
415  PUTRGB16(dst_2, py_2, 0, 0 + 8);
416 
417  LOADCHROMA(1);
418  PUTRGB16(dst_2, py_2, 1, 2 + 8);
419  PUTRGB16(dst_1, py_1, 1, 2);
420 
421  LOADCHROMA(2);
422  PUTRGB16(dst_1, py_1, 2, 4);
423  PUTRGB16(dst_2, py_2, 2, 4 + 8);
424 
425  LOADCHROMA(3);
426  PUTRGB16(dst_2, py_2, 3, 6 + 8);
427  PUTRGB16(dst_1, py_1, 3, 6);
429 
430 YUV2RGBFUNC(yuv2rgb_c_15_ordered_dither, uint16_t, 0)
431  const uint8_t *d16 = ff_dither_2x2_8[y & 1];
432  const uint8_t *e16 = ff_dither_2x2_8[(y & 1)^1];
433 
434 #define PUTRGB15(dst, src, i, o) \
435  Y = src[2 * i]; \
436  dst[2 * i] = r[Y + d16[0 + o]] + \
437  g[Y + d16[1 + o]] + \
438  b[Y + e16[0 + o]]; \
439  Y = src[2 * i + 1]; \
440  dst[2 * i + 1] = r[Y + d16[1 + o]] + \
441  g[Y + d16[0 + o]] + \
442  b[Y + e16[1 + o]];
443  LOADCHROMA(0);
444  PUTRGB15(dst_1, py_1, 0, 0);
445  PUTRGB15(dst_2, py_2, 0, 0 + 8);
446 
447  LOADCHROMA(1);
448  PUTRGB15(dst_2, py_2, 1, 2 + 8);
449  PUTRGB15(dst_1, py_1, 1, 2);
450 
451  LOADCHROMA(2);
452  PUTRGB15(dst_1, py_1, 2, 4);
453  PUTRGB15(dst_2, py_2, 2, 4 + 8);
454 
455  LOADCHROMA(3);
456  PUTRGB15(dst_2, py_2, 3, 6 + 8);
457  PUTRGB15(dst_1, py_1, 3, 6);
459 
460 // r, g, b, dst_1, dst_2
461 YUV2RGBFUNC(yuv2rgb_c_12_ordered_dither, uint16_t, 0)
462  const uint8_t *d16 = ff_dither_4x4_16[y & 3];
463 
464 #define PUTRGB12(dst, src, i, o) \
465  Y = src[2 * i]; \
466  dst[2 * i] = r[Y + d16[0 + o]] + \
467  g[Y + d16[0 + o]] + \
468  b[Y + d16[0 + o]]; \
469  Y = src[2 * i + 1]; \
470  dst[2 * i + 1] = r[Y + d16[1 + o]] + \
471  g[Y + d16[1 + o]] + \
472  b[Y + d16[1 + o]];
473 
474  LOADCHROMA(0);
475  PUTRGB12(dst_1, py_1, 0, 0);
476  PUTRGB12(dst_2, py_2, 0, 0 + 8);
477 
478  LOADCHROMA(1);
479  PUTRGB12(dst_2, py_2, 1, 2 + 8);
480  PUTRGB12(dst_1, py_1, 1, 2);
481 
482  LOADCHROMA(2);
483  PUTRGB12(dst_1, py_1, 2, 4);
484  PUTRGB12(dst_2, py_2, 2, 4 + 8);
485 
486  LOADCHROMA(3);
487  PUTRGB12(dst_2, py_2, 3, 6 + 8);
488  PUTRGB12(dst_1, py_1, 3, 6);
490 
491 // r, g, b, dst_1, dst_2
492 YUV2RGBFUNC(yuv2rgb_c_8_ordered_dither, uint8_t, 0)
493  const uint8_t *d32 = ff_dither_8x8_32[y & 7];
494  const uint8_t *d64 = ff_dither_8x8_73[y & 7];
495 
496 #define PUTRGB8(dst, src, i, o) \
497  Y = src[2 * i]; \
498  dst[2 * i] = r[Y + d32[0 + o]] + \
499  g[Y + d32[0 + o]] + \
500  b[Y + d64[0 + o]]; \
501  Y = src[2 * i + 1]; \
502  dst[2 * i + 1] = r[Y + d32[1 + o]] + \
503  g[Y + d32[1 + o]] + \
504  b[Y + d64[1 + o]];
505 
506  LOADCHROMA(0);
507  PUTRGB8(dst_1, py_1, 0, 0);
508  PUTRGB8(dst_2, py_2, 0, 0 + 8);
509 
510  LOADCHROMA(1);
511  PUTRGB8(dst_2, py_2, 1, 2 + 8);
512  PUTRGB8(dst_1, py_1, 1, 2);
513 
514  LOADCHROMA(2);
515  PUTRGB8(dst_1, py_1, 2, 4);
516  PUTRGB8(dst_2, py_2, 2, 4 + 8);
517 
518  LOADCHROMA(3);
519  PUTRGB8(dst_2, py_2, 3, 6 + 8);
520  PUTRGB8(dst_1, py_1, 3, 6);
521 
522 ENDYUV2RGBLINE(8, 0)
523  const uint8_t *d32 = ff_dither_8x8_32[y & 7];
524  const uint8_t *d64 = ff_dither_8x8_73[y & 7];
525  LOADCHROMA(0);
526  PUTRGB8(dst_1, py_1, 0, 0);
527  PUTRGB8(dst_2, py_2, 0, 0 + 8);
528 
529  LOADCHROMA(1);
530  PUTRGB8(dst_2, py_2, 1, 2 + 8);
531  PUTRGB8(dst_1, py_1, 1, 2);
532 
533 ENDYUV2RGBLINE(8, 1)
534  const uint8_t *d32 = ff_dither_8x8_32[y & 7];
535  const uint8_t *d64 = ff_dither_8x8_73[y & 7];
536  LOADCHROMA(0);
537  PUTRGB8(dst_1, py_1, 0, 0);
538  PUTRGB8(dst_2, py_2, 0, 0 + 8);
539 
541 
542 
543 YUV2RGBFUNC(yuv2rgb_c_4_ordered_dither, uint8_t, 0)
544  const uint8_t * d64 = ff_dither_8x8_73[y & 7];
545  const uint8_t *d128 = ff_dither_8x8_220[y & 7];
546  int acc;
547 
548 #define PUTRGB4D(dst, src, i, o) \
549  Y = src[2 * i]; \
550  acc = r[Y + d128[0 + o]] + \
551  g[Y + d64[0 + o]] + \
552  b[Y + d128[0 + o]]; \
553  Y = src[2 * i + 1]; \
554  acc |= (r[Y + d128[1 + o]] + \
555  g[Y + d64[1 + o]] + \
556  b[Y + d128[1 + o]]) << 4; \
557  dst[i] = acc;
558 
559  LOADCHROMA(0);
560  PUTRGB4D(dst_1, py_1, 0, 0);
561  PUTRGB4D(dst_2, py_2, 0, 0 + 8);
562 
563  LOADCHROMA(1);
564  PUTRGB4D(dst_2, py_2, 1, 2 + 8);
565  PUTRGB4D(dst_1, py_1, 1, 2);
566 
567  LOADCHROMA(2);
568  PUTRGB4D(dst_1, py_1, 2, 4);
569  PUTRGB4D(dst_2, py_2, 2, 4 + 8);
570 
571  LOADCHROMA(3);
572  PUTRGB4D(dst_2, py_2, 3, 6 + 8);
573  PUTRGB4D(dst_1, py_1, 3, 6);
574 
575 ENDYUV2RGBLINE(4, 0)
576  const uint8_t * d64 = ff_dither_8x8_73[y & 7];
577  const uint8_t *d128 = ff_dither_8x8_220[y & 7];
578  int acc;
579  LOADCHROMA(0);
580  PUTRGB4D(dst_1, py_1, 0, 0);
581  PUTRGB4D(dst_2, py_2, 0, 0 + 8);
582 
583  LOADCHROMA(1);
584  PUTRGB4D(dst_2, py_2, 1, 2 + 8);
585  PUTRGB4D(dst_1, py_1, 1, 2);
586 
587 ENDYUV2RGBLINE(4, 1)
588  const uint8_t * d64 = ff_dither_8x8_73[y & 7];
589  const uint8_t *d128 = ff_dither_8x8_220[y & 7];
590  int acc;
591  LOADCHROMA(0);
592  PUTRGB4D(dst_1, py_1, 0, 0);
593  PUTRGB4D(dst_2, py_2, 0, 0 + 8);
595 
596 YUV2RGBFUNC(yuv2rgb_c_4b_ordered_dither, uint8_t, 0)
597  const uint8_t *d64 = ff_dither_8x8_73[y & 7];
598  const uint8_t *d128 = ff_dither_8x8_220[y & 7];
599 
600 #define PUTRGB4DB(dst, src, i, o) \
601  Y = src[2 * i]; \
602  dst[2 * i] = r[Y + d128[0 + o]] + \
603  g[Y + d64[0 + o]] + \
604  b[Y + d128[0 + o]]; \
605  Y = src[2 * i + 1]; \
606  dst[2 * i + 1] = r[Y + d128[1 + o]] + \
607  g[Y + d64[1 + o]] + \
608  b[Y + d128[1 + o]];
609 
610  LOADCHROMA(0);
611  PUTRGB4DB(dst_1, py_1, 0, 0);
612  PUTRGB4DB(dst_2, py_2, 0, 0 + 8);
613 
614  LOADCHROMA(1);
615  PUTRGB4DB(dst_2, py_2, 1, 2 + 8);
616  PUTRGB4DB(dst_1, py_1, 1, 2);
617 
618  LOADCHROMA(2);
619  PUTRGB4DB(dst_1, py_1, 2, 4);
620  PUTRGB4DB(dst_2, py_2, 2, 4 + 8);
621 
622  LOADCHROMA(3);
623  PUTRGB4DB(dst_2, py_2, 3, 6 + 8);
624  PUTRGB4DB(dst_1, py_1, 3, 6);
625 ENDYUV2RGBLINE(8, 0)
626  const uint8_t *d64 = ff_dither_8x8_73[y & 7];
627  const uint8_t *d128 = ff_dither_8x8_220[y & 7];
628  LOADCHROMA(0);
629  PUTRGB4DB(dst_1, py_1, 0, 0);
630  PUTRGB4DB(dst_2, py_2, 0, 0 + 8);
631 
632  LOADCHROMA(1);
633  PUTRGB4DB(dst_2, py_2, 1, 2 + 8);
634  PUTRGB4DB(dst_1, py_1, 1, 2);
635 ENDYUV2RGBLINE(8, 1)
636  const uint8_t *d64 = ff_dither_8x8_73[y & 7];
637  const uint8_t *d128 = ff_dither_8x8_220[y & 7];
638  LOADCHROMA(0);
639  PUTRGB4DB(dst_1, py_1, 0, 0);
640  PUTRGB4DB(dst_2, py_2, 0, 0 + 8);
642 
643 YUV2RGBFUNC(yuv2rgb_c_1_ordered_dither, uint8_t, 0)
644  const uint8_t *d128 = ff_dither_8x8_220[y & 7];
645  char out_1 = 0, out_2 = 0;
646  g = c->table_gU[128 + YUVRGB_TABLE_HEADROOM] + c->table_gV[128 + YUVRGB_TABLE_HEADROOM];
647 
648 #define PUTRGB1(out, src, i, o) \
649  Y = src[2 * i]; \
650  out += out + g[Y + d128[0 + o]]; \
651  Y = src[2 * i + 1]; \
652  out += out + g[Y + d128[1 + o]];
653 
654  PUTRGB1(out_1, py_1, 0, 0);
655  PUTRGB1(out_2, py_2, 0, 0 + 8);
656 
657  PUTRGB1(out_2, py_2, 1, 2 + 8);
658  PUTRGB1(out_1, py_1, 1, 2);
659 
660  PUTRGB1(out_1, py_1, 2, 4);
661  PUTRGB1(out_2, py_2, 2, 4 + 8);
662 
663  PUTRGB1(out_2, py_2, 3, 6 + 8);
664  PUTRGB1(out_1, py_1, 3, 6);
665 
666  dst_1[0] = out_1;
667  dst_2[0] = out_2;
669 
671 {
672  SwsFunc t = NULL;
673 
674  if (ARCH_PPC)
675  t = ff_yuv2rgb_init_ppc(c);
676  if (ARCH_X86)
677  t = ff_yuv2rgb_init_x86(c);
678 
679  if (t)
680  return t;
681 
683  "No accelerated colorspace conversion found from %s to %s.\n",
684  av_get_pix_fmt_name(c->srcFormat), av_get_pix_fmt_name(c->dstFormat));
685 
686  switch (c->dstFormat) {
687  case AV_PIX_FMT_BGR48BE:
688  case AV_PIX_FMT_BGR48LE:
689  return yuv2rgb_c_bgr48;
690  case AV_PIX_FMT_RGB48BE:
691  case AV_PIX_FMT_RGB48LE:
692  return yuv2rgb_c_48;
693  case AV_PIX_FMT_ARGB:
694  case AV_PIX_FMT_ABGR:
695  if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat))
696  return yuva2argb_c;
697  case AV_PIX_FMT_RGBA:
698  case AV_PIX_FMT_BGRA:
699  return (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) ? yuva2rgba_c : yuv2rgb_c_32;
700  case AV_PIX_FMT_RGB24:
701  return yuv2rgb_c_24_rgb;
702  case AV_PIX_FMT_BGR24:
703  return yuv2rgb_c_24_bgr;
704  case AV_PIX_FMT_RGB565:
705  case AV_PIX_FMT_BGR565:
706  return yuv2rgb_c_16_ordered_dither;
707  case AV_PIX_FMT_RGB555:
708  case AV_PIX_FMT_BGR555:
709  return yuv2rgb_c_15_ordered_dither;
710  case AV_PIX_FMT_RGB444:
711  case AV_PIX_FMT_BGR444:
712  return yuv2rgb_c_12_ordered_dither;
713  case AV_PIX_FMT_RGB8:
714  case AV_PIX_FMT_BGR8:
715  return yuv2rgb_c_8_ordered_dither;
716  case AV_PIX_FMT_RGB4:
717  case AV_PIX_FMT_BGR4:
718  return yuv2rgb_c_4_ordered_dither;
721  return yuv2rgb_c_4b_ordered_dither;
723  return yuv2rgb_c_1_ordered_dither;
724  }
725  return NULL;
726 }
727 
728 static void fill_table(uint8_t* table[256 + 2*YUVRGB_TABLE_HEADROOM], const int elemsize,
729  const int64_t inc, void *y_tab)
730 {
731  int i;
732  uint8_t *y_table = y_tab;
733 
734  y_table -= elemsize * (inc >> 9);
735 
736  for (i = 0; i < 256 + 2*YUVRGB_TABLE_HEADROOM; i++) {
737  int64_t cb = av_clip_uint8(i-YUVRGB_TABLE_HEADROOM)*inc;
738  table[i] = y_table + elemsize * (cb >> 16);
739  }
740 }
741 
742 static void fill_gv_table(int table[256 + 2*YUVRGB_TABLE_HEADROOM], const int elemsize, const int64_t inc)
743 {
744  int i;
745  int off = -(inc >> 9);
746 
747  for (i = 0; i < 256 + 2*YUVRGB_TABLE_HEADROOM; i++) {
748  int64_t cb = av_clip_uint8(i-YUVRGB_TABLE_HEADROOM)*inc;
749  table[i] = elemsize * (off + (cb >> 16));
750  }
751 }
752 
753 static uint16_t roundToInt16(int64_t f)
754 {
755  int r = (f + (1 << 15)) >> 16;
756 
757  if (r < -0x7FFF)
758  return 0x8000;
759  else if (r > 0x7FFF)
760  return 0x7FFF;
761  else
762  return r;
763 }
764 
765 av_cold int ff_yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4],
766  int fullRange, int brightness,
767  int contrast, int saturation)
768 {
769  const int isRgb = c->dstFormat == AV_PIX_FMT_RGB32 ||
771  c->dstFormat == AV_PIX_FMT_BGR24 ||
778  c->dstFormat == AV_PIX_FMT_RGB8 ||
779  c->dstFormat == AV_PIX_FMT_RGB4 ||
782  const int isNotNe = c->dstFormat == AV_PIX_FMT_NE(RGB565LE, RGB565BE) ||
783  c->dstFormat == AV_PIX_FMT_NE(RGB555LE, RGB555BE) ||
784  c->dstFormat == AV_PIX_FMT_NE(RGB444LE, RGB444BE) ||
785  c->dstFormat == AV_PIX_FMT_NE(BGR565LE, BGR565BE) ||
786  c->dstFormat == AV_PIX_FMT_NE(BGR555LE, BGR555BE) ||
787  c->dstFormat == AV_PIX_FMT_NE(BGR444LE, BGR444BE);
788  const int bpp = c->dstFormatBpp;
789  uint8_t *y_table;
790  uint16_t *y_table16;
791  uint32_t *y_table32;
792  int i, base, rbase, gbase, bbase, av_uninit(abase), needAlpha;
793  const int yoffs = (fullRange ? 384 : 326) + YUVRGB_TABLE_LUMA_HEADROOM;
794  const int table_plane_size = 1024 + 2*YUVRGB_TABLE_LUMA_HEADROOM;
795 
796  int64_t crv = inv_table[0];
797  int64_t cbu = inv_table[1];
798  int64_t cgu = -inv_table[2];
799  int64_t cgv = -inv_table[3];
800  int64_t cy = 1 << 16;
801  int64_t oy = 0;
802  int64_t yb = 0;
803 
804  if (!fullRange) {
805  cy = (cy * 255) / 219;
806  oy = 16 << 16;
807  } else {
808  crv = (crv * 224) / 255;
809  cbu = (cbu * 224) / 255;
810  cgu = (cgu * 224) / 255;
811  cgv = (cgv * 224) / 255;
812  }
813 
814  cy = (cy * contrast) >> 16;
815  crv = (crv * contrast * saturation) >> 32;
816  cbu = (cbu * contrast * saturation) >> 32;
817  cgu = (cgu * contrast * saturation) >> 32;
818  cgv = (cgv * contrast * saturation) >> 32;
819  oy -= 256 * brightness;
820 
821  c->uOffset = 0x0400040004000400LL;
822  c->vOffset = 0x0400040004000400LL;
823  c->yCoeff = roundToInt16(cy * (1 << 13)) * 0x0001000100010001ULL;
824  c->vrCoeff = roundToInt16(crv * (1 << 13)) * 0x0001000100010001ULL;
825  c->ubCoeff = roundToInt16(cbu * (1 << 13)) * 0x0001000100010001ULL;
826  c->vgCoeff = roundToInt16(cgv * (1 << 13)) * 0x0001000100010001ULL;
827  c->ugCoeff = roundToInt16(cgu * (1 << 13)) * 0x0001000100010001ULL;
828  c->yOffset = roundToInt16(oy * (1 << 3)) * 0x0001000100010001ULL;
829 
830  c->yuv2rgb_y_coeff = (int16_t)roundToInt16(cy * (1 << 13));
831  c->yuv2rgb_y_offset = (int16_t)roundToInt16(oy * (1 << 9));
832  c->yuv2rgb_v2r_coeff = (int16_t)roundToInt16(crv * (1 << 13));
833  c->yuv2rgb_v2g_coeff = (int16_t)roundToInt16(cgv * (1 << 13));
834  c->yuv2rgb_u2g_coeff = (int16_t)roundToInt16(cgu * (1 << 13));
835  c->yuv2rgb_u2b_coeff = (int16_t)roundToInt16(cbu * (1 << 13));
836 
837  //scale coefficients by cy
838  crv = ((crv * (1 << 16)) + 0x8000) / FFMAX(cy, 1);
839  cbu = ((cbu * (1 << 16)) + 0x8000) / FFMAX(cy, 1);
840  cgu = ((cgu * (1 << 16)) + 0x8000) / FFMAX(cy, 1);
841  cgv = ((cgv * (1 << 16)) + 0x8000) / FFMAX(cy, 1);
842 
843  av_freep(&c->yuvTable);
844 
845 #define ALLOC_YUV_TABLE(x) \
846  c->yuvTable = av_malloc(x); \
847  if (!c->yuvTable) \
848  return AVERROR(ENOMEM);
849  switch (bpp) {
850  case 1:
851  ALLOC_YUV_TABLE(table_plane_size);
852  y_table = c->yuvTable;
853  yb = -(384 << 16) - YUVRGB_TABLE_LUMA_HEADROOM*cy - oy;
854  for (i = 0; i < table_plane_size - 110; i++) {
855  y_table[i + 110] = av_clip_uint8((yb + 0x8000) >> 16) >> 7;
856  yb += cy;
857  }
858  fill_table(c->table_gU, 1, cgu, y_table + yoffs);
859  fill_gv_table(c->table_gV, 1, cgv);
860  break;
861  case 4:
862  case 4 | 128:
863  rbase = isRgb ? 3 : 0;
864  gbase = 1;
865  bbase = isRgb ? 0 : 3;
866  ALLOC_YUV_TABLE(table_plane_size * 3);
867  y_table = c->yuvTable;
868  yb = -(384 << 16) - YUVRGB_TABLE_LUMA_HEADROOM*cy - oy;
869  for (i = 0; i < table_plane_size - 110; i++) {
870  int yval = av_clip_uint8((yb + 0x8000) >> 16);
871  y_table[i + 110] = (yval >> 7) << rbase;
872  y_table[i + 37 + table_plane_size] = ((yval + 43) / 85) << gbase;
873  y_table[i + 110 + 2*table_plane_size] = (yval >> 7) << bbase;
874  yb += cy;
875  }
876  fill_table(c->table_rV, 1, crv, y_table + yoffs);
877  fill_table(c->table_gU, 1, cgu, y_table + yoffs + table_plane_size);
878  fill_table(c->table_bU, 1, cbu, y_table + yoffs + 2*table_plane_size);
879  fill_gv_table(c->table_gV, 1, cgv);
880  break;
881  case 8:
882  rbase = isRgb ? 5 : 0;
883  gbase = isRgb ? 2 : 3;
884  bbase = isRgb ? 0 : 6;
885  ALLOC_YUV_TABLE(table_plane_size * 3);
886  y_table = c->yuvTable;
887  yb = -(384 << 16) - YUVRGB_TABLE_LUMA_HEADROOM*cy - oy;
888  for (i = 0; i < table_plane_size - 38; i++) {
889  int yval = av_clip_uint8((yb + 0x8000) >> 16);
890  y_table[i + 16] = ((yval + 18) / 36) << rbase;
891  y_table[i + 16 + table_plane_size] = ((yval + 18) / 36) << gbase;
892  y_table[i + 37 + 2*table_plane_size] = ((yval + 43) / 85) << bbase;
893  yb += cy;
894  }
895  fill_table(c->table_rV, 1, crv, y_table + yoffs);
896  fill_table(c->table_gU, 1, cgu, y_table + yoffs + table_plane_size);
897  fill_table(c->table_bU, 1, cbu, y_table + yoffs + 2*table_plane_size);
898  fill_gv_table(c->table_gV, 1, cgv);
899  break;
900  case 12:
901  rbase = isRgb ? 8 : 0;
902  gbase = 4;
903  bbase = isRgb ? 0 : 8;
904  ALLOC_YUV_TABLE(table_plane_size * 3 * 2);
905  y_table16 = c->yuvTable;
906  yb = -(384 << 16) - YUVRGB_TABLE_LUMA_HEADROOM*cy - oy;
907  for (i = 0; i < table_plane_size; i++) {
908  uint8_t yval = av_clip_uint8((yb + 0x8000) >> 16);
909  y_table16[i] = (yval >> 4) << rbase;
910  y_table16[i + table_plane_size] = (yval >> 4) << gbase;
911  y_table16[i + 2*table_plane_size] = (yval >> 4) << bbase;
912  yb += cy;
913  }
914  if (isNotNe)
915  for (i = 0; i < table_plane_size * 3; i++)
916  y_table16[i] = av_bswap16(y_table16[i]);
917  fill_table(c->table_rV, 2, crv, y_table16 + yoffs);
918  fill_table(c->table_gU, 2, cgu, y_table16 + yoffs + table_plane_size);
919  fill_table(c->table_bU, 2, cbu, y_table16 + yoffs + 2*table_plane_size);
920  fill_gv_table(c->table_gV, 2, cgv);
921  break;
922  case 15:
923  case 16:
924  rbase = isRgb ? bpp - 5 : 0;
925  gbase = 5;
926  bbase = isRgb ? 0 : (bpp - 5);
927  ALLOC_YUV_TABLE(table_plane_size * 3 * 2);
928  y_table16 = c->yuvTable;
929  yb = -(384 << 16) - YUVRGB_TABLE_LUMA_HEADROOM*cy - oy;
930  for (i = 0; i < table_plane_size; i++) {
931  uint8_t yval = av_clip_uint8((yb + 0x8000) >> 16);
932  y_table16[i] = (yval >> 3) << rbase;
933  y_table16[i + table_plane_size] = (yval >> (18 - bpp)) << gbase;
934  y_table16[i + 2*table_plane_size] = (yval >> 3) << bbase;
935  yb += cy;
936  }
937  if (isNotNe)
938  for (i = 0; i < table_plane_size * 3; i++)
939  y_table16[i] = av_bswap16(y_table16[i]);
940  fill_table(c->table_rV, 2, crv, y_table16 + yoffs);
941  fill_table(c->table_gU, 2, cgu, y_table16 + yoffs + table_plane_size);
942  fill_table(c->table_bU, 2, cbu, y_table16 + yoffs + 2*table_plane_size);
943  fill_gv_table(c->table_gV, 2, cgv);
944  break;
945  case 24:
946  case 48:
947  ALLOC_YUV_TABLE(table_plane_size);
948  y_table = c->yuvTable;
949  yb = -(384 << 16) - YUVRGB_TABLE_LUMA_HEADROOM*cy - oy;
950  for (i = 0; i < table_plane_size; i++) {
951  y_table[i] = av_clip_uint8((yb + 0x8000) >> 16);
952  yb += cy;
953  }
954  fill_table(c->table_rV, 1, crv, y_table + yoffs);
955  fill_table(c->table_gU, 1, cgu, y_table + yoffs);
956  fill_table(c->table_bU, 1, cbu, y_table + yoffs);
957  fill_gv_table(c->table_gV, 1, cgv);
958  break;
959  case 32:
960  case 64:
961  base = (c->dstFormat == AV_PIX_FMT_RGB32_1 ||
962  c->dstFormat == AV_PIX_FMT_BGR32_1) ? 8 : 0;
963  rbase = base + (isRgb ? 16 : 0);
964  gbase = base + 8;
965  bbase = base + (isRgb ? 0 : 16);
966  needAlpha = CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat);
967  if (!needAlpha)
968  abase = (base + 24) & 31;
969  ALLOC_YUV_TABLE(table_plane_size * 3 * 4);
970  y_table32 = c->yuvTable;
971  yb = -(384 << 16) - YUVRGB_TABLE_LUMA_HEADROOM*cy - oy;
972  for (i = 0; i < table_plane_size; i++) {
973  unsigned yval = av_clip_uint8((yb + 0x8000) >> 16);
974  y_table32[i] = (yval << rbase) +
975  (needAlpha ? 0 : (255u << abase));
976  y_table32[i + table_plane_size] = yval << gbase;
977  y_table32[i + 2*table_plane_size] = yval << bbase;
978  yb += cy;
979  }
980  fill_table(c->table_rV, 4, crv, y_table32 + yoffs);
981  fill_table(c->table_gU, 4, cgu, y_table32 + yoffs + table_plane_size);
982  fill_table(c->table_bU, 4, cbu, y_table32 + yoffs + 2*table_plane_size);
983  fill_gv_table(c->table_gV, 4, cgv);
984  break;
985  default:
986  if(!isPlanar(c->dstFormat) || bpp <= 24)
987  av_log(c, AV_LOG_ERROR, "%ibpp not supported by yuv2rgb\n", bpp);
988  return -1;
989  }
990  return 0;
991 }
uint64_t vrCoeff
dst_1[0]
Definition: yuv2rgb.c:666
#define NULL
Definition: coverity.c:32
char out_2
Definition: yuv2rgb.c:645
#define YUVRGB_TABLE_HEADROOM
pa_1
Definition: yuv2rgb.c:286
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:64
packed RGB 1:2:1 bitstream, 4bpp, (msb)1B 2G 1R(lsb), a byte contains two pixels, the first pixel in ...
Definition: pixfmt.h:85
const uint8_t * e16
Definition: yuv2rgb.c:401
int acc
Definition: yuv2rgb.c:546
const uint8_t ff_dither_2x2_8[][8]
Definition: output.c:45
av_cold SwsFunc ff_yuv2rgb_init_x86(SwsContext *c)
Definition: yuv2rgb.c:72
packed RGB 5:5:5, 16bpp, (msb)1X 5R 5G 5B(lsb), little-endian, X=unused/undefined ...
Definition: pixfmt.h:116
uint8_t * table_bU[256+2 *YUVRGB_TABLE_HEADROOM]
#define av_bswap16
Definition: bswap.h:31
int dstFormatBpp
Number of bits per pixel of the destination pixel format.
#define ALLOC_YUV_TABLE(x)
#define PUTRGB15(dst, src, i, o)
Definition: yuv2rgb.c:434
packed RGB 4:4:4, 16bpp, (msb)4X 4R 4G 4B(lsb), big-endian, X=unused/undefined
Definition: pixfmt.h:151
#define PUTBGR24(dst, src, i)
Definition: yuv2rgb.c:93
#define AV_PIX_FMT_RGB444
Definition: pixfmt.h:330
const uint8_t ff_dither_8x8_220[][8]
Definition: output.c:84
packed RGB 1:2:1 bitstream, 4bpp, (msb)1R 2G 1B(lsb), a byte contains two pixels, the first pixel in ...
Definition: pixfmt.h:88
uint64_t ubCoeff
static void fill_table(uint8_t *table[256+2 *YUVRGB_TABLE_HEADROOM], const int elemsize, const int64_t inc, void *y_tab)
Definition: yuv2rgb.c:728
packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), little-endian
Definition: pixfmt.h:114
packed RGB 1:2:1, 8bpp, (msb)1B 2G 1R(lsb)
Definition: pixfmt.h:86
const uint8_t ff_dither_8x8_32[][8]
Definition: output.c:59
#define PUTRGB(dst, src, i)
Definition: yuv2rgb.c:77
static double cb(void *priv, double x, double y)
Definition: vf_geq.c:97
const uint8_t ff_dither_2x2_4[][8]
Definition: output.c:39
uint8_t
#define av_cold
Definition: attributes.h:82
const uint8_t ff_dither_4x4_16[][8]
Definition: output.c:51
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:111
static void fill_gv_table(int table[256+2 *YUVRGB_TABLE_HEADROOM], const int elemsize, const int64_t inc)
Definition: yuv2rgb.c:742
packed RGB 4:4:4, 16bpp, (msb)4X 4R 4G 4B(lsb), little-endian, X=unused/undefined ...
Definition: pixfmt.h:150
packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), big-endian
Definition: pixfmt.h:113
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
Definition: pixfmt.h:95
#define PUTRGB16(dst, src, i, o)
Definition: yuv2rgb.c:404
uint64_t yOffset
external API header
enum AVPixelFormat dstFormat
Destination pixel format.
#define isALPHA(x)
Definition: swscale.c:51
uint8_t * table_gU[256+2 *YUVRGB_TABLE_HEADROOM]
#define PUTRGBA(dst, ysrc, asrc, i, s)
Definition: yuv2rgb.c:103
#define av_log(a,...)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
#define AV_PIX_FMT_BGR32_1
Definition: pixfmt.h:321
#define AV_PIX_FMT_NE(be, le)
Definition: pixfmt.h:315
const int32_t ff_yuv2rgb_coeffs[11][4]
Definition: yuv2rgb.c:49
#define PUTBGR48(dst, src, i)
Definition: yuv2rgb.c:119
const uint8_t * d64
Definition: yuv2rgb.c:494
static const struct endianess table[]
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition: pixfmt.h:96
const char * r
Definition: vf_curves.c:111
g
Definition: yuv2rgb.c:646
#define YUVRGB_TABLE_LUMA_HEADROOM
#define ENDYUV2RGBFUNC()
Definition: yuv2rgb.c:170
uint64_t ugCoeff
#define SWS_CS_DEFAULT
Definition: swscale.h:95
#define FFMAX(a, b)
Definition: common.h:94
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
Definition: pixfmt.h:93
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:160
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:94
#define YUV2RGBFUNC(func_name, dst_type, alpha)
Definition: yuv2rgb.c:129
static uint16_t roundToInt16(int64_t f)
Definition: yuv2rgb.c:753
packed RGB 1:2:1, 8bpp, (msb)1R 2G 1B(lsb)
Definition: pixfmt.h:89
uint64_t vgCoeff
uint64_t uOffset
int32_t
int table_gV[256+2 *YUVRGB_TABLE_HEADROOM]
const int * sws_getCoefficients(int colorspace)
Return a pointer to yuv<->rgb coefficients for the given colorspace suitable for sws_setColorspaceDet...
Definition: yuv2rgb.c:63
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:65
uint8_t * table_rV[256+2 *YUVRGB_TABLE_HEADROOM]
#define PUTRGB4D(dst, src, i, o)
Definition: yuv2rgb.c:548
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:159
av_cold int ff_yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4], int fullRange, int brightness, int contrast, int saturation)
Definition: yuv2rgb.c:765
const uint8_t * d16
Definition: yuv2rgb.c:400
#define AV_PIX_FMT_BGR555
Definition: pixfmt.h:334
const uint8_t * f16
Definition: yuv2rgb.c:402
packed RGB 3:3:2, 8bpp, (msb)2B 3G 3R(lsb)
Definition: pixfmt.h:84
#define CLOSEYUV2RGBFUNC(dst_delta)
Definition: yuv2rgb.c:176
SwsFunc ff_yuv2rgb_get_func_ptr(SwsContext *c)
Definition: yuv2rgb.c:670
static av_always_inline int isPlanar(enum AVPixelFormat pix_fmt)
#define PUTRGB12(dst, src, i, o)
Definition: yuv2rgb.c:464
#define AV_PIX_FMT_RGB32
Definition: pixfmt.h:318
const uint8_t ff_dither_8x8_73[][8]
Definition: output.c:71
int(* SwsFunc)(struct SwsContext *context, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[])
byte swapping routines
const uint8_t * d32
Definition: yuv2rgb.c:493
#define ENDYUV2RGBLINE(dst_delta, ss)
Definition: yuv2rgb.c:159
pa_2
Definition: yuv2rgb.c:287
#define u(width,...)
#define AV_PIX_FMT_BGR565
Definition: pixfmt.h:333
av_cold SwsFunc ff_yuv2rgb_init_ppc(SwsContext *c)
packed RGB 5:5:5, 16bpp, (msb)1X 5R 5G 5B(lsb), big-endian , X=unused/undefined
Definition: pixfmt.h:115
#define PUTRGB48(dst, src, i)
Definition: yuv2rgb.c:109
Y , 1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb...
Definition: pixfmt.h:72
#define PUTRGB4DB(dst, src, i, o)
Definition: yuv2rgb.c:600
static double c[64]
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:110
#define PUTRGB8(dst, src, i, o)
Definition: yuv2rgb.c:496
#define AV_PIX_FMT_BGR444
Definition: pixfmt.h:335
enum AVPixelFormat srcFormat
Source pixel format.
const uint8_t * d128
Definition: yuv2rgb.c:545
packed RGB 3:3:2, 8bpp, (msb)2R 3G 3B(lsb)
Definition: pixfmt.h:87
#define AV_PIX_FMT_RGB555
Definition: pixfmt.h:329
#define PUTRGB1(out, src, i, o)
Definition: yuv2rgb.c:648
#define AV_PIX_FMT_RGB32_1
Definition: pixfmt.h:319
char out_1
Definition: yuv2rgb.c:645
uint64_t yCoeff
#define AV_PIX_FMT_RGB565
Definition: pixfmt.h:328
#define LOADCHROMA(i)
Definition: yuv2rgb.c:70
#define av_uninit(x)
Definition: attributes.h:149
#define av_freep(p)
dst_2[0]
Definition: yuv2rgb.c:667
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
Definition: pixdesc.c:2182
uint64_t vOffset
#define PUTRGB24(dst, src, i)
Definition: yuv2rgb.c:83