[svn] / trunk / xvidcore / src / bitstream / mbcoding.c Repository:
ViewVC logotype

Diff of /trunk/xvidcore/src/bitstream/mbcoding.c

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

revision 883, Fri Feb 21 08:32:34 2003 UTC revision 1537, Sun Aug 22 13:16:12 2004 UTC
# Line 1  Line 1 
1   /******************************************************************************  /*****************************************************************************
2    *                                                                            *   *
3    *  This file is part of XviD, a free MPEG-4 video encoder/decoder            *   *  XVID MPEG-4 VIDEO CODEC
4    *                                                                            *   *  - MB coding -
5    *  XviD is an implementation of a part of one or more MPEG-4 Video tools     *   *
6    *  as specified in ISO/IEC 14496-2 standard.  Those intending to use this    *   *  Copyright (C) 2002 Michael Militzer <isibaar@xvid.org>
7    *  software module in hardware or software products are advised that its     *   *
8    *  use may infringe existing patents or copyrights, and any such use         *   *  This program is free software ; you can redistribute it and/or modify
9    *  would be at such party's own risk.  The original developer of this        *   *  it under the terms of the GNU General Public License as published by
10    *  software module and his/her company, and subsequent editors and their     *   *  the Free Software Foundation ; either version 2 of the License, or
11    *  companies, will have no liability for use of this software or             *   *  (at your option) any later version.
12    *  modifications or derivatives thereof.                                     *   *
13    *                                                                            *   *  This program is distributed in the hope that it will be useful,
14    *  XviD is free software; you can redistribute it and/or modify it           *   *  but WITHOUT ANY WARRANTY ; without even the implied warranty of
15    *  under the terms of the GNU General Public License as published by         *   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    *  the Free Software Foundation; either version 2 of the License, or         *   *  GNU General Public License for more details.
17    *  (at your option) any later version.                                       *   *
18    *                                                                            *   *  You should have received a copy of the GNU General Public License
19    *  XviD is distributed in the hope that it will be useful, but               *   *  along with this program ; if not, write to the Free Software
20    *  WITHOUT ANY WARRANTY; without even the implied warranty of                *   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
21    *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *   *
22    *  GNU General Public License for more details.                              *   * $Id: mbcoding.c,v 1.48 2004-08-22 13:16:12 edgomez Exp $
23    *                                                                            *   *
24    *  You should have received a copy of the GNU General Public License         *   ****************************************************************************/
   *  along with this program; if not, write to the Free Software               *  
   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA  *  
   *                                                                            *  
   ******************************************************************************/  
   
  /******************************************************************************  
   *                                                                            *  
   *  mbcoding.c                                                                *  
   *                                                                            *  
   *  Copyright (C) 2002 - Michael Militzer <isibaar@xvid.org>                  *  
   *                                                                            *  
   *  For more information visit the XviD homepage: http://www.xvid.org         *  
   *                                                                            *  
   ******************************************************************************/  
   
  /******************************************************************************  
   *                                                                                                                                                        *  
   *  Revision history:                                                         *  
   *                                                                            *  
   *  28.10.2002 GMC support - gruel                                                                                        *  
   *  28.06.2002 added check_resync_marker()                                    *  
   *  14.04.2002 bframe encoding                                                                                            *  
   *  08.03.2002 initial version; isibaar                                                           *  
   *                                                                                                                                                        *  
   ******************************************************************************/  
   
25    
26  #include <stdio.h>  #include <stdio.h>
27  #include <stdlib.h>  #include <stdlib.h>
28    #include <string.h>
29    
30  #include "../portab.h"  #include "../portab.h"
31  #include "../global.h"  #include "../global.h"
32  #include "bitstream.h"  #include "bitstream.h"
# Line 60  Line 36 
36    
37  #include "../utils/mbfunctions.h"  #include "../utils/mbfunctions.h"
38    
 /* #define BIGLUT */  
   
 #ifdef BIGLUT  
 #define LEVELOFFSET 2048  
 #else  
39  #define LEVELOFFSET 32  #define LEVELOFFSET 32
 #endif  
40    
41    /* Initialized once during xvid_global call
42     * RO access is thread safe */
43  static REVERSE_EVENT DCT3D[2][4096];  static REVERSE_EVENT DCT3D[2][4096];
   
 #ifdef BIGLUT  
 static VLC coeff_VLC[2][2][4096][64];  
 VLC *intra_table;  
 static VLC *inter_table;  
 #else  
44  static VLC coeff_VLC[2][2][64][64];  static VLC coeff_VLC[2][2][64][64];
 #endif  
45    
46  /* not really MB related, but VLCs are only available here */  /* not really MB related, but VLCs are only available here */
47  void bs_put_spritetrajectory(Bitstream * bs, const int val)  void bs_put_spritetrajectory(Bitstream * bs, const int val)
# Line 86  Line 51 
51          const int code2 = sprite_trajectory_len[len].code;          const int code2 = sprite_trajectory_len[len].code;
52          const int len2 = sprite_trajectory_len[len].len;          const int len2 = sprite_trajectory_len[len].len;
53    
54  //      printf("GMC=%d Code/Len  = %d / %d ",val, code,len);  #if 0
55  //      printf("Code2 / Len2 = %d / %d \n",code2,len2);          printf("GMC=%d Code/Len  = %d / %d ",val, code,len);
56            printf("Code2 / Len2 = %d / %d \n",code2,len2);
57    #endif
58    
59          BitstreamPutBits(bs, code2, len2);          BitstreamPutBits(bs, code2, len2);
60          if (len) BitstreamPutBits(bs, code, len);          if (len) BitstreamPutBits(bs, code, len);
# Line 113  Line 80 
80          uint32_t i, j, k, intra, last, run,  run_esc, level, level_esc, escape, escape_len, offset;          uint32_t i, j, k, intra, last, run,  run_esc, level, level_esc, escape, escape_len, offset;
81          int32_t l;          int32_t l;
82    
 #ifdef BIGLUT  
         intra_table = coeff_VLC[1];  
         inter_table = coeff_VLC[0];  
 #endif  
   
   
83          for (intra = 0; intra < 2; intra++)          for (intra = 0; intra < 2; intra++)
84                  for (i = 0; i < 4096; i++)                  for (i = 0; i < 4096; i++)
85                          DCT3D[intra][i].event.level = 0;                          DCT3D[intra][i].event.level = 0;
86    
87          for (intra = 0; intra < 2; intra++)          for (intra = 0; intra < 2; intra++) {
88                  for (last = 0; last < 2; last++)                  for (last = 0; last < 2; last++) {
89                  {                          for (run = 0; run < 63 + last; run++) {
90                          for (run = 0; run < 63 + last; run++)                                  for (level = 0; level < (uint32_t)(32 << intra); level++) {
                                 for (level = 0; level < (uint32_t)(32 << intra); level++)  
                                 {  
 #ifdef BIGLUT  
                                         offset = LEVELOFFSET;  
 #else  
91                                          offset = !intra * LEVELOFFSET;                                          offset = !intra * LEVELOFFSET;
 #endif  
92                                          coeff_VLC[intra][last][level + offset][run].len = 128;                                          coeff_VLC[intra][last][level + offset][run].len = 128;
93                                  }                                  }
94                  }                  }
95                    }
96            }
97    
98          for (intra = 0; intra < 2; intra++)          for (intra = 0; intra < 2; intra++) {
99                  for (i = 0; i < 102; i++)                  for (i = 0; i < 102; i++) {
                 {  
 #ifdef BIGLUT  
                         offset = LEVELOFFSET;  
 #else  
100                          offset = !intra * LEVELOFFSET;                          offset = !intra * LEVELOFFSET;
101  #endif  
102                          for (j = 0; j < (uint32_t)(1 << (12 - coeff_tab[intra][i].vlc.len)); j++)                          for (j = 0; j < (uint32_t)(1 << (12 - coeff_tab[intra][i].vlc.len)); j++) {
                         {  
103                                  DCT3D[intra][(coeff_tab[intra][i].vlc.code << (12 - coeff_tab[intra][i].vlc.len)) | j].len       = coeff_tab[intra][i].vlc.len;                                  DCT3D[intra][(coeff_tab[intra][i].vlc.code << (12 - coeff_tab[intra][i].vlc.len)) | j].len       = coeff_tab[intra][i].vlc.len;
104                                  DCT3D[intra][(coeff_tab[intra][i].vlc.code << (12 - coeff_tab[intra][i].vlc.len)) | j].event = coeff_tab[intra][i].event;                                  DCT3D[intra][(coeff_tab[intra][i].vlc.code << (12 - coeff_tab[intra][i].vlc.len)) | j].event = coeff_tab[intra][i].event;
105                          }                          }
# Line 156  Line 108 
108                                  = coeff_tab[intra][i].vlc.code << 1;                                  = coeff_tab[intra][i].vlc.code << 1;
109                          coeff_VLC[intra][coeff_tab[intra][i].event.last][coeff_tab[intra][i].event.level + offset][coeff_tab[intra][i].event.run].len                          coeff_VLC[intra][coeff_tab[intra][i].event.last][coeff_tab[intra][i].event.level + offset][coeff_tab[intra][i].event.run].len
110                                  = coeff_tab[intra][i].vlc.len + 1;                                  = coeff_tab[intra][i].vlc.len + 1;
111  #ifndef BIGLUT  
112                          if (!intra)                          if (!intra) {
 #endif  
                         {  
113                                  coeff_VLC[intra][coeff_tab[intra][i].event.last][offset - coeff_tab[intra][i].event.level][coeff_tab[intra][i].event.run].code                                  coeff_VLC[intra][coeff_tab[intra][i].event.last][offset - coeff_tab[intra][i].event.level][coeff_tab[intra][i].event.run].code
114                                          = (coeff_tab[intra][i].vlc.code << 1) | 1;                                          = (coeff_tab[intra][i].vlc.code << 1) | 1;
115                                  coeff_VLC[intra][coeff_tab[intra][i].event.last][offset - coeff_tab[intra][i].event.level][coeff_tab[intra][i].event.run].len                                  coeff_VLC[intra][coeff_tab[intra][i].event.last][offset - coeff_tab[intra][i].event.level][coeff_tab[intra][i].event.run].len
116                                          = coeff_tab[intra][i].vlc.len + 1;                                          = coeff_tab[intra][i].vlc.len + 1;
117                          }                          }
118                  }                  }
119            }
120    
121            for (intra = 0; intra < 2; intra++) {
122                    for (last = 0; last < 2; last++) {
123                            for (run = 0; run < 63 + last; run++) {
124                                    for (level = 1; level < (uint32_t)(32 << intra); level++) {
125    
         for (intra = 0; intra < 2; intra++)  
                 for (last = 0; last < 2; last++)  
                         for (run = 0; run < 63 + last; run++)  
                         {  
                                 for (level = 1; level < (uint32_t)(32 << intra); level++)  
                                 {  
126                                          if (level <= max_level[intra][last][run] && run <= max_run[intra][last][level])                                          if (level <= max_level[intra][last][run] && run <= max_run[intra][last][level])
127                                              continue;                                              continue;
128    
 #ifdef BIGLUT  
                                         offset = LEVELOFFSET;  
 #else  
129                                          offset = !intra * LEVELOFFSET;                                          offset = !intra * LEVELOFFSET;
 #endif  
130                      level_esc = level - max_level[intra][last][run];                      level_esc = level - max_level[intra][last][run];
131                                          run_esc = run - 1 - max_run[intra][last][level];                                          run_esc = run - 1 - max_run[intra][last][level];
                                         /*use this test to use shorter esc2 codes when possible  
                                         if (level_esc <= max_level[intra][last][run] && run <= max_run[intra][last][level_esc]  
                                                 && !(coeff_VLC[intra][last][level_esc + offset][run].len + 7 + 1  
                                                          > coeff_VLC[intra][last][level + offset][run_esc].code + 7 + 2))*/  
132    
133                                          if (level_esc <= max_level[intra][last][run] && run <= max_run[intra][last][level_esc])                                          if (level_esc <= max_level[intra][last][run] && run <= max_run[intra][last][level_esc]) {
                                         {  
134                                                  escape     = ESCAPE1;                                                  escape     = ESCAPE1;
135                                                  escape_len = 7 + 1;                                                  escape_len = 7 + 1;
136                                                  run_esc    = run;                                                  run_esc    = run;
137                                          }                                          } else {
138                                          else                                                  if (run_esc <= max_run[intra][last][level] && level <= max_level[intra][last][run_esc]) {
                                         {  
                                                 if (run_esc <= max_run[intra][last][level] && level <= max_level[intra][last][run_esc])  
                                                 {  
139                                                          escape     = ESCAPE2;                                                          escape     = ESCAPE2;
140                                                          escape_len = 7 + 2;                                                          escape_len = 7 + 2;
141                                                          level_esc  = level;                                                          level_esc  = level;
142                                                  }                                                  } else {
143                                                  else                                                          if (!intra) {
                                                 {  
 #ifndef BIGLUT  
                                                         if (!intra)  
 #endif  
                                                         {  
144                                                                  coeff_VLC[intra][last][level + offset][run].code                                                                  coeff_VLC[intra][last][level + offset][run].code
145                                                                          = (ESCAPE3 << 21) | (last << 20) | (run << 14) | (1 << 13) | ((level & 0xfff) << 1) | 1;                                                                          = (ESCAPE3 << 21) | (last << 20) | (run << 14) | (1 << 13) | ((level & 0xfff) << 1) | 1;
146                                                                  coeff_VLC[intra][last][level + offset][run].len = 30;                                                                  coeff_VLC[intra][last][level + offset][run].len = 30;
# Line 224  Line 157 
157                                                  |  coeff_VLC[intra][last][level_esc + offset][run_esc].code;                                                  |  coeff_VLC[intra][last][level_esc + offset][run_esc].code;
158                                          coeff_VLC[intra][last][level + offset][run].len                                          coeff_VLC[intra][last][level + offset][run].len
159                                                  = coeff_VLC[intra][last][level_esc + offset][run_esc].len + escape_len;                                                  = coeff_VLC[intra][last][level_esc + offset][run_esc].len + escape_len;
160  #ifndef BIGLUT  
161                                          if (!intra)                                          if (!intra) {
 #endif  
                                         {  
162                                                  coeff_VLC[intra][last][offset - level][run].code                                                  coeff_VLC[intra][last][offset - level][run].code
163                                                          = (escape << coeff_VLC[intra][last][level_esc + offset][run_esc].len)                                                          = (escape << coeff_VLC[intra][last][level_esc + offset][run_esc].len)
164                                                          |  coeff_VLC[intra][last][level_esc + offset][run_esc].code | 1;                                                          |  coeff_VLC[intra][last][level_esc + offset][run_esc].code | 1;
# Line 236  Line 167 
167                                          }                                          }
168                                  }                                  }
169    
170  #ifdef BIGLUT                                  if (!intra) {
                                 for (level = 32 << intra; level < 2048; level++)  
                                 {  
                                         coeff_VLC[intra][last][level + offset][run].code  
                                                 = (ESCAPE3 << 21) | (last << 20) | (run << 14) | (1 << 13) | ((level & 0xfff) << 1) | 1;  
                                         coeff_VLC[intra][last][level + offset][run].len = 30;  
   
                                         coeff_VLC[intra][last][offset - level][run].code  
                                                 = (ESCAPE3 << 21) | (last << 20) | (run << 14) | (1 << 13) | ((-level & 0xfff) << 1) | 1;  
                                         coeff_VLC[intra][last][offset - level][run].len = 30;  
                                 }  
 #else  
                                 if (!intra)  
                                 {  
171                                          coeff_VLC[intra][last][0][run].code                                          coeff_VLC[intra][last][0][run].code
172                                                  = (ESCAPE3 << 21) | (last << 20) | (run << 14) | (1 << 13) | ((-32 & 0xfff) << 1) | 1;                                                  = (ESCAPE3 << 21) | (last << 20) | (run << 14) | (1 << 13) | ((-32 & 0xfff) << 1) | 1;
173                                          coeff_VLC[intra][last][0][run].len = 30;                                          coeff_VLC[intra][last][0][run].len = 30;
174                                  }                                  }
 #endif  
175                          }                          }
176  /* init sprite_trajectory tables */                  }
177  /* even if GMC is not specified (it might be used later...) */          }
178    
179            /* init sprite_trajectory tables
180             * even if GMC is not specified (it might be used later...) */
181    
182          sprite_trajectory_code[0+16384].code = 0;          sprite_trajectory_code[0+16384].code = 0;
183          sprite_trajectory_code[0+16384].len = 0;          sprite_trajectory_code[0+16384].len = 0;
184          for (k=0;k<14;k++)          for (k=0;k<14;k++) {
         {  
185                  int limit = (1<<k);                  int limit = (1<<k);
186    
187                  for (l=-(2*limit-1); l <= -limit; l++)                  for (l=-(2*limit-1); l <= -limit; l++) {
                 {  
188                          sprite_trajectory_code[l+16384].code = (2*limit-1)+l;                          sprite_trajectory_code[l+16384].code = (2*limit-1)+l;
189                          sprite_trajectory_code[l+16384].len = k+1;                          sprite_trajectory_code[l+16384].len = k+1;
190                  }                  }
191    
192                  for (l=limit; l<= 2*limit-1; l++)                  for (l=limit; l<= 2*limit-1; l++) {
                 {  
193                          sprite_trajectory_code[l+16384].code = l;                          sprite_trajectory_code[l+16384].code = l;
194                          sprite_trajectory_code[l+16384].len = k+1;                          sprite_trajectory_code[l+16384].len = k+1;
195                  }                  }
# Line 334  Line 251 
251    
252  }  }
253    
 #ifdef BIGLUT  
   
 static __inline void  
 CodeCoeff(Bitstream * bs,  
                   const int16_t qcoeff[64],  
                   VLC * table,  
                   const uint16_t * zigzag,  
                   uint16_t intra)  
 {  
   
         uint32_t j, last;  
         short v;  
         VLC *vlc;  
   
         j = intra;  
         last = intra;  
   
         while (j < 64 && (v = qcoeff[zigzag[j]]) == 0)  
                 j++;  
   
         do {  
                 vlc = table + 64 * 2048 + (v << 6) + j - last;  
                 last = ++j;  
   
                 /* count zeroes */  
                 while (j < 64 && (v = qcoeff[zigzag[j]]) == 0)  
                         j++;  
   
                 /* write code */  
                 if (j != 64) {  
                         BitstreamPutBits(bs, vlc->code, vlc->len);  
                 } else {  
                         vlc += 64 * 4096;  
                         BitstreamPutBits(bs, vlc->code, vlc->len);  
                         break;  
                 }  
         } while (1);  
   
 }  
   
   
   
 /* returns the number of bits required to encode qcoeff */  
 int  
 CodeCoeff_CalcBits(const int16_t qcoeff[64],  
                   VLC * table,  
                   const uint16_t * zigzag,  
                   uint16_t intra)  
 {  
         int bits = 0;  
         uint32_t j, last;  
         short v;  
         VLC *vlc;  
   
         j = intra;  
         last = intra;  
   
         while (j < 64 && (v = qcoeff[zigzag[j]]) == 0)  
                 j++;  
   
         if (j >= 64) return 0;  /* empty block */  
   
         do {  
                 vlc = table + 64 * 2048 + (v << 6) + j - last;  
                 last = ++j;  
   
                 /* count zeroes */  
                 while (j < 64 && (v = qcoeff[zigzag[j]]) == 0)  
                         j++;  
   
                 /* write code */  
                 if (j != 64) {  
                         bits += vlc->len;  
                 } else {  
                         vlc += 64 * 4096;  
                         bits += vlc->len;  
                         break;  
                 }  
         } while (1);  
   
         return bits;  
 }  
   
   
 #else  
   
254  static __inline void  static __inline void
255  CodeCoeffInter(Bitstream * bs,  CodeCoeffInter(Bitstream * bs,
256                    const int16_t qcoeff[64],                    const int16_t qcoeff[64],
# Line 498  Line 329 
329          {          {
330                  if ((level = qcoeff[zigzag[i++]]) != 0)                  if ((level = qcoeff[zigzag[i++]]) != 0)
331                  {                  {
332                          abs_level = ABS(prev_level);                          abs_level = abs(prev_level);
333                          abs_level = abs_level < 64 ? abs_level : 0;                          abs_level = abs_level < 64 ? abs_level : 0;
334                          code      = coeff_VLC[1][0][abs_level][prev_run].code;                          code      = coeff_VLC[1][0][abs_level][prev_run].code;
335                          len               = coeff_VLC[1][0][abs_level][prev_run].len;                          len               = coeff_VLC[1][0][abs_level][prev_run].len;
# Line 518  Line 349 
349                          run++;                          run++;
350          }          }
351    
352          abs_level = ABS(prev_level);          abs_level = abs(prev_level);
353          abs_level = abs_level < 64 ? abs_level : 0;          abs_level = abs_level < 64 ? abs_level : 0;
354          code      = coeff_VLC[1][1][abs_level][prev_run].code;          code      = coeff_VLC[1][1][abs_level][prev_run].code;
355          len               = coeff_VLC[1][1][abs_level][prev_run].len;          len               = coeff_VLC[1][1][abs_level][prev_run].len;
# Line 559  Line 390 
390          {          {
391                  if ((level = qcoeff[zigzag[i++]]) != 0)                  if ((level = qcoeff[zigzag[i++]]) != 0)
392                  {                  {
393                          abs_level = ABS(prev_level);                          abs_level = abs(prev_level);
394                          abs_level = abs_level < 64 ? abs_level : 0;                          abs_level = abs_level < 64 ? abs_level : 0;
395                          len               = coeff_VLC[1][0][abs_level][prev_run].len;                          len               = coeff_VLC[1][0][abs_level][prev_run].len;
396                          bits      += len!=128 ? len : 30;                          bits      += len!=128 ? len : 30;
# Line 572  Line 403 
403                          run++;                          run++;
404          }          }
405    
406          abs_level = ABS(prev_level);          abs_level = abs(prev_level);
407          abs_level = abs_level < 64 ? abs_level : 0;          abs_level = abs_level < 64 ? abs_level : 0;
408          len               = coeff_VLC[1][1][abs_level][prev_run].len;          len               = coeff_VLC[1][1][abs_level][prev_run].len;
409          bits      += len!=128 ? len : 30;          bits      += len!=128 ? len : 30;
# Line 624  Line 455 
455          return bits;          return bits;
456  }  }
457    
458    static const int iDQtab[5] = {
459            1, 0, -1 /* no change */, 2, 3
460    };
461    #define DQ_VALUE2INDEX(value)  iDQtab[(value)+2]
462    
 #endif  
463    
464  static __inline void  static __inline void
465  CodeBlockIntra(const FRAMEINFO * const frame,  CodeBlockIntra(const FRAMEINFO * const frame,
# Line 639  Line 473 
473    
474          cbpy = pMB->cbp >> 2;          cbpy = pMB->cbp >> 2;
475    
476          // write mcbpc          /* write mcbpc */
477          if (frame->coding_type == I_VOP) {          if (frame->coding_type == I_VOP) {
478                  mcbpc = ((pMB->mode >> 1) & 3) | ((pMB->cbp & 3) << 2);                  mcbpc = ((pMB->mode >> 1) & 3) | ((pMB->cbp & 3) << 2);
479                  BitstreamPutBits(bs, mcbpc_intra_tab[mcbpc].code,                  BitstreamPutBits(bs, mcbpc_intra_tab[mcbpc].code,
# Line 650  Line 484 
484                                                   mcbpc_inter_tab[mcbpc].len);                                                   mcbpc_inter_tab[mcbpc].len);
485          }          }
486    
487          // ac prediction flag          /* ac prediction flag */
488          if (pMB->acpred_directions[0])          if (pMB->acpred_directions[0])
489                  BitstreamPutBits(bs, 1, 1);                  BitstreamPutBits(bs, 1, 1);
490          else          else
491                  BitstreamPutBits(bs, 0, 1);                  BitstreamPutBits(bs, 0, 1);
492    
493          // write cbpy          /* write cbpy */
494          BitstreamPutBits(bs, cbpy_tab[cbpy].code, cbpy_tab[cbpy].len);          BitstreamPutBits(bs, xvid_cbpy_tab[cbpy].code, xvid_cbpy_tab[cbpy].len);
495    
496          // write dquant          /* write dquant */
497          if (pMB->mode == MODE_INTRA_Q)          if (pMB->mode == MODE_INTRA_Q)
498                  BitstreamPutBits(bs, pMB->dquant, 2);                  BitstreamPutBits(bs, DQ_VALUE2INDEX(pMB->dquant), 2);
499    
500          // write interlacing          /* write interlacing */
501          if (frame->global_flags & XVID_INTERLACING) {          if (frame->vol_flags & XVID_VOL_INTERLACING) {
502                  BitstreamPutBit(bs, pMB->field_dct);                  BitstreamPutBit(bs, pMB->field_dct);
503          }          }
504          // code block coeffs          /* code block coeffs */
505          for (i = 0; i < 6; i++) {          for (i = 0; i < 6; i++) {
506                  if (i < 4)                  if (i < 4)
507                          BitstreamPutBits(bs, dcy_tab[qcoeff[i * 64 + 0] + 255].code,                          BitstreamPutBits(bs, dcy_tab[qcoeff[i * 64 + 0] + 255].code,
# Line 678  Line 512 
512    
513                  if (pMB->cbp & (1 << (5 - i))) {                  if (pMB->cbp & (1 << (5 - i))) {
514                          const uint16_t *scan_table =                          const uint16_t *scan_table =
515                                  frame->global_flags & XVID_ALTERNATESCAN ?                                  frame->vop_flags & XVID_VOP_ALTERNATESCAN ?
516                                  scan_tables[2] : scan_tables[pMB->acpred_directions[i]];                                  scan_tables[2] : scan_tables[pMB->acpred_directions[i]];
517    
518                          bits = BitstreamPos(bs);                          bits = BitstreamPos(bs);
519    
 #ifdef BIGLUT  
                         CodeCoeff(bs, &qcoeff[i * 64], intra_table, scan_table, 1);  
 #else  
520                          CodeCoeffIntra(bs, &qcoeff[i * 64], scan_table);                          CodeCoeffIntra(bs, &qcoeff[i * 64], scan_table);
 #endif  
521    
522                          bits = BitstreamPos(bs) - bits;                          bits = BitstreamPos(bs) - bits;
523                          pStat->iTextBits += bits;                          pStat->iTextBits += bits;
# Line 711  Line 541 
541          mcbpc = (pMB->mode & 7) | ((pMB->cbp & 3) << 3);          mcbpc = (pMB->mode & 7) | ((pMB->cbp & 3) << 3);
542          cbpy = 15 - (pMB->cbp >> 2);          cbpy = 15 - (pMB->cbp >> 2);
543    
544          // write mcbpc          /* write mcbpc */
545          BitstreamPutBits(bs, mcbpc_inter_tab[mcbpc].code,          BitstreamPutBits(bs, mcbpc_inter_tab[mcbpc].code,
546                                           mcbpc_inter_tab[mcbpc].len);                                           mcbpc_inter_tab[mcbpc].len);
547    
548          if ( (frame->coding_type == S_VOP) && (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) )          if ( (frame->coding_type == S_VOP) && (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) )
549                  BitstreamPutBit(bs, pMB->mcsel);                // mcsel: '0'=local motion, '1'=GMC                  BitstreamPutBit(bs, pMB->mcsel);                /* mcsel: '0'=local motion, '1'=GMC */
550    
551          // write cbpy          /* write cbpy */
552          BitstreamPutBits(bs, cbpy_tab[cbpy].code, cbpy_tab[cbpy].len);          BitstreamPutBits(bs, xvid_cbpy_tab[cbpy].code, xvid_cbpy_tab[cbpy].len);
553    
554          // write dquant          /* write dquant */
555          if (pMB->mode == MODE_INTER_Q)          if (pMB->mode == MODE_INTER_Q)
556                  BitstreamPutBits(bs, pMB->dquant, 2);                  BitstreamPutBits(bs, DQ_VALUE2INDEX(pMB->dquant), 2);
557    
558          // interlacing          /* interlacing */
559          if (frame->global_flags & XVID_INTERLACING) {          if (frame->vol_flags & XVID_VOL_INTERLACING) {
560                  if (pMB->cbp) {                  if (pMB->cbp) {
561                          BitstreamPutBit(bs, pMB->field_dct);                          BitstreamPutBit(bs, pMB->field_dct);
562                          DPRINTF(DPRINTF_MB,"codep: field_dct: %i", pMB->field_dct);                          DPRINTF(XVID_DEBUG_MB,"codep: field_dct: %i\n", pMB->field_dct);
563                  }                  }
564    
565                  // if inter block, write field ME flag                  /* if inter block, write field ME flag */
566                  if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) {                  if ((pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) && (pMB->mcsel == 0)) {
567                          BitstreamPutBit(bs, pMB->field_pred);                          BitstreamPutBit(bs, 0 /*pMB->field_pred*/); /* not implemented yet */
568                          DPRINTF(DPRINTF_MB,"codep: field_pred: %i", pMB->field_pred);                          DPRINTF(XVID_DEBUG_MB,"codep: field_pred: %i\n", pMB->field_pred);
569    
570                          // write field prediction references                          /* write field prediction references */
571    #if 0 /* Remove the #if once field_pred is supported */
572                          if (pMB->field_pred) {                          if (pMB->field_pred) {
573                                  BitstreamPutBit(bs, pMB->field_for_top);                                  BitstreamPutBit(bs, pMB->field_for_top);
574                                  BitstreamPutBit(bs, pMB->field_for_bot);                                  BitstreamPutBit(bs, pMB->field_for_bot);
575                          }                          }
576    #endif
577                  }                  }
578          }          }
579          // code motion vector(s) if motion is local          /* code motion vector(s) if motion is local  */
580          if (!pMB->mcsel)          if (!pMB->mcsel)
581                  for (i = 0; i < (pMB->mode == MODE_INTER4V ? 4 : 1); i++) {                  for (i = 0; i < (pMB->mode == MODE_INTER4V ? 4 : 1); i++) {
582                          CodeVector(bs, pMB->pmvs[i].x, frame->fcode, pStat);                          CodeVector(bs, pMB->pmvs[i].x, frame->fcode, pStat);
# Line 753  Line 585 
585    
586          bits = BitstreamPos(bs);          bits = BitstreamPos(bs);
587    
588          // code block coeffs          /* code block coeffs */
589          for (i = 0; i < 6; i++)          for (i = 0; i < 6; i++)
590                  if (pMB->cbp & (1 << (5 - i)))                  if (pMB->cbp & (1 << (5 - i))) {
                 {  
591                          const uint16_t *scan_table =                          const uint16_t *scan_table =
592                                  frame->global_flags & XVID_ALTERNATESCAN ?                                  frame->vop_flags & XVID_VOP_ALTERNATESCAN ?
593                                  scan_tables[2] : scan_tables[0];                                  scan_tables[2] : scan_tables[0];
594    
 #ifdef BIGLUT  
                         CodeCoeff(bs, &qcoeff[i * 64], inter_table, scan_table, 0);  
 #else  
595                          CodeCoeffInter(bs, &qcoeff[i * 64], scan_table);                          CodeCoeffInter(bs, &qcoeff[i * 64], scan_table);
 #endif  
596                  }                  }
597    
598          bits = BitstreamPos(bs) - bits;          bits = BitstreamPos(bs) - bits;
# Line 781  Line 608 
608                   Statistics * pStat)                   Statistics * pStat)
609  {  {
610          if (frame->coding_type != I_VOP)          if (frame->coding_type != I_VOP)
611                          BitstreamPutBit(bs, 0); // not_coded                          BitstreamPutBit(bs, 0); /* not_coded */
612    
613          if (pMB->mode == MODE_INTRA || pMB->mode == MODE_INTRA_Q)          if (pMB->mode == MODE_INTRA || pMB->mode == MODE_INTRA_Q)
614                  CodeBlockIntra(frame, pMB, qcoeff, bs, pStat);                  CodeBlockIntra(frame, pMB, qcoeff, bs, pStat);
# Line 790  Line 617 
617    
618  }  }
619    
 /*  
 // moved to mbcoding.h so that in can be 'static __inline'  
 void  
 MBSkip(Bitstream * bs)  
 {  
         BitstreamPutBit(bs, 1); // not coded  
 }  
 */  
   
620  /***************************************************************  /***************************************************************
621   * bframe encoding start   * bframe encoding start
622   ***************************************************************/   ***************************************************************/
# Line 855  Line 673 
673                  BitstreamPutBit(bs, 1);                  BitstreamPutBit(bs, 1);
674                  return;                  return;
675    
676          default:;                                       // invalid          default:;                                       /* invalid */
677          }          }
678  }  }
679    
680    
681    
682  void  void
683  MBCodingBVOP(const MACROBLOCK * mb,  MBCodingBVOP(const FRAMEINFO * const frame,
684                             const MACROBLOCK * mb,
685                           const int16_t qcoeff[6 * 64],                           const int16_t qcoeff[6 * 64],
686                           const int32_t fcode,                           const int32_t fcode,
687                           const int32_t bcode,                           const int32_t bcode,
688                           Bitstream * bs,                           Bitstream * bs,
689                           Statistics * pStat,                           Statistics * pStat)
                          int direction)  
690  {  {
691          int vcode = fcode;          int vcode = fcode;
692          unsigned int i;          unsigned int i;
693    
694            const uint16_t *scan_table =
695                    frame->vop_flags & XVID_VOP_ALTERNATESCAN ?
696                    scan_tables[2] : scan_tables[0];
697            int bits;
698    
699    
700  /*      ------------------------------------------------------------------  /*      ------------------------------------------------------------------
701                  when a block is skipped it is decoded DIRECT(0,0)                  when a block is skipped it is decoded DIRECT(0,0)
702                  hence is interpolated from forward & backward frames                  hence is interpolated from forward & backward frames
703          ------------------------------------------------------------------ */          ------------------------------------------------------------------ */
704    
705          if (mb->mode == MODE_DIRECT_NONE_MV) {          if (mb->mode == MODE_DIRECT_NONE_MV) {
706                  BitstreamPutBit(bs, 1); // skipped                  BitstreamPutBit(bs, 1); /* skipped */
707                  return;                  return;
708          }          }
709    
710          BitstreamPutBit(bs, 0);         // not skipped          BitstreamPutBit(bs, 0);         /* not skipped */
711    
712          if (mb->cbp == 0) {          if (mb->cbp == 0) {
713                  BitstreamPutBit(bs, 1); // cbp == 0                  BitstreamPutBit(bs, 1); /* cbp == 0 */
714          } else {          } else {
715                  BitstreamPutBit(bs, 0); // cbp == xxx                  BitstreamPutBit(bs, 0); /* cbp == xxx */
716          }          }
717    
718          put_bvop_mbtype(bs, mb->mode);          put_bvop_mbtype(bs, mb->mode);
# Line 898  Line 722 
722          }          }
723    
724          if (mb->mode != MODE_DIRECT && mb->cbp != 0) {          if (mb->mode != MODE_DIRECT && mb->cbp != 0) {
725                  put_bvop_dbquant(bs, 0);        // todo: mb->dquant = 0                  put_bvop_dbquant(bs, 0);        /* todo: mb->dquant = 0 */
726          }          }
727    
728            if (frame->vol_flags & XVID_VOL_INTERLACING) {
729                    if (mb->cbp) {
730                            BitstreamPutBit(bs, mb->field_dct);
731                            DPRINTF(XVID_DEBUG_MB,"codep: field_dct: %i\n", mb->field_dct);
732                    }
733    
734                    /* if not direct block, write field ME flag */
735                    if (mb->mode != MODE_DIRECT) {
736                            BitstreamPutBit(bs, 0 /*mb->field_pred*/); /* field ME not implemented */
737    
738                            /* write field prediction references */
739    #if 0 /* Remove the #if once field_pred is supported */
740                            if (mb->field_pred) {
741                                    BitstreamPutBit(bs, mb->field_for_top);
742                                    BitstreamPutBit(bs, mb->field_for_bot);
743                            }
744    #endif
745                    }
746            }
747    
748    
749          switch (mb->mode) {          switch (mb->mode) {
750                  case MODE_INTERPOLATE:                  case MODE_INTERPOLATE:
751                          CodeVector(bs, mb->pmvs[1].x, vcode, pStat); //forward vector of interpolate mode                          CodeVector(bs, mb->pmvs[1].x, vcode, pStat); /* forward vector of interpolate mode */
752                          CodeVector(bs, mb->pmvs[1].y, vcode, pStat);                          CodeVector(bs, mb->pmvs[1].y, vcode, pStat);
753                  case MODE_BACKWARD:                  case MODE_BACKWARD:
754                          vcode = bcode;                          vcode = bcode;
# Line 912  Line 757 
757                          CodeVector(bs, mb->pmvs[0].y, vcode, pStat);                          CodeVector(bs, mb->pmvs[0].y, vcode, pStat);
758                          break;                          break;
759                  case MODE_DIRECT:                  case MODE_DIRECT:
760                          CodeVector(bs, mb->pmvs[3].x, 1, pStat);        // fcode is always 1 for delta vector                          CodeVector(bs, mb->pmvs[3].x, 1, pStat);        /* fcode is always 1 for delta vector */
761                          CodeVector(bs, mb->pmvs[3].y, 1, pStat);        // prediction is always (0,0)                          CodeVector(bs, mb->pmvs[3].y, 1, pStat);        /* prediction is always (0,0) */
762                  default: break;                  default: break;
763          }          }
764    
765            bits = BitstreamPos(bs);
766          for (i = 0; i < 6; i++) {          for (i = 0; i < 6; i++) {
767                  if (mb->cbp & (1 << (5 - i))) {                  if (mb->cbp & (1 << (5 - i))) {
768  #ifdef BIGLUT                          CodeCoeffInter(bs, &qcoeff[i * 64], scan_table);
                         CodeCoeff(bs, &qcoeff[i * 64], inter_table, scan_tables[0], 0);  
 #else  
                         CodeCoeffInter(bs, &qcoeff[i * 64], scan_tables[0]);  
 #endif  
769                  }                  }
770          }          }
771            pStat->iTextBits += BitstreamPos(bs) - bits;
772  }  }
773    
774    
# Line 935  Line 778 
778   ***************************************************************/   ***************************************************************/
779    
780    
781  // for IVOP addbits == 0  /*
782  // for PVOP addbits == fcode - 1   * for IVOP addbits == 0
783  // for BVOP addbits == max(fcode,bcode) - 1   * for PVOP addbits == fcode - 1
784  // returns true or false   * for BVOP addbits == max(fcode,bcode) - 1
785     * returns true or false
786     */
787  int  int
788  check_resync_marker(Bitstream * bs, int addbits)  check_resync_marker(Bitstream * bs, int addbits)
789  {  {
# Line 1052  Line 897 
897                  return data;                  return data;
898    
899          res = BitstreamGetBits(bs, fcode - 1);          res = BitstreamGetBits(bs, fcode - 1);
900          mv = ((ABS(data) - 1) * scale_fac) + res + 1;          mv = ((abs(data) - 1) * scale_fac) + res + 1;
901    
902          return data < 0 ? -mv : mv;          return data < 0 ? -mv : mv;
903    
# Line 1115  Line 960 
960    
961  }  }
962    
963    #define GET_BITS(cache, n) ((cache)>>(32-(n)))
964    
965  static __inline int  static __inline int
966  get_coeff(Bitstream * bs,  get_coeff(Bitstream * bs,
967                    int *run,                    int *run,
# Line 1127  Line 974 
974          int32_t level;          int32_t level;
975          REVERSE_EVENT *reverse_event;          REVERSE_EVENT *reverse_event;
976    
977            uint32_t cache = BitstreamShowBits(bs, 32);
978    
979          if (short_video_header)         /* inter-VLCs will be used for both intra and inter blocks */          if (short_video_header)         /* inter-VLCs will be used for both intra and inter blocks */
980                  intra = 0;                  intra = 0;
981    
982          if (BitstreamShowBits(bs, 7) != ESCAPE) {          if (GET_BITS(cache, 7) != ESCAPE) {
983                  reverse_event = &DCT3D[intra][BitstreamShowBits(bs, 12)];                  reverse_event = &DCT3D[intra][GET_BITS(cache, 12)];
984    
985                  if ((level = reverse_event->event.level) == 0)                  if ((level = reverse_event->event.level) == 0)
986                          goto error;                          goto error;
# Line 1139  Line 988 
988                  *last = reverse_event->event.last;                  *last = reverse_event->event.last;
989                  *run  = reverse_event->event.run;                  *run  = reverse_event->event.run;
990    
991                  BitstreamSkip(bs, reverse_event->len);                  /* Don't forget to update the bitstream position */
992                    BitstreamSkip(bs, reverse_event->len+1);
993    
994                  return BitstreamGetBits(bs, 1) ? -level : level;                  return (GET_BITS(cache, reverse_event->len+1)&0x01) ? -level : level;
995          }          }
996    
997          BitstreamSkip(bs, 7);          /* flush 7bits of cache */
998            cache <<= 7;
999    
1000          if (short_video_header) {          if (short_video_header) {
1001                  /* escape mode 4 - H.263 type, only used if short_video_header = 1  */                  /* escape mode 4 - H.263 type, only used if short_video_header = 1  */
1002                  *last = BitstreamGetBit(bs);                  *last =  GET_BITS(cache, 1);
1003                  *run = BitstreamGetBits(bs, 6);                  *run  = (GET_BITS(cache, 7) &0x3f);
1004                  level = BitstreamGetBits(bs, 8);                  level = (GET_BITS(cache, 15)&0xff);
1005    
1006                  if (level == 0 || level == 128)                  if (level == 0 || level == 128)
1007                          DPRINTF(DPRINTF_ERROR, "Illegal LEVEL for ESCAPE mode 4: %d", level);                          DPRINTF(XVID_DEBUG_ERROR, "Illegal LEVEL for ESCAPE mode 4: %d\n", level);
1008    
1009                    /* We've "eaten" 22 bits */
1010                    BitstreamSkip(bs, 22);
1011    
1012                  return (level << 24) >> 24;                  return (level << 24) >> 24;
1013          }          }
1014    
1015          mode = BitstreamShowBits(bs, 2);          if ((mode = GET_BITS(cache, 2)) < 3) {
1016                    const int skip[3] = {1, 1, 2};
1017                    cache <<= skip[mode];
1018    
1019          if (mode < 3) {                  reverse_event = &DCT3D[intra][GET_BITS(cache, 12)];
                 BitstreamSkip(bs, (mode == 2) ? 2 : 1);  
   
                 reverse_event = &DCT3D[intra][BitstreamShowBits(bs, 12)];  
1020    
1021                  if ((level = reverse_event->event.level) == 0)                  if ((level = reverse_event->event.level) == 0)
1022                          goto error;                          goto error;
# Line 1171  Line 1024 
1024                  *last = reverse_event->event.last;                  *last = reverse_event->event.last;
1025                  *run  = reverse_event->event.run;                  *run  = reverse_event->event.run;
1026    
1027                  BitstreamSkip(bs, reverse_event->len);                  if (mode < 2) {
1028                            /* first escape mode, level is offset */
                 if (mode < 2)                   /* first escape mode, level is offset */  
1029                          level += max_level[intra][*last][*run];                          level += max_level[intra][*last][*run];
1030                  else                                    /* second escape mode, run is offset */                  } else {
1031                            /* second escape mode, run is offset */
1032                          *run += max_run[intra][*last][level] + 1;                          *run += max_run[intra][*last][level] + 1;
1033                    }
1034    
1035                    /* Update bitstream position */
1036                    BitstreamSkip(bs, 7 + skip[mode] + reverse_event->len + 1);
1037    
1038                  return BitstreamGetBits(bs, 1) ? -level : level;                  return (GET_BITS(cache, reverse_event->len+1)&0x01) ? -level : level;
1039          }          }
1040    
1041          /* third escape mode - fixed length codes */          /* third escape mode - fixed length codes */
1042          BitstreamSkip(bs, 2);          cache <<= 2;
1043          *last = BitstreamGetBits(bs, 1);          *last =  GET_BITS(cache, 1);
1044          *run = BitstreamGetBits(bs, 6);          *run  = (GET_BITS(cache, 7)&0x3f);
1045          BitstreamSkip(bs, 1);           /* marker */          level = (GET_BITS(cache, 20)&0xfff);
1046          level = BitstreamGetBits(bs, 12);  
1047          BitstreamSkip(bs, 1);           /* marker */          /* Update bitstream position */
1048            BitstreamSkip(bs, 30);
1049    
1050          return (level << 20) >> 20;          return (level << 20) >> 20;
1051    
# Line 1209  Line 1067 
1067          do {          do {
1068                  level = get_coeff(bs, &run, &last, 1, 0);                  level = get_coeff(bs, &run, &last, 1, 0);
1069                  if (run == -1) {                  if (run == -1) {
1070                          DPRINTF(DPRINTF_ERROR,"fatal: invalid run");                          DPRINTF(XVID_DEBUG_ERROR,"fatal: invalid run");
1071                          break;                          break;
1072                  }                  }
1073                  coeff += run;                  coeff += run;
1074                  block[scan[coeff]] = level;                  block[scan[coeff]] = level;
1075    
1076                  DPRINTF(DPRINTF_COEFF,"block[%i] %i", scan[coeff], level);                  DPRINTF(XVID_DEBUG_COEFF,"block[%i] %i\n", scan[coeff], level);
1077                  //DPRINTF(DPRINTF_COEFF,"block[%i] %i %08x", scan[coeff], level, BitstreamShowBits(bs, 32));  #if 0
1078                    DPRINTF(XVID_DEBUG_COEFF,"block[%i] %i %08x\n", scan[coeff], level, BitstreamShowBits(bs, 32));
1079    #endif
1080    
1081                  if (level < -2047 || level > 2047) {                  if (level < -2047 || level > 2047) {
1082                          DPRINTF(DPRINTF_ERROR,"warning: intra_overflow %i", level);                          DPRINTF(XVID_DEBUG_ERROR,"warning: intra_overflow %i\n", level);
1083                  }                  }
1084                  coeff++;                  coeff++;
1085          } while (!last);          } while (!last);
# Line 1227  Line 1087 
1087  }  }
1088    
1089  void  void
1090  get_inter_block(Bitstream * bs,  get_inter_block_h263(
1091                    Bitstream * bs,
1092                                  int16_t * block,                                  int16_t * block,
1093                                  int direction)                  int direction,
1094                    const int quant,
1095                    const uint16_t *matrix)
1096  {  {
1097    
1098          const uint16_t *scan = scan_tables[direction];          const uint16_t *scan = scan_tables[direction];
1099            const uint16_t quant_m_2 = quant << 1;
1100            const uint16_t quant_add = (quant & 1 ? quant : quant - 1);
1101          int p;          int p;
1102          int level;          int level;
1103          int run;          int run;
# Line 1242  Line 1107 
1107          do {          do {
1108                  level = get_coeff(bs, &run, &last, 0, 0);                  level = get_coeff(bs, &run, &last, 0, 0);
1109                  if (run == -1) {                  if (run == -1) {
1110                          DPRINTF(DPRINTF_ERROR,"fatal: invalid run");                          DPRINTF(XVID_DEBUG_ERROR,"fatal: invalid run");
1111                          break;                          break;
1112                  }                  }
1113                  p += run;                  p += run;
1114    
1115                  block[scan[p]] = level;                  if (level < 0) {
1116                            level = level*quant_m_2 - quant_add;
1117                            block[scan[p]] = (level >= -2048 ? level : -2048);
1118                    } else {
1119                            level = level * quant_m_2 + quant_add;
1120                            block[scan[p]] = (level <= 2047 ? level : 2047);
1121                    }
1122                    p++;
1123            } while (!last);
1124    }
1125    
1126    void
1127    get_inter_block_mpeg(
1128                    Bitstream * bs,
1129                    int16_t * block,
1130                    int direction,
1131                    const int quant,
1132                    const uint16_t *matrix)
1133    {
1134            const uint16_t *scan = scan_tables[direction];
1135            uint32_t sum = 0;
1136            int p;
1137            int level;
1138            int run;
1139            int last;
1140    
1141                  DPRINTF(DPRINTF_COEFF,"block[%i] %i", scan[p], level);          p = 0;
1142                  // DPRINTF(DPRINTF_COEFF,"block[%i] %i %08x", scan[p], level, BitstreamShowBits(bs, 32));          do {
1143                    level = get_coeff(bs, &run, &last, 0, 0);
1144                    if (run == -1) {
1145                            DPRINTF(XVID_DEBUG_ERROR,"fatal: invalid run");
1146                            break;
1147                    }
1148                    p += run;
1149    
1150                  if (level < -2047 || level > 2047) {                  if (level < 0) {
1151                          DPRINTF(DPRINTF_ERROR,"warning: inter overflow %i", level);                          level = ((2 * -level + 1) * matrix[scan[p]] * quant) >> 4;
1152                            block[scan[p]] = (level <= 2048 ? -level : -2048);
1153                    } else {
1154                            level = ((2 *  level + 1) * matrix[scan[p]] * quant) >> 4;
1155                            block[scan[p]] = (level <= 2047 ? level : 2047);
1156                  }                  }
1157    
1158                    sum ^= block[scan[p]];
1159    
1160                  p++;                  p++;
1161          } while (!last);          } while (!last);
1162    
1163            /*      mismatch control */
1164            if ((sum & 1) == 0) {
1165                    block[63] ^= 1;
1166  }  }
1167    }
1168    
1169    
1170  /*****************************************************************************  /*****************************************************************************
1171   * VLC tables and other constant arrays   * VLC tables and other constant arrays
# Line 1590  Line 1497 
1497  VLC sprite_trajectory_len[15] = {  VLC sprite_trajectory_len[15] = {
1498          { 0x00 , 2},          { 0x00 , 2},
1499          { 0x02 , 3}, { 0x03, 3}, { 0x04, 3}, { 0x05, 3}, { 0x06, 3},          { 0x02 , 3}, { 0x03, 3}, { 0x04, 3}, { 0x05, 3}, { 0x06, 3},
1500          { 0x0E , 4}, { 0x1E, 5}, { 0x3E, 6}, { 0x7F, 7}, { 0xFE, 8},          { 0x0E , 4}, { 0x1E, 5}, { 0x3E, 6}, { 0x7E, 7}, { 0xFE, 8},
1501          { 0x1FE, 9}, {0x3FE,10}, {0x7FE,11}, {0xFFE,12} };          { 0x1FE, 9}, {0x3FE,10}, {0x7FE,11}, {0xFFE,12} };
1502    
1503    
# Line 1618  Line 1525 
1525          {5, 6}, {5, 9}, {5, 8}, {3, 7}, {2, 9}          {5, 6}, {5, 9}, {5, 8}, {3, 7}, {2, 9}
1526  };  };
1527    
1528  const VLC cbpy_tab[16] = {  const VLC xvid_cbpy_tab[16] = {
1529          {3, 4}, {5, 5}, {4, 5}, {9, 4}, {3, 5}, {7, 4}, {2, 6}, {11, 4},          {3, 4}, {5, 5}, {4, 5}, {9, 4}, {3, 5}, {7, 4}, {2, 6}, {11, 4},
1530          {2, 5}, {3, 6}, {5, 4}, {10, 4}, {4, 4}, {8, 4}, {6, 4}, {3, 2}          {2, 5}, {3, 6}, {5, 4}, {10, 4}, {4, 4}, {8, 4}, {6, 4}, {3, 2}
1531  };  };

Legend:
Removed from v.883  
changed lines
  Added in v.1537

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