[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Flood Fill



Why is numarray faster?
Good question, but I assume it has to do with how the access to
surface is achieved since surfaces also can bee a hardware surface.
Check with the SDL developers for a more in depth answer.

About locking.
When you assign a surface to a surfarray it locks that surface
for as long as the surfarray exists. Deleting it in the end
is just to make sure the garbage handling does its job immediately,
it may be unnecessary.

The get_at and set_at commands only locks the surface while they
are executing and then unlocks the surface again . So surface.lock() should in theory avoid the locking part of the
_at commands.


Thanks for the bug catching.
But thinking about it I think that comparison should
be removed completely. It only makes sense if you fill
with a solid color.

try:
       surfaceA=pygame.surfarray.pixels2d(surface)
       patternA=pygame.surfarray.pixels2d(pattern)
       old_color = surfaceA[x][y]
       #new_color = patternA[x%pat_width][y%pat_height]#make sure that surface color is not the same as the pattern color
       usearray=True
   except:
       surface.lock()
       pattern.lock()
       old_color = surface.get_at((x,y))
#       new_color = pattern.get_at((x%pat_width, y%pat_height))
       usearray=False
#    if old_color == new_color : return #can't fill with same color
Bo)


Knapp wrote:

One other question. Why is numarray faster?
It would seem that line 2 and 3 are setting up a surface.get_at in the
background.
Also why don't you lock the surface for the surfarray? I know it does
it by itself but then so does surface.get_at. It would look to me like
these both would run at the same speed. Why is numarray faster?

Also note the error correction in line 11.

01   try:
02       surfaceA=pygame.surfarray.pixels2d(surface)
03       patternA=pygame.surfarray.pixels2d(pattern)
04       old_color = surfaceA[x][y]
05       new_color = patternA[x%pat_width][y%pat_height]
06       usearray=True
07   except:
08       surface.lock()
09       pattern.lock()
10       old_color = surface.get_at((x,y))
11       new_color = pattern.get_at((x%pat_width, y%pat_height))
12       usearray=False

On 11/30/05, Peter Shinners <pete@xxxxxxxxxxxx> wrote:


On Wed, 2005-11-30 at 14:16 +0100, Bo Jangeborg wrote:


Talking about numeric, are there any plans to replace it with scipy ?


Do you mean replacing Numeric with the newer numarray? It is an overdue
change. Originally the two array libraries were a bit different, but
these days they are compatable.

The thing I didn't like about numarray is that it is actually slower for
"smaller" sized arrays. Many game sprite images would fit into this
smaller category. It's been way too long since I looked into this
though.