Same as raw() but RGB values are scaled to 0-255
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))
1128711
function RGBA_TO_CMYK() {
        var r = this.r() / 255;
        var g = this.g() / 255;
        var b = this.b() / 255;
        var black = 1 - Math.max(r, g, b);

        if (black === 0) {
            return kolor.cmyk(0, 0, 0, 0);
        }

        var c = (1 - r - black) / (1 - black);
        var m = (1 - g - black) / (1 - black);
        var y = (1 - b - black) / (1 - black);
        return kolor.cmyk(c, m, y, black, this.a());
    }
634394
def rgb_to_hex(Class, r, g, b):
        """"""
        return ("%2s%2s%2s" % 
                (hex(int(r)).lstrip('0x'), hex(int(g)).lstrip('0x'), hex(int(b)).lstrip('0x'))
            ).replace(' ', '0').upper()
36244
function (x0, y0, width, height, c)
    {
        _c = c || _c
        const data = _c.getImageData(x0, y0, width, height)
        const bits = data.data

        const pixels = []
        for (let y = 0; y < height; y += _scale)
        {
            for (let x = 0; x < width; x += _scale)
            {
                const index = x * 4 + y * width * 4
                if (bits[index + 3] === 0)
                {
                    pixels.push(null)
                }
                else
                {
                    const color = Color.rgbToHex(bits[index], bits[index + 1], bits[index + 2])
                    pixels.push(parseInt(color, 16))
                }
            }
        }
        return pixels
    }
1169532
def normalize_rgb(r, g, b, a):
    
    r = int(r, 10)
    g = int(g, 10)
    b = int(b, 10)
    if a:
        a = float(a) * 256
    if r > 255 or g > 255 or b > 255 or (a and a > 255):
        return None
    color = '#%02x%02x%02x' % (r, g, b)
    if a:
        color += '%02x' % int(a)
    return color
1089117
def hex2rgb(hexval: str, allow_short: bool = False) -> RGB:
    
    if not hexval:
        raise ValueError(
            'Expecting hex string (#RGB, #RRGGBB), got nothing: {!r}'.format(
                hexval
            )
        )
    try:
        hexval = hexval.strip().lstrip('#')
    except AttributeError:
        raise ValueError(
            'Expecting hex string (#RGB, #RRGGBB), got: ({}) {!r}'.format(
                type(hexval).__name__,
                hexval
            )
        )
    if allow_short:
        hexval = fix_hex(hexval)
    if not len(hexval) == 6:
        raise ValueError(
            'Not a length 3 or 6 hex string (#RGB, #RRGGBB), got: {}'.format(
                hexval
            )
        )
    try:
        val = tuple(
            int(''.join(hexval[i:i + 2]), 16)
            for i in range(0, len(hexval), 2)
        )
    except ValueError:
        # Bad hex string.
        raise ValueError('Invalid hex value: {}'.format(hexval))
    # Only needed to satisft typing. `return val` would work fine.
    r, g, b = val
    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
296174
def grayscale?(value)
      r(value) == b(value) && b(value) == g(value)
    end
1332751
function (data, colorFunc, state) {
        var gradientPixels = this._gradientPixels;
        var pixelsSingleState = gradientPixels[state] || (gradientPixels[state] = new Uint8ClampedArray(256 * 4));
        var color = [0, 0, 0, 0];
        var off = 0;
        for (var i = 0; i < 256; i++) {
            colorFunc[state](i / 255, true, color);
            pixelsSingleState[off++] = color[0];
            pixelsSingleState[off++] = color[1];
            pixelsSingleState[off++] = color[2];
            pixelsSingleState[off++] = color[3];
        }
        return pixelsSingleState;
    }
313901
function (r, g, b) {
            if (r > 255 || g > 255 || b > 255)
                throw "Invalid color component";
            return ((r << 16) | (g << 8) | b).toString(16);
        }
433430
def _rgb_to_rgbw(color):
        
        # Get the maximum between R, G, and B
        max_value = max(color)

        # If the maximum value is 0, immediately return pure black.
        if max_value == 0:
            return [0] * 4

        # Figure out what the color with 100% hue is
        multiplier = 255 / max_value
        hue_red = color.R * multiplier
        hue_green = color.G * multiplier
        hue_blue = color.B * multiplier

        # Calculate the whiteness (not strictly speaking luminance)
        max_hue = max(hue_red, hue_green, hue_blue)
        min_hue = min(hue_red, hue_green, hue_blue)
        luminance = ((max_hue + min_hue) / 2 - 127.5) * 2 / multiplier

        # Calculate the output values
        r = max(0, min(255, int(color.R - luminance)))
        g = max(0, min(255, int(color.G - luminance)))
        b = max(0, min(255, int(color.B - luminance)))
        w = max(0, min(255, int(luminance)))

        return [r, g, b, w]
184963
def htmlcolor_to_rgb(str_color):
    
    if not (str_color.startswith('#') and len(str_color) == 7):
        raise ValueError("Bad html color format. Expected: '#RRGGBB' ")
    result = [1.0 * int(n, 16) / 255 for n in (str_color[1:3], str_color[3:5], str_color[5:])]
    return result
878234
def hex_to_rgba(color):
    
    value = str(color).lstrip('#').strip()
    if len(value) == 6:
        rgb = [int(value[i:i + 2], 16) for i in (0, 2, 4)]
        rgba = np.append(rgb, 255).astype(np.uint8)
    else:
        raise ValueError('Only RGB supported')

    return rgba
1064129
function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
    // XXX: Lab input is in the range of [0, 100], [amin, amax], [bmin, bmax]
    // not the usual [0, 1]. If a command like setFillColor is used the src
    // values will already be within the correct range. However, if we are
    // converting an image we have to map the values to the correct range given
    // above.
    // Ls,as,bs <---> L*,a*,b* in the spec
    var Ls = src[srcOffset];
    var as = src[srcOffset + 1];
    var bs = src[srcOffset + 2];
    if (maxVal !== false) {
      Ls = decode(Ls, maxVal, 0, 100);
      as = decode(as, maxVal, cs.amin, cs.amax);
      bs = decode(bs, maxVal, cs.bmin, cs.bmax);
    }

    // Adjust limits of 'as' and 'bs'
    as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
    bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;

    // Computes intermediate variables X,Y,Z as per spec
    var M = (Ls + 16) / 116;
    var L = M + (as / 500);
    var N = M - (bs / 200);

    var X = cs.XW * fn_g(L);
    var Y = cs.YW * fn_g(M);
    var Z = cs.ZW * fn_g(N);

    var r, g, b;
    // Using different conversions for D50 and D65 white points,
    // per http://www.color.org/srgb.pdf
    if (cs.ZW < 1) {
      // Assuming D50 (X=0.9642, Y=1.00, Z=0.8249)
      r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
      g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
      b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
    } else {
      // Assuming D65 (X=0.9505, Y=1.00, Z=1.0888)
      r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
      g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
      b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
    }
    // clamp color values to [0,1] range then convert to [0,255] range.
    dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0;
    dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0;
    dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0;
  }
300043
def colourblind(i):
    '''
        
    '''

    rawRGBs = [(162,200,236),
               (255,128,14),
               (171,171,171),
               (95,158,209),
               (89,89,89),
               (0,107,164),
               (255,188,121),
               (207,207,207),
               (200,82,0),
               (137,137,137)]

    scaledRGBs = []
    for r in rawRGBs:
        scaledRGBs.append((old_div(r[0],255.),old_div(r[1],255.),old_div(r[2],255.)))

    idx = sc.mod(i,len(scaledRGBs))
    return scaledRGBs[idx]
950604
def rgb2rgba(rgb):
    """"""
    rgba = []
    for i in range(0, len(rgb), 3):
        rgba += rgb[i:i+3]
        rgba.append(255)

    return rgba
849193
public static void srgbToLab( double r , double g , double b , double lab[] ) {
		ColorXyz.srgbToXyz(r,g,b,lab);

		double X = lab[0];
		double Y = lab[1];
		double Z = lab[2];


		double xr = X/Xr;
		double yr = Y/Yr;
		double zr = Z/Zr;

		double fx, fy, fz;
		if(xr > epsilon)	fx = Math.pow(xr, 1.0 / 3.0);
		else				fx = (kappa*xr + 16.0)/116.0;
		if(yr > epsilon)	fy = Math.pow(yr, 1.0 / 3.0);
		else				fy = (kappa*yr + 16.0)/116.0;
		if(zr > epsilon)	fz = Math.pow(zr, 1.0 / 3.0);
		else				fz = (kappa*zr + 16.0)/116.0;

		lab[0] = 116.0*fy-16.0;
		lab[1] = 500.0*(fx-fy);
		lab[2] = 200.0*(fy-fz);
	}