Set a palette in a Windows BMP file (8 bit) ?

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
myicq
Posts: 29
Joined: 2012-04-11T04:23:21-07:00
Authentication code: 8675308

Set a palette in a Windows BMP file (8 bit) ?

Post by myicq »

Referring to previous topic on this matter I have come a bit further.

Thanks to the help of [snibgo].

I am almost there, but would like to have the final step.

What I have so far is the conversion from "Raw" to "header" version of BMP.

I now only need to find out how to insert the palette into the image.

Please see the files here.
My trials have been:

Code: Select all

convert -size 300x119 -depth 8 gray:qwerty.raw q3.bmp
.. this will create a 24 bit type "grayscale" image.

Code: Select all

convert -size 300x119 -depth 8 gray:qwerty.raw -type palette q3_palette.bmp
.. this will create a 4 bit type "palette" image.

I would like to create same thing as "good.bmp" which has 3 channel depths, unlike q3_palette. Also it has 256 colors.

In addition to that, I would like to modify the colors() array, which is the palette Windows sees. Either specified directly on the command line, or taken from "good.bmp".

At this moment I have to manually load each image to convert into PSP, then convert, load palette, save.

Hope I asked the question right.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Set a palette in a Windows BMP file (8 bit) ?

Post by snibgo »

Your image has only three colours. IM tries to keep the palette (and hence the number of bits used to index into the palette) small, if it can. I don't know of a way to tell IM to create a palette larger than it needs to be. However, you may be able to do it somehow. For example, this ...

Code: Select all

convert good.bmp q3.bmp -compose Over -composite -type palette q4.bmp
... results in q4.bmp having a palette with 16 entries.
snibgo's IM pages: im.snibgo.com
myicq
Posts: 29
Joined: 2012-04-11T04:23:21-07:00
Authentication code: 8675308

Re: Set a palette in a Windows BMP file (8 bit) ?

Post by myicq »

Excellent idea, the explanation makes sense to me. Although it is annoying when software tries to be "intelligent" on my behalf, just like Excel / Word tends to do. I will make some experiments with your idea there.

Do you know how to modify the individual items of the Color array ? Example modify a 16 or 256 color BMP and specifically make color 5 = #A3A3A3 ? Or specify the entire array ? Or copy a color array from somewhere ?

Thanks for your help.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Set a palette in a Windows BMP file (8 bit) ?

Post by snibgo »

IM provides tools for manipulating images, rather than the implementation of images in particular file formats. Decades ago, I wrote software to manipulate BMP files; it isn't difficult. Such software could easily change palette entries. The only difficulty would be coping with the very wide variety of BMP formats.

I expect there is software somewhere that does what you want.
snibgo's IM pages: im.snibgo.com
Post Reply