static int xpm_decode_frame(AVCodecContext *avctx, void *data,

                            int *got_frame, AVPacket *avpkt)

{

    XPMDecContext *x = avctx->priv_data;

    AVFrame *p=data;

    const uint8_t *end, *ptr = avpkt->data;

    int ncolors, cpp, ret, i, j;

    int64_t size;

    uint32_t *dst;



    avctx->pix_fmt = AV_PIX_FMT_BGRA;



    end = avpkt->data + avpkt->size;

    while (memcmp(ptr, "/* XPM */\n", 10) && ptr < end - 10)

        ptr++;



    if (ptr >= end) {

        av_log(avctx, AV_LOG_ERROR, "missing signature\n");

        return AVERROR_INVALIDDATA;

    }



    ptr += mod_strcspn(ptr, "\"");

    if (sscanf(ptr, "\"%u %u %u %u\",",

               &avctx->width, &avctx->height, &ncolors, &cpp) != 4) {

        av_log(avctx, AV_LOG_ERROR, "missing image parameters\n");

        return AVERROR_INVALIDDATA;

    }



    if ((ret = ff_set_dimensions(avctx, avctx->width, avctx->height)) < 0)

        return ret;



    if ((ret = ff_get_buffer(avctx, p, 0)) < 0)

        return ret;



    if (cpp <= 0 || cpp >= 5) {

        av_log(avctx, AV_LOG_ERROR, "unsupported/invalid number of chars per pixel: %d\n", cpp);

        return AVERROR_INVALIDDATA;

    }



    size = 1;

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

        size *= 94;



    if (ncolors <= 0 || ncolors > size) {

        av_log(avctx, AV_LOG_ERROR, "invalid number of colors: %d\n", ncolors);

        return AVERROR_INVALIDDATA;

    }



    size *= 4;



    av_fast_padded_malloc(&x->pixels, &x->pixels_size, size);

    if (!x->pixels)

        return AVERROR(ENOMEM);



    ptr += mod_strcspn(ptr, ",") + 1;

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

        const uint8_t *index;

        int len;



        ptr += mod_strcspn(ptr, "\"") + 1;

        if (ptr + cpp > end)

            return AVERROR_INVALIDDATA;

        index = ptr;

        ptr += cpp;



        ptr = strstr(ptr, "c ");

        if (ptr) {

            ptr += 2;

        } else {

            return AVERROR_INVALIDDATA;

        }



        len = strcspn(ptr, "\" ");



        if ((ret = ascii2index(index, cpp)) < 0)

            return ret;



        x->pixels[ret] = color_string_to_rgba(ptr, len);

        ptr += mod_strcspn(ptr, ",") + 1;

    }



    for (i = 0; i < avctx->height; i++) {

        dst = (uint32_t *)(p->data[0] + i * p->linesize[0]);

        ptr += mod_strcspn(ptr, "\"") + 1;



        for (j = 0; j < avctx->width; j++) {

            if (ptr + cpp > end)

                return AVERROR_INVALIDDATA;



            if ((ret = ascii2index(ptr, cpp)) < 0)

                return ret;



            *dst++ = x->pixels[ret];

            ptr += cpp;

        }

        ptr += mod_strcspn(ptr, ",") + 1;

    }



    p->key_frame = 1;

    p->pict_type = AV_PICTURE_TYPE_I;



    *got_frame = 1;



    return avpkt->size;

}

static int xpm_decode_frame(AVCodecContext *avctx, void *data,

                            int *got_frame, AVPacket *avpkt)

{

    XPMDecContext *x = avctx->priv_data;

    AVFrame *p=data;

    const uint8_t *end, *ptr = avpkt->data;

    int ncolors, cpp, ret, i, j;

    int64_t size;

    uint32_t *dst;



    avctx->pix_fmt = AV_PIX_FMT_BGRA;



    end = avpkt->data + avpkt->size;

    while (memcmp(ptr, "\n", 10) && ptr < end - 10)

        ptr++;



    if (ptr >= end) {

        av_log(avctx, AV_LOG_ERROR, "missing signature\n");

        return AVERROR_INVALIDDATA;

    }



    ptr += mod_strcspn(ptr, "\"");

    if (sscanf(ptr, "\"%u %u %u %u\",",

               &avctx->width, &avctx->height, &ncolors, &cpp) != 4) {

        av_log(avctx, AV_LOG_ERROR, "missing image parameters\n");

        return AVERROR_INVALIDDATA;

    }



    if ((ret = ff_set_dimensions(avctx, avctx->width, avctx->height)) < 0)

        return ret;



    if ((ret = ff_get_buffer(avctx, p, 0)) < 0)

        return ret;



    if (cpp <= 0 || cpp >= 5) {

        av_log(avctx, AV_LOG_ERROR, "unsupported/invalid number of chars per pixel: %d\n", cpp);

        return AVERROR_INVALIDDATA;

    }



    size = 1;

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

        size *= 94;



    if (ncolors <= 0 || ncolors > size) {

        av_log(avctx, AV_LOG_ERROR, "invalid number of colors: %d\n", ncolors);

        return AVERROR_INVALIDDATA;

    }



    size *= 4;



    av_fast_padded_malloc(&x->pixels, &x->pixels_size, size);

    if (!x->pixels)

        return AVERROR(ENOMEM);



    ptr += mod_strcspn(ptr, ",") + 1;

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

        const uint8_t *index;

        int len;



        ptr += mod_strcspn(ptr, "\"") + 1;

        if (ptr + cpp > end)

            return AVERROR_INVALIDDATA;

        index = ptr;

        ptr += cpp;



        ptr = strstr(ptr, "c ");

        if (ptr) {

            ptr += 2;

        } else {

            return AVERROR_INVALIDDATA;

        }



        len = strcspn(ptr, "\" ");



        if ((ret = ascii2index(index, cpp)) < 0)

            return ret;



        x->pixels[ret] = color_string_to_rgba(ptr, len);

        ptr += mod_strcspn(ptr, ",") + 1;

    }



    for (i = 0; i < avctx->height; i++) {

        dst = (uint32_t *)(p->data[0] + i * p->linesize[0]);

        ptr += mod_strcspn(ptr, "\"") + 1;



        for (j = 0; j < avctx->width; j++) {

            if (ptr + cpp > end)

                return AVERROR_INVALIDDATA;



            if ((ret = ascii2index(ptr, cpp)) < 0)

                return ret;



            *dst++ = x->pixels[ret];

            ptr += cpp;

        }

        ptr += mod_strcspn(ptr, ",") + 1;

    }



    p->key_frame = 1;

    p->pict_type = AV_PICTURE_TYPE_I;



    *got_frame = 1;



    return avpkt->size;

}

static int FUNC_0(AVCodecContext *VAR_0, void *VAR_1,

                            int *VAR_2, AVPacket *VAR_3)

{

    XPMDecContext *x = VAR_0->priv_data;

    AVFrame *p=VAR_1;

    const uint8_t *VAR_4, *ptr = VAR_3->VAR_1;

    int VAR_5, VAR_6, VAR_7, VAR_8, VAR_9;

    int64_t size;

    uint32_t *dst;



    VAR_0->pix_fmt = AV_PIX_FMT_BGRA;



    VAR_4 = VAR_3->VAR_1 + VAR_3->size;

    while (memcmp(ptr, "\n", 10) && ptr < VAR_4 - 10)

        ptr++;



    if (ptr >= VAR_4) {

        av_log(VAR_0, AV_LOG_ERROR, "missing signature\n");

        return AVERROR_INVALIDDATA;

    }



    ptr += mod_strcspn(ptr, "\"");

    if (sscanf(ptr, "\"%u %u %u %u\",",

               &VAR_0->width, &VAR_0->height, &VAR_5, &VAR_6) != 4) {

        av_log(VAR_0, AV_LOG_ERROR, "missing image parameters\n");

        return AVERROR_INVALIDDATA;

    }



    if ((VAR_7 = ff_set_dimensions(VAR_0, VAR_0->width, VAR_0->height)) < 0)

        return VAR_7;



    if ((VAR_7 = ff_get_buffer(VAR_0, p, 0)) < 0)

        return VAR_7;



    if (VAR_6 <= 0 || VAR_6 >= 5) {

        av_log(VAR_0, AV_LOG_ERROR, "unsupported/invalid number of chars per pixel: %d\n", VAR_6);

        return AVERROR_INVALIDDATA;

    }



    size = 1;

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

        size *= 94;



    if (VAR_5 <= 0 || VAR_5 > size) {

        av_log(VAR_0, AV_LOG_ERROR, "invalid number of colors: %d\n", VAR_5);

        return AVERROR_INVALIDDATA;

    }



    size *= 4;



    av_fast_padded_malloc(&x->pixels, &x->pixels_size, size);

    if (!x->pixels)

        return AVERROR(ENOMEM);



    ptr += mod_strcspn(ptr, ",") + 1;

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

        const uint8_t *VAR_10;

        int VAR_11;



        ptr += mod_strcspn(ptr, "\"") + 1;

        if (ptr + VAR_6 > VAR_4)

            return AVERROR_INVALIDDATA;

        VAR_10 = ptr;

        ptr += VAR_6;



        ptr = strstr(ptr, "c ");

        if (ptr) {

            ptr += 2;

        } else {

            return AVERROR_INVALIDDATA;

        }



        VAR_11 = strcspn(ptr, "\" ");



        if ((VAR_7 = ascii2index(VAR_10, VAR_6)) < 0)

            return VAR_7;



        x->pixels[VAR_7] = color_string_to_rgba(ptr, VAR_11);

        ptr += mod_strcspn(ptr, ",") + 1;

    }



    for (VAR_8 = 0; VAR_8 < VAR_0->height; VAR_8++) {

        dst = (uint32_t *)(p->VAR_1[0] + VAR_8 * p->linesize[0]);

        ptr += mod_strcspn(ptr, "\"") + 1;



        for (VAR_9 = 0; VAR_9 < VAR_0->width; VAR_9++) {

            if (ptr + VAR_6 > VAR_4)

                return AVERROR_INVALIDDATA;



            if ((VAR_7 = ascii2index(ptr, VAR_6)) < 0)

                return VAR_7;



            *dst++ = x->pixels[VAR_7];

            ptr += VAR_6;

        }

        ptr += mod_strcspn(ptr, ",") + 1;

    }



    p->key_frame = 1;

    p->pict_type = AV_PICTURE_TYPE_I;



    *VAR_2 = 1;



    return VAR_3->size;

}

static int FUNC_0(AVCodecContext *VAR_0, void *VAR_1,
int *VAR_2, AVPacket *VAR_3)
{ XPMDecContext *x = VAR_0->priv_data; AVFrame *p=VAR_1; const uint8_t *VAR_4, *ptr = VAR_3->VAR_1; int VAR_5, VAR_6, VAR_7, VAR_8, VAR_9; int64_t size; uint32_t *dst; VAR_0->pix_fmt = AV_PIX_FMT_BGRA; VAR_4 = VAR_3->VAR_1 + VAR_3->size; while (memcmp(ptr, "\n", 10) && ptr < VAR_4 - 10)
ptr++; if (ptr >= VAR_4) { av_log(VAR_0, AV_LOG_ERROR, "missing signature\n"); return AVERROR_INVALIDDATA; } ptr += mod_strcspn(ptr, "\""); if (sscanf(ptr, "\"%u %u %u %u\",",
&VAR_0->width, &VAR_0->height, &VAR_5, &VAR_6) != 4) { av_log(VAR_0, AV_LOG_ERROR, "missing image parameters\n"); return AVERROR_INVALIDDATA; } if ((VAR_7 = ff_set_dimensions(VAR_0, VAR_0->width, VAR_0->height)) < 0)
return VAR_7; if ((VAR_7 = ff_get_buffer(VAR_0, p, 0)) < 0)
return VAR_7; if (VAR_6 <= 0 || VAR_6 >= 5) { av_log(VAR_0, AV_LOG_ERROR, "unsupported/invalid number of chars per pixel: %d\n", VAR_6); return AVERROR_INVALIDDATA; } size = 1; for (VAR_8 = 0; VAR_8 < VAR_6; VAR_8++) size *= 94; if (VAR_5 <= 0 || VAR_5 > size) { av_log(VAR_0, AV_LOG_ERROR, "invalid number of colors: %d\n", VAR_5); return AVERROR_INVALIDDATA; } size *= 4; av_fast_padded_malloc(&x->pixels, &x->pixels_size, size); if (!x->pixels)
return AVERROR(ENOMEM); ptr += mod_strcspn(ptr, ",") + 1; for (VAR_8 = 0; VAR_8 < VAR_5; VAR_8++) { const uint8_t *VAR_10; int VAR_11; ptr += mod_strcspn(ptr, "\"") + 1; if (ptr + VAR_6 > VAR_4)
return AVERROR_INVALIDDATA; VAR_10 = ptr; ptr += VAR_6; ptr = strstr(ptr, "c "); if (ptr) { ptr += 2; } else { return AVERROR_INVALIDDATA; } VAR_11 = strcspn(ptr, "\" "); if ((VAR_7 = ascii2index(VAR_10, VAR_6)) < 0)
return VAR_7; x->pixels[VAR_7] = color_string_to_rgba(ptr, VAR_11); ptr += mod_strcspn(ptr, ",") + 1; } for (VAR_8 = 0; VAR_8 < VAR_0->height; VAR_8++) { dst = (uint32_t *)(p->VAR_1[0] + VAR_8 * p->linesize[0]); ptr += mod_strcspn(ptr, "\"") + 1; for (VAR_9 = 0; VAR_9 < VAR_0->width; VAR_9++) { if (ptr + VAR_6 > VAR_4)
return AVERROR_INVALIDDATA; if ((VAR_7 = ascii2index(ptr, VAR_6)) < 0)
return VAR_7; *dst++ = x->pixels[VAR_7]; ptr += VAR_6; } ptr += mod_strcspn(ptr, ",") + 1; } p->key_frame = 1; p->pict_type = AV_PICTURE_TYPE_I; *VAR_2 = 1; return VAR_3->size; }