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

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

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

revision 3, Fri Mar 8 02:46:11 2002 UTC revision 851, Sat Feb 15 15:22:19 2003 UTC
# Line 40  Line 40 
40   *   *
41   *************************************************************************/   *************************************************************************/
42    
43    #include "../global.h"
44  #include "quant_h263.h"  #include "quant_h263.h"
45    
46  /*      mutliply+shift division table  /*      mutliply+shift division table
# Line 48  Line 49 
49  #define SCALEBITS       16  #define SCALEBITS       16
50  #define FIX(X)          ((1L << SCALEBITS) / (X) + 1)  #define FIX(X)          ((1L << SCALEBITS) / (X) + 1)
51    
52  static const uint32_t multipliers[32] =  static const uint32_t multipliers[32] = {
 {  
53          0,                      FIX(2),         FIX(4),         FIX(6),          0,                      FIX(2),         FIX(4),         FIX(6),
54          FIX(8),         FIX(10),        FIX(12),        FIX(14),          FIX(8),         FIX(10),        FIX(12),        FIX(14),
55          FIX(16),        FIX(18),        FIX(20),        FIX(22),          FIX(16),        FIX(18),        FIX(20),        FIX(22),
# Line 62  Line 62 
62    
63    
64    
 #define DIV_DIV(a, b) ((a)>0) ? ((a)+((b)>>1))/(b) : ((a)-((b)>>1))/(b)  
   
65  // function pointers  // function pointers
66  quanth263_intraFuncPtr quant_intra;  quanth263_intraFuncPtr quant_intra;
67  quanth263_intraFuncPtr dequant_intra;  quanth263_intraFuncPtr dequant_intra;
# Line 77  Line 75 
75  */  */
76    
77    
78  void quant_intra_c(int16_t * coeff, const int16_t * data, const uint32_t quant, const uint32_t dcscalar)  void
79    quant_intra_c(int16_t * coeff,
80                              const int16_t * data,
81                              const uint32_t quant,
82                              const uint32_t dcscalar)
83  {  {
84          const uint32_t mult = multipliers[quant];          const uint32_t mult = multipliers[quant];
85          const uint16_t quant_m_2 = quant << 1;          const uint16_t quant_m_2 = quant << 1;
# Line 111  Line 113 
113  /*      quantize inter-block  /*      quantize inter-block
114  */  */
115    
116  uint32_t quant_inter_c(int16_t *coeff, const int16_t *data, const uint32_t quant)  uint32_t
117    quant_inter_c(int16_t * coeff,
118                              const int16_t * data,
119                              const uint32_t quant)
120  {  {
121          const uint32_t mult = multipliers[quant];          const uint32_t mult = multipliers[quant];
122          const uint16_t quant_m_2 = quant << 1;          const uint16_t quant_m_2 = quant << 1;
# Line 151  Line 156 
156  /*      dequantize intra-block & clamp to [-2048,2047]  /*      dequantize intra-block & clamp to [-2048,2047]
157  */  */
158    
159  void dequant_intra_c(int16_t *data, const int16_t *coeff, const uint32_t quant, const uint32_t dcscalar)  void
160    dequant_intra_c(int16_t * data,
161                                    const int16_t * coeff,
162                                    const uint32_t quant,
163                                    const uint32_t dcscalar)
164  {  {
165          const int32_t quant_m_2 = quant << 1;          const int32_t quant_m_2 = quant << 1;
166          const int32_t quant_add = (quant & 1 ? quant : quant - 1);          const int32_t quant_add = (quant & 1 ? quant : quant - 1);
167      uint32_t i;      uint32_t i;
168    
169          data[0] = coeff[0]  * dcscalar;          data[0] = coeff[0]  * dcscalar;
170          if (data[0] < -2048)          if (data[0] < -2048) {
         {  
171                  data[0] = -2048;                  data[0] = -2048;
172          }          } else if (data[0] > 2047) {
         else if (data[0] > 2047)  
         {  
173                  data[0] = 2047;                  data[0] = 2047;
174          }          }
175    
176    
177          for (i = 1; i < 64; i++) {          for (i = 1; i < 64; i++) {
178                  int32_t acLevel = coeff[i];                  int32_t acLevel = coeff[i];
179                  if (acLevel == 0)  
180                  {                  if (acLevel == 0) {
181                          data[i] = 0;                          data[i] = 0;
182                  }                  } else if (acLevel < 0) {
                 else if (acLevel < 0)  
                 {  
183                          acLevel = quant_m_2 * -acLevel + quant_add;                          acLevel = quant_m_2 * -acLevel + quant_add;
184                          data[i] = (acLevel <= 2048 ? -acLevel : -2048);                          data[i] = (acLevel <= 2048 ? -acLevel : -2048);
185                  }                  } else                                  //  if (acLevel > 0) {
                 else  //  if (acLevel > 0) {  
186                  {                  {
187                          acLevel = quant_m_2 * acLevel + quant_add;                          acLevel = quant_m_2 * acLevel + quant_add;
188                          data[i] = (acLevel <= 2047 ? acLevel : 2047);                          data[i] = (acLevel <= 2047 ? acLevel : 2047);
# Line 192  Line 195 
195  /* dequantize inter-block & clamp to [-2048,2047]  /* dequantize inter-block & clamp to [-2048,2047]
196  */  */
197    
198  void dequant_inter_c(int16_t *data, const int16_t *coeff, const uint32_t quant)  void
199    dequant_inter_c(int16_t * data,
200                                    const int16_t * coeff,
201                                    const uint32_t quant)
202  {  {
203          const uint16_t quant_m_2 = quant << 1;          const uint16_t quant_m_2 = quant << 1;
204          const uint16_t quant_add = (quant & 1 ? quant : quant - 1);          const uint16_t quant_add = (quant & 1 ? quant : quant - 1);
# Line 201  Line 207 
207          for (i = 0; i < 64; i++) {          for (i = 0; i < 64; i++) {
208                  int16_t acLevel = coeff[i];                  int16_t acLevel = coeff[i];
209    
210                  if (acLevel == 0)                  if (acLevel == 0) {
                 {  
211                          data[i] = 0;                          data[i] = 0;
212                  }                  } else if (acLevel < 0) {
                 else if (acLevel < 0)  
                 {  
213                          acLevel = acLevel * quant_m_2 - quant_add;                          acLevel = acLevel * quant_m_2 - quant_add;
214                          data[i] = (acLevel >= -2048 ? acLevel : -2048);                          data[i] = (acLevel >= -2048 ? acLevel : -2048);
215                  }                  } else                                  // if (acLevel > 0)
                 else // if (acLevel > 0)  
216                  {                  {
217                          acLevel = acLevel * quant_m_2 + quant_add;                          acLevel = acLevel * quant_m_2 + quant_add;
218                          data[i] = (acLevel <= 2047 ? acLevel : 2047);                          data[i] = (acLevel <= 2047 ? acLevel : 2047);

Legend:
Removed from v.3  
changed lines
  Added in v.851

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