00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "contributors.h"
00018
00019 #include <math.h>
00020
00021 #include "global.h"
00022
00023 #include "image.h"
00024 #include "mb_access.h"
00025 #include "vlc.h"
00026 #include "transform.h"
00027 #include "mc_prediction.h"
00028 #include "q_offsets.h"
00029 #include "q_matrix.h"
00030 #include "quant4x4.h"
00031
00032
00033
00034
00035
00036
00037
00038
00039 int quant_4x4_normal(Macroblock *currMB, int **tblock, struct quant_methods *q_method)
00040 {
00041 QuantParameters *p_Quant = currMB->p_Img->p_Quant;
00042 int block_x = q_method->block_x;
00043 int qp = q_method->qp;
00044 int* ACLevel = q_method->ACLevel;
00045 int* ACRun = q_method->ACRun;
00046 LevelQuantParams **q_params_4x4 = q_method->q_params;
00047 const byte (*pos_scan)[2] = q_method->pos_scan;
00048 const byte *c_cost = q_method->c_cost;
00049 int *coeff_cost = q_method->coeff_cost;
00050 Boolean is_cavlc = (currMB->p_slice->symbol_mode == CAVLC);
00051 int i,j, coeff_ctr;
00052
00053 int *m7;
00054 int scaled_coeff;
00055
00056 int level, run = 0;
00057 int nonzero = FALSE;
00058 int qp_per = p_Quant->qp_per_matrix[qp];
00059 int q_bits = Q_BITS + qp_per;
00060 const byte *p_scan = &pos_scan[0][0];
00061 int* ACL = &ACLevel[0];
00062 int* ACR = &ACRun[0];
00063
00064
00065 for (coeff_ctr = 0; coeff_ctr < 16; coeff_ctr++)
00066 {
00067 i = *p_scan++;
00068 j = *p_scan++;
00069
00070 m7 = &tblock[j][block_x + i];
00071
00072 if (*m7 != 0)
00073 {
00074 scaled_coeff = iabs (*m7) * q_params_4x4[j][i].ScaleComp;
00075 level = (scaled_coeff + q_params_4x4[j][i].OffsetComp) >> q_bits;
00076
00077 if (level != 0)
00078 {
00079 if (is_cavlc)
00080 level = imin(level, CAVLC_LEVEL_LIMIT);
00081
00082 *coeff_cost += (level > 1) ? MAX_VALUE : c_cost[run];
00083
00084 level = isignab(level, *m7);
00085 *m7 = rshift_rnd_sf(((level * q_params_4x4[j][i].InvScaleComp) << qp_per), 4);
00086
00087
00088
00089 *ACL++ = level;
00090 *ACR++ = run;
00091
00092 run = 0;
00093 nonzero = TRUE;
00094 }
00095 else
00096 {
00097 run++;
00098 *m7 = 0;
00099 }
00100 }
00101 else
00102 {
00103 run++;
00104 }
00105 }
00106
00107 *ACL = 0;
00108
00109 return nonzero;
00110 }
00111
00112 int quant_ac4x4_normal(Macroblock *currMB, int **tblock, struct quant_methods *q_method, int type)
00113 {
00114 int block_x = q_method->block_x;
00115 int qp = q_method->qp;
00116 int* ACLevel = q_method->ACLevel;
00117 int* ACRun = q_method->ACRun;
00118 LevelQuantParams **q_params_4x4 = q_method->q_params;
00119 const byte (*pos_scan)[2] = q_method->pos_scan;
00120 const byte *c_cost = q_method->c_cost;
00121 int *coeff_cost = q_method->coeff_cost;
00122
00123 QuantParameters *p_Quant = currMB->p_Img->p_Quant;
00124 Boolean is_cavlc = (currMB->p_slice->symbol_mode == CAVLC);
00125 int i,j, coeff_ctr;
00126
00127 int *m7;
00128 int scaled_coeff;
00129
00130 int level, run = 0;
00131 int nonzero = FALSE;
00132 int qp_per = p_Quant->qp_per_matrix[qp];
00133 int q_bits = Q_BITS + qp_per;
00134 const byte *p_scan = &pos_scan[1][0];
00135 int* ACL = &ACLevel[0];
00136 int* ACR = &ACRun[0];
00137
00138
00139 for (coeff_ctr = 1; coeff_ctr < 16; coeff_ctr++)
00140 {
00141 i = *p_scan++;
00142 j = *p_scan++;
00143
00144 m7 = &tblock[j][block_x + i];
00145 if (*m7 != 0)
00146 {
00147 scaled_coeff = iabs (*m7) * q_params_4x4[j][i].ScaleComp;
00148 level = (scaled_coeff + q_params_4x4[j][i].OffsetComp) >> q_bits;
00149
00150 if (level != 0)
00151 {
00152 if (is_cavlc)
00153 level = imin(level, CAVLC_LEVEL_LIMIT);
00154
00155 *coeff_cost += (level > 1) ? MAX_VALUE : c_cost[run];
00156
00157 level = isignab(level, *m7);
00158 *m7 = rshift_rnd_sf(((level * q_params_4x4[j][i].InvScaleComp) << qp_per), 4);
00159
00160
00161
00162 *ACL++ = level;
00163 *ACR++ = run;
00164
00165 run = 0;
00166 nonzero = TRUE;
00167 }
00168 else
00169 {
00170 run++;
00171 *m7 = 0;
00172 }
00173 }
00174 else
00175 {
00176 run++;
00177 }
00178 }
00179
00180 *ACL = 0;
00181
00182 return nonzero;
00183 }
00184
00185
00186
00187
00188
00189
00190
00191
00192 int quant_dc4x4_normal(Macroblock *currMB, int **tblock, int qp, int* DCLevel, int* DCRun,
00193 LevelQuantParams *q_params_4x4, const byte (*pos_scan)[2])
00194 {
00195 QuantParameters *p_Quant = currMB->p_Img->p_Quant;
00196 Boolean is_cavlc = (currMB->p_slice->symbol_mode == CAVLC);
00197 int i,j, coeff_ctr;
00198
00199 int *m7;
00200 int scaled_coeff;
00201
00202 int level, run = 0;
00203 int nonzero = FALSE;
00204 int qp_per = p_Quant->qp_per_matrix[qp];
00205 int q_bits = Q_BITS + qp_per + 1;
00206 const byte *p_scan = &pos_scan[0][0];
00207 int* DCL = &DCLevel[0];
00208 int* DCR = &DCRun[0];
00209
00210
00211 for (coeff_ctr = 0; coeff_ctr < 16; coeff_ctr++)
00212 {
00213 i = *p_scan++;
00214 j = *p_scan++;
00215
00216 m7 = &tblock[j][i];
00217
00218 if (*m7 != 0)
00219 {
00220 scaled_coeff = iabs (*m7) * q_params_4x4->ScaleComp;
00221 level = (scaled_coeff + (q_params_4x4->OffsetComp << 1) ) >> q_bits;
00222
00223 if (level != 0)
00224 {
00225 if (is_cavlc)
00226 level = imin(level, CAVLC_LEVEL_LIMIT);
00227 level = isignab(level, *m7);
00228
00229 *m7 = level;
00230 *DCL++ = level;
00231 *DCR++ = run;
00232
00233 run = 0;
00234 nonzero = TRUE;
00235 }
00236 else
00237 {
00238 run++;
00239 *m7 = 0;
00240 }
00241 }
00242 else
00243 {
00244 run++;
00245 }
00246 }
00247
00248 *DCL = 0;
00249
00250 return nonzero;
00251 }