Ejemplo n.º 1
0
 public HSVColour(ColourVector v, UnitColourComponent a)
 {
     _h = v.X;
     _s = v.Y;
     _v = v.Z;
     _a = a;
 }
Ejemplo n.º 2
0
 public HSVColour(DegreeColourComponent h, UnitColourComponent s, UnitColourComponent v, UnitColourComponent a)
 {
     _h = h;
     _s = s;
     _v = v;
     _a = a;
 }
Ejemplo n.º 3
0
 public HSVColour(DegreeColourComponent h, UnitColourComponent s, UnitColourComponent v)
 {
     _h = h;
     _s = s;
     _v = v;
     _a = ColourSpaceConstants.ONE;
 }
Ejemplo n.º 4
0
 public HSLColour(DegreeColourComponent h, UnitColourComponent s, UnitColourComponent l, UnitColourComponent a)
 {
     _h = h;
     _s = s;
     _l = l;
     _a = a;
 }
Ejemplo n.º 5
0
 public HSLColour(DegreeColourComponent h, UnitColourComponent s, UnitColourComponent l)
 {
     _h = h;
     _s = s;
     _l = l;
     _a = ColourSpaceConstants.ONE;
 }
Ejemplo n.º 6
0
        public static SRGBColour ToSRGB(this HSVColour hsv)
        {
            var r = new UnitColourComponent(ColourSpaceConstants.ZERO);
            var g = new UnitColourComponent(ColourSpaceConstants.ZERO);
            var b = new UnitColourComponent(ColourSpaceConstants.ZERO);

            // https://en.wikipedia.org/wiki/HSL_and_HSV#From_HSV
            // http://www.easyrgb.com/en/math.php

            if (hsv.S == ColourSpaceConstants.ZERO)
            {
                var vb = hsv.V.ToByteColour();
                return(new SRGBColour(vb, vb, vb, hsv.A.ToByteColour()));
            }

            // Calcs simplified from Wikipedia and verified to match calcs at EasyRGB
            var h_unit = hsv.H.Value / ColourSpaceConstants.SIXTY;

            while (h_unit >= ColourSpaceConstants.SIX)
            {
                h_unit -= ColourSpaceConstants.SIX;
            }
            var h_int = Math.Floor(h_unit);

            var v     = hsv.V.ToByteColour();
            var var_1 = ((UnitColourComponent)(hsv.V.Value * (ColourSpaceConstants.ONE - hsv.S.Value))).ToByteColour();                                 // 0 + m
            var var_2 = ((UnitColourComponent)(hsv.V.Value * (ColourSpaceConstants.ONE - hsv.S.Value * (h_unit - h_int)))).ToByteColour();              // m + X (1<=H<=2, 3<=H<=4, 5<=H<=6)
            var var_3 = ((UnitColourComponent)(hsv.V.Value * (ColourSpaceConstants.ONE - hsv.S.Value * (1 - (h_unit - h_int))))).ToByteColour();        // m + X (0<=H<=1, 2<=H<=3, 4<=H<=5)

            switch (h_int)
            {
            case 0: return(new SRGBColour(v, var_3, var_1, hsv.A.ToByteColour()));

            case 1: return(new SRGBColour(var_2, v, var_1, hsv.A.ToByteColour()));

            case 2: return(new SRGBColour(var_1, v, var_3, hsv.A.ToByteColour()));

            case 3: return(new SRGBColour(var_1, var_2, v, hsv.A.ToByteColour()));

            case 4: return(new SRGBColour(var_3, var_1, v, hsv.A.ToByteColour()));

            default: return(new SRGBColour(v, var_1, var_2, hsv.A.ToByteColour()));
            }
        }
Ejemplo n.º 7
0
        public static SRGBColour ToSRGB(this HSLColour hsl)
        {
            var r = new UnitColourComponent(ColourSpaceConstants.ZERO);
            var g = new UnitColourComponent(ColourSpaceConstants.ZERO);
            var b = new UnitColourComponent(ColourSpaceConstants.ZERO);

            // https://en.wikipedia.org/wiki/HSL_and_HSV#From_HSV
            // http://www.easyrgb.com/en/math.php

            if (hsl.S == ColourSpaceConstants.ZERO)
            {
                var lb = hsl.L.ToByteColour();
                return(new SRGBColour(lb, lb, lb, hsl.A.ToByteColour()));
            }

            // Calcs simplified from Wikipedia and verified to match calcs at EasyRGB
            var h_unit = hsl.H.Value / ColourSpaceConstants.SIXTY;

            while (h_unit >= ColourSpaceConstants.SIX)
            {
                h_unit -= ColourSpaceConstants.SIX;
            }
            var h_int = Math.Floor(h_unit);

            var c = hsl.S * (ColourSpaceConstants.ONE - Math.Abs(ColourSpaceConstants.TWO * hsl.L - ColourSpaceConstants.ONE));

            // X for 1st = C * (h_unit - h_int)
            // X for 2nd = C * (1 - (h_unit + h_int))

            switch (h_int)
            {
            case 0: return(new SRGBColour(v, var_3, var_1, hsl.A.ToByteColour()));

            case 1: return(new SRGBColour(var_2, v, var_1, hsl.A.ToByteColour()));

            case 2: return(new SRGBColour(var_1, v, var_3, hsl.A.ToByteColour()));

            case 3: return(new SRGBColour(var_1, var_2, v, hsl.A.ToByteColour()));

            case 4: return(new SRGBColour(var_3, var_1, v, hsl.A.ToByteColour()));

            default: return(new SRGBColour(v, var_1, var_2, hsl.A.ToByteColour()));
            }
        }
Ejemplo n.º 8
0
 public static DegreeColourComponent ToDegreeColour(this UnitColourComponent unit) => new DegreeColourComponent(unit.Value * DegreeColourComponent.MaxValue);
Ejemplo n.º 9
0
 public static ByteColourComponent ToByteColour(this UnitColourComponent colourComp) => new ByteColourComponent(colourComp.Value * (ColourPrimitive)ByteColourComponent.MaxValue);