Пример #1
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            BColor c = obj as BColor;

            if ((Object)c == null)
            {
                return(false);
            }

            return(ColorValues == c.ColorValues && ReferenceWhite == c.ReferenceWhite);
        }
 /// <summary>
 /// Converts a color to a HSV color
 /// </summary>
 /// <param name="InColor">The color to convert</param>
 /// <param name="colorspace">The colorspace to be used for the converted color</param>
 /// <returns>The converted color</returns>
 public BColorHSV ToHSV(BColor InColor, RGBSpaceName colorspace)
 {
     varArr = Do(InColor, ColorModel.HSV, colorspace);
     return new BColorHSV(colorspace, (byte)(varArr[0] * 0.70833), (byte)(varArr[1] * 255), (byte)(varArr[2] * 255));
 }
 /// <summary>
 /// Converts a color to a HSV color
 /// </summary>
 /// <param name="InColor">The color to convert</param>
 /// <returns>The converted color</returns>
 public BColorHSV ToHSV(BColor InColor)
 {
     varArr = Do(InColor, ColorModel.HSV);
     return new BColorHSV(RGBSpace, (byte)(varArr[0] * 0.70833), (byte)(varArr[1] * 255), (byte)(varArr[2] * 255));
 }
 /// <summary>
 /// Converts a color to a gray color
 /// </summary>
 /// <param name="InColor">The color to convert</param>
 /// <param name="ReferenceWhite">The reference white to be used for the converted color</param>
 /// <returns>The converted color</returns>
 public BColorGray ToGray(BColor InColor, WhitepointName ReferenceWhite)
 {
     varArr = Do(InColor, ColorModel.Gray, ReferenceWhite);
     return new BColorGray(OutReferenceWhite.Name, (byte)(varArr[0] * 255));
 }
 /// <summary>
 /// Converts from one colorspace to another
 /// </summary>
 /// <param name="inColor">Input color</param>
 /// <param name="outModel">Output colormodel</param>
 /// <returns>Returns a color with the converted values from the input</returns>
 internal double[] Do(BColor inColor, ColorModel outModel)
 {
     OutputModel = outModel;
     RGBSpace = StandardColorspace;
     YCbCrSpace = StandardYCbCrSpace;
     OutReferenceWhite = ReferenceWhite;
     SetInputColor(inColor);
     return Do();
 }
 /// <summary>
 /// Converts from one colorspace to another
 /// </summary>
 /// <param name="inColor">Input color</param>
 /// <param name="outModel">Output colormodel</param>
 /// <param name="RefWhite">The reference white the output should have</param>
 /// <returns>Returns a color with the converted values from the input</returns>
 internal double[] Do(BColor inColor, ColorModel outModel, WhitepointName RefWhite)
 {
     if (RefWhite != WhitepointName.Custom) OutReferenceWhite = WhitepointArr[(int)RefWhite];
     else OutReferenceWhite = ReferenceWhite;
     OutputModel = outModel;
     RGBSpace = StandardColorspace;
     YCbCrSpace = StandardYCbCrSpace;
     SetInputColor(inColor);
     return Do();
 }
 /// <summary>
 /// Converts a color to a LCHuv color
 /// </summary>
 /// <param name="InColor">The color to convert</param>
 /// <param name="ReferenceWhite">The reference white to be used for the converted color</param>
 /// <returns>The converted color</returns>
 public BColorLCHuv ToLCHuv(BColor InColor, WhitepointName ReferenceWhite)
 {
     varArr = Do(InColor, ColorModel.CIELCHuv, ReferenceWhite);
     return new BColorLCHuv(OutReferenceWhite.Name, (byte)(varArr[0] * 2.55), (byte)(varArr[1] * 255), (byte)(varArr[2] * 0.70833));
 }
 /// <summary>
 /// Converts a color to a LCH99c color
 /// </summary>
 /// <param name="InColor">The color to convert</param>
 /// <returns>The converted color</returns>
 public BColorLCH99c ToLCH99c(BColor InColor)
 {
     varArr = Do(InColor, ColorModel.LCH99c, WhitepointName.D65);
     return new BColorLCH99c((byte)(varArr[0] * 2.55), (byte)(varArr[1] * 255), (byte)(varArr[2] * 0.70833));
 }
 /// <summary>
 /// Converts a color to a YCbCr color
 /// </summary>
 /// <param name="InColor">The color to convert</param>
 /// <param name="BaseColorspace">The colorspace the converted color will be based on</param>
 /// <param name="colorspace">The colorspace to be used for the converted color</param>
 /// <returns>The converted color</returns>
 public BColorYCbCr ToYCbCr(BColor InColor, RGBSpaceName BaseColorspace, YCbCrSpaceName colorspace)
 {
     varArr = Do(InColor, ColorModel.YCbCr, BaseColorspace, colorspace);
     return new BColorYCbCr(YCbCrSpace, RGBSpace, (byte)(varArr[0] * 255), (byte)(varArr[1] * 255), (byte)(varArr[2] * 255));
 }
Пример #10
0
 /// <summary>
 /// Converts a color to a YCbCr color
 /// </summary>
 /// <param name="InColor">The color to convert</param>
 /// <returns>The converted color</returns>
 public BColorYCbCr ToYCbCr(BColor InColor)
 {
     varArr = Do(InColor, ColorModel.YCbCr);
     return new BColorYCbCr(YCbCrSpace, RGBSpace, (byte)(varArr[0] * 255), (byte)(varArr[1] * 255), (byte)(varArr[2] * 255));
 }
Пример #11
0
 /// <summary>
 /// Converts a color to a XYZ color
 /// </summary>
 /// <param name="InColor">The color to convert</param>
 /// <param name="ReferenceWhite">The reference white to be used for the converted color</param>
 /// <returns>The converted color</returns>
 public BColorXYZ ToXYZ(BColor InColor, WhitepointName ReferenceWhite)
 {
     varArr = Do(InColor, ColorModel.CIEXYZ, ReferenceWhite);
     return new BColorXYZ(OutReferenceWhite.Name, (byte)(varArr[0] * 255), (byte)(varArr[1] * 255), (byte)(varArr[2] * 255));
 }
Пример #12
0
 /// <summary>
 /// Converts a color to an RGB color
 /// </summary>
 /// <param name="InColor">The color to convert</param>
 /// <param name="colorspace">The colorspace to be used for the converted color</param>
 /// <returns>The converted color</returns>
 public BColorRGB ToRGB(BColor InColor, RGBSpaceName colorspace)
 {
     varArr = Do(InColor, ColorModel.RGB, colorspace);
     return new BColorRGB(colorspace, (byte)(varArr[0] * 255), (byte)(varArr[1] * 255), (byte)(varArr[2] * 255));
 }
Пример #13
0
 /// <summary>
 /// Converts a color to an RGB color
 /// </summary>
 /// <param name="InColor">The color to convert</param>
 /// <returns>The converted color</returns>
 public BColorRGB ToRGB(BColor InColor)
 {
     varArr = Do(InColor, ColorModel.RGB);
     return new BColorRGB(RGBSpace, (byte)(varArr[0] * 255), (byte)(varArr[1] * 255), (byte)(varArr[2] * 255));
 }
Пример #14
0
 /// <summary>
 /// Converts a color to a Luv color
 /// </summary>
 /// <param name="InColor">The color to convert</param>
 /// <returns>The converted color</returns>
 public BColorLuv ToLuv(BColor InColor)
 {
     varArr = Do(InColor, ColorModel.CIELuv);
     return new BColorLuv(OutReferenceWhite.Name, (byte)(varArr[0] * 2.55), (sbyte)varArr[1], (sbyte)varArr[2]);
 }
Пример #15
0
        private void SetInputColor(BColor inColor)
        {
            InputModel = inColor.Model;
            DoAdaption = inColor.ReferenceWhite != OutReferenceWhite.Name;

            if (InputModel != ColorModel.Gray)
            {
                ValArr1 = inColor.DoubleColorArray;
                ValArr2 = inColor.DoubleColorArray;
            }
            else
            {
                ValArr1 = new double[] { ((BColorGray)inColor).G / 255d, 0, 0 };
                ValArr2 = new double[] { ((BColorGray)inColor).G / 255d, 0, 0 };
            }

            switch (InputModel)
            {
                case ColorModel.CIELab:
                case ColorModel.CIELCHab:
                case ColorModel.CIELCHuv:
                case ColorModel.LCH99:
                case ColorModel.LCH99b:
                case ColorModel.LCH99c:
                case ColorModel.LCH99d:
                case ColorModel.CIELuv:
                case ColorModel.CIEXYZ:
                case ColorModel.CIEYxy:
                case ColorModel.Gray:
                case ColorModel.DEF:
                case ColorModel.Bef:
                case ColorModel.BCH:
                    if (inColor.ReferenceWhite == WhitepointName.Custom || OutReferenceWhite.Name == WhitepointName.Custom) DoAdaption = true;
                    InputWhitepoint = WhitepointArr[(int)inColor.ReferenceWhite];
                    break;

                case ColorModel.HSL:
                    InputRGBSpace = ((BColorHSL)inColor).Space;
                    InputWhitepoint = InputRGBSpace.ReferenceWhite;
                    DoAdaptionRGB();
                    break;
                case ColorModel.HSV:
                    InputRGBSpace = ((BColorHSV)inColor).Space;
                    InputWhitepoint = InputRGBSpace.ReferenceWhite;
                    DoAdaptionRGB();
                    break;
                case ColorModel.RGB:
                    InputRGBSpace = ((BColorRGB)inColor).Space;
                    IsRGBLinear = ((BColorRGB)inColor).IsLinear;
                    InputWhitepoint = InputRGBSpace.ReferenceWhite;
                    DoAdaptionRGB();
                    break;
                case ColorModel.YCbCr:
                    InputRGBSpace = ((BColorYCbCr)inColor).BaseSpace;
                    InputYCbCrSpace = ((BColorYCbCr)inColor).Space;
                    InputWhitepoint = InputRGBSpace.ReferenceWhite;
                    DoAdaptionYCbCr();
                    break;

                default:
                    throw new NotImplementedException();
            }
        }
Пример #16
0
 /// <summary>
 /// Converts a color to a Lab color
 /// </summary>
 /// <param name="InColor">The color to convert</param>
 /// <param name="ReferenceWhite">The reference white to be used for the converted color</param>
 /// <returns>The converted color</returns>
 public BColorLab ToLab(BColor InColor, WhitepointName ReferenceWhite)
 {
     varArr = Do(InColor, ColorModel.CIELab, ReferenceWhite);
     return new BColorLab(OutReferenceWhite.Name, (byte)(varArr[0] * 2.55), (sbyte)varArr[1], (sbyte)varArr[2]);
 }
Пример #17
0
 /// <summary>
 /// Converts a color to a Yxy color
 /// </summary>
 /// <param name="InColor">The color to convert</param>
 /// <param name="ReferenceWhite">The reference white to be used for the converted color</param>
 /// <returns>The converted color</returns>
 public BColorYxy ToYxy(BColor InColor, WhitepointName ReferenceWhite)
 {
     varArr = Do(InColor, ColorModel.CIEYxy, ReferenceWhite);
     return new BColorYxy(OutReferenceWhite.Name, (byte)(varArr[0] * 255), (sbyte)varArr[1], (sbyte)varArr[2]);
 }
Пример #18
0
 /// <summary>
 /// Converts from one colorspace to another
 /// </summary>
 /// <param name="inColor">Input color</param>
 /// <param name="outModel">Output colormodel</param>
 /// <param name="colorspace">The colorspace the output should be in</param>
 /// <returns>Returns a color with the converted values from the input</returns>
 internal double[] Do(BColor inColor, ColorModel outModel, RGBSpaceName colorspace)
 {
     OutputModel = outModel;
     RGBSpace = colorspace;
     YCbCrSpace = StandardYCbCrSpace;
     OutReferenceWhite = WhitepointArr[(int)RGBColorspace.GetWhitepointName(colorspace)];
     SetInputColor(inColor);
     return Do();
 }
Пример #19
0
 /// <summary>
 /// Converts a color to a LCHab color
 /// </summary>
 /// <param name="InColor">The color to convert</param>
 /// <returns>The converted color</returns>
 public BColorLCHab ToLCHab(BColor InColor)
 {
     varArr = Do(InColor, ColorModel.CIELCHab);
     return new BColorLCHab(OutReferenceWhite.Name, (byte)(varArr[0] * 2.55), (byte)(varArr[1] * 255), (byte)(varArr[2] * 0.70833));
 }