Java Color Multiply multiplyColorComponents(int color, float brightnessFactor)

Here you can find the source of multiplyColorComponents(int color, float brightnessFactor)

Description

Individually multiply R, G, B color components by scalar value to dim or brighten the color.

License

Open Source License

Parameter

Parameter Description
color - original color
brightnessFactor - should be positive and <> 1.0F

Return

- modified color

Declaration

public static int multiplyColorComponents(int color, float brightnessFactor) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2012 Yancarlo Ramsey and CJ Bowman
 * Licensed as open source with restrictions. Please see attached LICENSE.txt.
 ******************************************************************************/

public class Main {
    private static final int MASKR = 0xFF0000;
    private static final int MASKG = 0x00FF00;
    private static final int MASKB = 0x0000FF;

    /**//  w w  w .jav a2  s. com
     * Individually multiply R, G, B color components by scalar value to dim or brighten the color.
     * Does not check for overflow. Beware when using values over 1.0F.
     * @param color - original color
     * @param brightnessFactor - should be positive and <> 1.0F
     * @return - modified color
     */
    public static int multiplyColorComponents(int color, float brightnessFactor) {
        return ((int) (brightnessFactor * (color & MASKR)) & MASKR)
                | ((int) (brightnessFactor * (color & MASKG)) & MASKG)
                | ((int) (brightnessFactor * (color & MASKB)) & MASKB);
    }
}

Related

  1. multiply(double color1, double color2)
  2. multiply(int colorA, int colorB)
  3. multiplyColor(int p_180188_0_, int p_180188_1_)
  4. multiplyColor(int src, int dst)