Conversion from 8-bit RGB into XYZ.  8-bit = range of 0 to 255.
489181
public static void rgbToXyz( int r , int g , int b , double xyz[] ) {
		srgbToXyz(r/255.0,g/255.0,b/255.0,xyz);
	}
1289187
function XYZToSRGB ({ x, y, z, a }) {
    // Poynton, "Frequently Asked Questions About Color," page 10
    // Wikipedia: http://en.wikipedia.org/wiki/SRGB
    // Wikipedia: http://en.wikipedia.org/wiki/CIE_1931_color_space

    // Convert XYZ to linear RGB
    const r = clamp(3.2406 * x - 1.5372 * y - 0.4986 * z, 0, 1);
    const g = clamp(-0.9689 * x + 1.8758 * y + 0.0415 * z, 0, 1);
    const b = clamp(0.0557 * x - 0.2040 * y + 1.0570 * z, 0, 1);

    return linearRGBToSRGB({ r, g, b, a });
}
1244377
public static function rgb2xyz($rgb)
    {
        // Inverse sRGB Companding
        $rgb = array_map(function ($n) {
            if ($n <= 0.04045) {
                return $n / 12.92;
            }
            return pow(($n + 0.055) / 1.055, 2.4);
        }, $rgb);

        // Linear RGB to XYZ
        return array(
            0.4124564 * $rgb[0] + 0.3575761 * $rgb[1] + 0.1804375 * $rgb[2],
            0.2126729 * $rgb[0] + 0.7151522 * $rgb[1] + 0.0721750 * $rgb[2],
            0.0193339 * $rgb[0] + 0.1191920 * $rgb[1] + 0.9503041 * $rgb[2]
        );
    }
1363068
def cmyk_to_rgb(Class, c, m, y, k):
        
        c = float(c)/100.0
        m = float(m)/100.0
        y = float(y)/100.0
        k = float(k)/100.0

        nc = (c * (1-k)) + k
        nm = (m * (1-k)) + k
        ny = (y * (1-k)) + k

        r = int((1-nc) * 255)
        g = int((1-nm) * 255)
        b = int((1-ny) * 255)

        return dict(r=r, g=g, b=b)
445106
public static int fromYCbCr(int y, int cb, int cr, int alpha) {
        int cbc = cb - YUV_OFFSET;
        int crc = cr - YUV_OFFSET;
        int r = y + crc + (crc >> 2) + (crc >> 3) + (crc >> 5);
        int g = y - ((cbc >> 2) + (cbc >> 4) + (cbc >> 5)) - ((crc >> 1) + (crc >> 3) + (crc >> 4) + (crc >> 5));
        int b = y + cbc + (cbc >> 1) + (cbc >> 2) + (cbc >> 6);

        /* Using float operations
        int r = (int) (y + 1.402 * (cr - YUV_OFFSET));
        int g = (int) (y - 0.344 * (cb - YUV_OFFSET) - 0.714 * (cr - YUV_OFFSET));
        int b = (int) (y + 1.772 * (cb - YUV_OFFSET));
        r = clamp(r);
        g = clamp(g);
        b = clamp(b);
        */

        return getARGB(r, g, b, alpha);
    }
306652
function rgbToHex(r, g, b) {
    [r, g, b] = [limit(r, 0, 255), limit(g, 0, 255), limit(b, 0, 255)];
    return "#" + ("000000" + ((r << 16) | (g << 8) | b).toString(16)).slice(-6);
}
60496
def hexa_to_rgb(color):
    """"""
    r = int(color[1:3], 16)
    g = int(color[3:5], 16)
    b = int(color[5:7], 16)
    if len(color) == 7:
        return r, g, b
    elif len(color) == 9:
        return r, g, b, int(color[7:9], 16)
    else:
        raise ValueError("Invalid hexadecimal notation.")
698207
def _scaleTo8bit(self, img):
        '''
        
        '''
        r = scaleSignalCutParams(img, 0.02)  # , nSigma=3)
        self.signal_ranges.append(r)
        return toUIntArray(img, dtype=np.uint8, range=r)
20605
def rgb_to_xy(self, red, green, blue):
        
        point = self.color.get_xy_point_from_rgb(red, green, blue)
        return (point.x, point.y)
380857
def xy_to_hex(self, x, y, bri=1):
        """"""
        r, g, b = self.color.get_rgb_from_xy_and_brightness(x, y, bri)
        return self.color.rgb_to_hex(r, g, b)
302344
def color_hex_to_dec_tuple(color):
    
    assert len(color) in [3, 4, 6, 8]
    if len(color) in [3, 4]:
        color = "".join([c*2 for c in color])
    n = int(color, 16)
    t = ((n >> 16) & 255, (n >> 8) & 255, n & 255)
    if len(color) == 8:
        t = t + ((n >> 24) & 255,)
    return t
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)
780346
public static void xyzToSrgb( float x , float y , float z , float srgb[] ) {
		srgb[0] = 3.240479f*x - 1.53715f*y - 0.498535f*z;
		srgb[1] = -0.969256f*x + 1.875991f*y + 0.041556f*z;
		srgb[2] = 0.055648f*x - 0.204043f*y + 1.057311f*z;
	}
1170957
function(RGBArray) {
    var hex = '#';
    RGBArray.forEach(function(value) {
        if (value < 16) {
            hex += 0;
        }
        hex += value.toString(16);
    });
    return hex;
}
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};
    }
772582
function(rgb){
            var parts = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
            var hex = (parts[1]<<16|parts[2]<<8|parts[3]).toString(16);
            return "#"+Array(6-hex.length).concat([hex]).toString().replace(/,/g, 0);
        }
1065159
def rgb_2_hex(self, r, g, b):
        
        return "#{:02X}{:02X}{:02X}".format(int(r * 255), int(g * 255), int(b * 255))