PerlMagick equivalent of "+map," remove Local Color Tables?

PerlMagick is an object-oriented Perl interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning PerlMagick.
Post Reply
mirkon

PerlMagick equivalent of "+map," remove Local Color Tables?

Post by mirkon »

I have a script that regularly churns out a bunch of animated GIFs, which, because of the software toolchain on the other end, absolutely cannot have local color tables. Right now I'm saving the animations with their local color tables, then using the "+map" command-line option to convert them out - but I'm pretty sure that doing this in pure PerlMagick, and eliminating the need to Write a temporary image, would save me some processing time (which I can't get enough of).

Problem is I can't figure a way to make this happen. I've tried various permutations of variable sets, the Quantize() function, and some dithering stuff to defeat local color tables from within PerlMagick, but nothing works.

So,

Is there a PerlMagick equivalent to the +map option? (I can't find anything in the PerlMagick docs about wholesale colormap operations like -/+map) Alternatively, does anyone know of another method to remove local color tables from an animated GIF using PerlMagick?

Any input appreciated, thanks!
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: PerlMagick equivalent of "+map," remove Local Color Tables?

Post by magick »

Try the Remap() PerlMagick method to generate a global colormap.
mirkon

Re: PerlMagick equivalent of "+map," remove Local Color Tables?

Post by mirkon »

That sounds like the right track for me to be on, but I still can't figure out how to use it.

I don't see any mention of Remap() in my installed perldoc page or on http://www.imagemagick.org/script/perl-magick.php - is there somewhere else I can look for documentation on PerlMagick Remap?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: PerlMagick equivalent of "+map," remove Local Color Tables?

Post by magick »

We will update the PerlMagick's web page with Remap() by sometime tomorrow. Another option is to use Map() or Quantize() with the global => 'true' option.
mirkon

Re: PerlMagick equivalent of "+map," remove Local Color Tables?

Post by mirkon »

Thanks for that tip. Using Remap with some arbitrary palette image (http://www.imagemagick.org/Usage/quantize/netscape.gif for instance) is successfully dithering my GIF frames, though it still isn't removing my local color table entries according to giftrans.

I don't think it much matters though, because now the dithering itself is taking more CPU time than when I save an intermediate file and use `convert ... +map ...`. I don't suppose there is a way to harness some faster color-mapping method from within PerlMagick? Otherwise it looks like +map is the best I'm going to be able to get.
mirkon

Re: PerlMagick equivalent of "+map," remove Local Color Tables?

Post by mirkon »

I've been experimenting with this a little more, and I think I may have hit upon the source of my problem.

If I set each frame of my animation to type => "Palette" (per tip from http://www.imagemagick.org/Usage/quantize/#map_common) in PerlMagick, then use Remap(), the local color tables are gone. But the transparency in my animation frames is replaced with black.

Contrarily, if I set the frames to type => "PaletteMatte" - or, after setting to type Palette, use Transparent() to re-transparify the black - local color tables remain, despite the Remap().

It looks like the transparent color is getting in the way of PerlMagick successfully merging the colormaps. But the +map operator is able to handle transparency just fine. Is there a way to work around this?
tcrass
Posts: 38
Joined: 2009-11-22T11:12:52-07:00
Authentication code: 8675309

Re: PerlMagick equivalent of "+map," remove Local Color Tables?

Post by tcrass »

Hi there,

does anyone know if there is there a way to *prevent* dithering when calling Remap() -- and is willing to share this information with me? ;-)

Thanx --

tcrass
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: PerlMagick equivalent of "+map," remove Local Color Tables?

Post by magick »

Remap() has a dither-method option. Use "None" to not dither the results.
tcrass
Posts: 38
Joined: 2009-11-22T11:12:52-07:00
Authentication code: 8675309

Re: PerlMagick equivalent of "+map," remove Local Color Tables?

Post by tcrass »

magick wrote:Remap() has a dither-method option. Use "None" to not dither the results.
Ah, thanks! But this is not yet documented on http://www.imagemagick.org/script/perl-magick.php, is it?

Regards --

tcrass

[EDIT] Hmm... seems not to work. The following piece of code outputs a dithered image (error handling omitted):

Code: Select all

my $img = Image::Magick->new();
$img->Read('some_image.png');
my $map = Image::Magick->new();
$map->Read('some_palette.png');
$img->Remap(image => $map, 'dither-method' => 'none');
$img->Write('remapped.png');
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: PerlMagick equivalent of "+map," remove Local Color Tables?

Post by magick »

We can reproduce the problem you posted and will have a patch available by sometime tomorrow. You'll need to set the new 'dither' option to 'false' to prevent Remap() from dithering its results.
tcrass
Posts: 38
Joined: 2009-11-22T11:12:52-07:00
Authentication code: 8675309

Re: PerlMagick equivalent of "+map," remove Local Color Tables?

Post by tcrass »

magick wrote:We can reproduce the problem you posted and will have a patch available by sometime tomorrow.
Great!

Thanx --

tcrass
Post Reply