static int alloc_buffers(AVCodecContext *avctx)

{

    CFHDContext *s = avctx->priv_data;

    int i, j, k, ret, planes;



    if ((ret = ff_set_dimensions(avctx, s->coded_width, s->coded_height)) < 0)

        return ret;

    avctx->pix_fmt = s->coded_format;



    avcodec_get_chroma_sub_sample(avctx->pix_fmt, &s->chroma_x_shift, &s->chroma_y_shift);

    planes = av_pix_fmt_count_planes(avctx->pix_fmt);



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

        int width = i ? avctx->width >> s->chroma_x_shift : avctx->width;

        int height = i ? avctx->height >> s->chroma_y_shift : avctx->height;

        int stride = FFALIGN(width / 8, 8) * 8;

        int w8, h8, w4, h4, w2, h2;

        height = FFALIGN(height / 8, 2) * 8;

        s->plane[i].width = width;

        s->plane[i].height = height;

        s->plane[i].stride = stride;



        w8 = FFALIGN(s->plane[i].width / 8, 8);

        h8 = FFALIGN(s->plane[i].height / 8, 2);

        w4 = w8 * 2;

        h4 = h8 * 2;

        w2 = w4 * 2;

        h2 = h4 * 2;



        s->plane[i].idwt_buf = av_malloc_array(height * stride, sizeof(*s->plane[i].idwt_buf));

        s->plane[i].idwt_tmp = av_malloc_array(height * stride, sizeof(*s->plane[i].idwt_tmp));

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

            return AVERROR(ENOMEM);

        }



        s->plane[i].subband[0] = s->plane[i].idwt_buf;

        s->plane[i].subband[1] = s->plane[i].idwt_buf + 2 * w8 * h8;

        s->plane[i].subband[2] = s->plane[i].idwt_buf + 1 * w8 * h8;

        s->plane[i].subband[3] = s->plane[i].idwt_buf + 3 * w8 * h8;

        s->plane[i].subband[4] = s->plane[i].idwt_buf + 2 * w4 * h4;

        s->plane[i].subband[5] = s->plane[i].idwt_buf + 1 * w4 * h4;

        s->plane[i].subband[6] = s->plane[i].idwt_buf + 3 * w4 * h4;

        s->plane[i].subband[7] = s->plane[i].idwt_buf + 2 * w2 * h2;

        s->plane[i].subband[8] = s->plane[i].idwt_buf + 1 * w2 * h2;

        s->plane[i].subband[9] = s->plane[i].idwt_buf + 3 * w2 * h2;



        for (j = 0; j < DWT_LEVELS; j++) {

            for(k = 0; k < 4; k++) {

                s->plane[i].band[j][k].a_width  = w8 << j;

                s->plane[i].band[j][k].a_height = h8 << j;

            }

        }



        /* ll2 and ll1 commented out because they are done in-place */

        s->plane[i].l_h[0] = s->plane[i].idwt_tmp;

        s->plane[i].l_h[1] = s->plane[i].idwt_tmp + 2 * w8 * h8;

        //s->plane[i].l_h[2] = ll2;

        s->plane[i].l_h[3] = s->plane[i].idwt_tmp;

        s->plane[i].l_h[4] = s->plane[i].idwt_tmp + 2 * w4 * h4;

        //s->plane[i].l_h[5] = ll1;

        s->plane[i].l_h[6] = s->plane[i].idwt_tmp;

        s->plane[i].l_h[7] = s->plane[i].idwt_tmp + 2 * w2 * h2;

    }



    s->a_height = s->coded_height;

    s->a_width  = s->coded_width;

    s->a_format = s->coded_format;



    return 0;

}

static int alloc_buffers(AVCodecContext *avctx)

{

    CFHDContext *s = avctx->priv_data;

    int i, j, k, ret, planes;



    if ((ret = ff_set_dimensions(avctx, s->coded_width, s->coded_height)) < 0)

        return ret;

    avctx->pix_fmt = s->coded_format;



    avcodec_get_chroma_sub_sample(avctx->pix_fmt, &s->chroma_x_shift, &s->chroma_y_shift);

    planes = av_pix_fmt_count_planes(avctx->pix_fmt);



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

        int width = i ? avctx->width >> s->chroma_x_shift : avctx->width;

        int height = i ? avctx->height >> s->chroma_y_shift : avctx->height;

        int stride = FFALIGN(width / 8, 8) * 8;

        int w8, h8, w4, h4, w2, h2;

        height = FFALIGN(height / 8, 2) * 8;

        s->plane[i].width = width;

        s->plane[i].height = height;

        s->plane[i].stride = stride;



        w8 = FFALIGN(s->plane[i].width / 8, 8);

        h8 = FFALIGN(s->plane[i].height / 8, 2);

        w4 = w8 * 2;

        h4 = h8 * 2;

        w2 = w4 * 2;

        h2 = h4 * 2;



        s->plane[i].idwt_buf = av_malloc_array(height * stride, sizeof(*s->plane[i].idwt_buf));

        s->plane[i].idwt_tmp = av_malloc_array(height * stride, sizeof(*s->plane[i].idwt_tmp));

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

            return AVERROR(ENOMEM);

        }



        s->plane[i].subband[0] = s->plane[i].idwt_buf;

        s->plane[i].subband[1] = s->plane[i].idwt_buf + 2 * w8 * h8;

        s->plane[i].subband[2] = s->plane[i].idwt_buf + 1 * w8 * h8;

        s->plane[i].subband[3] = s->plane[i].idwt_buf + 3 * w8 * h8;

        s->plane[i].subband[4] = s->plane[i].idwt_buf + 2 * w4 * h4;

        s->plane[i].subband[5] = s->plane[i].idwt_buf + 1 * w4 * h4;

        s->plane[i].subband[6] = s->plane[i].idwt_buf + 3 * w4 * h4;

        s->plane[i].subband[7] = s->plane[i].idwt_buf + 2 * w2 * h2;

        s->plane[i].subband[8] = s->plane[i].idwt_buf + 1 * w2 * h2;

        s->plane[i].subband[9] = s->plane[i].idwt_buf + 3 * w2 * h2;



        for (j = 0; j < DWT_LEVELS; j++) {

            for(k = 0; k < 4; k++) {

                s->plane[i].band[j][k].a_width  = w8 << j;

                s->plane[i].band[j][k].a_height = h8 << j;

            }

        }



        

        s->plane[i].l_h[0] = s->plane[i].idwt_tmp;

        s->plane[i].l_h[1] = s->plane[i].idwt_tmp + 2 * w8 * h8;

        

        s->plane[i].l_h[3] = s->plane[i].idwt_tmp;

        s->plane[i].l_h[4] = s->plane[i].idwt_tmp + 2 * w4 * h4;

        

        s->plane[i].l_h[6] = s->plane[i].idwt_tmp;

        s->plane[i].l_h[7] = s->plane[i].idwt_tmp + 2 * w2 * h2;

    }



    s->a_height = s->coded_height;

    s->a_width  = s->coded_width;

    s->a_format = s->coded_format;



    return 0;

}

        s->plane[i].idwt_buf = av_malloc_array(height * stride, sizeof(*s->plane[i].idwt_buf));
static int FUNC_0(AVCodecContext *VAR_0)

{

    CFHDContext *s = VAR_0->priv_data;

    int VAR_1, VAR_2, VAR_3, VAR_4, VAR_5;



    if ((VAR_4 = ff_set_dimensions(VAR_0, s->coded_width, s->coded_height)) < 0)

        return VAR_4;

    VAR_0->pix_fmt = s->coded_format;



    avcodec_get_chroma_sub_sample(VAR_0->pix_fmt, &s->chroma_x_shift, &s->chroma_y_shift);

    VAR_5 = av_pix_fmt_count_planes(VAR_0->pix_fmt);



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

        int VAR_6 = VAR_1 ? VAR_0->VAR_6 >> s->chroma_x_shift : VAR_0->VAR_6;

        int VAR_7 = VAR_1 ? VAR_0->VAR_7 >> s->chroma_y_shift : VAR_0->VAR_7;

        int VAR_8 = FFALIGN(VAR_6 / 8, 8) * 8;

        int VAR_9, VAR_10, VAR_11, VAR_12, VAR_13, VAR_14;

        VAR_7 = FFALIGN(VAR_7 / 8, 2) * 8;

        s->plane[VAR_1].VAR_6 = VAR_6;

        s->plane[VAR_1].VAR_7 = VAR_7;

        s->plane[VAR_1].VAR_8 = VAR_8;



        VAR_9 = FFALIGN(s->plane[VAR_1].VAR_6 / 8, 8);

        VAR_10 = FFALIGN(s->plane[VAR_1].VAR_7 / 8, 2);

        VAR_11 = VAR_9 * 2;

        VAR_12 = VAR_10 * 2;

        VAR_13 = VAR_11 * 2;

        VAR_14 = VAR_12 * 2;



        s->plane[VAR_1].idwt_buf = av_malloc_array(VAR_7 * VAR_8, sizeof(*s->plane[VAR_1].idwt_buf));

        s->plane[VAR_1].idwt_tmp = av_malloc_array(VAR_7 * VAR_8, sizeof(*s->plane[VAR_1].idwt_tmp));

        if (!s->plane[VAR_1].idwt_buf || !s->plane[VAR_1].idwt_tmp) {

            return AVERROR(ENOMEM);

        }



        s->plane[VAR_1].subband[0] = s->plane[VAR_1].idwt_buf;

        s->plane[VAR_1].subband[1] = s->plane[VAR_1].idwt_buf + 2 * VAR_9 * VAR_10;

        s->plane[VAR_1].subband[2] = s->plane[VAR_1].idwt_buf + 1 * VAR_9 * VAR_10;

        s->plane[VAR_1].subband[3] = s->plane[VAR_1].idwt_buf + 3 * VAR_9 * VAR_10;

        s->plane[VAR_1].subband[4] = s->plane[VAR_1].idwt_buf + 2 * VAR_11 * VAR_12;

        s->plane[VAR_1].subband[5] = s->plane[VAR_1].idwt_buf + 1 * VAR_11 * VAR_12;

        s->plane[VAR_1].subband[6] = s->plane[VAR_1].idwt_buf + 3 * VAR_11 * VAR_12;

        s->plane[VAR_1].subband[7] = s->plane[VAR_1].idwt_buf + 2 * VAR_13 * VAR_14;

        s->plane[VAR_1].subband[8] = s->plane[VAR_1].idwt_buf + 1 * VAR_13 * VAR_14;

        s->plane[VAR_1].subband[9] = s->plane[VAR_1].idwt_buf + 3 * VAR_13 * VAR_14;



        for (VAR_2 = 0; VAR_2 < DWT_LEVELS; VAR_2++) {

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

                s->plane[VAR_1].band[VAR_2][VAR_3].a_width  = VAR_9 << VAR_2;

                s->plane[VAR_1].band[VAR_2][VAR_3].a_height = VAR_10 << VAR_2;

            }

        }



        

        s->plane[VAR_1].l_h[0] = s->plane[VAR_1].idwt_tmp;

        s->plane[VAR_1].l_h[1] = s->plane[VAR_1].idwt_tmp + 2 * VAR_9 * VAR_10;

        

        s->plane[VAR_1].l_h[3] = s->plane[VAR_1].idwt_tmp;

        s->plane[VAR_1].l_h[4] = s->plane[VAR_1].idwt_tmp + 2 * VAR_11 * VAR_12;

        

        s->plane[VAR_1].l_h[6] = s->plane[VAR_1].idwt_tmp;

        s->plane[VAR_1].l_h[7] = s->plane[VAR_1].idwt_tmp + 2 * VAR_13 * VAR_14;

    }



    s->a_height = s->coded_height;

    s->a_width  = s->coded_width;

    s->a_format = s->coded_format;



    return 0;

}

static int FUNC_0(AVCodecContext *VAR_0)
{ CFHDContext *s = VAR_0->priv_data; int VAR_1, VAR_2, VAR_3, VAR_4, VAR_5; if ((VAR_4 = ff_set_dimensions(VAR_0, s->coded_width, s->coded_height)) < 0)
return VAR_4; VAR_0->pix_fmt = s->coded_format; avcodec_get_chroma_sub_sample(VAR_0->pix_fmt, &s->chroma_x_shift, &s->chroma_y_shift); VAR_5 = av_pix_fmt_count_planes(VAR_0->pix_fmt); for (VAR_1 = 0; VAR_1 < VAR_5; VAR_1++) { int VAR_6 = VAR_1 ? VAR_0->VAR_6 >> s->chroma_x_shift : VAR_0->VAR_6; int VAR_7 = VAR_1 ? VAR_0->VAR_7 >> s->chroma_y_shift : VAR_0->VAR_7; int VAR_8 = FFALIGN(VAR_6 / 8, 8) * 8; int VAR_9, VAR_10, VAR_11, VAR_12, VAR_13, VAR_14; VAR_7 = FFALIGN(VAR_7 / 8, 2) * 8; s->plane[VAR_1].VAR_6 = VAR_6; s->plane[VAR_1].VAR_7 = VAR_7; s->plane[VAR_1].VAR_8 = VAR_8; VAR_9 = FFALIGN(s->plane[VAR_1].VAR_6 / 8, 8); VAR_10 = FFALIGN(s->plane[VAR_1].VAR_7 / 8, 2); VAR_11 = VAR_9 * 2; VAR_12 = VAR_10 * 2; VAR_13 = VAR_11 * 2; VAR_14 = VAR_12 * 2; s->plane[VAR_1].idwt_buf = av_malloc_array(VAR_7 * VAR_8, sizeof(*s->plane[VAR_1].idwt_buf)); s->plane[VAR_1].idwt_tmp = av_malloc_array(VAR_7 * VAR_8, sizeof(*s->plane[VAR_1].idwt_tmp)); if (!s->plane[VAR_1].idwt_buf || !s->plane[VAR_1].idwt_tmp) { return AVERROR(ENOMEM); } s->plane[VAR_1].subband[0] = s->plane[VAR_1].idwt_buf; s->plane[VAR_1].subband[1] = s->plane[VAR_1].idwt_buf + 2 * VAR_9 * VAR_10; s->plane[VAR_1].subband[2] = s->plane[VAR_1].idwt_buf + 1 * VAR_9 * VAR_10; s->plane[VAR_1].subband[3] = s->plane[VAR_1].idwt_buf + 3 * VAR_9 * VAR_10; s->plane[VAR_1].subband[4] = s->plane[VAR_1].idwt_buf + 2 * VAR_11 * VAR_12; s->plane[VAR_1].subband[5] = s->plane[VAR_1].idwt_buf + 1 * VAR_11 * VAR_12; s->plane[VAR_1].subband[6] = s->plane[VAR_1].idwt_buf + 3 * VAR_11 * VAR_12; s->plane[VAR_1].subband[7] = s->plane[VAR_1].idwt_buf + 2 * VAR_13 * VAR_14; s->plane[VAR_1].subband[8] = s->plane[VAR_1].idwt_buf + 1 * VAR_13 * VAR_14; s->plane[VAR_1].subband[9] = s->plane[VAR_1].idwt_buf + 3 * VAR_13 * VAR_14; for (VAR_2 = 0; VAR_2 < DWT_LEVELS; VAR_2++) { for(VAR_3 = 0; VAR_3 < 4; VAR_3++) { s->plane[VAR_1].band[VAR_2][VAR_3].a_width  = VAR_9 << VAR_2; s->plane[VAR_1].band[VAR_2][VAR_3].a_height = VAR_10 << VAR_2; } } s->plane[VAR_1].l_h[0] = s->plane[VAR_1].idwt_tmp; s->plane[VAR_1].l_h[1] = s->plane[VAR_1].idwt_tmp + 2 * VAR_9 * VAR_10; s->plane[VAR_1].l_h[3] = s->plane[VAR_1].idwt_tmp; s->plane[VAR_1].l_h[4] = s->plane[VAR_1].idwt_tmp + 2 * VAR_11 * VAR_12; s->plane[VAR_1].l_h[6] = s->plane[VAR_1].idwt_tmp; s->plane[VAR_1].l_h[7] = s->plane[VAR_1].idwt_tmp + 2 * VAR_13 * VAR_14; } s->a_height = s->coded_height; s->a_width  = s->coded_width; s->a_format = s->coded_format; return 0; }