static int dirac_unpack_idwt_params(DiracContext *s)
{
    GetBitContext *gb = &s->gb;
    int i, level;
    unsigned tmp;
#define CHECKEDREAD(dst, cond, errmsg) \
    tmp = svq3_get_ue_golomb(gb); \
    if (cond) { \
        av_log(s->avctx, AV_LOG_ERROR, errmsg); \
        return -1; \
    }\
    dst = tmp;
    align_get_bits(gb);
    s->zero_res = s->num_refs ? get_bits1(gb) : 0;
    if (s->zero_res)
        return 0;
    /*[DIRAC_STD] 11.3.1 Transform parameters. transform_parameters() */
    CHECKEDREAD(s->wavelet_idx, tmp > 6, "wavelet_idx is too big\n")
    CHECKEDREAD(s->wavelet_depth, tmp > MAX_DWT_LEVELS || tmp < 1, "invalid number of DWT decompositions\n")
    if (!s->low_delay) {
        /* Codeblock paramaters (core syntax only) */
        if (get_bits1(gb)) {
            for (i = 0; i <= s->wavelet_depth; i++) {
                CHECKEDREAD(s->codeblock[i].width , tmp < 1, "codeblock width invalid\n")
                CHECKEDREAD(s->codeblock[i].height, tmp < 1, "codeblock height invalid\n")
            CHECKEDREAD(s->codeblock_mode, tmp > 1, "unknown codeblock mode\n")
        } else
            for (i = 0; i <= s->wavelet_depth; i++)
                s->codeblock[i].width = s->codeblock[i].height = 1;
    } else {
        /* Slice parameters + quantization matrix*/
        /*[DIRAC_STD] 11.3.4 Slice coding Parameters (low delay syntax only). slice_parameters() */
        s->lowdelay.num_x     = svq3_get_ue_golomb(gb);
        s->lowdelay.num_y     = svq3_get_ue_golomb(gb);
        s->lowdelay.bytes.num = svq3_get_ue_golomb(gb);
        s->lowdelay.bytes.den = svq3_get_ue_golomb(gb);
        /* [DIRAC_STD] 11.3.5 Quantisation matrices (low-delay syntax). quant_matrix() */
        if (get_bits1(gb)) {
            av_log(s->avctx,AV_LOG_DEBUG,"Low Delay: Has Custom Quantization Matrix!\n");
            /* custom quantization matrix */
            s->lowdelay.quant[0][0] = svq3_get_ue_golomb(gb);
            for (level = 0; level < s->wavelet_depth; level++) {
                s->lowdelay.quant[level][1] = svq3_get_ue_golomb(gb);
                s->lowdelay.quant[level][2] = svq3_get_ue_golomb(gb);
                s->lowdelay.quant[level][3] = svq3_get_ue_golomb(gb);
        } else {
            /* default quantization matrix */
            for (level = 0; level < s->wavelet_depth; level++)
                for (i = 0; i < 4; i++) {
                    s->lowdelay.quant[level][i] = default_qmat[s->wavelet_idx][level][i];
                    /* haar with no shift differs for different depths */
                    if (s->wavelet_idx == 3)
                        s->lowdelay.quant[level][i] += 4*(s->wavelet_depth-1 - level);
    return 0;
static int dirac_unpack_idwt_params(DiracContext *s)
{
    GetBitContext *gb = &s->gb;
    int i, level;
    unsigned tmp;
#define CHECKEDREAD(dst, cond, errmsg) \
    tmp = svq3_get_ue_golomb(gb); \
    if (cond) { \
        av_log(s->avctx, AV_LOG_ERROR, errmsg); \
        return -1; \
    }\
    dst = tmp;
    align_get_bits(gb);
    s->zero_res = s->num_refs ? get_bits1(gb) : 0;
    if (s->zero_res)
        return 0;
    
    CHECKEDREAD(s->wavelet_idx, tmp > 6, "wavelet_idx is too big\n")
    CHECKEDREAD(s->wavelet_depth, tmp > MAX_DWT_LEVELS || tmp < 1, "invalid number of DWT decompositions\n")
    if (!s->low_delay) {
        
        if (get_bits1(gb)) {
            for (i = 0; i <= s->wavelet_depth; i++) {
                CHECKEDREAD(s->codeblock[i].width , tmp < 1, "codeblock width invalid\n")
                CHECKEDREAD(s->codeblock[i].height, tmp < 1, "codeblock height invalid\n")
            CHECKEDREAD(s->codeblock_mode, tmp > 1, "unknown codeblock mode\n")
        } else
            for (i = 0; i <= s->wavelet_depth; i++)
                s->codeblock[i].width = s->codeblock[i].height = 1;
    } else {
        
        
        s->lowdelay.num_x     = svq3_get_ue_golomb(gb);
        s->lowdelay.num_y     = svq3_get_ue_golomb(gb);
        s->lowdelay.bytes.num = svq3_get_ue_golomb(gb);
        s->lowdelay.bytes.den = svq3_get_ue_golomb(gb);
        
        if (get_bits1(gb)) {
            av_log(s->avctx,AV_LOG_DEBUG,"Low Delay: Has Custom Quantization Matrix!\n");
            
            s->lowdelay.quant[0][0] = svq3_get_ue_golomb(gb);
            for (level = 0; level < s->wavelet_depth; level++) {
                s->lowdelay.quant[level][1] = svq3_get_ue_golomb(gb);
                s->lowdelay.quant[level][2] = svq3_get_ue_golomb(gb);
                s->lowdelay.quant[level][3] = svq3_get_ue_golomb(gb);
        } else {
            
            for (level = 0; level < s->wavelet_depth; level++)
                for (i = 0; i < 4; i++) {
                    s->lowdelay.quant[level][i] = default_qmat[s->wavelet_idx][level][i];
                    
                    if (s->wavelet_idx == 3)
                        s->lowdelay.quant[level][i] += 4*(s->wavelet_depth-1 - level);
    return 0;
static int FUNC_0(DiracContext *VAR_0)
{
    GetBitContext *gb = &VAR_0->gb;
    int VAR_1, VAR_2;
    unsigned VAR_3;
#define CHECKEDREAD(dst, cond, errmsg) \
    VAR_3 = svq3_get_ue_golomb(gb); \
    if (cond) { \
        av_log(VAR_0->avctx, AV_LOG_ERROR, errmsg); \
        return -1; \
    }\
    dst = VAR_3;
    align_get_bits(gb);
    VAR_0->zero_res = VAR_0->num_refs ? get_bits1(gb) : 0;
    if (VAR_0->zero_res)
        return 0;
    
    CHECKEDREAD(VAR_0->wavelet_idx, VAR_3 > 6, "wavelet_idx is too big\n")
    CHECKEDREAD(VAR_0->wavelet_depth, VAR_3 > MAX_DWT_LEVELS || VAR_3 < 1, "invalid number of DWT decompositions\n")
    if (!VAR_0->low_delay) {
        
        if (get_bits1(gb)) {
            for (VAR_1 = 0; VAR_1 <= VAR_0->wavelet_depth; VAR_1++) {
                CHECKEDREAD(VAR_0->codeblock[VAR_1].width , VAR_3 < 1, "codeblock width invalid\n")
                CHECKEDREAD(VAR_0->codeblock[VAR_1].height, VAR_3 < 1, "codeblock height invalid\n")
            CHECKEDREAD(VAR_0->codeblock_mode, VAR_3 > 1, "unknown codeblock mode\n")
        } else
            for (VAR_1 = 0; VAR_1 <= VAR_0->wavelet_depth; VAR_1++)
                VAR_0->codeblock[VAR_1].width = VAR_0->codeblock[VAR_1].height = 1;
    } else {
        
        
        VAR_0->lowdelay.num_x     = svq3_get_ue_golomb(gb);
        VAR_0->lowdelay.num_y     = svq3_get_ue_golomb(gb);
        VAR_0->lowdelay.bytes.num = svq3_get_ue_golomb(gb);
        VAR_0->lowdelay.bytes.den = svq3_get_ue_golomb(gb);
        
        if (get_bits1(gb)) {
            av_log(VAR_0->avctx,AV_LOG_DEBUG,"Low Delay: Has Custom Quantization Matrix!\n");
            
            VAR_0->lowdelay.quant[0][0] = svq3_get_ue_golomb(gb);
            for (VAR_2 = 0; VAR_2 < VAR_0->wavelet_depth; VAR_2++) {
                VAR_0->lowdelay.quant[VAR_2][1] = svq3_get_ue_golomb(gb);
                VAR_0->lowdelay.quant[VAR_2][2] = svq3_get_ue_golomb(gb);
                VAR_0->lowdelay.quant[VAR_2][3] = svq3_get_ue_golomb(gb);
        } else {
            
            for (VAR_2 = 0; VAR_2 < VAR_0->wavelet_depth; VAR_2++)
                for (VAR_1 = 0; VAR_1 < 4; VAR_1++) {
                    VAR_0->lowdelay.quant[VAR_2][VAR_1] = default_qmat[VAR_0->wavelet_idx][VAR_2][VAR_1];
                    
                    if (VAR_0->wavelet_idx == 3)
                        VAR_0->lowdelay.quant[VAR_2][VAR_1] += 4*(VAR_0->wavelet_depth-1 - VAR_2);
    return 0;
static int FUNC_0(DiracContext *VAR_0)
{ GetBitContext *gb = &VAR_0->gb; int VAR_1, VAR_2; unsigned VAR_3; #define CHECKEDREAD(dst, cond, errmsg) \
VAR_3 = svq3_get_ue_golomb(gb); \ if (cond) { \ av_log(VAR_0->avctx, AV_LOG_ERROR, errmsg); \ return -1; \ }\ dst = VAR_3; align_get_bits(gb); VAR_0->zero_res = VAR_0->num_refs ? get_bits1(gb) : 0; if (VAR_0->zero_res)
return 0; CHECKEDREAD(VAR_0->wavelet_idx, VAR_3 > 6, "wavelet_idx is too big\n")
CHECKEDREAD(VAR_0->wavelet_depth, VAR_3 > MAX_DWT_LEVELS || VAR_3 < 1, "invalid number of DWT decompositions\n")
if (!VAR_0->low_delay) { if (get_bits1(gb)) { for (VAR_1 = 0; VAR_1 <= VAR_0->wavelet_depth; VAR_1++) { CHECKEDREAD(VAR_0->codeblock[VAR_1].width , VAR_3 < 1, "codeblock width invalid\n")
CHECKEDREAD(VAR_0->codeblock[VAR_1].height, VAR_3 < 1, "codeblock height invalid\n")
CHECKEDREAD(VAR_0->codeblock_mode, VAR_3 > 1, "unknown codeblock mode\n")
} else for (VAR_1 = 0; VAR_1 <= VAR_0->wavelet_depth; VAR_1++) VAR_0->codeblock[VAR_1].width = VAR_0->codeblock[VAR_1].height = 1; } else { VAR_0->lowdelay.num_x     = svq3_get_ue_golomb(gb); VAR_0->lowdelay.num_y     = svq3_get_ue_golomb(gb); VAR_0->lowdelay.bytes.num = svq3_get_ue_golomb(gb); VAR_0->lowdelay.bytes.den = svq3_get_ue_golomb(gb); if (get_bits1(gb)) { av_log(VAR_0->avctx,AV_LOG_DEBUG,"Low Delay: Has Custom Quantization Matrix!\n"); VAR_0->lowdelay.quant[0][0] = svq3_get_ue_golomb(gb); for (VAR_2 = 0; VAR_2 < VAR_0->wavelet_depth; VAR_2++) { VAR_0->lowdelay.quant[VAR_2][1] = svq3_get_ue_golomb(gb); VAR_0->lowdelay.quant[VAR_2][2] = svq3_get_ue_golomb(gb); VAR_0->lowdelay.quant[VAR_2][3] = svq3_get_ue_golomb(gb); } else { for (VAR_2 = 0; VAR_2 < VAR_0->wavelet_depth; VAR_2++) for (VAR_1 = 0; VAR_1 < 4; VAR_1++) { VAR_0->lowdelay.quant[VAR_2][VAR_1] = default_qmat[VAR_0->wavelet_idx][VAR_2][VAR_1]; if (VAR_0->wavelet_idx == 3)
VAR_0->lowdelay.quant[VAR_2][VAR_1] += 4*(VAR_0->wavelet_depth-1 - VAR_2); return 0;