예제 #1
0
        /// <summary>Verifies whether two ComparisonCriteria objects are equal
        /// </summary>
        /// <param name="obj">Object to compare with.</param>
        /// <returns>true if the objects are equal, false otherwise.</returns>
        public override bool Equals(Object obj)
        {
            ComparisonCriteria x = this;
            ComparisonCriteria y = obj as ComparisonCriteria;

            if (x == null && y == null)
            {
                return(true);
            }
            if (x == null || y == null)
            {
                return(false);
            }
            return
                ((x.MinColorDistance == y.MinColorDistance) &&
                 (x.MinColorContrast == y.MinColorContrast) &&
                 (x.MinBrightnessDistance == y.MinBrightnessDistance) &&
                 (x.MinBrightnessContrast == y.MinBrightnessContrast) &&
                 (x.MaxColorDistance == y.MaxColorDistance) &&
                 (x.MaxColorContrast == y.MaxColorContrast) &&
                 (x.MaxBrightnessDistance == y.MaxBrightnessDistance) &&
                 (x.MaxBrightnessContrast == y.MaxBrightnessContrast) &&
                 (x.MaxPixelDistance == y.MaxPixelDistance) &&
                 (x.MaxErrorProportion == y.MaxErrorProportion) &&
                 (x.MismatchDescription == y.MismatchDescription));
        }
예제 #2
0
        /// <summary>
        /// Compares to bitmaps based on tolerance criteria
        /// </summary>
        /// <param name='sourceImage'>Master image for comparison.</param>
        /// <param name='targetImage'>Sampled image for comparison.</param>
        /// <param name='maxColorDistanceTolerance'>Maximum color distance tolerance</param>
        /// <returns>true if master and sample are equal, false otherwise.</returns>
        public static bool AreBitmapsEqualUsingCriteria(Bitmap sourceImage, Bitmap targetImage, float maxColorDistanceTolerance)
        {
            ComparisonCriteria criteria = new ComparisonCriteria();

            criteria.MaxColorDistance = maxColorDistanceTolerance;

            return(AreBitmapsEqualUsingCriteria(sourceImage, targetImage, criteria));
        }
예제 #3
0
        /// <summary>
        /// Executes the comparison operation with supporting services.
        /// </summary>
        /// <param name="prefixName">
        /// Prefix name for criteria and operation configuration arguments.
        /// </param>
        /// <returns>The results of the comparison operation.</returns>
        /// <remarks><p>
        /// This method implements the typical wrapping around
        /// the comparison API, where services are available to help
        /// with configuration and logging.
        /// </p><p>
        /// The operation is configured, and a new criteria object is
        /// configured and assigned unless the current criteria has
        /// already been modified in some way. If the criteria is not
        /// met, an exception is thrown. If LogImagesOnUnmet is true and
        /// the criteria is not met, the images will be logged.
        /// </p><p>
        /// The ComparisonOperation object and the ComparisonResult
        /// object are configured with the
        /// ConfigurationSettings.SetObjectProperties method; see
        /// this API for more information.
        /// </p></remarks>
        public ComparisonResult ExecuteServiced(string prefixName)
        {
#if (IGNORE_IMAGE_LOGGING)
            throw new NotImplementedException("ComparisonOperation.ExecuteServiced is not implemented when IGNORE_IMAGE_LOGGING is defined.");
#else
            if (prefixName == null)
            {
                throw new ArgumentNullException("prefixName");
            }
            GlobalLog.LogStatus("Performing {" + prefixName + "} comparison...");

            if (Criteria.Equals(ComparisonCriteria.PerfectMatch))
            {
                // Doing a SetObjectProperties call on this.criteria
                // would modify the properties of the shared perfect match
                // instance.
                ComparisonCriteria newCriteria = new ComparisonCriteria();
                //ConfigurationSettings.Current
                //    .SetObjectProperties(newCriteria, prefixName);
                Criteria = newCriteria;
                GlobalLog.LogStatus(criteria.ToString());
            }

            ComparisonResult result = Execute();

            if (!result.CriteriaMet)
            {
                if (LogImagesOnCriteriaUnmet)
                {
                    masterImage.Save(prefixName + "master", System.Drawing.Imaging.ImageFormat.Png);
                    GlobalLog.LogFile(prefixName + "master");
                    //l.LogImage(masterImage, prefixName + "master");
                    sampleImage.Save(prefixName + "sample", System.Drawing.Imaging.ImageFormat.Png);
                    GlobalLog.LogFile(prefixName + "sample");

                    //l.LogImage(sampleImage, prefixName + "sample");
                    Bitmap differences = new Bitmap(sampleImage);
                    result.HighlightDifferences(differences);

                    differences.Save(prefixName + "differences", System.Drawing.Imaging.ImageFormat.Png);
                    GlobalLog.LogFile(prefixName + "differences");
                    //l.LogImage(differences, prefixName + "differences");
                }

                string message = criteria.MismatchDescription +
                                 Environment.NewLine + result.ToString();
                throw new Exception(message);
            }
            else
            {
                GlobalLog.LogStatus(result.ToStringBrief());
            }
            return(result);
#endif
        }
예제 #4
0
 /// <summary>
 /// Compares to bitmaps based on tolerance criteria
 /// </summary>
 /// <param name='sourceImage'>Master image for comparison.</param>
 /// <param name='targetImage'>Sampled image for comparison.</param>
 /// <param name='criteria'>Criteria for image comparison.</param>
 /// <returns>true if master and sample are equal, false otherwise.</returns>
 public static bool AreBitmapsEqualUsingCriteria(Bitmap sourceImage, Bitmap targetImage, ComparisonCriteria criteria)
 {
     return(AreBitmapsEqualUsingCriteria(sourceImage, targetImage, criteria, true));
 }
예제 #5
0
        /// <summary>
        /// Compares to bitmaps based on tolerance criteria
        /// </summary>
        /// <param name='sourceImage'>Master image for comparison.</param>
        /// <param name='targetImage'>Sampled image for comparison.</param>
        /// <param name='differenceImage'>On return, bitmap with differences highlighted
        /// if any were found, null otherwise.</param>
        /// <param name='criteria'>Criteria for image comparison.</param>
        /// <param name='logBitmaps'>Log bitmaps if comparison fails</param>
        /// <returns>true if master and sample are equal, false otherwise.</returns>
        public static bool AreBitmapsEqualUsingCriteria(Bitmap sourceImage, Bitmap targetImage, out Bitmap differenceImage, ComparisonCriteria criteria, bool logBitmaps)
        {
            ComparisonOperation operation;
            ComparisonResult    result;

            operation             = new ComparisonOperation();
            operation.Criteria    = criteria;
            operation.MasterImage = sourceImage;
            operation.SampleImage = targetImage;
            result          = operation.Execute();
            differenceImage = null;
            if ((result.CriteriaMet == false))
            {
                AreBitmapsEqual(sourceImage, targetImage, out differenceImage);
                result.HighlightDifferences(differenceImage);
                if (logBitmaps)
                {
                    GlobalLog.LogStatus("Logging Images: sourceImage targetImage differencesImage:\r\n");
                    GlobalLog.LogDebug(result.ToString());
                    LogImageOnDisk(sourceImage, "sourceImage" + _combinationIndex.ToString() + ".png");
                    LogImageOnDisk(targetImage, "targetImage" + _combinationIndex.ToString() + ".png");
                    LogImageOnDisk(differenceImage, "differencesImage" + _combinationIndex.ToString() + ".png");
                    _combinationIndex++;
                }
            }
            return(result.CriteriaMet);
        }
예제 #6
0
        /// <summary>
        /// Compares to bitmaps based on tolerance criteria
        /// </summary>
        /// <param name='sourceImage'>Master image for comparison.</param>
        /// <param name='targetImage'>Sampled image for comparison.</param>
        /// <param name='criteria'>Criteria for image comparison.</param>
        /// <param name='logBitmaps'>Log bitmaps if comparison fails</param>
        /// <returns>true if master and sample are equal, false otherwise.</returns>
        public static bool AreBitmapsEqualUsingCriteria(Bitmap sourceImage, Bitmap targetImage, ComparisonCriteria criteria, bool logBitmaps)
        {
            Bitmap differenceImage;

            return(AreBitmapsEqualUsingCriteria(sourceImage, targetImage, out differenceImage, criteria, logBitmaps));
        }