Example #1
0
        private static void AssertDefaults(UnperspectiveScript script, UnperspectiveMethod method)
        {
            Assert.AreEqual(null, script.AspectRatio);
            Assert.AreEqual(0, script.BorderColorLocation.X);
            Assert.AreEqual(0, script.BorderColorLocation.Y);
            Assert.AreEqual(0, script.Blur);
            Assert.AreEqual(UnperspectiveDefault.EdgeLength, script.Default);
            Assert.AreEqual(false, script.DisableViewportCrop);
            Assert.AreEqual(null, script.Height);
            Assert.AreEqual(10, script.MinLength);
            Assert.AreEqual(40, script.MaxPeaks);
            Assert.AreEqual(null, script.Rotation);
            Assert.AreEqual(null, script.Width);

            if (method == UnperspectiveMethod.Peak)
            {
                Assert.AreEqual(5.0, script.Sharpen);
                Assert.AreEqual(1.0, script.Smooth);
                Assert.AreEqual(4, script.Threshold);
            }
            else
            {
                Assert.AreEqual(0.0, script.Sharpen);
                Assert.AreEqual(5.0, script.Smooth);
                Assert.AreEqual(10, script.Threshold);
            }
        }
Example #2
0
 public void Execute_InputNull_ThrowsException()
 {
     ExceptionAssert.ThrowsArgumentException <ArgumentNullException>("input", () =>
     {
         var script = new UnperspectiveScript();
         script.Execute(null);
     });
 }
Example #3
0
        public void PerceptibleReciprocal_NegativeNan_ReturnsPositiveInfinity()
        {
            var script = new UnperspectiveScript();

            Type       type   = script.GetType();
            MethodInfo method = type.GetMethod("PerceptibleReciprocal", BindingFlags.Static | BindingFlags.NonPublic);

            var result = method.Invoke(null, new object[] { -double.NaN });

            Assert.AreEqual(result, double.PositiveInfinity);
        }
Example #4
0
        private static void GetRotation_Geometry10x10_ReturnsCorrectRotation(int x, int y, UnperspectiveRotation expectedRotation)
        {
            var script = new UnperspectiveScript();

            Type       type   = script.GetType();
            MethodInfo method = type.GetMethod("GetRotation", BindingFlags.Instance | BindingFlags.NonPublic);

            using (MagickImage image = new MagickImage(MagickColors.Fuchsia, 10, 10))
            {
                var result = method.Invoke(script, new object[] { new PointD[] { new PointD(x, y) }, image });
                Assert.AreEqual(expectedRotation, result);
            }
        }
Example #5
0
        private static void AssertInvalidOperation(string expectedMessage, UnperspectiveMethod method, Action <UnperspectiveScript> initAction)
        {
            var script = new UnperspectiveScript(method);

            using (var logo = new MagickImage(Images.Logo))
            {
                initAction(script);

                ExceptionAssert.Throws <InvalidOperationException>(expectedMessage, () =>
                {
                    script.Execute(logo);
                });
            }
        }
Example #6
0
        public void BorderColorLocation_AfterBottomRight_ThrowsException()
        {
            var script = new UnperspectiveScript();

            using (var logo = new MagickImage(Images.Logo))
            {
                script.BorderColorLocation = new PointD(logo.Width, logo.Height);

                // TODO: Fix this after the next release of Magick.NET
                // ExceptionAssert.ThrowsArgumentException<ArgumentOutOfRangeException>("x", "Invalid X coordinate: " + logo.Width, () =>
                ExceptionAssert.Throws <ArgumentOutOfRangeException>(() =>
                {
                    script.Execute(logo);
                });
            }
        }
Example #7
0
        public void BorderColorLocation_BeforeLeftTop_ThrowsException()
        {
            var script = new UnperspectiveScript();

            using (var logo = new MagickImage(Images.Logo))
            {
                script.BorderColorLocation = new PointD(-1, -1);

                // TODO: Fix this after the next release of Magick.NET
                // ExceptionAssert.ThrowsArgumentException<ArgumentOutOfRangeException>("x", "Invalid X coordinate: -1", () =>
                ExceptionAssert.Throws <ArgumentOutOfRangeException>(() =>
                {
                    script.Execute(logo);
                });
            }
        }
Example #8
0
        private void AssertExecute(string input, string methodName, UnperspectiveMethod method, Action <UnperspectiveScript> action)
        {
            var inputFile = GetInputFile(input);

            /* LosslessCompress(input); */

            using (var image = new MagickImage(inputFile))
            {
                var script = new UnperspectiveScript(method);
                action(script);

                using (var scriptOutput = script.Execute(image))
                {
                    string outputFile = GetOutputFile(inputFile, methodName);
                    AssertOutput(scriptOutput, outputFile);
                }
            }
        }
Example #9
0
        private static void AssertMinLength(int rotation, int minLength)
        {
            var script = new UnperspectiveScript();

            script.MinLength = minLength;

            var inputFile = GetInputFile("monet2_p30_t30_r30_out.jpg");

            using (var image = new MagickImage(inputFile))
            {
                image.Rotate(rotation);

                ExceptionAssert.Throws <InvalidOperationException>("Unable to continue, the edge length is less than 40.", () =>
                {
                    script.Execute(image);
                });
            }
        }
Example #10
0
        private static void GetCoefficients_UnsolvableMatrix_ThrowsException(double[] arguments)
        {
            var script = new UnperspectiveScript();

            Type       type   = script.GetType();
            MethodInfo method = type.GetMethod("GetCoefficients", BindingFlags.Static | BindingFlags.NonPublic, null, new Type[] { typeof(double[]) }, null);

            ExceptionAssert.Throws <InvalidOperationException>("Unsolvable matrix detected.", () =>
            {
                try
                {
                    method.Invoke(null, new object[] { arguments });
                }
                catch (TargetInvocationException ex)
                {
                    throw ex.InnerException;
                }
            });
        }
Example #11
0
        private static MagickGeometry GetDimensions(UnperspectiveDefault value)
        {
            var script = new UnperspectiveScript();

            script.AspectRatio = 1.5;
            script.Default     = value;

            Type       type   = script.GetType();
            MethodInfo method = type.GetMethod("GetDimensions", BindingFlags.Instance | BindingFlags.NonPublic);

            PointD[] corners = new PointD[4]
            {
                new PointD(0, 0),
                new PointD(300, 600),
                new PointD(10, 10),
                new PointD(290, 490)
            };
            MagickGeometry inputDimensions   = new MagickGeometry(1000, 1000);
            MagickGeometry trimmedDimensions = new MagickGeometry(800, 800);

            return((MagickGeometry)method.Invoke(script, new object[] { null, corners, inputDimensions, trimmedDimensions }));
        }
Example #12
0
        private static void Reset_AllSettingsChanged_RestoredToDefault(UnperspectiveMethod method)
        {
            var script = new UnperspectiveScript(method);

            script.AspectRatio         = 1.5;
            script.BorderColorLocation = new PointD(10, 10);
            script.Blur                = 15.0;
            script.ColorFuzz           = (Percentage)5.0;
            script.Default             = UnperspectiveDefault.BoundingBoxWidth;
            script.DisableViewportCrop = true;
            script.Height              = 140;
            script.MaxPeaks            = 25;
            script.MinLength           = 5;
            script.Rotation            = UnperspectiveRotation.Rotate180;
            script.Sharpen             = 8.5;
            script.Smooth              = 2.0;
            script.Threshold           = 5;
            script.Width               = 50;

            script.Reset();

            AssertDefaults(script, method);
        }
Example #13
0
        private static void Constructor_SettingsSetToDefaults(UnperspectiveMethod method)
        {
            var script = new UnperspectiveScript(method);

            AssertDefaults(script, method);
        }