elsehsb.Hue=q*(color.G-color.B)/360;
}
elseif(Max==color.G)hsb.Hue=(120+q*(color.B-color.R))/360;
elseif(Max==color.B)hsb.Hue=(240+q*(color.R-color.G))/360;
elsehsb.Hue=0.0;
returnhsb;
}
publicHSBToHSB()
{
returnToHSB(this);
}
publicstaticCMYKToCMYK(Colorcolor)
{
CMYKcmyk=newCMYK();
doublelow=1.0;
cmyk.Cyan=(double)(255-color.R)/255;
if(low>cmyk.Cyan)
low=cmyk.Cyan;
cmyk.Magenta=(double)(255-color.G)/255;
if(low>cmyk.Magenta)
low=cmyk.Magenta;
cmyk.Yellow=(double)(255-color.B)/255;
if(low>cmyk.Yellow)
low=cmyk.Yellow;
if(low>0.0)
{
cmyk.Key=low;
}
returncmyk;
}
publicCMYKToCMYK()
{
returnToCMYK(this);
}
publicoverrideintGetHashCode()
{
returnbaxxxxse.GetHashCode();
}
publicoverrideboolEquals(obxxxxjectobj)
{
returnbaxxxxse.Equals(obj);
}
}
publicstructHSB
{
privatedoublehue;
privatedoublesaturation;
privatedoublebrightness;
publicdoubleHue
{
get{returnhue;}
set{hue=ColorHelper.CheckColor(value);}
}
publicdoubleHue360
{
get{returnhue*360;}
set{hue=ColorHelper.CheckColor(value/360);}
}
publicdoubleSaturation
{
get{returnsaturation;}
set{saturation=ColorHelper.CheckColor(value);}
}
publicdoubleSaturation100
{
get{returnsaturation*100;}
set{saturation=ColorHelper.CheckColor(value/100);}
}
publicdoubleBrightness
{
get{returnbrightness;}
set{brightness=ColorHelper.CheckColor(value);}
}
publicdoubleBrightness100
{
get{returnbrightness*100;}
set{brightness=ColorHelper.CheckColor(value/100);}
}
publicHSB(doublehuedoublesaturationdoublebrightness)
:
this()
{
this.Hue=hue;
this.Saturation=saturation;
this.Brightness=brightness;
}
publicHSB(inthueintsaturationintbrightness)
:
this()
{
this.Hue360=hue;
this.Saturation100=saturation;
this.Brightness100=brightness;
}
publicHSB(Colorcolor)
{
this=RGB.ToHSB(color);
}
publicstaticimplicitoperatorHSB(Colorcolor)
{
returnRGB.ToHSB(color);
}
publicstaticimplicitoperatorColor(HSBcolor)
{
returncolor.ToColor();
}
publicstaticimplicitoperatorRGB(HSBcolor)
{
returncolor.ToColor();
}
publicstaticimplicitoperatorCMYK(HSBcolor)
{
returncolor.ToColor();
}
publicstaticbooloperator==(HSBleftHSBright)
{
return(left.Hue==right.Hue)&&(left.Saturation==right.Saturation)&&(left.Brightness==right.Brightness);
}
publicstaticbooloperator!
=(HSBleftHSBright)
{
return!
(left==right);
}
publicoverridestringToString()
{
returnString.Format("Hue:
{0}Saturation:
{1}Brightness:
{2}"ColorHelper.Round(Hue360)
ColorHelper.Round(Saturation100)ColorHelper.Round(Brightness100));
}
publicstaticColorToColor(HSBhsb)
{
intMid;
intMax=ColorHelper.Round(hsb.Brightness*255);
intMin=ColorHelper.Round((1.0-hsb.Saturation)*(hsb.Brightness/1.0)*255);
doubleq=(double)(Max-Min)/255;
if(hsb.Hue>=0&&hsb.Hue<=(double)1/6)
{
Mid=ColorHelper.Round(((hsb.Hue-0)*q)*1530+Min);
returnColor.FromArgb(MaxMidMin);
}
if(hsb.Hue<=(double)1/3)
{
Mid=ColorHelper.Round(-((hsb.Hue-(double)1/6)*q)*1530+Max);
returnColor.FromArgb(MidMaxMin);
}
if(hsb.Hue<=0.5)
{
Mid=ColorHelper.Round(((hsb.Hue-(double)1/3)*q)*1530+Min);
returnColor.FromArgb(MinMaxMid);
}
if(hsb.Hue<=(double)2/3)
{
Mid=ColorHelper.Round(-((hsb.Hue-0.5)*q)*1530+Max);
returnColor.FromArgb(MinMidMax);
}
if(hsb.Hue<=(double)5/6)
{
Mid=ColorHelper.Round(((hsb.Hue-(double)2/3)*q)*1530+Min);
returnColor.FromArgb(MidMinMax);
}
if(hsb.Hue<=1.0)
{
Mid=ColorHelper.Round(-((hsb.Hue-(double)5/6)*q)*1530+Max);
returnColor.FromArgb(MaxMinMid);
}
returnColor.FromArgb(000);
}
publicstaticColorToColor(doublehuedoublesaturationdoublebrightness)
{
returnToColor(newHSB(huesaturationbrightness));
}
publicColorToColor()
{
returnToColor(this);
}
publicoverrideintGetHashCode()
{
returnbaxxxxse.GetHashCode();
}
publicoverrideboolEquals(obxxxxjectobj)
{
returnbaxxxxse.Equals(obj);
}
}
publicstructCMYK
{
privatedoublecyan;
privatedoublemagenta;
privatedoubleyellow;
privatedoublekey;
publicdoubleCyan
{
get{returncyan;}
set{cyan=ColorHelper.CheckColor(value);}
}
publicdoubleCyan100
{
get{returncyan*100;}
set{cyan=ColorHelper.CheckColor(value/100);}
}
publicdoubleMagenta
{
get{returnmagenta;}
set{magenta=ColorHelper.CheckColor(value);}
}
publicdoubleMagenta100
{
get{returnmagenta*100;}
set{magenta=ColorHelper.CheckColor(value/100);}
}
publicdoubleYellow
{
get{returnyellow;}
set{yellow=ColorHelper.CheckColor(value);}
}
publicdoubleYellow100
{
get{returnyellow*100;}
set{yellow=ColorHelper.CheckColor(value/100);}
}
publicdoubleKey
{
get{returnkey;}
set{key=ColorHelper.CheckColor(value);}
}
publicdoubleKey100
{
get{returnkey*100;}
set{key=ColorHelper.CheckColor(value/100);}
}
publicCMYK(doublecyandoublemagentadoubleyellowdoublekey)
:
this()
{
this.Cyan=cyan;
this.Magenta=magenta;
this.Yellow=yellow;
this.Key=key;
}
publicCMYK(intcyanintmagentaintyellowintkey)
:
this()
{
this.Cyan100=cyan;
this.Magenta100=magenta;
this.Yellow100=yellow;
this.Key100=key;
}
publicCMYK(Colorcolor)
{
this=RGB.ToCMYK(color);
}
publicstaticimplicitoperatorCMYK(Colorcolor)
{
returnRGB.ToCMYK(color);
}
publicstaticimplicitoperatorColor(CMYKcolor)
{
returncolor.ToColor();
}
publicstaticimplicitoperatorRGB(CMYKcolor)
{
returncolor.ToColor();
}
publicstaticimplicitoperatorHSB(CMYKcolor)
{
returncolor.ToColor();
}
publicstaticbooloperator==(CMYKleftCMYKright)
{
return(left.Cyan==right.Cyan)&&(left.Magenta==right.Magenta)&&(left.Yellow==right.Yellow)&&
(left.Key==right.Key);
}
publicstaticbooloperator!
=(CMYKleftCMYKright)
{
return!
(left==right);
}
publicoverridestringToString()
{
returnString.Format("Cyan:
{0}Magenta:
{1}Yellow:
{2}Key:
{3}"ColorHelper.Round(Cyan100)
ColorHelper.Round(Magenta100)ColorHelper.Round(Yellow100