/**
  * @dataProvider blendTests
  */
 public function testColorBlend(Color $foreground, Color $background, Color $expectedResult)
 {
     $blender = new AlphaCompositeBlender();
     $result = $blender->blendColors($foreground, $background);
     $this->assertEquals($expectedResult->red(), $result->red());
     $this->assertEquals($expectedResult->green(), $result->green());
     $this->assertEquals($expectedResult->blue(), $result->blue());
     $diff = abs($expectedResult->alpha() - $result->alpha());
     $this->assertLessThan(0.01, $diff);
 }
 public function formatColor(Color $color)
 {
     if ($color->alpha() < 1) {
         return $this->formatColorFunction('rgba', array($color->red(), $color->green(), $color->blue(), round($color->alpha(), 2)));
     } else {
         return $this->formatColorFunction('rgb', array($color->red(), $color->green(), $color->blue()));
     }
 }
 /**
  * Converts BlendedColor objects to Color objects if needed.
  * 
  * @param \OttawaDeveloper\Tools\ColorAnalyzer\Color $color
  * 
  * @return \OttawaDeveloper\Tools\ColorAnalyzer\Color
  */
 private function resolveColor(\OttawaDeveloper\Tools\ColorAnalyzer\Color $color)
 {
     if ($this->useOriginalColors && $color instanceof \OttawaDeveloper\Tools\ColorAnalyzer\BlendedColor) {
         return $color->originalColor();
     } else {
         return $color;
     }
 }
 public function formatColor(\OttawaDeveloper\Tools\ColorAnalyzer\Color $color)
 {
     $colorValues = array('red' => $color->red() / 255, 'green' => $color->green() / 255, 'blue' => $color->blue() / 255);
     $minimumValue = min($colorValues);
     $maximumValue = max($colorValues);
     $luminescence = round(($minimumValue + $maximumValue) / 2, 2);
     if ($minimumValue == $maximumValue) {
         return $this->formatHslColor(0, 0, $luminescence, $color->alpha());
     }
     $colorRange = $maximumValue - $minimumValue;
     $saturation = $colorRange;
     if ($luminescence < 0.5) {
         $saturation /= $maximumValue + $minimumValue;
     } else {
         $saturation /= 2 - $colorRange;
     }
     $hue = 0;
     if ($colorValues['red'] >= $colorValues['blue'] && $colorValues['red'] >= $colorValues['green']) {
         $hue = ($colorValues['green'] - $colorValues['blue']) / $colorRange;
     } elseif ($colorValues['green'] >= $colorValues['blue'] && $colorValues['green'] >= $colorValues['red']) {
         $hue = 2 + ($colorValues['blue'] - $colorValues['red']) / $colorRange;
     } else {
         $hue = 4 + ($colorValues['red'] - $colorValues['green']) / $colorRange;
     }
     return $this->formatHslColor($hue * 60, $saturation, $luminescence, $color->alpha());
 }
 public function formatColor(\OttawaDeveloper\Tools\ColorAnalyzer\Color $color)
 {
     $string = '#';
     $string .= str_pad(dechex($color->red()), 2, '0', STR_PAD_LEFT);
     $string .= str_pad(dechex($color->green()), 2, '0', STR_PAD_LEFT);
     $string .= str_pad(dechex($color->blue()), 2, '0', STR_PAD_LEFT);
     if ($color->alpha() < 1) {
         $string .= str_pad(dechex((int) round($color->alpha() * 255)), 2, '0', STR_PAD_LEFT);
     }
     return strtoupper($string);
 }