/// <summary>
        /// Compares the images into the given result.
        /// </summary>
        private unsafe void CompareData(ComparisonResult result)
        {
            sampleData = null;
            masterData = BitmapUtils.LockBitmapDataRead(MasterImage);
            try
            {
                sampleData = BitmapUtils.LockBitmapDataRead(SampleImage);

                int width = MasterScanLineWidth;
                positions         = PositionDelta.ForWithinDistance(Criteria.MaxPixelDistance);
                maxSquareDistance = (255 * 255 + 255 * 255 + 255 * 255) *
                                    Criteria.MaxColorDistance;
                minSquareDistance = (255 * 255 + 255 * 255 + 255 * 255) *
                                    Criteria.MinColorDistance;

                int errorCount = 0;
                for (int y = 0; y < MasterSize.Height; y++)
                {
                    PixelData *masterPixels = (PixelData *)
                                              ((byte *)masterData.Scan0.ToPointer() + y * width);
                    PixelData *samplePixels = (PixelData *)
                                              ((byte *)sampleData.Scan0.ToPointer() + y * width);
                    for (int x = 0; x < MasterSize.Width; x++)
                    {
                        bool match = PixelsEqual(*masterPixels, *samplePixels);
                        if (!match || minSquareDistance != 0)
                        {
                            result.SetIdentical(false);
                            CheckPixel(x, y, result, ref errorCount);
                            if (errorCount > MaxErrorCount)
                            {
                                result.SetCriteriaMet(false);
                                return;
                            }
                        }
                        masterPixels++;
                        samplePixels++;
                    }
                }
            }
            finally
            {
                MasterImage.UnlockBits(masterData);
                if (sampleData != null)
                {
                    SampleImage.UnlockBits(sampleData);
                }
                masterData = null;
                sampleData = null;
            }
        }