Exemplo n.º 1
0
        public void HsvTo()
        {
            HsvColor hsv = new HsvColor(208, 0.05882352941176472, 1, 0.5);

            Assert.AreEqual(0.5, hsv.ToCmy().Alpha, "To CMY");

            Assert.AreEqual(0.5, hsv.ToCmyk().Alpha, "To CMYK");

            Assert.AreEqual(0.5, hsv.ToHsl().Alpha, "To HSL");

            Assert.AreEqual(0.5, hsv.ToHsv().Alpha, "To HSV");

            Assert.AreEqual(0.5, hsv.ToRgb().Alpha, "To RGB");
        }
Exemplo n.º 2
0
        public void ToCmyk()
        {
            foreach (HtmlColorSample sample in HtmlColorSamples.All)
            {
                double h = sample.Hsv.Hue / 360d;
                double s = sample.Hsv.Saturation;
                double v = sample.Hsv.Value;

                HsvColor hsv = new HsvColor(h, s, v);

                double c1 = sample.Cmyk.Cyan;
                double m1 = sample.Cmyk.Magenta;
                double y1 = sample.Cmyk.Yellow;
                double k1 = sample.Cmyk.Key;

                ColorUtils.HsvToCmyk(h, s, v, out double c2, out double m2, out double y2, out double k2);
                Assert.AreEqual(c1.ToString("N2"), c2.ToString("N2"), "#1 C (" + sample.Name + ")");
                Assert.AreEqual(m1.ToString("N2"), m2.ToString("N2"), "#1 M (" + sample.Name + ")");
                Assert.AreEqual(y1.ToString("N2"), y2.ToString("N2"), "#1 Y (" + sample.Name + ")");
                Assert.AreEqual(k1.ToString("N2"), k2.ToString("N2"), "#1 K (" + sample.Name + ")");

                CmykColor cmyk1 = ColorUtils.HsvToCmyk(h, s, v);
                Assert.AreEqual(c1.ToString("N2"), cmyk1.C.ToString("N2"), "#2 C (" + sample.Name + ")");
                Assert.AreEqual(m1.ToString("N2"), cmyk1.M.ToString("N2"), "#2 M (" + sample.Name + ")");
                Assert.AreEqual(y1.ToString("N2"), cmyk1.Y.ToString("N2"), "#2 Y (" + sample.Name + ")");
                Assert.AreEqual(k1.ToString("N2"), cmyk1.K.ToString("N2"), "#2 K (" + sample.Name + ")");

                CmykColor cmyk2 = ColorUtils.HsvToCmyk(hsv);
                Assert.AreEqual(c1.ToString("N2"), cmyk2.C.ToString("N2"), "#3 C (" + sample.Name + ")");
                Assert.AreEqual(m1.ToString("N2"), cmyk2.M.ToString("N2"), "#3 M (" + sample.Name + ")");
                Assert.AreEqual(y1.ToString("N2"), cmyk2.Y.ToString("N2"), "#3 Y (" + sample.Name + ")");
                Assert.AreEqual(k1.ToString("N2"), cmyk2.K.ToString("N2"), "#3 K (" + sample.Name + ")");

                CmykColor cmyk3 = hsv.ToCmyk();
                Assert.AreEqual(c1.ToString("N2"), cmyk3.C.ToString("N2"), "#4 C (" + sample.Name + ")");
                Assert.AreEqual(m1.ToString("N2"), cmyk3.M.ToString("N2"), "#4 M (" + sample.Name + ")");
                Assert.AreEqual(y1.ToString("N2"), cmyk3.Y.ToString("N2"), "#4 Y (" + sample.Name + ")");
                Assert.AreEqual(k1.ToString("N2"), cmyk3.K.ToString("N2"), "#4 K (" + sample.Name + ")");
            }
        }