Thanks to Julio Marchi for this space in MSX All
 

Shape (.SHP)

  The shape file is a collection of stacked pictures, where each picture has its own header and the picture data. This file do not have the MSX file header.

  The shape file format is described next:

 


  Header

  Each picture header has the following informations:

Offset
(hexa)
Size
(bytes)
Description
0 1 Shape ID
1 1 Shape type (1-4)
2 1 Shape width in pixels
3 1 Shape height in blocks of 8x8 pixels

  Header example: 01 01 30 06.

  Header description:

 Shape ID: 1
 Shape type: 1
 Shape width: &H30 or 48 pixels
 Shape height: &H06 or 6 blocks of 8x8 pixels = 48 pixels



  Picture data

  Depending on the shape type, each picture will be composed by the following tables:

Type Picture data Size
(bytes)
1 Pattern table Width x Height
2 Pattern and color tables 2 x Width x Height
3 Mask and pattern tables 2 x Width x Height
4 Mask, pattern and color tables 3 x Width x Height

  For each picture, the mask, pattern and color tables have the same size.


  Pattern table

  The pattern table (or character table) is responsible for setting the color pattern for each line of 8x1 pixels on screen. It defines if a pixel has front or background color, according to the colors defined for this line at the color table.


  Color table

  Defines the front and background colors for each line of 8x1 pixels. It works together with the pattern table.

  For further informations on these tables, please click here.


  Mask

  The mask is a pixel selector for the shape. This option can only be found at shapes type 3 and 4.
  Shapes type 1 and 2 overwrite all pixels within the picture limits, when copied on a screen region. In the other hand, shapes type 3 and 4 use a mask to indicate the pixels that will be copied to the screen.
  The mask value 0 indicates that the pixel will be copied to the screen, whereas the value 1 indicates that the pixel will not be copied. According to that, the mask is generally the complement values for the pattern data.

  Example:

  Shape       Mask

 00100000   11011111
 01010000   10101111
 10001000   01110111
 10001000   01110111
 11111000   00000111
 10001000   01110111
 10001000   01110111
 00000000   11111111


  The mask defines the contours of the letter "A". By using this mask, only the pixels that defines the letter "A" will be considered to be drawn, instead of considering all the pixels belonging to the picture's area.
  The next figure illustrates an overwriting situation for this shape, when using and not using the mask.

 


  Example

  Backing to the example on the header section, once it is a shape type 1, the picture data is composed only by the pattern table.
  Each table size is calculated by multiplying the width and height values present on the header. So, the size of the pattern table for our example is 48x6 or 288 bytes.
  We conclude that the picture 1 takes 4+88 or 292 bytes, and the file offsets 0 and 291 delimit it. Picture 2 starts from offset 292.

  0       291 292
 ┌───────────┬───────────┐
 │ Picture 1 │ Picture 2 │ ...
 └───────────┴───────────┘



  Shape file

  We cannot access directly a "picture N" in a shape file. For that, we must read picture by picture until reach the desired picture. This can be achieved by reading each picture header, calculating the current picture size and jumping to the next picture.

  This file type has always a size multiple of 128 bytes. In that case, it is possible to find trash at the end of file. The end of shapes is reached when the next picture ID is 255 (&HFF).


Marcelo Silveira
Systems and Computing Engineer
Expert in Image Processing and Artificial Intelligence
© MarMSX 1999-2025