← Back to team overview

phatch-dev team mailing list archive

Re: variable border action

 

Hey,

I was thinking maybe it's not a good idea for each action to handle 'RGBA'
to 'P' conversion on its own. There are many actions that deal with
transparency and convert the images to 'RGBA'. To name a few: highlight,
color to alpha, mask. It is better to leave the 'RGBA' to 'P' conversion to
the save action, unless we have to. Or else the performance will suffer
because of all the overhead of repeating the same conversion in every
action.

Best Regards,
Nadia

On Mon, Jun 1, 2009 at 10:34 PM, Nadia Alramli <nadiana@xxxxxxxxx> wrote:

> Hey Erich,
>
> Sorry, It took me sometime to get back to you on this. I needed to play
> with convert a bit to make sure I have the right answer.
>
>
>> In PIL.Image.Image._new, which is what actually provides the new image
>> when convert() is called, a type 'P' Image object will be assigned a new
>> color palette.  This color palette has no relation to the color palette of
>> the actual image. (I consider this to be a very serious bug in PIL).
>>
> I agree, those bugs are really annoying.
>
>
>>    So what I do is get the palette from the converted image, and assign
>> that to the Image.palette.palette.
>>
>>
>>
>> Secondly, since the color palette is most likely different after hte
>> conversion, a simple index will not work. Instead save the transparent color
>> value by looking up the index for it in the original palette. When the new
>> palette is assigned, I then search for the transparent color value and save
>> the appropriate index in the info['transparency'] attribute.
>>
> I can see a possible issue here. The colors in the palette are not
> necessaryly unique. So it is possible to match the wrong index. In my
> opinion a simpler solution is to create the new image in mode 'RGBA' instead
> of 'RGB'. The GIF transparency will be kept this way. Then to convert from
> RGBA to P you can use the updated solution here:
> http://nadiana.com/pil-tips-converting-png-gif#Thesolution
> I updated the article with a much better solution. I discovered it today
> while playing with convert to find a solution for your issue.
>
> I'm glad to have you in our team :)
>
> Regards,
> Nadia
>
>

Follow ups

References