Java Utililty Methods Color Blend

List of utility methods to do Color Blend

Description

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

Method

ColoralphaBlend(Color o, int a)
alpha Blend
return new Color(o.getRed(), o.getGreen(), o.getBlue(), a);
ColoralphaBlend(final Color src, final Color dst)
Blends the two colors taking into account their alpha.
If one of the two input colors implements the UIResource interface, the result color will also implement this interface.
Color blend;
final float srcA = (float) src.getAlpha() / 255.0f;
final float dstA = (float) dst.getAlpha() / 255.0f;
final float outA = srcA + dstA * (1 - srcA);
if (outA > 0) {
    final float outR = ((float) src.getRed() * srcA + (float) dst.getRed() * dstA * (1.0f - srcA)) / outA;
    final float outG = ((float) src.getGreen() * srcA + (float) dst.getGreen() * dstA * (1.0f - srcA))
            / outA;
...
Colorblend(Color a, Color b)
blend
int red = lerp(a.getRed(), b.getRed(), (a.getAlpha() / 255.0));
int blue = lerp(a.getBlue(), b.getBlue(), (a.getAlpha() / 255.0));
int green = lerp(a.getGreen(), b.getGreen(), (a.getAlpha() / 255.0));
int alpha = lerp(a.getAlpha(), b.getAlpha(), (a.getAlpha() / 255.0));
return new Color(red, green, blue, alpha);
Colorblend(Color a, Color b, double val)
blend
return new Color((int) (b.getRed() * val + a.getRed() * (1 - val)),
        (int) (b.getGreen() * val + a.getGreen() * (1 - val)),
        (int) (b.getBlue() * val + a.getBlue() * (1 - val)));
Colorblend(Color c0, Color c1)
blend
double totalAlpha = c0.getAlpha() + c1.getAlpha();
double weight0 = c0.getAlpha() / totalAlpha;
double weight1 = c1.getAlpha() / totalAlpha;
double r = weight0 * c0.getRed() + weight1 * c1.getRed();
double g = weight0 * c0.getGreen() + weight1 * c1.getGreen();
double b = weight0 * c0.getBlue() + weight1 * c1.getBlue();
double a = Math.max(c0.getAlpha(), c1.getAlpha());
return new Color((int) r, (int) g, (int) b, (int) a);
...
Colorblend(Color c1, Color c2)
Blend 2 colors equally.
return new Color((c1.getRed() + c2.getRed()) / 2, (c1.getGreen() + c2.getGreen()) / 2,
        (c1.getBlue() + c2.getBlue()) / 2);
Colorblend(Color c1, Color c2)
Blends the two supplied colors.
return new Color((c1.getRed() + c2.getRed()) >> 1, (c1.getGreen() + c2.getGreen()) >> 1,
        (c1.getBlue() + c2.getBlue()) >> 1);
Colorblend(Color c1, Color c2, double v)
blend
double v2 = 1 - v;
return c1 == null ? (c2 == null ? null : c2)
        : c2 == null ? c1
                : new Color(Math.min(255, (int) (c1.getRed() * v2 + c2.getRed() * v)),
                        Math.min(255, (int) (c1.getGreen() * v2 + c2.getGreen() * v)),
                        Math.min(255, (int) (c1.getBlue() * v2 + c2.getBlue() * v)),
                        Math.min(255, (int) (c1.getAlpha() * v2 + c2.getAlpha() * v)));
Colorblend(Color cFrom, Color cTo, float factor)
Blends the given colors by the given factor.
if (factor < 0f || factor > 1f) {
    throw new IllegalArgumentException("factor not between 0 and 1: " + factor);
float[] rgbaFrom = cFrom.getRGBComponents(null);
float[] rgbaTo = cTo.getRGBComponents(null);
rgbaFrom[0] += (rgbaTo[0] - rgbaFrom[0]) * factor;
rgbaFrom[1] += (rgbaTo[1] - rgbaFrom[1]) * factor;
rgbaFrom[2] += (rgbaTo[2] - rgbaFrom[2]) * factor;
...
Colorblend(Color col1, Color col2, float weight1)
Blend two colours, in the given proportions.
float weight2 = (1.0F - weight1) / 255;
weight1 /= 255;
return new Color(col1.getRed() * weight1 + col2.getRed() * weight2,
        col1.getGreen() * weight1 + col2.getGreen() * weight2,
        col1.getBlue() * weight1 + col2.getBlue() * weight2);