static void dnxhd_decode_dct_block(DNXHDContext *ctx, DCTELEM *block, int n, int qscale)

{

    int i, j, index, index2;

    int level, component, sign;

    const uint8_t *weigth_matrix;



    if (n&2) {

        component = 1 + (n&1);

        weigth_matrix = ctx->cid_table->chroma_weigth;

    } else {

        component = 0;

        weigth_matrix = ctx->cid_table->luma_weigth;

    }



    ctx->last_dc[component] += dnxhd_decode_dc(ctx);

    block[0] = ctx->last_dc[component];

    //av_log(ctx->avctx, AV_LOG_DEBUG, "dc %d\n", block[0]);

    for (i = 1; ; i++) {

        index = get_vlc2(&ctx->gb, ctx->ac_vlc.table, DNXHD_VLC_BITS, 2);

        //av_log(ctx->avctx, AV_LOG_DEBUG, "index %d\n", index);

        level = ctx->cid_table->ac_level[index];

        if (!level) { /* EOB */

            //av_log(ctx->avctx, AV_LOG_DEBUG, "EOB\n");

            return;

        }

        sign = get_sbits(&ctx->gb, 1);



        if (ctx->cid_table->ac_index_flag[index]) {

            level += get_bits(&ctx->gb, ctx->cid_table->index_bits)<<6;

        }



        if (ctx->cid_table->ac_run_flag[index]) {

            index2 = get_vlc2(&ctx->gb, ctx->run_vlc.table, DNXHD_VLC_BITS, 2);

            i += ctx->cid_table->run[index2];

        }



        j = ctx->scantable.permutated[i];

        //av_log(ctx->avctx, AV_LOG_DEBUG, "j %d\n", j);

        //av_log(ctx->avctx, AV_LOG_DEBUG, "level %d, weigth %d\n", level, weigth_matrix[i]);

        level = (2*level+1) * qscale * weigth_matrix[i];

        if (weigth_matrix[i] != 32) // FIXME 10bit

            level += 32;

        level >>= 6;

        level = (level^sign) - sign;



        if (i > 63) {

            av_log(ctx->avctx, AV_LOG_ERROR, "ac tex damaged %d, %d\n", n, i);

            return;

        }



        //av_log(NULL, AV_LOG_DEBUG, "i %d, j %d, end level %d\n", i, j, level);

        block[j] = level;

    }

}

static void dnxhd_decode_dct_block(DNXHDContext *ctx, DCTELEM *block, int n, int qscale)

{

    int i, j, index, index2;

    int level, component, sign;

    const uint8_t *weigth_matrix;



    if (n&2) {

        component = 1 + (n&1);

        weigth_matrix = ctx->cid_table->chroma_weigth;

    } else {

        component = 0;

        weigth_matrix = ctx->cid_table->luma_weigth;

    }



    ctx->last_dc[component] += dnxhd_decode_dc(ctx);

    block[0] = ctx->last_dc[component];

    

    for (i = 1; ; i++) {

        index = get_vlc2(&ctx->gb, ctx->ac_vlc.table, DNXHD_VLC_BITS, 2);

        

        level = ctx->cid_table->ac_level[index];

        if (!level) { 

            

            return;

        }

        sign = get_sbits(&ctx->gb, 1);



        if (ctx->cid_table->ac_index_flag[index]) {

            level += get_bits(&ctx->gb, ctx->cid_table->index_bits)<<6;

        }



        if (ctx->cid_table->ac_run_flag[index]) {

            index2 = get_vlc2(&ctx->gb, ctx->run_vlc.table, DNXHD_VLC_BITS, 2);

            i += ctx->cid_table->run[index2];

        }



        j = ctx->scantable.permutated[i];

        

        

        level = (2*level+1) * qscale * weigth_matrix[i];

        if (weigth_matrix[i] != 32) 

            level += 32;

        level >>= 6;

        level = (level^sign) - sign;



        if (i > 63) {

            av_log(ctx->avctx, AV_LOG_ERROR, "ac tex damaged %d, %d\n", n, i);

            return;

        }



        

        block[j] = level;

    }

}

static void FUNC_0(DNXHDContext *VAR_0, DCTELEM *VAR_1, int VAR_2, int VAR_3)

{

    int VAR_4, VAR_5, VAR_6, VAR_7;

    int VAR_8, VAR_9, VAR_10;

    const uint8_t *VAR_11;



    if (VAR_2&2) {

        VAR_9 = 1 + (VAR_2&1);

        VAR_11 = VAR_0->cid_table->chroma_weigth;

    } else {

        VAR_9 = 0;

        VAR_11 = VAR_0->cid_table->luma_weigth;

    }



    VAR_0->last_dc[VAR_9] += dnxhd_decode_dc(VAR_0);

    VAR_1[0] = VAR_0->last_dc[VAR_9];

    

    for (VAR_4 = 1; ; VAR_4++) {

        VAR_6 = get_vlc2(&VAR_0->gb, VAR_0->ac_vlc.table, DNXHD_VLC_BITS, 2);

        

        VAR_8 = VAR_0->cid_table->ac_level[VAR_6];

        if (!VAR_8) { 

            

            return;

        }

        VAR_10 = get_sbits(&VAR_0->gb, 1);



        if (VAR_0->cid_table->ac_index_flag[VAR_6]) {

            VAR_8 += get_bits(&VAR_0->gb, VAR_0->cid_table->index_bits)<<6;

        }



        if (VAR_0->cid_table->ac_run_flag[VAR_6]) {

            VAR_7 = get_vlc2(&VAR_0->gb, VAR_0->run_vlc.table, DNXHD_VLC_BITS, 2);

            VAR_4 += VAR_0->cid_table->run[VAR_7];

        }



        VAR_5 = VAR_0->scantable.permutated[VAR_4];

        

        

        VAR_8 = (2*VAR_8+1) * VAR_3 * VAR_11[VAR_4];

        if (VAR_11[VAR_4] != 32) 

            VAR_8 += 32;

        VAR_8 >>= 6;

        VAR_8 = (VAR_8^VAR_10) - VAR_10;



        if (VAR_4 > 63) {

            av_log(VAR_0->avctx, AV_LOG_ERROR, "ac tex damaged %d, %d\VAR_2", VAR_2, VAR_4);

            return;

        }



        

        VAR_1[VAR_5] = VAR_8;

    }

}

static void FUNC_0(DNXHDContext *VAR_0, DCTELEM *VAR_1, int VAR_2, int VAR_3)
{ int VAR_4, VAR_5, VAR_6, VAR_7; int VAR_8, VAR_9, VAR_10; const uint8_t *VAR_11; if (VAR_2&2) { VAR_9 = 1 + (VAR_2&1); VAR_11 = VAR_0->cid_table->chroma_weigth; } else { VAR_9 = 0; VAR_11 = VAR_0->cid_table->luma_weigth; } VAR_0->last_dc[VAR_9] += dnxhd_decode_dc(VAR_0); VAR_1[0] = VAR_0->last_dc[VAR_9]; for (VAR_4 = 1; ; VAR_4++) { VAR_6 = get_vlc2(&VAR_0->gb, VAR_0->ac_vlc.table, DNXHD_VLC_BITS, 2); VAR_8 = VAR_0->cid_table->ac_level[VAR_6]; if (!VAR_8) { return; } VAR_10 = get_sbits(&VAR_0->gb, 1); if (VAR_0->cid_table->ac_index_flag[VAR_6]) { VAR_8 += get_bits(&VAR_0->gb, VAR_0->cid_table->index_bits)<<6; } if (VAR_0->cid_table->ac_run_flag[VAR_6]) { VAR_7 = get_vlc2(&VAR_0->gb, VAR_0->run_vlc.table, DNXHD_VLC_BITS, 2); VAR_4 += VAR_0->cid_table->run[VAR_7]; } VAR_5 = VAR_0->scantable.permutated[VAR_4]; VAR_8 = (2*VAR_8+1) * VAR_3 * VAR_11[VAR_4]; if (VAR_11[VAR_4] != 32)
VAR_8 += 32; VAR_8 >>= 6; VAR_8 = (VAR_8^VAR_10) - VAR_10; if (VAR_4 > 63) { av_log(VAR_0->avctx, AV_LOG_ERROR, "ac tex damaged %d, %d\VAR_2", VAR_2, VAR_4); return; } VAR_1[VAR_5] = VAR_8; } }