Main Page | Class List | File List | Class Members | File Members

vid_quant.c

Go to the documentation of this file.
00001 /************************************************************************
00002  *
00003  *  vid_quant.c, part of tmn (TMN encoder)
00004  *  Copyright (C) 1995, 1996  Telenor R&D, Norway
00005  *        Karl Olav Lillevold <Karl.Lillevold@nta.no>
00006  *  
00007  *  Contacts: 
00008  *  Karl Olav Lillevold               <Karl.Lillevold@nta.no>, or
00009  *  Robert Danielsen                  <Robert.Danielsen@nta.no>
00010  *
00011  *  Telenor Research and Development  http://www.nta.no/brukere/DVC/
00012  *  P.O.Box 83                        tel.:   +47 63 84 84 00
00013  *  N-2007 Kjeller, Norway            fax.:   +47 63 81 00 76
00014  *  
00015  ************************************************************************/
00016 
00017 /*
00018  * Disclaimer of Warranty
00019  *
00020  * These software programs are available to the user without any
00021  * license fee or royalty on an "as is" basis.  Telenor Research and
00022  * Development disclaims any and all warranties, whether express,
00023  * implied, or statuary, including any implied warranties or
00024  * merchantability or of fitness for a particular purpose.  In no
00025  * event shall the copyright-holder be liable for any incidental,
00026  * punitive, or consequential damages of any kind whatsoever arising
00027  * from the use of these programs.
00028  *
00029  * This disclaimer of warranty extends to the user of these programs
00030  * and user's customers, employees, agents, transferees, successors,
00031  * and assigns.
00032  *
00033  * Telenor Research and Development does not represent or warrant that
00034  * the programs furnished hereunder are free of infringement of any
00035  * third-party patents.
00036  *
00037  * Commercial implementations of H.263, including shareware, are
00038  * subject to royalty fees to patent holders.  Many of these patents
00039  * are general enough such that they are unavoidable regardless of
00040  * implementation design.
00041  * */
00042 
00043 
00044 #include"vid_sim.h"
00045 
00046 /**********************************************************************
00047  *
00048  *      Name:        Quant
00049  *      Description:    quantizer for SIM3
00050  *      
00051  *      Input:        pointers to coeff and qcoeff
00052  *        
00053  *      Returns:        
00054  *      Side effects:   
00055  *
00056  *      Date: 940111    Author: Karl.Lillevold@nta.no
00057  *
00058  ***********************************************************************/
00059 
00060 
00061 void Quant(int *coeff, int *qcoeff, int QP, int Mode)
00062 {
00063   int i;
00064   int level;
00065   
00066   if (QP) {
00067     if (Mode == MODE_INTRA || Mode == MODE_INTRA_Q) { /* Intra */
00068       qcoeff[0] = mmax(1,mmin(254,coeff[0]/8));
00069 
00070       for (i = 1; i < 64; i++) {
00071         level = (abs(coeff[i])) / (2*QP);
00072         qcoeff[i] =  mmin(127,mmax(-127,sign(coeff[i]) * level));
00073       }
00074     }
00075     else { /* non Intra */
00076       for (i = 0; i < 64; i++) {
00077         level = (abs(coeff[i])-QP/2)  / (2*QP);
00078         qcoeff[i] = mmin(127,mmax(-127,sign(coeff[i]) * level));
00079       }
00080     }
00081   }
00082   else {
00083     /* No quantizing.
00084        Used only for testing. Bitstream will not be decodable 
00085        whether clipping is performed or not */
00086     for (i = 0; i < 64; i++) {
00087       qcoeff[i] = coeff[i];
00088     }
00089   }
00090   return;
00091 }
00092 
00093 /**********************************************************************
00094  *
00095  *      Name:        Dequant
00096  *      Description:    dequantizer for SIM3
00097  *      
00098  *      Input:        pointers to coeff and qcoeff
00099  *        
00100  *      Returns:        
00101  *      Side effects:   
00102  *
00103  *      Date: 940111    Author: Karl.Lillevold@nta.no
00104  *
00105  ***********************************************************************/
00106 
00107 
00108 void Dequant(int *qcoeff, int *rcoeff, int QP, int Mode)
00109 {
00110   int i;
00111   
00112   if (QP) {
00113     for (i = 0; i < 64; i++) {
00114       if (qcoeff[i]) {
00115         if ((QP % 2) == 1)
00116           rcoeff[i] = QP * (2*abs(qcoeff[i]) + 1);
00117         else
00118           rcoeff[i] = QP * (2*abs(qcoeff[i]) + 1) - 1;
00119         rcoeff[i] = sign(qcoeff[i]) * rcoeff[i];
00120       }
00121       else
00122         rcoeff[i] = 0;
00123     }
00124     if (Mode == MODE_INTRA || Mode == MODE_INTRA_Q) { /* Intra */
00125       rcoeff[0] = qcoeff[0]*8;
00126     }
00127   }
00128   else {
00129     /* No quantizing at all */
00130     for (i = 0; i < 64; i++) {
00131       rcoeff[i] = qcoeff[i];
00132     }
00133   }
00134   return;
00135 }
00136 
00137 
00138 

Generated on Sun Jul 16 16:27:45 2006 by  doxygen 1.3.9.1