Linear interpolate two 3-channel colors, using channel based interpolation.
340529
def interpolate_color(c1, c2, factor: float) -> list:
    
    assert(len(c1) == len(c2))

    new_color = []
    for i in range(len(c1)):
        new_color.append(int(interpolate(c1[i], c2[i], factor)))
    return new_color
106261
def configure_threecolor_image(self):
        
        order = {'red': 0, 'green': 1, 'blue': 2}
        self.image = np.zeros((self.shape[0], self.shape[1], 3))
        for color, var in self.multicolorvars.items():
            channel = var.get()  # determine which channel should be plotted as this color
            self.image[:, :, order[color]] = self.data[channel]

            # scale the image by the power
            self.image[:, :, order[color]] = np.power(self.image[:, :, order[color]],
                                                      self.multicolorpower[color].get())

            # adjust the percentile thresholds
            lower = np.nanpercentile(self.image[:, :, order[color]], self.multicolormin[color].get())
            upper = np.nanpercentile(self.image[:, :, order[color]], self.multicolormax[color].get())
            self.image[np.where(self.image[:, :, order[color]] < lower)] = lower
            self.image[np.where(self.image[:, :, order[color]] > upper)] = upper

        # image values must be between (0,1) so scale image
        for color, index in order.items():
            self.image[:, :, index] /= np.nanmax(self.image[:, :, index])
7345
function(color1, color2) {
		for (var i=0;i<3;i++) {
			for (var j=1;j<arguments.length;j++) {
				color1[i] += arguments[j][i];
			}
		}
		return color1;
	}
461375
def colorize(arr, colors, values):
    
    hcolors = np.array([rgb2hcl(*i[:3]) for i in colors])
    # unwrap colormap in hcl space
    hcolors[:, 0] = np.rad2deg(np.unwrap(np.deg2rad(np.array(hcolors)[:, 0])))
    channels = [np.interp(arr,
                          np.array(values),
                          np.array(hcolors)[:, i])
                for i in range(3)]

    channels = list(hcl2rgb(*channels))

    rest = [np.interp(arr,
                      np.array(values),
                      np.array(colors)[:, i + 3])
            for i in range(np.array(colors).shape[1] - 3)]

    channels.extend(rest)

    try:
        return [np.ma.array(channel, mask=arr.mask) for channel in channels]
    except AttributeError:
        return channels
1033731
def set_rgb(self, red, green, blue):
        
        x, y = rgb_to_xy(red, green, blue)
        self.xy = [x, y]
1282339
def add_interpolated_colorbar(da, colors, direction):
    
    # Special case that arises due to not so useful
    # aesthetic mapping.
    if len(colors) == 1:
        colors = [colors[0], colors[0]]

    # Number of horizontal egdes(breaks) in the grid
    # No need to create more nbreak than colors, provided
    # no. of colors = no. of breaks = no. of cmap colors
    # the shading does a perfect interpolation
    nbreak = len(colors)

    if direction == 'vertical':
        mesh_width = 1
        mesh_height = nbreak-1
        linewidth = da.height/mesh_height
        # Construct rectangular meshgrid
        # The values(Z) at each vertex are just the
        # normalized (onto [0, 1]) vertical distance
        x = np.array([0, da.width])
        y = np.arange(0, nbreak) * linewidth
        X, Y = np.meshgrid(x, y)
        Z = Y/y.max()
    else:
        mesh_width = nbreak-1
        mesh_height = 1
        linewidth = da.width/mesh_width
        x = np.arange(0, nbreak) * linewidth
        y = np.array([0, da.height])
        X, Y = np.meshgrid(x, y)
        Z = X/x.max()

    # As a 2D coordinates array
    coordinates = np.zeros(
        ((mesh_width+1)*(mesh_height+1), 2),
        dtype=float)
    coordinates[:, 0] = X.ravel()
    coordinates[:, 1] = Y.ravel()

    cmap = ListedColormap(colors)
    coll = mcoll.QuadMesh(mesh_width, mesh_height,
                          coordinates,
                          antialiased=False,
                          shading='gouraud',
                          linewidth=0,
                          cmap=cmap,
                          array=Z.ravel())
    da.add_artist(coll)
574125
function adjustLuminance(rgb, lum) {
  var newRgb = {};
  newRgb.red = calculateLuminance(rgb.red, lum);
  newRgb.green = calculateLuminance(rgb.green, lum);
  newRgb.blue = calculateLuminance(rgb.blue, lum);

  return newRgb;
}
621589
def _rgb2ycbcr(self, mode):
        """"""

        self._check_modes(("RGB", "RGBA"))

        (self.channels[0], self.channels[1], self.channels[2]) = \
            rgb2ycbcr(self.channels[0],
                      self.channels[1],
                      self.channels[2])

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

        self.mode = mode
35303
function rgbToHsl(rgb) {
		var r, g, b, max, min, d, h, s, l,
			cache,
			del_R, del_G, del_B;

		rgb = ColorHelper.hexToRGB(rgb);
		r = rgb[0] / 255;
		g = rgb[1] / 255;
		b = rgb[2] / 255;
		max = Math.max(r, g, b);
		min = Math.min(r, g, b);

		// Delta RGB value
		d = max - min;
		l = (max + min) / 2;

		// gray?, no chroma...
		if (d === 0) {
			// HSl results from 0 to 1
			h = 0;
			s = 0;
		} else {
			// Chromatic data...
			s = d / (l < 0.5 ? (max + min) : (2 - max - min));

			del_R = (((max - r) / 6) + (d / 2)) / d;
			del_G = (((max - g) / 6) + (d / 2)) / d;
			del_B = (((max - b) / 6) + (d / 2)) / d;

			if (r === max) {
				h = del_B - del_G;
			} else if (g === max) {
				h = (1 / 3) + del_R - del_B;
			} else if (b === max) {
				h = (2 / 3) + del_G - del_R;
			}

			if (h < 0) {
				h += 1;
			}
			if (h > 0) {
				h -= 1;
			}
		}

		h = Math.round(h * 360);
		if (h < 0) {
			h += 360;
		}

		cache = colorCache(this);
		cache.hsl = [h, Math.round(s * 100), Math.round(l * 100)];
		return cache.hsl;
	}
241576
def interpolate_tuple(startcolor, goalcolor, steps):
    
    # white

    R = startcolor[0]
    G = startcolor[1]
    B = startcolor[2]

    targetR = goalcolor[0]
    targetG = goalcolor[1]
    targetB = goalcolor[2]

    DiffR = targetR - R
    DiffG = targetG - G
    DiffB = targetB - B

    buffer = []

    for i in range(0, steps + 1):
        iR = R + (DiffR * i // steps)
        iG = G + (DiffG * i // steps)
        iB = B + (DiffB * i // steps)

        hR = string.replace(hex(iR), "0x", "")
        hG = string.replace(hex(iG), "0x", "")
        hB = string.replace(hex(iB), "0x", "")

        if len(hR) == 1:
            hR = "0" + hR
        if len(hB) == 1:
            hB = "0" + hB

        if len(hG) == 1:
            hG = "0" + hG

        color = string.upper("#" + hR + hG + hB)
        buffer.append(color)

    return buffer
318278
function rgb(red, green, blue){
  switch (arguments.length) {
    case 1:
      utils.assertColor(red);
      var color = red.rgba;
      return new nodes.RGBA(
          color.r
        , color.g
        , color.b
        , 1);
    default:
      return rgba(
          red
        , green
        , blue
        , new nodes.Unit(1));
  }
}
758395
function(color1, color2) {
		var result = color1.slice();
		for (var i=0;i<3;i++) {
			for (var j=1;j<arguments.length;j++) {
				result[i] += arguments[j][i];
			}
		}
		return result;
	}
889598
function contrast(color) {
    const rgb = [parseInt(color.substring(1, 3), 16),
      parseInt(color.substring(3, 5), 16),
      parseInt(color.substring(5, 7), 16)];
    for (let i = 0; i < 3; i++) {
      rgb[i] = 255 - rgb[i];
    }
    return `rgb(${rgb[0]}, ${rgb[1]}, ${rgb[2]})`;
  }
684763
function Color(x, y, z, m) {
      var me, _ref2;
      me = this;
      if (!(x != null) && !(y != null) && !(z != null) && !(m != null)) {
        x = [255, 0, 255];
      }
      if (type(x) === "array" && x.length === 3) {
        if (m == null) m = y;
        _ref2 = x, x = _ref2[0], y = _ref2[1], z = _ref2[2];
      }
      if (type(x) === "string") {
        m = 'hex';
      } else {
        if (m == null) m = 'rgb';
      }
      if (m === 'rgb') {
        me.rgb = [x, y, z];
      } else if (m === 'hsl') {
        me.rgb = Color.hsl2rgb(x, y, z);
      } else if (m === 'hsv') {
        me.rgb = Color.hsv2rgb(x, y, z);
      } else if (m === 'hex') {
        me.rgb = Color.hex2rgb(x);
      } else if (m === 'lab') {
        me.rgb = Color.lab2rgb(x, y, z);
      } else if (m === 'csl') {
        me.rgb = Color.csl2rgb(x, y, z);
      } else if (m === 'hsi') {
        me.rgb = Color.hsi2rgb(x, y, z);
      }
    }
23420
public static void RGB_to_PLU8(Picture input, Planar<GrayU8> output) {
		if( input.getColor() != ColorSpace.RGB )
			throw new RuntimeException("Unexpected input color space!");
		if( output.getNumBands() != 3 )
			throw new RuntimeException("Unexpected number of bands in output image!");

		output.reshape(input.getWidth(),input.getHeight());

		int dataIn[] = input.getData()[0];

		GrayU8 out0 = output.getBand(0);
		GrayU8 out1 = output.getBand(1);
		GrayU8 out2 = output.getBand(2);

		int indexIn = 0;
		int indexOut = 0;
		for (int i = 0; i < output.height; i++) {
			for (int j = 0; j < output.width; j++, indexOut++ ) {
				int r = dataIn[indexIn++];
				int g = dataIn[indexIn++];
				int b = dataIn[indexIn++];

				out2.data[indexOut] = (byte)r;
				out1.data[indexOut] = (byte)g;
				out0.data[indexOut] = (byte)b;
			}
		}
	}
1111591
def xy_to_rgb(self, x, y, bri=1):
        """"""
        r, g, b = self.color.get_rgb_from_xy_and_brightness(x, y, bri)
        return (r, g, b)
950604
def rgb2rgba(rgb):
    """"""
    rgba = []
    for i in range(0, len(rgb), 3):
        rgba += rgb[i:i+3]
        rgba.append(255)

    return rgba