Scales an RGB color object from decimal 0.0-1.0 to int 0-255.
335316
def get_upscaled_value_tuple(self):
        
        # Scale up to 0-255 values.
        rgb_r = int(math.floor(0.5 + self.rgb_r * 255))
        rgb_g = int(math.floor(0.5 + self.rgb_g * 255))
        rgb_b = int(math.floor(0.5 + self.rgb_b * 255))

        return rgb_r, rgb_g, rgb_b
770370
public static float[] cmykFromRgb(int rgbColor) {
        int red = (0xff0000 & rgbColor) >> 16;
        int green = (0xff00 & rgbColor) >> 8;
        int blue = (0xff & rgbColor);
        float black = Math.min(1.0f - red / 255.0f, Math.min(1.0f - green / 255.0f, 1.0f - blue / 255.0f));
        float cyan = 1.0f;
        float magenta = 1.0f;
        float yellow = 1.0f;
        if (black != 1.0f) {
            // black 1.0 causes zero divide
            cyan = (1.0f - (red / 255.0f) - black) / (1.0f - black);
            magenta = (1.0f - (green / 255.0f) - black) / (1.0f - black);
            yellow = (1.0f - (blue / 255.0f) - black) / (1.0f - black);
        }
        return new float[]{cyan, magenta, yellow, black};
    }
109263
public int getColor(float v) {
		int n = (int)(v*255);
		if (n < 0)
			n = 0;
		else if (n > 255)
			n = 255;
		return 0xff000000 | (n << 16) | (n << 8) | n;
	}
256824
def to_rgb(self):
        ''' 

        '''
        from .rgb import RGB # prevent circular import
        r, g, b = colorsys.hls_to_rgb(float(self.h)/360, self.l, self.s)
        return RGB(round(r*255), round(g*255), round(b*255), self.a)
66115
def to_8bit(self):
        
        h, s, v = colorsys.rgb_to_hsv(*self.scale(1))
        # Check if the color is a shade of grey
        if s * v < 0.3:
            if v < 0.3:
                return Color8Bit(Color8Bit.BLACK, False)
            elif v < 0.66:
                return Color8Bit(Color8Bit.BLACK, True)
            elif v < 0.91:
                return Color8Bit(Color8Bit.WHITE, False)
            else:
                return Color8Bit(Color8Bit.WHITE, True)
        # not grey? What color is it then?
        if h < 0.041 or h > 0.92:
            res = Color8Bit.RED
        elif h < 0.11:
            # orange = dark yellow
            return Color8Bit(Color8Bit.YELLOW, False)
        elif h < 0.2:
            res = Color8Bit.YELLOW
        elif h < 0.45:
            res = Color8Bit.GREEN
        elif h < 0.6:
            res = Color8Bit.CYAN
        elif h < 0.74:
            res = Color8Bit.BLUE
        else:
            res = Color8Bit.MAGENTA
        return Color8Bit(res, v > 0.6)
820400
function rgbToRgb(r, g, b){
    return {
        r: bound01(r, 255) * 255,
        g: bound01(g, 255) * 255,
        b: bound01(b, 255) * 255
    };
}
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);
}
1170957
function(RGBArray) {
    var hex = '#';
    RGBArray.forEach(function(value) {
        if (value < 16) {
            hex += 0;
        }
        hex += value.toString(16);
    });
    return hex;
}
759099
def __RGB_to_Hue(var_R, var_G, var_B, var_min, var_max):
    
    if var_max == var_min:
        return 0.0
    elif var_max == var_R:
        return (60.0 * ((var_G - var_B) / (var_max - var_min)) + 360) % 360.0
    elif var_max == var_G:
        return 60.0 * ((var_B - var_R) / (var_max - var_min)) + 120
    elif var_max == var_B:
        return 60.0 * ((var_R - var_G) / (var_max - var_min)) + 240.0
347684
function getColor (i) {
    i = parseInt(i);
    if (i < 0 || i >= colors.length) {
      // pick a color from the scale defined above
      return scale(((i - colors.length) * (211 / 971)) % 1);
    } else {
      return chroma(colors[i]);
    }
  }
253583
def xterm_to_rgb(xcolor):
    
    assert 0 <= xcolor <= 255
    if xcolor < 16:
        # basic colors
        return BASIC16[xcolor]
    elif 16 <= xcolor <= 231:
        # color cube
        xcolor -= 16
        return (CUBE_STEPS[xcolor // 36 % 6],
                CUBE_STEPS[xcolor // 6 % 6],
                CUBE_STEPS[xcolor % 6])
    elif 232 <= xcolor <= 255:
        # gray tone
        c = 8 + (xcolor - 232) * 0x0A
        return (c, c, c)
595758
public static int filterColor(int color, Filter filter) {
        if (filter == Filter.NONE) {
            return color;
        }
        int a = color >>> 24;
        int r = (color >> 16) & 0xFF;
        int g = (color >> 8) & 0xFF;
        int b = color & 0xFF;
        switch (filter) {
            case GRAYSCALE:
                r = g = b = (int) (0.213f * r + 0.715f * g + 0.072f * b);
                break;
            case GRAYSCALE_INVERT:
                r = g = b = 255 - (int) (0.213f * r + 0.715f * g + 0.072f * b);
                break;
            case INVERT:
                r = 255 - r;
                g = 255 - g;
                b = 255 - b;
                break;
        }
        return (a << 24) | (r << 16) | (g << 8) | b;
    }
415947
def _color_name_to_rgb(self, color):
        "  "
        try:
            rgb = int(color, 16)
        except ValueError:
            raise
        else:
            r = (rgb >> 16) & 0xff
            g = (rgb >> 8) & 0xff
            b = rgb & 0xff
            return r, g, b
867386
def rgb2cmy(self, img, whitebg=False):
        """"""
        tmp = img*1.0
        if whitebg:
            tmp = (1.0 - (img - img.min())/(img.max() - img.min()))
        out = tmp*0.0
        out[:,:,0] = (tmp[:,:,1] + tmp[:,:,2])/2.0
        out[:,:,1] = (tmp[:,:,0] + tmp[:,:,2])/2.0
        out[:,:,2] = (tmp[:,:,0] + tmp[:,:,1])/2.0
        return out
948363
private static int toAnsi(long color)
    {
        if (color >= 0) { // an rgb value encoded as in Color.getRGB
            return toAnsi(getRed(color), getGreen(color), getBlue(color));
        }
        else {
            return (int) (-color - 1);
        }
    }
854566
def RGB(self, val):
        """"""
        # need to convert to normalized float
        val = np.atleast_1d(val).astype(np.float32) / 255.
        self.rgba = val
558110
def rgb(self):
        
        (red, green, blue) = self.raw

        return (min(int((red * 255) / self.red_max), 255),
                min(int((green * 255) / self.green_max), 255),
                min(int((blue * 255) / self.blue_max), 255))