public void SetBits(Buffer2DView <T> srcView, Int32Rect srcRect, Int32Point?dstPoint = null) { if (srcRect.X < 0 || srcRect.Width < 0 || (srcRect.X + srcRect.Width) > srcView._buffer._bounds.Width || srcRect.Y < 0 || srcRect.Height < 0 || (srcRect.Y + srcRect.Height) > srcView._buffer._bounds.Height) { throw new ArgumentOutOfRangeException("srcRect", "The source rect must specify coordinates within the bounds of the source buffer."); } Int32Point theDstPoint = dstPoint ?? new Int32Point(srcRect.X, srcRect.Y); if (theDstPoint.X < 0 || (theDstPoint.X + srcRect.Width) > _bounds.Width || theDstPoint.Y < 0 || (theDstPoint.Y + srcRect.Height) > _bounds.Height) { throw new ArgumentOutOfRangeException("dstPoint", "The destination point must specify coordinates within the bounds of the buffer."); } unsafe { int sizeOfT = Marshal.SizeOf(typeof(T)); byte *pRead = ((byte *)srcView._buffer._pBits.ToPointer()) + (srcRect.Y + srcView._buffer._bounds.Y) * srcView._buffer._rowWidth * sizeOfT + (srcRect.X + srcView._buffer._bounds.X) * sizeOfT; byte *pWrite = ((byte *)_pBits.ToPointer()) + (theDstPoint.Y + _bounds.Y) * _rowWidth * sizeOfT + (theDstPoint.X + _bounds.X) * sizeOfT; for (int row = 0; row < srcRect.Height; row++) { for (int col = 0; col < srcRect.Width * sizeOfT; col++) { *(pWrite + col) = *(pRead + col); } pRead += srcView._buffer._rowWidth * sizeOfT; pWrite += _rowWidth * sizeOfT; } } }
public Buffer2DView(Buffer2DView <T> buffer, Int32Rect bounds) { _buffer = new Buffer2D <T>(buffer._buffer, bounds); }