Java Color Brighten brighten(final int color)

Here you can find the source of brighten(final int color)

Description

brighten

License

Apache License

Declaration

public static int brighten(final int color) 

Method Source Code

//package com.java2s;
/*// w  ww .j a va2 s. co  m
 * Copyright 2014 Aritz Lopez
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

public class Main {
    /**
     * The mask to get the two least significant bytes of an integer;
     */
    public static final int MASK = 0xFF;
    /**
     * The shifting used to put the alpha component in position
     */
    public static final int ALPHA_SHIFT = 24;
    /**
     * The shifting used to put the red component in position
     */
    public static final int RED_SHIFT = 16;
    /**
     * The shifting used to put the green component in position
     */
    public static final int GREEN_SHIFT = 8;
    private static final double BRIGHTNESS_FACTOR = 0.2;

    public static int brighten(final int color) {
        final int r = getRed(color);
        final int g = getGreen(color);
        final int b = getBlue(color);
        int newR = (int) (r + (255 - r) * BRIGHTNESS_FACTOR);
        int newG = (int) (g + (255 - g) * BRIGHTNESS_FACTOR);
        int newB = (int) (b + (255 - b) * BRIGHTNESS_FACTOR);
        return getColor(getAlpha(color), newR, newG, newB);
    }

    /**
     * Returns the red channel of the color
     *
     * @param color The color to get the red channel of
     * @return The red channel of the color
     */
    public static int getRed(final int color) {
        return (color >> RED_SHIFT) & MASK;
    }

    /**
     * Returns the green channel of the color
     *
     * @param color The color to get the green channel of
     * @return The green channel of the color
     */
    public static int getGreen(final int color) {
        return (color >> GREEN_SHIFT) & MASK;
    }

    /**
     * Returns the blue channel of the color
     *
     * @param color The color to get the blue channel of
     * @return The blue channel of the color
     */
    public static int getBlue(final int color) {
        return (color & MASK);
    }

    /**
     * Gets a color composed of the specified channels. All values must be between 0 and 255, both inclusive
     *
     * @param alpha The alpha channel [0-255]
     * @param red   The red channel [0-255]
     * @param green The green channel [0-255]
     * @param blue  The blue channel [0-255]
     * @return The color composed of the specified channels
     */
    public static int getColor(final int alpha, final int red, final int green, final int blue) {
        return (alpha << ALPHA_SHIFT) | (red << RED_SHIFT) | (green << GREEN_SHIFT) | blue;
    }

    /**
     * Returns the alpha channel of the color
     *
     * @param color The color to get the alpha channel of
     * @return The alpha channel of the color
     */
    public static int getAlpha(final int color) {
        return (color >> ALPHA_SHIFT) & MASK;
    }
}

Related

  1. adjustColorBrightness(Color base, float brightness)
  2. adjustHSB(Color inputColor, float hue, float saturation, float brightness)
  3. brighten(Color c, double f)
  4. brighten(Color color)
  5. brighten(final Color color, final double percentage)
  6. brighten(final int cValue, double colorBrigthnessFactor)
  7. brighten(float[] rgb, float luminosity)
  8. brightenColor(Color color, double factor)
  9. brighter(Color c)