public static int contrast ( Color left , Color right ) throws ServletException { return ( Math . max ( left . getRed ( ) , right . getRed ( ) ) - Math . min ( left . getRed ( ) , right . getRed ( ) ) ) + ( Math . max ( left . getGreen ( ) , right . getGreen ( ) ) - Math . min ( left . getGreen ( ) , right . getGreen ( ) ) ) + ( Math . max ( left . getBlue ( ) , right . getBlue ( ) ) - Math . max ( left . getBlue ( ) , right . getBlue ( ) ) ) ; }
calculate the contrast between 2 colors