Example #1
0
        /// <summary>
        /// Given a difference buffer and an array of failed points, this method uses VScan utility to go through
        /// the failed points and determine how many of them can be ignored.
        /// </summary>
        /// <param name="diffBuffer">The difference buffer.</param>
        /// <param name="failedPoints">The array of failed points.</param>
        /// <returns>Number of pixels that CANNOT be ignored. Pass == 0.</returns>
        private static int VerifyDifferenceUsingVScan(RenderBuffer diffBuffer, string VScanToleranceFile)
        {
            int             failures = 0;
            ImageComparator comparator;

            if (VScanToleranceFile != null && File.Exists(VScanToleranceFile)) // using custom tolerance
            {
                CurveTolerance tolerance = new CurveTolerance();
                tolerance.LoadTolerance(VScanToleranceFile);
                comparator = new ImageComparator(tolerance);
            }
            else // using default tolerance;
            {
                comparator = new ImageComparator();
            }

            ImageAdapter blackImageAdapter = new ImageAdapter(diffBuffer.Width, diffBuffer.Height, ColorToIColor(Colors.Black));
            ImageAdapter diffImageAdapter  = new ImageAdapter(diffBuffer.Width, diffBuffer.Height);

            for (int x = 0; x < diffBuffer.Width; x++)
            {
                for (int y = 0; y < diffBuffer.Height; y++)
                {
                    diffImageAdapter[x, y] = ColorToIColor(diffBuffer.FrameBuffer[x, y]);
                }
            }

            bool passed = comparator.Compare(blackImageAdapter, diffImageAdapter, true);

            failures = (passed == false && comparator.MismatchingPoints != null) ? comparator.MismatchingPoints.NumMismatchesAboveLevel(1) : 0;

            return(failures);
        }
Example #2
0
        /// <summary>
        /// Perform the comparison operation
        /// This method abstracts out all the details of image comparison to a boolean result
        /// The basic assumption is that the default set of tolerances is adequate
        /// </summary>
        /// <param name="testImageAdapter"></param>
        /// <param name="masterImageAdapter"></param>
        /// <returns></returns>
        private static bool Compare(IImageAdapter testImageAdapter, IImageAdapter masterImageAdapter)
        {
            bool            TestPassed = false;
            ImageComparator comparator = null;

            if (File.Exists(toleranceFilePath))
            {
                CurveTolerance tolerance = new CurveTolerance();
                tolerance.LoadTolerance(toleranceFilePath);
                comparator = new ImageComparator(tolerance);
                TestLog.Current.LogStatus("Using custom tolerance (" + toleranceFilePath + ")");
            }
            else
            {
                comparator = new ImageComparator();
                TestLog.Current.LogStatus("Using default tolerance");
            }

            if (!xtcContainsDpiInfo)
            {
                // No master image dpi info found in test definition
                TestPassed = comparator.Compare(masterImageAdapter, testImageAdapter, true);
            }
            else
            {
                TestPassed = comparator.Compare(masterImageAdapter,                                                                            // master image adapter
                                                new Point((int)Math.Round(masterImageAdapter.DpiX), (int)Math.Round(masterImageAdapter.DpiY)), // master image dpi info
                                                testImageAdapter,                                                                              // test image adapter
                                                new Point((int)Math.Round(testImageAdapter.DpiX), (int)Math.Round(testImageAdapter.DpiY)),     // test image dpi info
                                                true);                                                                                         // populateMismatchingPoints
            }

            if (!TestPassed)
            {
                Package package = Package.Create(".\\FailurePackage.vscan",
                                                 ImageUtility.ToBitmap(masterImageAdapter),
                                                 ImageUtility.ToBitmap(testImageAdapter),
                                                 comparator.Curve.CurveTolerance.WriteToleranceToNode());
                package.Save();
                TestLog.Current.LogFile(package.PackageName);
            }

            return(TestPassed);
        }