FFmpeg  4.4.7
vf_zscale.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Paul B Mahol
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  * zscale video filter using z.lib library
24  */
25 
26 #include <float.h>
27 #include <stdio.h>
28 #include <string.h>
29 
30 #include <zimg.h>
31 
32 #include "avfilter.h"
33 #include "formats.h"
34 #include "internal.h"
35 #include "video.h"
36 #include "libavutil/avstring.h"
37 #include "libavutil/eval.h"
38 #include "libavutil/internal.h"
39 #include "libavutil/intreadwrite.h"
40 #include "libavutil/mathematics.h"
41 #include "libavutil/opt.h"
42 #include "libavutil/parseutils.h"
43 #include "libavutil/pixdesc.h"
44 #include "libavutil/imgutils.h"
45 #include "libavutil/avassert.h"
46 
47 #define ZIMG_ALIGNMENT 32
48 
49 static const char *const var_names[] = {
50  "in_w", "iw",
51  "in_h", "ih",
52  "out_w", "ow",
53  "out_h", "oh",
54  "a",
55  "sar",
56  "dar",
57  "hsub",
58  "vsub",
59  "ohsub",
60  "ovsub",
61  NULL
62 };
63 
64 enum var_name {
76  VARS_NB
77 };
78 
79 typedef struct ZScaleContext {
80  const AVClass *class;
81 
82  /**
83  * New dimensions. Special values are:
84  * 0 = original width/height
85  * -1 = keep original aspect
86  * -N = try to keep aspect but make sure it is divisible by N
87  */
88  int w, h;
89  int dither;
90  int filter;
92  int trc;
93  int primaries;
94  int range;
95  int chromal;
97  int trc_in;
99  int range_in;
101  char *size_str;
104  double param_a;
105  double param_b;
106 
107  char *w_expr; ///< width expression string
108  char *h_expr; ///< height expression string
109 
114 
116 
117  void *tmp;
118  size_t tmp_size;
119 
120  zimg_image_format src_format, dst_format;
121  zimg_image_format alpha_src_format, alpha_dst_format;
122  zimg_graph_builder_params alpha_params, params;
123  zimg_filter_graph *alpha_graph, *graph;
124 
125  enum AVColorSpace in_colorspace, out_colorspace;
127  enum AVColorPrimaries in_primaries, out_primaries;
128  enum AVColorRange in_range, out_range;
129  enum AVChromaLocation in_chromal, out_chromal;
130 } ZScaleContext;
131 
133 {
134  ZScaleContext *s = ctx->priv;
135  int ret;
136 
137  if (s->size_str && (s->w_expr || s->h_expr)) {
139  "Size and width/height expressions cannot be set at the same time.\n");
140  return AVERROR(EINVAL);
141  }
142 
143  if (s->w_expr && !s->h_expr)
144  FFSWAP(char *, s->w_expr, s->size_str);
145 
146  if (s->size_str) {
147  char buf[32];
148  if ((ret = av_parse_video_size(&s->w, &s->h, s->size_str)) < 0) {
150  "Invalid size '%s'\n", s->size_str);
151  return ret;
152  }
153  snprintf(buf, sizeof(buf)-1, "%d", s->w);
154  av_opt_set(s, "w", buf, 0);
155  snprintf(buf, sizeof(buf)-1, "%d", s->h);
156  av_opt_set(s, "h", buf, 0);
157  }
158  if (!s->w_expr)
159  av_opt_set(s, "w", "iw", 0);
160  if (!s->h_expr)
161  av_opt_set(s, "h", "ih", 0);
162 
163  return 0;
164 }
165 
167 {
168  static const enum AVPixelFormat pixel_fmts[] = {
189  };
190  int ret;
191 
192  ret = ff_formats_ref(ff_make_format_list(pixel_fmts), &ctx->inputs[0]->outcfg.formats);
193  if (ret < 0)
194  return ret;
195  return ff_formats_ref(ff_make_format_list(pixel_fmts), &ctx->outputs[0]->incfg.formats);
196 }
197 
198 static int config_props(AVFilterLink *outlink)
199 {
200  AVFilterContext *ctx = outlink->src;
201  AVFilterLink *inlink = outlink->src->inputs[0];
202  ZScaleContext *s = ctx->priv;
204  const AVPixFmtDescriptor *out_desc = av_pix_fmt_desc_get(outlink->format);
205  int64_t w, h;
206  double var_values[VARS_NB], res;
207  char *expr;
208  int ret;
209  int64_t factor_w, factor_h;
210 
211  var_values[VAR_IN_W] = var_values[VAR_IW] = inlink->w;
212  var_values[VAR_IN_H] = var_values[VAR_IH] = inlink->h;
213  var_values[VAR_OUT_W] = var_values[VAR_OW] = NAN;
214  var_values[VAR_OUT_H] = var_values[VAR_OH] = NAN;
215  var_values[VAR_A] = (double) inlink->w / inlink->h;
216  var_values[VAR_SAR] = inlink->sample_aspect_ratio.num ?
217  (double) inlink->sample_aspect_ratio.num / inlink->sample_aspect_ratio.den : 1;
218  var_values[VAR_DAR] = var_values[VAR_A] * var_values[VAR_SAR];
219  var_values[VAR_HSUB] = 1 << desc->log2_chroma_w;
220  var_values[VAR_VSUB] = 1 << desc->log2_chroma_h;
221  var_values[VAR_OHSUB] = 1 << out_desc->log2_chroma_w;
222  var_values[VAR_OVSUB] = 1 << out_desc->log2_chroma_h;
223 
224  /* evaluate width and height */
225  av_expr_parse_and_eval(&res, (expr = s->w_expr),
226  var_names, var_values,
227  NULL, NULL, NULL, NULL, NULL, 0, ctx);
228  var_values[VAR_OUT_W] = var_values[VAR_OW] = trunc(res);
229  if ((ret = av_expr_parse_and_eval(&res, (expr = s->h_expr),
230  var_names, var_values,
231  NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0)
232  goto fail;
233  if (!(res >= INT32_MIN && res <= INT32_MAX)) {
234  ret = AVERROR(EINVAL);
235  goto fail;
236  }
237 
238  s->h = var_values[VAR_OUT_H] = var_values[VAR_OH] = res;
239  /* evaluate again the width, as it may depend on the output height */
240  if ((ret = av_expr_parse_and_eval(&res, (expr = s->w_expr),
241  var_names, var_values,
242  NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0)
243  goto fail;
244  if (!(res >= INT32_MIN && res <= INT32_MAX)) {
245  ret = AVERROR(EINVAL);
246  goto fail;
247  }
248  s->w = res;
249 
250  w = s->w;
251  h = s->h;
252 
253  /* Check if it is requested that the result has to be divisible by a some
254  * factor (w or h = -n with n being the factor). */
255  factor_w = 1;
256  factor_h = 1;
257  if (w < -1) {
258  factor_w = -w;
259  }
260  if (h < -1) {
261  factor_h = -h;
262  }
263 
264  if (w < 0 && h < 0)
265  s->w = s->h = 0;
266 
267  if (!(w = s->w))
268  w = inlink->w;
269  if (!(h = s->h))
270  h = inlink->h;
271 
272  /* Make sure that the result is divisible by the factor we determined
273  * earlier. If no factor was set, it is nothing will happen as the default
274  * factor is 1 */
275  if (w < 0)
276  w = av_rescale(h, inlink->w, inlink->h * factor_w) * factor_w;
277  if (h < 0)
278  h = av_rescale(w, inlink->h, inlink->w * factor_h) * factor_h;
279 
280  /* Note that force_original_aspect_ratio may overwrite the previous set
281  * dimensions so that it is not divisible by the set factors anymore. */
282  if (s->force_original_aspect_ratio) {
283  int tmp_w = av_rescale(h, inlink->w, inlink->h);
284  int tmp_h = av_rescale(w, inlink->h, inlink->w);
285 
286  if (s->force_original_aspect_ratio == 1) {
287  w = FFMIN(tmp_w, w);
288  h = FFMIN(tmp_h, h);
289  } else {
290  w = FFMAX(tmp_w, w);
291  h = FFMAX(tmp_h, h);
292  }
293  }
294 
295  if (w > INT_MAX || h > INT_MAX ||
296  (h * inlink->w) > INT_MAX ||
297  (w * inlink->h) > INT_MAX)
298  av_log(ctx, AV_LOG_ERROR, "Rescaled value for width or height is too big.\n");
299 
300  outlink->w = w;
301  outlink->h = h;
302 
303  if (inlink->w == outlink->w &&
304  inlink->h == outlink->h &&
305  inlink->format == outlink->format)
306  ;
307  else {
308  }
309 
310  if (inlink->sample_aspect_ratio.num){
311  outlink->sample_aspect_ratio = av_mul_q((AVRational){outlink->h * inlink->w, outlink->w * inlink->h}, inlink->sample_aspect_ratio);
312  } else
313  outlink->sample_aspect_ratio = inlink->sample_aspect_ratio;
314 
315  av_log(ctx, AV_LOG_TRACE, "w:%d h:%d fmt:%s sar:%d/%d -> w:%d h:%d fmt:%s sar:%d/%d\n",
316  inlink ->w, inlink ->h, av_get_pix_fmt_name( inlink->format),
318  outlink->w, outlink->h, av_get_pix_fmt_name(outlink->format),
319  outlink->sample_aspect_ratio.num, outlink->sample_aspect_ratio.den);
320  return 0;
321 
322 fail:
324  "Error when evaluating the expression '%s'.\n"
325  "Maybe the expression for out_w:'%s' or for out_h:'%s' is self-referencing.\n",
326  expr, s->w_expr, s->h_expr);
327  return ret;
328 }
329 
331 {
332  char err_msg[1024];
333  int err_code = zimg_get_last_error(err_msg, sizeof(err_msg));
334 
335  av_log(ctx, AV_LOG_ERROR, "code %d: %s\n", err_code, err_msg);
336 
337  return AVERROR_EXTERNAL;
338 }
339 
340 static int convert_chroma_location(enum AVChromaLocation chroma_location)
341 {
342  switch (chroma_location) {
344  case AVCHROMA_LOC_LEFT:
345  return ZIMG_CHROMA_LEFT;
346  case AVCHROMA_LOC_CENTER:
347  return ZIMG_CHROMA_CENTER;
349  return ZIMG_CHROMA_TOP_LEFT;
350  case AVCHROMA_LOC_TOP:
351  return ZIMG_CHROMA_TOP;
353  return ZIMG_CHROMA_BOTTOM_LEFT;
354  case AVCHROMA_LOC_BOTTOM:
355  return ZIMG_CHROMA_BOTTOM;
356  }
357  return ZIMG_CHROMA_LEFT;
358 }
359 
360 static int convert_matrix(enum AVColorSpace colorspace)
361 {
362  switch (colorspace) {
363  case AVCOL_SPC_RGB:
364  return ZIMG_MATRIX_RGB;
365  case AVCOL_SPC_BT709:
366  return ZIMG_MATRIX_709;
368  return ZIMG_MATRIX_UNSPECIFIED;
369  case AVCOL_SPC_FCC:
370  return ZIMG_MATRIX_FCC;
371  case AVCOL_SPC_BT470BG:
372  return ZIMG_MATRIX_470BG;
373  case AVCOL_SPC_SMPTE170M:
374  return ZIMG_MATRIX_170M;
375  case AVCOL_SPC_SMPTE240M:
376  return ZIMG_MATRIX_240M;
377  case AVCOL_SPC_YCGCO:
378  return ZIMG_MATRIX_YCGCO;
380  return ZIMG_MATRIX_2020_NCL;
381  case AVCOL_SPC_BT2020_CL:
382  return ZIMG_MATRIX_2020_CL;
384  return ZIMG_MATRIX_CHROMATICITY_DERIVED_NCL;
386  return ZIMG_MATRIX_CHROMATICITY_DERIVED_CL;
387  case AVCOL_SPC_ICTCP:
388  return ZIMG_MATRIX_ICTCP;
389  }
390  return ZIMG_MATRIX_UNSPECIFIED;
391 }
392 
393 static int convert_trc(enum AVColorTransferCharacteristic color_trc)
394 {
395  switch (color_trc) {
397  return ZIMG_TRANSFER_UNSPECIFIED;
398  case AVCOL_TRC_BT709:
399  return ZIMG_TRANSFER_709;
400  case AVCOL_TRC_GAMMA22:
401  return ZIMG_TRANSFER_470_M;
402  case AVCOL_TRC_GAMMA28:
403  return ZIMG_TRANSFER_470_BG;
404  case AVCOL_TRC_SMPTE170M:
405  return ZIMG_TRANSFER_601;
406  case AVCOL_TRC_SMPTE240M:
407  return ZIMG_TRANSFER_240M;
408  case AVCOL_TRC_LINEAR:
409  return ZIMG_TRANSFER_LINEAR;
410  case AVCOL_TRC_LOG:
411  return ZIMG_TRANSFER_LOG_100;
412  case AVCOL_TRC_LOG_SQRT:
413  return ZIMG_TRANSFER_LOG_316;
415  return ZIMG_TRANSFER_IEC_61966_2_4;
416  case AVCOL_TRC_BT2020_10:
417  return ZIMG_TRANSFER_2020_10;
418  case AVCOL_TRC_BT2020_12:
419  return ZIMG_TRANSFER_2020_12;
420  case AVCOL_TRC_SMPTE2084:
421  return ZIMG_TRANSFER_ST2084;
423  return ZIMG_TRANSFER_ARIB_B67;
425  return ZIMG_TRANSFER_IEC_61966_2_1;
426  }
427  return ZIMG_TRANSFER_UNSPECIFIED;
428 }
429 
431 {
432  switch (color_primaries) {
434  return ZIMG_PRIMARIES_UNSPECIFIED;
435  case AVCOL_PRI_BT709:
436  return ZIMG_PRIMARIES_709;
437  case AVCOL_PRI_BT470M:
438  return ZIMG_PRIMARIES_470_M;
439  case AVCOL_PRI_BT470BG:
440  return ZIMG_PRIMARIES_470_BG;
441  case AVCOL_PRI_SMPTE170M:
442  return ZIMG_PRIMARIES_170M;
443  case AVCOL_PRI_SMPTE240M:
444  return ZIMG_PRIMARIES_240M;
445  case AVCOL_PRI_FILM:
446  return ZIMG_PRIMARIES_FILM;
447  case AVCOL_PRI_BT2020:
448  return ZIMG_PRIMARIES_2020;
449  case AVCOL_PRI_SMPTE428:
450  return ZIMG_PRIMARIES_ST428;
451  case AVCOL_PRI_SMPTE431:
452  return ZIMG_PRIMARIES_ST431_2;
453  case AVCOL_PRI_SMPTE432:
454  return ZIMG_PRIMARIES_ST432_1;
455  case AVCOL_PRI_JEDEC_P22:
456  return ZIMG_PRIMARIES_EBU3213_E;
457  }
458  return ZIMG_PRIMARIES_UNSPECIFIED;
459 }
460 
462 {
463  switch (color_range) {
465  case AVCOL_RANGE_MPEG:
466  return ZIMG_RANGE_LIMITED;
467  case AVCOL_RANGE_JPEG:
468  return ZIMG_RANGE_FULL;
469  }
470  return ZIMG_RANGE_LIMITED;
471 }
472 
473 static void format_init(zimg_image_format *format, AVFrame *frame, const AVPixFmtDescriptor *desc,
474  int colorspace, int primaries, int transfer, int range, int location)
475 {
476  format->width = frame->width;
477  format->height = frame->height;
478  format->subsample_w = desc->log2_chroma_w;
479  format->subsample_h = desc->log2_chroma_h;
480  format->depth = desc->comp[0].depth;
481  format->pixel_type = (desc->flags & AV_PIX_FMT_FLAG_FLOAT) ? ZIMG_PIXEL_FLOAT : desc->comp[0].depth > 8 ? ZIMG_PIXEL_WORD : ZIMG_PIXEL_BYTE;
482  format->color_family = (desc->flags & AV_PIX_FMT_FLAG_RGB) ? ZIMG_COLOR_RGB : ZIMG_COLOR_YUV;
483  format->matrix_coefficients = (desc->flags & AV_PIX_FMT_FLAG_RGB) ? ZIMG_MATRIX_RGB : colorspace == -1 ? convert_matrix(frame->colorspace) : colorspace;
484  format->color_primaries = primaries == -1 ? convert_primaries(frame->color_primaries) : primaries;
485  format->transfer_characteristics = transfer == - 1 ? convert_trc(frame->color_trc) : transfer;
486  format->pixel_range = (desc->flags & AV_PIX_FMT_FLAG_RGB) ? ZIMG_RANGE_FULL : range == -1 ? convert_range(frame->color_range) : range;
487  format->chroma_location = location == -1 ? convert_chroma_location(frame->chroma_location) : location;
488 }
489 
490 static int graph_build(zimg_filter_graph **graph, zimg_graph_builder_params *params,
491  zimg_image_format *src_format, zimg_image_format *dst_format,
492  void **tmp, size_t *tmp_size)
493 {
494  int ret;
495  size_t size;
496 
497  zimg_filter_graph_free(*graph);
498  *graph = zimg_filter_graph_build(src_format, dst_format, params);
499  if (!*graph)
500  return print_zimg_error(NULL);
501 
502  ret = zimg_filter_graph_get_tmp_size(*graph, &size);
503  if (ret)
504  return print_zimg_error(NULL);
505 
506  if (size > *tmp_size) {
507  av_freep(tmp);
508  *tmp = av_malloc(size);
509  if (!*tmp)
510  return AVERROR(ENOMEM);
511 
512  *tmp_size = size;
513  }
514 
515  return 0;
516 }
517 
519 {
520  AVFrame *aligned = NULL;
521  int ret = 0, plane;
522 
523  /* Realign any unaligned input frame. */
524  for (plane = 0; plane < 3; plane++) {
525  int p = desc->comp[plane].plane;
526  if ((uintptr_t)(*frame)->data[p] % ZIMG_ALIGNMENT || (*frame)->linesize[p] % ZIMG_ALIGNMENT) {
527  if (!(aligned = av_frame_alloc())) {
528  ret = AVERROR(ENOMEM);
529  goto fail;
530  }
531 
532  aligned->format = (*frame)->format;
533  aligned->width = (*frame)->width;
534  aligned->height = (*frame)->height;
535 
536  if ((ret = av_frame_get_buffer(aligned, ZIMG_ALIGNMENT)) < 0)
537  goto fail;
538 
539  if ((ret = av_frame_copy(aligned, *frame)) < 0)
540  goto fail;
541 
542  if ((ret = av_frame_copy_props(aligned, *frame)) < 0)
543  goto fail;
544 
546  *frame = aligned;
547  return 0;
548  }
549  }
550 
551 fail:
553  return ret;
554 }
555 
556 static int filter_frame(AVFilterLink *link, AVFrame *in)
557 {
558  ZScaleContext *s = link->dst->priv;
559  AVFilterLink *outlink = link->dst->outputs[0];
561  const AVPixFmtDescriptor *odesc = av_pix_fmt_desc_get(outlink->format);
562  zimg_image_buffer_const src_buf = { ZIMG_API_VERSION };
563  zimg_image_buffer dst_buf = { ZIMG_API_VERSION };
564  char buf[32];
565  int ret = 0, plane;
566  AVFrame *out = NULL;
567 
568  if ((ret = realign_frame(desc, &in)) < 0)
569  goto fail;
570 
571  if (!(out = ff_get_video_buffer(outlink, outlink->w, outlink->h))) {
572  ret = AVERROR(ENOMEM);
573  goto fail;
574  }
575 
577  out->width = outlink->w;
578  out->height = outlink->h;
579 
580  if( in->width != link->w
581  || in->height != link->h
582  || in->format != link->format
583  || s->in_colorspace != in->colorspace
584  || s->in_trc != in->color_trc
585  || s->in_primaries != in->color_primaries
586  || s->in_range != in->color_range
587  || s->out_colorspace != out->colorspace
588  || s->out_trc != out->color_trc
589  || s->out_primaries != out->color_primaries
590  || s->out_range != out->color_range
591  || s->in_chromal != in->chroma_location
592  || s->out_chromal != out->chroma_location) {
593  snprintf(buf, sizeof(buf)-1, "%d", outlink->w);
594  av_opt_set(s, "w", buf, 0);
595  snprintf(buf, sizeof(buf)-1, "%d", outlink->h);
596  av_opt_set(s, "h", buf, 0);
597 
598  link->dst->inputs[0]->format = in->format;
599  link->dst->inputs[0]->w = in->width;
600  link->dst->inputs[0]->h = in->height;
601 
602  if ((ret = config_props(outlink)) < 0)
603  goto fail;
604 
605  zimg_image_format_default(&s->src_format, ZIMG_API_VERSION);
606  zimg_image_format_default(&s->dst_format, ZIMG_API_VERSION);
607  zimg_graph_builder_params_default(&s->params, ZIMG_API_VERSION);
608 
609  s->params.dither_type = s->dither;
610  s->params.cpu_type = ZIMG_CPU_AUTO;
611  s->params.resample_filter = s->filter;
612  s->params.resample_filter_uv = s->filter;
613  s->params.nominal_peak_luminance = s->nominal_peak_luminance;
614  s->params.allow_approximate_gamma = s->approximate_gamma;
615  s->params.filter_param_a = s->params.filter_param_a_uv = s->param_a;
616  s->params.filter_param_b = s->params.filter_param_b_uv = s->param_b;
617 
618  format_init(&s->src_format, in, desc, s->colorspace_in,
619  s->primaries_in, s->trc_in, s->range_in, s->chromal_in);
620  format_init(&s->dst_format, out, odesc, s->colorspace,
621  s->primaries, s->trc, s->range, s->chromal);
622 
623  if (s->colorspace != -1)
624  out->colorspace = (int)s->dst_format.matrix_coefficients;
625 
626  if (s->primaries != -1)
627  out->color_primaries = (int)s->dst_format.color_primaries;
628 
629  if (s->range != -1)
630  out->color_range = (int)s->dst_format.pixel_range + 1;
631 
632  if (s->trc != -1)
633  out->color_trc = (int)s->dst_format.transfer_characteristics;
634 
635  if (s->chromal != -1)
636  out->chroma_location = (int)s->dst_format.chroma_location - 1;
637 
638  ret = graph_build(&s->graph, &s->params, &s->src_format, &s->dst_format,
639  &s->tmp, &s->tmp_size);
640  if (ret < 0)
641  goto fail;
642 
643  s->in_colorspace = in->colorspace;
644  s->in_trc = in->color_trc;
645  s->in_primaries = in->color_primaries;
646  s->in_range = in->color_range;
647  s->out_colorspace = out->colorspace;
648  s->out_trc = out->color_trc;
649  s->out_primaries = out->color_primaries;
650  s->out_range = out->color_range;
651 
652  if (desc->flags & AV_PIX_FMT_FLAG_ALPHA && odesc->flags & AV_PIX_FMT_FLAG_ALPHA) {
653  zimg_image_format_default(&s->alpha_src_format, ZIMG_API_VERSION);
654  zimg_image_format_default(&s->alpha_dst_format, ZIMG_API_VERSION);
655  zimg_graph_builder_params_default(&s->alpha_params, ZIMG_API_VERSION);
656 
657  s->alpha_params.dither_type = s->dither;
658  s->alpha_params.cpu_type = ZIMG_CPU_AUTO;
659  s->alpha_params.resample_filter = s->filter;
660 
661  s->alpha_src_format.width = in->width;
662  s->alpha_src_format.height = in->height;
663  s->alpha_src_format.depth = desc->comp[0].depth;
664  s->alpha_src_format.pixel_type = (desc->flags & AV_PIX_FMT_FLAG_FLOAT) ? ZIMG_PIXEL_FLOAT : desc->comp[0].depth > 8 ? ZIMG_PIXEL_WORD : ZIMG_PIXEL_BYTE;
665  s->alpha_src_format.color_family = ZIMG_COLOR_GREY;
666 
667  s->alpha_dst_format.width = out->width;
668  s->alpha_dst_format.height = out->height;
669  s->alpha_dst_format.depth = odesc->comp[0].depth;
670  s->alpha_dst_format.pixel_type = (odesc->flags & AV_PIX_FMT_FLAG_FLOAT) ? ZIMG_PIXEL_FLOAT : odesc->comp[0].depth > 8 ? ZIMG_PIXEL_WORD : ZIMG_PIXEL_BYTE;
671  s->alpha_dst_format.color_family = ZIMG_COLOR_GREY;
672 
673  zimg_filter_graph_free(s->alpha_graph);
674  s->alpha_graph = zimg_filter_graph_build(&s->alpha_src_format, &s->alpha_dst_format, &s->alpha_params);
675  if (!s->alpha_graph) {
676  ret = print_zimg_error(link->dst);
677  goto fail;
678  }
679  }
680  }
681 
682  if (s->colorspace != -1)
683  out->colorspace = (int)s->dst_format.matrix_coefficients;
684 
685  if (s->primaries != -1)
686  out->color_primaries = (int)s->dst_format.color_primaries;
687 
688  if (s->range != -1)
689  out->color_range = (int)s->dst_format.pixel_range;
690 
691  if (s->trc != -1)
692  out->color_trc = (int)s->dst_format.transfer_characteristics;
693 
694  av_reduce(&out->sample_aspect_ratio.num, &out->sample_aspect_ratio.den,
695  (int64_t)in->sample_aspect_ratio.num * outlink->h * link->w,
696  (int64_t)in->sample_aspect_ratio.den * outlink->w * link->h,
697  INT_MAX);
698 
699  for (plane = 0; plane < 3; plane++) {
700  int p = desc->comp[plane].plane;
701  src_buf.plane[plane].data = in->data[p];
702  src_buf.plane[plane].stride = in->linesize[p];
703  src_buf.plane[plane].mask = -1;
704 
705  p = odesc->comp[plane].plane;
706  dst_buf.plane[plane].data = out->data[p];
707  dst_buf.plane[plane].stride = out->linesize[p];
708  dst_buf.plane[plane].mask = -1;
709  }
710 
711  ret = zimg_filter_graph_process(s->graph, &src_buf, &dst_buf, s->tmp, 0, 0, 0, 0);
712  if (ret) {
713  ret = print_zimg_error(link->dst);
714  goto fail;
715  }
716 
717  if (desc->flags & AV_PIX_FMT_FLAG_ALPHA && odesc->flags & AV_PIX_FMT_FLAG_ALPHA) {
718  src_buf.plane[0].data = in->data[3];
719  src_buf.plane[0].stride = in->linesize[3];
720  src_buf.plane[0].mask = -1;
721 
722  dst_buf.plane[0].data = out->data[3];
723  dst_buf.plane[0].stride = out->linesize[3];
724  dst_buf.plane[0].mask = -1;
725 
726  ret = zimg_filter_graph_process(s->alpha_graph, &src_buf, &dst_buf, s->tmp, 0, 0, 0, 0);
727  if (ret) {
728  ret = print_zimg_error(link->dst);
729  goto fail;
730  }
731  } else if (odesc->flags & AV_PIX_FMT_FLAG_ALPHA) {
732  int x, y;
733 
734  if (odesc->flags & AV_PIX_FMT_FLAG_FLOAT) {
735  for (y = 0; y < out->height; y++) {
736  for (x = 0; x < out->width; x++) {
737  AV_WN32(out->data[3] + x * odesc->comp[3].step + y * out->linesize[3],
738  av_float2int(1.0f));
739  }
740  }
741  } else {
742  for (y = 0; y < outlink->h; y++)
743  memset(out->data[3] + y * out->linesize[3], 0xff, outlink->w);
744  }
745  }
746 
747 fail:
748  av_frame_free(&in);
749  if (ret) {
750  av_frame_free(&out);
751  return ret;
752  }
753 
754  return ff_filter_frame(outlink, out);
755 }
756 
758 {
759  ZScaleContext *s = ctx->priv;
760 
761  zimg_filter_graph_free(s->graph);
762  zimg_filter_graph_free(s->alpha_graph);
763  av_freep(&s->tmp);
764  s->tmp_size = 0;
765 }
766 
767 static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
768  char *res, int res_len, int flags)
769 {
770  ZScaleContext *s = ctx->priv;
771  int ret;
772 
773  if ( !strcmp(cmd, "width") || !strcmp(cmd, "w")
774  || !strcmp(cmd, "height") || !strcmp(cmd, "h")) {
775 
776  int old_w = s->w;
777  int old_h = s->h;
778  AVFilterLink *outlink = ctx->outputs[0];
779 
780  av_opt_set(s, cmd, args, 0);
781  if ((ret = config_props(outlink)) < 0) {
782  s->w = old_w;
783  s->h = old_h;
784  }
785  } else
786  ret = AVERROR(ENOSYS);
787 
788  return ret;
789 }
790 
791 #define OFFSET(x) offsetof(ZScaleContext, x)
792 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
793 #define TFLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
794 
795 static const AVOption zscale_options[] = {
796  { "w", "Output video width", OFFSET(w_expr), AV_OPT_TYPE_STRING, .flags = TFLAGS },
797  { "width", "Output video width", OFFSET(w_expr), AV_OPT_TYPE_STRING, .flags = TFLAGS },
798  { "h", "Output video height", OFFSET(h_expr), AV_OPT_TYPE_STRING, .flags = TFLAGS },
799  { "height", "Output video height", OFFSET(h_expr), AV_OPT_TYPE_STRING, .flags = TFLAGS },
800  { "size", "set video size", OFFSET(size_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS },
801  { "s", "set video size", OFFSET(size_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS },
802  { "dither", "set dither type", OFFSET(dither), AV_OPT_TYPE_INT, {.i64 = 0}, 0, ZIMG_DITHER_ERROR_DIFFUSION, FLAGS, "dither" },
803  { "d", "set dither type", OFFSET(dither), AV_OPT_TYPE_INT, {.i64 = 0}, 0, ZIMG_DITHER_ERROR_DIFFUSION, FLAGS, "dither" },
804  { "none", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_DITHER_NONE}, 0, 0, FLAGS, "dither" },
805  { "ordered", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_DITHER_ORDERED}, 0, 0, FLAGS, "dither" },
806  { "random", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_DITHER_RANDOM}, 0, 0, FLAGS, "dither" },
807  { "error_diffusion", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_DITHER_ERROR_DIFFUSION}, 0, 0, FLAGS, "dither" },
808  { "filter", "set filter type", OFFSET(filter), AV_OPT_TYPE_INT, {.i64 = ZIMG_RESIZE_BILINEAR}, 0, ZIMG_RESIZE_LANCZOS, FLAGS, "filter" },
809  { "f", "set filter type", OFFSET(filter), AV_OPT_TYPE_INT, {.i64 = ZIMG_RESIZE_BILINEAR}, 0, ZIMG_RESIZE_LANCZOS, FLAGS, "filter" },
810  { "point", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_RESIZE_POINT}, 0, 0, FLAGS, "filter" },
811  { "bilinear", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_RESIZE_BILINEAR}, 0, 0, FLAGS, "filter" },
812  { "bicubic", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_RESIZE_BICUBIC}, 0, 0, FLAGS, "filter" },
813  { "spline16", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_RESIZE_SPLINE16}, 0, 0, FLAGS, "filter" },
814  { "spline36", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_RESIZE_SPLINE36}, 0, 0, FLAGS, "filter" },
815  { "lanczos", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_RESIZE_LANCZOS}, 0, 0, FLAGS, "filter" },
816  { "out_range", "set color range", OFFSET(range), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_RANGE_FULL, FLAGS, "range" },
817  { "range", "set color range", OFFSET(range), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_RANGE_FULL, FLAGS, "range" },
818  { "r", "set color range", OFFSET(range), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_RANGE_FULL, FLAGS, "range" },
819  { "input", 0, 0, AV_OPT_TYPE_CONST, {.i64 = -1}, 0, 0, FLAGS, "range" },
820  { "limited", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_RANGE_LIMITED}, 0, 0, FLAGS, "range" },
821  { "full", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_RANGE_FULL}, 0, 0, FLAGS, "range" },
822  { "unknown", 0, 0, AV_OPT_TYPE_CONST, {.i64 = -1}, 0, 0, FLAGS, "range" },
823  { "tv", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_RANGE_LIMITED}, 0, 0, FLAGS, "range" },
824  { "pc", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_RANGE_FULL}, 0, 0, FLAGS, "range" },
825  { "primaries", "set color primaries", OFFSET(primaries), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, FLAGS, "primaries" },
826  { "p", "set color primaries", OFFSET(primaries), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, FLAGS, "primaries" },
827  { "input", 0, 0, AV_OPT_TYPE_CONST, {.i64 = -1}, 0, 0, FLAGS, "primaries" },
828  { "709", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_709}, 0, 0, FLAGS, "primaries" },
829  { "unspecified", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_UNSPECIFIED}, 0, 0, FLAGS, "primaries" },
830  { "170m", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_170M}, 0, 0, FLAGS, "primaries" },
831  { "240m", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_240M}, 0, 0, FLAGS, "primaries" },
832  { "2020", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_2020}, 0, 0, FLAGS, "primaries" },
833  { "unknown", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_UNSPECIFIED}, 0, 0, FLAGS, "primaries" },
834  { "bt709", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_709}, 0, 0, FLAGS, "primaries" },
835  { "bt470m", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_470_M}, 0, 0, FLAGS, "primaries" },
836  { "bt470bg", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_470_BG}, 0, 0, FLAGS, "primaries" },
837  { "smpte170m", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_170M}, 0, 0, FLAGS, "primaries" },
838  { "smpte240m", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_240M}, 0, 0, FLAGS, "primaries" },
839  { "film", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_FILM}, 0, 0, FLAGS, "primaries" },
840  { "bt2020", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_2020}, 0, 0, FLAGS, "primaries" },
841  { "smpte428", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_ST428}, 0, 0, FLAGS, "primaries" },
842  { "smpte431", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_ST431_2}, 0, 0, FLAGS, "primaries" },
843  { "smpte432", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_ST432_1}, 0, 0, FLAGS, "primaries" },
844  { "jedec-p22", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_EBU3213_E}, 0, 0, FLAGS, "primaries" },
845  { "ebu3213", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_EBU3213_E}, 0, 0, FLAGS, "primaries" },
846  { "transfer", "set transfer characteristic", OFFSET(trc), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, FLAGS, "transfer" },
847  { "t", "set transfer characteristic", OFFSET(trc), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, FLAGS, "transfer" },
848  { "input", 0, 0, AV_OPT_TYPE_CONST, {.i64 = -1}, 0, 0, FLAGS, "transfer" },
849  { "709", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_709}, 0, 0, FLAGS, "transfer" },
850  { "unspecified", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_UNSPECIFIED}, 0, 0, FLAGS, "transfer" },
851  { "601", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_601}, 0, 0, FLAGS, "transfer" },
852  { "linear", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_LINEAR}, 0, 0, FLAGS, "transfer" },
853  { "2020_10", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_2020_10}, 0, 0, FLAGS, "transfer" },
854  { "2020_12", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_2020_12}, 0, 0, FLAGS, "transfer" },
855  { "unknown", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_UNSPECIFIED}, 0, 0, FLAGS, "transfer" },
856  { "bt470m", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_470_M}, 0, 0, FLAGS, "transfer" },
857  { "bt470bg", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_470_BG}, 0, 0, FLAGS, "transfer" },
858  { "smpte170m", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_601}, 0, 0, FLAGS, "transfer" },
859  { "bt709", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_709}, 0, 0, FLAGS, "transfer" },
860  { "linear", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_LINEAR}, 0, 0, FLAGS, "transfer" },
861  { "log100", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_LOG_100}, 0, 0, FLAGS, "transfer" },
862  { "log316", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_LOG_316}, 0, 0, FLAGS, "transfer" },
863  { "bt2020-10", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_2020_10}, 0, 0, FLAGS, "transfer" },
864  { "bt2020-12", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_2020_12}, 0, 0, FLAGS, "transfer" },
865  { "smpte2084", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_ST2084}, 0, 0, FLAGS, "transfer" },
866  { "iec61966-2-4", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_IEC_61966_2_4},0, 0, FLAGS, "transfer" },
867  { "iec61966-2-1", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_IEC_61966_2_1},0, 0, FLAGS, "transfer" },
868  { "arib-std-b67", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_ARIB_B67}, 0, 0, FLAGS, "transfer" },
869  { "matrix", "set colorspace matrix", OFFSET(colorspace), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, FLAGS, "matrix" },
870  { "m", "set colorspace matrix", OFFSET(colorspace), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, FLAGS, "matrix" },
871  { "input", 0, 0, AV_OPT_TYPE_CONST, {.i64 = -1}, 0, 0, FLAGS, "matrix" },
872  { "709", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_709}, 0, 0, FLAGS, "matrix" },
873  { "unspecified", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_UNSPECIFIED}, 0, 0, FLAGS, "matrix" },
874  { "470bg", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_470BG}, 0, 0, FLAGS, "matrix" },
875  { "170m", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_170M}, 0, 0, FLAGS, "matrix" },
876  { "2020_ncl", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_2020_NCL}, 0, 0, FLAGS, "matrix" },
877  { "2020_cl", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_2020_CL}, 0, 0, FLAGS, "matrix" },
878  { "unknown", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_UNSPECIFIED}, 0, 0, FLAGS, "matrix" },
879  { "gbr", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_RGB}, 0, 0, FLAGS, "matrix" },
880  { "bt709", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_709}, 0, 0, FLAGS, "matrix" },
881  { "fcc", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_FCC}, 0, 0, FLAGS, "matrix" },
882  { "bt470bg", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_470BG}, 0, 0, FLAGS, "matrix" },
883  { "smpte170m", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_170M}, 0, 0, FLAGS, "matrix" },
884  { "smpte2400m", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_240M}, 0, 0, FLAGS, "matrix" },
885  { "ycgco", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_YCGCO}, 0, 0, FLAGS, "matrix" },
886  { "bt2020nc", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_2020_NCL}, 0, 0, FLAGS, "matrix" },
887  { "bt2020c", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_2020_CL}, 0, 0, FLAGS, "matrix" },
888  { "chroma-derived-nc",0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_CHROMATICITY_DERIVED_NCL}, 0, 0, FLAGS, "matrix" },
889  { "chroma-derived-c", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_CHROMATICITY_DERIVED_CL}, 0, 0, FLAGS, "matrix" },
890  { "ictcp", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_ICTCP}, 0, 0, FLAGS, "matrix" },
891  { "in_range", "set input color range", OFFSET(range_in), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_RANGE_FULL, FLAGS, "range" },
892  { "rangein", "set input color range", OFFSET(range_in), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_RANGE_FULL, FLAGS, "range" },
893  { "rin", "set input color range", OFFSET(range_in), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_RANGE_FULL, FLAGS, "range" },
894  { "primariesin", "set input color primaries", OFFSET(primaries_in), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, FLAGS, "primaries" },
895  { "pin", "set input color primaries", OFFSET(primaries_in), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, FLAGS, "primaries" },
896  { "transferin", "set input transfer characteristic", OFFSET(trc_in), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, FLAGS, "transfer" },
897  { "tin", "set input transfer characteristic", OFFSET(trc_in), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, FLAGS, "transfer" },
898  { "matrixin", "set input colorspace matrix", OFFSET(colorspace_in), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, FLAGS, "matrix" },
899  { "min", "set input colorspace matrix", OFFSET(colorspace_in), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, FLAGS, "matrix" },
900  { "chromal", "set output chroma location", OFFSET(chromal), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_CHROMA_BOTTOM, FLAGS, "chroma" },
901  { "c", "set output chroma location", OFFSET(chromal), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_CHROMA_BOTTOM, FLAGS, "chroma" },
902  { "input", 0, 0, AV_OPT_TYPE_CONST, {.i64 = -1}, 0, 0, FLAGS, "chroma" },
903  { "left", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_CHROMA_LEFT}, 0, 0, FLAGS, "chroma" },
904  { "center", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_CHROMA_CENTER}, 0, 0, FLAGS, "chroma" },
905  { "topleft", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_CHROMA_TOP_LEFT}, 0, 0, FLAGS, "chroma" },
906  { "top", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_CHROMA_TOP}, 0, 0, FLAGS, "chroma" },
907  { "bottomleft",0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_CHROMA_BOTTOM_LEFT}, 0, 0, FLAGS, "chroma" },
908  { "bottom", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_CHROMA_BOTTOM}, 0, 0, FLAGS, "chroma" },
909  { "chromalin", "set input chroma location", OFFSET(chromal_in), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_CHROMA_BOTTOM, FLAGS, "chroma" },
910  { "cin", "set input chroma location", OFFSET(chromal_in), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_CHROMA_BOTTOM, FLAGS, "chroma" },
911  { "npl", "set nominal peak luminance", OFFSET(nominal_peak_luminance), AV_OPT_TYPE_DOUBLE, {.dbl = NAN}, 0, DBL_MAX, FLAGS },
912  { "agamma", "allow approximate gamma", OFFSET(approximate_gamma), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, FLAGS },
913  { "param_a", "parameter A, which is parameter \"b\" for bicubic, "
914  "and the number of filter taps for lanczos", OFFSET(param_a), AV_OPT_TYPE_DOUBLE, {.dbl = NAN}, -DBL_MAX, DBL_MAX, FLAGS },
915  { "param_b", "parameter B, which is parameter \"c\" for bicubic", OFFSET(param_b), AV_OPT_TYPE_DOUBLE, {.dbl = NAN}, -DBL_MAX, DBL_MAX, FLAGS },
916  { NULL }
917 };
918 
920 
922  {
923  .name = "default",
924  .type = AVMEDIA_TYPE_VIDEO,
925  .filter_frame = filter_frame,
926  },
927  { NULL }
928 };
929 
931  {
932  .name = "default",
933  .type = AVMEDIA_TYPE_VIDEO,
934  .config_props = config_props,
935  },
936  { NULL }
937 };
938 
940  .name = "zscale",
941  .description = NULL_IF_CONFIG_SMALL("Apply resizing, colorspace and bit depth conversion."),
942  .init_dict = init_dict,
943  .query_formats = query_formats,
944  .priv_size = sizeof(ZScaleContext),
945  .priv_class = &zscale_class,
946  .uninit = uninit,
950 };
static const AVFilterPad inputs[]
Definition: af_acontrast.c:193
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
static const char *const format[]
Definition: af_aiir.c:456
#define av_cold
Definition: attributes.h:88
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;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);return NULL;} return ac;} 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;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->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);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
simple assert() macros that are a bit more flexible than ISO C assert().
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1096
Main libavfilter public API header.
#define flags(name, subs,...)
Definition: cbs_av1.c:572
#define s(width, name)
Definition: cbs_vp9.c:257
static av_always_inline void filter(int16_t *output, ptrdiff_t out_stride, const int16_t *low, ptrdiff_t low_stride, const int16_t *high, ptrdiff_t high_stride, int len, int clip)
Definition: cfhddsp.c:27
#define fail()
Definition: checkasm.h:133
#define FFSWAP(type, a, b)
Definition: common.h:108
#define FFMIN(a, b)
Definition: common.h:105
#define FFMAX(a, b)
Definition: common.h:103
#define NULL
Definition: coverity.c:32
long long int64_t
Definition: coverity.c:34
static __device__ float trunc(float a)
Definition: cuda_runtime.h:179
static int aligned(int val)
Definition: dashdec.c:168
static AVFrame * frame
int av_expr_parse_and_eval(double *d, const char *s, const char *const *const_names, const double *const_values, const char *const *func1_names, double(*const *funcs1)(void *, double), const char *const *func2_names, double(*const *funcs2)(void *, double, double), void *opaque, int log_offset, void *log_ctx)
Parse and evaluate an expression.
Definition: eval.c:791
simple arithmetic expression evaluator
int
int ff_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
Add ref as a new reference to formats.
Definition: formats.c:466
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:286
@ AV_OPT_TYPE_CONST
Definition: opt.h:234
@ AV_OPT_TYPE_INT
Definition: opt.h:225
@ AV_OPT_TYPE_DOUBLE
Definition: opt.h:227
@ AV_OPT_TYPE_BOOL
Definition: opt.h:242
@ AV_OPT_TYPE_STRING
Definition: opt.h:229
#define AVERROR_EXTERNAL
Generic error in an external library.
Definition: error.h:57
#define AVERROR(e)
Definition: error.h:43
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
Definition: frame.c:337
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:203
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:658
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:190
int av_frame_copy(AVFrame *dst, const AVFrame *src)
Copy the frame data from src to dst.
Definition: frame.c:799
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
Definition: log.h:220
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
Definition: rational.c:80
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
Definition: rational.c:35
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
Definition: mathematics.c:129
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
Definition: opt.c:465
misc image utilities
static av_always_inline uint32_t av_float2int(float f)
Reinterpret a float as a 32-bit integer.
Definition: intfloat.h:50
#define AV_WN32(p, v)
Definition: intreadwrite.h:376
static const struct ColorPrimaries color_primaries[AVCOL_PRI_NB]
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
const char * desc
Definition: libsvtav1.c:79
uint8_t w
Definition: llviddspenc.c:39
#define NAN
Definition: mathematics.h:64
AVOptions.
int av_parse_video_size(int *width_ptr, int *height_ptr, const char *str)
Parse str and put in width_ptr and height_ptr the detected values.
Definition: parseutils.c:148
misc parsing utilities
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:2489
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2573
#define AV_PIX_FMT_FLAG_ALPHA
The pixel format has an alpha channel.
Definition: pixdesc.h:179
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
Definition: pixdesc.h:148
#define AV_PIX_FMT_FLAG_FLOAT
The pixel format contains IEEE-754 floating point values.
Definition: pixdesc.h:190
#define AV_PIX_FMT_YUV420P16
Definition: pixfmt.h:410
#define AV_PIX_FMT_GBRPF32
Definition: pixfmt.h:428
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:406
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:398
AVChromaLocation
Location of chroma samples.
Definition: pixfmt.h:605
@ AVCHROMA_LOC_TOP
Definition: pixfmt.h:610
@ AVCHROMA_LOC_BOTTOM
Definition: pixfmt.h:612
@ AVCHROMA_LOC_TOPLEFT
ITU-R 601, SMPTE 274M 296M S314M(DV 4:1:1), mpeg2 4:2:2.
Definition: pixfmt.h:609
@ AVCHROMA_LOC_LEFT
MPEG-2/4 4:2:0, H.264 default for 4:2:0.
Definition: pixfmt.h:607
@ AVCHROMA_LOC_BOTTOMLEFT
Definition: pixfmt.h:611
@ AVCHROMA_LOC_CENTER
MPEG-1 4:2:0, JPEG 4:2:0, H.263 4:2:0.
Definition: pixfmt.h:608
@ AVCHROMA_LOC_UNSPECIFIED
Definition: pixfmt.h:606
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:399
#define AV_PIX_FMT_GBRAP16
Definition: pixfmt.h:421
#define AV_PIX_FMT_GBRP9
Definition: pixfmt.h:414
#define AV_PIX_FMT_YUV422P9
Definition: pixfmt.h:397
AVColorRange
Visual content value range.
Definition: pixfmt.h:551
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition: pixfmt.h:569
@ AVCOL_RANGE_UNSPECIFIED
Definition: pixfmt.h:552
@ AVCOL_RANGE_JPEG
Full range content.
Definition: pixfmt.h:586
#define AV_PIX_FMT_YUVA444P10
Definition: pixfmt.h:438
#define AV_PIX_FMT_YUVA420P16
Definition: pixfmt.h:441
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:403
#define AV_PIX_FMT_YUVA420P10
Definition: pixfmt.h:436
#define AV_PIX_FMT_YUVA422P9
Definition: pixfmt.h:434
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:404
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:415
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:400
#define AV_PIX_FMT_GBRP12
Definition: pixfmt.h:416
#define AV_PIX_FMT_YUV420P9
Definition: pixfmt.h:396
#define AV_PIX_FMT_YUVA420P9
Definition: pixfmt.h:433
#define AV_PIX_FMT_YUVA422P10
Definition: pixfmt.h:437
#define AV_PIX_FMT_YUV420P14
Definition: pixfmt.h:407
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:99
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:70
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:101
@ AV_PIX_FMT_YUVJ440P
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range
Definition: pixfmt.h:100
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:72
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:73
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:71
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition: pixfmt.h:177
@ AV_PIX_FMT_YUVJ411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
Definition: pixfmt.h:258
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:215
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
Definition: pixfmt.h:79
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
Definition: pixfmt.h:176
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:168
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Definition: pixfmt.h:80
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Definition: pixfmt.h:78
#define AV_PIX_FMT_YUV422P14
Definition: pixfmt.h:408
#define AV_PIX_FMT_YUV422P16
Definition: pixfmt.h:411
AVColorPrimaries
Chromaticity coordinates of the source primaries.
Definition: pixfmt.h:458
@ AVCOL_PRI_BT470BG
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM
Definition: pixfmt.h:465
@ AVCOL_PRI_FILM
colour filters using Illuminant C
Definition: pixfmt.h:468
@ AVCOL_PRI_SMPTE432
SMPTE ST 432-1 (2010) / P3 D65 / Display P3.
Definition: pixfmt.h:473
@ AVCOL_PRI_BT709
also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP177 Annex B
Definition: pixfmt.h:460
@ AVCOL_PRI_JEDEC_P22
Definition: pixfmt.h:475
@ AVCOL_PRI_SMPTE240M
functionally identical to above
Definition: pixfmt.h:467
@ AVCOL_PRI_UNSPECIFIED
Definition: pixfmt.h:461
@ AVCOL_PRI_SMPTE431
SMPTE ST 431-2 (2011) / DCI P3.
Definition: pixfmt.h:472
@ AVCOL_PRI_SMPTE428
SMPTE ST 428-1 (CIE 1931 XYZ)
Definition: pixfmt.h:470
@ AVCOL_PRI_SMPTE170M
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
Definition: pixfmt.h:466
@ AVCOL_PRI_BT2020
ITU-R BT2020.
Definition: pixfmt.h:469
@ AVCOL_PRI_BT470M
also FCC Title 47 Code of Federal Regulations 73.682 (a)(20)
Definition: pixfmt.h:463
AVColorTransferCharacteristic
Color Transfer Characteristic.
Definition: pixfmt.h:483
@ AVCOL_TRC_SMPTE170M
also ITU-R BT601-6 525 or 625 / ITU-R BT1358 525 or 625 / ITU-R BT1700 NTSC
Definition: pixfmt.h:490
@ AVCOL_TRC_SMPTE2084
SMPTE ST 2084 for 10-, 12-, 14- and 16-bit systems.
Definition: pixfmt.h:500
@ AVCOL_TRC_GAMMA22
also ITU-R BT470M / ITU-R BT1700 625 PAL & SECAM
Definition: pixfmt.h:488
@ AVCOL_TRC_SMPTE240M
Definition: pixfmt.h:491
@ AVCOL_TRC_LOG
"Logarithmic transfer characteristic (100:1 range)"
Definition: pixfmt.h:493
@ AVCOL_TRC_IEC61966_2_4
IEC 61966-2-4.
Definition: pixfmt.h:495
@ AVCOL_TRC_LINEAR
"Linear transfer characteristics"
Definition: pixfmt.h:492
@ AVCOL_TRC_GAMMA28
also ITU-R BT470BG
Definition: pixfmt.h:489
@ AVCOL_TRC_ARIB_STD_B67
ARIB STD-B67, known as "Hybrid log-gamma".
Definition: pixfmt.h:504
@ AVCOL_TRC_LOG_SQRT
"Logarithmic transfer characteristic (100 * Sqrt(10) : 1 range)"
Definition: pixfmt.h:494
@ AVCOL_TRC_BT2020_12
ITU-R BT2020 for 12-bit system.
Definition: pixfmt.h:499
@ AVCOL_TRC_IEC61966_2_1
IEC 61966-2-1 (sRGB or sYCC)
Definition: pixfmt.h:497
@ AVCOL_TRC_BT2020_10
ITU-R BT2020 for 10-bit system.
Definition: pixfmt.h:498
@ AVCOL_TRC_UNSPECIFIED
Definition: pixfmt.h:486
@ AVCOL_TRC_BT709
also ITU-R BT1361
Definition: pixfmt.h:485
#define AV_PIX_FMT_YUVA444P16
Definition: pixfmt.h:443
#define AV_PIX_FMT_YUVA422P16
Definition: pixfmt.h:442
#define AV_PIX_FMT_GBRP16
Definition: pixfmt.h:418
#define AV_PIX_FMT_YUV444P14
Definition: pixfmt.h:409
#define AV_PIX_FMT_YUVA444P9
Definition: pixfmt.h:435
#define AV_PIX_FMT_GBRP14
Definition: pixfmt.h:417
#define AV_PIX_FMT_GBRAPF32
Definition: pixfmt.h:429
#define AV_PIX_FMT_YUV444P16
Definition: pixfmt.h:412
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:402
AVColorSpace
YUV colorspace type.
Definition: pixfmt.h:512
@ AVCOL_SPC_BT709
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / SMPTE RP177 Annex B
Definition: pixfmt.h:514
@ AVCOL_SPC_BT470BG
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601
Definition: pixfmt.h:518
@ AVCOL_SPC_CHROMA_DERIVED_CL
Chromaticity-derived constant luminance system.
Definition: pixfmt.h:527
@ AVCOL_SPC_BT2020_CL
ITU-R BT2020 constant luminance system.
Definition: pixfmt.h:524
@ AVCOL_SPC_RGB
order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB)
Definition: pixfmt.h:513
@ AVCOL_SPC_BT2020_NCL
ITU-R BT2020 non-constant luminance system.
Definition: pixfmt.h:523
@ AVCOL_SPC_UNSPECIFIED
Definition: pixfmt.h:515
@ AVCOL_SPC_SMPTE170M
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
Definition: pixfmt.h:519
@ AVCOL_SPC_FCC
FCC Title 47 Code of Federal Regulations 73.682 (a)(20)
Definition: pixfmt.h:517
@ AVCOL_SPC_CHROMA_DERIVED_NCL
Chromaticity-derived non-constant luminance system.
Definition: pixfmt.h:526
@ AVCOL_SPC_SMPTE240M
functionally identical to above
Definition: pixfmt.h:520
@ AVCOL_SPC_YCGCO
Used by Dirac / VC-2 and H.264 FRext, see ITU-T SG16.
Definition: pixfmt.h:521
@ AVCOL_SPC_ICTCP
ITU-R BT.2100-0, ICtCp.
Definition: pixfmt.h:528
var_name
Definition: setts_bsf.c:50
#define snprintf
Definition: snprintf.h:34
Describe the class of an AVClass context structure.
Definition: log.h:67
int plane
Which of the 4 planes contains the component.
Definition: pixdesc.h:35
int step
Number of elements between 2 horizontally consecutive pixels.
Definition: pixdesc.h:41
int depth
Number of bits in the component.
Definition: pixdesc.h:58
An instance of a filter.
Definition: avfilter.h:341
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:349
void * priv
private data for use by the filter
Definition: avfilter.h:356
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:353
A filter pad used for either input or output.
Definition: internal.h:54
const char * name
Pad name.
Definition: internal.h:60
Filter definition.
Definition: avfilter.h:145
const char * name
Filter name.
Definition: avfilter.h:149
This structure describes decoded (raw) audio or video data.
Definition: frame.h:318
enum AVChromaLocation chroma_location
Definition: frame.h:575
int width
Definition: frame.h:376
int height
Definition: frame.h:376
enum AVColorPrimaries color_primaries
Definition: frame.h:564
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: frame.h:562
enum AVColorSpace colorspace
YUV colorspace type.
Definition: frame.h:573
enum AVColorTransferCharacteristic color_trc
Definition: frame.h:566
AVOption.
Definition: opt.h:248
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:117
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:92
uint64_t flags
Combination of AV_PIX_FMT_FLAG_...
Definition: pixdesc.h:106
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:101
Rational number (pair of numerator and denominator).
Definition: rational.h:58
int num
Numerator.
Definition: rational.h:59
int den
Denominator.
Definition: rational.h:60
double param_b
Definition: vf_zscale.c:105
double nominal_peak_luminance
Definition: vf_zscale.c:102
void * tmp
Definition: vf_zscale.c:117
zimg_graph_builder_params params
Definition: vf_zscale.c:122
enum AVColorTransferCharacteristic in_trc out_trc
Definition: vf_zscale.c:126
enum AVColorPrimaries in_primaries out_primaries
Definition: vf_zscale.c:127
zimg_image_format alpha_src_format
Definition: vf_zscale.c:121
int out_h_chr_pos
Definition: vf_zscale.c:110
double param_a
Definition: vf_zscale.c:104
int w
New dimensions.
Definition: vf_zscale.c:88
int approximate_gamma
Definition: vf_zscale.c:103
int force_original_aspect_ratio
Definition: vf_zscale.c:115
char * size_str
Definition: vf_zscale.c:101
enum AVColorSpace in_colorspace out_colorspace
Definition: vf_zscale.c:125
zimg_graph_builder_params alpha_params
Definition: vf_zscale.c:122
int out_v_chr_pos
Definition: vf_zscale.c:111
int in_h_chr_pos
Definition: vf_zscale.c:112
int in_v_chr_pos
Definition: vf_zscale.c:113
zimg_image_format dst_format
Definition: vf_zscale.c:120
enum AVChromaLocation in_chromal out_chromal
Definition: vf_zscale.c:129
zimg_filter_graph * graph
Definition: vf_zscale.c:123
size_t tmp_size
Definition: vf_zscale.c:118
char * w_expr
width expression string
Definition: vf_zscale.c:107
enum AVColorRange in_range out_range
Definition: vf_zscale.c:128
int colorspace_in
Definition: vf_zscale.c:96
zimg_filter_graph * alpha_graph
Definition: vf_zscale.c:123
zimg_image_format src_format
Definition: vf_zscale.c:120
zimg_image_format alpha_dst_format
Definition: vf_zscale.c:121
int primaries_in
Definition: vf_zscale.c:98
int colorspace
Definition: vf_zscale.c:91
char * h_expr
height expression string
Definition: vf_zscale.c:108
#define av_freep(p)
#define av_malloc(s)
#define av_log(a,...)
static uint8_t tmp[11]
Definition: aes_ctr.c:27
FILE * out
Definition: movenc.c:54
AVFormatContext * ctx
Definition: movenc.c:48
AVDictionary * opts
Definition: movenc.c:50
int size
static const uint8_t dither[8][8]
Definition: vf_fspp.c:59
if(ret< 0)
Definition: vf_mcdeint.c:282
color_range
@ VAR_VSUB
Definition: vf_zscale.c:73
@ VAR_OUT_H
Definition: vf_zscale.c:68
@ VARS_NB
Definition: vf_zscale.c:76
@ VAR_SAR
Definition: vf_zscale.c:70
@ VAR_OH
Definition: vf_zscale.c:68
@ VAR_IN_W
Definition: vf_zscale.c:65
@ VAR_IW
Definition: vf_zscale.c:65
@ VAR_OW
Definition: vf_zscale.c:67
@ VAR_OHSUB
Definition: vf_zscale.c:74
@ VAR_IH
Definition: vf_zscale.c:66
@ VAR_A
Definition: vf_zscale.c:69
@ VAR_OUT_W
Definition: vf_zscale.c:67
@ VAR_OVSUB
Definition: vf_zscale.c:75
@ VAR_HSUB
Definition: vf_zscale.c:72
@ VAR_IN_H
Definition: vf_zscale.c:66
@ VAR_DAR
Definition: vf_zscale.c:71
AVFilter ff_vf_zscale
Definition: vf_zscale.c:939
static int realign_frame(const AVPixFmtDescriptor *desc, AVFrame **frame)
Definition: vf_zscale.c:518
static int config_props(AVFilterLink *outlink)
Definition: vf_zscale.c:198
static int graph_build(zimg_filter_graph **graph, zimg_graph_builder_params *params, zimg_image_format *src_format, zimg_image_format *dst_format, void **tmp, size_t *tmp_size)
Definition: vf_zscale.c:490
static int print_zimg_error(AVFilterContext *ctx)
Definition: vf_zscale.c:330
static int convert_trc(enum AVColorTransferCharacteristic color_trc)
Definition: vf_zscale.c:393
static int convert_range(enum AVColorRange color_range)
Definition: vf_zscale.c:461
static int filter_frame(AVFilterLink *link, AVFrame *in)
Definition: vf_zscale.c:556
#define ZIMG_ALIGNMENT
Definition: vf_zscale.c:47
#define TFLAGS
Definition: vf_zscale.c:793
static int query_formats(AVFilterContext *ctx)
Definition: vf_zscale.c:166
#define FLAGS
Definition: vf_zscale.c:792
static void format_init(zimg_image_format *format, AVFrame *frame, const AVPixFmtDescriptor *desc, int colorspace, int primaries, int transfer, int range, int location)
Definition: vf_zscale.c:473
static int convert_primaries(enum AVColorPrimaries color_primaries)
Definition: vf_zscale.c:430
AVFILTER_DEFINE_CLASS(zscale)
static int convert_matrix(enum AVColorSpace colorspace)
Definition: vf_zscale.c:360
static const char *const var_names[]
Definition: vf_zscale.c:49
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
Definition: vf_zscale.c:767
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_zscale.c:757
static int convert_chroma_location(enum AVChromaLocation chroma_location)
Definition: vf_zscale.c:340
#define OFFSET(x)
Definition: vf_zscale.c:791
static const AVFilterPad avfilter_vf_zscale_outputs[]
Definition: vf_zscale.c:930
static const AVOption zscale_options[]
Definition: vf_zscale.c:795
static av_cold int init_dict(AVFilterContext *ctx, AVDictionary **opts)
Definition: vf_zscale.c:132
static const AVFilterPad avfilter_vf_zscale_inputs[]
Definition: vf_zscale.c:921
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:104