This applies an adaptation matrix to change the XYZ color's illuminant.
        You'll most likely only need this during RGB conversions.
972544
def apply_adaptation(self, target_illuminant, adaptation='bradford'):
        
        logger.debug("  \- Original illuminant: %s", self.illuminant)
        logger.debug("  \- Target illuminant: %s", target_illuminant)

        # If the XYZ values were taken with a different reference white than the
        # native reference white of the target RGB space, a transformation matrix
        # must be applied.
        if self.illuminant != target_illuminant:
            logger.debug("  \* Applying transformation from %s to %s ",
                         self.illuminant, target_illuminant)
            # Sets the adjusted XYZ values, and the new illuminant.
            apply_chromatic_adaptation_on_color(
                color=self,
                targ_illum=target_illuminant,
                adaptation=adaptation)
924487
function( r, g, b, a ){
    this._dat[ 0|BLEND_COLOR_R ] = encodeHalf( r );
    this._dat[ 0|BLEND_COLOR_G ] = encodeHalf( g );
    this._dat[ 0|BLEND_COLOR_B ] = encodeHalf( b );
    this._dat[ 0|BLEND_COLOR_A ] = encodeHalf( a );
    this._set |= BLEND_COLOR_SET|0;
    return this;
  }
1227332
private void startInvertedColors() {
        if (managerFeatures.getInvertedColors().isInverted()) {
            managerFeatures.getInvertedColors().turnOff(mGvrContext.getMainScene());
        } else {
            managerFeatures.getInvertedColors().turnOn(mGvrContext.getMainScene());
        }
    }
759706
function fromXYZ(x, y, z) {
    var color = create();
    setXYZ(color, x, y, z);
    return color;
}
834780
private void rederiveColor() {
        Color src = UIManager.getColor(uiDefaultParentName);
        if (src != null) {
            float[] tmp = Color.RGBtoHSB(src.getRed(), src.getGreen(), src.getBlue(), null);
            // apply offsets
            tmp[0] = clamp(tmp[0] + hOffset);
            tmp[1] = clamp(tmp[1] + sOffset);
            tmp[2] = clamp(tmp[2] + bOffset);
            int alpha = clamp(src.getAlpha() + aOffset);
            argbValue = (Color.HSBtoRGB(tmp[0], tmp[1], tmp[2]) & 0xFFFFFF) | (alpha << 24);
        } else {
            float[] tmp = new float[3];
            tmp[0] = clamp(hOffset);
            tmp[1] = clamp(sOffset);
            tmp[2] = clamp(bOffset);
            int alpha = clamp(aOffset);
            argbValue = (Color.HSBtoRGB(tmp[0], tmp[1], tmp[2]) & 0xFFFFFF) | (alpha << 24);
        }
    }
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
1323320
private int adjustAlpha(int color, float factor) {
        int alpha = Math.round(Color.alpha(color) * factor);
        int red = Color.red(color);
        int green = Color.green(color);
        int blue = Color.blue(color);
        return Color.argb(alpha, red, green, blue);
    }
157977
function CMYK_TO_RGBA() {
        var c = this.c();
        var m = this.m();
        var y = this.y();
        var black = this.b();

        var r = 1 - Math.min(1, c * (1 - black) + black);
        var g = 1 - Math.min(1, m * (1 - black) + black);
        var b = 1 - Math.min(1, y * (1 - black) + black);
        return kolor.rgba(r * 255, g * 255, b * 255, this.a());
    }
807325
function translateColor(colorArr, variationName, execMode) {
  const [colorVar, alpha] = colorArr;

  // returns the real color representation
  if (!options.palette) {
    options.palette = getColorPalette();
  }

  const underlineColor = options.palette[variationName][colorVar];

  if (!underlineColor) {
    // variable is not mandatory in non-default variations
    if (variationName !== defaultVariation) {
      return null;
    }
    throw new Error(
      `The variable name '${colorVar}' doesn't exists in your palette.`,
    );
  }

  switch (execMode) {
    case ExecutionMode.CSS_COLOR:
      // with default alpha - just returns the color
      if (alpha === '1') {
        return rgb2hex(underlineColor).hex;
      }
      // with custom alpha, convert it to rgba
      const rgbaColor = hexToRgba(rgb2hex(underlineColor).hex, alpha);
      return rgbaColor;
    default:
      if (alpha === 1) {
        return `rgba(var(--bolt-theme-${colorVar}), ${alpha})`;
        //return `var(--bolt-theme-${colorVar})`; // @todo: re-evaluate if hex values should ever get outputted here
      } else {
        return `rgba(var(--bolt-theme-${colorVar}), ${alpha})`;
      }
  }
}
339134
@ColorInt public static int decreaseRgbChannels(Context context,
                                                    @ColorRes int res, float percent) {
        int c = resolveColor(res, context);

        // reduce rgb channel values to produce box shadow effect
        int red = (Color.red(c));
        red -= (red * percent);
        red = red > 0 ? red : 0;

        int green = (Color.green(c));
        green -= (green * percent);
        green = green > 0 ? green : 0;

        int blue = (Color.blue(c));
        blue -= (blue * percent);
        blue = blue > 0 ? blue : 0;

        return Color.argb(Color.alpha(c), red, green, blue);
    }
835198
def matte_replace(x, y)
      f = copy
      f.opacity = OpaqueOpacity unless f.alpha?
      target = f.pixel_color(x, y)
      f.transparent(target)
    end
813171
def lighten_color(color, amount):
    """"""
    color = [int(col + (255 - col) * amount) for col in hex_to_rgb(color)]
    return rgb_to_hex(color)
513630
def mix!(other, pct = 50.0)
      coeff = pct.to_f / 100.0
      new_rgb = to_rgb.zip(other.to_rgb).map{|c1, c2| (c1 * (1 - coeff)) + (c2 * coeff)}
      h, s, l = self.class.rgb_to_hsl(*new_rgb)
      self.hue, self.saturation, self.lightness = 360*h, s, l
    end
890652
def rgb_to_xyz(colour)
      r, g, b = colour.map do |v|
          v /= 255.0
          if v > 0.04045
              v = ((v + 0.055 ) / 1.055)**2.4
          else
              v = v / 12.92
          end
          v *= 100
      end

      #Observer = 2°, Illuminant = D65
      x = r * 0.4124 + g * 0.3576 + b * 0.1805
      y = r * 0.2126 + g * 0.7152 + b * 0.0722
      z = r * 0.0193 + g * 0.1192 + b * 0.9505

      return [x, y, z]
    end
961048
public static void applyTransform(GrayS8 input , int transform[] , int minValue, GrayS8 output ) {
		output.reshape(input.width,input.height);

		if( BoofConcurrency.USE_CONCURRENT ) {
			ImplEnhanceHistogram_MT.applyTransform(input, transform, minValue, output);
		} else {
			ImplEnhanceHistogram.applyTransform(input, transform, minValue, output);
		}
	}
866919
def changecolourmode(self, newcolour):
        
        if type(newcolour) != type(0) and self.pilimage.mode != "RGB":
            if self.verbose :
                print "Switching to RGB !"
            self.pilimage = self.pilimage.convert("RGB")
            self.draw = None # important, we have to bebuild the draw object.
            self.makedraw()
264523
def swapColors(self):
		
		rgba = self.color.get_0_255()
		self.color = self.secondColor
		self.secondColor = Color(rgba, '0-255')