Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!lll-winken!uunet!tektronix!tekgen!jonh From: jonh@tekgen.BV.TEK.COM (Jon Howell) Newsgroups: comp.graphics Subject: Re: Looking for simple fill algorithm Message-ID: <4344@tekgen.BV.TEK.COM> Date: 23 Apr 89 22:40:17 GMT References: <390030@hpfcdq.HP.COM> <1718@blake.acs.washington.edu> Reply-To: jonh@tekgen.BV.TEK.COM (Jon Howell) Organization: Tektronix, Inc., Beaverton, OR. Lines: 45 The basics are covered in Foley and Van Dam's _Fundamentals_of_Interactive_ _Computer_Graphics_, pp. 448-449 in pseudocode: A FLOOD FILL converts all adjecent values of the same color to another color. A BOUNDARY FILL converts all pixels within a certain-colored boundary to another color. Foley & Van Dam's FLOOD FILL code: procedure FLOOD_FILL_4( x, y, {Starting point} old_value, {value to convert} new_value: integer); {Color to conver to} begin if READ_PIXEL(x,y)=old_value then begin WRITE_PIXEL(x,y,new_value); {change color} {Attempt to propagate in four (eight) directions} FLOOD_FILL_4(x,y-1, old_value, new_value); {Repeat for (x,y+1..),(x-1,y..),(x+1,y..), and four more if you want an 8-bounded (diag.) region} end end procedure BOUNDARY_FILL_4( x, y, {Starting point} boundary_value, {boundary color} new_value: integer); {Color to fill with} {it is permissible to have new_value=boundary_value; otherwise no pixels may be initially set to new_value} [huh?!?] begin if READ_PIXEL(x,y)<>boundary_value {boundary not reached} and READ_PIXEL(x,y)<>new_value {and prev. filled pel not " } then begin WRITE_PIXEL(x, y, new_value); {change color} {four (eight) call to BOUNDARY FILL} end end Get the book. Lots of handy code and algoritms amid the explanations of hardware. Hope you can make sense of the PASCAL pseudocode. He shoulda used C. :-) --Jon -- jonh@tekgen.bv.tek.com (503) MAK-SEMA Jon Howell | Q: How come they never // // // _ __ _ . . . . ___ . _ | play that on the radio? // // // / \(_ __ (_) |\/| /| |\ | | /| / | A: They should. // // // \_/__) / | | /"| | \| _|_ /"| \_ | --Dave Barry