Alexandria.Raster.SetupDrawImage C# (CSharp) Method

SetupDrawImage() private method

private SetupDrawImage ( Vector2i &position, Vector2i &size, int &data, int &offset, int &pitch ) : void
position Vector2i
size Vector2i
data int
offset int
pitch int
return void
        void SetupDrawImage(ref Vector2i position, ref Vector2i size, ref int[] data, ref int offset, ref int pitch)
        {
            if (size.X < 0)
                throw new ArgumentOutOfRangeException("Size's X field cannot be less than zero.", "size");
            if (size.Y < 0)
                throw new ArgumentOutOfRangeException("Size's Y field cannot be less than zero.", "size");
            if (data == null)
                throw new ArgumentNullException("data");
            if (offset < 0)
                throw new ArgumentOutOfRangeException("Offset cannot be less than zero.", "offset");
            if (offset + pitch * (long)size.Y < 0 || offset + pitch * (long)(size.Y - 1) + size.X > data.Length)
                throw new ArgumentOutOfRangeException("The combination of offset, pitch, and size are out of range for the data.", "pitch");

            if (position.X < 0) {
                size.X += position.X;
                offset -= position.X;
            }

            if (position.Y < 0) {
                size.Y += position.Y;
                offset -= position.Y * pitch;
            }

            if (position.X + size.X > Width)
                size.X = Width - position.X;

            if (position.Y + size.Y > Height)
                size.Y = Height - position.Y;

            if(size.X > 0 && size.Y > 0)
                DirtyArea(position.X, position.Y, position.X + size.X - 1, position.Y + size.Y - 1);
        }