Calculate luminance value with different strategies.

@param integer $red   The color red.
@param integer $green The color green.
@param integer $blue  The color blue.

@return float $luminance with a value between 0 and 1.
517352
public function getLuminance($red, $green, $blue)
    {
        switch ($this->luminanceStrategy) {
            case 1:
                $luminance = ($red * 0.2126 + $green * 0.7152 + $blue * 0.0722) / 255;
                break;
            case 2:
                $luminance = ($red * 0.299 + $green * 0.587 + $blue * 0.114) / 255;
                break;
            case 3:
                $luminance = sqrt(0.299 * pow($red, 2) + 0.587 * pow($green, 2) + 0.114 * pow($blue, 2)) / 255;
                break;
            case 0:
            default:
                $luminance = ($red + $green + $blue) / (255 * 3);
        }

        return $luminance;
    }
714588
public static String toColor(String red, String green, String blue) {
		return toColorWithAlpha(red, green, blue, null);
	}
256026
public static function fromRgb(int $red, int $green, int $blue): Color
    {
        if (!Validator::isValidRgb($red, $green, $blue)) {
            throw new InvalidColorException('Invalid RGB values');
        }

        return new self($red, $green, $blue);
    }
703736
function allocateColor( $name, $red, $green, $blue )
    {
        if ( isset( $this->Palette[$name] ) )
        {
            eZDebug::writeError( 'Color already defined: ' . $name, __METHOD__ );
            return null;
        }
        $red = max( 0, min( 255, $red ) );
        $green = max( 0, min( 255, $green ) );
        $blue = max( 0, min( 255, $blue ) );
        $color = ImageColorAllocate( $this->ImageObject, $red, $green, $blue );
        $this->Palette[$name] = $color;
        $this->PaletteIndex[] = $color;
        return $color;
    }
1258258
private static function _hue2rgb( $m1, $m2, $h )
	{
		$h = ( $h < 0 ) ? $h + 1 : ( ( $h > 1 ) ? $h - 1 : $h );
		if ( $h * 6 < 1 ) return $m1 + ( $m2 - $m1 ) * $h * 6;
		if ( $h * 2 < 1 ) return $m2;
		if ( $h * 3 < 2 ) return $m1 + ( $m2 - $m1 ) * ( 0.66666 - $h ) * 6;
		return $m1;
	}
898048
public static function rgbToHsl($red, $green, $blue)
    {
        if (\min($red, $green, $blue) < 0) {
            throw new InvalidArgumentException('The parameters for rgbToHsl should be no less than 0');
        }

        if (\max($red, $green, $blue) > 0xFF) {
            throw new InvalidArgumentException('The parameters for rgbToHsl should be no more than 255');
        }

        $clrMin = \min($red, $green, $blue);
        $clrMax = \max($red, $green, $blue);
        $deltaMax = $clrMax - $clrMin;

        $L = ($clrMax + $clrMin) / 510;

        if (0 == $deltaMax) {
            $H = 0;
            $S = 0;
        } else {
            if (0.5 > $L) {
                $S = $deltaMax / ($clrMax + $clrMin);
            } else {
                $S = $deltaMax / (510 - $clrMax - $clrMin);
            }

            if ($clrMax === $red) {
                $H = ($green - $blue) / (6.0 * $deltaMax);

                if (0 > $H) {
                    $H += 1.0;
                }
            } elseif ($clrMax === $green) {
                $H = 1 / 3 + ($blue - $red) / (6.0 * $deltaMax);
            } else {
                $H = 2 / 3 + ($red - $green) / (6.0 * $deltaMax);
            }
        }

        return array(
            (float) ($H * 360 % 360),
            (float) ($S * 100),
            (float) ($L * 100),
        );
    }
172761
public function setCloudsMaximumColor($red, $green, $blue)
    {
        $this->cloudsMaximumColor = floatval($red) . ' ' . floatval($green) . ' ' . floatval($blue);
        return $this;
    }
534601
public function luminosityContrast(Color $color): float
    {
        $colorLuminosity1 = $this->getLuminosity() + 0.05;
        $colorLuminosity2 = $color->getLuminosity() + 0.05;

        return max($colorLuminosity1, $colorLuminosity2) / min($colorLuminosity1, $colorLuminosity2);
    }
927372
public function color($red, $green, $blue)
    {
        $this->writer->getRenderer()->setForegroundColor(new Rgb($red, $green, $blue));

        return $this;
    }
594763
private double doubleValueRightColor( double left, double color ) {
        return rgba( doubleValue( left, red( color ) ), //
                        doubleValue( left, green( color ) ), //
                        doubleValue( left, blue( color ) ), 1 );
    }
1001184
public static function rgbToHsl($r, $g, $b)
    {
        $r /= 255;
        $g /= 255;
        $b /= 255;
        $max = max($r, $g, $b);
        $min = min($r, $g, $b);
        $h = 0;
        $l = ($max + $min) / 2;
        $d = $max - $min;

        if ($d == 0) {
            $h = $s = 0; // achromatic
        } else {
            $s = (1 - abs(2 * $l - 1));
            switch ($max) {
                case $r:
                    $h = 60 * fmod((($g - $b) / $d), 6);
                    if ($b > $g) {
                        $h += 360;
                    }
                    break;
                case $g:
                    $h = 60 * (($b - $r) / $d + 2);
                    break;
                case $b:
                    $h = 60 * (($r - $g) / $d + 4);
                    break;
            }
        }

        return array(round($h, 2), round($s, 2), round($l, 2));
    }
558110
def rgb(self):
        
        (red, green, blue) = self.raw

        return (min(int((red * 255) / self.red_max), 255),
                min(int((green * 255) / self.green_max), 255),
                min(int((blue * 255) / self.blue_max), 255))
496215
public function setCloudsMinimumColor($red, $green, $blue)
    {
        $this->cloudsMinimumColor = floatval($red) . ' ' . floatval($green) . ' ' . floatval($blue);
        return $this;
    }
678258
public function blend(RGBColor $color, $amount)
    {
        return $this->setFromArray(array(
                    min(255, min($this->getRed(), $color->getRed()) + round(abs($color->getRed() - $this->getRed()) * $amount))
                    , min(255, min($this->getGreen(), $color->getGreen()) + round(abs($color->getGreen() - $this->getGreen()) * $amount))
                    , min(255, min($this->getBlue(), $color->getBlue()) + round(abs($color->getBlue() - $this->getBlue()) * $amount))
                    , min(100, min($this->getAlpha(), $color->getAlpha()) + round(abs($color->getAlpha() - $this->getAlpha()) * $amount))
        ));
    }
849714
public static function rgb($red, $green, $blue)
    {
        self::throwIfInvalidColorComponentValue($red);
        self::throwIfInvalidColorComponentValue($green);
        self::throwIfInvalidColorComponentValue($blue);

        return strtoupper(
            self::convertColorComponentToHex($red) .
            self::convertColorComponentToHex($green) .
            self::convertColorComponentToHex($blue)
        );
    }
1216342
public function setFromValue($rgb, $hasalpha = true)
    {
        $r = ($rgb >> 16) & 0xFF;
        $g = ($rgb >> 8) & 0xFF;
        $b = ($rgb >> 0) & 0xFF;
        if ($hasalpha) {
            $a = ($rgb >> 24) & 0xff;

            return $this->setRed($r)
                            ->setGreen($g)
                            ->setBlue($b)
                            ->setAlpha($a);
        }

        return $this->setRed($r)
                        ->setGreen($g)
                        ->setBlue($b);
    }
377743
public function getColorDifference($color1, $color2): int
    {
        return Plugin::$plugin->color->getColorDifference($color1, $color2);
    }