coerce a value for use in color operation
482643
protected function coerceColor($value) {
switch($value[0]) {
case 'color': return $value;
case 'raw_color':
$c = array("color", 0, 0, 0);
$colorStr = substr($value[1], 1);
$num = hexdec($colorStr);
$width = strlen($colorStr) == 3 ? 16 : 256;

for ($i = 3; $i > 0; $i--) { // 3 2 1
$t = $num % $width;
$num /= $width;

$c[$i] = $t * (256/$width) + $t * floor(16/$width);
}

return $c;
case 'keyword':
$name = $value[1];
if (isset(self::$cssColors[$name])) {
$rgba = explode(',', self::$cssColors[$name]);

if(isset($rgba[3]))
return array('color', $rgba[0], $rgba[1], $rgba[2], $rgba[3]);

return array('color', $rgba[0], $rgba[1], $rgba[2]);
}
return null;
}
}
898367
def colour=(value)
      if value.nil?
        @colour = nil
      elsif value.is_a? Integer
        raise ArgumentError, 'Embed colour must be 24-bit!' if value >= 16_777_216

        @colour = value
      elsif value.is_a? String
        self.colour = value.delete('#').to_i(16)
      elsif value.is_a? Array
        raise ArgumentError, 'Colour tuple must have three values!' if value.length != 3

        self.colour = value[0] << 16 | value[1] << 8 | value[2]
      else
        self.colour = value.to_i
      end
    end
512891
def hex_color(value):
    '''
    '''
    r = ((value >> (8 * 2)) & 255) / 255.0
    g = ((value >> (8 * 1)) & 255) / 255.0
    b = ((value >> (8 * 0)) & 255) / 255.0
    return (r, g, b)
313901
function (r, g, b) {
            if (r > 255 || g > 255 || b > 255)
                throw "Invalid color component";
            return ((r << 16) | (g << 8) | b).toString(16);
        }
517782
function coerce(name, value) {
  var def = 1
  var result
  var level

  /* istanbul ignore if - Handled by unified in v6.0.0 */
  if (typeof value === 'boolean') {
    result = [value]
  } else if (value == null) {
    result = [def]
  } else if (
    typeof value === 'object' &&
    (typeof value[0] === 'number' ||
      typeof value[0] === 'boolean' ||
      typeof value[0] === 'string')
  ) {
    result = value.concat()
  } else {
    result = [1, value]
  }

  level = result[0]

  if (typeof level === 'boolean') {
    level = level ? 1 : 0
  } else if (typeof level === 'string') {
    if (level === 'off') {
      level = 0
    } else if (level === 'on' || level === 'warn') {
      level = 1
    } else if (level === 'error') {
      level = 2
    } else {
      level = 1
      result = [level, result]
    }
  }

  if (level < 0 || level > 2) {
    throw new Error(
      'Invalid severity `' +
        level +
        '` for `' +
        name +
        '`, ' +
        'expected 0, 1, or 2'
    )
  }

  result[0] = level

  return result
}
1020331
def _user_to_rgba(color, expand=True, clip=False):
    """"""
    if color is None:
        color = np.zeros(4, np.float32)
    if isinstance(color, string_types):
        color = _string_to_rgb(color)
    elif isinstance(color, ColorArray):
        color = color.rgba
    # We have to treat this specially
    elif isinstance(color, (list, tuple)):
        if any(isinstance(c, string_types) for c in color):
            color = [_user_to_rgba(c, expand=expand, clip=clip) for c in color]
            if any(len(c) > 1 for c in color):
                raise RuntimeError('could not parse colors, are they nested?')
            color = [c[0] for c in color]
    color = np.atleast_2d(color).astype(np.float32)
    if color.shape[1] not in (3, 4):
        raise ValueError('color must have three or four elements')
    if expand and color.shape[1] == 3:  # only expand if requested
        color = np.concatenate((color, np.ones((color.shape[0], 1))),
                               axis=1)
    if color.min() < 0 or color.max() > 1:
        if clip:
            color = np.clip(color, 0, 1)
        else:
            raise ValueError("Color values must be between 0 and 1 (or use "
                             "clip=True to automatically clip the values).")
    return color
1317424
function enumIndex(value) {
  if (isBool(value)) {
    if (boolFromValue(value)) {
      return 1;
    } else {
      return 0;
    }
  } else if (isColor(value)) {
    return toEnum(colorEnum(), colorFromValue(value));
  } else if (isDir(value)) {
    return toEnum(dirEnum(), dirFromValue(value));
  } else {
    throw Error('Value should be Bool, Color or Dir.');
  }
}
247595
function isColor(value) {
  return value.r != null
    && value.g != null
    && value.b != null
    && value.a != null
    && value.hex != null;
}
61683
def coerce(cls, key, value):
        """"""
        if isinstance(value, PasswordHash):
            return value
        return super(PasswordHash, cls).coerce(key, value)
89125
def coerce(value):
        
        is_number = lambda x: isinstance(x, (int, float, complex)) #is x an instance of those things
        if isinstance(value, IntervalCell) or issubclass(value.__class__,IntervalCell): 
            #if intervalcell or subclass, return the subclass
            return value
        elif is_number(value):
            return IntervalCell(value, value)
        elif hasattr(value, 'low') and hasattr(value, 'high'):
            # duck type
            assert value.low <= value.high, "Invalid low/high in %s" % str(value)
            return value
        elif isinstance(value, (list, tuple)) and all(map(is_number, value)):
            if len(value) == 1:
                low, high = value[0], value[0]
            elif len(value) == 2:
                low, high = value
            else:
                low, high = min(value), max(value)
            if high < low:
                raise Contradiction("Low must be lte High") 
            return IntervalCell(low, high)
        else:
            raise Exception("Don't know how to coerce %s" % (type(value)))
116466
def red(self, value):
        """"""
        if value != self._red and \
           isinstance(value, int):
            self._red = value
1303381
function Color(value) {
    this.r = 0;
    this.g = 0;
    this.b = 0;
    this.a = null;
    var result = this.fromArray(value) ||
        this.namedColor(value) ||
        this.rgb(value) ||
        this.rgba(value) ||
        this.hex6(value) ||
        this.hex3(value);
}
813922
def colorize(self, col, row, value=None):
        ''

#        colorstack = tuple(c.coloropt for c in self.getColorizers() if wrapply(c.func, self, col, row, value))

        colorstack = []
        for colorizer in self.getColorizers():
            try:
                r = colorizer.func(self, col, row, value)
                if r:
                    colorstack.append(colorizer.coloropt if colorizer.coloropt else r)
            except Exception as e:
                exceptionCaught(e)

        return colors.resolve_colors(tuple(colorstack))
1027654
def color(self, value=None):
        """"""
        if value is None:
            value = self.norm_score
        rgb = Score.value_color(value)
        return rgb
1064044
function(value) {
		// Action is further copy-pasted, same as foreColor

		// "If value is not a valid CSS color, prepend "#" to it."
		//
		// "If value is still not a valid CSS color, or if it is currentColor,
		// abort these steps and do nothing."
		//
		// Cheap hack for testing, no attempt to be comprehensive.
		if (/^([0-9a-fA-F]{3}){1,2}$/.test(value)) {
			value = "#" + value;
		}
		if (!/^(rgba?|hsla?)\(.*\)$/.test(value)
		&& !parseSimpleColor(value)
		&& value.toLowerCase() != "transparent") {
			return;
		}

		// "Set the selection's value to value."
		setSelectionValue("hilitecolor", value);
	}
120149
def coerce(cls, key, value):
        """"""
        if not isinstance(value, MutationList):
            if isinstance(value, list):
                return MutationList(value)

            # this call will raise ValueError
            return Mutable.coerce(key, value)
        else:
            return value
813766
def get_color(value, alpha):
    """"""
    color = QColor()
    for typ in COLORS:
        if isinstance(value, typ):
            color = QColor(COLORS[typ])
    color.setAlphaF(alpha)
    return color