int av_image_fill_pointers(uint8_t *data[4], enum PixelFormat pix_fmt, int height,

                           uint8_t *ptr, const int linesizes[4])

{

    int i, total_size, size[4], has_plane[4];



    const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[pix_fmt];

    memset(data     , 0, sizeof(data[0])*4);

    memset(size     , 0, sizeof(size));

    memset(has_plane, 0, sizeof(has_plane));



    if ((unsigned)pix_fmt >= PIX_FMT_NB || desc->flags & PIX_FMT_HWACCEL)

        return AVERROR(EINVAL);



    data[0] = ptr;

    if (linesizes[0] > (INT_MAX - 1024) / height)

        return AVERROR(EINVAL);

    size[0] = linesizes[0] * height;



    if (desc->flags & PIX_FMT_PAL) {

        size[0] = (size[0] + 3) & ~3;

        data[1] = ptr + size[0]; /* palette is stored here as 256 32 bits words */

        return size[0] + 256 * 4;

    }



    for (i = 0; i < 4; i++)

        has_plane[desc->comp[i].plane] = 1;



    total_size = size[0];

    for (i = 1; i < 4 && has_plane[i]; i++) {

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

        data[i] = data[i-1] + size[i-1];

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

        if (linesizes[i] > INT_MAX / h)

            return AVERROR(EINVAL);

        size[i] = h * linesizes[i];

        if (total_size > INT_MAX - size[i])

            return AVERROR(EINVAL);

        total_size += size[i];

    }



    return total_size;

}

int av_image_fill_pointers(uint8_t *data[4], enum PixelFormat pix_fmt, int height,

                           uint8_t *ptr, const int linesizes[4])

{

    int i, total_size, size[4], has_plane[4];



    const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[pix_fmt];

    memset(data     , 0, sizeof(data[0])*4);

    memset(size     , 0, sizeof(size));

    memset(has_plane, 0, sizeof(has_plane));



    if ((unsigned)pix_fmt >= PIX_FMT_NB || desc->flags & PIX_FMT_HWACCEL)

        return AVERROR(EINVAL);



    data[0] = ptr;

    if (linesizes[0] > (INT_MAX - 1024) / height)

        return AVERROR(EINVAL);

    size[0] = linesizes[0] * height;



    if (desc->flags & PIX_FMT_PAL) {

        size[0] = (size[0] + 3) & ~3;

        data[1] = ptr + size[0]; 

        return size[0] + 256 * 4;

    }



    for (i = 0; i < 4; i++)

        has_plane[desc->comp[i].plane] = 1;



    total_size = size[0];

    for (i = 1; i < 4 && has_plane[i]; i++) {

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

        data[i] = data[i-1] + size[i-1];

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

        if (linesizes[i] > INT_MAX / h)

            return AVERROR(EINVAL);

        size[i] = h * linesizes[i];

        if (total_size > INT_MAX - size[i])

            return AVERROR(EINVAL);

        total_size += size[i];

    }



    return total_size;

}

    if (desc->flags & PIX_FMT_PAL) {     if (desc->flags & PIX_FMT_PAL) {
int FUNC_0(uint8_t *VAR_0[4], enum PixelFormat VAR_1, int VAR_2,

                           uint8_t *VAR_3, const int VAR_4[4])

{

    int VAR_5, VAR_6, VAR_7[4], VAR_8[4];



    const AVPixFmtDescriptor *VAR_9 = &av_pix_fmt_descriptors[VAR_1];

    memset(VAR_0     , 0, sizeof(VAR_0[0])*4);

    memset(VAR_7     , 0, sizeof(VAR_7));

    memset(VAR_8, 0, sizeof(VAR_8));



    if ((unsigned)VAR_1 >= PIX_FMT_NB || VAR_9->flags & PIX_FMT_HWACCEL)

        return AVERROR(EINVAL);



    VAR_0[0] = VAR_3;

    if (VAR_4[0] > (INT_MAX - 1024) / VAR_2)

        return AVERROR(EINVAL);

    VAR_7[0] = VAR_4[0] * VAR_2;



    if (VAR_9->flags & PIX_FMT_PAL) {

        VAR_7[0] = (VAR_7[0] + 3) & ~3;

        VAR_0[1] = VAR_3 + VAR_7[0]; 

        return VAR_7[0] + 256 * 4;

    }



    for (VAR_5 = 0; VAR_5 < 4; VAR_5++)

        VAR_8[VAR_9->comp[VAR_5].plane] = 1;



    VAR_6 = VAR_7[0];

    for (VAR_5 = 1; VAR_5 < 4 && VAR_8[VAR_5]; VAR_5++) {

        int VAR_10, VAR_11 = (VAR_5 == 1 || VAR_5 == 2) ? VAR_9->log2_chroma_h : 0;

        VAR_0[VAR_5] = VAR_0[VAR_5-1] + VAR_7[VAR_5-1];

        VAR_10 = (VAR_2 + (1 << VAR_11) - 1) >> VAR_11;

        if (VAR_4[VAR_5] > INT_MAX / VAR_10)

            return AVERROR(EINVAL);

        VAR_7[VAR_5] = VAR_10 * VAR_4[VAR_5];

        if (VAR_6 > INT_MAX - VAR_7[VAR_5])

            return AVERROR(EINVAL);

        VAR_6 += VAR_7[VAR_5];

    }



    return VAR_6;

}

int FUNC_0(uint8_t *VAR_0[4], enum PixelFormat VAR_1, int VAR_2,
uint8_t *VAR_3, const int VAR_4[4])
{ int VAR_5, VAR_6, VAR_7[4], VAR_8[4]; const AVPixFmtDescriptor *VAR_9 = &av_pix_fmt_descriptors[VAR_1]; memset(VAR_0     , 0, sizeof(VAR_0[0])*4); memset(VAR_7     , 0, sizeof(VAR_7)); memset(VAR_8, 0, sizeof(VAR_8)); if ((unsigned)VAR_1 >= PIX_FMT_NB || VAR_9->flags & PIX_FMT_HWACCEL)
return AVERROR(EINVAL); VAR_0[0] = VAR_3; if (VAR_4[0] > (INT_MAX - 1024) / VAR_2)
return AVERROR(EINVAL); VAR_7[0] = VAR_4[0] * VAR_2; if (VAR_9->flags & PIX_FMT_PAL) { VAR_7[0] = (VAR_7[0] + 3) & ~3; VAR_0[1] = VAR_3 + VAR_7[0]; return VAR_7[0] + 256 * 4; } for (VAR_5 = 0; VAR_5 < 4; VAR_5++) VAR_8[VAR_9->comp[VAR_5].plane] = 1; VAR_6 = VAR_7[0]; for (VAR_5 = 1; VAR_5 < 4 && VAR_8[VAR_5]; VAR_5++) { int VAR_10, VAR_11 = (VAR_5 == 1 || VAR_5 == 2) ? VAR_9->log2_chroma_h : 0; VAR_0[VAR_5] = VAR_0[VAR_5-1] + VAR_7[VAR_5-1]; VAR_10 = (VAR_2 + (1 << VAR_11) - 1) >> VAR_11; if (VAR_4[VAR_5] > INT_MAX / VAR_10)
return AVERROR(EINVAL); VAR_7[VAR_5] = VAR_10 * VAR_4[VAR_5]; if (VAR_6 > INT_MAX - VAR_7[VAR_5])
return AVERROR(EINVAL); VAR_6 += VAR_7[VAR_5]; } return VAR_6; }