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

Re: [pygame] ChangeColor Routine



On Sun, 13 Feb 2005 14:03:04 +1100, Rene Dudfield <renesd@xxxxxxxxx> wrote:
> I thought this might work.  But == does not work on the [1,1,1].  It
> only works on the each element.  Not sure how to make it do that.
> 
> def abrokenway(pic, oldcolor, newcolor):
>     array = pygame.surfarray.pixels3d(pic)
>     mask = Numeric.where(array == oldcolor, 1, 0)
>     Numeric.putmask(array, mask, newcolor)

I think you could use Surface.map_rbg to get the value for oldcolor
and newcolor and then assign them using pixels2d instead of 3d.

An to the original poster: The surfarray module isn't any faster than
get_at and set_at if you are setting and testing single pixels. The
speed increase is attained by eliminating Python loops using Numeric's
operators and special functions.


-- 
Sami Hangaslammi