How to change BMP color without changing original palette?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
swit
Posts: 3
Joined: 2017-07-15T08:17:12-07:00
Authentication code: 1151

How to change BMP color without changing original palette?

Post by swit »

Hello,
I'm trying to use ImageMagick to switch single color that exists in BMP image original palette (#ffff00) into another color from existing pallete (#800000). Here is the code I’ve tried:

Code: Select all

magick.exe input.BMP -fill "#800000" -opaque "#ffff00" -type palette output.BMP
The problem is that ImageMagick automatically optimizes the pallete and moves colors around. This image shows the problem (input above, output below)
Image
Is there a way to preserve the original pallete (it must stay exactly the same, colors can't be deleted or moved around) and simply change the color on the image using one of the colors on the pallete? If it's not possible with ImageMagick what tool I can use to achieve this? (needs to support windows, linux, OSX and accept command line/terminal code).

Here is the input image in case someone would like to experiment:
https://www.dropbox.com/s/49170cjtorgqe ... R.BMP?dl=1
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to change BMP color without changing original palette?

Post by snibgo »

IM doesn't give the user control of the palette. Gimp does, somewhat, so that might do what you want. And you can drive Gimp from the command line.
snibgo's IM pages: im.snibgo.com
swit
Posts: 3
Joined: 2017-07-15T08:17:12-07:00
Authentication code: 1151

Re: How to change BMP color without changing original palette?

Post by swit »

Thanks, snibgo. The feature is needed for game modification installed by a player. Distributing whole gimp in a mod package would be excessive (especially for 3 operating systems) since this change is meant to be done ‘on the fly’ for hundreds of files. Distributing already converted files would be better but that would still increase package size significantly.

Any other ideas for simple tools that could do the job without messing with pallete? Thanks in advance.
User avatar
Sam.
Posts: 6
Joined: 2012-02-10T18:26:10-07:00
Authentication code: 8675308
Location: USA

Re: How to change BMP color without changing original palette?

Post by Sam. »

As snibgo said, IM doesn't give you much control over the palette. With remap you can define exactly what colors to use in the palette, but IM will still probably reorder it.
swit
Posts: 3
Joined: 2017-07-15T08:17:12-07:00
Authentication code: 1151

Re: How to change BMP color without changing original palette?

Post by swit »

Thanks Sam. I've just checked how many files will require this treatment and it's far less than I anticipated (less than 100). Considering small size of these BMPs I will do the conversion manually and include them in mod package.
Post Reply