Esempio n. 1
0
        /// <summary>
        /// Create a hue filter matrix using the given angle in degrees.
        /// </summary>
        /// <param name="degrees">The angle of rotation in degrees.</param>
        /// <returns>The <see cref="Matrix4x4"/></returns>
        public static Matrix4x4 CreateHueFilter(float degrees)
        {
            // Wrap the angle round at 360.
            degrees %= 360;

            // Make sure it's not negative.
            while (degrees < 0)
            {
                degrees += 360;
            }

            float radian    = MathFExtensions.DegreeToRadian(degrees);
            float cosRadian = MathF.Cos(radian);
            float sinRadian = MathF.Sin(radian);

            // The matrix is set up to preserve the luminance of the image.
            // See http://graficaobscura.com/matrix/index.html
            // Number are taken from https://msdn.microsoft.com/en-us/library/jj192162(v=vs.85).aspx
            return(new Matrix4x4
            {
                M11 = .213F + (cosRadian * .787F) - (sinRadian * .213F),
                M12 = .213F - (cosRadian * .213F) - (sinRadian * 0.143F),
                M13 = .213F - (cosRadian * .213F) - (sinRadian * .787F),
                M21 = .715F - (cosRadian * .715F) - (sinRadian * .715F),
                M22 = .715F + (cosRadian * .285F) + (sinRadian * 0.140F),
                M23 = .715F - (cosRadian * .715F) + (sinRadian * .715F),
                M31 = .072F - (cosRadian * .072F) + (sinRadian * .928F),
                M32 = .072F - (cosRadian * .072F) - (sinRadian * 0.283F),
                M33 = .072F + (cosRadian * .928F) + (sinRadian * .072F),
                M44 = 1
            });
        }
        public CieLuv Convert(CieLchuv input)
        {
            // Conversion algorithm described here:
            // https://en.wikipedia.org/wiki/CIELUV#Cylindrical_representation_.28CIELCH.29
            float l = input.L, c = input.C, hDegrees = input.H;
            float hRadians = MathFExtensions.DegreeToRadian(hDegrees);

            float u = c * MathF.Cos(hRadians);
            float v = c * MathF.Sin(hRadians);

            return(new CieLuv(l, u, v, input.WhitePoint));
        }
Esempio n. 3
0
        public CieLab Convert(CieLch input)
        {
            // Conversion algorithm described here:
            // https://en.wikipedia.org/wiki/Lab_color_space#Cylindrical_representation:_CIELCh_or_CIEHLC
            float l = input.L, c = input.C, hDegrees = input.H;
            float hRadians = MathFExtensions.DegreeToRadian(hDegrees);

            float a = c * MathF.Cos(hRadians);
            float b = c * MathF.Sin(hRadians);

            return(new CieLab(l, a, b, input.WhitePoint));
        }
Esempio n. 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HueProcessor{TPixel}"/> class.
        /// </summary>
        /// <param name="angle">The new brightness of the image. Must be between -100 and 100.</param>
        public HueProcessor(float angle)
        {
            // Wrap the angle round at 360.
            angle = angle % 360;

            // Make sure it's not negative.
            while (angle < 0)
            {
                angle += 360;
            }

            this.Angle = angle;

            float radians    = MathFExtensions.DegreeToRadian(angle);
            float cosradians = MathF.Cos(radians);
            float sinradians = MathF.Sin(radians);

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

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

            // The matrix is set up to preserve the luminance of the image.
            // See http://graficaobscura.com/matrix/index.html
            // Number are taken from https://msdn.microsoft.com/en-us/library/jj192162(v=vs.85).aspx
            var matrix4X4 = new Matrix4x4
            {
                M11 = lumR + (cosradians * oneMinusLumR) - (sinradians * lumR),
                M12 = lumR - (cosradians * lumR) - (sinradians * 0.143F),
                M13 = lumR - (cosradians * lumR) - (sinradians * oneMinusLumR),
                M21 = lumG - (cosradians * lumG) - (sinradians * lumG),
                M22 = lumG + (cosradians * oneMinusLumG) + (sinradians * 0.140F),
                M23 = lumG - (cosradians * lumG) + (sinradians * lumG),
                M31 = lumB - (cosradians * lumB) + (sinradians * oneMinusLumB),
                M32 = lumB - (cosradians * lumB) - (sinradians * 0.283F),
                M33 = lumB + (cosradians * oneMinusLumB) + (sinradians * lumB),
                M44 = 1
            };

            this.Matrix = matrix4X4;
        }
Esempio n. 5
0
 /// <summary>
 /// Creates a rotation matrix using the given rotation in degrees and a center point.
 /// </summary>
 /// <param name="degrees">The amount of rotation, in degrees.</param>
 /// <param name="centerPoint">The center point.</param>
 /// <returns>A rotation matrix.</returns>
 public static Matrix3x2 CreateRotationDegrees(float degrees, PointF centerPoint) => Matrix3x2.CreateRotation(MathFExtensions.DegreeToRadian(degrees), centerPoint);
Esempio n. 6
0
 /// <summary>
 /// Creates a rotation matrix using the given rotation in degrees.
 /// </summary>
 /// <param name="degrees">The amount of rotation, in degrees.</param>
 /// <returns>A rotation matrix.</returns>
 public static Matrix3x2 CreateRotationDegrees(float degrees) => Matrix3x2.CreateRotation(MathFExtensions.DegreeToRadian(degrees));
Esempio n. 7
0
 /// <summary>
 /// Creates a skew matrix from the given angles in degrees and a center point.
 /// </summary>
 /// <param name="degreesX">The X angle, in degrees.</param>
 /// <param name="degreesY">The Y angle, in degrees.</param>
 /// <param name="centerPoint">The center point.</param>
 /// <returns>A skew matrix.</returns>
 public static Matrix3x2 CreateSkewDegrees(float degreesX, float degreesY, PointF centerPoint) => Matrix3x2.CreateSkew(MathFExtensions.DegreeToRadian(degreesX), MathFExtensions.DegreeToRadian(degreesY), centerPoint);
Esempio n. 8
0
 /// <summary>
 /// Creates a skew matrix from the given angles in degrees.
 /// </summary>
 /// <param name="degreesX">The X angle, in degrees.</param>
 /// <param name="degreesY">The Y angle, in degrees.</param>
 /// <returns>A skew matrix.</returns>
 public static Matrix3x2 CreateSkewDegrees(float degreesX, float degreesY) => Matrix3x2.CreateSkew(MathFExtensions.DegreeToRadian(degreesX), MathFExtensions.DegreeToRadian(degreesY));
Esempio n. 9
0
 public void Convert_Degree_To_Radian()
 {
     Assert.Equal((float)(Math.PI / 2D), MathFExtensions.DegreeToRadian(90F), new FloatRoundingComparer(6));
 }