Exemplo n.º 1
0
        /// <summary>
        /// Does the actual population of the Pixel Matrix
        /// </summary>
        private void DoPopulate()
        {
            Columns    = new List <PixelColumn>();
            Comparator = null;
            if (LinkCompare)
            {
                Comparator = new List <PixelColumn>();
            }

            //set the search dimensions
            if (SearchWidth <= 0)
            {
                SearchWidth = image2.bitmap.Width;
            }
            if (SearchHeight <= 0)
            {
                SearchHeight = image2.bitmap.Height;
            }

            //set thepixel scanning dimensions
            if (WidthSearchOffset < 1)
            {
                WidthSearchOffset = 1;
            }
            if (HeightSearchOffset < 1)
            {
                HeightSearchOffset = 1;
            }

            if (GridSystemOn)
            {
                imageGrid = new ImageGrid(SearchWidth, SearchHeight);
            }

            //set some grid and comparator variables here, for scope reasons
            GridColumn  gridColumn       = null;
            Grid        grid             = null;
            PixelCell   comparatorCell   = null;
            PixelColumn comparatorColumn = null;

            //look at every pixel in each image, and compare the colours
            for (int i = 0; i < SearchWidth; i += WidthSearchOffset)
            {
                PixelColumn column = new PixelColumn();
                if (LinkCompare)
                {
                    comparatorColumn = new PixelColumn();
                }

                //set a new grid column, if required
                if (GridSystemOn)
                {
                    if (i == 0)
                    {
                        gridColumn = new GridColumn();
                    }
                    else if (i % imageGrid.GridWidth == 0)
                    {
                        imageGrid.Columns.Add(gridColumn); gridColumn = new GridColumn();
                    }
                }

                for (int n = 0; n < SearchHeight; n += HeightSearchOffset)
                {
                    PixelCell cell = new PixelCell();
                    if (LinkCompare)
                    {
                        comparatorCell = new PixelCell();
                    }

                    //set a new grid, if required
                    if (GridSystemOn)
                    {
                        if (n > 0 && n % imageGrid.GridHeight == 0 && i % imageGrid.GridWidth == 0)
                        {
                            gridColumn.grids.Add(grid);
                            grid = new Grid();
                        }
                        else if (n == 0 && i % imageGrid.GridWidth == 0)
                        {
                            grid = new Grid();
                        }
                    }

                    //get the pixel colours. image 1 pixel one either comes from image1, or the comparison PixelMatrix, if it exists
                    Int64 image1Pixel = Comparision == null?image1.bitmap.GetPixel(i, n).Name.HexToLong() : Comparision[i].Cells[n].colour;

                    Int64 image2Pixel = image2.bitmap.GetPixel(i, n).Name.HexToLong();

                    //set the comparator
                    if (LinkCompare)
                    {
                        comparatorCell.colour = image2Pixel; comparatorColumn.Cells.Add(comparatorCell);
                    }

                    if (image1Pixel != image2Pixel)
                    {
                        cell.hasChanged = true;
                        cell.change     = image1Pixel - image2Pixel;
                        if (GridSystemOn)
                        {
                            grid.change += cell.positiveChange;
                        }
                    }
                    else
                    {
                        cell.hasChanged = false;
                    }

                    column.Cells.Add(cell);

                    if (GridSystemOn && n + 1 == image1.bitmap.Height && i % imageGrid.GridWidth == 0)
                    {
                        gridColumn.grids.Add(grid);
                    }
                }//height

                Columns.Add(column);
                if (LinkCompare)
                {
                    Comparator.Add(comparatorColumn);
                }

                if (GridSystemOn && i + 1 == image1.bitmap.Width)
                {
                    imageGrid.Columns.Add(gridColumn);
                }
            }//width
        }