Exemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LAB"/> struct.
 /// </summary>
 /// <param name="lab">The color in <see cref="LAB"/> color space.</param>
 public LAB(LAB lab)
     : this()
 {
     L = lab.L;
     A = lab.A;
     B = lab.B;
 }
Exemplo n.º 2
0
        /// <summary>
        /// Converts the instance into the target <see cref="IColorSpace"/>.
        /// </summary>
        /// <typeparam name="T">The target <see cref="IColorSpace"/> in which the instance should be converted.</typeparam>
        /// <returns>
        /// The converted <see cref="IColorSpace"/> instance.
        /// </returns>
        public T To <T>() where T : IColorSpace, new()
        {
            if (typeof(T) == typeof(LCH))
            {
                // just return a new LCH
                return(new T {
                    Color = Color
                });
            }

            if (typeof(T) == typeof(LAB))
            {
                // conversion to LAB is supported
                return(new T {
                    Color = ToCIELab().Color
                });
            }

            if (typeof(T) == typeof(LUV))
            {
                // conversion to LUV is supported
                return(new T {
                    Color = ToCIELuv().Color
                });
            }

            if (ColorSpace == BaseColorSpace.LAB)
            {
                LAB lab = ToCIELab();

                // convert from LAB to the target color space
                return(lab.To <T>());
            }

            if (ColorSpace == BaseColorSpace.LUV)
            {
                LUV luv = ToCIELuv();

                // convert from LAB to the target color space
                return(luv.To <T>());
            }

            // should be never reached because the ColorSpace is either LAB or LUV
            return(new T());
        }
Exemplo n.º 3
0
        /// <summary>
        /// Converts a source <see cref="IColorSpace"/> into this <see cref="IColorSpace"/>.
        /// </summary>
        /// <typeparam name="T">The source <see cref="IColorSpace"/> from which this instance should be converted.</typeparam>
        /// <param name="color">The <see cref="IColorSpace"/> to be converted.</param>
        public void From <T>(T color) where T : IColorSpace, new()
        {
            if (typeof(T) == typeof(LCH))
            {
                // just return a new LCH
                Color = color.Color;
                return;
            }

            if (typeof(T) == typeof(LAB))
            {
                // conversion to LAB is supported
                Color = FromCIELab(color.Color.A, color.Color.B, color.Color.C).Color;
                return;
            }

            if (typeof(T) == typeof(LUV))
            {
                // conversion to LUV is supported
                Color = FromCIELuv(color.Color.A, color.Color.B, color.Color.C).Color;
                return;
            }

            if (ColorSpace == BaseColorSpace.LAB)
            {
                // try to convert to LAB
                LAB lab = color.To <LAB>();

                // convert from LAB to the target color space
                Color = FromCIELab(lab).Color;
                return;
            }

            if (ColorSpace == BaseColorSpace.LUV)
            {
                // try to convert to LUV
                LUV luv = color.To <LUV>();

                // convert from LUV to the target color space
                Color = FromCIELuv(luv).Color;
                return;
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Converts from <see cref="LAB"/> to <see cref="XYZ"/> color space.
 /// </summary>
 /// <param name="lab">The source color in <see cref="LAB"/> color space.</param>
 /// <returns>
 /// The color in <see cref="XYZ"/> color space.
 /// </returns>
 public static XYZ ToXYZ(LAB lab)
 {
     return ToXYZ(lab.L, lab.A, lab.B);
 }
Exemplo n.º 5
0
 /// <summary>
 /// Converts from <see cref="LAB"/> to <see cref="LCH"/> (ab) color space.
 /// </summary>
 /// <param name="lab">The source color <see cref="LAB"/> in color space.</param>
 /// <returns>
 /// The color in <see cref="LCH"/> (ab) color space.
 /// </returns>
 public static LCH FromCIELab(LAB lab)
 {
     return(FromCIELab(lab.L, lab.A, lab.B));
 }