Parse a Hex color ("#RGB", "#RGBA" or "#RRGGBB", "#RRGGBBAA" format) and set this color to
the corresponding r,g,b,a values
@name parseHex
@memberOf me.Color
@function
@param {String} color
@return {me.Color} Reference to this object for method chaining
329942
function (hexColor) {
            // TODO : Memoize this function by caching its input

            var match;
            if ((match = hex8Rx.exec(hexColor))) {
                // #AARRGGBB
                return this.setColor(
                    parseInt(match[1], 16),
                    parseInt(match[2], 16),
                    parseInt(match[3], 16),
                    (me.Math.clamp(parseInt(match[4], 16), 0, 255) / 255.0).toFixed(1)
                );
            }

            if ((match = hex6Rx.exec(hexColor))) {
                // #RRGGBB
                return this.setColor(
                    parseInt(match[1], 16),
                    parseInt(match[2], 16),
                    parseInt(match[3], 16)
                );
            }

            if ((match = hex4Rx.exec(hexColor))) {
                // #ARGB
                return this.setColor(
                    parseInt(match[1] + match[1], 16),
                    parseInt(match[2] + match[2], 16),
                    parseInt(match[3] + match[3], 16),
                    (me.Math.clamp(parseInt(match[4] + match[4], 16), 0, 255) / 255.0).toFixed(1)
                );
            }

            if ((match = hex3Rx.exec(hexColor))) {
                // #RGB
                return this.setColor(
                    parseInt(match[1] + match[1], 16),
                    parseInt(match[2] + match[2], 16),
                    parseInt(match[3] + match[3], 16)
                );
            }

            throw new Error(
                "invalid parameter: " + hexColor
            );
        }
653586
public static GenericColor valueOf(String color) {

    Objects.requireNonNull(color, "color");
    Color namedColor = Color.fromName(color);
    if (namedColor != null) {
      return valueOf(namedColor);
    }
    int length = color.length();
    Throwable cause = null;
    try {
      // "#RRGGBB" / #AARRGGBB
      Color hexColor = Color.parseHexString(color);
      if (hexColor != null) {
        return valueOf(hexColor);
      }
      // "rgb(1,1,1)" = 10
      if (length >= 7) {
        String model = BasicHelper.toUpperCase(color.substring(0, 3));
        ColorModel colorModel = ColorModel.valueOf(model);
        int index = 3;
        boolean hasAlpha = false;
        char c = Character.toLowerCase(color.charAt(index));
        if (c == 'a') {
          hasAlpha = true;
          index++;
          c = color.charAt(index);
        }
        if (c == '(') {
          index++;
          int endIndex = color.indexOf(',', index);
          if (endIndex > 0) {
            String firstSegment = color.substring(index, endIndex).trim();
            index = endIndex + 1;
            endIndex = color.indexOf(',', index);
            if (endIndex > 0) {
              String secondSegment = color.substring(index, endIndex).trim();
              index = endIndex + 1;
              if (hasAlpha) {
                endIndex = color.indexOf(',', index);
              } else {
                endIndex = length - 1;
              }
              if (endIndex > 0) {
                String thirdSegment = color.substring(index, endIndex).trim();
                Alpha alpha;
                if (hasAlpha) {
                  alpha = new Alpha(color.substring(endIndex + 1, length - 1));
                } else {
                  alpha = Alpha.OPAQUE;
                }
                switch (colorModel) {
                  case RGB:
                    return valueOf(new Red(firstSegment), new Green(secondSegment), new Blue(thirdSegment), alpha);
                  case HSL:
                    return valueOf(new Hue(firstSegment), new Saturation(secondSegment), new Lightness(thirdSegment), alpha);
                  case HSV:
                  case HSB:
                    return valueOf(new Hue(firstSegment), new Saturation(secondSegment), new Brightness(thirdSegment), alpha);
                  default :
                    throw new IllegalStateException("" + colorModel);
                }
              }
            }
          }
        }
      }
    } catch (RuntimeException e) {
      cause = e;
    }
    throw new IllegalArgumentException(color, cause);
  }
1127029
def interpret_color(color)
      if color.is_a? String
        # Turns RRGGBB into BBGGRR for hex conversion.
        color = color[-2..-1] << color[2..3] << color[0..1]
        color = color.to_i(16)
      end

      color
    end
81104
function rgbToHex(r, g, b) {
  var integer = ((Math.round(r) & 0xFF) << 16)
    + ((Math.round(g) & 0xFF) << 8)
    + (Math.round(b) & 0xFF);

  var string = integer.toString(16).toUpperCase();
  return '#' + ('000000'.substring(string.length) + string);
}
114181
function hexToRgba (color) {
    var hex   = color[ 0 ] === '#' ? color.substr(1) : color,
      dig   = hex.length / 3,
      red   = hex.substr(0, dig),
      green = hex.substr(dig, dig),
      blue  = hex.substr(dig * 2);
    if (dig === 1) {
      red += red;
      green += green;
      blue += blue;
    }
    return 'rgba(' + parseInt(red, 16) + ',' + parseInt(green, 16) + ',' + parseInt(blue, 16) + ',0.1)';
  }
829496
function (colour, a) {
          // first check if colour is rgb
          var rgb = /^rgb\(([0-9]*),\s?([0-9]*),\s?([0-9]*)\)$/.exec(colour);
          // or check if it is hex
          if (!rgb) rgb = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(colour);
          if (!rgb) return colour;
          for (var i = 0; i <= 3; i++) {
            rgb[i] = parseInt(rgb[i], 16);
          }
          return 'rgba(' + rgb[1] + ', ' + rgb[2] + ', ' + rgb[3] + ', ' + a + ')';
        }
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;
    }
67302
public static String toHex(Color color) {
		String R = Integer.toHexString(color.getRed());
		R = R.length() < 2 ? ('0' + R) : R;
		String G = Integer.toHexString(color.getGreen());
		G = G.length() < 2 ? ('0' + G) : G;
		String B = Integer.toHexString(color.getBlue());
		B = B.length() < 2 ? ('0' + B) : B;
		return '#' + R + G + B;
	}
895542
function _0xColorToHex(color, convertToStr) {
        var hexColor = tinycolor(color.replace("0x", "#"));
        hexColor._format = "0x";

        if (convertToStr) {
            return hexColor.toString();
        }
        return hexColor;
    }
1170957
function(RGBArray) {
    var hex = '#';
    RGBArray.forEach(function(value) {
        if (value < 16) {
            hex += 0;
        }
        hex += value.toString(16);
    });
    return hex;
}
55866
function rgb2hex(rgbarray) {
    var hex = '#'
    rgbarray.forEach( function (dig) {
      dig = dig.toString(16)
      hex += ("00" + dig).substr( dig.length )
    })
    return hex
  }
1243376
function getColorStr(color) {
    var hex = color.hexString();
    var alpha = getAlphaHex(color.alpha());
    var colorStr = '#' + alpha + hex.slice(1);

    return colorStr.toLowerCase();
}
331496
function(color) {
            var normalizedColor = Splunk.util.normalizeColor(color);

            return (normalizedColor) ? parseInt(normalizedColor.replace("#", "0x"), 16) : 0;
        }
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})`
}
162853
function getSingleColor(color)
{
    if (typeof color === 'number')
    {
        return hex2string(color);
    }
    else if ( typeof color === 'string' )
    {
        if ( color.indexOf('0x') === 0 )
        {
            color = color.replace('0x', '#');
        }
    }

    return color;
}
374910
function changeDecColorsToHex(color) {
  return color.replace(decimalColorRx, (colorValue, r, g, b) => {
    const hr = changeDecColorToHex(r);
    const hg = changeDecColorToHex(g);
    const hb = changeDecColorToHex(b);

    return `#${hr}${hg}${hb}`;
  });
}
491087
function rgbToObject(rgb) {
  const isRgba = rgb.toLowerCase().indexOf('rgba') === 0;
  const color = rgb.replace(/ /g, '');
  const result = isRgba ? RGBA_REGEX.exec(color) : RGB_REGEX.exec(color);

  // Safety check, if color is in the wrong format
  if (!result) {
    console.warn(`Plx, ERROR: rgb or rgba color is not in the right format: "${ rgb }"`); // eslint-disable-line
    return null;
  }

  // All color functions are returning { r, g, b, a } object
  return {
    r: parseInt(result[1], 10),
    g: parseInt(result[2], 10),
    b: parseInt(result[3], 10),
    a: isRgba ? parseFloat(result[4]) : 1,
  };
}