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

Re: [pygame] Blitting to alpha channel or using another image's alpha channel



Thanks for the suggestions! I gave them a shot, but I couldn't get
either to work properly.

Ian Mallett <geometrian@xxxxxxxxx> wrote:
> You could probably just take the mask surface (RGBA surface) and blit a RGB
> surface over it, then take the resulting surface and get your effect:

Okay, I have the mask surface with the mask values in the alpha
channel. As far as I can tell, blitting an RGB image over it resets
the alpha channel to be entirely opaque.

René Dudfield <renesd@xxxxxxxxx> wrote:
> I think you can do this with Surface.set_masks() and surface.set_shifts.
>
> Get the r,g,b,a masks, and shifts, then change them so that only the a
> part is valid any more.

I tried this, but it seems that the parts of the pixels that aren't
valid just get overwritten. Here's one attempt:

    newsurf=pygame.Surface((128,128),flags=pygame.SRCALPHA)
    newsurf.blit(sourcesurf,(0,0))
    rm,gm,bm,alm=newsurf.get_masks()
    rs,gs,bs,als=newsurf.get_shifts()
    newsurf.set_masks((alm,0,0,0))
    newsurf.set_shifts((als,0,0,0))
    masksurf.set_masks((alm,0,0,0))
    masksurf.set_shifts((als,0,0,0))
    newsurf.blit(masksurf,(0,0))
    newsurf.set_masks((rm,gm,bm,alm))
    newsurf.set_shifts((rs,gs,bs,als))

I tried to get the blit to treat both surfaces' alpha channels as if
they were red channels, and to ignore everything else. This does
transplant the alpha channel successfully, but it also seems to
overwrite all the other channels too. I tried other combinations, but
had no luck.