/// <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; } }
private unsafe void CompareData(ComparisonResult result) { BitmapData sampleData = null; BitmapData masterData = MasterImage.LockBits(MasterRectangle, ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb); try { sampleData = SampleImage.LockBits(SampleRectangle, ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb); int width = MasterScanLineWidth; int errorCount = 0; PixelData *masterPixels; PixelData *samplePixels = (PixelData *)sampleData.Scan0; for (int y = 0; y < MasterSize.Height; y++) { masterPixels = (PixelData *) ((byte *)masterData.Scan0.ToPointer() + y * width); samplePixels = (PixelData *) ((byte *)sampleData.Scan0.ToPointer() + y * width); for (int x = 0; x < MasterSize.Width; x++) { bool match = PixelsEqual(*masterPixels, *samplePixels); if (!match) { result.AddDifference( new PixelColorDifference(x, y, masterPixels->red, masterPixels->green, masterPixels->blue, samplePixels->red, samplePixels->green, samplePixels->blue)); result.SetIdentical(false); errorCount++; if (errorCount > MaxErrorCount) { result.SetCriteriaMet(false); return; } } masterPixels++; samplePixels++; } } } finally { MasterImage.UnlockBits(masterData); if (sampleData != null) { SampleImage.UnlockBits(sampleData); } } }