public static BitArray64 Random(int length)
        {
            var result = new BitArray64(length);

            result.Randomize();
            return(result);
        }
Beispiel #2
0
        public void SetColumn(BitArray64 source, int column)
        {
            ValidateColumn(column);
            var height = MathHelper.Min(_height, source.Length);

            for (var r = 0; r < height; r++)
            {
                _pixels[r][column] = source[r];
            }
        }
Beispiel #3
0
        public void SetRow(BitArray64 source, int row)
        {
            ValidateRow(row);
            var width = MathHelper.Min(_width, source.Length);

            for (var c = 0; c < width; c++)
            {
                _pixels[row][c] = source[c];
            }
        }
Beispiel #4
0
        public BitArray64 GetColumn(int column)
        {
            ValidateColumn(column);
            var result = new BitArray64(_height);

            for (var r = 0; r < _height; r++)
            {
                result[r] = _pixels[r][column];
            }

            return(result);
        }
        public BitArray64(BitArray64 bits)
        {
            if (bits == null)
            {
                throw new ArgumentNullException(nameof(bits));
            }

            var arrayLength = DetermineInternalArrayLength(bits._length, 1);

            _data   = new ulong[arrayLength];
            _length = bits._length;
            Array.Copy(bits._data, _data, arrayLength);
            _version = bits._version;
        }
Beispiel #6
0
        private PixelMap(PixelMap pixelMap)
        {
            if (pixelMap == null)
            {
                throw new ArgumentNullException(nameof(pixelMap));
            }

            _width  = pixelMap.Width;
            _height = pixelMap.Height;
            _pixels = new BitArray64[pixelMap.Height];
            for (var i = 0; i < _pixels.Length; i++)
            {
                _pixels[i] = new BitArray64(pixelMap._pixels[i]);
            }
        }
Beispiel #7
0
        public PixelMap(int width, int height)
        {
            if (width < 1 || height < 1)
            {
                throw new ArgumentException("Width and height must each be greater than zero");
            }

            _width  = width;
            _height = height;
            _pixels = new BitArray64[height];
            for (var i = 0; i < height; i++)
            {
                _pixels[i] = new BitArray64(width);
            }
        }
        public void Xor(BitArray64 value)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }
            if (_length != value._length)
            {
                throw new ArgumentException("The specified BitArray64 has a different length");
            }

            for (var i = 0; i < _data.Length; i++)
            {
                _data[i] ^= value._data[i];
            }

            _version++;
        }
Beispiel #9
0
        public void FromXNode(XElement element)
        {
            _width  = Int32.Parse(element.Attribute("Width").Value);
            _height = Int32.Parse(element.Attribute("Height").Value);
            _pixels = new BitArray64[_height];

            // Parse value string
            var rowStrings = element.Value.Split('|');

            for (var i = 0; i < _height; i++)
            {
                var rowIntString = rowStrings[i].Split(',');
                var rowValue     = new ulong[rowIntString.Length];
                for (var j = 0; j < rowIntString.Length; j++)
                {
                    rowValue[j] = UInt64.Parse(rowIntString[j]);
                }

                _pixels[i] = new BitArray64(rowValue);
            }
        }
Beispiel #10
0
        public void Transform(Rectangle relativeRectangle)
        {
            if (relativeRectangle.Width <= 0 || relativeRectangle.Height <= 0)
            {
                throw new ArgumentException("The size of the specified transformation rectangle must be greater than zero");
            }

            // Determine the size and location of the transformed grid
            var overlapRectangle = Rectangle.Intersect(Rectangle.FromLTRB(0, 0, _width, _height), relativeRectangle);

            //if (overlapRectangle == relativeRectangle)
            //return;

            // Initialize the new pixel matrix
            var newPixels = new BitArray64[relativeRectangle.Height];

            for (var i = 0; i < relativeRectangle.Height; i++)
            {
                newPixels[i] = new BitArray64(relativeRectangle.Width);
            }

            // If the transformation overlaps its original size and position,
            // copy the pixels in the overlapping area
            if (overlapRectangle.Size != Size.Empty)
            {
                for (var r = 0; r < overlapRectangle.Height; r++)
                {
                    for (var c = 0; c < overlapRectangle.Width; c++)
                    {
                        newPixels[r][c] = _pixels[overlapRectangle.Y + r][overlapRectangle.X + c];
                    }
                }
            }

            _width  = relativeRectangle.Width;
            _height = relativeRectangle.Height;
            _pixels = newPixels;
        }
Beispiel #11
0
 public ulong[] this[int row]
 {
     get { return(_pixels[row].ToUInt64Array()); }
     set { _pixels[row] = new BitArray64(value); }
 }