Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
139 user(s) are online (74 user(s) are browsing Forums)

Members: 0
Guests: 139

more...

Headlines

 
  Register To Post  

Using Flood()
Just popping in
Just popping in


See User information
Hi all,
This might sound a bit stupid, but I've been able to most things when programming the Amiga, but flood fill isn't one of them. I have always been missing something but cannot work out what it is. Now, I really need to do it for a project I am working on and it still doesn't work.

I've knocked up a quick example to see if I could get it working but even the small example doesn't work. It's meant to draw a circle and fill it. Should be easy, right? The circle draws fine, but no fill happens. Can anyone see what I am doing wrong?

Example code below, compiled with SAS/C 6.x and run/tested on AmigaOS 4.1.4:

/* Attempt to test flood fill */
#include <exec/types.h>
#include <graphics/gfx.h>
#include <graphics/gfxmacros.h>
#include <intuition/intuition.h>

#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/graphics.h>
#include <proto/intuition.h>

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

int main(int argcchar *argv[])
{
    
struct Window *win;

    
win OpenWindowTags(NULL,
                         
WA_InnerWidth,    200,
                         
WA_InnerHeight,   200,
                         
WA_IDCMP,         IDCMP_CLOSEWINDOW,
                         
WA_Title,         "test flood",
                         
WA_DragBar,       TRUE,
                         
WA_CloseGadget,   TRUE,
                         
WA_NoCareRefreshTRUE,
                         
WA_SmartRefresh,  TRUE,
                         
TAG_DONE);
    if(
win)
    {
        
WORD centreXcentreY;
        
struct TmpRas tr;
        
LONG size;
        
UBYTE *buf;

        
centreX = (win->Width win->BorderLeft win->BorderRight) / 2;
        
centreY = (win->Height win->BorderTop win->BorderBottom) / 2;

        
SetOutlinePen(win->RPort1);
        
SetAPen(win->RPort1);
        
SetDrPt(win->RPort0xFF);
        
DrawCircle(win->RPortcentreXcentreY25);

        
size = (200 200) / 8;

        
buf AllocVec(sizeMEMF_CHIP);
        if(
buf)
        {
            
InitTmpRas(&trbufsize);
            
win->RPort->TmpRas = &tr;

            
Flood(win->RPort0centreXcentreY);

            
win->RPort->TmpRas NULL;
            
FreeVec(buf);
        }

        
Wait(<< win->UserPort->mp_SigBit);

        
CloseWindow(win);
    }
    return 
0;
}


Go to top
Re: Using Flood()
Not too shy to talk
Not too shy to talk


See User information
Your TmpRas buffer is too small.

From the autodocs:

Quote:

NOTES
In order to use Flood, the destination RastPort must
have a valid TmpRas raster whose size is as large as
that of the RastPort
.



The bitmap used in the RastPort is that of the screen, no matter how small the window is.

Use

GetBitMapAttr(win->RPort->BitMap,BMA_WIDTH);
GetBitMapAttr(win->RPort->BitMap,BMA_HEIGHT);
size = (((15) & ~15) / 8) * h;

Go to top
Re: Using Flood()
Not too shy to talk
Not too shy to talk


See User information

Well, I tested it on OS 4 and you are right, it does not work, not matter what I do.

I changed your code like so:

/* Attempt to test flood fill */

#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/graphics.h>
#include <proto/intuition.h>

#include <stdlib.h>

int main (int argc,char **argv)

{
struct Window *win;

win OpenWindowTags(NULL,
        
WA_InnerWidth,    200,
        
WA_InnerHeight,   200,
        
WA_IDCMP,         IDCMP_CLOSEWINDOW IDCMP_VANILLAKEY,
        
WA_Title,         "test flood",
        
WA_FlagsWFLG_DRAGBAR WFLG_CLOSEGADGET WFLG_NOCAREREFRESH WFLG_ACTIVATE,
        
TAG_DONE);
if(
win)
    {
    
WORD centreXcentreY;
    
struct TmpRas tr;
    
UBYTE *buf;
    
short w,h;
    
struct Message *msg;
    
short mode argc atoi(argv[1]) : 1;

    
Printf ("mode = %ld\n",mode);

    
centreX = (win->Width win->BorderLeft win->BorderRight) / 2;
    
centreY = (win->Height win->BorderTop win->BorderBottom) / 2;

    
SetAPen(win->RPort1);
    
DrawEllipse(win->RPortcentreXcentreY25 ,25);

    
GetBitMapAttr (win->RPort->BitMap,BMA_WIDTH);
    
GetBitMapAttr (win->RPort->BitMap,BMA_HEIGHT);

    
buf AllocRaster(w,h);
    if(
buf)
        {
        
InitTmpRas(&trbufRASSIZE(w,h));
        
win->RPort->TmpRas = &tr;

        
SetAPen (win->RPort,2);
        
SetOutlinePen (win->RPort,1);
        
Flood(win->RPortmodecentreXcentreY);

        
win->RPort->TmpRas NULL;
        
FreeRaster(buf,w,h);
        }

    
Wait ((<< win->UserPort->mp_SigBit) | SIGBREAKF_CTRL_C);

    while ((
msg GetMsg (win->UserPort)))
        
ReplyMsg (msg);

    
CloseWindow(win);
    }

return 
0;
}


It works well on WinUAE in 3.1 and 3.9 with or without Picasso96. But on OS4 I get corrupted graphics. It does *something* but no flood fill.

Go to top
Re: Using Flood()
Home away from home
Home away from home


See User information
I tried your test program building natively.

It didn't work here either.

First thought, from reading the description in the autodocs, it refers to pen colors of pixels etc. Pen are less meaningfull on a 16/32 bit screen, so could be an issue related to that. I would try on an 8bit workbench, but I'm running a long video conversion at the moment, so can't mess with my WB screen till it's done


Go to top
Re: Using Flood()
Just popping in
Just popping in


See User information
Thanks thomas and broadblues for having a look.

Firstly, I didn't realise it was the screen's rastport. I thought it was the window, so that is a definite issue. Thanks for the correction thomas.

Actually, the real program I am writing is on OS4, I just thought I would go back to a simpler example and build it up from there once it works.

On the real program I end up with the whole window being filled with corrupted rubbish when I try to floodfill. I know that what I am filling is fully enclosed. Maybe it is a 16/32 bit screen issue. I will try a few scenarios and have a look.

Cheers!

Go to top
Re: Using Flood()
Not too shy to talk
Not too shy to talk


See User information
Quote:
I didn't realise it was the screen's rastport. I thought it was the window, so that is a definite issue.


It's the window's rastport. But all rastports share the screen's bitmap.

And as you might have seen in my source code, you should use AllocRaster instead of AllocVec(...,MEMF_CHIP). This is because RTG systems might allow to allocate raster data in FAST mem and CHIP mem is rare.

Go to top
Re: Using Flood()
Just popping in
Just popping in


See User information
Thanks.

Actually, the real project uses AllocRaster(). I was just experimenting in my example, but your tips are appreciated and I really should be using GetBitMapAttr() which I wasn't before, so thanks for that too.

Go to top
Re: Using Flood()
Home away from home
Home away from home


See User information
Quote:



It's the window's rastport. But all rastports share the screen's bitmap.


No they don't. Not on an OS4 screen with compositing enabled. Windows have their own bitmap.


Go to top
Re: Using Flood()
Just popping in
Just popping in


See User information

Maybe you can do it with Areas.

I had trouble with Flood on AOS4 and I finally gave up and used AreaEllipse
to draw a filled ellipse/circle.

I have not tried AreaFill on an arbitrarily shaped area, but it might be worth trying that.

Tom

Go to top
Re: Using Flood()
Home away from home
Home away from home


See User information
Have now tried on an 8bit screen, and with the example given I see the window filled with corruption, and diagonal lines.

Clearly something broken.

I'll put in abug report on it.

Go to top
Re: Using Flood()
Just can't stay away
Just can't stay away


See User information
I had trouble with Flood on AOS4 and I finally gave up and used AreaEllipse
to draw a filled ellipse/circle.


I had a real serious problem with the Flood in Halo. The 'Library' episode is grimist chapter of the adventure after '343 Guilty Spark'. Ooops sorry, different 'Flood' reference. BTW, HALO is a fantastic program -. I'd pay $$$ to see it on the AmigaOne.

Go to top
Re: Using Flood()
Just popping in
Just popping in


See User information
@broadblues

Hmm. I get the same weird result in an 8-bit screen. I guess there is a bug.

Unfortunately I can't use AreaFill() because I'm filling a pie chart slice which has an arc. I guess I'll have to do my own floodfill as a workaround until it's fixed.

Go to top
Re: Using Flood()
Not too shy to talk
Not too shy to talk


See User information

You can use AreaMove / AreaDraw / AreaEnd to fill a random area.

Here is an example: http://thomas-rapp.homepage.t-online.de/examples/piechart.c

Go to top
Re: Using Flood()
Home away from home
Home away from home


See User information
@Steady
I would definetely go with Thomas' tecnique rather than flod even if flood woorked, it would be faster for sure.

@Thomas
shouldn't fcos == cosf ?


Go to top
Re: Using Flood()
Just popping in
Just popping in


See User information
Oh yes, definitely. Flood was always my last option but I had it in my head that the area functions wouldn't work. Happily, I was wrong.

Thanks Thomas.

Go to top
Re: Using Flood()
Not too shy to talk
Not too shy to talk


See User information
Quote:

@Thomas
shouldn't fcos == cosf ?


This example was developed with Dice C long ago and it has cos with double floats and fcos with single floats.


Quote:
I had it in my head that the area functions wouldn't work.


They won't work if you don't initialise the AreaInfo in addition to the TmpRas.


Go to top
Re: Using Flood()
Just popping in
Just popping in


See User information
That's OK. I had assumed that. I might go for a few more points though as 10 degrees might have edges that are too long and straight, but we'll see.

Go to top
Re: Using Flood()
Home away from home
Home away from home


See User information
Quote:

This example was developed with Dice C long ago and it has cos with double floats and fcos with single floats.


Ha! Should have spotted that I used to use Dice C all the time....





Go to top
Re: Using Flood()
Just popping in
Just popping in


See User information
BTW. Got the pie charting stuff working thanks to the AreaFill example.

Thanks Thomas.

Go to top

  Register To Post

 




Currently Active Users Viewing This Thread: 1 ( 0 members and 1 Anonymous Users )




Powered by XOOPS 2.0 © 2001-2023 The XOOPS Project