Example #1
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());
        }
Example #2
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;
            }
        }
Example #3
0
 /// <summary>
 /// Converts from <see cref="LUV"/> to <see cref="XYZ"/> color space.
 /// </summary>
 /// <param name="luv">The source color in <see cref="LUV"/> color space.</param>
 /// <returns>
 /// The color in <see cref="XYZ"/> color space.
 /// </returns>
 public static XYZ ToXYZ(LUV luv)
 {
     return(ToXYZ(luv.L, luv.U, luv.V));
 }
Example #4
0
 /// <summary>
 /// Converts from <see cref="LUV"/> to <see cref="LCH"/> (uv) color space.
 /// </summary>
 /// <param name="luv">The source color in<see cref="LUV"/> color space.</param>
 /// <returns>
 /// The color in <see cref="LCH"/> (uv) color space.
 /// </returns>
 public static LCH FromCIELuv(LUV luv)
 {
     return(FromCIELuv(luv.L, luv.U, luv.V));
 }
Example #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LUV"/> struct.
 /// </summary>
 /// <param name="luv">The color in <see cref="LUV"/> color space.</param>
 public LUV(LUV luv) : this()
 {
     L = luv.L;
     U = luv.U;
     V = luv.V;
 }