private void LockBitmap()
{
Rectangle bounds = new Rectangle(Point.Empty, this.bitmap.Size);
// Figure out the number of bytes in a row. This is rounded up to be a multiple
// of 4 bytes, since a scan line in an image must always be a multiple of 4 bytes
// in length.
this.pixelSize = Image.GetPixelFormatSize(this.bitmap.PixelFormat) / 8;
this.bytesInARow = bounds.Width * this.pixelSize;
if (this.bytesInARow % 4 != 0)
{
this.bytesInARow = 4 * ((this.bytesInARow / 4) + 1);
}
// Lock the bitmap
this.bitmapData = this.bitmap.LockBits(bounds, ImageLockMode.ReadWrite, this.bitmap.PixelFormat);
// Set the value to the first scan line
this.pixelBase = (byte*)this.bitmapData.Scan0.ToPointer();
if (this.computeIntegrals)
{
// Allocate values for integral image calculation.
this.normalWidth = this.width + 1;
int normalHeight = this.height + 1;
this.tiltedWidth = this.width + 2;
int tiltedHeight = this.height + 2;
this.normalSumImage = new long[normalHeight, this.normalWidth];
this.normalSumHandle = GCHandle.Alloc(this.normalSumImage, GCHandleType.Pinned);
this.normalSum = (long*)this.normalSumHandle.AddrOfPinnedObject().ToPointer();
this.squaredSumImage = new long[normalHeight, this.normalWidth];
this.squaredSumHandle = GCHandle.Alloc(this.squaredSumImage, GCHandleType.Pinned);
this.squaredSum = (long*)this.squaredSumHandle.AddrOfPinnedObject().ToPointer();
if (this.computeTilted)
{
this.tiltedSumImage = new long[tiltedHeight, this.tiltedWidth];
this.tiltedSumHandle = GCHandle.Alloc(this.tiltedSumImage, GCHandleType.Pinned);
this.tiltedSum = (long*)this.tiltedSumHandle.AddrOfPinnedObject().ToPointer();
}
this.CalculateIntegrals();
}
}