Libraries: IncColors

 

IncColors:

This class contains functions for working with colors. It has color conversion and other useful functions.

List of functions:

  • void RGBtoHSV(double aR,double aG,double aB,double & oH,double & oS,double & oV)
  • void RGBtoXYZ(double aR,double aG,double aB,double & oX,double & oY,double & oZ)
  • void XYZtoRGB(double aX,double aY,double aZ,double & oR,double & oG,double & oB)
  • void XYZtoYxy(double aX,double aY,double aZ,double & oY,double & ox,double & oy)
  • void XYZtoYxy(double aX,double aY,double aZ,double & oY,double & ox,double & oy)
  • void XYZtoHunterLab(double aX,double aY,double aZ,double & oL,double & oa,double & ob)
  • void HunterLabToXYZ(double aL,double aa,double ab,double & oX,double & oY,double & oZ)
  • void XYZtoCIELab(double aX,double aY,double aZ,double & oCIEL,double & oCIEa,double & oCIEb)
  • void CIELabToXYZ(double aCIEL,double aCIEa,double aCIEb,double & oX,double & oY,double & oZ)
  • void CIELabToCIELCH(double aCIEL,double aCIEa,double aCIEb,double & oCIEL,double & oCIEC,double & oCIEH)
  • void CIELCHtoCIELab(double aCIEL,double aCIEC,double aCIEH,double & oCIEL,double & oCIEa,double & oCIEb)
  • void XYZtoCIELuv(double aX,double aY,double aZ,double & oCIEL,double & oCIEu,double & oCIEv)
  • void CIELuvToXYZ(double aCIEL,double aCIEu,double aCIEv,double & oX,double & oY,double & oZ)
  • void RGBtoHSL(double aR,double aG,double aB,double & oH,double & oS,double & oL)
  • void HSLtoRGB(double aH,double aS,double aL,double & oR,double & oG,double & oB)
  • void RGBtoHSV(double aR,double aG,double aB,double & oH,double & oS,double & oV)
  • void HSVtoRGB(double aH,double aS,double aV,double & oR,double & oG,double & oB)
  • void RGBtoCMY(double aR,double aG,double aB,double & oC,double & oM,double & oY)
  • void CMYtoRGB(double aC,double aM,double aY,double & oR,double & oG,double & oB)
  • void CMYtoCMYK(double aC,double aM,double aY,double & oC,double & oM,double & oY,double & oK)
  • void CMYKtoCMY(double aC,double aM,double aY,double aK,double & oC,double & oM,double & oY)
  • void ColorToRGB(color aColor,double & aR,double & aG,double & aB)
  • double GetR(color aColor)
  • double GetG(color aColor)
  • double GetB(color aColor)
  • color RGBToColor(double aR,double aG,double aB)
  • color MixColors(color aCol1,color aCol2,double aK) // aK - от 0 до 1
  • void Gradient(color & aColors[],color & aOut[],int aOutCount,bool aCycle=false)
  • void RGBtoXYZsimple(double aR,double aG,double aB,double & oX,double & oY,double & oZ)
  • void XYZtoRGBsimple(double aX,double aY,double aZ,double & oR,double & oG,double & oB)
  • color Negative(color aColor)
  • color StandardColor(color aColor,int & aIndex)
  • double RGBtoGray(double aR,double aG,double aB)
  • double RGBtoGraySimple(double aR,double aG,double aB)

Author: Дмитрий

 

Wonderful set of features for working with colour! Thank you.

But, for full happiness, I lack the function of converting a number lying in a given interval to colour (and colour can be converted as you like with the help of your functions).

I use such a primitive construction:

//+------------------------------------------------------------------+
//|JQS RainbowColour v1.0.0|
//|Copyright © 2010, JQS aka Joo. |
//|                                 http://www.mql4.com/ru/users/joo |
//| https://www.mql5.com/en/users/joo |
//+------------------------------------------------------------------+
color RainbowColor(double BrushIn,double min,double max)
{
        string R,G,B;
        int temp;
        double Brush=ScaleColor(BrushIn,min,max,0.0,100.0);
        //If less than the lower limit
        if (Brush<0.0)
        {
                R="255";
                G="0";
                B="0";
                return(StringToColor("C'"+R+","+G+","+B+"'"));
        }
        //If greater than the upper limit
        if (Brush>100.0)
        {
                R="255";
                G="0";
                B="255";
                return(StringToColor("C'"+R+","+G+","+B+"'"));
        }
        //From red to yellow 255.0.0 -> 255.255.255.0
        if (Brush>=0.0 && Brush<20.0)
        {
                R="255";
                temp=(int)MathRound(ScaleColor(Brush,0.0,20.0,0.0,255.0));
                G=(string)temp;
                B="0";
                return(StringToColor("C'"+R+","+G+","+B+"'"));
        }
        //--------------------------------------------
        //From yellow to green 255.255.0 -> 0.255.0
        if (Brush>=20.0 && Brush<40.0)
        {
                temp=(int)(255.0-MathRound(ScaleColor(Brush-20.0,0.0,20.0,0.0,255.0)));
                R=(string)temp;
                G="255";
                B="0";
                return(StringToColor("C'"+R+","+G+","+B+"'"));
        }
        //--------------------------------------------
        //Green to blue 0.255.0 -> 0.255.255.255
        if (Brush>=40.0 && Brush<60.0)
        {
                R="0";
                G="255";
                temp=(int)(MathRound(ScaleColor(Brush-40.0,0.0,20.0,0.0,255.0)));
                B=(string)temp;
                return(StringToColor("C'"+R+","+G+","+B+"'"));
        }
        //--------------------------------------------
        //From cyan to blue 0.255.255 -> 0.0.255
        if (Brush>=60.0 && Brush<80.0)
        {
                R="0";
                temp=(int)(255.0-MathRound(ScaleColor(Brush-60.0,0.0,20.0,0.0,255.0)));
                G=(string)temp;
                B="255";
                return(StringToColor("C'"+R+","+G+","+B+"'"));
        }
        //--------------------------------------------
        //From blue to violet 0.0.255 -> 255.0.255
        if (Brush>=80.0 && Brush<=100.0)
        {
                temp=(int)(MathRound(ScaleColor(Brush-80.0,0.0,20.0,0.0,255.0)));
                R=(string)temp;
                G="0";
                B="255";
                return(StringToColor("C'"+R+","+G+","+B+"'"));
        }
        return(StringToColor("C'"+(string)255+","+(string)255+","+(string)255+"'"));
}
//+------------------------------------------------------------------+

double ScaleColor(double In,double InMIN,double InMAX,double OutMIN,double OutMAX)
{
        double Out=((In-InMIN)*(OutMAX-OutMIN)/(InMAX-InMIN))+OutMIN;
        return(Out);
}
//+------------------------------------------------------------------+

The function returns the colour according to the rainbow colour scale.

Could you add this function to the library? - and improve it in terms of speed.

 
joo:

Wonderful set of features for working with colour! Thank you.

But, for full happiness, I lack the function of converting a number lying in a given interval to colour (and colour can be converted as you like with the help of your functions).

I use such a primitive construction:

The function returns the colour according to the rainbow colour scale.

Could you add this function to the library? - and improve it in terms of speed.

I'll have a look at my leisure, figure out what kind of function it is, and insert it if necessary. But in general, there is a conversion from HSL and to HSL. The H component is the hue (colour number), just from 0 to 1 we go through the whole rainbow.