Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Michael S Newsgroups: comp.lang.c Subject: Re: filling area by color atack safety Date: Sun, 17 Mar 2024 15:15:19 +0200 Organization: A noiseless patient Spider Lines: 67 Message-ID: <20240317151519.000057d0@yahoo.com> References: <20240317144625.00002011@yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Injection-Info: dont-email.me; posting-host="fd62a22e31fcf9828d4eedf77229489a"; logging-data="3724928"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/qNBf2kSofoBTEHH9Ta/1bisREOH76Yic=" Cancel-Lock: sha1:gxq707c1mH/gP5qORcl27UVtxWQ= X-Newsreader: Claws Mail 3.19.1 (GTK+ 2.24.33; x86_64-w64-mingw32) Bytes: 3737 On Sun, 17 Mar 2024 12:54:34 +0000 bart wrote: > On 17/03/2024 12:46, Michael S wrote: > > On Sat, 16 Mar 2024 11:33:20 +0000 > > Malcolm McLean wrote: > > =20 > >> On 16/03/2024 04:11, fir wrote: =20 > >>> 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=C2=A0 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) > >>> { > >>> =C2=A0 if(old_color =3D=3D new_color) return 0; > >>> > >>> =C2=A0 if(XYIsInScreen( x,=C2=A0 y)) > >>> =C2=A0 if(GetPixelUnsafe(x,y)=3D=3Dold_color) > >>> =C2=A0 { > >>> =C2=A0=C2=A0=C2=A0 SetPixelSafe(x,y,new_color); > >>> =C2=A0=C2=A0=C2=A0 RecolorizePixelAndAdjacentOnes(x+1, y,=C2=A0 old= _color, > >>> new_color); RecolorizePixelAndAdjacentOnes(x-1, y,=C2=A0 old_color, > >>> new_color); RecolorizePixelAndAdjacentOnes(x, y-1,=C2=A0 old_color, > >>> new_color); RecolorizePixelAndAdjacentOnes(x, y+1,=C2=A0 old_color, > >>> new_color); return 1; > >>> =C2=A0 } > >>> > >>> =C2=A0 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? > >> > =20 > >> This is a cheap and cheerful fllod fill. And it's easy to get right > >> and shouldn't afall over. =20 > >=20 > > Except I don't understand why it works it all. > > Can't fill area have sub-areas that only connected through > > diagonal? =20 >=20 > Suppose you have an image which is a chessboard. You want to fill one > of the black squares so that it is red. >=20 > If you allow connectivity through the diagonals (so two notionally=20 > square pixels that only meet at their corners would be connected), > then all the black squares would turn red, not just one. >=20 That's what I want. Do fir wants something else?