Beispiel #1
0
        private List <Palette.Swatch> QuantizePixels(int maxColorIndex, int maxColors)
        {
            // Create the priority queue which is sorted by volume descending. This means we always
            // split the largest box in the queue
            CustomHeap <Vbox> customHeap = new CustomHeap <Vbox>(new VboxComparatorVolume());

            // To start, offer a box which contains all of the colors
            customHeap.Offer(new Vbox(0, maxColorIndex));
            // Now go through the boxes, splitting them until we have reached maxColors or there are no
            // more boxes to split
            SplitBoxes(customHeap, maxColors);
            // Finally, return the average colors of the color boxes
            return(GenerateAverageColors(customHeap));
        }
Beispiel #2
0
        private List <Palette.Swatch> GenerateAverageColors(CustomHeap <Vbox> vboxes)
        {
            List <Palette.Swatch> colors = new List <Palette.Swatch>(vboxes.count);

            foreach (Vbox vbox in vboxes)
            {
                Palette.Swatch color = vbox.GetAverageColor();
                if (!ShouldIgnoreColor(color))
                {
                    // As we're averaging a color box, we can still get colors which we do not want, so
                    // we check again here
                    colors.Add(color);
                }
            }

            Tizen.Log.Info("Palette", "Final generated color count = " + colors.Count + "\n");
            return(colors);
        }
Beispiel #3
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.
        ///
        /// param queue PriorityQueue to poll for boxes
        /// param maxSize Maximum amount of boxes to split
        /// </summary>
        private void SplitBoxes(CustomHeap <Vbox> queue, int maxSize)
        {
            int i = 0;

            while (queue.count < maxSize)
            {
                i++;
                Vbox vbox = queue.Poll();
                if (vbox != null && vbox.CanSplit())
                {
                    // First split the box, and offer the result
                    queue.Offer(vbox.SplitBox());
                    // Then offer the box back
                    queue.Offer(vbox);
                }
                else
                {
                    // If we get here then there are no more boxes to split, so return
                    return;
                }
            }
        }