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