static int alloc_buffer(AVCodecContext *s, InputStream *ist, FrameBuffer **pbuf)

{

    FrameBuffer  *buf = av_mallocz(sizeof(*buf));

    int i, ret;

    const int pixel_size = av_pix_fmt_descriptors[s->pix_fmt].comp[0].step_minus1+1;

    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 (!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:

     * bethsoft-vid, cdgraphics, ansi, aasc, fraps-v1, qtrle-1bit

     */

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



    avcodec_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

            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->ist     = ist;



    *pbuf = buf;

    return 0;

}

static int alloc_buffer(AVCodecContext *s, InputStream *ist, FrameBuffer **pbuf)

{

    FrameBuffer  *buf = av_mallocz(sizeof(*buf));

    int i, ret;

    const int pixel_size = av_pix_fmt_descriptors[s->pix_fmt].comp[0].step_minus1+1;

    int h_chroma_shift, v_chroma_shift;

    int edge = 32; 

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



    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);



    avcodec_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

            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->ist     = ist;



    *pbuf = buf;

    return 0;

}

        if (s->flags & CODEC_FLAG_EMU_EDGE)
static int FUNC_0(AVCodecContext *VAR_0, InputStream *VAR_1, FrameBuffer **VAR_2)

{

    FrameBuffer  *buf = av_mallocz(sizeof(*buf));

    int VAR_3, VAR_4;

    const int VAR_5 = av_pix_fmt_descriptors[VAR_0->pix_fmt].comp[0].step_minus1+1;

    int VAR_6, VAR_7;

    int VAR_8 = 32; 

    int VAR_9 = VAR_0->width, VAR_10 = VAR_0->height;



    if (!buf)

        return AVERROR(ENOMEM);



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

        VAR_9 += 2*VAR_8;

        VAR_10 += 2*VAR_8;

    }



    avcodec_align_dimensions(VAR_0, &VAR_9, &VAR_10);

    if ((VAR_4 = av_image_alloc(buf->base, buf->linesize, VAR_9, VAR_10,

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

        av_freep(&buf);

        return VAR_4;

    }

    









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



    avcodec_get_chroma_sub_sample(VAR_0->pix_fmt, &VAR_6, &VAR_7);

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

        const int h_shift = VAR_3==0 ? 0 : VAR_6;

        const int v_shift = VAR_3==0 ? 0 : VAR_7;

        if (VAR_0->flags & CODEC_FLAG_EMU_EDGE)

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

        else

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

                           FFALIGN((buf->linesize[VAR_3]*VAR_8 >> v_shift) +

                                   (VAR_5*VAR_8 >> h_shift), 32);

    }

    buf->VAR_9       = VAR_0->width;

    buf->VAR_10       = VAR_0->height;

    buf->pix_fmt = VAR_0->pix_fmt;

    buf->VAR_1     = VAR_1;



    *VAR_2 = buf;

    return 0;

}

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