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

vid_putvlc.c

Go to the documentation of this file.
00001 /************************************************************************
00002  *
00003  *  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 /************************************************************************
00045  *
00046  * Author:        Robert Danielsen <Robert.Danielsen@nta.no>
00047  * Date:        06.05.96
00048  *
00049  * Comment:     Besed on ideas from MPEG-2 Software Simulation Group
00050  *
00051  ************************************************************************/
00052 
00053 #include <assert.h>
00054 #include "vid_sim.h"
00055 #include "vid_vlc.h"
00056 
00057 int
00058 put_mv (int mvint)
00059 {
00060   int sign = 0;
00061   int absmv;
00062 
00063   if (mvint >= 32) {
00064     absmv = -mvint + 64;
00065     sign = 1;
00066   }
00067   else
00068     absmv = mvint;
00069   
00070   putbits (mvtab[absmv].len, mvtab[absmv].code);
00071 
00072   if (mvint != 0) {
00073     putbits (1, sign);
00074     return mvtab[absmv].len + 1;
00075   }
00076   else
00077     return mvtab[absmv].len;
00078 }
00079 
00080 int
00081 put_cbpcm_intra (int cbpc, int mode)
00082 {
00083   int index;
00084 
00085   index = ((mode & 3) >> 1) | ((cbpc & 3) << 2);
00086 
00087   putbits (cbpcm_intra_tab[index].len, cbpcm_intra_tab[index].code);
00088   
00089   return cbpcm_intra_tab[index].len;
00090 }
00091 
00092 int
00093 put_cbpcm_inter (int cbpc, int mode)
00094 {
00095   int index;
00096 
00097   index = (mode & 7) | ((cbpc & 3) << 3);
00098 
00099   putbits (cbpcm_inter_tab[index].len, cbpcm_inter_tab[index].code);
00100   
00101   return cbpcm_inter_tab[index].len;
00102 }
00103 
00104 
00105 int
00106 put_cbpy (int cbp, int mode)
00107 {
00108   int index;
00109 
00110   index = cbp >> 2;
00111 
00112   if (mode < 3)
00113     index ^= 15;
00114   
00115   putbits (cbpy_tab[index].len, cbpy_tab[index].code);
00116   
00117   return cbpy_tab[index].len;
00118 }
00119 
00120 
00121 int
00122 put_coeff (int run, int level, int last)
00123 {
00124   int length = 0;
00125   
00126   assert (last >= 0 && last < 2);
00127   assert (run >= 0 && run < 64);
00128   assert (level > 0 && level < 128);
00129   
00130   if (last == 0) {
00131     if (run < 2 && level < 13 ) {
00132       putbits (coeff_tab0[run][level-1].len,
00133                coeff_tab0[run][level-1].code);
00134 
00135       length = coeff_tab0[run][level-1].len;
00136     }
00137     else if (run > 1 && run < 27 && level < 5) {
00138       putbits (coeff_tab1[run-2][level-1].len,
00139                coeff_tab1[run-2][level-1].code);
00140       
00141       length = coeff_tab1[run-2][level-1].len;
00142     }
00143   }
00144   else if (last == 1) {
00145     if (run < 2 && level < 4) {
00146       putbits (coeff_tab2[run][level-1].len,
00147                coeff_tab2[run][level-1].code);
00148       
00149       length = coeff_tab2[run][level-1].len;
00150     }
00151     else if (run > 1 && run < 42 && level == 1) {
00152       putbits (coeff_tab3[run-2].len,
00153                coeff_tab3[run-2].code);
00154       
00155       length = coeff_tab3[run-2].len;
00156     }
00157   }
00158   return length;
00159 }
00160       
00161     

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