/// <summary>
        ///     Converts RGB to YUV.
        /// </summary>
        /// <param name="red">red must be in [0, 255].</param>
        /// <param name="green">green must be in [0, 255].</param>
        /// <param name="blue">blue must be in [0, 255].</param>
        public static YUV RGBtoYUV(int red, int green, int blue)
        {
            var yuv = new YUV();

            // normalizes red/green/blue values
            var nRed   = red / 255.0;
            var nGreen = green / 255.0;
            var nBlue  = blue / 255.0;

            // converts
            yuv.Y = 0.299 * nRed + 0.587 * nGreen + 0.114 * nBlue;
            yuv.U = -0.1471376975169300226 * nRed - 0.2888623024830699774 * nGreen + 0.436 * nBlue;
            yuv.V = 0.615 * nRed - 0.5149857346647646220 * nGreen - 0.1000142653352353780 * nBlue;

            return(yuv);
        }
        /// <summary>
        ///     Converts YUV to a .net Color.
        /// </summary>
        public static Color YUVtoColor(YUV yuv)
        {
            var rgb = YUVtoRGB(yuv);

            return Color.FromArgb((byte) rgb.Red, (byte) rgb.Green, (byte) rgb.Blue);
        }
        /// <summary>
        ///     Converts RGB to YUV.
        /// </summary>
        /// <param name="red">red must be in [0, 255].</param>
        /// <param name="green">green must be in [0, 255].</param>
        /// <param name="blue">blue must be in [0, 255].</param>
        public static YUV RGBtoYUV(int red, int green, int blue)
        {
            var yuv = new YUV();

            // normalizes red/green/blue values
            var nRed = red/255.0;
            var nGreen = green/255.0;
            var nBlue = blue/255.0;

            // converts
            yuv.Y = 0.299*nRed + 0.587*nGreen + 0.114*nBlue;
            yuv.U = -0.1471376975169300226*nRed - 0.2888623024830699774*nGreen + 0.436*nBlue;
            yuv.V = 0.615*nRed - 0.5149857346647646220*nGreen - 0.1000142653352353780*nBlue;

            return yuv;
        }
 /// <summary>
 ///     Converts YUV to RGB.
 /// </summary>
 public static RGB YUVtoRGB(YUV yuv)
 {
     return YUVtoRGB(yuv.Y, yuv.U, yuv.V);
 }
        /// <summary>
        ///     Converts YUV to a .net Color.
        /// </summary>
        public static Color YUVtoColor(YUV yuv)
        {
            var rgb = YUVtoRGB(yuv);

            return(Color.FromArgb((byte)rgb.Red, (byte)rgb.Green, (byte)rgb.Blue));
        }
 /// <summary>
 ///     Converts YUV to RGB.
 /// </summary>
 public static RGB YUVtoRGB(YUV yuv)
 {
     return(YUVtoRGB(yuv.Y, yuv.U, yuv.V));
 }