RGBで初期化しインスタンスを取得する。
16進数の場合は引数が1つ。
R,G,Bを個別で指定する場合は引数が3つ。
@param int R 0-255(0x00-0xFF)
@param int G 0-255(0x00-0xFF) or null
@param int B 0-255(0x00-0xFF) or null
@return self
11376
public static function rgb($v1,$v2=null,$v3=null)
	{
		if(is_null($v2)){
			$rgb = $v1;
			$r = ($rgb >> 16) & 0xFF;
			$g = ($rgb >> 8) & 0xFF;
			$b = $rgb & 0xFF;
			$self = new self();
			return $self->r($r)->g($g)->b($b);
		}else{
			$r = $v1 & 0xFF;
			$g = $v2 & 0xFF;
			$b = $v3 & 0xFF;
			$self = new self();
			return $self->r($r)->g($g)->b($b);
		}
	}
267520
public function setFontColor($r, $g = null, $b = null) {
		
		if(true === is_string($r) && preg_match('/^#?([A-Fa-f0-9]{6})$/', $r, $color)) {
			list($r, $g, $b) = sscanf($color[1], '%02x%02x%02x');
		}

		if(false === ('-' . intval($r) == '-' . $r)) {
			return trigger_error(sprintf('Argument 1 passed to %s() must be of the type integer or a valid hex color with 6 characters (# not included)', __METHOD__), E_USER_ERROR);
		}

		if(false === ('-' . intval($g) == '-' . $g)) {
			return trigger_error(sprintf('Argument 2 passed to %s() must be of the type integer, "%s" given', __METHOD__, gettype($g)), E_USER_ERROR);
		}

		if(false === ('-' . intval($b) == '-' . $b)) {
			return trigger_error(sprintf('Argument 3 passed to %s() must be of the type integer, "%s" given', __METHOD__, gettype($b)), E_USER_ERROR);
		}

		$this -> color = ['r' => $r, 'g' => $g, 'b' => $b];
	}
948849
public ColorPixel add(double r, double g, double b){
		return setRGB_fromDouble_preserveAlpha(r+r_asDouble(), g+g_asDouble(), b+b_asDouble());
	}
856325
public static final String toBrowserRGB(final int r, final int g, final int b)
    {
        return "rgb(" + fixRGB(r) + "," + fixRGB(g) + "," + fixRGB(b) + ")";
    }
506222
public static function rgb2xyz( $rgb )
	{
		list( $r, $g, $b ) = $rgb;
		$r	= $r / 255;
		$g	= $g / 255;
		$b	= $b / 255;
		$x	= 0.430574 * $r + 0.341550 * $g + 0.178325 * $b;
		$y	= 0.222015 * $r + 0.706655 * $g + 0.071330 * $b;
		$z	= 0.020183 * $r + 0.129553 * $g + 0.939180 * $b;
		return array( $x, $y, $z );
	}
994112
def colorRGB(r, g, b):
        
        return (float(r / 255), float(g / 255), float(b / 255))
202061
def sgr_bg_rgb(r, g, b):
        """"""
        assert r in range(256)
        assert g in range(256)
        assert b in range(256)
        return '48;2;{};{};{}'.format(r, g, b)
453204
public static void rgbToYuv( double r , double g , double b , double yuv[] ) {
		double y = yuv[0] = 0.299*r + 0.587*g + 0.114*b;
		yuv[1] = 0.492*(b-y);
		yuv[2] = 0.877*(r-y);
	}
869560
def rgb2ansi(r, g, b):
    

    # Thanks to
    # https://github.com/tehmaze/ansi/blob/master/ansi/colour/rgb.py

    grayscale = False
    poss = True
    step = 2.5

    while poss:
        if min(r, g, b) < step:
            grayscale = max(r, g, b) < step
            poss = False

        step += 42.5

    if grayscale:
        return 232 + int(float(sum((r, g, b)) / 33.0))

    m = ((r, 36), (g, 6), (b, 1))
    return 16 + sum(int(6 * float(val) / 256) * mod for val, mod in m)
346990
public void setImageColor(float r, float g, float b) {
		setColor(TOP_LEFT, r, g, b);
		setColor(TOP_RIGHT, r, g, b);
		setColor(BOTTOM_LEFT, r, g, b);
		setColor(BOTTOM_RIGHT, r, g, b);
	}
293544
private static final double[] getRGB(double cyan, double magenta, double yellow, double black) {
        double[] rgb = {0.0, 0.0, 0.0};

        rgb[0] = 1.0 - Math.min(1.0, cyan    * (1.0 - black) + black);
        rgb[1] = 1.0 - Math.min(1.0, magenta * (1.0 - black) + black);
        rgb[2] = 1.0 - Math.min(1.0, yellow  * (1.0 - black) + black);

        return rgb;
    }
461778
private int applyFog( int rgb , float fraction ) {
		// avoid floating point math
		int adjustment = (int)(1000*fraction);

		int r = (rgb >> 16)&0xFF;
		int g = (rgb >> 8)&0xFF;
		int b = rgb & 0xFF;

		r = (r * adjustment + ((backgroundColor>>16)&0xFF)*(1000-adjustment)) / 1000;
		g = (g * adjustment + ((backgroundColor>>8)&0xFF)*(1000-adjustment)) / 1000;
		b = (b * adjustment + (backgroundColor&0xFF)*(1000-adjustment)) / 1000;

		return (r << 16) | (g << 8) | b;
	}
1141771
public static final Color hex2RGB(final String hex)
    {
        String r, g, b;

        final int len = hex.length();

        if (len == 7)
        {
            r = hex.substring(1, 3);

            g = hex.substring(3, 5);

            b = hex.substring(5, 7);
        }
        else if (len == 4)
        {
            r = hex.substring(1, 2);

            g = hex.substring(2, 3);

            b = hex.substring(3, 4);

            r = r + r;

            g = g + g;

            b = b + b;
        }
        else
        {
            return null;// error - invalid length
        }
        try
        {
            return new Color(Integer.valueOf(r, 16), Integer.valueOf(g, 16), Integer.valueOf(b, 16));
        }
        catch (final NumberFormatException ignored)
        {
            return null;
        }
    }
381442
public static void float2rgbe(byte[] rgbe, float red, float green, float blue) {
        float v;
        int e;

        v = red;
        if (green > v) {
            v = green;
        }
        if (blue > v) {
            v = blue;
        }
        if (v < 1e-32f) {
            rgbe[0] = rgbe[1] = rgbe[2] = rgbe[3] = 0;
        }
        else {
            FracExp fe = frexp(v);
            v = (float) (fe.getFraction() * 256.0 / v);
            rgbe[0] = (byte) (red * v);
            rgbe[1] = (byte) (green * v);
            rgbe[2] = (byte) (blue * v);
            rgbe[3] = (byte) (fe.getExponent() + 128);
        }
    }
887186
function(rgb) {
		var r,g,b;
		if (typeof(rgb) == 'object') {
			r = rgb.r;
			g = rgb.g;
			b = rgb.b;
		} else if (typeof(rgb.match) == 'function'){
			var parts = rgb.match(/^rgb\((\d+),(\d+),(\d+)\)$/);
			if (parts) {
				r = parts[1];
				g = parts[2];
				b = parts[3];
			}
		}
		if (isNaN(r) || isNaN(b) || isNaN(g)) {
			throw new TL.Error("invalid_rgb_err");
		}
		return "#" + TL.Util.intToHexString(r) + TL.Util.intToHexString(g) + TL.Util.intToHexString(b);
	}
272196
public static RGBColor rgb(int r, int g, int b) {
    return new RGBColor(makeRgb(r, g, b));
  }
33600
function(r, g, b, a) {
    var rgb = [r, g, b].map(function (c) { return number(c); });
    a = number(a);
    if (rgb.some(isNaN) || isNaN(a)) return null;
    rgb.push(a);
    return rgb;
  }