コード例 #1
0
        /**
         * Run the Color Contrast calculation on the image.
         */
        internal IColorContrastResult RunColorContrastCalculationV1()
        {
            ColorContrastResult result = null;

            ColorContrastRunner runner = new ColorContrastRunner(_colorContrastConfig);

            Color previousColor = null;

            foreach (var pixel in GetBinaryRowSearchIterator())
            {
                if (IsNewRow(pixel))
                {
                    runner.OnRowBegin();
                }

                runner.OnPixel(pixel.Color, previousColor);
                previousColor = pixel.Color;

                if (IsEndOfRow(pixel))
                {
                    var newResult = runner.OnRowEnd();

                    if (result == null)
                    {
                        result = newResult;
                    }

                    // Save newResult if it's higher confidence than the current result.
                    // newResult.Confidence is guaranteed to be either High, Mid, or Low
                    if (newResult.Confidence == Confidence.High)
                    {
                        result = newResult;
                        break;
                    }
                    else if (newResult.Confidence == Confidence.Mid)
                    {
                        // The analyzer claims that this condition is always false, but testing
                        // proves that we definitely execute the code inside the if block.
#pragma warning disable CA1508 // Avoid dead conditional code
                        if (result.Confidence != Confidence.Mid)
#pragma warning restore CA1508 // Avoid dead conditional code
                        {
                            result = newResult;
                        }
                    }
                }
            }

            return(result);
        }
コード例 #2
0
        /**
         * Run the Color Contrast calculation on the image.
         */
        public ColorContrastResult RunColorContrastCalculation()
        {
            ColorContrastResult result = null;

            ColorContrastRunner runner = new ColorContrastRunner(_colorContrastConfig);

            Color previousColor = null;

            foreach (var pixel in GetBinaryRowSearchIterator())
            {
                if (IsNewRow(pixel))
                {
                    runner.OnRowBegin();
                }

                runner.OnPixel(pixel.Color, previousColor);
                previousColor = pixel.Color;

                if (IsEndOfRow(pixel))
                {
                    var newResult = runner.OnRowEnd();

                    if (result == null)
                    {
                        result = newResult;
                    }

                    if (newResult.ConfidenceValue() == ColorContrastResult.Confidence.High)
                    {
                        result = newResult;
                        break;
                    }
                    else if (newResult.ConfidenceValue() == ColorContrastResult.Confidence.Mid &&
                             result.ConfidenceValue() == ColorContrastResult.Confidence.Low)
                    {
                        result = newResult;
                    }
                }
            }

            return(result);
        }