Return the NTSC gray level of an RGB value.
@param rgb1 the input pixel
@return the gray level (0-255)
489878
public static int brightnessNTSC(int rgb) {
		int r = (rgb >> 16) & 0xff;
		int g = (rgb >> 8) & 0xff;
		int b = rgb & 0xff;
		return (int)(r*0.299f + g*0.587f + b*0.114f);
	}
483332
function () {
        if (this.alpha < 1.0) {
            return "rgba(" + this.rgb.map(function (c) {
                return Math.round(c);
            }).concat(this.alpha).join(', ') + ")";
        } else {
            return '#' + this.rgb.map(function (i) {
                i = Math.round(i);
                i = (i > 255 ? 255 : (i < 0 ? 0 : i)).toString(16);
                return i.length === 1 ? '0' + i : i;
            }).join('');
        }
    }
1370249
public function grayscale()
    {
        $gray = min(
                255
                , round(
                        0.299 * $this->getRed() +
                        0.587 * $this->getGreen() +
                        0.114 * $this->getBlue()
                )
        );

        return $this->setFromArray(array(
                    $gray, $gray, $gray, $this->getAlpha()
        ));
    }
579483
private int getNewColor(int i)
  {
    int r = (((i) * 224) % 255);
    int g = (((i + 197) * 1034345) % 255);
    int b = (((i + 23) * 74353) % 255);

    //  too dark or too bright?
    if (((r + b + g) / 3) < 100)
    {
      r = 255 - r;
      g = 255 - g;
      b = 255 - b;
    }
    else if (((r + b + g) / 3) > 192)
    {
      r = 1 * (r / 2);
      g = 1 * (g / 2);
      b = 1 * (b / 2);
    }

    if (r == 255 && g == 255 && b == 255)
    {
      r = 255;
      g = 255;
      b = 0;
    }

    return (r * 65536 + g * 256 + b);
  }
764583
@SuppressWarnings({ "checkstyle:magicnumber", "static-method" })
	@Pure
	public Color rgba(int rgb, double opacity) {
		final int red = (rgb & 0x00FF0000) >> 16;
		final int green = (rgb & 0x0000FF00) >> 8;
		final int blue = rgb & 0x000000FF;
		return Color.rgb(red, green, blue, opacity);
	}
1179251
public static <I extends ImageGray<I>, II extends ImageGray<II>>
	Class<II> getIntegralType( Class<I> inputType ) {
		if( inputType == GrayF32.class ) {
			return (Class<II>)GrayF32.class;
		} else if( inputType == GrayU8.class ){
			return (Class<II>)GrayS32.class;
		} else if( inputType == GrayS32.class ){
			return (Class<II>)GrayS32.class;
		} else {
			throw new IllegalArgumentException("Unknown input image type: "+inputType.getSimpleName());
		}
	}
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)
901030
def _rgb2l(self, mode):
        
        self._check_modes(("RGB", "RGBA"))

        kb_ = 0.114
        kr_ = 0.299

        r__ = self.channels[0]
        g__ = self.channels[1]
        b__ = self.channels[2]

        y__ = kr_ * r__ + (1 - kr_ - kb_) * g__ + kb_ * b__

        if self.fill_value is not None:
            self.fill_value = ([rgb2ycbcr(self.fill_value[0],
                                          self.fill_value[1],
                                          self.fill_value[2])[0]] +
                               self.fill_value[3:])

        self.channels = [y__] + self.channels[3:]

        self.mode = mode
855893
private int getSrcColor(int x, int y) {
        int argb = srcColorModel.getRGB(srcRaster.getDataElements(x, y, null));
        if (transparency == Transparency.OPAQUE) {
            argb = 0xff000000 | argb;
        }

        return argb;
    }
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};
    }
179914
function rgbToHsv(r, g, b) {

    r = bound01(r, 255);
    g = bound01(g, 255);
    b = bound01(b, 255);

    var max = mathMax(r, g, b), min = mathMin(r, g, b);
    var h, s, v = max;

    var d = max - min;
    s = max === 0 ? 0 : d / max;

    if(max == min) {
        h = 0; // achromatic
    }
    else {
        switch(max) {
            case r: h = (g - b) / d + (g < b ? 6 : 0); break;
            case g: h = (b - r) / d + 2; break;
            case b: h = (r - g) / d + 4; break;
        }
        h /= 6;
    }
    return { h: h, s: s, v: v };
}
313901
function (r, g, b) {
            if (r > 255 || g > 255 || b > 255)
                throw "Invalid color component";
            return ((r << 16) | (g << 8) | b).toString(16);
        }
842558
static double rgba( double r, double g, double b, double a ) {
        return Double.longBitsToDouble( Math.round( a * 0xFFFF ) << 48 | (colorLargeDigit(r) << 32) | (colorLargeDigit(g) << 16) | colorLargeDigit(b) );
    }
114267
protected static int getBytesPerPixel(Bitmap.Config config) {
        if (config == Bitmap.Config.ARGB_8888) {
            return 4;
        } else if (config == Bitmap.Config.RGB_565) {
            return 2;
        } else if (config == Bitmap.Config.ARGB_4444) {
            return 2;
        } else if (config == Bitmap.Config.ALPHA_8) {
            return 1;
        }
        return 1;
    }
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)
1172155
public function getChroma() {
		$r = ($this->rgb >> 16) & 0xff;
		$g = ($this->rgb >> 8) & 0xff;
		$b = $this->rgb & 0xff;
		return (max($r, $g, $b) - min($r, $g, $b)) / 255;
	}
390159
public static function rgb($r = 255, $g = 255, $b = 255)
    {
        // Check if values are in range.
        static::validateComp('R', $r, 0, 255);
        static::validateComp('G', $g, 0, 255);
        static::validateComp('B', $b, 0, 255);

        return new static($r, $g, $b);
    }