Main File Header (Offset 0) (4 Bytes)

The SHP file itself starts with four bytes that are always "1.10".

SHP Image Count (Offset 4) (4 Bytes)

4 Byte variable giving the number of SHP images in the file.

Table List (Begins at Offset 8)

This lists the address(es) where each image begins and the address of the palette information for that image (this part is generally ignored.)

Essentially, it is a repeating table of two values:

SHP Offset (four byte long integer)
SHP Palette Offset (four byte long integer)

If the SHP file has 10 images, there would be 10 sets of the above, for 20 total values.

Here's an example from a SHP:

256
0
7930
0
10757
0
10853
0

Basically, SHP #1 begins at offset 256, SHP #2 at offset 7930, etc.

The Table List offsets that concern us for Steel Panthers are:

Image #1 Address Offset: 8
Image #2 Address Offset: 16
Image #3 Address Offset: 24
Image #4 Address Offset:
32

etc.
A simple equation to calculate where to get the offset from is this:
8 * ImageNumber = Offset Location
Thus, Image 35 would be 8 * 35 = 280 offset.

Image Information (Begins at and continues)

Each SHP image begins with a header which is 24 bytes long and stores various parameters such as the image size.

The header is uncompressed and is arranged in the following order:

Offset

Data

0

Height (aka lines) (two byte integer)
(this is really the number of lines -1)

2

Width (two byte integer)

4

Var1 (four byte long integer)

8

X Start (four byte long integer)

12

Y Start (four byte long integer)

16

X End (four byte long integer)

20

Y End (four byte long integer)

The header is followed by the actual image data. These headers are very easy “tells” by which to locate SHP data; especially if all the icons in a SHP file are the same standard size: 88 x 88 – then you'd look for the following sequence that indicates the start of a new SHP Icon+Header: 88 0 88 0

The Actual SHP Files

These are compressed image files utilizing a 256-color palette.

The compression method is a simple run-length-encoding (RLE) that works via truncating multiple strings of the same character together; e.g.





Completely Blank (All 255 Pink Transparent SHP)

Contains nothing but the 24 byte header, with the following values:

Height: 88
Width: 88
var1: 0
xstart: 640
ystart: 90
xend: 0
yend: 32

SHP Run Length Encoding Code

SHP files are compressed via Run Length Encoding (RLE) using the following format:

AB

A: Pixels of this color to be painted.
B: Palette Index of Color.











DECOMPRESSION CODE

Do
{
// read data and decode
ch=fgetc(inf);
r=ch%2;
b=ch/2;
if (b==0 && r==1) // a skip over
{
ch=fgetc(inf);
for (i=0; i<ch; ++i)
put_pix(l,BKG_COLOR);
}
else if (b==0) // end of line
{
++l;
if (shpheader.xstart<0)
{
pix_pos=0;
}
else pix_pos=0;//pix_pos=shpheader.xstart;
}
else if (r==0) // a run of bytes
{
ch=fgetc(inf); // the color #
for (i=0; i<b; ++i)
put_pix(l,(short)ch);
}
else // b!0 and r==1 ... read the next b bytes as color #'s
{
for (i=0; i<b; ++i)
{
ch=fgetc(inf);
put_pix(l,(short)ch);
}
}
} while (l<=lf);
}











OLD

Shp Files

Although it isn't necessary to understand the details of the shp file format to work with them, a little information may help you in using ShpEd. First of all, the shp format is based on a 256 color model. Each of the 256 colors is defined in a palette as a Red/Green/Blue combination able to take on values 0-63 (0-255 in the external palettes). Although some shp files include palette information as an integral part of the file, some do not. In any event, as far as I know, none of the games actually use the palette information in the shp file. Instead, there are one or more palettes defined somewhere in the game files. The bitmaps exported from ShpEd are in 24-bpp format (16million color) mode, so there are effectively an infinite number of colors available while you edit, but when the image is imported into ShpEd for incorporation into the shp file, only the maximum 256 colors in the game palette are available. This can lead to some problems in color matching. Pacific General uses many palettes, some of which are very limited in their color range, so the problems with color matching can be very apparent. This is not a limitation of ShpEd but is inherent in the games themselves.



Shp files include a provision for transparency, i.e. portions of the image don't cover up the information already on the screen. Since bmp files do not include a transparent feature, a special bright pink color (RGB triple 255,225,225) is used by ShpEd to represent transparent portions of the image. It is important in working on bitmaps with transparent areas that this color not be changed. Adding more transparent area to an image is best done by using the eyedropper function to copy the pink color from one area to another. Edited bmp files must be saved in 24-bpp mode. It is all that ShpEd can read.



The shp file itself starts with four bytes that are always "1.10". The next four bytes give the number of images in the file. This is followed by a table which lists the address where the information for each of the images starts and the address of the palette information for that image (remember, this is generally ignored). The information for each image begins with a header which is 24 bytes long and stores various parameters such as the image size. The header is followed by the actual image data.



------



Header. Use Old Header. For Steel Panthers files, the header is non-standard. If this box is checked, ShpEd will not try to change the information. This is a good option if you are only trying to make small changes to the image. You can write a new header using the Fix Header button if you need to.



Fix Header. For Steel Panthers, the headers are more complicated than for most shp images. The function, described in detail elsewhere, will allow you to write a header to display images in the Iconxxxx files correctly. See SP Fix in the contents.