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 #include "colorspace.h"
37 
38 enum DitherMode {
42 };
43 
44 enum Colorspace {
55 };
56 
57 enum Whitepoint {
63 };
64 
71 };
72 
84 };
85 
86 static const enum AVColorPrimaries default_prm[CS_NB + 1] = {
97 };
98 
99 static const enum AVColorSpace default_csp[CS_NB + 1] = {
110 };
111 
115 };
116 
118  double alpha, beta, gamma, delta;
119 };
120 
121 typedef struct ColorSpaceContext {
122  const AVClass *class;
123 
125 
126  enum Colorspace user_all, user_iall;
127  enum AVColorSpace in_csp, out_csp, user_csp, user_icsp;
128  enum AVColorRange in_rng, out_rng, user_rng, user_irng;
129  enum AVColorTransferCharacteristic in_trc, out_trc, user_trc, user_itrc;
130  enum AVColorPrimaries in_prm, out_prm, user_prm, user_iprm;
131  enum AVPixelFormat in_format, user_format;
135 
136  int16_t *rgb[3];
137  ptrdiff_t rgb_stride;
138  unsigned rgb_sz;
140 
143  DECLARE_ALIGNED(16, int16_t, lrgb2lrgb_coeffs)[3][3][8];
144 
147  int16_t *lin_lut, *delin_lut;
148 
151  DECLARE_ALIGNED(16, int16_t, yuv2rgb_coeffs)[3][3][8];
152  DECLARE_ALIGNED(16, int16_t, rgb2yuv_coeffs)[3][3][8];
153  DECLARE_ALIGNED(16, int16_t, yuv2yuv_coeffs)[3][3][8];
154  DECLARE_ALIGNED(16, int16_t, yuv_offset)[2 /* in, out */][8];
161 
164 
165 // FIXME deal with odd width/heights
166 // FIXME faster linearize/delinearize implementation (integer pow)
167 // FIXME bt2020cl support (linearization between yuv/rgb step instead of between rgb/xyz)
168 // FIXME test that the values in (de)lin_lut don't exceed their container storage
169 // type size (only useful if we keep the LUT and don't move to fast integer pow)
170 // FIXME dithering if bitdepth goes down?
171 // FIXME bitexact for fate integration?
172 
173 static const double ycgco_matrix[3][3] =
174 {
175  { 0.25, 0.5, 0.25 },
176  { -0.25, 0.5, -0.25 },
177  { 0.5, 0, -0.5 },
178 };
179 
180 static const double gbr_matrix[3][3] =
181 {
182  { 0, 1, 0 },
183  { 0, -0.5, 0.5 },
184  { 0.5, -0.5, 0 },
185 };
186 
187 /*
188  * All constants explained in e.g. https://linuxtv.org/downloads/v4l-dvb-apis/ch02s06.html
189  * The older ones (bt470bg/m) are also explained in their respective ITU docs
190  * (e.g. https://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.470-5-199802-S!!PDF-E.pdf)
191  * whereas the newer ones can typically be copied directly from wikipedia :)
192  */
194  [AVCOL_SPC_FCC] = { 0.30, 0.59, 0.11 },
195  [AVCOL_SPC_BT470BG] = { 0.299, 0.587, 0.114 },
196  [AVCOL_SPC_SMPTE170M] = { 0.299, 0.587, 0.114 },
197  [AVCOL_SPC_BT709] = { 0.2126, 0.7152, 0.0722 },
198  [AVCOL_SPC_SMPTE240M] = { 0.212, 0.701, 0.087 },
199  [AVCOL_SPC_YCOCG] = { 0.25, 0.5, 0.25 },
200  [AVCOL_SPC_RGB] = { 1, 1, 1 },
201  [AVCOL_SPC_BT2020_NCL] = { 0.2627, 0.6780, 0.0593 },
202  [AVCOL_SPC_BT2020_CL] = { 0.2627, 0.6780, 0.0593 },
203 };
204 
206 {
207  const struct LumaCoefficients *coeffs;
208 
209  if (csp >= AVCOL_SPC_NB)
210  return NULL;
211  coeffs = &luma_coefficients[csp];
212  if (!coeffs->cr)
213  return NULL;
214 
215  return coeffs;
216 }
217 
218 static void fill_rgb2yuv_table(const struct LumaCoefficients *coeffs,
219  double rgb2yuv[3][3])
220 {
221  double bscale, rscale;
222 
223  // special ycgco matrix
224  if (coeffs->cr == 0.25 && coeffs->cg == 0.5 && coeffs->cb == 0.25) {
225  memcpy(rgb2yuv, ycgco_matrix, sizeof(double) * 9);
226  return;
227  } else if (coeffs->cr == 1 && coeffs->cg == 1 && coeffs->cb == 1) {
228  memcpy(rgb2yuv, gbr_matrix, sizeof(double) * 9);
229  return;
230  }
231 
232  rgb2yuv[0][0] = coeffs->cr;
233  rgb2yuv[0][1] = coeffs->cg;
234  rgb2yuv[0][2] = coeffs->cb;
235  bscale = 0.5 / (coeffs->cb - 1.0);
236  rscale = 0.5 / (coeffs->cr - 1.0);
237  rgb2yuv[1][0] = bscale * coeffs->cr;
238  rgb2yuv[1][1] = bscale * coeffs->cg;
239  rgb2yuv[1][2] = 0.5;
240  rgb2yuv[2][0] = 0.5;
241  rgb2yuv[2][1] = rscale * coeffs->cg;
242  rgb2yuv[2][2] = rscale * coeffs->cb;
243 }
244 
245 // FIXME I'm pretty sure gamma22/28 also have a linear toe slope, but I can't
246 // find any actual tables that document their real values...
247 // See http://www.13thmonkey.org/~boris/gammacorrection/ first graph why it matters
249  [AVCOL_TRC_BT709] = { 1.099, 0.018, 0.45, 4.5 },
250  [AVCOL_TRC_GAMMA22] = { 1.0, 0.0, 1.0 / 2.2, 0.0 },
251  [AVCOL_TRC_GAMMA28] = { 1.0, 0.0, 1.0 / 2.8, 0.0 },
252  [AVCOL_TRC_SMPTE170M] = { 1.099, 0.018, 0.45, 4.5 },
253  [AVCOL_TRC_SMPTE240M] = { 1.1115, 0.0228, 0.45, 4.0 },
254  [AVCOL_TRC_IEC61966_2_1] = { 1.055, 0.0031308, 1.0 / 2.4, 12.92 },
255  [AVCOL_TRC_IEC61966_2_4] = { 1.099, 0.018, 0.45, 4.5 },
256  [AVCOL_TRC_BT2020_10] = { 1.099, 0.018, 0.45, 4.5 },
257  [AVCOL_TRC_BT2020_12] = { 1.0993, 0.0181, 0.45, 4.5 },
258 };
259 
260 static const struct TransferCharacteristics *
262 {
263  const struct TransferCharacteristics *coeffs;
264 
265  if (trc >= AVCOL_TRC_NB)
266  return NULL;
267  coeffs = &transfer_characteristics[trc];
268  if (!coeffs->alpha)
269  return NULL;
270 
271  return coeffs;
272 }
273 
275  [WP_D65] = { 0.3127, 0.3290 },
276  [WP_C] = { 0.3100, 0.3160 },
277  [WP_DCI] = { 0.3140, 0.3510 },
278  [WP_E] = { 1/3.0f, 1/3.0f },
279 };
280 
282  [AVCOL_PRI_BT709] = { WP_D65, { 0.640, 0.330, 0.300, 0.600, 0.150, 0.060 } },
283  [AVCOL_PRI_BT470M] = { WP_C, { 0.670, 0.330, 0.210, 0.710, 0.140, 0.080 } },
284  [AVCOL_PRI_BT470BG] = { WP_D65, { 0.640, 0.330, 0.290, 0.600, 0.150, 0.060 } },
285  [AVCOL_PRI_SMPTE170M] = { WP_D65, { 0.630, 0.340, 0.310, 0.595, 0.155, 0.070 } },
286  [AVCOL_PRI_SMPTE240M] = { WP_D65, { 0.630, 0.340, 0.310, 0.595, 0.155, 0.070 } },
287  [AVCOL_PRI_SMPTE428] = { WP_E, { 0.735, 0.265, 0.274, 0.718, 0.167, 0.009 } },
288  [AVCOL_PRI_SMPTE431] = { WP_DCI, { 0.680, 0.320, 0.265, 0.690, 0.150, 0.060 } },
289  [AVCOL_PRI_SMPTE432] = { WP_D65, { 0.680, 0.320, 0.265, 0.690, 0.150, 0.060 } },
290  [AVCOL_PRI_FILM] = { WP_C, { 0.681, 0.319, 0.243, 0.692, 0.145, 0.049 } },
291  [AVCOL_PRI_BT2020] = { WP_D65, { 0.708, 0.292, 0.170, 0.797, 0.131, 0.046 } },
292  [AVCOL_PRI_JEDEC_P22] = { WP_D65, { 0.630, 0.340, 0.295, 0.605, 0.155, 0.077 } },
293 };
294 
296 {
297  const struct ColorPrimaries *p;
298 
299  if (prm >= AVCOL_PRI_NB)
300  return NULL;
301  p = &color_primaries[prm];
302  if (!p->coeff.xr)
303  return NULL;
304 
305  return p;
306 }
307 
309 {
310  int n;
311  double in_alpha = s->in_txchr->alpha, in_beta = s->in_txchr->beta;
312  double in_gamma = s->in_txchr->gamma, in_delta = s->in_txchr->delta;
313  double in_ialpha = 1.0 / in_alpha, in_igamma = 1.0 / in_gamma, in_idelta = 1.0 / in_delta;
314  double out_alpha = s->out_txchr->alpha, out_beta = s->out_txchr->beta;
315  double out_gamma = s->out_txchr->gamma, out_delta = s->out_txchr->delta;
316 
317  s->lin_lut = av_malloc(sizeof(*s->lin_lut) * 32768 * 2);
318  if (!s->lin_lut)
319  return AVERROR(ENOMEM);
320  s->delin_lut = &s->lin_lut[32768];
321  for (n = 0; n < 32768; n++) {
322  double v = (n - 2048.0) / 28672.0, d, l;
323 
324  // delinearize
325  if (v <= -out_beta) {
326  d = -out_alpha * pow(-v, out_gamma) + (out_alpha - 1.0);
327  } else if (v < out_beta) {
328  d = out_delta * v;
329  } else {
330  d = out_alpha * pow(v, out_gamma) - (out_alpha - 1.0);
331  }
332  s->delin_lut[n] = av_clip_int16(lrint(d * 28672.0));
333 
334  // linearize
335  if (v <= -in_beta) {
336  l = -pow((1.0 - in_alpha - v) * in_ialpha, in_igamma);
337  } else if (v < in_beta) {
338  l = v * in_idelta;
339  } else {
340  l = pow((v + in_alpha - 1.0) * in_ialpha, in_igamma);
341  }
342  s->lin_lut[n] = av_clip_int16(lrint(l * 28672.0));
343  }
344 
345  return 0;
346 }
347 
348 /*
349  * See http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html
350  * This function uses the Bradford mechanism.
351  */
352 static void fill_whitepoint_conv_table(double out[3][3], enum WhitepointAdaptation wp_adapt,
353  enum Whitepoint src, enum Whitepoint dst)
354 {
355  static const double ma_tbl[NB_WP_ADAPT_NON_IDENTITY][3][3] = {
356  [WP_ADAPT_BRADFORD] = {
357  { 0.8951, 0.2664, -0.1614 },
358  { -0.7502, 1.7135, 0.0367 },
359  { 0.0389, -0.0685, 1.0296 },
360  }, [WP_ADAPT_VON_KRIES] = {
361  { 0.40024, 0.70760, -0.08081 },
362  { -0.22630, 1.16532, 0.04570 },
363  { 0.00000, 0.00000, 0.91822 },
364  },
365  };
366  const double (*ma)[3] = ma_tbl[wp_adapt];
367  const struct WhitepointCoefficients *wp_src = &whitepoint_coefficients[src];
368  double zw_src = 1.0 - wp_src->xw - wp_src->yw;
369  const struct WhitepointCoefficients *wp_dst = &whitepoint_coefficients[dst];
370  double zw_dst = 1.0 - wp_dst->xw - wp_dst->yw;
371  double mai[3][3], fac[3][3], tmp[3][3];
372  double rs, gs, bs, rd, gd, bd;
373 
374  ff_matrix_invert_3x3(ma, mai);
375  rs = ma[0][0] * wp_src->xw + ma[0][1] * wp_src->yw + ma[0][2] * zw_src;
376  gs = ma[1][0] * wp_src->xw + ma[1][1] * wp_src->yw + ma[1][2] * zw_src;
377  bs = ma[2][0] * wp_src->xw + ma[2][1] * wp_src->yw + ma[2][2] * zw_src;
378  rd = ma[0][0] * wp_dst->xw + ma[0][1] * wp_dst->yw + ma[0][2] * zw_dst;
379  gd = ma[1][0] * wp_dst->xw + ma[1][1] * wp_dst->yw + ma[1][2] * zw_dst;
380  bd = ma[2][0] * wp_dst->xw + ma[2][1] * wp_dst->yw + ma[2][2] * zw_dst;
381  fac[0][0] = rd / rs;
382  fac[1][1] = gd / gs;
383  fac[2][2] = bd / bs;
384  fac[0][1] = fac[0][2] = fac[1][0] = fac[1][2] = fac[2][0] = fac[2][1] = 0.0;
385  ff_matrix_mul_3x3(tmp, ma, fac);
386  ff_matrix_mul_3x3(out, tmp, mai);
387 }
388 
389 static void apply_lut(int16_t *buf[3], ptrdiff_t stride,
390  int w, int h, const int16_t *lut)
391 {
392  int y, x, n;
393 
394  for (n = 0; n < 3; n++) {
395  int16_t *data = buf[n];
396 
397  for (y = 0; y < h; y++) {
398  for (x = 0; x < w; x++)
399  data[x] = lut[av_clip_uintp2(2048 + data[x], 15)];
400 
401  data += stride;
402  }
403  }
404 }
405 
406 struct ThreadData {
407  AVFrame *in, *out;
408  ptrdiff_t in_linesize[3], out_linesize[3];
410 };
411 
412 static int convert(AVFilterContext *ctx, void *data, int job_nr, int n_jobs)
413 {
414  struct ThreadData *td = data;
415  ColorSpaceContext *s = ctx->priv;
416  uint8_t *in_data[3], *out_data[3];
417  int16_t *rgb[3];
418  int h_in = (td->in->height + 1) >> 1;
419  int h1 = 2 * (job_nr * h_in / n_jobs), h2 = 2 * ((job_nr + 1) * h_in / n_jobs);
420  int w = td->in->width, h = h2 - h1;
421 
422  in_data[0] = td->in->data[0] + td->in_linesize[0] * h1;
423  in_data[1] = td->in->data[1] + td->in_linesize[1] * (h1 >> td->in_ss_h);
424  in_data[2] = td->in->data[2] + td->in_linesize[2] * (h1 >> td->in_ss_h);
425  out_data[0] = td->out->data[0] + td->out_linesize[0] * h1;
426  out_data[1] = td->out->data[1] + td->out_linesize[1] * (h1 >> td->out_ss_h);
427  out_data[2] = td->out->data[2] + td->out_linesize[2] * (h1 >> td->out_ss_h);
428  rgb[0] = s->rgb[0] + s->rgb_stride * h1;
429  rgb[1] = s->rgb[1] + s->rgb_stride * h1;
430  rgb[2] = s->rgb[2] + s->rgb_stride * h1;
431 
432  // FIXME for simd, also make sure we do pictures with negative stride
433  // top-down so we don't overwrite lines with padding of data before it
434  // in the same buffer (same as swscale)
435 
436  if (s->yuv2yuv_fastmode) {
437  // FIXME possibly use a fast mode in case only the y range changes?
438  // since in that case, only the diagonal entries in yuv2yuv_coeffs[]
439  // are non-zero
440  s->yuv2yuv(out_data, td->out_linesize, in_data, td->in_linesize, w, h,
441  s->yuv2yuv_coeffs, s->yuv_offset);
442  } else {
443  // FIXME maybe (for caching efficiency) do pipeline per-line instead of
444  // full buffer per function? (Or, since yuv2rgb requires 2 lines: per
445  // 2 lines, for yuv420.)
446  /*
447  * General design:
448  * - yuv2rgb converts from whatever range the input was ([16-235/240] or
449  * [0,255] or the 10/12bpp equivalents thereof) to an integer version
450  * of RGB in psuedo-restricted 15+sign bits. That means that the float
451  * range [0.0,1.0] is in [0,28762], and the remainder of the int16_t
452  * range is used for overflow/underflow outside the representable
453  * range of this RGB type. rgb2yuv is the exact opposite.
454  * - gamma correction is done using a LUT since that appears to work
455  * fairly fast.
456  * - If the input is chroma-subsampled (420/422), the yuv2rgb conversion
457  * (or rgb2yuv conversion) uses nearest-neighbour sampling to read
458  * read chroma pixels at luma resolution. If you want some more fancy
459  * filter, you can use swscale to convert to yuv444p.
460  * - all coefficients are 14bit (so in the [-2.0,2.0] range).
461  */
462  s->yuv2rgb(rgb, s->rgb_stride, in_data, td->in_linesize, w, h,
463  s->yuv2rgb_coeffs, s->yuv_offset[0]);
464  if (!s->rgb2rgb_passthrough) {
465  apply_lut(rgb, s->rgb_stride, w, h, s->lin_lut);
466  if (!s->lrgb2lrgb_passthrough)
467  s->dsp.multiply3x3(rgb, s->rgb_stride, w, h, s->lrgb2lrgb_coeffs);
468  apply_lut(rgb, s->rgb_stride, w, h, s->delin_lut);
469  }
470  if (s->dither == DITHER_FSB) {
471  s->rgb2yuv_fsb(out_data, td->out_linesize, rgb, s->rgb_stride, w, h,
473  } else {
474  s->rgb2yuv(out_data, td->out_linesize, rgb, s->rgb_stride, w, h,
475  s->rgb2yuv_coeffs, s->yuv_offset[1]);
476  }
477  }
478 
479  return 0;
480 }
481 
482 static int get_range_off(AVFilterContext *ctx, int *off,
483  int *y_rng, int *uv_rng,
484  enum AVColorRange rng, int depth)
485 {
486  switch (rng) {
488  ColorSpaceContext *s = ctx->priv;
489 
490  if (!s->did_warn_range) {
491  av_log(ctx, AV_LOG_WARNING, "Input range not set, assuming tv/mpeg\n");
492  s->did_warn_range = 1;
493  }
494  }
495  // fall-through
496  case AVCOL_RANGE_MPEG:
497  *off = 16 << (depth - 8);
498  *y_rng = 219 << (depth - 8);
499  *uv_rng = 224 << (depth - 8);
500  break;
501  case AVCOL_RANGE_JPEG:
502  *off = 0;
503  *y_rng = *uv_rng = (256 << (depth - 8)) - 1;
504  break;
505  default:
506  return AVERROR(EINVAL);
507  }
508 
509  return 0;
510 }
511 
513  const AVFrame *in, const AVFrame *out)
514 {
515  ColorSpaceContext *s = ctx->priv;
516  const AVPixFmtDescriptor *in_desc = av_pix_fmt_desc_get(in->format);
517  const AVPixFmtDescriptor *out_desc = av_pix_fmt_desc_get(out->format);
518  int emms = 0, m, n, o, res, fmt_identical, redo_yuv2rgb = 0, redo_rgb2yuv = 0;
519 
520 #define supported_depth(d) ((d) == 8 || (d) == 10 || (d) == 12)
521 #define supported_subsampling(lcw, lch) \
522  (((lcw) == 0 && (lch) == 0) || ((lcw) == 1 && (lch) == 0) || ((lcw) == 1 && (lch) == 1))
523 #define supported_format(d) \
524  ((d) != NULL && (d)->nb_components == 3 && \
525  !((d)->flags & AV_PIX_FMT_FLAG_RGB) && \
526  supported_depth((d)->comp[0].depth) && \
527  supported_subsampling((d)->log2_chroma_w, (d)->log2_chroma_h))
528 
529  if (!supported_format(in_desc)) {
530  av_log(ctx, AV_LOG_ERROR,
531  "Unsupported input format %d (%s) or bitdepth (%d)\n",
533  in_desc ? in_desc->comp[0].depth : -1);
534  return AVERROR(EINVAL);
535  }
536  if (!supported_format(out_desc)) {
537  av_log(ctx, AV_LOG_ERROR,
538  "Unsupported output format %d (%s) or bitdepth (%d)\n",
539  out->format, av_get_pix_fmt_name(out->format),
540  out_desc ? out_desc->comp[0].depth : -1);
541  return AVERROR(EINVAL);
542  }
543 
544  if (in->color_primaries != s->in_prm) s->in_primaries = NULL;
545  if (out->color_primaries != s->out_prm) s->out_primaries = NULL;
546  if (in->color_trc != s->in_trc) s->in_txchr = NULL;
547  if (out->color_trc != s->out_trc) s->out_txchr = NULL;
548  if (in->colorspace != s->in_csp ||
549  in->color_range != s->in_rng) s->in_lumacoef = NULL;
550  if (out->colorspace != s->out_csp ||
551  out->color_range != s->out_rng) s->out_lumacoef = NULL;
552 
553  if (!s->out_primaries || !s->in_primaries) {
554  s->in_prm = in->color_primaries;
555  if (s->user_iall != CS_UNSPECIFIED)
556  s->in_prm = default_prm[FFMIN(s->user_iall, CS_NB)];
558  s->in_prm = s->user_iprm;
559  s->in_primaries = get_color_primaries(s->in_prm);
560  if (!s->in_primaries) {
561  av_log(ctx, AV_LOG_ERROR,
562  "Unsupported input primaries %d (%s)\n",
563  s->in_prm, av_color_primaries_name(s->in_prm));
564  return AVERROR(EINVAL);
565  }
566  s->out_prm = out->color_primaries;
567  s->out_primaries = get_color_primaries(s->out_prm);
568  if (!s->out_primaries) {
569  if (s->out_prm == AVCOL_PRI_UNSPECIFIED) {
570  if (s->user_all == CS_UNSPECIFIED) {
571  av_log(ctx, AV_LOG_ERROR, "Please specify output primaries\n");
572  } else {
573  av_log(ctx, AV_LOG_ERROR,
574  "Unsupported output color property %d\n", s->user_all);
575  }
576  } else {
577  av_log(ctx, AV_LOG_ERROR,
578  "Unsupported output primaries %d (%s)\n",
579  s->out_prm, av_color_primaries_name(s->out_prm));
580  }
581  return AVERROR(EINVAL);
582  }
584  sizeof(*s->in_primaries));
585  if (!s->lrgb2lrgb_passthrough) {
586  double rgb2xyz[3][3], xyz2rgb[3][3], rgb2rgb[3][3];
587  const struct WhitepointCoefficients *wp_out, *wp_in;
588 
589  wp_out = &whitepoint_coefficients[s->out_primaries->wp];
590  wp_in = &whitepoint_coefficients[s->in_primaries->wp];
591  ff_fill_rgb2xyz_table(&s->out_primaries->coeff, wp_out, rgb2xyz);
592  ff_matrix_invert_3x3(rgb2xyz, xyz2rgb);
593  ff_fill_rgb2xyz_table(&s->in_primaries->coeff, wp_in, rgb2xyz);
594  if (s->out_primaries->wp != s->in_primaries->wp &&
595  s->wp_adapt != WP_ADAPT_IDENTITY) {
596  double wpconv[3][3], tmp[3][3];
597 
599  s->out_primaries->wp);
600  ff_matrix_mul_3x3(tmp, rgb2xyz, wpconv);
601  ff_matrix_mul_3x3(rgb2rgb, tmp, xyz2rgb);
602  } else {
603  ff_matrix_mul_3x3(rgb2rgb, rgb2xyz, xyz2rgb);
604  }
605  for (m = 0; m < 3; m++)
606  for (n = 0; n < 3; n++) {
607  s->lrgb2lrgb_coeffs[m][n][0] = lrint(16384.0 * rgb2rgb[m][n]);
608  for (o = 1; o < 8; o++)
609  s->lrgb2lrgb_coeffs[m][n][o] = s->lrgb2lrgb_coeffs[m][n][0];
610  }
611 
612  emms = 1;
613  }
614  }
615 
616  if (!s->in_txchr) {
617  av_freep(&s->lin_lut);
618  s->in_trc = in->color_trc;
619  if (s->user_iall != CS_UNSPECIFIED)
620  s->in_trc = default_trc[FFMIN(s->user_iall, CS_NB)];
622  s->in_trc = s->user_itrc;
623  s->in_txchr = get_transfer_characteristics(s->in_trc);
624  if (!s->in_txchr) {
625  av_log(ctx, AV_LOG_ERROR,
626  "Unsupported input transfer characteristics %d (%s)\n",
627  s->in_trc, av_color_transfer_name(s->in_trc));
628  return AVERROR(EINVAL);
629  }
630  }
631 
632  if (!s->out_txchr) {
633  av_freep(&s->lin_lut);
634  s->out_trc = out->color_trc;
635  s->out_txchr = get_transfer_characteristics(s->out_trc);
636  if (!s->out_txchr) {
637  if (s->out_trc == AVCOL_TRC_UNSPECIFIED) {
638  if (s->user_all == CS_UNSPECIFIED) {
639  av_log(ctx, AV_LOG_ERROR,
640  "Please specify output transfer characteristics\n");
641  } else {
642  av_log(ctx, AV_LOG_ERROR,
643  "Unsupported output color property %d\n", s->user_all);
644  }
645  } else {
646  av_log(ctx, AV_LOG_ERROR,
647  "Unsupported output transfer characteristics %d (%s)\n",
648  s->out_trc, av_color_transfer_name(s->out_trc));
649  }
650  return AVERROR(EINVAL);
651  }
652  }
653 
655  !memcmp(s->in_txchr, s->out_txchr, sizeof(*s->in_txchr)));
656  if (!s->rgb2rgb_passthrough && !s->lin_lut) {
657  res = fill_gamma_table(s);
658  if (res < 0)
659  return res;
660  emms = 1;
661  }
662 
663  if (!s->in_lumacoef) {
664  s->in_csp = in->colorspace;
665  if (s->user_iall != CS_UNSPECIFIED)
666  s->in_csp = default_csp[FFMIN(s->user_iall, CS_NB)];
668  s->in_csp = s->user_icsp;
669  s->in_rng = in->color_range;
671  s->in_rng = s->user_irng;
672  s->in_lumacoef = get_luma_coefficients(s->in_csp);
673  if (!s->in_lumacoef) {
674  av_log(ctx, AV_LOG_ERROR,
675  "Unsupported input colorspace %d (%s)\n",
676  s->in_csp, av_color_space_name(s->in_csp));
677  return AVERROR(EINVAL);
678  }
679  redo_yuv2rgb = 1;
680  }
681 
682  if (!s->out_lumacoef) {
683  s->out_csp = out->colorspace;
684  s->out_rng = out->color_range;
685  s->out_lumacoef = get_luma_coefficients(s->out_csp);
686  if (!s->out_lumacoef) {
687  if (s->out_csp == AVCOL_SPC_UNSPECIFIED) {
688  if (s->user_all == CS_UNSPECIFIED) {
689  av_log(ctx, AV_LOG_ERROR,
690  "Please specify output transfer characteristics\n");
691  } else {
692  av_log(ctx, AV_LOG_ERROR,
693  "Unsupported output color property %d\n", s->user_all);
694  }
695  } else {
696  av_log(ctx, AV_LOG_ERROR,
697  "Unsupported output transfer characteristics %d (%s)\n",
698  s->out_csp, av_color_space_name(s->out_csp));
699  }
700  return AVERROR(EINVAL);
701  }
702  redo_rgb2yuv = 1;
703  }
704 
705  fmt_identical = in_desc->log2_chroma_h == out_desc->log2_chroma_h &&
706  in_desc->log2_chroma_w == out_desc->log2_chroma_w;
707  s->yuv2yuv_fastmode = s->rgb2rgb_passthrough && fmt_identical;
708  s->yuv2yuv_passthrough = s->yuv2yuv_fastmode && s->in_rng == s->out_rng &&
709  !memcmp(s->in_lumacoef, s->out_lumacoef,
710  sizeof(*s->in_lumacoef)) &&
711  in_desc->comp[0].depth == out_desc->comp[0].depth;
712  if (!s->yuv2yuv_passthrough) {
713  if (redo_yuv2rgb) {
714  double rgb2yuv[3][3], (*yuv2rgb)[3] = s->yuv2rgb_dbl_coeffs;
715  int off, bits, in_rng;
716 
717  res = get_range_off(ctx, &off, &s->in_y_rng, &s->in_uv_rng,
718  s->in_rng, in_desc->comp[0].depth);
719  if (res < 0) {
720  av_log(ctx, AV_LOG_ERROR,
721  "Unsupported input color range %d (%s)\n",
722  s->in_rng, av_color_range_name(s->in_rng));
723  return res;
724  }
725  for (n = 0; n < 8; n++)
726  s->yuv_offset[0][n] = off;
727  fill_rgb2yuv_table(s->in_lumacoef, rgb2yuv);
728  ff_matrix_invert_3x3(rgb2yuv, yuv2rgb);
729  bits = 1 << (in_desc->comp[0].depth - 1);
730  for (n = 0; n < 3; n++) {
731  for (in_rng = s->in_y_rng, m = 0; m < 3; m++, in_rng = s->in_uv_rng) {
732  s->yuv2rgb_coeffs[n][m][0] = lrint(28672 * bits * yuv2rgb[n][m] / in_rng);
733  for (o = 1; o < 8; o++)
734  s->yuv2rgb_coeffs[n][m][o] = s->yuv2rgb_coeffs[n][m][0];
735  }
736  }
737  av_assert2(s->yuv2rgb_coeffs[0][1][0] == 0);
738  av_assert2(s->yuv2rgb_coeffs[2][2][0] == 0);
739  av_assert2(s->yuv2rgb_coeffs[0][0][0] == s->yuv2rgb_coeffs[1][0][0]);
740  av_assert2(s->yuv2rgb_coeffs[0][0][0] == s->yuv2rgb_coeffs[2][0][0]);
741  s->yuv2rgb = s->dsp.yuv2rgb[(in_desc->comp[0].depth - 8) >> 1]
742  [in_desc->log2_chroma_h + in_desc->log2_chroma_w];
743  emms = 1;
744  }
745 
746  if (redo_rgb2yuv) {
747  double (*rgb2yuv)[3] = s->rgb2yuv_dbl_coeffs;
748  int off, out_rng, bits;
749 
750  res = get_range_off(ctx, &off, &s->out_y_rng, &s->out_uv_rng,
751  s->out_rng, out_desc->comp[0].depth);
752  if (res < 0) {
753  av_log(ctx, AV_LOG_ERROR,
754  "Unsupported output color range %d (%s)\n",
755  s->out_rng, av_color_range_name(s->out_rng));
756  return res;
757  }
758  for (n = 0; n < 8; n++)
759  s->yuv_offset[1][n] = off;
761  bits = 1 << (29 - out_desc->comp[0].depth);
762  for (out_rng = s->out_y_rng, n = 0; n < 3; n++, out_rng = s->out_uv_rng) {
763  for (m = 0; m < 3; m++) {
764  s->rgb2yuv_coeffs[n][m][0] = lrint(bits * out_rng * rgb2yuv[n][m] / 28672);
765  for (o = 1; o < 8; o++)
766  s->rgb2yuv_coeffs[n][m][o] = s->rgb2yuv_coeffs[n][m][0];
767  }
768  }
769  av_assert2(s->rgb2yuv_coeffs[1][2][0] == s->rgb2yuv_coeffs[2][0][0]);
770  s->rgb2yuv = s->dsp.rgb2yuv[(out_desc->comp[0].depth - 8) >> 1]
771  [out_desc->log2_chroma_h + out_desc->log2_chroma_w];
772  s->rgb2yuv_fsb = s->dsp.rgb2yuv_fsb[(out_desc->comp[0].depth - 8) >> 1]
773  [out_desc->log2_chroma_h + out_desc->log2_chroma_w];
774  emms = 1;
775  }
776 
777  if (s->yuv2yuv_fastmode && (redo_yuv2rgb || redo_rgb2yuv)) {
778  int idepth = in_desc->comp[0].depth, odepth = out_desc->comp[0].depth;
779  double (*rgb2yuv)[3] = s->rgb2yuv_dbl_coeffs;
780  double (*yuv2rgb)[3] = s->yuv2rgb_dbl_coeffs;
781  double yuv2yuv[3][3];
782  int in_rng, out_rng;
783 
784  ff_matrix_mul_3x3(yuv2yuv, yuv2rgb, rgb2yuv);
785  for (out_rng = s->out_y_rng, m = 0; m < 3; m++, out_rng = s->out_uv_rng) {
786  for (in_rng = s->in_y_rng, n = 0; n < 3; n++, in_rng = s->in_uv_rng) {
787  s->yuv2yuv_coeffs[m][n][0] =
788  lrint(16384 * yuv2yuv[m][n] * out_rng * (1 << idepth) /
789  (in_rng * (1 << odepth)));
790  for (o = 1; o < 8; o++)
791  s->yuv2yuv_coeffs[m][n][o] = s->yuv2yuv_coeffs[m][n][0];
792  }
793  }
794  av_assert2(s->yuv2yuv_coeffs[1][0][0] == 0);
795  av_assert2(s->yuv2yuv_coeffs[2][0][0] == 0);
796  s->yuv2yuv = s->dsp.yuv2yuv[(idepth - 8) >> 1][(odepth - 8) >> 1]
797  [in_desc->log2_chroma_h + in_desc->log2_chroma_w];
798  }
799  }
800 
801  if (emms)
802  emms_c();
803 
804  return 0;
805 }
806 
808 {
809  ColorSpaceContext *s = ctx->priv;
810 
812 
813  return 0;
814 }
815 
817 {
818  ColorSpaceContext *s = ctx->priv;
819 
820  av_freep(&s->rgb[0]);
821  av_freep(&s->rgb[1]);
822  av_freep(&s->rgb[2]);
823  s->rgb_sz = 0;
824  av_freep(&s->dither_scratch_base[0][0]);
825  av_freep(&s->dither_scratch_base[0][1]);
826  av_freep(&s->dither_scratch_base[1][0]);
827  av_freep(&s->dither_scratch_base[1][1]);
828  av_freep(&s->dither_scratch_base[2][0]);
829  av_freep(&s->dither_scratch_base[2][1]);
830 
831  av_freep(&s->lin_lut);
832 }
833 
834 static int filter_frame(AVFilterLink *link, AVFrame *in)
835 {
836  AVFilterContext *ctx = link->dst;
837  AVFilterLink *outlink = ctx->outputs[0];
838  ColorSpaceContext *s = ctx->priv;
839  // FIXME if yuv2yuv_passthrough, don't get a new buffer but use the
840  // input one if it is writable *OR* the actual literal values of in_*
841  // and out_* are identical (not just their respective properties)
842  AVFrame *out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
843  int res;
844  ptrdiff_t rgb_stride = FFALIGN(in->width * sizeof(int16_t), 32);
845  unsigned rgb_sz = rgb_stride * in->height;
846  struct ThreadData td;
847 
848  if (!out) {
849  av_frame_free(&in);
850  return AVERROR(ENOMEM);
851  }
852  res = av_frame_copy_props(out, in);
853  if (res < 0) {
854  av_frame_free(&in);
855  return res;
856  }
857 
858  out->color_primaries = s->user_prm == AVCOL_PRI_UNSPECIFIED ?
859  default_prm[FFMIN(s->user_all, CS_NB)] : s->user_prm;
860  if (s->user_trc == AVCOL_TRC_UNSPECIFIED) {
862 
863  out->color_trc = default_trc[FFMIN(s->user_all, CS_NB)];
864  if (out->color_trc == AVCOL_TRC_BT2020_10 && desc && desc->comp[0].depth >= 12)
866  } else {
867  out->color_trc = s->user_trc;
868  }
869  out->colorspace = s->user_csp == AVCOL_SPC_UNSPECIFIED ?
870  default_csp[FFMIN(s->user_all, CS_NB)] : s->user_csp;
871  out->color_range = s->user_rng == AVCOL_RANGE_UNSPECIFIED ?
872  in->color_range : s->user_rng;
873  if (rgb_sz != s->rgb_sz) {
875  int uvw = in->width >> desc->log2_chroma_w;
876 
877  av_freep(&s->rgb[0]);
878  av_freep(&s->rgb[1]);
879  av_freep(&s->rgb[2]);
880  s->rgb_sz = 0;
881  av_freep(&s->dither_scratch_base[0][0]);
882  av_freep(&s->dither_scratch_base[0][1]);
883  av_freep(&s->dither_scratch_base[1][0]);
884  av_freep(&s->dither_scratch_base[1][1]);
885  av_freep(&s->dither_scratch_base[2][0]);
886  av_freep(&s->dither_scratch_base[2][1]);
887 
888  s->rgb[0] = av_malloc(rgb_sz);
889  s->rgb[1] = av_malloc(rgb_sz);
890  s->rgb[2] = av_malloc(rgb_sz);
891  s->dither_scratch_base[0][0] =
892  av_malloc(sizeof(*s->dither_scratch_base[0][0]) * (in->width + 4));
893  s->dither_scratch_base[0][1] =
894  av_malloc(sizeof(*s->dither_scratch_base[0][1]) * (in->width + 4));
895  s->dither_scratch_base[1][0] =
896  av_malloc(sizeof(*s->dither_scratch_base[1][0]) * (uvw + 4));
897  s->dither_scratch_base[1][1] =
898  av_malloc(sizeof(*s->dither_scratch_base[1][1]) * (uvw + 4));
899  s->dither_scratch_base[2][0] =
900  av_malloc(sizeof(*s->dither_scratch_base[2][0]) * (uvw + 4));
901  s->dither_scratch_base[2][1] =
902  av_malloc(sizeof(*s->dither_scratch_base[2][1]) * (uvw + 4));
903  s->dither_scratch[0][0] = &s->dither_scratch_base[0][0][1];
904  s->dither_scratch[0][1] = &s->dither_scratch_base[0][1][1];
905  s->dither_scratch[1][0] = &s->dither_scratch_base[1][0][1];
906  s->dither_scratch[1][1] = &s->dither_scratch_base[1][1][1];
907  s->dither_scratch[2][0] = &s->dither_scratch_base[2][0][1];
908  s->dither_scratch[2][1] = &s->dither_scratch_base[2][1][1];
909  if (!s->rgb[0] || !s->rgb[1] || !s->rgb[2] ||
910  !s->dither_scratch_base[0][0] || !s->dither_scratch_base[0][1] ||
911  !s->dither_scratch_base[1][0] || !s->dither_scratch_base[1][1] ||
912  !s->dither_scratch_base[2][0] || !s->dither_scratch_base[2][1]) {
913  uninit(ctx);
914  return AVERROR(ENOMEM);
915  }
916  s->rgb_sz = rgb_sz;
917  }
918  res = create_filtergraph(ctx, in, out);
919  if (res < 0)
920  return res;
921  s->rgb_stride = rgb_stride / sizeof(int16_t);
922  td.in = in;
923  td.out = out;
924  td.in_linesize[0] = in->linesize[0];
925  td.in_linesize[1] = in->linesize[1];
926  td.in_linesize[2] = in->linesize[2];
927  td.out_linesize[0] = out->linesize[0];
928  td.out_linesize[1] = out->linesize[1];
929  td.out_linesize[2] = out->linesize[2];
932  if (s->yuv2yuv_passthrough) {
933  res = av_frame_copy(out, in);
934  if (res < 0)
935  return res;
936  } else {
937  ctx->internal->execute(ctx, convert, &td, NULL,
938  FFMIN((in->height + 1) >> 1, ff_filter_get_nb_threads(ctx)));
939  }
940  av_frame_free(&in);
941 
942  return ff_filter_frame(outlink, out);
943 }
944 
946 {
947  static const enum AVPixelFormat pix_fmts[] = {
953  };
954  int res;
955  ColorSpaceContext *s = ctx->priv;
957 
958  if (!formats)
959  return AVERROR(ENOMEM);
960  if (s->user_format == AV_PIX_FMT_NONE)
961  return ff_set_common_formats(ctx, formats);
962  res = ff_formats_ref(formats, &ctx->inputs[0]->out_formats);
963  if (res < 0)
964  return res;
965  formats = NULL;
966  res = ff_add_format(&formats, s->user_format);
967  if (res < 0)
968  return res;
969 
970  return ff_formats_ref(formats, &ctx->outputs[0]->in_formats);
971 }
972 
973 static int config_props(AVFilterLink *outlink)
974 {
975  AVFilterContext *ctx = outlink->dst;
976  AVFilterLink *inlink = outlink->src->inputs[0];
977 
978  if (inlink->w % 2 || inlink->h % 2) {
979  av_log(ctx, AV_LOG_ERROR, "Invalid odd size (%dx%d)\n",
980  inlink->w, inlink->h);
981  return AVERROR_PATCHWELCOME;
982  }
983 
984  outlink->w = inlink->w;
985  outlink->h = inlink->h;
986  outlink->sample_aspect_ratio = inlink->sample_aspect_ratio;
987  outlink->time_base = inlink->time_base;
988 
989  return 0;
990 }
991 
992 #define OFFSET(x) offsetof(ColorSpaceContext, x)
993 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM
994 #define ENUM(x, y, z) { x, "", 0, AV_OPT_TYPE_CONST, { .i64 = y }, INT_MIN, INT_MAX, FLAGS, z }
995 
996 static const AVOption colorspace_options[] = {
997  { "all", "Set all color properties together",
998  OFFSET(user_all), AV_OPT_TYPE_INT, { .i64 = CS_UNSPECIFIED },
999  CS_UNSPECIFIED, CS_NB - 1, FLAGS, "all" },
1000  ENUM("bt470m", CS_BT470M, "all"),
1001  ENUM("bt470bg", CS_BT470BG, "all"),
1002  ENUM("bt601-6-525", CS_BT601_6_525, "all"),
1003  ENUM("bt601-6-625", CS_BT601_6_625, "all"),
1004  ENUM("bt709", CS_BT709, "all"),
1005  ENUM("smpte170m", CS_SMPTE170M, "all"),
1006  ENUM("smpte240m", CS_SMPTE240M, "all"),
1007  ENUM("bt2020", CS_BT2020, "all"),
1008 
1009  { "space", "Output colorspace",
1010  OFFSET(user_csp), AV_OPT_TYPE_INT, { .i64 = AVCOL_SPC_UNSPECIFIED },
1011  AVCOL_SPC_RGB, AVCOL_SPC_NB - 1, FLAGS, "csp"},
1012  ENUM("bt709", AVCOL_SPC_BT709, "csp"),
1013  ENUM("fcc", AVCOL_SPC_FCC, "csp"),
1014  ENUM("bt470bg", AVCOL_SPC_BT470BG, "csp"),
1015  ENUM("smpte170m", AVCOL_SPC_SMPTE170M, "csp"),
1016  ENUM("smpte240m", AVCOL_SPC_SMPTE240M, "csp"),
1017  ENUM("ycgco", AVCOL_SPC_YCGCO, "csp"),
1018  ENUM("gbr", AVCOL_SPC_RGB, "csp"),
1019  ENUM("bt2020nc", AVCOL_SPC_BT2020_NCL, "csp"),
1020  ENUM("bt2020ncl", AVCOL_SPC_BT2020_NCL, "csp"),
1021 
1022  { "range", "Output color range",
1023  OFFSET(user_rng), AV_OPT_TYPE_INT, { .i64 = AVCOL_RANGE_UNSPECIFIED },
1025  ENUM("tv", AVCOL_RANGE_MPEG, "rng"),
1026  ENUM("mpeg", AVCOL_RANGE_MPEG, "rng"),
1027  ENUM("pc", AVCOL_RANGE_JPEG, "rng"),
1028  ENUM("jpeg", AVCOL_RANGE_JPEG, "rng"),
1029 
1030  { "primaries", "Output color primaries",
1031  OFFSET(user_prm), AV_OPT_TYPE_INT, { .i64 = AVCOL_PRI_UNSPECIFIED },
1032  AVCOL_PRI_RESERVED0, AVCOL_PRI_NB - 1, FLAGS, "prm" },
1033  ENUM("bt709", AVCOL_PRI_BT709, "prm"),
1034  ENUM("bt470m", AVCOL_PRI_BT470M, "prm"),
1035  ENUM("bt470bg", AVCOL_PRI_BT470BG, "prm"),
1036  ENUM("smpte170m", AVCOL_PRI_SMPTE170M, "prm"),
1037  ENUM("smpte240m", AVCOL_PRI_SMPTE240M, "prm"),
1038  ENUM("smpte428", AVCOL_PRI_SMPTE428, "prm"),
1039  ENUM("film", AVCOL_PRI_FILM, "prm"),
1040  ENUM("smpte431", AVCOL_PRI_SMPTE431, "prm"),
1041  ENUM("smpte432", AVCOL_PRI_SMPTE432, "prm"),
1042  ENUM("bt2020", AVCOL_PRI_BT2020, "prm"),
1043  ENUM("jedec-p22", AVCOL_PRI_JEDEC_P22, "prm"),
1044 
1045  { "trc", "Output transfer characteristics",
1046  OFFSET(user_trc), AV_OPT_TYPE_INT, { .i64 = AVCOL_TRC_UNSPECIFIED },
1047  AVCOL_TRC_RESERVED0, AVCOL_TRC_NB - 1, FLAGS, "trc" },
1048  ENUM("bt709", AVCOL_TRC_BT709, "trc"),
1049  ENUM("bt470m", AVCOL_TRC_GAMMA22, "trc"),
1050  ENUM("gamma22", AVCOL_TRC_GAMMA22, "trc"),
1051  ENUM("bt470bg", AVCOL_TRC_GAMMA28, "trc"),
1052  ENUM("gamma28", AVCOL_TRC_GAMMA28, "trc"),
1053  ENUM("smpte170m", AVCOL_TRC_SMPTE170M, "trc"),
1054  ENUM("smpte240m", AVCOL_TRC_SMPTE240M, "trc"),
1055  ENUM("srgb", AVCOL_TRC_IEC61966_2_1, "trc"),
1056  ENUM("iec61966-2-1", AVCOL_TRC_IEC61966_2_1, "trc"),
1057  ENUM("xvycc", AVCOL_TRC_IEC61966_2_4, "trc"),
1058  ENUM("iec61966-2-4", AVCOL_TRC_IEC61966_2_4, "trc"),
1059  ENUM("bt2020-10", AVCOL_TRC_BT2020_10, "trc"),
1060  ENUM("bt2020-12", AVCOL_TRC_BT2020_12, "trc"),
1061 
1062  { "format", "Output pixel format",
1063  OFFSET(user_format), AV_OPT_TYPE_INT, { .i64 = AV_PIX_FMT_NONE },
1065  ENUM("yuv420p", AV_PIX_FMT_YUV420P, "fmt"),
1066  ENUM("yuv420p10", AV_PIX_FMT_YUV420P10, "fmt"),
1067  ENUM("yuv420p12", AV_PIX_FMT_YUV420P12, "fmt"),
1068  ENUM("yuv422p", AV_PIX_FMT_YUV422P, "fmt"),
1069  ENUM("yuv422p10", AV_PIX_FMT_YUV422P10, "fmt"),
1070  ENUM("yuv422p12", AV_PIX_FMT_YUV422P12, "fmt"),
1071  ENUM("yuv444p", AV_PIX_FMT_YUV444P, "fmt"),
1072  ENUM("yuv444p10", AV_PIX_FMT_YUV444P10, "fmt"),
1073  ENUM("yuv444p12", AV_PIX_FMT_YUV444P12, "fmt"),
1074 
1075  { "fast", "Ignore primary chromaticity and gamma correction",
1076  OFFSET(fast_mode), AV_OPT_TYPE_BOOL, { .i64 = 0 },
1077  0, 1, FLAGS },
1078 
1079  { "dither", "Dithering mode",
1080  OFFSET(dither), AV_OPT_TYPE_INT, { .i64 = DITHER_NONE },
1081  DITHER_NONE, DITHER_NB - 1, FLAGS, "dither" },
1082  ENUM("none", DITHER_NONE, "dither"),
1083  ENUM("fsb", DITHER_FSB, "dither"),
1084 
1085  { "wpadapt", "Whitepoint adaptation method",
1086  OFFSET(wp_adapt), AV_OPT_TYPE_INT, { .i64 = WP_ADAPT_BRADFORD },
1087  WP_ADAPT_BRADFORD, NB_WP_ADAPT - 1, FLAGS, "wpadapt" },
1088  ENUM("bradford", WP_ADAPT_BRADFORD, "wpadapt"),
1089  ENUM("vonkries", WP_ADAPT_VON_KRIES, "wpadapt"),
1090  ENUM("identity", WP_ADAPT_IDENTITY, "wpadapt"),
1091 
1092  { "iall", "Set all input color properties together",
1093  OFFSET(user_iall), AV_OPT_TYPE_INT, { .i64 = CS_UNSPECIFIED },
1094  CS_UNSPECIFIED, CS_NB - 1, FLAGS, "all" },
1095  { "ispace", "Input colorspace",
1096  OFFSET(user_icsp), AV_OPT_TYPE_INT, { .i64 = AVCOL_SPC_UNSPECIFIED },
1097  AVCOL_PRI_RESERVED0, AVCOL_PRI_NB - 1, FLAGS, "csp" },
1098  { "irange", "Input color range",
1099  OFFSET(user_irng), AV_OPT_TYPE_INT, { .i64 = AVCOL_RANGE_UNSPECIFIED },
1101  { "iprimaries", "Input color primaries",
1102  OFFSET(user_iprm), AV_OPT_TYPE_INT, { .i64 = AVCOL_PRI_UNSPECIFIED },
1103  AVCOL_PRI_RESERVED0, AVCOL_PRI_NB - 1, FLAGS, "prm" },
1104  { "itrc", "Input transfer characteristics",
1105  OFFSET(user_itrc), AV_OPT_TYPE_INT, { .i64 = AVCOL_TRC_UNSPECIFIED },
1106  AVCOL_TRC_RESERVED0, AVCOL_TRC_NB - 1, FLAGS, "trc" },
1107 
1108  { NULL }
1109 };
1110 
1111 AVFILTER_DEFINE_CLASS(colorspace);
1112 
1113 static const AVFilterPad inputs[] = {
1114  {
1115  .name = "default",
1116  .type = AVMEDIA_TYPE_VIDEO,
1117  .filter_frame = filter_frame,
1118  },
1119  { NULL }
1120 };
1121 
1122 static const AVFilterPad outputs[] = {
1123  {
1124  .name = "default",
1125  .type = AVMEDIA_TYPE_VIDEO,
1126  .config_props = config_props,
1127  },
1128  { NULL }
1129 };
1130 
1132  .name = "colorspace",
1133  .description = NULL_IF_CONFIG_SMALL("Convert between colorspaces."),
1134  .init = init,
1135  .uninit = uninit,
1136  .query_formats = query_formats,
1137  .priv_size = sizeof(ColorSpaceContext),
1138  .priv_class = &colorspace_class,
1139  .inputs = inputs,
1140  .outputs = outputs,
1142 };
ITU-R BT2020 for 12-bit system.
Definition: pixfmt.h:473
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / SMPTE RP177 Annex B
Definition: pixfmt.h:488
#define NULL
Definition: coverity.c:32
AVFrame * out
Definition: af_adeclick.c:485
IEC 61966-2-4.
Definition: pixfmt.h:469
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2446
This structure describes decoded (raw) audio or video data.
Definition: frame.h:226
rgb2yuv_fn rgb2yuv
int16_t yuv_offset[2][8]
static enum AVColorPrimaries default_prm[CS_NB+1]
Definition: vf_colorspace.c:86
AVOption.
Definition: opt.h:246
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])
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:71
#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
JEDEC P22 phosphors.
Definition: pixfmt.h:449
const char * desc
Definition: nvenc.c:65
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:492
static void yuv2rgb(uint8_t *out, int ridx, int Y, int U, int V)
Definition: g2meet.c:277
SMPTE ST 432-1 (2010) / P3 D65 / Display P3.
Definition: pixfmt.h:448
int16_t yuv2rgb_coeffs[3][3][8]
ptrdiff_t in_linesize[3]
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
Definition: pixfmt.h:493
static int get_range_off(AVFilterContext *ctx, int *off, int *y_rng, int *uv_rng, enum AVColorRange rng, int depth)
SMPTE ST 431-2 (2011) / DCI P3.
Definition: pixfmt.h:447
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:383
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:99
#define src
Definition: vp8dsp.c:254
order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB)
Definition: pixfmt.h:487
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:457
functionally identical to above
Definition: pixfmt.h:494
const char * av_color_space_name(enum AVColorSpace space)
Definition: pixdesc.c:2839
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:60
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:346
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:1080
AVFrame * in
Definition: af_afftdn.c:1082
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:486
const char * av_color_range_name(enum AVColorRange range)
Definition: pixdesc.c:2772
AVFilter ff_vf_colorspace
enum Colorspace user_all user_iall
Used by Dirac / VC-2 and H.264 FRext, see ITU-T SG16.
Definition: pixfmt.h:495
enum Whitepoint wp
also ITU-R BT470M / ITU-R BT1700 625 PAL & SECAM
Definition: pixfmt.h:462
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:112
Colorspace
Definition: vf_colorspace.c:44
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:79
Not part of ABI.
Definition: pixfmt.h:513
AVColorRange
MPEG vs JPEG YUV range.
Definition: pixfmt.h:509
ColorSpaceDSPContext dsp
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:384
const struct ColorPrimaries * in_primaries
AVColorPrimaries
Chromaticity coordinates of the source primaries.
Definition: pixfmt.h:433
#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:54
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:438
int width
Definition: frame.h:284
#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:202
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:186
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:353
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: frame.h:471
#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:450
enum AVColorSpace colorspace
YUV colorspace type.
Definition: frame.h:482
also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP177 Annex B
Definition: pixfmt.h:435
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
SMPTE ST 428-1 (CIE 1931 XYZ)
Definition: pixfmt.h:445
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:382
static int create_filtergraph(AVFilterContext *ctx, const AVFrame *in, const AVFrame *out)
int av_frame_copy(AVFrame *dst, const AVFrame *src)
Copy the frame data from src to dst.
Definition: frame.c:792
static const AVFilterPad inputs[]
const char * av_color_primaries_name(enum AVColorPrimaries primaries)
Definition: pixdesc.c:2791
#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:70
struct PrimaryCoefficients coeff
#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:802
#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:78
colour filters using Illuminant C
Definition: pixfmt.h:443
int ff_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
Add *ref as a new reference to formats.
Definition: formats.c:440
uint8_t w
Definition: llviddspenc.c:38
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 const double gbr_matrix[3][3]
static enum AVColorSpace default_csp[CS_NB+1]
Definition: vf_colorspace.c:99
AVFrame * m
ITU-R BT2020 non-constant luminance system.
Definition: pixfmt.h:497
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM
Definition: pixfmt.h:440
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]
#define s(width, name)
Definition: cbs_vp9.c:257
int n
Definition: avisynth_c.h:684
#define FLAGS
FCC Title 47 Code of Federal Regulations 73.682 (a)(20)
Definition: pixfmt.h:491
the normal 2^n-1 "JPEG" YUV ranges
Definition: pixfmt.h:512
planar GBR 4:4:4:4 48bpp, little-endian
Definition: pixfmt.h:288
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
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:299
also ITU-R BT1361
Definition: pixfmt.h:459
static const double ycgco_matrix[3][3]
static void fill_whitepoint_conv_table(double out[3][3], enum WhitepointAdaptation wp_adapt, enum Whitepoint src, enum Whitepoint dst)
also ITU-R BT601-6 525 or 625 / ITU-R BT1358 525 or 625 / ITU-R BT1700 NTSC
Definition: pixfmt.h:464
static int query_formats(AVFilterContext *ctx)
int16_t yuv2yuv_coeffs[3][3][8]
functionally identical to above
Definition: pixfmt.h:442
Used for passing data between threads.
Definition: af_adeclick.c:484
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:257
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:65
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:57
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:379
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:479
const struct LumaCoefficients * in_lumacoef
void ff_matrix_invert_3x3(const double in[3][3], double out[3][3])
Definition: colorspace.c:27
const char * name
Filter name.
Definition: avfilter.h:148
static enum AVColorTransferCharacteristic default_trc[CS_NB+1]
Definition: vf_colorspace.c:73
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:350
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:266
static const struct LumaCoefficients luma_coefficients[AVCOL_SPC_NB]
#define flags(name, subs,...)
Definition: cbs_av1.c:596
AVFilterInternal * internal
An opaque struct for libavfilter internal use.
Definition: avfilter.h:378
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:380
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:386
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:240
the normal 219*2^(n-8) "MPEG" YUV ranges
Definition: pixfmt.h:511
ITU-R BT2020 constant luminance system.
Definition: pixfmt.h:498
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:66
IEC 61966-2-1 (sRGB or sYCC)
Definition: pixfmt.h:471
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:2815
also ITU-R BT470BG
Definition: pixfmt.h:463
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Definition: pixfmt.h:80
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:155
static const struct TransferCharacteristics * get_transfer_characteristics(enum AVColorTransferCharacteristic trc)
int16_t rgb2yuv_coeffs[3][3][8]
pixel format definitions
void ff_matrix_mul_3x3(double dst[3][3], const double src1[3][3], const double src2[3][3])
Definition: colorspace.c:54
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:473
An instance of a filter.
Definition: avfilter.h:338
AVFILTER_DEFINE_CLASS(colorspace)
ITU-R BT2020 for 10-bit system.
Definition: pixfmt.h:472
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:441
ITU-R BT2020.
Definition: pixfmt.h:444
int height
Definition: frame.h:284
FILE * out
Definition: movenc.c:54
#define av_freep(p)
enum AVColorTransferCharacteristic color_trc
Definition: frame.h:475
formats
Definition: signature.h:48
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:2362
#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:64
rgb2yuv_fsb_fn rgb2yuv_fsb[NB_BPP][NB_SS]
Definition: colorspacedsp.h:67
Not part of ABI.
Definition: pixfmt.h:503
DitherMode
Definition: vf_colorspace.c:38
yuv2yuv_fn yuv2yuv
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:654
void ff_fill_rgb2xyz_table(const struct PrimaryCoefficients *coeffs, const struct WhitepointCoefficients *wp, double rgb2xyz[3][3])
Definition: colorspace.c:68
AVFrame * o
#define OFFSET(x)
static uint8_t tmp[11]
Definition: aes_ctr.c:26