Page 1 of 1

Force use of palette, exactly as given?

Posted: 2015-10-06T14:09:26-07:00
by stoo
Hi guys,

I'm trying to generate textures for the Quake engine. The textures must be in PCX format and they must use a strict 256 colour palette.

http://quakewiki.org/wiki/Quake_palette

Image

The palette in the PCX must be EXACTLY as above, in exactly the same order and with duplicate colours retained.

Code: Select all

CONVERT texture_composed_01.png -remap quake1palette.png texture_qpal.pcx
This command does put the image into the Quake palette. Unfortunately it also rearranges the palette and removes all duplicate entries!

Is there any way to force ImageMagick to use the palette EXACTLY as specified to output an 8-bit indexed PCX?

Thanks.

(Forgot to say: ImageMagick-6.9.2-Q16, Windows, Shell)

Re: Force use of palette, exactly as given

Posted: 2015-10-06T14:17:15-07:00
by snibgo
Try:

Code: Select all

-define png:preserve-colormap[=true]
See http://www.imagemagick.org/script/comma ... php#define

Re: Force use of palette, exactly as given?

Posted: 2015-10-06T14:34:54-07:00
by stoo
Thanks for the response, snibgo. Unfortunately, that option seems to make absolutely no difference at all. :/

Re: Force use of palette, exactly as given?

Posted: 2015-10-06T14:44:18-07:00
by snibgo
"preserve-colormap" probably needs the input file to already have the colormap you want. I don't think IM has a method of forcing a output to contain an exact colormap. (But I could be wrong. I don't use colormaps.)

Re: Force use of palette, exactly as given?

Posted: 2015-10-06T14:47:03-07:00
by stoo
Well, if that's true that really sucks... and I have a feature request :P

Re: Force use of palette, exactly as given?

Posted: 2015-10-06T15:40:59-07:00
by fmw42
The only way I know is to create an image colortable and use -remap to remap the image to only have those colors. See http://www.imagemagick.org/Usage/quantize/#remap

Re: Force use of palette, exactly as given?

Posted: 2015-10-06T16:12:38-07:00
by stoo
Hi fmw42,

Thanks for your reply. That is exactly what I am doing. I am remapping the image to a palette stored in an 8-bit PNG with the exact colours I need in the exact order I need.

The problem is the remap is "lossy". It does not use the 256 colour pallete as it is provided. It re-orders the palette and removes duplicates. This makes it useless for purposes where the palette must be exactly as specified.

Basically, it would be super awesome if IM had an option like -remapexact or something that didn't try to "optimize" the palette when remapping.

Re: Force use of palette, exactly as given?

Posted: 2015-10-06T16:29:29-07:00
by fmw42
Did you add +dither or -dither none?

Re: Force use of palette, exactly as given?

Posted: 2015-10-06T17:13:00-07:00
by snibgo
The problem is that you want one image remapped to another image, and to take the exact palette from that other image.

Maybe the job can be done in Gimp, menu: image, mode, indexed, then "use custom palette".

Re: Force use of palette, exactly as given?

Posted: 2015-10-07T01:25:54-07:00
by stoo
fmw42 - Yep, unfortunately dithering options make no difference.

snibgo - Yeah, I can do this with several other tools, but the whole point was I needed it to be automated and scriptable.

Here's what I need the palette to be:

Image

Here's what IM does:

Image

Here's how I think -remap works in IM:

1. IM decodes the image passed by -remap
2. IM gathers a list of all unique RGB values in the decoded image (pixel by pixel?)
3. IM builds a palette with RGB values found in step 2 and orders them (what order?)
4. IM applies the palette to the target image using whatever options the user provides (dither etc.)

The "problem" lies in steps 2 and 3.

2. When gathering the colours used in the -remap, IM just picks up each unique RGB value once. This is probably correct behaviour 99.999% of the time, it's just not for my purposes. I need it to take ALL the RGB values, in the order they appear, without removing duplicates.

3. When building the palette, IM uses some method I haven't figured out to index the palette. What I need it to do is take each RGB value in the order it finds them in the image, without rearranging them.

Outputting this indexed PCX is just the final step in a larger script. The rest of the script works absolutely fine. It's just a shame that IM can't manage the final step because it has no way to force the use of a palette - it can only "rebuild" a palette from an existing image, and the user has very little control over how it rebuilds it.

Re: Force use of palette, exactly as given?

Posted: 2015-10-07T05:27:45-07:00
by snibgo
If Gimp can do the job, then running Gimp in batch mode with a script seems the obvious solution.

If I understand you correctly, you don't want steps 2 or 3. You want to use the actual palette that is in quake1palette.png. The pixel values in that file aren't relevant. They can be ignored. Only the palette is relevant, and you want your output to have exactly that palette, in the same order. Is that correct?

Re: Force use of palette, exactly as given?

Posted: 2015-10-08T10:58:34-07:00
by stoo
Yes. Here is a PNG that just happens to have the palette and the pixels in the image mapped 1:1.

Image

Re: Force use of palette, exactly as given?

Posted: 2016-06-09T02:20:06-07:00
by Knight Captain
I'm in a similar situation trying to bulk modify indexed PNG images exported from Exult Studio for use in Ultima 7. Was this question answered, using either IM or the Gimp consoles?

Like many 90s games, Ultima 7 uses some palette swapping of its own in-game. This was their memory-friendly way to show the time of day using different palettes, as well as some visual effects.
Palette 0 is for daytime, 1 for dusk/dawn, 2 for night, 3 for when you're invisible, 10 for lightning.
Palette 10 is washed out for blinding lightening strikes, and it looks like Palette 8 is when everything turns red briefly to indicate you have been hit. Each palette has the same order to allow this swapping. Due to this DOS-era design, modified files need to use the stock daytime pallet so the swaps to other palettes done by the game engine will work correctly.

So far I am able to bulk modify images for the color swaps, but the preserve-colormap option does not keep the one from the source image. How can I take the below palette, keep it in order as-is, and use it in my new images via IM?

The IM-created files are defaulting to RGB PNGs. Is there a way to have the new files default to Indexed? My workaround at the moment is to open each in Gimp and manually switch it back, but that's a pain when each sprite can have 32 images or more. I can't specify PNG8 without the palette file.

Code: Select all

GIMP Palette
# Exported from ExultStudio
  0   0   0
248 240 204
244 228 164
240 220 120
236 208  80
236 200  40
216 172  32
196 148  24
176 128  16
156 104  12
136  84   8
116  68   4
 96  48   0
 76  36   0
 56  20   0
252 252 252
252 216 216
252 184 184
252 152 156
252 120 128
252  88 100
252  56  76
252  28  52
220  20  40
192  12  28
164   8  20
136   4  12
108   0   4
 80   0   0
 52   0   0
 24   0   0
252 236 216
252 220 184
252 204 152
252 188 124
252 172  92
252 156  60
252 140  28
252 124   0
224 108   0
192  96   0
164  80   0
136  68   0
108  52   0
 80  36   0
 52  24   0
 24   8   0
252 252 216
244 244 156
236 236  96
228 228  44
220 220   0
192 192   0
164 164   0
136 136   0
108 108   0
 80  80   0
 52  52   0
 24  24   0
216 252 216
176 252 172
140 252 128
108 252  84
 80 252  40
 56 252   0
 40 220   0
 28 192   0
 20 164   0
 12 136   0
  4 108   0
  0  80   0
  0  52   0
  0  24   0
216 216 252
184 184 252
152 152 252
124 124 252
 92  92 252
 60  60 252
  0   0 252
  0   0 224
  0   0 192
  0   0 164
  0   0 136
  0   0 108
  0   0  80
  0   0  52
  0   0  24
232 200 232
212 152 212
196 108 196
176  72 176
160  40 160
140  16 140
124   0 124
108   0 108
 96   0  96
 80   0  80
 68   0  68
 52   0  52
 36   0  36
 24   0  24
244 232 228
236 220 212
228 204 192
224 192 176
216 176 160
208 164 144
200 152 128
196 140 116
172 124 100
152 108  88
128  92  76
108  76  60
 84  60  48
 60  44  36
 40  28  20
 16  12   8
236 236 236
220 220 220
204 204 204
188 188 188
172 172 172
156 156 156
140 140 140
124 124 124
108 108 108
 96  96  96
 80  80  80
 68  68  68
 52  52  52
 36  36  36
 24  24  24
  8   8   8
232 224 212
216 200 176
200 176 144
184 152 112
168 132  88
152 112  64
136  92  44
124  76  24
108  60  12
 92  52  12
 76  44  12
 60  36  12
 44  28   8
 32  20   8
236 232 228
220 212 208
204 196 188
188 176 172
172 160 152
156 144 136
140 128 120
124 112 104
108  96  92
 96  84  80
 80  72  68
 68  60  56
 52  48  44
 36  32  32
 24  20  20
224 232 212
200 212 180
180 192 152
156 172 124
136 152  96
112 132  76
 92 112  56
 76  92  40
 64  80  32
 56  68  28
 48  60  24
 40  48  20
 32  36  16
 24  28   8
 12  16   4
236 216 204
220 184 160
204 152 124
188 128  92
172 100  60
156  80  36
140  60  12
124  44   0
108  36   0
 96  32   0
 80  28   0
 68  20   0
 52  16   0
 36  12   0
240 240 252
228 228 252
216 216 252
204 204 252
192 192 252
180 180 252
168 168 252
156 156 252
132 208   0
132 176   0
124 148   0
104 120   0
 80  88   0
 60  64   0
 44  36   0
 28   8   0
 32   0   0
236 216 196
220 192 180
204 180 160
188 156 148
172 144 128
156 132 116
140 116 100
124 100  88
108  84  76
 96  72  68
 80  64  56
 68  52  44
 52  44  36
 36  24  24
 24  16  16
252 252 252
176 212 240
112 172 228
 52 140 216
  0 108 208
 48 140 216
108 176 228
176 212 240
252 252 252
252 236  64
252 192  40
252 140  16
252  80   0
200  56   0
152  40   0
104  24   0
124 220 124
 68 180  68
 24 144  24
  0 108   0
248 184 252
252 100 236
252   0 180
204   0 112
252 252 252
252 252   0
252 208   0
252 172   0
  0   0   0
100  60  16
252 208 112
233   0   4
There is a duplicate color or two for the transparency and color cycling effects the game engine uses.

Re: Force use of palette, exactly as given?

Posted: 2016-06-09T02:50:41-07:00
by snibgo
If you can do it manually in Gimp, I guess you can script it in Gimp.

Re: Force use of palette, exactly as given?

Posted: 2016-06-10T10:20:42-07:00
by Knight Captain
It looks like I may not need to keep the same palette in each image, as the import of the files worked after making the PNGs Indexed. How can I get the palette info into a file form that IM can use so I can specify the Indexed option?