Esempio n. 1
0
        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);
                }
            }
        }
Esempio n. 2
0
        /// <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;
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Verifies that the master and sample images match in size.
 /// Otherwise, the difference is added to the result.
 /// </summary>
 /// <param name="result">The comparison result to add the difference
 /// to. May be null.</param>
 /// <returns>true if the sizes match, false otherwise.</returns>
 protected bool RequireSizeMatch(ComparisonResult result)
 {
     if (MasterSize.Equals(SampleSize))
     {
         return(true);
     }
     else
     {
         result.AddDifference(
             new SizeDifference(MasterSize, SampleSize));
         result.SetIdentical(false);
         result.SetCriteriaMet(false);
         return(false);
     }
 }