/// <summary> /// HSVの色調整を行ってピクセルデータを返す。 /// </summary> /// <param name="c">カラー</param> /// <param name="hue">色差加算値(-360≦hue≦360)</param> /// <param name="saturation">彩度加割合(-255≦saturation≦255)</param> /// <param name="lightness">輝度加算割合(-255≦lightness≦255)</param> /// <returns></returns> public static Color ProcessHSLFilter(Color c, int hue, int saturation, int lightness) { if (((hue == 0) && (saturation == 0) && (lightness == 0))) { return(c); // 色変換しない。 } ColorHSL srcHSL = ColorConverter.ConvertRGBtoHSL(c); float h = ColorUtility.GetHueWithLimitedRange((srcHSL.Hue + hue) % 360.0f); float s = ColorUtility.ModifyValueByPercent(srcHSL.Saturation, 0f, 1.0f, saturation / 255.0f); float l = Math.Min(ColorUtility.ModifyValueByPercent(srcHSL.Lightness, 0f, srcHSL.Lightness * 2, lightness / 255.0f), 1.0f); return(ColorConverter.ConvertHSLtoRGB(ColorHSL.FromHSL(h, s, l), c.A)); }
/// <summary> /// RGBからHSLへ変換を行う。 /// </summary> /// <param name="rgb">RGB色</param> /// <returns>HSL色</returns> public static ColorHSL ConvertRGBtoHSL(Color rgb) { int min = Math.Min(rgb.G, Math.Min(rgb.B, rgb.R)); int max = Math.Max(rgb.G, Math.Max(rgb.B, rgb.R)); float hue = GetHue(rgb, min, max); float lightness = ((min + max) / 2.0f) / 255.0f; float saturation; if (min == max) { saturation = 0.0f; } else { saturation = (lightness < 0.5) ? (float)(max - min) / (float)(max + min) : (float)(max - min) / (2 * 255.0f - max - min); } return(ColorHSL.FromHSL(hue, saturation, lightness)); }