static int alloc_sequence_buffers(DiracContext *s)

{

    int sbwidth  = DIVRNDUP(s->source.width,  4);

    int sbheight = DIVRNDUP(s->source.height, 4);

    int i, w, h, top_padding;



    /* todo: think more about this / use or set Plane here */

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

        int max_xblen = MAX_BLOCKSIZE >> (i ? s->chroma_x_shift : 0);

        int max_yblen = MAX_BLOCKSIZE >> (i ? s->chroma_y_shift : 0);

        w = s->source.width  >> (i ? s->chroma_x_shift : 0);

        h = s->source.height >> (i ? s->chroma_y_shift : 0);



        /* we allocate the max we support here since num decompositions can

         * change from frame to frame. Stride is aligned to 16 for SIMD, and

         * 1<<MAX_DWT_LEVELS top padding to avoid if(y>0) in arith decoding

         * MAX_BLOCKSIZE padding for MC: blocks can spill up to half of that

         * on each side */

        top_padding = FFMAX(1<<MAX_DWT_LEVELS, max_yblen/2);

        w = FFALIGN(CALC_PADDING(w, MAX_DWT_LEVELS), 8); /* FIXME: Should this be 16 for SSE??? */

        h = top_padding + CALC_PADDING(h, MAX_DWT_LEVELS) + max_yblen/2;



        s->plane[i].idwt_buf_base = av_mallocz_array((w+max_xblen), h * sizeof(IDWTELEM));

        s->plane[i].idwt_tmp      = av_malloc_array((w+16), sizeof(IDWTELEM));

        s->plane[i].idwt_buf      = s->plane[i].idwt_buf_base + top_padding*w;

        if (!s->plane[i].idwt_buf_base || !s->plane[i].idwt_tmp)

            return AVERROR(ENOMEM);

    }



    w = s->source.width;

    h = s->source.height;



    /* fixme: allocate using real stride here */

    s->sbsplit  = av_malloc_array(sbwidth, sbheight);

    s->blmotion = av_malloc_array(sbwidth, sbheight * 16 * sizeof(*s->blmotion));

    s->edge_emu_buffer_base = av_malloc_array((w+64), MAX_BLOCKSIZE);



    s->mctmp     = av_malloc_array((w+64+MAX_BLOCKSIZE), (h+MAX_BLOCKSIZE) * sizeof(*s->mctmp));

    s->mcscratch = av_malloc_array((w+64), MAX_BLOCKSIZE);



    if (!s->sbsplit || !s->blmotion || !s->mctmp || !s->mcscratch)

        return AVERROR(ENOMEM);

    return 0;

}

static int alloc_sequence_buffers(DiracContext *s)

{

    int sbwidth  = DIVRNDUP(s->source.width,  4);

    int sbheight = DIVRNDUP(s->source.height, 4);

    int i, w, h, top_padding;



    

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

        int max_xblen = MAX_BLOCKSIZE >> (i ? s->chroma_x_shift : 0);

        int max_yblen = MAX_BLOCKSIZE >> (i ? s->chroma_y_shift : 0);

        w = s->source.width  >> (i ? s->chroma_x_shift : 0);

        h = s->source.height >> (i ? s->chroma_y_shift : 0);



        









        top_padding = FFMAX(1<<MAX_DWT_LEVELS, max_yblen/2);

        w = FFALIGN(CALC_PADDING(w, MAX_DWT_LEVELS), 8); 

        h = top_padding + CALC_PADDING(h, MAX_DWT_LEVELS) + max_yblen/2;



        s->plane[i].idwt_buf_base = av_mallocz_array((w+max_xblen), h * sizeof(IDWTELEM));

        s->plane[i].idwt_tmp      = av_malloc_array((w+16), sizeof(IDWTELEM));

        s->plane[i].idwt_buf      = s->plane[i].idwt_buf_base + top_padding*w;

        if (!s->plane[i].idwt_buf_base || !s->plane[i].idwt_tmp)

            return AVERROR(ENOMEM);

    }



    w = s->source.width;

    h = s->source.height;



    

    s->sbsplit  = av_malloc_array(sbwidth, sbheight);

    s->blmotion = av_malloc_array(sbwidth, sbheight * 16 * sizeof(*s->blmotion));

    s->edge_emu_buffer_base = av_malloc_array((w+64), MAX_BLOCKSIZE);



    s->mctmp     = av_malloc_array((w+64+MAX_BLOCKSIZE), (h+MAX_BLOCKSIZE) * sizeof(*s->mctmp));

    s->mcscratch = av_malloc_array((w+64), MAX_BLOCKSIZE);



    if (!s->sbsplit || !s->blmotion || !s->mctmp || !s->mcscratch)

        return AVERROR(ENOMEM);

    return 0;

}

static int FUNC_0(DiracContext *VAR_0)

{

    int VAR_1  = DIVRNDUP(VAR_0->source.width,  4);

    int VAR_2 = DIVRNDUP(VAR_0->source.height, 4);

    int VAR_3, VAR_4, VAR_5, VAR_6;



    

    for (VAR_3 = 0; VAR_3 < 3; VAR_3++) {

        int VAR_7 = MAX_BLOCKSIZE >> (VAR_3 ? VAR_0->chroma_x_shift : 0);

        int VAR_8 = MAX_BLOCKSIZE >> (VAR_3 ? VAR_0->chroma_y_shift : 0);

        VAR_4 = VAR_0->source.width  >> (VAR_3 ? VAR_0->chroma_x_shift : 0);

        VAR_5 = VAR_0->source.height >> (VAR_3 ? VAR_0->chroma_y_shift : 0);



        









        VAR_6 = FFMAX(1<<MAX_DWT_LEVELS, VAR_8/2);

        VAR_4 = FFALIGN(CALC_PADDING(VAR_4, MAX_DWT_LEVELS), 8); 

        VAR_5 = VAR_6 + CALC_PADDING(VAR_5, MAX_DWT_LEVELS) + VAR_8/2;



        VAR_0->plane[VAR_3].idwt_buf_base = av_mallocz_array((VAR_4+VAR_7), VAR_5 * sizeof(IDWTELEM));

        VAR_0->plane[VAR_3].idwt_tmp      = av_malloc_array((VAR_4+16), sizeof(IDWTELEM));

        VAR_0->plane[VAR_3].idwt_buf      = VAR_0->plane[VAR_3].idwt_buf_base + VAR_6*VAR_4;

        if (!VAR_0->plane[VAR_3].idwt_buf_base || !VAR_0->plane[VAR_3].idwt_tmp)

            return AVERROR(ENOMEM);

    }



    VAR_4 = VAR_0->source.width;

    VAR_5 = VAR_0->source.height;



    

    VAR_0->sbsplit  = av_malloc_array(VAR_1, VAR_2);

    VAR_0->blmotion = av_malloc_array(VAR_1, VAR_2 * 16 * sizeof(*VAR_0->blmotion));

    VAR_0->edge_emu_buffer_base = av_malloc_array((VAR_4+64), MAX_BLOCKSIZE);



    VAR_0->mctmp     = av_malloc_array((VAR_4+64+MAX_BLOCKSIZE), (VAR_5+MAX_BLOCKSIZE) * sizeof(*VAR_0->mctmp));

    VAR_0->mcscratch = av_malloc_array((VAR_4+64), MAX_BLOCKSIZE);



    if (!VAR_0->sbsplit || !VAR_0->blmotion || !VAR_0->mctmp || !VAR_0->mcscratch)

        return AVERROR(ENOMEM);

    return 0;

}

static int FUNC_0(DiracContext *VAR_0)
{ int VAR_1  = DIVRNDUP(VAR_0->source.width,  4); int VAR_2 = DIVRNDUP(VAR_0->source.height, 4); int VAR_3, VAR_4, VAR_5, VAR_6; for (VAR_3 = 0; VAR_3 < 3; VAR_3++) { int VAR_7 = MAX_BLOCKSIZE >> (VAR_3 ? VAR_0->chroma_x_shift : 0); int VAR_8 = MAX_BLOCKSIZE >> (VAR_3 ? VAR_0->chroma_y_shift : 0); VAR_4 = VAR_0->source.width  >> (VAR_3 ? VAR_0->chroma_x_shift : 0); VAR_5 = VAR_0->source.height >> (VAR_3 ? VAR_0->chroma_y_shift : 0); VAR_6 = FFMAX(1<<MAX_DWT_LEVELS, VAR_8/2); VAR_4 = FFALIGN(CALC_PADDING(VAR_4, MAX_DWT_LEVELS), 8); VAR_5 = VAR_6 + CALC_PADDING(VAR_5, MAX_DWT_LEVELS) + VAR_8/2; VAR_0->plane[VAR_3].idwt_buf_base = av_mallocz_array((VAR_4+VAR_7), VAR_5 * sizeof(IDWTELEM)); VAR_0->plane[VAR_3].idwt_tmp      = av_malloc_array((VAR_4+16), sizeof(IDWTELEM)); VAR_0->plane[VAR_3].idwt_buf      = VAR_0->plane[VAR_3].idwt_buf_base + VAR_6*VAR_4; if (!VAR_0->plane[VAR_3].idwt_buf_base || !VAR_0->plane[VAR_3].idwt_tmp)
return AVERROR(ENOMEM); } VAR_4 = VAR_0->source.width; VAR_5 = VAR_0->source.height; VAR_0->sbsplit  = av_malloc_array(VAR_1, VAR_2); VAR_0->blmotion = av_malloc_array(VAR_1, VAR_2 * 16 * sizeof(*VAR_0->blmotion)); VAR_0->edge_emu_buffer_base = av_malloc_array((VAR_4+64), MAX_BLOCKSIZE); VAR_0->mctmp     = av_malloc_array((VAR_4+64+MAX_BLOCKSIZE), (VAR_5+MAX_BLOCKSIZE) * sizeof(*VAR_0->mctmp)); VAR_0->mcscratch = av_malloc_array((VAR_4+64), MAX_BLOCKSIZE); if (!VAR_0->sbsplit || !VAR_0->blmotion || !VAR_0->mctmp || !VAR_0->mcscratch)
return AVERROR(ENOMEM); return 0; }