Ejemplo n.º 1
0
 /// <param name="r">Red (from 0 to 1)</param>
 /// <param name="g">Green (from 0 to 1)</param>
 /// <param name="b">Blue (from 0 to 1)</param>
 /// <param name="workingSpace">
 /// <see cref="RGBWorkingSpaces" />
 /// </param>
 public LinearRGBColor(double r, double g, double b, IRGBWorkingSpace workingSpace)
 {
     R             = r.CheckRange(0, 1);
     G             = g.CheckRange(0, 1);
     B             = b.CheckRange(0, 1);
     _workingSpace = workingSpace;
 }
Ejemplo n.º 2
0
 protected bool Equals(IRGBWorkingSpace other)
 {
     if (other == null)
     {
         throw new ArgumentNullException("other");
     }
     return(Equals(WhitePoint, other.WhitePoint) && ChromaticityCoordinates.Equals(other.ChromaticityCoordinates) && Equals(Companding, other.Companding));
 }
Ejemplo n.º 3
0
        private XYZToLinearRGBConverter GetXYZToLinearRGBConverter(IRGBWorkingSpace workingSpace)
        {
            if (_lastXYZToLinearRGBConverter != null &&
                _lastXYZToLinearRGBConverter.TargetRGBWorkingSpace.Equals(workingSpace))
            {
                return(_lastXYZToLinearRGBConverter);
            }

            return(_lastXYZToLinearRGBConverter = new XYZToLinearRGBConverter(workingSpace));
        }
Ejemplo n.º 4
0
 public ColourfulConverter()
 {
     WhitePoint = DefaultWhitePoint;
     LMSTransformationMatrix   = XYZAndLMSConverter.DefaultTransformationMatrix;
     ChromaticAdaptation       = new VonKriesChromaticAdaptation(_cachedXYZAndLMSConverter, _cachedXYZAndLMSConverter);
     TargetLabWhitePoint       = LabColor.DefaultWhitePoint;
     TargetHunterLabWhitePoint = HunterLabColor.DefaultWhitePoint;
     TargetLuvWhitePoint       = LuvColor.DefaultWhitePoint;
     TargetRGBWorkingSpace     = RGBColor.DefaultWorkingSpace;
 }
Ejemplo n.º 5
0
        private LinearRGBToXYZConverter GetLinearRGBToXYZConverter(IRGBWorkingSpace workingSpace)
        {
            if (_lastLinearRGBToXYZConverter != null &&
                _lastLinearRGBToXYZConverter.SourceRGBWorkingSpace.Equals(workingSpace))
            {
                return(_lastLinearRGBToXYZConverter);
            }

            return(_lastLinearRGBToXYZConverter = new LinearRGBToXYZConverter(workingSpace));
        }
Ejemplo n.º 6
0
        public void DifferentWorkingSpace_IsNotEqual()
        {
            // arrange
            IRGBWorkingSpace x = RGBWorkingSpaces.sRGB;
            IRGBWorkingSpace y = RGBWorkingSpaces.AdobeRGB1998;

            // act
            bool equals = x.Equals(y);

            // assert
            Assert.IsFalse(equals);
        }
Ejemplo n.º 7
0
        public void DifferentWorkingSpace_SameSpecifiers_IsEqual()
        {
            // arrange
            IRGBWorkingSpace x = new AdobeRGB1998Duplicate();
            IRGBWorkingSpace y = RGBWorkingSpaces.AdobeRGB1998;

            // act
            bool equals = y.Equals(x);

            // assert
            Assert.IsTrue(equals);
        }
Ejemplo n.º 8
0
        public void SameWorkingSpace_IsEqual()
        {
            // arrange
            IRGBWorkingSpace x = RGBWorkingSpaces.sRGB;
            IRGBWorkingSpace y = RGBWorkingSpaces.sRGB;

            // act
            bool equals = x.Equals(y);

            // assert
            Assert.IsTrue(equals);
        }
        /// <summary>
        /// Computes RGB/XYZ matrix
        /// </summary>
        protected static Matrix GetRGBToXYZMatrix(IRGBWorkingSpace workingSpace)
        {
            if (workingSpace == null)
            {
                throw new ArgumentNullException(nameof(workingSpace));
            }

            // for more info, see: http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html

            var    chromaticity = workingSpace.ChromaticityCoordinates;
            double xr           = chromaticity.R.x,
                   xg           = chromaticity.G.x,
                   xb           = chromaticity.B.x,
                   yr           = chromaticity.R.y,
                   yg           = chromaticity.G.y,
                   yb           = chromaticity.B.y;

            var          Xr = xr / yr;
            const double Yr = 1;
            var          Zr = (1 - xr - yr) / yr;

            var          Xg = xg / yg;
            const double Yg = 1;
            var          Zg = (1 - xg - yg) / yg;

            var          Xb = xb / yb;
            const double Yb = 1;
            var          Zb = (1 - xb - yb) / yb;

            var S = new Matrix(new Vector[]
            {
                new[] { Xr, Xg, Xb },
                new[] { Yr, Yg, Yb },
                new[] { Zr, Zg, Zb },
            }).Inverse();

            var W = workingSpace.WhitePoint.Vector;

            var SW = S.MultiplyBy(W);
            var Sr = SW[0];
            var Sg = SW[1];
            var Sb = SW[2];

            Matrix M = new Vector[]
            {
                new[] { Sr *Xr, Sg *Xg, Sb *Xb },
                new[] { Sr *Yr, Sg *Yg, Sb *Yb },
                new[] { Sr *Zr, Sg *Zg, Sb *Zb },
            };

            return(M);
        }
Ejemplo n.º 10
0
        /// <inheritdoc cref="object" />
        public bool Equals(IRGBWorkingSpace other)
        {
            if (other == null)
            {
                return(false);
            }

            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return(Equals(WhitePoint, other.WhitePoint) &&
                   ChromaticityCoordinates.Equals(other.ChromaticityCoordinates) &&
                   Companding.Equals(other.Companding));
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Applying the working space companding function (<see cref="IRGBWorkingSpace.Companding"/>) to uncompanded vector.
        /// </summary>
        private static RGBColor CompandVector(Vector uncompandedVector, IRGBWorkingSpace workingSpace)
        {
            ICompanding companding = workingSpace.Companding;
            Vector      compandedVector = uncompandedVector.Select(companding.Companding).ToList();
            double      R, G, B;

            compandedVector.AssignVariables(out R, out G, out B);

            R = R.CropRange(0, 1);
            G = G.CropRange(0, 1);
            B = B.CropRange(0, 1);

            var result = new RGBColor(R, G, B, workingSpace);

            return(result);
        }
        protected static Matrix GetRGBToXYZMatrix(IRGBWorkingSpace workingSpace)
        {
            if (workingSpace == null)
            {
                throw new ArgumentNullException("workingSpace");
            }

            // for more info, see: http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html

            RGBPrimariesChromaticityCoordinates chromaticity = workingSpace.ChromaticityCoordinates;
            double xr = chromaticity.R.x, xg = chromaticity.G.x, xb = chromaticity.B.x,
                   yr = chromaticity.R.y, yg = chromaticity.G.y, yb = chromaticity.B.y;

            double Sr, Sg, Sb;

            double       Xr = xr / yr;
            const double Yr = 1;
            double       Zr = (1 - xr - yr) / yr;

            double       Xg = xg / yg;
            const double Yg = 1;
            double       Zg = (1 - xg - yg) / yg;

            double       Xb = xb / yb;
            const double Yb = 1;
            double       Zb = (1 - xb - yb) / yb;

            var S = new []
            {
                new[] { Xr, Xg, Xb },
                new[] { Yr, Yg, Yb },
                new[] { Zr, Zg, Zb },
            }.Inverse();

            Vector W = workingSpace.WhitePoint.Vector;

            (S.MultiplyBy(W)).AssignVariables(out Sr, out Sg, out Sb);

            var M = new []
            {
                new[] { Sr *Xr, Sg *Xg, Sb *Xb },
                new[] { Sr *Yr, Sg *Yg, Sb *Yb },
                new[] { Sr *Zr, Sg *Zg, Sb *Zb },
            };

            return(M);
        }
        protected static Matrix GetRGBToXYZMatrix(IRGBWorkingSpace workingSpace)
        {
            if (workingSpace == null) throw new ArgumentNullException("workingSpace");

            // for more info, see: http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html

            RGBPrimariesChromaticityCoordinates chromaticity = workingSpace.ChromaticityCoordinates;
            double xr = chromaticity.R.x, xg = chromaticity.G.x, xb = chromaticity.B.x,
                   yr = chromaticity.R.y, yg = chromaticity.G.y, yb = chromaticity.B.y;

            double Sr, Sg, Sb;

            double Xr = xr / yr;
            const double Yr = 1;
            double Zr = (1 - xr - yr) / yr;

            double Xg = xg / yg;
            const double Yg = 1;
            double Zg = (1 - xg - yg) / yg;

            double Xb = xb / yb;
            const double Yb = 1;
            double Zb = (1 - xb - yb) / yb;

            var S = new []
                {
                    new[] { Xr, Xg, Xb },
                    new[] { Yr, Yg, Yb },
                    new[] { Zr, Zg, Zb },
                }.Inverse();

            Vector W = workingSpace.WhitePoint.Vector;

            (S.MultiplyBy(W)).AssignVariables(out Sr, out Sg, out Sb);

            var M = new []
                {
                    new[] { Sr * Xr, Sg * Xg, Sb * Xb },
                    new[] { Sr * Yr, Sg * Yg, Sb * Yb },
                    new[] { Sr * Zr, Sg * Zg, Sb * Zb },
                };

            return M;
        }
Ejemplo n.º 14
0
 /// <summary>
 /// Creates RGB color with all channels equal
 /// </summary>
 /// <param name="value">Grey value (from 0 to 1)</param>
 /// <param name="workingSpace"><see cref="RGBWorkingSpaces"/></param>
 public static RGBColor FromGrey(double value, IRGBWorkingSpace workingSpace)
 {
     return(new RGBColor(value, value, value, workingSpace));
 }
Ejemplo n.º 15
0
 public RGBColor(double r, double g, double b, IRGBWorkingSpace workingSpace)
     : base(r, g, b)
 {
     WorkingSpace = workingSpace;
 }
Ejemplo n.º 16
0
 /// <param name="vector"><see cref="Vector"/>, expected 3 dimensions (range from 0 to 1)</param>
 /// <param name="workingSpace"><see cref="RGBWorkingSpaces"/></param>
 public RGBColor(Vector vector, IRGBWorkingSpace workingSpace)
     : base(vector)
 {
     WorkingSpace = workingSpace;
 }
Ejemplo n.º 17
0
 public RGBColor(double r, double g, double b, IRGBWorkingSpace workingSpace)
     : base(r, g, b)
 {
     WorkingSpace = workingSpace;
 }
Ejemplo n.º 18
0
 public static RGBColor FromRGB8bit(byte red, byte green, byte blue, IRGBWorkingSpace workingSpace)
 {
     return new RGBColor(red / 255d, green / 255d, blue / 255d, workingSpace);
 }
 /// <param name="sourceRGBWorkingSpace">Source RGB working space</param>
 public LinearRGBToXYZConverter(IRGBWorkingSpace sourceRGBWorkingSpace)
 {
     SourceRGBWorkingSpace = sourceRGBWorkingSpace;
     _conversionMatrix     = GetRGBToXYZMatrix(SourceRGBWorkingSpace);
 }
 /// <summary>
 /// Computes XYZ/RGB matrix
 /// </summary>
 protected static Matrix GetXYZToRGBMatrix(IRGBWorkingSpace workingSpace) => GetRGBToXYZMatrix(workingSpace).Inverse();
Ejemplo n.º 21
0
 public static RGBColor ToRGBColor(this Color c, IRGBWorkingSpace space)
 {
     return(new RGBColor(c.r, c.g, c.b, space));
 }
 protected static Matrix GetXYZToRGBMatrix(IRGBWorkingSpace workingSpace)
 {
     return GetRGBToXYZMatrix(workingSpace).Inverse();
 }
Ejemplo n.º 23
0
 /// <param name="vector"><see cref="Vector"/>, expected 3 dimensions (range from 0 to 1)</param>
 /// <param name="workingSpace"><see cref="RGBWorkingSpaces"/></param>
 public RGBColor(Vector vector, IRGBWorkingSpace workingSpace)
     : base(vector)
 {
     WorkingSpace = workingSpace;
 }
Ejemplo n.º 24
0
 protected bool Equals(IRGBWorkingSpace other)
 {
     if (other == null) throw new ArgumentNullException("other");
     return Equals(WhitePoint, other.WhitePoint) && ChromaticityCoordinates.Equals(other.ChromaticityCoordinates) && Equals(Companding, other.Companding);
 }
Ejemplo n.º 25
0
 /// <summary>
 /// Creates RGB color from 8-bit channels
 /// </summary>
 /// <param name="red"></param>
 /// <param name="green"></param>
 /// <param name="blue"></param>
 /// <param name="workingSpace">
 /// <see cref="RGBWorkingSpaces" />
 /// </param>
 public static RGBColor FromRGB8bit(byte red, byte green, byte blue, IRGBWorkingSpace workingSpace) => new RGBColor(red / 255d, green / 255d, blue / 255d, workingSpace);
Ejemplo n.º 26
0
 /// <summary>
 /// Creates RGB color with all channels equal
 /// </summary>
 /// <param name="value">Grey value (from 0 to 1)</param>
 /// <param name="workingSpace">
 /// <see cref="RGBWorkingSpaces" />
 /// </param>
 public static LinearRGBColor FromGrey(double value, IRGBWorkingSpace workingSpace) => new LinearRGBColor(value, value, value, workingSpace);
Ejemplo n.º 27
0
 public XYZToLinearRGBConverter(IRGBWorkingSpace targetRGBWorkingSpace)
 {
     TargetRGBWorkingSpace = targetRGBWorkingSpace ?? RGBColor.DefaultWorkingSpace;
     _conversionMatrix     = GetXYZToRGBMatrix(TargetRGBWorkingSpace);
 }
Ejemplo n.º 28
0
 /// <param name="workingSpace"><see cref="RGBWorkingSpaces"/></param>
 public RGBColor(Color color, IRGBWorkingSpace workingSpace)
     : base(((double)color.R) / 255, ((double)color.G) / 255, ((double)color.B) / 255)
 {
     WorkingSpace = workingSpace;
 }
Ejemplo n.º 29
0
 public static RGBColor AsRGBColor(Color color, IRGBWorkingSpace workingSpace)
 {
     return(new RGBColor(((double)color.R) / 255, ((double)color.G) / 255, ((double)color.B) / 255, workingSpace));
 }
Ejemplo n.º 30
0
 /// <summary>
 /// Creates RGB color with all channels equal
 /// </summary>
 /// <param name="value">Grey value (from 0 to 1)</param>
 /// <param name="workingSpace"><see cref="RGBWorkingSpaces"/></param>
 public static RGBColor FromGrey(double value, IRGBWorkingSpace workingSpace)
 {
     return new RGBColor(value, value, value, workingSpace);
 }
Ejemplo n.º 31
0
 /// <param name="vector"><see cref="Vector" />, expected 3 dimensions (range from 0 to 1)</param>
 /// <param name="workingSpace">
 /// <see cref="RGBWorkingSpaces" />
 /// </param>
 public LinearRGBColor(Vector vector, IRGBWorkingSpace workingSpace)
     : this(vector[0], vector[1], vector[2], workingSpace)
 {
 }
Ejemplo n.º 32
0
 /// <param name="color"></param>
 /// <param name="workingSpace">
 /// <see cref="RGBWorkingSpaces" />
 /// </param>
 public RGBColor(Color color, IRGBWorkingSpace workingSpace)
     : this((double)color.R / 255, (double)color.G / 255, (double)color.B / 255, workingSpace)
 {
 }