Exemple #1
0
        public void Addition()
        {
            var first = new Matrix5x5(
                1, 2, 3, 4, 6,
                6, 1, 5, 3, 8,
                2, 6, 4, 9, 9,
                1, 3, 8, 3, 4,
                5, 7, 8, 2, 5
                );
            var second = new Matrix5x5(
                3, 5, 0, 8, 7,
                2, 2, 4, 8, 3,
                0, 2, 5, 1, 2,
                1, 4, 0, 5, 1,
                3, 4, 8, 2, 3
                );
            var result = new Matrix5x5(
                4, 7, 3, 12, 13,
                8, 3, 9, 11, 11,
                2, 8, 9, 10, 11,
                2, 7, 8, 8, 5,
                8, 11, 16, 4, 8
                );

            Assert.Equal(result, first + second);
        }
Exemple #2
0
        public void Multiplication()
        {
            var first = new Matrix5x5(
                1, 2, 3, 4, 6,
                6, 1, 5, 3, 8,
                2, 6, 4, 9, 9,
                1, 3, 8, 3, 4,
                5, 7, 8, 2, 5
                );
            var second = new Matrix5x5(
                3, 5, 0, 8, 7,
                2, 2, 4, 8, 3,
                0, 2, 5, 1, 2,
                1, 4, 0, 5, 1,
                3, 4, 8, 2, 3
                );
            var result = new Matrix5x5(
                29, 55, 71, 59, 41,
                47, 86, 93, 92, 82,
                54, 102, 116, 131, 76,
                24, 55, 84, 63, 47,
                46, 83, 108, 124, 89
                );

            Assert.Equal(result, first * second);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="Alpha"/> class.
        /// </summary>
        /// <param name="value">The angle value (0 to 360).</param>
        public Hue(float value)
        {
            value = value * (float)(Math.PI / 180f);
            Value = value;
            var cosradians = Math.Cos(value);
            var sinradians = Math.Sin(value);

            float lumR = .213f;
            float lumG = .715f;
            float lumB = .072f;

            float oneMinusLumR = 1f - lumR;
            float oneMinusLumG = 1f - lumG;
            float oneMinusLumB = 1f - lumB;

            _Matrix = new Matrix5x5
            {
                M11 = (float)(lumR + (cosradians * oneMinusLumR) - (sinradians * lumR)),
                M12 = (float)(lumR - (cosradians * lumR) - (sinradians * 0.143)),
                M13 = (float)(lumR - (cosradians * lumR) - (sinradians * oneMinusLumR)),
                M21 = (float)(lumG - (cosradians * lumG) - (sinradians * lumG)),
                M22 = (float)(lumG + (cosradians * oneMinusLumG) + (sinradians * 0.140)),
                M23 = (float)(lumG - (cosradians * lumG) + (sinradians * lumG)),
                M31 = (float)(lumB - (cosradians * lumB) + (sinradians * oneMinusLumB)),
                M32 = (float)(lumB - (cosradians * lumB) - (sinradians * 0.283)),
                M33 = (float)(lumB + (cosradians * oneMinusLumB) + (sinradians * lumB)),
                M44 = 1,
                M55 = 1
            };
        }
Exemple #4
0
        public void Minus()
        {
            var first = new Matrix5x5(
                1, 2, 3, 4, 6,
                6, 1, 5, 3, 8,
                2, 6, 4, 9, 9,
                1, 3, 8, 3, 4,
                5, 7, 8, 2, 5
                );
            var second = new Matrix5x5(
                3, 5, 0, 8, 7,
                2, 2, 4, 8, 3,
                0, 2, 5, 1, 2,
                1, 4, 0, 5, 1,
                3, 4, 8, 2, 3
                );
            var result = new Matrix5x5(
                -2, -3, 3, -4, -1,
                4, -1, 1, -5, 5,
                2, 4, -1, 8, 7,
                0, -1, 8, -2, 3,
                2, 3, 0, 0, 2
                );

            Assert.Equal(result, first - second);
        }
Exemple #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Brightness"/> class.
 /// </summary>
 /// <param name="value">The brightness value (-1 to 1).</param>
 public Brightness(float value)
 {
     Value   = value;
     _Matrix = new Matrix5x5
               (
         1f, 0f, 0f, 0f, 0f,
         0f, 1f, 0f, 0f, 0f,
         0f, 0f, 1f, 0f, 0f,
         0f, 0f, 0f, 1f, 0f,
         value, value, value, 0f, 1f
               );
 }
Exemple #6
0
        public void IsIdentity()
        {
            var value = new Matrix5x5(
                1, 0, 0, 0, 0,
                0, 1, 0, 0, 0,
                0, 0, 1, 0, 0,
                0, 0, 0, 1, 0,
                0, 0, 0, 0, 1
                );

            Assert.Equal(Matrix5x5.Identity, value);
        }
Exemple #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Alpha"/> class.
 /// </summary>
 /// <param name="value">The alpha value (0 to 1).</param>
 public Alpha(float value)
 {
     Value   = value;
     _Matrix = new Matrix5x5
               (
         1f, 0f, 0f, 0f, 0f,
         0f, 1f, 0f, 0f, 0f,
         0f, 0f, 1f, 0f, 0f,
         0f, 0f, 0f, value, 0f,
         0f, 0f, 0f, 0f, 1f
               );
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="Contrast"/> class.
        /// </summary>
        /// <param name="value">The Contrast value (0 to 1).</param>
        public Contrast(float value)
        {
            Value = value;
            float TempValue = 0.5f * (1f - value);

            _Matrix = new Matrix5x5
                      (
                value, 0f, 0f, 0f, 0f,
                0f, value, 0f, 0f, 0f,
                0f, 0f, value, 0f, 0f,
                0f, 0f, 0f, 1f, 0f,
                TempValue, TempValue, TempValue, 0f, 1f
                      );
        }
Exemple #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Saturation"/> class.
        /// </summary>
        /// <param name="value">The saturation value (-1 to 1).</param>
        public Saturation(float value)
        {
            ++value;
            Value = 1f - value;
            float saturationComplementR = 0.3086f * Value;
            float saturationComplementG = 0.6094f * Value;
            float saturationComplementB = 0.0820f * Value;

            _Matrix = new Matrix5x5
                      (
                saturationComplementR + value, saturationComplementR, saturationComplementR, 0f, 0f,
                saturationComplementG, saturationComplementG + value, saturationComplementG, 0f, 0f,
                saturationComplementB, saturationComplementB, saturationComplementB + value, 0f, 0f,
                0f, 0f, 0f, 1f, 0f,
                0f, 0f, 0f, 0f, 1f
                      );
        }
Exemple #10
0
        public void AreNotEqual()
        {
            var first = new Matrix5x5(
                1, 0, 0, 0, 0,
                0, 1, 0, 0, 0,
                0, 0, 1, 0, 0,
                0, 0, 0, 1, 0,
                0, 0, 0, 0, 1
                );
            var second = new Matrix5x5(
                1, 0, 0, 0, 1,
                0, 1, 0, 0, 0,
                0, 0, 1, 0, 0,
                0, 0, 0, 1, 0,
                0, 0, 0, 0, 1
                );

            Assert.NotEqual(first, second);
        }
Exemple #11
0
        public void Negation()
        {
            var first = new Matrix5x5(
                1, 2, 3, 4, 6,
                6, 1, 5, 3, 8,
                2, 6, 4, 9, 9,
                1, 3, 8, 3, 4,
                5, 7, 8, 2, 5
                );
            var result = new Matrix5x5(
                -1, -2, -3, -4, -6,
                -6, -1, -5, -3, -8,
                -2, -6, -4, -9, -9,
                -1, -3, -8, -3, -4,
                -5, -7, -8, -2, -5
                );

            Assert.Equal(result, -first);
        }
Exemple #12
0
        public void MultiplicationFloat()
        {
            var first = new Matrix5x5(
                1, 2, 3, 4, 6,
                6, 1, 5, 3, 8,
                2, 6, 4, 9, 9,
                1, 3, 8, 3, 4,
                5, 7, 8, 2, 5
                );
            float value  = 2;
            var   result = new Matrix5x5(
                2, 4, 6, 8, 12,
                12, 2, 10, 6, 16,
                4, 12, 8, 18, 18,
                2, 6, 16, 6, 8,
                10, 14, 16, 4, 10
                );

            Assert.Equal(result, first * value);
        }
Exemple #13
0
        public void ConstructorAssignsProperties()
        {
            var value = new Matrix5x5(
                1, 0, 0, 0, 0,
                0, 1, 0, 0, 0,
                0, 0, 1, 0, 0,
                0, 0, 0, 1, 0,
                0, 0, 0, 0, 1
                );

            Assert.Equal(1, value.M11);
            Assert.Equal(1, value.M22);
            Assert.Equal(1, value.M33);
            Assert.Equal(1, value.M44);
            Assert.Equal(1, value.M55);
            Assert.Equal(0, value.M12);
            Assert.Equal(0, value.M13);
            Assert.Equal(0, value.M14);
            Assert.Equal(0, value.M15);
            Assert.Equal(0, value.M21);
            Assert.Equal(0, value.M23);
            Assert.Equal(0, value.M24);
            Assert.Equal(0, value.M25);
            Assert.Equal(0, value.M31);
            Assert.Equal(0, value.M32);
            Assert.Equal(0, value.M34);
            Assert.Equal(0, value.M35);
            Assert.Equal(0, value.M41);
            Assert.Equal(0, value.M42);
            Assert.Equal(0, value.M43);
            Assert.Equal(0, value.M45);
            Assert.Equal(0, value.M51);
            Assert.Equal(0, value.M52);
            Assert.Equal(0, value.M53);
            Assert.Equal(0, value.M54);
        }
Exemple #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ColorMatrix"/> class.
 /// </summary>
 /// <param name="matrix">The matrix.</param>
 public ColorMatrix(Matrix5x5 matrix)
 {
     _Matrix = matrix;
 }