[svn] / trunk / xvidcore / src / quant / quant_mpeg4.c Repository:
ViewVC logotype

Diff of /trunk/xvidcore/src/quant/quant_mpeg4.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 194, Sun Jun 9 23:30:50 2002 UTC revision 195, Wed Jun 12 20:38:41 2002 UTC
# Line 63  Line 63 
63  #define SCALEBITS    17  #define SCALEBITS    17
64  #define FIX(X)        ((1UL << SCALEBITS) / (X) + 1)  #define FIX(X)        ((1UL << SCALEBITS) / (X) + 1)
65    
66  static const uint32_t multipliers[32] =  static const uint32_t multipliers[32] = {
 {  
67      0,          FIX(2),     FIX(4),     FIX(6),      0,          FIX(2),     FIX(4),     FIX(6),
68      FIX(8),     FIX(10),    FIX(12),    FIX(14),      FIX(8),     FIX(10),    FIX(12),    FIX(14),
69      FIX(16),    FIX(18),    FIX(20),    FIX(22),      FIX(16),    FIX(18),    FIX(20),    FIX(22),
# Line 83  Line 82 
82      // coeff[i] = (level + quantd) / quant2;      // coeff[i] = (level + quantd) / quant2;
83  */  */
84    
85  void quant4_intra_c(int16_t * coeff, const int16_t * data, const uint32_t quant, const uint32_t dcscalar)  void
86    quant4_intra_c(int16_t * coeff,
87                               const int16_t * data,
88                               const uint32_t quant,
89                               const uint32_t dcscalar)
90  {  {
91      const uint32_t quantd = ((VM18P*quant) + (VM18Q/2)) / VM18Q;      const uint32_t quantd = ((VM18P*quant) + (VM18Q/2)) / VM18Q;
92      const uint32_t mult = multipliers[quant];      const uint32_t mult = multipliers[quant];
# Line 94  Line 97 
97    
98      coeff[0] = DIV_DIV(data[0], (int32_t)dcscalar);      coeff[0] = DIV_DIV(data[0], (int32_t)dcscalar);
99    
100      for (i = 1; i < 64; i++)          for (i = 1; i < 64; i++) {
101      {                  if (data[i] < 0) {
         if (data[i] < 0)  
         {  
102              uint32_t level = -data[i];              uint32_t level = -data[i];
103    
104              level = ((level<<4) + (intra_matrix[i]>>1)) / intra_matrix[i];              level = ((level<<4) + (intra_matrix[i]>>1)) / intra_matrix[i];
105              level = ((level + quantd) * mult) >> 17;              level = ((level + quantd) * mult) >> 17;
106              coeff[i] = -(int16_t)level;              coeff[i] = -(int16_t)level;
107          }                  } else if (data[i] > 0) {
         else if (data[i] > 0)  
         {  
108              uint32_t level = data[i];              uint32_t level = data[i];
109    
110              level = ((level<<4) + (intra_matrix[i]>>1)) / intra_matrix[i];              level = ((level<<4) + (intra_matrix[i]>>1)) / intra_matrix[i];
111              level = ((level + quantd) * mult) >> 17;              level = ((level + quantd) * mult) >> 17;
112              coeff[i] = level;              coeff[i] = level;
113          }                  } else {
         else  
         {  
114              coeff[i] = 0;              coeff[i] = 0;
115          }          }
116      }      }
# Line 123  Line 122 
122      // data[i] = (coeff[i] * default_intra_matrix[i] * quant2) >> 4;      // data[i] = (coeff[i] * default_intra_matrix[i] * quant2) >> 4;
123  */  */
124    
125  void dequant4_intra_c(int16_t *data, const int16_t *coeff, const uint32_t quant, const uint32_t dcscalar)  void
126    dequant4_intra_c(int16_t * data,
127                                     const int16_t * coeff,
128                                     const uint32_t quant,
129                                     const uint32_t dcscalar)
130  {  {
131      uint32_t i;      uint32_t i;
132          int16_t *intra_matrix;          int16_t *intra_matrix;
# Line 131  Line 134 
134          intra_matrix = get_intra_matrix();          intra_matrix = get_intra_matrix();
135    
136      data[0] = coeff[0]  * dcscalar;      data[0] = coeff[0]  * dcscalar;
137      if (data[0] < -2048)          if (data[0] < -2048) {
     {  
138          data[0] = -2048;          data[0] = -2048;
139      }          } else if (data[0] > 2047) {
     else if (data[0] > 2047)  
     {  
140          data[0] = 2047;          data[0] = 2047;
141      }      }
142    
143      for (i = 1; i < 64; i++)          for (i = 1; i < 64; i++) {
144      {                  if (coeff[i] == 0) {
         if (coeff[i] == 0)  
         {  
145              data[i] = 0;              data[i] = 0;
146          }                  } else if (coeff[i] < 0) {
         else if (coeff[i] < 0)  
         {  
147              uint32_t level = -coeff[i];              uint32_t level = -coeff[i];
148    
149              level = (level * intra_matrix[i] * quant) >> 3;              level = (level * intra_matrix[i] * quant) >> 3;
150              data[i] = (level <= 2048 ? -(int16_t)level : -2048);              data[i] = (level <= 2048 ? -(int16_t)level : -2048);
151          }                  } else                                  // if (coeff[i] > 0)
         else // if (coeff[i] > 0)  
152          {          {
153              uint32_t level = coeff[i];              uint32_t level = coeff[i];
154    
155              level = (level * intra_matrix[i] * quant) >> 3;              level = (level * intra_matrix[i] * quant) >> 3;
156              data[i] = (level <= 2047 ? level : 2047);              data[i] = (level <= 2047 ? level : 2047);
157          }          }
# Line 170  Line 167 
167      // sum += abs(level);      // sum += abs(level);
168  */  */
169    
170  uint32_t quant4_inter_c(int16_t * coeff, const int16_t * data, const uint32_t quant)  uint32_t
171    quant4_inter_c(int16_t * coeff,
172                               const int16_t * data,
173                               const uint32_t quant)
174  {  {
175      const uint32_t mult = multipliers[quant];      const uint32_t mult = multipliers[quant];
176      uint32_t sum = 0;      uint32_t sum = 0;
# Line 179  Line 179 
179    
180          inter_matrix = get_inter_matrix();          inter_matrix = get_inter_matrix();
181    
182      for (i = 0; i < 64; i++)          for (i = 0; i < 64; i++) {
183      {                  if (data[i] < 0) {
         if (data[i] < 0)  
         {  
184              uint32_t level = -data[i];              uint32_t level = -data[i];
185    
186              level = ((level<<4) + (inter_matrix[i]>>1)) / inter_matrix[i];              level = ((level<<4) + (inter_matrix[i]>>1)) / inter_matrix[i];
187              level = (level * mult) >> 17;              level = (level * mult) >> 17;
188              sum += level;              sum += level;
189              coeff[i] = -(int16_t)level;              coeff[i] = -(int16_t)level;
190          }                  } else if (data[i] > 0) {
         else if (data[i] > 0)  
         {  
191              uint32_t level = data[i];              uint32_t level = data[i];
192    
193              level = ((level<<4) + (inter_matrix[i]>>1)) / inter_matrix[i];              level = ((level<<4) + (inter_matrix[i]>>1)) / inter_matrix[i];
194              level = (level * mult) >> 17;              level = (level * mult) >> 17;
195              sum += level;              sum += level;
196              coeff[i] = level;              coeff[i] = level;
197          }                  } else {
         else  
         {  
198              coeff[i] = 0;              coeff[i] = 0;
199          }          }
200      }      }
# Line 211  Line 207 
207    data = ((2 * coeff + SIGN(coeff)) * inter_matrix[i] * quant) / 16    data = ((2 * coeff + SIGN(coeff)) * inter_matrix[i] * quant) / 16
208  */  */
209    
210  void dequant4_inter_c(int16_t *data, const int16_t *coeff, const uint32_t quant)  void
211    dequant4_inter_c(int16_t * data,
212                                     const int16_t * coeff,
213                                     const uint32_t quant)
214  {  {
215      uint32_t sum = 0;      uint32_t sum = 0;
216      uint32_t i;      uint32_t i;
# Line 219  Line 218 
218    
219          inter_matrix = get_inter_matrix();          inter_matrix = get_inter_matrix();
220    
221      for (i = 0; i < 64; i++)          for (i = 0; i < 64; i++) {
222      {                  if (coeff[i] == 0) {
         if (coeff[i] == 0)  
         {  
223              data[i] = 0;              data[i] = 0;
224          }                  } else if (coeff[i] < 0) {
         else if (coeff[i] < 0)  
         {  
225              int32_t level = -coeff[i];              int32_t level = -coeff[i];
226    
227              level = ((2 * level + 1) * inter_matrix[i] * quant) >> 4;              level = ((2 * level + 1) * inter_matrix[i] * quant) >> 4;
228              data[i] = (level <= 2048 ? -level : -2048);              data[i] = (level <= 2048 ? -level : -2048);
229          }                  } else                                  // if (coeff[i] > 0)
         else // if (coeff[i] > 0)  
230          {          {
231              uint32_t level = coeff[i];              uint32_t level = coeff[i];
232    
233              level = ((2 * level + 1) * inter_matrix[i] * quant) >> 4;              level = ((2 * level + 1) * inter_matrix[i] * quant) >> 4;
234              data[i] = (level <= 2047 ? level : 2047);              data[i] = (level <= 2047 ? level : 2047);
235          }          }
# Line 243  Line 239 
239    
240      // mismatch control      // mismatch control
241    
242      if ((sum & 1) == 0)          if ((sum & 1) == 0) {
     {  
243          data[63] ^= 1;          data[63] ^= 1;
244      }      }
245  }  }

Legend:
Removed from v.194  
changed lines
  Added in v.195

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4