CodePudding user response:
//
Void HSL2RGB (int hue, double saturation, double lightness, BYTE & amp; Red, BYTE & amp; Green, BYTE & amp; Blue)
{
If (saturation==0)
{
Red=green=blue=(BYTE) (lightness * 255);
}
The else
{
Double m1, m2,
If (lightness & lt;=0.5)
M2=lightness + lightness * saturation;
The else
M2=lightness + saturation - lightness * saturation;
//
M1=2 * lightness - m2;
Red=ByteValue (m1, m2, hue + 120);
Green=ByteValue (m1, m2, hue);
Blue=ByteValue (m1, m2, hue - 120);
}
}
Typedef enum {Red, Green, Blue};
BOOL RGB2HLS (BYTE red, BYTE green, BYTE blue, int & amp; Hue, double & amp; Saturation, double & amp; Lightness)
{
Double mn, mx;
Int major;
If (red & lt; Green)
{
Mn=red; Mx=green; Major=Green;
}
The else
{
Mn=green; Mx=red; Major=Red;
}
//
If (blue & lt; Mn)
{
Mn=blue;
}
Else if (blue & gt; Mx)
{
Mx=blue; Major=Blue;
}
//
If (mn==mx)
{
Lightness=mn/255;
Saturation=0;
Hue=240;//?? 0;
}
The else
{
Lightness=(mn + mx)/510;//2 * 255
If (lightness & lt;=0.5) saturation=(double) (mx - mn)/(double) (mn + mx);
The else saturation=(double) (mx - mn)/(double) (510 - mn - mx);
The switch (major)
{
Case Red:
Hue=(int) (* 60 (green, blue)/(mx - mn) + 360);
break;
Case Green:
Hue=(int) ((blue - red) * 60/(mx - mn) + 120);
break;
Case Blue:
Hue=(int) (60/(red, green) * (mx - mn) + 240);
break;
}
If (hue & gt;=360) hue -=360;
}
If (mn==0 & amp; & Mx==255) return TRUE;
The else return FALSE;
}
//
BYTE ByteValue (double m1, m2, double double hue)
{
If (hue> Hue - 360)=360;
Else if (hue//
If (hueElse if (hue<180) m1=m2;
Else if (hue<240) m1=m1 + (m2 - m1) * (240 - hue)/60;
//
Return (BYTE) (m1 * 255);
}
CodePudding user response:
Only through into an HSL calculation? Such as saturation, lightness can be directly calculated in RGB mode (https://blog.csdn.net/xingyanxiao/article/details/48035537), which have similar principle hue adjustment? Back and forth between RGB and an HSL conversion efficiency is too low,CodePudding user response:
The same does not necessarily 'color RGBCodePudding user response: