[svn] / branches / dev-api-4 / xvidcore / src / bitstream / mbcoding.c Repository:
ViewVC logotype

Diff of /branches/dev-api-4/xvidcore/src/bitstream/mbcoding.c

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

revision 69, Tue Mar 26 11:16:08 2002 UTC revision 78, Thu Mar 28 20:57:25 2002 UTC
# Line 18  Line 18 
18    
19  void create_vlc_tables(void)  void create_vlc_tables(void)
20  {  {
21    
22          int32_t k, l, i, intra, last;          int32_t k, l, i, intra, last;
23          VLC *vlc[2];          VLC *vlc[2];
24          VLC **coeff_ptr;          VLC **coeff_ptr;
# Line 138  Line 139 
139                          }                          }
140                  }                  }
141          }          }
142    
143          intra_table += 64*255; // center vlc tables          intra_table += 64*255; // center vlc tables
144          inter_table += 64*255; // center vlc tables          inter_table += 64*255; // center vlc tables
145    
# Line 184  Line 186 
186    
187  }  }
188    
189  static __inline void CodeVector(Bitstream *bs, int16_t value, int16_t f_code, Statistics *pStat)  static __inline void CodeVector(Bitstream *bs,
190                                    int16_t value,
191                                    int16_t f_code,
192                                    Statistics *pStat)
193  {  {
194    
195          const int scale_factor = 1 << (f_code - 1);          const int scale_factor = 1 << (f_code - 1);
196          const int cmp = scale_factor << 5;          const int cmp = scale_factor << 5;
197    
# Line 198  Line 204 
204      pStat->iMvSum += value * value;      pStat->iMvSum += value * value;
205      pStat->iMvCount++;      pStat->iMvCount++;
206    
207          if (value == 0)          if (value == 0) {
208                  BitstreamPutBits(bs, mb_motion_table[32].code, mb_motion_table[32].len);                  BitstreamPutBits(bs, mb_motion_table[32].code, mb_motion_table[32].len);
209      else {          } else {
210                  uint16_t length, code, mv_res, sign;                  uint16_t length, code, mv_res, sign;
211    
212                  length = 16 << f_code;                  length = 16 << f_code;
# Line 229  Line 235 
235                  if(f_code)                  if(f_code)
236                          BitstreamPutBits(bs, mv_res, f_code);                          BitstreamPutBits(bs, mv_res, f_code);
237    }    }
238    
239  }  }
240    
241    
242  static __inline void CodeCoeff(Bitstream *bs, int16_t qcoeff[64], VLC *table,  static __inline void CodeCoeff(Bitstream *bs,
243                                                             const uint16_t *zigzag, uint16_t intra) {                                 int16_t qcoeff[64],
244                                   VLC *table,
245                                   const uint16_t *zigzag,
246                                   uint16_t intra)
247    {
248    
249          uint32_t j, last;          uint32_t j, last;
250          short v;          short v;
251          VLC *vlc;          VLC *vlc;
# Line 258  Line 270 
270                          break;                          break;
271                  }                  }
272          } while(1);          } while(1);
273    
274  }  }
275    
276    
277  static void CodeBlockIntra(const MBParam * pParam, const MACROBLOCK *pMB,  static void CodeBlockIntra(const MBParam * pParam,
278                                                                    int16_t qcoeff[][64], Bitstream * bs, Statistics * pStat)                             const MACROBLOCK *pMB,
279                               int16_t qcoeff[6*64],
280                               Bitstream * bs,
281                               Statistics * pStat)
282  {  {
283    
284          uint32_t i, mcbpc, cbpy, bits;          uint32_t i, mcbpc, cbpy, bits;
285    
286          cbpy = pMB->cbp >> 2;          cbpy = pMB->cbp >> 2;
# Line 301  Line 318 
318          for(i = 0; i < 6; i++)          for(i = 0; i < 6; i++)
319          {          {
320                  if(i < 4)                  if(i < 4)
321                          BitstreamPutBits(bs, dcy_tab[qcoeff[i][0] + 255].code,                          BitstreamPutBits(bs,
322                                                           dcy_tab[qcoeff[i][0] + 255].len);                                           dcy_tab[qcoeff[i*64 + 0] + 255].code,
323                                             dcy_tab[qcoeff[i*64 + 0] + 255].len);
324                  else                  else
325                          BitstreamPutBits(bs, dcc_tab[qcoeff[i][0] + 255].code,                          BitstreamPutBits(bs,
326                                           dcc_tab[qcoeff[i][0] + 255].len);                                           dcc_tab[qcoeff[i*64 + 0] + 255].code,
327                                             dcc_tab[qcoeff[i*64 + 0] + 255].len);
328    
329                  if(pMB->cbp & (1 << (5 - i)))                  if(pMB->cbp & (1 << (5 - i)))
330                  {                  {
331                          bits = BitstreamPos(bs);                          bits = BitstreamPos(bs);
332    
333                          CodeCoeff(bs, qcoeff[i], intra_table, scan_tables[pMB->acpred_directions[i]], 1);                          CodeCoeff(bs,
334                                      &qcoeff[i*64],
335                                      intra_table,
336                                      scan_tables[pMB->acpred_directions[i]],
337                                      1);
338    
339                          bits = BitstreamPos(bs) - bits;                          bits = BitstreamPos(bs) - bits;
340                          pStat->iTextBits += bits;                          pStat->iTextBits += bits;
341                  }                  }
342          }          }
343    
344  }  }
345    
346    
347  static void CodeBlockInter(const MBParam * pParam, const MACROBLOCK *pMB,  static void CodeBlockInter(const MBParam * pParam,
348                                                                    int16_t qcoeff[][64], Bitstream * bs, Statistics * pStat)                             const MACROBLOCK *pMB,
349                               int16_t qcoeff[6*64],
350                               Bitstream * bs,
351                               Statistics * pStat)
352  {  {
353    
354          int32_t i;          int32_t i;
355          uint32_t bits, mcbpc, cbpy;          uint32_t bits, mcbpc, cbpy;
356    
# Line 372  Line 400 
400          // code block coeffs          // code block coeffs
401          for(i = 0; i < 6; i++)          for(i = 0; i < 6; i++)
402                  if(pMB->cbp & (1 << (5 - i)))                  if(pMB->cbp & (1 << (5 - i)))
403                          CodeCoeff(bs, qcoeff[i], inter_table, scan_tables[0], 0);                          CodeCoeff(bs, &qcoeff[i*64], inter_table, scan_tables[0], 0);
404    
405          bits = BitstreamPos(bs) - bits;          bits = BitstreamPos(bs) - bits;
406          pStat->iTextBits += bits;          pStat->iTextBits += bits;
407    
408  }  }
409    
410    
411  void MBCoding(const MBParam * pParam, MACROBLOCK *pMB,  void MBCoding(const MBParam * pParam,
412                int16_t qcoeff[][64],                MACROBLOCK *pMB,
413                    Bitstream * bs, Statistics * pStat)                int16_t qcoeff[6*64],
414                  Bitstream * bs,
415                  Statistics * pStat)
416  {  {
417    
418          int intra = (pMB->mode == MODE_INTRA || pMB->mode == MODE_INTRA_Q);          int intra = (pMB->mode == MODE_INTRA || pMB->mode == MODE_INTRA_Q);
419    
420      if(pParam->coding_type == P_VOP) {      if(pParam->coding_type == P_VOP) {
# Line 400  Line 432 
432                  CodeBlockIntra(pParam, pMB, qcoeff, bs, pStat);                  CodeBlockIntra(pParam, pMB, qcoeff, bs, pStat);
433          else          else
434                  CodeBlockInter(pParam, pMB, qcoeff, bs, pStat);                  CodeBlockInter(pParam, pMB, qcoeff, bs, pStat);
435    
436  }  }
437    
438    
# Line 409  Line 442 
442    
443  int get_mcbpc_intra(Bitstream * bs)  int get_mcbpc_intra(Bitstream * bs)
444  {  {
445    
446          uint32_t index;          uint32_t index;
447    
448          while((index = BitstreamShowBits(bs, 9)) == 1)          while((index = BitstreamShowBits(bs, 9)) == 1)
# Line 417  Line 451 
451          index >>= 3;          index >>= 3;
452    
453          BitstreamSkip(bs, mcbpc_intra_table[index].len);          BitstreamSkip(bs, mcbpc_intra_table[index].len);
454    
455          return mcbpc_intra_table[index].code;          return mcbpc_intra_table[index].code;
456    
457  }  }
458    
459  int get_mcbpc_inter(Bitstream * bs)  int get_mcbpc_inter(Bitstream * bs)
460  {  {
461    
462          uint32_t index;          uint32_t index;
463    
464          while((index = CLIP(BitstreamShowBits(bs, 9), 256)) == 1)          while((index = CLIP(BitstreamShowBits(bs, 9), 256)) == 1)
465                  BitstreamSkip(bs, 9);                  BitstreamSkip(bs, 9);
466    
467      BitstreamSkip(bs,  mcbpc_inter_table[index].len);      BitstreamSkip(bs,  mcbpc_inter_table[index].len);
468    
469          return mcbpc_inter_table[index].code;          return mcbpc_inter_table[index].code;
470    
471  }  }
472    
473  int get_cbpy(Bitstream * bs, int intra)  int get_cbpy(Bitstream * bs, int intra)
474  {  {
475    
476          int cbpy;          int cbpy;
477          uint32_t index = BitstreamShowBits(bs, 6);          uint32_t index = BitstreamShowBits(bs, 6);
478    
# Line 443  Line 483 
483                  cbpy = 15 - cbpy;                  cbpy = 15 - cbpy;
484    
485          return cbpy;          return cbpy;
486    
487  }  }
488    
489  int get_mv_data(Bitstream * bs)  int get_mv_data(Bitstream * bs)
490  {  {
491    
492          uint32_t index;          uint32_t index;
493    
494          if(BitstreamGetBit(bs))          if(BitstreamGetBit(bs))
# Line 472  Line 514 
514    
515          BitstreamSkip(bs, TMNMVtab2[index].len);          BitstreamSkip(bs, TMNMVtab2[index].len);
516          return TMNMVtab2[index].code;          return TMNMVtab2[index].code;
517    
518  }  }
519    
520  int get_mv(Bitstream * bs, int fcode)  int get_mv(Bitstream * bs, int fcode)
521  {  {
522    
523          int data;          int data;
524          int res;          int res;
525          int mv;          int mv;
# Line 490  Line 534 
534          mv = ((ABS(data) - 1) * scale_fac) + res + 1;          mv = ((ABS(data) - 1) * scale_fac) + res + 1;
535    
536          return data < 0 ? -mv : mv;          return data < 0 ? -mv : mv;
537    
538  }  }
539    
540  int get_dc_dif(Bitstream * bs, uint32_t dc_size)  int get_dc_dif(Bitstream * bs, uint32_t dc_size)
541  {  {
542    
543          int code = BitstreamGetBits(bs, dc_size);          int code = BitstreamGetBits(bs, dc_size);
544          int msb = code >> (dc_size - 1);          int msb = code >> (dc_size - 1);
545    
# Line 501  Line 547 
547                  return (-1 * (code^((1 << dc_size) - 1)));                  return (-1 * (code^((1 << dc_size) - 1)));
548    
549          return code;          return code;
550    
551  }  }
552    
553  int get_dc_size_lum(Bitstream * bs)  int get_dc_size_lum(Bitstream * bs)
554  {  {
555    
556          int code, i;          int code, i;
557          code = BitstreamShowBits(bs, 11);          code = BitstreamShowBits(bs, 11);
558    
# Line 518  Line 566 
566    
567          BitstreamSkip(bs, dc_lum_tab[code].len);          BitstreamSkip(bs, dc_lum_tab[code].len);
568          return dc_lum_tab[code].code;          return dc_lum_tab[code].code;
569    
570  }  }
571    
572    
573  int get_dc_size_chrom(Bitstream * bs)  int get_dc_size_chrom(Bitstream * bs)
574  {  {
575    
576          uint32_t code, i;          uint32_t code, i;
577          code = BitstreamShowBits(bs, 12);          code = BitstreamShowBits(bs, 12);
578    
# Line 535  Line 585 
585          }          }
586    
587          return 3 - BitstreamGetBits(bs, 2);          return 3 - BitstreamGetBits(bs, 2);
588    
589  }  }
590    
591  int get_coeff(Bitstream * bs, int *run, int *last, int intra, int short_video_header)  int get_coeff(Bitstream * bs, int *run, int *last, int intra, int short_video_header)
592  {  {
593    
594      uint32_t mode;      uint32_t mode;
595      const VLC *tab;      const VLC *tab;
596          int32_t level;          int32_t level;
# Line 626  Line 678 
678  error:  error:
679          *run = VLC_ERROR;          *run = VLC_ERROR;
680          return 0;          return 0;
681    
682  }  }
683    
684    
685  void get_intra_block(Bitstream * bs, int16_t * block, int direction, int coeff)  void get_intra_block(Bitstream * bs, int16_t * block, int direction, int coeff)
686  {  {
687    
688          const uint16_t * scan = scan_tables[ direction ];          const uint16_t * scan = scan_tables[ direction ];
689          int level;          int level;
690          int run;          int run;
# Line 652  Line 706 
706                  }                  }
707                  coeff++;                  coeff++;
708          } while (!last);          } while (!last);
709    
710  }  }
711    
712  void get_inter_block(Bitstream * bs, int16_t * block)  void get_inter_block(Bitstream * bs, int16_t * block)
713  {  {
714    
715          const uint16_t * scan = scan_tables[0];          const uint16_t * scan = scan_tables[0];
716          int p;          int p;
717          int level;          int level;
# Line 679  Line 735 
735                  }                  }
736                  p++;                  p++;
737          } while (!last);          } while (!last);
738    
739  }  }

Legend:
Removed from v.69  
changed lines
  Added in v.78

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