Page 1 of 1

Re: Can I replace palette or image map with another?

Posted: 2008-12-21T22:10:52-07:00
by anthony
Pixel Graffiti wrote:Does this mean I cannot use IM to force an 8bit 256 color image to use a pre-defined palette or image map of my choosing?
No it means you can't replace one specific palette for another.

If you want to color reduce an image to a given palette, where colors are either directly mapped or dithered to 'close' matching colors in the user supplied palette... no problem...

See IM Examples, Quantization and Dithers, Map
http://www.imagemagick.org/Usage/quantize/#map

What you can't do directly is replace each specific color to another specific but very different color, where you have over a hundred such color mappings, all at the same time. I am talking about pure, or near pure colors here.

You can only map each specific color one at a time. Eg you can not just map the colors red -> blue, blue -> green, white -> gray, etc etc, except by doing do one specific color at at time.

This can also make it difficult to do a cyclic map eg; red->blue, blue->green and green->red.

I followed the example from the IM Usage pages entitled: Dither using Pre-Defined Color Maps and used the +dither attribute to turn off dithering so that the palette would not be altered and colors would simply be replaced pixel for pixel.
Note quite. You probbaly have the operation straight, but the way you said it was wrong. +dither does replace each color with the closest matching color (or should) in the given palette. However the images palette will be completely replaced by the given map. The images original palette or color map will not retained or saved).

In fact it is very rare for any of the original palette to be retained by IM as IM generally will 'lose it' during some image processing operation, and Im wll try to re-create a new palette when saving the image to a file format that needs one (like GIF, or XPM)

I did manage to change the palette to a new one using this method, however, the resulting palette is not in the same order and possibly not the same colors as the palette I specified in the commandline.
Yes the saved images palette is re-created. So the order may not be the same. In fact if the image did not use a specific color, that color would probably not be in the saved images palette either!

So while the resulting image looks normal when loaded or viewed in any paint prog it looks like a train wreck when it is viewed from within the 8bit 256 color DOS prog I need it to be used with because this particular program has a fixed color palette it uses.
That is a problem. IM was never designed to cater to a specific program with a fixed color palette. Remember IM is a general image processor.

However IM is open source, and it is possible someone could write a coder to output an image with a specific 'fixed' palette. There might even be a coder already doing this, but I am not that familiar with the coder modules. It is open source and those modules are simple, so should be fairly easy to do.
Is this simply not possible with IM?
Possible yes, but not from the command line, at least not at this time. IM is open source, anyone can modify and contribute to it.
If so does anyone know of a command line program I can invoke from a batch file for quick batch conversion of many files using some sort of specific pixel for pixel palette conversion method? Any help would be appreciated tremendously.
I have not heard of one, though there are a LOT of GIF specific programs, some designed more for GIF animations that might be able to do this. I have not looked but you could try "gifsicle" which also has color replacement options. It might just do it simply in the way you want. It might not.

Also I suggest you look at and compile "giftrans" which can output and directly manipulate the color palette of GIF file format. I do suggest you at least use the patched one from my personal downloads page (patch if for outputting the correct GIF animation dispose values)...
http://www.cit.gu.edu.au/~anthony/software/#giftrans