]> git.lizzy.rs Git - zlib.git/blobdiff - deflate.h
zlib 1.2.1.2
[zlib.git] / deflate.h
index 740c25a4fa033ab28d24c694cbcd9a586f3f56d0..410681d18a4abbb9148d95b3a2ba610aa354b963 100644 (file)
--- a/deflate.h
+++ b/deflate.h
@@ -1,6 +1,6 @@
 /* deflate.h -- internal compression state
- * Copyright (C) 1995 Jean-loup Gailly
- * For conditions of distribution and use, see copyright notice in zlib.h 
+ * Copyright (C) 1995-2002 Jean-loup Gailly
+ * For conditions of distribution and use, see copyright notice in zlib.h
  */
 
 /* WARNING: this file should *not* be used by applications. It is
@@ -8,19 +8,25 @@
    subject to change. Applications should only use zlib.h.
  */
 
-/* $Id: deflate.h,v 1.3 1995/04/14 12:39:45 jloup Exp $ */
+/* @(#) $Id$ */
+
+#ifndef DEFLATE_H
+#define DEFLATE_H
 
 #include "zutil.h"
 
+/* define NO_GZIP when compiling if you want to disable gzip header and
+   trailer creation by deflate().  NO_GZIP would be used to avoid linking in
+   the crc code when it is not needed.  For shared libraries, gzip encoding
+   should be left enabled. */
+#ifndef NO_GZIP
+#  define GZIP
+#endif
+
 /* ===========================================================================
  * Internal compression state.
  */
 
-/* Data type */
-#define BINARY  0
-#define ASCII   1
-#define UNKNOWN 2
-
 #define LENGTH_CODES 29
 /* number of length codes, not counting the special END_BLOCK code */
 
@@ -58,7 +64,7 @@ typedef struct ct_data_s {
         ush  dad;        /* father node in Huffman tree */
         ush  len;        /* length of bit string */
     } dl;
-} ct_data;
+} FAR ct_data;
 
 #define Freq fc.freq
 #define Code fc.code
@@ -71,32 +77,34 @@ typedef struct tree_desc_s {
     ct_data *dyn_tree;           /* the dynamic tree */
     int     max_code;            /* largest code with non zero frequency */
     static_tree_desc *stat_desc; /* the corresponding static tree */
-} tree_desc;
+} FAR tree_desc;
 
 typedef ush Pos;
+typedef Pos FAR Posf;
 typedef unsigned IPos;
+
 /* A Pos is an index in the character window. We use short instead of int to
  * save space in the various tables. IPos is used only for parameter passing.
  */
 
 typedef struct internal_state {
-    z_stream *strm;      /* pointer back to this zlib stream */
+    z_streamstrm;      /* pointer back to this zlib stream */
     int   status;        /* as the name implies */
-    Byte *pending_buf;   /* output still pending */
-    Byte *pending_out;   /* next pending byte to output to the stream */
+    Bytef *pending_buf;  /* output still pending */
+    ulg   pending_buf_size; /* size of pending_buf */
+    Bytef *pending_out;  /* next pending byte to output to the stream */
     int   pending;       /* nb of bytes in the pending buffer */
-    uLong adler;         /* adler32 of uncompressed data */
-    int   noheader;      /* suppress zlib header and adler32 */
-    Byte  data_type;     /* UNKNOWN, BINARY or ASCII */
+    int   wrap;          /* bit 0 true for zlib, bit 1 true for gzip */
     Byte  method;        /* STORED (for zip only) or DEFLATED */
+    int   last_flush;    /* value of flush param for previous deflate call */
 
-               /* used by deflate.c: */
+                /* used by deflate.c: */
 
     uInt  w_size;        /* LZ77 window size (32K by default) */
     uInt  w_bits;        /* log2(w_size)  (8..16) */
     uInt  w_mask;        /* w_size - 1 */
 
-    Byte *window;
+    Bytef *window;
     /* Sliding window. Input bytes are read into the second half of the window,
      * and move to the first half later to keep a dictionary of at least wSize
      * bytes. With this organization, matches are limited to a distance of
@@ -111,13 +119,13 @@ typedef struct internal_state {
      * is directly used as sliding window.
      */
 
-    Pos *prev;
+    Posf *prev;
     /* Link to older string with same hash index. To limit the size of this
      * array to 64K, this link is maintained only for the last 32K strings.
      * An index in this array is thus a window index modulo 32K.
      */
 
-    Pos *head; /* Heads of the hash chains or NIL. */
+    Posf *head; /* Heads of the hash chains or NIL. */
 
     uInt  ins_h;          /* hash index of string to be inserted */
     uInt  hash_size;      /* number of elements in hash table */
@@ -171,17 +179,17 @@ typedef struct internal_state {
     uInt good_match;
     /* Use a faster search when the previous match is longer than this */
 
-     int nice_match; /* Stop searching when current match exceeds this */
-
-               /* used by trees.c: */
+    int nice_match; /* Stop searching when current match exceeds this */
 
-    ct_data dyn_ltree[HEAP_SIZE];   /* literal and length tree */
-    ct_data dyn_dtree[2*D_CODES+1]; /* distance tree */
-    ct_data bl_tree[2*BL_CODES+1];  /* Huffman tree for the bit lengths */
+                /* used by trees.c: */
+    /* Didn't use ct_data typedef below to supress compiler warning */
+    struct ct_data_s dyn_ltree[HEAP_SIZE];   /* literal and length tree */
+    struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
+    struct ct_data_s bl_tree[2*BL_CODES+1];  /* Huffman tree for bit lengths */
 
-    tree_desc l_desc;               /* descriptor for literal tree */
-    tree_desc d_desc;               /* descriptor for distance tree */
-    tree_desc bl_desc;              /* descriptor for bit length tree */
+    struct tree_desc_s l_desc;               /* desc. for literal tree */
+    struct tree_desc_s d_desc;               /* desc. for distance tree */
+    struct tree_desc_s bl_desc;              /* desc. for bit length tree */
 
     ush bl_count[MAX_BITS+1];
     /* number of codes at each bit length for an optimal tree */
@@ -197,7 +205,7 @@ typedef struct internal_state {
     /* Depth of each subtree used as tie breaker for trees of equal frequency
      */
 
-    uch *l_buf;           /* buffer for literals or lengths */
+    uchf *l_buf;          /* buffer for literals or lengths */
 
     uInt  lit_bufsize;
     /* Size of match buffer for literals/lengths.  There are 4 reasons for
@@ -221,7 +229,7 @@ typedef struct internal_state {
 
     uInt last_lit;      /* running index in l_buf */
 
-    ush *d_buf;
+    ushf *d_buf;
     /* Buffer for distances. To simplify the code, d_buf and l_buf have
      * the same number of elements. To use different lengths, an extra flag
      * array would be necessary.
@@ -229,11 +237,12 @@ typedef struct internal_state {
 
     ulg opt_len;        /* bit length of current block with optimal trees */
     ulg static_len;     /* bit length of current block with static trees */
-    ulg compressed_len; /* total bit length of compressed file */
     uInt matches;       /* number of string matches in current block */
+    int last_eob_len;   /* bit length of EOB code for last block */
 
 #ifdef DEBUG
-    ulg bits_sent;      /* bit length of the compressed data */
+    ulg compressed_len; /* total bit length of compressed file mod 2^32 */
+    ulg bits_sent;      /* bit length of compressed data sent mod 2^32 */
 #endif
 
     ush bi_buf;
@@ -245,8 +254,7 @@ typedef struct internal_state {
      * are always zero.
      */
 
-} deflate_state;
-
+} FAR deflate_state;
 
 /* Output a byte on the stream.
  * IN assertion: there is enough room in pending_buf.
@@ -264,7 +272,54 @@ typedef struct internal_state {
  * distances are limited to MAX_DIST instead of WSIZE.
  */
 
-       /* in trees.c */
-void ct_init       __P((deflate_state *s));
-int  ct_tally      __P((deflate_state *s, int dist, int lc));
-ulg ct_flush_block __P((deflate_state *s, char *buf, ulg stored_len, int eof));
+        /* in trees.c */
+void _tr_init         OF((deflate_state *s));
+int  _tr_tally        OF((deflate_state *s, unsigned dist, unsigned lc));
+void _tr_flush_block  OF((deflate_state *s, charf *buf, ulg stored_len,
+                          int eof));
+void _tr_align        OF((deflate_state *s));
+void _tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len,
+                          int eof));
+
+#define d_code(dist) \
+   ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)])
+/* Mapping from a distance to a distance code. dist is the distance - 1 and
+ * must not have side effects. _dist_code[256] and _dist_code[257] are never
+ * used.
+ */
+
+#ifndef DEBUG
+/* Inline versions of _tr_tally for speed: */
+
+#if defined(GEN_TREES_H) || !defined(STDC)
+  extern uch _length_code[];
+  extern uch _dist_code[];
+#else
+  extern const uch _length_code[];
+  extern const uch _dist_code[];
+#endif
+
+# define _tr_tally_lit(s, c, flush) \
+  { uch cc = (c); \
+    s->d_buf[s->last_lit] = 0; \
+    s->l_buf[s->last_lit++] = cc; \
+    s->dyn_ltree[cc].Freq++; \
+    flush = (s->last_lit == s->lit_bufsize-1); \
+   }
+# define _tr_tally_dist(s, distance, length, flush) \
+  { uch len = (length); \
+    ush dist = (distance); \
+    s->d_buf[s->last_lit] = dist; \
+    s->l_buf[s->last_lit++] = len; \
+    dist--; \
+    s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
+    s->dyn_dtree[d_code(dist)].Freq++; \
+    flush = (s->last_lit == s->lit_bufsize-1); \
+  }
+#else
+# define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c)
+# define _tr_tally_dist(s, distance, length, flush) \
+              flush = _tr_tally(s, distance, length)
+#endif
+
+#endif /* DEFLATE_H */