Beispiel #1
0
        public void Colors()
        {
            var actual = Analysis.Colors.Black;
            var expected = new NativeColor(255, 0, 0, 0);
            AssertEx.AreEqual<NativeColor>(expected, actual);

            actual = Analysis.Colors.Blue;
            expected = new NativeColor(255, 0, 0, 255);
            AssertEx.AreEqual<NativeColor>(expected, actual);

            actual = Analysis.Colors.Green;
            expected = new NativeColor(255, 0, 255, 0);
            AssertEx.AreEqual<NativeColor>(expected, actual);

            actual = Analysis.Colors.Red;
            expected = new NativeColor(255, 255, 0, 0);
            AssertEx.AreEqual<NativeColor>(expected, actual);

            actual = Analysis.Colors.Transparent;
            expected = new NativeColor(0, 0, 0, 0);
            AssertEx.AreEqual<NativeColor>(expected, actual);

            actual = Analysis.Colors.White;
            expected = new NativeColor(255, 255, 255, 255);
            AssertEx.AreEqual<NativeColor>(expected, actual);
        }
Beispiel #2
0
        public void ToArgb()
        {
            var nc = new NativeColor(255, 0, 0, 0);
            int actual = nc.ToArgb();
            var c = Color.FromArgb(255, 0, 0, 0);
            int expected = c.ToArgb();
            AssertEx.AreEqual<int>(expected, actual);

            nc = new NativeColor(1, 2, 3, 4);
            actual = nc.ToArgb();
            c = Color.FromArgb(1, 2, 3, 4);
            expected = c.ToArgb();
            AssertEx.AreEqual<int>(expected, actual);

            nc = new NativeColor(255, 255, 255, 255);
            actual = nc.ToArgb();
            c = Color.FromArgb(255, 255, 255, 255);
            expected = c.ToArgb();
            AssertEx.AreEqual<int>(expected, actual);

            nc = new NativeColor(0, 255, 255, 255);
            actual = nc.ToArgb();
            c = Color.FromArgb(0, 255, 255, 255);
            expected = c.ToArgb();
            AssertEx.AreEqual<int>(expected, actual);

            nc = new NativeColor(255, 0, 0, 0);
            actual = nc.ToArgb();
            c = Color.FromArgb(255, 0, 0, 0);
            expected = c.ToArgb();
            AssertEx.AreEqual<int>(expected, actual);
        }
Beispiel #3
0
 /// <summary>Iterates through a set of <see cref="T:System.Drawing.Analysis.Manipulation.Pixel"/>s and sets the <see cref="T:System.Drawing.Analysis.NativeColor"/> using a given <see cref="T:System.Drawing.Analysis.ISetPixelProvider"/>.</summary>
 /// <param name="source">The source.</param>
 /// <param name="color">The <see cref="T:System.Drawing.Analysis.NativeColor"/> to set the <see cref="T:System.Drawing.Analysis.Manipulation.Pixel"/> to.</param>
 /// <param name="provider">The <see cref="T:System.Drawing.Analysis.ISetPixelProvider"/> that will be used to perform the SetPixel operation.</param>
 /// <returns>An <see cref="T:System.Collections.Generic.IEnumerable{Pixel}"/> with the new colors set.</returns>
 public static IEnumerable<Pixel> SetColor(this IEnumerable<Pixel> source, NativeColor color, ISetPixelProvider provider)
 {
     if (provider == null)
         throw new ArgumentNullException("provider");
     foreach (var item in source)
     {
         provider.SetPixel(item.X, item.Y, color);
         yield return new Pixel(item.X, item.Y, color);
     }
 }
Beispiel #4
0
        /// <summary>Determines whether all pixels of the provider are the same color.</summary>
        /// <param name="color">The <see cref="T:System.Drawing.Analysis.NativeColor"/>.</param>
        /// <returns>true if every pixel is the same color, or if the sequence is empty; otherwise, false.</returns>
        public bool All(NativeColor color)
        {
            int targetX = GetTargetX;
            int targetY = GetTargetY;

            for (int x = _view.X; x < targetX; ++x)
                for (int y = _view.Y; y < targetY; ++y)
                    if (color != _provider.GetPixel(x, y))
                        return false;
            return true;
        }
Beispiel #5
0
        /// <summary>Creates a new instance of <see cref="T:System.Drawing.Analysis.ColorToleranceBorders"/> from a given <see cref="T:System.Drawing.Analysis.NativeColor"/> and <see cref="T:System.Drawing.Analysis.ColorTolerance"/>.</summary>
        /// <param name="baseColor">The <see cref="T:System.Drawing.Analysis.NativeColor"/>.</param>
        /// <param name="tolerance">The <see cref="T:System.Drawing.Analysis.ColorTolerance"/>.</param>
        public ColorToleranceBorders(NativeColor baseColor, ColorTolerance tolerance)
        {
            _baseColor = baseColor;
            _baseTolerance = tolerance;

            _minA = (baseColor.A < tolerance.A ? 0 : (baseColor.A - tolerance.A));
            _minR = (baseColor.R < tolerance.R ? 0 : (baseColor.R - tolerance.R));
            _minG = (baseColor.G < tolerance.G ? 0 : (baseColor.G - tolerance.G));
            _minB = (baseColor.B < tolerance.B ? 0 : (baseColor.B - tolerance.B));

            _maxA = (baseColor.A + tolerance.A > 255) ? 255 : (baseColor.A + tolerance.A);
            _maxR = (baseColor.R + tolerance.R > 255) ? 255 : (baseColor.R + tolerance.R);
            _maxG = (baseColor.G + tolerance.G > 255) ? 255 : (baseColor.G + tolerance.G);
            _maxB = (baseColor.B + tolerance.B > 255) ? 255 : (baseColor.B + tolerance.B);
        }
Beispiel #6
0
        /// <summary>Clears the current view using a specific <see cref="T:System.Drawing.Analysis.NativeColor"/>.</summary>
        /// <param name="color">The <see cref="T:System.Drawing.Analysis.NativeColor"/>.</param>
        public void Clear(NativeColor color)
        {
            // TODO: Unit testing
            int targetX = GetTargetX;
            int targetY = GetTargetY;

            var view = View;

            for (int x = view.X; x < targetX; ++x)
            {
                for (int y = view.Y; y < targetY; ++y)
                {
                    _provider.SetPixel(x, y, color);
                }
            }
        }
 public override void SetPixel(Point point, NativeColor color)
 {
     Bitmap.SetPixel(point.X, point.Y, color.ToDrawingColor());
 }
Beispiel #8
0
 /// <summary>Determines whether all pixels of the provider are the same color.</summary>
 /// <param name="color">The <see cref="T:System.Drawing.Analysis.NativeColor"/>.</param>
 /// <param name="tolerance">The <see cref="T:System.Drawing.Analysis.ColorTolerance"/>.</param>
 /// <returns>true if every pixel is the same color, or if the sequence is empty; otherwise, false.</returns>
 public bool All(NativeColor color, ColorTolerance tolerance)
 {
     throw new NotImplementedException();
 }
 public override void SetPixel(int x, int y, NativeColor color)
 {
     Bitmap.SetPixel(x, y,  color.ToDrawingColor());
 }
Beispiel #10
0
        /// <summary>Gets the first <see cref="T:System.Drawing.Analysis.Manipulation.Pixel"/> matching a specified color taking care of a given tolerance.</summary>
        /// <param name="color">The <see cref="T:System.Drawing.Analysis.NativeColor"/> to find.</param>
        /// <param name="tolerance">The <see cref="T:System.Drawing.Analysis.ColorTolerance"/>.</param>
        /// <returns>A <see cref="T:System.Drawing.Analysis.Manipulation.Pixel"/> instance which represents the found pixel. If there is none, the method returns the default value of <see cref="T:System.Drawing.Analysis.Manipulation.Pixel"/>.</returns>
        public Pixel? FirstOrDefault(NativeColor color, ColorTolerance tolerance)
        {
            int targetX = GetTargetX;
            int targetY = GetTargetY;

            ColorToleranceBorders borders = new ColorToleranceBorders(color, tolerance);

            for (int x = _view.X; x < targetX; ++x)
                for (int y = _view.Y; y < targetY; ++y)
                {
                    var readColor = _provider.GetPixel(x, y);
                    if (_provider.GetPixel(x, y).FitsTolerance(borders, tolerance))
                        return new Pixel(x, y, readColor);
                }

            return default(Pixel?);
        }
Beispiel #11
0
 /// <summary>Determines whether all pixels of the provider are the same color respecting a given tolerance.</summary>
 /// <param name="color">The <see cref="T:System.Drawing.Analysis.NativeColor"/>.</param>
 /// <returns>true if every pixel is the same color, or if the sequence is empty; otherwise, false.</returns>
 public bool All(NativeColor color)
 {
     throw new NotImplementedException();
 }
Beispiel #12
0
 /// <summary>Sets The <see cref="T:System.Drawing.Analysis.NativeColor"/> of the specified pixel in this provider.</summary>
 /// <param name="point">The coordinates of the pixel to set.</param>
 /// <param name="color">A NativeColor structure that represents The <see cref="T:System.Drawing.Analysis.NativeColor"/> to assign to the specified pixel.</param>
 public abstract void SetPixel(Point point, NativeColor color);
Beispiel #13
0
        /// <summary>Gets the first <see cref="T:System.Drawing.Analysis.Manipulation.Pixel"/> matching a specified color.</summary>
        /// <param name="color">The <see cref="T:System.Drawing.Analysis.NativeColor"/> to find.</param>
        /// <returns>A <see cref="T:System.Drawing.Analysis.Manipulation.Pixel"/> instance which represents the found pixel. If there is none, the method returns the default value of <see cref="T:System.Drawing.Analysis.Manipulation.Pixel"/>.</returns>
        public Pixel? FirstOrDefault(NativeColor color)
        {
            int targetX = GetTargetX;
            int targetY = GetTargetY;

            for (int x = _view.X; x < targetX; ++x)
                for (int y = _view.Y; y < targetY; ++y)
                {
                    var readColor = _provider.GetPixel(x, y);
                    if (color == readColor)
                        return new Pixel(x, y, readColor);
                }

            return default(Pixel?);
        }
Beispiel #14
0
 /// <summary>Returns the number of pixels in the current view matching a given <see cref="T:System.Drawing.Analysis.NativeColor"/> respecting a tolerance.</summary>
 /// <param name="color">The <see cref="T:System.Drawing.Analysis.NativeColor"/>.</param>
 /// <param name="tolerance">The <see cref="T:System.Drawing.Analysis.ColorTolerance"/>.</param>
 /// <returns>The number of pixels in the current view matching a given <see cref="T:System.Drawing.Analysis.NativeColor"/> respecting a tolerance.</returns>
 public int Count(NativeColor color, ColorTolerance tolerance)
 {
     throw new NotImplementedException();
 }
Beispiel #15
0
 /// <summary>Creates a new <see cref="T:System.Drawing.Analysis.Manipulation.Pixel"/> instance using the given parameters.</summary>
 /// <param name="x">The x-coordinate of the pixel.</param>
 /// <param name="y">The y-coordinate of the pixel.</param>
 /// <param name="color">A <see cref="T:System.Drawing.Analysis.NativeColor"/> instance that represents the color of the pixel.</param>
 public Pixel(int x, int y, NativeColor color)
 {
     _x = x;
     _y = y;
     _color = color;
 }
 /// <summary>Swaps a pixel color at a specific location with the given one.</summary>
 /// <param name="x">The x-coordinate of the pixel to set.</param>
 /// <param name="y">The y-coordinate of the pixel to set.</param>
 /// <param name="color">A NativeColor structure that represents The <see cref="T:System.Drawing.Analysis.NativeColor"/> to assign to the specified pixel.</param>
 /// <returns>A NativeColor structure that represents the previous color of the specified pixel.</returns>
 public override NativeColor SwapPixel(int x, int y, NativeColor color)
 {
     if (x >= Size.Width || y >= Size.Height)
         throw new InvalidOperationException();
     return SwapPixelInternal(x, y, color);
 }
Beispiel #17
0
 /// <summary>Returns the number of pixels in the current view matching a given <see cref="T:System.Drawing.Analysis.NativeColor"/>.</summary>
 /// <param name="color">The <see cref="T:System.Drawing.Analysis.NativeColor"/>.</param>
 /// <returns>The number of pixels in the current view matching a given <see cref="T:System.Drawing.Analysis.NativeColor"/>.</returns>
 public int Count(NativeColor color)
 {
     throw new NotImplementedException();
 }
        private unsafe NativeColor SwapPixelInternal(int x, int y, NativeColor color)
        {
            int index = Size.Width * y + x;

            var c = _scan0[index];
            _scan0[index] = color;
            return c;
        }
 /// <summary>Sets The <see cref="T:System.Drawing.Analysis.NativeColor"/> of the specified pixel in this provider.</summary>
 /// <param name="point">The coordinates of the pixel to set.</param>
 /// <param name="color">A NativeColor structure that represents The <see cref="T:System.Drawing.Analysis.NativeColor"/> to assign to the specified pixel.</param>
 public override void SetPixel(Point point, NativeColor color)
 {
     if (point.X >= Size.Width || point.Y >= Size.Height)
         throw new InvalidOperationException();
     SetPixelInternal(point.X, point.Y, color);
 }
        private unsafe void SetPixelInternal(int x, int y, NativeColor color)
        {
#if USEUNCHECKED
            unchecked
            {
#endif
                int index = Size.Width * y + x;
                _scan0[index] = color;
#if USEUNCHECKED
            }
#endif
        }
 /// <summary>Swaps a pixel color at a specific location with the given one.</summary>
 /// <param name="x">The x-coordinate of the pixel to set.</param>
 /// <param name="y">The y-coordinate of the pixel to set.</param>
 /// <param name="color">A NativeColor structure that represents The <see cref="T:System.Drawing.Analysis.NativeColor"/> to assign to the specified pixel.</param>
 /// <returns>A NativeColor structure that represents the previous color of the specified pixel.</returns>
 public override NativeColor SwapPixel(int x, int y, NativeColor color)
 {
     var c = GetPixel(x, y);
     SetPixel(x, y, color);
     return c;
 }
Beispiel #22
0
        /// <summary>Gets the first <see cref="T:System.Drawing.Analysis.Manipulation.Pixel"/> matching a specified color taking care of a given tolerance.</summary>
        /// <param name="color">The <see cref="T:System.Drawing.Analysis.NativeColor"/> to find.</param>
        /// <param name="tolerance">The <see cref="T:System.Drawing.Analysis.ColorTolerance"/>.</param>
        /// <returns>A <see cref="T:System.Drawing.Analysis.Manipulation.Pixel"/> instance which represents the found pixel.</returns>
        public Pixel First(NativeColor color, ColorTolerance tolerance)
        {
            int targetX = GetTargetX;
            int targetY = GetTargetY;

            ColorToleranceBorders borders = new ColorToleranceBorders(color, tolerance);

            for (int x = _view.X; x < targetX; ++x)
                for (int y = _view.Y; y < targetY; ++y)
                {
                    var readColor = _provider.GetPixel(x, y);
                    if (_provider.GetPixel(x, y).FitsTolerance(borders, tolerance))
                        return new Pixel(x, y, readColor);
                }

            throw new InvalidOperationException();
        }
Beispiel #23
0
 /// <summary>Sets The <see cref="T:System.Drawing.Analysis.NativeColor"/> of the specified pixel in this provider.</summary>
 /// <param name="x">The x-coordinate of the pixel to set.</param>
 /// <param name="y">The y-coordinate of the pixel to set.</param>
 /// <param name="color">A NativeColor structure that represents The <see cref="T:System.Drawing.Analysis.NativeColor"/> to assign to the specified pixel.</param>
 public abstract void SetPixel(int x, int y, NativeColor color);
Beispiel #24
0
 /// <summary>Gets the first <see cref="T:System.Drawing.Analysis.Manipulation.Pixel"/> matching a specified color.</summary>
 /// <param name="color">The <see cref="T:System.Drawing.Analysis.NativeColor"/> to find.</param>
 /// <returns>A <see cref="T:System.Drawing.Analysis.Manipulation.Pixel"/> instance which represents the found pixel. If there is none, the method returns the default value of <see cref="T:System.Drawing.Analysis.Manipulation.Pixel"/>.</returns>
 public Pixel? FirstOrDefault(NativeColor color)
 {
     throw new NotImplementedException();
 }
Beispiel #25
0
 /// <summary>Swaps a pixel color at a specific location with the given one.</summary>
 /// <param name="x">The x-coordinate of the pixel to set.</param>
 /// <param name="y">The y-coordinate of the pixel to set.</param>
 /// <param name="color">A NativeColor structure that represents The <see cref="T:System.Drawing.Analysis.NativeColor"/> to assign to the specified pixel.</param>
 /// <returns>A NativeColor structure that represents the previous color of the specified pixel.</returns>
 public abstract NativeColor SwapPixel(int x, int y, NativeColor color);
Beispiel #26
0
 /// <summary>Gets the first <see cref="T:System.Drawing.Analysis.Manipulation.Pixel"/> matching a specified color respecting a given tolerance.</summary>
 /// <param name="color">The <see cref="T:System.Drawing.Analysis.NativeColor"/> to find.</param>
 /// <param name="tolerance">The <see cref="T:System.Drawing.Analysis.ColorTolerance"/>.</param>
 /// <returns>A <see cref="T:System.Drawing.Analysis.Manipulation.Pixel"/> instance which represents the found pixel. If there is none, the method returns the default value of <see cref="T:System.Drawing.Analysis.Manipulation.Pixel"/>.</returns>
 public Pixel? FirstOrDefault(NativeColor color, ColorTolerance tolerance)
 {
     throw new NotImplementedException();
 }
Beispiel #27
0
 /// <summary>Filters the pixels matching a color respecting a given tolerance.</summary>
 /// <param name="color">The <see cref="T:System.Drawing.Analysis.NativeColor"/>.</param>
 /// <param name="tolerance">The <see cref="T:System.Drawing.Analysis.ColorTolerance"/>.</param>
 /// <returns>An <see cref="T:System.Collections.Generic.IEnumerable{T}"/> that contains <see cref="T:System.Drawing.Analysis.Manipulation.Pixel"/>s which matched the given color and tolerance.</returns>
 public IEnumerable<Pixel> FindPixels(NativeColor color, ColorTolerance tolerance)
 {
     throw new NotImplementedException();
 }
Beispiel #28
0
        /// <summary>Determines whether all pixels of the provider are the same color respecting a given tolerance.</summary>
        /// <param name="color">The <see cref="T:System.Drawing.Analysis.NativeColor"/>.</param>
        /// <param name="tolerance">The <see cref="T:System.Drawing.Analysis.ColorTolerance"/>.</param>
        /// <returns>true if every pixel is the same color, or if the sequence is empty; otherwise, false.</returns>
        public bool All(NativeColor color, ColorTolerance tolerance)
        {
            int targetX = GetTargetX;
            int targetY = GetTargetY;

            ColorToleranceBorders borders = new ColorToleranceBorders(color, tolerance);

            for (int x = _view.X; x < targetX; ++x)
                for (int y = _view.Y; y < targetY; ++y)
                    if (_provider.GetPixel(x, y).NotFitsTolerance(borders, tolerance)) // FitNot (!)
                        return false;
            return true;
        }
Beispiel #29
0
 /// <summary>Gets the first <see cref="T:System.Drawing.Analysis.Manipulation.Pixel"/> matching a specified color.</summary>
 /// <param name="color">The <see cref="T:System.Drawing.Analysis.NativeColor"/> to find.</param>
 /// <returns>A <see cref="T:System.Drawing.Analysis.Manipulation.Pixel"/> instance which represents the found pixel.</returns>
 public Pixel First(NativeColor color)
 {
     throw new NotImplementedException();
 }
Beispiel #30
0
        //see: http://msdn.microsoft.com/en-us/library/bb535050.aspx
        /// <summary>Gets the first <see cref="T:System.Drawing.Analysis.Manipulation.Pixel"/> matching a specified color.</summary>
        /// <param name="color">The <see cref="T:System.Drawing.Analysis.NativeColor"/> to find.</param>
        /// <returns>A <see cref="T:System.Drawing.Analysis.Manipulation.Pixel"/> instance which represents the found pixel.</returns>
        public Pixel First(NativeColor color)
        {
            int targetX = GetTargetX;
            int targetY = GetTargetY;

            for (int x = _view.X; x < targetX; ++x)
                for (int y = _view.Y; y < targetY; ++y)
                {
                    var readColor = _provider.GetPixel(x, y);
                    if (color == readColor)
                        return new Pixel(x, y, readColor);
                }

            throw new InvalidOperationException();
        }