static int dnxhd_decode_macroblock(const DNXHDContext *ctx, RowContext *row,

                                   AVFrame *frame, int x, int y)

{

    int shift1 = ctx->bit_depth >= 10;

    int dct_linesize_luma   = frame->linesize[0];

    int dct_linesize_chroma = frame->linesize[1];

    uint8_t *dest_y, *dest_u, *dest_v;

    int dct_y_offset, dct_x_offset;

    int qscale, i, act;

    int interlaced_mb = 0;



    if (ctx->mbaff) {

        interlaced_mb = get_bits1(&row->gb);

        qscale = get_bits(&row->gb, 10);

    } else {

        qscale = get_bits(&row->gb, 11);

    }

    act = get_bits1(&row->gb);

    if (act) {

        static int warned = 0;

        if (!warned) {

            warned = 1;

            av_log(ctx->avctx, AV_LOG_ERROR,

                   "Unsupported adaptive color transform, patch welcome.\n");

        }

    }



    if (qscale != row->last_qscale) {

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

            row->luma_scale[i]   = qscale * ctx->cid_table->luma_weight[i];

            row->chroma_scale[i] = qscale * ctx->cid_table->chroma_weight[i];

        }

        row->last_qscale = qscale;

    }



    for (i = 0; i < 8 + 4 * ctx->is_444; i++) {

        if (ctx->decode_dct_block(ctx, row, i) < 0)

            return AVERROR_INVALIDDATA;

    }



    if (frame->interlaced_frame) {

        dct_linesize_luma   <<= 1;

        dct_linesize_chroma <<= 1;

    }



    dest_y = frame->data[0] + ((y * dct_linesize_luma)   << 4) + (x << (4 + shift1));

    dest_u = frame->data[1] + ((y * dct_linesize_chroma) << 4) + (x << (3 + shift1 + ctx->is_444));

    dest_v = frame->data[2] + ((y * dct_linesize_chroma) << 4) + (x << (3 + shift1 + ctx->is_444));



    if (frame->interlaced_frame && ctx->cur_field) {

        dest_y += frame->linesize[0];

        dest_u += frame->linesize[1];

        dest_v += frame->linesize[2];

    }

    if (interlaced_mb) {

        dct_linesize_luma   <<= 1;

        dct_linesize_chroma <<= 1;

    }



    dct_y_offset = interlaced_mb ? frame->linesize[0] : (dct_linesize_luma << 3);

    dct_x_offset = 8 << shift1;

    if (!ctx->is_444) {

        ctx->idsp.idct_put(dest_y,                               dct_linesize_luma, row->blocks[0]);

        ctx->idsp.idct_put(dest_y + dct_x_offset,                dct_linesize_luma, row->blocks[1]);

        ctx->idsp.idct_put(dest_y + dct_y_offset,                dct_linesize_luma, row->blocks[4]);

        ctx->idsp.idct_put(dest_y + dct_y_offset + dct_x_offset, dct_linesize_luma, row->blocks[5]);



        if (!(ctx->avctx->flags & AV_CODEC_FLAG_GRAY)) {

            dct_y_offset = interlaced_mb ? frame->linesize[1] : (dct_linesize_chroma << 3);

            ctx->idsp.idct_put(dest_u,                dct_linesize_chroma, row->blocks[2]);

            ctx->idsp.idct_put(dest_v,                dct_linesize_chroma, row->blocks[3]);

            ctx->idsp.idct_put(dest_u + dct_y_offset, dct_linesize_chroma, row->blocks[6]);

            ctx->idsp.idct_put(dest_v + dct_y_offset, dct_linesize_chroma, row->blocks[7]);

        }

    } else {

        ctx->idsp.idct_put(dest_y,                               dct_linesize_luma, row->blocks[0]);

        ctx->idsp.idct_put(dest_y + dct_x_offset,                dct_linesize_luma, row->blocks[1]);

        ctx->idsp.idct_put(dest_y + dct_y_offset,                dct_linesize_luma, row->blocks[6]);

        ctx->idsp.idct_put(dest_y + dct_y_offset + dct_x_offset, dct_linesize_luma, row->blocks[7]);



        if (!(ctx->avctx->flags & AV_CODEC_FLAG_GRAY)) {

            dct_y_offset = interlaced_mb ? frame->linesize[1] : (dct_linesize_chroma << 3);

            ctx->idsp.idct_put(dest_u,                               dct_linesize_chroma, row->blocks[2]);

            ctx->idsp.idct_put(dest_u + dct_x_offset,                dct_linesize_chroma, row->blocks[3]);

            ctx->idsp.idct_put(dest_u + dct_y_offset,                dct_linesize_chroma, row->blocks[8]);

            ctx->idsp.idct_put(dest_u + dct_y_offset + dct_x_offset, dct_linesize_chroma, row->blocks[9]);

            ctx->idsp.idct_put(dest_v,                               dct_linesize_chroma, row->blocks[4]);

            ctx->idsp.idct_put(dest_v + dct_x_offset,                dct_linesize_chroma, row->blocks[5]);

            ctx->idsp.idct_put(dest_v + dct_y_offset,                dct_linesize_chroma, row->blocks[10]);

            ctx->idsp.idct_put(dest_v + dct_y_offset + dct_x_offset, dct_linesize_chroma, row->blocks[11]);

        }

    }



    return 0;

}

static int dnxhd_decode_macroblock(const DNXHDContext *ctx, RowContext *row,

                                   AVFrame *frame, int x, int y)

{

    int shift1 = ctx->bit_depth >= 10;

    int dct_linesize_luma   = frame->linesize[0];

    int dct_linesize_chroma = frame->linesize[1];

    uint8_t *dest_y, *dest_u, *dest_v;

    int dct_y_offset, dct_x_offset;

    int qscale, i, act;

    int interlaced_mb = 0;



    if (ctx->mbaff) {

        interlaced_mb = get_bits1(&row->gb);

        qscale = get_bits(&row->gb, 10);

    } else {

        qscale = get_bits(&row->gb, 11);

    }

    act = get_bits1(&row->gb);

    if (act) {

        static int warned = 0;

        if (!warned) {

            warned = 1;

            av_log(ctx->avctx, AV_LOG_ERROR,

                   "Unsupported adaptive color transform, patch welcome.\n");

        }

    }



    if (qscale != row->last_qscale) {

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

            row->luma_scale[i]   = qscale * ctx->cid_table->luma_weight[i];

            row->chroma_scale[i] = qscale * ctx->cid_table->chroma_weight[i];

        }

        row->last_qscale = qscale;

    }



    for (i = 0; i < 8 + 4 * ctx->is_444; i++) {

        if (ctx->decode_dct_block(ctx, row, i) < 0)

            return AVERROR_INVALIDDATA;

    }



    if (frame->interlaced_frame) {

        dct_linesize_luma   <<= 1;

        dct_linesize_chroma <<= 1;

    }



    dest_y = frame->data[0] + ((y * dct_linesize_luma)   << 4) + (x << (4 + shift1));

    dest_u = frame->data[1] + ((y * dct_linesize_chroma) << 4) + (x << (3 + shift1 + ctx->is_444));

    dest_v = frame->data[2] + ((y * dct_linesize_chroma) << 4) + (x << (3 + shift1 + ctx->is_444));



    if (frame->interlaced_frame && ctx->cur_field) {

        dest_y += frame->linesize[0];

        dest_u += frame->linesize[1];

        dest_v += frame->linesize[2];

    }

    if (interlaced_mb) {

        dct_linesize_luma   <<= 1;

        dct_linesize_chroma <<= 1;

    }



    dct_y_offset = interlaced_mb ? frame->linesize[0] : (dct_linesize_luma << 3);

    dct_x_offset = 8 << shift1;

    if (!ctx->is_444) {

        ctx->idsp.idct_put(dest_y,                               dct_linesize_luma, row->blocks[0]);

        ctx->idsp.idct_put(dest_y + dct_x_offset,                dct_linesize_luma, row->blocks[1]);

        ctx->idsp.idct_put(dest_y + dct_y_offset,                dct_linesize_luma, row->blocks[4]);

        ctx->idsp.idct_put(dest_y + dct_y_offset + dct_x_offset, dct_linesize_luma, row->blocks[5]);



        if (!(ctx->avctx->flags & AV_CODEC_FLAG_GRAY)) {

            dct_y_offset = interlaced_mb ? frame->linesize[1] : (dct_linesize_chroma << 3);

            ctx->idsp.idct_put(dest_u,                dct_linesize_chroma, row->blocks[2]);

            ctx->idsp.idct_put(dest_v,                dct_linesize_chroma, row->blocks[3]);

            ctx->idsp.idct_put(dest_u + dct_y_offset, dct_linesize_chroma, row->blocks[6]);

            ctx->idsp.idct_put(dest_v + dct_y_offset, dct_linesize_chroma, row->blocks[7]);

        }

    } else {

        ctx->idsp.idct_put(dest_y,                               dct_linesize_luma, row->blocks[0]);

        ctx->idsp.idct_put(dest_y + dct_x_offset,                dct_linesize_luma, row->blocks[1]);

        ctx->idsp.idct_put(dest_y + dct_y_offset,                dct_linesize_luma, row->blocks[6]);

        ctx->idsp.idct_put(dest_y + dct_y_offset + dct_x_offset, dct_linesize_luma, row->blocks[7]);



        if (!(ctx->avctx->flags & AV_CODEC_FLAG_GRAY)) {

            dct_y_offset = interlaced_mb ? frame->linesize[1] : (dct_linesize_chroma << 3);

            ctx->idsp.idct_put(dest_u,                               dct_linesize_chroma, row->blocks[2]);

            ctx->idsp.idct_put(dest_u + dct_x_offset,                dct_linesize_chroma, row->blocks[3]);

            ctx->idsp.idct_put(dest_u + dct_y_offset,                dct_linesize_chroma, row->blocks[8]);

            ctx->idsp.idct_put(dest_u + dct_y_offset + dct_x_offset, dct_linesize_chroma, row->blocks[9]);

            ctx->idsp.idct_put(dest_v,                               dct_linesize_chroma, row->blocks[4]);

            ctx->idsp.idct_put(dest_v + dct_x_offset,                dct_linesize_chroma, row->blocks[5]);

            ctx->idsp.idct_put(dest_v + dct_y_offset,                dct_linesize_chroma, row->blocks[10]);

            ctx->idsp.idct_put(dest_v + dct_y_offset + dct_x_offset, dct_linesize_chroma, row->blocks[11]);

        }

    }



    return 0;

}

static int FUNC_0(const DNXHDContext *VAR_0, RowContext *VAR_1,

                                   AVFrame *VAR_2, int VAR_3, int VAR_4)

{

    int VAR_5 = VAR_0->bit_depth >= 10;

    int VAR_6   = VAR_2->linesize[0];

    int VAR_7 = VAR_2->linesize[1];

    uint8_t *dest_y, *dest_u, *dest_v;

    int VAR_8, VAR_9;

    int VAR_10, VAR_11, VAR_12;

    int VAR_13 = 0;



    if (VAR_0->mbaff) {

        VAR_13 = get_bits1(&VAR_1->gb);

        VAR_10 = get_bits(&VAR_1->gb, 10);

    } else {

        VAR_10 = get_bits(&VAR_1->gb, 11);

    }

    VAR_12 = get_bits1(&VAR_1->gb);

    if (VAR_12) {

        static int VAR_14 = 0;

        if (!VAR_14) {

            VAR_14 = 1;

            av_log(VAR_0->avctx, AV_LOG_ERROR,

                   "Unsupported adaptive color transform, patch welcome.\n");

        }

    }



    if (VAR_10 != VAR_1->last_qscale) {

        for (VAR_11 = 0; VAR_11 < 64; VAR_11++) {

            VAR_1->luma_scale[VAR_11]   = VAR_10 * VAR_0->cid_table->luma_weight[VAR_11];

            VAR_1->chroma_scale[VAR_11] = VAR_10 * VAR_0->cid_table->chroma_weight[VAR_11];

        }

        VAR_1->last_qscale = VAR_10;

    }



    for (VAR_11 = 0; VAR_11 < 8 + 4 * VAR_0->is_444; VAR_11++) {

        if (VAR_0->decode_dct_block(VAR_0, VAR_1, VAR_11) < 0)

            return AVERROR_INVALIDDATA;

    }



    if (VAR_2->interlaced_frame) {

        VAR_6   <<= 1;

        VAR_7 <<= 1;

    }



    dest_y = VAR_2->data[0] + ((VAR_4 * VAR_6)   << 4) + (VAR_3 << (4 + VAR_5));

    dest_u = VAR_2->data[1] + ((VAR_4 * VAR_7) << 4) + (VAR_3 << (3 + VAR_5 + VAR_0->is_444));

    dest_v = VAR_2->data[2] + ((VAR_4 * VAR_7) << 4) + (VAR_3 << (3 + VAR_5 + VAR_0->is_444));



    if (VAR_2->interlaced_frame && VAR_0->cur_field) {

        dest_y += VAR_2->linesize[0];

        dest_u += VAR_2->linesize[1];

        dest_v += VAR_2->linesize[2];

    }

    if (VAR_13) {

        VAR_6   <<= 1;

        VAR_7 <<= 1;

    }



    VAR_8 = VAR_13 ? VAR_2->linesize[0] : (VAR_6 << 3);

    VAR_9 = 8 << VAR_5;

    if (!VAR_0->is_444) {

        VAR_0->idsp.idct_put(dest_y,                               VAR_6, VAR_1->blocks[0]);

        VAR_0->idsp.idct_put(dest_y + VAR_9,                VAR_6, VAR_1->blocks[1]);

        VAR_0->idsp.idct_put(dest_y + VAR_8,                VAR_6, VAR_1->blocks[4]);

        VAR_0->idsp.idct_put(dest_y + VAR_8 + VAR_9, VAR_6, VAR_1->blocks[5]);



        if (!(VAR_0->avctx->flags & AV_CODEC_FLAG_GRAY)) {

            VAR_8 = VAR_13 ? VAR_2->linesize[1] : (VAR_7 << 3);

            VAR_0->idsp.idct_put(dest_u,                VAR_7, VAR_1->blocks[2]);

            VAR_0->idsp.idct_put(dest_v,                VAR_7, VAR_1->blocks[3]);

            VAR_0->idsp.idct_put(dest_u + VAR_8, VAR_7, VAR_1->blocks[6]);

            VAR_0->idsp.idct_put(dest_v + VAR_8, VAR_7, VAR_1->blocks[7]);

        }

    } else {

        VAR_0->idsp.idct_put(dest_y,                               VAR_6, VAR_1->blocks[0]);

        VAR_0->idsp.idct_put(dest_y + VAR_9,                VAR_6, VAR_1->blocks[1]);

        VAR_0->idsp.idct_put(dest_y + VAR_8,                VAR_6, VAR_1->blocks[6]);

        VAR_0->idsp.idct_put(dest_y + VAR_8 + VAR_9, VAR_6, VAR_1->blocks[7]);



        if (!(VAR_0->avctx->flags & AV_CODEC_FLAG_GRAY)) {

            VAR_8 = VAR_13 ? VAR_2->linesize[1] : (VAR_7 << 3);

            VAR_0->idsp.idct_put(dest_u,                               VAR_7, VAR_1->blocks[2]);

            VAR_0->idsp.idct_put(dest_u + VAR_9,                VAR_7, VAR_1->blocks[3]);

            VAR_0->idsp.idct_put(dest_u + VAR_8,                VAR_7, VAR_1->blocks[8]);

            VAR_0->idsp.idct_put(dest_u + VAR_8 + VAR_9, VAR_7, VAR_1->blocks[9]);

            VAR_0->idsp.idct_put(dest_v,                               VAR_7, VAR_1->blocks[4]);

            VAR_0->idsp.idct_put(dest_v + VAR_9,                VAR_7, VAR_1->blocks[5]);

            VAR_0->idsp.idct_put(dest_v + VAR_8,                VAR_7, VAR_1->blocks[10]);

            VAR_0->idsp.idct_put(dest_v + VAR_8 + VAR_9, VAR_7, VAR_1->blocks[11]);

        }

    }



    return 0;

}

static int FUNC_0(const DNXHDContext *VAR_0, RowContext *VAR_1,
AVFrame *VAR_2, int VAR_3, int VAR_4)
{ int VAR_5 = VAR_0->bit_depth >= 10; int VAR_6   = VAR_2->linesize[0]; int VAR_7 = VAR_2->linesize[1]; uint8_t *dest_y, *dest_u, *dest_v; int VAR_8, VAR_9; int VAR_10, VAR_11, VAR_12; int VAR_13 = 0; if (VAR_0->mbaff) { VAR_13 = get_bits1(&VAR_1->gb); VAR_10 = get_bits(&VAR_1->gb, 10); } else { VAR_10 = get_bits(&VAR_1->gb, 11); } VAR_12 = get_bits1(&VAR_1->gb); if (VAR_12) { static int VAR_14 = 0; if (!VAR_14) { VAR_14 = 1; av_log(VAR_0->avctx, AV_LOG_ERROR,
"Unsupported adaptive color transform, patch welcome.\n"); } } if (VAR_10 != VAR_1->last_qscale) { for (VAR_11 = 0; VAR_11 < 64; VAR_11++) { VAR_1->luma_scale[VAR_11]   = VAR_10 * VAR_0->cid_table->luma_weight[VAR_11]; VAR_1->chroma_scale[VAR_11] = VAR_10 * VAR_0->cid_table->chroma_weight[VAR_11]; } VAR_1->last_qscale = VAR_10; } for (VAR_11 = 0; VAR_11 < 8 + 4 * VAR_0->is_444; VAR_11++) { if (VAR_0->decode_dct_block(VAR_0, VAR_1, VAR_11) < 0)
return AVERROR_INVALIDDATA; } if (VAR_2->interlaced_frame) { VAR_6   <<= 1; VAR_7 <<= 1; } dest_y = VAR_2->data[0] + ((VAR_4 * VAR_6)   << 4) + (VAR_3 << (4 + VAR_5)); dest_u = VAR_2->data[1] + ((VAR_4 * VAR_7) << 4) + (VAR_3 << (3 + VAR_5 + VAR_0->is_444)); dest_v = VAR_2->data[2] + ((VAR_4 * VAR_7) << 4) + (VAR_3 << (3 + VAR_5 + VAR_0->is_444)); if (VAR_2->interlaced_frame && VAR_0->cur_field) { dest_y += VAR_2->linesize[0]; dest_u += VAR_2->linesize[1]; dest_v += VAR_2->linesize[2]; } if (VAR_13) { VAR_6   <<= 1; VAR_7 <<= 1; } VAR_8 = VAR_13 ? VAR_2->linesize[0] : (VAR_6 << 3); VAR_9 = 8 << VAR_5; if (!VAR_0->is_444) { VAR_0->idsp.idct_put(dest_y,                               VAR_6, VAR_1->blocks[0]); VAR_0->idsp.idct_put(dest_y + VAR_9,                VAR_6, VAR_1->blocks[1]); VAR_0->idsp.idct_put(dest_y + VAR_8,                VAR_6, VAR_1->blocks[4]); VAR_0->idsp.idct_put(dest_y + VAR_8 + VAR_9, VAR_6, VAR_1->blocks[5]); if (!(VAR_0->avctx->flags & AV_CODEC_FLAG_GRAY)) { VAR_8 = VAR_13 ? VAR_2->linesize[1] : (VAR_7 << 3); VAR_0->idsp.idct_put(dest_u,                VAR_7, VAR_1->blocks[2]); VAR_0->idsp.idct_put(dest_v,                VAR_7, VAR_1->blocks[3]); VAR_0->idsp.idct_put(dest_u + VAR_8, VAR_7, VAR_1->blocks[6]); VAR_0->idsp.idct_put(dest_v + VAR_8, VAR_7, VAR_1->blocks[7]); } } else { VAR_0->idsp.idct_put(dest_y,                               VAR_6, VAR_1->blocks[0]); VAR_0->idsp.idct_put(dest_y + VAR_9,                VAR_6, VAR_1->blocks[1]); VAR_0->idsp.idct_put(dest_y + VAR_8,                VAR_6, VAR_1->blocks[6]); VAR_0->idsp.idct_put(dest_y + VAR_8 + VAR_9, VAR_6, VAR_1->blocks[7]); if (!(VAR_0->avctx->flags & AV_CODEC_FLAG_GRAY)) { VAR_8 = VAR_13 ? VAR_2->linesize[1] : (VAR_7 << 3); VAR_0->idsp.idct_put(dest_u,                               VAR_7, VAR_1->blocks[2]); VAR_0->idsp.idct_put(dest_u + VAR_9,                VAR_7, VAR_1->blocks[3]); VAR_0->idsp.idct_put(dest_u + VAR_8,                VAR_7, VAR_1->blocks[8]); VAR_0->idsp.idct_put(dest_u + VAR_8 + VAR_9, VAR_7, VAR_1->blocks[9]); VAR_0->idsp.idct_put(dest_v,                               VAR_7, VAR_1->blocks[4]); VAR_0->idsp.idct_put(dest_v + VAR_9,                VAR_7, VAR_1->blocks[5]); VAR_0->idsp.idct_put(dest_v + VAR_8,                VAR_7, VAR_1->blocks[10]); VAR_0->idsp.idct_put(dest_v + VAR_8 + VAR_9, VAR_7, VAR_1->blocks[11]); } } return 0; }