home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / graphics / gifbla20.zip / SOURCE / GBCON.H < prev    next >
C/C++ Source or Header  |  1992-12-15  |  3KB  |  88 lines

  1.  
  2. /* gbcon.h - Include file for arithmetic coding context routines. */
  3.  
  4. #ifndef P_DEFINED
  5. #define P_DEFINED
  6. #ifdef NOPROTOS
  7. #define P(a,b) b
  8. #else
  9. #define P(a,b) a
  10. #endif
  11. #endif
  12.  
  13. #define ARCON_NCODES 256 /* must be power of two */
  14.  
  15. #define ARCON_BIG_RBSIZE 1792
  16. typedef struct {
  17.     unsigned char rb[ARCON_BIG_RBSIZE];
  18.     int count,tail;
  19.     int freqs[2*ARCON_NCODES-1];
  20. } ARCON_BIG_CONTEXT;
  21.  
  22. #define ARCON_MAX_SMALL_RBSIZE 80
  23. #define ARCON_V11_SMALL_RBSIZE 64
  24. #define ARCON_V20_SMALL_RBSIZE 80
  25. typedef struct {
  26.     unsigned char rb[ARCON_MAX_SMALL_RBSIZE];
  27.     int count,tail,rbsize;
  28.     unsigned char hits[ARCON_MAX_SMALL_RBSIZE];
  29.     char hitfreqs[ARCON_MAX_SMALL_RBSIZE];
  30.     int nhits;
  31. } ARCON_SMALL_CONTEXT;
  32.  
  33. #define ARCON_V11_MAXTYPEFREQ 512
  34. typedef struct {
  35.     int freqs[2];
  36. } ARCON_TYPE_CONTEXT;
  37.  
  38. /* Routines to keep track of large contexts: */
  39. extern void arcon_big_init P((ARCON_BIG_CONTEXT *ac),());
  40. /* Initializes a large context. */
  41. extern int arcon_big_add P((ARCON_BIG_CONTEXT *ac, int c),());
  42. /* Adds c to ac. Returns 0 on success, or -1 on failure. */
  43. #define arcon_big_rtot(ac) ((ac)->freqs[2*ARCON_NCODES-2])
  44. /* Returns the current total frequency of ac. */
  45. extern int arcon_big_find_range P((ARCON_BIG_CONTEXT *ac,
  46.     int c, int *prstart, int *prend),());
  47. /* Sets *prstart..*prend to the current range for c in ac. Returns the
  48.     size of this range, 0 if not found. */
  49. extern int arcon_big_find_c P((ARCON_BIG_CONTEXT *ac,
  50.     int rpos, int *prstart, int *prend),());
  51. /* Sets *prstart..*prend to the current range that contains rpos in ac.
  52.     Returns the character that corresponds to this range, -1 if not found. */
  53.  
  54. /* Routines to keep track of small contexts: */
  55. extern void arcon_small_init P((ARCON_SMALL_CONTEXT *ac, int rbsize),());
  56. /* Initializes a small context. */
  57. extern int arcon_small_add P((ARCON_SMALL_CONTEXT *ac, int c),());
  58. /* Adds c to ac. Returns 0 on success, or -1 on failure. */
  59. #define arcon_small_rtot(ac) ((ac)->count)
  60. /* Returns the current total frequency of ac. */
  61. extern int arcon_small_find_range P((ARCON_SMALL_CONTEXT *ac,
  62.     int c, int *prstart, int *prend),());
  63. /* Sets *prstart..*prend to the current range for c in ac. Returns the
  64.     size of this range, 0 if not found. */
  65. extern int arcon_small_find_c P((ARCON_SMALL_CONTEXT *ac,
  66.     int rpos, int *prstart, int *prend),());
  67. /* Sets *prstart..*prend to the current range that contains rpos in ac.
  68.     Returns the character that corresponds to this range, -1 if not found. */
  69.  
  70. /* Routines to keep track of type contexts, version 1.1: */
  71. #define arcon_type_init(ac) ((ac)->freqs[0] = (ac)->freqs[1] = 1)
  72. #define arcon_type_add(ac,c) \
  73.     ((++((ac)->freqs[(c)]) + (ac)->freqs[1-(c)]) <= ARCON_V11_MAXTYPEFREQ \
  74.         ? 0 \
  75.         : ((ac)->freqs[0]=((ac)->freqs[0]+1)/2, \
  76.             (ac)->freqs[1]=((ac)->freqs[1]+1)/2, 0))
  77. #define arcon_type_rtot(ac) ((ac)->freqs[0]+(ac)->freqs[1])
  78. #define arcon_type_find_range(ac,c,prstart,prend) \
  79.     ((c)==0 \
  80.         ? ((*(prstart))=0, (*(prend))=(ac)->freqs[0], (ac)->freqs[0]) \
  81.         : ((*(prstart))=(ac)->freqs[0], \
  82.             (*(prend))=(*prstart)+(ac)->freqs[1], (ac)->freqs[1]))
  83. #define arcon_type_find_c(ac,rpos,prstart,prend) \
  84.     ((rpos)<(ac)->freqs[0] \
  85.         ? ((*(prstart))=0, (*(prend))=(ac)->freqs[0], 0) \
  86.         : ((*(prstart))=(ac)->freqs[0], \
  87.             (*(prend))=(*prstart)+(ac)->freqs[1], 1))
  88.