Ejemplo n.º 1
0
        public ColorRgb(ColorXyz xyz, RgbWorkingSpace ws)
        {
            var m = ws.XyztoRgbMatrix;

            double x = xyz.X / 100;
            double y = xyz.Y / 100;
            double z = xyz.Z / 100;

            double lin_r = (x * m[0, 0]) + (y * m[0, 1]) + (z * m[0, 2]);       // red
            double lin_g = (x * m[1, 0]) + (y * m[1, 1]) + (z * m[1, 2]);       // green
            double lin_b = (x * m[2, 0]) + (y * m[2, 1]) + (z * m[2, 2]);       // blue

            double r = (lin_r <= 0.0031308) ? 12.92 * lin_r : (1.055) * System.Math.Pow(lin_r, (1.0 / 2.4)) - 0.055;
            double g = (lin_g <= 0.0031308) ? 12.92 * lin_g : (1.055) * System.Math.Pow(lin_g, (1.0 / 2.4)) - 0.055;
            double b = (lin_b <= 0.0031308) ? 12.92 * lin_b : (1.055) * System.Math.Pow(lin_b, (1.0 / 2.4)) - 0.055;

            r = ClampToRange_0_1(r);
            g = ClampToRange_0_1(g);
            b = ClampToRange_0_1(b);

            this._alpha = xyz.Alpha;
            this._r     = r;
            this._g     = g;
            this._b     = b;
        }
Ejemplo n.º 2
0
 public bool Equals(RgbWorkingSpace other)
 {
     // TODO: Object.Equals for ICompanding will be slow.
     return(this.WhitePoint.Equals(other.WhitePoint) &&
            this.ChromaticityCoordinates.Equals(other.ChromaticityCoordinates) &&
            Equals(this.Companding, other.Companding));
 }
Ejemplo n.º 3
0
 public LinearRgb(Vector3 vector, RgbWorkingSpace workingSpace)
     : this()
 {
     // Clamp to 0-1 range.
     this.backingVector = Vector3.Clamp(vector, Vector3.Zero, Vector3.One);
     this.WorkingSpace  = workingSpace;
 }
Ejemplo n.º 4
0
 public Rgb(Vector3 vector, RgbWorkingSpace workingSpace)
 {
     vector            = Vector3.Clamp(vector, Min, Max);
     this.R            = vector.X;
     this.G            = vector.Y;
     this.B            = vector.Z;
     this.WorkingSpace = workingSpace;
 }
Ejemplo n.º 5
0
 public LinearRgb(Vector3 vector, RgbWorkingSpace workingSpace)
 {
     // Clamp to 0-1 range.
     vector            = Vector3.Clamp(vector, Min, Max);
     this.R            = vector.X;
     this.G            = vector.Y;
     this.B            = vector.Z;
     this.WorkingSpace = workingSpace;
 }
Ejemplo n.º 6
0
        public bool Equals(RgbWorkingSpace x, RgbWorkingSpace y)
        {
            if (x is RgbWorkingSpace g1 && y is RgbWorkingSpace g2)
            {
                return(this.Equals(g1.WhitePoint, g2.WhitePoint) &&
                       this.Equals(g1.ChromaticityCoordinates, g2.ChromaticityCoordinates));
            }

            return(this.Equals(x.WhitePoint, y.WhitePoint) &&
                   this.Equals(x.ChromaticityCoordinates, y.ChromaticityCoordinates));
        }
Ejemplo n.º 7
0
        public ColorXyz(ColorLab lab, RgbWorkingSpace ws)
        {
            ColorXyz i = ws.ReferenceWhite.ColorXyz;

            double delta = 6.0 / 29.0;

            double fy = (lab.L + 16) / 116.0;
            double fx = fy + (lab.A / 500.0);
            double fz = fy - (lab.B / 200.0);

            double x = (fx > delta) ? i.X * (fx * fx * fx) : (fx - 16.0 / 116.0) * 3 * (delta * delta) * i.X;
            double y = (fy > delta) ? i.Y * (fy * fy * fy) : (fy - 16.0 / 116.0) * 3 * (delta * delta) * i.Y;
            double z = (fz > delta) ? i.Z * (fz * fz * fz) : (fz - 16.0 / 116.0) * 3 * (delta * delta) * i.Z;

            this._alpha = lab.Alpha;
            this._x     = x;
            this._y     = y;
            this._z     = z;
        }
Ejemplo n.º 8
0
        public ColorXyz(ColorRgb rgb, RgbWorkingSpace ws)
        {
            double[,] m = ws.RgbtoxyzMatrix;

            // convert to a sRGB form
            double r = (rgb.R > 0.04045) ? System.Math.Pow((rgb.R + 0.055) / (1.055), 2.4) : (rgb.R / 12.92);
            double g = (rgb.G > 0.04045) ? System.Math.Pow((rgb.G + 0.055) / (1.055), 2.4) : (rgb.G / 12.92);
            double b = (rgb.B > 0.04045) ? System.Math.Pow((rgb.B + 0.055) / (1.055), 2.4) : (rgb.B / 12.92);


            double x = (r * m[0, 0] + g * m[0, 1] + b * m[0, 2]);
            double y = (r * m[1, 0] + g * m[1, 1] + b * m[1, 2]);
            double z = (r * m[2, 0] + g * m[2, 1] + b * m[2, 2]);

            x *= 100;
            y *= 100;
            z *= 100;

            this._alpha = rgb.Alpha;
            this._x     = x;
            this._y     = y;
            this._z     = z;
        }
Ejemplo n.º 9
0
 public LinearRgb(float r, float g, float b, RgbWorkingSpace workingSpace)
     : this(new Vector3(r, g, b), workingSpace)
 {
 }
Ejemplo n.º 10
0
 public int GetHashCode(RgbWorkingSpace obj)
 {
     throw new NotImplementedException();
 }