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

Re: [pygame] Stuck with surfarray



Jasper Phillips wrote:
Hmmm, actually I just wanted to swap the RGB, and leave the A intact.  But I
think I can work this out with a more complicated Numeric.where()
There are two options then, use this 'array2d' method and use some bit masking, or use an 'array3d' version that properly copies the alpha. Not sure which will be faster actually. I also see it is not possible to call surfarray.make_surface() on a 2d array and get more than an 8bit image.

def swapRGB2(surf, srcRGB, dstRGB):
dstsurf = surf.convert(32, pygame.SRCALPHA)
dstarray = pygame.surfarray.pixels3d(dstsurf)
srcarray = pygame.surfarray.array3d(surf)
dstarray[:] = Numeric.where(srcarray == srcRGB, dstRGB, srcarray)
return dstsurf