Java Color Brighten brighter(Color c, double factor)

Here you can find the source of brighter(Color c, double factor)

Description

Make the color brighter by the specified factor.

License

Open Source License

Parameter

Parameter Description
c a color
factor the smaller the factor, the brighter.

Return

a brighter color

Declaration

private static Color brighter(Color c, double factor) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.awt.*;

public class Main {
    /**/*from w  w  w .j a v  a2  s .c om*/
     * Make the color brighter by the specified factor.
     * <p/>
     * This code is adapted from java.awt.Color to take in a factor.
     * Therefore, it inherits its quirks. Most importantly,
     * a smaller factor makes the color more bright.
     *
     * @param c      a color
     * @param factor the smaller the factor, the brighter.
     * @return a brighter color
     */
    private static Color brighter(Color c, double factor) {
        int r = c.getRed();
        int g = c.getGreen();
        int b = c.getBlue();

        /* From 2D group:
         * 1. black.brighter() should return grey
         * 2. applying brighter to blue will always return blue, brighter
         * 3. non pure color (non zero rgb) will eventually return white
         */
        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(final int cValue, double colorBrigthnessFactor)
  2. brighten(float[] rgb, float luminosity)
  3. brightenColor(Color color, double factor)
  4. brighter(Color c)
  5. brighter(Color c)
  6. brighter(Color c, double p)
  7. brighter(Color col, double FACTOR)
  8. brighter(Color color)
  9. brighter(Color color)