static int scaling_list_data(GetBitContext *gb, AVCodecContext *avctx, ScalingList *sl, HEVCSPS *sps)

{

    uint8_t scaling_list_pred_mode_flag;

    int32_t scaling_list_dc_coef[2][6];

    int size_id, matrix_id, pos;

    int i;



    for (size_id = 0; size_id < 4; size_id++)

        for (matrix_id = 0; matrix_id < 6; matrix_id += ((size_id == 3) ? 3 : 1)) {

            scaling_list_pred_mode_flag = get_bits1(gb);

            if (!scaling_list_pred_mode_flag) {

                unsigned int delta = get_ue_golomb_long(gb);

                /* Only need to handle non-zero delta. Zero means default,

                 * which should already be in the arrays. */

                if (delta) {

                    // Copy from previous array.

                    if (matrix_id < delta) {

                        av_log(avctx, AV_LOG_ERROR,

                               "Invalid delta in scaling list data: %d.\n", delta);

                        return AVERROR_INVALIDDATA;

                    }



                    memcpy(sl->sl[size_id][matrix_id],

                           sl->sl[size_id][matrix_id - delta],

                           size_id > 0 ? 64 : 16);

                    if (size_id > 1)

                        sl->sl_dc[size_id - 2][matrix_id] = sl->sl_dc[size_id - 2][matrix_id - delta];

                }

            } else {

                int next_coef, coef_num;

                int32_t scaling_list_delta_coef;



                next_coef = 8;

                coef_num  = FFMIN(64, 1 << (4 + (size_id << 1)));

                if (size_id > 1) {

                    scaling_list_dc_coef[size_id - 2][matrix_id] = get_se_golomb(gb) + 8;

                    next_coef = scaling_list_dc_coef[size_id - 2][matrix_id];

                    sl->sl_dc[size_id - 2][matrix_id] = next_coef;

                }

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

                    if (size_id == 0)

                        pos = 4 * ff_hevc_diag_scan4x4_y[i] +

                                  ff_hevc_diag_scan4x4_x[i];

                    else

                        pos = 8 * ff_hevc_diag_scan8x8_y[i] +

                                  ff_hevc_diag_scan8x8_x[i];



                    scaling_list_delta_coef = get_se_golomb(gb);

                    next_coef = (next_coef + scaling_list_delta_coef + 256) % 256;

                    sl->sl[size_id][matrix_id][pos] = next_coef;

                }

            }

        }



    if (sps->chroma_format_idc == 3) {

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

            sl->sl[3][1][i] = sl->sl[2][1][i];

            sl->sl[3][2][i] = sl->sl[2][2][i];

            sl->sl[3][4][i] = sl->sl[2][4][i];

            sl->sl[3][5][i] = sl->sl[2][5][i];

        }

        sl->sl_dc[1][1] = sl->sl_dc[0][1];

        sl->sl_dc[1][2] = sl->sl_dc[0][2];

        sl->sl_dc[1][4] = sl->sl_dc[0][4];

        sl->sl_dc[1][5] = sl->sl_dc[0][5];

    }





    return 0;

}

static int scaling_list_data(GetBitContext *gb, AVCodecContext *avctx, ScalingList *sl, HEVCSPS *sps)

{

    uint8_t scaling_list_pred_mode_flag;

    int32_t scaling_list_dc_coef[2][6];

    int size_id, matrix_id, pos;

    int i;



    for (size_id = 0; size_id < 4; size_id++)

        for (matrix_id = 0; matrix_id < 6; matrix_id += ((size_id == 3) ? 3 : 1)) {

            scaling_list_pred_mode_flag = get_bits1(gb);

            if (!scaling_list_pred_mode_flag) {

                unsigned int delta = get_ue_golomb_long(gb);

                



                if (delta) {

                    

                    if (matrix_id < delta) {

                        av_log(avctx, AV_LOG_ERROR,

                               "Invalid delta in scaling list data: %d.\n", delta);

                        return AVERROR_INVALIDDATA;

                    }



                    memcpy(sl->sl[size_id][matrix_id],

                           sl->sl[size_id][matrix_id - delta],

                           size_id > 0 ? 64 : 16);

                    if (size_id > 1)

                        sl->sl_dc[size_id - 2][matrix_id] = sl->sl_dc[size_id - 2][matrix_id - delta];

                }

            } else {

                int next_coef, coef_num;

                int32_t scaling_list_delta_coef;



                next_coef = 8;

                coef_num  = FFMIN(64, 1 << (4 + (size_id << 1)));

                if (size_id > 1) {

                    scaling_list_dc_coef[size_id - 2][matrix_id] = get_se_golomb(gb) + 8;

                    next_coef = scaling_list_dc_coef[size_id - 2][matrix_id];

                    sl->sl_dc[size_id - 2][matrix_id] = next_coef;

                }

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

                    if (size_id == 0)

                        pos = 4 * ff_hevc_diag_scan4x4_y[i] +

                                  ff_hevc_diag_scan4x4_x[i];

                    else

                        pos = 8 * ff_hevc_diag_scan8x8_y[i] +

                                  ff_hevc_diag_scan8x8_x[i];



                    scaling_list_delta_coef = get_se_golomb(gb);

                    next_coef = (next_coef + scaling_list_delta_coef + 256) % 256;

                    sl->sl[size_id][matrix_id][pos] = next_coef;

                }

            }

        }



    if (sps->chroma_format_idc == 3) {

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

            sl->sl[3][1][i] = sl->sl[2][1][i];

            sl->sl[3][2][i] = sl->sl[2][2][i];

            sl->sl[3][4][i] = sl->sl[2][4][i];

            sl->sl[3][5][i] = sl->sl[2][5][i];

        }

        sl->sl_dc[1][1] = sl->sl_dc[0][1];

        sl->sl_dc[1][2] = sl->sl_dc[0][2];

        sl->sl_dc[1][4] = sl->sl_dc[0][4];

        sl->sl_dc[1][5] = sl->sl_dc[0][5];

    }





    return 0;

}

                    next_coef = (next_coef + scaling_list_delta_coef + 256) % 256;
static int FUNC_0(GetBitContext *VAR_0, AVCodecContext *VAR_1, ScalingList *VAR_2, HEVCSPS *VAR_3)

{

    uint8_t scaling_list_pred_mode_flag;

    int32_t scaling_list_dc_coef[2][6];

    int VAR_4, VAR_5, VAR_6;

    int VAR_7;



    for (VAR_4 = 0; VAR_4 < 4; VAR_4++)

        for (VAR_5 = 0; VAR_5 < 6; VAR_5 += ((VAR_4 == 3) ? 3 : 1)) {

            scaling_list_pred_mode_flag = get_bits1(VAR_0);

            if (!scaling_list_pred_mode_flag) {

                unsigned int VAR_8 = get_ue_golomb_long(VAR_0);

                



                if (VAR_8) {

                    

                    if (VAR_5 < VAR_8) {

                        av_log(VAR_1, AV_LOG_ERROR,

                               "Invalid VAR_8 in scaling list data: %d.\n", VAR_8);

                        return AVERROR_INVALIDDATA;

                    }



                    memcpy(VAR_2->VAR_2[VAR_4][VAR_5],

                           VAR_2->VAR_2[VAR_4][VAR_5 - VAR_8],

                           VAR_4 > 0 ? 64 : 16);

                    if (VAR_4 > 1)

                        VAR_2->sl_dc[VAR_4 - 2][VAR_5] = VAR_2->sl_dc[VAR_4 - 2][VAR_5 - VAR_8];

                }

            } else {

                int VAR_9, VAR_10;

                int32_t scaling_list_delta_coef;



                VAR_9 = 8;

                VAR_10  = FFMIN(64, 1 << (4 + (VAR_4 << 1)));

                if (VAR_4 > 1) {

                    scaling_list_dc_coef[VAR_4 - 2][VAR_5] = get_se_golomb(VAR_0) + 8;

                    VAR_9 = scaling_list_dc_coef[VAR_4 - 2][VAR_5];

                    VAR_2->sl_dc[VAR_4 - 2][VAR_5] = VAR_9;

                }

                for (VAR_7 = 0; VAR_7 < VAR_10; VAR_7++) {

                    if (VAR_4 == 0)

                        VAR_6 = 4 * ff_hevc_diag_scan4x4_y[VAR_7] +

                                  ff_hevc_diag_scan4x4_x[VAR_7];

                    else

                        VAR_6 = 8 * ff_hevc_diag_scan8x8_y[VAR_7] +

                                  ff_hevc_diag_scan8x8_x[VAR_7];



                    scaling_list_delta_coef = get_se_golomb(VAR_0);

                    VAR_9 = (VAR_9 + scaling_list_delta_coef + 256) % 256;

                    VAR_2->VAR_2[VAR_4][VAR_5][VAR_6] = VAR_9;

                }

            }

        }



    if (VAR_3->chroma_format_idc == 3) {

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

            VAR_2->VAR_2[3][1][VAR_7] = VAR_2->VAR_2[2][1][VAR_7];

            VAR_2->VAR_2[3][2][VAR_7] = VAR_2->VAR_2[2][2][VAR_7];

            VAR_2->VAR_2[3][4][VAR_7] = VAR_2->VAR_2[2][4][VAR_7];

            VAR_2->VAR_2[3][5][VAR_7] = VAR_2->VAR_2[2][5][VAR_7];

        }

        VAR_2->sl_dc[1][1] = VAR_2->sl_dc[0][1];

        VAR_2->sl_dc[1][2] = VAR_2->sl_dc[0][2];

        VAR_2->sl_dc[1][4] = VAR_2->sl_dc[0][4];

        VAR_2->sl_dc[1][5] = VAR_2->sl_dc[0][5];

    }





    return 0;

}

static int FUNC_0(GetBitContext *VAR_0, AVCodecContext *VAR_1, ScalingList *VAR_2, HEVCSPS *VAR_3)
{ uint8_t scaling_list_pred_mode_flag; int32_t scaling_list_dc_coef[2][6]; int VAR_4, VAR_5, VAR_6; int VAR_7; for (VAR_4 = 0; VAR_4 < 4; VAR_4++) for (VAR_5 = 0; VAR_5 < 6; VAR_5 += ((VAR_4 == 3) ? 3 : 1)) { scaling_list_pred_mode_flag = get_bits1(VAR_0); if (!scaling_list_pred_mode_flag) { unsigned int VAR_8 = get_ue_golomb_long(VAR_0); if (VAR_8) { if (VAR_5 < VAR_8) { av_log(VAR_1, AV_LOG_ERROR,
"Invalid VAR_8 in scaling list data: %d.\n", VAR_8); return AVERROR_INVALIDDATA; } memcpy(VAR_2->VAR_2[VAR_4][VAR_5],
VAR_2->VAR_2[VAR_4][VAR_5 - VAR_8],
VAR_4 > 0 ? 64 : 16); if (VAR_4 > 1)
VAR_2->sl_dc[VAR_4 - 2][VAR_5] = VAR_2->sl_dc[VAR_4 - 2][VAR_5 - VAR_8]; } } else { int VAR_9, VAR_10; int32_t scaling_list_delta_coef; VAR_9 = 8; VAR_10  = FFMIN(64, 1 << (4 + (VAR_4 << 1))); if (VAR_4 > 1) { scaling_list_dc_coef[VAR_4 - 2][VAR_5] = get_se_golomb(VAR_0) + 8; VAR_9 = scaling_list_dc_coef[VAR_4 - 2][VAR_5]; VAR_2->sl_dc[VAR_4 - 2][VAR_5] = VAR_9; } for (VAR_7 = 0; VAR_7 < VAR_10; VAR_7++) { if (VAR_4 == 0)
VAR_6 = 4 * ff_hevc_diag_scan4x4_y[VAR_7] +
ff_hevc_diag_scan4x4_x[VAR_7]; else
VAR_6 = 8 * ff_hevc_diag_scan8x8_y[VAR_7] +
ff_hevc_diag_scan8x8_x[VAR_7]; scaling_list_delta_coef = get_se_golomb(VAR_0); VAR_9 = (VAR_9 + scaling_list_delta_coef + 256) % 256; VAR_2->VAR_2[VAR_4][VAR_5][VAR_6] = VAR_9; } } } if (VAR_3->chroma_format_idc == 3) { for (VAR_7 = 0; VAR_7 < 64; VAR_7++) { VAR_2->VAR_2[3][1][VAR_7] = VAR_2->VAR_2[2][1][VAR_7]; VAR_2->VAR_2[3][2][VAR_7] = VAR_2->VAR_2[2][2][VAR_7]; VAR_2->VAR_2[3][4][VAR_7] = VAR_2->VAR_2[2][4][VAR_7]; VAR_2->VAR_2[3][5][VAR_7] = VAR_2->VAR_2[2][5][VAR_7]; } VAR_2->sl_dc[1][1] = VAR_2->sl_dc[0][1]; VAR_2->sl_dc[1][2] = VAR_2->sl_dc[0][2]; VAR_2->sl_dc[1][4] = VAR_2->sl_dc[0][4]; VAR_2->sl_dc[1][5] = VAR_2->sl_dc[0][5]; } return 0; }