floodFill method
Implementation
Future<void> floodFill(int x, int y) async {
// Setup
_prepare();
// ***Do first call to floodfill.
_linearFill(x, y);
// ***Call floodfill routine while floodfill _ranges still exist on the
// queue
_FloodFillRange range;
while (_ranges.isNotEmpty) {
// **Get Next Range Off the Queue
range = _ranges.removeFirst();
// **Check Above and Below Each Pixel in the Floodfill Range
int downPxIdx = (_width * (range.y + 1)) + range.startX;
int upPxIdx = (_width * (range.y - 1)) + range.startX;
int upY = range.y - 1; // so we can pass the y coord by ref
int downY = range.y + 1;
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
if (range.y > 0 && (!_pixelsChecked[upPxIdx]) && _checkPixel(i, upY)) {
_linearFill(i, 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
if (range.y < (_height - 1) &&
(!_pixelsChecked[downPxIdx]) &&
_checkPixel(i, downY)) {
_linearFill(i, downY);
}
downPxIdx++;
upPxIdx++;
}
}
}