Color Blending ref: http://www.w3.org/TR/compositing-1
542884
function colorBlend(mode) {
    return function(first, second) {
        first = Color.color(first);
        second = Color.color(second);
        var ab = first.rgba[3];
        var as = second.rgba[3];
        var ar = as + ab * (1 - as);
        var rgba = [ 0, 0, 0, ar ]; // result

        var cb, cs, cr;
        for (var i = 0; i < 3; i++) {
            cb = first.rgba[i] / 255;
            cs = second.rgba[i] / 255;
            cr = mode(cb, cs);
            if (ar) {
                cr = (as * cs + ab * (cb - as * (cb + cs - cr))) / ar;
            }
            rgba[i] = Math.round(cr * 255);
        }
        return Color.color(rgba);
    }
}
77046
function Color3(r, g, b) {
            if (r === void 0) { r = 0; }
            if (g === void 0) { g = 0; }
            if (b === void 0) { b = 0; }
            this.r = r;
            this.g = g;
            this.b = b;
        }
752626
function filled_rectangle($x1, $y1, $w, $h, $color, $blend = "Normal", $opacity = 1.0) {
		//var_dump($color);
		//Helpers::dompdf_debug("trace", "($x1, $y1, $w, $h, [$color[0], $color[1], $color[2]], $blend, $opacity)");

		//$this->_set_stroke_color($color);
		//$this->_set_fill_color($color);
		//$this->_set_line_style(1, "square", "miter", array());
		$this->_set_line_transparency($blend, $opacity);
		$this->_set_fill_transparency($blend, $opacity);

		$this->_pdf->Rect($x1, $y1, $w, $h, 'F', $this->_make_line_style($color, 1, "square", "miter", array()), $this->_get_rgb($color)); //***

	}
16547
public static Color interpolateColor( Color color1, Color color2, float fraction ) {
        float int2Float = 1f / 255f;
        fraction = Math.min(fraction, 1f);
        fraction = Math.max(fraction, 0f);

        float r1 = color1.getRed() * int2Float;
        float g1 = color1.getGreen() * int2Float;
        float b1 = color1.getBlue() * int2Float;
        float a1 = color1.getAlpha() * int2Float;

        float r2 = color2.getRed() * int2Float;
        float g2 = color2.getGreen() * int2Float;
        float b2 = color2.getBlue() * int2Float;
        float a2 = color2.getAlpha() * int2Float;

        float deltaR = r2 - r1;
        float deltaG = g2 - g1;
        float deltaB = b2 - b1;
        float deltaA = a2 - a1;

        float red = r1 + (deltaR * fraction);
        float green = g1 + (deltaG * fraction);
        float blue = b1 + (deltaB * fraction);
        float alpha = a1 + (deltaA * fraction);

        red = Math.min(red, 1f);
        red = Math.max(red, 0f);
        green = Math.min(green, 1f);
        green = Math.max(green, 0f);
        blue = Math.min(blue, 1f);
        blue = Math.max(blue, 0f);
        alpha = Math.min(alpha, 1f);
        alpha = Math.max(alpha, 0f);

        return new Color(red, green, blue, alpha);
    }
660972
function shader (color, percent) {
  const parseStrIndex = 16;
  const sliceStrIndex = 1;

  // Throw an error for colors
  if ((percent != 0) && (percent > 1.0 || -1.0 > percent)) {
    throw new Error(`Color Shader Error: unable shade accurately "${color}" by "${percent}" amount. The amount must be less than 1.0 and greater than -1.0.`);
  }

  let f;

  // Handle different string lengths
  switch (color.length) {

    // In the case of a 3 char string like fff...
    // ...then double the chars and parse the hex.
    case 3:
      color = color + color;
      f = parseInt(color, parseStrIndex);
      break;

    // In the case of a 4 char string like #fff...
    // ...then remove the hash, double the chars and parse the hex.
    case 4:
      color = color.slice(sliceStrIndex);
      color = color + color;
      f = parseInt(color, parseStrIndex);
      break;

    // In the case of a 7 char string like #ffffff,
    // ...then remove the hash and parse the hex.
    case 7:
      f = parseInt(color.slice(sliceStrIndex), parseStrIndex);
      break;

    // In the case of a 6 char string like ffffff...
    // ...then parse the hex without doing anything.
    default:
      f = parseInt(color, parseStrIndex);
      break;
  }

  const t = percent < 0 ? 0 : 255;
  const p = percent < 0 ? percent *- 1 : percent;

  // Old RGB values
  const r = f >> 16
  const g = f >> 8 & 0x00FF
  const b = f & 0x0000FF

  // Return new hex code
  return `#${
    (
      0x1000000 + (Math.round((t - r) * p) + r) * 0x10000 +
      (Math.round((t - g) * p) + g) * 0x100 +
      (Math.round((t - b) * p) + b)
    ).toString(16).slice(1)
  }`;
}
100471
function inerpolateColors(col1, col2, amount) {
  let col1rgb = parseColor(col1);
  let col2rgb = parseColor(col2);
  return RGBobj2string({
    r: Math.min(255, col1rgb.r * amount + col2rgb.r * (1-amount)),
    g: Math.min(255, col1rgb.g * amount + col2rgb.g * (1-amount)),
    b: Math.min(255, col1rgb.b * amount + col2rgb.b * (1-amount)),
    a: Math.min(1, col1rgb.a * amount + col2rgb.a * (1-amount))
  });
}
882253
function (vertices, color, c)
    {
        _c = c || _c
        if (color)
        {
            _c.fillStyle = color
        }
        const edges = [], active = []
        let minY = Infinity, maxY = 0

        // create edges
        for (let i = 0; i < vertices.length; i += 2)
        {
            const p1 = { x: vertices[i] * _scale, y: vertices[i + 1] * _scale }
            const p2 = { x: vertices[mod(i + 2, vertices.length)] * _scale, y: vertices[mod(i + 3, vertices.length)] * _scale }
            if (p1.y - p2.y !== 0)
            {
                const edge = {}
                edge.p1 = p1
                edge.p2 = p2
                if (p1.y < p2.y)
                {
                    edge.minY = p1.y
                    edge.minX = p1.x
                }
                else
                {
                    edge.minY = p2.y
                    edge.minX = p2.x
                }
                minY = (edge.minY < minY) ? edge.minY : minY
                edge.maxY = Math.max(p1.y, p2.y)
                maxY = (edge.maxY > maxY) ? edge.maxY : maxY
                if (p1.x - p2.x === 0)
                {
                    edge.slope = Infinity
                    edge.b = p1.x
                }
                else
                {
                    edge.slope = (p1.y - p2.y) / (p1.x - p2.x)
                    edge.b = p1.y - edge.slope * p1.x
                }
                edges.push(edge)
            }
        }
        edges.sort((a, b) => { return a.minY - b.minY })
        for (let y = minY; y <= maxY; y++)
        {
            for (let i = 0; i < edges.length; i++)
            {
                const edge = edges[i]
                if (edge.minY === y)
                {
                    active.push(edge)
                    edges.splice(i, 1)
                    i--
                }
            }
            for (let i = 0; i < active.length; i++)
            {
                const edge = active[i]
                if (edge.maxY < y)
                {
                    active.splice(i, 1)
                    i--
                }
                else
                {
                    if (edge.slope !== Infinity)
                    {
                        edge.x = Math.round((y - edge.b) / edge.slope)
                    }
                    else
                    {
                        edge.x = edge.b
                    }
                }
            }
            active.sort((a, b) => { return a.x - b.x === 0 ? b.maxY - a.maxY : a.x - b.x })
            let bit = true, current = 1
            for (let x = active[0].x; x <= active[active.length - 1].x; x++)
            {
                if (bit)
                {
                    put(x, y)
                }
                if (active[current].x === x)
                {
                    if (active[current].maxY !== y)
                    {
                        bit = !bit
                    }
                    current++
                }
            }
        }
    }
1052970
function applyContrastColors(config) {
  const { colors } = config;

  return {
    ...config,
    colors: {
      ...colors,
      primaryContrast: getContrastColor(colors.primary, colors),
      accentContrast: getContrastColor(colors.accent, colors),
      focus: getFocusColor(colors),
    },
  };
}
108486
public static int mixColors(float t, int rgb1, int rgb2) {
		int a1 = (rgb1 >> 24) & 0xff;
		int r1 = (rgb1 >> 16) & 0xff;
		int g1 = (rgb1 >> 8) & 0xff;
		int b1 = rgb1 & 0xff;
		int a2 = (rgb2 >> 24) & 0xff;
		int r2 = (rgb2 >> 16) & 0xff;
		int g2 = (rgb2 >> 8) & 0xff;
		int b2 = rgb2 & 0xff;
		a1 = lerp(t, a1, a2);
		r1 = lerp(t, r1, r2);
		g1 = lerp(t, g1, g2);
		b1 = lerp(t, b1, b2);
		return (a1 << 24) | (r1 << 16) | (g1 << 8) | b1;
	}
522367
function (gl, cur, next) {
  // enable/disable blend
  if (cur.blend !== next.blend) {
    if (!next.blend) {
      gl.disable(gl.BLEND);
      return;
    }

    gl.enable(gl.BLEND);

    if (
      next.blendSrc === enums.BLEND_CONSTANT_COLOR ||
      next.blendSrc === enums.BLEND_ONE_MINUS_CONSTANT_COLOR ||
      next.blendDst === enums.BLEND_CONSTANT_COLOR ||
      next.blendDst === enums.BLEND_ONE_MINUS_CONSTANT_COLOR
    ) {
      gl.blendColor(
        (next.blendColor >> 24) / 255,
        (next.blendColor >> 16 & 0xff) / 255,
        (next.blendColor >> 8 & 0xff) / 255,
        (next.blendColor & 0xff) / 255
      );
    }

    if (next.blendSep) {
      gl.blendFuncSeparate(next.blendSrc, next.blendDst, next.blendSrcAlpha, next.blendDstAlpha);
      gl.blendEquationSeparate(next.blendEq, next.blendAlphaEq);
    } else {
      gl.blendFunc(next.blendSrc, next.blendDst);
      gl.blendEquation(next.blendEq);
    }

    return;
  }

  // nothing to update
  if (next.blend === false) {
    return;
  }

  // blend-color
  if (cur.blendColor !== next.blendColor) {
    gl.blendColor(
      (next.blendColor >> 24) / 255,
      (next.blendColor >> 16 & 0xff) / 255,
      (next.blendColor >> 8 & 0xff) / 255,
      (next.blendColor & 0xff) / 255
    );
  }

  // separate diff, reset all
  if (cur.blendSep !== next.blendSep) {
    if (next.blendSep) {
      gl.blendFuncSeparate(next.blendSrc, next.blendDst, next.blendSrcAlpha, next.blendDstAlpha);
      gl.blendEquationSeparate(next.blendEq, next.blendAlphaEq);
    } else {
      gl.blendFunc(next.blendSrc, next.blendDst);
      gl.blendEquation(next.blendEq);
    }

    return;
  }

  if (next.blendSep) {
    // blend-func-separate
    if (
      cur.blendSrc !== next.blendSrc ||
      cur.blendDst !== next.blendDst ||
      cur.blendSrcAlpha !== next.blendSrcAlpha ||
      cur.blendDstAlpha !== next.blendDstAlpha
    ) {
      gl.blendFuncSeparate(next.blendSrc, next.blendDst, next.blendSrcAlpha, next.blendDstAlpha);
    }

    // blend-equation-separate
    if (
      cur.blendEq !== next.blendEq ||
      cur.blendAlphaEq !== next.blendAlphaEq
    ) {
      gl.blendEquationSeparate(next.blendEq, next.blendAlphaEq);
    }
  } else {
    // blend-func
    if (
      cur.blendSrc !== next.blendSrc ||
      cur.blendDst !== next.blendDst
    ) {
      gl.blendFunc(next.blendSrc, next.blendDst);
    }

    // blend-equation
    if (cur.blendEq !== next.blendEq) {
      gl.blendEquation(next.blendEq);
    }
  }
}
672063
public static int mix(int base, int added) {
        float bAlpha = ColorHelper.getAlpha(base) / 255f;
        float aAlpha = ColorHelper.getAlpha(added) / 255f;
        float alpha = 1 - (1 - bAlpha) * (1 - aAlpha); // alpha

        int bR = ColorHelper.getRed(base);
        int bG = ColorHelper.getGreen(base);
        int bB = ColorHelper.getBlue(base);

        int aR = ColorHelper.getRed(added);
        int aG = ColorHelper.getGreen(added);
        int aB = ColorHelper.getBlue(added);

        int r = Math.round((aR * aAlpha / alpha) + (bR * bAlpha * (1 - aAlpha) / alpha)); // red
        int g = Math.round((aG * aAlpha / alpha) + (bG * bAlpha * (1 - aAlpha) / alpha)); // green
        int b = Math.round((aB * aAlpha / alpha) + (bB * bAlpha * (1 - aAlpha) / alpha)); // blue

        return getARGB(r, g, b, (int) clamp(alpha * MAX));
    }
442384
function (color, elem, prop, wrapper) {
                var renderer = this,
                  colorObject,
                  regexRgba = /^rgba/,
                  markup,
                  fillType,
                  ret = NONE;

                // Check for linear or radial gradient
                if (color && color.linearGradient) {
                    fillType = 'gradient';
                } else if (color && color.radialGradient) {
                    fillType = 'pattern';
                }


                if (fillType) {

                    var stopColor,
                      stopOpacity,
                      gradient = color.linearGradient || color.radialGradient,
                      x1,
                      y1,
                      x2,
                      y2,
                      opacity1,
                      opacity2,
                      color1,
                      color2,
                      fillAttr = '',
                      stops = color.stops,
                      firstStop,
                      lastStop,
                      colors = [],
                      addFillNode = function () {
                          // Add the fill subnode. When colors attribute is used, the meanings of opacity and o:opacity2
                          // are reversed.
                          markup = ['<fill colors="' + colors.join(',') + '" opacity="', opacity2, '" o:opacity2="', opacity1,
                              '" type="', fillType, '" ', fillAttr, 'focus="100%" method="any" />'];
                          createElement(renderer.prepVML(markup), null, null, elem);
                      };

                    // Extend from 0 to 1
                    firstStop = stops[0];
                    lastStop = stops[stops.length - 1];
                    if (firstStop[0] > 0) {
                        stops.unshift([
                            0,
                            firstStop[1]
                        ]);
                    }
                    if (lastStop[0] < 1) {
                        stops.push([
                            1,
                            lastStop[1]
                        ]);
                    }

                    // Compute the stops
                    each(stops, function (stop, i) {
                        if (regexRgba.test(stop[1])) {
                            colorObject = Color(stop[1]);
                            stopColor = colorObject.get('rgb');
                            stopOpacity = colorObject.get('a');
                        } else {
                            stopColor = stop[1];
                            stopOpacity = 1;
                        }

                        // Build the color attribute
                        colors.push((stop[0] * 100) + '% ' + stopColor);

                        // Only start and end opacities are allowed, so we use the first and the last
                        if (!i) {
                            opacity1 = stopOpacity;
                            color2 = stopColor;
                        } else {
                            opacity2 = stopOpacity;
                            color1 = stopColor;
                        }
                    });

                    // Apply the gradient to fills only.
                    if (prop === 'fill') {

                        // Handle linear gradient angle
                        if (fillType === 'gradient') {
                            x1 = gradient.x1 || gradient[0] || 0;
                            y1 = gradient.y1 || gradient[1] || 0;
                            x2 = gradient.x2 || gradient[2] || 0;
                            y2 = gradient.y2 || gradient[3] || 0;
                            fillAttr = 'angle="' + (90  - math.atan(
                                (y2 - y1) / // y vector
                                (x2 - x1) // x vector
                              ) * 180 / mathPI) + '"';

                            addFillNode();

                            // Radial (circular) gradient
                        } else {

                            var r = gradient.r,
                              sizex = r * 2,
                              sizey = r * 2,
                              cx = gradient.cx,
                              cy = gradient.cy,
                              radialReference = elem.radialReference,
                              bBox,
                              applyRadialGradient = function () {
                                  if (radialReference) {
                                      bBox = wrapper.getBBox();
                                      cx += (radialReference[0] - bBox.x) / bBox.width - 0.5;
                                      cy += (radialReference[1] - bBox.y) / bBox.height - 0.5;
                                      sizex *= radialReference[2] / bBox.width;
                                      sizey *= radialReference[2] / bBox.height;
                                  }
                                  fillAttr = 'src="' + defaultOptions.global.VMLRadialGradientURL + '" ' +
                                    'size="' + sizex + ',' + sizey + '" ' +
                                    'origin="0.5,0.5" ' +
                                    'position="' + cx + ',' + cy + '" ' +
                                    'color2="' + color2 + '" ';

                                  addFillNode();
                              };

                            // Apply radial gradient
                            if (wrapper.added) {
                                applyRadialGradient();
                            } else {
                                // We need to know the bounding box to get the size and position right
                                wrapper.onAdd = applyRadialGradient;
                            }

                            // The fill element's color attribute is broken in IE8 standards mode, so we
                            // need to set the parent shape's fillcolor attribute instead.
                            ret = color1;
                        }

                        // Gradients are not supported for VML stroke, return the first color. #722.
                    } else {
                        ret = stopColor;
                    }

                    // if the color is an rgba color, split it and add a fill node
                    // to hold the opacity component
                } else if (regexRgba.test(color) && elem.tagName !== 'IMG') {

                    colorObject = Color(color);

                    markup = ['<', prop, ' opacity="', colorObject.get('a'), '"/>'];
                    createElement(this.prepVML(markup), null, null, elem);

                    ret = colorObject.get('rgb');


                } else {
                    var propNodes = elem.getElementsByTagName(prop); // 'stroke' or 'fill' node
                    if (propNodes.length) {
                        propNodes[0].opacity = 1;
                        propNodes[0].type = 'solid';
                    }
                    ret = color;
                }

                return ret;
            }
433430
def _rgb_to_rgbw(color):
        
        # Get the maximum between R, G, and B
        max_value = max(color)

        # If the maximum value is 0, immediately return pure black.
        if max_value == 0:
            return [0] * 4

        # Figure out what the color with 100% hue is
        multiplier = 255 / max_value
        hue_red = color.R * multiplier
        hue_green = color.G * multiplier
        hue_blue = color.B * multiplier

        # Calculate the whiteness (not strictly speaking luminance)
        max_hue = max(hue_red, hue_green, hue_blue)
        min_hue = min(hue_red, hue_green, hue_blue)
        luminance = ((max_hue + min_hue) / 2 - 127.5) * 2 / multiplier

        # Calculate the output values
        r = max(0, min(255, int(color.R - luminance)))
        g = max(0, min(255, int(color.G - luminance)))
        b = max(0, min(255, int(color.B - luminance)))
        w = max(0, min(255, int(luminance)))

        return [r, g, b, w]
1171157
def set_fill_color(self,r,g=-1,b=-1):
        ""
        if((r==0 and g==0 and b==0) or g==-1):
            self.fill_color=sprintf('%.3f g',r/255.0)
        else:
            self.fill_color=sprintf('%.3f %.3f %.3f rg',r/255.0,g/255.0,b/255.0)
        self.color_flag=(self.fill_color!=self.text_color)
        if(self.page>0):
            self._out(self.fill_color)
548222
public static int blendFunctionToGL(
    final JCGLBlendFunction function)
  {
    switch (function) {
      case BLEND_CONSTANT_ALPHA:
        return GL2ES2.GL_CONSTANT_ALPHA;
      case BLEND_CONSTANT_COLOR:
        return GL2ES2.GL_CONSTANT_COLOR;
      case BLEND_DESTINATION_ALPHA:
        return GL.GL_DST_ALPHA;
      case BLEND_DESTINATION_COLOR:
        return GL.GL_DST_COLOR;
      case BLEND_ONE:
        return GL.GL_ONE;
      case BLEND_ONE_MINUS_CONSTANT_ALPHA:
        return GL2ES2.GL_ONE_MINUS_CONSTANT_ALPHA;
      case BLEND_ONE_MINUS_CONSTANT_COLOR:
        return GL2ES2.GL_ONE_MINUS_CONSTANT_COLOR;
      case BLEND_ONE_MINUS_DESTINATION_ALPHA:
        return GL.GL_ONE_MINUS_DST_ALPHA;
      case BLEND_ONE_MINUS_DESTINATION_COLOR:
        return GL.GL_ONE_MINUS_DST_COLOR;
      case BLEND_ONE_MINUS_SOURCE_ALPHA:
        return GL.GL_ONE_MINUS_SRC_ALPHA;
      case BLEND_ONE_MINUS_SOURCE_COLOR:
        return GL.GL_ONE_MINUS_SRC_COLOR;
      case BLEND_SOURCE_ALPHA:
        return GL.GL_SRC_ALPHA;
      case BLEND_SOURCE_ALPHA_SATURATE:
        return GL.GL_SRC_ALPHA_SATURATE;
      case BLEND_SOURCE_COLOR:
        return GL.GL_SRC_COLOR;
      case BLEND_ZERO:
        return GL.GL_ZERO;
    }

    throw new UnreachableCodeException();
  }
869549
def _get_color(self, r, g, b):
        
        clr = (r, g, b)
        return clr
232655
def _fill(self):
        """"""
        r, g, b = hue2col(self._hue)
        width = self.winfo_width()
        height = self.winfo_height()
        h = float(height - 1)
        w = float(width - 1)
        if height:
            c = [(r + i / h * (255 - r), g + i / h * (255 - g), b + i / h * (255 - b)) for i in range(height)]
            data = []
            for i in range(height):
                line = []
                for j in range(width):
                    rij = round2(j / w * c[i][0])
                    gij = round2(j / w * c[i][1])
                    bij = round2(j / w * c[i][2])
                    color = rgb_to_hexa(rij, gij, bij)
                    line.append(color)
                data.append("{" + " ".join(line) + "}")
            self.bg.put(" ".join(data))