// Decompiled by Jad v1.5.7. Copyright 1997-99 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   ColorUtils.java

package com.symantec.itools.awt.util;

import java.awt.Color;

import com.symantec.itools.util.GeneralUtils;

public class ColorUtils
{

    public ColorUtils()
    {
    }

    public static Color darken(int i, int j, int k, double d)
        throws IllegalArgumentException
    {
        GeneralUtils.checkValidPercent(d);
        return new Color(Math.max((int)((double)i * (1.0D - d)), 0), Math.max((int)((double)j * (1.0D - d)), 0), Math.max((int)((double)k * (1.0D - d)), 0));
    }

    public static Color darken(Color color, double d)
        throws IllegalArgumentException
    {
        GeneralUtils.checkValidPercent(d);
        int i = color.getRed();
        int j = color.getGreen();
        int k = color.getBlue();
        return darken(i, j, k, d);
    }

    public static Color lighten(int i, int j, int k, double d)
        throws IllegalArgumentException
    {
        GeneralUtils.checkValidPercent(d);
        int l = i + (int)((double)(255 - i) * d);
        int i1 = j + (int)((double)(255 - j) * d);
        int j1 = k + (int)((double)(255 - k) * d);
        return new Color(l, i1, j1);
    }

    public static Color lighten(Color color, double d)
        throws IllegalArgumentException
    {
        GeneralUtils.checkValidPercent(d);
        int i = color.getRed();
        int j = color.getGreen();
        int k = color.getBlue();
        return lighten(i, j, k, d);
    }

    public static Color fade(Color color, Color color1, double d)
        throws IllegalArgumentException
    {
        GeneralUtils.checkValidPercent(d);
        int i = color.getRed();
        int j = color.getGreen();
        int k = color.getBlue();
        int l = color1.getRed();
        int i1 = color1.getGreen();
        int j1 = color1.getBlue();
        int k1;
        if(i > l)
            k1 = l + (int)((double)(i - l) * (1.0D - d));
        else
            k1 = l - (int)((double)(l - i) * (1.0D - d));
        int l1;
        if(j > l)
            l1 = i1 + (int)((double)(j - i1) * (1.0D - d));
        else
            l1 = i1 - (int)((double)(i1 - j) * (1.0D - d));
        int i2;
        if(k > j1)
            i2 = j1 + (int)((double)(k - j1) * (1.0D - d));
        else
            i2 = j1 - (int)((double)(j1 - k) * (1.0D - d));
        return new Color(k1, l1, i2);
    }

    public static double lightness(Color color)
    {
        if(color == null)
        {
            return 0.0D;
        }
        else
        {
            double d = color.getRed();
            double d1 = color.getGreen();
            double d2 = color.getBlue();
            double d3 = Math.max(d, Math.max(d1, d2)) / 255D / 2D;
            double d4 = Math.min(d, Math.min(d1, d2)) / 255D / 2D;
            return d3 + d4;
        }
    }

    public static Color calculateHilightColor(Color color)
    {
        if(color == null)
            return null;
        double d = lightness(color);
        if(d >= 0.90000000000000002D)
            return darken(color, 0.10000000000000001D);
        if(d <= 0.20000000000000001D)
            return lighten(color, 0.59999999999999998D);
        else
            return lighten(color, 0.59999999999999998D);
    }

    public static Color calculateShadowColor(Color color)
    {
        if(color == null)
            return null;
        double d = lightness(color);
        if(d >= 0.90000000000000002D)
            return darken(color, 0.25D);
        if(d <= 0.20000000000000001D)
            return lighten(color, 0.20000000000000001D);
        else
            return darken(color, 0.25D);
    }
}
