コード例 #1
0
        private List <Swatch> QuantizePixels(int maxColors)
        {
            // Create the priority queue which is sorted by volume descending. This means we always
            // split the largest box in the queue
            MaxHeap <Vbox> pq = new MaxHeap <Vbox>(new VBOX_COMPARATOR_VOLUME());

            // To start, offer a box which contains all of the colors
            pq.Add(new Vbox(0, mColors.Length - 1));

            // Now go through the boxes, splitting them until we have reached maxColors or there are no
            // more boxes to split
            SplitBoxes(pq, maxColors);

            // Finally, return the average colors of the color boxes
            return(GenerateAverageColors(pq));
        }
コード例 #2
0
        /// <summary>
        /// Iterate through the Queue, popping ColorCutQuantizer.Vbox objects from the queue and splitting them.
        /// Once split, the new box and the remaining box are offered back to the queue.
        /// </summary>
        /// <param name="queue">PriorityQueue to poll for boxes</param>
        /// <param name="maxSize">Maximum amount of boxes to split</param>
        private void SplitBoxes(MaxHeap <Vbox> queue, int maxSize)
        {
            while (queue.Count < maxSize)
            {
                Vbox vbox = queue.ExtractDominating();

                if (vbox != null && vbox.CanSplit())
                {
                    // First split the box, and offer the result
                    queue.Add(vbox.SplitBox());

                    // Then offer the box back
                    queue.Add(vbox);
                }
                else
                {
                    // If we get here then there are no more boxes to split, so return
                    return;
                }
            }
        }