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_around(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 AdaptRndWeight = p_Img->AdaptRndWeight;
00048
00049 int block_x = q_method->block_x;
00050
00051 int qp = q_method->qp;
00052 int* ACLevel = q_method->ACLevel;
00053 int* ACRun = q_method->ACRun;
00054 LevelQuantParams **q_params_8x8 = q_method->q_params;
00055 int **fadjust8x8 = q_method->fadjust;
00056 const byte (*pos_scan)[2] = q_method->pos_scan;
00057 const byte *c_cost = q_method->c_cost;
00058 int *coeff_cost = q_method->coeff_cost;
00059
00060 int i,j, coeff_ctr;
00061
00062 int *m7;
00063 int scaled_coeff;
00064
00065 int level, run = 0;
00066 int nonzero = FALSE;
00067 int qp_per = p_Quant->qp_per_matrix[qp];
00068 int q_bits = Q_BITS_8 + qp_per;
00069 const byte *p_scan = &pos_scan[0][0];
00070 int* ACL = &ACLevel[0];
00071 int* ACR = &ACRun[0];
00072 int* padjust8x8;
00073
00074
00075 for (coeff_ctr = 0; coeff_ctr < 64; ++coeff_ctr)
00076 {
00077 i = *p_scan++;
00078 j = *p_scan++;
00079
00080 padjust8x8 = &fadjust8x8[j][block_x + i];
00081 m7 = &tblock[j][block_x + i];
00082 if (*m7 != 0)
00083 {
00084 scaled_coeff = iabs (*m7) * q_params_8x8[j][i].ScaleComp;
00085 level = (scaled_coeff + q_params_8x8[j][i].OffsetComp) >> q_bits;
00086
00087 if (level != 0)
00088 {
00089 *padjust8x8 = rshift_rnd_sf((AdaptRndWeight * (scaled_coeff - (level << q_bits))), (q_bits + 1));
00090
00091 nonzero = TRUE;
00092
00093 *coeff_cost += (level > 1) ? MAX_VALUE : c_cost[run];
00094
00095 level = isignab(level, *m7);
00096 *m7 = rshift_rnd_sf(((level * q_params_8x8[j][i].InvScaleComp) << qp_per), 6);
00097 *ACL++ = level;
00098 *ACR++ = run;
00099
00100 run = 0;
00101 }
00102 else
00103 {
00104 *padjust8x8 = 0;
00105 ++run;
00106 *m7 = 0;
00107 }
00108 }
00109 else
00110 {
00111 *padjust8x8 = 0;
00112 ++run;
00113 }
00114 }
00115
00116 *ACL = 0;
00117
00118 return nonzero;
00119 }
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133 int quant_8x8cavlc_around(Macroblock *currMB, int **tblock, struct quant_methods *q_method, int*** cofAC)
00134 {
00135 ImageParameters *p_Img = currMB->p_Img;
00136 QuantParameters *p_Quant = p_Img->p_Quant;
00137 int AdaptRndWeight = p_Img->AdaptRndWeight;
00138 int block_x = q_method->block_x;
00139
00140 int qp = q_method->qp;
00141 LevelQuantParams **q_params_8x8 = q_method->q_params;
00142 int **fadjust8x8 = q_method->fadjust;
00143 const byte (*pos_scan)[2] = q_method->pos_scan;
00144 const byte *c_cost = q_method->c_cost;
00145 int *coeff_cost = q_method->coeff_cost;
00146
00147 int i,j, k, coeff_ctr;
00148
00149 int *m7;
00150 int scaled_coeff;
00151
00152 int level, runs[4] = { 0 };
00153 int nonzero = FALSE;
00154 int qp_per = p_Quant->qp_per_matrix[qp];
00155 int q_bits = Q_BITS_8 + qp_per;
00156 const byte *p_scan = &pos_scan[0][0];
00157 int* ACL[4];
00158 int* ACR[4];
00159 int* padjust8x8;
00160
00161 for (k = 0; k < 4; ++k)
00162 {
00163 ACL[k] = &cofAC[k][0][0];
00164 ACR[k] = &cofAC[k][1][0];
00165 }
00166
00167
00168 for (coeff_ctr = 0; coeff_ctr < 16; ++coeff_ctr)
00169 {
00170 for (k = 0; k < 4; ++k)
00171 {
00172 i = *p_scan++;
00173 j = *p_scan++;
00174
00175 padjust8x8 = &fadjust8x8[j][block_x + i];
00176 m7 = &tblock[j][block_x + i];
00177 if (*m7 != 0)
00178 {
00179 scaled_coeff = iabs (*m7) * q_params_8x8[j][i].ScaleComp;
00180 level = (scaled_coeff + q_params_8x8[j][i].OffsetComp) >> q_bits;
00181
00182 if (level != 0)
00183 {
00184 level = imin(level, CAVLC_LEVEL_LIMIT);
00185
00186 *padjust8x8 = rshift_rnd_sf((AdaptRndWeight * (scaled_coeff - (level << q_bits))), (q_bits + 1));
00187
00188 nonzero=TRUE;
00189
00190 *coeff_cost += (level > 1) ? MAX_VALUE : c_cost[runs[k]];
00191
00192 level = isignab(level, *m7);
00193 *m7 = rshift_rnd_sf(((level * q_params_8x8[j][i].InvScaleComp) << qp_per), 6);
00194
00195 *(ACL[k])++ = level;
00196 *(ACR[k])++ = runs[k];
00197
00198 runs[k] = 0;
00199 }
00200 else
00201 {
00202 *padjust8x8 = 0;
00203 *m7 = 0;
00204 ++runs[k];
00205 }
00206 }
00207 else
00208 {
00209 *padjust8x8 = 0;
00210 ++runs[k];
00211 }
00212 }
00213 }
00214
00215 for(k = 0; k < 4; ++k)
00216 *(ACL[k]) = 0;
00217
00218 return nonzero;
00219 }
00220