Esempio n. 1
0
        private void ApplyWhiteBalance(MagickImage image)
        {
            using (var mask = image.Clone())
            {
                mask.ColorSpace = ColorSpace.HSB;
                mask.Negate(Channels.Green);

                using (var newMask = mask.Separate(Channels.Green).First())
                {
                    using (var maskBlue = mask.Separate(Channels.Blue).First())
                    {
                        newMask.Composite(maskBlue, CompositeOperator.Multiply);
                    }

                    newMask.ContrastStretch((Percentage)0, WhiteBalance);
                    newMask.InverseOpaque(new MagickColor("white"), new MagickColor("black"));

                    double maskMean = GetMean(newMask);

                    double redRatio   = GetRatio(image, Channels.Red, newMask, maskMean);
                    double greenRatio = GetRatio(image, Channels.Green, newMask, maskMean);
                    double blueRatio  = GetRatio(image, Channels.Blue, newMask, maskMean);

                    var matrix = new MagickColorMatrix(3, redRatio, 0, 0, 0, greenRatio, 0, 0, 0, blueRatio);

                    image.ColorMatrix(matrix);
                }
            }
        }
Esempio n. 2
0
        private static void SetColumn_InvalidColumn_ThrowsException(int x)
        {
            var matrix = new MagickColorMatrix(2);

            Assert.Throws <ArgumentOutOfRangeException>("x", () =>
            {
                matrix.SetColumn(x, 1.0, 2.0);
            });
        }
Esempio n. 3
0
        public void SetRow_InvalidNumberOfValues_ThrowsException()
        {
            var matrix = new MagickColorMatrix(2);

            Assert.Throws <ArgumentException>("values", () =>
            {
                matrix.SetRow(0, 1, 2, 3);
            });
        }
Esempio n. 4
0
        private static void SetRow_InvalidRow_ThrowsException(int y)
        {
            var matrix = new MagickColorMatrix(2);

            Assert.Throws <ArgumentOutOfRangeException>("y", () =>
            {
                matrix.SetRow(y, 1.0, 2.0);
            });
        }
Esempio n. 5
0
        private static void GetValue_InvalidIndex_ThrowsException(string paramName, int x, int y)
        {
            MagickColorMatrix matrix = new MagickColorMatrix(2);

            ExceptionAssert.ThrowsArgumentOutOfRangeException(paramName, () =>
            {
                matrix.GetValue(x, y);
            });
        }
Esempio n. 6
0
        private static void SetValue_InvalidIndex_ThrowsException(string paramName, int x, int y)
        {
            var matrix = new MagickColorMatrix(2);

            Assert.Throws <ArgumentOutOfRangeException>(paramName, () =>
            {
                matrix.SetValue(x, y, 1);
            });
        }
Esempio n. 7
0
        public void SetColumn_InvalidNumberOfValues_ThrowsException()
        {
            MagickColorMatrix matrix = new MagickColorMatrix(2);

            ExceptionAssert.ThrowsArgumentException("values", () =>
            {
                matrix.SetColumn(0, 1, 2, 3);
            });
        }
Esempio n. 8
0
        public void SetColumn_ValuesIsNull_ThrowsException()
        {
            MagickColorMatrix matrix = new MagickColorMatrix(2);

            ExceptionAssert.ThrowsArgumentNullException("values", () =>
            {
                matrix.SetColumn(0, null);
            });
        }
Esempio n. 9
0
        private static void Indexer_InvalidIndex_ThrowsException(string paramName, int x, int y)
        {
            var matrix = new MagickColorMatrix(2);

            Assert.Throws <ArgumentOutOfRangeException>(paramName, () =>
            {
                double foo = matrix[x, y];
            });
        }
Esempio n. 10
0
        public void SetRowValuesIsNull_ThrowsException()
        {
            var matrix = new MagickColorMatrix(2);

            Assert.Throws <ArgumentNullException>("values", () =>
            {
                matrix.SetRow(0, null);
            });
        }
Esempio n. 11
0
        public void SetRow_CorrectNumberOfValues_SetsColumn()
        {
            var matrix = new MagickColorMatrix(2);

            matrix.SetRow(1, 6, 8);
            Assert.Equal(0, matrix.GetValue(0, 0));
            Assert.Equal(6, matrix.GetValue(0, 1));
            Assert.Equal(0, matrix.GetValue(1, 0));
            Assert.Equal(8, matrix.GetValue(1, 1));
        }
Esempio n. 12
0
        public void Constructor_ValidOrder_PropertiesAreSet()
        {
            var matrix = new MagickColorMatrix(2, 0.0, 1.0, 0.1, 1.1);

            Assert.Equal(2, matrix.Order);
            Assert.Equal(0.0, matrix.GetValue(0, 0));
            Assert.Equal(1.0, matrix.GetValue(1, 0));
            Assert.Equal(0.1, matrix.GetValue(0, 1));
            Assert.Equal(1.1, matrix.GetValue(1, 1));
        }
Esempio n. 13
0
        public void Test_Value()
        {
            MagickColorMatrix matrix = new MagickColorMatrix(2);

            matrix.SetValue(0, 0, 1.5);
            Assert.AreEqual(1.5, matrix.GetValue(0, 0));

            Assert.AreEqual(0.0, matrix.GetValue(0, 1));
            Assert.AreEqual(0.0, matrix.GetValue(1, 0));
        }
Esempio n. 14
0
        public void SetValue_ValidIndex_SetsValue()
        {
            var matrix = new MagickColorMatrix(2);

            matrix.SetValue(1, 0, 1.5);

            Assert.Equal(0.0, matrix.GetValue(0, 0));
            Assert.Equal(0.0, matrix.GetValue(0, 1));
            Assert.Equal(1.5, matrix.GetValue(1, 0));
            Assert.Equal(0.0, matrix.GetValue(1, 1));
        }
Esempio n. 15
0
        public void Test_SetRow()
        {
            MagickColorMatrix matrix = new MagickColorMatrix(2);

            matrix.SetRow(0, 2, 4);
            Assert.AreEqual(2, matrix.GetValue(0, 0));
            Assert.AreEqual(4, matrix.GetValue(1, 0));

            matrix.SetRow(1, 6, 8);
            Assert.AreEqual(6, matrix.GetValue(0, 1));
            Assert.AreEqual(8, matrix.GetValue(1, 1));
        }
Esempio n. 16
0
        private MagickImage GetImage()
        {
            MagickImage image = new MagickImage(RawData);

            image.ColorSpace = ColorSpace.sRGB;
            MagickColorMatrix matrix = new MagickColorMatrix(3);

            matrix.SetRow(0, 0, 0, 1);
            matrix.SetRow(1, 0, 1, 0);
            matrix.SetRow(2, 1, 0, 0);
            image.ColorMatrix(matrix);
            return(image);
        }
Esempio n. 17
0
 public override byte[] ToArray()
 {
     using (MagickImage image = new MagickImage(data))
     {
         if (image.ColorSpace != ColorSpace.sRGB)
         {
             image.ColorSpace = ColorSpace.sRGB;
         }
         MagickColorMatrix matrix = new MagickColorMatrix(3);
         matrix.SetRow(0, 0, 0, 1);
         matrix.SetRow(1, 0, 1, 0);
         matrix.SetRow(2, 1, 0, 0);
         image.ColorMatrix(matrix);
         return(image.ToByteArray());
     }
 }
Esempio n. 18
0
        public void Test_Constructor()
        {
            ExceptionAssert.Throws <ArgumentException>(delegate()
            {
                new MagickColorMatrix(-1);
            });

            ExceptionAssert.Throws <ArgumentException>(delegate()
            {
                new MagickColorMatrix(7);
            });

            new MagickColorMatrix(1);

            ExceptionAssert.Throws <ArgumentException>(delegate()
            {
                new MagickColorMatrix(2, 1.0);
            });

            MagickColorMatrix matrix = new MagickColorMatrix(2, 0.0, 1.0, 0.1, 1.1);

            Assert.AreEqual(0.0, matrix.GetValue(0, 0));
            Assert.AreEqual(1.0, matrix.GetValue(1, 0));
            Assert.AreEqual(0.1, matrix.GetValue(0, 1));
            Assert.AreEqual(1.1, matrix.GetValue(1, 1));

            ExceptionAssert.Throws <ArgumentOutOfRangeException>(delegate()
            {
                matrix.GetValue(2, 1);
            });

            ExceptionAssert.Throws <ArgumentOutOfRangeException>(delegate()
            {
                matrix.GetValue(1, 2);
            });

            ExceptionAssert.Throws <ArgumentOutOfRangeException>(delegate()
            {
                matrix.GetValue(1, -1);
            });

            ExceptionAssert.Throws <ArgumentOutOfRangeException>(delegate()
            {
                matrix.GetValue(-1, 1);
            });
        }
Esempio n. 19
0
        public void Indexer_ValidIndex_ReturnValue()
        {
            var matrix = new MagickColorMatrix(1, 8);

            Assert.Equal(8, matrix[0, 0]);
        }
Esempio n. 20
0
        public void GetValue_ValidIndex_ReturnValue()
        {
            var matrix = new MagickColorMatrix(1, 4);

            Assert.Equal(4, matrix.GetValue(0, 0));
        }
Esempio n. 21
0
        public void ToArray_ReturnsArray()
        {
            MagickColorMatrix matrix = new MagickColorMatrix(1, 6);

            CollectionAssert.AreEqual(new double[] { 6 }, matrix.ToArray());
        }
Esempio n. 22
0
        public void ToArray_ReturnsArray()
        {
            var matrix = new MagickColorMatrix(1, 6);

            Assert.Equal(new double[] { 6 }, matrix.ToArray());
        }