Exemple #1
0
 public static Double3 Max(Double3 first, Double3 second)
 {
     return new Double3(Mathd.Max(first.x, second.x), Mathd.Max(first.y, second.y), Mathd.Max(first.z, second.z));
 }
 private static Double3 GetPickerCoords(Colour col, Colour.Model newModel, Colour.RGBSpace workingSpace)
 {
     Double3 coords = Double3.zero;
     if (newModel == Colour.Model.RGB)
         coords = Colour.To_RGB(col, workingSpace);
     else if (newModel == Colour.Model.xyY)
         coords = Colour.To_xyY(col);
     else if (newModel == Colour.Model.HSL)
         coords = Colour.To_HSL(col, workingSpace);
     else if (newModel == Colour.Model.HSV)
         coords = Colour.To_HSV(col, workingSpace);
     else if (newModel == Colour.Model.XYZ)
         coords = new Double3(col.X, col.Y, col.Z);
     else if (newModel == Colour.Model.Lab)
         coords = Colour.To_Lab(col);
     //else if (originalModel == Colour.Model.LCH)
     //workingSpaceColour = Colour.From_LCH((Double3)arrangement);
     return coords;
 }
Exemple #3
0
 public Double3(Double3 v)
 {
     x = v.x;
     y = v.y;
     z = v.z;
 }
Exemple #4
0
        public static Colour From_HSL(Double3 hsl, RGBSpace space)
        {
            double c = (1 - Mathd.Abs((2.0 * hsl.z) - 1)) * hsl.y;
            double x = c * (1 - Mathd.Abs(((hsl.x * 6.0) % 2) - 1));
            double m = hsl.z - (c / 2.0);
            double h = hsl.x * 6;
            int i = Mathd.FloorToInt(h);
            switch (i)
            {
                case 0:
                    return From_RGB(new Double3(c + m, x + m, m), space);

                case 1:
                    return From_RGB(new Double3(x + m, c + m, m), space);

                case 2:
                    return From_RGB(new Double3(m, c + m, x + m), space);

                case 3:
                    return From_RGB(new Double3(m, x + m, c + m), space);

                case 4:
                    return From_RGB(new Double3(x + m, m, c + m), space);

                default:
                    return From_RGB(new Double3(c + m, m, x + m), space);
            }
        }
Exemple #5
0
 public static Double3 Pow(Double3 v, double p)
 {
     return new Double3(Pow(v.x, p), Pow(v.y, p), Pow(v.z, p));
 }
Exemple #6
0
 public Colour(Double3 coords)
 {
     val = coords;
 }
Exemple #7
0
 public Colour()
 {
     val = new Double3();
 }
Exemple #8
0
 private static void BuildConversionMatrices(RGBDefinition definition)
 {
     RGBDefinition d = definition;
     Double3 R = new Double3(d.r.x / d.r.y, 1.0, (1.0 - d.r.x - d.r.y) / d.r.y);
     Double3 G = new Double3(d.g.x / d.g.y, 1.0, (1.0 - d.g.x - d.g.y) / d.g.y);
     Double3 B = new Double3(d.b.x / d.b.y, 1.0, (1.0 - d.b.x - d.b.y) / d.b.y);
     Double3 W = new Double3(d.w.x / d.w.y, 1.0, (1.0 - d.w.x - d.w.y) / d.w.y);
     Double3x3 altMat = new Double3x3(R.x, G.x, B.x, R.y, G.y, B.y, R.z, G.z, B.z);
     Double3 s = Double3x3.Inverse(altMat) * W;
     d.toXYZ = new Double3x3(s.x * R.x, s.y * G.x, s.z * B.x, s.x * R.y, s.y * G.y, s.z * B.y, s.x * R.z, s.y * G.z, s.z * B.z);
     d.fromXYZ = Double3x3.Inverse(d.toXYZ);
 }
Exemple #9
0
        public static Double3 To_Lab(Colour col)
        {
            Double3 lab = new Double3();
            Double3 w = new Double3(95.047, 100.000, 108.883);
            System.Func<double, double> f = new System.Func<double, double>((x) =>
            {
                if (x > Mathd.Pow(6.0 / 29.0, 3))
                    return Mathd.Pow(x, (1.0 / 3.0));
                else
                    return ((1.0 / 3.0) * Mathd.Pow(29.0 / 6.0, 2.0) * x) + (4.0 / 29.0);
            });

            lab.x = (166.0 * f(col.Y / w.y)) - 16;
            lab.y = 500.0 * (f(col.X / w.x) - f(col.Y / w.y));
            lab.z = 200.0 * (f(col.Y / w.y) - f(col.Z / w.z));

            lab.x = (lab.x + 15) * (1.0 / 30.0);
            lab.y = (lab.y + 30) * (1.0 / 50.0);
            lab.z = (lab.z + 30) * (1.0 / 50.0);
            return lab;
        }
Exemple #10
0
 public static Colour From_xyY(Double3 xyY)
 {
     if (xyY.y == 0)
         return new Colour(Double3.zero);
     else
         return new Colour(new Double3((xyY.x * xyY.z) / xyY.y, xyY.z, ((1 + (-xyY.x) + (-xyY.y)) * xyY.z) / xyY.y));
 }
Exemple #11
0
 public static Colour From_RGB(Double3 rgb, RGBSpace space)
 {
     RGBDefinition d = rgbSpaces[space];
     Double3 linear = Mathd.Pow(rgb, d.gamma);
     return new Colour(d.toXYZ * linear);
 }
Exemple #12
0
        public static Colour From_Lab(Double3 lab)
        {
            lab.x = (lab.x * 30) - 15;
            lab.y = (lab.y * 60) - 30;
            lab.z = (lab.z * 60) - 30;
            Colour col = new Colour();
            Double3 w = new Double3(95.047, 100.000, 108.883);
            System.Func<double, double> f = new System.Func<double, double>((x) =>
            {
                if (x > Mathd.Pow(6.0 / 29.0, 3.0))
                    return Mathd.Pow(x, 3.0);
                else
                    return 3.0 * Mathd.Pow(6.0 / 29.0, 2.0) * (x - (4.0 / 29.0));
            });
            col.X = w.x * f(((1.0 / 116.0) * (lab.x + 16)) + ((1.0 / 500.0) * lab.y));
            col.Y = w.y * f((1.0 / 116.0) * (lab.x + 16));
            col.Z = w.z * f(((1.0 / 116.0) * (lab.x + 16)) - ((1.0 / 200.0) * lab.z));

            return col;
        }