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

Re: [pygame] Fubared set_alpha()



Derek Simkowiak wrote:
    What do you mean by "clearing the destination first"?
oh, just fill it with zeros... Surf.fill(0)


It looks to me like SRCALPHA flag of the source Surface is the only one that matters when blitting.

whoops, substitute SRCALPHA with pixelalphas. none of the regular SDL blitters effect the destination pixel alpha. this is what the extra blitters pygame uses tries to fix.


dest.set_alpha(None, 0)  # Clear SRCALPHA flag on dest
source.set_alpha(None, 0) # Clear it on the source also
dest.blit(source, [0,0])
    ...and ta-da, things work.
ah good, a fair enough workaround for now.


if(dst->format->Amask && dst->flags&SDL_SRCALPHA &&
(dst->format->BytesPerPixel == 2 || dst->format->BytesPerPixel==4))

Is this why I need to clear the SRCALPHA bit on the _destination_ image? I don't know.
yes, this is where pygame is deciding if it should handle the blit itself, or just call the regular SDL blit function. in cvs there's a new test to this case, if the source image has pixel alphas but SRCALPHA is not enabled, we go with SDL's blitter, since it does handle this case (and is faster then the pygame blitters)


Again, please revert that checkin until this problem has been more fully analyzed. (Also, my test results from before must be ignored, as I was clearing the SRCALPHA on my _destination_ surface without knowing it.)
i put in two changes to pygame. a little different than what your patch did. first the set_alpha() function does set the surface alpha to 255 if no alpha is passed. but this still disables the SRCALPHA flag. secondly the blit function now uses SDL's blitter for the case where the source has pixel alphas, but SDL_SRCALPHA is not set.


My question is, with SDL, am I supposed to clear the SRCALPHA on the destination surface, the source surface, or both? I was always under the impression it had to be on the cleared on the source surface. And my second question is, what does that translate into with PyGame?
hopefully some of the other answers cleared this up more. SDL's blitters do not effect the destination pixel alpha, except in the 'special case' you were relying on last year. i didn't realize there was a case where SDL did the job so pygame just always used my own blit. but you also found a couple bugs/oddities in that code so you were having extra troubles.

i've tested the new cvs code against your original plan, and it does work. for now you can also disable the destination SRCALPHA, but that is only so pygame doesn't try to 'help' when it doesn't need to.