Path: ...!weretis.net!feeder6.news.weretis.net!i2pn.org!i2pn2.org!.POSTED!not-for-mail From: fir Newsgroups: comp.lang.c Subject: filling area by color atack safety Date: Sat, 16 Mar 2024 05:11:44 +0100 Organization: i2pn2 (i2pn.org) Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sat, 16 Mar 2024 04:11:54 -0000 (UTC) Injection-Info: i2pn2.org; logging-data="2145243"; 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 X-Spam-Checker-Version: SpamAssassin 4.0.0 Bytes: 2316 Lines: 37 i was writing simple editor (something like paint but more custom for my eventual needs) for big pixel (low resolution) drawing it showed in a minute i need a click for changing given drawed area of of one color into another color (becouse if no someone would need to do it by hand pixel by pixel and the need to change color of given element is very common) there is very simple method of doing it - i men i click in given color pixel then replace it by my color and call the same function on adjacent 4 pixels (only need check if it is in screen at all and if the color to change is that initial color int RecolorizePixelAndAdjacentOnes(int x, int y, unsigned old_color, unsigned new_color) { if(old_color == new_color) return 0; if(XYIsInScreen( x, y)) if(GetPixelUnsafe(x,y)==old_color) { SetPixelSafe(x,y,new_color); RecolorizePixelAndAdjacentOnes(x+1, y, old_color, new_color); RecolorizePixelAndAdjacentOnes(x-1, y, old_color, new_color); RecolorizePixelAndAdjacentOnes(x, y-1, old_color, new_color); RecolorizePixelAndAdjacentOnes(x, y+1, old_color, new_color); return 1; } return 0; } it work but im not quite sure how to estimate the safety of this - incidentally as i said i use this editor to low res graphics like 200x200 pixels or less, and it is only a toll of private use, yet i got no time to work on it more than 1-2-3 days i guess but still is there maybe simple way to improve it?