← Back to team overview

phatch-dev team mailing list archive

Re: variable border action

 

Hi,

This was my policy until now:
> - if an action needed to do a mode conversion, it was allow to do so.
> However it should exclude any case where it is not necessary. For
> example for the variable border, the action should not convert to RGBA
> in case of positive pixel border and in case of negative pixel border
> when the opaqueness is 100%

I agree it is that case in most situations. But what if the original image
mode was 'P' with transparency? The easiest solution to keep transparency in
this case is to convert to 'RGBA' and keep it this way. Otherwise we have to
replicate the save action conversion functionality and convert back to 'P'
while keeping transparency. I think performance here matters more than
memory.

I agree we should only convert when we have to. And only convert back to 'P'
if absolutely necessary. In this case the border action can convert to
'RGBA' if the border is negative or if the image was mode 'p' with
transparency.

Best Regards,
Nadia


>
> So the save action should take care of converting to a mode which is
> supported by the file type if necessary. I'd would not like to convert
> by default in the beginning to RGBA as that might be unnecessary for
> many action lists, increase the memory and convert images which
> shouldn't be converted.



>
>
> Best regards,
> Stani
>
> On Tue, Jun 2, 2009 at 12:40 AM, Nadia Alramli <nadiana@xxxxxxxxx> wrote:
> > 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
> >>
> >
> >
>
>
>
> --
> Phatch Photo Batch Processor - http://photobatch.stani.be
> SPE Python IDE - http://pythonide.stani.be
>
> _______________________________________________
> Mailing list: https://launchpad.net/~phatch-dev<https://launchpad.net/%7Ephatch-dev>
> Post to     : phatch-dev@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~phatch-dev<https://launchpad.net/%7Ephatch-dev>
> More help   : https://help.launchpad.net/ListHelp
>

Follow ups

References