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
00040
00041
00042
00043
00044 int quant_4x4_around(int **tblock, int block_y, int block_x, int qp,
00045 int* ACLevel, int* ACRun,
00046 int **fadjust4x4, int **levelscale, int **invlevelscale, int **leveloffset,
00047 int *coeff_cost, const byte (*pos_scan)[2], const byte *c_cost, int is_cavlc)
00048 {
00049 static int i,j, coeff_ctr;
00050
00051 static int *m7;
00052 static int scaled_coeff;
00053
00054 int level, run = 0;
00055 int nonzero = FALSE;
00056 int qp_per = qp_per_matrix[qp];
00057 int q_bits = Q_BITS + qp_per;
00058 const byte *p_scan = &pos_scan[0][0];
00059 int* ACL = &ACLevel[0];
00060 int* ACR = &ACRun[0];
00061 int* padjust4x4;
00062
00063
00064 for (coeff_ctr = 0; coeff_ctr < 16; coeff_ctr++)
00065 {
00066 i = *p_scan++;
00067 j = *p_scan++;
00068
00069 padjust4x4 = &fadjust4x4[j][block_x + i];
00070 m7 = &tblock[j][block_x + i];
00071
00072 if (*m7 != 0)
00073 {
00074 scaled_coeff = iabs (*m7) * levelscale[j][i];
00075 level = (scaled_coeff + leveloffset[j][i]) >> q_bits;
00076
00077 if (level != 0)
00078 {
00079 if (is_cavlc)
00080 level = imin(level, CAVLC_LEVEL_LIMIT);
00081
00082 *padjust4x4 = rshift_rnd_sf((AdaptRndWeight * (scaled_coeff - (level << q_bits))), q_bits + 1);
00083
00084 *coeff_cost += (level > 1) ? MAX_VALUE : c_cost[run];
00085
00086 level = isignab(level, *m7);
00087 *m7 = rshift_rnd_sf(((level * invlevelscale[j][i]) << qp_per), 4);
00088
00089
00090
00091 *ACL++ = level;
00092 *ACR++ = run;
00093
00094 run = 0;
00095 nonzero = TRUE;
00096 }
00097 else
00098 {
00099 *padjust4x4 = 0;
00100 *m7 = 0;
00101 run++;
00102 }
00103 }
00104 else
00105 {
00106 *padjust4x4 = 0;
00107 run++;
00108 }
00109 }
00110
00111 *ACL = 0;
00112
00113 return nonzero;
00114 }
00115
00116 int quant_ac4x4_around(int **tblock, int block_y, int block_x, int qp,
00117 int* ACLevel, int* ACRun,
00118 int **fadjust4x4, int **levelscale, int **invlevelscale, int **leveloffset,
00119 int *coeff_cost, const byte (*pos_scan)[2], const byte *c_cost, int type, int is_cavlc)
00120 {
00121 static int i,j, coeff_ctr;
00122
00123 static int *m7;
00124 static int scaled_coeff;
00125
00126 int level, run = 0;
00127 int nonzero = FALSE;
00128 int qp_per = qp_per_matrix[qp];
00129 int q_bits = Q_BITS + qp_per;
00130 const byte *p_scan = &pos_scan[1][0];
00131 int* ACL = &ACLevel[0];
00132 int* ACR = &ACRun[0];
00133 int* padjust4x4;
00134
00135
00136 for (coeff_ctr = 1; coeff_ctr < 16; coeff_ctr++)
00137 {
00138 i = *p_scan++;
00139 j = *p_scan++;
00140
00141 padjust4x4 = &fadjust4x4[j][block_x + i];
00142 m7 = &tblock[j][block_x + i];
00143 if (*m7 != 0)
00144 {
00145 scaled_coeff = iabs (*m7) * levelscale[j][i];
00146 level = (scaled_coeff + leveloffset[j][i]) >> q_bits;
00147
00148 if (level != 0)
00149 {
00150 if (is_cavlc)
00151 level = imin(level, CAVLC_LEVEL_LIMIT);
00152
00153 *padjust4x4 = rshift_rnd_sf((AdaptRndWeight * (scaled_coeff - (level << q_bits))), (q_bits + 1));
00154
00155 *coeff_cost += (level > 1) ? MAX_VALUE : c_cost[run];
00156
00157 level = isignab(level, *m7);
00158 *m7 = rshift_rnd_sf(((level * invlevelscale[j][i]) << qp_per), 4);
00159
00160
00161
00162 *ACL++ = level;
00163 *ACR++ = run;
00164
00165 run = 0;
00166 nonzero = TRUE;
00167 }
00168 else
00169 {
00170 *padjust4x4 = 0;
00171 *m7 = 0;
00172 run++;
00173 }
00174 }
00175 else
00176 {
00177 *padjust4x4 = 0;
00178 run++;
00179 }
00180 }
00181
00182 *ACL = 0;
00183
00184 return nonzero;
00185 }
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198 int quant_dc4x4_around(int **tblock, int qp, int* DCLevel, int* DCRun,
00199 int levelscale, int invlevelscale, int leveloffset, const byte (*pos_scan)[2], int is_calvc)
00200 {
00201 static int i,j, coeff_ctr;
00202
00203 static int *m7;
00204 static int scaled_coeff;
00205
00206 int level, run = 0;
00207 int nonzero = FALSE;
00208 int qp_per = qp_per_matrix[qp];
00209 int q_bits = Q_BITS + qp_per + 1;
00210 const byte *p_scan = &pos_scan[0][0];
00211 int* DCL = &DCLevel[0];
00212 int* DCR = &DCRun[0];
00213
00214
00215 for (coeff_ctr = 0; coeff_ctr < 16; coeff_ctr++)
00216 {
00217 i = *p_scan++;
00218 j = *p_scan++;
00219
00220 m7 = &tblock[j][i];
00221
00222 if (*m7 != 0)
00223 {
00224 scaled_coeff = iabs (*m7) * levelscale;
00225 level = (scaled_coeff + (leveloffset << 1) ) >> q_bits;
00226
00227 if (level != 0)
00228 {
00229 if (is_calvc)
00230 level = imin(level, CAVLC_LEVEL_LIMIT);
00231
00232 level = isignab(level, *m7);
00233 *m7 = level;
00234 *DCL++ = level;
00235 *DCR++ = run;
00236
00237 run = 0;
00238 nonzero = TRUE;
00239 }
00240 else
00241 {
00242 run++;
00243 *m7 = 0;
00244 }
00245 }
00246 else
00247 {
00248 run++;
00249 }
00250 }
00251
00252 *DCL = 0;
00253
00254 return nonzero;
00255 }