FFmpeg
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 {
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  int 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  s->w = var_values[VAR_OUT_W] = var_values[VAR_OW] = 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  s->h = var_values[VAR_OUT_H] = var_values[VAR_OH] = res;
234  /* evaluate again the width, as it may depend on the output height */
235  if ((ret = av_expr_parse_and_eval(&res, (expr = s->w_expr),
236  var_names, var_values,
237  NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0)
238  goto fail;
239  s->w = res;
240 
241  w = s->w;
242  h = s->h;
243 
244  /* Check if it is requested that the result has to be divisible by a some
245  * factor (w or h = -n with n being the factor). */
246  factor_w = 1;
247  factor_h = 1;
248  if (w < -1) {
249  factor_w = -w;
250  }
251  if (h < -1) {
252  factor_h = -h;
253  }
254 
255  if (w < 0 && h < 0)
256  s->w = s->h = 0;
257 
258  if (!(w = s->w))
259  w = inlink->w;
260  if (!(h = s->h))
261  h = inlink->h;
262 
263  /* Make sure that the result is divisible by the factor we determined
264  * earlier. If no factor was set, it is nothing will happen as the default
265  * factor is 1 */
266  if (w < 0)
267  w = av_rescale(h, inlink->w, inlink->h * factor_w) * factor_w;
268  if (h < 0)
269  h = av_rescale(w, inlink->h, inlink->w * factor_h) * factor_h;
270 
271  /* Note that force_original_aspect_ratio may overwrite the previous set
272  * dimensions so that it is not divisible by the set factors anymore. */
273  if (s->force_original_aspect_ratio) {
274  int tmp_w = av_rescale(h, inlink->w, inlink->h);
275  int tmp_h = av_rescale(w, inlink->h, inlink->w);
276 
277  if (s->force_original_aspect_ratio == 1) {
278  w = FFMIN(tmp_w, w);
279  h = FFMIN(tmp_h, h);
280  } else {
281  w = FFMAX(tmp_w, w);
282  h = FFMAX(tmp_h, h);
283  }
284  }
285 
286  if (w > INT_MAX || h > INT_MAX ||
287  (h * inlink->w) > INT_MAX ||
288  (w * inlink->h) > INT_MAX)
289  av_log(ctx, AV_LOG_ERROR, "Rescaled value for width or height is too big.\n");
290 
291  outlink->w = w;
292  outlink->h = h;
293 
294  if (inlink->w == outlink->w &&
295  inlink->h == outlink->h &&
296  inlink->format == outlink->format)
297  ;
298  else {
299  }
300 
301  if (inlink->sample_aspect_ratio.num){
302  outlink->sample_aspect_ratio = av_mul_q((AVRational){outlink->h * inlink->w, outlink->w * inlink->h}, inlink->sample_aspect_ratio);
303  } else
304  outlink->sample_aspect_ratio = inlink->sample_aspect_ratio;
305 
306  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",
307  inlink ->w, inlink ->h, av_get_pix_fmt_name( inlink->format),
308  inlink->sample_aspect_ratio.num, inlink->sample_aspect_ratio.den,
309  outlink->w, outlink->h, av_get_pix_fmt_name(outlink->format),
310  outlink->sample_aspect_ratio.num, outlink->sample_aspect_ratio.den);
311  return 0;
312 
313 fail:
315  "Error when evaluating the expression '%s'.\n"
316  "Maybe the expression for out_w:'%s' or for out_h:'%s' is self-referencing.\n",
317  expr, s->w_expr, s->h_expr);
318  return ret;
319 }
320 
322 {
323  char err_msg[1024];
324  int err_code = zimg_get_last_error(err_msg, sizeof(err_msg));
325 
326  av_log(ctx, AV_LOG_ERROR, "code %d: %s\n", err_code, err_msg);
327 
328  return AVERROR_EXTERNAL;
329 }
330 
331 static int convert_chroma_location(enum AVChromaLocation chroma_location)
332 {
333  switch (chroma_location) {
335  case AVCHROMA_LOC_LEFT:
336  return ZIMG_CHROMA_LEFT;
337  case AVCHROMA_LOC_CENTER:
338  return ZIMG_CHROMA_CENTER;
340  return ZIMG_CHROMA_TOP_LEFT;
341  case AVCHROMA_LOC_TOP:
342  return ZIMG_CHROMA_TOP;
344  return ZIMG_CHROMA_BOTTOM_LEFT;
345  case AVCHROMA_LOC_BOTTOM:
346  return ZIMG_CHROMA_BOTTOM;
347  }
348  return ZIMG_CHROMA_LEFT;
349 }
350 
351 static int convert_matrix(enum AVColorSpace colorspace)
352 {
353  switch (colorspace) {
354  case AVCOL_SPC_RGB:
355  return ZIMG_MATRIX_RGB;
356  case AVCOL_SPC_BT709:
357  return ZIMG_MATRIX_709;
359  return ZIMG_MATRIX_UNSPECIFIED;
360  case AVCOL_SPC_FCC:
361  return ZIMG_MATRIX_FCC;
362  case AVCOL_SPC_BT470BG:
363  return ZIMG_MATRIX_470BG;
364  case AVCOL_SPC_SMPTE170M:
365  return ZIMG_MATRIX_170M;
366  case AVCOL_SPC_SMPTE240M:
367  return ZIMG_MATRIX_240M;
368  case AVCOL_SPC_YCGCO:
369  return ZIMG_MATRIX_YCGCO;
371  return ZIMG_MATRIX_2020_NCL;
372  case AVCOL_SPC_BT2020_CL:
373  return ZIMG_MATRIX_2020_CL;
375  return ZIMG_MATRIX_CHROMATICITY_DERIVED_NCL;
377  return ZIMG_MATRIX_CHROMATICITY_DERIVED_CL;
378  case AVCOL_SPC_ICTCP:
379  return ZIMG_MATRIX_ICTCP;
380  }
381  return ZIMG_MATRIX_UNSPECIFIED;
382 }
383 
384 static int convert_trc(enum AVColorTransferCharacteristic color_trc)
385 {
386  switch (color_trc) {
388  return ZIMG_TRANSFER_UNSPECIFIED;
389  case AVCOL_TRC_BT709:
390  return ZIMG_TRANSFER_709;
391  case AVCOL_TRC_GAMMA22:
392  return ZIMG_TRANSFER_470_M;
393  case AVCOL_TRC_GAMMA28:
394  return ZIMG_TRANSFER_470_BG;
395  case AVCOL_TRC_SMPTE170M:
396  return ZIMG_TRANSFER_601;
397  case AVCOL_TRC_SMPTE240M:
398  return ZIMG_TRANSFER_240M;
399  case AVCOL_TRC_LINEAR:
400  return ZIMG_TRANSFER_LINEAR;
401  case AVCOL_TRC_LOG:
402  return ZIMG_TRANSFER_LOG_100;
403  case AVCOL_TRC_LOG_SQRT:
404  return ZIMG_TRANSFER_LOG_316;
406  return ZIMG_TRANSFER_IEC_61966_2_4;
407  case AVCOL_TRC_BT2020_10:
408  return ZIMG_TRANSFER_2020_10;
409  case AVCOL_TRC_BT2020_12:
410  return ZIMG_TRANSFER_2020_12;
411  case AVCOL_TRC_SMPTE2084:
412  return ZIMG_TRANSFER_ST2084;
414  return ZIMG_TRANSFER_ARIB_B67;
416  return ZIMG_TRANSFER_IEC_61966_2_1;
417  }
418  return ZIMG_TRANSFER_UNSPECIFIED;
419 }
420 
422 {
423  switch (color_primaries) {
425  return ZIMG_PRIMARIES_UNSPECIFIED;
426  case AVCOL_PRI_BT709:
427  return ZIMG_PRIMARIES_709;
428  case AVCOL_PRI_BT470M:
429  return ZIMG_PRIMARIES_470_M;
430  case AVCOL_PRI_BT470BG:
431  return ZIMG_PRIMARIES_470_BG;
432  case AVCOL_PRI_SMPTE170M:
433  return ZIMG_PRIMARIES_170M;
434  case AVCOL_PRI_SMPTE240M:
435  return ZIMG_PRIMARIES_240M;
436  case AVCOL_PRI_FILM:
437  return ZIMG_PRIMARIES_FILM;
438  case AVCOL_PRI_BT2020:
439  return ZIMG_PRIMARIES_2020;
440  case AVCOL_PRI_SMPTE428:
441  return ZIMG_PRIMARIES_ST428;
442  case AVCOL_PRI_SMPTE431:
443  return ZIMG_PRIMARIES_ST431_2;
444  case AVCOL_PRI_SMPTE432:
445  return ZIMG_PRIMARIES_ST432_1;
446  case AVCOL_PRI_JEDEC_P22:
447  return ZIMG_PRIMARIES_EBU3213_E;
448  }
449  return ZIMG_PRIMARIES_UNSPECIFIED;
450 }
451 
453 {
454  switch (color_range) {
456  case AVCOL_RANGE_MPEG:
457  return ZIMG_RANGE_LIMITED;
458  case AVCOL_RANGE_JPEG:
459  return ZIMG_RANGE_FULL;
460  }
461  return ZIMG_RANGE_LIMITED;
462 }
463 
464 static void format_init(zimg_image_format *format, AVFrame *frame, const AVPixFmtDescriptor *desc,
465  int colorspace, int primaries, int transfer, int range, int location)
466 {
467  format->width = frame->width;
468  format->height = frame->height;
469  format->subsample_w = desc->log2_chroma_w;
470  format->subsample_h = desc->log2_chroma_h;
471  format->depth = desc->comp[0].depth;
472  format->pixel_type = (desc->flags & AV_PIX_FMT_FLAG_FLOAT) ? ZIMG_PIXEL_FLOAT : desc->comp[0].depth > 8 ? ZIMG_PIXEL_WORD : ZIMG_PIXEL_BYTE;
473  format->color_family = (desc->flags & AV_PIX_FMT_FLAG_RGB) ? ZIMG_COLOR_RGB : ZIMG_COLOR_YUV;
474  format->matrix_coefficients = (desc->flags & AV_PIX_FMT_FLAG_RGB) ? ZIMG_MATRIX_RGB : colorspace == -1 ? convert_matrix(frame->colorspace) : colorspace;
475  format->color_primaries = primaries == -1 ? convert_primaries(frame->color_primaries) : primaries;
476  format->transfer_characteristics = transfer == - 1 ? convert_trc(frame->color_trc) : transfer;
477  format->pixel_range = (desc->flags & AV_PIX_FMT_FLAG_RGB) ? ZIMG_RANGE_FULL : range == -1 ? convert_range(frame->color_range) : range;
478  format->chroma_location = location == -1 ? convert_chroma_location(frame->chroma_location) : location;
479 }
480 
481 static int graph_build(zimg_filter_graph **graph, zimg_graph_builder_params *params,
482  zimg_image_format *src_format, zimg_image_format *dst_format,
483  void **tmp, size_t *tmp_size)
484 {
485  int ret;
486  size_t size;
487 
488  zimg_filter_graph_free(*graph);
489  *graph = zimg_filter_graph_build(src_format, dst_format, params);
490  if (!*graph)
491  return print_zimg_error(NULL);
492 
493  ret = zimg_filter_graph_get_tmp_size(*graph, &size);
494  if (ret)
495  return print_zimg_error(NULL);
496 
497  if (size > *tmp_size) {
498  av_freep(tmp);
499  *tmp = av_malloc(size);
500  if (!*tmp)
501  return AVERROR(ENOMEM);
502 
503  *tmp_size = size;
504  }
505 
506  return 0;
507 }
508 
510 {
511  AVFrame *aligned = NULL;
512  int ret = 0, plane;
513 
514  /* Realign any unaligned input frame. */
515  for (plane = 0; plane < 3; plane++) {
516  int p = desc->comp[plane].plane;
517  if ((uintptr_t)(*frame)->data[p] % ZIMG_ALIGNMENT || (*frame)->linesize[p] % ZIMG_ALIGNMENT) {
518  if (!(aligned = av_frame_alloc())) {
519  ret = AVERROR(ENOMEM);
520  goto fail;
521  }
522 
523  aligned->format = (*frame)->format;
524  aligned->width = (*frame)->width;
525  aligned->height = (*frame)->height;
526 
528  goto fail;
529 
530  if ((ret = av_frame_copy(aligned, *frame)) < 0)
531  goto fail;
532 
533  if ((ret = av_frame_copy_props(aligned, *frame)) < 0)
534  goto fail;
535 
537  *frame = aligned;
538  return 0;
539  }
540  }
541 
542 fail:
544  return ret;
545 }
546 
548 {
549  ZScaleContext *s = link->dst->priv;
550  AVFilterLink *outlink = link->dst->outputs[0];
552  const AVPixFmtDescriptor *odesc = av_pix_fmt_desc_get(outlink->format);
553  zimg_image_buffer_const src_buf = { ZIMG_API_VERSION };
554  zimg_image_buffer dst_buf = { ZIMG_API_VERSION };
555  char buf[32];
556  int ret = 0, plane;
557  AVFrame *out = NULL;
558 
559  if ((ret = realign_frame(desc, &in)) < 0)
560  goto fail;
561 
562  if (!(out = ff_get_video_buffer(outlink, outlink->w, outlink->h))) {
563  ret = AVERROR(ENOMEM);
564  goto fail;
565  }
566 
568  out->width = outlink->w;
569  out->height = outlink->h;
570 
571  if( in->width != link->w
572  || in->height != link->h
573  || in->format != link->format
574  || s->in_colorspace != in->colorspace
575  || s->in_trc != in->color_trc
576  || s->in_primaries != in->color_primaries
577  || s->in_range != in->color_range
578  || s->out_colorspace != out->colorspace
579  || s->out_trc != out->color_trc
580  || s->out_primaries != out->color_primaries
581  || s->out_range != out->color_range
582  || s->in_chromal != in->chroma_location
583  || s->out_chromal != out->chroma_location) {
584  snprintf(buf, sizeof(buf)-1, "%d", outlink->w);
585  av_opt_set(s, "w", buf, 0);
586  snprintf(buf, sizeof(buf)-1, "%d", outlink->h);
587  av_opt_set(s, "h", buf, 0);
588 
589  link->dst->inputs[0]->format = in->format;
590  link->dst->inputs[0]->w = in->width;
591  link->dst->inputs[0]->h = in->height;
592 
593  if ((ret = config_props(outlink)) < 0)
594  goto fail;
595 
596  zimg_image_format_default(&s->src_format, ZIMG_API_VERSION);
597  zimg_image_format_default(&s->dst_format, ZIMG_API_VERSION);
598  zimg_graph_builder_params_default(&s->params, ZIMG_API_VERSION);
599 
600  s->params.dither_type = s->dither;
601  s->params.cpu_type = ZIMG_CPU_AUTO;
602  s->params.resample_filter = s->filter;
603  s->params.resample_filter_uv = s->filter;
604  s->params.nominal_peak_luminance = s->nominal_peak_luminance;
605  s->params.allow_approximate_gamma = s->approximate_gamma;
606  s->params.filter_param_a = s->params.filter_param_a_uv = s->param_a;
607  s->params.filter_param_b = s->params.filter_param_b_uv = s->param_b;
608 
609  format_init(&s->src_format, in, desc, s->colorspace_in,
610  s->primaries_in, s->trc_in, s->range_in, s->chromal_in);
611  format_init(&s->dst_format, out, odesc, s->colorspace,
612  s->primaries, s->trc, s->range, s->chromal);
613 
614  if (s->colorspace != -1)
615  out->colorspace = (int)s->dst_format.matrix_coefficients;
616 
617  if (s->primaries != -1)
618  out->color_primaries = (int)s->dst_format.color_primaries;
619 
620  if (s->range != -1)
621  out->color_range = (int)s->dst_format.pixel_range + 1;
622 
623  if (s->trc != -1)
624  out->color_trc = (int)s->dst_format.transfer_characteristics;
625 
626  if (s->chromal != -1)
627  out->chroma_location = (int)s->dst_format.chroma_location - 1;
628 
629  ret = graph_build(&s->graph, &s->params, &s->src_format, &s->dst_format,
630  &s->tmp, &s->tmp_size);
631  if (ret < 0)
632  goto fail;
633 
634  s->in_colorspace = in->colorspace;
635  s->in_trc = in->color_trc;
636  s->in_primaries = in->color_primaries;
637  s->in_range = in->color_range;
638  s->out_colorspace = out->colorspace;
639  s->out_trc = out->color_trc;
640  s->out_primaries = out->color_primaries;
641  s->out_range = out->color_range;
642 
643  if (desc->flags & AV_PIX_FMT_FLAG_ALPHA && odesc->flags & AV_PIX_FMT_FLAG_ALPHA) {
644  zimg_image_format_default(&s->alpha_src_format, ZIMG_API_VERSION);
645  zimg_image_format_default(&s->alpha_dst_format, ZIMG_API_VERSION);
646  zimg_graph_builder_params_default(&s->alpha_params, ZIMG_API_VERSION);
647 
648  s->alpha_params.dither_type = s->dither;
649  s->alpha_params.cpu_type = ZIMG_CPU_AUTO;
650  s->alpha_params.resample_filter = s->filter;
651 
652  s->alpha_src_format.width = in->width;
653  s->alpha_src_format.height = in->height;
654  s->alpha_src_format.depth = desc->comp[0].depth;
655  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;
656  s->alpha_src_format.color_family = ZIMG_COLOR_GREY;
657 
658  s->alpha_dst_format.width = out->width;
659  s->alpha_dst_format.height = out->height;
660  s->alpha_dst_format.depth = odesc->comp[0].depth;
661  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;
662  s->alpha_dst_format.color_family = ZIMG_COLOR_GREY;
663 
664  zimg_filter_graph_free(s->alpha_graph);
665  s->alpha_graph = zimg_filter_graph_build(&s->alpha_src_format, &s->alpha_dst_format, &s->alpha_params);
666  if (!s->alpha_graph) {
667  ret = print_zimg_error(link->dst);
668  goto fail;
669  }
670  }
671  }
672 
673  if (s->colorspace != -1)
674  out->colorspace = (int)s->dst_format.matrix_coefficients;
675 
676  if (s->primaries != -1)
677  out->color_primaries = (int)s->dst_format.color_primaries;
678 
679  if (s->range != -1)
680  out->color_range = (int)s->dst_format.pixel_range;
681 
682  if (s->trc != -1)
683  out->color_trc = (int)s->dst_format.transfer_characteristics;
684 
685  av_reduce(&out->sample_aspect_ratio.num, &out->sample_aspect_ratio.den,
686  (int64_t)in->sample_aspect_ratio.num * outlink->h * link->w,
687  (int64_t)in->sample_aspect_ratio.den * outlink->w * link->h,
688  INT_MAX);
689 
690  for (plane = 0; plane < 3; plane++) {
691  int p = desc->comp[plane].plane;
692  src_buf.plane[plane].data = in->data[p];
693  src_buf.plane[plane].stride = in->linesize[p];
694  src_buf.plane[plane].mask = -1;
695 
696  p = odesc->comp[plane].plane;
697  dst_buf.plane[plane].data = out->data[p];
698  dst_buf.plane[plane].stride = out->linesize[p];
699  dst_buf.plane[plane].mask = -1;
700  }
701 
702  ret = zimg_filter_graph_process(s->graph, &src_buf, &dst_buf, s->tmp, 0, 0, 0, 0);
703  if (ret) {
704  ret = print_zimg_error(link->dst);
705  goto fail;
706  }
707 
708  if (desc->flags & AV_PIX_FMT_FLAG_ALPHA && odesc->flags & AV_PIX_FMT_FLAG_ALPHA) {
709  src_buf.plane[0].data = in->data[3];
710  src_buf.plane[0].stride = in->linesize[3];
711  src_buf.plane[0].mask = -1;
712 
713  dst_buf.plane[0].data = out->data[3];
714  dst_buf.plane[0].stride = out->linesize[3];
715  dst_buf.plane[0].mask = -1;
716 
717  ret = zimg_filter_graph_process(s->alpha_graph, &src_buf, &dst_buf, s->tmp, 0, 0, 0, 0);
718  if (ret) {
719  ret = print_zimg_error(link->dst);
720  goto fail;
721  }
722  } else if (odesc->flags & AV_PIX_FMT_FLAG_ALPHA) {
723  int x, y;
724 
725  if (odesc->flags & AV_PIX_FMT_FLAG_FLOAT) {
726  for (y = 0; y < out->height; y++) {
727  for (x = 0; x < out->width; x++) {
728  AV_WN32(out->data[3] + x * odesc->comp[3].step + y * out->linesize[3],
729  av_float2int(1.0f));
730  }
731  }
732  } else {
733  for (y = 0; y < outlink->h; y++)
734  memset(out->data[3] + y * out->linesize[3], 0xff, outlink->w);
735  }
736  }
737 
738 fail:
739  av_frame_free(&in);
740  if (ret) {
741  av_frame_free(&out);
742  return ret;
743  }
744 
745  return ff_filter_frame(outlink, out);
746 }
747 
749 {
750  ZScaleContext *s = ctx->priv;
751 
752  zimg_filter_graph_free(s->graph);
753  zimg_filter_graph_free(s->alpha_graph);
754  av_freep(&s->tmp);
755  s->tmp_size = 0;
756 }
757 
758 static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
759  char *res, int res_len, int flags)
760 {
761  ZScaleContext *s = ctx->priv;
762  int ret;
763 
764  if ( !strcmp(cmd, "width") || !strcmp(cmd, "w")
765  || !strcmp(cmd, "height") || !strcmp(cmd, "h")) {
766 
767  int old_w = s->w;
768  int old_h = s->h;
769  AVFilterLink *outlink = ctx->outputs[0];
770 
771  av_opt_set(s, cmd, args, 0);
772  if ((ret = config_props(outlink)) < 0) {
773  s->w = old_w;
774  s->h = old_h;
775  }
776  } else
777  ret = AVERROR(ENOSYS);
778 
779  return ret;
780 }
781 
782 #define OFFSET(x) offsetof(ZScaleContext, x)
783 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
784 #define TFLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
785 
786 static const AVOption zscale_options[] = {
787  { "w", "Output video width", OFFSET(w_expr), AV_OPT_TYPE_STRING, .flags = TFLAGS },
788  { "width", "Output video width", OFFSET(w_expr), AV_OPT_TYPE_STRING, .flags = TFLAGS },
789  { "h", "Output video height", OFFSET(h_expr), AV_OPT_TYPE_STRING, .flags = TFLAGS },
790  { "height", "Output video height", OFFSET(h_expr), AV_OPT_TYPE_STRING, .flags = TFLAGS },
791  { "size", "set video size", OFFSET(size_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS },
792  { "s", "set video size", OFFSET(size_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS },
793  { "dither", "set dither type", OFFSET(dither), AV_OPT_TYPE_INT, {.i64 = 0}, 0, ZIMG_DITHER_ERROR_DIFFUSION, FLAGS, "dither" },
794  { "d", "set dither type", OFFSET(dither), AV_OPT_TYPE_INT, {.i64 = 0}, 0, ZIMG_DITHER_ERROR_DIFFUSION, FLAGS, "dither" },
795  { "none", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_DITHER_NONE}, 0, 0, FLAGS, "dither" },
796  { "ordered", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_DITHER_ORDERED}, 0, 0, FLAGS, "dither" },
797  { "random", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_DITHER_RANDOM}, 0, 0, FLAGS, "dither" },
798  { "error_diffusion", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_DITHER_ERROR_DIFFUSION}, 0, 0, FLAGS, "dither" },
799  { "filter", "set filter type", OFFSET(filter), AV_OPT_TYPE_INT, {.i64 = ZIMG_RESIZE_BILINEAR}, 0, ZIMG_RESIZE_LANCZOS, FLAGS, "filter" },
800  { "f", "set filter type", OFFSET(filter), AV_OPT_TYPE_INT, {.i64 = ZIMG_RESIZE_BILINEAR}, 0, ZIMG_RESIZE_LANCZOS, FLAGS, "filter" },
801  { "point", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_RESIZE_POINT}, 0, 0, FLAGS, "filter" },
802  { "bilinear", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_RESIZE_BILINEAR}, 0, 0, FLAGS, "filter" },
803  { "bicubic", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_RESIZE_BICUBIC}, 0, 0, FLAGS, "filter" },
804  { "spline16", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_RESIZE_SPLINE16}, 0, 0, FLAGS, "filter" },
805  { "spline36", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_RESIZE_SPLINE36}, 0, 0, FLAGS, "filter" },
806  { "lanczos", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_RESIZE_LANCZOS}, 0, 0, FLAGS, "filter" },
807  { "out_range", "set color range", OFFSET(range), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_RANGE_FULL, FLAGS, "range" },
808  { "range", "set color range", OFFSET(range), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_RANGE_FULL, FLAGS, "range" },
809  { "r", "set color range", OFFSET(range), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_RANGE_FULL, FLAGS, "range" },
810  { "input", 0, 0, AV_OPT_TYPE_CONST, {.i64 = -1}, 0, 0, FLAGS, "range" },
811  { "limited", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_RANGE_LIMITED}, 0, 0, FLAGS, "range" },
812  { "full", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_RANGE_FULL}, 0, 0, FLAGS, "range" },
813  { "unknown", 0, 0, AV_OPT_TYPE_CONST, {.i64 = -1}, 0, 0, FLAGS, "range" },
814  { "tv", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_RANGE_LIMITED}, 0, 0, FLAGS, "range" },
815  { "pc", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_RANGE_FULL}, 0, 0, FLAGS, "range" },
816  { "primaries", "set color primaries", OFFSET(primaries), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, FLAGS, "primaries" },
817  { "p", "set color primaries", OFFSET(primaries), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, FLAGS, "primaries" },
818  { "input", 0, 0, AV_OPT_TYPE_CONST, {.i64 = -1}, 0, 0, FLAGS, "primaries" },
819  { "709", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_709}, 0, 0, FLAGS, "primaries" },
820  { "unspecified", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_UNSPECIFIED}, 0, 0, FLAGS, "primaries" },
821  { "170m", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_170M}, 0, 0, FLAGS, "primaries" },
822  { "240m", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_240M}, 0, 0, FLAGS, "primaries" },
823  { "2020", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_2020}, 0, 0, FLAGS, "primaries" },
824  { "unknown", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_UNSPECIFIED}, 0, 0, FLAGS, "primaries" },
825  { "bt709", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_709}, 0, 0, FLAGS, "primaries" },
826  { "bt470m", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_470_M}, 0, 0, FLAGS, "primaries" },
827  { "bt470bg", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_470_BG}, 0, 0, FLAGS, "primaries" },
828  { "smpte170m", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_170M}, 0, 0, FLAGS, "primaries" },
829  { "smpte240m", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_240M}, 0, 0, FLAGS, "primaries" },
830  { "film", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_FILM}, 0, 0, FLAGS, "primaries" },
831  { "bt2020", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_2020}, 0, 0, FLAGS, "primaries" },
832  { "smpte428", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_ST428}, 0, 0, FLAGS, "primaries" },
833  { "smpte431", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_ST431_2}, 0, 0, FLAGS, "primaries" },
834  { "smpte432", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_ST432_1}, 0, 0, FLAGS, "primaries" },
835  { "jedec-p22", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_EBU3213_E}, 0, 0, FLAGS, "primaries" },
836  { "ebu3213", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_EBU3213_E}, 0, 0, FLAGS, "primaries" },
837  { "transfer", "set transfer characteristic", OFFSET(trc), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, FLAGS, "transfer" },
838  { "t", "set transfer characteristic", OFFSET(trc), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, FLAGS, "transfer" },
839  { "input", 0, 0, AV_OPT_TYPE_CONST, {.i64 = -1}, 0, 0, FLAGS, "transfer" },
840  { "709", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_709}, 0, 0, FLAGS, "transfer" },
841  { "unspecified", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_UNSPECIFIED}, 0, 0, FLAGS, "transfer" },
842  { "601", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_601}, 0, 0, FLAGS, "transfer" },
843  { "linear", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_LINEAR}, 0, 0, FLAGS, "transfer" },
844  { "2020_10", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_2020_10}, 0, 0, FLAGS, "transfer" },
845  { "2020_12", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_2020_12}, 0, 0, FLAGS, "transfer" },
846  { "unknown", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_UNSPECIFIED}, 0, 0, FLAGS, "transfer" },
847  { "bt470m", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_470_M}, 0, 0, FLAGS, "transfer" },
848  { "bt470bg", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_470_BG}, 0, 0, FLAGS, "transfer" },
849  { "smpte170m", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_601}, 0, 0, FLAGS, "transfer" },
850  { "bt709", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_709}, 0, 0, FLAGS, "transfer" },
851  { "linear", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_LINEAR}, 0, 0, FLAGS, "transfer" },
852  { "log100", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_LOG_100}, 0, 0, FLAGS, "transfer" },
853  { "log316", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_LOG_316}, 0, 0, FLAGS, "transfer" },
854  { "bt2020-10", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_2020_10}, 0, 0, FLAGS, "transfer" },
855  { "bt2020-12", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_2020_12}, 0, 0, FLAGS, "transfer" },
856  { "smpte2084", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_ST2084}, 0, 0, FLAGS, "transfer" },
857  { "iec61966-2-4", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_IEC_61966_2_4},0, 0, FLAGS, "transfer" },
858  { "iec61966-2-1", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_IEC_61966_2_1},0, 0, FLAGS, "transfer" },
859  { "arib-std-b67", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_ARIB_B67}, 0, 0, FLAGS, "transfer" },
860  { "matrix", "set colorspace matrix", OFFSET(colorspace), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, FLAGS, "matrix" },
861  { "m", "set colorspace matrix", OFFSET(colorspace), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, FLAGS, "matrix" },
862  { "input", 0, 0, AV_OPT_TYPE_CONST, {.i64 = -1}, 0, 0, FLAGS, "matrix" },
863  { "709", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_709}, 0, 0, FLAGS, "matrix" },
864  { "unspecified", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_UNSPECIFIED}, 0, 0, FLAGS, "matrix" },
865  { "470bg", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_470BG}, 0, 0, FLAGS, "matrix" },
866  { "170m", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_170M}, 0, 0, FLAGS, "matrix" },
867  { "2020_ncl", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_2020_NCL}, 0, 0, FLAGS, "matrix" },
868  { "2020_cl", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_2020_CL}, 0, 0, FLAGS, "matrix" },
869  { "unknown", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_UNSPECIFIED}, 0, 0, FLAGS, "matrix" },
870  { "gbr", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_RGB}, 0, 0, FLAGS, "matrix" },
871  { "bt709", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_709}, 0, 0, FLAGS, "matrix" },
872  { "fcc", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_FCC}, 0, 0, FLAGS, "matrix" },
873  { "bt470bg", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_470BG}, 0, 0, FLAGS, "matrix" },
874  { "smpte170m", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_170M}, 0, 0, FLAGS, "matrix" },
875  { "smpte2400m", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_240M}, 0, 0, FLAGS, "matrix" },
876  { "ycgco", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_YCGCO}, 0, 0, FLAGS, "matrix" },
877  { "bt2020nc", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_2020_NCL}, 0, 0, FLAGS, "matrix" },
878  { "bt2020c", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_2020_CL}, 0, 0, FLAGS, "matrix" },
879  { "chroma-derived-nc",0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_CHROMATICITY_DERIVED_NCL}, 0, 0, FLAGS, "matrix" },
880  { "chroma-derived-c", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_CHROMATICITY_DERIVED_CL}, 0, 0, FLAGS, "matrix" },
881  { "ictcp", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_ICTCP}, 0, 0, FLAGS, "matrix" },
882  { "in_range", "set input color range", OFFSET(range_in), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_RANGE_FULL, FLAGS, "range" },
883  { "rangein", "set input color range", OFFSET(range_in), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_RANGE_FULL, FLAGS, "range" },
884  { "rin", "set input color range", OFFSET(range_in), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_RANGE_FULL, FLAGS, "range" },
885  { "primariesin", "set input color primaries", OFFSET(primaries_in), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, FLAGS, "primaries" },
886  { "pin", "set input color primaries", OFFSET(primaries_in), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, FLAGS, "primaries" },
887  { "transferin", "set input transfer characteristic", OFFSET(trc_in), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, FLAGS, "transfer" },
888  { "tin", "set input transfer characteristic", OFFSET(trc_in), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, FLAGS, "transfer" },
889  { "matrixin", "set input colorspace matrix", OFFSET(colorspace_in), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, FLAGS, "matrix" },
890  { "min", "set input colorspace matrix", OFFSET(colorspace_in), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, FLAGS, "matrix" },
891  { "chromal", "set output chroma location", OFFSET(chromal), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_CHROMA_BOTTOM, FLAGS, "chroma" },
892  { "c", "set output chroma location", OFFSET(chromal), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_CHROMA_BOTTOM, FLAGS, "chroma" },
893  { "input", 0, 0, AV_OPT_TYPE_CONST, {.i64 = -1}, 0, 0, FLAGS, "chroma" },
894  { "left", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_CHROMA_LEFT}, 0, 0, FLAGS, "chroma" },
895  { "center", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_CHROMA_CENTER}, 0, 0, FLAGS, "chroma" },
896  { "topleft", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_CHROMA_TOP_LEFT}, 0, 0, FLAGS, "chroma" },
897  { "top", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_CHROMA_TOP}, 0, 0, FLAGS, "chroma" },
898  { "bottomleft",0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_CHROMA_BOTTOM_LEFT}, 0, 0, FLAGS, "chroma" },
899  { "bottom", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_CHROMA_BOTTOM}, 0, 0, FLAGS, "chroma" },
900  { "chromalin", "set input chroma location", OFFSET(chromal_in), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_CHROMA_BOTTOM, FLAGS, "chroma" },
901  { "cin", "set input chroma location", OFFSET(chromal_in), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_CHROMA_BOTTOM, FLAGS, "chroma" },
902  { "npl", "set nominal peak luminance", OFFSET(nominal_peak_luminance), AV_OPT_TYPE_DOUBLE, {.dbl = NAN}, 0, DBL_MAX, FLAGS },
903  { "agamma", "allow approximate gamma", OFFSET(approximate_gamma), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, FLAGS },
904  { "param_a", "parameter A, which is parameter \"b\" for bicubic, "
905  "and the number of filter taps for lanczos", OFFSET(param_a), AV_OPT_TYPE_DOUBLE, {.dbl = NAN}, -DBL_MAX, DBL_MAX, FLAGS },
906  { "param_b", "parameter B, which is parameter \"c\" for bicubic", OFFSET(param_b), AV_OPT_TYPE_DOUBLE, {.dbl = NAN}, -DBL_MAX, DBL_MAX, FLAGS },
907  { NULL }
908 };
909 
910 AVFILTER_DEFINE_CLASS(zscale);
911 
913  {
914  .name = "default",
915  .type = AVMEDIA_TYPE_VIDEO,
916  .filter_frame = filter_frame,
917  },
918  { NULL }
919 };
920 
922  {
923  .name = "default",
924  .type = AVMEDIA_TYPE_VIDEO,
925  .config_props = config_props,
926  },
927  { NULL }
928 };
929 
931  .name = "zscale",
932  .description = NULL_IF_CONFIG_SMALL("Apply resizing, colorspace and bit depth conversion."),
933  .init_dict = init_dict,
934  .query_formats = query_formats,
935  .priv_size = sizeof(ZScaleContext),
936  .priv_class = &zscale_class,
937  .uninit = uninit,
941 };
ff_get_video_buffer
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
AV_PIX_FMT_YUVA422P16
#define AV_PIX_FMT_YUVA422P16
Definition: pixfmt.h:442
AV_PIX_FMT_GBRAP16
#define AV_PIX_FMT_GBRAP16
Definition: pixfmt.h:421
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
ZScaleContext::range_in
int range_in
Definition: vf_zscale.c:99
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
ff_make_format_list
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:286
ZScaleContext::colorspace_in
int colorspace_in
Definition: vf_zscale.c:96
AVColorTransferCharacteristic
AVColorTransferCharacteristic
Color Transfer Characteristic.
Definition: pixfmt.h:483
out
FILE * out
Definition: movenc.c:54
av_frame_get_buffer
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
Definition: frame.c:337
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_zscale.c:748
FFSWAP
#define FFSWAP(type, a, b)
Definition: common.h:108
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1096
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2573
AVCOL_TRC_LINEAR
@ AVCOL_TRC_LINEAR
"Linear transfer characteristics"
Definition: pixfmt.h:492
AVCHROMA_LOC_BOTTOM
@ AVCHROMA_LOC_BOTTOM
Definition: pixfmt.h:612
ZScaleContext::h_expr
char * h_expr
height expression string
Definition: vf_zscale.c:108
ZScaleContext::filter
int filter
Definition: vf_zscale.c:90
ZIMG_ALIGNMENT
#define ZIMG_ALIGNMENT
Definition: vf_zscale.c:47
inlink
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
Definition: filter_design.txt:212
AV_PIX_FMT_FLAG_FLOAT
#define AV_PIX_FMT_FLAG_FLOAT
The pixel format contains IEEE-754 floating point values.
Definition: pixdesc.h:190
AVFrame::color_primaries
enum AVColorPrimaries color_primaries
Definition: frame.h:564
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:203
AV_PIX_FMT_YUVA422P9
#define AV_PIX_FMT_YUVA422P9
Definition: pixfmt.h:434
ZScaleContext::chromal
int chromal
Definition: vf_zscale.c:95
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:318
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:27
VAR_VSUB
@ VAR_VSUB
Definition: vf_zscale.c:73
pixdesc.h
TFLAGS
#define TFLAGS
Definition: vf_zscale.c:784
var_names
static const char *const var_names[]
Definition: vf_zscale.c:49
AVFrame::width
int width
Definition: frame.h:376
config_props
static int config_props(AVFilterLink *outlink)
Definition: vf_zscale.c:198
AV_PIX_FMT_YUVA420P16
#define AV_PIX_FMT_YUVA420P16
Definition: pixfmt.h:441
w
uint8_t w
Definition: llviddspenc.c:39
AVCOL_RANGE_JPEG
@ AVCOL_RANGE_JPEG
Full range content.
Definition: pixfmt.h:586
ZScaleContext::colorspace
int colorspace
Definition: vf_zscale.c:91
AVComponentDescriptor::depth
int depth
Number of bits in the component.
Definition: pixdesc.h:58
AV_PIX_FMT_YUVA420P10
#define AV_PIX_FMT_YUVA420P10
Definition: pixfmt.h:436
ZScaleContext::alpha_src_format
zimg_image_format alpha_src_format
Definition: vf_zscale.c:121
AVOption
AVOption.
Definition: opt.h:248
AVCOL_TRC_UNSPECIFIED
@ AVCOL_TRC_UNSPECIFIED
Definition: pixfmt.h:486
AVComponentDescriptor::step
int step
Number of elements between 2 horizontally consecutive pixels.
Definition: pixdesc.h:41
AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:399
AVCOL_PRI_JEDEC_P22
@ AVCOL_PRI_JEDEC_P22
Definition: pixfmt.h:475
format_init
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:464
AVCOL_SPC_RGB
@ AVCOL_SPC_RGB
order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB)
Definition: pixfmt.h:513
float.h
AVCOL_TRC_BT2020_12
@ AVCOL_TRC_BT2020_12
ITU-R BT2020 for 12-bit system.
Definition: pixfmt.h:499
AV_PIX_FMT_YUV440P
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:99
mathematics.h
filter
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce then the filter should push the output frames on the output link immediately As an exception to the previous rule if the input frame is enough to produce several output frames then the filter needs output only at least one per link The additional frames can be left buffered in the filter
Definition: filter_design.txt:228
AVDictionary
Definition: dict.c:30
zscale_options
static const AVOption zscale_options[]
Definition: vf_zscale.c:786
AVColorPrimaries
AVColorPrimaries
Chromaticity coordinates of the source primaries.
Definition: pixfmt.h:458
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:149
av_float2int
static av_always_inline uint32_t av_float2int(float f)
Reinterpret a float as a 32-bit integer.
Definition: intfloat.h:50
graph_build
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:481
video.h
AV_PIX_FMT_YUVA422P10
#define AV_PIX_FMT_YUVA422P10
Definition: pixfmt.h:437
ZScaleContext::h
int h
Definition: vf_zscale.c:88
AVCOL_SPC_BT2020_CL
@ AVCOL_SPC_BT2020_CL
ITU-R BT2020 constant luminance system.
Definition: pixfmt.h:524
ZScaleContext::out_chromal
enum AVChromaLocation in_chromal out_chromal
Definition: vf_zscale.c:129
ZScaleContext::primaries
int primaries
Definition: vf_zscale.c:93
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:31
ZScaleContext::in_h_chr_pos
int in_h_chr_pos
Definition: vf_zscale.c:112
formats.h
ZScaleContext::param_b
double param_b
Definition: vf_zscale.c:105
VAR_OUT_W
@ VAR_OUT_W
Definition: vf_zscale.c:67
AVFrame::chroma_location
enum AVChromaLocation chroma_location
Definition: frame.h:575
AVCOL_SPC_BT470BG
@ 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
AV_PIX_FMT_YUVA420P9
#define AV_PIX_FMT_YUVA420P9
Definition: pixfmt.h:433
convert_primaries
static int convert_primaries(enum AVColorPrimaries color_primaries)
Definition: vf_zscale.c:421
ZScaleContext::dst_format
zimg_image_format dst_format
Definition: vf_zscale.c:120
AV_PIX_FMT_GBRP14
#define AV_PIX_FMT_GBRP14
Definition: pixfmt.h:417
AVCOL_TRC_IEC61966_2_1
@ AVCOL_TRC_IEC61966_2_1
IEC 61966-2-1 (sRGB or sYCC)
Definition: pixfmt.h:497
AV_PIX_FMT_GBRAP
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:215
ZScaleContext::src_format
zimg_image_format src_format
Definition: vf_zscale.c:120
fail
#define fail()
Definition: checkasm.h:133
ZScaleContext::out_primaries
enum AVColorPrimaries in_primaries out_primaries
Definition: vf_zscale.c:127
AV_PIX_FMT_GBRP10
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:415
AV_PIX_FMT_YUVA444P16
#define AV_PIX_FMT_YUVA444P16
Definition: pixfmt.h:443
ZScaleContext::range
int range
Definition: vf_zscale.c:94
VAR_OW
@ VAR_OW
Definition: vf_zscale.c:67
AV_PIX_FMT_YUV422P9
#define AV_PIX_FMT_YUV422P9
Definition: pixfmt.h:397
AVCOL_TRC_GAMMA28
@ AVCOL_TRC_GAMMA28
also ITU-R BT470BG
Definition: pixfmt.h:489
convert_matrix
static int convert_matrix(enum AVColorSpace colorspace)
Definition: vf_zscale.c:351
query_formats
static int query_formats(AVFilterContext *ctx)
Definition: vf_zscale.c:166
ZScaleContext::alpha_params
zimg_graph_builder_params alpha_params
Definition: vf_zscale.c:122
av_opt_set
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
Definition: opt.c:465
AVCOL_TRC_LOG_SQRT
@ AVCOL_TRC_LOG_SQRT
"Logarithmic transfer characteristic (100 * Sqrt(10) : 1 range)"
Definition: pixfmt.h:494
av_reduce
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
AVRational::num
int num
Numerator.
Definition: rational.h:59
AVCOL_TRC_GAMMA22
@ AVCOL_TRC_GAMMA22
also ITU-R BT470M / ITU-R BT1700 625 PAL & SECAM
Definition: pixfmt.h:488
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:54
process_command
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
Definition: vf_zscale.c:758
VAR_SAR
@ VAR_SAR
Definition: vf_zscale.c:70
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:190
AV_PIX_FMT_YUV444P10
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:402
AV_PIX_FMT_YUVJ411P
@ 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
aligned
static int aligned(int val)
Definition: dashdec.c:168
avassert.h
AV_LOG_TRACE
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
Definition: log.h:220
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
ZScaleContext::alpha_graph
zimg_filter_graph * alpha_graph
Definition: vf_zscale.c:123
av_cold
#define av_cold
Definition: attributes.h:90
var_name
var_name
Definition: setts_bsf.c:50
AV_PIX_FMT_YUV422P16
#define AV_PIX_FMT_YUV422P16
Definition: pixfmt.h:411
AV_PIX_FMT_YUVJ422P
@ 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
ZScaleContext::param_a
double param_a
Definition: vf_zscale.c:104
intreadwrite.h
s
#define s(width, name)
Definition: cbs_vp9.c:257
AVCHROMA_LOC_TOP
@ AVCHROMA_LOC_TOP
Definition: pixfmt.h:610
ZScaleContext
Definition: vf_zscale.c:79
AV_PIX_FMT_YUVA420P
@ 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_YUV444P16
#define AV_PIX_FMT_YUV444P16
Definition: pixfmt.h:412
ZScaleContext::force_original_aspect_ratio
int force_original_aspect_ratio
Definition: vf_zscale.c:115
format
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample format(the sample packing is implied by the sample format) and sample rate. The lists are not just lists
AVCOL_SPC_SMPTE170M
@ AVCOL_SPC_SMPTE170M
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
Definition: pixfmt.h:519
AV_OPT_TYPE_DOUBLE
@ AV_OPT_TYPE_DOUBLE
Definition: opt.h:227
ff_formats_ref
int ff_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
Add *ref as a new reference to formats.
Definition: formats.c:466
outputs
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
AV_PIX_FMT_YUV420P9
#define AV_PIX_FMT_YUV420P9
Definition: pixfmt.h:396
realign_frame
static int realign_frame(const AVPixFmtDescriptor *desc, AVFrame **frame)
Definition: vf_zscale.c:509
AV_PIX_FMT_YUV420P16
#define AV_PIX_FMT_YUV420P16
Definition: pixfmt.h:410
AV_PIX_FMT_FLAG_ALPHA
#define AV_PIX_FMT_FLAG_ALPHA
The pixel format has an alpha channel.
Definition: pixdesc.h:179
ctx
AVFormatContext * ctx
Definition: movenc.c:48
AVCOL_PRI_SMPTE428
@ AVCOL_PRI_SMPTE428
SMPTE ST 428-1 (CIE 1931 XYZ)
Definition: pixfmt.h:470
AVPixFmtDescriptor::log2_chroma_w
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:92
VAR_A
@ VAR_A
Definition: vf_zscale.c:69
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66
AVCOL_PRI_SMPTE240M
@ AVCOL_PRI_SMPTE240M
functionally identical to above
Definition: pixfmt.h:467
color_range
color_range
Definition: vf_selectivecolor.c:44
AVCOL_PRI_UNSPECIFIED
@ AVCOL_PRI_UNSPECIFIED
Definition: pixfmt.h:461
NAN
#define NAN
Definition: mathematics.h:64
f
#define f(width, name)
Definition: cbs_vp9.c:255
link
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a link
Definition: filter_design.txt:23
AV_PIX_FMT_YUVJ444P
@ 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
AVCOL_SPC_CHROMA_DERIVED_CL
@ AVCOL_SPC_CHROMA_DERIVED_CL
Chromaticity-derived constant luminance system.
Definition: pixfmt.h:527
AVCOL_PRI_BT470BG
@ 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_SMPTE170M
@ AVCOL_PRI_SMPTE170M
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
Definition: pixfmt.h:466
if
if(ret)
Definition: filter_design.txt:179
AV_PIX_FMT_GBRP16
#define AV_PIX_FMT_GBRP16
Definition: pixfmt.h:418
opts
AVDictionary * opts
Definition: movenc.c:50
ZScaleContext::params
zimg_graph_builder_params params
Definition: vf_zscale.c:122
print_zimg_error
static int print_zimg_error(AVFilterContext *ctx)
Definition: vf_zscale.c:321
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:67
NULL
#define NULL
Definition: coverity.c:32
av_frame_copy_props
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:658
ZScaleContext::out_range
enum AVColorRange in_range out_range
Definition: vf_zscale.c:128
FLAGS
#define FLAGS
Definition: vf_zscale.c:783
AVCHROMA_LOC_LEFT
@ AVCHROMA_LOC_LEFT
MPEG-2/4 4:2:0, H.264 default for 4:2:0.
Definition: pixfmt.h:607
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
AVCHROMA_LOC_TOPLEFT
@ AVCHROMA_LOC_TOPLEFT
ITU-R 601, SMPTE 274M 296M S314M(DV 4:1:1), mpeg2 4:2:2.
Definition: pixfmt.h:609
AVCOL_TRC_IEC61966_2_4
@ AVCOL_TRC_IEC61966_2_4
IEC 61966-2-4.
Definition: pixfmt.h:495
AV_PIX_FMT_YUVJ420P
@ 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
AVFilterContext::inputs
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:349
AVComponentDescriptor::plane
int plane
Which of the 4 planes contains the component.
Definition: pixdesc.h:35
AVCOL_PRI_BT709
@ AVCOL_PRI_BT709
also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP177 Annex B
Definition: pixfmt.h:460
parseutils.h
ff_vf_zscale
AVFilter ff_vf_zscale
Definition: vf_zscale.c:930
convert_range
static int convert_range(enum AVColorRange color_range)
Definition: vf_zscale.c:452
ZScaleContext::out_v_chr_pos
int out_v_chr_pos
Definition: vf_zscale.c:111
AVCOL_TRC_BT2020_10
@ AVCOL_TRC_BT2020_10
ITU-R BT2020 for 10-bit system.
Definition: pixfmt.h:498
AVCOL_SPC_YCGCO
@ AVCOL_SPC_YCGCO
Used by Dirac / VC-2 and H.264 FRext, see ITU-T SG16.
Definition: pixfmt.h:521
ZScaleContext::dither
int dither
Definition: vf_zscale.c:89
AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:400
inputs
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several inputs
Definition: filter_design.txt:243
AV_PIX_FMT_GBRP9
#define AV_PIX_FMT_GBRP9
Definition: pixfmt.h:414
AVPixFmtDescriptor::flags
uint64_t flags
Combination of AV_PIX_FMT_FLAG_...
Definition: pixdesc.h:106
AVCOL_RANGE_UNSPECIFIED
@ AVCOL_RANGE_UNSPECIFIED
Definition: pixfmt.h:552
AVCOL_PRI_BT2020
@ AVCOL_PRI_BT2020
ITU-R BT2020.
Definition: pixfmt.h:469
AVCOL_TRC_SMPTE2084
@ AVCOL_TRC_SMPTE2084
SMPTE ST 2084 for 10-, 12-, 14- and 16-bit systems.
Definition: pixfmt.h:500
AVCOL_PRI_SMPTE431
@ AVCOL_PRI_SMPTE431
SMPTE ST 431-2 (2011) / DCI P3.
Definition: pixfmt.h:472
ZScaleContext::in_v_chr_pos
int in_v_chr_pos
Definition: vf_zscale.c:113
eval.h
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
av_expr_parse_and_eval
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:776
AVCOL_TRC_SMPTE240M
@ AVCOL_TRC_SMPTE240M
Definition: pixfmt.h:491
AVCOL_PRI_FILM
@ AVCOL_PRI_FILM
colour filters using Illuminant C
Definition: pixfmt.h:468
AV_WN32
#define AV_WN32(p, v)
Definition: intreadwrite.h:376
AV_PIX_FMT_FLAG_RGB
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
Definition: pixdesc.h:148
av_frame_copy
int av_frame_copy(AVFrame *dst, const AVFrame *src)
Copy the frame data from src to dst.
Definition: frame.c:799
AVCOL_TRC_LOG
@ AVCOL_TRC_LOG
"Logarithmic transfer characteristic (100:1 range)"
Definition: pixfmt.h:493
FFMAX
#define FFMAX(a, b)
Definition: common.h:103
AV_PIX_FMT_GBRPF32
#define AV_PIX_FMT_GBRPF32
Definition: pixfmt.h:428
AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:404
size
int size
Definition: twinvq_data.h:10344
ZScaleContext::primaries_in
int primaries_in
Definition: vf_zscale.c:98
ZScaleContext::approximate_gamma
int approximate_gamma
Definition: vf_zscale.c:103
ZScaleContext::alpha_dst_format
zimg_image_format alpha_dst_format
Definition: vf_zscale.c:121
VAR_OHSUB
@ VAR_OHSUB
Definition: vf_zscale.c:74
AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:406
ZScaleContext::graph
zimg_filter_graph * graph
Definition: vf_zscale.c:123
AVCHROMA_LOC_UNSPECIFIED
@ AVCHROMA_LOC_UNSPECIFIED
Definition: pixfmt.h:606
AVFrame::format
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition: frame.h:391
VAR_IN_W
@ VAR_IN_W
Definition: vf_zscale.c:65
avfilter_vf_zscale_outputs
static const AVFilterPad avfilter_vf_zscale_outputs[]
Definition: vf_zscale.c:921
FFMIN
#define FFMIN(a, b)
Definition: common.h:105
AV_PIX_FMT_YUVA444P
@ 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_YUVA444P10
#define AV_PIX_FMT_YUVA444P10
Definition: pixfmt.h:438
AVERROR_EXTERNAL
#define AVERROR_EXTERNAL
Generic error in an external library.
Definition: error.h:57
av_parse_video_size
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
VARS_NB
@ VARS_NB
Definition: vf_zscale.c:76
AVCOL_SPC_CHROMA_DERIVED_NCL
@ AVCOL_SPC_CHROMA_DERIVED_NCL
Chromaticity-derived non-constant luminance system.
Definition: pixfmt.h:526
VAR_HSUB
@ VAR_HSUB
Definition: vf_zscale.c:72
AVCOL_TRC_BT709
@ AVCOL_TRC_BT709
also ITU-R BT1361
Definition: pixfmt.h:485
internal.h
AVChromaLocation
AVChromaLocation
Location of chroma samples.
Definition: pixfmt.h:605
AVCOL_SPC_SMPTE240M
@ AVCOL_SPC_SMPTE240M
functionally identical to above
Definition: pixfmt.h:520
in
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
Definition: audio_convert.c:326
AVCOL_SPC_BT2020_NCL
@ AVCOL_SPC_BT2020_NCL
ITU-R BT2020 non-constant luminance system.
Definition: pixfmt.h:523
filter_frame
static int filter_frame(AVFilterLink *link, AVFrame *in)
Definition: vf_zscale.c:547
internal.h
init_dict
static av_cold int init_dict(AVFilterContext *ctx, AVDictionary **opts)
Definition: vf_zscale.c:132
AV_PIX_FMT_GBRP12
#define AV_PIX_FMT_GBRP12
Definition: pixfmt.h:416
AVColorSpace
AVColorSpace
YUV colorspace type.
Definition: pixfmt.h:512
ZScaleContext::tmp_size
size_t tmp_size
Definition: vf_zscale.c:118
ZScaleContext::out_colorspace
enum AVColorSpace in_colorspace out_colorspace
Definition: vf_zscale.c:125
VAR_IW
@ VAR_IW
Definition: vf_zscale.c:65
ZScaleContext::w
int w
New dimensions.
Definition: vf_zscale.c:88
ZScaleContext::trc
int trc
Definition: vf_zscale.c:92
AV_PIX_FMT_YUVJ440P
@ 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
VAR_OH
@ VAR_OH
Definition: vf_zscale.c:68
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:60
AVCOL_SPC_UNSPECIFIED
@ AVCOL_SPC_UNSPECIFIED
Definition: pixfmt.h:515
av_rescale
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
ZScaleContext::chromal_in
int chromal_in
Definition: vf_zscale.c:100
AVCOL_RANGE_MPEG
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition: pixfmt.h:569
AV_PIX_FMT_YUV444P9
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:398
AVFilter
Filter definition.
Definition: avfilter.h:145
VAR_IH
@ VAR_IH
Definition: vf_zscale.c:66
AVCOL_PRI_BT470M
@ AVCOL_PRI_BT470M
also FCC Title 47 Code of Federal Regulations 73.682 (a)(20)
Definition: pixfmt.h:463
ret
ret
Definition: filter_design.txt:187
ZScaleContext::trc_in
int trc_in
Definition: vf_zscale.c:97
ZScaleContext::size_str
char * size_str
Definition: vf_zscale.c:101
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
AV_PIX_FMT_YUVA444P9
#define AV_PIX_FMT_YUVA444P9
Definition: pixfmt.h:435
convert_chroma_location
static int convert_chroma_location(enum AVChromaLocation chroma_location)
Definition: vf_zscale.c:331
AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:403
AV_PIX_FMT_YUV422P14
#define AV_PIX_FMT_YUV422P14
Definition: pixfmt.h:408
AVFrame::height
int height
Definition: frame.h:376
AVCOL_TRC_ARIB_STD_B67
@ AVCOL_TRC_ARIB_STD_B67
ARIB STD-B67, known as "Hybrid log-gamma".
Definition: pixfmt.h:504
AVCHROMA_LOC_CENTER
@ AVCHROMA_LOC_CENTER
MPEG-1 4:2:0, JPEG 4:2:0, H.263 4:2:0.
Definition: pixfmt.h:608
AVRational::den
int den
Denominator.
Definition: rational.h:60
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
AVCOL_SPC_FCC
@ AVCOL_SPC_FCC
FCC Title 47 Code of Federal Regulations 73.682 (a)(20)
Definition: pixfmt.h:517
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:225
avfilter.h
AV_PIX_FMT_GBRAPF32
#define AV_PIX_FMT_GBRAPF32
Definition: pixfmt.h:429
VAR_IN_H
@ VAR_IN_H
Definition: vf_zscale.c:66
VAR_OVSUB
@ VAR_OVSUB
Definition: vf_zscale.c:75
AVPixFmtDescriptor::comp
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:117
AVCOL_TRC_SMPTE170M
@ 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
av_mul_q
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
Definition: rational.c:80
OFFSET
#define OFFSET(x)
Definition: vf_zscale.c:782
AV_PIX_FMT_YUV444P
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:71
AVFilterContext
An instance of a filter.
Definition: avfilter.h:341
AV_PIX_FMT_GBRP
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:168
desc
const char * desc
Definition: libsvtav1.c:79
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AV_PIX_FMT_YUV422P
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:70
convert_trc
static int convert_trc(enum AVColorTransferCharacteristic color_trc)
Definition: vf_zscale.c:384
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
AVCOL_PRI_SMPTE432
@ AVCOL_PRI_SMPTE432
SMPTE ST 432-1 (2010) / P3 D65 / Display P3.
Definition: pixfmt.h:473
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:242
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
AV_PIX_FMT_YUV411P
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:73
VAR_DAR
@ VAR_DAR
Definition: vf_zscale.c:71
imgutils.h
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:561
AV_PIX_FMT_YUV410P
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:72
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(zscale)
ZScaleContext::nominal_peak_luminance
double nominal_peak_luminance
Definition: vf_zscale.c:102
ZScaleContext::out_trc
enum AVColorTransferCharacteristic in_trc out_trc
Definition: vf_zscale.c:126
h
h
Definition: vp9dsp_template.c:2038
AV_PIX_FMT_YUV444P14
#define AV_PIX_FMT_YUV444P14
Definition: pixfmt.h:409
avstring.h
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Definition: opt.h:229
AVCOL_SPC_BT709
@ AVCOL_SPC_BT709
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / SMPTE RP177 Annex B
Definition: pixfmt.h:514
AVColorRange
AVColorRange
Visual content value range.
Definition: pixfmt.h:551
int
int
Definition: ffmpeg_filter.c:170
AVCOL_SPC_ICTCP
@ AVCOL_SPC_ICTCP
ITU-R BT.2100-0, ICtCp.
Definition: pixfmt.h:528
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:234
snprintf
#define snprintf
Definition: snprintf.h:34
VAR_OUT_H
@ VAR_OUT_H
Definition: vf_zscale.c:68
color_primaries
static const struct ColorPrimaries color_primaries[AVCOL_PRI_NB]
Definition: vf_colorspace.c:211
ZScaleContext::out_h_chr_pos
int out_h_chr_pos
Definition: vf_zscale.c:110
AVCHROMA_LOC_BOTTOMLEFT
@ AVCHROMA_LOC_BOTTOMLEFT
Definition: pixfmt.h:611
AVPixFmtDescriptor::log2_chroma_h
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:101
ZScaleContext::tmp
void * tmp
Definition: vf_zscale.c:117
AV_PIX_FMT_YUVA422P
@ 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_YUV420P14
#define AV_PIX_FMT_YUV420P14
Definition: pixfmt.h:407
av_get_pix_fmt_name
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
Definition: pixdesc.c:2489
ZScaleContext::w_expr
char * w_expr
width expression string
Definition: vf_zscale.c:107
avfilter_vf_zscale_inputs
static const AVFilterPad avfilter_vf_zscale_inputs[]
Definition: vf_zscale.c:912
dither
static const uint8_t dither[8][8]
Definition: vf_fspp.c:59