public virtual void MakeLighterTest() { DeviceRgb rgbColor = new DeviceRgb(50, 100, 150); DeviceRgb darkerRgbColor = DeviceRgb.MakeLighter(rgbColor); // check the resultant darkness of RGB items with using this multiplier float multiplier = Math.Min(1f, 150f / 255 + 0.33f) / (150f / 255); NUnit.Framework.Assert.AreEqual(multiplier * (50f / 255), darkerRgbColor.GetColorValue()[0], 0.0001); NUnit.Framework.Assert.AreEqual(multiplier * (100f / 255), darkerRgbColor.GetColorValue()[1], 0.0001); NUnit.Framework.Assert.AreEqual(multiplier * (150f / 255), darkerRgbColor.GetColorValue()[2], 0.0001); }
/// <summary> /// Converts /// <see cref="DeviceRgb">DeviceRgb</see> /// color to /// <see cref="DeviceCmyk">DeviceCmyk</see> /// color /// </summary> /// <param name="rgbColor">the DeviceRgb color which will be converted to DeviceCmyk color</param> /// <returns>converted color</returns> public static DeviceCmyk ConvertRgbToCmyk(DeviceRgb rgbColor) { float redComp = rgbColor.GetColorValue()[0]; float greenComp = rgbColor.GetColorValue()[1]; float blueComp = rgbColor.GetColorValue()[2]; float k = 1 - Math.Max(Math.Max(redComp, greenComp), blueComp); float c = (1 - redComp - k) / (1 - k); float m = (1 - greenComp - k) / (1 - k); float y = (1 - blueComp - k) / (1 - k); return(new DeviceCmyk(c, m, y, k)); }
public virtual void ColorByAWTColorTest() { System.Drawing.Color color = System.Drawing.Color.FromArgb(50, 100, 150); DeviceRgb rgbColor = new DeviceRgb(color); float[] rgbColorValue = rgbColor.GetColorValue(); NUnit.Framework.Assert.AreEqual(50f / 255, rgbColorValue[0], 0.0001); NUnit.Framework.Assert.AreEqual(100f / 255, rgbColorValue[1], 0.0001); NUnit.Framework.Assert.AreEqual(150f / 255, rgbColorValue[2], 0.0001); }
private float GetSumOfColorValues(DeviceRgb deviceRgb) { float sum = 0; float[] values = deviceRgb.GetColorValue(); for (int i = 0; i < values.Length; i++) { sum += values[i]; } return(sum); }
public virtual void ColorByAWTColorConstantTest() { // RED DeviceRgb rgbColor = new DeviceRgb(System.Drawing.Color.Red); float[] rgbColorValue = rgbColor.GetColorValue(); NUnit.Framework.Assert.AreEqual(1, rgbColorValue[0], 0.0001); NUnit.Framework.Assert.AreEqual(0, rgbColorValue[1], 0.0001); NUnit.Framework.Assert.AreEqual(0, rgbColorValue[2], 0.0001); // GREEN rgbColor = new DeviceRgb(System.Drawing.Color.Lime); rgbColorValue = rgbColor.GetColorValue(); NUnit.Framework.Assert.AreEqual(0, rgbColorValue[0], 0.0001); NUnit.Framework.Assert.AreEqual(1, rgbColorValue[1], 0.0001); NUnit.Framework.Assert.AreEqual(0, rgbColorValue[2], 0.0001); // BLUE rgbColor = new DeviceRgb(System.Drawing.Color.Blue); rgbColorValue = rgbColor.GetColorValue(); NUnit.Framework.Assert.AreEqual(0, rgbColorValue[0], 0.0001); NUnit.Framework.Assert.AreEqual(0, rgbColorValue[1], 0.0001); NUnit.Framework.Assert.AreEqual(1, rgbColorValue[2], 0.0001); }