This is a description of the SGX graphic format used in SymbOS and in SymSee.
A SGX graphic consists of any number of chunks, which define different picture parts. While there are limitations for the width and the height of a single part, the complete graphic can have any size, as all parts will be linked together.
Chunk types
Simple 4 colour graphic
byte 0: width in bytes (1-63) byte 1: width in pixel (1-252) byte 2: height in pixel (1-255) byte 3-n: linear graphic data (size = byte0 * byte2)
This chunk type can be recognized, if the first byte has a value between 1 and 63. The 4 colour graphic data is encoded in CPC Mode 1 format. Every byte contains 4 pixels:
bit7 = bit0 of pixel0 (left pixel) bit6 = bit0 of pixel1 bit5 = bit0 of pixel2 bit4 = bit0 of pixel3 (right pixel) bit3 = bit1 of pixel0 bit2 = bit1 of pixel1 bit1 = bit1 of pixel2 bit0 = bit1 of pixel3
Or you can see it like this:
pixel0 = bit7 + 2 * bit3 (left pixel) pixel1 = bit6 + 2 * bit2 pixel2 = bit5 + 2 * bit1 pixel3 = bit4 + 2 * bit0 (right pixel)
Extended 4 or 16 colour graphic
byte 0: 64 byte 1: type (0=4 colour graphic, 5=16 colour graphic) byte 2,3: width in bytes (1-255 [4c] or 2-254 [16c]) byte 4,5: width in pixel (1-1020 [4c] or 1-508 [16c]) byte 6,7: height in pixel (1-65535) byte 8-n: linear graphic data (size = byte2,3 * byte6,7)
This chunk type can be recognized with 64 in the first byte. 4 colour graphics are encoded in CPC Mode 1 format (see above). 16 colour graphics are encoded in MSX Screen 5/7 format. Every byte contains 2 pixels:
bit7-4 (high nibble): left pixel bit3-0 (low nibble): right pixel
Please note, that currently there are some limitations:
- the maximum width for 4 colour graphics is 1020 pixel
- the maximum width for 16 colour graphics is 508 pixel
- 16 colour graphics must always have an even width in bytes (2,4,...,254)
Line feed
byte 0: 255 byte 1,2: undefined
This chunk has a length of 3 bytes and can be recognized with 255 in the first byte. Usually every graphic part will be linked right to the previous part. After a line feed the next graphic part will be linked below the first graphic of the previous "line".
EOF
byte 0: 0 byte 1,2: undefined
An EOF is not explicit required, but should be added, if graphics are stored on an Amsdos or CP/M disc, as these file system are not able to store the exact size of a file.
Palette
SGX files don't contain colour palette definitions, as these graphics have been designed in a way, which makes it possible to display them in any environment and colour-depth (2, 4 or 16 colours) on the SymbOS desktop.
For 4 colour graphics it means, that there is just a grayscale definition:
- Pen 0: white
- Pen 1: black
- Pen 2: light gray
- Pen 3: dark gray
This can be used for any type of colour, like orange, brown, light red, dark red etc.
16 colour graphics have a fixed palette which has the following definition:
- Pen 00-03: #ff8,#000,#f80,#800
- Pen 04-07: #0ff,#008,#88f,#00f
- Pen 08-11: #fff,#080,#0f0,#f0f
- Pen 12-15: #ff0,#888,#f88,#f00
The values are in CPC Plus RGB format. #ff8 means: red=15, green=15, blue=8.
On the MSX it would mean: red=7, green=7, blue=4.
On the CPC old generation it means: red=2, green=2, blue=1 (= 1*3^0 + 2*3^1 + 2*3^2 = 25).