Beispiel #1
0
 /// <summary>
 /// Adds brightness info to a <see cref="PixelColor"/>.
 /// </summary>
 /// <param name="pixel"></param>
 public static void AddBrightnessInfo(this PixelColor pixel)
 {
     pixel.Brightness = GetBrightness(pixel.Red, pixel.Green, pixel.Blue); // Corrected lightness
 }
Beispiel #2
0
        private void AnalyzeImages(ImageData image1, ImageData image2)
        {
            // Assumption: both images have the same size
            var width  = image1.Width;
            var height = image1.Height;

            var data1 = image1;
            var data2 = image2;

            var imgd      = new Bitmap(width, height);
            var targetPix = new ImageData(imgd); // Attention, this copies, keep in sync image and stream

            var mismatchCount = 0;

            var diffBounds = new DifferenceBounds()
            {
                Top    = height,
                Left   = width,
                Bottom = 0,
                Right  = 0
            };

            var stopwatch = new Stopwatch();

            stopwatch.Start();

            int skip = 0;

            if (this.LargeImageThreshold > 0 && this.IgnoreAntialiasing && (width > this.LargeImageThreshold || height > this.LargeImageThreshold))
            {
                skip = 6;
            }

            var pixel1 = new PixelColor()
            {
                Red = 0, Green = 0, Blue = 0, Alpha = 0
            };
            var pixel2 = new PixelColor()
            {
                Red = 0, Green = 0, Blue = 0, Alpha = 0
            };

            Func <bool> updateMetric = () =>
            {
                this.data.RawMisMatchPercentage = (double)mismatchCount / (double)(height * width) * 100;
                this.data.MisMatchPercentage    = this.data.RawMisMatchPercentage; // Should be truncated
                this.data.DiffBounds            = diffBounds;

                // Should we skip?
                return(this.threshold >= 0 && this.data.RawMisMatchPercentage > this.threshold);
            };

            ToolSet.Loop(height, width, (verticalPos, horizontalPos) =>
            {
                if (skip != 0) // Only skip if the image isn't small
                {
                    if (verticalPos % skip == 0 || horizontalPos % skip == 0)
                    {
                        return(true);
                    }
                }

                int offset = (verticalPos * width + horizontalPos) * 4;

                if (!ToolSet.GetPixelInfo(pixel1, data1, offset) || !ToolSet.GetPixelInfo(pixel2, data2, offset))
                {
                    return(true);
                }

                if (this.IgnoreColors)
                {
                    pixel1.AddBrightnessInfo();
                    pixel2.AddBrightnessInfo();

                    if (new PixelBrightnessSimilarChecker(pixel1, pixel2).Result)
                    {
                        ToolSet.CopyGrayScalePixel(targetPix, offset, pixel2);
                    }
                    else
                    {
                        this.ErrorPixelTransform.Transform(targetPix, offset, pixel1, pixel2);
                        mismatchCount++;
                        diffBounds.UpdateBounds(horizontalPos, verticalPos);

                        if (updateMetric())
                        {
                            return(false);
                        }
                    }

                    return(true);
                }

                if (new RGBSimilarChecker(pixel1, pixel2).Result)
                {
                    ToolSet.CopyPixel(targetPix, offset, pixel1 /*, pixel2*/);
                }
                else
                {
                    pixel1.AddBrightnessInfo();
                    pixel2.AddBrightnessInfo();

                    bool isAntialiased =
                        new PixelAntialiasedChecker(pixel1, data1, verticalPos, horizontalPos, width).Result ||
                        new PixelAntialiasedChecker(pixel2, data2, verticalPos, horizontalPos, width).Result;

                    if (this.IgnoreAntialiasing && isAntialiased)
                    {
                        if (new PixelBrightnessSimilarChecker(pixel1, pixel2).Result)
                        {
                            ToolSet.CopyGrayScalePixel(targetPix, offset, pixel2);
                        }
                        else
                        {
                            this.ErrorPixelTransform.Transform(targetPix, offset, pixel1, pixel2);
                            mismatchCount++;
                            diffBounds.UpdateBounds(horizontalPos, verticalPos);

                            if (updateMetric())
                            {
                                return(false);
                            }
                        }
                    }
                    else
                    {
                        this.ErrorPixelTransform.Transform(targetPix, offset, pixel1, pixel2);
                        mismatchCount++;
                        diffBounds.UpdateBounds(horizontalPos, verticalPos);

                        if (updateMetric())
                        {
                            return(false);
                        }
                    }
                }

                return(true);
            });

            updateMetric();

            stopwatch.Stop();
            this.data.AnalysisTime = stopwatch.Elapsed;
        }
Beispiel #3
0
 /// <summary>
 /// Adds hue info to a <see cref="PixelColor"/>.
 /// </summary>
 /// <param name="pixel"></param>
 public static void AddHueInfo(this PixelColor pixel)
 {
     pixel.Hue = GetHue(pixel.Red, pixel.Green, pixel.Blue);
 }