Deutsch English Français Italiano |
<utddb3$2ef83$1@i2pn2.org> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!weretis.net!feeder6.news.weretis.net!i2pn.org!i2pn2.org!.POSTED!not-for-mail From: fir <fir@grunge.pl> Newsgroups: comp.lang.c Subject: Re: filling area by color atack safety Date: Wed, 20 Mar 2024 02:15:32 +0100 Organization: i2pn2 (i2pn.org) Message-ID: <utddb3$2ef83$1@i2pn2.org> References: <ut3669$21eur$1@i2pn2.org> <ut4020$2s8ov$1@dont-email.me> <ut4b09$2uhpm$1@dont-email.me> <ut4cnc$2ut2t$1@dont-email.me> <ut70b4$3itvb$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Wed, 20 Mar 2024 01:15:15 -0000 (UTC) Injection-Info: i2pn2.org; logging-data="2571523"; mail-complaints-to="usenet@i2pn2.org"; posting-account="+ydHcGjgSeBt3Wz3WTfKefUptpAWaXduqfw5xdfsuS0"; User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:27.0) Gecko/20100101 Firefox/27.0 SeaMonkey/2.24 In-Reply-To: <ut70b4$3itvb$1@dont-email.me> X-Spam-Checker-Version: SpamAssassin 4.0.0 Bytes: 2908 Lines: 58 Malcolm McLean wrote: > On 16/03/2024 15:09, Malcolm McLean wrote: >> On 16/03/2024 14:40, David Brown wrote: >>> On 16/03/2024 12:33, Malcolm McLean wrote: >>> >>>> And here's some code I wrote a while ago. Use that as a pattern. But >>>> not sure how well it works. Haven't used it for a long time. >>>> >>>> https://github.com/MalcolmMcLean/binaryimagelibrary/blob/master/drawbinary.c >>>> >>>> >>> >>> Your implementation is a mess, /vastly/ more difficult to prove >>> correct than the OP's original one, and unlikely to be very much >>> faster (it will certainly scale in the same way in both time and >>> memory usage). >>> >> Now is this David Brown being David Borwn, ot its it actaully ture? > >> And I need to run some tests, don't I? >> > #include <stdio.h> > #include <stdlib.h> > #include <string.h> > #include <time.h> > > int floodfill_r(unsigned char *grey, int width, int height, int x, int y, > unsigned char target, unsigned char dest) > { > if (x < 0 || x >= width || y < 0 || y >= height) > return 0; > if (grey[y*width+x] != target) > return 0; > grey[y*width+x] = dest; > floodfill_r(grey, width, height, x - 1, y, target, dest); > floodfill_r(grey, width, height, x + 1, y, target, dest); > floodfill_r(grey, width, height, x, y - 1, target, dest); > floodfill_r(grey, width, height, x, y + 1, target, dest); > > return 0; > } > if someone would write simpler version i would write recolorize_pixel_chain(int x, int y) { if(map[y][x]==color_to_replace) { map[y][x]=replacement_color); recolorize_pixel_chain(x+1, y); recolorize_pixel_chain(x-1, y); recolorize_pixel_chain(x, y+1); recolorize_pixel_chain(x, y-1); } } but from practical coding the one with longer names is more practical imo - but this one above is more 'presenting'