public int EndDeflate() { if (Dstate == null) { throw new ZlibException("No Deflate State!"); } Dstate = null; return(ZlibConstants.ZOk);; }
private int _InternalInitializeDeflate(bool wantRfc1950Header) { if (Istate != null) { throw new ZlibException("You may not call InitializeDeflate() after calling InitializeInflate()."); } Dstate = new DeflateManager { WantRfc1950HeaderBytes = wantRfc1950Header }; return(Dstate.Initialize(this, CompressLevel, WindowBits, Strategy)); }
internal void Gen_bitlen(DeflateManager s) { var tree = DynTree; var stree = StaticTree.treeCodes; var extra = StaticTree.extraBits; var baseRenamed = StaticTree.extraBase; var maxLength = StaticTree.maxLength; int h; int n; int bits; var overflow = 0; for (bits = 0; bits <= InternalConstants.MAX_BITS; bits++) { s.BlCount[bits] = 0; } tree[s.Heap[s.HeapMax] * 2 + 1] = 0; for (h = s.HeapMax + 1; h < HeapSize; h++) { n = s.Heap[h]; bits = tree[tree[n * 2 + 1] * 2 + 1] + 1; if (bits > maxLength) { bits = maxLength; overflow++; } tree[n * 2 + 1] = (short)bits; if (n > MaxCode) { continue; } s.BlCount[bits]++; var xbits = 0; if (n >= baseRenamed) { xbits = extra[n - baseRenamed]; } var f = tree[n * 2]; s.OptLen += f * (bits + xbits); if (stree != null) { s.StaticLen += f * (stree[n * 2 + 1] + xbits); } } if (overflow == 0) { return; } do { bits = maxLength - 1; while (s.BlCount[bits] == 0) { bits--; } s.BlCount[bits]--; s.BlCount[bits + 1] = (short)(s.BlCount[bits + 1] + 2); s.BlCount[maxLength]--; overflow -= 2; } while (overflow > 0); for (bits = maxLength; bits != 0; bits--) { n = s.BlCount[bits]; while (n != 0) { var m = s.Heap[--h]; if (m > MaxCode) { continue; } if (tree[m * 2 + 1] != bits) { s.OptLen = (int)(s.OptLen + (bits - (long)tree[m * 2 + 1]) * tree[m * 2]); tree[m * 2 + 1] = (short)bits; } n--; } } }
internal void Build_tree(DeflateManager s) { var tree = DynTree; var stree = StaticTree.treeCodes; var elems = StaticTree.elems; int n; var maxCode = -1; int node; s.HeapLen = 0; s.HeapMax = HeapSize; for (n = 0; n < elems; n++) { if (tree[n * 2] != 0) { s.Heap[++s.HeapLen] = maxCode = n; s.Depth[n] = 0; } else { tree[n * 2 + 1] = 0; } } while (s.HeapLen < 2) { node = s.Heap[++s.HeapLen] = maxCode < 2 ? ++maxCode : 0; tree[node * 2] = 1; s.Depth[node] = 0; s.OptLen--; if (stree != null) { s.StaticLen -= stree[node * 2 + 1]; } } MaxCode = maxCode; for (n = s.HeapLen / 2; n >= 1; n--) { s.Pqdownheap(tree, n); } node = elems; do { n = s.Heap[1]; s.Heap[1] = s.Heap[s.HeapLen--]; s.Pqdownheap(tree, 1); var m = s.Heap[1]; s.Heap[--s.HeapMax] = n; s.Heap[--s.HeapMax] = m; tree[node * 2] = unchecked ((short)(tree[n * 2] + tree[m * 2])); s.Depth[node] = (sbyte)(Math.Max((byte)s.Depth[n], (byte)s.Depth[m]) + 1); tree[n * 2 + 1] = tree[m * 2 + 1] = (short)node; s.Heap[1] = node++; s.Pqdownheap(tree, 1); } while (s.HeapLen >= 2); s.Heap[--s.HeapMax] = s.Heap[1]; Gen_bitlen(s); Gen_codes(tree, maxCode, s.BlCount); }