FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
vf_colorspace.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 Ronald S. Bultje <rsbultje@gmail.com>
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 /*
22  * @file
23  * Convert between colorspaces.
24  */
25 
26 #include "libavutil/avassert.h"
27 #include "libavutil/opt.h"
28 #include "libavutil/pixdesc.h"
29 #include "libavutil/pixfmt.h"
30 
31 #include "avfilter.h"
32 #include "colorspacedsp.h"
33 #include "formats.h"
34 #include "internal.h"
35 #include "video.h"
36 
37 enum DitherMode {
41 };
42 
43 enum Colorspace {
54 };
55 
56 enum Whitepoint {
60 };
61 
68 };
69 
81 };
82 
83 static const enum AVColorPrimaries default_prm[CS_NB + 1] = {
94 };
95 
96 static const enum AVColorSpace default_csp[CS_NB + 1] = {
107 };
108 
111  double xr, yr, xg, yg, xb, yb;
112 };
113 
115  double alpha, beta, gamma, delta;
116 };
117 
119  double cr, cg, cb;
120 };
121 
123  double xw, yw;
124 };
125 
126 typedef struct ColorSpaceContext {
127  const AVClass *class;
128 
130 
131  enum Colorspace user_all, user_iall;
132  enum AVColorSpace in_csp, out_csp, user_csp, user_icsp;
133  enum AVColorRange in_rng, out_rng, user_rng, user_irng;
134  enum AVColorTransferCharacteristic in_trc, out_trc, user_trc, user_itrc;
135  enum AVColorPrimaries in_prm, out_prm, user_prm, user_iprm;
136  enum AVPixelFormat in_format, user_format;
140 
141  int16_t *rgb[3];
142  ptrdiff_t rgb_stride;
143  unsigned rgb_sz;
145 
148  DECLARE_ALIGNED(16, int16_t, lrgb2lrgb_coeffs)[3][3][8];
149 
152  int16_t *lin_lut, *delin_lut;
153 
156  DECLARE_ALIGNED(16, int16_t, yuv2rgb_coeffs)[3][3][8];
157  DECLARE_ALIGNED(16, int16_t, rgb2yuv_coeffs)[3][3][8];
158  DECLARE_ALIGNED(16, int16_t, yuv2yuv_coeffs)[3][3][8];
159  DECLARE_ALIGNED(16, int16_t, yuv_offset)[2 /* in, out */][8];
166 
169 
170 // FIXME deal with odd width/heights (or just forbid it)
171 // FIXME faster linearize/delinearize implementation (integer pow)
172 // FIXME bt2020cl support (linearization between yuv/rgb step instead of between rgb/xyz)
173 // FIXME test that the values in (de)lin_lut don't exceed their container storage
174 // type size (only useful if we keep the LUT and don't move to fast integer pow)
175 // FIXME dithering if bitdepth goes down?
176 // FIXME bitexact for fate integration?
177 
178 /*
179  * All constants explained in e.g. https://linuxtv.org/downloads/v4l-dvb-apis/ch02s06.html
180  * The older ones (bt470bg/m) are also explained in their respective ITU docs
181  * (e.g. https://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.470-5-199802-S!!PDF-E.pdf)
182  * whereas the newer ones can typically be copied directly from wikipedia :)
183  */
185  [AVCOL_SPC_FCC] = { 0.30, 0.59, 0.11 },
186  [AVCOL_SPC_BT470BG] = { 0.299, 0.587, 0.114 },
187  [AVCOL_SPC_SMPTE170M] = { 0.299, 0.587, 0.114 },
188  [AVCOL_SPC_BT709] = { 0.2126, 0.7152, 0.0722 },
189  [AVCOL_SPC_SMPTE240M] = { 0.212, 0.701, 0.087 },
190  [AVCOL_SPC_BT2020_NCL] = { 0.2627, 0.6780, 0.0593 },
191  [AVCOL_SPC_BT2020_CL] = { 0.2627, 0.6780, 0.0593 },
192 };
193 
195 {
196  const struct LumaCoefficients *coeffs;
197 
198  if (csp >= AVCOL_SPC_NB)
199  return NULL;
200  coeffs = &luma_coefficients[csp];
201  if (!coeffs->cr)
202  return NULL;
203 
204  return coeffs;
205 }
206 
207 static void fill_rgb2yuv_table(const struct LumaCoefficients *coeffs,
208  double rgb2yuv[3][3])
209 {
210  double bscale, rscale;
211 
212  rgb2yuv[0][0] = coeffs->cr;
213  rgb2yuv[0][1] = coeffs->cg;
214  rgb2yuv[0][2] = coeffs->cb;
215  bscale = 0.5 / (coeffs->cb - 1.0);
216  rscale = 0.5 / (coeffs->cr - 1.0);
217  rgb2yuv[1][0] = bscale * coeffs->cr;
218  rgb2yuv[1][1] = bscale * coeffs->cg;
219  rgb2yuv[1][2] = 0.5;
220  rgb2yuv[2][0] = 0.5;
221  rgb2yuv[2][1] = rscale * coeffs->cg;
222  rgb2yuv[2][2] = rscale * coeffs->cb;
223 }
224 
225 // FIXME I'm pretty sure gamma22/28 also have a linear toe slope, but I can't
226 // find any actual tables that document their real values...
227 // See http://www.13thmonkey.org/~boris/gammacorrection/ first graph why it matters
229  [AVCOL_TRC_BT709] = { 1.099, 0.018, 0.45, 4.5 },
230  [AVCOL_TRC_GAMMA22] = { 1.0, 0.0, 1.0 / 2.2, 0.0 },
231  [AVCOL_TRC_GAMMA28] = { 1.0, 0.0, 1.0 / 2.8, 0.0 },
232  [AVCOL_TRC_SMPTE170M] = { 1.099, 0.018, 0.45, 4.5 },
233  [AVCOL_TRC_SMPTE240M] = { 1.1115, 0.0228, 0.45, 4.0 },
234  [AVCOL_TRC_IEC61966_2_1] = { 1.055, 0.0031308, 1.0 / 2.4, 12.92 },
235  [AVCOL_TRC_BT2020_10] = { 1.099, 0.018, 0.45, 4.5 },
236  [AVCOL_TRC_BT2020_12] = { 1.0993, 0.0181, 0.45, 4.5 },
237 };
238 
239 static const struct TransferCharacteristics *
241 {
242  const struct TransferCharacteristics *coeffs;
243 
244  if (trc >= AVCOL_TRC_NB)
245  return NULL;
246  coeffs = &transfer_characteristics[trc];
247  if (!coeffs->alpha)
248  return NULL;
249 
250  return coeffs;
251 }
252 
254  [WP_D65] = { 0.3127, 0.3290 },
255  [WP_C] = { 0.3100, 0.3160 },
256 };
257 
259  [AVCOL_PRI_BT709] = { WP_D65, 0.640, 0.330, 0.300, 0.600, 0.150, 0.060 },
260  [AVCOL_PRI_BT470M] = { WP_C, 0.670, 0.330, 0.210, 0.710, 0.140, 0.080 },
261  [AVCOL_PRI_BT470BG] = { WP_D65, 0.640, 0.330, 0.290, 0.600, 0.150, 0.060,},
262  [AVCOL_PRI_SMPTE170M] = { WP_D65, 0.630, 0.340, 0.310, 0.595, 0.155, 0.070 },
263  [AVCOL_PRI_SMPTE240M] = { WP_D65, 0.630, 0.340, 0.310, 0.595, 0.155, 0.070 },
264  [AVCOL_PRI_BT2020] = { WP_D65, 0.708, 0.292, 0.170, 0.797, 0.131, 0.046 },
265 };
266 
268 {
269  const struct ColorPrimaries *coeffs;
270 
271  if (prm >= AVCOL_PRI_NB)
272  return NULL;
273  coeffs = &color_primaries[prm];
274  if (!coeffs->xr)
275  return NULL;
276 
277  return coeffs;
278 }
279 
280 static void invert_matrix3x3(const double in[3][3], double out[3][3])
281 {
282  double m00 = in[0][0], m01 = in[0][1], m02 = in[0][2],
283  m10 = in[1][0], m11 = in[1][1], m12 = in[1][2],
284  m20 = in[2][0], m21 = in[2][1], m22 = in[2][2];
285  int i, j;
286  double det;
287 
288  out[0][0] = (m11 * m22 - m21 * m12);
289  out[0][1] = -(m01 * m22 - m21 * m02);
290  out[0][2] = (m01 * m12 - m11 * m02);
291  out[1][0] = -(m10 * m22 - m20 * m12);
292  out[1][1] = (m00 * m22 - m20 * m02);
293  out[1][2] = -(m00 * m12 - m10 * m02);
294  out[2][0] = (m10 * m21 - m20 * m11);
295  out[2][1] = -(m00 * m21 - m20 * m01);
296  out[2][2] = (m00 * m11 - m10 * m01);
297 
298  det = m00 * out[0][0] + m10 * out[0][1] + m20 * out[0][2];
299  det = 1.0 / det;
300 
301  for (i = 0; i < 3; i++) {
302  for (j = 0; j < 3; j++)
303  out[i][j] *= det;
304  }
305 }
306 
308 {
309  int n;
310  double in_alpha = s->in_txchr->alpha, in_beta = s->in_txchr->beta;
311  double in_gamma = s->in_txchr->gamma, in_delta = s->in_txchr->delta;
312  double in_ialpha = 1.0 / in_alpha, in_igamma = 1.0 / in_gamma, in_idelta = 1.0 / in_delta;
313  double out_alpha = s->out_txchr->alpha, out_beta = s->out_txchr->beta;
314  double out_gamma = s->out_txchr->gamma, out_delta = s->out_txchr->delta;
315 
316  s->lin_lut = av_malloc(sizeof(*s->lin_lut) * 32768 * 2);
317  if (!s->lin_lut)
318  return AVERROR(ENOMEM);
319  s->delin_lut = &s->lin_lut[32768];
320  for (n = 0; n < 32768; n++) {
321  double v = (n - 2048.0) / 28672.0, d, l;
322 
323  // delinearize
324  if (v <= -out_beta) {
325  d = -out_alpha * pow(-v, out_gamma) + (out_alpha - 1.0);
326  } else if (v < out_beta) {
327  d = out_delta * v;
328  } else {
329  d = out_alpha * pow(v, out_gamma) - (out_alpha - 1.0);
330  }
331  s->delin_lut[n] = av_clip_int16(lrint(d * 28672.0));
332 
333  // linearize
334  if (v <= -in_beta) {
335  l = -pow((1.0 - in_alpha - v) * in_ialpha, in_igamma);
336  } else if (v < in_beta) {
337  l = v * in_idelta;
338  } else {
339  l = pow((v + in_alpha - 1.0) * in_ialpha, in_igamma);
340  }
341  s->lin_lut[n] = av_clip_int16(lrint(l * 28672.0));
342  }
343 
344  return 0;
345 }
346 
347 /*
348  * see e.g. http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html
349  */
350 static void fill_rgb2xyz_table(const struct ColorPrimaries *coeffs,
351  double rgb2xyz[3][3])
352 {
353  const struct WhitepointCoefficients *wp = &whitepoint_coefficients[coeffs->wp];
354  double i[3][3], sr, sg, sb, zw;
355 
356  rgb2xyz[0][0] = coeffs->xr / coeffs->yr;
357  rgb2xyz[0][1] = coeffs->xg / coeffs->yg;
358  rgb2xyz[0][2] = coeffs->xb / coeffs->yb;
359  rgb2xyz[1][0] = rgb2xyz[1][1] = rgb2xyz[1][2] = 1.0;
360  rgb2xyz[2][0] = (1.0 - coeffs->xr - coeffs->yr) / coeffs->yr;
361  rgb2xyz[2][1] = (1.0 - coeffs->xg - coeffs->yg) / coeffs->yg;
362  rgb2xyz[2][2] = (1.0 - coeffs->xb - coeffs->yb) / coeffs->yb;
363  invert_matrix3x3(rgb2xyz, i);
364  zw = 1.0 - wp->xw - wp->yw;
365  sr = i[0][0] * wp->xw + i[0][1] * wp->yw + i[0][2] * zw;
366  sg = i[1][0] * wp->xw + i[1][1] * wp->yw + i[1][2] * zw;
367  sb = i[2][0] * wp->xw + i[2][1] * wp->yw + i[2][2] * zw;
368  rgb2xyz[0][0] *= sr;
369  rgb2xyz[0][1] *= sg;
370  rgb2xyz[0][2] *= sb;
371  rgb2xyz[1][0] *= sr;
372  rgb2xyz[1][1] *= sg;
373  rgb2xyz[1][2] *= sb;
374  rgb2xyz[2][0] *= sr;
375  rgb2xyz[2][1] *= sg;
376  rgb2xyz[2][2] *= sb;
377 }
378 
379 static void mul3x3(double dst[3][3], const double src1[3][3], const double src2[3][3])
380 {
381  int m, n;
382 
383  for (m = 0; m < 3; m++)
384  for (n = 0; n < 3; n++)
385  dst[m][n] = src2[m][0] * src1[0][n] +
386  src2[m][1] * src1[1][n] +
387  src2[m][2] * src1[2][n];
388 }
389 
390 /*
391  * See http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html
392  * This function uses the Bradford mechanism.
393  */
394 static void fill_whitepoint_conv_table(double out[3][3], enum WhitepointAdaptation wp_adapt,
395  enum Whitepoint src, enum Whitepoint dst)
396 {
397  static const double ma_tbl[NB_WP_ADAPT_NON_IDENTITY][3][3] = {
398  [WP_ADAPT_BRADFORD] = {
399  { 0.8951, 0.2664, -0.1614 },
400  { -0.7502, 1.7135, 0.0367 },
401  { 0.0389, -0.0685, 1.0296 },
402  }, [WP_ADAPT_VON_KRIES] = {
403  { 0.40024, 0.70760, -0.08081 },
404  { -0.22630, 1.16532, 0.04570 },
405  { 0.00000, 0.00000, 0.91822 },
406  },
407  };
408  const double (*ma)[3] = ma_tbl[wp_adapt];
409  const struct WhitepointCoefficients *wp_src = &whitepoint_coefficients[src];
410  double zw_src = 1.0 - wp_src->xw - wp_src->yw;
411  const struct WhitepointCoefficients *wp_dst = &whitepoint_coefficients[dst];
412  double zw_dst = 1.0 - wp_dst->xw - wp_dst->yw;
413  double mai[3][3], fac[3][3], tmp[3][3];
414  double rs, gs, bs, rd, gd, bd;
415 
416  invert_matrix3x3(ma, mai);
417  rs = ma[0][0] * wp_src->xw + ma[0][1] * wp_src->yw + ma[0][2] * zw_src;
418  gs = ma[1][0] * wp_src->xw + ma[1][1] * wp_src->yw + ma[1][2] * zw_src;
419  bs = ma[2][0] * wp_src->xw + ma[2][1] * wp_src->yw + ma[2][2] * zw_src;
420  rd = ma[0][0] * wp_dst->xw + ma[0][1] * wp_dst->yw + ma[0][2] * zw_dst;
421  gd = ma[1][0] * wp_dst->xw + ma[1][1] * wp_dst->yw + ma[1][2] * zw_dst;
422  bd = ma[2][0] * wp_dst->xw + ma[2][1] * wp_dst->yw + ma[2][2] * zw_dst;
423  fac[0][0] = rd / rs;
424  fac[1][1] = gd / gs;
425  fac[2][2] = bd / bs;
426  fac[0][1] = fac[0][2] = fac[1][0] = fac[1][2] = fac[2][0] = fac[2][1] = 0.0;
427  mul3x3(tmp, ma, fac);
428  mul3x3(out, tmp, mai);
429 }
430 
431 static void apply_lut(int16_t *buf[3], ptrdiff_t stride,
432  int w, int h, const int16_t *lut)
433 {
434  int y, x, n;
435 
436  for (n = 0; n < 3; n++) {
437  int16_t *data = buf[n];
438 
439  for (y = 0; y < h; y++) {
440  for (x = 0; x < w; x++)
441  data[x] = lut[av_clip_uintp2(2048 + data[x], 15)];
442 
443  data += stride;
444  }
445  }
446 }
447 
448 struct ThreadData {
449  AVFrame *in, *out;
450  ptrdiff_t in_linesize[3], out_linesize[3];
452 };
453 
454 static int convert(AVFilterContext *ctx, void *data, int job_nr, int n_jobs)
455 {
456  struct ThreadData *td = data;
457  ColorSpaceContext *s = ctx->priv;
458  uint8_t *in_data[3], *out_data[3];
459  int16_t *rgb[3];
460  int h_in = (td->in->height + 1) >> 1;
461  int h1 = 2 * (job_nr * h_in / n_jobs), h2 = 2 * ((job_nr + 1) * h_in / n_jobs);
462  int w = td->in->width, h = h2 - h1;
463 
464  in_data[0] = td->in->data[0] + td->in_linesize[0] * h1;
465  in_data[1] = td->in->data[1] + td->in_linesize[1] * (h1 >> td->in_ss_h);
466  in_data[2] = td->in->data[2] + td->in_linesize[2] * (h1 >> td->in_ss_h);
467  out_data[0] = td->out->data[0] + td->out_linesize[0] * h1;
468  out_data[1] = td->out->data[1] + td->out_linesize[1] * (h1 >> td->out_ss_h);
469  out_data[2] = td->out->data[2] + td->out_linesize[2] * (h1 >> td->out_ss_h);
470  rgb[0] = s->rgb[0] + s->rgb_stride * h1;
471  rgb[1] = s->rgb[1] + s->rgb_stride * h1;
472  rgb[2] = s->rgb[2] + s->rgb_stride * h1;
473 
474  // FIXME for simd, also make sure we do pictures with negative stride
475  // top-down so we don't overwrite lines with padding of data before it
476  // in the same buffer (same as swscale)
477 
478  if (s->yuv2yuv_fastmode) {
479  // FIXME possibly use a fast mode in case only the y range changes?
480  // since in that case, only the diagonal entries in yuv2yuv_coeffs[]
481  // are non-zero
482  s->yuv2yuv(out_data, td->out_linesize, in_data, td->in_linesize, w, h,
483  s->yuv2yuv_coeffs, s->yuv_offset);
484  } else {
485  // FIXME maybe (for caching effciency) do pipeline per-line instead of
486  // full buffer per function? (Or, since yuv2rgb requires 2 lines: per
487  // 2 lines, for yuv420.)
488  /*
489  * General design:
490  * - yuv2rgb converts from whatever range the input was ([16-235/240] or
491  * [0,255] or the 10/12bpp equivalents thereof) to an integer version
492  * of RGB in psuedo-restricted 15+sign bits. That means that the float
493  * range [0.0,1.0] is in [0,28762], and the remainder of the int16_t
494  * range is used for overflow/underflow outside the representable
495  * range of this RGB type. rgb2yuv is the exact opposite.
496  * - gamma correction is done using a LUT since that appears to work
497  * fairly fast.
498  * - If the input is chroma-subsampled (420/422), the yuv2rgb conversion
499  * (or rgb2yuv conversion) uses nearest-neighbour sampling to read
500  * read chroma pixels at luma resolution. If you want some more fancy
501  * filter, you can use swscale to convert to yuv444p.
502  * - all coefficients are 14bit (so in the [-2.0,2.0] range).
503  */
504  s->yuv2rgb(rgb, s->rgb_stride, in_data, td->in_linesize, w, h,
505  s->yuv2rgb_coeffs, s->yuv_offset[0]);
506  if (!s->rgb2rgb_passthrough) {
507  apply_lut(rgb, s->rgb_stride, w, h, s->lin_lut);
508  if (!s->lrgb2lrgb_passthrough)
509  s->dsp.multiply3x3(rgb, s->rgb_stride, w, h, s->lrgb2lrgb_coeffs);
510  apply_lut(rgb, s->rgb_stride, w, h, s->delin_lut);
511  }
512  if (s->dither == DITHER_FSB) {
513  s->rgb2yuv_fsb(out_data, td->out_linesize, rgb, s->rgb_stride, w, h,
515  } else {
516  s->rgb2yuv(out_data, td->out_linesize, rgb, s->rgb_stride, w, h,
517  s->rgb2yuv_coeffs, s->yuv_offset[1]);
518  }
519  }
520 
521  return 0;
522 }
523 
524 static int get_range_off(AVFilterContext *ctx, int *off,
525  int *y_rng, int *uv_rng,
526  enum AVColorRange rng, int depth)
527 {
528  switch (rng) {
530  ColorSpaceContext *s = ctx->priv;
531 
532  if (!s->did_warn_range) {
533  av_log(ctx, AV_LOG_WARNING, "Input range not set, assuming tv/mpeg\n");
534  s->did_warn_range = 1;
535  }
536  }
537  // fall-through
538  case AVCOL_RANGE_MPEG:
539  *off = 16 << (depth - 8);
540  *y_rng = 219 << (depth - 8);
541  *uv_rng = 224 << (depth - 8);
542  break;
543  case AVCOL_RANGE_JPEG:
544  *off = 0;
545  *y_rng = *uv_rng = (256 << (depth - 8)) - 1;
546  break;
547  default:
548  return AVERROR(EINVAL);
549  }
550 
551  return 0;
552 }
553 
555  const AVFrame *in, const AVFrame *out)
556 {
557  ColorSpaceContext *s = ctx->priv;
558  const AVPixFmtDescriptor *in_desc = av_pix_fmt_desc_get(in->format);
559  const AVPixFmtDescriptor *out_desc = av_pix_fmt_desc_get(out->format);
560  int emms = 0, m, n, o, res, fmt_identical, redo_yuv2rgb = 0, redo_rgb2yuv = 0;
561 
562 #define supported_depth(d) ((d) == 8 || (d) == 10 || (d) == 12)
563 #define supported_subsampling(lcw, lch) \
564  (((lcw) == 0 && (lch) == 0) || ((lcw) == 1 && (lch) == 0) || ((lcw) == 1 && (lch) == 1))
565 #define supported_format(d) \
566  ((d) != NULL && (d)->nb_components == 3 && \
567  !((d)->flags & AV_PIX_FMT_FLAG_RGB) && \
568  supported_depth((d)->comp[0].depth) && \
569  supported_subsampling((d)->log2_chroma_w, (d)->log2_chroma_h))
570 
571  if (!supported_format(in_desc)) {
572  av_log(ctx, AV_LOG_ERROR,
573  "Unsupported input format %d (%s) or bitdepth (%d)\n",
575  in_desc ? in_desc->comp[0].depth : -1);
576  return AVERROR(EINVAL);
577  }
578  if (!supported_format(out_desc)) {
579  av_log(ctx, AV_LOG_ERROR,
580  "Unsupported output format %d (%s) or bitdepth (%d)\n",
581  out->format, av_get_pix_fmt_name(out->format),
582  out_desc ? out_desc->comp[0].depth : -1);
583  return AVERROR(EINVAL);
584  }
585 
586  if (in->color_primaries != s->in_prm) s->in_primaries = NULL;
587  if (out->color_primaries != s->out_prm) s->out_primaries = NULL;
588  if (in->color_trc != s->in_trc) s->in_txchr = NULL;
589  if (out->color_trc != s->out_trc) s->out_txchr = NULL;
590  if (in->colorspace != s->in_csp ||
591  in->color_range != s->in_rng) s->in_lumacoef = NULL;
592  if (out->colorspace != s->out_csp ||
593  out->color_range != s->out_rng) s->out_lumacoef = NULL;
594 
595  if (!s->out_primaries || !s->in_primaries) {
596  s->in_prm = in->color_primaries;
597  if (s->user_iall != CS_UNSPECIFIED)
598  s->in_prm = default_prm[FFMIN(s->user_iall, CS_NB)];
600  s->in_prm = s->user_iprm;
601  s->in_primaries = get_color_primaries(s->in_prm);
602  if (!s->in_primaries) {
603  av_log(ctx, AV_LOG_ERROR,
604  "Unsupported input primaries %d (%s)\n",
605  s->in_prm, av_color_primaries_name(s->in_prm));
606  return AVERROR(EINVAL);
607  }
608  s->out_prm = out->color_primaries;
609  s->out_primaries = get_color_primaries(s->out_prm);
610  if (!s->out_primaries) {
611  if (s->out_prm == AVCOL_PRI_UNSPECIFIED) {
612  if (s->user_all == CS_UNSPECIFIED) {
613  av_log(ctx, AV_LOG_ERROR, "Please specify output primaries\n");
614  } else {
615  av_log(ctx, AV_LOG_ERROR,
616  "Unsupported output color property %d\n", s->user_all);
617  }
618  } else {
619  av_log(ctx, AV_LOG_ERROR,
620  "Unsupported output primaries %d (%s)\n",
621  s->out_prm, av_color_primaries_name(s->out_prm));
622  }
623  return AVERROR(EINVAL);
624  }
626  sizeof(*s->in_primaries));
627  if (!s->lrgb2lrgb_passthrough) {
628  double rgb2xyz[3][3], xyz2rgb[3][3], rgb2rgb[3][3];
629 
630  fill_rgb2xyz_table(s->out_primaries, rgb2xyz);
631  invert_matrix3x3(rgb2xyz, xyz2rgb);
632  fill_rgb2xyz_table(s->in_primaries, rgb2xyz);
633  if (s->out_primaries->wp != s->in_primaries->wp &&
634  s->wp_adapt != WP_ADAPT_IDENTITY) {
635  double wpconv[3][3], tmp[3][3];
636 
638  s->out_primaries->wp);
639  mul3x3(tmp, rgb2xyz, wpconv);
640  mul3x3(rgb2rgb, tmp, xyz2rgb);
641  } else {
642  mul3x3(rgb2rgb, rgb2xyz, xyz2rgb);
643  }
644  for (m = 0; m < 3; m++)
645  for (n = 0; n < 3; n++) {
646  s->lrgb2lrgb_coeffs[m][n][0] = lrint(16384.0 * rgb2rgb[m][n]);
647  for (o = 1; o < 8; o++)
648  s->lrgb2lrgb_coeffs[m][n][o] = s->lrgb2lrgb_coeffs[m][n][0];
649  }
650 
651  emms = 1;
652  }
653  }
654 
655  if (!s->in_txchr) {
656  av_freep(&s->lin_lut);
657  s->in_trc = in->color_trc;
658  if (s->user_iall != CS_UNSPECIFIED)
659  s->in_trc = default_trc[FFMIN(s->user_iall, CS_NB)];
661  s->in_trc = s->user_itrc;
662  s->in_txchr = get_transfer_characteristics(s->in_trc);
663  if (!s->in_txchr) {
664  av_log(ctx, AV_LOG_ERROR,
665  "Unsupported input transfer characteristics %d (%s)\n",
666  s->in_trc, av_color_transfer_name(s->in_trc));
667  return AVERROR(EINVAL);
668  }
669  }
670 
671  if (!s->out_txchr) {
672  av_freep(&s->lin_lut);
673  s->out_trc = out->color_trc;
674  s->out_txchr = get_transfer_characteristics(s->out_trc);
675  if (!s->out_txchr) {
676  if (s->out_trc == AVCOL_TRC_UNSPECIFIED) {
677  if (s->user_all == CS_UNSPECIFIED) {
678  av_log(ctx, AV_LOG_ERROR,
679  "Please specify output transfer characteristics\n");
680  } else {
681  av_log(ctx, AV_LOG_ERROR,
682  "Unsupported output color property %d\n", s->user_all);
683  }
684  } else {
685  av_log(ctx, AV_LOG_ERROR,
686  "Unsupported output transfer characteristics %d (%s)\n",
687  s->out_trc, av_color_transfer_name(s->out_trc));
688  }
689  return AVERROR(EINVAL);
690  }
691  }
692 
694  !memcmp(s->in_txchr, s->out_txchr, sizeof(*s->in_txchr)));
695  if (!s->rgb2rgb_passthrough && !s->lin_lut) {
696  res = fill_gamma_table(s);
697  if (res < 0)
698  return res;
699  emms = 1;
700  }
701 
702  if (!s->in_lumacoef) {
703  s->in_csp = in->colorspace;
704  if (s->user_iall != CS_UNSPECIFIED)
705  s->in_csp = default_csp[FFMIN(s->user_iall, CS_NB)];
707  s->in_csp = s->user_icsp;
708  s->in_rng = in->color_range;
710  s->in_rng = s->user_irng;
711  s->in_lumacoef = get_luma_coefficients(s->in_csp);
712  if (!s->in_lumacoef) {
713  av_log(ctx, AV_LOG_ERROR,
714  "Unsupported input colorspace %d (%s)\n",
715  s->in_csp, av_color_space_name(s->in_csp));
716  return AVERROR(EINVAL);
717  }
718  redo_yuv2rgb = 1;
719  }
720 
721  if (!s->out_lumacoef) {
722  s->out_csp = out->colorspace;
723  s->out_rng = out->color_range;
724  s->out_lumacoef = get_luma_coefficients(s->out_csp);
725  if (!s->out_lumacoef) {
726  if (s->out_csp == AVCOL_SPC_UNSPECIFIED) {
727  if (s->user_all == CS_UNSPECIFIED) {
728  av_log(ctx, AV_LOG_ERROR,
729  "Please specify output transfer characteristics\n");
730  } else {
731  av_log(ctx, AV_LOG_ERROR,
732  "Unsupported output color property %d\n", s->user_all);
733  }
734  } else {
735  av_log(ctx, AV_LOG_ERROR,
736  "Unsupported output transfer characteristics %d (%s)\n",
737  s->out_csp, av_color_space_name(s->out_csp));
738  }
739  return AVERROR(EINVAL);
740  }
741  redo_rgb2yuv = 1;
742  }
743 
744  fmt_identical = in_desc->log2_chroma_h == out_desc->log2_chroma_h &&
745  in_desc->log2_chroma_w == out_desc->log2_chroma_w;
746  s->yuv2yuv_fastmode = s->rgb2rgb_passthrough && fmt_identical;
747  s->yuv2yuv_passthrough = s->yuv2yuv_fastmode && s->in_rng == s->out_rng &&
748  !memcmp(s->in_lumacoef, s->out_lumacoef,
749  sizeof(*s->in_lumacoef)) &&
750  in_desc->comp[0].depth == out_desc->comp[0].depth;
751  if (!s->yuv2yuv_passthrough) {
752  if (redo_yuv2rgb) {
753  double rgb2yuv[3][3], (*yuv2rgb)[3] = s->yuv2rgb_dbl_coeffs;
754  int off, bits, in_rng;
755 
756  res = get_range_off(ctx, &off, &s->in_y_rng, &s->in_uv_rng,
757  s->in_rng, in_desc->comp[0].depth);
758  if (res < 0) {
759  av_log(ctx, AV_LOG_ERROR,
760  "Unsupported input color range %d (%s)\n",
761  s->in_rng, av_color_range_name(s->in_rng));
762  return res;
763  }
764  for (n = 0; n < 8; n++)
765  s->yuv_offset[0][n] = off;
766  fill_rgb2yuv_table(s->in_lumacoef, rgb2yuv);
767  invert_matrix3x3(rgb2yuv, yuv2rgb);
768  bits = 1 << (in_desc->comp[0].depth - 1);
769  for (n = 0; n < 3; n++) {
770  for (in_rng = s->in_y_rng, m = 0; m < 3; m++, in_rng = s->in_uv_rng) {
771  s->yuv2rgb_coeffs[n][m][0] = lrint(28672 * bits * yuv2rgb[n][m] / in_rng);
772  for (o = 1; o < 8; o++)
773  s->yuv2rgb_coeffs[n][m][o] = s->yuv2rgb_coeffs[n][m][0];
774  }
775  }
776  av_assert2(s->yuv2rgb_coeffs[0][1][0] == 0);
777  av_assert2(s->yuv2rgb_coeffs[2][2][0] == 0);
778  av_assert2(s->yuv2rgb_coeffs[0][0][0] == s->yuv2rgb_coeffs[1][0][0]);
779  av_assert2(s->yuv2rgb_coeffs[0][0][0] == s->yuv2rgb_coeffs[2][0][0]);
780  s->yuv2rgb = s->dsp.yuv2rgb[(in_desc->comp[0].depth - 8) >> 1]
781  [in_desc->log2_chroma_h + in_desc->log2_chroma_w];
782  emms = 1;
783  }
784 
785  if (redo_rgb2yuv) {
786  double (*rgb2yuv)[3] = s->rgb2yuv_dbl_coeffs;
787  int off, out_rng, bits;
788 
789  res = get_range_off(ctx, &off, &s->out_y_rng, &s->out_uv_rng,
790  s->out_rng, out_desc->comp[0].depth);
791  if (res < 0) {
792  av_log(ctx, AV_LOG_ERROR,
793  "Unsupported output color range %d (%s)\n",
794  s->out_rng, av_color_range_name(s->out_rng));
795  return res;
796  }
797  for (n = 0; n < 8; n++)
798  s->yuv_offset[1][n] = off;
800  bits = 1 << (29 - out_desc->comp[0].depth);
801  for (out_rng = s->out_y_rng, n = 0; n < 3; n++, out_rng = s->out_uv_rng) {
802  for (m = 0; m < 3; m++) {
803  s->rgb2yuv_coeffs[n][m][0] = lrint(bits * out_rng * rgb2yuv[n][m] / 28672);
804  for (o = 1; o < 8; o++)
805  s->rgb2yuv_coeffs[n][m][o] = s->rgb2yuv_coeffs[n][m][0];
806  }
807  }
808  av_assert2(s->rgb2yuv_coeffs[1][2][0] == s->rgb2yuv_coeffs[2][0][0]);
809  s->rgb2yuv = s->dsp.rgb2yuv[(out_desc->comp[0].depth - 8) >> 1]
810  [out_desc->log2_chroma_h + out_desc->log2_chroma_w];
811  s->rgb2yuv_fsb = s->dsp.rgb2yuv_fsb[(out_desc->comp[0].depth - 8) >> 1]
812  [out_desc->log2_chroma_h + out_desc->log2_chroma_w];
813  emms = 1;
814  }
815 
816  if (s->yuv2yuv_fastmode && (redo_yuv2rgb || redo_rgb2yuv)) {
817  int idepth = in_desc->comp[0].depth, odepth = out_desc->comp[0].depth;
818  double (*rgb2yuv)[3] = s->rgb2yuv_dbl_coeffs;
819  double (*yuv2rgb)[3] = s->yuv2rgb_dbl_coeffs;
820  double yuv2yuv[3][3];
821  int in_rng, out_rng;
822 
823  mul3x3(yuv2yuv, yuv2rgb, rgb2yuv);
824  for (out_rng = s->out_y_rng, m = 0; m < 3; m++, out_rng = s->out_uv_rng) {
825  for (in_rng = s->in_y_rng, n = 0; n < 3; n++, in_rng = s->in_uv_rng) {
826  s->yuv2yuv_coeffs[m][n][0] =
827  lrint(16384 * yuv2yuv[m][n] * out_rng * (1 << idepth) /
828  (in_rng * (1 << odepth)));
829  for (o = 1; o < 8; o++)
830  s->yuv2yuv_coeffs[m][n][o] = s->yuv2yuv_coeffs[m][n][0];
831  }
832  }
833  av_assert2(s->yuv2yuv_coeffs[1][0][0] == 0);
834  av_assert2(s->yuv2yuv_coeffs[2][0][0] == 0);
835  s->yuv2yuv = s->dsp.yuv2yuv[(idepth - 8) >> 1][(odepth - 8) >> 1]
836  [in_desc->log2_chroma_h + in_desc->log2_chroma_w];
837  }
838  }
839 
840  if (emms)
841  emms_c();
842 
843  return 0;
844 }
845 
847 {
848  ColorSpaceContext *s = ctx->priv;
849 
851 
852  return 0;
853 }
854 
856 {
857  ColorSpaceContext *s = ctx->priv;
858 
859  av_freep(&s->rgb[0]);
860  av_freep(&s->rgb[1]);
861  av_freep(&s->rgb[2]);
862  s->rgb_sz = 0;
863  av_freep(&s->dither_scratch_base[0][0]);
864  av_freep(&s->dither_scratch_base[0][1]);
865  av_freep(&s->dither_scratch_base[1][0]);
866  av_freep(&s->dither_scratch_base[1][1]);
867  av_freep(&s->dither_scratch_base[2][0]);
868  av_freep(&s->dither_scratch_base[2][1]);
869 
870  av_freep(&s->lin_lut);
871 }
872 
873 static int filter_frame(AVFilterLink *link, AVFrame *in)
874 {
875  AVFilterContext *ctx = link->dst;
876  AVFilterLink *outlink = ctx->outputs[0];
877  ColorSpaceContext *s = ctx->priv;
878  // FIXME if yuv2yuv_passthrough, don't get a new buffer but use the
879  // input one if it is writable *OR* the actual literal values of in_*
880  // and out_* are identical (not just their respective properties)
881  AVFrame *out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
882  int res;
883  ptrdiff_t rgb_stride = FFALIGN(in->width * sizeof(int16_t), 32);
884  unsigned rgb_sz = rgb_stride * in->height;
885  struct ThreadData td;
886 
887  if (!out) {
888  av_frame_free(&in);
889  return AVERROR(ENOMEM);
890  }
891  res = av_frame_copy_props(out, in);
892  if (res < 0) {
893  av_frame_free(&in);
894  return res;
895  }
896 
897  out->color_primaries = s->user_prm == AVCOL_PRI_UNSPECIFIED ?
898  default_prm[FFMIN(s->user_all, CS_NB)] : s->user_prm;
899  if (s->user_trc == AVCOL_TRC_UNSPECIFIED) {
901 
902  out->color_trc = default_trc[FFMIN(s->user_all, CS_NB)];
903  if (out->color_trc == AVCOL_TRC_BT2020_10 && desc && desc->comp[0].depth >= 12)
905  } else {
906  out->color_trc = s->user_trc;
907  }
908  out->colorspace = s->user_csp == AVCOL_SPC_UNSPECIFIED ?
909  default_csp[FFMIN(s->user_all, CS_NB)] : s->user_csp;
910  out->color_range = s->user_rng == AVCOL_RANGE_UNSPECIFIED ?
911  in->color_range : s->user_rng;
912  if (rgb_sz != s->rgb_sz) {
914  int uvw = in->width >> desc->log2_chroma_w;
915 
916  av_freep(&s->rgb[0]);
917  av_freep(&s->rgb[1]);
918  av_freep(&s->rgb[2]);
919  s->rgb_sz = 0;
920  av_freep(&s->dither_scratch_base[0][0]);
921  av_freep(&s->dither_scratch_base[0][1]);
922  av_freep(&s->dither_scratch_base[1][0]);
923  av_freep(&s->dither_scratch_base[1][1]);
924  av_freep(&s->dither_scratch_base[2][0]);
925  av_freep(&s->dither_scratch_base[2][1]);
926 
927  s->rgb[0] = av_malloc(rgb_sz);
928  s->rgb[1] = av_malloc(rgb_sz);
929  s->rgb[2] = av_malloc(rgb_sz);
930  s->dither_scratch_base[0][0] =
931  av_malloc(sizeof(*s->dither_scratch_base[0][0]) * (in->width + 4));
932  s->dither_scratch_base[0][1] =
933  av_malloc(sizeof(*s->dither_scratch_base[0][1]) * (in->width + 4));
934  s->dither_scratch_base[1][0] =
935  av_malloc(sizeof(*s->dither_scratch_base[1][0]) * (uvw + 4));
936  s->dither_scratch_base[1][1] =
937  av_malloc(sizeof(*s->dither_scratch_base[1][1]) * (uvw + 4));
938  s->dither_scratch_base[2][0] =
939  av_malloc(sizeof(*s->dither_scratch_base[2][0]) * (uvw + 4));
940  s->dither_scratch_base[2][1] =
941  av_malloc(sizeof(*s->dither_scratch_base[2][1]) * (uvw + 4));
942  s->dither_scratch[0][0] = &s->dither_scratch_base[0][0][1];
943  s->dither_scratch[0][1] = &s->dither_scratch_base[0][1][1];
944  s->dither_scratch[1][0] = &s->dither_scratch_base[1][0][1];
945  s->dither_scratch[1][1] = &s->dither_scratch_base[1][1][1];
946  s->dither_scratch[2][0] = &s->dither_scratch_base[2][0][1];
947  s->dither_scratch[2][1] = &s->dither_scratch_base[2][1][1];
948  if (!s->rgb[0] || !s->rgb[1] || !s->rgb[2] ||
949  !s->dither_scratch_base[0][0] || !s->dither_scratch_base[0][1] ||
950  !s->dither_scratch_base[1][0] || !s->dither_scratch_base[1][1] ||
951  !s->dither_scratch_base[2][0] || !s->dither_scratch_base[2][1]) {
952  uninit(ctx);
953  return AVERROR(ENOMEM);
954  }
955  s->rgb_sz = rgb_sz;
956  }
957  res = create_filtergraph(ctx, in, out);
958  if (res < 0)
959  return res;
960  s->rgb_stride = rgb_stride / sizeof(int16_t);
961  td.in = in;
962  td.out = out;
963  td.in_linesize[0] = in->linesize[0];
964  td.in_linesize[1] = in->linesize[1];
965  td.in_linesize[2] = in->linesize[2];
966  td.out_linesize[0] = out->linesize[0];
967  td.out_linesize[1] = out->linesize[1];
968  td.out_linesize[2] = out->linesize[2];
971  if (s->yuv2yuv_passthrough) {
972  res = av_frame_copy(out, in);
973  if (res < 0)
974  return res;
975  } else {
976  ctx->internal->execute(ctx, convert, &td, NULL,
977  FFMIN((in->height + 1) >> 1, ff_filter_get_nb_threads(ctx)));
978  }
979  av_frame_free(&in);
980 
981  return ff_filter_frame(outlink, out);
982 }
983 
985 {
986  static const enum AVPixelFormat pix_fmts[] = {
992  };
993  int res;
994  ColorSpaceContext *s = ctx->priv;
996 
997  if (!formats)
998  return AVERROR(ENOMEM);
999  if (s->user_format == AV_PIX_FMT_NONE)
1000  return ff_set_common_formats(ctx, formats);
1001  res = ff_formats_ref(formats, &ctx->inputs[0]->out_formats);
1002  if (res < 0)
1003  return res;
1004  formats = NULL;
1005  res = ff_add_format(&formats, s->user_format);
1006  if (res < 0)
1007  return res;
1008 
1009  return ff_formats_ref(formats, &ctx->outputs[0]->in_formats);
1010 }
1011 
1012 static int config_props(AVFilterLink *outlink)
1013 {
1014  AVFilterLink *inlink = outlink->src->inputs[0];
1015 
1016  outlink->w = inlink->w;
1017  outlink->h = inlink->h;
1018  outlink->sample_aspect_ratio = inlink->sample_aspect_ratio;
1019  outlink->time_base = inlink->time_base;
1020 
1021  return 0;
1022 }
1023 
1024 #define OFFSET(x) offsetof(ColorSpaceContext, x)
1025 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM
1026 #define ENUM(x, y, z) { x, "", 0, AV_OPT_TYPE_CONST, { .i64 = y }, INT_MIN, INT_MAX, FLAGS, z }
1027 
1028 static const AVOption colorspace_options[] = {
1029  { "all", "Set all color properties together",
1030  OFFSET(user_all), AV_OPT_TYPE_INT, { .i64 = CS_UNSPECIFIED },
1031  CS_UNSPECIFIED, CS_NB - 1, FLAGS, "all" },
1032  ENUM("bt470m", CS_BT470M, "all"),
1033  ENUM("bt470bg", CS_BT470BG, "all"),
1034  ENUM("bt601-6-525", CS_BT601_6_525, "all"),
1035  ENUM("bt601-6-625", CS_BT601_6_625, "all"),
1036  ENUM("bt709", CS_BT709, "all"),
1037  ENUM("smpte170m", CS_SMPTE170M, "all"),
1038  ENUM("smpte240m", CS_SMPTE240M, "all"),
1039  ENUM("bt2020", CS_BT2020, "all"),
1040 
1041  { "space", "Output colorspace",
1042  OFFSET(user_csp), AV_OPT_TYPE_INT, { .i64 = AVCOL_SPC_UNSPECIFIED },
1043  AVCOL_SPC_RGB, AVCOL_SPC_NB - 1, FLAGS, "csp"},
1044  ENUM("bt709", AVCOL_SPC_BT709, "csp"),
1045  ENUM("fcc", AVCOL_SPC_FCC, "csp"),
1046  ENUM("bt470bg", AVCOL_SPC_BT470BG, "csp"),
1047  ENUM("smpte170m", AVCOL_SPC_SMPTE170M, "csp"),
1048  ENUM("smpte240m", AVCOL_SPC_SMPTE240M, "csp"),
1049  ENUM("bt2020ncl", AVCOL_SPC_BT2020_NCL, "csp"),
1050 
1051  { "range", "Output color range",
1052  OFFSET(user_rng), AV_OPT_TYPE_INT, { .i64 = AVCOL_RANGE_UNSPECIFIED },
1054  ENUM("tv", AVCOL_RANGE_MPEG, "rng"),
1055  ENUM("mpeg", AVCOL_RANGE_MPEG, "rng"),
1056  ENUM("pc", AVCOL_RANGE_JPEG, "rng"),
1057  ENUM("jpeg", AVCOL_RANGE_JPEG, "rng"),
1058 
1059  { "primaries", "Output color primaries",
1060  OFFSET(user_prm), AV_OPT_TYPE_INT, { .i64 = AVCOL_PRI_UNSPECIFIED },
1061  AVCOL_PRI_RESERVED0, AVCOL_PRI_NB - 1, FLAGS, "prm" },
1062  ENUM("bt709", AVCOL_PRI_BT709, "prm"),
1063  ENUM("bt470m", AVCOL_PRI_BT470M, "prm"),
1064  ENUM("bt470bg", AVCOL_PRI_BT470BG, "prm"),
1065  ENUM("smpte170m", AVCOL_PRI_SMPTE170M, "prm"),
1066  ENUM("smpte240m", AVCOL_PRI_SMPTE240M, "prm"),
1067  ENUM("bt2020", AVCOL_PRI_BT2020, "prm"),
1068 
1069  { "trc", "Output transfer characteristics",
1070  OFFSET(user_trc), AV_OPT_TYPE_INT, { .i64 = AVCOL_TRC_UNSPECIFIED },
1071  AVCOL_TRC_RESERVED0, AVCOL_TRC_NB - 1, FLAGS, "trc" },
1072  ENUM("bt709", AVCOL_TRC_BT709, "trc"),
1073  ENUM("bt470m", AVCOL_TRC_GAMMA22, "trc"),
1074  ENUM("gamma22", AVCOL_TRC_GAMMA22, "trc"),
1075  ENUM("bt470bg", AVCOL_TRC_GAMMA28, "trc"),
1076  ENUM("gamma28", AVCOL_TRC_GAMMA28, "trc"),
1077  ENUM("smpte170m", AVCOL_TRC_SMPTE170M, "trc"),
1078  ENUM("smpte240m", AVCOL_TRC_SMPTE240M, "trc"),
1079  ENUM("srgb", AVCOL_TRC_IEC61966_2_1, "trc"),
1080  ENUM("iec61966-2-1", AVCOL_TRC_IEC61966_2_1, "trc"),
1081  ENUM("bt2020-10", AVCOL_TRC_BT2020_10, "trc"),
1082  ENUM("bt2020-12", AVCOL_TRC_BT2020_12, "trc"),
1083 
1084  { "format", "Output pixel format",
1085  OFFSET(user_format), AV_OPT_TYPE_INT, { .i64 = AV_PIX_FMT_NONE },
1087  ENUM("yuv420p", AV_PIX_FMT_YUV420P, "fmt"),
1088  ENUM("yuv420p10", AV_PIX_FMT_YUV420P10, "fmt"),
1089  ENUM("yuv420p12", AV_PIX_FMT_YUV420P12, "fmt"),
1090  ENUM("yuv422p", AV_PIX_FMT_YUV422P, "fmt"),
1091  ENUM("yuv422p10", AV_PIX_FMT_YUV422P10, "fmt"),
1092  ENUM("yuv422p12", AV_PIX_FMT_YUV422P12, "fmt"),
1093  ENUM("yuv444p", AV_PIX_FMT_YUV444P, "fmt"),
1094  ENUM("yuv444p10", AV_PIX_FMT_YUV444P10, "fmt"),
1095  ENUM("yuv444p12", AV_PIX_FMT_YUV444P12, "fmt"),
1096 
1097  { "fast", "Ignore primary chromaticity and gamma correction",
1098  OFFSET(fast_mode), AV_OPT_TYPE_BOOL, { .i64 = 0 },
1099  0, 1, FLAGS },
1100 
1101  { "dither", "Dithering mode",
1102  OFFSET(dither), AV_OPT_TYPE_INT, { .i64 = DITHER_NONE },
1103  DITHER_NONE, DITHER_NB - 1, FLAGS, "dither" },
1104  ENUM("none", DITHER_NONE, "dither"),
1105  ENUM("fsb", DITHER_FSB, "dither"),
1106 
1107  { "wpadapt", "Whitepoint adaptation method",
1108  OFFSET(wp_adapt), AV_OPT_TYPE_INT, { .i64 = WP_ADAPT_BRADFORD },
1109  WP_ADAPT_BRADFORD, NB_WP_ADAPT - 1, FLAGS, "wpadapt" },
1110  ENUM("bradford", WP_ADAPT_BRADFORD, "wpadapt"),
1111  ENUM("vonkries", WP_ADAPT_VON_KRIES, "wpadapt"),
1112  ENUM("identity", WP_ADAPT_IDENTITY, "wpadapt"),
1113 
1114  { "iall", "Set all input color properties together",
1115  OFFSET(user_iall), AV_OPT_TYPE_INT, { .i64 = CS_UNSPECIFIED },
1116  CS_UNSPECIFIED, CS_NB - 1, FLAGS, "all" },
1117  { "ispace", "Input colorspace",
1118  OFFSET(user_icsp), AV_OPT_TYPE_INT, { .i64 = AVCOL_SPC_UNSPECIFIED },
1119  AVCOL_PRI_RESERVED0, AVCOL_PRI_NB - 1, FLAGS, "csp" },
1120  { "irange", "Input color range",
1121  OFFSET(user_irng), AV_OPT_TYPE_INT, { .i64 = AVCOL_RANGE_UNSPECIFIED },
1123  { "iprimaries", "Input color primaries",
1124  OFFSET(user_iprm), AV_OPT_TYPE_INT, { .i64 = AVCOL_PRI_UNSPECIFIED },
1125  AVCOL_PRI_RESERVED0, AVCOL_PRI_NB - 1, FLAGS, "prm" },
1126  { "itrc", "Input transfer characteristics",
1127  OFFSET(user_itrc), AV_OPT_TYPE_INT, { .i64 = AVCOL_TRC_UNSPECIFIED },
1128  AVCOL_TRC_RESERVED0, AVCOL_TRC_NB - 1, FLAGS, "trc" },
1129 
1130  { NULL }
1131 };
1132 
1133 AVFILTER_DEFINE_CLASS(colorspace);
1134 
1135 static const AVFilterPad inputs[] = {
1136  {
1137  .name = "default",
1138  .type = AVMEDIA_TYPE_VIDEO,
1139  .filter_frame = filter_frame,
1140  },
1141  { NULL }
1142 };
1143 
1144 static const AVFilterPad outputs[] = {
1145  {
1146  .name = "default",
1147  .type = AVMEDIA_TYPE_VIDEO,
1148  .config_props = config_props,
1149  },
1150  { NULL }
1151 };
1152 
1154  .name = "colorspace",
1155  .description = NULL_IF_CONFIG_SMALL("Convert between colorspaces."),
1156  .init = init,
1157  .uninit = uninit,
1158  .query_formats = query_formats,
1159  .priv_size = sizeof(ColorSpaceContext),
1160  .priv_class = &colorspace_class,
1161  .inputs = inputs,
1162  .outputs = outputs,
1164 };
ITU-R BT2020 for 12-bit system.
Definition: pixfmt.h:426
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / SMPTE RP177 Annex B
Definition: pixfmt.h:438
#define NULL
Definition: coverity.c:32
const char * s
Definition: avisynth_c.h:768
AVFrame * out
Definition: af_sofalizer.c:585
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2266
This structure describes decoded (raw) audio or video data.
Definition: frame.h:184
rgb2yuv_fn rgb2yuv
int16_t yuv_offset[2][8]
static enum AVColorPrimaries default_prm[CS_NB+1]
Definition: vf_colorspace.c:83
AVOption.
Definition: opt.h:245
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
double yuv2rgb_dbl_coeffs[3][3]
#define ma
static void fn() rgb2yuv(uint8_t *_yuv[3], const ptrdiff_t yuv_stride[3], int16_t *rgb[3], ptrdiff_t s, int w, int h, const int16_t rgb2yuv_coeffs[3][3][8], const int16_t yuv_offset[8])
static void invert_matrix3x3(const double in[3][3], double out[3][3])
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:67
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
int * dither_scratch[3][2]
Main libavfilter public API header.
static int init(AVFilterContext *ctx)
enum AVColorTransferCharacteristic in_trc out_trc user_trc user_itrc
const char * desc
Definition: nvenc.c:101
static const AVOption colorspace_options[]
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601 ...
Definition: pixfmt.h:442
static void yuv2rgb(uint8_t *out, int ridx, int Y, int U, int V)
Definition: g2meet.c:276
int16_t yuv2rgb_coeffs[3][3][8]
ptrdiff_t in_linesize[3]
static enum AVSampleFormat formats[]
Definition: avresample.c:163
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
Definition: pixfmt.h:443
static int get_range_off(AVFilterContext *ctx, int *off, int *y_rng, int *uv_rng, enum AVColorRange rng, int depth)
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:345
static void fn() yuv2yuv(uint8_t *_dst[3], const ptrdiff_t dst_stride[3], uint8_t *_src[3], const ptrdiff_t src_stride[3], int w, int h, const int16_t c[3][3][8], const int16_t yuv_offset[2][8])
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:76
order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB)
Definition: pixfmt.h:437
enum DitherMode dither
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:92
AVColorTransferCharacteristic
Color Transfer Characteristic.
Definition: pixfmt.h:410
functionally identical to above
Definition: pixfmt.h:444
const char * av_color_space_name(enum AVColorSpace space)
Definition: pixdesc.c:2597
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:283
static const struct ColorPrimaries * get_color_primaries(enum AVColorPrimaries prm)
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
Definition: avfilter.h:125
const char * name
Pad name.
Definition: internal.h:59
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:315
void(* yuv2rgb_fn)(int16_t *rgb[3], ptrdiff_t rgb_stride, uint8_t *yuv[3], const ptrdiff_t yuv_stride[3], int w, int h, const int16_t yuv2rgb_coeffs[3][3][8], const int16_t yuv_offset[8])
Definition: colorspacedsp.h:27
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1189
AVFrame * in
Definition: af_sofalizer.c:585
uint8_t bits
Definition: crc.c:296
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:117
uint8_t
#define av_malloc(s)
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Definition: avassert.h:64
AVOptions.
AVColorSpace
YUV colorspace type.
Definition: pixfmt.h:436
const char * av_color_range_name(enum AVColorRange range)
Definition: pixdesc.c:2579
AVFilter ff_vf_colorspace
enum Colorspace user_all user_iall
enum Whitepoint wp
also ITU-R BT470M / ITU-R BT1700 625 PAL & SECAM
Definition: pixfmt.h:415
static void uninit(AVFilterContext *ctx)
yuv2rgb_fn yuv2rgb
const struct ColorPrimaries * out_primaries
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
Definition: mem.h:101
Colorspace
Definition: vf_colorspace.c:43
ptrdiff_t out_linesize[3]
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
Definition: pixfmt.h:75
Not part of ABI.
Definition: pixfmt.h:461
AVColorRange
MPEG vs JPEG YUV range.
Definition: pixfmt.h:457
ColorSpaceDSPContext dsp
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:346
const struct ColorPrimaries * in_primaries
AVColorPrimaries
Chromaticity coordinates of the source primaries.
Definition: pixfmt.h:389
#define FFALIGN(x, a)
Definition: macros.h:48
static const struct LumaCoefficients * get_luma_coefficients(enum AVColorSpace csp)
#define av_log(a,...)
A filter pad used for either input or output.
Definition: internal.h:53
enum AVColorSpace in_csp out_csp user_csp user_icsp
ptrdiff_t rgb_stride
also FCC Title 47 Code of Federal Regulations 73.682 (a)(20)
Definition: pixfmt.h:394
int width
width and height of the video frame
Definition: frame.h:236
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
int ff_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats)
A helper for query_formats() which sets all links to the same list of formats.
Definition: formats.c:568
#define td
Definition: regdef.h:70
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:101
double rgb2yuv_dbl_coeffs[3][3]
#define AVERROR(e)
Definition: error.h:43
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:158
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:176
const struct LumaCoefficients * out_lumacoef
static const uint8_t dither[8][8]
Definition: vf_fspp.c:57
void * priv
private data for use by the filter
Definition: avfilter.h:322
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: frame.h:422
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Definition: avfilter.h:116
Not part of ABI.
Definition: pixfmt.h:404
enum AVColorSpace colorspace
YUV colorspace type.
Definition: frame.h:435
also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP177 Annex B
Definition: pixfmt.h:391
static void fill_rgb2yuv_table(const struct LumaCoefficients *coeffs, double rgb2yuv[3][3])
simple assert() macros that are a bit more flexible than ISO C assert().
int ff_add_format(AVFilterFormats **avff, int64_t fmt)
Add fmt to the list of media formats contained in *avff.
Definition: formats.c:337
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:344
static int create_filtergraph(AVFilterContext *ctx, const AVFrame *in, const AVFrame *out)
int depth
Definition: v4l.c:62
int av_frame_copy(AVFrame *dst, const AVFrame *src)
Copy the frame data from src to dst.
Definition: frame.c:719
static const AVFilterPad inputs[]
const char * av_color_primaries_name(enum AVColorPrimaries primaries)
Definition: pixdesc.c:2585
#define supported_format(d)
static void apply_lut(int16_t *buf[3], ptrdiff_t stride, int w, int h, const int16_t *lut)
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:66
#define ENUM(x, y, z)
void(* yuv2yuv_fn)(uint8_t *yuv_out[3], const ptrdiff_t yuv_out_stride[3], uint8_t *yuv_in[3], const ptrdiff_t yuv_in_stride[3], int w, int h, const int16_t yuv2yuv_coeffs[3][3][8], const int16_t yuv_offset[2][8])
Definition: colorspacedsp.h:40
static const struct TransferCharacteristics transfer_characteristics[AVCOL_TRC_NB]
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Definition: avfilter.c:786
#define FFMIN(a, b)
Definition: common.h:96
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Definition: pixfmt.h:74
int ff_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
Add *ref as a new reference to formats.
Definition: formats.c:440
void(* rgb2yuv_fsb_fn)(uint8_t *yuv[3], const ptrdiff_t yuv_stride[3], int16_t *rgb[3], ptrdiff_t rgb_stride, int w, int h, const int16_t rgb2yuv_coeffs[3][3][8], const int16_t yuv_offset[8], int *rnd[3][2])
Definition: colorspacedsp.h:35
static enum AVColorSpace default_csp[CS_NB+1]
Definition: vf_colorspace.c:96
ITU-R BT2020 non-constant luminance system.
Definition: pixfmt.h:446
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM
Definition: pixfmt.h:396
static const struct ColorPrimaries color_primaries[AVCOL_PRI_NB]
AVFormatContext * ctx
Definition: movenc.c:48
static const AVFilterPad outputs[]
int16_t * rgb[3]
int16_t lrgb2lrgb_coeffs[3][3][8]
int n
Definition: avisynth_c.h:684
#define FLAGS
static void fill_rgb2xyz_table(const struct ColorPrimaries *coeffs, double rgb2xyz[3][3])
#define src
Definition: vp9dsp.c:530
FCC Title 47 Code of Federal Regulations 73.682 (a)(20)
Definition: pixfmt.h:441
the normal 2^n-1 "JPEG" YUV ranges
Definition: pixfmt.h:460
planar GBR 4:4:4:4 48bpp, little-endian
Definition: pixfmt.h:302
enum AVColorPrimaries in_prm out_prm user_prm user_iprm
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
Definition: frame.h:248
also ITU-R BT1361
Definition: pixfmt.h:412
static void fill_whitepoint_conv_table(double out[3][3], enum WhitepointAdaptation wp_adapt, enum Whitepoint src, enum Whitepoint dst)
#define src1
Definition: h264pred.c:139
also ITU-R BT601-6 525 or 625 / ITU-R BT1358 525 or 625 / ITU-R BT1700 NTSC
Definition: pixfmt.h:417
static int query_formats(AVFilterContext *ctx)
int16_t yuv2yuv_coeffs[3][3][8]
functionally identical to above
Definition: pixfmt.h:398
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:215
void(* multiply3x3)(int16_t *data[3], ptrdiff_t stride, int w, int h, const int16_t m[3][3][8])
Definition: colorspacedsp.h:74
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
void(* rgb2yuv_fn)(uint8_t *yuv[3], const ptrdiff_t yuv_stride[3], int16_t *rgb[3], ptrdiff_t rgb_stride, int w, int h, const int16_t rgb2yuv_coeffs[3][3][8], const int16_t yuv_offset[8])
Definition: colorspacedsp.h:31
rgb2yuv_fsb_fn rgb2yuv_fsb
WhitepointAdaptation
Definition: vf_colorspace.c:62
yuv2yuv_fn yuv2yuv[NB_BPP][NB_BPP][NB_SS]
Definition: colorspacedsp.h:70
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
static int fill_gamma_table(ColorSpaceContext *s)
void * buf
Definition: avisynth_c.h:690
Whitepoint
Definition: vf_colorspace.c:56
rgb2yuv_fn rgb2yuv[NB_BPP][NB_SS]
Definition: colorspacedsp.h:65
int * dither_scratch_base[3][2]
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:341
Describe the class of an AVClass context structure.
Definition: log.h:67
Filter definition.
Definition: avfilter.h:144
yuv2rgb_fn yuv2rgb[NB_BPP][NB_SS]
Definition: colorspacedsp.h:62
Not part of ABI.
Definition: pixfmt.h:430
const struct LumaCoefficients * in_lumacoef
const char * name
Filter name.
Definition: avfilter.h:148
static enum AVColorTransferCharacteristic default_trc[CS_NB+1]
Definition: vf_colorspace.c:70
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:319
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:262
static const struct LumaCoefficients luma_coefficients[AVCOL_SPC_NB]
AVFilterInternal * internal
An opaque struct for libavfilter internal use.
Definition: avfilter.h:347
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:342
static int flags
Definition: cpu.c:47
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:348
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:198
the normal 219*2^(n-8) "MPEG" YUV ranges
Definition: pixfmt.h:459
ITU-R BT2020 constant luminance system.
Definition: pixfmt.h:447
GLint GLenum GLboolean GLsizei stride
Definition: opengl_enc.c:105
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:62
IEC 61966-2-1 (sRGB or sYCC)
Definition: pixfmt.h:424
enum WhitepointAdaptation wp_adapt
enum AVColorRange in_rng out_rng user_rng user_irng
void ff_colorspacedsp_init(ColorSpaceDSPContext *dsp)
const char * av_color_transfer_name(enum AVColorTransferCharacteristic transfer)
Definition: pixdesc.c:2591
also ITU-R BT470BG
Definition: pixfmt.h:416
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Definition: pixfmt.h:76
enum AVPixelFormat in_format user_format
static int convert(AVFilterContext *ctx, void *data, int job_nr, int n_jobs)
avfilter_execute_func * execute
Definition: internal.h:153
static const struct TransferCharacteristics * get_transfer_characteristics(enum AVColorTransferCharacteristic trc)
int16_t rgb2yuv_coeffs[3][3][8]
static void mul3x3(double dst[3][3], const double src1[3][3], const double src2[3][3])
pixel format definitions
static const int16_t coeffs[]
static uint8_t tmp[8]
Definition: des.c:38
const struct TransferCharacteristics * in_txchr
const struct TransferCharacteristics * out_txchr
A list of supported formats for one end of a filter link.
Definition: formats.h:64
#define lrint
Definition: tablegen.h:53
enum AVColorPrimaries color_primaries
Definition: frame.h:424
An instance of a filter.
Definition: avfilter.h:307
AVFILTER_DEFINE_CLASS(colorspace)
ITU-R BT2020 for 10-bit system.
Definition: pixfmt.h:425
static const struct WhitepointCoefficients whitepoint_coefficients[WP_NB]
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
Definition: pixfmt.h:397
ITU-R BT2020.
Definition: pixfmt.h:400
int height
Definition: frame.h:236
FILE * out
Definition: movenc.c:54
#define av_freep(p)
enum AVColorTransferCharacteristic color_trc
Definition: frame.h:426
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
#define stride
AVFilterLink * inlink
Definition: vf_blend.c:56
internal API functions
int depth
Number of bits in the component.
Definition: pixdesc.h:58
static int filter_frame(AVFilterLink *link, AVFrame *in)
static int config_props(AVFilterLink *outlink)
AVPixelFormat
Pixel format.
Definition: pixfmt.h:60
rgb2yuv_fsb_fn rgb2yuv_fsb[NB_BPP][NB_SS]
Definition: colorspacedsp.h:67
Not part of ABI.
Definition: pixfmt.h:449
DitherMode
Definition: vf_colorspace.c:37
yuv2yuv_fn yuv2yuv
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:589
#define OFFSET(x)