// to 0x
or // added

@param string $color Color: FFFFFF, #FFFFFF, 0xFFFFFF or blue
@return string Color
559726
protected function _prepColor($color) {
		if (strpos($color, '#') !== false) {
			return str_replace('#', '0x', $color);
		}
		if (is_numeric($color)) {
			return '0x' . $color;
		}
		return $color;
	}
545177
func colorToFloat32(c color.Color) float32 {
	colorR, colorG, colorB, colorA := c.RGBA()
	colorR >>= 8
	colorG >>= 8
	colorB >>= 8
	colorA >>= 8

	red := colorR
	green := colorG << 8
	blue := colorB << 16
	alpha := colorA << 24

	return math.Float32frombits((alpha | blue | green | red) & 0xfeffffff)
}
108161
public static function name(Color $color): string
    {
        if (!self::hasName($color)) {
            throw new ColorException('No matching CSS color name found for ' . self::hex($color));
        }

        return X11Colors::$colors[$color->getHex()][0];
    }
184515
private static function rgb($color) {

		return (object) [

			'r' => intval(hexdec(substr($color, 0, 2))),
			'g' => intval(hexdec(substr($color, 2, 2))),
			'b' => intval(hexdec(substr($color, 4, 2)))
		];
	}
1061452
private static function hsl($color) {

		$r = intval(hexdec(substr($color, 0, 2))) / 255;
		$g = intval(hexdec(substr($color, 2, 2))) / 255;
		$b = intval(hexdec(substr($color, 4, 2))) / 255;

		$min 	= min($r, $g, $b);
		$max 	= max($r, $g, $b);
		$delta 	= $max - $min;
		$l 		= ($min + $max) / 2;
		$s 		= 0;
		$h 		= 0;

	    if($l > 0 && $l < 1) {
	    	$s = $delta / ($l < 0.5 ? (2 * $l) : (2 - 2 * $l));
	    }

	    if($delta > 0) {

			if($max == $r && $max != $g) { 
				$h += ($g - $b) / $delta;
			}

			if($max == $g && $max != $b) {
				$h += (2 + ($b - $r) / $delta);
			}

			if($max == $b && $max != $r) {
				$h += (4 + ($r - $g) / $delta);
			}

			$h /= 6;
	    }

	    return (object) [

	    	'h' => intval($h * 255), 
	    	's' => intval($s * 255), 
	    	'l' => intval($l * 255)
	    ];
	}
1211014
public static function parseHex($color)
    {
        if (!preg_match('/^#[A-Fa-f0-9]{6}$/', $color)) {
            throw new WrongColorFormatException($color);
        }

        return new Color(
            hexdec(substr($color, 1, 2)),
            hexdec(substr($color, 3, 2)),
            hexdec(substr($color, 5, 2))
        );
    }
1045444
public function validateColor($color)
    {
        $request = new Request('GET', 'color');
        $response = $this->sendRequest($request, [
            'query' => [
                'string' => $color,
            ]
        ]);

        return $response->getBody();
    }
1053933
static public function color($color) {
		if (!is_array($color)) {
			$color = compact('color');
		}

		$color += array('color' => null, 'style' => null, 'background' => null);

		if ($color['color'] == 'reset') {
			return "\033[0m";
		}

		$colors = array();
		foreach (array('color', 'style', 'background') as $type) {
			$code = $color[$type];
			if (isset(self::$_colors[$type][$code])) {
				$colors[] = self::$_colors[$type][$code];
			}
		}

		if (empty($colors)) {
			$colors[] = 0;
		}

		return "\033[" . join(';', $colors) . "m";
	}
1242093
private static function convertHexColorToRtf($color)
    {
        if (strlen($color) == 6) {
            $red    = hexdec(substr($color, 0, 2));
            $green  = hexdec(substr($color, 2, 2));
            $blue   = hexdec(substr($color, 4, 2));

            return '\red' . $red . '\green' . $green . '\blue' . $blue;
        }

        throw new PHPRtfLite_Exception('Color must be a hex number of length 3 or 6 digits! You gave me: #' . $color);
    }
1074940
public static function foreground($color)
    {
        list($red, $green, $blue) = str_split(substr($color, 1), 2);

        $red   = hexdec($red);
        $green = hexdec($green);
        $blue  = hexdec($blue);

        return ($red < 200 && $green < 100 && $blue < 200) ? self::WHITE : self::BLACK;
    }
690761
public static String colorToHex(Color color) {
        return String.format("#%02x%02x%02x", color.getRed(), color.getGreen(), color.getBlue());
    }
815200
public static String toHex(int color) {
		validateRGB(color);
		String hex = Integer.toHexString(color).toUpperCase();
		if (hex.length() == 1) {
			hex = "0" + hex;
		}
		return hex;
	}
437246
public function brightnessDifference(Color $color): float
    {
        $difference = $this->getBrightness() - $color->getBrightness();

        if ($difference < 0) {
            $difference *= -1.0;
        }

        return $difference;
    }
1170909
public function setColor($color)
    {
        if (!empty($color)) {
            $this->color = $this->convertColor($color);
        }

        return $this;
    }
150549
public static function Hex2Rgb( string $color )
   {

      if ( $color[ 0 ] == '#' )
      {
         $color = \substr( $color, 1 );
      }

      if ( \strlen( $color ) == 8 )
      {
         $color = \substr( $color, 2 );
      }

      if ( \strlen( $color ) == 6 )
      {
         $r = $color[ 0 ] . $color[ 1 ];
         $g = $color[ 2 ] . $color[ 3 ];
         $b = $color[ 4 ] . $color[ 5 ];
      }
      else if ( \strlen( $color ) == 3 )
      {
         $r = $color[ 0 ] . $color[ 0 ];
         $g = $color[ 1 ] . $color[ 1 ];
         $b = $color[ 2 ] . $color[ 2 ];
      }
      else if ( \strlen( $color ) == 2 )
      {
         $r = $color;
         $g = $color;
         $b = $color;
      }
      else
      {
         return false;
      }

      return [ \hexdec( $r ), \hexdec( $g ), \hexdec( $b ) ];

   }
1354711
func (c *Colorize) Color(v string) string {
	return colorsRe.ReplaceAllString(c.cliColor.Color(v), "")
}
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;
    }