Create a color from the hex representation
@param hexValue e.g. "#123456"
@return the color
171961
public static Color fromString(final String hexValue) {
        if (ColorHelper.helper == null)
            ColorHelper.helper = new ColorHelper();
        return ColorHelper.helper.getFromString(hexValue);
    }
597799
function() {
           
            var hex = this.get(this.OPT.HEX),
                l   = hex.length,
                c,i,rgb;

            // support #369 -> #336699 shorthand
            if (l === 3) {
                c = hex.split("");
                for (i=0; i<l; i=i+1) {
                    c[i] = c[i] + c[i];
                }

                hex = c.join("");
            }

            if (hex.length !== 6) {
                this.logger.log(this.get(this.TXT.ILLEGAL_HEX), "error");
                return false;
            }

            rgb = Color.hex2rgb(hex);

            this.logger.log(sub("Hex value set to {hex} ({rgb})", {
                    hex: hex, rgb: rgb
                }));

            this.setValue(rgb);
        }
617772
def color=(hex)
      valid_colors = Type::Color.constants.map { |c| Type::Color.const_get(c) }
      unless hex.nil? || valid_colors.include?(hex.to_s.downcase)
        raise ArgumentError, "Unable to set color to an invalid color.\nUse one of #{valid_colors}"
      end

      @color = hex
    end
36459
function _retrieveColor(palette, color, hue = '500', format) {
    if (typeof palette !== 'string' || typeof color !== 'string' || typeof hue !== 'string' || typeof format !== 'string') {
        throw new TypeError('Expected a string');
    }

    let hexColor;
    let result;

    try {
        hexColor = (palette === 'md') ? colors[palette][color][hue].hex : colors[palette][color];

        switch (format) {
            case 'rgb':
                result = _toRGB(hexColor);
                result = `rgb(${result.r}, ${result.g}, ${result.b})`;
                break;
            case 'hex':
                result = `#${hexColor}`;
                break;
            case 'raw':
                result = _toRGB(hexColor);
                result.hex = hexColor;
                break;
            default:
        }
    } catch (err) {
        throw new RangeError('No matching color.');
    }
    return result;
}
28487
public static PactDslJsonRootValue hexValue() {
    PactDslJsonRootValue value = new PactDslJsonRootValue();
    value.generators.addGenerator(Category.BODY, "", new RandomHexadecimalGenerator(10));
    value.setValue("1234a");
    value.setMatcher(value.regexp("[0-9a-fA-F]+"));
    return value;
  }
1047932
public static byte[] hexToBytes(char[] hex)
    {
        int length = hex.length / 2;
        byte[] raw = new byte[length];
        for (int i = 0; i < length; i++)
        {
            int high = Character.digit(hex[i * 2], 16);
            int low = Character.digit(hex[i * 2 + 1], 16);
            int value = (high << 4) | low;
            if (value > 127)
            {
                value -= 256;
            }
            raw[i] = (byte) value;
        }
        return raw;
    }
552975
public static Long hexToLongObject(@Nullable String str, Long defaultValue) {
		if (StringUtils.isEmpty(str)) {
			return defaultValue;
		}
		try {
			return Long.decode(str);
		} catch (final NumberFormatException nfe) {
			return defaultValue;
		}
	}
393366
def hex2rgb(h):
    
    if not h.startswith('#') or len(h) != 7:
        raise ValueError("Does not look like a hex color: '{0}'".format(h))
    return ','.join(map(str, (
        int(h[1:3], 16),
        int(h[3:5], 16),
        int(h[5:7], 16),
    )))
1243376
function getColorStr(color) {
    var hex = color.hexString();
    var alpha = getAlphaHex(color.alpha());
    var colorStr = '#' + alpha + hex.slice(1);

    return colorStr.toLowerCase();
}
1029607
function(color, alpha) {
            var colorAsHex = (typeof color === "number") ? color : this.hexFromColor(color);
            return this.colorFromHex(colorAsHex, alpha);
        }
247724
public static String processColor(String color) {
    	log.info("Process Color [{}].", color);
    	String colorRtn = null;
    	if (StringUtils.isNotBlank(color)) {
    		HSSFColor poiColor = null;
    		// #rgb -> #rrggbb
    		if (color.matches(COLOR_PATTERN_VALUE_SHORT)) {
    			log.debug("Short Hex Color [{}] Found.", color);
    			StringBuffer sbColor = new StringBuffer();
    			Matcher m = Pattern.compile("([a-f]|\\d)").matcher(color);
    			while (m.find()) {
    				m.appendReplacement(sbColor, "$1$1");
    			}
    			colorRtn = sbColor.toString();
    			log.debug("Translate Short Hex Color [{}] To [{}].", color, colorRtn);
    		}
    		// #rrggbb
    		else if (color.matches(COLOR_PATTERN_VALUE_LONG)) {
    			colorRtn = color;
    			log.debug("Hex Color [{}] Found, Return.", color);
    		}
    		// rgb(r, g, b)
    		else if (color.matches(COLOR_PATTERN_RGB)) {
    			Matcher m = Pattern.compile(COLOR_PATTERN_RGB).matcher(color);
    			if (m.matches()) {
    				log.debug("RGB Color [{}] Found.", color);
    				colorRtn = convertColor(calcColorValue(m.group(2)),
    							calcColorValue(m.group(3)),
    							calcColorValue(m.group(4)));
    				log.debug("Translate RGB Color [{}] To Hex [{}].", color, colorRtn);
    			}
    		}
    		// color name, red, green, ...
    		else if ((poiColor = getColor(color)) != null) {
    			log.debug("Color Name [{}] Found.", color);
    			short[] t = poiColor.getTriplet();
    			colorRtn = convertColor(t[0], t[1], t[2]);
    			log.debug("Translate Color Name [{}] To Hex [{}].", color, colorRtn);
    		}
    	}
    	return colorRtn;
    }
904641
function convertHexToRGB(color) {
  if (color.length === 4) {
    let extendedColor = '#'
    for (let i = 1; i < color.length; i++)
      extendedColor += color.charAt(i) + color.charAt(i)
    color = extendedColor
  }

  const values = {
    r: parseInt(color.substr(1, 2), 16),
    g: parseInt(color.substr(3, 2), 16),
    b: parseInt(color.substr(5, 2), 16)
  }

  return `rgb(${values.r}, ${values.g}, ${values.b})`
}
477047
private static Colour  parseColour(String val) throws SVGParseException
   {
      if (val.charAt(0) == '#')
      {
         IntegerParser  ip = IntegerParser.parseHex(val, 1, val.length());
         if (ip == null) {
            throw new SVGParseException("Bad hex colour value: "+val);
         }
         int  pos = ip.getEndPos();
         int  h1, h2, h3, h4;
         switch (pos) {
            case 4:
               int threehex = ip.value();
               h1 = threehex & 0xf00;  // r
               h2 = threehex & 0x0f0;  // g
               h3 = threehex & 0x00f;  // b
               return new Colour(0xff000000|h1<<12|h1<<8|h2<<8|h2<<4|h3<<4|h3);
            case 5:
               int fourhex = ip.value();
               h1 = fourhex & 0xf000;  // r
               h2 = fourhex & 0x0f00;  // g
               h3 = fourhex & 0x00f0;  // b
               h4 = fourhex & 0x000f;  // alpha
               return new Colour(h4<<28|h4<<24 | h1<<8|h1<<4 | h2<<4|h2 | h3|h3>>4);
            case 7:
               return new Colour(0xff000000 | ip.value());
            case 9:
               return new Colour(ip.value() << 24 | ip.value() >>> 8);
            default:
               // Hex value had bad length for a colour
               throw new SVGParseException("Bad hex colour value: "+val);
         }
      }

      String   valLowerCase = val.toLowerCase(Locale.US);
      boolean  isRGBA = valLowerCase.startsWith("rgba(");
      if (isRGBA || valLowerCase.startsWith("rgb("))
      {
         TextScanner  scan = new TextScanner(val.substring(isRGBA ? 5 : 4));
         scan.skipWhitespace();

         float  red = scan.nextFloat();
         if (!Float.isNaN(red) && scan.consume('%'))
            red = (red * 256) / 100;

         float  green = scan.checkedNextFloat(red);
         if (!Float.isNaN(green) && scan.consume('%'))
            green = (green * 256) / 100;

         float  blue = scan.checkedNextFloat(green);
         if (!Float.isNaN(blue) && scan.consume('%'))
            blue = (blue * 256) / 100;

         if (isRGBA) {
            float  alpha = scan.checkedNextFloat(blue);
            scan.skipWhitespace();
            if (Float.isNaN(alpha) || !scan.consume(')'))
               throw new SVGParseException("Bad rgba() colour value: "+val);
            return new Colour( clamp255(alpha * 256)<<24 | clamp255(red)<<16 | clamp255(green)<<8 | clamp255(blue) );
         } else {
            scan.skipWhitespace();
            if (Float.isNaN(blue) || !scan.consume(')'))
               throw new SVGParseException("Bad rgb() colour value: "+val);
            return new Colour( 0xff000000 | clamp255(red)<<16 | clamp255(green)<<8 | clamp255(blue) );
         }
      }
      else
      {
         boolean  isHSLA = valLowerCase.startsWith("hsla(");
         if (isHSLA || valLowerCase.startsWith("hsl("))
         {
            TextScanner  scan = new TextScanner(val.substring(isHSLA ? 5 : 4));
            scan.skipWhitespace();

            float  hue = scan.nextFloat();

            float  saturation = scan.checkedNextFloat(hue);
            if (!Float.isNaN(saturation))
               scan.consume('%');

            float  lightness = scan.checkedNextFloat(saturation);
            if (!Float.isNaN(lightness))
               scan.consume('%');

            if (isHSLA) {
               float alpha = scan.checkedNextFloat(lightness);
               scan.skipWhitespace();
               if (Float.isNaN(alpha) || !scan.consume(')'))
                  throw new SVGParseException("Bad hsla() colour value: "+val);
               return new Colour( clamp255(alpha * 256)<<24 | hslToRgb(hue, saturation, lightness) );
            } else {
               scan.skipWhitespace();
               if (Float.isNaN(lightness) || !scan.consume(')'))
                  throw new SVGParseException("Bad hsl() colour value: "+val);
               return new Colour( 0xff000000 | hslToRgb(hue, saturation, lightness) );
            }
         }
      }

      // Must be a colour keyword
      return parseColourKeyword(valLowerCase);
   }
937899
public static byte[] hexToBinary(String hexValue) throws IllegalArgumentException {
        Utils.require(hexValue.length() % 2 == 0,
                      "Invalid hex value (must be a multiple of 2 chars): " + hexValue);
        return DatatypeConverter.parseHexBinary(hexValue);
    }
87472
def hex_to_rgb(self, h):
        """"""
        rgb = (self.hex_to_red(h), self.hex_to_green(h), self.hex_to_blue(h))
        return rgb
270724
static public Value colorValue(String name, Color currentValue) {
		return new DefaultValue(name, EffectUtil.toString(currentValue)) {
			public void showDialog () {
				Color newColor = JColorChooser.showDialog(null, "Choose a color", EffectUtil.fromString(value));
				if (newColor != null) value = EffectUtil.toString(newColor);
			}

			public Object getObject () {
				return EffectUtil.fromString(value);
			}
		};
	}
762083
function rgb(hexStr) {
  const hex = hexStr.replace(/^#/, '');
  const fullHex = hex.length === 3
    ? `${hex[0]}${hex[0]}${hex[1]}${hex[1]}${hex[2]}${hex[2]}`
    : hex;

  const num = parseInt(fullHex, 16);
  // eslint-disable-next-line no-bitwise, no-mixed-operators
  return [num >> 16, num >> 8 & 255, num & 255].join(', ');
}