Exemple #1
0
        /// <summary>
        /// Transforms XYZ color to destination reference white.
        /// </summary>
        public XYZColor Transform(XYZColor sourceColor, XYZColor sourceWhitePoint, XYZColor targetWhitePoint)
        {
            if (sourceColor == null)
            {
                throw new ArgumentNullException("sourceColor");
            }
            if (sourceWhitePoint == null)
            {
                throw new ArgumentNullException("sourceWhitePoint");
            }
            if (targetWhitePoint == null)
            {
                throw new ArgumentNullException("targetWhitePoint");
            }

            if (sourceWhitePoint.Equals(targetWhitePoint))
            {
                return(sourceColor);
            }

            LMSColor sourceColorLMS      = _conversionToLMS.Convert(sourceColor);
            LMSColor sourceWhitePointLMS = _conversionToLMS.Convert(sourceWhitePoint);
            LMSColor targetWhitePointLMS = _conversionToLMS.Convert(targetWhitePoint);

            Matrix diagonalMatrix = MatrixFactory.CreateDiagonal(targetWhitePointLMS.L / sourceWhitePointLMS.L, targetWhitePointLMS.M / sourceWhitePointLMS.M, targetWhitePointLMS.S / sourceWhitePointLMS.S);

            var      targetColorLMS = new LMSColor(diagonalMatrix.MultiplyBy(sourceColorLMS.Vector));
            XYZColor targetColor    = _conversionToXYZ.Convert(targetColorLMS);

            return(targetColor);
        }
        public void RasterMapperConstructorTest()
        {
            RasterMapper mapper = new RasterMapper(RasterMapMode.ValueIsArea, MatrixFactory.CreateIdentity(4));

            Assert.AreEqual(RasterMapMode.ValueIsArea, mapper.Mode);
            Assert.AreEqual(MatrixFactory.CreateIdentity(4), mapper.RasterTransformation);
            Assert.AreEqual(MatrixFactory.CreateIdentity(4), mapper.GeometryTransformation);
            Assert.AreEqual(1, mapper.ColumnSize);
            Assert.AreEqual(1, mapper.RowSize);
            Assert.AreEqual(new CoordinateVector(1, 0), mapper.ColumnVector);
            Assert.AreEqual(new CoordinateVector(0, 1), mapper.RowVector);
            Assert.AreEqual(new CoordinateVector(1, 1, 1), mapper.Scale);
            Assert.AreEqual(Coordinate.Empty, mapper.Translation);

            // exceptions

            Assert.Throws <ArgumentNullException>(() => new RasterMapper(RasterMapMode.ValueIsArea, null));
            Assert.Throws <ArgumentException>(() => new RasterMapper(RasterMapMode.ValueIsArea, new Matrix(1, 4)));
            Assert.Throws <ArgumentException>(() => new RasterMapper(RasterMapMode.ValueIsArea, new Matrix(4, 1)));
            Assert.Throws <ArgumentException>(() => new RasterMapper(RasterMapMode.ValueIsArea, new Matrix(4, 4, Double.NaN)));
            Assert.Throws <ArgumentException>(() => new RasterMapper(RasterMapMode.ValueIsArea, new Matrix(4, 4)));
            Assert.Throws <ArgumentException>(() =>
            {
                Matrix matrix = new Matrix(4, 4);
                matrix[3, 0]  = matrix[3, 1] = matrix[3, 2] = matrix[3, 3] = 1;
                new RasterMapper(RasterMapMode.ValueIsArea, matrix);
            });
            Assert.Throws <NotSupportedException>(() => new RasterMapper(RasterMapMode.ValueIsArea, MatrixFactory.CreateDiagonal(0, 0, 0, 1)));
        }
        public void RasterMapperFromMapperTest()
        {
            // matrix from identity

            RasterMapper sourceMapper = new RasterMapper(RasterMapMode.ValueIsArea, MatrixFactory.CreateIdentity(4));

            RasterMapper mapper = RasterMapper.FromMapper(sourceMapper, MatrixFactory.CreateIdentity(4));

            Assert.AreEqual(RasterMapMode.ValueIsArea, mapper.Mode);
            Assert.AreEqual(MatrixFactory.CreateIdentity(4), mapper.GeometryTransformation);


            // coordinate and vector from identity

            mapper = RasterMapper.FromMapper(sourceMapper, new Coordinate(300, 1000, 0), new CoordinateVector(10, 3));

            Assert.AreEqual(RasterMapMode.ValueIsArea, mapper.Mode);
            Assert.AreEqual(new CoordinateVector(10, 0), mapper.ColumnVector);
            Assert.AreEqual(new CoordinateVector(0, 3), mapper.RowVector);
            Assert.AreEqual(new Coordinate(300, 1000), mapper.Translation);


            // all values from identity

            mapper = RasterMapper.FromMapper(sourceMapper, 300, 1000, 0, 10, 3, 0);

            Assert.AreEqual(RasterMapMode.ValueIsArea, mapper.Mode);
            Assert.AreEqual(new CoordinateVector(10, 0), mapper.ColumnVector);
            Assert.AreEqual(new CoordinateVector(0, 3), mapper.RowVector);
            Assert.AreEqual(new Coordinate(300, 1000), mapper.Translation);


            // exceptions

            Assert.Throws <ArgumentNullException>(() => RasterMapper.FromMapper(mapper, null));
            Assert.Throws <ArgumentException>(() => RasterMapper.FromMapper(mapper, new Matrix(1, 4)));
            Assert.Throws <ArgumentException>(() => RasterMapper.FromMapper(mapper, new Matrix(4, 1)));
            Assert.Throws <ArgumentException>(() => RasterMapper.FromMapper(mapper, new Matrix(4, 4, Double.NaN)));
            Assert.Throws <ArgumentException>(() => RasterMapper.FromMapper(mapper, new Matrix(4, 4)));
            Assert.Throws <ArgumentException>(() =>
            {
                Matrix matrix = new Matrix(4, 4);
                matrix[3, 0]  = matrix[3, 1] = matrix[3, 2] = matrix[3, 3] = 1;
                RasterMapper.FromMapper(mapper, matrix);
            });
            Assert.Throws <NotSupportedException>(() => RasterMapper.FromMapper(mapper, MatrixFactory.CreateDiagonal(0, 0, 0, 1)));
            Assert.Throws <ArgumentException>(() => RasterMapper.FromMapper(mapper, Coordinate.Undefined, new CoordinateVector(0, 1, 0)));
            Assert.Throws <ArgumentException>(() => RasterMapper.FromMapper(mapper, Coordinate.Empty, new CoordinateVector(Double.NaN, Double.NaN, Double.NaN)));
            Assert.Throws <ArgumentException>(() => RasterMapper.FromMapper(mapper, Coordinate.Empty, new CoordinateVector(0, 1, 0)));
            Assert.Throws <ArgumentException>(() => RasterMapper.FromMapper(mapper, Coordinate.Empty, new CoordinateVector(1, 0, 0)));
            Assert.Throws <ArgumentException>(() => RasterMapper.FromMapper(mapper, Double.NaN, 0, 0, 1, 0, 0));
            Assert.Throws <ArgumentException>(() => RasterMapper.FromMapper(mapper, 0, Double.NaN, 0, 1, 0, 0));
            Assert.Throws <ArgumentException>(() => RasterMapper.FromMapper(mapper, 0, 0, Double.NaN, 1, 0, 0));
            Assert.Throws <ArgumentException>(() => RasterMapper.FromMapper(mapper, 0, 0, 0, 1, 0, 0));
            Assert.Throws <ArgumentException>(() => RasterMapper.FromMapper(mapper, 0, 0, 0, 0, 1, 0));
            Assert.Throws <ArgumentException>(() => RasterMapper.FromMapper(mapper, 0, 0, 0, Double.NaN, 1, 0));
            Assert.Throws <ArgumentException>(() => RasterMapper.FromMapper(mapper, 0, 0, 0, 1, Double.NaN, 0));
            Assert.Throws <ArgumentException>(() => RasterMapper.FromMapper(mapper, 0, 0, 0, 1, 1, Double.NaN));
        }