/// <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) { YUV yuv = new YUV(); // normalizes red/green/blue values double nRed = (double)red / 255.0; double nGreen = (double)green / 255.0; double nBlue = (double)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) { RGB rgb = YUVtoRGB(yuv); return Color.FromArgb(rgb.Red, rgb.Green, rgb.Blue); }
/// <summary> /// Converts YUV to RGB. /// </summary> public static RGB YUVtoRGB(YUV yuv) { return YUVtoRGB(yuv.Y, yuv.U, yuv.V); }
/// <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) { YUV yuv = new YUV(); // normalizes red/green/blue values double nRed = (double)red/255.0; double nGreen = (double)green/255.0; double nBlue = (double)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) { RGB rgb = YUVtoRGB(yuv); return(Color.FromArgb(rgb.Red, rgb.Green, rgb.Blue)); }
/// <summary> /// Converts YUV to RGB. /// </summary> public static RGB YUVtoRGB(YUV yuv) { return(YUVtoRGB(yuv.Y, yuv.U, yuv.V)); }