/**
         * Run the Color Contrast calculation on the image.
         */
        public ColorContrastResult RunColorContrastCalculation()
        {
            var contrastResult = new ColorContrastResult();

            ColorContrastResult oldContrastResult = null;

            var colorContrastTransitions = new List <ColorContrastTransition>();

            Pixel lastPixel = new Pixel(Color.WHITE, 0, 0);

            foreach (var pixel in GetBinaryRowSearchIterator())
            {
                if (!lastPixel.Row.Equals(pixel.Row))
                {
                    if (contrastResult.ConfidenceValue().Equals(Confidence.High))
                    {
                        return(contrastResult);
                    }

                    if (oldContrastResult == null)
                    {
                        oldContrastResult = contrastResult;
                    }

                    if (contrastResult.ConfidenceValue() > oldContrastResult.ConfidenceValue())
                    {
                        oldContrastResult = contrastResult;
                    }
                }

                colorContrastTransitions.Add(new ColorContrastTransition(pixel.Color));

                foreach (var transition in colorContrastTransitions)
                {
                    transition.AddColor(pixel.Color);

                    if (transition.IsPotentialForegroundBackgroundPair())
                    {
                        contrastResult.OnColorPair(transition.ToColorPair());
                    }
                }

                colorContrastTransitions.RemoveAll(transition => transition.IsStartingAndEndingColorSame());

                lastPixel = pixel;
            }

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

            ColorContrastRunner runner = new ColorContrastRunner();

            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);
        }