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
00022 #include "image.h"
00023 #include "mb_access.h"
00024 #include "vlc.h"
00025 #include "transform.h"
00026 #include "mc_prediction.h"
00027 #include "q_offsets.h"
00028 #include "q_matrix.h"
00029 #include "quant8x8.h"
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 int quant_8x8_normal(Macroblock *currMB, int **tblock, struct quant_methods *q_method)
00044 {
00045 ImageParameters *p_Img = currMB->p_Img;
00046 QuantParameters *p_Quant = p_Img->p_Quant;
00047 int block_x = q_method->block_x;
00048 int* ACLevel = q_method->ACLevel;
00049 int* ACRun = q_method->ACRun;
00050 int qp = q_method->qp;
00051 LevelQuantParams **q_params_8x8 = q_method->q_params;
00052 const byte (*pos_scan)[2] = q_method->pos_scan;
00053 const byte *c_cost = q_method->c_cost;
00054 int *coeff_cost = q_method->coeff_cost;
00055
00056 int i,j, coeff_ctr;
00057
00058 int *m7;
00059 int scaled_coeff;
00060
00061 int level, run = 0;
00062 int nonzero = FALSE;
00063 int qp_per = p_Quant->qp_per_matrix[qp];
00064 int q_bits = Q_BITS_8 + qp_per;
00065 const byte *p_scan = &pos_scan[0][0];
00066 int* ACL = &ACLevel[0];
00067 int* ACR = &ACRun[0];
00068
00069
00070 for (coeff_ctr = 0; coeff_ctr < 64; coeff_ctr++)
00071 {
00072 i = *p_scan++;
00073 j = *p_scan++;
00074
00075 m7 = &tblock[j][block_x + i];
00076 if (*m7 != 0)
00077 {
00078 scaled_coeff = iabs (*m7) * q_params_8x8[j][i].ScaleComp;
00079 level = (scaled_coeff + q_params_8x8[j][i].OffsetComp) >> q_bits;
00080
00081 if (level != 0)
00082 {
00083 nonzero = TRUE;
00084
00085 *coeff_cost += (level > 1) ? MAX_VALUE : c_cost[run];
00086
00087 level = isignab(level, *m7);
00088 *m7 = rshift_rnd_sf(((level * q_params_8x8[j][i].InvScaleComp) << qp_per), 6);
00089 *ACL++ = level;
00090 *ACR++ = run;
00091
00092 run = 0;
00093 }
00094 else
00095 {
00096 run++;
00097 *m7 = 0;
00098 }
00099 }
00100 else
00101 {
00102 run++;
00103 }
00104 }
00105
00106 *ACL = 0;
00107
00108 return nonzero;
00109 }
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123 int quant_8x8cavlc_normal(Macroblock *currMB, int **tblock, struct quant_methods *q_method, int*** cofAC)
00124 {
00125 QuantParameters *p_Quant = currMB->p_Img->p_Quant;
00126 int block_x = q_method->block_x;
00127
00128 int qp = q_method->qp;
00129 LevelQuantParams **q_params_8x8 = q_method->q_params;
00130 const byte (*pos_scan)[2] = q_method->pos_scan;
00131 const byte *c_cost = q_method->c_cost;
00132 int *coeff_cost = q_method->coeff_cost;
00133
00134
00135 int i,j, k, coeff_ctr;
00136
00137 int *m7;
00138 int scaled_coeff;
00139
00140 int level, runs[4] = { 0 };
00141 int nonzero = FALSE;
00142 int qp_per = p_Quant->qp_per_matrix[qp];
00143 int q_bits = Q_BITS_8 + qp_per;
00144 const byte *p_scan = &pos_scan[0][0];
00145 int* ACL[4];
00146 int* ACR[4];
00147
00148 for (k = 0; k < 4; k++)
00149 {
00150 ACL[k] = &cofAC[k][0][0];
00151 ACR[k] = &cofAC[k][1][0];
00152 }
00153
00154
00155 for (coeff_ctr = 0; coeff_ctr < 16; coeff_ctr++)
00156 {
00157 for (k = 0; k < 4; k++)
00158 {
00159 i = *p_scan++;
00160 j = *p_scan++;
00161
00162 m7 = &tblock[j][block_x + i];
00163 if (*m7 != 0)
00164 {
00165 scaled_coeff = iabs (*m7) * q_params_8x8[j][i].ScaleComp;
00166 level = (scaled_coeff + q_params_8x8[j][i].OffsetComp) >> q_bits;
00167
00168 if (level != 0)
00169 {
00170 level = imin(level, CAVLC_LEVEL_LIMIT);
00171
00172 nonzero=TRUE;
00173
00174 *coeff_cost += (level > 1) ? MAX_VALUE : c_cost[runs[k]];
00175
00176 level = isignab(level, *m7);
00177 *m7 = rshift_rnd_sf(((level * q_params_8x8[j][i].InvScaleComp) << qp_per), 6);
00178
00179 *(ACL[k])++ = level;
00180 *(ACR[k])++ = runs[k];
00181
00182 runs[k] = 0;
00183 }
00184 else
00185 {
00186 runs[k]++;
00187 *m7 = 0;
00188 }
00189 }
00190 else
00191 {
00192 runs[k]++;
00193 }
00194 }
00195 }
00196
00197 for(k = 0; k < 4; k++)
00198 *(ACL[k]) = 0;
00199
00200 return nonzero;
00201 }
00202