FFmpeg
Loading...
Searching...
No Matches
vf_zscale.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015 Paul B Mahol
3 * Copyright (c) 2022 Victoria Zhislina, Intel
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22/**
23 * @file
24 * zscale video filter using z.lib library
25 */
26
27#include <float.h>
28#include <stdio.h>
29#include <string.h>
30
31#include <zimg.h>
32
33#include "avfilter.h"
34#include "filters.h"
35#include "formats.h"
36#include "video.h"
37#include "libavutil/eval.h"
38#include "libavutil/internal.h"
39#include "libavutil/intfloat.h"
42#include "libavutil/mem.h"
43#include "libavutil/opt.h"
45#include "libavutil/pixdesc.h"
46
47#define ZIMG_ALIGNMENT 64
48#define MIN_TILESIZE 64
49#define MAX_THREADS 64
50
51static const char *const var_names[] = {
52 "in_w", "iw",
53 "in_h", "ih",
54 "out_w", "ow",
55 "out_h", "oh",
56 "a",
57 "sar",
58 "dar",
59 "hsub",
60 "vsub",
61 "ohsub",
62 "ovsub",
63 NULL
64};
65
80
81typedef struct ZScaleContext {
82 const AVClass *class;
83
84 /**
85 * New dimensions. Special values are:
86 * 0 = original width/height
87 * -1 = keep original aspect
88 * -N = try to keep aspect but make sure it is divisible by N
89 */
90 int w, h;
91 int dither;
92 int filter;
94 int trc;
96 int range;
99 int trc_in;
103 char *size_str;
106 double param_a;
107 double param_b;
108
109 char *w_expr; ///< width expression string
110 char *h_expr; ///< height expression string
111
114
115 void *tmp[MAX_THREADS]; //separate for each thread;
122
123 zimg_image_format src_format, dst_format;
124 zimg_image_format src_format_tmp, dst_format_tmp;
125 zimg_graph_builder_params params;
126 zimg_graph_builder_params params_tmp;
127 zimg_filter_graph *graph[MAX_THREADS];
129
130typedef struct ThreadData {
132 AVFrame *in, *out;
133} ThreadData;
134
136{
137 ZScaleContext *s = ctx->priv;
138 int ret;
139 zimg_image_format_default(&s->src_format, ZIMG_API_VERSION);
140 zimg_image_format_default(&s->dst_format, ZIMG_API_VERSION);
141 zimg_image_format_default(&s->src_format_tmp, ZIMG_API_VERSION);
142 zimg_image_format_default(&s->dst_format_tmp, ZIMG_API_VERSION);
143
144 zimg_graph_builder_params_default(&s->params, ZIMG_API_VERSION);
145 zimg_graph_builder_params_default(&s->params_tmp, ZIMG_API_VERSION);
146
147 if (s->size_str && (s->w_expr || s->h_expr)) {
149 "Size and width/height expressions cannot be set at the same time.\n");
150 return AVERROR(EINVAL);
151 }
152
153 if (s->w_expr && !s->h_expr)
154 FFSWAP(char *, s->w_expr, s->size_str);
155
156 if (s->size_str) {
157 char buf[32];
158 if ((ret = av_parse_video_size(&s->w, &s->h, s->size_str)) < 0) {
160 "Invalid size '%s'\n", s->size_str);
161 return ret;
162 }
163 snprintf(buf, sizeof(buf)-1, "%d", s->w);
164 av_opt_set(s, "w", buf, 0);
165 snprintf(buf, sizeof(buf)-1, "%d", s->h);
166 av_opt_set(s, "h", buf, 0);
167 }
168 if (!s->w_expr)
169 av_opt_set(s, "w", "iw", 0);
170 if (!s->h_expr)
171 av_opt_set(s, "h", "ih", 0);
172
173 return 0;
174}
175
176static enum AVColorRange convert_range_from_zimg(enum zimg_pixel_range_e color_range);
177
179 AVFilterFormatsConfig **cfg_in,
180 AVFilterFormatsConfig **cfg_out)
181{
182 const ZScaleContext *s = ctx->priv;
184 static const enum AVPixelFormat pixel_fmts[] = {
208 };
209 int ret;
210
212 if (ret < 0)
213 return ret;
215 if (ret < 0)
216 return ret;
217
218 if ((ret = ff_formats_ref(ff_all_color_spaces(), &cfg_in[0]->color_spaces)) < 0 ||
219 (ret = ff_formats_ref(ff_all_color_ranges(), &cfg_in[0]->color_ranges)) < 0)
220 return ret;
221
222 formats = s->colorspace != ZIMG_MATRIX_UNSPECIFIED && s->colorspace > 0
223 ? ff_make_formats_list_singleton(s->colorspace)
225 if ((ret = ff_formats_ref(formats, &cfg_out[0]->color_spaces)) < 0)
226 return ret;
227
228 formats = s->range != -1
231 if ((ret = ff_formats_ref(formats, &cfg_out[0]->color_ranges)) < 0)
232 return ret;
233
234 if ((ret = ff_formats_ref(ff_all_chroma_locations(), &cfg_in[0]->chroma_locations)) < 0)
235 return ret;
236
237 formats = s->chromal != -1
238 ? ff_make_formats_list_singleton(s->chromal + 1)
240 if ((ret = ff_formats_ref(formats, &cfg_out[0]->chroma_locations)) < 0)
241 return ret;
242
243 if ((ret = ff_formats_ref(ff_all_alpha_modes(), &cfg_in[0]->alpha_modes)) < 0 ||
244 (ret = ff_formats_ref(ff_all_alpha_modes(), &cfg_out[0]->alpha_modes)) < 0)
245 return ret;
246
247 return 0;
248}
249
250static void slice_params(ZScaleContext *s, int out_h, int in_h)
251{
252 s->out_slice_start[0] = 0;
253 for (int i = 1; i < s->nb_threads; i++) {
254 int slice_end = out_h * i / s->nb_threads;
255 s->out_slice_end[i - 1] = s->out_slice_start[i] = FFALIGN(slice_end, 2);
256 }
257 s->out_slice_end[s->nb_threads - 1] = out_h;
258
259 for (int i = 0; i < s->nb_threads; i++) {
260 s->in_slice_start[i] = s->out_slice_start[i] * in_h / (double)out_h;
261 s->in_slice_end[i] = s->out_slice_end[i] * in_h / (double)out_h;
262 }
263}
264
265static int config_props(AVFilterLink *outlink)
266{
267 AVFilterContext *ctx = outlink->src;
268 AVFilterLink *inlink = outlink->src->inputs[0];
269 ZScaleContext *s = ctx->priv;
271 const AVPixFmtDescriptor *out_desc = av_pix_fmt_desc_get(outlink->format);
272 int64_t w, h;
273 double var_values[VARS_NB], res;
274 char *expr;
275 int ret;
276 int64_t factor_w, factor_h;
277
278 var_values[VAR_IN_W] = var_values[VAR_IW] = inlink->w;
279 var_values[VAR_IN_H] = var_values[VAR_IH] = inlink->h;
280 var_values[VAR_OUT_W] = var_values[VAR_OW] = NAN;
281 var_values[VAR_OUT_H] = var_values[VAR_OH] = NAN;
282 var_values[VAR_A] = (double) inlink->w / inlink->h;
283 var_values[VAR_SAR] = inlink->sample_aspect_ratio.num ?
284 (double) inlink->sample_aspect_ratio.num / inlink->sample_aspect_ratio.den : 1;
285 var_values[VAR_DAR] = var_values[VAR_A] * var_values[VAR_SAR];
286 var_values[VAR_HSUB] = 1 << desc->log2_chroma_w;
287 var_values[VAR_VSUB] = 1 << desc->log2_chroma_h;
288 var_values[VAR_OHSUB] = 1 << out_desc->log2_chroma_w;
289 var_values[VAR_OVSUB] = 1 << out_desc->log2_chroma_h;
290
291 /* evaluate width and height */
292 av_expr_parse_and_eval(&res, (expr = s->w_expr),
293 var_names, var_values,
294 NULL, NULL, NULL, NULL, NULL, 0, ctx);
295 var_values[VAR_OUT_W] = var_values[VAR_OW] = trunc(res);
296 if ((ret = av_expr_parse_and_eval(&res, (expr = s->h_expr),
297 var_names, var_values,
298 NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0)
299 goto fail;
300 if (!(res >= INT32_MIN && res <= INT32_MAX)) {
301 ret = AVERROR(EINVAL);
302 goto fail;
303 }
304
305 s->h = var_values[VAR_OUT_H] = var_values[VAR_OH] = res;
306 /* evaluate again the width, as it may depend on the output height */
307 if ((ret = av_expr_parse_and_eval(&res, (expr = s->w_expr),
308 var_names, var_values,
309 NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0)
310 goto fail;
311 if (!(res >= INT32_MIN && res <= INT32_MAX)) {
312 ret = AVERROR(EINVAL);
313 goto fail;
314 }
315 s->w = res;
316
317 w = s->w;
318 h = s->h;
319
320 /* Check if it is requested that the result has to be divisible by a some
321 * factor (w or h = -n with n being the factor). */
322 factor_w = 1;
323 factor_h = 1;
324 if (w < -1) {
325 factor_w = -w;
326 }
327 if (h < -1) {
328 factor_h = -h;
329 }
330
331 if (w < 0 && h < 0)
332 s->w = s->h = 0;
333
334 if (!(w = s->w))
335 w = inlink->w;
336 if (!(h = s->h))
337 h = inlink->h;
338
339 /* Make sure that the result is divisible by the factor we determined
340 * earlier. If no factor was set, it is nothing will happen as the default
341 * factor is 1 */
342 if (w < 0)
343 w = av_rescale(h, inlink->w, inlink->h * factor_w) * factor_w;
344 if (h < 0)
345 h = av_rescale(w, inlink->h, inlink->w * factor_h) * factor_h;
346
347 /* Note that force_original_aspect_ratio may overwrite the previous set
348 * dimensions so that it is not divisible by the set factors anymore. */
349 if (s->force_original_aspect_ratio) {
350 int tmp_w = av_rescale(h, inlink->w, inlink->h);
351 int tmp_h = av_rescale(w, inlink->h, inlink->w);
352
353 if (s->force_original_aspect_ratio == 1) {
354 w = FFMIN(tmp_w, w);
355 h = FFMIN(tmp_h, h);
356 } else {
357 w = FFMAX(tmp_w, w);
358 h = FFMAX(tmp_h, h);
359 }
360 }
361
362 if (w > INT_MAX || h > INT_MAX ||
363 (h * inlink->w) > INT_MAX ||
364 (w * inlink->h) > INT_MAX)
365 av_log(ctx, AV_LOG_ERROR, "Rescaled value for width or height is too big.\n");
366
367 outlink->w = w;
368 outlink->h = h;
369
370 s->first_time = 1;
371
372 if (inlink->sample_aspect_ratio.num){
373 outlink->sample_aspect_ratio = av_mul_q((AVRational){outlink->h * inlink->w, outlink->w * inlink->h}, inlink->sample_aspect_ratio);
374 } else
375 outlink->sample_aspect_ratio = inlink->sample_aspect_ratio;
376
377 av_log(ctx, AV_LOG_DEBUG, "w:%d h:%d fmt:%s csp:%s range:%s sar:%d/%d -> w:%d h:%d fmt:%s csp:%s range:%s sar:%d/%d\n",
378 inlink ->w, inlink ->h, av_get_pix_fmt_name( inlink->format),
381 outlink->w, outlink->h, av_get_pix_fmt_name(outlink->format),
384 return 0;
385
386fail:
388 "Error when evaluating the expression '%s'.\n"
389 "Maybe the expression for out_w:'%s' or for out_h:'%s' is self-referencing.\n",
390 expr, s->w_expr, s->h_expr);
391 return ret;
392}
393
395{
396 char err_msg[1024];
397 int err_code = zimg_get_last_error(err_msg, sizeof(err_msg));
398
399 av_log(ctx, AV_LOG_ERROR, "code %d: %s\n", err_code, err_msg);
400
401 return AVERROR_EXTERNAL;
402}
403
404static int convert_chroma_location(enum AVChromaLocation chroma_location)
405{
406 switch (chroma_location) {
409 return ZIMG_CHROMA_LEFT;
411 return ZIMG_CHROMA_CENTER;
413 return ZIMG_CHROMA_TOP_LEFT;
414 case AVCHROMA_LOC_TOP:
415 return ZIMG_CHROMA_TOP;
417 return ZIMG_CHROMA_BOTTOM_LEFT;
419 return ZIMG_CHROMA_BOTTOM;
420 }
421 return ZIMG_CHROMA_LEFT;
422}
423
424static int convert_matrix(enum AVColorSpace colorspace)
425{
426 switch (colorspace) {
427 case AVCOL_SPC_RGB:
428 return ZIMG_MATRIX_RGB;
429 case AVCOL_SPC_BT709:
430 return ZIMG_MATRIX_709;
432 return ZIMG_MATRIX_UNSPECIFIED;
433 case AVCOL_SPC_FCC:
434 return ZIMG_MATRIX_FCC;
436 return ZIMG_MATRIX_470BG;
438 return ZIMG_MATRIX_170M;
440 return ZIMG_MATRIX_240M;
441 case AVCOL_SPC_YCGCO:
442 return ZIMG_MATRIX_YCGCO;
444 return ZIMG_MATRIX_2020_NCL;
446 return ZIMG_MATRIX_2020_CL;
448 return ZIMG_MATRIX_CHROMATICITY_DERIVED_NCL;
450 return ZIMG_MATRIX_CHROMATICITY_DERIVED_CL;
451 case AVCOL_SPC_ICTCP:
452 return ZIMG_MATRIX_ICTCP;
453 }
454 return ZIMG_MATRIX_UNSPECIFIED;
455}
456
458{
459 switch (color_trc) {
461 return ZIMG_TRANSFER_UNSPECIFIED;
462 case AVCOL_TRC_BT709:
463 return ZIMG_TRANSFER_709;
465 return ZIMG_TRANSFER_470_M;
467 return ZIMG_TRANSFER_470_BG;
469 return ZIMG_TRANSFER_601;
471 return ZIMG_TRANSFER_240M;
472 case AVCOL_TRC_LINEAR:
473 return ZIMG_TRANSFER_LINEAR;
474 case AVCOL_TRC_LOG:
475 return ZIMG_TRANSFER_LOG_100;
477 return ZIMG_TRANSFER_LOG_316;
479 return ZIMG_TRANSFER_IEC_61966_2_4;
481 return ZIMG_TRANSFER_2020_10;
483 return ZIMG_TRANSFER_2020_12;
485 return ZIMG_TRANSFER_ST2084;
487 return ZIMG_TRANSFER_ARIB_B67;
489 return ZIMG_TRANSFER_IEC_61966_2_1;
490 }
491 return ZIMG_TRANSFER_UNSPECIFIED;
492}
493
495{
496 switch (color_primaries) {
498 return ZIMG_PRIMARIES_UNSPECIFIED;
499 case AVCOL_PRI_BT709:
500 return ZIMG_PRIMARIES_709;
501 case AVCOL_PRI_BT470M:
502 return ZIMG_PRIMARIES_470_M;
504 return ZIMG_PRIMARIES_470_BG;
506 return ZIMG_PRIMARIES_170M;
508 return ZIMG_PRIMARIES_240M;
509 case AVCOL_PRI_FILM:
510 return ZIMG_PRIMARIES_FILM;
511 case AVCOL_PRI_BT2020:
512 return ZIMG_PRIMARIES_2020;
514 return ZIMG_PRIMARIES_ST428;
516 return ZIMG_PRIMARIES_ST431_2;
518 return ZIMG_PRIMARIES_ST432_1;
520 return ZIMG_PRIMARIES_EBU3213_E;
521 }
522 return ZIMG_PRIMARIES_UNSPECIFIED;
523}
524
526{
527 switch (color_range) {
529 case AVCOL_RANGE_MPEG:
530 return ZIMG_RANGE_LIMITED;
531 case AVCOL_RANGE_JPEG:
532 return ZIMG_RANGE_FULL;
533 }
534 return ZIMG_RANGE_LIMITED;
535}
536
537static enum AVColorRange convert_range_from_zimg(enum zimg_pixel_range_e color_range)
538{
539 switch (color_range) {
540 case ZIMG_RANGE_LIMITED:
541 return AVCOL_RANGE_MPEG;
542 case ZIMG_RANGE_FULL:
543 return AVCOL_RANGE_JPEG;
544 }
546}
547
548/* returns 0 if image formats are the same and 1 otherwise */
549static int compare_zimg_image_formats(zimg_image_format *img_fmt0, zimg_image_format *img_fmt1)
550{
551 return ((img_fmt0->chroma_location != img_fmt1->chroma_location) ||
552#if ZIMG_API_VERSION >= 0x204
553 (img_fmt0->alpha != img_fmt1->alpha) ||
554#endif
555 (img_fmt0->color_family != img_fmt1->color_family) ||
556 (img_fmt0->color_primaries != img_fmt1->color_primaries) ||
557 (img_fmt0->depth != img_fmt1->depth) ||
558 (img_fmt0->field_parity != img_fmt1->field_parity) ||
559 (img_fmt0->height != img_fmt1->height) ||
560 (img_fmt0->matrix_coefficients != img_fmt1->matrix_coefficients) ||
561 (img_fmt0->pixel_range != img_fmt1->pixel_range) ||
562 (img_fmt0->pixel_type != img_fmt1->pixel_type) ||
563 (img_fmt0->subsample_h != img_fmt1->subsample_h) ||
564 (img_fmt0->subsample_w != img_fmt1->subsample_w) ||
565 (img_fmt0->transfer_characteristics != img_fmt1->transfer_characteristics) ||
566 (img_fmt0->width != img_fmt1->width));
567}
568
569/* returns 0 if graph builder parameters are the same and 1 otherwise */
570static int compare_zimg_graph_builder_params(zimg_graph_builder_params *parm0, zimg_graph_builder_params *parm1)
571{
572 /* the parameters that could be changed inside a single ffmpeg zscale invocation are checked only
573 and NaN values that are default for some params are treated properly*/
574 int ret = (parm0->allow_approximate_gamma != parm1->allow_approximate_gamma) ||
575 (parm0->dither_type != parm1->dither_type) ||
576 (parm0->resample_filter != parm1->resample_filter) ||
577 (parm0->resample_filter_uv != parm1->resample_filter_uv);
578
579 if ((isnan(parm0->nominal_peak_luminance) == 0) || (isnan(parm1->nominal_peak_luminance) == 0))
580 ret = ret || (parm0->nominal_peak_luminance != parm1->nominal_peak_luminance);
581 if ((isnan(parm0->filter_param_a) == 0) || (isnan(parm1->filter_param_a) == 0))
582 ret = ret || (parm0->filter_param_a != parm1->filter_param_a);
583 if ((isnan(parm0->filter_param_a_uv) == 0) || (isnan(parm1->filter_param_a_uv) == 0))
584 ret = ret || (parm0->filter_param_a_uv != parm1->filter_param_a_uv);
585 if ((isnan(parm0->filter_param_b) == 0) || (isnan(parm1->filter_param_b) == 0))
586 ret = ret || (parm0->filter_param_b != parm1->filter_param_b);
587 if ((isnan(parm0->filter_param_b_uv) == 0) || (isnan(parm1->filter_param_b_uv) == 0))
588 ret = ret || (parm0->filter_param_b_uv != parm1->filter_param_b_uv);
589
590 return ret;
591}
592
593static void format_init(zimg_image_format *format, AVFrame *frame, const AVPixFmtDescriptor *desc,
594 int colorspace, int primaries, int transfer, int range, int location)
595{
596 format->width = frame->width;
597 format->height = frame->height;
598 format->subsample_w = desc->log2_chroma_w;
599 format->subsample_h = desc->log2_chroma_h;
600 format->depth = desc->comp[0].depth;
601 format->pixel_type = (desc->flags & AV_PIX_FMT_FLAG_FLOAT) ? (desc->comp[0].depth > 16 ? ZIMG_PIXEL_FLOAT : ZIMG_PIXEL_HALF)
602 : (desc->comp[0].depth > 8 ? ZIMG_PIXEL_WORD : ZIMG_PIXEL_BYTE);
603 format->color_family = (desc->flags & AV_PIX_FMT_FLAG_RGB) ? ZIMG_COLOR_RGB
604 : (desc->nb_components > 1 ? ZIMG_COLOR_YUV : ZIMG_COLOR_GREY);
605 format->matrix_coefficients = (desc->flags & AV_PIX_FMT_FLAG_RGB) ? ZIMG_MATRIX_RGB : colorspace == -1 ? convert_matrix(frame->colorspace) : colorspace;
606 format->color_primaries = primaries == -1 ? convert_primaries(frame->color_primaries) : primaries;
607 format->transfer_characteristics = transfer == -1 ? convert_trc(frame->color_trc) : transfer;
608 format->pixel_range = (desc->flags & AV_PIX_FMT_FLAG_RGB) ? ZIMG_RANGE_FULL : range == -1 ? convert_range(frame->color_range) : range;
609 format->chroma_location = location == -1 ? convert_chroma_location(frame->chroma_location) : location;
610 if (desc->flags & AV_PIX_FMT_FLAG_ALPHA)
611 format->alpha = frame->alpha_mode == AVALPHA_MODE_PREMULTIPLIED ? ZIMG_ALPHA_PREMULTIPLIED : ZIMG_ALPHA_STRAIGHT;
612}
613
614static int graphs_build(AVFrame *in, AVFrame *out, const AVPixFmtDescriptor *desc, const AVPixFmtDescriptor *out_desc,
615 AVFilterContext *ctx, int job_nr, int n_jobs)
616{
617 ZScaleContext *s = ctx->priv;
618 int ret;
619 size_t size;
620 zimg_image_format src_format;
621 zimg_image_format dst_format;
622 const double in_slice_start = s->in_slice_start[job_nr];
623 const double in_slice_end = s->in_slice_end[job_nr];
624 const int out_slice_start = s->out_slice_start[job_nr];
625 const int out_slice_end = s->out_slice_end[job_nr];
626
627 src_format = s->src_format;
628 dst_format = s->dst_format;
629 /* The input slice is specified through the active_region field,
630 unlike the output slice.
631 according to zimg requirements input and output slices should have even dimensions */
632 src_format.active_region.width = in->width;
633 src_format.active_region.height = in_slice_end - in_slice_start;
634 src_format.active_region.left = 0;
635 src_format.active_region.top = in_slice_start;
636 //dst now is the single tile only!!
637 dst_format.width = out->width;
638 dst_format.height = out_slice_end - out_slice_start;
639
640 if (s->graph[job_nr]) {
641 zimg_filter_graph_free(s->graph[job_nr]);
642 }
643 s->graph[job_nr] = zimg_filter_graph_build(&src_format, &dst_format, &s->params);
644 if (!s->graph[job_nr])
645 return print_zimg_error(ctx);
646
647 ret = zimg_filter_graph_get_tmp_size(s->graph[job_nr], &size);
648 if (ret)
649 return print_zimg_error(ctx);
650
651 if (size > (SIZE_MAX - ZIMG_ALIGNMENT))
652 return AVERROR(ENOMEM);
653
654 if (s->tmp[job_nr])
655 av_freep(&s->tmp[job_nr]);
656 s->tmp[job_nr] = av_mallocz(size + ZIMG_ALIGNMENT);
657 if (!s->tmp[job_nr])
658 return AVERROR(ENOMEM);
659
660 return 0;
661}
662
664{
666 int ret = 0, plane, planes;
667
668 /* Realign any unaligned input frame. */
669 planes = av_pix_fmt_count_planes((*frame)->format);
670 for (plane = 0; plane < planes; plane++) {
671 int p = desc->comp[plane].plane;
672 if ((uintptr_t)(*frame)->data[p] % ZIMG_ALIGNMENT || (*frame)->linesize[p] % ZIMG_ALIGNMENT) {
673 aligned = ff_default_get_video_buffer2(link, (*frame)->width, (*frame)->height, ZIMG_ALIGNMENT);
674 if (!aligned)
675 return AVERROR(ENOMEM);
676
677 if ((ret = av_frame_copy(aligned, *frame)) < 0)
678 goto fail;
679
680 if ((ret = av_frame_copy_props(aligned, *frame)) < 0)
681 goto fail;
682
684 *frame = aligned;
685 return 0;
686 }
687 }
688
689fail:
691 return ret;
692}
693
695{
696 if (s->primaries != -1)
697 frame->color_primaries = (int)s->dst_format.color_primaries;
698
699 if (s->trc != -1)
700 frame->color_trc = (int)s->dst_format.transfer_characteristics;
701
702 if (s->chromal != -1)
703 frame->chroma_location = (int)s->dst_format.chroma_location + 1;
704}
705
706static int filter_slice(AVFilterContext *ctx, void *data, int job_nr, int n_jobs)
707{
708 ThreadData *td = data;
709 int ret = 0;
710 int p;
711 int need_gb;
712 ZScaleContext *s = ctx->priv;
713 zimg_image_buffer_const src_buf = { ZIMG_API_VERSION };
714 zimg_image_buffer dst_buf = { ZIMG_API_VERSION };
715 const int out_slice_start = s->out_slice_start[job_nr];
716
717 /* create zimg filter graphs for each thread
718 only if not created earlier or there is some change in frame parameters */
719 need_gb = compare_zimg_image_formats(&s->src_format, &s->src_format_tmp) ||
720 compare_zimg_image_formats(&s->dst_format, &s->dst_format_tmp) ||
721 compare_zimg_graph_builder_params(&s->params, &s->params_tmp);
722
723 if (need_gb){
724 ret = graphs_build(td->in, td->out, td->desc, td->odesc, ctx, job_nr, n_jobs);
725 if (ret < 0)
726 return print_zimg_error(ctx);
727 }
728 for (int i = 0; i < 4; i++) {
729 const int vsamp = i >= 1 ? td->odesc->log2_chroma_h : 0;
730
731 p = td->desc->comp[i].plane;
732
733 if (i < td->desc->nb_components) {
734 src_buf.plane[i].data = td->in->data[p];
735 src_buf.plane[i].stride = td->in->linesize[p];
736 src_buf.plane[i].mask = -1;
737 }
738
739 p = td->odesc->comp[i].plane;
740 if (i < td->odesc->nb_components) {
741 dst_buf.plane[i].data = td->out->data[p] + td->out->linesize[p] * (out_slice_start >> vsamp);
742 dst_buf.plane[i].stride = td->out->linesize[p];
743 dst_buf.plane[i].mask = -1;
744 }
745 }
746 if (!s->graph[job_nr])
747 return AVERROR(EINVAL);
748 ret = zimg_filter_graph_process(s->graph[job_nr], &src_buf, &dst_buf,
749 (uint8_t *)FFALIGN((uintptr_t)s->tmp[job_nr], ZIMG_ALIGNMENT),
750 0, 0, 0, 0);
751 if (ret)
752 return print_zimg_error(ctx);
753
754 return 0;
755}
756
757static int filter_frame(AVFilterLink *link, AVFrame *in)
758{
759 AVFilterContext *ctx = link->dst;
760 ZScaleContext *s = ctx->priv;
761 AVFilterLink *outlink = ctx->outputs[0];
763 const AVPixFmtDescriptor *odesc = av_pix_fmt_desc_get(outlink->format);
764 char buf[32];
765 int ret = 0, changed = 0;
766 AVFrame *out = NULL;
767 ThreadData td;
768
769 //we need to use this filter if something is different for an input and output only
770 //otherwise - just copy the input frame to the output
771 if ((link->format != outlink->format) ||
772 (link->w != outlink->w) ||
773 (link->h != outlink->h) ||
774 (link->colorspace != outlink->colorspace) ||
775 (link->color_range != outlink->color_range) ||
776 s->first_time ||
777 (s->src_format.chroma_location != s->dst_format.chroma_location) ||
778 (s->src_format.color_family !=s->dst_format.color_family) ||
779 (s->src_format.color_primaries !=s->dst_format.color_primaries) ||
780 (s->src_format.depth !=s->dst_format.depth) ||
781 (s->src_format.matrix_coefficients !=s->dst_format.matrix_coefficients) ||
782 (s->src_format.field_parity !=s->dst_format.field_parity) ||
783 (s->src_format.pixel_range !=s->dst_format.pixel_range) ||
784 (s->src_format.pixel_type !=s->dst_format.pixel_type) ||
785 (s->src_format.transfer_characteristics !=s->dst_format.transfer_characteristics)
786 ){
787 out = ff_default_get_video_buffer2(outlink, outlink->w, outlink->h, ZIMG_ALIGNMENT);
788 if (!out) {
789 ret = AVERROR(ENOMEM);
790 goto fail;
791 }
792
794 out->colorspace = outlink->colorspace;
795 out->color_range = outlink->color_range;
797 out->chroma_location = outlink->chroma_location;
798
799 if ((ret = realign_frame(link, desc, &in)) < 0)
800 goto fail;
801
802 snprintf(buf, sizeof(buf)-1, "%d", outlink->w);
803 av_opt_set(s, "w", buf, 0);
804 snprintf(buf, sizeof(buf)-1, "%d", outlink->h);
805 av_opt_set(s, "h", buf, 0);
806
807 link->dst->inputs[0]->format = in->format;
808 link->dst->inputs[0]->w = in->width;
809 link->dst->inputs[0]->h = in->height;
810 link->dst->inputs[0]->colorspace = in->colorspace;
811 link->dst->inputs[0]->color_range = in->color_range;
812
813 s->nb_threads = av_clip(FFMIN(ff_filter_get_nb_threads(ctx), FFMIN(link->h, outlink->h) / MIN_TILESIZE), 1, MAX_THREADS);
814 slice_params(s, out->height, in->height);
815
816 zimg_image_format_default(&s->src_format, ZIMG_API_VERSION);
817 zimg_image_format_default(&s->dst_format, ZIMG_API_VERSION);
818 zimg_graph_builder_params_default(&s->params, ZIMG_API_VERSION);
819
820 format_init(&s->dst_format, out, odesc, s->colorspace,
821 s->primaries, s->trc, s->range, s->chromal);
822 /* Input without a chroma location is assumed to be sited like the output. */
823 format_init(&s->src_format, in, desc, s->colorspace_in,
824 s->primaries_in, s->trc_in, s->range_in,
825 s->chromal_in == -1 && in->chroma_location == AVCHROMA_LOC_UNSPECIFIED ?
826 s->dst_format.chroma_location : s->chromal_in);
827 s->first_time = 0;
828
829 s->params.dither_type = s->dither;
830 s->params.cpu_type = ZIMG_CPU_AUTO_64B;
831 s->params.resample_filter = s->filter;
832 s->params.resample_filter_uv = s->filter;
833 s->params.nominal_peak_luminance = s->nominal_peak_luminance;
834 s->params.allow_approximate_gamma = s->approximate_gamma;
835 s->params.filter_param_a = s->params.filter_param_a_uv = s->param_a;
836 s->params.filter_param_b = s->params.filter_param_b_uv = s->param_b;
837
839 av_reduce(&out->sample_aspect_ratio.num, &out->sample_aspect_ratio.den,
840 (int64_t)in->sample_aspect_ratio.num * outlink->h * link->w,
841 (int64_t)in->sample_aspect_ratio.den * outlink->w * link->h,
842 INT_MAX);
843
844 if (out->width != in->width || out->height != in->height)
846 if (out->color_trc != in->color_trc || out->color_primaries != in->color_primaries)
848 av_frame_side_data_remove_by_props(&out->side_data, &out->nb_side_data, changed);
849
850 td.in = in;
851 td.out = out;
852 td.desc = desc;
853 td.odesc = odesc;
854
855 memset(s->jobs_ret, 0, s->nb_threads * sizeof(*s->jobs_ret));
856 ret = ff_filter_execute(ctx, filter_slice, &td, s->jobs_ret, s->nb_threads);
857 for (int i = 0; ret >= 0 && i < s->nb_threads; i++)
858 if (s->jobs_ret[i] < 0)
859 ret = s->jobs_ret[i];
860 if (ret < 0) {
861 av_frame_free(&in);
863 return ret;
864 }
865
866 s->src_format_tmp = s->src_format;
867 s->dst_format_tmp = s->dst_format;
868 s->params_tmp = s->params;
869
870 if ((!(desc->flags & AV_PIX_FMT_FLAG_ALPHA)) && (odesc->flags & AV_PIX_FMT_FLAG_ALPHA) ){
871 int x, y;
872 if (odesc->flags & AV_PIX_FMT_FLAG_FLOAT) {
873 const uint16_t h_one = 0x3C00; // float2half(1.0f)
874 for (y = 0; y < out->height; y++) {
875 const ptrdiff_t row = y * out->linesize[3];
876 if (odesc->comp[0].depth == 16)
877 for (x = 0; x < out->width; x++) {
878 AV_WN16(out->data[3] + x * odesc->comp[3].step + row, h_one);
879 }
880 else
881 for (x = 0; x < out->width; x++) {
882 AV_WN32(out->data[3] + x * odesc->comp[3].step + row,
883 av_float2int(1.0f));
884 }
885 }
886 } else if (s->dst_format.depth == 8) {
887 for (y = 0; y < outlink->h; y++)
888 memset(out->data[3] + y * out->linesize[3], 0xff, outlink->w);
889 } else {
890 const uint16_t max = (1 << s->dst_format.depth) - 1;
891 for (y = 0; y < outlink->h; y++) {
892 const ptrdiff_t row = y * out->linesize[3];
893 for (x = 0; x < out->width; x++)
894 AV_WN16(out->data[3] + x * odesc->comp[3].step + row, max);
895 }
896 }
897 }
898 } else {
899 /*no need for any filtering */
901 in->chroma_location = outlink->chroma_location;
903 return ff_filter_frame(outlink, in);
904 }
905fail:
906 av_frame_free(&in);
907 if (ret) {
909 return ret;
910 }
911
912 return ff_filter_frame(outlink, out);
913}
914
916{
917 ZScaleContext *s = ctx->priv;
918
919 for (int i = 0; i < s->nb_threads; i++) {
920 av_freep(&s->tmp[i]);
921 if (s->graph[i]) {
922 zimg_filter_graph_free(s->graph[i]);
923 s->graph[i] = NULL;
924 }
925 }
926}
927
928static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
929 char *res, int res_len, int flags)
930{
931 ZScaleContext *s = ctx->priv;
932 int ret;
933
934 if ( !strcmp(cmd, "width") || !strcmp(cmd, "w")
935 || !strcmp(cmd, "height") || !strcmp(cmd, "h")) {
936
937 int old_w = s->w;
938 int old_h = s->h;
939 AVFilterLink *outlink = ctx->outputs[0];
940
941 av_opt_set(s, cmd, args, 0);
942 if ((ret = config_props(outlink)) < 0) {
943 s->w = old_w;
944 s->h = old_h;
945 }
946 } else
947 ret = AVERROR(ENOSYS);
948
949 return ret;
950}
951
952#define OFFSET(x) offsetof(ZScaleContext, x)
953#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
954#define TFLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
955
956static const AVOption zscale_options[] = {
957 { "w", "Output video width", OFFSET(w_expr), AV_OPT_TYPE_STRING, .flags = TFLAGS },
958 { "width", "Output video width", OFFSET(w_expr), AV_OPT_TYPE_STRING, .flags = TFLAGS },
959 { "h", "Output video height", OFFSET(h_expr), AV_OPT_TYPE_STRING, .flags = TFLAGS },
960 { "height", "Output video height", OFFSET(h_expr), AV_OPT_TYPE_STRING, .flags = TFLAGS },
961 { "size", "set video size", OFFSET(size_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS },
962 { "s", "set video size", OFFSET(size_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS },
963 { "dither", "set dither type", OFFSET(dither), AV_OPT_TYPE_INT, {.i64 = 0}, 0, ZIMG_DITHER_ERROR_DIFFUSION, FLAGS, .unit = "dither" },
964 { "d", "set dither type", OFFSET(dither), AV_OPT_TYPE_INT, {.i64 = 0}, 0, ZIMG_DITHER_ERROR_DIFFUSION, FLAGS, .unit = "dither" },
965 { "none", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_DITHER_NONE}, 0, 0, FLAGS, .unit = "dither" },
966 { "ordered", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_DITHER_ORDERED}, 0, 0, FLAGS, .unit = "dither" },
967 { "random", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_DITHER_RANDOM}, 0, 0, FLAGS, .unit = "dither" },
968 { "error_diffusion", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_DITHER_ERROR_DIFFUSION}, 0, 0, FLAGS, .unit = "dither" },
969 { "filter", "set filter type", OFFSET(filter), AV_OPT_TYPE_INT, {.i64 = ZIMG_RESIZE_BILINEAR}, 0, ZIMG_RESIZE_SPLINE64, FLAGS, .unit = "filter" },
970 { "f", "set filter type", OFFSET(filter), AV_OPT_TYPE_INT, {.i64 = ZIMG_RESIZE_BILINEAR}, 0, ZIMG_RESIZE_SPLINE64, FLAGS, .unit = "filter" },
971 { "point", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_RESIZE_POINT}, 0, 0, FLAGS, .unit = "filter" },
972 { "bilinear", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_RESIZE_BILINEAR}, 0, 0, FLAGS, .unit = "filter" },
973 { "bicubic", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_RESIZE_BICUBIC}, 0, 0, FLAGS, .unit = "filter" },
974 { "spline16", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_RESIZE_SPLINE16}, 0, 0, FLAGS, .unit = "filter" },
975 { "spline36", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_RESIZE_SPLINE36}, 0, 0, FLAGS, .unit = "filter" },
976 { "spline64", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_RESIZE_SPLINE64}, 0, 0, FLAGS, .unit = "filter" },
977 { "lanczos", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_RESIZE_LANCZOS}, 0, 0, FLAGS, .unit = "filter" },
978 { "out_range", "set color range", OFFSET(range), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_RANGE_FULL, FLAGS, .unit = "range" },
979 { "range", "set color range", OFFSET(range), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_RANGE_FULL, FLAGS, .unit = "range" },
980 { "r", "set color range", OFFSET(range), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_RANGE_FULL, FLAGS, .unit = "range" },
981 { "input", 0, 0, AV_OPT_TYPE_CONST, {.i64 = -1}, 0, 0, FLAGS, .unit = "range" },
982 { "limited", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_RANGE_LIMITED}, 0, 0, FLAGS, .unit = "range" },
983 { "full", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_RANGE_FULL}, 0, 0, FLAGS, .unit = "range" },
984 { "unknown", 0, 0, AV_OPT_TYPE_CONST, {.i64 = -1}, 0, 0, FLAGS, .unit = "range" },
985 { "tv", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_RANGE_LIMITED}, 0, 0, FLAGS, .unit = "range" },
986 { "pc", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_RANGE_FULL}, 0, 0, FLAGS, .unit = "range" },
987 { "primaries", "set color primaries", OFFSET(primaries), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, FLAGS, .unit = "primaries" },
988 { "p", "set color primaries", OFFSET(primaries), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, FLAGS, .unit = "primaries" },
989 { "input", 0, 0, AV_OPT_TYPE_CONST, {.i64 = -1}, 0, 0, FLAGS, .unit = "primaries" },
990 { "709", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_709}, 0, 0, FLAGS, .unit = "primaries" },
991 { "unspecified", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_UNSPECIFIED}, 0, 0, FLAGS, .unit = "primaries" },
992 { "170m", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_170M}, 0, 0, FLAGS, .unit = "primaries" },
993 { "240m", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_240M}, 0, 0, FLAGS, .unit = "primaries" },
994 { "2020", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_2020}, 0, 0, FLAGS, .unit = "primaries" },
995 { "unknown", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_UNSPECIFIED}, 0, 0, FLAGS, .unit = "primaries" },
996 { "bt709", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_709}, 0, 0, FLAGS, .unit = "primaries" },
997 { "bt470m", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_470_M}, 0, 0, FLAGS, .unit = "primaries" },
998 { "bt470bg", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_470_BG}, 0, 0, FLAGS, .unit = "primaries" },
999 { "smpte170m", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_170M}, 0, 0, FLAGS, .unit = "primaries" },
1000 { "smpte240m", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_240M}, 0, 0, FLAGS, .unit = "primaries" },
1001 { "film", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_FILM}, 0, 0, FLAGS, .unit = "primaries" },
1002 { "bt2020", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_2020}, 0, 0, FLAGS, .unit = "primaries" },
1003 { "smpte428", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_ST428}, 0, 0, FLAGS, .unit = "primaries" },
1004 { "smpte431", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_ST431_2}, 0, 0, FLAGS, .unit = "primaries" },
1005 { "smpte432", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_ST432_1}, 0, 0, FLAGS, .unit = "primaries" },
1006 { "jedec-p22", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_EBU3213_E}, 0, 0, FLAGS, .unit = "primaries" },
1007 { "ebu3213", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_EBU3213_E}, 0, 0, FLAGS, .unit = "primaries" },
1008 { "transfer", "set transfer characteristic", OFFSET(trc), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, FLAGS, .unit = "transfer" },
1009 { "t", "set transfer characteristic", OFFSET(trc), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, FLAGS, .unit = "transfer" },
1010 { "input", 0, 0, AV_OPT_TYPE_CONST, {.i64 = -1}, 0, 0, FLAGS, .unit = "transfer" },
1011 { "709", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_709}, 0, 0, FLAGS, .unit = "transfer" },
1012 { "unspecified", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_UNSPECIFIED}, 0, 0, FLAGS, .unit = "transfer" },
1013 { "601", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_601}, 0, 0, FLAGS, .unit = "transfer" },
1014 { "linear", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_LINEAR}, 0, 0, FLAGS, .unit = "transfer" },
1015 { "2020_10", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_2020_10}, 0, 0, FLAGS, .unit = "transfer" },
1016 { "2020_12", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_2020_12}, 0, 0, FLAGS, .unit = "transfer" },
1017 { "unknown", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_UNSPECIFIED}, 0, 0, FLAGS, .unit = "transfer" },
1018 { "bt470m", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_470_M}, 0, 0, FLAGS, .unit = "transfer" },
1019 { "bt470bg", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_470_BG}, 0, 0, FLAGS, .unit = "transfer" },
1020 { "smpte170m", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_601}, 0, 0, FLAGS, .unit = "transfer" },
1021 { "smpte240m", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_240M}, 0, 0, FLAGS, .unit = "transfer" },
1022 { "bt709", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_709}, 0, 0, FLAGS, .unit = "transfer" },
1023 { "linear", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_LINEAR}, 0, 0, FLAGS, .unit = "transfer" },
1024 { "log100", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_LOG_100}, 0, 0, FLAGS, .unit = "transfer" },
1025 { "log316", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_LOG_316}, 0, 0, FLAGS, .unit = "transfer" },
1026 { "bt2020-10", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_2020_10}, 0, 0, FLAGS, .unit = "transfer" },
1027 { "bt2020-12", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_2020_12}, 0, 0, FLAGS, .unit = "transfer" },
1028 { "smpte2084", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_ST2084}, 0, 0, FLAGS, .unit = "transfer" },
1029 { "iec61966-2-4", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_IEC_61966_2_4},0, 0, FLAGS, .unit = "transfer" },
1030 { "iec61966-2-1", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_IEC_61966_2_1},0, 0, FLAGS, .unit = "transfer" },
1031 { "arib-std-b67", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_ARIB_B67}, 0, 0, FLAGS, .unit = "transfer" },
1032 { "matrix", "set colorspace matrix", OFFSET(colorspace), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, FLAGS, .unit = "matrix" },
1033 { "m", "set colorspace matrix", OFFSET(colorspace), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, FLAGS, .unit = "matrix" },
1034 { "input", 0, 0, AV_OPT_TYPE_CONST, {.i64 = -1}, 0, 0, FLAGS, .unit = "matrix" },
1035 { "709", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_709}, 0, 0, FLAGS, .unit = "matrix" },
1036 { "unspecified", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_UNSPECIFIED}, 0, 0, FLAGS, .unit = "matrix" },
1037 { "470bg", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_470BG}, 0, 0, FLAGS, .unit = "matrix" },
1038 { "170m", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_170M}, 0, 0, FLAGS, .unit = "matrix" },
1039 { "2020_ncl", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_2020_NCL}, 0, 0, FLAGS, .unit = "matrix" },
1040 { "2020_cl", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_2020_CL}, 0, 0, FLAGS, .unit = "matrix" },
1041 { "unknown", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_UNSPECIFIED}, 0, 0, FLAGS, .unit = "matrix" },
1042 { "gbr", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_RGB}, 0, 0, FLAGS, .unit = "matrix" },
1043 { "bt709", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_709}, 0, 0, FLAGS, .unit = "matrix" },
1044 { "fcc", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_FCC}, 0, 0, FLAGS, .unit = "matrix" },
1045 { "bt470bg", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_470BG}, 0, 0, FLAGS, .unit = "matrix" },
1046 { "smpte170m", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_170M}, 0, 0, FLAGS, .unit = "matrix" },
1047 { "smpte240m", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_240M}, 0, 0, FLAGS, .unit = "matrix" },
1048 { "ycgco", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_YCGCO}, 0, 0, FLAGS, .unit = "matrix" },
1049 { "bt2020nc", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_2020_NCL}, 0, 0, FLAGS, .unit = "matrix" },
1050 { "bt2020c", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_2020_CL}, 0, 0, FLAGS, .unit = "matrix" },
1051 { "chroma-derived-nc",0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_CHROMATICITY_DERIVED_NCL}, 0, 0, FLAGS, .unit = "matrix" },
1052 { "chroma-derived-c", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_CHROMATICITY_DERIVED_CL}, 0, 0, FLAGS, .unit = "matrix" },
1053 { "ictcp", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_ICTCP}, 0, 0, FLAGS, .unit = "matrix" },
1054 { "in_range", "set input color range", OFFSET(range_in), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_RANGE_FULL, FLAGS, .unit = "range" },
1055 { "rangein", "set input color range", OFFSET(range_in), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_RANGE_FULL, FLAGS, .unit = "range" },
1056 { "rin", "set input color range", OFFSET(range_in), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_RANGE_FULL, FLAGS, .unit = "range" },
1057 { "primariesin", "set input color primaries", OFFSET(primaries_in), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, FLAGS, .unit = "primaries" },
1058 { "pin", "set input color primaries", OFFSET(primaries_in), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, FLAGS, .unit = "primaries" },
1059 { "transferin", "set input transfer characteristic", OFFSET(trc_in), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, FLAGS, .unit = "transfer" },
1060 { "tin", "set input transfer characteristic", OFFSET(trc_in), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, FLAGS, .unit = "transfer" },
1061 { "matrixin", "set input colorspace matrix", OFFSET(colorspace_in), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, FLAGS, .unit = "matrix" },
1062 { "min", "set input colorspace matrix", OFFSET(colorspace_in), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, FLAGS, .unit = "matrix" },
1063 { "chromal", "set output chroma location", OFFSET(chromal), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_CHROMA_BOTTOM, FLAGS, .unit = "chroma" },
1064 { "c", "set output chroma location", OFFSET(chromal), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_CHROMA_BOTTOM, FLAGS, .unit = "chroma" },
1065 { "input", 0, 0, AV_OPT_TYPE_CONST, {.i64 = -1}, 0, 0, FLAGS, .unit = "chroma" },
1066 { "left", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_CHROMA_LEFT}, 0, 0, FLAGS, .unit = "chroma" },
1067 { "center", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_CHROMA_CENTER}, 0, 0, FLAGS, .unit = "chroma" },
1068 { "topleft", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_CHROMA_TOP_LEFT}, 0, 0, FLAGS, .unit = "chroma" },
1069 { "top", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_CHROMA_TOP}, 0, 0, FLAGS, .unit = "chroma" },
1070 { "bottomleft",0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_CHROMA_BOTTOM_LEFT}, 0, 0, FLAGS, .unit = "chroma" },
1071 { "bottom", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_CHROMA_BOTTOM}, 0, 0, FLAGS, .unit = "chroma" },
1072 { "chromalin", "set input chroma location", OFFSET(chromal_in), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_CHROMA_BOTTOM, FLAGS, .unit = "chroma" },
1073 { "cin", "set input chroma location", OFFSET(chromal_in), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_CHROMA_BOTTOM, FLAGS, .unit = "chroma" },
1074 { "npl", "set nominal peak luminance", OFFSET(nominal_peak_luminance), AV_OPT_TYPE_DOUBLE, {.dbl = NAN}, 0, DBL_MAX, FLAGS },
1075 { "agamma", "allow approximate gamma", OFFSET(approximate_gamma), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, FLAGS },
1076 { "param_a", "parameter A, which is parameter \"b\" for bicubic, "
1077 "and the number of filter taps for lanczos", OFFSET(param_a), AV_OPT_TYPE_DOUBLE, {.dbl = NAN}, -DBL_MAX, DBL_MAX, FLAGS },
1078 { "param_b", "parameter B, which is parameter \"c\" for bicubic", OFFSET(param_b), AV_OPT_TYPE_DOUBLE, {.dbl = NAN}, -DBL_MAX, DBL_MAX, FLAGS },
1079 { NULL }
1080};
1081
1083
1085 {
1086 .name = "default",
1087 .type = AVMEDIA_TYPE_VIDEO,
1088 .filter_frame = filter_frame,
1089 },
1090};
1091
1093 {
1094 .name = "default",
1095 .type = AVMEDIA_TYPE_VIDEO,
1096 .config_props = config_props,
1097 },
1098};
1099
1101 .p.name = "zscale",
1102 .p.description = NULL_IF_CONFIG_SMALL("Apply resizing, colorspace and bit depth conversion."),
1103 .p.priv_class = &zscale_class,
1104 .p.flags = AVFILTER_FLAG_SLICE_THREADS,
1105 .init = init,
1106 .priv_size = sizeof(ZScaleContext),
1107 .uninit = uninit,
1111 .process_command = process_command,
1112};
static int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
Definition aeval.c:246
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
#define TFLAGS
Definition af_afade.c:66
static const char *const format[]
Definition af_aiir.c:445
const FFFilter ff_vf_zscale
Definition vf_zscale.c:1100
static FILE * out
static AVFormatContext * ctx
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition avfilter.c:1073
int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
Definition avfilter.c:1701
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Definition avfilter.c:851
Main libavfilter public API header.
@ VAR_VSUB
Definition boxblur.c:42
@ VARS_NB
Definition boxblur.c:43
@ VAR_HSUB
Definition boxblur.c:41
#define flags(name, subs,...)
Definition cbs_h264.c:74
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define s(width, name)
Definition cbs_vp9.c:198
#define FLAGS
Definition cmdutils.c:596
#define av_clip
Definition common.h:100
#define NULL
Definition coverity.c:32
long long int64_t
Definition coverity.c:34
static const double approximate_gamma[AVCOL_TRC_NB]
Definition csp.c:140
static const AVColorPrimariesDesc color_primaries[AVCOL_PRI_NB]
Definition csp.c:76
static __device__ float trunc(float a)
#define max(a, b)
static int aligned(int val)
Definition dashdec.c:178
static AVFrame * frame
static int filter_frame(DBEDecodeContext *s, AVFrame *frame)
Definition dolby_e.c:1067
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:608
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:839
simple arithmetic expression evaluator
@ VAR_IW
Definition f_select.c:147
@ VAR_IH
Definition f_select.c:146
int ff_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
Add ref as a new reference to formats.
Definition formats.c:776
AVFilterFormats * ff_all_color_spaces(void)
Construct an AVFilterFormats representing all possible color spaces.
Definition formats.c:706
AVFilterFormats * ff_make_formats_list_singleton(int fmt)
Equivalent to ff_make_format_list({const int[]}{ fmt, -1 })
Definition formats.c:605
AVFilterFormats * ff_all_color_ranges(void)
Construct an AVFilterFormats representing all possible color ranges.
Definition formats.c:722
AVFilterFormats * ff_all_alpha_modes(void)
Construct an AVFilterFormats representing all possible alpha modes.
Definition formats.c:733
AVFilterFormats * ff_all_chroma_locations(void)
Construct an AVFilterFormats representing all possible chroma locations.
Definition formats.c:744
av_warn_unused_result AVFilterFormats * ff_make_pixel_format_list(const enum AVPixelFormat *fmts)
Create a list of supported pixel formats.
#define MAX_THREADS
#define fail
Definition test.h:479
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition opt.h:298
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition opt.h:258
@ AV_OPT_TYPE_DOUBLE
Underlying C type is double.
Definition opt.h:266
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition opt.h:326
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
Definition opt.h:275
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Definition avfilter.h:172
#define AVERROR_EXTERNAL
Generic error in an external library.
Definition error.h:59
#define AVERROR(e)
Definition error.h:45
void av_frame_side_data_remove_by_props(AVFrameSideData ***sd, int *nb_sd, int props)
Remove and free all side data instances that match any of the given side data properties.
Definition side_data.c:124
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition frame.c:64
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition frame.c:599
int av_frame_copy(AVFrame *dst, const AVFrame *src)
Copy the frame data from src to dst.
Definition frame.c:711
@ AV_SIDE_DATA_PROP_SIZE_DEPENDENT
Side data depends on the video dimensions.
Definition frame.h:361
@ AV_SIDE_DATA_PROP_COLOR_DEPENDENT
Side data depends on the video color space.
Definition frame.h:368
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition log.h:231
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
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.
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
Definition opt.c:891
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)
#define AV_WN16(p, v)
static av_cold void uninit(AVBitStreamFilterContext *ctx)
#define FILTER_INPUTS(array)
Definition filters.h:264
#define FILTER_OUTPUTS(array)
Definition filters.h:265
#define AVFILTER_DEFINE_CLASS(fname)
Definition filters.h:478
#define FILTER_QUERY_FUNC2(func)
Definition filters.h:241
#define av_cold
Definition attributes.h:117
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:97
const char * desc
Definition libsvtav1.c:83
static const struct @257111027162314367033347246032313251342043035002 planes[]
uint8_t w
Definition llvidencdsp.c:39
#define FFSWAP(type, a, b)
Definition macros.h:52
#define FFMIN(a, b)
Definition macros.h:49
#define FFMAX(a, b)
Definition macros.h:47
#define FFALIGN(x, a)
Definition macros.h:78
#define NAN
enum AVColorTransferCharacteristic transfer
enum AVColorPrimaries primaries
enum AVColorRange range
Memory handling functions.
static int slice_end(AVCodecContext *avctx, AVFrame *pict, int *got_output)
Handle slice ends.
Definition mpeg12dec.c:1697
const char data[16]
Definition mxf.c:149
var_name
Definition noise.c:46
static const char *const var_names[]
Definition noise.c:30
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:150
misc parsing utilities
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition pixdesc.c:3500
const char * av_color_space_name(enum AVColorSpace space)
Definition pixdesc.c:3860
const char * av_color_range_name(enum AVColorRange range)
Definition pixdesc.c:3776
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:3380
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition pixdesc.c:3460
#define AV_PIX_FMT_FLAG_ALPHA
The pixel format has an alpha channel.
Definition pixdesc.h:147
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
Definition pixdesc.h:136
#define AV_PIX_FMT_FLAG_FLOAT
The pixel format contains IEEE-754 floating point values.
Definition pixdesc.h:158
#define AV_PIX_FMT_GBRAP12
Definition pixfmt.h:569
#define AV_PIX_FMT_YUV420P16
Definition pixfmt.h:556
#define AV_PIX_FMT_GBRPF32
Definition pixfmt.h:584
#define AV_PIX_FMT_YUV444P12
Definition pixfmt.h:552
#define AV_PIX_FMT_YUV444P9
Definition pixfmt.h:544
AVChromaLocation
Location of chroma samples.
Definition pixfmt.h:802
@ AVCHROMA_LOC_TOP
Definition pixfmt.h:807
@ AVCHROMA_LOC_BOTTOM
Definition pixfmt.h:809
@ AVCHROMA_LOC_TOPLEFT
ITU-R 601, SMPTE 274M 296M S314M(DV 4:1:1), mpeg2 4:2:2.
Definition pixfmt.h:806
@ AVCHROMA_LOC_LEFT
MPEG-2/4 4:2:0, H.264 default for 4:2:0.
Definition pixfmt.h:804
@ AVCHROMA_LOC_BOTTOMLEFT
Definition pixfmt.h:808
@ AVCHROMA_LOC_CENTER
MPEG-1 4:2:0, JPEG 4:2:0, H.263 4:2:0.
Definition pixfmt.h:805
@ AVCHROMA_LOC_UNSPECIFIED
Definition pixfmt.h:803
#define AV_PIX_FMT_YUV420P10
Definition pixfmt.h:545
#define AV_PIX_FMT_GRAYF16
Definition pixfmt.h:587
#define AV_PIX_FMT_GRAY9
Definition pixfmt.h:524
#define AV_PIX_FMT_GBRAP16
Definition pixfmt.h:571
#define AV_PIX_FMT_GBRP9
Definition pixfmt.h:563
#define AV_PIX_FMT_YUV422P9
Definition pixfmt.h:543
AVColorRange
Visual content value range.
Definition pixfmt.h:748
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition pixfmt.h:766
@ AVCOL_RANGE_UNSPECIFIED
Definition pixfmt.h:749
@ AVCOL_RANGE_JPEG
Full range content.
Definition pixfmt.h:783
#define AV_PIX_FMT_YUVA444P10
Definition pixfmt.h:598
#define AV_PIX_FMT_YUVA420P16
Definition pixfmt.h:601
#define AV_PIX_FMT_YUV420P12
Definition pixfmt.h:549
#define AV_PIX_FMT_YUVA420P10
Definition pixfmt.h:596
@ AVALPHA_MODE_PREMULTIPLIED
Alpha channel is multiplied into color values.
Definition pixfmt.h:818
#define AV_PIX_FMT_YUVA422P9
Definition pixfmt.h:594
#define AV_PIX_FMT_YUV422P12
Definition pixfmt.h:550
#define AV_PIX_FMT_GBRAP14
Definition pixfmt.h:570
#define AV_PIX_FMT_GBRP10
Definition pixfmt.h:564
#define AV_PIX_FMT_YUV422P10
Definition pixfmt.h:546
#define AV_PIX_FMT_GBRAPF16
Definition pixfmt.h:583
#define AV_PIX_FMT_GBRP12
Definition pixfmt.h:565
#define AV_PIX_FMT_YUV420P9
Definition pixfmt.h:542
#define AV_PIX_FMT_YUVA420P9
Definition pixfmt.h:593
#define AV_PIX_FMT_YUVA422P10
Definition pixfmt.h:597
#define AV_PIX_FMT_GRAYF32
Definition pixfmt.h:588
#define AV_PIX_FMT_YUV420P14
Definition pixfmt.h:553
AVPixelFormat
Pixel format.
Definition pixfmt.h:71
@ AV_PIX_FMT_NONE
Definition pixfmt.h:72
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition pixfmt.h:73
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition pixfmt.h:106
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition pixfmt.h:77
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition pixfmt.h:81
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition pixfmt.h:108
@ 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:107
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition pixfmt.h:79
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition pixfmt.h:80
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition pixfmt.h:78
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition pixfmt.h:174
@ 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:283
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
Definition pixfmt.h:212
@ 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:86
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
Definition pixfmt.h:173
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
Definition pixfmt.h:165
@ 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:87
@ 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:85
#define AV_PIX_FMT_YUVA422P12
Definition pixfmt.h:599
#define AV_PIX_FMT_YUV422P14
Definition pixfmt.h:554
#define AV_PIX_FMT_GRAY10
Definition pixfmt.h:525
#define AV_PIX_FMT_GBRPF16
Definition pixfmt.h:582
#define AV_PIX_FMT_YUV422P16
Definition pixfmt.h:557
#define AV_PIX_FMT_GBRAP10
Definition pixfmt.h:568
AVColorPrimaries
Chromaticity coordinates of the source primaries.
Definition pixfmt.h:642
@ AVCOL_PRI_BT470BG
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM
Definition pixfmt.h:649
@ AVCOL_PRI_FILM
colour filters using Illuminant C
Definition pixfmt.h:652
@ AVCOL_PRI_SMPTE432
SMPTE ST 432-1 (2010) / P3 D65 / Display P3.
Definition pixfmt.h:657
@ AVCOL_PRI_BT709
also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP 177 Annex B
Definition pixfmt.h:644
@ AVCOL_PRI_JEDEC_P22
Definition pixfmt.h:659
@ AVCOL_PRI_SMPTE240M
identical to above, also called "SMPTE C" even though it uses D65
Definition pixfmt.h:651
@ AVCOL_PRI_UNSPECIFIED
Definition pixfmt.h:645
@ AVCOL_PRI_SMPTE431
SMPTE ST 431-2 (2011) / DCI P3.
Definition pixfmt.h:656
@ AVCOL_PRI_SMPTE428
SMPTE ST 428-1 (CIE 1931 XYZ)
Definition pixfmt.h:654
@ AVCOL_PRI_SMPTE170M
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
Definition pixfmt.h:650
@ AVCOL_PRI_BT2020
ITU-R BT2020.
Definition pixfmt.h:653
@ AVCOL_PRI_BT470M
also FCC Title 47 Code of Federal Regulations 73.682 (a)(20)
Definition pixfmt.h:647
AVColorTransferCharacteristic
Color Transfer Characteristic.
Definition pixfmt.h:672
@ AVCOL_TRC_SMPTE170M
also ITU-R BT601-6 525 or 625 / ITU-R BT1358 525 or 625 / ITU-R BT1700 NTSC
Definition pixfmt.h:679
@ AVCOL_TRC_SMPTE2084
SMPTE ST 2084 for 10-, 12-, 14- and 16-bit systems.
Definition pixfmt.h:689
@ AVCOL_TRC_GAMMA22
also ITU-R BT470M / ITU-R BT1700 625 PAL & SECAM
Definition pixfmt.h:677
@ AVCOL_TRC_SMPTE240M
Definition pixfmt.h:680
@ AVCOL_TRC_LOG
"Logarithmic transfer characteristic (100:1 range)"
Definition pixfmt.h:682
@ AVCOL_TRC_IEC61966_2_4
IEC 61966-2-4.
Definition pixfmt.h:684
@ AVCOL_TRC_LINEAR
"Linear transfer characteristics"
Definition pixfmt.h:681
@ AVCOL_TRC_GAMMA28
also ITU-R BT470BG
Definition pixfmt.h:678
@ AVCOL_TRC_ARIB_STD_B67
ARIB STD-B67, known as "Hybrid log-gamma".
Definition pixfmt.h:693
@ AVCOL_TRC_LOG_SQRT
"Logarithmic transfer characteristic (100 * Sqrt(10) : 1 range)"
Definition pixfmt.h:683
@ AVCOL_TRC_BT2020_12
ITU-R BT2020 for 12-bit system.
Definition pixfmt.h:688
@ AVCOL_TRC_IEC61966_2_1
IEC 61966-2-1 (sRGB or sYCC)
Definition pixfmt.h:686
@ AVCOL_TRC_BT2020_10
ITU-R BT2020 for 10-bit system.
Definition pixfmt.h:687
@ AVCOL_TRC_UNSPECIFIED
Definition pixfmt.h:675
@ AVCOL_TRC_BT709
also ITU-R BT1361
Definition pixfmt.h:674
#define AV_PIX_FMT_YUVA444P16
Definition pixfmt.h:603
#define AV_PIX_FMT_YUVA422P16
Definition pixfmt.h:602
#define AV_PIX_FMT_GBRP16
Definition pixfmt.h:567
#define AV_PIX_FMT_YUV444P14
Definition pixfmt.h:555
#define AV_PIX_FMT_YUVA444P9
Definition pixfmt.h:595
#define AV_PIX_FMT_GBRP14
Definition pixfmt.h:566
#define AV_PIX_FMT_YUVA444P12
Definition pixfmt.h:600
#define AV_PIX_FMT_GBRAPF32
Definition pixfmt.h:585
#define AV_PIX_FMT_YUV444P16
Definition pixfmt.h:558
#define AV_PIX_FMT_YUV444P10
Definition pixfmt.h:548
AVColorSpace
YUV colorspace type.
Definition pixfmt.h:706
@ AVCOL_SPC_BT709
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / derived in SMPTE RP 177 Annex B
Definition pixfmt.h:708
@ 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:712
@ AVCOL_SPC_CHROMA_DERIVED_CL
Chromaticity-derived constant luminance system.
Definition pixfmt.h:721
@ AVCOL_SPC_BT2020_CL
ITU-R BT2020 constant luminance system.
Definition pixfmt.h:718
@ AVCOL_SPC_RGB
order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB), YZX and ST 428-1
Definition pixfmt.h:707
@ AVCOL_SPC_BT2020_NCL
ITU-R BT2020 non-constant luminance system.
Definition pixfmt.h:717
@ AVCOL_SPC_UNSPECIFIED
Definition pixfmt.h:709
@ AVCOL_SPC_SMPTE170M
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC / functionally identical to above
Definition pixfmt.h:713
@ AVCOL_SPC_FCC
FCC Title 47 Code of Federal Regulations 73.682 (a)(20)
Definition pixfmt.h:711
@ AVCOL_SPC_CHROMA_DERIVED_NCL
Chromaticity-derived non-constant luminance system.
Definition pixfmt.h:720
@ AVCOL_SPC_SMPTE240M
derived from 170M primaries and D65 white point, 170M is derived from BT470 System M's primaries
Definition pixfmt.h:714
@ AVCOL_SPC_YCGCO
used by Dirac / VC-2 and H.264 FRext, see ITU-T SG16
Definition pixfmt.h:715
@ AVCOL_SPC_ICTCP
ITU-R BT.2100-0, ICtCp.
Definition pixfmt.h:722
@ VAR_OUT_H
Definition scale_eval.c:47
@ VAR_SAR
Definition scale_eval.c:49
@ VAR_OH
Definition scale_eval.c:47
@ VAR_IN_W
Definition scale_eval.c:44
@ VAR_OW
Definition scale_eval.c:46
@ VAR_OHSUB
Definition scale_eval.c:53
@ VAR_A
Definition scale_eval.c:48
@ VAR_OUT_W
Definition scale_eval.c:46
@ VAR_OVSUB
Definition scale_eval.c:54
@ VAR_IN_H
Definition scale_eval.c:45
@ VAR_DAR
Definition scale_eval.c:50
formats
Definition signature.h:47
static int config_props(AVBitStreamFilterLink *link)
Definition source.c:181
Describe the class of an AVClass context structure.
Definition log.h:76
int plane
Which of the 4 planes contains the component.
Definition pixdesc.h:34
int step
Number of elements between 2 horizontally consecutive pixels.
Definition pixdesc.h:40
int depth
Number of bits in the component.
Definition pixdesc.h:57
An instance of a filter.
Definition avfilter.h:279
AVFilterLink ** inputs
array of pointers to input links
Definition avfilter.h:287
Lists of formats / etc.
Definition avfilter.h:120
A list of supported formats for one end of a filter link.
Definition formats.h:64
A filter pad used for either input or output.
Definition filters.h:40
This structure describes decoded (raw) audio or video data.
Definition frame.h:479
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition frame.h:500
enum AVChromaLocation chroma_location
Definition frame.h:743
int width
Definition frame.h:551
int height
Definition frame.h:551
enum AVColorPrimaries color_primaries
Definition frame.h:732
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
Definition frame.h:576
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition frame.h:730
enum AVColorSpace colorspace
YUV colorspace type.
Definition frame.h:741
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
Definition frame.h:524
enum AVColorTransferCharacteristic color_trc
Definition frame.h:734
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition frame.h:566
AVOption.
Definition opt.h:428
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition pixdesc.h:69
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition pixdesc.h:105
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition pixdesc.h:80
uint64_t flags
Combination of AV_PIX_FMT_FLAG_... flags.
Definition pixdesc.h:94
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition pixdesc.h:89
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
Used for passing data between threads.
Definition v210dec.c:35
const AVPixFmtDescriptor * desc
Definition vf_tonemap.c:177
AVFrame * out
const AVPixFmtDescriptor * odesc
Definition vf_zscale.c:131
double param_b
Definition vf_zscale.c:107
double nominal_peak_luminance
Definition vf_zscale.c:104
double in_slice_end[MAX_THREADS]
Definition vf_zscale.c:119
zimg_image_format src_format_tmp
Definition vf_zscale.c:124
zimg_graph_builder_params params
Definition vf_zscale.c:125
void * tmp[MAX_THREADS]
Definition vf_zscale.c:115
double param_a
Definition vf_zscale.c:106
int w
New dimensions.
Definition vf_zscale.c:90
int approximate_gamma
Definition vf_zscale.c:105
int force_original_aspect_ratio
Definition vf_zscale.c:113
zimg_filter_graph * graph[MAX_THREADS]
Definition vf_zscale.c:127
char * size_str
Definition vf_zscale.c:103
double in_slice_start[MAX_THREADS]
Definition vf_zscale.c:118
zimg_image_format dst_format
Definition vf_zscale.c:123
int out_slice_start[MAX_THREADS]
Definition vf_zscale.c:120
char * w_expr
width expression string
Definition vf_zscale.c:109
int colorspace_in
Definition vf_zscale.c:98
zimg_graph_builder_params params_tmp
Definition vf_zscale.c:126
zimg_image_format dst_format_tmp
Definition vf_zscale.c:124
int jobs_ret[MAX_THREADS]
Definition vf_zscale.c:117
zimg_image_format src_format
Definition vf_zscale.c:123
char * h_expr
height expression string
Definition vf_zscale.c:110
int out_slice_end[MAX_THREADS]
Definition vf_zscale.c:121
#define av_mallocz(s)
#define av_freep(p)
#define av_log(a,...)
void(* filter)(uint8_t *src, ptrdiff_t stride, int qscale)
Definition h263dsp.c:29
int size
static enum AVPixelFormat pixel_fmts[]
Definition vf_amplify.c:52
static int filter_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static const uint16_t dither[8][8]
Definition vf_gradfun.c:46
color_range
static int config_props(AVFilterLink *outlink)
Definition vf_zscale.c:265
static int print_zimg_error(AVFilterContext *ctx)
Definition vf_zscale.c:394
static int convert_trc(enum AVColorTransferCharacteristic color_trc)
Definition vf_zscale.c:457
static int convert_range(enum AVColorRange color_range)
Definition vf_zscale.c:525
#define MIN_TILESIZE
Definition vf_zscale.c:48
static int filter_frame(AVFilterLink *link, AVFrame *in)
Definition vf_zscale.c:757
#define ZIMG_ALIGNMENT
Definition vf_zscale.c:47
static int filter_slice(AVFilterContext *ctx, void *data, int job_nr, int n_jobs)
Definition vf_zscale.c:706
static void slice_params(ZScaleContext *s, int out_h, int in_h)
Definition vf_zscale.c:250
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:593
static int convert_primaries(enum AVColorPrimaries color_primaries)
Definition vf_zscale.c:494
static int compare_zimg_image_formats(zimg_image_format *img_fmt0, zimg_image_format *img_fmt1)
Definition vf_zscale.c:549
#define MAX_THREADS
Definition vf_zscale.c:49
static int graphs_build(AVFrame *in, AVFrame *out, const AVPixFmtDescriptor *desc, const AVPixFmtDescriptor *out_desc, AVFilterContext *ctx, int job_nr, int n_jobs)
Definition vf_zscale.c:614
static int convert_matrix(enum AVColorSpace colorspace)
Definition vf_zscale.c:424
static int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
Definition vf_zscale.c:178
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
Definition vf_zscale.c:928
static int realign_frame(AVFilterLink *link, const AVPixFmtDescriptor *desc, AVFrame **frame)
Definition vf_zscale.c:663
static av_cold void uninit(AVFilterContext *ctx)
Definition vf_zscale.c:915
static int convert_chroma_location(enum AVChromaLocation chroma_location)
Definition vf_zscale.c:404
#define OFFSET(x)
Definition vf_zscale.c:952
static const AVFilterPad avfilter_vf_zscale_outputs[]
Definition vf_zscale.c:1092
static const AVOption zscale_options[]
Definition vf_zscale.c:956
static int compare_zimg_graph_builder_params(zimg_graph_builder_params *parm0, zimg_graph_builder_params *parm1)
Definition vf_zscale.c:570
static void update_output_color_information(ZScaleContext *s, AVFrame *frame)
Definition vf_zscale.c:694
static enum AVColorRange convert_range_from_zimg(enum zimg_pixel_range_e color_range)
Definition vf_zscale.c:537
static const AVFilterPad avfilter_vf_zscale_inputs[]
Definition vf_zscale.c:1084
AVFrame * ff_default_get_video_buffer2(AVFilterLink *link, int w, int h, int align)
Definition video.c:49