Exemplo n.º 1
0
        private void FloodFillScanlineStack(int x, int y, Color newColor, Color oldColor)
        {
            if (oldColor.ToArgb() == newColor.ToArgb())
            {
                return;
            }

            int        w     = args.bitmap.Width;
            int        h     = args.bitmap.Height;
            PixelStack stack = new PixelStack(w, h);

            int  y1;
            bool spanLeft, spanRight;

            if (!stack.Push(x, y))
            {
                return;
            }

            while (stack.Pop(ref x, ref y))
            {
                y1 = y;
                while (y1 >= 0 && GetPixel(x, y1) == oldColor)
                {
                    y1--;
                }
                y1++;
                spanLeft = spanRight = false;
                while (y1 < h && GetPixel(x, y1) == oldColor)
                {
                    SetPixel(x, y1, newColor);
                    if (!spanLeft && x > 0 && GetPixel(x - 1, y1) == oldColor)
                    {
                        if (!stack.Push(x - 1, y1))
                        {
                            return;
                        }
                        spanLeft = true;;
                    }
                    else if (spanLeft && x > 0 && GetPixel(x - 1, y1) != oldColor)
                    {
                        spanLeft = false;
                    }
                    if (!spanRight && x < w - 1 && GetPixel(x + 1, y1) == oldColor)
                    {
                        if (!stack.Push(x + 1, y1))
                        {
                            return;
                        }
                        spanRight = true;
                    }
                    else if (spanRight && x < w - 1 && x < w && GetPixel(x + 1, y1) != oldColor)
                    {
                        spanRight = false;
                    }
                    y1++;
                }
            }
        }
Exemplo n.º 2
0
        private void FloodFillScanlineStack(int x, int y, Color newColor, Color oldColor)
        {
            if (oldColor.ToArgb() == newColor.ToArgb())
            return;

              int w = args.bitmap.Width;
              int h = args.bitmap.Height;
              PixelStack stack = new PixelStack(w, h);

              int y1;
              bool spanLeft, spanRight;

              if (!stack.Push(x, y))
            return;

              while (stack.Pop(ref x, ref y)) {
            y1 = y;
            while (y1 >= 0 && GetPixel(x, y1) == oldColor) {
              y1--;
            }
            y1++;
            spanLeft = spanRight = false;
            while (y1 < h && GetPixel(x, y1) == oldColor) {
              SetPixel(x, y1, newColor);
              if (!spanLeft && x > 0 && GetPixel(x - 1, y1) == oldColor) {
            if (!stack.Push(x - 1, y1)) return;
            spanLeft = true; ;
              } else if (spanLeft && x > 0 && GetPixel(x - 1, y1) != oldColor) {
            spanLeft = false;
              }
              if (!spanRight && x < w - 1 && GetPixel(x + 1, y1) == oldColor) {
            if (!stack.Push(x + 1, y1)) return;
            spanRight = true;
              } else if (spanRight && x < w - 1 && x < w && GetPixel(x + 1, y1) != oldColor) {
            spanRight = false;
              }
              y1++;
            }
              }
        }