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

Re: [pygame] Stuck with surfarray



Jasper Phillips wrote:
def swapRGB( surf, sourceRGB, destRGB ):
    array = pygame.surfarray.array3d( surf )
    array = N.where( array == sourceRGB, destRGB, array )
    return pygame.surfarray.make_surface( array )

I'm stumped, What's the trick?  If only make_surf would take an RGB and
an alpha array, or surfarray could handle RGBA all at once. :-/

Having a RGBA array would make this a little easier, but you certainly aren't stuck without it. If you want to swap the complete RGBA, use a "2D" array and the mapped colors.

def swapRGBA(surf, srcRGBA, dstRGBA):
array = pygame.surfarray.array2d(surf)
src = surf.map_rgb(srcRGBA)
dst = surf.map_rgb(dstRGBA)
array = Numeric.where(array == src, dst, array)
return pygame.surfarray.make_surface(array)