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

Re: [pygame] surfarray.pixels3d(). I'm stumped.



On Aug 22, 2004, at 9:18 PM, Jasper Phillips wrote:

I get the same TypeError as with my previous code, on the last line of
filter3x3()...

I encountered a similar problem a few months ago, and solved it with help from the list. Here's my solution. It softens the RGB and alpha separately, then combines the two back into a single image.

def softenImageArray(orig):
""" shamelessly lifted from arraydemo.py"""
soften = Numeric.array(orig)*1
soften[1:,:] += orig[:-1,:]*8
soften[:-1,:] += orig[1:,:]*8
soften[:,1:] += orig[:,:-1]*8
soften[:,:-1] += orig[:,1:]*8
soften /= 33
return soften

def superSoftenImage(img):
""" just a wrapper for softenRgbArray. this softens both color and
alpha channel in the "img" surface. """
rgbarray = pygame.surfarray.array3d(img)
transformedArray = softenImageArray(rgbarray)
newImg = pygame.surfarray.make_surface(transformedArray).convert_alpha(img)
origAlphaArray = pygame.surfarray.array_alpha(img)
softenedAlphaArray = softenImageArray(origAlphaArray).astype( origAlphaArray.typecode())
newImgAlphaArray = pygame.surfarray.pixels_alpha(newImg)
newImgAlphaArray[:] = softenedAlphaArray
return newImg

//jack