Java Color Brighten brightenColor(Color color, double factor)

Here you can find the source of brightenColor(Color color, double factor)

Description

Brightens each of the RGB components of color by the specified factor.

License

Open Source License

Parameter

Parameter Description
color color to brighten
factor luminosity factor; if negative, the color is darkened

Return

brightened color

Declaration

public static Color brightenColor(Color color, double factor) 

Method Source Code

//package com.java2s;

import java.awt.Color;

public class Main {
    /**/*from  ww  w  .j a va  2s .  com*/
     * Brightens each of the RGB components of color by the specified factor.
     * Note: This is identical to the java.awt.Color.brighten() method, using a variable factor.
     * 
     * @param color color to brighten
     * @param factor luminosity factor; if negative, the color is darkened  
     * @return brightened color
     */
    public static Color brightenColor(Color color, double factor) {
        int r = color.getRed();
        int g = color.getGreen();
        int b = color.getBlue();

        int i = (int) (1.0 / (1.0 - factor));
        if (r == 0 && g == 0 && b == 0) {
            return new Color(i, i, i);
        }

        if (r > 0 && r < i) {
            r = i;
        }
        if (g > 0 && g < i) {
            g = i;
        }
        if (b > 0 && b < i) {
            b = i;
        }

        return new Color(Math.min((int) (r / factor), 255), Math.min((int) (g / factor), 255),
                Math.min((int) (b / factor), 255));
    }
}

Related

  1. brighten(Color color)
  2. brighten(final Color color, final double percentage)
  3. brighten(final int color)
  4. brighten(final int cValue, double colorBrigthnessFactor)
  5. brighten(float[] rgb, float luminosity)
  6. brighter(Color c)
  7. brighter(Color c)
  8. brighter(Color c, double factor)
  9. brighter(Color c, double p)