static int decode_hq_slice(DiracContext *s, DiracSlice *slice, uint8_t *tmp_buf)

{

    int i, level, orientation, quant_idx;

    int qfactor[MAX_DWT_LEVELS][4], qoffset[MAX_DWT_LEVELS][4];

    GetBitContext *gb = &slice->gb;

    SliceCoeffs coeffs_num[MAX_DWT_LEVELS];



    skip_bits_long(gb, 8*s->highquality.prefix_bytes);

    quant_idx = get_bits(gb, 8);



    if (quant_idx > DIRAC_MAX_QUANT_INDEX) {

        av_log(s->avctx, AV_LOG_ERROR, "Invalid quantization index - %i\n", quant_idx);

        return AVERROR_INVALIDDATA;

    }



    /* Slice quantization (slice_quantizers() in the specs) */

    for (level = 0; level < s->wavelet_depth; level++) {

        for (orientation = !!level; orientation < 4; orientation++) {

            const int quant = FFMAX(quant_idx - s->lowdelay.quant[level][orientation], 0);

            qfactor[level][orientation] = ff_dirac_qscale_tab[quant];

            qoffset[level][orientation] = ff_dirac_qoffset_intra_tab[quant] + 2;

        }

    }



    /* Luma + 2 Chroma planes */

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

        int coef_num, coef_par, off = 0;

        int64_t length = s->highquality.size_scaler*get_bits(gb, 8);

        int64_t bits_end = get_bits_count(gb) + 8*length;

        const uint8_t *addr = align_get_bits(gb);



        if (length*8 > get_bits_left(gb)) {

            av_log(s->avctx, AV_LOG_ERROR, "end too far away\n");

            return AVERROR_INVALIDDATA;

        }



        coef_num = subband_coeffs(s, slice->slice_x, slice->slice_y, i, coeffs_num);



        if (s->pshift)

            coef_par = ff_dirac_golomb_read_32bit(s->reader_ctx, addr,

                                                  length, tmp_buf, coef_num);

        else

            coef_par = ff_dirac_golomb_read_16bit(s->reader_ctx, addr,

                                                  length, tmp_buf, coef_num);



        if (coef_num > coef_par) {

            const int start_b = coef_par * (1 << (s->pshift + 1));

            const int end_b   = coef_num * (1 << (s->pshift + 1));

            memset(&tmp_buf[start_b], 0, end_b - start_b);

        }



        for (level = 0; level < s->wavelet_depth; level++) {

            const SliceCoeffs *c = &coeffs_num[level];

            for (orientation = !!level; orientation < 4; orientation++) {

                const SubBand *b1 = &s->plane[i].band[level][orientation];

                uint8_t *buf = b1->ibuf + c->top * b1->stride + (c->left << (s->pshift + 1));



                /* Change to c->tot_h <= 4 for AVX2 dequantization */

                const int qfunc = s->pshift + 2*(c->tot_h <= 2);

                s->diracdsp.dequant_subband[qfunc](&tmp_buf[off], buf, b1->stride,

                                                   qfactor[level][orientation],

                                                   qoffset[level][orientation],

                                                   c->tot_v, c->tot_h);



                off += c->tot << (s->pshift + 1);

            }

        }



        skip_bits_long(gb, bits_end - get_bits_count(gb));

    }



    return 0;

}

static int decode_hq_slice(DiracContext *s, DiracSlice *slice, uint8_t *tmp_buf)

{

    int i, level, orientation, quant_idx;

    int qfactor[MAX_DWT_LEVELS][4], qoffset[MAX_DWT_LEVELS][4];

    GetBitContext *gb = &slice->gb;

    SliceCoeffs coeffs_num[MAX_DWT_LEVELS];



    skip_bits_long(gb, 8*s->highquality.prefix_bytes);

    quant_idx = get_bits(gb, 8);



    if (quant_idx > DIRAC_MAX_QUANT_INDEX) {

        av_log(s->avctx, AV_LOG_ERROR, "Invalid quantization index - %i\n", quant_idx);

        return AVERROR_INVALIDDATA;

    }



    

    for (level = 0; level < s->wavelet_depth; level++) {

        for (orientation = !!level; orientation < 4; orientation++) {

            const int quant = FFMAX(quant_idx - s->lowdelay.quant[level][orientation], 0);

            qfactor[level][orientation] = ff_dirac_qscale_tab[quant];

            qoffset[level][orientation] = ff_dirac_qoffset_intra_tab[quant] + 2;

        }

    }



    

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

        int coef_num, coef_par, off = 0;

        int64_t length = s->highquality.size_scaler*get_bits(gb, 8);

        int64_t bits_end = get_bits_count(gb) + 8*length;

        const uint8_t *addr = align_get_bits(gb);



        if (length*8 > get_bits_left(gb)) {

            av_log(s->avctx, AV_LOG_ERROR, "end too far away\n");

            return AVERROR_INVALIDDATA;

        }



        coef_num = subband_coeffs(s, slice->slice_x, slice->slice_y, i, coeffs_num);



        if (s->pshift)

            coef_par = ff_dirac_golomb_read_32bit(s->reader_ctx, addr,

                                                  length, tmp_buf, coef_num);

        else

            coef_par = ff_dirac_golomb_read_16bit(s->reader_ctx, addr,

                                                  length, tmp_buf, coef_num);



        if (coef_num > coef_par) {

            const int start_b = coef_par * (1 << (s->pshift + 1));

            const int end_b   = coef_num * (1 << (s->pshift + 1));

            memset(&tmp_buf[start_b], 0, end_b - start_b);

        }



        for (level = 0; level < s->wavelet_depth; level++) {

            const SliceCoeffs *c = &coeffs_num[level];

            for (orientation = !!level; orientation < 4; orientation++) {

                const SubBand *b1 = &s->plane[i].band[level][orientation];

                uint8_t *buf = b1->ibuf + c->top * b1->stride + (c->left << (s->pshift + 1));



                

                const int qfunc = s->pshift + 2*(c->tot_h <= 2);

                s->diracdsp.dequant_subband[qfunc](&tmp_buf[off], buf, b1->stride,

                                                   qfactor[level][orientation],

                                                   qoffset[level][orientation],

                                                   c->tot_v, c->tot_h);



                off += c->tot << (s->pshift + 1);

            }

        }



        skip_bits_long(gb, bits_end - get_bits_count(gb));

    }



    return 0;

}

    if (quant_idx > DIRAC_MAX_QUANT_INDEX) {
static int FUNC_0(DiracContext *VAR_0, DiracSlice *VAR_1, uint8_t *VAR_2)

{

    int VAR_3, VAR_4, VAR_5, VAR_6;

    int VAR_7[MAX_DWT_LEVELS][4], qoffset[MAX_DWT_LEVELS][4];

    GetBitContext *gb = &VAR_1->gb;

    SliceCoeffs coeffs_num[MAX_DWT_LEVELS];



    skip_bits_long(gb, 8*VAR_0->highquality.prefix_bytes);

    VAR_6 = get_bits(gb, 8);



    if (VAR_6 > DIRAC_MAX_QUANT_INDEX) {

        av_log(VAR_0->avctx, AV_LOG_ERROR, "Invalid quantization index - %VAR_3\n", VAR_6);

        return AVERROR_INVALIDDATA;

    }



    

    for (VAR_4 = 0; VAR_4 < VAR_0->wavelet_depth; VAR_4++) {

        for (VAR_5 = !!VAR_4; VAR_5 < 4; VAR_5++) {

            const int quant = FFMAX(VAR_6 - VAR_0->lowdelay.quant[VAR_4][VAR_5], 0);

            VAR_7[VAR_4][VAR_5] = ff_dirac_qscale_tab[quant];

            qoffset[VAR_4][VAR_5] = ff_dirac_qoffset_intra_tab[quant] + 2;

        }

    }



    

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

        int VAR_8, VAR_9, VAR_10 = 0;

        int64_t length = VAR_0->highquality.size_scaler*get_bits(gb, 8);

        int64_t bits_end = get_bits_count(gb) + 8*length;

        const uint8_t *VAR_11 = align_get_bits(gb);



        if (length*8 > get_bits_left(gb)) {

            av_log(VAR_0->avctx, AV_LOG_ERROR, "end too far away\n");

            return AVERROR_INVALIDDATA;

        }



        VAR_8 = subband_coeffs(VAR_0, VAR_1->slice_x, VAR_1->slice_y, VAR_3, coeffs_num);



        if (VAR_0->pshift)

            VAR_9 = ff_dirac_golomb_read_32bit(VAR_0->reader_ctx, VAR_11,

                                                  length, VAR_2, VAR_8);

        else

            VAR_9 = ff_dirac_golomb_read_16bit(VAR_0->reader_ctx, VAR_11,

                                                  length, VAR_2, VAR_8);



        if (VAR_8 > VAR_9) {

            const int VAR_12 = VAR_9 * (1 << (VAR_0->pshift + 1));

            const int VAR_13   = VAR_8 * (1 << (VAR_0->pshift + 1));

            memset(&VAR_2[VAR_12], 0, VAR_13 - VAR_12);

        }



        for (VAR_4 = 0; VAR_4 < VAR_0->wavelet_depth; VAR_4++) {

            const SliceCoeffs *c = &coeffs_num[VAR_4];

            for (VAR_5 = !!VAR_4; VAR_5 < 4; VAR_5++) {

                const SubBand *b1 = &VAR_0->plane[VAR_3].band[VAR_4][VAR_5];

                uint8_t *buf = b1->ibuf + c->top * b1->stride + (c->left << (VAR_0->pshift + 1));



                

                const int qfunc = VAR_0->pshift + 2*(c->tot_h <= 2);

                VAR_0->diracdsp.dequant_subband[qfunc](&VAR_2[VAR_10], buf, b1->stride,

                                                   VAR_7[VAR_4][VAR_5],

                                                   qoffset[VAR_4][VAR_5],

                                                   c->tot_v, c->tot_h);



                VAR_10 += c->tot << (VAR_0->pshift + 1);

            }

        }



        skip_bits_long(gb, bits_end - get_bits_count(gb));

    }



    return 0;

}

static int FUNC_0(DiracContext *VAR_0, DiracSlice *VAR_1, uint8_t *VAR_2)
{ int VAR_3, VAR_4, VAR_5, VAR_6; int VAR_7[MAX_DWT_LEVELS][4], qoffset[MAX_DWT_LEVELS][4]; GetBitContext *gb = &VAR_1->gb; SliceCoeffs coeffs_num[MAX_DWT_LEVELS]; skip_bits_long(gb, 8*VAR_0->highquality.prefix_bytes); VAR_6 = get_bits(gb, 8); if (VAR_6 > DIRAC_MAX_QUANT_INDEX) { av_log(VAR_0->avctx, AV_LOG_ERROR, "Invalid quantization index - %VAR_3\n", VAR_6); return AVERROR_INVALIDDATA; } for (VAR_4 = 0; VAR_4 < VAR_0->wavelet_depth; VAR_4++) { for (VAR_5 = !!VAR_4; VAR_5 < 4; VAR_5++) { const int quant = FFMAX(VAR_6 - VAR_0->lowdelay.quant[VAR_4][VAR_5], 0); VAR_7[VAR_4][VAR_5] = ff_dirac_qscale_tab[quant]; qoffset[VAR_4][VAR_5] = ff_dirac_qoffset_intra_tab[quant] + 2; } } for (VAR_3 = 0; VAR_3 < 3; VAR_3++) { int VAR_8, VAR_9, VAR_10 = 0; int64_t length = VAR_0->highquality.size_scaler*get_bits(gb, 8); int64_t bits_end = get_bits_count(gb) + 8*length; const uint8_t *VAR_11 = align_get_bits(gb); if (length*8 > get_bits_left(gb)) { av_log(VAR_0->avctx, AV_LOG_ERROR, "end too far away\n"); return AVERROR_INVALIDDATA; } VAR_8 = subband_coeffs(VAR_0, VAR_1->slice_x, VAR_1->slice_y, VAR_3, coeffs_num); if (VAR_0->pshift)
VAR_9 = ff_dirac_golomb_read_32bit(VAR_0->reader_ctx, VAR_11,
length, VAR_2, VAR_8); else
VAR_9 = ff_dirac_golomb_read_16bit(VAR_0->reader_ctx, VAR_11,
length, VAR_2, VAR_8); if (VAR_8 > VAR_9) { const int VAR_12 = VAR_9 * (1 << (VAR_0->pshift + 1)); const int VAR_13   = VAR_8 * (1 << (VAR_0->pshift + 1)); memset(&VAR_2[VAR_12], 0, VAR_13 - VAR_12); } for (VAR_4 = 0; VAR_4 < VAR_0->wavelet_depth; VAR_4++) { const SliceCoeffs *c = &coeffs_num[VAR_4]; for (VAR_5 = !!VAR_4; VAR_5 < 4; VAR_5++) { const SubBand *b1 = &VAR_0->plane[VAR_3].band[VAR_4][VAR_5]; uint8_t *buf = b1->ibuf + c->top * b1->stride + (c->left << (VAR_0->pshift + 1)); const int qfunc = VAR_0->pshift + 2*(c->tot_h <= 2); VAR_0->diracdsp.dequant_subband[qfunc](&VAR_2[VAR_10], buf, b1->stride,
VAR_7[VAR_4][VAR_5],
qoffset[VAR_4][VAR_5],
c->tot_v, c->tot_h); VAR_10 += c->tot << (VAR_0->pshift + 1); } } skip_bits_long(gb, bits_end - get_bits_count(gb)); } return 0; }