/// <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; } } }
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)); }