Java Color Brighten brighten(Color c, double f)

Here you can find the source of brighten(Color c, double f)

Description

Brighten a color by a given amount

License

GNU General Public License

Declaration

public static Color brighten(Color c, double f) 

Method Source Code

//package com.java2s;
/*/*from   w  w  w .j ava  2 s. com*/
 * Copyright (C) 2015  University of Oregon
 *
 * You may distribute under the terms of either the GNU General Public
 * License or the Apache License, as specified in the LICENSE file.
 *
 * For more information, see the LICENSE file.
 */

import java.awt.*;

public class Main {
    /**
     * Brighten a color by a given amount  
     */
    public static Color brighten(Color c, double f) {
        return mix(c, Color.white, f);
    }

    /**
     * Mix two colors by a given amount  
     */
    public static Color mix(Color c1, Color c2, double f) {
        if (f >= 1.0)
            return c2;

        if (f <= 0)
            return c1;

        double r1 = c1.getRed();
        double g1 = c1.getGreen();
        double b1 = c1.getBlue();
        double r2 = c2.getRed();
        double g2 = c2.getGreen();
        double b2 = c2.getBlue();
        double r = f * r2 + (1 - f) * r1;
        double g = f * g2 + (1 - f) * g1;
        double b = f * b2 + (1 - f) * b1;

        Color c3 = new Color(Math.min((int) (r), 255), Math.min((int) (g),
                255), Math.min((int) (b), 255));

        return c3;
    }
}

Related

  1. adjustBrightness(Color c, float difference)
  2. adjustColorBrightness(Color base, float brightness)
  3. adjustHSB(Color inputColor, float hue, float saturation, float brightness)
  4. brighten(Color color)
  5. brighten(final Color color, final double percentage)
  6. brighten(final int color)
  7. brighten(final int cValue, double colorBrigthnessFactor)