def fill_scan(self, point, old_colour, colour):
        to_fill = [point]
        while to_fill:
            x, y = to_fill.pop()
            while y > 0 and self.pixel(x, y - 1) == old_colour:
                y -= 1
            lspan = False
            rspan = False
            while y < self.size[1] and self.pixel(x, y) == old_colour:
                self.set_pixel(x, y, colour)

                if not lspan and x > 0 and self.pixel(x - 1, y) == old_colour:
                    to_fill.append((x - 1, y))
                    lspan = True
                elif lspan and x > 0 and self.pixel(x - 1, y) == old_colour:
                    lspan = False

                if (not rspan and x < self.size[0] - 1
                      and self.pixel(x + 1, y) == old_colour):
                    to_fill.append((x + 1, y))
                    rspan = True
                elif (rspan and x < self.size[0] - 1
                      and self.pixel(x + 1, y) == old_colour):
                    rspan = False

                y += 1
Scanline flood-fill. Fast, but I'm not entirely sure what it's doing.
dataset/ETHPy150Open jerith/depixel/depixel/io_png.py/Bitmap.fill_scan