Java Color Lighten lightenColor(Color col, float factor)

Here you can find the source of lightenColor(Color col, float factor)

Description

Lightens up a color for groove, ridge, inset and outset border effects.

License

Apache License

Parameter

Parameter Description
col the color to lighten up
factor factor by which to lighten up (negative values darken the color)

Return

the modified color

Declaration

public static Color lightenColor(Color col, float factor) 

Method Source Code

//package com.java2s;
/*/*  w  w w .j  av  a2 s  .  co m*/
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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.
 */

import java.awt.Color;

public class Main {
    /**
     * Lightens up a color for groove, ridge, inset and outset border effects.
     * @param col the color to lighten up
     * @param factor factor by which to lighten up (negative values darken the color)
     * @return the modified color
     */
    public static Color lightenColor(Color col, float factor) {
        // TODO: This function converts the color into the sRGB namespace.
        // This should be avoided if possible.
        float[] cols = new float[4];
        cols = col.getRGBComponents(cols);
        if (factor > 0) {
            cols[0] += (1.0 - cols[0]) * factor;
            cols[1] += (1.0 - cols[1]) * factor;
            cols[2] += (1.0 - cols[2]) * factor;
        } else {
            cols[0] -= cols[0] * -factor;
            cols[1] -= cols[1] * -factor;
            cols[2] -= cols[2] * -factor;
        }
        return new Color(cols[0], cols[1], cols[2], cols[3]);
    }
}

Related

  1. lighten(Color color)
  2. lighten(Color color, double strength)
  3. lighten(final Color color, final int amount)
  4. lighten(int r, int g, int b, double percent)
  5. lightenColor(Color color)
  6. lighter(Color c)
  7. lighter(Color c)
  8. lighter(Color c, boolean transparant)