Esempio n. 1
0
    void Process()
    {
        reg = new List <Region>();
        li  = new PixelCollection();
        int    numcolor = 2;
        Region r = new Region(2);
        int    i, j;

        for (i = 0; i < wi; i++)
        {
            AddToQueue(i, 0, 2);
            AddToQueue(i, he - 1, 2);
        }
        for (i = 0; i < he; i++)
        {
            AddToQueue(0, i, 2);
            AddToQueue(wi - 1, i, 2);
        }
        ProcessQueue(r);
        for (i = 0; i < wi; i++)
        {
            for (j = 0; j < he; j++)
            {
                if (mask[i, j] == 0)
                {
                    numcolor++;
                    r = new Region(numcolor);
                    AddToQueue(i, j, numcolor);
                    ProcessQueue(r);
                }
            }
        }
    }
Esempio n. 2
0
 public void makeTextHandler(object sender, DoWorkEventArgs e)
 {
     using (MagickImage image = new MagickImage(path.Text))
     {
         PixelCollection pc         = image.GetPixels();
         int             pixelsMade = 0;
         int             pixelWidth = image.Width;
         foreach (Pixel pixel in pc)
         {
             Color color = pixel.ToColor().ToColor();
             if (pcd.Contains(color)) //could possibly not work because not same obj
             {
                 try
                 {
                     int index = pcd.FindIndex(a => a == color);
                     makeText.ReportProgress(0, hexList[index]);
                     //output.Text += hexList[index];
                 }
                 catch (Exception ex) { }
             }
             pixelsMade++;
             if (pixelsMade % pixelWidth == 0)
             {
                 makeText.ReportProgress(0, "\n");
                 //output.Text += "\n";
             }
         }
     }
 }
Esempio n. 3
0
 protected void RandomlyBindPixelsIntoPairs(PixelCollection pixelCollection, int pixelsToSelect)
 {
     lock (pixelCollection)
     {
         pixelCollection.OrderByPoints();
         _pixelPairs = new List <PixelPair>();
         var alreadySelectedPixelsIds = new List <int>();
         var randomGenerator          = new Random();
         for (int index = 0; index <= pixelsToSelect - 1; index++)
         {
             if (!alreadySelectedPixelsIds.Contains(index))
             {
                 alreadySelectedPixelsIds.Add(index);
                 int newIndex = randomGenerator.Next(index + 1, pixelsToSelect);
                 while (alreadySelectedPixelsIds.Contains(newIndex))
                 {
                     newIndex = randomGenerator.Next(index + 1, pixelsToSelect);
                 }
                 alreadySelectedPixelsIds.Add(newIndex);
                 _pixelPairs.Add(new PixelPair()
                 {
                     First  = pixelCollection[index],
                     Second = pixelCollection[newIndex],
                 });
             }
         }
     }
     return;
 }
        protected override void PixelCrossing(PixelCollection pixelCollection, int pixelsToSelect, int howManyChildren)
        {
            int deadPixelIndex = pixelsToSelect;

            lock (pixelCollection)
            {
                foreach (var pixelPair in _pixelPairs)
                {
                    for (int i = 0; i < howManyChildren; i++)
                    {
                        var newPixel = new Pixel()
                        {
                            Blue          = Average(pixelPair.First.Blue, pixelPair.Second.Blue),
                            Green         = Average(pixelPair.First.Green, pixelPair.Second.Green),
                            Red           = Average(pixelPair.First.Red, pixelPair.Second.Red),
                            Alpha         = byte.MaxValue,
                            IndexColumn   = pixelCollection[deadPixelIndex].IndexColumn,
                            IndexRow      = pixelCollection[deadPixelIndex].IndexRow,
                            IndexGlobal   = pixelCollection[deadPixelIndex].IndexGlobal,
                            RankingPoints = 0,
                        };
                        pixelCollection[deadPixelIndex] = newPixel;
                        deadPixelIndex++;
                    }
                }
                pixelCollection.OrderAscending();
            }
            return;
        }
        public void Test_IndexOutOfRange()
        {
            using (MagickImage image = new MagickImage(Color.Red, 5, 10))
            {
                using (PixelCollection pixels = image.GetReadOnlyPixels())
                {
                    ExceptionAssert.Throws <ArgumentException>(delegate()
                    {
                        pixels.GetValue(5, 0);
                    });

                    ExceptionAssert.Throws <ArgumentException>(delegate()
                    {
                        pixels.GetValue(-1, 0);
                    });

                    ExceptionAssert.Throws <ArgumentException>(delegate()
                    {
                        pixels.GetValue(0, -1);
                    });

                    ExceptionAssert.Throws <ArgumentException>(delegate()
                    {
                        pixels.GetValue(0, 10);
                    });
                }
            }
        }
Esempio n. 6
0
        protected override void PixelCrossing(PixelCollection pixelCollection, int pixelsToSelect, int howManyChildren)
        {
            var generator      = new Random();
            int deadPixelIndex = pixelsToSelect;

            lock (pixelCollection)
            {
                foreach (var pixelPair in _pixelPairs)
                {
                    var firstPixel  = pixelPair.First;
                    var secondPixel = pixelPair.Second;


                    var blueBitsFirst  = NumberConverter.ToBitArray(firstPixel.Blue);
                    var blueBitsSecond = NumberConverter.ToBitArray(secondPixel.Blue);
                    CrossPixels(ref blueBitsFirst, ref blueBitsSecond);

                    var redBitsFirst  = NumberConverter.ToBitArray(firstPixel.Red);
                    var redBitsSecond = NumberConverter.ToBitArray(secondPixel.Red);
                    CrossPixels(ref redBitsFirst, ref redBitsSecond);

                    var greenBitsFirst  = NumberConverter.ToBitArray(firstPixel.Green);
                    var greenBitsSecond = NumberConverter.ToBitArray(secondPixel.Green);
                    CrossPixels(ref greenBitsFirst, ref greenBitsSecond);

                    pixelCollection[deadPixelIndex].Blue      = NumberConverter.ToInt(blueBitsFirst);
                    pixelCollection[deadPixelIndex].Red       = NumberConverter.ToInt(redBitsFirst);
                    pixelCollection[deadPixelIndex].Green     = NumberConverter.ToInt(greenBitsFirst);
                    pixelCollection[deadPixelIndex + 1].Blue  = NumberConverter.ToInt(blueBitsSecond);
                    pixelCollection[deadPixelIndex + 1].Red   = NumberConverter.ToInt(redBitsSecond);
                    pixelCollection[deadPixelIndex + 1].Green = NumberConverter.ToInt(greenBitsSecond);
                    deadPixelIndex += howManyChildren;
                }
            }
        }
        public void Test_Coalesce()
        {
            using (IMagickImageCollection collection = new MagickImageCollection())
            {
                ExceptionAssert.Throws <InvalidOperationException>(delegate()
                {
                    collection.Coalesce();
                });

                collection.Read(Files.RoseSparkleGIF);

                using (PixelCollection pixels = collection[1].GetPixels())
                {
                    MagickColor color = pixels.GetPixel(53, 3).ToColor();
                    Assert.AreEqual(0, color.A);
                }

                collection.Coalesce();

                using (PixelCollection pixels = collection[1].GetPixels())
                {
                    MagickColor color = pixels.GetPixel(53, 3).ToColor();
                    Assert.AreEqual(Quantum.Max, color.A);
                }
            }
        }
Esempio n. 8
0
 public static void AreNotEqual(MagickColor notExpected, IMagickImage image, int x, int y)
 {
     using (PixelCollection collection = image.GetPixels())
     {
         AreNotEqual(notExpected, collection.GetPixel(x, y));
     }
 }
 //===========================================================================================
 private static void Test_Pixel(MagickImage image, int x, int y, MagickColor color)
 {
     using (PixelCollection collection = image.GetReadOnlyPixels())
     {
         ColorAssert.AreEqual(color, collection.GetPixel(x, y));
     }
 }
Esempio n. 10
0
 public static void AreEqual(MagickColor expected, IMagickImage image, int x, int y)
 {
     using (PixelCollection pixels = image.GetPixels())
     {
         AreEqual(expected, pixels.GetPixel(x, y));
     }
 }
Esempio n. 11
0
 private MagickColor GetBorderColor(MagickImage image)
 {
     using (PixelCollection pixels = image.GetReadOnlyPixels())
     {
         return(pixels.GetPixel((int)BorderColorLocation.X, (int)BorderColorLocation.Y).ToColor());
     }
 }
        public static PixelCollection Generate(int Width, int Height)
        {
            IList <Pixel> generatedPixels = new List <Pixel>();
            var           numberGenerator = new Random();
            int           pixelIndex      = 0;

            for (int row = 0; row < Height; row++)
            {
                for (int col = 0; col < Width; col++)
                {
                    generatedPixels.Add(new Pixel()
                    {
                        Blue        = numberGenerator.NextByte(),
                        Green       = numberGenerator.NextByte(),
                        Red         = numberGenerator.NextByte(),
                        Alpha       = byte.MaxValue,
                        IndexColumn = col,
                        IndexRow    = row,
                        IndexGlobal = pixelIndex,
                    });
                    pixelIndex++;
                }
            }
            var readyCollection = new PixelCollection(generatedPixels)
            {
                Width  = Width,
                Height = Height
            };

            return(readyCollection);
        }
Esempio n. 13
0
        public PixelCollection FloodFill(PixelCollection pixels, Pixel fillPixel, Color targetColor, Color replacementColor)
        {
            if (targetColor.Equals(replacementColor))
            {
                return(pixels);
            }
            if (!fillPixel.Color.Equals(targetColor))
            {
                return(pixels);
            }
            var pixelQueue = new Queue <Pixel>();

            pixels.SetPixel(fillPixel, replacementColor);
            pixelQueue.Enqueue(fillPixel);
            Pixel currentPixel;

            while (pixelQueue.Count > 0)
            {
                currentPixel = pixelQueue.Dequeue();
                var northPixel = pixels.GetPixelOrNull(currentPixel.Column, currentPixel.Row - 1);
                var southPixel = pixels.GetPixelOrNull(currentPixel.Column, currentPixel.Row + 1);
                var eastPixel  = pixels.GetPixelOrNull(currentPixel.Column + 1, currentPixel.Row);
                var westPixel  = pixels.GetPixelOrNull(currentPixel.Column - 1, currentPixel.Row);
                TryToColorPixel(pixels, pixelQueue, northPixel, targetColor, replacementColor);
                TryToColorPixel(pixels, pixelQueue, southPixel, targetColor, replacementColor);
                TryToColorPixel(pixels, pixelQueue, eastPixel, targetColor, replacementColor);
                TryToColorPixel(pixels, pixelQueue, westPixel, targetColor, replacementColor);
            }
            return(pixels);
        }
Esempio n. 14
0
        public PixelCollection BresenhamCircle(PixelCollection pixels, Point center,
                                               double radius, Color colour)
        {
            double x        = radius;
            double y        = 0;
            double decition = 0;

            while (x >= y)
            {
                if (decition <= 0)
                {
                    y++;
                    decition += 2 * y + 1;
                }

                if (decition > 0)
                {
                    x--;
                    decition -= 2 * x + 1;
                }
                pixels.SetPixel((int)(center.X + x), (int)(center.Y + y), colour);
                pixels.SetPixel((int)(center.X + y), (int)(center.Y + x), colour);
                pixels.SetPixel((int)(center.X - y), (int)(center.Y + x), colour);
                pixels.SetPixel((int)(center.X - x), (int)(center.Y + y), colour);
                pixels.SetPixel((int)(center.X - x), (int)(center.Y - y), colour);
                pixels.SetPixel((int)(center.X - y), (int)(center.Y - x), colour);
                pixels.SetPixel((int)(center.X + y), (int)(center.Y - x), colour);
                pixels.SetPixel((int)(center.X + x), (int)(center.Y - y), colour);
            }
            return(pixels);
        }
Esempio n. 15
0
        public PixelCollection Draw(PixelCollection pixels, IList <Point> drawingPoints, DrawingItemProperties properties)
        {
            var fillPixel = pixels.GetPixel(drawingPoints.First());

            FloodFill(pixels, fillPixel, fillPixel.Color, properties.Color);
            return(pixels);
        }
Esempio n. 16
0
        private static void TestPixels(MagickImage image, MagickColor firstRow, MagickColor secondRow)
        {
            using (PixelCollection pixels = image.GetPixels())
            {
                for (int y = 0; y < 2; y++)
                {
                    for (int x = 0; x < 10; x++)
                    {
                        ColorAssert.AreEqual(y == 0 ? firstRow : secondRow, pixels.GetPixel(x, y).ToColor());
                    }
                }
            }

            using (MemoryStream memStream = new MemoryStream())
            {
                image.Format = MagickFormat.Bmp;
                image.Write(memStream);
                memStream.Position = 0;

                using (MagickImage output = new MagickImage(memStream))
                {
                    using (PixelCollection pixels = output.GetPixels())
                    {
                        for (int y = 0; y < 2; y++)
                        {
                            for (int x = 0; x < 10; x++)
                            {
                                ColorAssert.AreEqual(y == 0 ? firstRow : secondRow, pixels.GetPixel(x, y).ToColor());
                            }
                        }
                    }
                }
            }
        }
Esempio n. 17
0
 private static void Test_Set(PixelCollection pixels, QuantumType[] value)
 {
     ExceptionAssert.Throws <ArgumentException>(delegate()
     {
         pixels.Set(value);
     });
 }
Esempio n. 18
0
        public void Test_FillColor()
        {
            using (MagickImage image = new MagickImage(MagickColors.Transparent, 100, 100))
            {
                ColorAssert.AreEqual(MagickColors.Black, image.Settings.FillColor);

                Pixel pixelA;
                image.Settings.FillColor = MagickColors.Red;
                image.Read("caption:Magick.NET");

                Assert.AreEqual(100, image.Width);
                Assert.AreEqual(100, image.Height);

                using (PixelCollection pixels = image.GetPixels())
                {
                    pixelA = pixels.GetPixel(69, 6);
                }

                Pixel pixelB;
                image.Settings.FillColor = MagickColors.Yellow;
                image.Read("caption:Magick.NET");
                using (PixelCollection pixels = image.GetPixels())
                {
                    pixelB = pixels.GetPixel(69, 6);
                }

                ColorAssert.AreNotEqual(pixelA.ToColor(), pixelB.ToColor());
            }
        }
Esempio n. 19
0
 public void Test_IEnumerable()
 {
     using (MagickImage image = new MagickImage(Color.Red, 5, 10))
     {
         PixelCollection pixels = image.GetReadOnlyPixels();
         Assert.AreEqual(50, pixels.Count());
     }
 }
Esempio n. 20
0
        public void Test_Set()
        {
            using (MagickImage image = new MagickImage(Color.Red, 5, 10))
            {
                using (WritablePixelCollection pixels = image.GetWritablePixels())
                {
                    ExceptionAssert.Throws <ArgumentNullException>(delegate()
                    {
                        pixels.Set((QuantumType[])null);
                    });

                    ExceptionAssert.Throws <ArgumentNullException>(delegate()
                    {
                        pixels.Set((Pixel)null);
                    });

                    ExceptionAssert.Throws <ArgumentNullException>(delegate()
                    {
                        pixels.Set((Pixel[])null);
                    });

                    Test_Set(pixels, new QuantumType[] { });
                    Test_Set(pixels, new QuantumType[] { 0 });
                    Test_Set(pixels, new QuantumType[] { 0, 0 });
                    Test_Set(pixels, new QuantumType[] { 0, 0, 0 });

                    pixels.Set(new QuantumType[] { 0, 0, 0, 0, 0 });
                    Test_PixelColor(pixels, Color.Black);
                    pixels.Write();
                }

                using (PixelCollection pixels = image.GetReadOnlyPixels())
                {
                    Test_PixelColor(pixels, Color.Black);
                }

                using (WritablePixelCollection pixels = image.GetWritablePixels())
                {
                    pixels.Set(new uint[] { 4294967295, 0, 0, 0, 0 });
                    Test_PixelColor(pixels, Color.Red);
                    pixels.Set(new ushort[] { 0, 0, 65535, 0, 0 });
                    Test_PixelColor(pixels, Color.Blue);
                    pixels.Set(new byte[] { 0, 255, 0, 0, 0 });
                    Test_PixelColor(pixels, Color.Lime);
                }

                using (WritablePixelCollection pixels = image.GetWritablePixels())
                {
                    for (int x = 0; x < pixels.Width; x++)
                    {
                        for (int y = 0; y < pixels.Height; y++)
                        {
                            pixels.Set(x, y, new QuantumType[] { 0, 0, 0, 0, 0 });
                        }
                    }
                }
            }
        }
Esempio n. 21
0
        public void Test_IndexOutOfRange()
        {
            using (MagickImage image = new MagickImage(MagickColors.Red, 5, 10))
            {
                using (PixelCollection pixels = image.GetPixels())
                {
                    ExceptionAssert.Throws <ArgumentOutOfRangeException>(delegate()
                    {
                        pixels.GetArea(4, 0, 2, 1);
                    });

                    ExceptionAssert.Throws <ArgumentOutOfRangeException>(delegate()
                    {
                        pixels.GetArea(new MagickGeometry(0, 9, 1, 2));
                    });

                    ExceptionAssert.Throws <ArgumentOutOfRangeException>(delegate()
                    {
                        pixels.GetArea(-1, 0, 1, 1);
                    });

                    ExceptionAssert.Throws <ArgumentOutOfRangeException>(delegate()
                    {
                        pixels.GetArea(0, -1, 1, 1);
                    });

                    ExceptionAssert.Throws <ArgumentOutOfRangeException>(delegate()
                    {
                        pixels.GetArea(0, 0, -1, 1);
                    });

                    ExceptionAssert.Throws <ArgumentOutOfRangeException>(delegate()
                    {
                        pixels.GetArea(0, 0, 1, -1);
                    });

                    ExceptionAssert.Throws <ArgumentOutOfRangeException>(delegate()
                    {
                        pixels.GetValue(5, 0);
                    });

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

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

                    ExceptionAssert.Throws <ArgumentOutOfRangeException>(delegate()
                    {
                        pixels.GetValue(0, 10);
                    });
                }
            }
        }
Esempio n. 22
0
 private void TryToColorPixel(PixelCollection pixels, Queue <Pixel> pixelQueue, Pixel currentPixel,
                              Color targetColor, Color replacementColor)
 {
     if (currentPixel != null && targetColor.Equals(currentPixel.Color))
     {
         pixels.SetPixel(currentPixel, replacementColor);
         pixelQueue.Enqueue(currentPixel);
     }
 }
Esempio n. 23
0
 public PixelCollection Execute(PixelCollection pixelCollection, int pixelsToSelect, int howManyChildren)
 {
     lock (pixelCollection)
     {
         RandomlyBindPixelsIntoPairs(pixelCollection, pixelsToSelect);
         PixelCrossing(pixelCollection, pixelsToSelect, howManyChildren);
         return(pixelCollection);
     }
 }
Esempio n. 24
0
 public PixelCollection Draw(PixelCollection pixels, IList <Point> drawingPoints,
                             DrawingItemProperties properties)
 {
     for (int i = 0; i < drawingPoints.Count - 1; i++)
     {
         pixels = _lineTool.BresenhamLine(pixels, drawingPoints[i], drawingPoints[i + 1], properties.Color);
     }
     return(pixels);
 }
Esempio n. 25
0
 public void Test_IEnumerable()
 {
     using (MagickImage image = new MagickImage(MagickColors.Red, 5, 10))
     {
         using (PixelCollection pixels = image.GetPixels())
         {
             Assert.AreEqual(50, pixels.Count());
         }
     }
 }
Esempio n. 26
0
        public PixelCollection Draw(PixelCollection pixels, IList <Point> drawingPoints,
                                    DrawingItemProperties properties)
        {
            Point  center       = PointCalculator.GetCenter(drawingPoints.First(), drawingPoints.Last());
            Point  topCenter    = new Point(center.X, drawingPoints.First().Y);
            Point  bottomCenter = new Point(center.X, drawingPoints.Last().Y);
            double radius       = PointCalculator.GetLenght(topCenter, bottomCenter) / 2;

            return(BresenhamCircle(pixels, center, radius, properties.Color));
        }
Esempio n. 27
0
        private static void Test_PixelColor(PixelCollection pixels, int x, int y, MagickColor color)
        {
            var values = pixels.GetValue(x, y);

            Assert.AreEqual(3, values.Length);

            MagickColor magickColor = new MagickColor(values[0], values[1], values[2]);

            ColorAssert.AreEqual(color, magickColor);
        }
        public void Test_Ping()
        {
            IMagickImageCollection collection = new MagickImageCollection();

            ExceptionAssert.Throws <ArgumentException>(delegate()
            {
                collection.Ping(new byte[0]);
            });

            ExceptionAssert.Throws <ArgumentNullException>(delegate()
            {
                collection.Ping((byte[])null);
            });

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

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

            ExceptionAssert.Throws <ArgumentException>(delegate()
            {
                collection.Ping(Files.Missing);
            });

            collection.Ping(Files.FujiFilmFinePixS1ProJPG);
            Test_Ping(collection);
            Assert.AreEqual(600, collection[0].Width);
            Assert.AreEqual(400, collection[0].Height);

            collection.Ping(new FileInfo(Files.FujiFilmFinePixS1ProJPG));
            Test_Ping(collection);
            Assert.AreEqual(600, collection[0].Width);
            Assert.AreEqual(400, collection[0].Height);

            collection.Ping(File.ReadAllBytes(Files.FujiFilmFinePixS1ProJPG));
            Test_Ping(collection);
            Assert.AreEqual(600, collection[0].Width);
            Assert.AreEqual(400, collection[0].Height);

            collection.Read(Files.SnakewarePNG);
            Assert.AreEqual(286, collection[0].Width);
            Assert.AreEqual(67, collection[0].Height);
            using (PixelCollection pixels = collection[0].GetPixels())
            {
                Assert.AreEqual(38324, pixels.ToArray().Length);
            }

            collection.Dispose();
        }
Esempio n. 29
0
        private int[] lineRangeScan_V(PixelCollection pPixels, int pBeginLine, int pEndLine, int pHeight)
        {
            var _return = new int[pEndLine - pBeginLine];

            for (var x = 0; x < (pEndLine - pBeginLine); x++)
            {
                _return[x] = lineScan_V(pPixels, pBeginLine + x, pHeight);
            }

            return(_return);
        }
Esempio n. 30
0
        private static void WritePixels(MagickImage image, string fileName)
        {
            using (PixelCollection pixels = image.GetPixels())
            {
                ushort[] data  = pixels.ToArray();
                byte[]   bytes = new byte[data.Length * 2];

                Buffer.BlockCopy(data, 0, bytes, 0, bytes.Length);
                File.WriteAllBytes(fileName, bytes);
            }
        }