Conversion from normalized RGB into XYZ.  Normalized RGB values have a range of 0:1
554458
public static void srgbToXyz( double r , double g , double b , double xyz[] ) {
		xyz[0] = 0.412453*r + 0.35758*g + 0.180423*b;
		xyz[1] = 0.212671*r + 0.71516*g + 0.072169*b;
		xyz[2] = 0.019334*r + 0.119193*g + 0.950227*b;
	}
647938
function adobe_rgb_to_xyz (r, g, b) {
	// matrix is from http://www.brucelindbloom.com/
	var x = r * 0.576700 + g * 0.185556 + b * 0.188212;
	var y = r * 0.297361 + g * 0.627355 + b * 0.0752847;
	var z = r * 0.0270328 + g * 0.0706879 + b * 0.991248;

	return {
		x: x, y: y, z: z
	};
}
650872
def rgb_to_hex(rgba):
    
    rgba = rgba.split('/')
    hex_value = '#' + rgba[0][:2] + rgba[1][:2] + rgba[2][:2]
    return hex_value
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)
1001480
def convertColor(value):
    
    s = value

    if s in colors:
        s = colors[s]

    rgbpMatch = rgbp.match(s)
    if rgbpMatch is not None:
        r = int(float(rgbpMatch.group(1)) * 255.0 / 100.0)
        g = int(float(rgbpMatch.group(2)) * 255.0 / 100.0)
        b = int(float(rgbpMatch.group(3)) * 255.0 / 100.0)
        s = '#%02x%02x%02x' % (r, g, b)
    else:
        rgbMatch = rgb.match(s)
        if rgbMatch is not None:
            r = int(rgbMatch.group(1))
            g = int(rgbMatch.group(2))
            b = int(rgbMatch.group(3))
            s = '#%02x%02x%02x' % (r, g, b)

    if s[0] == '#':
        s = s.lower()
        if len(s) == 7 and s[1] == s[2] and s[3] == s[4] and s[5] == s[6]:
            s = '#' + s[1] + s[3] + s[5]

    return s
820948
def hsl_to_rgb(arr):
    
    H, S, L = arr.T
    
    H = (H.copy()/255.0) * 360
    S = S.copy()/255.0
    L = L.copy()/255.0
    
    C = (1 - np.absolute(2 * L - 1)) * S

    Hp = H / 60.0
    X = C * (1 - np.absolute(np.mod(Hp, 2) - 1))

    # initilize with zero
    R = np.zeros(H.shape, float)
    G = np.zeros(H.shape, float)
    B = np.zeros(H.shape, float)

    # handle each case:

    mask = (Hp >= 0) == ( Hp < 1)
    R[mask] = C[mask]
    G[mask] = X[mask]

    mask = (Hp >= 1) == ( Hp < 2)
    R[mask] = X[mask]
    G[mask] = C[mask]

    mask = (Hp >= 2) == ( Hp < 3)
    G[mask] = C[mask]
    B[mask] = X[mask]

    mask = (Hp >= 3) == ( Hp < 4)
    G[mask] = X[mask]
    B[mask] = C[mask]

    mask = (Hp >= 4) == ( Hp < 5)
    R[mask] = X[mask]
    B[mask] = C[mask]

    mask = (Hp >= 5) == ( Hp < 6)
    R[mask] = C[mask]
    B[mask] = X[mask]

    m = L - 0.5*C
    R += m
    G += m
    B += m

    R *= 255.0
    G *= 255.0
    B *= 255.0

    return np.array((R.astype(int),G.astype(int),B.astype(int))).T
818439
def rgb_to_srgba(rgb)
      rgb << rgb if rgb.size == 3
      [
        rgb.slice(0,2).to_i(16) / 255.0,
        rgb.slice(2,2).to_i(16) / 255.0,
        rgb.slice(4,2).to_i(16) / 255.0
      ]
    end
788985
def rgb2lab(color)
      r, g, b = color.r * 255, color.g * 255, color.b * 255
      r = rgb_xyz r
      g = rgb_xyz g
      b = rgb_xyz b
      x = xyz_lab (0.4124564 * r + 0.3575761 * g + 0.1804375 * b) / X
      y = xyz_lab (0.2126729 * r + 0.7151522 * g + 0.0721750 * b) / Y
      z = xyz_lab (0.0193339 * r + 0.1191920 * g + 0.9503041 * b) / Z
      [116 * y - 16, 500 * (x - y), 200 * (y - z)]
    end
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
335508
def hex_to_xy(self, h):
        
        rgb = self.color.hex_to_rgb(h)
        return self.rgb_to_xy(rgb[0], rgb[1], rgb[2])
386295
def to_rgb
      chroma = (1 - (2 * @l - 1).abs) * @s
      x = chroma * (1 - ((@h / 60.0) % 2.0 - 1).abs)
      m = @l - chroma / 2.0

      rgb = if @h.zero?
              Color.new(0, 0, 0)
            elsif @h > 0 && @h < 60
              Color.new(chroma, x, 0)
            elsif @h > 60 && @h < 120
              Color.new(x, chroma, 0)
            elsif @h > 120 && @h < 180
              Color.new(0, chroma, x)
            elsif @h > 180 && @h < 240
              Color.new(0, x, chroma)
            elsif @h > 240 && @h < 300
              Color.new(x, 0, chroma)
            else
              Color.new(chroma, 0, x)
            end
      Color.new(((rgb.red + m) * 255.0).round, ((rgb.green + m) * 255.0).round, ((rgb.blue + m) * 255.0).round)
    end
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);
	}
734643
def to_xyz100(self, data, description):
        
        rgb_c = compute_to(data, description, self)
        # Step 6: Calculate R, G and B
        # rgb = (rgb_c.T / self.D_RGB).T
        # Step 7: Calculate X, Y and Z
        # xyz = self.solve_M16(rgb)
        return dot(self.invM_, rgb_c)
570079
function RGBA_TO_HSVA() {
        var r = this.r() / 255;
        var g = this.g() / 255;
        var b = this.b() / 255;
        var a = this.a();
        var max = Math.max(r, g, b);
        var min = Math.min(r, g, b);
        var diff = max - min;
        var h;
        var s;

        if (max === min) {
            h = 0;
        } else if (max === r && g >= b) {
            h = 60 * (g - b) / diff + 0;
        } else if (max === r && g < b) {
            h = 60 * (g - b) / diff + 360;
        } else if (max === g) {
            h = 60 * (b - r) / diff + 120;
        } else { // max === b
            h = 60 * (r - g) / diff + 240;
        }

        if (max === 0) {
            s = 0;
        } else {
            s = diff / max;
        }

        var v = max;
        return kolor.hsva(h, s, v, a);
    }
670562
def _value_to_color(value, cmap):
    """"""
    cm = plt.get_cmap(cmap)
    rgba = cm(value)
    return [int(round(255*v)) for v in rgba[0:3]]
1190129
def RGB_to_XYZ(cobj, target_illuminant=None, *args, **kwargs):
    
    # Will contain linearized RGB channels (removed the gamma func).
    linear_channels = {}

    if isinstance(cobj, sRGBColor):
        for channel in ['r', 'g', 'b']:
            V = getattr(cobj, 'rgb_' + channel)
            if V <= 0.04045:
                linear_channels[channel] = V / 12.92
            else:
                linear_channels[channel] = math.pow((V + 0.055) / 1.055, 2.4)
    elif isinstance(cobj, BT2020Color):
        if kwargs.get('is_12_bits_system'):
            a, b, c = 1.0993, 0.0181, 0.081697877417347
        else:
            a, b, c = 1.099, 0.018, 0.08124794403514049
        for channel in ['r', 'g', 'b']:
            V = getattr(cobj, 'rgb_' + channel)
            if V <= c:
                linear_channels[channel] = V / 4.5
            else:
                linear_channels[channel] = math.pow((V + (a - 1)) / a, 1 / 0.45)
    else:
        # If it's not sRGB...
        gamma = cobj.rgb_gamma

        for channel in ['r', 'g', 'b']:
            V = getattr(cobj, 'rgb_' + channel)
            linear_channels[channel] = math.pow(V, gamma)

    # Apply an RGB working space matrix to the XYZ values (matrix mul).
    xyz_x, xyz_y, xyz_z = apply_RGB_matrix(
        linear_channels['r'], linear_channels['g'], linear_channels['b'],
        rgb_type=cobj, convtype="rgb_to_xyz")

    if target_illuminant is None:
        target_illuminant = cobj.native_illuminant

    # The illuminant of the original RGB object. This will always match
    # the RGB colorspace's native illuminant.
    illuminant = cobj.native_illuminant
    xyzcolor = XYZColor(xyz_x, xyz_y, xyz_z, illuminant=illuminant)
    # This will take care of any illuminant changes for us (if source
    # illuminant != target illuminant).
    xyzcolor.apply_adaptation(target_illuminant)

    return xyzcolor
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};
    }