Java Utililty Methods Color Mix

List of utility methods to do Color Mix

Description

The list of methods to do Color Mix are organized into topic(s).

Method

intmix(int a, int b, int amt)
mix
return a + (((b - a) * amt) >> 8);
PaintmixColor(Paint p, double value)
mix Color
if (p == null || !(p instanceof Color))
    return p;
Color c = (Color) p;
return new Color(c.getRed(), c.getGreen(), c.getBlue(), ((int) value) * 255 / 100);
ColormixColors(Color a, Color b, double r)
mix Colors
double s = 1.0f - r;
return new Color(boundColor((a.getRed() * r + b.getRed() * s) / 255.0),
        boundColor((a.getGreen() * r + b.getGreen() * s) / 255.0),
        boundColor((a.getBlue() * r + b.getBlue() * s) / 255.0));
Color[]mixColors(Color c)

Returns an array of 9 colors which one could use very good together.

The code to calculate the colors is taken from Twyst .
I've just translated it into Java.

Color[] result = new Color[9];
result[0] = c;
double[] hs = RGBtoHSV(c);
double[] y = new double[3];
double[] yx = new double[3];
double[] p = new double[3];
double[] pr = new double[3];
p[0] = y[0] = hs[0];
...
ColormixColors(List colors)
mix Colors
int red = 0, green = 0, blue = 0;
for (Color color : colors) {
    double colorCount = 0;
    if (color.getRed() > 0)
        colorCount++;
    if (color.getGreen() > 0)
        colorCount++;
    if (color.getBlue() > 0)
...
ColormixColorWithAlpha(Color base, Color mix)
mix Color With Alpha
if (mix == null)
    return base;
final int a0 = mix.getAlpha();
if (a0 == 0) {
    return base;
} else if (a0 == 0xFF)
    return mix;
final float wm = (float) a0 / 0xFF;
...
ColormixedColor(Color originalColor, Color overlayColor)
mixed Color
final float[] hsbColor = Color.RGBtoHSB(originalColor.getRed(), originalColor.getGreen(),
        originalColor.getBlue(), new float[3]);
;
final float[] hsbError = Color.RGBtoHSB(overlayColor.getRed(), overlayColor.getGreen(),
        overlayColor.getBlue(), new float[3]);
final float[] hsbMixed = new float[3];
hsbMixed[0] = hsbError[0];
hsbMixed[1] = min(max(rangeLimit(hsbColor[1], hsbError[1], 0.3f), 0.5f), 1.0f);
...
ColormixOver(Color backColor, Color frontColor)
Mix 2 colors with priority color
final int r, g, b, a;
final float frontAlpha = frontColor.getAlpha() / 255f;
final float invAlpha = 1f - frontAlpha;
r = (int) ((backColor.getRed() * invAlpha) + (frontColor.getRed() * frontAlpha));
g = (int) ((backColor.getGreen() * invAlpha) + (frontColor.getGreen() * frontAlpha));
b = (int) ((backColor.getBlue() * invAlpha) + (frontColor.getBlue() * frontAlpha));
a = Math.max(backColor.getAlpha(), frontColor.getAlpha());
return new Color(r, g, b, a);
...
PaintmixWith(Paint paint, Color mix)
mix With
if (paint instanceof Color) {
    Color c = (Color) paint;
    return new Color((c.getRed() + mix.getRed()) / 2, (c.getGreen() + mix.getGreen()) / 2,
            (c.getBlue() + mix.getBlue()) / 2, (c.getAlpha() + mix.getAlpha()) / 2);
} else if (paint instanceof TexturePaint) {
    BufferedImage texture = ((TexturePaint) paint).getImage();
    BufferedImage mixed = new BufferedImage(texture.getWidth(), texture.getHeight(), texture.getType());
    for (int x = 0; x < texture.getWidth(); x++) {
...