MCPcopy Create free account
hub / github.com/InteractiveComputerGraphics/SPlisHSPlasH / deflateSetDictionary

Function deflateSetDictionary

extern/zlib/src/deflate.c:550–613  ·  view source on GitHub ↗

========================================================================= */

Source from the content-addressed store, hash-verified

548
549/* ========================================================================= */
550int ZEXPORT deflateSetDictionary(z_streamp strm, const Bytef *dictionary,
551 uInt dictLength) {
552 deflate_state *s;
553 uInt str, n;
554 int wrap;
555 unsigned avail;
556 z_const unsigned char *next;
557
558 if (deflateStateCheck(strm) || dictionary == Z_NULL)
559 return Z_STREAM_ERROR;
560 s = strm->state;
561 wrap = s->wrap;
562 if (wrap == 2 || (wrap == 1 && s->status != INIT_STATE) || s->lookahead)
563 return Z_STREAM_ERROR;
564
565 /* when using zlib wrappers, compute Adler-32 for provided dictionary */
566 if (wrap == 1)
567 strm->adler = adler32(strm->adler, dictionary, dictLength);
568 s->wrap = 0; /* avoid computing Adler-32 in read_buf */
569
570 /* if dictionary would fill window, just replace the history */
571 if (dictLength >= s->w_size) {
572 if (wrap == 0) { /* already empty otherwise */
573 CLEAR_HASH(s);
574 s->strstart = 0;
575 s->block_start = 0L;
576 s->insert = 0;
577 }
578 dictionary += dictLength - s->w_size; /* use the tail */
579 dictLength = s->w_size;
580 }
581
582 /* insert dictionary into window and hash */
583 avail = strm->avail_in;
584 next = strm->next_in;
585 strm->avail_in = dictLength;
586 strm->next_in = (z_const Bytef *)dictionary;
587 fill_window(s);
588 while (s->lookahead >= MIN_MATCH) {
589 str = s->strstart;
590 n = s->lookahead - (MIN_MATCH-1);
591 do {
592 UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]);
593#ifndef FASTEST
594 s->prev[str & s->w_mask] = s->head[s->ins_h];
595#endif
596 s->head[s->ins_h] = (Pos)str;
597 str++;
598 } while (--n);
599 s->strstart = str;
600 s->lookahead = MIN_MATCH-1;
601 fill_window(s);
602 }
603 s->strstart += s->lookahead;
604 s->block_start = (long)s->strstart;
605 s->insert = s->lookahead;
606 s->lookahead = 0;
607 s->match_length = s->prev_length = MIN_MATCH-1;

Callers

nothing calls this directly

Calls 3

deflateStateCheckFunction · 0.85
adler32Function · 0.85
fill_windowFunction · 0.85

Tested by

no test coverage detected