Home | History | Annotate | Download | only in encoder
      1 /******************************************************************************
      2  *
      3  * Copyright (C) 2018 The Android Open Source Project
      4  *
      5  * Licensed under the Apache License, Version 2.0 (the "License");
      6  * you may not use this file except in compliance with the License.
      7  * You may obtain a copy of the License at:
      8  *
      9  * http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  * Unless required by applicable law or agreed to in writing, software
     12  * distributed under the License is distributed on an "AS IS" BASIS,
     13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  * See the License for the specific language governing permissions and
     15  * limitations under the License.
     16  *
     17  *****************************************************************************
     18  * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
     19 */
     20 
     21 /**
     22 ******************************************************************************
     23 *
     24 * @file ihevce_global_tables.c
     25 *
     26 * @brief
     27 *    This file contains definitions of global tables used by the encoder
     28 *
     29 * @author
     30 *    Ittiam
     31 *
     32 ******************************************************************************
     33 */
     34 
     35 /*****************************************************************************/
     36 /* File Includes                                                             */
     37 /*****************************************************************************/
     38 /* System include files */
     39 #include <stdio.h>
     40 #include <string.h>
     41 #include <stdlib.h>
     42 #include <assert.h>
     43 #include <stdarg.h>
     44 #include <math.h>
     45 
     46 /* User include files */
     47 #include "ihevc_typedefs.h"
     48 #include "itt_video_api.h"
     49 #include "ihevce_api.h"
     50 
     51 #include "rc_cntrl_param.h"
     52 #include "rc_frame_info_collector.h"
     53 #include "rc_look_ahead_params.h"
     54 
     55 #include "ihevc_defs.h"
     56 #include "ihevc_structs.h"
     57 #include "ihevc_platform_macros.h"
     58 #include "ihevc_deblk.h"
     59 #include "ihevc_itrans_recon.h"
     60 #include "ihevc_chroma_itrans_recon.h"
     61 #include "ihevc_chroma_intra_pred.h"
     62 #include "ihevc_intra_pred.h"
     63 #include "ihevc_inter_pred.h"
     64 #include "ihevc_mem_fns.h"
     65 #include "ihevc_padding.h"
     66 #include "ihevc_weighted_pred.h"
     67 #include "ihevc_sao.h"
     68 #include "ihevc_resi_trans.h"
     69 #include "ihevc_quant_iquant_ssd.h"
     70 #include "ihevc_cabac_tables.h"
     71 
     72 #include "ihevce_defs.h"
     73 #include "ihevce_lap_enc_structs.h"
     74 #include "ihevce_multi_thrd_structs.h"
     75 #include "ihevce_multi_thrd_funcs.h"
     76 #include "ihevce_me_common_defs.h"
     77 #include "ihevce_had_satd.h"
     78 #include "ihevce_error_codes.h"
     79 #include "ihevce_bitstream.h"
     80 #include "ihevce_cabac.h"
     81 #include "ihevce_rdoq_macros.h"
     82 #include "ihevce_function_selector.h"
     83 #include "ihevce_enc_structs.h"
     84 #include "ihevce_cmn_utils_instr_set_router.h"
     85 #include "hme_datatype.h"
     86 #include "hme_common_defs.h"
     87 #include "hme_common_utils.h"
     88 #include "hme_interface.h"
     89 #include "hme_defs.h"
     90 #include "ihevce_me_instr_set_router.h"
     91 #include "hme_err_compute.h"
     92 #include "hme_globals.h"
     93 #include "ihevce_entropy_structs.h"
     94 #include "ihevce_enc_loop_structs.h"
     95 #include "ihevce_enc_loop_utils.h"
     96 #include "ihevce_enc_loop_pass.h"
     97 #include "ihevce_global_tables.h"
     98 
     99 /*****************************************************************************/
    100 /* Globals                                                                   */
    101 /*****************************************************************************/
    102 const level_data_t g_as_level_data[TOTAL_NUM_LEVELS] = {
    103     /* LEVEL1 */
    104     { LEVEL1, 552960, 36864, { 128, 0 }, { 350, 0 }, 2, 16, 1, 1 },
    105 
    106     /* LEVEL2 */
    107     { LEVEL2, 3686400, 122880, { 1500, 0 }, { 1500, 0 }, 2, 16, 1, 1 },
    108 
    109     /* LEVEL2_1 */
    110     { LEVEL2_1, 7372800, 245760, { 3000, 0 }, { 3000, 0 }, 2, 20, 1, 1 },
    111 
    112     /* LEVEL3 */
    113     { LEVEL3, 16588800, 552960, { 6000, 0 }, { 6000, 0 }, 2, 30, 2, 2 },
    114 
    115     /* LEVEL3_1 */
    116     { LEVEL3_1, 33177600, 983040, { 10000, 0 }, { 10000, 0 }, 2, 40, 3, 3 },
    117 
    118     /* LEVEL4 */
    119     { LEVEL4, 66846720, 2228224, { 12000, 30000 }, { 12000, 30000 }, 4, 75, 5, 5 },
    120 
    121     /* LEVEL4_1 */
    122     { LEVEL4_1, 133693440, 2228224, { 20000, 50000 }, { 20000, 50000 }, 4, 75, 5, 5 },
    123 
    124     /* LEVEL5 */
    125     { LEVEL5, 267386880, 8912896, { 25000, 100000 }, { 25000, 100000 }, 6, 200, 11, 10 },
    126 
    127     /* LEVEL5_1 */
    128     { LEVEL5_1, 534773760, 8912896, { 40000, 160000 }, { 40000, 160000 }, 8, 200, 11, 10 },
    129 
    130     /* LEVEL5_2 */
    131     { LEVEL5_2, 1069547520, 8912896, { 60000, 240000 }, { 60000, 240000 }, 8, 200, 11, 10 },
    132 
    133     /* LEVEL6 */
    134     { LEVEL6, 1069547520, 35651584, { 60000, 240000 }, { 60000, 240000 }, 8, 600, 22, 20 },
    135 
    136     /* LEVEL6_1 */
    137     { LEVEL6_1, 2139095040, 35651584, { 120000, 480000 }, { 120000, 480000 }, 8, 600, 22, 20 },
    138 
    139     /* LEVEL6_2 */
    140     { LEVEL6_2, 4278190080, 35651584, { 240000, 800000 }, { 240000, 800000 }, 6, 600, 22, 20 },
    141 
    142 };
    143 
    144 /** \brief Default flat Scaling matrix for 4x4 transform */
    145 const WORD16 gi2_flat_scale_mat_4x4[] = { 16, 16, 16, 16, 16, 16, 16, 16,
    146                                           16, 16, 16, 16, 16, 16, 16, 16 };
    147 
    148 /** \brief Default flat Scaling matrix for 8x8 transform */
    149 const WORD16 gi2_flat_scale_mat_8x8[] = { 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    150                                           16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    151                                           16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    152                                           16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    153                                           16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 };
    154 
    155 /** \brief Default flat Scaling matrix for 16x16 transform */
    156 const WORD16 gi2_flat_scale_mat_16x16[] = {
    157     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    158     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    159     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    160     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    161     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    162     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    163     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    164     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    165     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    166     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    167     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16
    168 };
    169 
    170 /** \brief Default flat ReScaling matrix for 4x4 transform */
    171 const WORD16 gi2_flat_rescale_mat_4x4[] = { 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048,
    172                                             2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048 };
    173 
    174 /** \brief Default flat ReScaling matrix for 8x8 transform */
    175 const WORD16 gi2_flat_rescale_mat_8x8[] = {
    176     2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048,
    177     2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048,
    178     2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048,
    179     2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048
    180 };
    181 
    182 /** \brief Default flat ReScaling matrix for 16x16 transform */
    183 const WORD16 gi2_flat_rescale_mat_16x16[] = {
    184     2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048,
    185     2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048,
    186     2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048,
    187     2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048,
    188     2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048,
    189     2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048,
    190     2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048,
    191     2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048,
    192     2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048,
    193     2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048,
    194     2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048,
    195     2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048,
    196     2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048,
    197     2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048,
    198     2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048,
    199     2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048
    200 };
    201 
    202 /**
    203 * @brief Give the scanning order of csb in a 32x32 TU
    204 * based on first idx. 0 - upright_diagonal, 1 - horizontal, 2 - vertical scan
    205 */
    206 const UWORD8 g_u1_scan_table_8x8[3][64] = {
    207     /* diag up right scan */
    208     { 0,  8,  1,  16, 9,  2,  24, 17, 10, 3,  32, 25, 18, 11, 4,  40, 33, 26, 19, 12, 5,  48,
    209       41, 34, 27, 20, 13, 6,  56, 49, 42, 35, 28, 21, 14, 7,  57, 50, 43, 36, 29, 22, 15, 58,
    210       51, 44, 37, 30, 23, 59, 52, 45, 38, 31, 60, 53, 46, 39, 61, 54, 47, 62, 55, 63 },
    211 
    212     /* horizontal scan */
    213     { 0,  1,  2,  3,  4,  5,  6,  7,  8,  9,  10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
    214       22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43,
    215       44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63 },
    216 
    217     /* vertical scan */
    218     { 0,  8,  16, 24, 32, 40, 48, 56, 1,  9,  17, 25, 33, 41, 49, 57, 2,  10, 18, 26, 34, 42,
    219       50, 58, 3,  11, 19, 27, 35, 43, 51, 59, 4,  12, 20, 28, 36, 44, 52, 60, 5,  13, 21, 29,
    220       37, 45, 53, 61, 6,  14, 22, 30, 38, 46, 54, 62, 7,  15, 23, 31, 39, 47, 55, 63 }
    221 };
    222 
    223 /**
    224 * @brief Give the scanning order of csb in a 16x16 TU  or 4x4 csb
    225 * based on first idx. 0 - upright_diagonal, 1 - horizontal, 2 - vertical scan
    226 */
    227 const UWORD8 g_u1_scan_table_4x4[3][16] = {
    228     /* diag up right scan */
    229     { 0, 4, 1, 8, 5, 2, 12, 9, 6, 3, 13, 10, 7, 14, 11, 15 },
    230 
    231     /* horizontal scan */
    232     { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
    233 
    234     /* vertical scan */
    235     { 0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15 }
    236 };
    237 
    238 /**
    239 * @brief Give the scanning order of csb in a 8x8 TU
    240 * based on first idx. 0 - upright_diagonal, 1 - horizontal, 2 - vertical scan
    241 */
    242 const UWORD8 g_u1_scan_table_2x2[3][4] = {
    243     /* diag up right scan */
    244     { 0, 2, 1, 3 },
    245 
    246     /* horizontal scan */
    247     { 0, 1, 2, 3 },
    248 
    249     /* vertical scan */
    250     { 0, 2, 1, 3 }
    251 };
    252 
    253 /**
    254 * @brief Give the scanning order of csb in a 4x4 TU
    255 * scan idx. doesn't matter as it's 0 for all cases
    256 */
    257 const UWORD8 g_u1_scan_table_1x1[1] = { 0 };
    258 
    259 /**
    260 ******************************************************************************
    261 *  @brief For a given frac pt, fracx, fracy, this module figures out the
    262 *  corresponding fpel/hpel buffers along with x and y offsets if any. The
    263 *  grid used is shown as follows:
    264 *    A j E k B
    265 *    l m n o p
    266 *    F q G r H
    267 *    s t u v w
    268 *    C x I y D
    269 *
    270 *  In this grid capital letters are fpel/hpel bufs.
    271 ******************************************************************************
    272 */
    273 qpel_input_buf_cfg_t gas_qpel_inp_buf_cfg[4][4] = {
    274     {
    275         /* 0, 0 pt: both buf id would be fxfy = 0 */
    276         { 0, 0, 0, 0, 0, 0 },
    277         /* 1, 0 pt: pt j; avg of A and E */
    278         { 0, 0, 0, 1, 0, 0 },
    279         /* 2, 0 pt: pt E, buf id 0 and 1 would be hxfy = 1 */
    280         { 1, 0, 0, 1, 0, 0 },
    281         /* 3, 0 pt: pt k, avg of E and B */
    282         { 1, 0, 0, 0, 1, 0 },
    283     },
    284     {
    285         /* 0, 1 pt: pt l: avg of A and F */
    286         { 0, 0, 0, 2, 0, 0 },
    287         /* 1, 1 pt: pt m : avg of E and F */
    288         { 1, 0, 0, 2, 0, 0 },
    289         /* 2, 2 pt: pt n: avg of E and G */
    290         { 1, 0, 0, 3, 0, 0 },
    291         /* 3, 2 pt : pt o: avg of E and H */
    292         { 1, 0, 0, 2, 1, 0 },
    293     },
    294     {
    295         /* 0, 2 pt: pt F; both buf id would be fxhy = 2 */
    296         { 2, 0, 0, 2, 0, 0 },
    297         /* 1, 2 pt: pt q; avg of F and G */
    298         { 2, 0, 0, 3, 0, 0 },
    299         /* 2, 2 pt: pt G: both buf id would be hxhy = 3 */
    300         { 3, 0, 0, 3, 0, 0 },
    301         /* 2, 3 pt: pt r: avg of G and H */
    302         { 3, 0, 0, 2, 1, 0 },
    303     },
    304     {
    305         /* 0, 3 pt: pt s; avg of F and C */
    306         { 2, 0, 0, 0, 0, 1 },
    307         /* 1, 3 ot: pt t; avg of F and I */
    308         { 2, 0, 0, 1, 0, 1 },
    309         /* 2, 3 pt: pt u, avg of G and I */
    310         { 3, 0, 0, 1, 0, 1 },
    311         /* 3, 3 pt; pt v, avg of H and I */
    312         { 2, 1, 0, 1, 0, 1 },
    313     }
    314 };
    315 
    316 /**
    317 * @brief is partition vertical
    318 */
    319 const WORD8 gai1_is_part_vertical[TOT_NUM_PARTS] = { 0, 1, 1, 0, 0, 0, 0, 0, 0,
    320                                                      1, 1, 1, 1, 0, 0, 0, 0 };
    321 
    322 /**
    323 * @brief partition dimensions
    324 */
    325 const WORD8 gai1_part_wd_and_ht[TOT_NUM_PARTS][2] = { { 16, 16 }, { 16, 8 }, { 16, 8 },  { 8, 16 },
    326                                                       { 8, 16 },  { 8, 8 },  { 8, 8 },   { 8, 8 },
    327                                                       { 8, 8 },   { 16, 4 }, { 16, 12 }, { 16, 12 },
    328                                                       { 16, 4 },  { 4, 16 }, { 12, 16 }, { 12, 16 },
    329                                                       { 4, 16 } };
    330 
    331 /**
    332 ******************************************************************************
    333 *  @brief bits to code given ref id assuming more than 2 ref ids active
    334 ******************************************************************************
    335 */
    336 UWORD8 gau1_ref_bits[16] = { 1, 3, 3, 5, 5, 5, 5, 7, 7, 7, 7, 7, 7, 7, 7, 9 };
    337 
    338 /**
    339 * @brief raster to zscan lookup table
    340 */
    341 const UWORD8 gau1_ctb_raster_to_zscan[256] = {
    342     0,   1,   4,   5,   16,  17,  20,  21,  64,  65,  68,  69,  80,  81,  84,  85,  2,   3,   6,
    343     7,   18,  19,  22,  23,  66,  67,  70,  71,  82,  83,  86,  87,  8,   9,   12,  13,  24,  25,
    344     28,  29,  72,  73,  76,  77,  88,  89,  92,  93,  10,  11,  14,  15,  26,  27,  30,  31,  74,
    345     75,  78,  79,  90,  91,  94,  95,  32,  33,  36,  37,  48,  49,  52,  53,  96,  97,  100, 101,
    346     112, 113, 116, 117, 34,  35,  38,  39,  50,  51,  54,  55,  98,  99,  102, 103, 114, 115, 118,
    347     119, 40,  41,  44,  45,  56,  57,  60,  61,  104, 105, 108, 109, 120, 121, 124, 125, 42,  43,
    348     46,  47,  58,  59,  62,  63,  106, 107, 110, 111, 122, 123, 126, 127, 128, 129, 132, 133, 144,
    349     145, 148, 149, 192, 193, 196, 197, 208, 209, 212, 213, 130, 131, 134, 135, 146, 147, 150, 151,
    350     194, 195, 198, 199, 210, 211, 214, 215, 136, 137, 140, 141, 152, 153, 156, 157, 200, 201, 204,
    351     205, 216, 217, 220, 221, 138, 139, 142, 143, 154, 155, 158, 159, 202, 203, 206, 207, 218, 219,
    352     222, 223, 160, 161, 164, 165, 176, 177, 180, 181, 224, 225, 228, 229, 240, 241, 244, 245, 162,
    353     163, 166, 167, 178, 179, 182, 183, 226, 227, 230, 231, 242, 243, 246, 247, 168, 169, 172, 173,
    354     184, 185, 188, 189, 232, 233, 236, 237, 248, 249, 252, 253, 170, 171, 174, 175, 186, 187, 190,
    355     191, 234, 235, 238, 239, 250, 251, 254, 255
    356 };
    357 
    358 /**
    359 * @brief <Fill me>
    360 */
    361 UWORD32 gau4_frame_qstep_multiplier[54] = { 16, 16, 16, 15, 15, 15, 15, 15, 15, 13, 13, 13, 13, 12,
    362                                             12, 11, 11, 10, 10, 9,  9,  8,  8,  8,  7,  7,  7,  6,
    363                                             6,  5,  5,  5,  4,  4,  3,  3,  3,  2,  2,  2,  1,  1,
    364                                             0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0 };
    365 
    366 /**
    367 ******************************************************************************
    368 * @brief  Look up table for choosing the appropriate function for
    369 *         Intra prediction
    370 *
    371 * @remarks Same look up table enums are used for luma & chroma but each
    372 *          have seperate functions implemented
    373 ******************************************************************************
    374 */
    375 WORD32 g_i4_ip_funcs[MAX_NUM_IP_MODES] = {
    376     IP_FUNC_MODE_0, /* Mode 0 */
    377     IP_FUNC_MODE_1, /* Mode 1 */
    378     IP_FUNC_MODE_2, /* Mode 2 */
    379     IP_FUNC_MODE_3TO9, /* Mode 3 */
    380     IP_FUNC_MODE_3TO9, /* Mode 4 */
    381     IP_FUNC_MODE_3TO9, /* Mode 5 */
    382     IP_FUNC_MODE_3TO9, /* Mode 6 */
    383     IP_FUNC_MODE_3TO9, /* Mode 7 */
    384     IP_FUNC_MODE_3TO9, /* Mode 8 */
    385     IP_FUNC_MODE_3TO9, /* Mode 9 */
    386     IP_FUNC_MODE_10, /* Mode 10 */
    387     IP_FUNC_MODE_11TO17, /* Mode 11 */
    388     IP_FUNC_MODE_11TO17, /* Mode 12 */
    389     IP_FUNC_MODE_11TO17, /* Mode 13 */
    390     IP_FUNC_MODE_11TO17, /* Mode 14 */
    391     IP_FUNC_MODE_11TO17, /* Mode 15 */
    392     IP_FUNC_MODE_11TO17, /* Mode 16 */
    393     IP_FUNC_MODE_11TO17, /* Mode 17 */
    394     IP_FUNC_MODE_18_34, /* Mode 18 */
    395     IP_FUNC_MODE_19TO25, /* Mode 19 */
    396     IP_FUNC_MODE_19TO25, /* Mode 20 */
    397     IP_FUNC_MODE_19TO25, /* Mode 21 */
    398     IP_FUNC_MODE_19TO25, /* Mode 22 */
    399     IP_FUNC_MODE_19TO25, /* Mode 23 */
    400     IP_FUNC_MODE_19TO25, /* Mode 24 */
    401     IP_FUNC_MODE_19TO25, /* Mode 25 */
    402     IP_FUNC_MODE_26, /* Mode 26 */
    403     IP_FUNC_MODE_27TO33, /* Mode 27 */
    404     IP_FUNC_MODE_27TO33, /* Mode 26 */
    405     IP_FUNC_MODE_27TO33, /* Mode 29 */
    406     IP_FUNC_MODE_27TO33, /* Mode 30 */
    407     IP_FUNC_MODE_27TO33, /* Mode 31 */
    408     IP_FUNC_MODE_27TO33, /* Mode 32 */
    409     IP_FUNC_MODE_27TO33, /* Mode 33 */
    410     IP_FUNC_MODE_18_34, /* Mode 34 */
    411 };
    412 
    413 /**
    414 ******************************************************************************
    415 * @brief  Look up table for calculating the TU size for all the TUs in a CU
    416 *         if CU part mode is one of SIZE_2Nx2N, SIZE_2NxN, SIZE_Nx2N
    417 *
    418 *         i ranging (0 to 3)
    419 *         tu_size[i] = cu_size >> gau1_inter_tu_shft_amt[i];
    420 *
    421 * @remarks For non AMP cases only TU size = CU/2 is used
    422 *          and number of TU partitions in these CU will be 4
    423 ******************************************************************************
    424 */
    425 UWORD8 gau1_inter_tu_shft_amt[4] = {
    426     /* SIZE_2Nx2N, SIZE_2NxN, SIZE_Nx2N cases */
    427     1,
    428     1,
    429     1,
    430     1
    431 };
    432 
    433 /**
    434 ******************************************************************************
    435 * @brief  Look up table for calculating the TU size for all the TUs in a CU
    436 *         if CU part mode is one of SIZE_2NxnU, SIZE_2NxnD, SIZE_nLx2N
    437 *         SIZE_nRx2N (AMP motion partition cases)
    438 *
    439 *         part_mode = {SIZE_2NxnU,SIZE_2NxnD,SIZE_nLx2N,SIZE_nRx2N}
    440 *         i ranging (0 to 9)
    441 *         tu_size[i] = cu_size >> gau1_inter_tu_shft_amt_amp[part_mode-4][i];
    442 *
    443 * @remarks For AMP cases a mixture of TU size = CU/2 & CU/4 is used
    444 *          based on motion partition orientation, number of TU partitions
    445 *          in these CU will be 10
    446 ******************************************************************************
    447 */
    448 UWORD8 gau1_inter_tu_shft_amt_amp[4][10] = {
    449     /* SIZE_2NxnU case */
    450     { 2, 2, 2, 2, 2, 2, 2, 2, 1, 1 },
    451 
    452     /* SIZE_2NxnD case */
    453     { 1, 1, 2, 2, 2, 2, 2, 2, 2, 2 },
    454 
    455     /* SIZE_nLx2N case */
    456     { 2, 2, 2, 2, 1, 2, 2, 2, 2, 1 },
    457 
    458     /* SIZE_nRx2N case */
    459     { 1, 2, 2, 2, 2, 1, 2, 2, 2, 2 }
    460 };
    461 
    462 /**
    463 ******************************************************************************
    464 * @brief  Look up table for calculating the TU position in horizontal
    465 *         for all the TUs in a CU, if CU part mode is one of
    466 *         SIZE_2Nx2N, SIZE_2NxN, SIZE_Nx2N
    467 *
    468 *         i ranging (0 to 3)
    469 *         tu_posx[i](in pixels in cu) =
    470 *                 ((cusize >> 2) * gau1_inter_tu_posx_scl_amt[i]);
    471 ******************************************************************************
    472 */
    473 UWORD8 gau1_inter_tu_posx_scl_amt[4] = {
    474     /* SIZE_2Nx2N, SIZE_2NxN, SIZE_Nx2N cases */
    475     0,
    476     2,
    477     0,
    478     2
    479 };
    480 
    481 /**
    482 ******************************************************************************
    483 * @brief  Look up table for calculating the TU position in horizontal
    484 *         for all the TUs in a CU, if CU part mode is one of
    485 *         SIZE_2NxnU, SIZE_2NxnD, SIZE_nLx2N,SIZE_nRx2N (AMP motion partition cases)
    486 *
    487 *         part_mode = {SIZE_2NxnU,SIZE_2NxnD,SIZE_nLx2N,SIZE_nRx2N}
    488 *         i ranging (0 to 9)
    489 *         tu_posx[i](in pixels in cu) =
    490 *              ((cusize >> 2) * gau1_inter_tu_posx_scl_amt_amp[part_mode-4][i]);
    491 ******************************************************************************
    492 */
    493 UWORD8 gau1_inter_tu_posx_scl_amt_amp[4][10] = {
    494     /* SIZE_2NxnU case */
    495     { 0, 1, 0, 1, 2, 3, 2, 3, 0, 2 },
    496 
    497     /* SIZE_2NxnD case */
    498     { 0, 2, 0, 1, 0, 1, 2, 3, 2, 3 },
    499 
    500     /* SIZE_nLx2N case */
    501     { 0, 1, 0, 1, 2, 0, 1, 0, 1, 2 },
    502 
    503     /* SIZE_nRx2N case */
    504     { 0, 2, 3, 2, 3, 0, 2, 3, 2, 3 }
    505 };
    506 
    507 /**
    508 ******************************************************************************
    509 * @brief  Look up table for calculating the TU position in vertical
    510 *         for all the TUs in a CU, if CU part mode is one of
    511 *         SIZE_2Nx2N, SIZE_2NxN, SIZE_Nx2N
    512 *
    513 *         i ranging (0 to 3)
    514 *         tu_posy[i](in pixels in cu) =
    515 *                 ((cusize >> 2) * gau1_inter_tu_posy_scl_amt[i]);
    516 ******************************************************************************
    517 */
    518 UWORD8 gau1_inter_tu_posy_scl_amt[4] = {
    519     /* SIZE_2Nx2N, SIZE_2NxN, SIZE_Nx2N cases */
    520     0,
    521     0,
    522     2,
    523     2
    524 };
    525 
    526 /**
    527 ******************************************************************************
    528 * @brief  Look up table for calculating the TU position in vertical
    529 *         for all the TUs in a CU, if CU part mode is one of
    530 *         SIZE_2NxnU, SIZE_2NxnD, SIZE_nLx2N,SIZE_nRx2N (AMP motion partition cases)
    531 *
    532 *         part_mode = {SIZE_2NxnU,SIZE_2NxnD,SIZE_nLx2N,SIZE_nRx2N}
    533 *         i ranging (0 to 9)
    534 *         tu_posy[i](in pixels in cu) =
    535 *              ((cusize >> 2) * gau1_inter_tu_posy_scl_amt_amp[part_mode-4][i]);
    536 ******************************************************************************
    537 */
    538 UWORD8 gau1_inter_tu_posy_scl_amt_amp[4][10] = {
    539     /* SIZE_2NxnU case */
    540     { 0, 0, 1, 1, 0, 0, 1, 1, 2, 2 },
    541 
    542     /* SIZE_2NxnD case */
    543     { 0, 0, 2, 2, 3, 3, 2, 2, 3, 3 },
    544 
    545     /* SIZE_nLx2N case */
    546     { 0, 0, 1, 1, 0, 2, 2, 3, 3, 2 },
    547 
    548     /* SIZE_nRx2N case */
    549     { 0, 0, 0, 1, 1, 2, 2, 2, 3, 3 }
    550 };
    551 
    552 /**
    553 * @brief transform shift. Initialized in ihevce_enc_loop_init()
    554 */
    555 WORD32 ga_trans_shift[5];
    556 
    557 /**
    558 * @brief chroma 422 intra angle mapping
    559 */
    560 const UWORD8 gau1_chroma422_intra_angle_mapping[36] = {
    561     0,  1,  2,  2,  2,  2,  3,  5,  7,  8,  10, 12, 13, 15, 17, 18, 19, 20,
    562     21, 22, 23, 23, 24, 24, 25, 25, 26, 27, 27, 28, 28, 29, 29, 30, 31, DM_CHROMA_IDX
    563 };
    564 
    565 // clang-format off
    566 /**
    567 ******************************************************************************
    568 * @breif  LUT for returning the fractional bits(Q12) to encode a bin based on
    569 *         probability state and the encoded bin (MPS / LPS). The fractional
    570 *         bits are computed as -log2(probabililty of symbol)
    571 *
    572 *         Probabilites of the cabac states (0-63) are explained in section C
    573 *         of ieee paper by Detlev Marpe et al (VOL. 13, NO. 7, JULY 2003)
    574 *          alpha = (0.01875/0.5) ^ (1/63), p0 = 0.5 and p63 = 0.01875
    575 *
    576 *         Note that HEVC and AVC use the same cabac tables
    577 *
    578 * input   : curpState[bits7-1]  | (curMPS ^ encoded bin)[bit0]
    579 *
    580 * output  : fractionnal bits to encode the bin
    581 *
    582 ******************************************************************************
    583 */
    584 UWORD16 gau2_ihevce_cabac_bin_to_bits[64 * 2]   =
    585 {
    586     /* bits for mps */          /* bits for lps */
    587     ROUND_Q12(1.000000000),     ROUND_Q12(1.000000000),
    588     ROUND_Q12(0.928535439),     ROUND_Q12(1.075189930),
    589     ROUND_Q12(0.863825936),     ROUND_Q12(1.150379860),
    590     ROUND_Q12(0.804976479),     ROUND_Q12(1.225569790),
    591     ROUND_Q12(0.751252392),     ROUND_Q12(1.300759720),
    592     ROUND_Q12(0.702043265),     ROUND_Q12(1.375949650),
    593     ROUND_Q12(0.656836490),     ROUND_Q12(1.451139580),
    594     ROUND_Q12(0.615197499),     ROUND_Q12(1.526329510),
    595     ROUND_Q12(0.576754745),     ROUND_Q12(1.601519441),
    596     ROUND_Q12(0.541188141),     ROUND_Q12(1.676709371),
    597     ROUND_Q12(0.508220033),     ROUND_Q12(1.751899301),
    598     ROUND_Q12(0.477608072),     ROUND_Q12(1.827089231),
    599     ROUND_Q12(0.449139524),     ROUND_Q12(1.902279161),
    600     ROUND_Q12(0.422626680),     ROUND_Q12(1.977469091),
    601     ROUND_Q12(0.397903130),     ROUND_Q12(2.052659021),
    602     ROUND_Q12(0.374820697),     ROUND_Q12(2.127848951),
    603     ROUND_Q12(0.353246914),     ROUND_Q12(2.203038881),
    604     ROUND_Q12(0.333062915),     ROUND_Q12(2.278228811),
    605     ROUND_Q12(0.314161674),     ROUND_Q12(2.353418741),
    606     ROUND_Q12(0.296446520),     ROUND_Q12(2.428608671),
    607     ROUND_Q12(0.279829872),     ROUND_Q12(2.503798601),
    608     ROUND_Q12(0.264232174),     ROUND_Q12(2.578988531),
    609     ROUND_Q12(0.249580966),     ROUND_Q12(2.654178461),
    610     ROUND_Q12(0.235810099),     ROUND_Q12(2.729368392),
    611     ROUND_Q12(0.222859049),     ROUND_Q12(2.804558322),
    612     ROUND_Q12(0.210672321),     ROUND_Q12(2.879748252),
    613     ROUND_Q12(0.199198934),     ROUND_Q12(2.954938182),
    614     ROUND_Q12(0.188391967),     ROUND_Q12(3.030128112),
    615     ROUND_Q12(0.178208162),     ROUND_Q12(3.105318042),
    616     ROUND_Q12(0.168607572),     ROUND_Q12(3.180507972),
    617     ROUND_Q12(0.159553254),     ROUND_Q12(3.255697902),
    618     ROUND_Q12(0.151010993),     ROUND_Q12(3.330887832),
    619     ROUND_Q12(0.142949058),     ROUND_Q12(3.406077762),
    620     ROUND_Q12(0.135337985),     ROUND_Q12(3.481267692),
    621     ROUND_Q12(0.128150381),     ROUND_Q12(3.556457622),
    622     ROUND_Q12(0.121360753),     ROUND_Q12(3.631647552),
    623     ROUND_Q12(0.114945349),     ROUND_Q12(3.706837482),
    624     ROUND_Q12(0.108882016),     ROUND_Q12(3.782027412),
    625     ROUND_Q12(0.103150076),     ROUND_Q12(3.857217343),
    626     ROUND_Q12(0.097730208),     ROUND_Q12(3.932407273),
    627     ROUND_Q12(0.092604344),     ROUND_Q12(4.007597203),
    628     ROUND_Q12(0.087755577),     ROUND_Q12(4.082787133),
    629     ROUND_Q12(0.083168071),     ROUND_Q12(4.157977063),
    630     ROUND_Q12(0.078826986),     ROUND_Q12(4.233166993),
    631     ROUND_Q12(0.074718402),     ROUND_Q12(4.308356923),
    632     ROUND_Q12(0.070829259),     ROUND_Q12(4.383546853),
    633     ROUND_Q12(0.067147292),     ROUND_Q12(4.458736783),
    634     ROUND_Q12(0.063660977),     ROUND_Q12(4.533926713),
    635     ROUND_Q12(0.060359483),     ROUND_Q12(4.609116643),
    636     ROUND_Q12(0.057232622),     ROUND_Q12(4.684306573),
    637     ROUND_Q12(0.054270808),     ROUND_Q12(4.759496503),
    638     ROUND_Q12(0.051465018),     ROUND_Q12(4.834686433),
    639     ROUND_Q12(0.048806753),     ROUND_Q12(4.909876363),
    640     ROUND_Q12(0.046288005),     ROUND_Q12(4.985066294),
    641     ROUND_Q12(0.043901228),     ROUND_Q12(5.060256224),
    642     ROUND_Q12(0.041639305),     ROUND_Q12(5.135446154),
    643     ROUND_Q12(0.039495525),     ROUND_Q12(5.210636084),
    644     ROUND_Q12(0.037463555),     ROUND_Q12(5.285826014),
    645     ROUND_Q12(0.035537418),     ROUND_Q12(5.361015944),
    646     ROUND_Q12(0.033711472),     ROUND_Q12(5.436205874),
    647     ROUND_Q12(0.031980387),     ROUND_Q12(5.511395804),
    648     ROUND_Q12(0.030339132),     ROUND_Q12(5.586585734),
    649     ROUND_Q12(0.028782950),     ROUND_Q12(5.661775664),
    650     ROUND_Q12(0.027307346),     ROUND_Q12(5.736965594)
    651 };
    652 // clang-format on
    653 
    654 /**
    655 * @brief <Fill Me>
    656 */
    657 WORD32 gai4_subBlock2csbfId_map4x4TU[1];
    658 WORD32 gai4_subBlock2csbfId_map8x8TU[4];
    659 WORD32 gai4_subBlock2csbfId_map16x16TU[16];
    660 WORD32 gai4_subBlock2csbfId_map32x32TU[64];
    661 
    662 /**
    663 * @brief the neighbor flags for a general ctb (ctb inside the frame; not any corners).
    664 * The table gau4_nbr_flags_8x8_4x4blks generated for 16x16 4x4 blocks(ctb_size = 64).
    665 * But the same table holds good for other 4x4 blocks 2d arrays(eg 8x8 4x4 blks,4x4 4x4blks).
    666 * But the flags must be accessed with stride of 16 since the table has been generated for
    667 * ctb_size = 64. For odd 4x4 2d arrays(eg 3x3 4x4 blks) the flags needs modification.
    668 * The flags also need modification for corner ctbs.
    669 */
    670 const UWORD32 gau4_nbr_flags_8x8_4x4blks[64] = {
    671     0x11188, 0x11180, 0x11188, 0x11180, 0x11188, 0x11180, 0x11188, 0x11180, 0x11188, 0x10180,
    672     0x11180, 0x10180, 0x11188, 0x10180, 0x11180, 0x10180, 0x11188, 0x11180, 0x11188, 0x10180,
    673     0x11188, 0x11180, 0x11188, 0x10180, 0x11188, 0x10180, 0x11180, 0x10180, 0x11180, 0x10180,
    674     0x11180, 0x10180, 0x11188, 0x11180, 0x11188, 0x11180, 0x11188, 0x11180, 0x11188, 0x10180,
    675     0x11188, 0x10180, 0x11180, 0x10180, 0x11188, 0x10180, 0x11180, 0x10180, 0x11188, 0x11180,
    676     0x11188, 0x10180, 0x11188, 0x11180, 0x11188, 0x10180, 0x11180, 0x10180, 0x11180, 0x10180,
    677     0x11180, 0x10180, 0x11180, 0x10180
    678 };
    679 
    680 /**
    681 * @brief subset of intra modes to be evaluated during pre enc intra process
    682 */
    683 const UWORD8 gau1_modes_to_eval[11] = { 0, 1, 26, 2, 6, 10, 14, 18, 22, 30, 34 };
    684 
    685 const float gad_look_up_activity[TOT_QP_MOD_OFFSET] = { 0.314980262f, 0.353553391f, 0.396850263f,
    686                                                         0.445449359f, 0.5f,         0.561231024f,
    687                                                         0.629960525f, 0.707106781f, 0.793700526f,
    688                                                         0.890898718f, 1.0f,         1.122462048f,
    689                                                         1.25992105f,  1.414213562f };
    690