133 if (
s->size_str && (
s->w_expr ||
s->h_expr)) {
135 "Size and width/height expressions cannot be set at the same time.\n");
139 if (
s->w_expr && !
s->h_expr)
140 FFSWAP(
char *,
s->w_expr,
s->size_str);
146 "Invalid size '%s'\n",
s->size_str);
202 double var_values[
VARS_NB], res;
205 int factor_w, factor_h;
213 (
double)
inlink->sample_aspect_ratio.num /
inlink->sample_aspect_ratio.den : 1;
269 if (
s->force_original_aspect_ratio) {
273 if (
s->force_original_aspect_ratio == 1) {
282 if (
w > INT_MAX ||
h > INT_MAX ||
297 if (
inlink->sample_aspect_ratio.num){
304 inlink->sample_aspect_ratio.num,
inlink->sample_aspect_ratio.den,
311 "Error when evaluating the expression '%s'.\n"
312 "Maybe the expression for out_w:'%s' or for out_h:'%s' is self-referencing.\n",
313 expr,
s->w_expr,
s->h_expr);
320 int err_code = zimg_get_last_error(err_msg,
sizeof(err_msg));
329 switch (chroma_location) {
332 return ZIMG_CHROMA_LEFT;
334 return ZIMG_CHROMA_CENTER;
336 return ZIMG_CHROMA_TOP_LEFT;
338 return ZIMG_CHROMA_TOP;
340 return ZIMG_CHROMA_BOTTOM_LEFT;
342 return ZIMG_CHROMA_BOTTOM;
344 return ZIMG_CHROMA_LEFT;
349 switch (colorspace) {
351 return ZIMG_MATRIX_RGB;
353 return ZIMG_MATRIX_709;
355 return ZIMG_MATRIX_UNSPECIFIED;
357 return ZIMG_MATRIX_FCC;
359 return ZIMG_MATRIX_470BG;
361 return ZIMG_MATRIX_170M;
363 return ZIMG_MATRIX_240M;
365 return ZIMG_MATRIX_YCGCO;
367 return ZIMG_MATRIX_2020_NCL;
369 return ZIMG_MATRIX_2020_CL;
371 return ZIMG_MATRIX_CHROMATICITY_DERIVED_NCL;
373 return ZIMG_MATRIX_CHROMATICITY_DERIVED_CL;
375 return ZIMG_MATRIX_ICTCP;
377 return ZIMG_MATRIX_UNSPECIFIED;
384 return ZIMG_TRANSFER_UNSPECIFIED;
386 return ZIMG_TRANSFER_709;
388 return ZIMG_TRANSFER_470_M;
390 return ZIMG_TRANSFER_470_BG;
392 return ZIMG_TRANSFER_601;
394 return ZIMG_TRANSFER_240M;
396 return ZIMG_TRANSFER_LINEAR;
398 return ZIMG_TRANSFER_LOG_100;
400 return ZIMG_TRANSFER_LOG_316;
402 return ZIMG_TRANSFER_IEC_61966_2_4;
404 return ZIMG_TRANSFER_2020_10;
406 return ZIMG_TRANSFER_2020_12;
408 return ZIMG_TRANSFER_ST2084;
410 return ZIMG_TRANSFER_ARIB_B67;
412 return ZIMG_TRANSFER_IEC_61966_2_1;
414 return ZIMG_TRANSFER_UNSPECIFIED;
421 return ZIMG_PRIMARIES_UNSPECIFIED;
423 return ZIMG_PRIMARIES_709;
425 return ZIMG_PRIMARIES_470_M;
427 return ZIMG_PRIMARIES_470_BG;
429 return ZIMG_PRIMARIES_170M;
431 return ZIMG_PRIMARIES_240M;
433 return ZIMG_PRIMARIES_FILM;
435 return ZIMG_PRIMARIES_2020;
437 return ZIMG_PRIMARIES_ST428;
439 return ZIMG_PRIMARIES_ST431_2;
441 return ZIMG_PRIMARIES_ST432_1;
443 return ZIMG_PRIMARIES_EBU3213_E;
445 return ZIMG_PRIMARIES_UNSPECIFIED;
453 return ZIMG_RANGE_LIMITED;
455 return ZIMG_RANGE_FULL;
457 return ZIMG_RANGE_LIMITED;
461 int colorspace,
int primaries,
int transfer,
int range,
int location)
478 zimg_image_format *src_format, zimg_image_format *dst_format,
479 void **
tmp,
size_t *tmp_size)
484 zimg_filter_graph_free(*graph);
485 *graph = zimg_filter_graph_build(src_format, dst_format,
params);
489 ret = zimg_filter_graph_get_tmp_size(*graph, &
size);
493 if (
size > *tmp_size) {
511 zimg_image_buffer_const src_buf = { ZIMG_API_VERSION };
512 zimg_image_buffer dst_buf = { ZIMG_API_VERSION };
524 out->width = outlink->
w;
525 out->height = outlink->
h;
530 ||
s->in_colorspace !=
in->colorspace
531 ||
s->in_trc !=
in->color_trc
532 ||
s->in_primaries !=
in->color_primaries
533 ||
s->in_range !=
in->color_range
534 ||
s->out_colorspace !=
out->colorspace
535 ||
s->out_trc !=
out->color_trc
536 ||
s->out_primaries !=
out->color_primaries
537 ||
s->out_range !=
out->color_range
538 ||
s->in_chromal !=
in->chroma_location
539 ||
s->out_chromal !=
out->chroma_location) {
546 link->dst->inputs[0]->w =
in->width;
547 link->dst->inputs[0]->h =
in->height;
555 zimg_image_format_default(&
s->src_format, ZIMG_API_VERSION);
556 zimg_image_format_default(&
s->dst_format, ZIMG_API_VERSION);
557 zimg_graph_builder_params_default(&
s->params, ZIMG_API_VERSION);
559 s->params.dither_type =
s->dither;
560 s->params.cpu_type = ZIMG_CPU_AUTO;
561 s->params.resample_filter =
s->filter;
562 s->params.resample_filter_uv =
s->filter;
563 s->params.nominal_peak_luminance =
s->nominal_peak_luminance;
564 s->params.allow_approximate_gamma =
s->approximate_gamma;
567 s->primaries_in,
s->trc_in,
s->range_in,
s->chromal_in);
569 s->primaries,
s->trc,
s->range,
s->chromal);
571 if (
s->colorspace != -1)
572 out->colorspace = (
int)
s->dst_format.matrix_coefficients;
574 if (
s->primaries != -1)
575 out->color_primaries = (
int)
s->dst_format.color_primaries;
578 out->color_range = (
int)
s->dst_format.pixel_range + 1;
581 out->color_trc = (
int)
s->dst_format.transfer_characteristics;
583 if (
s->chromal != -1)
584 out->chroma_location = (
int)
s->dst_format.chroma_location - 1;
587 &
s->tmp, &
s->tmp_size);
591 s->in_colorspace =
in->colorspace;
592 s->in_trc =
in->color_trc;
593 s->in_primaries =
in->color_primaries;
594 s->in_range =
in->color_range;
595 s->out_colorspace =
out->colorspace;
596 s->out_trc =
out->color_trc;
597 s->out_primaries =
out->color_primaries;
598 s->out_range =
out->color_range;
601 zimg_image_format_default(&
s->alpha_src_format, ZIMG_API_VERSION);
602 zimg_image_format_default(&
s->alpha_dst_format, ZIMG_API_VERSION);
603 zimg_graph_builder_params_default(&
s->alpha_params, ZIMG_API_VERSION);
605 s->alpha_params.dither_type =
s->dither;
606 s->alpha_params.cpu_type = ZIMG_CPU_AUTO;
607 s->alpha_params.resample_filter =
s->filter;
609 s->alpha_src_format.width =
in->width;
610 s->alpha_src_format.height =
in->height;
611 s->alpha_src_format.depth =
desc->comp[0].depth;
612 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;
613 s->alpha_src_format.color_family = ZIMG_COLOR_GREY;
615 s->alpha_dst_format.width =
out->width;
616 s->alpha_dst_format.height =
out->height;
617 s->alpha_dst_format.depth = odesc->
comp[0].
depth;
619 s->alpha_dst_format.color_family = ZIMG_COLOR_GREY;
621 zimg_filter_graph_free(
s->alpha_graph);
622 s->alpha_graph = zimg_filter_graph_build(&
s->alpha_src_format, &
s->alpha_dst_format, &
s->alpha_params);
623 if (!
s->alpha_graph) {
630 if (
s->colorspace != -1)
631 out->colorspace = (
int)
s->dst_format.matrix_coefficients;
633 if (
s->primaries != -1)
634 out->color_primaries = (
int)
s->dst_format.color_primaries;
637 out->color_range = (
int)
s->dst_format.pixel_range;
640 out->color_trc = (
int)
s->dst_format.transfer_characteristics;
642 av_reduce(&
out->sample_aspect_ratio.num, &
out->sample_aspect_ratio.den,
643 (int64_t)
in->sample_aspect_ratio.num * outlink->
h *
link->w,
644 (int64_t)
in->sample_aspect_ratio.den * outlink->
w *
link->h,
649 src_buf.plane[
plane].data =
in->data[p];
650 src_buf.plane[
plane].stride =
in->linesize[p];
651 src_buf.plane[
plane].mask = -1;
654 dst_buf.plane[
plane].data =
out->data[p];
655 dst_buf.plane[
plane].stride =
out->linesize[p];
656 dst_buf.plane[
plane].mask = -1;
659 ret = zimg_filter_graph_process(
s->graph, &src_buf, &dst_buf,
s->tmp, 0, 0, 0, 0);
666 src_buf.plane[0].data =
in->data[3];
667 src_buf.plane[0].stride =
in->linesize[3];
668 src_buf.plane[0].mask = -1;
670 dst_buf.plane[0].data =
out->data[3];
671 dst_buf.plane[0].stride =
out->linesize[3];
672 dst_buf.plane[0].mask = -1;
674 ret = zimg_filter_graph_process(
s->alpha_graph, &src_buf, &dst_buf,
s->tmp, 0, 0, 0, 0);
683 for (y = 0; y <
out->height; y++) {
684 for (x = 0; x <
out->width; x++) {
690 for (y = 0; y < outlink->
h; y++)
691 memset(
out->data[3] + y *
out->linesize[3], 0xff, outlink->
w);
709 zimg_filter_graph_free(
s->graph);
710 zimg_filter_graph_free(
s->alpha_graph);
716 char *res,
int res_len,
int flags)
721 if ( !strcmp(cmd,
"width") || !strcmp(cmd,
"w")
722 || !strcmp(cmd,
"height") || !strcmp(cmd,
"h")) {
739 #define OFFSET(x) offsetof(ZScaleContext, x)
740 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
754 {
"error_diffusion", 0, 0,
AV_OPT_TYPE_CONST, {.i64 = ZIMG_DITHER_ERROR_DIFFUSION}, 0, 0,
FLAGS,
"dither" },
776 {
"unspecified", 0, 0,
AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_UNSPECIFIED}, 0, 0,
FLAGS,
"primaries" },
812 {
"iec61966-2-4", 0, 0,
AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_IEC_61966_2_4},0, 0,
FLAGS,
"transfer" },
813 {
"iec61966-2-1", 0, 0,
AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_IEC_61966_2_1},0, 0,
FLAGS,
"transfer" },
834 {
"chroma-derived-nc",0, 0,
AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_CHROMATICITY_DERIVED_NCL}, 0, 0,
FLAGS,
"matrix" },
835 {
"chroma-derived-c", 0, 0,
AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_CHROMATICITY_DERIVED_CL}, 0, 0,
FLAGS,
"matrix" },
840 {
"primariesin",
"set input color primaries",
OFFSET(primaries_in),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX,
FLAGS,
"primaries" },
842 {
"transferin",
"set input transfer characteristic",
OFFSET(trc_in),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX,
FLAGS,
"transfer" },
844 {
"matrixin",
"set input colorspace matrix",
OFFSET(colorspace_in),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX,
FLAGS,
"matrix" },
846 {
"chromal",
"set output chroma location",
OFFSET(chromal),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_CHROMA_BOTTOM,
FLAGS,
"chroma" },
847 {
"c",
"set output chroma location",
OFFSET(chromal),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_CHROMA_BOTTOM,
FLAGS,
"chroma" },
855 {
"chromalin",
"set input chroma location",
OFFSET(chromal_in),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_CHROMA_BOTTOM,
FLAGS,
"chroma" },
856 {
"cin",
"set input chroma location",
OFFSET(chromal_in),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_CHROMA_BOTTOM,
FLAGS,
"chroma" },
888 .priv_class = &zscale_class,