void copy_picture_field(TInterlaceContext *tinterlace,

                        uint8_t *dst[4], int dst_linesize[4],

                        const uint8_t *src[4], int src_linesize[4],

                        enum AVPixelFormat format, int w, int src_h,

                        int src_field, int interleave, int dst_field,

                        int flags)

{

    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(format);

    int hsub = desc->log2_chroma_w;

    int plane, vsub = desc->log2_chroma_h;

    int k = src_field == FIELD_UPPER_AND_LOWER ? 1 : 2;

    int h;



    for (plane = 0; plane < desc->nb_components; plane++) {

        int lines = plane == 1 || plane == 2 ? AV_CEIL_RSHIFT(src_h, vsub) : src_h;

        int cols  = plane == 1 || plane == 2 ? AV_CEIL_RSHIFT(    w, hsub) : w;

        uint8_t *dstp = dst[plane];

        const uint8_t *srcp = src[plane];

        int srcp_linesize = src_linesize[plane] * k;

        int dstp_linesize = dst_linesize[plane] * (interleave ? 2 : 1);



        lines = (lines + (src_field == FIELD_UPPER)) / k;

        if (src_field == FIELD_LOWER)

            srcp += src_linesize[plane];

        if (interleave && dst_field == FIELD_LOWER)

            dstp += dst_linesize[plane];

        // Low-pass filtering is required when creating an interlaced destination from

        // a progressive source which contains high-frequency vertical detail.

        // Filtering will reduce interlace 'twitter' and Moire patterning.

        if (flags & TINTERLACE_FLAG_VLPF || flags & TINTERLACE_FLAG_CVLPF) {

            int x = 0;

            if (flags & TINTERLACE_FLAG_CVLPF)

                x = 1;

            for (h = lines; h > 0; h--) {

                ptrdiff_t pref = src_linesize[plane];

                ptrdiff_t mref = -pref;

                if (h >= (lines - x))  mref = 0; // there is no line above

                else if (h <= (1 + x)) pref = 0; // there is no line below



                tinterlace->lowpass_line(dstp, cols, srcp, mref, pref);

                dstp += dstp_linesize;

                srcp += srcp_linesize;

            }

        } else {

            av_image_copy_plane(dstp, dstp_linesize, srcp, srcp_linesize, cols, lines);

        }

    }

}

void copy_picture_field(TInterlaceContext *tinterlace,

                        uint8_t *dst[4], int dst_linesize[4],

                        const uint8_t *src[4], int src_linesize[4],

                        enum AVPixelFormat format, int w, int src_h,

                        int src_field, int interleave, int dst_field,

                        int flags)

{

    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(format);

    int hsub = desc->log2_chroma_w;

    int plane, vsub = desc->log2_chroma_h;

    int k = src_field == FIELD_UPPER_AND_LOWER ? 1 : 2;

    int h;



    for (plane = 0; plane < desc->nb_components; plane++) {

        int lines = plane == 1 || plane == 2 ? AV_CEIL_RSHIFT(src_h, vsub) : src_h;

        int cols  = plane == 1 || plane == 2 ? AV_CEIL_RSHIFT(    w, hsub) : w;

        uint8_t *dstp = dst[plane];

        const uint8_t *srcp = src[plane];

        int srcp_linesize = src_linesize[plane] * k;

        int dstp_linesize = dst_linesize[plane] * (interleave ? 2 : 1);



        lines = (lines + (src_field == FIELD_UPPER)) / k;

        if (src_field == FIELD_LOWER)

            srcp += src_linesize[plane];

        if (interleave && dst_field == FIELD_LOWER)

            dstp += dst_linesize[plane];

        

        

        

        if (flags & TINTERLACE_FLAG_VLPF || flags & TINTERLACE_FLAG_CVLPF) {

            int x = 0;

            if (flags & TINTERLACE_FLAG_CVLPF)

                x = 1;

            for (h = lines; h > 0; h--) {

                ptrdiff_t pref = src_linesize[plane];

                ptrdiff_t mref = -pref;

                if (h >= (lines - x))  mref = 0; 

                else if (h <= (1 + x)) pref = 0; 



                tinterlace->lowpass_line(dstp, cols, srcp, mref, pref);

                dstp += dstp_linesize;

                srcp += srcp_linesize;

            }

        } else {

            av_image_copy_plane(dstp, dstp_linesize, srcp, srcp_linesize, cols, lines);

        }

    }

}

void FUNC_0(TInterlaceContext *VAR_0,

                        uint8_t *VAR_1[4], int VAR_2[4],

                        const uint8_t *VAR_3[4], int VAR_4[4],

                        enum AVPixelFormat VAR_5, int VAR_6, int VAR_7,

                        int VAR_8, int VAR_9, int VAR_10,

                        int VAR_11)

{

    const AVPixFmtDescriptor *VAR_12 = av_pix_fmt_desc_get(VAR_5);

    int VAR_13 = VAR_12->log2_chroma_w;

    int VAR_14, VAR_15 = VAR_12->log2_chroma_h;

    int VAR_16 = VAR_8 == FIELD_UPPER_AND_LOWER ? 1 : 2;

    int VAR_17;



    for (VAR_14 = 0; VAR_14 < VAR_12->nb_components; VAR_14++) {

        int lines = VAR_14 == 1 || VAR_14 == 2 ? AV_CEIL_RSHIFT(VAR_7, VAR_15) : VAR_7;

        int cols  = VAR_14 == 1 || VAR_14 == 2 ? AV_CEIL_RSHIFT(    VAR_6, VAR_13) : VAR_6;

        uint8_t *dstp = VAR_1[VAR_14];

        const uint8_t *srcp = VAR_3[VAR_14];

        int srcp_linesize = VAR_4[VAR_14] * VAR_16;

        int dstp_linesize = VAR_2[VAR_14] * (VAR_9 ? 2 : 1);



        lines = (lines + (VAR_8 == FIELD_UPPER)) / VAR_16;

        if (VAR_8 == FIELD_LOWER)

            srcp += VAR_4[VAR_14];

        if (VAR_9 && VAR_10 == FIELD_LOWER)

            dstp += VAR_2[VAR_14];

        

        

        

        if (VAR_11 & TINTERLACE_FLAG_VLPF || VAR_11 & TINTERLACE_FLAG_CVLPF) {

            int x = 0;

            if (VAR_11 & TINTERLACE_FLAG_CVLPF)

                x = 1;

            for (VAR_17 = lines; VAR_17 > 0; VAR_17--) {

                ptrdiff_t pref = VAR_4[VAR_14];

                ptrdiff_t mref = -pref;

                if (VAR_17 >= (lines - x))  mref = 0; 

                else if (VAR_17 <= (1 + x)) pref = 0; 



                VAR_0->lowpass_line(dstp, cols, srcp, mref, pref);

                dstp += dstp_linesize;

                srcp += srcp_linesize;

            }

        } else {

            av_image_copy_plane(dstp, dstp_linesize, srcp, srcp_linesize, cols, lines);

        }

    }

}

void FUNC_0(TInterlaceContext *VAR_0,
uint8_t *VAR_1[4], int VAR_2[4],
const uint8_t *VAR_3[4], int VAR_4[4],
enum AVPixelFormat VAR_5, int VAR_6, int VAR_7,
int VAR_8, int VAR_9, int VAR_10,
int VAR_11)
{ const AVPixFmtDescriptor *VAR_12 = av_pix_fmt_desc_get(VAR_5); int VAR_13 = VAR_12->log2_chroma_w; int VAR_14, VAR_15 = VAR_12->log2_chroma_h; int VAR_16 = VAR_8 == FIELD_UPPER_AND_LOWER ? 1 : 2; int VAR_17; for (VAR_14 = 0; VAR_14 < VAR_12->nb_components; VAR_14++) { int lines = VAR_14 == 1 || VAR_14 == 2 ? AV_CEIL_RSHIFT(VAR_7, VAR_15) : VAR_7; int cols  = VAR_14 == 1 || VAR_14 == 2 ? AV_CEIL_RSHIFT(    VAR_6, VAR_13) : VAR_6; uint8_t *dstp = VAR_1[VAR_14]; const uint8_t *srcp = VAR_3[VAR_14]; int srcp_linesize = VAR_4[VAR_14] * VAR_16; int dstp_linesize = VAR_2[VAR_14] * (VAR_9 ? 2 : 1); lines = (lines + (VAR_8 == FIELD_UPPER)) / VAR_16; if (VAR_8 == FIELD_LOWER)
srcp += VAR_4[VAR_14]; if (VAR_9 && VAR_10 == FIELD_LOWER)
dstp += VAR_2[VAR_14]; if (VAR_11 & TINTERLACE_FLAG_VLPF || VAR_11 & TINTERLACE_FLAG_CVLPF) { int x = 0; if (VAR_11 & TINTERLACE_FLAG_CVLPF)
x = 1; for (VAR_17 = lines; VAR_17 > 0; VAR_17--) { ptrdiff_t pref = VAR_4[VAR_14]; ptrdiff_t mref = -pref; if (VAR_17 >= (lines - x))  mref = 0; else if (VAR_17 <= (1 + x)) pref = 0; VAR_0->lowpass_line(dstp, cols, srcp, mref, pref); dstp += dstp_linesize; srcp += srcp_linesize; } } else { av_image_copy_plane(dstp, dstp_linesize, srcp, srcp_linesize, cols, lines); } } }