Last modified on 30 May 2023, at 09:44

Format:SGX (SymbOS graphic files)

Revision as of 09:44, 30 May 2023 by Prodatron (Talk | contribs) (data compression)

Screen shots showing the same 16 colour SGX graphic in 6 different screen modes

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 part

byte 0: [bit0-6] width in bytes (1-63)
        [bit7] flag, if graphic data is compressed
byte 1: width in pixel (1-252)
byte 2: height in pixel (1-255)
if uncompressed:
byte 3-n: linear graphic data (size = byte0 * byte2)
if compressed:
byte 3,4: size of compressed graphic data
byte 5-n: compressed linear graphic data (ZX0 with special SymbOS header)

This chunk type can be recognized, if the first byte has a value between 1 and 63 (uncompressed) or between 129 and 191 (compressed). 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 and 16 colour graphic part

byte 0: [bit0-6] 64
        [bit7] flag, if graphic data is compressed
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)
if uncompressed:
byte 8-n: linear graphic data (size = byte2,3 * byte6,7)
if compressed:
byte 8,9: size of compressed graphic data
byte 10-n: compressed linear graphic data (ZX0 with special SymbOS header)

This chunk type can be recognized with 64 (uncompressed) or 192 (compressed) 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 a 4 colour graphic part is 1020 pixel
  • the maximum width for a 16 colour graphic part is 508 pixel
  • 16 colour graphic parts 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).


Palette configuration and colors (for 16 colors format):

SymbosSGX.jpg

Graphic data compression

Both simple and extended graphic parts can be stored in a compressed way. Compressed data has to be stored in the following SymbOS-specific way, which is used for all kind of compressed data in SymbOS:

00  4B  last 4 bytes of the data (not compressed)
04  1W  size of non compressed part at the beginning (usual 0)
06  ?B  not compressed part of the data
??  ?B  compressed part of the data without the last 4 bytes
        using the "ZX0 data compressor" by Einar Saukas, see
        https://github.com/einar-saukas/ZX0

See also

Web links