Spectrum 512

From MultimediaWiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Spectrum 512 was an image drawing program for the Atari ST.

16-bit words are stored in big-endian order.

Spectrum 512 Uncompressed

  • Extension: .spu
typedef spectrum512_file {
 uint16_t data[16000];             /* first 80 words (first scanline) is unused and should be zeroes */
 uint16_t palettes[199 * 3 * 16];  /* 199 scanlines, 3 palettes per scanline, 16 entries per palette */
} spectrum512_file;

Spectrum 512 Compressed

  • Extension: .spc
typedef spectrum512_compressed_file {
 uint16_t magic;                   /* "SP" */
 uint16_t reserved;                /* always 0 */
 uint32_t data_length;             /* length of compressed image data */
 uint32_t palette_length;          /* length of compressed palettes */
 uint8_t data[];
 uint8_t palettes[];
} spectrum512_compressed_file;

Image data is compressed by RLE.

   0 <= x <= 127        x+1 literals
-128 <= x <=  -1        -x+2 times next byte

Each plane is stored separately, i.e. 199 scanlines of plane 0, 199 scanlines of plane 1, et cetera.

Just like uncompressed .spu files, there are 199 * 3 palettes of 16 entries. Each palette is compressed separately. A compressed palette:

typedef compressed_palette {
 uint16_t map;                    /* bit = 1, color is present; bit = 0, color is black (0x0000) */
 uint16_t colors[];
} compressed palette;

Bit 0 of map refers to palette entry 0 and so on. Bit 0 and bit 15 should always be zero. The background is always black and palette entry 15 is unused. This results in 15 * 3 + 1 = 46 colors per scanline.

Spectrum 512 Smooshed

  • Extension: .sps
typedef spectrum512_smooshed_file {
 uint16_t magic;                  /* "SP" */
 uint16_t reserved;               /* always 0 */
 uint32_t data_length;
 uint32_t palette_length;
 uint8_t data[];
 uint8_t palettes[];
} spectrum512_smooshed_file;

The image data is compressed similar to .spc files.

There's a second variant where the data is not encoded plane by plane and line by line, but in byte wide vertical stripes (for each plane (for each column (scanline 1-199))).

It is unknown how (or impossible) to distinguish the two variants.

The palettes are compressed similar to .spc files, but rather than uint16_t values, variable length codes are stored. Each palette consists of a 14-bit map which marks which entries will follow (entries 0 and 15 are skipped and set to black). After the map, zero or more codes of 9-bits follow.

Palettes

Spectrum 512 files use three palettes per scanline. Because of the Atari ST's limitted graphics capabilities, a trick was used to change the hardware color palette twice per scanline. Given an x-coordinate and a color index, the following algorithm returns the corresponding spectrum palette index (0-47).

int find_index(unsigned int x, unsigned int c) {
    unsigned int t = 10 * c;

    if (c&1) t -= 5;
    else     t++;

    if (x < t)      return c;
    if (x >= t+160) return c + 32;
    return c + 16;
}

Image Data

Uncompressed image data (.spu files) is stored in a planar format.

Atarist lowres.png