// Created by: NW,JPB,CAL
// Copyright (c) 1991-1999 Matra Datavision
// Copyright (c) 1999-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.

#ifndef _Quantity_Color_HeaderFile
#define _Quantity_Color_HeaderFile

#include <Standard.hxx>
#include <Standard_DefineAlloc.hxx>
#include <Standard_Handle.hxx>

#include <Standard_ShortReal.hxx>
#include <Quantity_NameOfColor.hxx>
#include <Quantity_Parameter.hxx>
#include <Quantity_TypeOfColor.hxx>
#include <Quantity_Rate.hxx>
#include <Standard_Real.hxx>
#include <Standard_Boolean.hxx>
#include <Standard_CString.hxx>
#include <Standard_Integer.hxx>
class Quantity_ColorDefinitionError;


//! This class allows the definition of a colour.
//! The names of the colours are from the X11 specification.
//! color object may be used for numerous applicative purposes.
//! A color is defined by:
//! -   its respective quantities of red, green and blue (R-G-B values), or
//! -   its hue angle and its values of lightness and  saturation (H-L-S values).
//! These two color definition systems are equivalent.
//! Use this class in conjunction with:
//! -   the Quantity_TypeOfColor enumeration
//! which identifies the color definition system you are using,
//! -   the Quantity_NameOfColor enumeration
//! which lists numerous predefined colors and
//! identifies them by their name.
class Quantity_Color 
{
public:

  DEFINE_STANDARD_ALLOC

  
  //! Creates a colour with the default value of
  //! Colour name : YELLOW
  Standard_EXPORT Quantity_Color();
  
  //! Creates the colour <AName>.
  Standard_EXPORT Quantity_Color(const Quantity_NameOfColor AName);
  
  //! Creates a colour according to the definition system
  //! TypeOfColor.
  //! TOC_RGB : <R1> the value of red between 0. and 1.
  //! <R2> the value of green between 0. and 1.
  //! <R3> the value of blue between 0. and 1.
  //!
  //! TOC_HLS : <R1> is the hue angle in degrees, 0. being red
  //! <R2> is the lightness between 0. and 1.
  //! <R3> is the saturation between 0. and 1.
  Standard_EXPORT Quantity_Color(const Quantity_Parameter R1, const Quantity_Parameter R2, const Quantity_Parameter R3, const Quantity_TypeOfColor AType);
  
  //! Increases or decreases the contrast by <ADelta>.
  //! <ADelta> is a percentage. Any value greater than zero
  //! will increase the contrast.
  //! The variation is expressed as a percentage of the
  //! current value.
  //! It is a variation of the saturation.
  Standard_EXPORT void ChangeContrast (const Quantity_Rate ADelta);
  
  //! Increases or decreases the intensity by <ADelta>.
  //! <ADelta> is a percentage. Any value greater than zero
  //! will increase the intensity.
  //! The variation is expressed as a percentage of the
  //! current value.
  //! It is a variation of the lightness.
  Standard_EXPORT void ChangeIntensity (const Quantity_Rate ADelta);
  
  //! Updates the colour <me> from the definition of the
  //! colour <AName>.
  Standard_EXPORT void SetValues (const Quantity_NameOfColor AName);
  
  //! Updates a colour according to the mode specified by
  //! TypeOfColor
  //! TOC_RGB : <R1> the value of red between 0. and 1.
  //! <R2> the value of green between 0. and 1.
  //! <R3> the value of blue between 0. and 1.
  //!
  //! TOC_HLS : <R1> is the hue angle in degrees, 0. being red
  //! <R2> is the lightness between 0. and 1.
  //! <R3> is the saturation between 0. and 1.
  Standard_EXPORT void SetValues (const Quantity_Parameter R1, const Quantity_Parameter R2, const Quantity_Parameter R3, const Quantity_TypeOfColor AType);
  
  //! Returns the percentage change of contrast and intensity
  //! between <me> and <AColor>.
  //! <DC> and <DI> are percentages, either positive or negative.
  //! The calculation is with respect to the current value of <me>
  //! If <DC> is positive then <me> is more contrasty.
  //! If <DI> is positive then <me> is more intense.
  Standard_EXPORT void Delta (const Quantity_Color& AColor, Quantity_Parameter& DC, Quantity_Parameter& DI) const;
  
  //! Returns the distance between two colours. It's a
  //! value between 0 and the square root of 3
  //! (the black/white distance)
  Standard_EXPORT Standard_Real Distance (const Quantity_Color& AColor) const;
  
  //! Returns the square of distance between two colours.
  Standard_EXPORT Standard_Real SquareDistance (const Quantity_Color& AColor) const;
  
  //! Returns the Blue component (quantity of blue) of the
  //! color <me>.
  Standard_EXPORT Quantity_Parameter Blue() const;
  
  //! Returns the Green component (quantity of green) of the
  //! color <me>.
  Standard_EXPORT Quantity_Parameter Green() const;
  
  //! Returns the Hue component (hue angle) of the
  //! color <me>.
  Standard_EXPORT Quantity_Parameter Hue() const;
  
  //! Returns Standard_True if the distance between <me> and
  //! <Other> is greater than Epsilon ().
  Standard_EXPORT Standard_Boolean IsDifferent (const Quantity_Color& Other) const;
Standard_Boolean operator != (const Quantity_Color& Other) const
{
  return IsDifferent(Other);
}
  
  //! Returns true if the Other color is
  //! -   different from, or
  //! -   equal to this color.
  //! Two colors are considered to be equal if their
  //! distance is no greater than Epsilon().
  //! These methods are aliases of operator != and operator ==.
  Standard_EXPORT Standard_Boolean IsEqual (const Quantity_Color& Other) const;
Standard_Boolean operator == (const Quantity_Color& Other) const
{
  return IsEqual(Other);
}
  
  //! Returns the Light component (value of the lightness) of the
  //! color <me>.
  Standard_EXPORT Quantity_Parameter Light() const;
  
  //! Returns the name of the color defined by its
  //! quantities of red R, green G and blue B; more
  //! precisely this is the nearest color from the
  //! Quantity_NameOfColor enumeration.
  //! Exceptions
  //! Standard_OutOfRange if R, G or B is less than 0. or greater than 1.
  Standard_EXPORT Quantity_NameOfColor Name() const;
  
  //! Returns the Red component (quantity of red) of the
  //! color <me>.
  Standard_EXPORT Quantity_Parameter Red() const;
  
  //! Returns the Saturation component (value of the saturation)
  //! of the color <me>.
  Standard_EXPORT Quantity_Parameter Saturation() const;
  
  //! Returns in R1, R2 and R3 the components of
  //! this color according to the color system definition AType.
  //! -   if AType is Quantity_TOC_RGB R1 is the
  //! quantity of red, R2 is the quantity of green and
  //! R3 is the quantity of blue in this color.
  //! -   if AType is Quantity_TOC_HLS R1 is the
  //! hue angle in degrees (0 being red), R2 is the
  //! lightness and R3 is the saturation of this color.
  Standard_EXPORT void Values (Quantity_Parameter& R1, Quantity_Parameter& R2, Quantity_Parameter& R3, const Quantity_TypeOfColor AType) const;
  
  //! Sets the specified value used to compare <me> and
  //! an other color in IsDifferent and in IsEqual methods.
  //! Warning: The default value is 0.0001
  Standard_EXPORT static void SetEpsilon (const Quantity_Parameter AnEpsilon);
  
  //! Returns the specified value used to compare <me> and
  //! an other color in IsDifferent and in IsEqual methods.
  Standard_EXPORT static Quantity_Parameter Epsilon();
  
  //! Returns the name of the colour for which the RGB components
  //! are nearest to <R>, <G> and <B>.
  Standard_EXPORT static Quantity_NameOfColor Name (const Quantity_Parameter R, const Quantity_Parameter G, const Quantity_Parameter B);
  
  //! Returns the name of the color identified by
  //! AName in the Quantity_NameOfColor enumeration.
  //! For example, the name of the color which
  //! corresponds to Quantity_NOC_BLACK is "BLACK".
  //! Exceptions
  //! Standard_OutOfRange if AName in not known
  //! in the Quantity_NameOfColor enumeration.
  Standard_EXPORT static Standard_CString StringName (const Quantity_NameOfColor AColor);
  
  //! Finds color from predefined names.
  //! For example, the name of the color which
  //! corresponds to "BLACK" is Quantity_NOC_BLACK.
  //! Returns false if name is unknown.
  Standard_EXPORT static Standard_Boolean ColorFromName (const Standard_CString theName, Quantity_NameOfColor& theColor);
  
  //! Converts HLS components into RGB ones.
  Standard_EXPORT static void HlsRgb (const Quantity_Parameter H, const Quantity_Parameter L, const Quantity_Parameter S, Quantity_Parameter& R, Quantity_Parameter& G, Quantity_Parameter& B);
  
  //! Converts RGB components into HLS ones.
  Standard_EXPORT static void RgbHls (const Quantity_Parameter R, const Quantity_Parameter G, const Quantity_Parameter B, Quantity_Parameter& H, Quantity_Parameter& L, Quantity_Parameter& S);
  
  //! Convert the Color value to ARGB integer value.
  //! theARGB has Alpha equal to zero, so the output is
  //! formatted as 0x00RRGGBB
  Standard_EXPORT static void Color2argb (const Quantity_Color& theColor, Standard_Integer& theARGB);
  
  //! Convert integer ARGB value to Color. Alpha bits are ignored
  Standard_EXPORT static void Argb2color (const Standard_Integer theARGB, Quantity_Color& theColor);
  
  //! Internal test
  Standard_EXPORT static void Test();




protected:





private:

  
  //! Converts HLS components into RGB ones.
  Standard_EXPORT static void hlsrgb (const Standard_ShortReal H, const Standard_ShortReal L, const Standard_ShortReal S, Standard_ShortReal& R, Standard_ShortReal& G, Standard_ShortReal& B);
  
  //! Converts RGB components into HLS ones.
  Standard_EXPORT static void rgbhls (const Standard_ShortReal R, const Standard_ShortReal G, const Standard_ShortReal B, Standard_ShortReal& H, Standard_ShortReal& L, Standard_ShortReal& S);
  
  //! Returns the values of a predefined colour according to
  //! the mode specified by TypeOfColor
  //! TOC_RGB : <R1> the value of red between 0. and 1.
  //! <R2> the value of green between 0. and 1.
  //! <R3> the value of blue between 0. and 1.
  //!
  //! TOC_HLS : <R1> is the hue angle in degrees, 0. being red
  //! <R2> is the lightness between 0. and 1.
  //! <R3> is the saturation between 0. and 1.
  Standard_EXPORT static void ValuesOf (const Quantity_NameOfColor AName, const Quantity_TypeOfColor AType, Standard_ShortReal& R1, Standard_ShortReal& R2, Standard_ShortReal& R3);


  Standard_ShortReal MyRed;
  Standard_ShortReal MyGreen;
  Standard_ShortReal MyBlue;


};







#endif // _Quantity_Color_HeaderFile
