00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "contributors.h"
00017
00018 #include <math.h>
00019
00020 #include "global.h"
00021 #include "q_matrix.h"
00022 #include "quant4x4.h"
00023 #include "quantChroma.h"
00024 #include "rdoq.h"
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 int quant_dc2x2_trellis(Macroblock *currMB, int **tblock, int qp, int* DCLevel, int* DCRun,
00038 LevelQuantParams *q_params_4x4, int **fadjust, const byte (*pos_scan)[2])
00039 {
00040 Slice *currSlice = currMB->p_slice;
00041 QuantParameters *p_Quant = currMB->p_Img->p_Quant;
00042 Boolean is_cavlc = (currMB->p_slice->symbol_mode == CAVLC);
00043 int coeff_ctr;
00044
00045 int *m7;
00046
00047 int level, run = 0;
00048 int nonzero = FALSE;
00049 int qp_per = p_Quant->qp_per_matrix[qp];
00050 int qp_rem = p_Quant->qp_rem_matrix[qp];
00051
00052 int* DCL = &DCLevel[0];
00053 int* DCR = &DCRun[0];
00054
00055 int levelTrellis[16];
00056
00057 currSlice->rdoq_dc_cr(currMB, tblock,qp_per,qp_rem, q_params_4x4, pos_scan, levelTrellis, CHROMA_DC);
00058
00059 m7 = *tblock;
00060
00061
00062 for (coeff_ctr=0; coeff_ctr < 4; coeff_ctr++)
00063 {
00064
00065
00066 if (*m7)
00067 {
00068 level = levelTrellis[coeff_ctr];
00069
00070 if (level != 0)
00071 {
00072 if (is_cavlc)
00073 level = imin(level, CAVLC_LEVEL_LIMIT);
00074
00075 level = isignab(level, *m7);
00076
00077 *m7++ = ((level * q_params_4x4->InvScaleComp) << qp_per);
00078
00079 *DCL++ = level;
00080 *DCR++ = run;
00081
00082 run = 0;
00083 nonzero = TRUE;
00084 }
00085 else
00086 {
00087 run++;
00088 *m7++ = 0;
00089 }
00090 }
00091 else
00092 {
00093 run++;
00094 m7++;
00095 }
00096 }
00097
00098 *DCL = 0;
00099
00100 return nonzero;
00101 }
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114 int quant_dc4x2_trellis(Macroblock *currMB, int **tblock, int qp, int* DCLevel, int* DCRun,
00115 LevelQuantParams *q_params_4x4, int **fadjust, const byte (*pos_scan)[2])
00116 {
00117 Slice *currSlice = currMB->p_slice;
00118 QuantParameters *p_Quant = currMB->p_Img->p_Quant;
00119 Boolean is_cavlc = (currMB->p_slice->symbol_mode == CAVLC);
00120 int i,j, coeff_ctr;
00121
00122 int *m7;
00123
00124 int level, run = 0;
00125 int nonzero = FALSE;
00126 int qp_per = p_Quant->qp_per_matrix[qp];
00127 int qp_rem = p_Quant->qp_rem_matrix[qp];
00128 const byte *p_scan = &pos_scan[0][0];
00129 int* DCL = &DCLevel[0];
00130 int* DCR = &DCRun[0];
00131
00132 int levelTrellis[16];
00133
00134 currSlice->rdoq_dc_cr(currMB, tblock,qp_per,qp_rem, q_params_4x4,pos_scan, levelTrellis, CHROMA_DC_2x4);
00135
00136 for (coeff_ctr=0; coeff_ctr < 8; coeff_ctr++)
00137 {
00138 j = *p_scan++;
00139 i = *p_scan++;
00140
00141 m7 = &tblock[j][i];
00142
00143 if (*m7 != 0)
00144 {
00145 level = levelTrellis[coeff_ctr];
00146
00147 if (level != 0)
00148 {
00149 if (is_cavlc)
00150 level = imin(level, CAVLC_LEVEL_LIMIT);
00151 level = isignab(level, *m7);
00152
00153 *m7 = ((level * q_params_4x4->InvScaleComp) << qp_per);
00154
00155 *DCL++ = level;
00156 *DCR++ = run;
00157
00158 run = 0;
00159 nonzero = TRUE;
00160 }
00161 else
00162 {
00163 run++;
00164 *m7 = 0;
00165 }
00166 }
00167 else
00168 {
00169 run++;
00170 }
00171 }
00172
00173 *DCL = 0;
00174
00175 return nonzero;
00176 }
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186 void rdoq_dc_cr_CAVLC(Macroblock *currMB, int **tblock, int qp_per, int qp_rem, LevelQuantParams *q_params_4x4, const byte (*pos_scan)[2], int levelTrellis[], int type)
00187 {
00188 ImageParameters *p_Img = currMB->p_Img;
00189
00190 const byte *p_scan = &pos_scan[0][0];
00191 levelDataStruct levelData[16];
00192 double lambda_md = 0.0;
00193
00194 if ((p_Img->type==B_SLICE) && p_Img->nal_reference_idc)
00195 {
00196 lambda_md = p_Img->lambda_md[5][p_Img->masterQP];
00197 }
00198 else
00199 {
00200 lambda_md = p_Img->lambda_md[p_Img->type][p_Img->masterQP];
00201 }
00202
00203 init_trellis_data_DC_cr_CAVLC(currMB, tblock, qp_per, qp_rem, q_params_4x4, p_scan, &levelData[0]);
00204 est_RunLevel_CAVLC(currMB, levelData, levelTrellis, CHROMA_DC, 0, 0, p_Img->num_cdc_coeff, lambda_md);
00205 }
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215 void rdoq_dc_cr_CABAC(Macroblock *currMB, int **tblock, int qp_per, int qp_rem, LevelQuantParams *q_params_4x4, const byte (*pos_scan)[2], int levelTrellis[], int type)
00216 {
00217 ImageParameters *p_Img = currMB->p_Img;
00218 const byte *p_scan = &pos_scan[0][0];
00219 levelDataStruct levelData[16];
00220 double lambda_md = 0.0;
00221 int kStart=0, kStop=0, noCoeff = 0, estBits;
00222
00223 if ((p_Img->type==B_SLICE) && p_Img->nal_reference_idc)
00224 {
00225 lambda_md = p_Img->lambda_md[5][p_Img->masterQP];
00226 }
00227 else
00228 {
00229 lambda_md = p_Img->lambda_md[p_Img->type][p_Img->masterQP];
00230 }
00231
00232 noCoeff = init_trellis_data_DC_cr_CABAC(currMB, tblock, qp_per, qp_rem, q_params_4x4, p_scan, &levelData[0], &kStart, &kStop);
00233 estBits = est_write_and_store_CBP_block_bit(currMB, type);
00234 est_writeRunLevel_CABAC(currMB, levelData, levelTrellis, type, lambda_md, kStart, kStop, noCoeff, estBits);
00235 }
00236
00237