[cvs] / xvidcore / src / utils / mbtransquant.c Repository:
ViewVC logotype

Diff of /xvidcore/src/utils/mbtransquant.c

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

revision 1.21.2.20, Mon Nov 24 22:06:19 2003 UTC revision 1.23.2.3, Sun Dec 19 12:04:27 2004 UTC
# Line 138  Line 138 
138    
139          /* Quantize the block */          /* Quantize the block */
140          start_timer();          start_timer();
141          quant[mpeg](&data[0 * 64], &qcoeff[0 * 64], pMB->quant, scaler_lum);          quant[mpeg](&data[0 * 64], &qcoeff[0 * 64], pMB->quant, scaler_lum, pParam->mpeg_quant_matrices);
142          quant[mpeg](&data[1 * 64], &qcoeff[1 * 64], pMB->quant, scaler_lum);          quant[mpeg](&data[1 * 64], &qcoeff[1 * 64], pMB->quant, scaler_lum, pParam->mpeg_quant_matrices);
143          quant[mpeg](&data[2 * 64], &qcoeff[2 * 64], pMB->quant, scaler_lum);          quant[mpeg](&data[2 * 64], &qcoeff[2 * 64], pMB->quant, scaler_lum, pParam->mpeg_quant_matrices);
144          quant[mpeg](&data[3 * 64], &qcoeff[3 * 64], pMB->quant, scaler_lum);          quant[mpeg](&data[3 * 64], &qcoeff[3 * 64], pMB->quant, scaler_lum, pParam->mpeg_quant_matrices);
145          quant[mpeg](&data[4 * 64], &qcoeff[4 * 64], pMB->quant, scaler_chr);          quant[mpeg](&data[4 * 64], &qcoeff[4 * 64], pMB->quant, scaler_chr, pParam->mpeg_quant_matrices);
146          quant[mpeg](&data[5 * 64], &qcoeff[5 * 64], pMB->quant, scaler_chr);          quant[mpeg](&data[5 * 64], &qcoeff[5 * 64], pMB->quant, scaler_chr, pParam->mpeg_quant_matrices);
147          stop_quant_timer();          stop_quant_timer();
148  }  }
149    
# Line 168  Line 168 
168          scaler_chr = get_dc_scaler(iQuant, 0);          scaler_chr = get_dc_scaler(iQuant, 0);
169    
170          start_timer();          start_timer();
171          dequant[mpeg](&qcoeff[0 * 64], &data[0 * 64], iQuant, scaler_lum);          dequant[mpeg](&qcoeff[0 * 64], &data[0 * 64], iQuant, scaler_lum, pParam->mpeg_quant_matrices);
172          dequant[mpeg](&qcoeff[1 * 64], &data[1 * 64], iQuant, scaler_lum);          dequant[mpeg](&qcoeff[1 * 64], &data[1 * 64], iQuant, scaler_lum, pParam->mpeg_quant_matrices);
173          dequant[mpeg](&qcoeff[2 * 64], &data[2 * 64], iQuant, scaler_lum);          dequant[mpeg](&qcoeff[2 * 64], &data[2 * 64], iQuant, scaler_lum, pParam->mpeg_quant_matrices);
174          dequant[mpeg](&qcoeff[3 * 64], &data[3 * 64], iQuant, scaler_lum);          dequant[mpeg](&qcoeff[3 * 64], &data[3 * 64], iQuant, scaler_lum, pParam->mpeg_quant_matrices);
175          dequant[mpeg](&qcoeff[4 * 64], &data[4 * 64], iQuant, scaler_chr);          dequant[mpeg](&qcoeff[4 * 64], &data[4 * 64], iQuant, scaler_chr, pParam->mpeg_quant_matrices);
176          dequant[mpeg](&qcoeff[5 * 64], &data[5 * 64], iQuant, scaler_chr);          dequant[mpeg](&qcoeff[5 * 64], &data[5 * 64], iQuant, scaler_chr, pParam->mpeg_quant_matrices);
177          stop_iquant_timer();          stop_iquant_timer();
178  }  }
179    
# Line 183  Line 183 
183                                             int Q,                                             int Q,
184                                             const uint16_t * const Zigzag,                                             const uint16_t * const Zigzag,
185                                             const uint16_t * const QuantMatrix,                                             const uint16_t * const QuantMatrix,
186                                             int Non_Zero);                                             int Non_Zero,
187                                               int Sum);
188    
189  /* Quantize all blocks -- Inter mode */  /* Quantize all blocks -- Inter mode */
190  static __inline uint8_t  static __inline uint8_t
# Line 214  Line 215 
215                  /* Quantize the block */                  /* Quantize the block */
216                  start_timer();                  start_timer();
217    
218                  sum = quant[mpeg](&qcoeff[i*64], &data[i*64], pMB->quant);                  sum = quant[mpeg](&qcoeff[i*64], &data[i*64], pMB->quant, pParam->mpeg_quant_matrices);
219    
220                  if(sum && (frame->vop_flags & XVID_VOP_TRELLISQUANT)) {                  if(sum && (pMB->quant > 2) && (frame->vop_flags & XVID_VOP_TRELLISQUANT)) {
221                            const uint16_t *matrix;
222                          const static uint16_t h263matrix[] =                          const static uint16_t h263matrix[] =
223                                  {                                  {
224                                          16, 16, 16, 16, 16, 16, 16, 16,                                          16, 16, 16, 16, 16, 16, 16, 16,
# Line 228  Line 230 
230                                          16, 16, 16, 16, 16, 16, 16, 16,                                          16, 16, 16, 16, 16, 16, 16, 16,
231                                          16, 16, 16, 16, 16, 16, 16, 16                                          16, 16, 16, 16, 16, 16, 16, 16
232                                  };                                  };
233    
234                            matrix = (mpeg)?get_inter_matrix(pParam->mpeg_quant_matrices):h263matrix;
235                          sum = dct_quantize_trellis_c(&qcoeff[i*64], &data[i*64],                          sum = dct_quantize_trellis_c(&qcoeff[i*64], &data[i*64],
236                                                                                   pMB->quant, &scan_tables[0][0],                                                                                   pMB->quant, &scan_tables[0][0],
237                                                                                   (mpeg)?(uint16_t*)get_inter_matrix():h263matrix,                                                                                   matrix,
238                                                                                   63);                                                                                   63,
239                                                                                     sum);
240                  }                  }
241                  stop_quant_timer();                  stop_quant_timer();
242    
# Line 281  Line 286 
286          mpeg = !!(pParam->vol_flags & XVID_VOL_MPEGQUANT);          mpeg = !!(pParam->vol_flags & XVID_VOL_MPEGQUANT);
287    
288          start_timer();          start_timer();
289          if(cbp & (1 << (5 - 0))) dequant[mpeg](&data[0 * 64], &qcoeff[0 * 64], iQuant);          if(cbp & (1 << (5 - 0))) dequant[mpeg](&data[0 * 64], &qcoeff[0 * 64], iQuant, pParam->mpeg_quant_matrices);
290          if(cbp & (1 << (5 - 1))) dequant[mpeg](&data[1 * 64], &qcoeff[1 * 64], iQuant);          if(cbp & (1 << (5 - 1))) dequant[mpeg](&data[1 * 64], &qcoeff[1 * 64], iQuant, pParam->mpeg_quant_matrices);
291          if(cbp & (1 << (5 - 2))) dequant[mpeg](&data[2 * 64], &qcoeff[2 * 64], iQuant);          if(cbp & (1 << (5 - 2))) dequant[mpeg](&data[2 * 64], &qcoeff[2 * 64], iQuant, pParam->mpeg_quant_matrices);
292          if(cbp & (1 << (5 - 3))) dequant[mpeg](&data[3 * 64], &qcoeff[3 * 64], iQuant);          if(cbp & (1 << (5 - 3))) dequant[mpeg](&data[3 * 64], &qcoeff[3 * 64], iQuant, pParam->mpeg_quant_matrices);
293          if(cbp & (1 << (5 - 4))) dequant[mpeg](&data[4 * 64], &qcoeff[4 * 64], iQuant);          if(cbp & (1 << (5 - 4))) dequant[mpeg](&data[4 * 64], &qcoeff[4 * 64], iQuant, pParam->mpeg_quant_matrices);
294          if(cbp & (1 << (5 - 5))) dequant[mpeg](&data[5 * 64], &qcoeff[5 * 64], iQuant);          if(cbp & (1 << (5 - 5))) dequant[mpeg](&data[5 * 64], &qcoeff[5 * 64], iQuant, pParam->mpeg_quant_matrices);
295          stop_iquant_timer();          stop_iquant_timer();
296  }  }
297    
# Line 369  Line 374 
374    
375          transfer_operation_16to8_t *transfer_op = NULL;          transfer_operation_16to8_t *transfer_op = NULL;
376    
         if (pMB->field_dct) {  
                 next_block = stride;  
                 stride *= 2;  
         }  
   
377          /* Makes this vars booleans */          /* Makes this vars booleans */
378          vop_reduced = !!(frame->vop_flags & XVID_VOP_REDUCED);          vop_reduced = !!(frame->vop_flags & XVID_VOP_REDUCED);
379    
# Line 382  Line 382 
382          pU_Cur = pCurrent->u + (y_pos << (3+vop_reduced)) * stride2 + (x_pos << (3+vop_reduced));          pU_Cur = pCurrent->u + (y_pos << (3+vop_reduced)) * stride2 + (x_pos << (3+vop_reduced));
383          pV_Cur = pCurrent->v + (y_pos << (3+vop_reduced)) * stride2 + (x_pos << (3+vop_reduced));          pV_Cur = pCurrent->v + (y_pos << (3+vop_reduced)) * stride2 + (x_pos << (3+vop_reduced));
384    
385            if (pMB->field_dct) {
386                    next_block = stride;
387                    stride *= 2;
388            }
389    
390          /* Block size */          /* Block size */
391          cst = 8<<vop_reduced;          cst = 8<<vop_reduced;
392    
# Line 778  Line 783 
783          return -1;          return -1;
784  }  }
785    
 static int __inline  
 Compute_Sum(const int16_t *C, int last)  
 {  
         int sum = 0;  
   
         while(last--)  
                 sum += abs(C[last]);  
   
         return(sum);  
 }  
   
786  /* this routine has been strippen of all debug code */  /* this routine has been strippen of all debug code */
787  static int  static int
788  dct_quantize_trellis_c(int16_t *const Out,  dct_quantize_trellis_c(int16_t *const Out,
# Line 796  Line 790 
790                                             int Q,                                             int Q,
791                                             const uint16_t * const Zigzag,                                             const uint16_t * const Zigzag,
792                                             const uint16_t * const QuantMatrix,                                             const uint16_t * const QuantMatrix,
793                                             int Non_Zero)                                             int Non_Zero,
794                                               int Sum)
795  {  {
796    
797          /* Note: We should search last non-zero coeffs on *real* DCT input coeffs          /* Note: We should search last non-zero coeffs on *real* DCT input coeffs
# Line 819  Line 814 
814          int Last_Node = -1;          int Last_Node = -1;
815          uint32_t Last_Cost = 0;          uint32_t Last_Cost = 0;
816    
817          int i, j, sum;          int i, j;
818    
819          /* source (w/ CBP penalty) */          /* source (w/ CBP penalty) */
820          Run_Costs[-1] = 2<<TL_SHIFT;          Run_Costs[-1] = 2<<TL_SHIFT;
# Line 999  Line 994 
994                  }                  }
995          }          }
996    
997          /* It seems trellis doesn't give good results... just compute the Out sum          /* It seems trellis doesn't give good results... just leave the block untouched
998           * and quit */           * and return the original sum value */
999          if (Last_Node<0)          if (Last_Node<0)
1000                  return Compute_Sum(Out, Non_Zero);                  return Sum;
1001    
1002          /* reconstruct optimal sequence backward with surviving paths */          /* reconstruct optimal sequence backward with surviving paths */
1003          memset(Out, 0x00, 64*sizeof(*Out));          memset(Out, 0x00, 64*sizeof(*Out));
1004          Out[Zigzag[Last_Node]] = Last.Level;          Out[Zigzag[Last_Node]] = Last.Level;
1005          i = Last_Node - Last.Run;          i = Last_Node - Last.Run;
1006          sum = 0;          Sum = abs(Last.Level);
1007          while(i>=0) {          while(i>=0) {
1008                  Out[Zigzag[i]] = Nodes[i].Level;                  Out[Zigzag[i]] = Nodes[i].Level;
1009                  sum += abs(Nodes[i].Level);                  Sum += abs(Nodes[i].Level);
1010                  i -= Nodes[i].Run;                  i -= Nodes[i].Run;
1011          }          }
1012    
1013          return sum;          return Sum;
1014  }  }
1015    
1016  /* original version including heavy debugging info */  /* original version including heavy debugging info */

Legend:
Removed from v.1.21.2.20  
changed lines
  Added in v.1.23.2.3

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