static int dirac_decode_frame_internal(DiracContext *s)

{

    DWTContext d;

    int y, i, comp, dsty;



    if (s->low_delay) {

        /* [DIRAC_STD] 13.5.1 low_delay_transform_data() */

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

            Plane *p = &s->plane[comp];

            memset(p->idwt_buf, 0, p->idwt_stride * p->idwt_height * sizeof(IDWTELEM));

        }

        if (!s->zero_res)

            decode_lowdelay(s);

    }



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

        Plane *p       = &s->plane[comp];

        uint8_t *frame = s->current_picture->avframe->data[comp];



        /* FIXME: small resolutions */

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

            s->edge_emu_buffer[i] = s->edge_emu_buffer_base + i*FFALIGN(p->width, 16);



        if (!s->zero_res && !s->low_delay)

        {

            memset(p->idwt_buf, 0, p->idwt_stride * p->idwt_height * sizeof(IDWTELEM));

            decode_component(s, comp); /* [DIRAC_STD] 13.4.1 core_transform_data() */

        }

        if (ff_spatial_idwt_init2(&d, p->idwt_buf, p->idwt_width, p->idwt_height, p->idwt_stride,

                                  s->wavelet_idx+2, s->wavelet_depth, p->idwt_tmp))

            return -1;



        if (!s->num_refs) { /* intra */

            for (y = 0; y < p->height; y += 16) {

                ff_spatial_idwt_slice2(&d, y+16); /* decode */

                s->diracdsp.put_signed_rect_clamped(frame + y*p->stride, p->stride,

                                                    p->idwt_buf + y*p->idwt_stride, p->idwt_stride, p->width, 16);

            }

        } else { /* inter */

            int rowheight = p->ybsep*p->stride;



            select_dsp_funcs(s, p->width, p->height, p->xblen, p->yblen);



            for (i = 0; i < s->num_refs; i++)

                interpolate_refplane(s, s->ref_pics[i], comp, p->width, p->height);



            memset(s->mctmp, 0, 4*p->yoffset*p->stride);



            dsty = -p->yoffset;

            for (y = 0; y < s->blheight; y++) {

                int h     = 0,

                    start = FFMAX(dsty, 0);

                uint16_t *mctmp    = s->mctmp + y*rowheight;

                DiracBlock *blocks = s->blmotion + y*s->blwidth;



                init_obmc_weights(s, p, y);



                if (y == s->blheight-1 || start+p->ybsep > p->height)

                    h = p->height - start;

                else

                    h = p->ybsep - (start - dsty);

                if (h < 0)

                    break;



                memset(mctmp+2*p->yoffset*p->stride, 0, 2*rowheight);

                mc_row(s, blocks, mctmp, comp, dsty);



                mctmp += (start - dsty)*p->stride + p->xoffset;

                ff_spatial_idwt_slice2(&d, start + h); /* decode */

                s->diracdsp.add_rect_clamped(frame + start*p->stride, mctmp, p->stride,

                                             p->idwt_buf + start*p->idwt_stride, p->idwt_stride, p->width, h);



                dsty += p->ybsep;

            }

        }

    }





    return 0;

}

static int dirac_decode_frame_internal(DiracContext *s)

{

    DWTContext d;

    int y, i, comp, dsty;



    if (s->low_delay) {

        

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

            Plane *p = &s->plane[comp];

            memset(p->idwt_buf, 0, p->idwt_stride * p->idwt_height * sizeof(IDWTELEM));

        }

        if (!s->zero_res)

            decode_lowdelay(s);

    }



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

        Plane *p       = &s->plane[comp];

        uint8_t *frame = s->current_picture->avframe->data[comp];



        

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

            s->edge_emu_buffer[i] = s->edge_emu_buffer_base + i*FFALIGN(p->width, 16);



        if (!s->zero_res && !s->low_delay)

        {

            memset(p->idwt_buf, 0, p->idwt_stride * p->idwt_height * sizeof(IDWTELEM));

            decode_component(s, comp); 

        }

        if (ff_spatial_idwt_init2(&d, p->idwt_buf, p->idwt_width, p->idwt_height, p->idwt_stride,

                                  s->wavelet_idx+2, s->wavelet_depth, p->idwt_tmp))

            return -1;



        if (!s->num_refs) { 

            for (y = 0; y < p->height; y += 16) {

                ff_spatial_idwt_slice2(&d, y+16); 

                s->diracdsp.put_signed_rect_clamped(frame + y*p->stride, p->stride,

                                                    p->idwt_buf + y*p->idwt_stride, p->idwt_stride, p->width, 16);

            }

        } else { 

            int rowheight = p->ybsep*p->stride;



            select_dsp_funcs(s, p->width, p->height, p->xblen, p->yblen);



            for (i = 0; i < s->num_refs; i++)

                interpolate_refplane(s, s->ref_pics[i], comp, p->width, p->height);



            memset(s->mctmp, 0, 4*p->yoffset*p->stride);



            dsty = -p->yoffset;

            for (y = 0; y < s->blheight; y++) {

                int h     = 0,

                    start = FFMAX(dsty, 0);

                uint16_t *mctmp    = s->mctmp + y*rowheight;

                DiracBlock *blocks = s->blmotion + y*s->blwidth;



                init_obmc_weights(s, p, y);



                if (y == s->blheight-1 || start+p->ybsep > p->height)

                    h = p->height - start;

                else

                    h = p->ybsep - (start - dsty);

                if (h < 0)

                    break;



                memset(mctmp+2*p->yoffset*p->stride, 0, 2*rowheight);

                mc_row(s, blocks, mctmp, comp, dsty);



                mctmp += (start - dsty)*p->stride + p->xoffset;

                ff_spatial_idwt_slice2(&d, start + h); 

                s->diracdsp.add_rect_clamped(frame + start*p->stride, mctmp, p->stride,

                                             p->idwt_buf + start*p->idwt_stride, p->idwt_stride, p->width, h);



                dsty += p->ybsep;

            }

        }

    }





    return 0;

}

static int FUNC_0(DiracContext *VAR_0)

{

    DWTContext d;

    int VAR_1, VAR_2, VAR_3, VAR_4;



    if (VAR_0->low_delay) {

        

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

            Plane *p = &VAR_0->plane[VAR_3];

            memset(p->idwt_buf, 0, p->idwt_stride * p->idwt_height * sizeof(IDWTELEM));

        }

        if (!VAR_0->zero_res)

            decode_lowdelay(VAR_0);

    }



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

        Plane *p       = &VAR_0->plane[VAR_3];

        uint8_t *frame = VAR_0->current_picture->avframe->data[VAR_3];



        

        for (VAR_2 = 0; VAR_2 < 4; VAR_2++)

            VAR_0->edge_emu_buffer[VAR_2] = VAR_0->edge_emu_buffer_base + VAR_2*FFALIGN(p->width, 16);



        if (!VAR_0->zero_res && !VAR_0->low_delay)

        {

            memset(p->idwt_buf, 0, p->idwt_stride * p->idwt_height * sizeof(IDWTELEM));

            decode_component(VAR_0, VAR_3); 

        }

        if (ff_spatial_idwt_init2(&d, p->idwt_buf, p->idwt_width, p->idwt_height, p->idwt_stride,

                                  VAR_0->wavelet_idx+2, VAR_0->wavelet_depth, p->idwt_tmp))

            return -1;



        if (!VAR_0->num_refs) { 

            for (VAR_1 = 0; VAR_1 < p->height; VAR_1 += 16) {

                ff_spatial_idwt_slice2(&d, VAR_1+16); 

                VAR_0->diracdsp.put_signed_rect_clamped(frame + VAR_1*p->stride, p->stride,

                                                    p->idwt_buf + VAR_1*p->idwt_stride, p->idwt_stride, p->width, 16);

            }

        } else { 

            int VAR_5 = p->ybsep*p->stride;



            select_dsp_funcs(VAR_0, p->width, p->height, p->xblen, p->yblen);



            for (VAR_2 = 0; VAR_2 < VAR_0->num_refs; VAR_2++)

                interpolate_refplane(VAR_0, VAR_0->ref_pics[VAR_2], VAR_3, p->width, p->height);



            memset(VAR_0->mctmp, 0, 4*p->yoffset*p->stride);



            VAR_4 = -p->yoffset;

            for (VAR_1 = 0; VAR_1 < VAR_0->blheight; VAR_1++) {

                int h     = 0,

                    start = FFMAX(VAR_4, 0);

                uint16_t *mctmp    = VAR_0->mctmp + VAR_1*VAR_5;

                DiracBlock *blocks = VAR_0->blmotion + VAR_1*VAR_0->blwidth;



                init_obmc_weights(VAR_0, p, VAR_1);



                if (VAR_1 == VAR_0->blheight-1 || start+p->ybsep > p->height)

                    h = p->height - start;

                else

                    h = p->ybsep - (start - VAR_4);

                if (h < 0)

                    break;



                memset(mctmp+2*p->yoffset*p->stride, 0, 2*VAR_5);

                mc_row(VAR_0, blocks, mctmp, VAR_3, VAR_4);



                mctmp += (start - VAR_4)*p->stride + p->xoffset;

                ff_spatial_idwt_slice2(&d, start + h); 

                VAR_0->diracdsp.add_rect_clamped(frame + start*p->stride, mctmp, p->stride,

                                             p->idwt_buf + start*p->idwt_stride, p->idwt_stride, p->width, h);



                VAR_4 += p->ybsep;

            }

        }

    }





    return 0;

}

static int FUNC_0(DiracContext *VAR_0)
{ DWTContext d; int VAR_1, VAR_2, VAR_3, VAR_4; if (VAR_0->low_delay) { for (VAR_3 = 0; VAR_3 < 3; VAR_3++) { Plane *p = &VAR_0->plane[VAR_3]; memset(p->idwt_buf, 0, p->idwt_stride * p->idwt_height * sizeof(IDWTELEM)); } if (!VAR_0->zero_res)
decode_lowdelay(VAR_0); } for (VAR_3 = 0; VAR_3 < 3; VAR_3++) { Plane *p       = &VAR_0->plane[VAR_3]; uint8_t *frame = VAR_0->current_picture->avframe->data[VAR_3]; for (VAR_2 = 0; VAR_2 < 4; VAR_2++) VAR_0->edge_emu_buffer[VAR_2] = VAR_0->edge_emu_buffer_base + VAR_2*FFALIGN(p->width, 16); if (!VAR_0->zero_res && !VAR_0->low_delay)
{ memset(p->idwt_buf, 0, p->idwt_stride * p->idwt_height * sizeof(IDWTELEM)); decode_component(VAR_0, VAR_3); } if (ff_spatial_idwt_init2(&d, p->idwt_buf, p->idwt_width, p->idwt_height, p->idwt_stride,
VAR_0->wavelet_idx+2, VAR_0->wavelet_depth, p->idwt_tmp))
return -1; if (!VAR_0->num_refs) { for (VAR_1 = 0; VAR_1 < p->height; VAR_1 += 16) { ff_spatial_idwt_slice2(&d, VAR_1+16); VAR_0->diracdsp.put_signed_rect_clamped(frame + VAR_1*p->stride, p->stride,
p->idwt_buf + VAR_1*p->idwt_stride, p->idwt_stride, p->width, 16); } } else { int VAR_5 = p->ybsep*p->stride; select_dsp_funcs(VAR_0, p->width, p->height, p->xblen, p->yblen); for (VAR_2 = 0; VAR_2 < VAR_0->num_refs; VAR_2++) interpolate_refplane(VAR_0, VAR_0->ref_pics[VAR_2], VAR_3, p->width, p->height); memset(VAR_0->mctmp, 0, 4*p->yoffset*p->stride); VAR_4 = -p->yoffset; for (VAR_1 = 0; VAR_1 < VAR_0->blheight; VAR_1++) { int h     = 0,
start = FFMAX(VAR_4, 0); uint16_t *mctmp    = VAR_0->mctmp + VAR_1*VAR_5; DiracBlock *blocks = VAR_0->blmotion + VAR_1*VAR_0->blwidth; init_obmc_weights(VAR_0, p, VAR_1); if (VAR_1 == VAR_0->blheight-1 || start+p->ybsep > p->height)
h = p->height - start; else
h = p->ybsep - (start - VAR_4); if (h < 0)
break; memset(mctmp+2*p->yoffset*p->stride, 0, 2*VAR_5); mc_row(VAR_0, blocks, mctmp, VAR_3, VAR_4); mctmp += (start - VAR_4)*p->stride + p->xoffset; ff_spatial_idwt_slice2(&d, start + h); VAR_0->diracdsp.add_rect_clamped(frame + start*p->stride, mctmp, p->stride,
p->idwt_buf + start*p->idwt_stride, p->idwt_stride, p->width, h); VAR_4 += p->ybsep; } } } return 0; }