Java Color Brighten brighten(Color color)

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

Description

brighten

License

Open Source License

Parameter

Parameter Description
color a parameter

Return

Increases brightness. If factor < 1 it will get dimmer.

Declaration

public static Color brighten(Color color) 

Method Source Code

//package com.java2s;
/* /*from   w  ww  .  ja  v a  2  s  . c  o  m*/
    
 Created on Mar 4, 2005
    
 The Bungee View applet lets you search, browse, and data-mine an image collection.  
 Copyright (C) 2006  Mark Derthick
    
 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version 2
 of the License, or (at your option) any later version.  See gpl.html.
    
 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 General Public License for more details.
    
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    
 You may also contact the author at 
 mad@cs.cmu.edu, 
 or at
 Mark Derthick
 Carnegie-Mellon University
 Human-Computer Interaction Institute
 Pittsburgh, PA 15213
    
 */

import java.awt.Color;

public class Main {
    private static final float colorComponentChangeFactor = 2.0f;

    /**
     * @param color
     * @return Increases brightness. If factor < 1 it will get dimmer.
     */
    public static Color brighten(Color color) {
        return brighten(color, colorComponentChangeFactor);
    }

    /**
     * @param color
     * @param factor
     * @return Multiplies brightness by factor. If factor < 1 it will get
     *         dimmer.
     */
    public static Color brighten(Color color, float factor) {
        if (factor <= 0.0)
            factor = colorComponentChangeFactor;
        float[] hsb = getHSBcomponents(color);
        return Color.getHSBColor(hsb[0], hsb[1], Math.min(1.0f, hsb[2] * factor));
    }

    public static float[] getHSBcomponents(Color color) {
        float[] result = new float[3];
        Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), result);
        return result;
    }

    public static Color getHSBColor(float h, float s, float b, float alpha) {
        Color c = Color.getHSBColor(h, s, b);
        return new Color(c.getRed(), c.getGreen(), c.getBlue(), (int) (alpha * 255 + 0.5));
    }
}

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 c, double f)
  5. brighten(final Color color, final double percentage)
  6. brighten(final int color)
  7. brighten(final int cValue, double colorBrigthnessFactor)
  8. brighten(float[] rgb, float luminosity)