int avpicture_layout(const AVPicture* src, enum AVPixelFormat pix_fmt,

                     int width, int height,

                     unsigned char *dest, int dest_size)

{

    int i, j, nb_planes = 0, linesizes[4];

    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);

    int size = avpicture_get_size(pix_fmt, width, height);



    if (size > dest_size || size < 0)

        return AVERROR(EINVAL);



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

        nb_planes = FFMAX(desc->comp[i].plane, nb_planes);



    nb_planes++;



    av_image_fill_linesizes(linesizes, pix_fmt, width);

    for (i = 0; i < nb_planes; i++) {

        int h, shift = (i == 1 || i == 2) ? desc->log2_chroma_h : 0;

        const unsigned char *s = src->data[i];

        h = (height + (1 << shift) - 1) >> shift;



        for (j = 0; j < h; j++) {

            memcpy(dest, s, linesizes[i]);

            dest += linesizes[i];

            s += src->linesize[i];

        }

    }



    if (desc->flags & AV_PIX_FMT_FLAG_PAL)

        memcpy((unsigned char *)(((size_t)dest + 3) & ~3),

               src->data[1], 256 * 4);



    return size;

}

int avpicture_layout(const AVPicture* src, enum AVPixelFormat pix_fmt,

                     int width, int height,

                     unsigned char *dest, int dest_size)

{

    int i, j, nb_planes = 0, linesizes[4];

    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);

    int size = avpicture_get_size(pix_fmt, width, height);



    if (size > dest_size || size < 0)

        return AVERROR(EINVAL);



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

        nb_planes = FFMAX(desc->comp[i].plane, nb_planes);



    nb_planes++;



    av_image_fill_linesizes(linesizes, pix_fmt, width);

    for (i = 0; i < nb_planes; i++) {

        int h, shift = (i == 1 || i == 2) ? desc->log2_chroma_h : 0;

        const unsigned char *s = src->data[i];

        h = (height + (1 << shift) - 1) >> shift;



        for (j = 0; j < h; j++) {

            memcpy(dest, s, linesizes[i]);

            dest += linesizes[i];

            s += src->linesize[i];

        }

    }



    if (desc->flags & AV_PIX_FMT_FLAG_PAL)

        memcpy((unsigned char *)(((size_t)dest + 3) & ~3),

               src->data[1], 256 * 4);



    return size;

}

int FUNC_0(const AVPicture* VAR_0, enum AVPixelFormat VAR_1,

                     int VAR_2, int VAR_3,

                     unsigned char *VAR_4, int VAR_5)

{

    int VAR_6, VAR_7, VAR_8 = 0, VAR_9[4];

    const AVPixFmtDescriptor *VAR_10 = av_pix_fmt_desc_get(VAR_1);

    int VAR_11 = avpicture_get_size(VAR_1, VAR_2, VAR_3);



    if (VAR_11 > VAR_5 || VAR_11 < 0)

        return AVERROR(EINVAL);



    for (VAR_6 = 0; VAR_6 < VAR_10->nb_components; VAR_6++)

        VAR_8 = FFMAX(VAR_10->comp[VAR_6].plane, VAR_8);



    VAR_8++;



    av_image_fill_linesizes(VAR_9, VAR_1, VAR_2);

    for (VAR_6 = 0; VAR_6 < VAR_8; VAR_6++) {

        int VAR_12, VAR_13 = (VAR_6 == 1 || VAR_6 == 2) ? VAR_10->log2_chroma_h : 0;

        const unsigned char *VAR_14 = VAR_0->data[VAR_6];

        VAR_12 = (VAR_3 + (1 << VAR_13) - 1) >> VAR_13;



        for (VAR_7 = 0; VAR_7 < VAR_12; VAR_7++) {

            memcpy(VAR_4, VAR_14, VAR_9[VAR_6]);

            VAR_4 += VAR_9[VAR_6];

            VAR_14 += VAR_0->linesize[VAR_6];

        }

    }



    if (VAR_10->flags & AV_PIX_FMT_FLAG_PAL)

        memcpy((unsigned char *)(((size_t)VAR_4 + 3) & ~3),

               VAR_0->data[1], 256 * 4);



    return VAR_11;

}

int FUNC_0(const AVPicture* VAR_0, enum AVPixelFormat VAR_1,
int VAR_2, int VAR_3,
unsigned char *VAR_4, int VAR_5)
{ int VAR_6, VAR_7, VAR_8 = 0, VAR_9[4]; const AVPixFmtDescriptor *VAR_10 = av_pix_fmt_desc_get(VAR_1); int VAR_11 = avpicture_get_size(VAR_1, VAR_2, VAR_3); if (VAR_11 > VAR_5 || VAR_11 < 0)
return AVERROR(EINVAL); for (VAR_6 = 0; VAR_6 < VAR_10->nb_components; VAR_6++) VAR_8 = FFMAX(VAR_10->comp[VAR_6].plane, VAR_8); VAR_8++; av_image_fill_linesizes(VAR_9, VAR_1, VAR_2); for (VAR_6 = 0; VAR_6 < VAR_8; VAR_6++) { int VAR_12, VAR_13 = (VAR_6 == 1 || VAR_6 == 2) ? VAR_10->log2_chroma_h : 0; const unsigned char *VAR_14 = VAR_0->data[VAR_6]; VAR_12 = (VAR_3 + (1 << VAR_13) - 1) >> VAR_13; for (VAR_7 = 0; VAR_7 < VAR_12; VAR_7++) { memcpy(VAR_4, VAR_14, VAR_9[VAR_6]); VAR_4 += VAR_9[VAR_6]; VAR_14 += VAR_0->linesize[VAR_6]; } } if (VAR_10->flags & AV_PIX_FMT_FLAG_PAL)
memcpy((unsigned char *)(((size_t)VAR_4 + 3) & ~3),
VAR_0->data[1], 256 * 4); return VAR_11; }