/// <summary>
 /// Returns true if this color is less than or equal to reference color on all channels.
 /// </summary>
 /// <param name="reference">The reference color to evaluate against.</param>
 /// <returns>True if this color is less than or equal to reference on all channels.</returns>
 internal bool MeetsTolerance(ColorDifference reference)
 {
     return((this.A <= reference.A) &&
            (this.R <= reference.R) &&
            (this.G <= reference.G) &&
            (this.B <= reference.B));
 }
Exemple #2
0
        /// <summary>
        /// Performs Bitwise AND of Color bits.
        /// </summary>
        /// <param name="color1">The first color.</param>
        /// <param name="color2">The second color.</param>
        /// <returns></returns>
        internal static Color And(this Color color1, Color color2)
        {
            ColorDifference andValue = new ColorDifference();

            andValue.A = (byte)(color1.A & color2.A);
            andValue.R = (byte)(color1.R & color2.R);
            andValue.G = (byte)(color1.G & color2.G);
            andValue.B = (byte)(color1.B & color2.B);
            return(Color.FromArgb(andValue.A, andValue.R, andValue.G, andValue.B));
        }
Exemple #3
0
        /// <summary>
        /// Performs Bitwise OR of Color bits.
        /// </summary>
        /// <param name="color1">The first color.</param>
        /// <param name="color2">The second color.</param>
        /// <returns></returns>
        internal static Color Or(this Color color1, Color color2)
        {
            ColorDifference orValue = new ColorDifference();

            orValue.A = (byte)(color1.A | color2.A);
            orValue.R = (byte)(color1.R | color2.R);
            orValue.G = (byte)(color1.G | color2.G);
            orValue.B = (byte)(color1.B | color2.B);
            return(Color.FromArgb(orValue.A, orValue.R, orValue.G, orValue.B));
        }
Exemple #4
0
        /// <summary>
        /// Color differencing helper for snapshot comparisons.
        /// </summary>
        /// <param name="color1">The first color</param>
        /// <param name="color2">The second color</param>
        /// <param name="subtractAlpha">If set to false, the Alpha channel is overridden to full opacity, rather than the difference.
        /// This is important for visualization, especially if both colors are fully opaque, as the difference produces a fully transparent difference.</param>
        /// <returns></returns>
        internal static Color Subtract(this Color color1, Color color2, bool subtractAlpha)
        {
            ColorDifference diff = Compare(color1, color2);

            if (!subtractAlpha)
            {
                diff.A = 255;
            }
            return(Color.FromArgb(diff.A, diff.R, diff.G, diff.B));
        }
Exemple #5
0
        /// <summary>
        /// Compares colors by producing an absolute valued Color Difference object
        /// </summary>
        /// <param name="color1">The first color</param>
        /// <param name="color2">The second colar</param>
        /// <returns>The Color Difference of the two colors</returns>
        internal static ColorDifference Compare(this Color color1, Color color2)
        {
            ColorDifference diff = new ColorDifference();

            diff.A = (byte)Math.Abs(color1.A - color2.A);
            diff.R = (byte)Math.Abs(color1.R - color2.R);
            diff.G = (byte)Math.Abs(color1.G - color2.G);
            diff.B = (byte)Math.Abs(color1.B - color2.B);
            return(diff);
        }
 /// <summary>
 /// Ensures that the image colors are all within tolerance range of the expected Color.
 /// </summary>
 /// <param name="image">The actual image being verified.</param>
 /// <returns>A VerificationResult enumeration value based on the image, the expected color, and the tolerance.</returns>
 public override VerificationResult Verify(Snapshot image)
 {
     for (int row = 0; row < image.Height; row++)
     {
         for (int column = 0; column < image.Width; column++)
         {
             ColorDifference diff = image[row, column].Compare(ExpectedColor);
             if (!diff.MeetsTolerance(Tolerance))
             {
                 //Exit early as we have a counter-example to prove failure.
                 return(VerificationResult.Fail);
             }
         }
     }
     return(VerificationResult.Pass);
 }
 /// <summary>
 /// Initializes a new instance of the SnapshotColorVerifier class, using the specified tolerance value.
 /// </summary>
 /// <param name="expectedColor">The expected color to test against.</param>
 /// <param name="tolerance">A ColorDifference instance specifying the desired tolerance.</param>
 public SnapshotColorVerifier(Color expectedColor, ColorDifference tolerance)
 {
     this.Tolerance     = tolerance;
     this.ExpectedColor = expectedColor;
 }
 /// <summary>
 /// Initializes a new instance of a SnapshotColorVerifier class, using black pixels with zero tolerance.
 /// </summary>
 public SnapshotColorVerifier()
 {
     Tolerance     = new ColorDifference();
     ExpectedColor = Color.Black;
 }