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

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

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

revision 1713, Mon Jul 10 08:09:59 2006 UTC revision 1909, Sun Nov 28 15:19:07 2010 UTC
# Line 1  Line 1 
1  /*****************************************************************************  /*****************************************************************************
2   *   *
3   *  XVID MPEG-4 VIDEO CODEC   *  XVID MPEG-4 VIDEO CODEC
4   *  - MB Transfert/Quantization functions -   *  - MB Transfer/Quantization functions -
5   *   *
6   *  Copyright(C) 2001-2003  Peter Ross <pross@xvid.org>   *  Copyright(C) 2001-2010  Peter Ross <pross@xvid.org>
7   *               2001-2003  Michael Militzer <isibaar@xvid.org>   *               2001-2010  Michael Militzer <michael@xvid.org>
8   *               2003       Edouard Gomez <ed.gomez@free.fr>   *               2003       Edouard Gomez <ed.gomez@free.fr>
9   *   *
10   *  This program is free software ; you can redistribute it and/or modify   *  This program is free software ; you can redistribute it and/or modify
# Line 21  Line 21 
21   *  along with this program ; if not, write to the Free Software   *  along with this program ; if not, write to the Free Software
22   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
23   *   *
24   * $Id: mbtransquant.c,v 1.32 2006-07-10 08:09:59 syskin Exp $   * $Id: mbtransquant.c,v 1.33 2010-11-28 15:18:21 Isibaar Exp $
25   *   *
26   ****************************************************************************/   ****************************************************************************/
27    
# Line 40  Line 40 
40  #include "../dct/fdct.h"  #include "../dct/fdct.h"
41  #include "../dct/idct.h"  #include "../dct/idct.h"
42  #include "../quant/quant.h"  #include "../quant/quant.h"
43    #include "../motion/sad.h"
44  #include "../encoder.h"  #include "../encoder.h"
45    
46  #include  "../quant/quant_matrix.h"  #include  "../quant/quant_matrix.h"
# Line 187  Line 188 
188                                             const uint16_t * const QuantMatrix,                                             const uint16_t * const QuantMatrix,
189                                             int Non_Zero,                                             int Non_Zero,
190                                             int Sum,                                             int Sum,
191                                             int Lambda_Mod);                                             int Lambda_Mod,
192                                               const uint32_t rel_var8,
193                                               const int Metric);
194    
195  /* Quantize all blocks -- Inter mode */  /* Quantize all blocks -- Inter mode */
196  static __inline uint8_t  static __inline uint8_t
# Line 240  Line 243 
243                                                                                   matrix,                                                                                   matrix,
244                                                                                   63,                                                                                   63,
245                                                                                   sum,                                                                                   sum,
246                                                                                   pMB->lambda[i]);                                                                                   pMB->lambda[i],
247                                                                                     pMB->rel_var8[i],
248                                                                                     !!(frame->vop_flags & XVID_VOP_RD_PSNRHVSM));
249                  }                  }
250                  stop_quant_timer();                  stop_quant_timer();
251    
# Line 763  Line 768 
768    
769  #define TRELLIS_MIN_EFFORT      3  #define TRELLIS_MIN_EFFORT      3
770    
771    static __inline uint32_t calc_mseh(int16_t dQ, uint16_t mask,
772                                       const int index, const int Lambda)
773    {
774            uint32_t t = (mask * Inv_iMask_Coeff[index] + 32) >> 7;
775            uint16_t u = abs(dQ) << 4;
776            uint16_t thresh = (t < 65536) ? t : 65535;
777    
778            if (u <= thresh)
779                    u = 0; /* The error is not perceivable */
780            else
781                    u -= thresh;
782    
783            u = ((u + iCSF_Round[index]) * iCSF_Coeff[index]) >> 16;
784    
785            return (((Lambda*u*u)>>4) + 4*Lambda*dQ*dQ) / 5;
786    }
787    
788  /* this routine has been strippen of all debug code */  /* this routine has been strippen of all debug code */
789  static int  static int
790  dct_quantize_trellis_c(int16_t *const Out,  dct_quantize_trellis_c(int16_t *const Out,
# Line 772  Line 794 
794                                             const uint16_t * const QuantMatrix,                                             const uint16_t * const QuantMatrix,
795                                             int Non_Zero,                                             int Non_Zero,
796                                             int Sum,                                             int Sum,
797                                             int Lambda_Mod)                                             int Lambda_Mod,
798                                               const uint32_t rel_var8,
799                                               const int Metric)
800  {  {
801    
802          /* 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 797  Line 821 
821    
822          int i, j;          int i, j;
823    
824            uint32_t mask = (Metric) ? ((isqrt(2*coeff8_energy(In)*rel_var8) + 48) >> 6) : 0;
825    
826          /* source (w/ CBP penalty) */          /* source (w/ CBP penalty) */
827          Run_Costs[-1] = 2<<TL_SHIFT;          Run_Costs[-1] = 2<<TL_SHIFT;
828    
# Line 812  Line 838 
838    
839                  const int AC = In[Zigzag[i]];                  const int AC = In[Zigzag[i]];
840                  const int Level1 = Out[Zigzag[i]];                  const int Level1 = Out[Zigzag[i]];
841                  const unsigned int Dist0 = Lambda* AC*AC;                  const unsigned int Dist0 = (Metric) ? (calc_mseh(AC, mask, Zigzag[i], Lambda)) : (Lambda* AC*AC);
842                  uint32_t Best_Cost = 0xf0000000;                  uint32_t Best_Cost = 0xf0000000;
843                  Last_Cost += Dist0;                  Last_Cost += Dist0;
844    
# Line 829  Line 855 
855                                  Nodes[i].Level = 1;                                  Nodes[i].Level = 1;
856                                  dQ = Lev0 - AC;                                  dQ = Lev0 - AC;
857                          }                          }
858                          Cost0 = Lambda*dQ*dQ;                          Cost0 = (Metric) ? (calc_mseh(dQ, mask, Zigzag[i], Lambda)) : (Lambda*dQ*dQ);
859    
860                          Nodes[i].Run = 1;                          Nodes[i].Run = 1;
861                          Best_Cost = (Code_Len20[0]<<TL_SHIFT) + Run_Costs[i-1]+Cost0;                          Best_Cost = (Code_Len20[0]<<TL_SHIFT) + Run_Costs[i-1]+Cost0;
# Line 884  Line 910 
910                                  Tbl_L2_Last = (Level2>=- 6) ? B16_17_Code_Len_Last[Level2^-1] : Code_Len0;                                  Tbl_L2_Last = (Level2>=- 6) ? B16_17_Code_Len_Last[Level2^-1] : Code_Len0;
911                          }                          }
912    
913                            if (Metric) {
914                                    Dist1 = calc_mseh(dQ1, mask, Zigzag[i], Lambda);
915                                    Dist2 = calc_mseh(dQ2, mask, Zigzag[i], Lambda);
916                            }
917                            else {
918                          Dist1 = Lambda*dQ1*dQ1;                          Dist1 = Lambda*dQ1*dQ1;
919                          Dist2 = Lambda*dQ2*dQ2;                          Dist2 = Lambda*dQ2*dQ2;
920                            }
921                          dDist21 = Dist2-Dist1;                          dDist21 = Dist2-Dist1;
922    
923                          for(Run=i-Run_Start; Run>0; --Run)                          for(Run=i-Run_Start; Run>0; --Run)

Legend:
Removed from v.1713  
changed lines
  Added in v.1909

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