Java Color Brighten slightlyBrighter(Color color)

Here you can find the source of slightlyBrighter(Color color)

Description

Moderated version of Color.brighter()

License

Open Source License

Parameter

Parameter Description
color a parameter

Declaration

public static Color slightlyBrighter(Color color) 

Method Source Code

//package com.java2s;
/**/*  w w  w .  ja  va 2  s  . c  o m*/
 * DataCleaner (community edition)
 * Copyright (C) 2014 Neopost - Customer Information Management
 *
 * This copyrighted material is made available to anyone wishing to use, modify,
 * copy, or redistribute it subject to the terms and conditions of the GNU
 * Lesser General Public License, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
 * for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this distribution; if not, write to:
 * Free Software Foundation, Inc.
 * 51 Franklin Street, Fifth Floor
 * Boston, MA  02110-1301  USA
 */

import java.awt.Color;

public class Main {
    /**
     * Slightly moderated version of COLOR.FACTOR
     */
    private static final double COLOR_SCALE_FACTOR = 0.9;

    /**
     * Moderated version of Color.brighter()
     * 
     * @param color
     * @return
     */
    public static Color slightlyBrighter(Color color) {
        int r = color.getRed();
        int g = color.getGreen();
        int b = color.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 - COLOR_SCALE_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 / COLOR_SCALE_FACTOR), 255),
                Math.min((int) (g / COLOR_SCALE_FACTOR), 255), Math.min((int) (b / COLOR_SCALE_FACTOR), 255));
    }
}

Related

  1. perceivedBrightness(Color c)
  2. setBrightness(Color color, float brightness)
  3. setBrightness(Color color, float brightness)
  4. setColorBrightness(Color c, double y)
  5. shiftHSB(java.awt.Color color, double hueDelta, double saturationDelta, double brightnessDelta)
  6. whiter(Color color)