static int alloc_buffer(FrameBuffer **pool, AVCodecContext *s, FrameBuffer **pbuf)

{

    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(s->pix_fmt);

    FrameBuffer *buf;

    int i, ret;

    int pixel_size;

    int h_chroma_shift, v_chroma_shift;

    int edge = 32; // XXX should be avcodec_get_edge_width(), but that fails on svq1

    int w = s->width, h = s->height;



    if (!desc)

        return AVERROR(EINVAL);

    pixel_size = desc->comp[0].step_minus1 + 1;



    buf = av_mallocz(sizeof(*buf));

    if (!buf)

        return AVERROR(ENOMEM);



    if (!(s->flags & CODEC_FLAG_EMU_EDGE)) {

        w += 2*edge;

        h += 2*edge;

    }



    avcodec_align_dimensions(s, &w, &h);

    if ((ret = av_image_alloc(buf->base, buf->linesize, w, h,

                              s->pix_fmt, 32)) < 0) {

        av_freep(&buf);

        return ret;

    }

    /* XXX this shouldn't be needed, but some tests break without this line

     * those decoders are buggy and need to be fixed.

     * the following tests fail:

     */

    memset(buf->base[0], 128, ret);



    av_pix_fmt_get_chroma_sub_sample(s->pix_fmt,

                                     &h_chroma_shift, &v_chroma_shift);



    for (i = 0; i < FF_ARRAY_ELEMS(buf->data); i++) {

        const int h_shift = i==0 ? 0 : h_chroma_shift;

        const int v_shift = i==0 ? 0 : v_chroma_shift;

        if (s->flags & CODEC_FLAG_EMU_EDGE)

            buf->data[i] = buf->base[i];

        else if (buf->base[i])

            buf->data[i] = buf->base[i] +

                           FFALIGN((buf->linesize[i]*edge >> v_shift) +

                                   (pixel_size*edge >> h_shift), 32);

    }

    buf->w       = s->width;

    buf->h       = s->height;

    buf->pix_fmt = s->pix_fmt;

    buf->pool    = pool;



    *pbuf = buf;

    return 0;

}

static int alloc_buffer(FrameBuffer **pool, AVCodecContext *s, FrameBuffer **pbuf)

{

    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(s->pix_fmt);

    FrameBuffer *buf;

    int i, ret;

    int pixel_size;

    int h_chroma_shift, v_chroma_shift;

    int edge = 32; 

    int w = s->width, h = s->height;



    if (!desc)

        return AVERROR(EINVAL);

    pixel_size = desc->comp[0].step_minus1 + 1;



    buf = av_mallocz(sizeof(*buf));

    if (!buf)

        return AVERROR(ENOMEM);



    if (!(s->flags & CODEC_FLAG_EMU_EDGE)) {

        w += 2*edge;

        h += 2*edge;

    }



    avcodec_align_dimensions(s, &w, &h);

    if ((ret = av_image_alloc(buf->base, buf->linesize, w, h,

                              s->pix_fmt, 32)) < 0) {

        av_freep(&buf);

        return ret;

    }

    







    memset(buf->base[0], 128, ret);



    av_pix_fmt_get_chroma_sub_sample(s->pix_fmt,

                                     &h_chroma_shift, &v_chroma_shift);



    for (i = 0; i < FF_ARRAY_ELEMS(buf->data); i++) {

        const int h_shift = i==0 ? 0 : h_chroma_shift;

        const int v_shift = i==0 ? 0 : v_chroma_shift;

        if (s->flags & CODEC_FLAG_EMU_EDGE)

            buf->data[i] = buf->base[i];

        else if (buf->base[i])

            buf->data[i] = buf->base[i] +

                           FFALIGN((buf->linesize[i]*edge >> v_shift) +

                                   (pixel_size*edge >> h_shift), 32);

    }

    buf->w       = s->width;

    buf->h       = s->height;

    buf->pix_fmt = s->pix_fmt;

    buf->pool    = pool;



    *pbuf = buf;

    return 0;

}

static int FUNC_0(FrameBuffer **VAR_0, AVCodecContext *VAR_1, FrameBuffer **VAR_2)

{

    const AVPixFmtDescriptor *VAR_3 = av_pix_fmt_desc_get(VAR_1->pix_fmt);

    FrameBuffer *buf;

    int VAR_4, VAR_5;

    int VAR_6;

    int VAR_7, VAR_8;

    int VAR_9 = 32; 

    int VAR_10 = VAR_1->width, VAR_11 = VAR_1->height;



    if (!VAR_3)

        return AVERROR(EINVAL);

    VAR_6 = VAR_3->comp[0].step_minus1 + 1;



    buf = av_mallocz(sizeof(*buf));

    if (!buf)

        return AVERROR(ENOMEM);



    if (!(VAR_1->flags & CODEC_FLAG_EMU_EDGE)) {

        VAR_10 += 2*VAR_9;

        VAR_11 += 2*VAR_9;

    }



    avcodec_align_dimensions(VAR_1, &VAR_10, &VAR_11);

    if ((VAR_5 = av_image_alloc(buf->base, buf->linesize, VAR_10, VAR_11,

                              VAR_1->pix_fmt, 32)) < 0) {

        av_freep(&buf);

        return VAR_5;

    }

    







    memset(buf->base[0], 128, VAR_5);



    av_pix_fmt_get_chroma_sub_sample(VAR_1->pix_fmt,

                                     &VAR_7, &VAR_8);



    for (VAR_4 = 0; VAR_4 < FF_ARRAY_ELEMS(buf->data); VAR_4++) {

        const int h_shift = VAR_4==0 ? 0 : VAR_7;

        const int v_shift = VAR_4==0 ? 0 : VAR_8;

        if (VAR_1->flags & CODEC_FLAG_EMU_EDGE)

            buf->data[VAR_4] = buf->base[VAR_4];

        else if (buf->base[VAR_4])

            buf->data[VAR_4] = buf->base[VAR_4] +

                           FFALIGN((buf->linesize[VAR_4]*VAR_9 >> v_shift) +

                                   (VAR_6*VAR_9 >> h_shift), 32);

    }

    buf->VAR_10       = VAR_1->width;

    buf->VAR_11       = VAR_1->height;

    buf->pix_fmt = VAR_1->pix_fmt;

    buf->VAR_0    = VAR_0;



    *VAR_2 = buf;

    return 0;

}

static int FUNC_0(FrameBuffer **VAR_0, AVCodecContext *VAR_1, FrameBuffer **VAR_2)
{ const AVPixFmtDescriptor *VAR_3 = av_pix_fmt_desc_get(VAR_1->pix_fmt); FrameBuffer *buf; int VAR_4, VAR_5; int VAR_6; int VAR_7, VAR_8; int VAR_9 = 32; int VAR_10 = VAR_1->width, VAR_11 = VAR_1->height; if (!VAR_3)
return AVERROR(EINVAL); VAR_6 = VAR_3->comp[0].step_minus1 + 1; buf = av_mallocz(sizeof(*buf)); if (!buf)
return AVERROR(ENOMEM); if (!(VAR_1->flags & CODEC_FLAG_EMU_EDGE)) { VAR_10 += 2*VAR_9; VAR_11 += 2*VAR_9; } avcodec_align_dimensions(VAR_1, &VAR_10, &VAR_11); if ((VAR_5 = av_image_alloc(buf->base, buf->linesize, VAR_10, VAR_11,
VAR_1->pix_fmt, 32)) < 0) { av_freep(&buf); return VAR_5; } memset(buf->base[0], 128, VAR_5); av_pix_fmt_get_chroma_sub_sample(VAR_1->pix_fmt,
&VAR_7, &VAR_8); for (VAR_4 = 0; VAR_4 < FF_ARRAY_ELEMS(buf->data); VAR_4++) { const int h_shift = VAR_4==0 ? 0 : VAR_7; const int v_shift = VAR_4==0 ? 0 : VAR_8; if (VAR_1->flags & CODEC_FLAG_EMU_EDGE)
buf->data[VAR_4] = buf->base[VAR_4]; else if (buf->base[VAR_4])
buf->data[VAR_4] = buf->base[VAR_4] +
FFALIGN((buf->linesize[VAR_4]*VAR_9 >> v_shift) +
(VAR_6*VAR_9 >> h_shift), 32); } buf->VAR_10       = VAR_1->width; buf->VAR_11       = VAR_1->height; buf->pix_fmt = VAR_1->pix_fmt; buf->VAR_0    = VAR_0; *VAR_2 = buf; return 0; }