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

Re: [pygame] Surfarray question



Hi Abhinav,

You have found some unexpected behavior in pygame.surfarrray. blit_array is improperly named. It is a straight copy, not a true blit. And when a 3d array is copied to a 32 bit source alpha surface the per-pixel alpha is 0. The destination surface is completely transparent. The only workaround I can find is to set alpha to 255 after the blit_array() call:

       r_mysurface = storeObject.lib_get(o_id,"__render_surface")
       pygame.surfarray.blit_array(r_mysurface, r_myarray)
	pygame.surfarray.pixels_alpha(r_mysurface)[...] = 255


In Pgame 1.9 this will also work:

	r_mysurface.fill((0,0,0,255), None, pgyame.BLIT_RGBA_MAX)


I don't know if the 0 alpha is a bug or simply a peculiarity. Elsewhere in Pygame a 3-element color has an alpha of 255. But blit_array has probably set alpha to 0 since it was first implemented. It has simply gone unnoticed until now. Should it be changed?

Lenard

Abhinav Lele wrote:
Hi,

I am using surfarray to blit an image.
When i use array2d i see the image being renderer, but with array3d i dont.


I use the following code to load image :

            r_temp_surface = pygame.image.load(fpath).convert_alpha()
            salpha =  r_temp_surface.get_alpha()
            r_surface = pygame.Surface((o_w,o_h)).convert_alpha()
            pygame.transform.smoothscale(r_temp_surface,(o_w,o_h),r_surface)
            #if salpha != None:
            #    r_surface.set_alpha(salpha)
            r_array = pygame.surfarray.array3d(r_surface)
            print "New Surface Alpha: " , r_surface.get_alpha()
            storeObject.lib_set(o_id,"__render_surface",r_surface)
            storeObject.lib_set(o_id,"__render_array",r_array)



To render I use :

        r_myarray = storeObject.lib_get(o_id,"__render_array")
        r_mysurface = storeObject.lib_get(o_id,"__render_surface")
        pygame.surfarray.blit_array(r_mysurface, r_myarray)
        surface.blit  (r_mysurface,(gx,gy))



Plz help.

-Abhinav


--
Lenard Lindstrom
<len-l@xxxxxxxxx>