Example #1
0
        private int[] DecodeGridPattern()
        {
            var(row, column) = PyxcellConvert.GetGridPosition(_gridNumber);

            var pixelRow = _image.GetPixelRowSpan(row);

            var pattern = new int[Constraints.GridSize];

            for (int i = 0; i < pattern.Length; i++)
            {
                Color columnFill = new Rgba32(pixelRow[column + i].Rgba);
                pattern[i] = columnFill == Color.Transparent ? 0 : 1;
            }

            return(pattern);
        }
Example #2
0
        public void Draw(int[] pattern, Color colour)
        {
            var(row, column) = PyxcellConvert.GetGridPosition(_gridNumber);

            for (int i = 0; i < pattern.Length; i++)
            {
                if (pattern[i] == 1)
                {
                    var topLeft     = new PointF(column + i, row);
                    var bottomRight = new PointF(topLeft.X + 1, topLeft.Y + Constraints.GridSize);

                    var line = new RectangularPolygon(topLeft, bottomRight);
                    _image.Mutate(x => x.Fill(colour, line));
                }
            }

            _gridNumber++;
        }
Example #3
0
        private Color DecodeGridColour()
        {
            var(row, column) = PyxcellConvert.GetGridPosition(_gridNumber);

            var pixelRow = _image.GetPixelRowSpan(row);

            Color colour = Color.Transparent;

            for (int i = 0; i < Constraints.GridSize; i++)
            {
                colour = new Rgba32(pixelRow[column + i].Rgba);
                if (colour != Color.Transparent)
                {
                    break;
                }
            }

            if (colour == Color.Transparent)
            {
                throw new Exception($"Could not find colour for grid {_gridNumber}.");
            }

            return(colour);
        }