Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
deflate.cc File Reference
#include "deflate.h"
Include dependency graph for deflate.cc:

Go to the source code of this file.

Classes

struct  config_s
 
struct  static_tree_desc_s
 

Macros

#define NIL   0
 
#define TOO_FAR   4096
 
#define EQUAL   0
 
#define RANK(f)   (((f) << 1) - ((f) > 4 ? 9 : 0))
 
#define UPDATE_HASH(s, h, c)   (h = (((h)<<s->hash_shift) ^ (c)) & s->hash_mask)
 
#define INSERT_STRING(s, str, match_head)
 
#define CLEAR_HASH(s)
 
#define check_match(s, start, match, length)
 
#define FLUSH_BLOCK_ONLY(s, last)
 
#define FLUSH_BLOCK(s, last)
 

Typedefs

typedef block_state compress_func OF ((deflate_state *s, int flush))
 
typedef struct config_s config
 

Enumerations

enum  block_state { need_more, block_done, finish_started, finish_done }
 

Functions

local void fill_window OF ((deflate_state *s))
 
local block_state deflate_stored OF ((deflate_state *s, int flush))
 
local void putShortMSB OF ((deflate_state *s, uInt b))
 
local void flush_pending OF ((z_streamp strm))
 
local int read_buf OF ((z_streamp strm, Bytef *buf, unsigned size))
 
local uInt longest_match OF ((deflate_state *s, IPos cur_match))
 
int ZEXPORT deflateInit_ (z_streamp strm, int level, const char *version, int stream_size)
 
int ZEXPORT deflateInit2_ (z_streamp strm, int level, int method, int windowBits, int memLevel, int strategy, const char *version, int stream_size)
 
int ZEXPORT deflateSetDictionary (z_streamp strm, const Bytef *dictionary, uInt dictLength)
 
int ZEXPORT deflateResetKeep (z_streamp strm)
 
int ZEXPORT deflateReset (z_streamp strm)
 
int ZEXPORT deflateSetHeader (z_streamp strm, gz_headerp head)
 
int ZEXPORT deflatePending (z_streamp strm, unsigned *pending, int *bits)
 
int ZEXPORT deflatePrime (z_streamp strm, int bits, int value)
 
int ZEXPORT deflateParams (z_streamp strm, int level, int strategy)
 
int ZEXPORT deflateTune (z_streamp strm, int good_length, int max_lazy, int nice_length, int max_chain)
 
uLong ZEXPORT deflateBound (z_streamp strm, uLong sourceLen)
 
local void putShortMSB (deflate_state *s, uInt b)
 
local void flush_pending (z_streamp strm)
 
int ZEXPORT deflate (z_streamp strm, int flush)
 
int ZEXPORT deflateEnd (z_streamp strm)
 
int ZEXPORT deflateCopy (z_streamp dest, z_streamp source)
 
local int read_buf (z_streamp strm, Bytef *buf, unsigned size)
 
local void lm_init (deflate_state *s)
 
local uInt longest_match (deflate_state *s, IPos cur_match)
 
local void fill_window (deflate_state *s)
 
local block_state deflate_stored (deflate_state *s, int flush)
 
local block_state deflate_fast (deflate_state *s, int flush)
 
local block_state deflate_slow (deflate_state *s, int flush)
 
local block_state deflate_rle (deflate_state *s, int flush)
 
local block_state deflate_huff (deflate_state *s, int flush)
 

Variables

local const config configuration_table [10]
 

Macro Definition Documentation

#define check_match (   s,
  start,
  match,
  length 
)

Definition at line 1323 of file deflate.cc.

#define CLEAR_HASH (   s)
Value:
s->head[s->hash_size-1] = NIL; \
zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head));
#define NIL
Definition: deflate.cc:104
const XML_Char * s
Definition: expat.h:262
void ZLIB_INTERNAL zmemzero(Bytef *dest, uInt len)
Definition: zutil.cc:168

Definition at line 196 of file deflate.cc.

#define EQUAL   0

Definition at line 151 of file deflate.cc.

#define FLUSH_BLOCK (   s,
  last 
)
Value:
{ \
if (s->strm->avail_out == 0) return (last) ? finish_started : need_more; \
}
if(nIso!=0)
#define FLUSH_BLOCK_ONLY(s, last)
Definition: deflate.cc:1483
const XML_Char * s
Definition: expat.h:262

Definition at line 1495 of file deflate.cc.

#define FLUSH_BLOCK_ONLY (   s,
  last 
)
Value:
{ \
_tr_flush_block(s, (s->block_start >= 0L ? \
(charf *)&s->window[(unsigned)s->block_start] : \
(charf *)Z_NULL), \
(ulg)((long)s->strstart - s->block_start), \
(last)); \
s->block_start = s->strstart; \
Tracev((stderr,"[FLUSH]")); \
}
unsigned long ulg
Definition: csz_inflate.cc:211
local void flush_pending(z_streamp strm)
Definition: deflate.cc:605
#define Tracev(x)
Definition: zutil.h:232
const XML_Char * s
Definition: expat.h:262
void ZLIB_INTERNAL _tr_flush_block(deflate_state *s, charf *buf, ulg stored_len, int last)
Definition: trees.cc:877
#define Z_NULL
Definition: zlib.h:208
static constexpr double L
Definition: G4SIunits.hh:124

Definition at line 1483 of file deflate.cc.

#define INSERT_STRING (   s,
  str,
  match_head 
)
Value:
(UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
match_head = s->prev[(str) & s->w_mask] = s->head[s->ins_h], \
s->head[s->ins_h] = (Pos)(str))
#define MIN_MATCH
Definition: zutil.h:75
#define UPDATE_HASH(s, h, c)
Definition: deflate.cc:167
ush Pos
Definition: deflate.h:89
const XML_Char * s
Definition: expat.h:262

Definition at line 186 of file deflate.cc.

#define NIL   0

Definition at line 104 of file deflate.cc.

#define RANK (   f)    (((f) << 1) - ((f) > 4 ? 9 : 0))

Definition at line 159 of file deflate.cc.

#define TOO_FAR   4096

Definition at line 108 of file deflate.cc.

#define UPDATE_HASH (   s,
  h,
 
)    (h = (((h)<<s->hash_shift) ^ (c)) & s->hash_mask)

Definition at line 167 of file deflate.cc.

Typedef Documentation

typedef struct config_s config
typedef block_state compress_func OF((deflate_state *s, int flush))

Definition at line 73 of file deflate.cc.

Enumeration Type Documentation

Enumerator
need_more 
block_done 
finish_started 
finish_done 

Definition at line 66 of file deflate.cc.

66  {
67  need_more, /* block not completed, need more input or more output */
68  block_done, /* block flush performed */
69  finish_started, /* finish started, need only more output at next deflate */
70  finish_done /* finish done, accept no more input or output */
71 } block_state;
block_state
Definition: deflate.cc:66

Function Documentation

int ZEXPORT deflate ( z_streamp  strm,
int  flush 
)

Definition at line 627 of file deflate.cc.

628 {
629  int old_flush; /* value of flush param for previous deflate call */
630  deflate_state *s;
631 
632  if (strm == Z_NULL || strm->state == Z_NULL ||
633  flush > Z_BLOCK || flush < 0) {
634  return Z_STREAM_ERROR;
635  }
636  s = strm->state;
637 
638  if (strm->next_out == Z_NULL ||
639  (strm->next_in == Z_NULL && strm->avail_in != 0) ||
640  (s->status == FINISH_STATE && flush != Z_FINISH)) {
641  ERR_RETURN(strm, Z_STREAM_ERROR);
642  }
643  if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR);
644 
645  s->strm = strm; /* just in case */
646  old_flush = s->last_flush;
647  s->last_flush = flush;
648 
649  /* Write the header */
650  if (s->status == INIT_STATE) {
651 #ifdef GZIP
652  if (s->wrap == 2) {
653  strm->adler = crc32(0L, Z_NULL, 0);
654  put_byte(s, 31);
655  put_byte(s, 139);
656  put_byte(s, 8);
657  if (s->gzhead == Z_NULL) {
658  put_byte(s, 0);
659  put_byte(s, 0);
660  put_byte(s, 0);
661  put_byte(s, 0);
662  put_byte(s, 0);
663  put_byte(s, s->level == 9 ? 2 :
664  (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
665  4 : 0));
666  put_byte(s, OS_CODE);
667  s->status = BUSY_STATE;
668  }
669  else {
670  put_byte(s, (s->gzhead->text ? 1 : 0) +
671  (s->gzhead->hcrc ? 2 : 0) +
672  (s->gzhead->extra == Z_NULL ? 0 : 4) +
673  (s->gzhead->name == Z_NULL ? 0 : 8) +
674  (s->gzhead->comment == Z_NULL ? 0 : 16)
675  );
676  put_byte(s, (Byte)(s->gzhead->time & 0xff));
677  put_byte(s, (Byte)((s->gzhead->time >> 8) & 0xff));
678  put_byte(s, (Byte)((s->gzhead->time >> 16) & 0xff));
679  put_byte(s, (Byte)((s->gzhead->time >> 24) & 0xff));
680  put_byte(s, s->level == 9 ? 2 :
681  (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
682  4 : 0));
683  put_byte(s, s->gzhead->os & 0xff);
684  if (s->gzhead->extra != Z_NULL) {
685  put_byte(s, s->gzhead->extra_len & 0xff);
686  put_byte(s, (s->gzhead->extra_len >> 8) & 0xff);
687  }
688  if (s->gzhead->hcrc)
689  strm->adler = crc32(strm->adler, s->pending_buf,
690  s->pending);
691  s->gzindex = 0;
692  s->status = EXTRA_STATE;
693  }
694  }
695  else
696 #endif
697  {
698  uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8;
699  uInt level_flags;
700 
701  if (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2)
702  level_flags = 0;
703  else if (s->level < 6)
704  level_flags = 1;
705  else if (s->level == 6)
706  level_flags = 2;
707  else
708  level_flags = 3;
709  header |= (level_flags << 6);
710  if (s->strstart != 0) header |= PRESET_DICT;
711  header += 31 - (header % 31);
712 
713  s->status = BUSY_STATE;
714  putShortMSB(s, header);
715 
716  /* Save the adler32 of the preset dictionary: */
717  if (s->strstart != 0) {
718  putShortMSB(s, (uInt)(strm->adler >> 16));
719  putShortMSB(s, (uInt)(strm->adler & 0xffff));
720  }
721  strm->adler = adler32(0L, Z_NULL, 0);
722  }
723  }
724 #ifdef GZIP
725  if (s->status == EXTRA_STATE) {
726  if (s->gzhead->extra != Z_NULL) {
727  uInt beg = s->pending; /* start of bytes to update crc */
728 
729  while (s->gzindex < (s->gzhead->extra_len & 0xffff)) {
730  if (s->pending == s->pending_buf_size) {
731  if (s->gzhead->hcrc && s->pending > beg)
732  strm->adler = crc32(strm->adler, s->pending_buf + beg,
733  s->pending - beg);
734  flush_pending(strm);
735  beg = s->pending;
736  if (s->pending == s->pending_buf_size)
737  break;
738  }
739  put_byte(s, s->gzhead->extra[s->gzindex]);
740  s->gzindex++;
741  }
742  if (s->gzhead->hcrc && s->pending > beg)
743  strm->adler = crc32(strm->adler, s->pending_buf + beg,
744  s->pending - beg);
745  if (s->gzindex == s->gzhead->extra_len) {
746  s->gzindex = 0;
747  s->status = NAME_STATE;
748  }
749  }
750  else
751  s->status = NAME_STATE;
752  }
753  if (s->status == NAME_STATE) {
754  if (s->gzhead->name != Z_NULL) {
755  uInt beg = s->pending; /* start of bytes to update crc */
756  int val;
757 
758  do {
759  if (s->pending == s->pending_buf_size) {
760  if (s->gzhead->hcrc && s->pending > beg)
761  strm->adler = crc32(strm->adler, s->pending_buf + beg,
762  s->pending - beg);
763  flush_pending(strm);
764  beg = s->pending;
765  if (s->pending == s->pending_buf_size) {
766  val = 1;
767  break;
768  }
769  }
770  val = s->gzhead->name[s->gzindex++];
771  put_byte(s, val);
772  } while (val != 0);
773  if (s->gzhead->hcrc && s->pending > beg)
774  strm->adler = crc32(strm->adler, s->pending_buf + beg,
775  s->pending - beg);
776  if (val == 0) {
777  s->gzindex = 0;
778  s->status = COMMENT_STATE;
779  }
780  }
781  else
782  s->status = COMMENT_STATE;
783  }
784  if (s->status == COMMENT_STATE) {
785  if (s->gzhead->comment != Z_NULL) {
786  uInt beg = s->pending; /* start of bytes to update crc */
787  int val;
788 
789  do {
790  if (s->pending == s->pending_buf_size) {
791  if (s->gzhead->hcrc && s->pending > beg)
792  strm->adler = crc32(strm->adler, s->pending_buf + beg,
793  s->pending - beg);
794  flush_pending(strm);
795  beg = s->pending;
796  if (s->pending == s->pending_buf_size) {
797  val = 1;
798  break;
799  }
800  }
801  val = s->gzhead->comment[s->gzindex++];
802  put_byte(s, val);
803  } while (val != 0);
804  if (s->gzhead->hcrc && s->pending > beg)
805  strm->adler = crc32(strm->adler, s->pending_buf + beg,
806  s->pending - beg);
807  if (val == 0)
808  s->status = HCRC_STATE;
809  }
810  else
811  s->status = HCRC_STATE;
812  }
813  if (s->status == HCRC_STATE) {
814  if (s->gzhead->hcrc) {
815  if (s->pending + 2 > s->pending_buf_size)
816  flush_pending(strm);
817  if (s->pending + 2 <= s->pending_buf_size) {
818  put_byte(s, (Byte)(strm->adler & 0xff));
819  put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
820  strm->adler = crc32(0L, Z_NULL, 0);
821  s->status = BUSY_STATE;
822  }
823  }
824  else
825  s->status = BUSY_STATE;
826  }
827 #endif
828 
829  /* Flush as much pending output as possible */
830  if (s->pending != 0) {
831  flush_pending(strm);
832  if (strm->avail_out == 0) {
833  /* Since avail_out is 0, deflate will be called again with
834  * more output space, but possibly with both pending and
835  * avail_in equal to zero. There won't be anything to do,
836  * but this is not an error situation so make sure we
837  * return OK instead of BUF_ERROR at next call of deflate:
838  */
839  s->last_flush = -1;
840  return Z_OK;
841  }
842 
843  /* Make sure there is something to do and avoid duplicate consecutive
844  * flushes. For repeated and useless calls with Z_FINISH, we keep
845  * returning Z_STREAM_END instead of Z_BUF_ERROR.
846  */
847  } else if (strm->avail_in == 0 && RANK(flush) <= RANK(old_flush) &&
848  flush != Z_FINISH) {
849  ERR_RETURN(strm, Z_BUF_ERROR);
850  }
851 
852  /* User must not provide more input after the first FINISH: */
853  if (s->status == FINISH_STATE && strm->avail_in != 0) {
854  ERR_RETURN(strm, Z_BUF_ERROR);
855  }
856 
857  /* Start a new block or continue the current one.
858  */
859  if (strm->avail_in != 0 || s->lookahead != 0 ||
860  (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) {
861  block_state bstate;
862 
863  bstate = s->strategy == Z_HUFFMAN_ONLY ? deflate_huff(s, flush) :
864  (s->strategy == Z_RLE ? deflate_rle(s, flush) :
865  (*(configuration_table[s->level].func))(s, flush));
866 
867  if (bstate == finish_started || bstate == finish_done) {
868  s->status = FINISH_STATE;
869  }
870  if (bstate == need_more || bstate == finish_started) {
871  if (strm->avail_out == 0) {
872  s->last_flush = -1; /* avoid BUF_ERROR next call, see above */
873  }
874  return Z_OK;
875  /* If flush != Z_NO_FLUSH && avail_out == 0, the next call
876  * of deflate should use the same flush parameter to make sure
877  * that the flush is complete. So we don't have to output an
878  * empty block here, this will be done at next call. This also
879  * ensures that for a very small output buffer, we emit at most
880  * one empty block.
881  */
882  }
883  if (bstate == block_done) {
884  if (flush == Z_PARTIAL_FLUSH) {
885  _tr_align(s);
886  } else if (flush != Z_BLOCK) { /* FULL_FLUSH or SYNC_FLUSH */
887  _tr_stored_block(s, (char*)0, 0L, 0);
888  /* For a full flush, this empty block will be recognized
889  * as a special marker by inflate_sync().
890  */
891  if (flush == Z_FULL_FLUSH) {
892  CLEAR_HASH(s); /* forget history */
893  if (s->lookahead == 0) {
894  s->strstart = 0;
895  s->block_start = 0L;
896  s->insert = 0;
897  }
898  }
899  }
900  flush_pending(strm);
901  if (strm->avail_out == 0) {
902  s->last_flush = -1; /* avoid BUF_ERROR at next call, see above */
903  return Z_OK;
904  }
905  }
906  }
907  Assert(strm->avail_out > 0, "bug2");
908 
909  if (flush != Z_FINISH) return Z_OK;
910  if (s->wrap <= 0) return Z_STREAM_END;
911 
912  /* Write the trailer */
913 #ifdef GZIP
914  if (s->wrap == 2) {
915  put_byte(s, (Byte)(strm->adler & 0xff));
916  put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
917  put_byte(s, (Byte)((strm->adler >> 16) & 0xff));
918  put_byte(s, (Byte)((strm->adler >> 24) & 0xff));
919  put_byte(s, (Byte)(strm->total_in & 0xff));
920  put_byte(s, (Byte)((strm->total_in >> 8) & 0xff));
921  put_byte(s, (Byte)((strm->total_in >> 16) & 0xff));
922  put_byte(s, (Byte)((strm->total_in >> 24) & 0xff));
923  }
924  else
925 #endif
926  {
927  putShortMSB(s, (uInt)(strm->adler >> 16));
928  putShortMSB(s, (uInt)(strm->adler & 0xffff));
929  }
930  flush_pending(strm);
931  /* If avail_out is zero, the application will call deflate again
932  * to flush the rest.
933  */
934  if (s->wrap > 0) s->wrap = -s->wrap; /* write the trailer only once! */
935  return s->pending != 0 ? Z_OK : Z_STREAM_END;
936 }
#define INIT_STATE
Definition: deflate.h:54
#define Z_BLOCK
Definition: zlib.h:169
unsigned long ZEXPORT crc32(unsigned long crc, const unsigned char FAR *buf, uInt len)
Definition: crc32.cc:202
local void putShortMSB(deflate_state *s, uInt b)
Definition: deflate.cc:593
void ZLIB_INTERNAL _tr_stored_block(deflate_state *s, charf *buf, ulg stored_len, int last)
Definition: trees.cc:841
local block_state deflate_huff(deflate_state *s, int flush)
Definition: deflate.cc:1871
#define HCRC_STATE
Definition: deflate.h:58
local void flush_pending(z_streamp strm)
Definition: deflate.cc:605
#define Z_NO_FLUSH
Definition: zlib.h:164
#define PRESET_DICT
Definition: zutil.h:79
#define Z_PARTIAL_FLUSH
Definition: zlib.h:165
#define Assert(cond, msg)
Definition: zutil.h:230
uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len)
Definition: adler32.cc:65
void ZLIB_INTERNAL _tr_align(deflate_state *s)
Definition: trees.cc:863
block_state
Definition: deflate.cc:66
#define Z_STREAM_ERROR
Definition: zlib.h:177
gz_headerp gzhead
Definition: deflate.h:105
uInt lookahead
Definition: deflate.h:161
#define BUSY_STATE
Definition: deflate.h:59
const XML_Char * s
Definition: expat.h:262
#define Z_FINISH
Definition: zlib.h:168
z_streamp strm
Definition: deflate.h:98
#define Z_DEFLATED
Definition: zlib.h:205
#define Z_STREAM_END
Definition: zlib.h:174
#define put_byte(s, c)
Definition: deflate.h:278
#define COMMENT_STATE
Definition: deflate.h:57
Bytef * pending_buf
Definition: deflate.h:100
#define NAME_STATE
Definition: deflate.h:56
long block_start
Definition: deflate.h:151
local const config configuration_table[10]
Definition: deflate.cc:131
uInt gzindex
Definition: deflate.h:106
#define FINISH_STATE
Definition: deflate.h:60
#define Z_HUFFMAN_ONLY
Definition: zlib.h:193
#define CLEAR_HASH(s)
Definition: deflate.cc:196
#define Z_BUF_ERROR
Definition: zlib.h:180
uInt pending
Definition: deflate.h:103
uInt strstart
Definition: deflate.h:159
#define ERR_RETURN(strm, err)
Definition: zutil.h:52
ulg pending_buf_size
Definition: deflate.h:101
#define Z_OK
Definition: zlib.h:173
#define EXTRA_STATE
Definition: deflate.h:55
#define Z_NULL
Definition: zlib.h:208
local block_state deflate_rle(deflate_state *s, int flush)
Definition: deflate.cc:1800
#define Z_FULL_FLUSH
Definition: zlib.h:167
static constexpr double L
Definition: G4SIunits.hh:124
int last_flush
Definition: deflate.h:108
#define RANK(f)
Definition: deflate.cc:159
#define OS_CODE
Definition: zutil.h:180
#define Z_RLE
Definition: zlib.h:194

Here is the call graph for this function:

Here is the caller graph for this function:

local block_state deflate_fast ( deflate_state s,
int  flush 
)

Definition at line 1571 of file deflate.cc.

1572 {
1573  IPos hash_head; /* head of the hash chain */
1574  int bflush; /* set if current block must be flushed */
1575 
1576  for (;;) {
1577  /* Make sure that we always have enough lookahead, except
1578  * at the end of the input file. We need MAX_MATCH bytes
1579  * for the next match, plus MIN_MATCH bytes to insert the
1580  * string following the next match.
1581  */
1582  if (s->lookahead < MIN_LOOKAHEAD) {
1583  fill_window(s);
1584  if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
1585  return need_more;
1586  }
1587  if (s->lookahead == 0) break; /* flush the current block */
1588  }
1589 
1590  /* Insert the string window[strstart .. strstart+2] in the
1591  * dictionary, and set hash_head to the head of the hash chain:
1592  */
1593  hash_head = NIL;
1594  if (s->lookahead >= MIN_MATCH) {
1595  INSERT_STRING(s, s->strstart, hash_head);
1596  }
1597 
1598  /* Find the longest match, discarding those <= prev_length.
1599  * At this point we have always match_length < MIN_MATCH
1600  */
1601  if (hash_head != NIL && s->strstart - hash_head <= MAX_DIST(s)) {
1602  /* To simplify the code, we prevent matches with the string
1603  * of window index 0 (in particular we have to avoid a match
1604  * of the string with itself at the start of the input file).
1605  */
1606  s->match_length = longest_match (s, hash_head);
1607  /* longest_match() sets match_start */
1608  }
1609  if (s->match_length >= MIN_MATCH) {
1611 
1612  _tr_tally_dist(s, s->strstart - s->match_start,
1613  s->match_length - MIN_MATCH, bflush);
1614 
1615  s->lookahead -= s->match_length;
1616 
1617  /* Insert new strings in the hash table only if the match length
1618  * is not too large. This saves time but degrades compression.
1619  */
1620 #ifndef FASTEST
1621  if (s->match_length <= s->max_insert_length &&
1622  s->lookahead >= MIN_MATCH) {
1623  s->match_length--; /* string at strstart already in table */
1624  do {
1625  s->strstart++;
1626  INSERT_STRING(s, s->strstart, hash_head);
1627  /* strstart never exceeds WSIZE-MAX_MATCH, so there are
1628  * always MIN_MATCH bytes ahead.
1629  */
1630  } while (--s->match_length != 0);
1631  s->strstart++;
1632  } else
1633 #endif
1634  {
1635  s->strstart += s->match_length;
1636  s->match_length = 0;
1637  s->ins_h = s->window[s->strstart];
1638  UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
1639 #if MIN_MATCH != 3
1640  Call UPDATE_HASH() MIN_MATCH-3 more times
1641 #endif
1642  /* If lookahead < MIN_MATCH, ins_h is garbage, but it does not
1643  * matter since it will be recomputed at next deflate call.
1644  */
1645  }
1646  } else {
1647  /* No match, output a literal byte */
1648  Tracevv((stderr,"%c", s->window[s->strstart]));
1649  _tr_tally_lit (s, s->window[s->strstart], bflush);
1650  s->lookahead--;
1651  s->strstart++;
1652  }
1653  if (bflush) FLUSH_BLOCK(s, 0);
1654  }
1655  s->insert = s->strstart < MIN_MATCH-1 ? s->strstart : MIN_MATCH-1;
1656  if (flush == Z_FINISH) {
1657  FLUSH_BLOCK(s, 1);
1658  return finish_done;
1659  }
1660  if (s->last_lit)
1661  FLUSH_BLOCK(s, 0);
1662  return block_done;
1663 }
Bytef * window
Definition: deflate.h:116
#define Z_NO_FLUSH
Definition: zlib.h:164
#define MIN_MATCH
Definition: zutil.h:75
#define UPDATE_HASH(s, h, c)
Definition: deflate.cc:167
uInt match_length
Definition: deflate.h:156
#define NIL
Definition: deflate.cc:104
Definition: G4Pair.hh:150
uInt match_start
Definition: deflate.h:160
uInt lookahead
Definition: deflate.h:161
#define _tr_tally_lit(s, c, flush)
Definition: deflate.h:323
#define MAX_DIST(s)
Definition: deflate.h:286
#define check_match(s, start, match, length)
Definition: deflate.cc:1323
#define MIN_LOOKAHEAD
Definition: deflate.h:281
#define Z_FINISH
Definition: zlib.h:168
local void fill_window(deflate_state *s)
Definition: deflate.cc:1336
#define INSERT_STRING(s, str, match_head)
Definition: deflate.cc:186
#define _tr_tally_dist(s, distance, length, flush)
Definition: deflate.h:330
#define FLUSH_BLOCK(s, last)
Definition: deflate.cc:1495
local uInt longest_match(deflate_state *s, IPos cur_match)
Definition: deflate.cc:1101
#define times
uInt last_lit
Definition: deflate.h:239
uInt strstart
Definition: deflate.h:159
#define Tracevv(x)
Definition: zutil.h:233
unsigned IPos
Definition: deflate.h:91

Here is the call graph for this function:

local block_state deflate_huff ( deflate_state s,
int  flush 
)

Definition at line 1871 of file deflate.cc.

1872 {
1873  int bflush; /* set if current block must be flushed */
1874 
1875  for (;;) {
1876  /* Make sure that we have a literal to write. */
1877  if (s->lookahead == 0) {
1878  fill_window(s);
1879  if (s->lookahead == 0) {
1880  if (flush == Z_NO_FLUSH)
1881  return need_more;
1882  break; /* flush the current block */
1883  }
1884  }
1885 
1886  /* Output a literal byte */
1887  s->match_length = 0;
1888  Tracevv((stderr,"%c", s->window[s->strstart]));
1889  _tr_tally_lit (s, s->window[s->strstart], bflush);
1890  s->lookahead--;
1891  s->strstart++;
1892  if (bflush) FLUSH_BLOCK(s, 0);
1893  }
1894  s->insert = 0;
1895  if (flush == Z_FINISH) {
1896  FLUSH_BLOCK(s, 1);
1897  return finish_done;
1898  }
1899  if (s->last_lit)
1900  FLUSH_BLOCK(s, 0);
1901  return block_done;
1902 }
Bytef * window
Definition: deflate.h:116
#define Z_NO_FLUSH
Definition: zlib.h:164
uInt match_length
Definition: deflate.h:156
uInt lookahead
Definition: deflate.h:161
#define _tr_tally_lit(s, c, flush)
Definition: deflate.h:323
#define Z_FINISH
Definition: zlib.h:168
local void fill_window(deflate_state *s)
Definition: deflate.cc:1336
#define FLUSH_BLOCK(s, last)
Definition: deflate.cc:1495
uInt last_lit
Definition: deflate.h:239
uInt strstart
Definition: deflate.h:159
#define Tracevv(x)
Definition: zutil.h:233

Here is the call graph for this function:

Here is the caller graph for this function:

local block_state deflate_rle ( deflate_state s,
int  flush 
)

Definition at line 1800 of file deflate.cc.

1801 {
1802  int bflush; /* set if current block must be flushed */
1803  uInt prev; /* byte at distance one to match */
1804  Bytef *scan, *strend; /* scan goes up to strend for length of run */
1805 
1806  for (;;) {
1807  /* Make sure that we always have enough lookahead, except
1808  * at the end of the input file. We need MAX_MATCH bytes
1809  * for the longest run, plus one for the unrolled loop.
1810  */
1811  if (s->lookahead <= MAX_MATCH) {
1812  fill_window(s);
1813  if (s->lookahead <= MAX_MATCH && flush == Z_NO_FLUSH) {
1814  return need_more;
1815  }
1816  if (s->lookahead == 0) break; /* flush the current block */
1817  }
1818 
1819  /* See how many times the previous byte repeats */
1820  s->match_length = 0;
1821  if (s->lookahead >= MIN_MATCH && s->strstart > 0) {
1822  scan = s->window + s->strstart - 1;
1823  prev = *scan;
1824  if (prev == *++scan && prev == *++scan && prev == *++scan) {
1825  strend = s->window + s->strstart + MAX_MATCH;
1826  do {
1827  } while (prev == *++scan && prev == *++scan &&
1828  prev == *++scan && prev == *++scan &&
1829  prev == *++scan && prev == *++scan &&
1830  prev == *++scan && prev == *++scan &&
1831  scan < strend);
1832  s->match_length = MAX_MATCH - (int)(strend - scan);
1833  if (s->match_length > s->lookahead)
1834  s->match_length = s->lookahead;
1835  }
1836  Assert(scan <= s->window+(uInt)(s->window_size-1), "wild scan");
1837  }
1838 
1839  /* Emit match if have run of MIN_MATCH or longer, else emit literal */
1840  if (s->match_length >= MIN_MATCH) {
1841  check_match(s, s->strstart, s->strstart - 1, s->match_length);
1842 
1843  _tr_tally_dist(s, 1, s->match_length - MIN_MATCH, bflush);
1844 
1845  s->lookahead -= s->match_length;
1846  s->strstart += s->match_length;
1847  s->match_length = 0;
1848  } else {
1849  /* No match, output a literal byte */
1850  Tracevv((stderr,"%c", s->window[s->strstart]));
1851  _tr_tally_lit (s, s->window[s->strstart], bflush);
1852  s->lookahead--;
1853  s->strstart++;
1854  }
1855  if (bflush) FLUSH_BLOCK(s, 0);
1856  }
1857  s->insert = 0;
1858  if (flush == Z_FINISH) {
1859  FLUSH_BLOCK(s, 1);
1860  return finish_done;
1861  }
1862  if (s->last_lit)
1863  FLUSH_BLOCK(s, 0);
1864  return block_done;
1865 }
Bytef * window
Definition: deflate.h:116
#define Z_NO_FLUSH
Definition: zlib.h:164
#define MIN_MATCH
Definition: zutil.h:75
uInt match_length
Definition: deflate.h:156
#define Assert(cond, msg)
Definition: zutil.h:230
uInt lookahead
Definition: deflate.h:161
#define _tr_tally_lit(s, c, flush)
Definition: deflate.h:323
#define check_match(s, start, match, length)
Definition: deflate.cc:1323
ulg window_size
Definition: deflate.h:126
#define Z_FINISH
Definition: zlib.h:168
local void fill_window(deflate_state *s)
Definition: deflate.cc:1336
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
#define MAX_MATCH
Definition: zutil.h:76
#define _tr_tally_dist(s, distance, length, flush)
Definition: deflate.h:330
#define FLUSH_BLOCK(s, last)
Definition: deflate.cc:1495
uInt last_lit
Definition: deflate.h:239
uInt strstart
Definition: deflate.h:159
#define Tracevv(x)
Definition: zutil.h:233

Here is the call graph for this function:

Here is the caller graph for this function:

local block_state deflate_slow ( deflate_state s,
int  flush 
)

Definition at line 1671 of file deflate.cc.

1672 {
1673  IPos hash_head; /* head of hash chain */
1674  int bflush; /* set if current block must be flushed */
1675 
1676  /* Process the input block. */
1677  for (;;) {
1678  /* Make sure that we always have enough lookahead, except
1679  * at the end of the input file. We need MAX_MATCH bytes
1680  * for the next match, plus MIN_MATCH bytes to insert the
1681  * string following the next match.
1682  */
1683  if (s->lookahead < MIN_LOOKAHEAD) {
1684  fill_window(s);
1685  if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
1686  return need_more;
1687  }
1688  if (s->lookahead == 0) break; /* flush the current block */
1689  }
1690 
1691  /* Insert the string window[strstart .. strstart+2] in the
1692  * dictionary, and set hash_head to the head of the hash chain:
1693  */
1694  hash_head = NIL;
1695  if (s->lookahead >= MIN_MATCH) {
1696  INSERT_STRING(s, s->strstart, hash_head);
1697  }
1698 
1699  /* Find the longest match, discarding those <= prev_length.
1700  */
1702  s->match_length = MIN_MATCH-1;
1703 
1704  if (hash_head != NIL && s->prev_length < s->max_lazy_match &&
1705  s->strstart - hash_head <= MAX_DIST(s)) {
1706  /* To simplify the code, we prevent matches with the string
1707  * of window index 0 (in particular we have to avoid a match
1708  * of the string with itself at the start of the input file).
1709  */
1710  s->match_length = longest_match (s, hash_head);
1711  /* longest_match() sets match_start */
1712 
1713  if (s->match_length <= 5 && (s->strategy == Z_FILTERED
1714 #if TOO_FAR <= 32767
1715  || (s->match_length == MIN_MATCH &&
1716  s->strstart - s->match_start > TOO_FAR)
1717 #endif
1718  )) {
1719 
1720  /* If prev_match is also MIN_MATCH, match_start is garbage
1721  * but we will ignore the current match anyway.
1722  */
1723  s->match_length = MIN_MATCH-1;
1724  }
1725  }
1726  /* If there was a match at the previous step and the current
1727  * match is not better, output the previous match:
1728  */
1729  if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) {
1730  uInt max_insert = s->strstart + s->lookahead - MIN_MATCH;
1731  /* Do not insert strings in hash table beyond this. */
1732 
1733  check_match(s, s->strstart-1, s->prev_match, s->prev_length);
1734 
1735  _tr_tally_dist(s, s->strstart -1 - s->prev_match,
1736  s->prev_length - MIN_MATCH, bflush);
1737 
1738  /* Insert in hash table all strings up to the end of the match.
1739  * strstart-1 and strstart are already inserted. If there is not
1740  * enough lookahead, the last two strings are not inserted in
1741  * the hash table.
1742  */
1743  s->lookahead -= s->prev_length-1;
1744  s->prev_length -= 2;
1745  do {
1746  if (++s->strstart <= max_insert) {
1747  INSERT_STRING(s, s->strstart, hash_head);
1748  }
1749  } while (--s->prev_length != 0);
1750  s->match_available = 0;
1751  s->match_length = MIN_MATCH-1;
1752  s->strstart++;
1753 
1754  if (bflush) FLUSH_BLOCK(s, 0);
1755 
1756  } else if (s->match_available) {
1757  /* If there was no match at the previous position, output a
1758  * single literal. If there was a match but the current match
1759  * is longer, truncate the previous match to a single literal.
1760  */
1761  Tracevv((stderr,"%c", s->window[s->strstart-1]));
1762  _tr_tally_lit(s, s->window[s->strstart-1], bflush);
1763  if (bflush) {
1764  FLUSH_BLOCK_ONLY(s, 0);
1765  }
1766  s->strstart++;
1767  s->lookahead--;
1768  if (s->strm->avail_out == 0) return need_more;
1769  } else {
1770  /* There is no previous match to compare with, wait for
1771  * the next step to decide.
1772  */
1773  s->match_available = 1;
1774  s->strstart++;
1775  s->lookahead--;
1776  }
1777  }
1778  Assert (flush != Z_NO_FLUSH, "no flush?");
1779  if (s->match_available) {
1780  Tracevv((stderr,"%c", s->window[s->strstart-1]));
1781  _tr_tally_lit(s, s->window[s->strstart-1], bflush);
1782  s->match_available = 0;
1783  }
1784  s->insert = s->strstart < MIN_MATCH-1 ? s->strstart : MIN_MATCH-1;
1785  if (flush == Z_FINISH) {
1786  FLUSH_BLOCK(s, 1);
1787  return finish_done;
1788  }
1789  if (s->last_lit)
1790  FLUSH_BLOCK(s, 0);
1791  return block_done;
1792 }
Bytef * window
Definition: deflate.h:116
#define Z_NO_FLUSH
Definition: zlib.h:164
#define MIN_MATCH
Definition: zutil.h:75
uInt max_lazy_match
Definition: deflate.h:174
uInt match_length
Definition: deflate.h:156
#define NIL
Definition: deflate.cc:104
#define Assert(cond, msg)
Definition: zutil.h:230
uInt prev_length
Definition: deflate.h:163
#define FLUSH_BLOCK_ONLY(s, last)
Definition: deflate.cc:1483
#define Z_FILTERED
Definition: zlib.h:192
uInt match_start
Definition: deflate.h:160
uInt lookahead
Definition: deflate.h:161
#define _tr_tally_lit(s, c, flush)
Definition: deflate.h:323
#define MAX_DIST(s)
Definition: deflate.h:286
#define check_match(s, start, match, length)
Definition: deflate.cc:1323
#define MIN_LOOKAHEAD
Definition: deflate.h:281
#define Z_FINISH
Definition: zlib.h:168
local void fill_window(deflate_state *s)
Definition: deflate.cc:1336
z_streamp strm
Definition: deflate.h:98
#define TOO_FAR
Definition: deflate.cc:108
#define INSERT_STRING(s, str, match_head)
Definition: deflate.cc:186
#define _tr_tally_dist(s, distance, length, flush)
Definition: deflate.h:330
#define FLUSH_BLOCK(s, last)
Definition: deflate.cc:1495
int match_available
Definition: deflate.h:158
local uInt longest_match(deflate_state *s, IPos cur_match)
Definition: deflate.cc:1101
uInt last_lit
Definition: deflate.h:239
uInt strstart
Definition: deflate.h:159
IPos prev_match
Definition: deflate.h:157
#define Tracevv(x)
Definition: zutil.h:233
unsigned IPos
Definition: deflate.h:91

Here is the call graph for this function:

local block_state deflate_stored ( deflate_state s,
int  flush 
)

Definition at line 1509 of file deflate.cc.

1510 {
1511  /* Stored blocks are limited to 0xffff bytes, pending_buf is limited
1512  * to pending_buf_size, and each stored block has a 5 byte header:
1513  */
1514  ulg max_block_size = 0xffff;
1515  ulg max_start;
1516 
1517  if (max_block_size > s->pending_buf_size - 5) {
1518  max_block_size = s->pending_buf_size - 5;
1519  }
1520 
1521  /* Copy as much as possible from input to output: */
1522  for (;;) {
1523  /* Fill the window as much as possible: */
1524  if (s->lookahead <= 1) {
1525 
1526  Assert(s->strstart < s->w_size+MAX_DIST(s) ||
1527  s->block_start >= (long)s->w_size, "slide too late");
1528 
1529  fill_window(s);
1530  if (s->lookahead == 0 && flush == Z_NO_FLUSH) return need_more;
1531 
1532  if (s->lookahead == 0) break; /* flush the current block */
1533  }
1534  Assert(s->block_start >= 0L, "block gone");
1535 
1536  s->strstart += s->lookahead;
1537  s->lookahead = 0;
1538 
1539  /* Emit a stored block if pending_buf will be full: */
1540  max_start = s->block_start + max_block_size;
1541  if (s->strstart == 0 || (ulg)s->strstart >= max_start) {
1542  /* strstart == 0 is possible when wraparound on 16-bit machine */
1543  s->lookahead = (uInt)(s->strstart - max_start);
1544  s->strstart = (uInt)max_start;
1545  FLUSH_BLOCK(s, 0);
1546  }
1547  /* Flush if we may have to slide, otherwise block_start may become
1548  * negative and the data will be gone:
1549  */
1550  if (s->strstart - (uInt)s->block_start >= MAX_DIST(s)) {
1551  FLUSH_BLOCK(s, 0);
1552  }
1553  }
1554  s->insert = 0;
1555  if (flush == Z_FINISH) {
1556  FLUSH_BLOCK(s, 1);
1557  return finish_done;
1558  }
1559  if ((long)s->strstart > s->block_start)
1560  FLUSH_BLOCK(s, 0);
1561  return block_done;
1562 }
unsigned long ulg
Definition: csz_inflate.cc:211
#define Z_NO_FLUSH
Definition: zlib.h:164
#define Assert(cond, msg)
Definition: zutil.h:230
uInt lookahead
Definition: deflate.h:161
#define MAX_DIST(s)
Definition: deflate.h:286
#define Z_FINISH
Definition: zlib.h:168
local void fill_window(deflate_state *s)
Definition: deflate.cc:1336
#define FLUSH_BLOCK(s, last)
Definition: deflate.cc:1495
long block_start
Definition: deflate.h:151
uInt strstart
Definition: deflate.h:159
ulg pending_buf_size
Definition: deflate.h:101
static constexpr double L
Definition: G4SIunits.hh:124

Here is the call graph for this function:

uLong ZEXPORT deflateBound ( z_streamp  strm,
uLong  sourceLen 
)

Definition at line 533 of file deflate.cc.

534 {
535  deflate_state *s;
536  uLong complen, wraplen;
537  Bytef *str;
538 
539  /* conservative upper bound for compressed data */
540  complen = sourceLen +
541  ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 5;
542 
543  /* if can't get parameters, return conservative bound plus zlib wrapper */
544  if (strm == Z_NULL || strm->state == Z_NULL)
545  return complen + 6;
546 
547  /* compute wrapper length */
548  s = strm->state;
549  switch (s->wrap) {
550  case 0: /* raw deflate */
551  wraplen = 0;
552  break;
553  case 1: /* zlib wrapper */
554  wraplen = 6 + (s->strstart ? 4 : 0);
555  break;
556  case 2: /* gzip wrapper */
557  wraplen = 18;
558  if (s->gzhead != Z_NULL) { /* user-supplied gzip header */
559  if (s->gzhead->extra != Z_NULL)
560  wraplen += 2 + s->gzhead->extra_len;
561  str = s->gzhead->name;
562  if (str != Z_NULL)
563  do {
564  wraplen++;
565  } while (*str++);
566  str = s->gzhead->comment;
567  if (str != Z_NULL)
568  do {
569  wraplen++;
570  } while (*str++);
571  if (s->gzhead->hcrc)
572  wraplen += 2;
573  }
574  break;
575  default: /* for compiler happiness */
576  wraplen = 6;
577  }
578 
579  /* if not default parameters, return conservative bound */
580  if (s->w_bits != 15 || s->hash_bits != 8 + 7)
581  return complen + wraplen;
582 
583  /* default settings: return tight bound for that case */
584  return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) +
585  (sourceLen >> 25) + 13 - 6 + wraplen;
586 }
const XML_Char * s
Definition: expat.h:262
#define Z_NULL
Definition: zlib.h:208
int ZEXPORT deflateCopy ( z_streamp  dest,
z_streamp  source 
)

Definition at line 973 of file deflate.cc.

974 {
975 #ifdef MAXSEG_64K
976  return Z_STREAM_ERROR;
977 #else
978  deflate_state *ds;
979  deflate_state *ss;
980  ushf *overlay;
981 
982 
983  if (source == Z_NULL || dest == Z_NULL || source->state == Z_NULL) {
984  return Z_STREAM_ERROR;
985  }
986 
987  ss = source->state;
988 
989  zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream));
990 
991  ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state));
992  if (ds == Z_NULL) return Z_MEM_ERROR;
993  dest->state = (struct internal_state FAR *) ds;
994  zmemcpy((voidpf)ds, (voidpf)ss, sizeof(deflate_state));
995  ds->strm = dest;
996 
997  ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));
998  ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos));
999  ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos));
1000  overlay = (ushf *) ZALLOC(dest, ds->lit_bufsize, sizeof(ush)+2);
1001  ds->pending_buf = (uchf *) overlay;
1002 
1003  if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL ||
1004  ds->pending_buf == Z_NULL) {
1005  deflateEnd (dest);
1006  return Z_MEM_ERROR;
1007  }
1008  /* following zmemcpy do not work for 16-bit MSDOS */
1009  zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte));
1010  zmemcpy((voidpf)ds->prev, (voidpf)ss->prev, ds->w_size * sizeof(Pos));
1011  zmemcpy((voidpf)ds->head, (voidpf)ss->head, ds->hash_size * sizeof(Pos));
1012  zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size);
1013 
1014  ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
1015  ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush);
1016  ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize;
1017 
1018  ds->l_desc.dyn_tree = ds->dyn_ltree;
1019  ds->d_desc.dyn_tree = ds->dyn_dtree;
1020  ds->bl_desc.dyn_tree = ds->bl_tree;
1021 
1022  return Z_OK;
1023 #endif /* MAXSEG_64K */
1024 }
int ZEXPORT deflateEnd(z_streamp strm)
Definition: deflate.cc:939
ush FAR ushf
Definition: zutil.h:44
ush Pos
Definition: deflate.h:89
void ZLIB_INTERNAL zmemcpy(Bytef *dest, const Bytef *source, uInt len)
Definition: zutil.cc:150
#define Z_STREAM_ERROR
Definition: zlib.h:177
#define ZALLOC(strm, items, size)
Definition: zutil.h:244
Pos FAR Posf
Definition: deflate.h:90
#define Z_MEM_ERROR
Definition: zlib.h:179
unsigned short ush
Definition: csz_inflate.cc:210
#define Z_OK
Definition: zlib.h:173
#define Z_NULL
Definition: zlib.h:208
uch FAR uchf
Definition: zutil.h:42

Here is the call graph for this function:

int ZEXPORT deflateEnd ( z_streamp  strm)

Definition at line 939 of file deflate.cc.

940 {
941  int status;
942 
943  if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
944 
945  status = strm->state->status;
946  if (status != INIT_STATE &&
947  status != EXTRA_STATE &&
948  status != NAME_STATE &&
949  status != COMMENT_STATE &&
950  status != HCRC_STATE &&
951  status != BUSY_STATE &&
952  status != FINISH_STATE) {
953  return Z_STREAM_ERROR;
954  }
955 
956  /* Deallocate in reverse order of allocations: */
957  TRY_FREE(strm, strm->state->pending_buf);
958  TRY_FREE(strm, strm->state->head);
959  TRY_FREE(strm, strm->state->prev);
960  TRY_FREE(strm, strm->state->window);
961 
962  ZFREE(strm, strm->state);
963  strm->state = Z_NULL;
964 
965  return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK;
966 }
#define INIT_STATE
Definition: deflate.h:54
#define HCRC_STATE
Definition: deflate.h:58
#define Z_STREAM_ERROR
Definition: zlib.h:177
#define BUSY_STATE
Definition: deflate.h:59
z_streamp strm
Definition: deflate.h:98
#define Z_DATA_ERROR
Definition: zlib.h:178
#define ZFREE(strm, addr)
Definition: zutil.h:246
#define COMMENT_STATE
Definition: deflate.h:57
#define NAME_STATE
Definition: deflate.h:56
#define TRY_FREE(s, p)
Definition: zutil.h:247
#define FINISH_STATE
Definition: deflate.h:60
#define Z_OK
Definition: zlib.h:173
#define EXTRA_STATE
Definition: deflate.h:55
#define Z_NULL
Definition: zlib.h:208

Here is the caller graph for this function:

int ZEXPORT deflateInit2_ ( z_streamp  strm,
int  level,
int  method,
int  windowBits,
int  memLevel,
int  strategy,
const char *  version,
int  stream_size 
)

Definition at line 209 of file deflate.cc.

211 {
212  deflate_state *s;
213  int wrap = 1;
214  static const char my_version[] = ZLIB_VERSION;
215 
216  ushf *overlay;
217  /* We overlay pending_buf and d_buf+l_buf. This works since the average
218  * output size for (length,distance) codes is <= 24 bits.
219  */
220 
221  if (version == Z_NULL || version[0] != my_version[0] ||
222  stream_size != sizeof(z_stream)) {
223  return Z_VERSION_ERROR;
224  }
225  if (strm == Z_NULL) return Z_STREAM_ERROR;
226 
227  strm->msg = Z_NULL;
228  if (strm->zalloc == (alloc_func)0) {
229 #ifdef Z_SOLO
230  return Z_STREAM_ERROR;
231 #else
232  strm->zalloc = zcalloc;
233  strm->opaque = (voidpf)0;
234 #endif
235  }
236  if (strm->zfree == (free_func)0)
237 #ifdef Z_SOLO
238  return Z_STREAM_ERROR;
239 #else
240  strm->zfree = zcfree;
241 #endif
242 
243 #ifdef FASTEST
244  if (level != 0) level = 1;
245 #else
246  if (level == Z_DEFAULT_COMPRESSION) level = 6;
247 #endif
248 
249  if (windowBits < 0) { /* suppress zlib wrapper */
250  wrap = 0;
251  windowBits = -windowBits;
252  }
253 #ifdef GZIP
254  else if (windowBits > 15) {
255  wrap = 2; /* write gzip wrapper instead */
256  windowBits -= 16;
257  }
258 #endif
259  if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED ||
260  windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
261  strategy < 0 || strategy > Z_FIXED) {
262  return Z_STREAM_ERROR;
263  }
264  if (windowBits == 8) windowBits = 9; /* until 256-byte window bug fixed */
265  s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state));
266  if (s == Z_NULL) return Z_MEM_ERROR;
267  strm->state = (struct internal_state FAR *)s;
268  s->strm = strm;
269 
270  s->wrap = wrap;
271  s->gzhead = Z_NULL;
272  s->w_bits = windowBits;
273  s->w_size = 1 << s->w_bits;
274  s->w_mask = s->w_size - 1;
275 
276  s->hash_bits = memLevel + 7;
277  s->hash_size = 1 << s->hash_bits;
278  s->hash_mask = s->hash_size - 1;
279  s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH);
280 
281  s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte));
282  s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos));
283  s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos));
284 
285  s->high_water = 0; /* nothing written to s->window yet */
286 
287  s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */
288 
289  overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2);
290  s->pending_buf = (uchf *) overlay;
291  s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(ush)+2L);
292 
293  if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL ||
294  s->pending_buf == Z_NULL) {
295  s->status = FINISH_STATE;
296  strm->msg = ERR_MSG(Z_MEM_ERROR);
297  deflateEnd (strm);
298  return Z_MEM_ERROR;
299  }
300  s->d_buf = overlay + s->lit_bufsize/sizeof(ush);
301  s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize;
302 
303  s->level = level;
304  s->strategy = strategy;
305  s->method = (Byte)method;
306 
307  return deflateReset(strm);
308 }
int ZEXPORT deflateEnd(z_streamp strm)
Definition: deflate.cc:939
uInt hash_bits
Definition: deflate.h:141
unsigned long ulg
Definition: csz_inflate.cc:211
ush FAR ushf
Definition: zutil.h:44
voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, unsigned size)
Definition: zutil.cc:294
Bytef * window
Definition: deflate.h:116
#define MIN_MATCH
Definition: zutil.h:75
uInt hash_mask
Definition: deflate.h:142
ush Pos
Definition: deflate.h:89
uInt hash_shift
Definition: deflate.h:144
Posf * prev
Definition: deflate.h:131
#define Z_STREAM_ERROR
Definition: zlib.h:177
gz_headerp gzhead
Definition: deflate.h:105
#define Z_FIXED
Definition: zlib.h:195
ulg high_water
Definition: deflate.h:266
#define ERR_MSG(err)
Definition: zutil.h:50
#define ZALLOC(strm, items, size)
Definition: zutil.h:244
const XML_Char * s
Definition: expat.h:262
z_streamp strm
Definition: deflate.h:98
Posf * head
Definition: deflate.h:137
#define Z_DEFLATED
Definition: zlib.h:205
uchf * l_buf
Definition: deflate.h:217
Pos FAR Posf
Definition: deflate.h:90
void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr)
Definition: zutil.cc:301
#define Z_MEM_ERROR
Definition: zlib.h:179
Bytef * pending_buf
Definition: deflate.h:100
uInt lit_bufsize
Definition: deflate.h:219
ushf * d_buf
Definition: deflate.h:241
const XML_Char * version
Definition: expat.h:187
#define ZLIB_VERSION
Definition: zlib.h:40
#define FINISH_STATE
Definition: deflate.h:60
#define Z_VERSION_ERROR
Definition: zlib.h:181
unsigned short ush
Definition: csz_inflate.cc:210
ulg pending_buf_size
Definition: deflate.h:101
#define Z_NULL
Definition: zlib.h:208
static constexpr double L
Definition: G4SIunits.hh:124
uch FAR uchf
Definition: zutil.h:42
int ZEXPORT deflateReset(z_streamp strm)
Definition: deflate.cc:411
uInt hash_size
Definition: deflate.h:140
#define Z_DEFAULT_COMPRESSION
Definition: zlib.h:189

Here is the call graph for this function:

Here is the caller graph for this function:

int ZEXPORT deflateInit_ ( z_streamp  strm,
int  level,
const char *  version,
int  stream_size 
)

Definition at line 201 of file deflate.cc.

202 {
203  return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL,
204  Z_DEFAULT_STRATEGY, version, stream_size);
205  /* To do: ignore strm->next_in if we use it as window */
206 }
z_streamp strm
Definition: deflate.h:98
#define Z_DEFLATED
Definition: zlib.h:205
const XML_Char * version
Definition: expat.h:187
#define DEF_MEM_LEVEL
Definition: gzguts.h:142
#define Z_DEFAULT_STRATEGY
Definition: zlib.h:196
int ZEXPORT deflateInit2_(z_streamp strm, int level, int method, int windowBits, int memLevel, int strategy, const char *version, int stream_size)
Definition: deflate.cc:209

Here is the call graph for this function:

int ZEXPORT deflateParams ( z_streamp  strm,
int  level,
int  strategy 
)

Definition at line 465 of file deflate.cc.

466 {
467  deflate_state *s;
468  compress_func func;
469  int err = Z_OK;
470 
471  if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
472  s = strm->state;
473 
474 #ifdef FASTEST
475  if (level != 0) level = 1;
476 #else
477  if (level == Z_DEFAULT_COMPRESSION) level = 6;
478 #endif
479  if (level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED) {
480  return Z_STREAM_ERROR;
481  }
482  func = configuration_table[s->level].func;
483 
484  if ((strategy != s->strategy || func != configuration_table[level].func) &&
485  strm->total_in != 0) {
486  /* Flush the last buffer: */
487  err = deflate(strm, Z_BLOCK);
488  if (err == Z_BUF_ERROR && s->pending == 0)
489  err = Z_OK;
490  }
491  if (s->level != level) {
492  s->level = level;
497  }
498  s->strategy = strategy;
499  return err;
500 }
uInt good_match
Definition: deflate.h:188
#define Z_BLOCK
Definition: zlib.h:169
uInt max_lazy_match
Definition: deflate.h:174
ush good_length
Definition: deflate.cc:118
#define Z_STREAM_ERROR
Definition: zlib.h:177
#define Z_FIXED
Definition: zlib.h:195
const XML_Char * s
Definition: expat.h:262
z_streamp strm
Definition: deflate.h:98
compress_func func
Definition: deflate.cc:122
ush max_chain
Definition: deflate.cc:121
ush max_lazy
Definition: deflate.cc:119
local const config configuration_table[10]
Definition: deflate.cc:131
uInt max_chain_length
Definition: deflate.h:168
int nice_match
Definition: deflate.h:191
int ZEXPORT deflate(z_streamp strm, int flush)
Definition: deflate.cc:627
#define Z_BUF_ERROR
Definition: zlib.h:180
uInt pending
Definition: deflate.h:103
#define Z_OK
Definition: zlib.h:173
#define Z_NULL
Definition: zlib.h:208
ush nice_length
Definition: deflate.cc:120
#define Z_DEFAULT_COMPRESSION
Definition: zlib.h:189

Here is the call graph for this function:

Here is the caller graph for this function:

int ZEXPORT deflatePending ( z_streamp  strm,
unsigned *  pending,
int bits 
)

Definition at line 431 of file deflate.cc.

432 {
433  if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
434  if (pending != Z_NULL)
435  *pending = strm->state->pending;
436  if (bits != Z_NULL)
437  *bits = strm->state->bi_valid;
438  return Z_OK;
439 }
#define Z_STREAM_ERROR
Definition: zlib.h:177
z_streamp strm
Definition: deflate.h:98
uInt pending
Definition: deflate.h:103
#define Z_OK
Definition: zlib.h:173
#define Z_NULL
Definition: zlib.h:208
int ZEXPORT deflatePrime ( z_streamp  strm,
int  bits,
int  value 
)

Definition at line 442 of file deflate.cc.

443 {
444  deflate_state *s;
445  int put;
446 
447  if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
448  s = strm->state;
449  if ((Bytef *)(s->d_buf) < s->pending_out + ((Buf_size + 7) >> 3))
450  return Z_BUF_ERROR;
451  do {
452  put = Buf_size - s->bi_valid;
453  if (put > bits)
454  put = bits;
455  s->bi_buf |= (ush)((value & ((1 << put) - 1)) << s->bi_valid);
456  s->bi_valid += put;
457  _tr_flush_bits(s);
458  value >>= put;
459  bits -= put;
460  } while (bits);
461  return Z_OK;
462 }
Bytef * pending_out
Definition: deflate.h:102
#define Z_STREAM_ERROR
Definition: zlib.h:177
const XML_Char * s
Definition: expat.h:262
#define Buf_size
Definition: deflate.h:51
z_streamp strm
Definition: deflate.h:98
const XML_Char int const XML_Char * value
Definition: expat.h:331
ushf * d_buf
Definition: deflate.h:241
void ZLIB_INTERNAL _tr_flush_bits(deflate_state *s)
Definition: trees.cc:854
unsigned short ush
Definition: csz_inflate.cc:210
#define Z_BUF_ERROR
Definition: zlib.h:180
#define Z_OK
Definition: zlib.h:173
#define Z_NULL
Definition: zlib.h:208

Here is the call graph for this function:

int ZEXPORT deflateReset ( z_streamp  strm)

Definition at line 411 of file deflate.cc.

412 {
413  int ret;
414 
415  ret = deflateResetKeep(strm);
416  if (ret == Z_OK)
417  lm_init(strm->state);
418  return ret;
419 }
int ZEXPORT deflateResetKeep(z_streamp strm)
Definition: deflate.cc:377
local void lm_init(deflate_state *s)
Definition: deflate.cc:1060
z_streamp strm
Definition: deflate.h:98
#define Z_OK
Definition: zlib.h:173

Here is the call graph for this function:

Here is the caller graph for this function:

int ZEXPORT deflateResetKeep ( z_streamp  strm)

Definition at line 377 of file deflate.cc.

378 {
379  deflate_state *s;
380 
381  if (strm == Z_NULL || strm->state == Z_NULL ||
382  strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) {
383  return Z_STREAM_ERROR;
384  }
385 
386  strm->total_in = strm->total_out = 0;
387  strm->msg = Z_NULL; /* use zfree if we ever allocate msg dynamically */
388  strm->data_type = Z_UNKNOWN;
389 
390  s = (deflate_state *)strm->state;
391  s->pending = 0;
392  s->pending_out = s->pending_buf;
393 
394  if (s->wrap < 0) {
395  s->wrap = -s->wrap; /* was made negative by deflate(..., Z_FINISH); */
396  }
397  s->status = s->wrap ? INIT_STATE : BUSY_STATE;
398  strm->adler =
399 #ifdef GZIP
400  s->wrap == 2 ? crc32(0L, Z_NULL, 0) :
401 #endif
402  adler32(0L, Z_NULL, 0);
403  s->last_flush = Z_NO_FLUSH;
404 
405  _tr_init(s);
406 
407  return Z_OK;
408 }
#define INIT_STATE
Definition: deflate.h:54
unsigned long ZEXPORT crc32(unsigned long crc, const unsigned char FAR *buf, uInt len)
Definition: crc32.cc:202
#define Z_NO_FLUSH
Definition: zlib.h:164
void ZLIB_INTERNAL _tr_init(deflate_state *s)
Definition: trees.cc:378
#define Z_UNKNOWN
Definition: zlib.h:202
if(nIso!=0)
uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len)
Definition: adler32.cc:65
Bytef * pending_out
Definition: deflate.h:102
#define Z_STREAM_ERROR
Definition: zlib.h:177
#define BUSY_STATE
Definition: deflate.h:59
const XML_Char * s
Definition: expat.h:262
z_streamp strm
Definition: deflate.h:98
Bytef * pending_buf
Definition: deflate.h:100
uInt pending
Definition: deflate.h:103
#define Z_OK
Definition: zlib.h:173
#define Z_NULL
Definition: zlib.h:208
static constexpr double L
Definition: G4SIunits.hh:124
int last_flush
Definition: deflate.h:108

Here is the call graph for this function:

Here is the caller graph for this function:

int ZEXPORT deflateSetDictionary ( z_streamp  strm,
const Bytef *  dictionary,
uInt  dictLength 
)

Definition at line 311 of file deflate.cc.

312 {
313  deflate_state *s;
314  uInt str, n;
315  int wrap;
316  unsigned avail;
317  z_const unsigned char *next;
318 
319  if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL)
320  return Z_STREAM_ERROR;
321  s = strm->state;
322  wrap = s->wrap;
323  if (wrap == 2 || (wrap == 1 && s->status != INIT_STATE) || s->lookahead)
324  return Z_STREAM_ERROR;
325 
326  /* when using zlib wrappers, compute Adler-32 for provided dictionary */
327  if (wrap == 1)
328  strm->adler = adler32(strm->adler, dictionary, dictLength);
329  s->wrap = 0; /* avoid computing Adler-32 in read_buf */
330 
331  /* if dictionary would fill window, just replace the history */
332  if (dictLength >= s->w_size) {
333  if (wrap == 0) { /* already empty otherwise */
334  CLEAR_HASH(s);
335  s->strstart = 0;
336  s->block_start = 0L;
337  s->insert = 0;
338  }
339  dictionary += dictLength - s->w_size; /* use the tail */
340  dictLength = s->w_size;
341  }
342 
343  /* insert dictionary into window and hash */
344  avail = strm->avail_in;
345  next = strm->next_in;
346  strm->avail_in = dictLength;
347  strm->next_in = (z_const Bytef *)dictionary;
348  fill_window(s);
349  while (s->lookahead >= MIN_MATCH) {
350  str = s->strstart;
351  n = s->lookahead - (MIN_MATCH-1);
352  do {
353  UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]);
354 #ifndef FASTEST
355  s->prev[str & s->w_mask] = s->head[s->ins_h];
356 #endif
357  s->head[s->ins_h] = (Pos)str;
358  str++;
359  } while (--n);
360  s->strstart = str;
361  s->lookahead = MIN_MATCH-1;
362  fill_window(s);
363  }
364  s->strstart += s->lookahead;
365  s->block_start = (long)s->strstart;
366  s->insert = s->lookahead;
367  s->lookahead = 0;
368  s->match_length = s->prev_length = MIN_MATCH-1;
369  s->match_available = 0;
370  strm->next_in = next;
371  strm->avail_in = avail;
372  s->wrap = wrap;
373  return Z_OK;
374 }
#define INIT_STATE
Definition: deflate.h:54
Bytef * window
Definition: deflate.h:116
#define MIN_MATCH
Definition: zutil.h:75
#define UPDATE_HASH(s, h, c)
Definition: deflate.cc:167
uInt match_length
Definition: deflate.h:156
ush Pos
Definition: deflate.h:89
uInt prev_length
Definition: deflate.h:163
uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len)
Definition: adler32.cc:65
Posf * prev
Definition: deflate.h:131
#define Z_STREAM_ERROR
Definition: zlib.h:177
uInt lookahead
Definition: deflate.h:161
const XML_Char * s
Definition: expat.h:262
local void fill_window(deflate_state *s)
Definition: deflate.cc:1336
z_streamp strm
Definition: deflate.h:98
Posf * head
Definition: deflate.h:137
long block_start
Definition: deflate.h:151
int match_available
Definition: deflate.h:158
#define CLEAR_HASH(s)
Definition: deflate.cc:196
uInt strstart
Definition: deflate.h:159
#define Z_OK
Definition: zlib.h:173
#define Z_NULL
Definition: zlib.h:208
static constexpr double L
Definition: G4SIunits.hh:124

Here is the call graph for this function:

int ZEXPORT deflateSetHeader ( z_streamp  strm,
gz_headerp  head 
)

Definition at line 422 of file deflate.cc.

423 {
424  if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
425  if (strm->state->wrap != 2) return Z_STREAM_ERROR;
426  strm->state->gzhead = head;
427  return Z_OK;
428 }
#define Z_STREAM_ERROR
Definition: zlib.h:177
z_streamp strm
Definition: deflate.h:98
Posf * head
Definition: deflate.h:137
#define Z_OK
Definition: zlib.h:173
#define Z_NULL
Definition: zlib.h:208
int ZEXPORT deflateTune ( z_streamp  strm,
int  good_length,
int  max_lazy,
int  nice_length,
int  max_chain 
)

Definition at line 503 of file deflate.cc.

504 {
505  deflate_state *s;
506 
507  if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
508  s = strm->state;
509  s->good_match = good_length;
510  s->max_lazy_match = max_lazy;
511  s->nice_match = nice_length;
512  s->max_chain_length = max_chain;
513  return Z_OK;
514 }
uInt good_match
Definition: deflate.h:188
uInt max_lazy_match
Definition: deflate.h:174
#define Z_STREAM_ERROR
Definition: zlib.h:177
const XML_Char * s
Definition: expat.h:262
z_streamp strm
Definition: deflate.h:98
uInt max_chain_length
Definition: deflate.h:168
int nice_match
Definition: deflate.h:191
#define Z_OK
Definition: zlib.h:173
#define Z_NULL
Definition: zlib.h:208
local void fill_window ( deflate_state s)

Definition at line 1336 of file deflate.cc.

1337 {
1338  unsigned n, m;
1339  Posf *p;
1340  unsigned more; /* Amount of free space at the end of the window. */
1341  uInt wsize = s->w_size;
1342 
1343  Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead");
1344 
1345  do {
1346  more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);
1347 
1348  /* Deal with !@#$% 64K limit: */
1349  if (sizeof(int) <= 2) {
1350  if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
1351  more = wsize;
1352 
1353  } else if (more == (unsigned)(-1)) {
1354  /* Very unlikely, but possible on 16 bit machine if
1355  * strstart == 0 && lookahead == 1 (input done a byte at time)
1356  */
1357  more--;
1358  }
1359  }
1360 
1361  /* If the window is almost full and there is insufficient lookahead,
1362  * move the upper half to the lower one to make room in the upper half.
1363  */
1364  if (s->strstart >= wsize+MAX_DIST(s)) {
1365 
1366  zmemcpy(s->window, s->window+wsize, (unsigned)wsize);
1367  s->match_start -= wsize;
1368  s->strstart -= wsize; /* we now have strstart >= MAX_DIST */
1369  s->block_start -= (long) wsize;
1370 
1371  /* Slide the hash table (could be avoided with 32 bit values
1372  at the expense of memory usage). We slide even when level == 0
1373  to keep the hash table consistent if we switch back to level > 0
1374  later. (Using level 0 permanently is not an optimal usage of
1375  zlib, so we don't care about this pathological case.)
1376  */
1377  n = s->hash_size;
1378  p = &s->head[n];
1379  do {
1380  m = *--p;
1381  *p = (Pos)(m >= wsize ? m-wsize : NIL);
1382  } while (--n);
1383 
1384  n = wsize;
1385 #ifndef FASTEST
1386  p = &s->prev[n];
1387  do {
1388  m = *--p;
1389  *p = (Pos)(m >= wsize ? m-wsize : NIL);
1390  /* If n is not on any hash chain, prev[n] is garbage but
1391  * its value will never be used.
1392  */
1393  } while (--n);
1394 #endif
1395  more += wsize;
1396  }
1397  if (s->strm->avail_in == 0) break;
1398 
1399  /* If there was no sliding:
1400  * strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 &&
1401  * more == window_size - lookahead - strstart
1402  * => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1)
1403  * => more >= window_size - 2*WSIZE + 2
1404  * In the BIG_MEM or MMAP case (not yet supported),
1405  * window_size == input_size + MIN_LOOKAHEAD &&
1406  * strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD.
1407  * Otherwise, window_size == 2*WSIZE so more >= 2.
1408  * If there was sliding, more >= WSIZE. So in all cases, more >= 2.
1409  */
1410  Assert(more >= 2, "more < 2");
1411 
1412  n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more);
1413  s->lookahead += n;
1414 
1415  /* Initialize the hash value now that we have some input: */
1416  if (s->lookahead + s->insert >= MIN_MATCH) {
1417  uInt str = s->strstart - s->insert;
1418  s->ins_h = s->window[str];
1419  UPDATE_HASH(s, s->ins_h, s->window[str + 1]);
1420 #if MIN_MATCH != 3
1421  Call UPDATE_HASH() MIN_MATCH-3 more times
1422 #endif
1423  while (s->insert) {
1424  UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]);
1425 #ifndef FASTEST
1426  s->prev[str & s->w_mask] = s->head[s->ins_h];
1427 #endif
1428  s->head[s->ins_h] = (Pos)str;
1429  str++;
1430  s->insert--;
1431  if (s->lookahead + s->insert < MIN_MATCH)
1432  break;
1433  }
1434  }
1435  /* If the whole input has less than MIN_MATCH bytes, ins_h is garbage,
1436  * but this is not important since only literal bytes will be emitted.
1437  */
1438 
1439  } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0);
1440 
1441  /* If the WIN_INIT bytes after the end of the current data have never been
1442  * written, then zero those bytes in order to avoid memory check reports of
1443  * the use of uninitialized (or uninitialised as Julian writes) bytes by
1444  * the longest match routines. Update the high water mark for the next
1445  * time through here. WIN_INIT is set to MAX_MATCH since the longest match
1446  * routines allow scanning to strstart + MAX_MATCH, ignoring lookahead.
1447  */
1448  if (s->high_water < s->window_size) {
1449  ulg curr = s->strstart + (ulg)(s->lookahead);
1450  ulg init;
1451 
1452  if (s->high_water < curr) {
1453  /* Previous high water mark below current data -- zero WIN_INIT
1454  * bytes or up to end of window, whichever is less.
1455  */
1456  init = s->window_size - curr;
1457  if (init > WIN_INIT)
1458  init = WIN_INIT;
1459  zmemzero(s->window + curr, (unsigned)init);
1460  s->high_water = curr + init;
1461  }
1462  else if (s->high_water < (ulg)curr + WIN_INIT) {
1463  /* High water mark at or above current data, but below current data
1464  * plus WIN_INIT -- zero out to current data plus WIN_INIT, or up
1465  * to end of window, whichever is less.
1466  */
1467  init = (ulg)curr + WIN_INIT - s->high_water;
1468  if (init > s->window_size - s->high_water)
1469  init = s->window_size - s->high_water;
1470  zmemzero(s->window + s->high_water, (unsigned)init);
1471  s->high_water += init;
1472  }
1473  }
1474 
1476  "not enough room for search");
1477 }
local int read_buf(z_streamp strm, Bytef *buf, unsigned size)
Definition: deflate.cc:1033
unsigned long ulg
Definition: csz_inflate.cc:211
Bytef * window
Definition: deflate.h:116
#define MIN_MATCH
Definition: zutil.h:75
#define UPDATE_HASH(s, h, c)
Definition: deflate.cc:167
#define NIL
Definition: deflate.cc:104
ush Pos
Definition: deflate.h:89
const char * p
Definition: xmltok.h:285
#define Assert(cond, msg)
Definition: zutil.h:230
Definition: G4Pair.hh:150
if(nIso!=0)
Posf * prev
Definition: deflate.h:131
void ZLIB_INTERNAL zmemcpy(Bytef *dest, const Bytef *source, uInt len)
Definition: zutil.cc:150
uInt match_start
Definition: deflate.h:160
ulg high_water
Definition: deflate.h:266
uInt lookahead
Definition: deflate.h:161
#define WIN_INIT
Definition: deflate.h:291
#define MAX_DIST(s)
Definition: deflate.h:286
ulg window_size
Definition: deflate.h:126
void ZLIB_INTERNAL zmemzero(Bytef *dest, uInt len)
Definition: zutil.cc:168
#define MIN_LOOKAHEAD
Definition: deflate.h:281
static constexpr double m
Definition: G4SIunits.hh:129
z_streamp strm
Definition: deflate.h:98
Posf * head
Definition: deflate.h:137
Pos FAR Posf
Definition: deflate.h:90
long block_start
Definition: deflate.h:151
#define times
uInt strstart
Definition: deflate.h:159
uInt hash_size
Definition: deflate.h:140

Here is the call graph for this function:

Here is the caller graph for this function:

local void flush_pending ( z_streamp  strm)

Definition at line 605 of file deflate.cc.

606 {
607  unsigned len;
608  deflate_state *s = strm->state;
609 
610  _tr_flush_bits(s);
611  len = s->pending;
612  if (len > strm->avail_out) len = strm->avail_out;
613  if (len == 0) return;
614 
615  zmemcpy(strm->next_out, s->pending_out, len);
616  strm->next_out += len;
617  s->pending_out += len;
618  strm->total_out += len;
619  strm->avail_out -= len;
620  s->pending -= len;
621  if (s->pending == 0) {
622  s->pending_out = s->pending_buf;
623  }
624 }
const XML_Char int len
Definition: expat.h:262
Bytef * pending_out
Definition: deflate.h:102
void ZLIB_INTERNAL zmemcpy(Bytef *dest, const Bytef *source, uInt len)
Definition: zutil.cc:150
const XML_Char * s
Definition: expat.h:262
z_streamp strm
Definition: deflate.h:98
Bytef * pending_buf
Definition: deflate.h:100
void ZLIB_INTERNAL _tr_flush_bits(deflate_state *s)
Definition: trees.cc:854
uInt pending
Definition: deflate.h:103

Here is the call graph for this function:

Here is the caller graph for this function:

local void lm_init ( deflate_state s)

Definition at line 1060 of file deflate.cc.

1061 {
1062  s->window_size = (ulg)2L*s->w_size;
1063 
1064  CLEAR_HASH(s);
1065 
1066  /* Set the default configuration parameters:
1067  */
1072 
1073  s->strstart = 0;
1074  s->block_start = 0L;
1075  s->lookahead = 0;
1076  s->insert = 0;
1077  s->match_length = s->prev_length = MIN_MATCH-1;
1078  s->match_available = 0;
1079  s->ins_h = 0;
1080 #ifndef FASTEST
1081 #ifdef ASMV
1082  match_init(); /* initialize the asm code */
1083 #endif
1084 #endif
1085 }
uInt good_match
Definition: deflate.h:188
unsigned long ulg
Definition: csz_inflate.cc:211
#define MIN_MATCH
Definition: zutil.h:75
uInt max_lazy_match
Definition: deflate.h:174
uInt match_length
Definition: deflate.h:156
uInt prev_length
Definition: deflate.h:163
ush good_length
Definition: deflate.cc:118
uInt lookahead
Definition: deflate.h:161
ulg window_size
Definition: deflate.h:126
ush max_chain
Definition: deflate.cc:121
long block_start
Definition: deflate.h:151
ush max_lazy
Definition: deflate.cc:119
local const config configuration_table[10]
Definition: deflate.cc:131
int match_available
Definition: deflate.h:158
#define CLEAR_HASH(s)
Definition: deflate.cc:196
uInt max_chain_length
Definition: deflate.h:168
int nice_match
Definition: deflate.h:191
uInt strstart
Definition: deflate.h:159
static constexpr double L
Definition: G4SIunits.hh:124
ush nice_length
Definition: deflate.cc:120

Here is the caller graph for this function:

local uInt longest_match ( deflate_state s,
IPos  cur_match 
)

Definition at line 1101 of file deflate.cc.

1102 {
1103  unsigned chain_length = s->max_chain_length;/* max hash chain length */
1104  Bytef *scan = s->window + s->strstart; /* current string */
1105  Bytef *match; /* matched string */
1106  int len; /* length of current match */
1107  int best_len = s->prev_length; /* best match length so far */
1108  int nice_match = s->nice_match; /* stop if match long enough */
1109  IPos limit = s->strstart > (IPos)MAX_DIST(s) ?
1110  s->strstart - (IPos)MAX_DIST(s) : NIL;
1111  /* Stop when cur_match becomes <= limit. To simplify the code,
1112  * we prevent matches with the string of window index 0.
1113  */
1114  Posf *prev = s->prev;
1115  uInt wmask = s->w_mask;
1116 
1117 #ifdef UNALIGNED_OK
1118  /* Compare two bytes at a time. Note: this is not always beneficial.
1119  * Try with and without -DUNALIGNED_OK to check.
1120  */
1121  Bytef *strend = s->window + s->strstart + MAX_MATCH - 1;
1122  ush scan_start = *(ushf*)scan;
1123  ush scan_end = *(ushf*)(scan+best_len-1);
1124 #else
1125  Bytef *strend = s->window + s->strstart + MAX_MATCH;
1126  Byte scan_end1 = scan[best_len-1];
1127  Byte scan_end = scan[best_len];
1128 #endif
1129 
1130  /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16.
1131  * It is easy to get rid of this optimization if necessary.
1132  */
1133  Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
1134 
1135  /* Do not waste too much time if we already have a good match: */
1136  if (s->prev_length >= s->good_match) {
1137  chain_length >>= 2;
1138  }
1139  /* Do not look for matches beyond the end of the input. This is necessary
1140  * to make deflate deterministic.
1141  */
1142  if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead;
1143 
1144  Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
1145 
1146  do {
1147  Assert(cur_match < s->strstart, "no future");
1148  match = s->window + cur_match;
1149 
1150  /* Skip to next match if the match length cannot increase
1151  * or if the match length is less than 2. Note that the checks below
1152  * for insufficient lookahead only occur occasionally for performance
1153  * reasons. Therefore uninitialized memory will be accessed, and
1154  * conditional jumps will be made that depend on those values.
1155  * However the length of the match is limited to the lookahead, so
1156  * the output of deflate is not affected by the uninitialized values.
1157  */
1158 #if (defined(UNALIGNED_OK) && MAX_MATCH == 258)
1159  /* This code assumes sizeof(unsigned short) == 2. Do not use
1160  * UNALIGNED_OK if your compiler uses a different size.
1161  */
1162  if (*(ushf*)(match+best_len-1) != scan_end ||
1163  *(ushf*)match != scan_start) continue;
1164 
1165  /* It is not necessary to compare scan[2] and match[2] since they are
1166  * always equal when the other bytes match, given that the hash keys
1167  * are equal and that HASH_BITS >= 8. Compare 2 bytes at a time at
1168  * strstart+3, +5, ... up to strstart+257. We check for insufficient
1169  * lookahead only every 4th comparison; the 128th check will be made
1170  * at strstart+257. If MAX_MATCH-2 is not a multiple of 8, it is
1171  * necessary to put more guard bytes at the end of the window, or
1172  * to check more often for insufficient lookahead.
1173  */
1174  Assert(scan[2] == match[2], "scan[2]?");
1175  scan++, match++;
1176  do {
1177  } while (*(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
1178  *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
1179  *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
1180  *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
1181  scan < strend);
1182  /* The funny "do {}" generates better code on most compilers */
1183 
1184  /* Here, scan <= window+strstart+257 */
1185  Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
1186  if (*scan == *match) scan++;
1187 
1188  len = (MAX_MATCH - 1) - (int)(strend-scan);
1189  scan = strend - (MAX_MATCH-1);
1190 
1191 #else /* UNALIGNED_OK */
1192 
1193  if (match[best_len] != scan_end ||
1194  match[best_len-1] != scan_end1 ||
1195  *match != *scan ||
1196  *++match != scan[1]) continue;
1197 
1198  /* The check at best_len-1 can be removed because it will be made
1199  * again later. (This heuristic is not always a win.)
1200  * It is not necessary to compare scan[2] and match[2] since they
1201  * are always equal when the other bytes match, given that
1202  * the hash keys are equal and that HASH_BITS >= 8.
1203  */
1204  scan += 2, match++;
1205  Assert(*scan == *match, "match[2]?");
1206 
1207  /* We check for insufficient lookahead only every 8th comparison;
1208  * the 256th check will be made at strstart+258.
1209  */
1210  do {
1211  } while (*++scan == *++match && *++scan == *++match &&
1212  *++scan == *++match && *++scan == *++match &&
1213  *++scan == *++match && *++scan == *++match &&
1214  *++scan == *++match && *++scan == *++match &&
1215  scan < strend);
1216 
1217  Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
1218 
1219  len = MAX_MATCH - (int)(strend - scan);
1220  scan = strend - MAX_MATCH;
1221 
1222 #endif /* UNALIGNED_OK */
1223 
1224  if (len > best_len) {
1225  s->match_start = cur_match;
1226  best_len = len;
1227  if (len >= nice_match) break;
1228 #ifdef UNALIGNED_OK
1229  scan_end = *(ushf*)(scan+best_len-1);
1230 #else
1231  scan_end1 = scan[best_len-1];
1232  scan_end = scan[best_len];
1233 #endif
1234  }
1235  } while ((cur_match = prev[cur_match & wmask]) > limit
1236  && --chain_length != 0);
1237 
1238  if ((uInt)best_len <= s->lookahead) return (uInt)best_len;
1239  return s->lookahead;
1240 }
const XML_Char int len
Definition: expat.h:262
uInt good_match
Definition: deflate.h:188
uInt hash_bits
Definition: deflate.h:141
unsigned long ulg
Definition: csz_inflate.cc:211
ush FAR ushf
Definition: zutil.h:44
Bytef * window
Definition: deflate.h:116
#define NIL
Definition: deflate.cc:104
#define Assert(cond, msg)
Definition: zutil.h:230
uInt prev_length
Definition: deflate.h:163
Posf * prev
Definition: deflate.h:131
uInt match_start
Definition: deflate.h:160
uInt lookahead
Definition: deflate.h:161
#define MAX_DIST(s)
Definition: deflate.h:286
ulg window_size
Definition: deflate.h:126
#define MIN_LOOKAHEAD
Definition: deflate.h:281
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
#define MAX_MATCH
Definition: zutil.h:76
Pos FAR Posf
Definition: deflate.h:90
uInt max_chain_length
Definition: deflate.h:168
int nice_match
Definition: deflate.h:191
unsigned short ush
Definition: csz_inflate.cc:210
uInt strstart
Definition: deflate.h:159
unsigned IPos
Definition: deflate.h:91

Here is the call graph for this function:

Here is the caller graph for this function:

local void putShortMSB OF ( (deflate_state *s, uInt b)  )
local void flush_pending OF ( (z_streamp strm)  )
local int read_buf OF ( (z_streamp strm, Bytef *buf, unsigned size)  )
local uInt longest_match OF ( (deflate_state *s, IPos cur_match)  )
local void putShortMSB ( deflate_state s,
uInt  b 
)

Definition at line 593 of file deflate.cc.

594 {
595  put_byte(s, (Byte)(b >> 8));
596  put_byte(s, (Byte)(b & 0xff));
597 }
#define put_byte(s, c)
Definition: deflate.h:278

Here is the caller graph for this function:

local int read_buf ( z_streamp  strm,
Bytef *  buf,
unsigned  size 
)

Definition at line 1033 of file deflate.cc.

1034 {
1035  unsigned len = strm->avail_in;
1036 
1037  if (len > size) len = size;
1038  if (len == 0) return 0;
1039 
1040  strm->avail_in -= len;
1041 
1042  zmemcpy(buf, strm->next_in, len);
1043  if (strm->state->wrap == 1) {
1044  strm->adler = adler32(strm->adler, buf, len);
1045  }
1046 #ifdef GZIP
1047  else if (strm->state->wrap == 2) {
1048  strm->adler = crc32(strm->adler, buf, len);
1049  }
1050 #endif
1051  strm->next_in += len;
1052  strm->total_in += len;
1053 
1054  return (int)len;
1055 }
const XML_Char int len
Definition: expat.h:262
unsigned long ZEXPORT crc32(unsigned long crc, const unsigned char FAR *buf, uInt len)
Definition: crc32.cc:202
uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len)
Definition: adler32.cc:65
void ZLIB_INTERNAL zmemcpy(Bytef *dest, const Bytef *source, uInt len)
Definition: zutil.cc:150
z_streamp strm
Definition: deflate.h:98

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

local const config configuration_table[10]
Initial value:
= {
{0, 0, 0, 0, deflate_stored},
{4, 4, 8, 4, deflate_fast},
{4, 5, 16, 8, deflate_fast},
{4, 6, 32, 32, deflate_fast},
{4, 4, 16, 16, deflate_slow},
{8, 16, 32, 32, deflate_slow},
{8, 16, 128, 128, deflate_slow},
{8, 32, 128, 256, deflate_slow},
{32, 128, 258, 1024, deflate_slow},
{32, 258, 258, 4096, deflate_slow}}
local block_state deflate_fast(deflate_state *s, int flush)
Definition: deflate.cc:1571
local block_state deflate_slow(deflate_state *s, int flush)
Definition: deflate.cc:1671
local block_state deflate_stored(deflate_state *s, int flush)
Definition: deflate.cc:1509

Definition at line 131 of file deflate.cc.