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

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

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

revision 1.26, Sun Sep 8 14:43:04 2002 UTC revision 1.28, Sun Sep 8 15:40:02 2002 UTC
# Line 1  Line 1 
1  /*****************************************************************************  /*****************************************************************************
2   *   *
3   *  XVID MPEG-4 VIDEO CODEC   *  XVID MPEG-4 VIDEO CODEC
4   *  - Vector Length Coding tables -   *  - Macro Block coding functions -
5   *   *
6   *  Copyright(C) 2002 Michael Militzer <isibaar@xvid.org>   *  Copyright(C) 2002 Michael Militzer <isibaar@xvid.org>
7   *   *
# Line 56  Line 56 
56  static VLC DCT3Dinter[4096];  static VLC DCT3Dinter[4096];
57    
58  /*****************************************************************************  /*****************************************************************************
59   * Functions   * Vector Length Coding Initialization
60   ****************************************************************************/   ****************************************************************************/
61    
62  void  void
# Line 180  Line 180 
180    
181  }  }
182    
183    /*****************************************************************************
184     * Local inlined functions for MB coding
185     ****************************************************************************/
186    
187  static __inline void  static __inline void
188  CodeVector(Bitstream * bs,  CodeVector(Bitstream * bs,
189                     int32_t value,                     int32_t value,
# Line 235  Line 239 
239    
240  }  }
241    
   
242  static __inline void  static __inline void
243  CodeCoeff(Bitstream * bs,  CodeCoeff(Bitstream * bs,
244                    const int16_t qcoeff[64],                    const int16_t qcoeff[64],
# Line 274  Line 277 
277    
278  }  }
279    
280    /*****************************************************************************
281     * Local functions
282     ****************************************************************************/
283    
284  static void  static void
285  CodeBlockIntra(const FRAMEINFO * frame,  CodeBlockIntra(const FRAMEINFO * frame,
# Line 400  Line 406 
406    
407  }  }
408    
409    /*****************************************************************************
410     * Macro Block bitstream encoding functions
411     ****************************************************************************/
412    
413  void  void
414  MBCoding(const FRAMEINFO * frame,  MBCoding(const FRAMEINFO * frame,
# Line 428  Line 437 
437          return;          return;
438  }  }
439    
440    #if 0
441  /***************************************************************  /***************************************************************
442   * bframe encoding start   * bframe encoding start
443   ***************************************************************/   ***************************************************************/
# Line 504  Line 513 
513          }          }
514  }  }
515    
   
   
516  void  void
517  MBCodingBVOP(const MACROBLOCK * mb,  MBCodingBVOP(const MACROBLOCK * mb,
518                           const int16_t qcoeff[6 * 64],                           const int16_t qcoeff[6 * 64],
# Line 565  Line 572 
572                  }                  }
573          }          }
574  }  }
575    #endif
576    
577    
578    /*****************************************************************************
579     * decoding stuff starts here
580     ****************************************************************************/
581    
582  /***************************************************************  /*
583   * decoding stuff starts here                                  *   * For IVOP addbits == 0
584   ***************************************************************/   * For PVOP addbits == fcode - 1
585     * For BVOP addbits == max(fcode,bcode) - 1
586     * returns true or false
587     */
588    
 // for IVOP addbits == 0  
 // for PVOP addbits == fcode - 1  
 // for BVOP addbits == max(fcode,bcode) - 1  
 // returns true or false  
589  int  int
590  check_resync_marker(Bitstream * bs, int addbits)  check_resync_marker(Bitstream * bs, int addbits)
591  {  {
# Line 753  Line 762 
762    
763  }  }
764    
765    /*****************************************************************************
766     * Local inlined function to "decode" written vlc codes
767     ****************************************************************************/
768    
769    static __inline int
770    get_coeff(Bitstream * bs,
771                      int *run,
772                      int *last,
773                      int intra,
774                      int short_video_header)
775    {
776    
777            uint32_t mode;
778            const VLC *tab;
779            int32_t level;
780    
781            if (short_video_header)         // inter-VLCs will be used for both intra and inter blocks
782                    intra = 0;
783    
784            tab = &DCT3D[intra][BitstreamShowBits(bs, 12)];
785    
786            if (tab->code == -1)
787                    goto error;
788    
789            BitstreamSkip(bs, tab->len);
790    
791            if (tab->code != ESCAPE) {
792                    if (!intra) {
793                            *run = (tab->code >> 4) & 255;
794                            level = tab->code & 15;
795                            *last = (tab->code >> 12) & 1;
796                    } else {
797                            *run = (tab->code >> 8) & 255;
798                            level = tab->code & 255;
799                            *last = (tab->code >> 16) & 1;
800                    }
801                    return BitstreamGetBit(bs) ? -level : level;
802            }
803    
804            if (short_video_header) {
805                    // escape mode 4 - H.263 type, only used if short_video_header = 1
806                    *last = BitstreamGetBit(bs);
807                    *run = BitstreamGetBits(bs, 6);
808                    level = BitstreamGetBits(bs, 8);
809    
810                    if (level == 0 || level == 128)
811                            DEBUG1("Illegal LEVEL for ESCAPE mode 4:", level);
812    
813                    return (level >= 128 ? -(256 - level) : level);
814            }
815    
816            mode = BitstreamShowBits(bs, 2);
817    
818            if (mode < 3) {
819                    BitstreamSkip(bs, (mode == 2) ? 2 : 1);
820    
821                    tab = &DCT3D[intra][BitstreamShowBits(bs, 12)];
822                    if (tab->code == -1)
823                            goto error;
824    
825                    BitstreamSkip(bs, tab->len);
826    
827                    if (!intra) {
828                            *run = (tab->code >> 4) & 255;
829                            level = tab->code & 15;
830                            *last = (tab->code >> 12) & 1;
831                    } else {
832                            *run = (tab->code >> 8) & 255;
833                            level = tab->code & 255;
834                            *last = (tab->code >> 16) & 1;
835                    }
836    
837                    if (mode < 2)                   // first escape mode, level is offset
838                            level += max_level[*last + (!intra << 1)][*run];        // need to add back the max level
839                    else if (mode == 2)             // second escape mode, run is offset
840                            *run += max_run[*last + (!intra << 1)][level] + 1;
841    
842                    return BitstreamGetBit(bs) ? -level : level;
843            }
844            // third escape mode - fixed length codes
845            BitstreamSkip(bs, 2);
846            *last = BitstreamGetBits(bs, 1);
847            *run = BitstreamGetBits(bs, 6);
848            BitstreamSkip(bs, 1);           // marker
849            level = BitstreamGetBits(bs, 12);
850            BitstreamSkip(bs, 1);           // marker
851    
852            return (level & 0x800) ? (level | (-1 ^ 0xfff)) : level;
853    
854      error:
855            *run = VLC_ERROR;
856            return 0;
857    
858    }
859    
860    /*****************************************************************************
861     * MB reading functions
862     ****************************************************************************/
863    
864  void  void
865  get_intra_block(Bitstream * bs,  get_intra_block(Bitstream * bs,
866                                  int16_t * block,                                  int16_t * block,

Legend:
Removed from v.1.26  
changed lines
  Added in v.1.28

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