ColorThief\ColorThief::sumColors PHP Method

sumColors() private static method

Find the partial sum arrays along the selected axis.
private static sumColors ( string $axis, array $histo, VBox $vBox ) : array
$axis string r|g|b
$histo array
$vBox VBox
return array [$total, $partialSum]
    private static function sumColors($axis, $histo, $vBox)
    {
        $total = 0;
        $partialSum = array();
        // The selected axis should be the first range
        $colorIterateOrder = array_diff(array('r', 'g', 'b'), array($axis));
        array_unshift($colorIterateOrder, $axis);
        // Retrieves iteration ranges
        list($firstRange, $secondRange, $thirdRange) = static::getVBoxColorRanges($vBox, $colorIterateOrder);
        foreach ($firstRange as $firstColor) {
            $sum = 0;
            foreach ($secondRange as $secondColor) {
                foreach ($thirdRange as $thirdColor) {
                    list($red, $green, $blue) = static::rearrangeColors($colorIterateOrder, $firstColor, $secondColor, $thirdColor);
                    $index = static::getColorIndex($red, $green, $blue);
                    if (isset($histo[$index])) {
                        $sum += $histo[$index];
                    }
                }
            }
            $total += $sum;
            $partialSum[$firstColor] = $total;
        }
        return array($total, $partialSum);
    }