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