/// <summary> /// Fills the specified point on the bitmap with the currently selected fill color. /// </summary> /// <param name="pt">The starting point for the fill.</param> public override void FloodFill(System.Drawing.Point pt) { watch.Reset(); watch.Start(); //***Prepare for fill. PrepareForFloodFill(pt); ranges = new FloodFillRangeQueue(((bitmapWidth + bitmapHeight) / 2) * 5);//new Queue<FloodFillRange>(); //***Get starting color. int x = pt.X; int y = pt.Y; int idx = CoordsToByteIndex(ref x, ref y); startColor = new byte[] { bitmap.Pixels[idx], bitmap.Pixels[idx + 1], bitmap.Pixels[idx + 2] }; bool[] pixelsChecked = this.pixelsChecked; //***Do first call to floodfill. LinearFill(ref x, ref y); //***Call floodfill routine while floodfill ranges still exist on the queue while (ranges.Count > 0) { //**Get Next Range Off the Queue FloodFillRange range = ranges.Dequeue(); //**Check Above and Below Each Pixel in the Floodfill Range int downPxIdx = (bitmapWidth * (range.Y + 1)) + range.StartX; //CoordsToPixelIndex(lFillLoc,y+1); int upPxIdx = (bitmapWidth * (range.Y - 1)) + range.StartX; //CoordsToPixelIndex(lFillLoc, y - 1); int upY = range.Y - 1; //so we can pass the y coord by ref int downY = range.Y + 1; int tempIdx; for (int i = range.StartX; i <= range.EndX; i++) { //*Start Fill Upwards //if we're not above the top of the bitmap and the pixel above this one is within the color tolerance tempIdx = CoordsToByteIndex(ref i, ref upY); if (range.Y > 0 && (!pixelsChecked[upPxIdx]) && CheckPixel(ref tempIdx)) { LinearFill(ref i, ref upY); } //*Start Fill Downwards //if we're not below the bottom of the bitmap and the pixel below this one is within the color tolerance tempIdx = CoordsToByteIndex(ref i, ref downY); if (range.Y < (bitmapHeight - 1) && (!pixelsChecked[downPxIdx]) && CheckPixel(ref tempIdx)) { LinearFill(ref i, ref downY); } downPxIdx++; upPxIdx++; } } watch.Stop(); }
/// <summary> /// Fills the specified point on the bitmap with the fill value. /// </summary> /// <param name="pt">The starting point for the fill.</param> public override FillData FloodFill(Vector2Int pt) { ranges = new FloodFillRangeQueue(((gridWidth + gridHeight) / 2) * 5); int x = pt.x; int y = pt.y; //***Do first call to floodfill. LinearFill(ref x, ref y); //***Call floodfill routine while floodfill ranges still exist on the queue while (ranges.Count > 0) { //**Get Next Range Off the Queue FloodFillRange range = ranges.Dequeue(); //**Check Above and Below Each cell in the Floodfill Range int upY = range.Y - 1;//so we can pass the y coord by ref int downY = range.Y + 1; int i = range.StartX; if (range.StartX > 0) { i--; //check the diagonals } int downPxIdx = (gridWidth * (range.Y + 1)) + i; int upPxIdx = (gridWidth * (range.Y - 1)) + i; while (i <= range.EndX + 1 && i < gridWidth) { //*Start Fill Upwards //if we're not above the top of the grid and the cell above this one is free if (range.Y > 0 && (!gridCells[upPxIdx]) && CheckCell(ref upPxIdx)) { LinearFill(ref i, ref upY); } //*Start Fill Downwards //if we're not below the bottom of the grid and the pixel below this one is free if (range.Y < (gridHeight - 1) && (!gridCells[downPxIdx]) && CheckCell(ref downPxIdx)) { LinearFill(ref i, ref downY); } downPxIdx++; upPxIdx++; i++; } } return(new FillData(gridWidth, gridCells)); }