Page 1 of 1

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

Posted: 2013-03-25T05:38:25-07:00
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.

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

Posted: 2013-03-25T07:38:54-07:00
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.

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

Posted: 2013-03-26T06:00:21-07:00
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.

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

Posted: 2013-03-26T06:48:56-07:00
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.