private bool TallyTree(int dist, int lc) { this.pendingBuffer[this.d_buf + this.lastLit * 2] = (byte)Utils.ShiftRight(dist, 8); this.pendingBuffer[this.d_buf + this.lastLit * 2 + 1] = (byte)dist; this.pendingBuffer[this.litBuf + this.lastLit] = (byte)lc; ++this.lastLit; if (dist == 0) { ++this.dyn_ltree[lc * 2]; } else { ++this.matches; --dist; ++this.dyn_ltree[((int)TreeConstants.LengthCode[lc] + 256 + 1) * 2]; ++this.dyn_dtree[CompressionTree.GetDistanceCode(dist) * 2]; } if ((this.lastLit & 8191) == 0 && this.level > 2) { int number = this.lastLit * 8; int num1 = this.strstart - this.blockStart; for (int index = 0; index < 30; ++index) { number = (int)((long)number + (long)this.dyn_dtree[index * 2] * (5L + (long)TreeConstants.ExtraDBits[index])); } int num2 = Utils.ShiftRight(number, 3); if (this.matches < this.lastLit / 2 && num2 < num1 / 2) { return(true); } } return(this.lastLit == this.litBufsize - 1); }
private void CompressBlock(short[] ltree, short[] dtree) { int num1 = 0; if (this.lastLit != 0) { do { int num2 = (int)this.pendingBuffer[this.d_buf + num1 * 2] << 8 & 65280 | (int)this.pendingBuffer[this.d_buf + num1 * 2 + 1] & (int)byte.MaxValue; int c = (int)this.pendingBuffer[this.litBuf + num1] & (int)byte.MaxValue; ++num1; if (num2 == 0) { this.SendCode(c, ltree); } else { int index = (int)TreeConstants.LengthCode[c]; this.SendCode(index + 256 + 1, ltree); int extraLbit = TreeConstants.ExtraLBits[index]; if (extraLbit != 0) { this.SendBits(c - TreeConstants.BaseLength[index], extraLbit); } int distance = num2 - 1; int distanceCode = CompressionTree.GetDistanceCode(distance); this.SendCode(distanceCode, dtree); int extraDbit = TreeConstants.ExtraDBits[distanceCode]; if (extraDbit != 0) { this.SendBits(distance - TreeConstants.BaseDistance[distanceCode], extraDbit); } } }while (num1 < this.lastLit); } this.SendCode(256, ltree); this.last_eob_len = (int)ltree[513]; }