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

            UColor c = obj as UColor;

            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 UColorHSV ToHSV(UColor InColor, RGBSpaceName colorspace)
 {
     varArr = Do(InColor, ColorModel.HSV, colorspace);
     return new UColorHSV(colorspace, (ushort)(varArr[0] * 182.041667), (ushort)(varArr[1] * 65535), (ushort)(varArr[2] * 65535));
 }
 /// <summary>
 /// Converts a color to a HSL color
 /// </summary>
 /// <param name="InColor">The color to convert</param>
 /// <returns>The converted color</returns>
 public UColorHSL ToHSL(UColor InColor)
 {
     varArr = Do(InColor, ColorModel.HSL);
     return new UColorHSL(RGBSpace, (ushort)(varArr[0] * 182.041667), (ushort)(varArr[1] * 65535), (ushort)(varArr[2] * 65535));
 }
 /// <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 UColorGray ToGray(UColor InColor, WhitepointName ReferenceWhite)
 {
     varArr = Do(InColor, ColorModel.Gray, ReferenceWhite);
     return new UColorGray(OutReferenceWhite.Name, (ushort)(varArr[0] * 65535));
 }
 /// <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(UColor 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(UColor 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 UColorLCHuv ToLCHuv(UColor InColor, WhitepointName ReferenceWhite)
 {
     varArr = Do(InColor, ColorModel.CIELCHuv, ReferenceWhite);
     return new UColorLCHuv(OutReferenceWhite.Name, (ushort)(varArr[0] * 655.35), (ushort)(varArr[1] * 65535), (ushort)(varArr[2] * 182.041667));
 }
 /// <summary>
 /// Converts a color to a LCH99b color
 /// </summary>
 /// <param name="InColor">The color to convert</param>
 /// <returns>The converted color</returns>
 public UColorLCH99b ToLCH99b(UColor InColor)
 {
     varArr = Do(InColor, ColorModel.LCH99b, WhitepointName.D65);
     return new UColorLCH99b((ushort)(varArr[0] * 65.535), (ushort)(varArr[1] * 65535), (ushort)(varArr[2] * 182.041667));
 }
 /// <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 UColorYCbCr ToYCbCr(UColor InColor, RGBSpaceName BaseColorspace, YCbCrSpaceName colorspace)
 {
     varArr = Do(InColor, ColorModel.YCbCr, BaseColorspace, colorspace);
     return new UColorYCbCr(YCbCrSpace, RGBSpace, (ushort)(varArr[0] * 65535), (ushort)(varArr[1] * 65535), (ushort)(varArr[2] * 65535));
 }
Пример #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 UColorYCbCr ToYCbCr(UColor InColor)
 {
     varArr = Do(InColor, ColorModel.YCbCr);
     return new UColorYCbCr(YCbCrSpace, RGBSpace, (ushort)(varArr[0] * 65535), (ushort)(varArr[1] * 65535), (ushort)(varArr[2] * 65535));
 }
Пример #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 UColorXYZ ToXYZ(UColor InColor, WhitepointName ReferenceWhite)
 {
     varArr = Do(InColor, ColorModel.CIEXYZ, ReferenceWhite);
     return new UColorXYZ(OutReferenceWhite.Name, (ushort)(varArr[0] * 65535), (ushort)(varArr[1] * 65535), (ushort)(varArr[2] * 65535));
 }
Пример #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 UColorRGB ToRGB(UColor InColor, RGBSpaceName colorspace)
 {
     varArr = Do(InColor, ColorModel.RGB, colorspace);
     return new UColorRGB(colorspace, (ushort)(varArr[0] * 65535), (ushort)(varArr[1] * 65535), (ushort)(varArr[2] * 65535));
 }
Пример #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 UColorRGB ToRGB(UColor InColor)
 {
     varArr = Do(InColor, ColorModel.RGB);
     return new UColorRGB(RGBSpace, (ushort)(varArr[0] * 65535), (ushort)(varArr[1] * 65535), (ushort)(varArr[2] * 65535));
 }
Пример #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 UColorLuv ToLuv(UColor InColor)
 {
     varArr = Do(InColor, ColorModel.CIELuv);
     return new UColorLuv(OutReferenceWhite.Name, (ushort)(varArr[0] * 655.35), (short)varArr[1], (short)varArr[2]);
 }
Пример #15
0
        private void SetInputColor(UColor inColor)
        {
            InputModel = inColor.Model;
            DoAdaption = inColor.ReferenceWhite != OutReferenceWhite.Name;
            if (InputModel != ColorModel.Gray)
            {
                ValArr1 = inColor.DoubleColorArray;
                ValArr2 = inColor.DoubleColorArray;
            }
            else
            {
                ValArr1 = new double[] { ((UColorGray)inColor).G / 65535d, 0, 0 };
                ValArr2 = new double[] { ((UColorGray)inColor).G / 65535d, 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 = ((UColorHSL)inColor).Space;
                    InputWhitepoint = InputRGBSpace.ReferenceWhite;
                    DoAdaptionRGB();
                    break;
                case ColorModel.HSV:
                    InputRGBSpace = ((UColorHSV)inColor).Space;
                    InputWhitepoint = InputRGBSpace.ReferenceWhite;
                    DoAdaptionRGB();
                    break;
                case ColorModel.RGB:
                    InputRGBSpace = ((UColorRGB)inColor).Space;
                    IsRGBLinear = ((UColorRGB)inColor).IsLinear;
                    InputWhitepoint = InputRGBSpace.ReferenceWhite;
                    DoAdaptionRGB();
                    break;
                case ColorModel.YCbCr:
                    InputRGBSpace = ((UColorYCbCr)inColor).BaseSpace;
                    InputYCbCrSpace = ((UColorYCbCr)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 UColorLab ToLab(UColor InColor, WhitepointName ReferenceWhite)
 {
     varArr = Do(InColor, ColorModel.CIELab, ReferenceWhite);
     return new UColorLab(OutReferenceWhite.Name, (ushort)(varArr[0] * 655.35), (short)varArr[1], (short)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 UColorYxy ToYxy(UColor InColor, WhitepointName ReferenceWhite)
 {
     varArr = Do(InColor, ColorModel.CIEYxy, ReferenceWhite);
     return new UColorYxy(OutReferenceWhite.Name, (ushort)(varArr[0] * 65535), (short)varArr[1], (short)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(UColor 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 UColorLCHab ToLCHab(UColor InColor)
 {
     varArr = Do(InColor, ColorModel.CIELCHab);
     return new UColorLCHab(OutReferenceWhite.Name, (ushort)(varArr[0] * 655.35), (ushort)(varArr[1] * 65535), (ushort)(varArr[2] * 182.041667));
 }