/// <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;
        }
Esempio n. 2
0
        internal static Slice Pack([NotNull] CompressedWord[] words, int size, int highest)
        {
            Contract.Requires(size >= 0 && size <= words.Length);

            if (size == 0)
            {             // empty bitmap
                return(Slice.Empty);
            }

            var writer = new SliceWriter(checked ((size + 1) << 2));

            writer.WriteFixed32(CompressedWord.MakeHeader(highest));
            for (int i = 0; i < size; i++)
            {
                writer.WriteFixed32(words[i].RawValue);
            }
            return(writer.ToSlice());
        }