00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _RDOQ_H_
00018 #define _RDOQ_H_
00019
00020 #include <math.h>
00021
00022
00023 #define SIGN_BITS 1
00024
00025 static const int estErr4x4[6][4][4] =
00026 {
00027 {
00028 {25600, 27040, 25600, 27040},
00029 {27040, 25600, 27040, 25600},
00030 {25600, 27040, 25600, 27040},
00031 {27040, 25600, 27040, 25600}
00032 },
00033 {
00034 {30976, 31360, 30976, 31360},
00035 {31360, 32400, 31360, 32400},
00036 {30976, 31360, 30976, 31360},
00037 {31360, 32400, 31360, 32400}
00038 },
00039 {
00040 {43264, 40960, 43264, 40960},
00041 {40960, 40000, 40960, 40000},
00042 {43264, 40960, 43264, 40960},
00043 {40960, 40000, 40960, 40000}
00044 },
00045 {
00046 {50176, 51840, 50176, 51840},
00047 {51840, 52900, 51840, 52900},
00048 {50176, 51840, 50176, 51840},
00049 {51840, 52900, 51840, 52900}
00050 },
00051 {
00052 {65536, 64000, 65536, 64000},
00053 {64000, 62500, 64000, 62500},
00054 {65536, 64000, 65536, 64000},
00055 {64000, 62500, 64000, 62500}
00056 },
00057 {
00058 {82944, 84640, 82944, 84640},
00059 {84640, 84100, 84640, 84100},
00060 {82944, 84640, 82944, 84640},
00061 {84640, 84100, 84640, 84100}
00062 }
00063 };
00064
00065 static const int estErr8x8[6][8][8]={
00066 {
00067 {6553600, 6677056, 6400000, 6677056, 6553600, 6677056, 6400000, 6677056},
00068 {6677056, 6765201, 6658560, 6765201, 6677056, 6765201, 6658560, 6765201},
00069 {6400000, 6658560, 6553600, 6658560, 6400000, 6658560, 6553600, 6658560},
00070 {6677056, 6765201, 6658560, 6765201, 6677056, 6765201, 6658560, 6765201},
00071 {6553600, 6677056, 6400000, 6677056, 6553600, 6677056, 6400000, 6677056},
00072 {6677056, 6765201, 6658560, 6765201, 6677056, 6765201, 6658560, 6765201},
00073 {6400000, 6658560, 6553600, 6658560, 6400000, 6658560, 6553600, 6658560},
00074 {6677056, 6765201, 6658560, 6765201, 6677056, 6765201, 6658560, 6765201}
00075 },
00076 {
00077 {7929856, 8156736, 8028160, 8156736, 7929856, 8156736, 8028160, 8156736},
00078 {8156736, 7537770, 7814560, 7537770, 8156736, 7537770, 7814560, 7537770},
00079 {8028160, 7814560, 7840000, 7814560, 8028160, 7814560, 7840000, 7814560},
00080 {8156736, 7537770, 7814560, 7537770, 8156736, 7537770, 7814560, 7537770},
00081 {7929856, 8156736, 8028160, 8156736, 7929856, 8156736, 8028160, 8156736},
00082 {8156736, 7537770, 7814560, 7537770, 8156736, 7537770, 7814560, 7537770},
00083 {8028160, 7814560, 7840000, 7814560, 8028160, 7814560, 7840000, 7814560},
00084 {8156736, 7537770, 7814560, 7537770, 8156736, 7537770, 7814560, 7537770}
00085 },
00086 {
00087 {11075584, 10653696, 11151360, 10653696, 11075584, 10653696, 11151360, 10653696},
00088 {10653696, 11045652, 11109160, 11045652, 10653696, 11045652, 11109160, 11045652},
00089 {11151360, 11109160, 11289600, 11109160, 11151360, 11109160, 11289600, 11109160},
00090 {10653696, 11045652, 11109160, 11045652, 10653696, 11045652, 11109160, 11045652},
00091 {11075584, 10653696, 11151360, 10653696, 11075584, 10653696, 11151360, 10653696},
00092 {10653696, 11045652, 11109160, 11045652, 10653696, 11045652, 11109160, 11045652},
00093 {11151360, 11109160, 11289600, 11109160, 11151360, 11109160, 11289600, 11109160},
00094 {10653696, 11045652, 11109160, 11045652, 10653696, 11045652, 11109160, 11045652}
00095 },
00096 {
00097 {12845056, 12503296, 12544000, 12503296, 12845056, 12503296, 12544000, 12503296},
00098 {12503296, 13050156, 12588840, 13050156, 12503296, 13050156, 12588840, 13050156},
00099 {12544000, 12588840, 12960000, 12588840, 12544000, 12588840, 12960000, 12588840},
00100 {12503296, 13050156, 12588840, 13050156, 12503296, 13050156, 12588840, 13050156},
00101 {12845056, 12503296, 12544000, 12503296, 12845056, 12503296, 12544000, 12503296},
00102 {12503296, 13050156, 12588840, 13050156, 12503296, 13050156, 12588840, 13050156},
00103 {12544000, 12588840, 12960000, 12588840, 12544000, 12588840, 12960000, 12588840},
00104 {12503296, 13050156, 12588840, 13050156, 12503296, 13050156, 12588840, 13050156}
00105 },
00106 {
00107 {16777216, 16646400, 16384000, 16646400, 16777216, 16646400, 16384000, 16646400},
00108 {16646400, 16370116, 16692640, 16370116, 16646400, 16370116, 16692640, 16370116},
00109 {16384000, 16692640, 16646400, 16692640, 16384000, 16692640, 16646400, 16692640},
00110 {16646400, 16370116, 16692640, 16370116, 16646400, 16370116, 16692640, 16370116},
00111 {16777216, 16646400, 16384000, 16646400, 16777216, 16646400, 16384000, 16646400},
00112 {16646400, 16370116, 16692640, 16370116, 16646400, 16370116, 16692640, 16370116},
00113 {16384000, 16692640, 16646400, 16692640, 16384000, 16692640, 16646400, 16692640},
00114 {16646400, 16370116, 16692640, 16370116, 16646400, 16370116, 16692640, 16370116}
00115 },
00116 {
00117 {21233664, 21381376, 21667840, 21381376, 21233664, 21381376, 21667840, 21381376},
00118 {21381376, 21381376, 21374440, 21381376, 21381376, 21381376, 21374440, 21381376},
00119 {21667840, 21374440, 21529600, 21374440, 21667840, 21374440, 21529600, 21374440},
00120 {21381376, 21381376, 21374440, 21381376, 21381376, 21381376, 21374440, 21381376},
00121 {21233664, 21381376, 21667840, 21381376, 21233664, 21381376, 21667840, 21381376},
00122 {21381376, 21381376, 21374440, 21381376, 21381376, 21381376, 21374440, 21381376},
00123 {21667840, 21374440, 21529600, 21374440, 21667840, 21374440, 21529600, 21374440},
00124 {21381376, 21381376, 21374440, 21381376, 21381376, 21381376, 21374440, 21381376}
00125 }
00126 };
00127
00128
00129 struct est_bits_cabac
00130 {
00131 int significantBits[16][2];
00132 int lastBits[16][2];
00133 int greaterOneBits[2][5][2];
00134 int greaterOneState[5];
00135 int blockCbpBits[4][2];
00136 };
00137 typedef struct est_bits_cabac estBitsCabacStruct;
00138
00139 typedef struct level_data_struct
00140 {
00141 int level[3];
00142 int levelDouble;
00143 double errLevel[3];
00144 int noLevels;
00145 int coeff_ctr;
00146 int pre_level;
00147 int sign;
00148 } levelDataStruct;
00149
00150
00151 extern void init_rdoq_slice(Slice *currSlice);
00152
00153
00154 extern void est_RunLevel_CAVLC(Macroblock *currMB, levelDataStruct *levelData, int *levelTrellis, int block_type,
00155 int b8, int b4, int coeff_num, double lambda);
00156 extern int est_CAVLC_bits (ImageParameters *p_Img, int level_to_enc[16], int sign_to_enc[16], int nnz, int block_type);
00157
00158
00159 extern void precalculate_unary_exp_golomb_level(ImageParameters *p_Img);
00160 extern int est_unary_exp_golomb_level_bits(unsigned int symbol, int bits0, int bits1);
00161 extern int est_exp_golomb_encode_eq_prob (unsigned int symbol);
00162
00163 extern void estRunLevel_CABAC (Macroblock* currMB, int context);
00164
00165
00166
00167 extern int est_write_and_store_CBP_block_bit(Macroblock* currMB, int type);
00168 extern void est_writeRunLevel_CABAC(Macroblock *currMB, levelDataStruct levelData[], int levelTabMin[], int type, double lambda, int kStart,
00169 int kStop, int noCoeff, int estCBP);
00170 extern void init_trellis_data_4x4_CAVLC(Macroblock *currMB, int **tblock, int block_x, int qp_per, int qp_rem,
00171 LevelQuantParams **q_params_4x4, const byte *p_scan,
00172 levelDataStruct *dataLevel, int type);
00173 extern int init_trellis_data_4x4_CABAC(Macroblock *currMB, int **tblock, int block_x, int qp_per, int qp_rem,
00174 LevelQuantParams **q_params_4x4, const byte *p_scan,
00175 levelDataStruct *dataLevel, int* kStart, int* kStop, int type);
00176 extern void init_trellis_data_8x8_CAVLC(Macroblock *currMB, int **tblock, int block_x, int qp_per, int qp_rem,
00177 LevelQuantParams **q_params_8x8, const byte *p_scan,
00178 levelDataStruct levelData[4][16]);
00179 extern int init_trellis_data_8x8_CABAC(Macroblock *currMB, int **tblock, int block_x, int qp_per, int qp_rem,
00180 LevelQuantParams **q_params_8x8, const byte *p_scan,
00181 levelDataStruct *dataLevel, int* kStart, int* kStop);
00182 extern void init_trellis_data_DC_CAVLC(Macroblock *currMB, int **tblock, int qp_per, int qp_rem,
00183 LevelQuantParams *q_params_4x4, const byte *p_scan,
00184 levelDataStruct *dataLevel);
00185 extern int init_trellis_data_DC_CABAC(Macroblock *currMB, int **tblock, int qp_per, int qp_rem,
00186 LevelQuantParams *q_params_4x4, const byte *p_scan,
00187 levelDataStruct *dataLevel, int* kStart, int* kStop);
00188 extern int init_trellis_data_DC_cr_CAVLC(Macroblock *currMB, int **tblock, int qp_per, int qp_rem,
00189 LevelQuantParams *q_params_4x4, const byte *p_scan,
00190 levelDataStruct *dataLevel);
00191 extern int init_trellis_data_DC_cr_CABAC(Macroblock *currMB, int **tblock, int qp_per, int qp_rem,
00192 LevelQuantParams *q_params_4x4, const byte *p_scan,
00193 levelDataStruct *dataLevel, int* kStart, int* kStop);
00194
00195 extern void RDOQ_update_mode (Slice *currSlice, RD_PARAMS *enc_mb);
00196 extern void copy_rddata_trellis (Macroblock *currMB, RD_DATA *dest, RD_DATA *src);
00197 extern void updateMV_mp (Macroblock *currMB, int *m_cost, short ref, int list, int h, int v, int blocktype, int block8x8);
00198 extern void trellis_coding (Macroblock *currMB, Boolean prev_recode_mb);
00199 extern void get_dQP_table (Slice *currSlice);
00200
00201 #endif // _RDOQ_H_
00202