public void ShouldReturnErrorInfoWhenMeasureErrorsIsTrue()
            {
                using (IMagickImageCollection collection = new MagickImageCollection())
                {
                    collection.Add(Files.FujiFilmFinePixS1ProJPG);

                    QuantizeSettings settings = new QuantizeSettings
                    {
                        Colors        = 3,
                        MeasureErrors = true,
                    };

                    MagickErrorInfo errorInfo = collection.Quantize(settings);
                    Assert.IsNotNull(errorInfo);

#if Q8
                    Assert.AreEqual(13.47, errorInfo.MeanErrorPerPixel, 0.01);
                    Assert.AreEqual(0.47, errorInfo.NormalizedMaximumError, 0.01);
                    Assert.AreEqual(0.006, errorInfo.NormalizedMeanError, 0.001);
#elif Q16 || Q16HDRI
                    Assert.AreEqual(3505, errorInfo.MeanErrorPerPixel, 1);
                    Assert.AreEqual(0.47, errorInfo.NormalizedMaximumError, 0.01);
                    Assert.AreEqual(0.006, errorInfo.NormalizedMeanError, 0.001);
#else
#error Not implemented!
#endif
                }
            }
        public void Test_Quantize()
        {
            using (IMagickImageCollection collection = new MagickImageCollection())
            {
                ExceptionAssert.Throws <InvalidOperationException>(delegate()
                {
                    collection.Quantize();
                });

                collection.Add(Files.FujiFilmFinePixS1ProJPG);

                ExceptionAssert.Throws <ArgumentNullException>(delegate()
                {
                    collection.Quantize(null);
                });

                QuantizeSettings settings = new QuantizeSettings();
                settings.Colors = 3;

                MagickErrorInfo errorInfo = collection.Quantize(settings);
                Assert.IsNull(errorInfo);

#if Q8
                ColorAssert.AreEqual(new MagickColor("#2b414f"), collection[0], 66, 115);
                ColorAssert.AreEqual(new MagickColor("#7b929f"), collection[0], 179, 123);
                ColorAssert.AreEqual(new MagickColor("#44739f"), collection[0], 188, 135);
#elif Q16 || Q16HDRI
                ColorAssert.AreEqual(new MagickColor("#447073169f39"), collection[0], 66, 115);
                ColorAssert.AreEqual(new MagickColor("#7b4292c29f25"), collection[0], 179, 123);
                ColorAssert.AreEqual(new MagickColor("#2aef41654efc"), collection[0], 188, 135);
#else
#error Not implemented!
#endif
            }
        }
Example #3
0
        public void CompareImages([CallerMemberName] string testName = "")
        {
            string          expectedPath = Path.Combine(testDirectory, testName + ".expected.png");
            string          actualPath   = Path.Combine(testDirectory, testName + ".wpf.out.png");
            MagickImage     expected     = new MagickImage(expectedPath);
            MagickImage     actual       = new MagickImage(actualPath);
            MagickErrorInfo error        = expected.Compare(actual);

            Assert.IsNull(error);
        }
Example #4
0
            public void ShouldReturnEmptyErrorInfoWhenTheImagesAreEqual()
            {
                using (IMagickImage image = new MagickImage(Files.Builtin.Logo))
                {
                    using (IMagickImage other = new MagickImage(Files.Builtin.Logo))
                    {
                        MagickErrorInfo errorInfo = image.Compare(other);

                        Assert.AreEqual(0, errorInfo.MeanErrorPerPixel);
                        Assert.AreEqual(0, errorInfo.NormalizedMaximumError);
                        Assert.AreEqual(0, errorInfo.NormalizedMeanError);
                    }
                }
            }
Example #5
0
            public void ShouldReturnNullWhenMeasureErrorsIsFalse()
            {
                using (IMagickImageCollection images = new MagickImageCollection())
                {
                    images.Add(Files.FujiFilmFinePixS1ProJPG);

                    QuantizeSettings settings = new QuantizeSettings
                    {
                        Colors        = 1,
                        MeasureErrors = false,
                    };

                    MagickErrorInfo errorInfo = images.Quantize(settings);
                    Assert.IsNull(errorInfo);
                }
            }
        public void Quantize_MeasureErrorsIsFalse_ReturnsNull()
        {
            using (IMagickImageCollection collection = new MagickImageCollection())
            {
                collection.Add(Files.FujiFilmFinePixS1ProJPG);

                QuantizeSettings settings = new QuantizeSettings
                {
                    Colors        = 1,
                    MeasureErrors = false,
                };

                MagickErrorInfo errorInfo = collection.Quantize(settings);
                Assert.IsNull(errorInfo);
            }
        }
Example #7
0
        protected void CompareImages([CallerMemberName] string testName = "")
        {
            string          expectedPath = Path.Combine(this.OutputPath, testName + ".expected.png");
            string          actualPath   = Path.Combine(this.OutputPath, testName + ".out.png");
            MagickImage     expected     = new MagickImage(expectedPath);
            MagickImage     actual       = new MagickImage(actualPath);
            MagickErrorInfo error        = expected.Compare(actual);

            if (error.NormalizedMaximumError > 0.1)
            {
                if (error.NormalizedMaximumError > 0.15)
                {
                    Assert.Fail("NormalizedMaximumError = " + error.NormalizedMaximumError);
                }
                else
                {
                    Assert.Inconclusive("Close but no cigar. NormalizedMaximumError = " + error.NormalizedMaximumError);
                }
            }
        }
Example #8
0
            public void ShouldReturnErrorInfoWhenTheImagesAreNotEqual()
            {
                using (IMagickImage image = new MagickImage(Files.Builtin.Logo))
                {
                    using (IMagickImage other = new MagickImage(Files.Builtin.Logo))
                    {
                        other.Rotate(180);

                        MagickErrorInfo errorInfo = image.Compare(other);

#if Q8
                        Assert.AreEqual(44.55, errorInfo.MeanErrorPerPixel, 0.01);
#elif Q16 || Q16HDRI
                        Assert.AreEqual(11450.85, errorInfo.MeanErrorPerPixel, 0.01);
#else
#error Not implemented!
#endif
                        Assert.AreEqual(1, errorInfo.NormalizedMaximumError);
                        Assert.AreEqual(0.13, errorInfo.NormalizedMeanError, 0.01);
                    }
                }
            }