/// <summary>Flush the state and update the header</summary> /// <returns>Slice contained the finished compressed bitmap</returns> /// <remarks>You cannot write any more words after Packing, until <see cref="Reset"/> is called.</remarks> public void Pack() { if (m_packed) { ThrowAlreadyPacked(); } // flush any pending word Flush(); if (m_words == 0) { // empty! m_bounds = BitRange.Empty; // there will be no header m_writer.Position = m_head; } else { // we need to find the lowest and highest bits m_bounds = CompressedBitmap.ComputeBounds(m_writer.ToMutableSlice(), m_words); // update the header int p; m_writer.Rewind(out p, m_head); //the last word is either a literal, or a 1-bit filler m_writer.WriteFixed32(CompressedWord.MakeHeader(m_bounds.Highest)); m_writer.Position = p; } m_packed = true; }