FFmpeg
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/bswap.h"
31 #include "config.h"
32 #include "rgb2rgb.h"
33 #include "swscale.h"
34 #include "swscale_internal.h"
35 #include "libavutil/pixdesc.h"
36 
37 /* Color space conversion coefficients for YCbCr -> RGB mapping.
38  *
39  * Entries are {crv, cbu, cgu, cgv}
40  *
41  * crv = (255 / 224) * 65536 * (1 - cr) / 0.5
42  * cbu = (255 / 224) * 65536 * (1 - cb) / 0.5
43  * cgu = (255 / 224) * 65536 * (cb / cg) * (1 - cb) / 0.5
44  * cgv = (255 / 224) * 65536 * (cr / cg) * (1 - cr) / 0.5
45  *
46  * where Y = cr * R + cg * G + cb * B and cr + cg + cb = 1.
47  */
48 const int32_t ff_yuv2rgb_coeffs[11][4] = {
49  { 104597, 132201, 25675, 53279 }, /* no sequence_display_extension */
50  { 117489, 138438, 13975, 34925 }, /* ITU-R Rec. 709 (1990) */
51  { 104597, 132201, 25675, 53279 }, /* unspecified */
52  { 104597, 132201, 25675, 53279 }, /* reserved */
53  { 104448, 132798, 24759, 53109 }, /* FCC */
54  { 104597, 132201, 25675, 53279 }, /* ITU-R Rec. 624-4 System B, G */
55  { 104597, 132201, 25675, 53279 }, /* SMPTE 170M */
56  { 117579, 136230, 16907, 35559 }, /* SMPTE 240M (1987) */
57  { 0 }, /* YCgCo */
58  { 110013, 140363, 12277, 42626 }, /* Bt-2020-NCL */
59  { 110013, 140363, 12277, 42626 }, /* Bt-2020-CL */
60 };
61 
62 const int *sws_getCoefficients(int colorspace)
63 {
64  if (colorspace > 10 || colorspace < 0 || colorspace == 8)
65  colorspace = SWS_CS_DEFAULT;
66  return ff_yuv2rgb_coeffs[colorspace];
67 }
68 
69 #define LOADCHROMA(i) \
70  U = pu[i]; \
71  V = pv[i]; \
72  r = (void *)c->table_rV[V+YUVRGB_TABLE_HEADROOM]; \
73  g = (void *)(c->table_gU[U+YUVRGB_TABLE_HEADROOM] + c->table_gV[V+YUVRGB_TABLE_HEADROOM]); \
74  b = (void *)c->table_bU[U+YUVRGB_TABLE_HEADROOM];
75 
76 #define PUTRGB(dst, src, i) \
77  Y = src[2 * i]; \
78  dst[2 * i] = r[Y] + g[Y] + b[Y]; \
79  Y = src[2 * i + 1]; \
80  dst[2 * i + 1] = r[Y] + g[Y] + b[Y];
81 
82 #define PUTRGB24(dst, src, i) \
83  Y = src[2 * i]; \
84  dst[6 * i + 0] = r[Y]; \
85  dst[6 * i + 1] = g[Y]; \
86  dst[6 * i + 2] = b[Y]; \
87  Y = src[2 * i + 1]; \
88  dst[6 * i + 3] = r[Y]; \
89  dst[6 * i + 4] = g[Y]; \
90  dst[6 * i + 5] = b[Y];
91 
92 #define PUTBGR24(dst, src, i) \
93  Y = src[2 * i]; \
94  dst[6 * i + 0] = b[Y]; \
95  dst[6 * i + 1] = g[Y]; \
96  dst[6 * i + 2] = r[Y]; \
97  Y = src[2 * i + 1]; \
98  dst[6 * i + 3] = b[Y]; \
99  dst[6 * i + 4] = g[Y]; \
100  dst[6 * i + 5] = r[Y];
101 
102 #define PUTRGBA(dst, ysrc, asrc, i, s) \
103  Y = ysrc[2 * i]; \
104  dst[2 * i] = r[Y] + g[Y] + b[Y] + (asrc[2 * i] << s); \
105  Y = ysrc[2 * i + 1]; \
106  dst[2 * i + 1] = r[Y] + g[Y] + b[Y] + (asrc[2 * i + 1] << s);
107 
108 #define PUTRGB48(dst, src, i) \
109  Y = src[ 2 * i]; \
110  dst[12 * i + 0] = dst[12 * i + 1] = r[Y]; \
111  dst[12 * i + 2] = dst[12 * i + 3] = g[Y]; \
112  dst[12 * i + 4] = dst[12 * i + 5] = b[Y]; \
113  Y = src[ 2 * i + 1]; \
114  dst[12 * i + 6] = dst[12 * i + 7] = r[Y]; \
115  dst[12 * i + 8] = dst[12 * i + 9] = g[Y]; \
116  dst[12 * i + 10] = dst[12 * i + 11] = b[Y];
117 
118 #define PUTBGR48(dst, src, i) \
119  Y = src[2 * i]; \
120  dst[12 * i + 0] = dst[12 * i + 1] = b[Y]; \
121  dst[12 * i + 2] = dst[12 * i + 3] = g[Y]; \
122  dst[12 * i + 4] = dst[12 * i + 5] = r[Y]; \
123  Y = src[2 * i + 1]; \
124  dst[12 * i + 6] = dst[12 * i + 7] = b[Y]; \
125  dst[12 * i + 8] = dst[12 * i + 9] = g[Y]; \
126  dst[12 * i + 10] = dst[12 * i + 11] = r[Y];
127 
128 #define YUV2RGBFUNC(func_name, dst_type, alpha) \
129  static int func_name(SwsContext *c, const uint8_t *src[], \
130  int srcStride[], int srcSliceY, int srcSliceH, \
131  uint8_t *dst[], int dstStride[]) \
132  { \
133  int y; \
134  \
135  if (!alpha && c->srcFormat == AV_PIX_FMT_YUV422P) { \
136  srcStride[1] *= 2; \
137  srcStride[2] *= 2; \
138  } \
139  for (y = 0; y < srcSliceH; y += 2) { \
140  int yd = y + srcSliceY; \
141  dst_type *dst_1 = \
142  (dst_type *)(dst[0] + (yd) * dstStride[0]); \
143  dst_type *dst_2 = \
144  (dst_type *)(dst[0] + (yd + 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 av_unused *pu = src[1] + (y >> 1) * srcStride[1]; \
149  const uint8_t av_unused *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 #if HAVE_BIGENDIAN
271 YUV2RGBFUNC(yuva2argb_c, uint32_t, 1)
272 #else
273 YUV2RGBFUNC(yuva2rgba_c, uint32_t, 1)
274 #endif
275  LOADCHROMA(0);
276  PUTRGBA(dst_1, py_1, pa_1, 0, 24);
277  PUTRGBA(dst_2, py_2, pa_2, 0, 24);
278 
279  LOADCHROMA(1);
280  PUTRGBA(dst_2, py_2, pa_2, 1, 24);
281  PUTRGBA(dst_1, py_1, pa_1, 1, 24);
282 
283  LOADCHROMA(2);
284  PUTRGBA(dst_1, py_1, pa_1, 2, 24);
285  PUTRGBA(dst_2, py_2, pa_2, 2, 24);
286 
287  LOADCHROMA(3);
288  PUTRGBA(dst_2, py_2, pa_2, 3, 24);
289  PUTRGBA(dst_1, py_1, pa_1, 3, 24);
290  pa_1 += 8;
291  pa_2 += 8;
292 ENDYUV2RGBLINE(8, 0)
293  LOADCHROMA(0);
294  PUTRGBA(dst_1, py_1, pa_1, 0, 24);
295  PUTRGBA(dst_2, py_2, pa_2, 0, 24);
296 
297  LOADCHROMA(1);
298  PUTRGBA(dst_2, py_2, pa_2, 1, 24);
299  PUTRGBA(dst_1, py_1, pa_1, 1, 24);
300  pa_1 += 4;
301  pa_2 += 4;
302 ENDYUV2RGBLINE(8, 1)
303  LOADCHROMA(0);
304  PUTRGBA(dst_1, py_1, pa_1, 0, 24);
305  PUTRGBA(dst_2, py_2, pa_2, 0, 24);
307 
308 #if HAVE_BIGENDIAN
309 YUV2RGBFUNC(yuva2rgba_c, uint32_t, 1)
310 #else
311 YUV2RGBFUNC(yuva2argb_c, uint32_t, 1)
312 #endif
313  LOADCHROMA(0);
314  PUTRGBA(dst_1, py_1, pa_1, 0, 0);
315  PUTRGBA(dst_2, py_2, pa_2, 0, 0);
316 
317  LOADCHROMA(1);
318  PUTRGBA(dst_2, py_2, pa_2, 1, 0);
319  PUTRGBA(dst_1, py_1, pa_1, 1, 0);
320 
321  LOADCHROMA(2);
322  PUTRGBA(dst_1, py_1, pa_1, 2, 0);
323  PUTRGBA(dst_2, py_2, pa_2, 2, 0);
324 
325  LOADCHROMA(3);
326  PUTRGBA(dst_2, py_2, pa_2, 3, 0);
327  PUTRGBA(dst_1, py_1, pa_1, 3, 0);
328  pa_1 += 8;
329  pa_2 += 8;
330 ENDYUV2RGBLINE(8, 0)
331  LOADCHROMA(0);
332  PUTRGBA(dst_1, py_1, pa_1, 0, 0);
333  PUTRGBA(dst_2, py_2, pa_2, 0, 0);
334 
335  LOADCHROMA(1);
336  PUTRGBA(dst_2, py_2, pa_2, 1, 0);
337  PUTRGBA(dst_1, py_1, pa_1, 1, 0);
338  pa_1 += 4;
339  pa_2 += 4;
340 ENDYUV2RGBLINE(8, 1)
341  LOADCHROMA(0);
342  PUTRGBA(dst_1, py_1, pa_1, 0, 0);
343  PUTRGBA(dst_2, py_2, pa_2, 0, 0);
345 
346 YUV2RGBFUNC(yuv2rgb_c_24_rgb, uint8_t, 0)
347  LOADCHROMA(0);
348  PUTRGB24(dst_1, py_1, 0);
349  PUTRGB24(dst_2, py_2, 0);
350 
351  LOADCHROMA(1);
352  PUTRGB24(dst_2, py_2, 1);
353  PUTRGB24(dst_1, py_1, 1);
354 
355  LOADCHROMA(2);
356  PUTRGB24(dst_1, py_1, 2);
357  PUTRGB24(dst_2, py_2, 2);
358 
359  LOADCHROMA(3);
360  PUTRGB24(dst_2, py_2, 3);
361  PUTRGB24(dst_1, py_1, 3);
362 ENDYUV2RGBLINE(24, 0)
363  LOADCHROMA(0);
364  PUTRGB24(dst_1, py_1, 0);
365  PUTRGB24(dst_2, py_2, 0);
366 
367  LOADCHROMA(1);
368  PUTRGB24(dst_2, py_2, 1);
369  PUTRGB24(dst_1, py_1, 1);
370 ENDYUV2RGBLINE(24, 1)
371  LOADCHROMA(0);
372  PUTRGB24(dst_1, py_1, 0);
373  PUTRGB24(dst_2, py_2, 0);
375 
376 // only trivial mods from yuv2rgb_c_24_rgb
377 YUV2RGBFUNC(yuv2rgb_c_24_bgr, uint8_t, 0)
378  LOADCHROMA(0);
379  PUTBGR24(dst_1, py_1, 0);
380  PUTBGR24(dst_2, py_2, 0);
381 
382  LOADCHROMA(1);
383  PUTBGR24(dst_2, py_2, 1);
384  PUTBGR24(dst_1, py_1, 1);
385 
386  LOADCHROMA(2);
387  PUTBGR24(dst_1, py_1, 2);
388  PUTBGR24(dst_2, py_2, 2);
389 
390  LOADCHROMA(3);
391  PUTBGR24(dst_2, py_2, 3);
392  PUTBGR24(dst_1, py_1, 3);
393 ENDYUV2RGBLINE(24, 0)
394  LOADCHROMA(0);
395  PUTBGR24(dst_1, py_1, 0);
396  PUTBGR24(dst_2, py_2, 0);
397 
398  LOADCHROMA(1);
399  PUTBGR24(dst_2, py_2, 1);
400  PUTBGR24(dst_1, py_1, 1);
401 ENDYUV2RGBLINE(24, 1)
402  LOADCHROMA(0);
403  PUTBGR24(dst_1, py_1, 0);
404  PUTBGR24(dst_2, py_2, 0);
406 
407 YUV2RGBFUNC(yuv2rgb_c_16_ordered_dither, uint16_t, 0)
408  const uint8_t *d16 = ff_dither_2x2_8[y & 1];
409  const uint8_t *e16 = ff_dither_2x2_4[y & 1];
410  const uint8_t *f16 = ff_dither_2x2_8[(y & 1)^1];
411 
412 #define PUTRGB16(dst, src, i, o) \
413  Y = src[2 * i]; \
414  dst[2 * i] = r[Y + d16[0 + o]] + \
415  g[Y + e16[0 + o]] + \
416  b[Y + f16[0 + o]]; \
417  Y = src[2 * i + 1]; \
418  dst[2 * i + 1] = r[Y + d16[1 + o]] + \
419  g[Y + e16[1 + o]] + \
420  b[Y + f16[1 + o]];
421  LOADCHROMA(0);
422  PUTRGB16(dst_1, py_1, 0, 0);
423  PUTRGB16(dst_2, py_2, 0, 0 + 8);
424 
425  LOADCHROMA(1);
426  PUTRGB16(dst_2, py_2, 1, 2 + 8);
427  PUTRGB16(dst_1, py_1, 1, 2);
428 
429  LOADCHROMA(2);
430  PUTRGB16(dst_1, py_1, 2, 4);
431  PUTRGB16(dst_2, py_2, 2, 4 + 8);
432 
433  LOADCHROMA(3);
434  PUTRGB16(dst_2, py_2, 3, 6 + 8);
435  PUTRGB16(dst_1, py_1, 3, 6);
437 
438 YUV2RGBFUNC(yuv2rgb_c_15_ordered_dither, uint16_t, 0)
439  const uint8_t *d16 = ff_dither_2x2_8[y & 1];
440  const uint8_t *e16 = ff_dither_2x2_8[(y & 1)^1];
441 
442 #define PUTRGB15(dst, src, i, o) \
443  Y = src[2 * i]; \
444  dst[2 * i] = r[Y + d16[0 + o]] + \
445  g[Y + d16[1 + o]] + \
446  b[Y + e16[0 + o]]; \
447  Y = src[2 * i + 1]; \
448  dst[2 * i + 1] = r[Y + d16[1 + o]] + \
449  g[Y + d16[0 + o]] + \
450  b[Y + e16[1 + o]];
451  LOADCHROMA(0);
452  PUTRGB15(dst_1, py_1, 0, 0);
453  PUTRGB15(dst_2, py_2, 0, 0 + 8);
454 
455  LOADCHROMA(1);
456  PUTRGB15(dst_2, py_2, 1, 2 + 8);
457  PUTRGB15(dst_1, py_1, 1, 2);
458 
459  LOADCHROMA(2);
460  PUTRGB15(dst_1, py_1, 2, 4);
461  PUTRGB15(dst_2, py_2, 2, 4 + 8);
462 
463  LOADCHROMA(3);
464  PUTRGB15(dst_2, py_2, 3, 6 + 8);
465  PUTRGB15(dst_1, py_1, 3, 6);
467 
468 // r, g, b, dst_1, dst_2
469 YUV2RGBFUNC(yuv2rgb_c_12_ordered_dither, uint16_t, 0)
470  const uint8_t *d16 = ff_dither_4x4_16[y & 3];
471 
472 #define PUTRGB12(dst, src, i, o) \
473  Y = src[2 * i]; \
474  dst[2 * i] = r[Y + d16[0 + o]] + \
475  g[Y + d16[0 + o]] + \
476  b[Y + d16[0 + o]]; \
477  Y = src[2 * i + 1]; \
478  dst[2 * i + 1] = r[Y + d16[1 + o]] + \
479  g[Y + d16[1 + o]] + \
480  b[Y + d16[1 + o]];
481 
482  LOADCHROMA(0);
483  PUTRGB12(dst_1, py_1, 0, 0);
484  PUTRGB12(dst_2, py_2, 0, 0 + 8);
485 
486  LOADCHROMA(1);
487  PUTRGB12(dst_2, py_2, 1, 2 + 8);
488  PUTRGB12(dst_1, py_1, 1, 2);
489 
490  LOADCHROMA(2);
491  PUTRGB12(dst_1, py_1, 2, 4);
492  PUTRGB12(dst_2, py_2, 2, 4 + 8);
493 
494  LOADCHROMA(3);
495  PUTRGB12(dst_2, py_2, 3, 6 + 8);
496  PUTRGB12(dst_1, py_1, 3, 6);
498 
499 // r, g, b, dst_1, dst_2
500 YUV2RGBFUNC(yuv2rgb_c_8_ordered_dither, uint8_t, 0)
501  const uint8_t *d32 = ff_dither_8x8_32[yd & 7];
502  const uint8_t *d64 = ff_dither_8x8_73[yd & 7];
503 
504 #define PUTRGB8(dst, src, i, o) \
505  Y = src[2 * i]; \
506  dst[2 * i] = r[Y + d32[0 + o]] + \
507  g[Y + d32[0 + o]] + \
508  b[Y + d64[0 + o]]; \
509  Y = src[2 * i + 1]; \
510  dst[2 * i + 1] = r[Y + d32[1 + o]] + \
511  g[Y + d32[1 + o]] + \
512  b[Y + d64[1 + o]];
513 
514  LOADCHROMA(0);
515  PUTRGB8(dst_1, py_1, 0, 0);
516  PUTRGB8(dst_2, py_2, 0, 0 + 8);
517 
518  LOADCHROMA(1);
519  PUTRGB8(dst_2, py_2, 1, 2 + 8);
520  PUTRGB8(dst_1, py_1, 1, 2);
521 
522  LOADCHROMA(2);
523  PUTRGB8(dst_1, py_1, 2, 4);
524  PUTRGB8(dst_2, py_2, 2, 4 + 8);
525 
526  LOADCHROMA(3);
527  PUTRGB8(dst_2, py_2, 3, 6 + 8);
528  PUTRGB8(dst_1, py_1, 3, 6);
529 
530 ENDYUV2RGBLINE(8, 0)
531  const uint8_t *d32 = ff_dither_8x8_32[yd & 7];
532  const uint8_t *d64 = ff_dither_8x8_73[yd & 7];
533  LOADCHROMA(0);
534  PUTRGB8(dst_1, py_1, 0, 0);
535  PUTRGB8(dst_2, py_2, 0, 0 + 8);
536 
537  LOADCHROMA(1);
538  PUTRGB8(dst_2, py_2, 1, 2 + 8);
539  PUTRGB8(dst_1, py_1, 1, 2);
540 
541 ENDYUV2RGBLINE(8, 1)
542  const uint8_t *d32 = ff_dither_8x8_32[yd & 7];
543  const uint8_t *d64 = ff_dither_8x8_73[yd & 7];
544  LOADCHROMA(0);
545  PUTRGB8(dst_1, py_1, 0, 0);
546  PUTRGB8(dst_2, py_2, 0, 0 + 8);
547 
549 
550 
551 YUV2RGBFUNC(yuv2rgb_c_4_ordered_dither, uint8_t, 0)
552  const uint8_t * d64 = ff_dither_8x8_73[yd & 7];
553  const uint8_t *d128 = ff_dither_8x8_220[yd & 7];
554  int acc;
555 
556 #define PUTRGB4D(dst, src, i, o) \
557  Y = src[2 * i]; \
558  acc = r[Y + d128[0 + o]] + \
559  g[Y + d64[0 + o]] + \
560  b[Y + d128[0 + o]]; \
561  Y = src[2 * i + 1]; \
562  acc |= (r[Y + d128[1 + o]] + \
563  g[Y + d64[1 + o]] + \
564  b[Y + d128[1 + o]]) << 4; \
565  dst[i] = acc;
566 
567  LOADCHROMA(0);
568  PUTRGB4D(dst_1, py_1, 0, 0);
569  PUTRGB4D(dst_2, py_2, 0, 0 + 8);
570 
571  LOADCHROMA(1);
572  PUTRGB4D(dst_2, py_2, 1, 2 + 8);
573  PUTRGB4D(dst_1, py_1, 1, 2);
574 
575  LOADCHROMA(2);
576  PUTRGB4D(dst_1, py_1, 2, 4);
577  PUTRGB4D(dst_2, py_2, 2, 4 + 8);
578 
579  LOADCHROMA(3);
580  PUTRGB4D(dst_2, py_2, 3, 6 + 8);
581  PUTRGB4D(dst_1, py_1, 3, 6);
582 
583 ENDYUV2RGBLINE(4, 0)
584  const uint8_t * d64 = ff_dither_8x8_73[yd & 7];
585  const uint8_t *d128 = ff_dither_8x8_220[yd & 7];
586  int acc;
587  LOADCHROMA(0);
588  PUTRGB4D(dst_1, py_1, 0, 0);
589  PUTRGB4D(dst_2, py_2, 0, 0 + 8);
590 
591  LOADCHROMA(1);
592  PUTRGB4D(dst_2, py_2, 1, 2 + 8);
593  PUTRGB4D(dst_1, py_1, 1, 2);
594 
595 ENDYUV2RGBLINE(4, 1)
596  const uint8_t * d64 = ff_dither_8x8_73[yd & 7];
597  const uint8_t *d128 = ff_dither_8x8_220[yd & 7];
598  int acc;
599  LOADCHROMA(0);
600  PUTRGB4D(dst_1, py_1, 0, 0);
601  PUTRGB4D(dst_2, py_2, 0, 0 + 8);
603 
604 YUV2RGBFUNC(yuv2rgb_c_4b_ordered_dither, uint8_t, 0)
605  const uint8_t *d64 = ff_dither_8x8_73[yd & 7];
606  const uint8_t *d128 = ff_dither_8x8_220[yd & 7];
607 
608 #define PUTRGB4DB(dst, src, i, o) \
609  Y = src[2 * i]; \
610  dst[2 * i] = r[Y + d128[0 + o]] + \
611  g[Y + d64[0 + o]] + \
612  b[Y + d128[0 + o]]; \
613  Y = src[2 * i + 1]; \
614  dst[2 * i + 1] = r[Y + d128[1 + o]] + \
615  g[Y + d64[1 + o]] + \
616  b[Y + d128[1 + o]];
617 
618  LOADCHROMA(0);
619  PUTRGB4DB(dst_1, py_1, 0, 0);
620  PUTRGB4DB(dst_2, py_2, 0, 0 + 8);
621 
622  LOADCHROMA(1);
623  PUTRGB4DB(dst_2, py_2, 1, 2 + 8);
624  PUTRGB4DB(dst_1, py_1, 1, 2);
625 
626  LOADCHROMA(2);
627  PUTRGB4DB(dst_1, py_1, 2, 4);
628  PUTRGB4DB(dst_2, py_2, 2, 4 + 8);
629 
630  LOADCHROMA(3);
631  PUTRGB4DB(dst_2, py_2, 3, 6 + 8);
632  PUTRGB4DB(dst_1, py_1, 3, 6);
633 ENDYUV2RGBLINE(8, 0)
634  const uint8_t *d64 = ff_dither_8x8_73[yd & 7];
635  const uint8_t *d128 = ff_dither_8x8_220[yd & 7];
636  LOADCHROMA(0);
637  PUTRGB4DB(dst_1, py_1, 0, 0);
638  PUTRGB4DB(dst_2, py_2, 0, 0 + 8);
639 
640  LOADCHROMA(1);
641  PUTRGB4DB(dst_2, py_2, 1, 2 + 8);
642  PUTRGB4DB(dst_1, py_1, 1, 2);
643 ENDYUV2RGBLINE(8, 1)
644  const uint8_t *d64 = ff_dither_8x8_73[yd & 7];
645  const uint8_t *d128 = ff_dither_8x8_220[yd & 7];
646  LOADCHROMA(0);
647  PUTRGB4DB(dst_1, py_1, 0, 0);
648  PUTRGB4DB(dst_2, py_2, 0, 0 + 8);
650 
651 YUV2RGBFUNC(yuv2rgb_c_1_ordered_dither, uint8_t, 0)
652  const uint8_t *d128 = ff_dither_8x8_220[yd & 7];
653  char out_1 = 0, out_2 = 0;
654  g = c->table_gU[128 + YUVRGB_TABLE_HEADROOM] + c->table_gV[128 + YUVRGB_TABLE_HEADROOM];
655 
656 #define PUTRGB1(out, src, i, o) \
657  Y = src[2 * i]; \
658  out += out + g[Y + d128[0 + o]]; \
659  Y = src[2 * i + 1]; \
660  out += out + g[Y + d128[1 + o]];
661 
662  PUTRGB1(out_1, py_1, 0, 0);
663  PUTRGB1(out_2, py_2, 0, 0 + 8);
664 
665  PUTRGB1(out_2, py_2, 1, 2 + 8);
666  PUTRGB1(out_1, py_1, 1, 2);
667 
668  PUTRGB1(out_1, py_1, 2, 4);
669  PUTRGB1(out_2, py_2, 2, 4 + 8);
670 
671  PUTRGB1(out_2, py_2, 3, 6 + 8);
672  PUTRGB1(out_1, py_1, 3, 6);
673 
674  dst_1[0] = out_1;
675  dst_2[0] = out_2;
677 
679 {
680  SwsFunc t = NULL;
681 
682 #if ARCH_PPC
683  t = ff_yuv2rgb_init_ppc(c);
684 #elif ARCH_X86
685  t = ff_yuv2rgb_init_x86(c);
686 #elif ARCH_LOONGARCH64
688 #endif
689 
690  if (t)
691  return t;
692 
694  "No accelerated colorspace conversion found from %s to %s.\n",
695  av_get_pix_fmt_name(c->srcFormat), av_get_pix_fmt_name(c->dstFormat));
696 
697  switch (c->dstFormat) {
698  case AV_PIX_FMT_BGR48BE:
699  case AV_PIX_FMT_BGR48LE:
700  return yuv2rgb_c_bgr48;
701  case AV_PIX_FMT_RGB48BE:
702  case AV_PIX_FMT_RGB48LE:
703  return yuv2rgb_c_48;
704  case AV_PIX_FMT_ARGB:
705  case AV_PIX_FMT_ABGR:
706  if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat))
707  return yuva2argb_c;
708  case AV_PIX_FMT_RGBA:
709  case AV_PIX_FMT_BGRA:
710  return (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) ? yuva2rgba_c : yuv2rgb_c_32;
711  case AV_PIX_FMT_RGB24:
712  return yuv2rgb_c_24_rgb;
713  case AV_PIX_FMT_BGR24:
714  return yuv2rgb_c_24_bgr;
715  case AV_PIX_FMT_RGB565:
716  case AV_PIX_FMT_BGR565:
717  return yuv2rgb_c_16_ordered_dither;
718  case AV_PIX_FMT_RGB555:
719  case AV_PIX_FMT_BGR555:
720  return yuv2rgb_c_15_ordered_dither;
721  case AV_PIX_FMT_RGB444:
722  case AV_PIX_FMT_BGR444:
723  return yuv2rgb_c_12_ordered_dither;
724  case AV_PIX_FMT_RGB8:
725  case AV_PIX_FMT_BGR8:
726  return yuv2rgb_c_8_ordered_dither;
727  case AV_PIX_FMT_RGB4:
728  case AV_PIX_FMT_BGR4:
729  return yuv2rgb_c_4_ordered_dither;
732  return yuv2rgb_c_4b_ordered_dither;
734  return yuv2rgb_c_1_ordered_dither;
735  }
736  return NULL;
737 }
738 
739 static void fill_table(uint8_t* table[256 + 2*YUVRGB_TABLE_HEADROOM], const int elemsize,
740  const int64_t inc, void *y_tab)
741 {
742  int i;
743  uint8_t *y_table = y_tab;
744 
745  y_table -= elemsize * (inc >> 9);
746 
747  for (i = 0; i < 256 + 2*YUVRGB_TABLE_HEADROOM; i++) {
749  table[i] = y_table + elemsize * (cb >> 16);
750  }
751 }
752 
753 static void fill_gv_table(int table[256 + 2*YUVRGB_TABLE_HEADROOM], const int elemsize, const int64_t inc)
754 {
755  int i;
756  int off = -(inc >> 9);
757 
758  for (i = 0; i < 256 + 2*YUVRGB_TABLE_HEADROOM; i++) {
760  table[i] = elemsize * (off + (cb >> 16));
761  }
762 }
763 
764 static uint16_t roundToInt16(int64_t f)
765 {
766  int r = (f + (1 << 15)) >> 16;
767 
768  if (r < -0x7FFF)
769  return 0x8000;
770  else if (r > 0x7FFF)
771  return 0x7FFF;
772  else
773  return r;
774 }
775 
776 av_cold int ff_yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4],
777  int fullRange, int brightness,
778  int contrast, int saturation)
779 {
780  const int isRgb = c->dstFormat == AV_PIX_FMT_RGB32 ||
781  c->dstFormat == AV_PIX_FMT_RGB32_1 ||
782  c->dstFormat == AV_PIX_FMT_BGR24 ||
783  c->dstFormat == AV_PIX_FMT_RGB565BE ||
784  c->dstFormat == AV_PIX_FMT_RGB565LE ||
785  c->dstFormat == AV_PIX_FMT_RGB555BE ||
786  c->dstFormat == AV_PIX_FMT_RGB555LE ||
787  c->dstFormat == AV_PIX_FMT_RGB444BE ||
788  c->dstFormat == AV_PIX_FMT_RGB444LE ||
789  c->dstFormat == AV_PIX_FMT_X2RGB10BE ||
790  c->dstFormat == AV_PIX_FMT_X2RGB10LE ||
791  c->dstFormat == AV_PIX_FMT_RGB8 ||
792  c->dstFormat == AV_PIX_FMT_RGB4 ||
793  c->dstFormat == AV_PIX_FMT_RGB4_BYTE ||
794  c->dstFormat == AV_PIX_FMT_MONOBLACK;
795  const int isNotNe = c->dstFormat == AV_PIX_FMT_NE(RGB565LE, RGB565BE) ||
796  c->dstFormat == AV_PIX_FMT_NE(RGB555LE, RGB555BE) ||
797  c->dstFormat == AV_PIX_FMT_NE(RGB444LE, RGB444BE) ||
798  c->dstFormat == AV_PIX_FMT_NE(BGR565LE, BGR565BE) ||
799  c->dstFormat == AV_PIX_FMT_NE(BGR555LE, BGR555BE) ||
800  c->dstFormat == AV_PIX_FMT_NE(BGR444LE, BGR444BE) ||
801  c->dstFormat == AV_PIX_FMT_NE(X2RGB10LE, X2RGB10BE) ||
802  c->dstFormat == AV_PIX_FMT_NE(X2BGR10LE, X2BGR10BE);
803  const int bpp = c->dstFormatBpp;
804  uint8_t *y_table;
805  uint16_t *y_table16;
806  uint32_t *y_table32;
807  int i, base, rbase, gbase, bbase, av_uninit(abase), needAlpha;
808  const int yoffs = (fullRange ? 384 : 326) + YUVRGB_TABLE_LUMA_HEADROOM;
809  const int table_plane_size = 1024 + 2*YUVRGB_TABLE_LUMA_HEADROOM;
810 
811  int64_t crv = inv_table[0];
812  int64_t cbu = inv_table[1];
813  int64_t cgu = -inv_table[2];
814  int64_t cgv = -inv_table[3];
815  int64_t cy = 1 << 16;
816  int64_t oy = 0;
817  int64_t yb = 0;
818 
819  if (!fullRange) {
820  cy = (cy * 255) / 219;
821  oy = 16 << 16;
822  } else {
823  crv = (crv * 224) / 255;
824  cbu = (cbu * 224) / 255;
825  cgu = (cgu * 224) / 255;
826  cgv = (cgv * 224) / 255;
827  }
828 
829  cy = (cy * contrast) >> 16;
830  crv = (crv * contrast * saturation) >> 32;
831  cbu = (cbu * contrast * saturation) >> 32;
832  cgu = (cgu * contrast * saturation) >> 32;
833  cgv = (cgv * contrast * saturation) >> 32;
834  oy -= 256LL * brightness;
835 
836  c->uOffset = 0x0400040004000400LL;
837  c->vOffset = 0x0400040004000400LL;
838  c->yCoeff = roundToInt16(cy * (1 << 13)) * 0x0001000100010001ULL;
839  c->vrCoeff = roundToInt16(crv * (1 << 13)) * 0x0001000100010001ULL;
840  c->ubCoeff = roundToInt16(cbu * (1 << 13)) * 0x0001000100010001ULL;
841  c->vgCoeff = roundToInt16(cgv * (1 << 13)) * 0x0001000100010001ULL;
842  c->ugCoeff = roundToInt16(cgu * (1 << 13)) * 0x0001000100010001ULL;
843  c->yOffset = roundToInt16(oy * (1 << 3)) * 0x0001000100010001ULL;
844 
845  c->yuv2rgb_y_coeff = (int16_t)roundToInt16(cy * (1 << 13));
846  c->yuv2rgb_y_offset = (int16_t)roundToInt16(oy * (1 << 9));
847  c->yuv2rgb_v2r_coeff = (int16_t)roundToInt16(crv * (1 << 13));
848  c->yuv2rgb_v2g_coeff = (int16_t)roundToInt16(cgv * (1 << 13));
849  c->yuv2rgb_u2g_coeff = (int16_t)roundToInt16(cgu * (1 << 13));
850  c->yuv2rgb_u2b_coeff = (int16_t)roundToInt16(cbu * (1 << 13));
851 
852  //scale coefficients by cy
853  crv = ((crv * (1 << 16)) + 0x8000) / FFMAX(cy, 1);
854  cbu = ((cbu * (1 << 16)) + 0x8000) / FFMAX(cy, 1);
855  cgu = ((cgu * (1 << 16)) + 0x8000) / FFMAX(cy, 1);
856  cgv = ((cgv * (1 << 16)) + 0x8000) / FFMAX(cy, 1);
857 
858  av_freep(&c->yuvTable);
859 
860 #define ALLOC_YUV_TABLE(x) \
861  c->yuvTable = av_malloc(x); \
862  if (!c->yuvTable) \
863  return AVERROR(ENOMEM);
864  switch (bpp) {
865  case 1:
866  ALLOC_YUV_TABLE(table_plane_size);
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  y_table[i + 110] = av_clip_uint8((yb + 0x8000) >> 16) >> 7;
871  yb += cy;
872  }
873  fill_table(c->table_gU, 1, cgu, y_table + yoffs);
874  fill_gv_table(c->table_gV, 1, cgv);
875  break;
876  case 4:
877  case 4 | 128:
878  rbase = isRgb ? 3 : 0;
879  gbase = 1;
880  bbase = isRgb ? 0 : 3;
881  ALLOC_YUV_TABLE(table_plane_size * 3);
882  y_table = c->yuvTable;
883  yb = -(384 << 16) - YUVRGB_TABLE_LUMA_HEADROOM*cy - oy;
884  for (i = 0; i < table_plane_size - 110; i++) {
885  int yval = av_clip_uint8((yb + 0x8000) >> 16);
886  y_table[i + 110] = (yval >> 7) << rbase;
887  y_table[i + 37 + table_plane_size] = ((yval + 43) / 85) << gbase;
888  y_table[i + 110 + 2*table_plane_size] = (yval >> 7) << bbase;
889  yb += cy;
890  }
891  fill_table(c->table_rV, 1, crv, y_table + yoffs);
892  fill_table(c->table_gU, 1, cgu, y_table + yoffs + table_plane_size);
893  fill_table(c->table_bU, 1, cbu, y_table + yoffs + 2*table_plane_size);
894  fill_gv_table(c->table_gV, 1, cgv);
895  break;
896  case 8:
897  rbase = isRgb ? 5 : 0;
898  gbase = isRgb ? 2 : 3;
899  bbase = isRgb ? 0 : 6;
900  ALLOC_YUV_TABLE(table_plane_size * 3);
901  y_table = c->yuvTable;
902  yb = -(384 << 16) - YUVRGB_TABLE_LUMA_HEADROOM*cy - oy;
903  for (i = 0; i < table_plane_size - 38; i++) {
904  int yval = av_clip_uint8((yb + 0x8000) >> 16);
905  y_table[i + 16] = ((yval + 18) / 36) << rbase;
906  y_table[i + 16 + table_plane_size] = ((yval + 18) / 36) << gbase;
907  y_table[i + 37 + 2*table_plane_size] = ((yval + 43) / 85) << bbase;
908  yb += cy;
909  }
910  fill_table(c->table_rV, 1, crv, y_table + yoffs);
911  fill_table(c->table_gU, 1, cgu, y_table + yoffs + table_plane_size);
912  fill_table(c->table_bU, 1, cbu, y_table + yoffs + 2*table_plane_size);
913  fill_gv_table(c->table_gV, 1, cgv);
914  break;
915  case 12:
916  rbase = isRgb ? 8 : 0;
917  gbase = 4;
918  bbase = isRgb ? 0 : 8;
919  ALLOC_YUV_TABLE(table_plane_size * 3 * 2);
920  y_table16 = c->yuvTable;
921  yb = -(384 << 16) - YUVRGB_TABLE_LUMA_HEADROOM*cy - oy;
922  for (i = 0; i < table_plane_size; i++) {
923  uint8_t yval = av_clip_uint8((yb + 0x8000) >> 16);
924  y_table16[i] = (yval >> 4) << rbase;
925  y_table16[i + table_plane_size] = (yval >> 4) << gbase;
926  y_table16[i + 2*table_plane_size] = (yval >> 4) << bbase;
927  yb += cy;
928  }
929  if (isNotNe)
930  for (i = 0; i < table_plane_size * 3; i++)
931  y_table16[i] = av_bswap16(y_table16[i]);
932  fill_table(c->table_rV, 2, crv, y_table16 + yoffs);
933  fill_table(c->table_gU, 2, cgu, y_table16 + yoffs + table_plane_size);
934  fill_table(c->table_bU, 2, cbu, y_table16 + yoffs + 2*table_plane_size);
935  fill_gv_table(c->table_gV, 2, cgv);
936  break;
937  case 15:
938  case 16:
939  rbase = isRgb ? bpp - 5 : 0;
940  gbase = 5;
941  bbase = isRgb ? 0 : (bpp - 5);
942  ALLOC_YUV_TABLE(table_plane_size * 3 * 2);
943  y_table16 = c->yuvTable;
944  yb = -(384 << 16) - YUVRGB_TABLE_LUMA_HEADROOM*cy - oy;
945  for (i = 0; i < table_plane_size; i++) {
946  uint8_t yval = av_clip_uint8((yb + 0x8000) >> 16);
947  y_table16[i] = (yval >> 3) << rbase;
948  y_table16[i + table_plane_size] = (yval >> (18 - bpp)) << gbase;
949  y_table16[i + 2*table_plane_size] = (yval >> 3) << bbase;
950  yb += cy;
951  }
952  if (isNotNe)
953  for (i = 0; i < table_plane_size * 3; i++)
954  y_table16[i] = av_bswap16(y_table16[i]);
955  fill_table(c->table_rV, 2, crv, y_table16 + yoffs);
956  fill_table(c->table_gU, 2, cgu, y_table16 + yoffs + table_plane_size);
957  fill_table(c->table_bU, 2, cbu, y_table16 + yoffs + 2*table_plane_size);
958  fill_gv_table(c->table_gV, 2, cgv);
959  break;
960  case 24:
961  case 48:
962  ALLOC_YUV_TABLE(table_plane_size);
963  y_table = c->yuvTable;
964  yb = -(384 << 16) - YUVRGB_TABLE_LUMA_HEADROOM*cy - oy;
965  for (i = 0; i < table_plane_size; i++) {
966  y_table[i] = av_clip_uint8((yb + 0x8000) >> 16);
967  yb += cy;
968  }
969  fill_table(c->table_rV, 1, crv, y_table + yoffs);
970  fill_table(c->table_gU, 1, cgu, y_table + yoffs);
971  fill_table(c->table_bU, 1, cbu, y_table + yoffs);
972  fill_gv_table(c->table_gV, 1, cgv);
973  break;
974  case 30:
975  rbase = isRgb ? 20 : 0;
976  gbase = 10;
977  bbase = isRgb ? 0 : 20;
978  needAlpha = CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat);
979  if (!needAlpha)
980  abase = 30;
981  ALLOC_YUV_TABLE(table_plane_size * 3 * 4);
982  y_table32 = c->yuvTable;
983  yb = -(384 << 16) - YUVRGB_TABLE_LUMA_HEADROOM*cy - oy;
984  for (i = 0; i < table_plane_size; i++) {
985  unsigned yval = av_clip_uintp2((yb + 0x8000) >> 14, 10);
986  y_table32[i]= (yval << rbase) + (needAlpha ? 0 : (255u << abase));
987  y_table32[i + table_plane_size] = yval << gbase;
988  y_table32[i + 2 * table_plane_size] = yval << bbase;
989  yb += cy;
990  }
991  if (isNotNe) {
992  for (i = 0; i < table_plane_size * 3; i++)
993  y_table32[i] = av_bswap32(y_table32[i]);
994  }
995  fill_table(c->table_rV, 4, crv, y_table32 + yoffs);
996  fill_table(c->table_gU, 4, cgu, y_table32 + yoffs + table_plane_size);
997  fill_table(c->table_bU, 4, cbu, y_table32 + yoffs + 2 * table_plane_size);
998  fill_gv_table(c->table_gV, 4, cgv);
999  break;
1000  case 32:
1001  case 64:
1002  base = (c->dstFormat == AV_PIX_FMT_RGB32_1 ||
1003  c->dstFormat == AV_PIX_FMT_BGR32_1) ? 8 : 0;
1004  rbase = base + (isRgb ? 16 : 0);
1005  gbase = base + 8;
1006  bbase = base + (isRgb ? 0 : 16);
1007  needAlpha = CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat);
1008  if (!needAlpha)
1009  abase = (base + 24) & 31;
1010  ALLOC_YUV_TABLE(table_plane_size * 3 * 4);
1011  y_table32 = c->yuvTable;
1012  yb = -(384 << 16) - YUVRGB_TABLE_LUMA_HEADROOM*cy - oy;
1013  for (i = 0; i < table_plane_size; i++) {
1014  unsigned yval = av_clip_uint8((yb + 0x8000) >> 16);
1015  y_table32[i] = (yval << rbase) +
1016  (needAlpha ? 0 : (255u << abase));
1017  y_table32[i + table_plane_size] = yval << gbase;
1018  y_table32[i + 2*table_plane_size] = yval << bbase;
1019  yb += cy;
1020  }
1021  fill_table(c->table_rV, 4, crv, y_table32 + yoffs);
1022  fill_table(c->table_gU, 4, cgu, y_table32 + yoffs + table_plane_size);
1023  fill_table(c->table_bU, 4, cbu, y_table32 + yoffs + 2*table_plane_size);
1024  fill_gv_table(c->table_gV, 4, cgv);
1025  break;
1026  default:
1027  if(!isPlanar(c->dstFormat) || bpp <= 24)
1028  av_log(c, AV_LOG_ERROR, "%ibpp not supported by yuv2rgb\n", bpp);
1029  return AVERROR(EINVAL);
1030  }
1031  return 0;
1032 }
PUTRGB1
#define PUTRGB1(out, src, i, o)
Definition: yuv2rgb.c:656
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
AV_PIX_FMT_BGR48LE
@ AV_PIX_FMT_BGR48LE
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:146
ff_dither_4x4_16
const uint8_t ff_dither_4x4_16[][8]
Definition: output.c:51
r
const char * r
Definition: vf_curves.c:126
acc
int acc
Definition: yuv2rgb.c:554
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
fill_table
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:739
LOADCHROMA
#define LOADCHROMA(i)
Definition: yuv2rgb.c:69
cb
static double cb(void *priv, double x, double y)
Definition: vf_geq.c:241
AV_PIX_FMT_RGB444LE
@ AV_PIX_FMT_RGB444LE
packed RGB 4:4:4, 16bpp, (msb)4X 4R 4G 4B(lsb), little-endian, X=unused/undefined
Definition: pixfmt.h:136
u
#define u(width, name, range_min, range_max)
Definition: cbs_h2645.c:250
ff_dither_8x8_32
const uint8_t ff_dither_8x8_32[][8]
Definition: output.c:59
av_clip_uintp2
#define av_clip_uintp2
Definition: common.h:122
out_2
char out_2
Definition: yuv2rgb.c:653
int64_t
long long int64_t
Definition: coverity.c:34
pixdesc.h
table
static const uint16_t table[]
Definition: prosumer.c:205
e16
const uint8_t * e16
Definition: yuv2rgb.c:409
AV_PIX_FMT_RGB32_1
#define AV_PIX_FMT_RGB32_1
Definition: pixfmt.h:452
base
uint8_t base
Definition: vp3data.h:128
AV_PIX_FMT_BGR24
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:76
AV_PIX_FMT_BGRA
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition: pixfmt.h:102
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
PUTRGB
#define PUTRGB(dst, src, i)
Definition: yuv2rgb.c:76
AV_PIX_FMT_RGB555BE
@ AV_PIX_FMT_RGB555BE
packed RGB 5:5:5, 16bpp, (msb)1X 5R 5G 5B(lsb), big-endian , X=unused/undefined
Definition: pixfmt.h:114
pa_1
pa_1
Definition: yuv2rgb.c:290
SwsFunc
int(* SwsFunc)(struct SwsContext *context, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[])
Definition: swscale_internal.h:99
ff_yuv2rgb_init_x86
av_cold SwsFunc ff_yuv2rgb_init_x86(SwsContext *c)
Definition: yuv2rgb.c:68
ENDYUV2RGBFUNC
#define ENDYUV2RGBFUNC()
Definition: yuv2rgb.c:170
ff_yuv2rgb_init_loongarch
av_cold SwsFunc ff_yuv2rgb_init_loongarch(SwsContext *c)
Definition: swscale_init_loongarch.c:91
PUTRGBA
#define PUTRGBA(dst, ysrc, asrc, i, s)
Definition: yuv2rgb.c:102
ALLOC_YUV_TABLE
#define ALLOC_YUV_TABLE(x)
YUV2RGBFUNC
#define YUV2RGBFUNC(func_name, dst_type, alpha)
Definition: yuv2rgb.c:128
AV_PIX_FMT_BGR8
@ AV_PIX_FMT_BGR8
packed RGB 3:3:2, 8bpp, (msb)2B 3G 3R(lsb)
Definition: pixfmt.h:90
PUTBGR24
#define PUTBGR24(dst, src, i)
Definition: yuv2rgb.c:92
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
av_cold
#define av_cold
Definition: attributes.h:90
YUVRGB_TABLE_HEADROOM
#define YUVRGB_TABLE_HEADROOM
Definition: swscale_internal.h:42
ff_dither_2x2_4
const uint8_t ff_dither_2x2_4[][8]
Definition: output.c:39
ff_dither_8x8_220
const uint8_t ff_dither_8x8_220[][8]
Definition: output.c:84
AV_PIX_FMT_RGB4
@ AV_PIX_FMT_RGB4
packed RGB 1:2:1 bitstream, 4bpp, (msb)1R 2G 1B(lsb), a byte contains two pixels, the first pixel in ...
Definition: pixfmt.h:94
AV_PIX_FMT_BGR32_1
#define AV_PIX_FMT_BGR32_1
Definition: pixfmt.h:454
AV_PIX_FMT_RGBA
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:100
fill_gv_table
static void fill_gv_table(int table[256+2 *YUVRGB_TABLE_HEADROOM], const int elemsize, const int64_t inc)
Definition: yuv2rgb.c:753
PUTRGB4D
#define PUTRGB4D(dst, src, i, o)
Definition: yuv2rgb.c:556
ff_yuv2rgb_coeffs
const int32_t ff_yuv2rgb_coeffs[11][4]
Definition: yuv2rgb.c:48
AV_PIX_FMT_RGB565LE
@ AV_PIX_FMT_RGB565LE
packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), little-endian
Definition: pixfmt.h:113
PUTRGB16
#define PUTRGB16(dst, src, i, o)
Definition: yuv2rgb.c:412
NULL
#define NULL
Definition: coverity.c:32
d16
const uint8_t * d16
Definition: yuv2rgb.c:408
AV_PIX_FMT_RGB48LE
@ AV_PIX_FMT_RGB48LE
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:110
AV_PIX_FMT_MONOBLACK
@ AV_PIX_FMT_MONOBLACK
Y , 1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb.
Definition: pixfmt.h:83
AV_PIX_FMT_RGB8
@ AV_PIX_FMT_RGB8
packed RGB 3:3:2, 8bpp, (msb)3R 3G 2B(lsb)
Definition: pixfmt.h:93
AV_PIX_FMT_BGR4
@ AV_PIX_FMT_BGR4
packed RGB 1:2:1 bitstream, 4bpp, (msb)1B 2G 1R(lsb), a byte contains two pixels, the first pixel in ...
Definition: pixfmt.h:91
AV_PIX_FMT_NE
#define AV_PIX_FMT_NE(be, le)
Definition: pixfmt.h:448
AV_PIX_FMT_ABGR
@ AV_PIX_FMT_ABGR
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
Definition: pixfmt.h:101
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
AV_PIX_FMT_BGR4_BYTE
@ AV_PIX_FMT_BGR4_BYTE
packed RGB 1:2:1, 8bpp, (msb)1B 2G 1R(lsb)
Definition: pixfmt.h:92
AV_PIX_FMT_X2RGB10LE
@ AV_PIX_FMT_X2RGB10LE
packed RGB 10:10:10, 30bpp, (msb)2X 10R 10G 10B(lsb), little-endian, X=unused/undefined
Definition: pixfmt.h:384
PUTBGR48
#define PUTBGR48(dst, src, i)
Definition: yuv2rgb.c:118
d64
const uint8_t * d64
Definition: yuv2rgb.c:502
f
f
Definition: af_crystalizer.c:121
AV_PIX_FMT_RGB24
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:75
g
g
Definition: yuv2rgb.c:654
av_bswap32
#define av_bswap32
Definition: bswap.h:28
AV_PIX_FMT_RGB444BE
@ AV_PIX_FMT_RGB444BE
packed RGB 4:4:4, 16bpp, (msb)4X 4R 4G 4B(lsb), big-endian, X=unused/undefined
Definition: pixfmt.h:137
AV_PIX_FMT_BGR555
#define AV_PIX_FMT_BGR555
Definition: pixfmt.h:471
PUTRGB12
#define PUTRGB12(dst, src, i, o)
Definition: yuv2rgb.c:472
AV_PIX_FMT_RGB32
#define AV_PIX_FMT_RGB32
Definition: pixfmt.h:451
roundToInt16
static uint16_t roundToInt16(int64_t f)
Definition: yuv2rgb.c:764
ff_yuv2rgb_init_ppc
av_cold SwsFunc ff_yuv2rgb_init_ppc(SwsContext *c)
Definition: yuv2rgb_altivec.c:535
ff_dither_8x8_73
const uint8_t ff_dither_8x8_73[][8]
Definition: output.c:71
AV_PIX_FMT_ARGB
@ AV_PIX_FMT_ARGB
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
Definition: pixfmt.h:99
PUTRGB4DB
#define PUTRGB4DB(dst, src, i, o)
Definition: yuv2rgb.c:608
f16
const uint8_t * f16
Definition: yuv2rgb.c:410
pa_2
pa_2
Definition: yuv2rgb.c:291
AV_PIX_FMT_RGB555LE
@ AV_PIX_FMT_RGB555LE
packed RGB 5:5:5, 16bpp, (msb)1X 5R 5G 5B(lsb), little-endian, X=unused/undefined
Definition: pixfmt.h:115
CLOSEYUV2RGBFUNC
#define CLOSEYUV2RGBFUNC(dst_delta)
Definition: yuv2rgb.c:176
AV_PIX_FMT_RGB48BE
@ AV_PIX_FMT_RGB48BE
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:109
ff_yuv2rgb_get_func_ptr
SwsFunc ff_yuv2rgb_get_func_ptr(SwsContext *c)
Definition: yuv2rgb.c:678
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:255
AV_PIX_FMT_BGR444
#define AV_PIX_FMT_BGR444
Definition: pixfmt.h:472
AV_PIX_FMT_RGB555
#define AV_PIX_FMT_RGB555
Definition: pixfmt.h:466
swscale_internal.h
AV_PIX_FMT_X2RGB10BE
@ AV_PIX_FMT_X2RGB10BE
packed RGB 10:10:10, 30bpp, (msb)2X 10R 10G 10B(lsb), big-endian, X=unused/undefined
Definition: pixfmt.h:385
AV_PIX_FMT_BGR565
#define AV_PIX_FMT_BGR565
Definition: pixfmt.h:470
AV_PIX_FMT_RGB4_BYTE
@ AV_PIX_FMT_RGB4_BYTE
packed RGB 1:2:1, 8bpp, (msb)1R 2G 1B(lsb)
Definition: pixfmt.h:95
AV_PIX_FMT_RGB565
#define AV_PIX_FMT_RGB565
Definition: pixfmt.h:465
ff_yuv2rgb_c_init_tables
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:776
SWS_CS_DEFAULT
#define SWS_CS_DEFAULT
Definition: swscale.h:102
YUVRGB_TABLE_LUMA_HEADROOM
#define YUVRGB_TABLE_LUMA_HEADROOM
Definition: swscale_internal.h:43
av_uninit
#define av_uninit(x)
Definition: attributes.h:154
bswap.h
PUTRGB8
#define PUTRGB8(dst, src, i, o)
Definition: yuv2rgb.c:504
d128
const uint8_t * d128
Definition: yuv2rgb.c:553
PUTRGB24
#define PUTRGB24(dst, src, i)
Definition: yuv2rgb.c:82
PUTRGB48
#define PUTRGB48(dst, src, i)
Definition: yuv2rgb.c:108
av_clip_uint8
#define av_clip_uint8
Definition: common.h:104
AV_PIX_FMT_RGB565BE
@ AV_PIX_FMT_RGB565BE
packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), big-endian
Definition: pixfmt.h:112
d32
const uint8_t * d32
Definition: yuv2rgb.c:501
sws_getCoefficients
const int * sws_getCoefficients(int colorspace)
Return a pointer to yuv<->rgb coefficients for the given colorspace suitable for sws_setColorspaceDet...
Definition: yuv2rgb.c:62
dst_2
dst_2[0]
Definition: yuv2rgb.c:675
ENDYUV2RGBLINE
#define ENDYUV2RGBLINE(dst_delta, ss)
Definition: yuv2rgb.c:159
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
int32_t
int32_t
Definition: audioconvert.c:56
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
out_1
char out_1
Definition: yuv2rgb.c:653
isPlanar
static av_always_inline int isPlanar(enum AVPixelFormat pix_fmt)
Definition: swscale_internal.h:872
dst_1
dst_1[0]
Definition: yuv2rgb.c:674
av_bswap16
#define av_bswap16
Definition: bswap.h:27
SwsContext
Definition: swscale_internal.h:299
rgb2rgb.h
swscale.h
PUTRGB15
#define PUTRGB15(dst, src, i, o)
Definition: yuv2rgb.c:442
av_get_pix_fmt_name
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:2882
isALPHA
static av_always_inline int isALPHA(enum AVPixelFormat pix_fmt)
Definition: swscale_internal.h:854
ff_dither_2x2_8
const uint8_t ff_dither_2x2_8[][8]
Definition: output.c:45
AV_PIX_FMT_BGR48BE
@ AV_PIX_FMT_BGR48BE
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:145
AV_PIX_FMT_RGB444
#define AV_PIX_FMT_RGB444
Definition: pixfmt.h:467