Determines if current color is different from given color

@param  AbstractColor $color
@param  int           $tolerance
@return boolean
422117
public function differs(\Intervention\Image\AbstractColor $color, $tolerance = 0)
    {
        $color_tolerance = round($tolerance * 2.55);
        $alpha_tolerance = round($tolerance);

        $delta = [
            'r' => abs($color->getRedValue() - $this->getRedValue()),
            'g' => abs($color->getGreenValue() - $this->getGreenValue()),
            'b' => abs($color->getBlueValue() - $this->getBlueValue()),
            'a' => abs($color->getAlphaValue() - $this->getAlphaValue())
        ];

        return (
            $delta['r'] > $color_tolerance or
            $delta['g'] > $color_tolerance or
            $delta['b'] > $color_tolerance or
            $delta['a'] > $alpha_tolerance
        );
    }
890092
public function getDiff($color)
    {
        if (!$color instanceof Color) {
            $color = new Color($color);
        }
        return pow($this->r - $color->r, 2)
            + pow($this->g - $color->g, 2)
            + pow($this->b - $color->b, 2);
    }
1350686
public function setBackground($color = null)
    {
        if (null === $color) {
            $this->background = null;
            return;
        }
        if (!isset(static::$availableBackgroundColors[$color])) {
            throw new \InvalidArgumentException(sprintf(
                'Invalid background color specified: "%s". Expected one of (%s)',
                $color,
                implode(', ', array_keys(static::$availableBackgroundColors))
            ));
        }
        $this->background = static::$availableBackgroundColors[$color];
    }
994186
public function hasColorSupport(): bool
    {
        if ($this->colorSupport !== null) {
            return $this->colorSupport;
        }
        if (DIRECTORY_SEPARATOR !== '\\') {
            return function_exists('posix_isatty') && posix_isatty(STDOUT);
        } else {
            return getenv('ANSICON') !== false;
        }
    }
518850
public function fg($color)
    {
        Assert::nullOrOneOf($color, self::$colors, 'The color must be null or one of the Style::* color constants. Got: "%s"');

        $this->fgColor = $color;

        return $this;
    }
646325
protected function getColor($im, $color) {
        if ($color === self::COLOR_BG) {
            return $this->colorBg->allocate($im);
        } else {
            return $this->colorFg->allocate($im);
        }
    }
90104
public static function getColorCode($color, $options = array())
    {
        $code = (int) $color;
        if (is_string($color)) {
            $options = array_merge(explode('+', strtolower($color)), $options);
            $color = array_shift($options);
            if (!isset(self::$colors[$color])) {
                throw new ConsoleException("Unknown color '$color'");
            }
            $code = self::$colors[$color];
        }
        foreach ($options as $opt) {
            $opt = strtolower($opt);
            if (!isset(self::$options[$opt])) {
                throw new ConsoleException("Unknown option '$color'");
            }
            $code = $code | self::$options[$opt];
        }
        return $code;
    }
356621
public static function isSupportColor(): bool
    {
        if (DIRECTORY_SEPARATOR === '\\') {
            return
                '10.0.10586' === PHP_WINDOWS_VERSION_MAJOR . '.' . PHP_WINDOWS_VERSION_MINOR . '.' . PHP_WINDOWS_VERSION_BUILD
                || false !== getenv('ANSICON')
                || 'ON' === getenv('ConEmuANSI')
                || 'xterm' === getenv('TERM')// || 'cygwin' === getenv('TERM')
                ;
        }

        if (!\defined('STDOUT')) {
            return false;
        }

        return self::isInteractive(STDOUT);
    }
1045444
public function validateColor($color)
    {
        $request = new Request('GET', 'color');
        $response = $this->sendRequest($request, [
            'query' => [
                'string' => $color,
            ]
        ]);

        return $response->getBody();
    }
712048
public function setColor($color)
	{
		if (is_array($color))
		{
			$this->color[0] = $color[0];
			$this->color[1] = $color[1];
			$this->color[2] = $color[2];
		}
		else
		{
			$color = ltrim($color, '#');

			$this->color[0] = hexdec(substr($color, 0, 2));
			$this->color[1] = hexdec(substr($color, 2, 2));
			$this->color[2] = hexdec(substr($color, 4, 2));
		}

		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))
        ));
    }
1235411
protected function getColorMapOrAsHex(string $color)
    {
        return isset($this->colorMap[$color]) ? $this->colorMap[$color] : $color;
    }
559726
protected function _prepColor($color) {
		if (strpos($color, '#') !== false) {
			return str_replace('#', '0x', $color);
		}
		if (is_numeric($color)) {
			return '0x' . $color;
		}
		return $color;
	}
872894
public function looksBright($color, $threshold = 127.5): bool
    {
        $c = color($color);
        return looks_bright($c, $threshold);
    }
229138
public function colorize($string, $color = null, $bgColor = null)
    {
        return $this->adapter->colorize($string, $color, $bgColor);
    }
65537
protected static function getMixedColorAsRgb($color)
	{
		if (is_array($color)) {
			if (!static::validateRgbColor($color)) return false;
			return $color;
		} else {
			return static::hexToRgb($color);
		}
	}
1337893
private static function _readColor($color,$palette,$version)
	{
		if ($color <= 0x07 || $color >= 0x40) {
			// special built-in color
			return self::_mapBuiltInColor($color);
		} elseif (isset($palette) && isset($palette[$color - 8])) {
			// palette color, color index 0x08 maps to pallete index 0
			return $palette[$color - 8];
		} else {
			// default color table
			if ($version == self::XLS_BIFF8) {
				return self::_mapColor($color);
			} else {
				// BIFF5
				return self::_mapColorBIFF5($color);
			}
		}

		return $color;
	}