Analysis of PCX Files for SMG

This article is based on my enquiry about a problem and RVinceD's reply.

My enquiry:
I have attached a stuff2.pcx. I loaded the original unlocked version into Ultimate Paint and then saved without any change by me. It gives me a beige background for all stuff2 graphics when I run SMG. Can you tell what change this made to the file?
I have also attached a version saved from Ultimate Paint without the "transparent check box" checked. It gives the same appearance.

RVinceD's reply:
The PCX file (the one we use in SMG) was the first design.
It's structure (internal) is very simple compared to what we have today.
Machines were slow and memory expensive, and so PCX was designed with that in mind.

In the 1st picture you will see that the file appears to have been created for special purposes ... note dots per inch (resolution) for screen and printer displays or when the image was first created on a screen or scanner.

There is also information to note where on the screen or printer the image should be displayed/printed.

None of this is used by SMG.

It is completely palette driven (colors are looked up on a fixed palette of colors).
New formats (and perhaps this is what is causing your problem) do not use the palette or do so in a modified manner.
Just as MS Paint no longer allows you to save the PCX file, perhaps the other products you are using (Paintbrush and something else) have also been upgraded so that, while it allows you to save the file, it does so in an upgraded manner.

As you view the next pictures, note how your software has drastically changed the color palette.


Stuff2.pcx original locked file

1.0 Inches by 1.0 Inches 640 pixels per Inch Horizontal
400 pixels per Inch Vertical => 640 x 400


Stuff2.pcx original unlocked file

1.6 Inches by 1.0 Inches 400 pixels per Inch => 640 x 400


Stuff2.pcx saved from ultimate paint

6.4 Inches by 4.0 Inches 100 pixels per Inch => 640 x 400

Stuff2.pcx saved without transparent clicked

6.4 Inches by 4.0 Inches 100 pixels per Inch => 640 x 400

Internal Structure

PCX was the original PC Paintbrush software (by Zsoft) file type.
Microsoft purchased rights, and used this for MS Paintbrush. Numerical format is little-endian.

All sections are fixed in length except for the image.
The larger the image, then the larger the section.

If the image is using a color palette, then the values in the bytes for the image are indices into the color palette.
If the palette is being used (256 color), then Run Length Encoding (RLE) compression is being used.

Newer versions are now supported. The above 256 color palette versions are no longer used.

If the image is not using a color palette (in other words, using 24 bit RGB color), then the palette is not being used (and does not exist in the file) and the image bytes are in triplets (R G and B color planes). If 24 bit, then there is NO compression.


None of the new (nor older) versions of PCX support the Alpha channel.

Thus, all transparent drawing is done using the initial, earlier, first way of doing things.
You select a color and tell the video monitor to ignore that color.
This color is the color in the first position of the palette (see next picture)

The alternative method would be to read in the image files and, noting the color in position 1 of palette [index 0], then modify the image in memory by adding the alpha position and setting the alpha values.
Shadows are handled another way.
In position 119 [index 246] of the color palette, there is a color denoting where shadows should be drawn. (see next picture)
This can be done by a number of ways.
By using the color as a mask and then draw a light gray on it.
Note how shadows appear black when zoomed out in SMG.

Alternately, one could use modified alpha channels within memory.

I'm betting SMG used the earlier, tried and true way.
But I honestly don't know.


Here is the magic.


Here comes a series of PCX files comparing the palette.
Also you can see how palette colors in position 1 and 119 [index 246] change and match up with the image.

Before you move on. By reviewing slides 3 and 4, you'll see that the palette your software is creating is causing the problem.

Remember the values inside the image are not colors, but rather indices (pointers) into the color palette such that the color select is displayed.

Thus, you are getting all of those biege colors.

One last important point.
PCX, old and new versions, (according to documentation online) "DOES NOT" support the alpha channel.
From what you explain, your software is using it. Is it possible that your software allows you to save other image formats?
And if so, the other formats make sense when using the alpha channel?

Check around the "help" ... you want to select 256 color format.
If you find it, that has a great possibility of fixing this problem.










To Sid Meier's Gettysburg main page Index






Free Web Hosting