int ff_scale_eval_dimensions(void *log_ctx,

    const char *w_expr, const char *h_expr,

    AVFilterLink *inlink, AVFilterLink *outlink,

    int *ret_w, int *ret_h)

{

    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);

    const AVPixFmtDescriptor *out_desc = av_pix_fmt_desc_get(outlink->format);

    const char *expr;

    int w, h;

    int factor_w, factor_h;

    int eval_w, eval_h;

    int ret;

    const char scale2ref = outlink->src->nb_inputs == 2 && outlink->src->inputs[1] == inlink;

    double var_values[VARS_NB + VARS_S2R_NB], res;

    const AVPixFmtDescriptor *main_desc;

    const AVFilterLink *main_link;

    const char *const *names = scale2ref ? var_names_scale2ref : var_names;



    if (scale2ref) {

        main_link = outlink->src->inputs[0];

        main_desc = av_pix_fmt_desc_get(main_link->format);

    }



    var_values[VAR_PI]    = M_PI;

    var_values[VAR_PHI]   = M_PHI;

    var_values[VAR_E]     = M_E;

    var_values[VAR_IN_W]  = var_values[VAR_IW] = inlink->w;

    var_values[VAR_IN_H]  = var_values[VAR_IH] = inlink->h;

    var_values[VAR_OUT_W] = var_values[VAR_OW] = NAN;

    var_values[VAR_OUT_H] = var_values[VAR_OH] = NAN;

    var_values[VAR_A]     = (double) inlink->w / inlink->h;

    var_values[VAR_SAR]   = inlink->sample_aspect_ratio.num ?

        (double) inlink->sample_aspect_ratio.num / inlink->sample_aspect_ratio.den : 1;

    var_values[VAR_DAR]   = var_values[VAR_A] * var_values[VAR_SAR];

    var_values[VAR_HSUB]  = 1 << desc->log2_chroma_w;

    var_values[VAR_VSUB]  = 1 << desc->log2_chroma_h;

    var_values[VAR_OHSUB] = 1 << out_desc->log2_chroma_w;

    var_values[VAR_OVSUB] = 1 << out_desc->log2_chroma_h;



    if (scale2ref) {

        var_values[VARS_NB + VAR_S2R_MAIN_W] = main_link->w;

        var_values[VARS_NB + VAR_S2R_MAIN_H] = main_link->h;

        var_values[VARS_NB + VAR_S2R_MAIN_A] = (double) main_link->w / main_link->h;

        var_values[VARS_NB + VAR_S2R_MAIN_SAR] = main_link->sample_aspect_ratio.num ?

            (double) main_link->sample_aspect_ratio.num / main_link->sample_aspect_ratio.den : 1;

        var_values[VARS_NB + VAR_S2R_MAIN_DAR] = var_values[VARS_NB + VAR_S2R_MDAR] =

            var_values[VARS_NB + VAR_S2R_MAIN_A] * var_values[VARS_NB + VAR_S2R_MAIN_SAR];

        var_values[VARS_NB + VAR_S2R_MAIN_HSUB] = 1 << main_desc->log2_chroma_w;

        var_values[VARS_NB + VAR_S2R_MAIN_VSUB] = 1 << main_desc->log2_chroma_h;

    }



    /* evaluate width and height */

    av_expr_parse_and_eval(&res, (expr = w_expr),

                           names, var_values,

                           NULL, NULL, NULL, NULL, NULL, 0, log_ctx);

    eval_w = var_values[VAR_OUT_W] = var_values[VAR_OW] = res;



    if ((ret = av_expr_parse_and_eval(&res, (expr = h_expr),

                                      names, var_values,

                                      NULL, NULL, NULL, NULL, NULL, 0, log_ctx)) < 0)

        goto fail;

    eval_h = var_values[VAR_OUT_H] = var_values[VAR_OH] = res;

    /* evaluate again the width, as it may depend on the output height */

    if ((ret = av_expr_parse_and_eval(&res, (expr = w_expr),

                                      names, var_values,

                                      NULL, NULL, NULL, NULL, NULL, 0, log_ctx)) < 0)

        goto fail;

    eval_w = res;



    w = eval_w;

    h = eval_h;



    /* Check if it is requested that the result has to be divisible by a some

     * factor (w or h = -n with n being the factor). */

    factor_w = 1;

    factor_h = 1;

    if (w < -1) {

        factor_w = -w;

    }

    if (h < -1) {

        factor_h = -h;

    }



    if (w < 0 && h < 0)

        eval_w = eval_h = 0;



    if (!(w = eval_w))

        w = inlink->w;

    if (!(h = eval_h))

        h = inlink->h;



    /* Make sure that the result is divisible by the factor we determined

     * earlier. If no factor was set, it is nothing will happen as the default

     * factor is 1 */

    if (w < 0)

        w = av_rescale(h, inlink->w, inlink->h * factor_w) * factor_w;

    if (h < 0)

        h = av_rescale(w, inlink->h, inlink->w * factor_h) * factor_h;



    *ret_w = w;

    *ret_h = h;



    return 0;



fail:

    av_log(log_ctx, AV_LOG_ERROR,

           "Error when evaluating the expression '%s'.\n"

           "Maybe the expression for out_w:'%s' or for out_h:'%s' is self-referencing.\n",

           expr, w_expr, h_expr);

    return ret;

}

int ff_scale_eval_dimensions(void *log_ctx,

    const char *w_expr, const char *h_expr,

    AVFilterLink *inlink, AVFilterLink *outlink,

    int *ret_w, int *ret_h)

{

    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);

    const AVPixFmtDescriptor *out_desc = av_pix_fmt_desc_get(outlink->format);

    const char *expr;

    int w, h;

    int factor_w, factor_h;

    int eval_w, eval_h;

    int ret;

    const char scale2ref = outlink->src->nb_inputs == 2 && outlink->src->inputs[1] == inlink;

    double var_values[VARS_NB + VARS_S2R_NB], res;

    const AVPixFmtDescriptor *main_desc;

    const AVFilterLink *main_link;

    const char *const *names = scale2ref ? var_names_scale2ref : var_names;



    if (scale2ref) {

        main_link = outlink->src->inputs[0];

        main_desc = av_pix_fmt_desc_get(main_link->format);

    }



    var_values[VAR_PI]    = M_PI;

    var_values[VAR_PHI]   = M_PHI;

    var_values[VAR_E]     = M_E;

    var_values[VAR_IN_W]  = var_values[VAR_IW] = inlink->w;

    var_values[VAR_IN_H]  = var_values[VAR_IH] = inlink->h;

    var_values[VAR_OUT_W] = var_values[VAR_OW] = NAN;

    var_values[VAR_OUT_H] = var_values[VAR_OH] = NAN;

    var_values[VAR_A]     = (double) inlink->w / inlink->h;

    var_values[VAR_SAR]   = inlink->sample_aspect_ratio.num ?

        (double) inlink->sample_aspect_ratio.num / inlink->sample_aspect_ratio.den : 1;

    var_values[VAR_DAR]   = var_values[VAR_A] * var_values[VAR_SAR];

    var_values[VAR_HSUB]  = 1 << desc->log2_chroma_w;

    var_values[VAR_VSUB]  = 1 << desc->log2_chroma_h;

    var_values[VAR_OHSUB] = 1 << out_desc->log2_chroma_w;

    var_values[VAR_OVSUB] = 1 << out_desc->log2_chroma_h;



    if (scale2ref) {

        var_values[VARS_NB + VAR_S2R_MAIN_W] = main_link->w;

        var_values[VARS_NB + VAR_S2R_MAIN_H] = main_link->h;

        var_values[VARS_NB + VAR_S2R_MAIN_A] = (double) main_link->w / main_link->h;

        var_values[VARS_NB + VAR_S2R_MAIN_SAR] = main_link->sample_aspect_ratio.num ?

            (double) main_link->sample_aspect_ratio.num / main_link->sample_aspect_ratio.den : 1;

        var_values[VARS_NB + VAR_S2R_MAIN_DAR] = var_values[VARS_NB + VAR_S2R_MDAR] =

            var_values[VARS_NB + VAR_S2R_MAIN_A] * var_values[VARS_NB + VAR_S2R_MAIN_SAR];

        var_values[VARS_NB + VAR_S2R_MAIN_HSUB] = 1 << main_desc->log2_chroma_w;

        var_values[VARS_NB + VAR_S2R_MAIN_VSUB] = 1 << main_desc->log2_chroma_h;

    }



    

    av_expr_parse_and_eval(&res, (expr = w_expr),

                           names, var_values,

                           NULL, NULL, NULL, NULL, NULL, 0, log_ctx);

    eval_w = var_values[VAR_OUT_W] = var_values[VAR_OW] = res;



    if ((ret = av_expr_parse_and_eval(&res, (expr = h_expr),

                                      names, var_values,

                                      NULL, NULL, NULL, NULL, NULL, 0, log_ctx)) < 0)

        goto fail;

    eval_h = var_values[VAR_OUT_H] = var_values[VAR_OH] = res;

    

    if ((ret = av_expr_parse_and_eval(&res, (expr = w_expr),

                                      names, var_values,

                                      NULL, NULL, NULL, NULL, NULL, 0, log_ctx)) < 0)

        goto fail;

    eval_w = res;



    w = eval_w;

    h = eval_h;



    



    factor_w = 1;

    factor_h = 1;

    if (w < -1) {

        factor_w = -w;

    }

    if (h < -1) {

        factor_h = -h;

    }



    if (w < 0 && h < 0)

        eval_w = eval_h = 0;



    if (!(w = eval_w))

        w = inlink->w;

    if (!(h = eval_h))

        h = inlink->h;



    





    if (w < 0)

        w = av_rescale(h, inlink->w, inlink->h * factor_w) * factor_w;

    if (h < 0)

        h = av_rescale(w, inlink->h, inlink->w * factor_h) * factor_h;



    *ret_w = w;

    *ret_h = h;



    return 0;



fail:

    av_log(log_ctx, AV_LOG_ERROR,

           "Error when evaluating the expression '%s'.\n"

           "Maybe the expression for out_w:'%s' or for out_h:'%s' is self-referencing.\n",

           expr, w_expr, h_expr);

    return ret;

}

int FUNC_0(void *VAR_0,

    const char *VAR_1, const char *VAR_2,

    AVFilterLink *VAR_3, AVFilterLink *VAR_4,

    int *VAR_5, int *VAR_6)

{

    const AVPixFmtDescriptor *VAR_7 = av_pix_fmt_desc_get(VAR_3->format);

    const AVPixFmtDescriptor *VAR_8 = av_pix_fmt_desc_get(VAR_4->format);

    const char *VAR_9;

    int VAR_10, VAR_11;

    int VAR_12, VAR_13;

    int VAR_14, VAR_15;

    int VAR_16;

    const char VAR_17 = VAR_4->src->nb_inputs == 2 && VAR_4->src->inputs[1] == VAR_3;

    double VAR_18[VARS_NB + VARS_S2R_NB], res;

    const AVPixFmtDescriptor *VAR_19;

    const AVFilterLink *VAR_20;

    const char *const *VAR_21 = VAR_17 ? var_names_scale2ref : var_names;



    if (VAR_17) {

        VAR_20 = VAR_4->src->inputs[0];

        VAR_19 = av_pix_fmt_desc_get(VAR_20->format);

    }



    VAR_18[VAR_PI]    = M_PI;

    VAR_18[VAR_PHI]   = M_PHI;

    VAR_18[VAR_E]     = M_E;

    VAR_18[VAR_IN_W]  = VAR_18[VAR_IW] = VAR_3->VAR_10;

    VAR_18[VAR_IN_H]  = VAR_18[VAR_IH] = VAR_3->VAR_11;

    VAR_18[VAR_OUT_W] = VAR_18[VAR_OW] = NAN;

    VAR_18[VAR_OUT_H] = VAR_18[VAR_OH] = NAN;

    VAR_18[VAR_A]     = (double) VAR_3->VAR_10 / VAR_3->VAR_11;

    VAR_18[VAR_SAR]   = VAR_3->sample_aspect_ratio.num ?

        (double) VAR_3->sample_aspect_ratio.num / VAR_3->sample_aspect_ratio.den : 1;

    VAR_18[VAR_DAR]   = VAR_18[VAR_A] * VAR_18[VAR_SAR];

    VAR_18[VAR_HSUB]  = 1 << VAR_7->log2_chroma_w;

    VAR_18[VAR_VSUB]  = 1 << VAR_7->log2_chroma_h;

    VAR_18[VAR_OHSUB] = 1 << VAR_8->log2_chroma_w;

    VAR_18[VAR_OVSUB] = 1 << VAR_8->log2_chroma_h;



    if (VAR_17) {

        VAR_18[VARS_NB + VAR_S2R_MAIN_W] = VAR_20->VAR_10;

        VAR_18[VARS_NB + VAR_S2R_MAIN_H] = VAR_20->VAR_11;

        VAR_18[VARS_NB + VAR_S2R_MAIN_A] = (double) VAR_20->VAR_10 / VAR_20->VAR_11;

        VAR_18[VARS_NB + VAR_S2R_MAIN_SAR] = VAR_20->sample_aspect_ratio.num ?

            (double) VAR_20->sample_aspect_ratio.num / VAR_20->sample_aspect_ratio.den : 1;

        VAR_18[VARS_NB + VAR_S2R_MAIN_DAR] = VAR_18[VARS_NB + VAR_S2R_MDAR] =

            VAR_18[VARS_NB + VAR_S2R_MAIN_A] * VAR_18[VARS_NB + VAR_S2R_MAIN_SAR];

        VAR_18[VARS_NB + VAR_S2R_MAIN_HSUB] = 1 << VAR_19->log2_chroma_w;

        VAR_18[VARS_NB + VAR_S2R_MAIN_VSUB] = 1 << VAR_19->log2_chroma_h;

    }



    

    av_expr_parse_and_eval(&res, (VAR_9 = VAR_1),

                           VAR_21, VAR_18,

                           NULL, NULL, NULL, NULL, NULL, 0, VAR_0);

    VAR_14 = VAR_18[VAR_OUT_W] = VAR_18[VAR_OW] = res;



    if ((VAR_16 = av_expr_parse_and_eval(&res, (VAR_9 = VAR_2),

                                      VAR_21, VAR_18,

                                      NULL, NULL, NULL, NULL, NULL, 0, VAR_0)) < 0)

        goto fail;

    VAR_15 = VAR_18[VAR_OUT_H] = VAR_18[VAR_OH] = res;

    

    if ((VAR_16 = av_expr_parse_and_eval(&res, (VAR_9 = VAR_1),

                                      VAR_21, VAR_18,

                                      NULL, NULL, NULL, NULL, NULL, 0, VAR_0)) < 0)

        goto fail;

    VAR_14 = res;



    VAR_10 = VAR_14;

    VAR_11 = VAR_15;



    



    VAR_12 = 1;

    VAR_13 = 1;

    if (VAR_10 < -1) {

        VAR_12 = -VAR_10;

    }

    if (VAR_11 < -1) {

        VAR_13 = -VAR_11;

    }



    if (VAR_10 < 0 && VAR_11 < 0)

        VAR_14 = VAR_15 = 0;



    if (!(VAR_10 = VAR_14))

        VAR_10 = VAR_3->VAR_10;

    if (!(VAR_11 = VAR_15))

        VAR_11 = VAR_3->VAR_11;



    





    if (VAR_10 < 0)

        VAR_10 = av_rescale(VAR_11, VAR_3->VAR_10, VAR_3->VAR_11 * VAR_12) * VAR_12;

    if (VAR_11 < 0)

        VAR_11 = av_rescale(VAR_10, VAR_3->VAR_11, VAR_3->VAR_10 * VAR_13) * VAR_13;



    *VAR_5 = VAR_10;

    *VAR_6 = VAR_11;



    return 0;



fail:

    av_log(VAR_0, AV_LOG_ERROR,

           "Error when evaluating the expression '%s'.\n"

           "Maybe the expression for out_w:'%s' or for out_h:'%s' is self-referencing.\n",

           VAR_9, VAR_1, VAR_2);

    return VAR_16;

}

int FUNC_0(void *VAR_0,
const char *VAR_1, const char *VAR_2,
AVFilterLink *VAR_3, AVFilterLink *VAR_4,
int *VAR_5, int *VAR_6)
{ const AVPixFmtDescriptor *VAR_7 = av_pix_fmt_desc_get(VAR_3->format); const AVPixFmtDescriptor *VAR_8 = av_pix_fmt_desc_get(VAR_4->format); const char *VAR_9; int VAR_10, VAR_11; int VAR_12, VAR_13; int VAR_14, VAR_15; int VAR_16; const char VAR_17 = VAR_4->src->nb_inputs == 2 && VAR_4->src->inputs[1] == VAR_3; double VAR_18[VARS_NB + VARS_S2R_NB], res; const AVPixFmtDescriptor *VAR_19; const AVFilterLink *VAR_20; const char *const *VAR_21 = VAR_17 ? var_names_scale2ref : var_names; if (VAR_17) { VAR_20 = VAR_4->src->inputs[0]; VAR_19 = av_pix_fmt_desc_get(VAR_20->format); } VAR_18[VAR_PI]    = M_PI; VAR_18[VAR_PHI]   = M_PHI; VAR_18[VAR_E]     = M_E; VAR_18[VAR_IN_W]  = VAR_18[VAR_IW] = VAR_3->VAR_10; VAR_18[VAR_IN_H]  = VAR_18[VAR_IH] = VAR_3->VAR_11; VAR_18[VAR_OUT_W] = VAR_18[VAR_OW] = NAN; VAR_18[VAR_OUT_H] = VAR_18[VAR_OH] = NAN; VAR_18[VAR_A]     = (double) VAR_3->VAR_10 / VAR_3->VAR_11; VAR_18[VAR_SAR]   = VAR_3->sample_aspect_ratio.num ?
(double) VAR_3->sample_aspect_ratio.num / VAR_3->sample_aspect_ratio.den : 1; VAR_18[VAR_DAR]   = VAR_18[VAR_A] * VAR_18[VAR_SAR]; VAR_18[VAR_HSUB]  = 1 << VAR_7->log2_chroma_w; VAR_18[VAR_VSUB]  = 1 << VAR_7->log2_chroma_h; VAR_18[VAR_OHSUB] = 1 << VAR_8->log2_chroma_w; VAR_18[VAR_OVSUB] = 1 << VAR_8->log2_chroma_h; if (VAR_17) { VAR_18[VARS_NB + VAR_S2R_MAIN_W] = VAR_20->VAR_10; VAR_18[VARS_NB + VAR_S2R_MAIN_H] = VAR_20->VAR_11; VAR_18[VARS_NB + VAR_S2R_MAIN_A] = (double) VAR_20->VAR_10 / VAR_20->VAR_11; VAR_18[VARS_NB + VAR_S2R_MAIN_SAR] = VAR_20->sample_aspect_ratio.num ?
(double) VAR_20->sample_aspect_ratio.num / VAR_20->sample_aspect_ratio.den : 1; VAR_18[VARS_NB + VAR_S2R_MAIN_DAR] = VAR_18[VARS_NB + VAR_S2R_MDAR] =
VAR_18[VARS_NB + VAR_S2R_MAIN_A] * VAR_18[VARS_NB + VAR_S2R_MAIN_SAR]; VAR_18[VARS_NB + VAR_S2R_MAIN_HSUB] = 1 << VAR_19->log2_chroma_w; VAR_18[VARS_NB + VAR_S2R_MAIN_VSUB] = 1 << VAR_19->log2_chroma_h; } av_expr_parse_and_eval(&res, (VAR_9 = VAR_1),
VAR_21, VAR_18,
NULL, NULL, NULL, NULL, NULL, 0, VAR_0); VAR_14 = VAR_18[VAR_OUT_W] = VAR_18[VAR_OW] = res; if ((VAR_16 = av_expr_parse_and_eval(&res, (VAR_9 = VAR_2),
VAR_21, VAR_18,
NULL, NULL, NULL, NULL, NULL, 0, VAR_0)) < 0)
goto fail; VAR_15 = VAR_18[VAR_OUT_H] = VAR_18[VAR_OH] = res; if ((VAR_16 = av_expr_parse_and_eval(&res, (VAR_9 = VAR_1),
VAR_21, VAR_18,
NULL, NULL, NULL, NULL, NULL, 0, VAR_0)) < 0)
goto fail; VAR_14 = res; VAR_10 = VAR_14; VAR_11 = VAR_15; VAR_12 = 1; VAR_13 = 1; if (VAR_10 < -1) { VAR_12 = -VAR_10; } if (VAR_11 < -1) { VAR_13 = -VAR_11; } if (VAR_10 < 0 && VAR_11 < 0)
VAR_14 = VAR_15 = 0; if (!(VAR_10 = VAR_14))
VAR_10 = VAR_3->VAR_10; if (!(VAR_11 = VAR_15))
VAR_11 = VAR_3->VAR_11; if (VAR_10 < 0)
VAR_10 = av_rescale(VAR_11, VAR_3->VAR_10, VAR_3->VAR_11 * VAR_12) * VAR_12; if (VAR_11 < 0)
VAR_11 = av_rescale(VAR_10, VAR_3->VAR_11, VAR_3->VAR_10 * VAR_13) * VAR_13; *VAR_5 = VAR_10; *VAR_6 = VAR_11; return 0; fail:
av_log(VAR_0, AV_LOG_ERROR,
"Error when evaluating the expression '%s'.\n"
"Maybe the expression for out_w:'%s' or for out_h:'%s' is self-referencing.\n",
VAR_9, VAR_1, VAR_2); return VAR_16; }