[Image-SIG] Paste with alpha not working correctly

Jerome Leclanche adys.wh at gmail.com
Sun Aug 29 19:53:34 CEST 2010


Hi Helge

I believe I've run into that issue before when creating composited
images. I fixed it with the following hack in libImaging/Paste.c:135 @
paste_mask_RGBA
Replaced the for loop with the following:

        for (y = 0; y < ysize; y++) {
            UINT8* out = (UINT8*) imOut->image[y+dy]+dx*pixelsize;
            UINT8* in = (UINT8*) imIn->image[y+sy]+sx*pixelsize;
            UINT8* mask = (UINT8*) imMask->image[y+sy]+sx*4+3;
            for (x = 0; x < xsize; x++) {
                for (i = 0; i < pixelsize; i++) {
                    *mask = 255; // XXX Disable masking (transparency bug)
//                  if (i == 3) {*out = 255; out++, in++;continue;} //
XXX Disable masking (transparency bug)
                    *out = BLEND(*mask, *out, *in, tmp1, tmp2);
                    out++, in++;
                }
                mask += 4;
            }
        }
    }

(You may want to swap the comments, I don't remember which line fixed
it, it's been a while)

J. Leclanche / Adys



On Sun, Aug 29, 2010 at 6:42 PM, Helge <image-sig at online.de> wrote:
> Hello Edward, hello list,
>
> Edward Cannon schrieb:
>>
>> you are doing something "wrong." the paste command ignores the alpha
>> channel entirely, the only
>> way it will use it is if the image also used as a mask ie
>>   comp.paste(fg, (0,0), fg)
>> which will do what you will expect, use fg's mask to do the blending.
>> adding a different mask
>> is like replacing the alpha in fg with the different mask. The way to
>> make a white blend to transparent
>> is to make a white image and then add the gradient as a mask.
>
> Sorry this does not solve my problem at all. I don't want to do a white
> blend to transparent but want to paste multiple images with mask on a
> transparent bg. Using code like this
> fg=fg.convert("RGBA")
> fg.putalpha(mask)
> bg.paste(fg,(0,0),fg)
> instead of using a separate mask in the paste call does not remove the tint
> from the bg but will apply the alpha twice (fg is less visible).
>
>> I am not
>> entirely sure if this will generalize
>> to your bigger problem, if you still have trouble post a sample picture or
>> two.
>
> To clarify my intention: I want to make a collage of multiple images on a
> transparent bg with mask. So the blend should go from transparent to image
> for each image (and if already another image was pasted at the place this is
> taken into account). Result should be a png file with alpha that can be
> viewed on different background colors (or even images). The transparent
> parts should have no "tint" except the colors of my pasted images.
>
> I uploaded an example here:
> <https://content.wuala.com/contents/nanyouco/Images/PIL/index.html?key=JWSJEVSOHCCJ>
> There are only two variants in the upper table that are correct:
> * the upper right corner of a collage on transparent "white" presented on a
> white bg
> * the lower left corner of a collage on transparent "black" presented on a
> black bg
> I was expecting in each table row all images appear identical (in all rows
> the same picture set is shown).
>
> Best Regards,
> Helge
> _______________________________________________
> Image-SIG maillist  -  Image-SIG at python.org
> http://mail.python.org/mailman/listinfo/image-sig
>


More information about the Image-SIG mailing list