Re: fast fill routine/fractals

new topic     » goto parent     » topic index » view thread      » older message » newer message

Message text written by Nick Metcalfe
>Does anybody have a fast flood fill routine for complex outlines? The
offerings in the archive are quite slow. I want it for a boundary trace
fractal drawing method and at the moment the fill is slower than the trac=
e.
<

Here is a flood-fill routine based one one I used in a sprite editor
program.  There may be faster routines out there (I didn't look).  The
routine works for any complicated outline.  It can easily be modified to
fill with a pattern.  Since the math is simple, it could be coded in
assembler without too much difficulty.  - Colin Taylor

<code>
function fill(sequence bitmap, sequence start_loc, integer new_color)
-- fills contiguous pixels of old_color with new_color
    integer old_color, working
    sequence map
    old_color =3D bitmap[start_loc[2]][start_loc[1]]
    bitmap[start_loc[2]][start_loc[1]] =3D new_color
    map =3D repeat(repeat(0, length(bitmap[1])+2), length(bitmap)+2)
    map[start_loc[2]+1][start_loc[1]+1] =3D 1
    working =3D 1
    while working do
        -- forward pass
        working =3D 0
        for i =3D 1 to length(bitmap) do
            for j =3D 1 to length(bitmap[i]) do
                if bitmap[i][j] =3D old_color then
                    if (map[i][j+1] or map[i+1][j] or
                            map[i+2][j+1] or map[i+1][j+2]) then
                        bitmap[i][j] =3D new_color
                        map[i+1][j+1] =3D 1
                        working =3D 1
                    end if
                end if
            end for
        end for
        -- backward pass
        if working then
            working =3D 0
            for i =3D length(bitmap) to 1 by -1 do
                for j =3D length(bitmap[i]) to 1 by -1 do
                    if bitmap[i][j] =3D old_color then
                        if (map[i][j+1] or map[i+1][j] or
                                map[i+2][j+1] or map[i+1][j+2]) then
                            bitmap[i][j] =3D new_color
                            map[i+1][j+1] =3D 1
                            working =3D 1
                        end if
                    end if
                end for
            end for
        end if
    end while
    return bitmap
end function  -- fill
</code>

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu