int ff_draw_init(FFDrawContext *draw, enum AVPixelFormat format, unsigned flags)

{

    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(format);

    const AVComponentDescriptor *c;

    unsigned i, nb_planes = 0;

    int pixelstep[MAX_PLANES] = { 0 };



    if (!desc->name)

        return AVERROR(EINVAL);

    if (desc->flags & ~(AV_PIX_FMT_FLAG_PLANAR | AV_PIX_FMT_FLAG_RGB | AV_PIX_FMT_FLAG_PSEUDOPAL | AV_PIX_FMT_FLAG_ALPHA))

        return AVERROR(ENOSYS);

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

        c = &desc->comp[i];

        /* for now, only 8-bits formats */

        if (c->depth_minus1 != 8 - 1)

            return AVERROR(ENOSYS);

        if (c->plane >= MAX_PLANES)

            return AVERROR(ENOSYS);

        /* strange interleaving */

        if (pixelstep[c->plane] != 0 &&

            pixelstep[c->plane] != c->step_minus1 + 1)

            return AVERROR(ENOSYS);

        pixelstep[c->plane] = c->step_minus1 + 1;

        if (pixelstep[c->plane] >= 8)

            return AVERROR(ENOSYS);

        nb_planes = FFMAX(nb_planes, c->plane + 1);

    }

    if ((desc->log2_chroma_w || desc->log2_chroma_h) && nb_planes < 3)

        return AVERROR(ENOSYS); /* exclude NV12 and NV21 */

    memset(draw, 0, sizeof(*draw));

    draw->desc      = desc;

    draw->format    = format;

    draw->nb_planes = nb_planes;

    memcpy(draw->pixelstep, pixelstep, sizeof(draw->pixelstep));

    draw->hsub[1] = draw->hsub[2] = draw->hsub_max = desc->log2_chroma_w;

    draw->vsub[1] = draw->vsub[2] = draw->vsub_max = desc->log2_chroma_h;

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

        draw->comp_mask[desc->comp[i].plane] |=

            1 << (desc->comp[i].offset_plus1 - 1);

    return 0;

}

int ff_draw_init(FFDrawContext *draw, enum AVPixelFormat format, unsigned flags)

{

    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(format);

    const AVComponentDescriptor *c;

    unsigned i, nb_planes = 0;

    int pixelstep[MAX_PLANES] = { 0 };



    if (!desc->name)

        return AVERROR(EINVAL);

    if (desc->flags & ~(AV_PIX_FMT_FLAG_PLANAR | AV_PIX_FMT_FLAG_RGB | AV_PIX_FMT_FLAG_PSEUDOPAL | AV_PIX_FMT_FLAG_ALPHA))

        return AVERROR(ENOSYS);

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

        c = &desc->comp[i];

        

        if (c->depth_minus1 != 8 - 1)

            return AVERROR(ENOSYS);

        if (c->plane >= MAX_PLANES)

            return AVERROR(ENOSYS);

        

        if (pixelstep[c->plane] != 0 &&

            pixelstep[c->plane] != c->step_minus1 + 1)

            return AVERROR(ENOSYS);

        pixelstep[c->plane] = c->step_minus1 + 1;

        if (pixelstep[c->plane] >= 8)

            return AVERROR(ENOSYS);

        nb_planes = FFMAX(nb_planes, c->plane + 1);

    }

    if ((desc->log2_chroma_w || desc->log2_chroma_h) && nb_planes < 3)

        return AVERROR(ENOSYS); 

    memset(draw, 0, sizeof(*draw));

    draw->desc      = desc;

    draw->format    = format;

    draw->nb_planes = nb_planes;

    memcpy(draw->pixelstep, pixelstep, sizeof(draw->pixelstep));

    draw->hsub[1] = draw->hsub[2] = draw->hsub_max = desc->log2_chroma_w;

    draw->vsub[1] = draw->vsub[2] = draw->vsub_max = desc->log2_chroma_h;

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

        draw->comp_mask[desc->comp[i].plane] |=

            1 << (desc->comp[i].offset_plus1 - 1);

    return 0;

}

int FUNC_0(FFDrawContext *VAR_0, enum AVPixelFormat VAR_1, unsigned VAR_2)

{

    const AVPixFmtDescriptor *VAR_3 = av_pix_fmt_desc_get(VAR_1);

    const AVComponentDescriptor *VAR_4;

    unsigned VAR_5, VAR_6 = 0;

    int VAR_7[MAX_PLANES] = { 0 };



    if (!VAR_3->name)

        return AVERROR(EINVAL);

    if (VAR_3->VAR_2 & ~(AV_PIX_FMT_FLAG_PLANAR | AV_PIX_FMT_FLAG_RGB | AV_PIX_FMT_FLAG_PSEUDOPAL | AV_PIX_FMT_FLAG_ALPHA))

        return AVERROR(ENOSYS);

    for (VAR_5 = 0; VAR_5 < VAR_3->nb_components; VAR_5++) {

        VAR_4 = &VAR_3->comp[VAR_5];

        

        if (VAR_4->depth_minus1 != 8 - 1)

            return AVERROR(ENOSYS);

        if (VAR_4->plane >= MAX_PLANES)

            return AVERROR(ENOSYS);

        

        if (VAR_7[VAR_4->plane] != 0 &&

            VAR_7[VAR_4->plane] != VAR_4->step_minus1 + 1)

            return AVERROR(ENOSYS);

        VAR_7[VAR_4->plane] = VAR_4->step_minus1 + 1;

        if (VAR_7[VAR_4->plane] >= 8)

            return AVERROR(ENOSYS);

        VAR_6 = FFMAX(VAR_6, VAR_4->plane + 1);

    }

    if ((VAR_3->log2_chroma_w || VAR_3->log2_chroma_h) && VAR_6 < 3)

        return AVERROR(ENOSYS); 

    memset(VAR_0, 0, sizeof(*VAR_0));

    VAR_0->VAR_3      = VAR_3;

    VAR_0->VAR_1    = VAR_1;

    VAR_0->VAR_6 = VAR_6;

    memcpy(VAR_0->VAR_7, VAR_7, sizeof(VAR_0->VAR_7));

    VAR_0->hsub[1] = VAR_0->hsub[2] = VAR_0->hsub_max = VAR_3->log2_chroma_w;

    VAR_0->vsub[1] = VAR_0->vsub[2] = VAR_0->vsub_max = VAR_3->log2_chroma_h;

    for (VAR_5 = 0; VAR_5 < ((VAR_3->nb_components - 1) | 1); VAR_5++)

        VAR_0->comp_mask[VAR_3->comp[VAR_5].plane] |=

            1 << (VAR_3->comp[VAR_5].offset_plus1 - 1);

    return 0;

}

int FUNC_0(FFDrawContext *VAR_0, enum AVPixelFormat VAR_1, unsigned VAR_2)
{ const AVPixFmtDescriptor *VAR_3 = av_pix_fmt_desc_get(VAR_1); const AVComponentDescriptor *VAR_4; unsigned VAR_5, VAR_6 = 0; int VAR_7[MAX_PLANES] = { 0 }; if (!VAR_3->name)
return AVERROR(EINVAL); if (VAR_3->VAR_2 & ~(AV_PIX_FMT_FLAG_PLANAR | AV_PIX_FMT_FLAG_RGB | AV_PIX_FMT_FLAG_PSEUDOPAL | AV_PIX_FMT_FLAG_ALPHA))
return AVERROR(ENOSYS); for (VAR_5 = 0; VAR_5 < VAR_3->nb_components; VAR_5++) { VAR_4 = &VAR_3->comp[VAR_5]; if (VAR_4->depth_minus1 != 8 - 1)
return AVERROR(ENOSYS); if (VAR_4->plane >= MAX_PLANES)
return AVERROR(ENOSYS); if (VAR_7[VAR_4->plane] != 0 &&
VAR_7[VAR_4->plane] != VAR_4->step_minus1 + 1)
return AVERROR(ENOSYS); VAR_7[VAR_4->plane] = VAR_4->step_minus1 + 1; if (VAR_7[VAR_4->plane] >= 8)
return AVERROR(ENOSYS); VAR_6 = FFMAX(VAR_6, VAR_4->plane + 1); } if ((VAR_3->log2_chroma_w || VAR_3->log2_chroma_h) && VAR_6 < 3)
return AVERROR(ENOSYS); memset(VAR_0, 0, sizeof(*VAR_0)); VAR_0->VAR_3      = VAR_3; VAR_0->VAR_1    = VAR_1; VAR_0->VAR_6 = VAR_6; memcpy(VAR_0->VAR_7, VAR_7, sizeof(VAR_0->VAR_7)); VAR_0->hsub[1] = VAR_0->hsub[2] = VAR_0->hsub_max = VAR_3->log2_chroma_w; VAR_0->vsub[1] = VAR_0->vsub[2] = VAR_0->vsub_max = VAR_3->log2_chroma_h; for (VAR_5 = 0; VAR_5 < ((VAR_3->nb_components - 1) | 1); VAR_5++) VAR_0->comp_mask[VAR_3->comp[VAR_5].plane] |=
1 << (VAR_3->comp[VAR_5].offset_plus1 - 1); return 0; }