static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *in)

{

    HQDN3DContext *hqdn3d = inlink->dst->priv;

    AVFilterLink *outlink = inlink->dst->outputs[0];



    AVFilterBufferRef *out;

    int direct, c;



    if (in->perms & AV_PERM_WRITE) {

        direct = 1;

        out = in;

    } else {

        out = ff_get_video_buffer(outlink, AV_PERM_WRITE, outlink->w, outlink->h);

        if (!out) {

            avfilter_unref_bufferp(&in);

            return AVERROR(ENOMEM);

        }



        avfilter_copy_buffer_ref_props(out, in);

        out->video->w = outlink->w;

        out->video->h = outlink->h;

    }



    for (c = 0; c < 3; c++) {

        denoise(hqdn3d, in->data[c], out->data[c],

                hqdn3d->line, &hqdn3d->frame_prev[c],

                in->video->w >> (!!c * hqdn3d->hsub),

                in->video->h >> (!!c * hqdn3d->vsub),

                in->linesize[c], out->linesize[c],

                hqdn3d->coefs[c?2:0], hqdn3d->coefs[c?3:1]);

    }



    if (!direct)

        avfilter_unref_bufferp(&in);



    return ff_filter_frame(outlink, out);

}

static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *in)

{

    HQDN3DContext *hqdn3d = inlink->dst->priv;

    AVFilterLink *outlink = inlink->dst->outputs[0];



    AVFilterBufferRef *out;

    int direct, c;



    if (in->perms & AV_PERM_WRITE) {

        direct = 1;

        out = in;

    } else {

        out = ff_get_video_buffer(outlink, AV_PERM_WRITE, outlink->w, outlink->h);

        if (!out) {

            avfilter_unref_bufferp(&in);

            return AVERROR(ENOMEM);

        }



        avfilter_copy_buffer_ref_props(out, in);

        out->video->w = outlink->w;

        out->video->h = outlink->h;

    }



    for (c = 0; c < 3; c++) {

        denoise(hqdn3d, in->data[c], out->data[c],

                hqdn3d->line, &hqdn3d->frame_prev[c],

                in->video->w >> (!!c * hqdn3d->hsub),

                in->video->h >> (!!c * hqdn3d->vsub),

                in->linesize[c], out->linesize[c],

                hqdn3d->coefs[c?2:0], hqdn3d->coefs[c?3:1]);

    }



    if (!direct)

        avfilter_unref_bufferp(&in);



    return ff_filter_frame(outlink, out);

}

    int direct, c;
static int FUNC_0(AVFilterLink *VAR_0, AVFilterBufferRef *VAR_1)

{

    HQDN3DContext *hqdn3d = VAR_0->dst->priv;

    AVFilterLink *outlink = VAR_0->dst->outputs[0];



    AVFilterBufferRef *out;

    int VAR_2, VAR_3;



    if (VAR_1->perms & AV_PERM_WRITE) {

        VAR_2 = 1;

        out = VAR_1;

    } else {

        out = ff_get_video_buffer(outlink, AV_PERM_WRITE, outlink->w, outlink->h);

        if (!out) {

            avfilter_unref_bufferp(&VAR_1);

            return AVERROR(ENOMEM);

        }



        avfilter_copy_buffer_ref_props(out, VAR_1);

        out->video->w = outlink->w;

        out->video->h = outlink->h;

    }



    for (VAR_3 = 0; VAR_3 < 3; VAR_3++) {

        denoise(hqdn3d, VAR_1->data[VAR_3], out->data[VAR_3],

                hqdn3d->line, &hqdn3d->frame_prev[VAR_3],

                VAR_1->video->w >> (!!VAR_3 * hqdn3d->hsub),

                VAR_1->video->h >> (!!VAR_3 * hqdn3d->vsub),

                VAR_1->linesize[VAR_3], out->linesize[VAR_3],

                hqdn3d->coefs[VAR_3?2:0], hqdn3d->coefs[VAR_3?3:1]);

    }



    if (!VAR_2)

        avfilter_unref_bufferp(&VAR_1);



    return ff_filter_frame(outlink, out);

}

static int FUNC_0(AVFilterLink *VAR_0, AVFilterBufferRef *VAR_1)
{ HQDN3DContext *hqdn3d = VAR_0->dst->priv; AVFilterLink *outlink = VAR_0->dst->outputs[0]; AVFilterBufferRef *out; int VAR_2, VAR_3; if (VAR_1->perms & AV_PERM_WRITE) { VAR_2 = 1; out = VAR_1; } else { out = ff_get_video_buffer(outlink, AV_PERM_WRITE, outlink->w, outlink->h); if (!out) { avfilter_unref_bufferp(&VAR_1); return AVERROR(ENOMEM); } avfilter_copy_buffer_ref_props(out, VAR_1); out->video->w = outlink->w; out->video->h = outlink->h; } for (VAR_3 = 0; VAR_3 < 3; VAR_3++) { denoise(hqdn3d, VAR_1->data[VAR_3], out->data[VAR_3],
hqdn3d->line, &hqdn3d->frame_prev[VAR_3],
VAR_1->video->w >> (!!VAR_3 * hqdn3d->hsub),
VAR_1->video->h >> (!!VAR_3 * hqdn3d->vsub),
VAR_1->linesize[VAR_3], out->linesize[VAR_3],
hqdn3d->coefs[VAR_3?2:0], hqdn3d->coefs[VAR_3?3:1]); } if (!VAR_2)
avfilter_unref_bufferp(&VAR_1); return ff_filter_frame(outlink, out); }