private static function quantizeIter(&$priorityQueue, $target, $histo)
{
$nColors = 1;
$nIterations = 0;
while ($nIterations < static::MAX_ITERATIONS) {
$vBox = $priorityQueue->pop();
if (!$vBox->count()) {
/* just put it back */
$priorityQueue->push($vBox);
$nIterations++;
continue;
}
// do the cut
$vBoxes = static::medianCutApply($histo, $vBox);
if (!(is_array($vBoxes) && isset($vBoxes[0]))) {
// echo "vbox1 not defined; shouldn't happen!"."\n";
return;
}
$priorityQueue->push($vBoxes[0]);
if (isset($vBoxes[1])) {
/* vbox2 can be null */
$priorityQueue->push($vBoxes[1]);
$nColors++;
}
if ($nColors >= $target) {
return;
}
if ($nIterations++ > static::MAX_ITERATIONS) {
// echo "infinite loop; perhaps too few pixels!"."\n";
return;
}
}
}