Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Within a computer, natural language is unnatural.


devel / comp.lang.c / filling area by color atack safety

SubjectAuthor
* filling area by color atack safetyfir
+* Re: filling area by color atack safetyMalcolm McLean
|+* Re: filling area by color atack safetyBen Bacarisse
||+* Re: filling area by color atack safetybart
|||+- Re: filling area by color atack safetyBen Bacarisse
|||+* Re: filling area by color atack safetyTim Rentsch
||||`* Re: filling area by color atack safetyMichael S
|||| +- Re: filling area by color atack safetyTim Rentsch
|||| `* Re: filling area by color atack safetyfir
||||  `* Re: filling area by color atack safetybart
||||   +- Re: filling area by color atack safetybart
||||   +- Re: filling area by color atack safetyfir
||||   `- Re: filling area by color atack safetyDavid Brown
|||`- Re: filling area by color atack safetyTim Rentsch
||`* Re: filling area by color atack safetyMalcolm McLean
|| +* Re: filling area by color atack safetyScott Lurndal
|| |+* Re: filling area by color atack safetyMalcolm McLean
|| ||+* Re: filling area by color atack safetyChris M. Thomasson
|| |||`* Re: filling area by color atack safetyChris M. Thomasson
|| ||| `- Re: filling area by color atack safetyMichael S
|| ||`- Re: filling area by color atack safetyfir
|| |`- Re: filling area by color atack safetyMichael S
|| `* Re: filling area by color atack safetyBen Bacarisse
||  `* Re: filling area by color atack safetyMalcolm McLean
||   +- Re: filling area by color atack safetyKaz Kylheku
||   +- Re: filling area by color atack safetyBen Bacarisse
||   `* Re: filling area by color atack safetyScott Lurndal
||    `* Re: filling area by color atack safetyTim Rentsch
||     `* Re: filling area by color atack safetyScott Lurndal
||      `- Re: filling area by color atack safetyTim Rentsch
|+* Re: filling area by color atack safetyDavid Brown
||+* Re: filling area by color atack safetyMalcolm McLean
|||+* Re: filling area by color atack safetyMalcolm McLean
||||+- Re: filling area by color atack safetyMichael S
||||+* Re: filling area by color atack safetyMichael S
|||||+* Re: filling area by color atack safetyMichael S
||||||`* Re: filling area by color atack safetyTim Rentsch
|||||| `* Re: filling area by color atack safetyMalcolm McLean
||||||  `* Re: filling area by color atack safetyTim Rentsch
||||||   `- Re: filling area by color atack safetyMalcolm McLean
|||||`* Re: filling area by color atack safetyfir
||||| `* Re: filling area by color atack safetyMichael S
|||||  `* Re: filling area by color atack safetyfir
|||||   `* Re: filling area by color atack safetyMichael S
|||||    `* Re: filling area by color atack safetyfir
|||||     `* Re: filling area by color atack safetyMichael S
|||||      `- Re: filling area by color atack safetyfir
||||`- Re: filling area by color atack safetyfir
|||`* Re: filling area by color atack safetyDavid Brown
||| `* Re: filling area by color atack safetyMalcolm McLean
|||  `* Re: filling area by color atack safetyDavid Brown
|||   `* Re: filling area by color atack safetyMalcolm McLean
|||    `* Re: filling area by color atack safetyDavid Brown
|||     `* Re: filling area by color atack safetyMalcolm McLean
|||      +* Re: filling area by color atack safetyScott Lurndal
|||      |+- Re: filling area by color atack safetybart
|||      |`* Re: filling area by color atack safetyDavid Brown
|||      | `- Re: filling area by color atack safetyRichard Harnden
|||      +* Re: filling area by color atack safetyKeith Thompson
|||      |+- Keith-world (Was: filling area by color atack safety)Kenny McCormack
|||      |`- Re: filling area by color atack safetyDavid Brown
|||      +- Re: filling area by color atack safetyChris M. Thomasson
|||      `- Re: filling area by color atack safetyDavid Brown
||+* Re: filling area by color atack safetyScott Lurndal
|||`* Re: filling area by color atack safetyBen Bacarisse
||| +* Re: filling area by color atack safetyMalcolm McLean
||| |`- Re: filling area by color atack safetybart
||| `- Re: filling area by color atack safetyDavid Brown
||`* Re: filling area by color atack safetyfir
|| `- Re: filling area by color atack safetyfir
|+* Re: filling area by color atack safetyMichael S
||+* Re: filling area by color atack safetybart
|||`* Re: filling area by color atack safetyMichael S
||| `* Re: filling area by color atack safetybart
|||  +* Re: filling area by color atack safetyMichael S
|||  |`- Re: filling area by color atack safetyDavid Brown
|||  `* Re: filling area by color atack safetyBen Bacarisse
|||   `* Re: filling area by color atack safetySpiros Bousbouras
|||    `* Re: filling area by color atack safetyBen Bacarisse
|||     `- Re: filling area by color atack safetybart
||+* Re: filling area by color atack safetyTim Rentsch
|||`* Re: filling area by color atack safetyMalcolm McLean
||| `* Re: filling area by color atack safetyTim Rentsch
|||  `* Re: filling area by color atack safetyMalcolm McLean
|||   `- Re: filling area by color atack safetyTim Rentsch
||`* Re: filling area by color atack safetyfir
|| `* Re: filling area by color atack safetyMichael S
||  `- Re: filling area by color atack safetyfir
|`* Re: filling area by color atack safetyLew Pitcher
| +- Re: filling area by color atack safetybart
| `* Re: filling area by color atack safetyPeter 'Shaggy' Haywood
|  `- Re: filling area by color atack safetyfir
+* Re: filling area by color atack safetybart
|+* Re: filling area by color atack safetybart
||`- Re: filling area by color atack safetyMalcolm McLean
|`* Re: filling area by color atack safetyfir
| `* Re: filling area by color atack safetyPeter 'Shaggy' Haywood
|  +* Re: filling area by color atack safetyMichael S
|  |`- Re: filling area by color atack safetyMichael S
|  `- Re: filling area by color atack safetyfir
+- Re: filling area by color atack safetyPeter 'Shaggy' Haywood
`* Re: filling area by color atack safetyTim Rentsch

Pages:1234567
filling area by color atack safety

<ut3669$21eur$1@i2pn2.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34407&group=comp.lang.c#34407

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!.POSTED!not-for-mail
From: fir...@grunge.pl (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: <ut3669$21eur$1@i2pn2.org>
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
 by: fir - Sat, 16 Mar 2024 04:11 UTC

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?

Re: filling area by color atack safety

<ut4020$2s8ov$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34408&group=comp.lang.c#34408

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: malcolm....@gmail.com (Malcolm McLean)
Newsgroups: comp.lang.c
Subject: Re: filling area by color atack safety
Date: Sat, 16 Mar 2024 11:33:20 +0000
Organization: A noiseless patient Spider
Lines: 61
Message-ID: <ut4020$2s8ov$1@dont-email.me>
References: <ut3669$21eur$1@i2pn2.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 16 Mar 2024 11:33:20 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="0ac9f1a8c1dfcfccfb5694c886ca1efb";
logging-data="3023647"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18wlXCiM5M0atzSqvJj6Pmf5jKXsgE77Oo="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:Rgti+mMJ6G1smajQ+3M93NkFZzk=
In-Reply-To: <ut3669$21eur$1@i2pn2.org>
Content-Language: en-GB
 by: Malcolm McLean - Sat, 16 Mar 2024 11:33 UTC

On 16/03/2024 04:11, fir wrote:
> 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?
>
This is a cheap and cheerful fllod fill. And it's easy to get right and
shouldn't afall over. But but makes an awful not of unnecessary calls,
and on a small system and large image might even blow the stack.

Recursion make programs harder to reason about and prove correct.

So a real flood fill doesn't work like that. You use a queue and put the
pixels to be filled into that, and trace lines.

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

--
Check out Basic Algorithms and my other books:
https://www.lulu.com/spotlight/bgy1mm

Re: filling area by color atack safety

<87wmq2jn7s.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34409&group=comp.lang.c#34409

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.c
Subject: Re: filling area by color atack safety
Date: Sat, 16 Mar 2024 13:55:03 +0000
Organization: A noiseless patient Spider
Lines: 9
Message-ID: <87wmq2jn7s.fsf@bsb.me.uk>
References: <ut3669$21eur$1@i2pn2.org> <ut4020$2s8ov$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="bf33b7c7e83e08eff7dcc0646008df90";
logging-data="3078065"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+uG+2DH10GJ9QpHE1arQr8B72eE56jK6Y="
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:gUFX2qVvhnfZXNag/v/c2083hSE=
sha1:c/TCXzf6PZr3PmDa/cSfd0SwFPg=
X-BSB-Auth: 1.358c5f10a21759146eab.20240316135503GMT.87wmq2jn7s.fsf@bsb.me.uk
 by: Ben Bacarisse - Sat, 16 Mar 2024 13:55 UTC

Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:

> Recursion make programs harder to reason about and prove correct.

Are you prepared to offer any evidence to support this astonishing
statement or can we just assume it's another Malcolmism?

--
Ben.

Re: filling area by color atack safety

<ut4b09$2uhpm$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34410&group=comp.lang.c#34410

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: filling area by color atack safety
Date: Sat, 16 Mar 2024 15:40:09 +0100
Organization: A noiseless patient Spider
Lines: 90
Message-ID: <ut4b09$2uhpm$1@dont-email.me>
References: <ut3669$21eur$1@i2pn2.org> <ut4020$2s8ov$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 16 Mar 2024 14:40:09 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="2d79e9313fe696e13669cd0ceaff0321";
logging-data="3098422"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Tj1e6GuC5wug0/VUCKYXMMtPVQd9yRXk="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:p7Aa5e8cYOW6yzWYzy6dS8X8YAo=
Content-Language: en-GB
In-Reply-To: <ut4020$2s8ov$1@dont-email.me>
 by: David Brown - Sat, 16 Mar 2024 14:40 UTC

On 16/03/2024 12:33, Malcolm McLean wrote:
> On 16/03/2024 04:11, fir wrote:
>> 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?
> >
> This is a cheap and cheerful fllod fill. And it's easy to get right and
> shouldn't afall over. But but makes an awful not of unnecessary calls,
> and on a small system and large image might even blow the stack.

It is not going to lead to stack overflow on any reasonable system. If
the image size is 200 x 200, as the OP said, it will never reach a depth
of more than 400 calls (the maximum path length before back-tracking is
inevitable). Even for big images, I can't see it being a problem. I
remember using the same method on a 16K ZX Spectrum as a teenager.

>
> Recursion make programs harder to reason about and prove correct.

As a general statement, that is simply wrong. It is no coincidence that
most provably correct software development is done using functional
programming languages, which are based entirely on recursion. Recursion
maps well to inductive proofs, and avoids variables, and is thus often
much easier to work with for proving code correct.

>
> So a real flood fill doesn't work like that. You use a queue and put the
> pixels to be filled into that, and trace lines.
>

That might be a bit more efficient, but not significantly so (at least,
not in your implementation below). You are using a queue instead of the
stack, but it will grow in exactly the same manner.

> 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).

There are a variety of different flood-fill algorithms, with different
advantages and disadvantages. Speeds will often depend as much on the
way the get/set pixel code works, especially if the flood-fill is on
live displayed data rather than in a buffer off-screen. But typically
you need to get a /lot/ more advanced (i.e., not your algorithm) to
improve on the OP's version by an order of magnitude, so if speed is not
essential but understanding that it is correct is important, then it
makes more sense to stick to the original recursive version.

Re: filling area by color atack safety

<ut4b3c$2ugk7$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34411&group=comp.lang.c#34411

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: bc...@freeuk.com (bart)
Newsgroups: comp.lang.c
Subject: Re: filling area by color atack safety
Date: Sat, 16 Mar 2024 14:41:50 +0000
Organization: A noiseless patient Spider
Lines: 16
Message-ID: <ut4b3c$2ugk7$1@dont-email.me>
References: <ut3669$21eur$1@i2pn2.org> <ut4020$2s8ov$1@dont-email.me>
<87wmq2jn7s.fsf@bsb.me.uk>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 16 Mar 2024 14:41:48 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="22e0833e5034a71499d44743897d4a7c";
logging-data="3097223"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19UFQMCr73Y4MypGvpBC44P"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:HWGwWh1ii1tECU473RxzZu6pNiA=
Content-Language: en-GB
In-Reply-To: <87wmq2jn7s.fsf@bsb.me.uk>
 by: bart - Sat, 16 Mar 2024 14:41 UTC

On 16/03/2024 13:55, Ben Bacarisse wrote:
> Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
>
>> Recursion make programs harder to reason about and prove correct.
>
> Are you prepared to offer any evidence to support this astonishing
> statement or can we just assume it's another Malcolmism?

You have evidence to suggest that the opposite is true?

I personally find recursion hard work and errors much harder to debug.
It is also becomes much more important to show that will not cause stack
overflow.

Re: filling area by color atack safety

<ut4ba7$2uits$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34412&group=comp.lang.c#34412

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: malcolm....@gmail.com (Malcolm McLean)
Newsgroups: comp.lang.c
Subject: Re: filling area by color atack safety
Date: Sat, 16 Mar 2024 14:45:27 +0000
Organization: A noiseless patient Spider
Lines: 16
Message-ID: <ut4ba7$2uits$1@dont-email.me>
References: <ut3669$21eur$1@i2pn2.org> <ut4020$2s8ov$1@dont-email.me>
<87wmq2jn7s.fsf@bsb.me.uk>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 16 Mar 2024 14:45:27 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="0ac9f1a8c1dfcfccfb5694c886ca1efb";
logging-data="3099580"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19caZ5BA7rAh+DEzHUwFW7ZTXmD2QJcTCs="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:b7GnlH0FR9NPinRUqmLIseeJXVM=
In-Reply-To: <87wmq2jn7s.fsf@bsb.me.uk>
Content-Language: en-GB
 by: Malcolm McLean - Sat, 16 Mar 2024 14:45 UTC

On 16/03/2024 13:55, Ben Bacarisse wrote:
> Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
>
>> Recursion make programs harder to reason about and prove correct.
>
> Are you prepared to offer any evidence to support this astonishing
> statement or can we just assume it's another Malcolmism?
>

Example given. A recursive algorithm which is hard to reason about and
prove correct, because we don't really know whether under perfectly
reasonable assumptions it will or will not blow the stack.
--
Check out Basic Algorithms and my other books:
https://www.lulu.com/spotlight/bgy1mm

Re: filling area by color atack safety

<ut4cnc$2ut2t$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34413&group=comp.lang.c#34413

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: malcolm....@gmail.com (Malcolm McLean)
Newsgroups: comp.lang.c
Subject: Re: filling area by color atack safety
Date: Sat, 16 Mar 2024 15:09:31 +0000
Organization: A noiseless patient Spider
Lines: 46
Message-ID: <ut4cnc$2ut2t$1@dont-email.me>
References: <ut3669$21eur$1@i2pn2.org> <ut4020$2s8ov$1@dont-email.me>
<ut4b09$2uhpm$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 16 Mar 2024 15:09:32 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="0ac9f1a8c1dfcfccfb5694c886ca1efb";
logging-data="3109981"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18T0W86wdmakFnCtDb4Ax+AukAzkqqC5i4="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:l4XTr0JWD9v0zXbqvuMWreB7nxM=
Content-Language: en-GB
In-Reply-To: <ut4b09$2uhpm$1@dont-email.me>
 by: Malcolm McLean - Sat, 16 Mar 2024 15:09 UTC

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?
It's not designed to be eay to prove correct, that's true. And the
maintain it's mess is that we are managing the queue manually for speed.

But the naive recursive algorithm is O(N) (N = pixels to flood), and
inherently we can't beat that without special hardware. The recursive
one tends to be slow because calls are expensive. And mine makes calls
to malloc() and realloc to manage the queue. And of course whilst we
might blow the stack, we are much less likely to run out of heap.

And it's been tweaked abit in hacky way to make it faster on real
images. And whilst it's still going to work, is it out of date?

And I need to run some tests, don't I?

>
> There are a variety of different flood-fill algorithms, with different
> advantages and disadvantages.  Speeds will often depend as much on the
> way the get/set pixel code works, especially if the flood-fill is on
> live displayed data rather than in a buffer off-screen.  But typically
> you need to get a /lot/ more advanced (i.e., not your algorithm) to
> improve on the OP's version by an order of magnitude, so if speed is not
> essential but understanding that it is correct is important, then it
> makes more sense to stick to the original recursive version.
>

What are these / lot / more advanced algorithms? Maybe they exist. But
don't people deserve some sort of link?

--
Check out Basic Algorithms and my other books:
https://www.lulu.com/spotlight/bgy1mm

Re: filling area by color atack safety

<SqlJN.144025$CYpe.59290@fx40.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34417&group=comp.lang.c#34417

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx40.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: filling area by color atack safety
Newsgroups: comp.lang.c
References: <ut3669$21eur$1@i2pn2.org> <ut4020$2s8ov$1@dont-email.me> <87wmq2jn7s.fsf@bsb.me.uk> <ut4ba7$2uits$1@dont-email.me>
Lines: 17
Message-ID: <SqlJN.144025$CYpe.59290@fx40.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Sat, 16 Mar 2024 18:21:38 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Sat, 16 Mar 2024 18:21:38 GMT
X-Received-Bytes: 1236
 by: Scott Lurndal - Sat, 16 Mar 2024 18:21 UTC

Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
>On 16/03/2024 13:55, Ben Bacarisse wrote:
>> Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
>>
>>> Recursion make programs harder to reason about and prove correct.
>>
>> Are you prepared to offer any evidence to support this astonishing
>> statement or can we just assume it's another Malcolmism?
>>
>
>Example given. A recursive algorithm which is hard to reason about and

Perhaps hard for _you_ to reason about. That doesn't
generalize to every other programmer that might read that
code.

Re: filling area by color atack safety

<BulJN.144026$CYpe.133853@fx40.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34418&group=comp.lang.c#34418

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!newsfeed.endofthelinebbs.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx40.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: filling area by color atack safety
Newsgroups: comp.lang.c
References: <ut3669$21eur$1@i2pn2.org> <ut4020$2s8ov$1@dont-email.me> <ut4b09$2uhpm$1@dont-email.me>
Lines: 15
Message-ID: <BulJN.144026$CYpe.133853@fx40.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Sat, 16 Mar 2024 18:25:37 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Sat, 16 Mar 2024 18:25:37 GMT
X-Received-Bytes: 1213
 by: Scott Lurndal - Sat, 16 Mar 2024 18:25 UTC

David Brown <david.brown@hesbynett.no> writes:
>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

Malcolm can't even spell 'integer' correctly in that code blob :-).

Certainly the intent of Fir's algorithm is easily discerned from
his code. I can't say that about Malcolms.

Re: filling area by color atack safety

<ut4r0q$31rir$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34421&group=comp.lang.c#34421

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: bc...@freeuk.com (bart)
Newsgroups: comp.lang.c
Subject: Re: filling area by color atack safety
Date: Sat, 16 Mar 2024 19:13:32 +0000
Organization: A noiseless patient Spider
Lines: 127
Message-ID: <ut4r0q$31rir$1@dont-email.me>
References: <ut3669$21eur$1@i2pn2.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 16 Mar 2024 19:13:30 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="22e0833e5034a71499d44743897d4a7c";
logging-data="3206747"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX196rJqHbKMkpKL5U+qrnxl+"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:IdMTVm+xistBUGgMmI1DNBDBKSk=
In-Reply-To: <ut3669$21eur$1@i2pn2.org>
Content-Language: en-GB
 by: bart - Sat, 16 Mar 2024 19:13 UTC

On 16/03/2024 04:11, fir wrote:
> 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  -

On my machine, it's OK up to a 400x400 image (starting with all one
colour and filling from the centre with another colour).

At 500x500, I get stack overflow. The 400x400 the maximum recursion
depth is 80,000 calls.

I don't an alternative ATM, I'm just reporting what I saw with my test
program shown below, since some here don't believe that recursion can be
problematical.

--------------------------
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef unsigned char byte;

enum {dimx=400};
enum {dimy=dimx};
byte image[dimx][dimy];
int maxdepth;

byte getpixel(int x, int y) {
return image[x][y];
}

void setpixel(int x, int y, byte newcol) {
image[x][y]=newcol;
}

int onscreen(int x, int y) {
return x>=0 && x<dimx && y>=0 && y<dimy;
}

void fill(int x, int y, unsigned old_color, unsigned new_color)
{ if(old_color == new_color) return;
static int depth=0;

++depth;
if (depth>maxdepth) maxdepth=depth;

if(onscreen( x, y)) {
//printf("FILL %d %d %d depth:%d\n",x,y, onscreen(x,y), depth);
if(getpixel(x,y)==old_color)
{
setpixel(x,y,new_color);
fill(x+1, y, old_color, new_color);
fill(x-1, y, old_color, new_color);
fill(x, y-1, old_color, new_color);
fill(x, y+1, old_color, new_color);
--depth;
return;
}
}
--depth;
return;
}

static void writepgm(byte* file) {
int x, y;
void* f;
f = fopen(file,"w");
fprintf(f,"%s\n","P2");
fprintf(f,"%d %d\n",dimx,dimy);
fprintf(f,"255\n");
for (y=0; y<dimy; ++y) {
for (x=0; x<dimx; ++x) {
fprintf(f,"%u%s",image[y][x]," ");
}
fprintf(f,"\n");
}
fclose(f);
}

int main(void) {

fill(dimx/2, dimy/2, 0, 80);

printf("maxdepth=%d\n",maxdepth);
puts("");

puts("Writing test.ppm:");
writepgm("test.ppm");

}

Re: filling area by color atack safety

<ut4tsj$3291j$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34422&group=comp.lang.c#34422

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: malcolm....@gmail.com (Malcolm McLean)
Newsgroups: comp.lang.c
Subject: Re: filling area by color atack safety
Date: Sat, 16 Mar 2024 20:02:16 +0000
Organization: A noiseless patient Spider
Lines: 25
Message-ID: <ut4tsj$3291j$1@dont-email.me>
References: <ut3669$21eur$1@i2pn2.org> <ut4020$2s8ov$1@dont-email.me>
<87wmq2jn7s.fsf@bsb.me.uk> <ut4ba7$2uits$1@dont-email.me>
<SqlJN.144025$CYpe.59290@fx40.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 16 Mar 2024 20:02:28 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="3d952fdd8617db9b3dbe21c198201920";
logging-data="3220531"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+vhgIlGoxFUUX3RqE2KHAdqsih4NmsK/Q="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:B3bwdGaeZav4HqF/hoVYny9cpKY=
In-Reply-To: <SqlJN.144025$CYpe.59290@fx40.iad>
Content-Language: en-US
 by: Malcolm McLean - Sat, 16 Mar 2024 20:02 UTC

On 16/03/2024 18:21, Scott Lurndal wrote:
> Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
>> On 16/03/2024 13:55, Ben Bacarisse wrote:
>>> Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
>>>
>>>> Recursion make programs harder to reason about and prove correct.
>>>
>>> Are you prepared to offer any evidence to support this astonishing
>>> statement or can we just assume it's another Malcolmism?
>>>
>>
>> Example given. A recursive algorithm which is hard to reason about and
>
> Perhaps hard for _you_ to reason about. That doesn't
> generalize to every other programmer that might read that
> code.
>
>
From experience this one blows the stack, but not always. Sometimes
it's OK to use.

Since you can reason about it so easily, you can tell the others when
you're OK and when you are not, in a handy intuitive way so that someone
thinking of implementing it will know.

Re: filling area by color atack safety

<ut4v4r$32mgb$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34424&group=comp.lang.c#34424

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: bc...@freeuk.com (bart)
Newsgroups: comp.lang.c
Subject: Re: filling area by color atack safety
Date: Sat, 16 Mar 2024 20:23:57 +0000
Organization: A noiseless patient Spider
Lines: 60
Message-ID: <ut4v4r$32mgb$1@dont-email.me>
References: <ut3669$21eur$1@i2pn2.org> <ut4r0q$31rir$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 16 Mar 2024 20:23:55 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="22e0833e5034a71499d44743897d4a7c";
logging-data="3234315"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+EdTX1x/VnWRMUI9fsACQY"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:+B/moxz6XDdMkdarXvnnPCGpI+Y=
In-Reply-To: <ut4r0q$31rir$1@dont-email.me>
Content-Language: en-GB
 by: bart - Sat, 16 Mar 2024 20:23 UTC

On 16/03/2024 19:13, bart wrote:
> On 16/03/2024 04:11, fir wrote:
>> 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  -
>
> On my machine, it's OK up to a 400x400 image (starting with all one
> colour and filling from the centre with another colour).
>
> At 500x500, I get stack overflow. The 400x400 the maximum recursion
> depth is 80,000 calls.

For an NxN image filling from the centre, the max depth is N*N/2, or
from one corner, it's N*N.

The depth with an N*1 image starting from one end seems to just N.

It appears to fill as much as possible (in my tests, all remaining
pixels), before returning from any call, at which point, the work is done.

I've just looked in my Computer Graphics Principles and Practice book
(after blowing off the dust), and the algorithm above is exactly the
'FloodFill4' one in the book. It mentions the problems with the stack;
maybe I should have looked in there first.

It talks about better approaches, but it doesn't give a better algorithm
that I can see. Perhaps the OP should just do an online search for one.

Re: filling area by color atack safety

<ut4vf6$32n1u$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34425&group=comp.lang.c#34425

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c
Subject: Re: filling area by color atack safety
Date: Sat, 16 Mar 2024 13:29:26 -0700
Organization: A noiseless patient Spider
Lines: 33
Message-ID: <ut4vf6$32n1u$1@dont-email.me>
References: <ut3669$21eur$1@i2pn2.org> <ut4020$2s8ov$1@dont-email.me>
<87wmq2jn7s.fsf@bsb.me.uk> <ut4ba7$2uits$1@dont-email.me>
<SqlJN.144025$CYpe.59290@fx40.iad> <ut4tsj$3291j$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 16 Mar 2024 20:29:27 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="ecbf074eed964d26a0e1ee52fa577a26";
logging-data="3234878"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19r0DDdfmh9dy/C3h43qweIkal1BzaJUIU="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:4PaAmeW8SkGy7WYtACyB1m4dQhQ=
Content-Language: en-US
In-Reply-To: <ut4tsj$3291j$1@dont-email.me>
 by: Chris M. Thomasson - Sat, 16 Mar 2024 20:29 UTC

On 3/16/2024 1:02 PM, Malcolm McLean wrote:
> On 16/03/2024 18:21, Scott Lurndal wrote:
>> Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
>>> On 16/03/2024 13:55, Ben Bacarisse wrote:
>>>> Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
>>>>
>>>>> Recursion make programs harder to reason about and prove correct.
>>>>
>>>> Are you prepared to offer any evidence to support this astonishing
>>>> statement or can we just assume it's another Malcolmism?
>>>>
>>>
>>> Example given. A recursive algorithm which is hard to reason about and
>>
>> Perhaps hard for _you_ to reason about.  That doesn't
>> generalize to every other programmer that might read that
>> code.
>>
>>
> From experience this one blows the stack, but not always. Sometimes
> it's OK to use.

Blowing the stack is not good at all. However, sometimes, I consider a
recursive algorithm easier to understand. So, I build it first... Get it
working, _then_ think about an iterative solution...

>
> Since you can reason about it so easily, you can tell the others when
> you're OK and when you are not, in a handy intuitive way so that someone
> thinking of implementing it will know.
>

Re: filling area by color atack safety

<ut4vgb$32kbs$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34426&group=comp.lang.c#34426

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: malcolm....@gmail.com (Malcolm McLean)
Newsgroups: comp.lang.c
Subject: Re: filling area by color atack safety
Date: Sat, 16 Mar 2024 20:29:52 +0000
Organization: A noiseless patient Spider
Lines: 63
Message-ID: <ut4vgb$32kbs$1@dont-email.me>
References: <ut3669$21eur$1@i2pn2.org> <ut4r0q$31rir$1@dont-email.me>
<ut4v4r$32mgb$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 16 Mar 2024 20:30:05 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="3d952fdd8617db9b3dbe21c198201920";
logging-data="3232124"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18sf9pgG4c2xPMNVPyfRMQhSCUEXUggadA="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:VsPSmFC73oNSDkwD6pE43uguMm8=
In-Reply-To: <ut4v4r$32mgb$1@dont-email.me>
Content-Language: en-US
 by: Malcolm McLean - Sat, 16 Mar 2024 20:29 UTC

On 16/03/2024 20:23, bart wrote:
> On 16/03/2024 19:13, bart wrote:
>> On 16/03/2024 04:11, fir wrote:
>>> 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  -
>>
>> On my machine, it's OK up to a 400x400 image (starting with all one
>> colour and filling from the centre with another colour).
>>
>> At 500x500, I get stack overflow. The 400x400 the maximum recursion
>> depth is 80,000 calls.
>
> For an NxN image filling from the centre, the max depth is N*N/2, or
> from one corner, it's N*N.
>
> The depth with an N*1 image starting from one end seems to just N.
>
> It appears to fill as much as possible (in my tests, all remaining
> pixels), before returning from any call, at which point, the work is done.
>
> I've just looked in my Computer Graphics Principles and Practice book
> (after blowing off the dust), and the algorithm above is exactly the
> 'FloodFill4' one in the book. It mentions the problems with the stack;
> maybe I should have looked in there first.
>
> It talks about better approaches, but it doesn't give a better algorithm
> that I can see. Perhaps the OP should just do an online search for one.
>
>
>
Now think about adding some barriers. But don't make life too easy for
Scott.

Re: filling area by color atack safety

<87r0g9jgjt.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34436&group=comp.lang.c#34436

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.c
Subject: Re: filling area by color atack safety
Date: Sun, 17 Mar 2024 10:31:18 +0000
Organization: A noiseless patient Spider
Lines: 31
Message-ID: <87r0g9jgjt.fsf@bsb.me.uk>
References: <ut3669$21eur$1@i2pn2.org> <ut4020$2s8ov$1@dont-email.me>
<ut4b09$2uhpm$1@dont-email.me> <BulJN.144026$CYpe.133853@fx40.iad>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="664dca1fae3f1391a07afac504c68131";
logging-data="3659162"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX189+FKs9lnbo5umiOubKJxdCR5+nMTmJpw="
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:MMKWcHBp61mL8fy3cst00i2yJGI=
sha1:ndDit9lNC2CMnKKSj0AfQTjHVx0=
X-BSB-Auth: 1.aeb2745325f2ec05fa32.20240317103118GMT.87r0g9jgjt.fsf@bsb.me.uk
 by: Ben Bacarisse - Sun, 17 Mar 2024 10:31 UTC

scott@slp53.sl.home (Scott Lurndal) writes:

> David Brown <david.brown@hesbynett.no> writes:
>>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
>
> Malcolm can't even spell 'integer' correctly in that code blob :-).

As someone with dyslexia I have never liked mocking remarks about
spelling errors. Using "even" suggests that a superficial issue hints
at deeper problems. This is rarely the case.

However, I /would/ urge Malcolm to correct the spelling if Bresenham
since the intent was clearly to credit the discoverer. Also,
misspellings don't play well with library databases.

> Certainly the intent of Fir's algorithm is easily discerned from
> his code. I can't say that about Malcolms.

I have some reservations about the code, but he posted a link so there
is no indication that he wants a review of it.

--
Ben.

Re: filling area by color atack safety

<87le6hjg0y.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34437&group=comp.lang.c#34437

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.c
Subject: Re: filling area by color atack safety
Date: Sun, 17 Mar 2024 10:42:37 +0000
Organization: A noiseless patient Spider
Lines: 15
Message-ID: <87le6hjg0y.fsf@bsb.me.uk>
References: <ut3669$21eur$1@i2pn2.org> <ut4020$2s8ov$1@dont-email.me>
<87wmq2jn7s.fsf@bsb.me.uk> <ut4b3c$2ugk7$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="664dca1fae3f1391a07afac504c68131";
logging-data="3659162"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19NpEYjn2UofDkJgjahc0XrNewtou2aM1U="
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:9LUbHYclMxJm4xmpbH8Bg2lvBWY=
sha1:68FpFLgrvdvF/0+0pk1pf/ZqJ4Y=
X-BSB-Auth: 1.d434cc89391988438352.20240317104237GMT.87le6hjg0y.fsf@bsb.me.uk
 by: Ben Bacarisse - Sun, 17 Mar 2024 10:42 UTC

bart <bc@freeuk.com> writes:

> On 16/03/2024 13:55, Ben Bacarisse wrote:
>> Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
>>
>>> Recursion make programs harder to reason about and prove correct.
>> Are you prepared to offer any evidence to support this astonishing
>> statement or can we just assume it's another Malcolmism?
>
> You have evidence to suggest that the opposite is true?

No, which is why I did not make such an assertion.

--
Ben.

Re: filling area by color atack safety

<87frwpje2b.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34439&group=comp.lang.c#34439

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.c
Subject: Re: filling area by color atack safety
Date: Sun, 17 Mar 2024 11:25:00 +0000
Organization: A noiseless patient Spider
Lines: 43
Message-ID: <87frwpje2b.fsf@bsb.me.uk>
References: <ut3669$21eur$1@i2pn2.org> <ut4020$2s8ov$1@dont-email.me>
<87wmq2jn7s.fsf@bsb.me.uk> <ut4ba7$2uits$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="664dca1fae3f1391a07afac504c68131";
logging-data="3679491"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/fH4oBzFPUWqxev9zaj+a2gIfkkpUeXP0="
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:udcYZK1zFDxwIkyWA66zZSkHpaY=
sha1:9Eqvb7/e4//FlhweyqhlEUnM+PU=
X-BSB-Auth: 1.5711426a435d346721f2.20240317112500GMT.87frwpje2b.fsf@bsb.me.uk
 by: Ben Bacarisse - Sun, 17 Mar 2024 11:25 UTC

Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:

> On 16/03/2024 13:55, Ben Bacarisse wrote:
>> Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
>>
>>> Recursion make programs harder to reason about and prove correct.
>> Are you prepared to offer any evidence to support this astonishing
>> statement or can we just assume it's another Malcolmism?
>
> Example given. A recursive algorithm which is hard to reason about and
> prove correct, because we don't really know whether under perfectly
> reasonable assumptions it will or will not blow the stack.

Had you offered a proof that your code neither "blows the stack" nor
runs out of any other resource we'd have a starting point for
comparison, but you have not done that.

Mind you, had you done that, we would have something that might
eventually become only one piece of evidence for what is an
astonishingly general remark. Broadly applicable remarks require either
broadly applicable evidence or a wealth of distinct cases.

Your "rule" suggests that all reasoning is impeded by the presence of
recursion and I don't think you can support that claim. This is
characteristic of many of your remarks -- they are general "rules" that
often remain rules even when there is evidence to the contrary.

I'll make another point in the hope of clarifying the matter. An
algorithm or code is usually proved correct (or not!) under the
assumption that it has adequate resources -- usually time and storage.
Further reasoning may then be done to determine the resource
requirements since this is so often dependent on context. This
separation is helpful as you don't usually want to tie "correctness" to
some specific installation. The code might run on a system with a
dynamically allocated stack, for example, that has very similar
limitations to "heap" memory.

To put is more generally, we often want to prove properties of code that
are independent of physical constraints. Your remark includes this kind
reasoning. Did you intend it to?

--
Ben.

Re: filling area by color atack safety

<ut6nma$3h3cb$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34442&group=comp.lang.c#34442

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: malcolm....@gmail.com (Malcolm McLean)
Newsgroups: comp.lang.c
Subject: Re: filling area by color atack safety
Date: Sun, 17 Mar 2024 12:28:56 +0000
Organization: A noiseless patient Spider
Lines: 56
Message-ID: <ut6nma$3h3cb$1@dont-email.me>
References: <ut3669$21eur$1@i2pn2.org> <ut4020$2s8ov$1@dont-email.me>
<ut4b09$2uhpm$1@dont-email.me> <BulJN.144026$CYpe.133853@fx40.iad>
<87r0g9jgjt.fsf@bsb.me.uk>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 17 Mar 2024 12:28:58 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="1302203e67d64edb589b5f20956e00a5";
logging-data="3706251"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+8K8Fbv0oLvOGJAFiZjsthUIwctFZhPC8="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:EWgyu3UuNKAytlr/X5AhuCFu/Ok=
Content-Language: en-GB
In-Reply-To: <87r0g9jgjt.fsf@bsb.me.uk>
 by: Malcolm McLean - Sun, 17 Mar 2024 12:28 UTC

On 17/03/2024 10:31, Ben Bacarisse wrote:
> scott@slp53.sl.home (Scott Lurndal) writes:
>
>> David Brown <david.brown@hesbynett.no> writes:
>>> 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
>>
>> Malcolm can't even spell 'integer' correctly in that code blob :-).
>
> As someone with dyslexia I have never liked mocking remarks about
> spelling errors. Using "even" suggests that a superficial issue hints
> at deeper problems. This is rarely the case.
>
> However, I /would/ urge Malcolm to correct the spelling if Bresenham
> since the intent was clearly to credit the discoverer. Also,
> misspellings don't play well with library databases.
>
>> Certainly the intent of Fir's algorithm is easily discerned from
>> his code. I can't say that about Malcolms.
>
> I have some reservations about the code, but he posted a link so there
> is no indication that he wants a review of it.
>
Tbe main intent was to help fir. That algorithm does tend to blow the
stack though of course it depends on the image. However worst case is a
pattern which is pixel wide line, e.g. a spiral or a maze or a series of
alterante light and dark bands with a lirtel gaps at each end. And you
achieve that by filling half the pixels. So foe a 100x100 image your
worst case is 10,000 = 5,000 recursive calls, and the stack is blown.

And so not that that hard to reason about. However no-one actually took
up the challenge and actually did so.

And mine only maes a few subroutines calls to standard library
functions, so you can tell at a glance that the stack won't be blown.
But it's not as clear what the worst case of for heap is, but it can't
be more than 2xNxlow integers, where 2 is 2 integers for the pixel x, y
cordinates, N is the number of pixels, and low is the catastrophic worst
case scenario, which can't be over about 4. And that's not going to be a
problem for most computers. Assuming things aren't bugged.

And I suggest that fir just replace the direct buffer reads and writes
with calls, and job done. But the code is fair game. If you can make it
better, that's a good thing, not a humiliation.

--
Check out Basic Algorithms and my other books:
https://www.lulu.com/spotlight/bgy1mm

Re: filling area by color atack safety

<ut6o5l$3h3cb$3@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34444&group=comp.lang.c#34444

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: malcolm....@gmail.com (Malcolm McLean)
Newsgroups: comp.lang.c
Subject: Re: filling area by color atack safety
Date: Sun, 17 Mar 2024 12:37:08 +0000
Organization: A noiseless patient Spider
Lines: 49
Message-ID: <ut6o5l$3h3cb$3@dont-email.me>
References: <ut3669$21eur$1@i2pn2.org> <ut4020$2s8ov$1@dont-email.me>
<87wmq2jn7s.fsf@bsb.me.uk> <ut4ba7$2uits$1@dont-email.me>
<87frwpje2b.fsf@bsb.me.uk>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 17 Mar 2024 12:37:09 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="1302203e67d64edb589b5f20956e00a5";
logging-data="3706251"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/hhNwaZR+JvzRUQh2uecWP/+nl9KeqUEc="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:YHhkOwv6DUbofburMtkHvs75sW8=
In-Reply-To: <87frwpje2b.fsf@bsb.me.uk>
Content-Language: en-GB
 by: Malcolm McLean - Sun, 17 Mar 2024 12:37 UTC

On 17/03/2024 11:25, Ben Bacarisse wrote:
> Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
>
>> On 16/03/2024 13:55, Ben Bacarisse wrote:
>>> Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
>>>
>>>> Recursion make programs harder to reason about and prove correct.
>>> Are you prepared to offer any evidence to support this astonishing
>>> statement or can we just assume it's another Malcolmism?
>>
>> Example given. A recursive algorithm which is hard to reason about and
>> prove correct, because we don't really know whether under perfectly
>> reasonable assumptions it will or will not blow the stack.
>
> Had you offered a proof that your code neither "blows the stack" nor
> runs out of any other resource we'd have a starting point for
> comparison, but you have not done that.
>
> Mind you, had you done that, we would have something that might
> eventually become only one piece of evidence for what is an
> astonishingly general remark. Broadly applicable remarks require either
> broadly applicable evidence or a wealth of distinct cases.
>
> Your "rule" suggests that all reasoning is impeded by the presence of
> recursion and I don't think you can support that claim. This is
> characteristic of many of your remarks -- they are general "rules" that
> often remain rules even when there is evidence to the contrary.
>
> I'll make another point in the hope of clarifying the matter. An
> algorithm or code is usually proved correct (or not!) under the
> assumption that it has adequate resources -- usually time and storage.
> Further reasoning may then be done to determine the resource
> requirements since this is so often dependent on context. This
> separation is helpful as you don't usually want to tie "correctness" to
> some specific installation. The code might run on a system with a
> dynamically allocated stack, for example, that has very similar
> limitations to "heap" memory.
>
> To put is more generally, we often want to prove properties of code that
> are independent of physical constraints. Your remark includes this kind
> reasoning. Did you intend it to?
>
The convetional wisdom is the opposite, But here, conventional wisdom
fails. Because heaps are unlimited whilst stacks are not.

--
Check out Basic Algorithms and my other books:
https://www.lulu.com/spotlight/bgy1mm

Re: filling area by color atack safety

<20240317144625.00002011@yahoo.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34445&group=comp.lang.c#34445

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: already5...@yahoo.com (Michael S)
Newsgroups: comp.lang.c
Subject: Re: filling area by color atack safety
Date: Sun, 17 Mar 2024 14:46:25 +0200
Organization: A noiseless patient Spider
Lines: 57
Message-ID: <20240317144625.00002011@yahoo.com>
References: <ut3669$21eur$1@i2pn2.org>
<ut4020$2s8ov$1@dont-email.me>
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="3664868"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Wdn7XiY7G+1gzHv9JkWMi+XKMLEquzX8="
Cancel-Lock: sha1:mxU4A8wWre+KFtP76Gj01VfwRNM=
X-Newsreader: Claws Mail 3.19.1 (GTK+ 2.24.33; x86_64-w64-mingw32)
 by: Michael S - Sun, 17 Mar 2024 12:46 UTC

On Sat, 16 Mar 2024 11:33:20 +0000
Malcolm McLean <malcolm.arthur.mclean@gmail.com> wrote:

> On 16/03/2024 04:11, fir wrote:
> > 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?
> >
> This is a cheap and cheerful fllod fill. And it's easy to get right
> and shouldn't afall over.

Except I don't understand why it works it all.
Can't fill area have sub-areas that only connected through diagonal?

Re: filling area by color atack safety

<ut6osq$3h8t0$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34446&group=comp.lang.c#34446

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: bc...@freeuk.com (bart)
Newsgroups: comp.lang.c
Subject: Re: filling area by color atack safety
Date: Sun, 17 Mar 2024 12:49:33 +0000
Organization: A noiseless patient Spider
Lines: 46
Message-ID: <ut6osq$3h8t0$1@dont-email.me>
References: <ut3669$21eur$1@i2pn2.org> <ut4020$2s8ov$1@dont-email.me>
<ut4b09$2uhpm$1@dont-email.me> <BulJN.144026$CYpe.133853@fx40.iad>
<87r0g9jgjt.fsf@bsb.me.uk> <ut6nma$3h3cb$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 17 Mar 2024 12:49:30 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="86cdd72051d773a92e0c8f332750da77";
logging-data="3711904"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/KGjkHzyWPLgkPJnjOgCjC"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:6rOOJ261X41IIDm4hLp1tGA3J68=
Content-Language: en-GB
In-Reply-To: <ut6nma$3h3cb$1@dont-email.me>
 by: bart - Sun, 17 Mar 2024 12:49 UTC

On 17/03/2024 12:28, Malcolm McLean wrote:
> On 17/03/2024 10:31, Ben Bacarisse wrote:
>> scott@slp53.sl.home (Scott Lurndal) writes:
>>
>>> David Brown <david.brown@hesbynett.no> writes:
>>>> 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
>>>
>>> Malcolm can't even spell 'integer' correctly in that code blob :-).
>>
>> As someone with dyslexia I have never liked mocking remarks about
>> spelling errors.  Using "even" suggests that a superficial issue hints
>> at deeper problems.  This is rarely the case.
>>
>> However, I /would/ urge Malcolm to correct the spelling if Bresenham
>> since the intent was clearly to credit the discoverer.  Also,
>> misspellings don't play well with library databases.
>>
>>> Certainly the intent of Fir's algorithm is easily discerned from
>>> his code.   I can't say that about Malcolms.
>>
>> I have some reservations about the code, but he posted a link so there
>> is no indication that he wants a review of it.
>>
> Tbe main intent was to help fir. That algorithm does tend to blow the
> stack though of course it depends on the image. However worst case is a
> pattern which is pixel wide line, e.g. a spiral or a maze or a series of
> alterante light and dark bands with a lirtel gaps at each end. And you
> achieve that by filling half the pixels. So foe a 100x100 image your
> worst case is 10,000 = 5,000 recursive calls, and the stack is blown.

I'd been planning to create a square spiral. But I found I got N*N/2
behaviour even with a blank image which was filled in from one corner.

After thinking about it, it became obvious that the potential call depth
wasn't the distance to a boundary in any direction, but the number of
pixels in the area to be eventually filled in, which could be a big
chunk of the N*N total.

Re: filling area by color atack safety

<ut6p67$3h8t0$2@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34447&group=comp.lang.c#34447

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: bc...@freeuk.com (bart)
Newsgroups: comp.lang.c
Subject: Re: filling area by color atack safety
Date: Sun, 17 Mar 2024 12:54:34 +0000
Organization: A noiseless patient Spider
Lines: 58
Message-ID: <ut6p67$3h8t0$2@dont-email.me>
References: <ut3669$21eur$1@i2pn2.org> <ut4020$2s8ov$1@dont-email.me>
<20240317144625.00002011@yahoo.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 17 Mar 2024 12:54:31 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="86cdd72051d773a92e0c8f332750da77";
logging-data="3711904"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+8O65DxhX+fRYS0aY9f1OO"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:bA0FaVU1dryV3PXJndVkO1PpVec=
In-Reply-To: <20240317144625.00002011@yahoo.com>
Content-Language: en-GB
 by: bart - Sun, 17 Mar 2024 12:54 UTC

On 17/03/2024 12:46, Michael S wrote:
> On Sat, 16 Mar 2024 11:33:20 +0000
> Malcolm McLean <malcolm.arthur.mclean@gmail.com> wrote:
>
>> On 16/03/2024 04:11, fir wrote:
>>> 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?
>> >
>> This is a cheap and cheerful fllod fill. And it's easy to get right
>> and shouldn't afall over.
>
> Except I don't understand why it works it all.
> Can't fill area have sub-areas that only connected through diagonal?

Suppose you have an image which is a chessboard. You want to fill one of
the black squares so that it is red.

If you allow connectivity through the diagonals (so two notionally
square pixels that only meet at their corners would be connected), then
all the black squares would turn red, not just one.

Re: filling area by color atack safety

<t7hick-t14.ln1@hendrix.foo>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34448&group=comp.lang.c#34448

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: phayw...@alphalink.com.au (Peter 'Shaggy' Haywood)
Newsgroups: comp.lang.c
Subject: Re: filling area by color atack safety
Date: Sun, 17 Mar 2024 18:03:57 +1100
Organization: A noiseless patient Spider
Lines: 34
Message-ID: <t7hick-t14.ln1@hendrix.foo>
References: <ut3669$21eur$1@i2pn2.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7Bit
Injection-Info: dont-email.me; posting-host="13a0669b382a7d0e07fe158547944872";
logging-data="3722673"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/FzXsAmsmiJy8ks9n/mOqkX2TBHJeRpBI="
User-Agent: KNode/0.10.9
Cancel-Lock: sha1:iNeFpCiKv4bRWPeJ2DY55qzDCoY=
 by: Peter 'Shaggy&# - Sun, 17 Mar 2024 07:03 UTC

Groovy hepcat fir was jivin' in comp.lang.c on Sat, 16 Mar 2024 03:11
pm. It's a cool scene! Dig it.

> 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)

Not really a C question, but I'll forgive that for now.
What you're looking for (and can easily find on Google, Duck Duck Go
or any other search engine, if you but utilise any of those services)
is called a "flood fill" algorithm.
But a word of advice: recursion can be tricky if you don't understand
the effect. Your method creates a very large recursive chain. This is
best avoided. Try it out "by hand". Get a piece of graph paper and draw
some shapes on it, including some complex ones. Now choose one of these
shapes and choose a starting pixel within this area and try applying
your algorithm. With a coloured pencil, colour in each square as you
go, just as the algorithm would. Also make note of the level of
recursion as you go. I think you'll be amazed. Repeat for all the
shapes on your graph paper.

--

----- Dig the NEW and IMPROVED news sig!! -----

-------------- Shaggy was here! ---------------
Ain't I'm a dawg!!

Re: filling area by color atack safety

<20240317151519.000057d0@yahoo.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34449&group=comp.lang.c#34449

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: already5...@yahoo.com (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: <ut3669$21eur$1@i2pn2.org>
<ut4020$2s8ov$1@dont-email.me>
<20240317144625.00002011@yahoo.com>
<ut6p67$3h8t0$2@dont-email.me>
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)
 by: Michael S - Sun, 17 Mar 2024 13:15 UTC

On Sun, 17 Mar 2024 12:54:34 +0000
bart <bc@freeuk.com> wrote:

> On 17/03/2024 12:46, Michael S wrote:
> > On Sat, 16 Mar 2024 11:33:20 +0000
> > Malcolm McLean <malcolm.arthur.mclean@gmail.com> wrote:
> >
> >> On 16/03/2024 04:11, fir wrote:
> >>> 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?
> >> >
> >> This is a cheap and cheerful fllod fill. And it's easy to get right
> >> and shouldn't afall over.
> >
> > Except I don't understand why it works it all.
> > Can't fill area have sub-areas that only connected through
> > diagonal?
>
> Suppose you have an image which is a chessboard. You want to fill one
> of the black squares so that it is red.
>
> If you allow connectivity through the diagonals (so two notionally
> square pixels that only meet at their corners would be connected),
> then all the black squares would turn red, not just one.
>

That's what I want.
Do fir wants something else?

Re: filling area by color atack safety

<ut6qt8$3hnat$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34450&group=comp.lang.c#34450

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: bc...@freeuk.com (bart)
Newsgroups: comp.lang.c
Subject: Re: filling area by color atack safety
Date: Sun, 17 Mar 2024 13:23:55 +0000
Organization: A noiseless patient Spider
Lines: 78
Message-ID: <ut6qt8$3hnat$1@dont-email.me>
References: <ut3669$21eur$1@i2pn2.org> <ut4020$2s8ov$1@dont-email.me>
<20240317144625.00002011@yahoo.com> <ut6p67$3h8t0$2@dont-email.me>
<20240317151519.000057d0@yahoo.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 17 Mar 2024 13:23:52 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="86cdd72051d773a92e0c8f332750da77";
logging-data="3726685"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+sDcRCE949noLQoxoDye+1"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:Of2gPKj6NFpkXd2IkK03WSvN6N4=
In-Reply-To: <20240317151519.000057d0@yahoo.com>
Content-Language: en-GB
 by: bart - Sun, 17 Mar 2024 13:23 UTC

On 17/03/2024 13:15, Michael S wrote:
> On Sun, 17 Mar 2024 12:54:34 +0000
> bart <bc@freeuk.com> wrote:
>
>> On 17/03/2024 12:46, Michael S wrote:
>>> On Sat, 16 Mar 2024 11:33:20 +0000
>>> Malcolm McLean <malcolm.arthur.mclean@gmail.com> wrote:
>>>
>>>> On 16/03/2024 04:11, fir wrote:
>>>>> 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?
>>>> >
>>>> This is a cheap and cheerful fllod fill. And it's easy to get right
>>>> and shouldn't afall over.
>>>
>>> Except I don't understand why it works it all.
>>> Can't fill area have sub-areas that only connected through
>>> diagonal?
>>
>> Suppose you have an image which is a chessboard. You want to fill one
>> of the black squares so that it is red.
>>
>> If you allow connectivity through the diagonals (so two notionally
>> square pixels that only meet at their corners would be connected),
>> then all the black squares would turn red, not just one.
>>
>
> That's what I want.
> Do fir wants something else?
>

His algorithm is the same as that presented in my textbook, where it is
called FloodFill4.

If I reread the notes I see now the significance of the '4', as it talks
about 4-connected and 8-connected versions.

Presumably you want the 8-connected version, which will have 4 extra
calls for the pixels at each corner.

Pages:1234567
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor